akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define endl enjoy_codeforces
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    lint q;std::cin>>q;
    while(q--){
        lint L=1;for(lint i=0;i<30;i++)L*=3;
        lint i0,j0,i1,j1;std::cin>>i0>>j0>>i1>>j1;
        i0--,j0--,i1--,j1--;
        for(;i0/L==i1/L&&j0/L==j1/L;L/=3);
        assert(1<=L);
        if(j0/L==j1/L){
            std::swap(i0,j0);std::swap(i1,j1);
        }
        assert(j0/L!=j1/L);
        lint d=0;
        for(;L;L/=3){
            lint I0=i0/L,I1=i1/L,J0=j0/L,J1=j1/L;
            assert(J0!=J1);
            if(I0!=I1)break;
            if(I0%3==1&&1<std::abs(J0-J1)){
                lint r0=i0%L,r1=i1%L;
                d=std::min({r0+1,r1+1,L-r0,L-r1});
                break;
            }
        }
        std::cout<<std::abs(i0-i1)+std::abs(j0-j1)+2*d<<'\n';
    }
}
/*
 * 避けなければならないものは高々一つです。
 * 大きい方から順にためします。
 *
 * i を L で割った商 I が異なるか、j を L で割った商 J が異なるかである最小の L にセットです。
 * これらが両方とも成り立っていたら、コストは 0 です。
 * I が同じで J が異なるとしましょう。
 * I%3==1 であり、J の差が 2 以上ならば壁はこれです。
 * このとき、コストは min(i0%L+1,i1%L+1,L-i0%L,L-j0%L) です。
 * そうでないときには、L / 3 をチェックです。
 * このように繰り返します。繰り返しのたびに、i の方まで違っていないかをチェックです。
 */


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

using namespace std;

long long int a = 0, b = 0, c =0, d = 0, e = 9999, n = 0, maxy = 0, mini = 9999, ans = 0, counter = 0, sur = 0;
std::vector<int> vec{};
std::vector<std::string>str{};
std::vector<std::string>str2{};

int arraykun[2300] = {}, nyan[1001] = {}, koji[50][50];
std::string output, output2, input,nyahhoi;
int kakunou[50][50] = { 53 }, moji[50];

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
int dp(int i, int j) {
	bool okada = true;
	if (i == 0 || j == 0) {
		okada = false;
		return 0;
	}
	if (koji[i][j] == -1) {
		okada = false;
		return 0;
	}
	if (i == 1 && j == 1) {
		okada = false;
		return 1;
	}
	if (okada) {
		return dp(i - 1, j) + dp(i, j - 1);
	}

}
int main()
{

	cin >> a;
	if (a == 0) {
		cout << 0 << endl;
	}
	else {
		while (true) {
			b = a / -2;
			c = a % -2;
			if (c < 0) {
				c = 1;
				b += 1;
			}

			a = b;




			vec.push_back(c);


			if (b == 1) {
				vec.push_back(b);
				break;
			}
		}
		for (int i = vec.size() - 1; i >= 0; i--) {
			cout << vec[i];
		}
	}
}






Measured memory_bytes: 256
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
const int MAX = 1e6;
int main() {
#ifdef LOCALe
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    vector<string> s(n);
    forn(i, n) cin >> s[i];
    vector<map<char, int>> v;
    forn(i, n) {
        map<char, int> cur;
        forn(j, sz(s[i])) {
            cur[s[i][j]]++;
        }
        v.pb(cur);
    }
    map<char, int> ans;
    for (char i = 'a'; i <= 'z'; i++) {
        ans[i] = 1e9;
    }
    forn(i, n) {
        for (char j = 'a'; j <= 'z'; j++) {
            ans[j] = min(ans[j], v[i][j]);
        }
    }
    for (auto x : ans) {
        forn(i, x.S) cout << x.F;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  int N;
  cin>>N;
  vector<int>P(N);
  for(int i=0;i<N;i++){
    cin>>P[i];
  }
  int cnt=0;
  for(int i=0;i<N;i++){
    if(P[i]!=i+1){cnt++;}
  }
  if(cnt==2||cnt==0){cout<<"YES"<<endl;}
  else{cout<<"NO"<<endl;}
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
  int n,p[20];
  int cnt=0;
  
  cin>>n;
  for(int i=0;i<n;i++)cin>>p[i];
  for(int i=1;i<n-1;i++){
    if(p[i-1]>p[i]&&p[i]>p[i+1]){
      cnt++;
    }else if(p[i-1]<p[i]&&p[i]<p[i+1]){
      cnt++;
    }
  }
  cout<<cnt<<endl;
}

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

int main() {
  int S;
  cin >> S;
  int s = S%100;
  string answer;
  if (100<=S && S<1300) {
    if (1<=s && s<=12) {
      answer = "AMBIGUOUS";
    }
    else {
      answer = "MMYY";
    }
  }
  else {
    if (1<=s && s<=12) {
      answer = "YYMM";
    }
    else {
      answer = "NA";
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

        long long n,k,s=0;
        cin>>n>>k;
        long long a[n],i;
        for(i=0;i<n;i++)
        cin>>a[i];
        sort(a,a+n);
        for(i=0;i<k;i++)
        s=s+a[i];
        cout<<s;
    return 0;
}


Measured memory_bytes: 3644
from collections import deque
import sys

imput = sys.stdin.readline

h,w = map(int,input().split())
sy,sx= map(int,input().split())
gy,gx= map(int,input().split())
S=[]



for i in range(h):
    S.append(input())

walk = [[1,0],[-1,0],[0,1],[0,-1]]
move = [[x,y] for x in range(-2,3) for y in range(-2,3) if [x,y] not in walk + [[0,0]]] 

dist = [[9999999]*w for i in range(h)]
#visited = [[0]*w for i in range(h)]

q=deque()
q.append((sx-1,sy-1,0))
dist[sy-1][sx-1]=0
goaled = 0
endwarp=0
#while goaled==0:
while len(q):
    endwarp=0
    
    x,y,d = q.popleft()
    
#    if x==gx-1 and y==gy-1:
#        goaled=1
#        print(d)
#        break
    
#    print(x,y,d)
    for i in walk:
        if 0<=x+i[0]<w and 0<=y+i[1]<h and S[y+i[1]][x+i[0]]!="#" and dist[y+i[1]][x+i[0]] > d:

                    dist[y+i[1]][x+i[0]] = d
                    q.appendleft((x+i[0],y+i[1],d+0))

    for i in move:
        if 0<=x+i[0]<w and 0<=y+i[1]<h and S[y+i[1]][x+i[0]]!="#" and dist[y+i[1]][x+i[0]] > d+1:

                    dist[y+i[1]][x+i[0]] = d+1
                    q.append((x+i[0],y+i[1],d+1))
                        
                        
                         
    
    

if dist[gy-1][gx-1]==9999999:
    print(-1)
    
else:
    print(dist[gy-1][gx-1])




Measured memory_bytes: 94528
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

using namespace std;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
const long double Pi=acos(-1),e=2.718;
const int N=1e2+10,W=1e5+10,mod=3e7;
ll w[N],v[N],dp[N][W],n,k;
ll solve(int i,int vv){
    if(vv<=0)return 0;
    if(i==n)return oo;
    ll &ret=dp[i][vv];
    if(ret+1)return ret;
    ret = oo;
    ret = min(ret,solve(i+1,vv-v[i])+w[i]);
    ret = min(ret,solve(i+1,vv));
    return ret;
}
int main()
{
    memset(dp,-1,sizeof dp);
    FASTIO
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> w[i] >> v[i];
    }
    for(int i=W;i>=0;i--){
        if(solve(0,i)<= k){
            return cout << i << endl,0;
        }
    }
    return 0;
}
/**

*/


Measured memory_bytes: 86272
object Main {
	val s = new java.util.Scanner(System.in)
	def main(args: Array[String]) {
		val x, y = s.nextInt;
		println(if(group(x)==group(y))"Yes"else"No");
	}
	def group(v: Int): Int = {
		v match {
			case 2 => 1
			case 4 | 6 | 9 | 11 => 2
			case _ => 0;
		}
	}
}


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

int main(){
  double n;
  cin >> n;
  vector<double> a(n);
  vector<double> b(n);
  double c = 0;
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    b.at(i) = 1 / a.at(i);
    c += b.at(i);
  }
  printf("%.6f", 1 / c);
}



Measured memory_bytes: 256
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			List<Point> points = new ArrayList<Point>();
			for(int i=0;i<n;i++) {
				points.add(new Point(sc.nextInt(), sc.nextInt()));
			}
			points.sort((p1, p2) -> {
				int result = p1.x - p2.x;
				if(result == 0)
					result = p1.y - p2.y;
				return result;
			});
			points.forEach(point -> System.out.println(point.x + " " + point.y));
		}
	}
}



Measured memory_bytes: 108060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  ll a,b,c;
  cin >> a >> b >> c;
  ll k = a*100+b*10+c;
  // cout << k;
  if(k%4==0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include"atcoder/all"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
//using namespace atcoder;
typedef long long ll;
int main(){
  ll N,K,i,j,sum;scanf("%lld%lld",&N,&K);
  ll a[N];
  vector<ll> B;
  for(i=0;i<N;i++) scanf("%lld",&a[i]);
  for(i=0;i<N;i++){
    sum = a[i];
    B.emplace_back(sum);
    for(j=i+1;j<N;j++){
      sum += a[j];
      B.emplace_back(sum);
    }
  }
  ll ans = 0;
  vector<ll> C;
  for(i=40;i>=0;i--){
    for(j=0;j<B.size();j++){
      if(B[j] & (1LL<<i)) C.emplace_back(B[j]);
    }
    if(C.size() >= K){
      ans += 1LL<<i;
      B.swap(C);
    }
    vector<ll>().swap(C);
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 8932
x,y=map(int,input().split())
if abs(x)==abs(y):
  print((x*y<0)+0)
elif x*y==0:
  if x>0 or y<0:
    print(abs(x-y)+1)
  else:
    print(abs(x-y))
elif x<y:
  if x*y>0:
    print(abs(x-y))
  else:
    if abs(x)<abs(y):
      print(1+abs(abs(x)-abs(y)))
    else:
      print(1+abs(abs(x)-abs(y)))
else:
  if x*y>0:
    print(2+abs(abs(x)-abs(y)))
  else:
    if abs(x)<abs(y):
      print(1+abs(abs(x)-abs(y)))
    else:
      print(1+abs(abs(x)-abs(y)))

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main(){
  int a,s1,s2,s3,s4,sum,x;
  char op1,op2,op3;
  scanf("%d",&a);
  s1 = a/1000;
  s2 = (a/100)%10;
  s3 = (a/10)%10;
  s4 = a%10;
  sum = (s1+s2+s3+s4-7)/2;
  if(sum == 0){
    printf("%d+%d+%d+%d=7\n",s1,s2,s3,s4);
  }else if(sum == s2){
    printf("%d-%d+%d+%d=7\n",s1,s2,s3,s4);
  }else if(sum == s3){
    printf("%d+%d-%d+%d=7\n",s1,s2,s3,s4);
  }else if(sum == s4){
    printf("%d+%d+%d-%d=7\n",s1,s2,s3,s4);
  }else if(sum == s3 + s2){
    printf("%d-%d-%d+%d=7\n",s1,s2,s3,s4);
  }else if(sum == s4 + s3){
    printf("%d+%d-%d-%d=7\n",s1,s2,s3,s4);
  }else if(sum == s2 + s4){
    printf("%d-%d+%d-%d=7\n",s1,s2,s3,s4);
  }else if(sum == s4 + s3 + s2){
    printf("%d-%d-%d-%d=7\n",s1,s2,s3,s4);
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

/**
 * 
 * @author DemonSong
 * 
 *         0033.Ball
 * 
 *         ???????????????????????????????????????????????¨??????????????????1 ?????? 10 ?????§???????????????????????????10 ?????????????????¨????????£??¨ A ???????????¨??????????????? B
 *         ???????????? C ???????????\??????????????? D ????????? E ??????????????????????????¢??§???????????§?????? D ?????????????????¨??§??? B ??¨??? C
 *         ?????????????????\??????????±????????????¨?????§????????????
 * 
 *         ?????£??¨ A ???????????¨????????????????????????????????????????????????????????? B ????????? C?????\?????????????????????????????¨????????? B ??¨??? C
 *         ??????????????????????????¨?????????????°?????????????????????§?????????????????????????????´?????? YES???????????????????????´?????? NO
 *         ??¨????????????????????°?????????????????????????????????????????????????????¨????????§?????????????????\?????????????????¨?????§?????????????????¨??????????????????????¶?????????????????????\???????????¨?????§??????????????¨?????????
 *         B, C ??¨?????? 10 ???????????????????????\????????????????£??????????????????¨????????????
 * 
 *         Input ?????°?????????????????????????????????????????????????????????????????????????????° N ?????????????????????????????\?????????N
 *         ???????????????????????????????????????????????????????????????????????? 10 ??????????????????????????????????????????????????§?????????????????????
 * 
 *         Output ????????????????????????????????????YES ????????? NO ????????????????????????????????????
 * 
 *         Sample Input 2 3 1 4 2 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1 Output for
 *         the Sample Input YES NO
 *
 */
public class Main{
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for (int i = 0; i < n; i++){
			for(int j = 1; j <= 10; j++){
				ball[j] = in.nextInt();
			}
			System.out.println(solve(ball));
		}
		in.close();
	}
	
	static int kase;
	static int[] ball = new int[15];
	static int[] l = new int[15];
	static int[] r = new int[15];
	private static String solve(int[] ball){
		kase = 0;
		dfs(1, 1, 1);
		return kase == 1 ? "YES" : "NO";
	}
	
	private static void dfs(int i, int j, int k){
		if (i > 10){
			kase = 1;
			return;
		}
		if (kase == 1) return;
		if (ball[i] > l[j-1]){
			l[j] = ball[i];
			dfs(i+1, j+1, k);
		}
		if (ball[i] > r[k-1]){
			r[k] = ball[i];
			dfs(i+1, j, k+1);
		}
	}
	
//	private static String solve(int[] ball){
//	int[] dp = new int[ball.length];
//	
//	int max = 0;
//	for (int i = 0; i < ball.length; i++){
//		dp[i] = 1;
//		for (int j = 0; j < i; j++){
//			if (ball[i] <= ball[j]){
//				dp[i] = Math.max(dp[i], dp[j]+1);
//			}
//			max = Math.max(max, dp[i]);
//		}
//	}
//	return max <= 2 ? "YES":"NO";
//}
}

Measured memory_bytes: 26092
#include<iostream>

#define MAX_N 500000

using namespace std;

typedef long long ll;

#define  rep(i,n) for(int i = 0;i < (n);i++)

ll factorial[MAX_N + 1];//factorial[n] := n! mod p
ll factorial_inverse[MAX_N+1];//factorial_inverse[n] = (n!)^-1 mod p

ll extend_gcd(ll a,ll b,ll &x,ll &y) {
    if(b == 0) {
        x = 1;y = 0;
        return a;
    }
    ll r = a % b;
    ll d = extend_gcd(b,r,y,x);
    y -= (a / b) * x ;

    return d;
}

void precompute_for_combination(ll n,ll p) {//前計算 階乗や階乗の逆限を求めておく
    factorial[0] = factorial[1] = 1;
    for(int i = 2;i <= n;i++) {
        factorial[i] = factorial[i - 1] * i % p;
    }

    ll y;
    extend_gcd(factorial[n],p,factorial_inverse[n],y);

    factorial_inverse[n] %= p;
    if(factorial_inverse[n] < 0)factorial_inverse[n] = p - factorial_inverse[n];

    for(int i = n;i > 0;i--) {
        factorial_inverse[i - 1] = factorial_inverse[i] * i % p; 
    }
}

ll combination(ll n,ll k,ll p) {
    if(n < k || n < 0 || k < 0) return 0;//不正な値
    return factorial[n] % p * factorial_inverse[k] % p * factorial_inverse[n - k] % p;
}
ll N,A,B,K;
int main() {
    cin >> N >> A >> B >> K;
    ll p = 998244353;

    precompute_for_combination(N,p);

    ll ret = 0;
    rep(i,N+1) {
        ll a = i;
        ll b = K - a * A;
        if(b % B)continue;
        b  /= B;
        (ret += combination(N,a,p) * combination(N,b,p) % p) %= p;
    }

    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>

int main(void){
  long int a,b;
  scanf("%ld",&a);
  scanf("%ld",&b);
  if(a==1||b==1){
  	printf("%d",1);
  }else{
  	a=a*b+1;
	a/=2;
	printf("%ld",a);
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int func(int d){
    int rectangle;
    int n = d;
    int total = 0;
    
    while(n < 600){
        rectangle = n*n*d;
        total += rectangle; 
        n += d;
    }
    
    return total;
}


int main (int argc, char const* argv[]){
    int n;
    
    
    while((cin >> n)){
        cout << func(n) << endl;
        
    }
    
    
    return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){ 
    int n, m; cin >> n >> m;
    vector<vector<vector<pii>>> G(n, vector<vector<pii>>(3));
    rep(i, m){
        int u, v; cin >> u >> v; u--, v--;
        rep(i, 3){
            int from = i, to = (from+1)%3;//第二ノードの決定
            G[u][from].push_back({v, to});
        }
    }
    int s, t; cin >> s >> t; s--, t--;
    queue<pii> que; que.push({s, 0});
    vector<vector<int>> cost(n, vector<int>(3, INF));
    cost[s][0] = 0;
    while(!que.empty()){
        auto nd = que.front(); que.pop();
        int v1 = nd.first, v2 = nd.second;
        for(auto e: G[v1][v2]){
            int nv1 = e.first, nv2 = e.second;
            if(cost[nv1][nv2] != INF) continue;
            cost[nv1][nv2] = cost[v1][v2] +1;
            que.push({nv1, nv2});
        }
    }
    ll res = cost[t][0];
    if(res == INF) res = -1; else res /= 3;
    cout << res << ln;
}

Measured memory_bytes: 25216
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int line = sc.nextInt();
		int line2 = sc.nextInt();
      	int ans = 0;
      if(line == 1){
        if(line2 == 2){
          ans = 3;
        }else{
          ans = 2;
        }
      }
      if(line == 2){
        if(line2 == 1){
          ans = 3;
        }else{
          ans = 1;
        }
      }
      if(line == 3){
        if(line2 == 1){
          ans = 2;
        }else{
          ans = 1;
        }
      }
      System.out.println(ans);
    }
}

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

int main()
{
  int x1,x2,x3,x4,x5;
  cin>>x1>>x2>>x3>>x4>>x5;
  if(x1 == 0)
    cout<<1;
  else if(x2 == 0)
   	cout<<2;
  else if(x3 == 0)
    cout<<3;
  else if(x4 == 0)
    cout<<4;
  else
    cout<<5;
}


Measured memory_bytes: 3564
#include <set>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
#define X first
#define Y second

const int MAX = 1<<17;

set <P> S;
int n, q;
ll rje[MAX];

void upd(ll x, ll kol) {
  if (!kol) return;
  auto it = S.lower_bound({x, -1});
  if (it != S.end() && it->X == x) {
    P nov = {x, it->Y + kol};
    S.erase(it);
    S.insert(nov);
  }
  else
    S.insert({x, kol});
}

int main()
{
  scanf("%d%d", &n, &q);
  vector <ll> V = {n};
  
  REP(i, q) {
    ll x;
    scanf("%lld", &x);
    V.push_back(x);
  }

  reverse(V.begin(), V.end());

  S.insert({V[0], 1});
  
  FOR(i, 1, (int) V.size()) {
    ll tmp = V[i];
    for (; !S.empty() && (--S.end())->X > tmp; ) {
      auto it = --S.end();
      upd(tmp, it->Y * (it->X / tmp));
      if (it->X % tmp)
	upd(it->X % tmp, it->Y);
      S.erase(it);
    }
  }

  for (auto it : S) {
    rje[0] += it.Y;
    rje[it.X] -= it.Y;
  }

  REP(i, n) {
    if (i) rje[i] += rje[i-1];
    printf("%lld\n", rje[i]);
  }

  return 0;
}


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

long long N, K;
long long LR, RL;
string S;

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

	for(long long i = 0; i < S.size() - 1; i++){
		if(S[i] == 'L' && S[i + 1] == 'R'){
			LR++;
		} else if(S[i] == 'L' && S[i + 1] == 'R'){
			RL++;
		}
	}

	long long sumi = 0;
	for(long long i = 0; i < S.size() - 1; i++){
		if(S[i] == 'R' && S[i+1] == 'R'){
			sumi++;
		}
	}
	for(long long i = 1; i < S.size(); i++){
		if(S[i-1] == 'L' && S[i] == 'L'){
			sumi++;
		}
	}

	sumi+= 2*K;
	cout << min(sumi, (long long)S.size() - 1) << endl;
}


Measured memory_bytes: 512
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())
#define PI 2 * acos(0)

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int A, B;
    cin >> A >> B;
    for(int i=1;i<=1000;i++)
    {
        if((int)(i*0.08)==A && (int)(i*0.1)==B) 
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}



Measured memory_bytes: 3664
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
 
#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif
 
using namespace std;

const int MOD=998244353;
int D[301][90001], P2[300];

long long fast_pow(long long a, long long b)
{
	long long ret=1;
	for(;b;b>>=1) {
		if(b&1) ret=(ret*a)%MOD;
		a=(a*a)%MOD;
	}
	return ret;
}

long long mod(long long a)
{
	if(a>=0) return a%MOD;
	return ((-a/MOD+1)*MOD+a)%MOD;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, ans, sum=0;
	cin>>N;
	ans=(4LL*MOD+fast_pow(3,N)-3*fast_pow(2,N)+3)%MOD;
	D[0][0]=1;
	for(int i=0;i<N;i++) {
		int a;
		cin>>a; sum+=a;
		for(int j=i;j>=0;j--) {
			for(int k=sum-a;k>=0;k--) {
				if(D[j][k]==0) continue;
				D[j+1][k+a]=(D[j+1][k+a]+D[j][k])%MOD;
			}
		}
	}
	P2[0]=1;
	for(int i=1;i<=N;i++) P2[i]=(2*P2[i-1])%MOD;
	for(int i=1;i<N-1;i++) {
		for(int j=(sum+1)/2;j<sum;j++) {
			if(D[i][j]==0) continue;
			ans=mod(ans-3LL*D[i][j]*(P2[N-i]-2));
		}
	}
	cout<<ans<<'\n';
	return 0;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n + k);
	for (int i = 0; i < n; i++) cin >> h[i];

	const long long INF = 1LL << 60;
	vector<long long> dp(n + k);
	for (int i = 0; i < dp.size(); i++) dp[i] = INF;
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
		}
	}
	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1408
n=int(input())
A=list(map(int,input().split()))
A=list(map(lambda x:x//400 if x//400<=7 else 8 ,A))
target=A.count(8)
total=len(set(A))
min=total-1 if 8 in A else total
print(min if min!=0 else 1,min+target)

Measured memory_bytes: 3060
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop,heapify
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

from itertools import accumulate
from functools import lru_cache

M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
 
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]



n = val()
h = li()
v = li()

class Node:
    def __init__(self,s,e):
        self.start=s
        self.end=e
        self.val = 0
        self.left=None
        self.right=None
 
def build(nums,l,r):
    if l == r:
        temp = Node(l,l)
        temp.val = nums[l]
    else:
        mid=(l+r)>>1
        temp=Node(l,r)
        temp.left=build(nums,l,mid)
        temp.right=build(nums,mid+1,r)
        temp.val = max(temp.left.val,temp.right.val)
    return temp

def update(root,start,value):
    if root.start == start == root.end:
        root.val = value
    elif root.start <= start and root.end >= start:
        update(root.left,start,value)
        update(root.right,start,value)
        root.val = max(root.left.val,root.right.val)





def query(root,start,end):
    if root.start>=start and root.end<=end:return root.val
    elif root.start>end or root.end<start:return -float('inf')
    else:
        temp1 = query(root.left,start,end)
        temp2 = query(root.right,start,end)
        return max(temp1,temp2)
        


ans = 0

root = build([0] * (n + 1), 0, n)
for i in range(n):
    curr = query(root, 0, h[i] - 1)
    ans = max(ans, curr + v[i])
    update(root, h[i], curr + v[i])

print(ans)

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

typedef long long int ll;



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

	ll i,j,t,k,l,m,n,x,y,z,a,b,c;

	cin >> k;

	if(k%2 == 0)
	{
		cout << -1 << '\n';
		return 0;
	}

	l = 7%k;

	i = 1;



	while(l!=0)
	{
		// cout << l << '\n';
		l = ((l*10)%k+7%k)%k;
		i++;

		if(i>1000005)
			break;

	}
	if(i<=1000000)
	cout << i << '\n';
	else
		cout << -1 << '\n';


	

}

Measured memory_bytes: 3648
N=int(input())
l1=list(map(int,input().split()))
l=[0]*N
l[1]=abs(l1[1]-l1[0])
for i in range(2,N):
  l[i]=min(l[i-1]+abs(l1[i]-l1[i-1]),l[i-2]+abs(l1[i]-l1[i-2]))
print(l[N-1])

Measured memory_bytes: 13980
n=int(input())
l=[]
for i in range(n):
  l.append(int(input()))
count=0
for i in range(n-1):
  if l[i]%2==1 and l[i+1]>0:
    count+=1
    l[i]=l[i]-1
    l[i+1]=l[i+1]-1
for i in range(n):
  count+=l[i]//2
print(count)

Measured memory_bytes: 7072
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BChristmasEveEve solver = new BChristmasEveEve();
        solver.solve(1, in, out);
        out.close();
    }

    static class BChristmasEveEve {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long max = 0;
            long answer = 0;
            for (int i = 0; i < n; i++) {
                long p = in.nextInt();
                max = Math.max(p, max);
                answer += p;
            }

            answer -= max / 2;

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22868
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<vector<int> >all;

void display(int a[], int n) 
{ 
   vector<int>temp;
    for (int i = 0; i < n; i++) { 
       temp.push_back(a[i]);
      //   cout << a[i] << "  "; 
    } 
    all.push_back(temp);
   //  cout << endl; 
} 
  
// Function to find the permutations 
void findPermutations(int a[], int n) 
{ 
  
    // Sort the given array 
    sort(a, a + n); 
  
    // Find all possible permutations 
   //  cout << "Possible permutations are:\n"; 
    do { 
        display(a, n); 
    } while (next_permutation(a, a + n)); 
} 
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   int n;
   cin>>n;
   int p1[n],p2[n];
   for(int i=0;i<n;i++)
      cin>>p1[i];

   for(int i=0;i<n;i++)
      cin>>p2[i];

   int a[n];
   for(int i=0;i<n;i++)
      a[i]=i+1;
   findPermutations(a,n);
   sort(all.begin(),all.end());
   int ind1,ind2;
   for(int i=0;i<all.size();i++)
   {
      bool flag=true;
      for(int j=0;j<n;j++)
      {
         if(p1[j]!=all[i][j])
            flag=false;
      }
      if(flag)
         ind1=i;
   }   
   for(int i=0;i<all.size();i++)
   {
      bool flag=true;
      for(int j=0;j<n;j++)
      {
         if(p2[j]!=all[i][j])
            flag=false;
      }
      if(flag)
         ind2=i;
   }   
   cout<<abs(ind1-ind2);
// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Measured memory_bytes: 4408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

const int N = 3;


bool rec(int y, int x, int p, string &str){
	static char data[3][3] = {{'A', 'B', 'C'},
														{'D', 'E', 'F'},
														{'G', 'H', 'I'}};
	static int dy[4] = {-1, 0, 1, 0};
	static int dx[4] = {0, 1, 0, -1};
	if(p == str.size()) return true;
	for(int i=0;i<4;i++){
		int ny = y + dy[i];
		int nx = x + dx[i];
		if(min(ny, nx) < 0 || max(ny, nx) >= N) continue;
		if(data[ny][nx] != str[p]) continue;
		if(rec(ny, nx, p + 1, str)) return true;
	}
	return false;
}

int main(){
	for(int i=0;i<1000;i++){
		string str;
		cin >> str;
		if(rec((str[0]-'A')/3, (str[0]-'A')%3, 1, str)) cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
 
typedef long long ll;
 
using namespace std;
 
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORd(i,a,b) for(int i=a;i>=b;i--)
#define II pair <int,int>
#define fi first
#define se second
 
const int maxn=1e5+10;
const ll maxN=1e18+10;
const int MOD=1e9;
 
bool cmp(II a, II b)
{
    return a.se<b.se;
}
 
int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
    int n;
    cin >> n;
    map <string,int> mang;
    set <string> luu;
    int lmax=0;
    FOR(i,1,n) {
        string x;
        cin >> x;
        mang[x]++; luu.insert(x);
        if (lmax<mang[x]) lmax=mang[x];
    }
  
  
  
    for (auto i=luu.begin();i!=luu.end();i++)
        if (mang[*i]==lmax) cout << *i << endl;
  
  
  
}

Measured memory_bytes: 33280
def bg_len(n)
  if n == 0
    1
  else
    3 + bg_len(n - 1) * 2
  end
end

def bg_p(n)
  if n == 0
    1
  else
    1 + bg_p(n - 1) * 2
  end
end

def bg_ans(n, x)
  if x == 0
    0
  elsif x == 1
    n == 0 ? 1 : 0
  elsif n == 0
    1
  else
    x -= 1
    l = bg_len(n - 1)

    if x < l
      bg_ans(n - 1, x)
    elsif x == l
      bg_p(n - 1)
    elsif x == (l + 1)
      bg_p(n - 1) + 1
    else
      p = bg_p(n - 1) + 1
      p + bg_ans(n - 1, x - l - 1)
    end
  end
end

n, x = gets.chomp.split(" ").map(&:to_i)

puts bg_ans(n, x)


Measured memory_bytes: 1916
y,m,d=map(int, input().split('/'))


heisei = False
heisei = heisei or y < 2019
heisei = heisei or y == 2019 and m < 4
heisei = heisei or y == 2019 and m == 4 and d <= 30

print("Heisei" if heisei else "TBD")


Measured memory_bytes: 2940
#define ll long long
#define lld long double
#define cn(n)  ll n;cin >> n;
#define tes(t) ll t;cin>>t;while(t--) 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define al(v) v.begin(), v.end()
#define oset(X) tree<X, null_type, less<X>, rb_tree_tag, tree_order_statistics_node_update>
#define roset(X) tree<X, null_type, greater<X>, rb_tree_tag, tree_order_statistics_node_update>
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const ll MOD2 = 998244353;
const long double PI = 3.141592653589793;
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
ll power(ll x, ll y, ll p){ll res = 1;x %= p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}
ll po(ll base, ll powerRaised){if (powerRaised != 0)return (base * po(base, powerRaised - 1));else return 1;}
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
ll lcm(ll a, ll b){return (a * b) / gcd(a, b);}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
// #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif //*
  int n;
  cin>>n;
  vector<int>v;
  rep(i,0,n-1)
  {
    ll x;
    cin>>x;
    v.pb(x);
  }
  ll ans=0;
  sort(al(v));
  rep(i,0,n-2)
  {
    rep(j,i+1,n-1)
    {
      if(v[i]==v[j])
      continue;
      ll sum=v[i]+v[j];
      int itr=lower_bound(al(v),sum)-v.begin();
      int pos2=upper_bound(al(v),v[j])-v.begin();
      // cout<<itr-j-1<<" ";
      ans+=(itr-pos2);
    }
  }
  cout<<ans;
  
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int s=0;
  c+=0.5;
  for(int i=1;i<=10000000;i++)
  {
    if(c>=a)
    {
      s+=b;
      c-=a;
    }
    else
      break;
  }
  cout<<s;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  // input
  int n; cin >> n;
  vector<int> x(8);


  // compute
  int ans;
  for(int i = 0;i < 8; i++) x[i] = pow(2,i); 
  
  if(n == 1) ans = 1;

  for(int i = 1;i < 8; i++){
    if(n < x[i]){
        ans = x[i-1];
        break;
    }
  }
  
  // output  
  cout << ans << endl;
  
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";



// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, ll v) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
    // 頂点数と辺数
    ll N, M; cin >> N >> M;

    // グラフ入力受取
    Graph G(N);
    for (ll i = 0; i < M; ++i) {
        ll a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // 全頂点が訪問済みになるまで探索
    ll count = 0;
    seen.assign(N, false);
    for (ll v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(G, v); // v が未探索なら v を始点とした DFS を行う
        ++count;
    }
    cout << count-1 << endl;
}

Measured memory_bytes: 9544
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)
#define INF 1e9
typedef long long LL;
const LL mod = 1e9+7;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  string answer;
  if (A+B >= C) { answer = "Yes"; }
  else { answer = "No"; }
  cout << answer << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;

int n,dx,dy,hx,hy;
bool done[20];
int cx[20],cy[20];

double calc(int x1,int y1,int x2,int y2){
	return sqrt((double)(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

bool dfs(int x,int y,double time,int k){
	if(time>=calc(x,y,dx,dy)) return false;
	if(k==n) return true;

	for(int i=0;i<n;i++){
		if(done[i]) continue;
		if(time+calc(x,y,cx[i],cy[i])>=calc(cx[i],cy[i],dx,dy)) return false;
	}

	for(int i=0;i<n;i++){
		if(done[i]) continue;
		if(dfs(cx[i],cy[i],time+calc(cx[i],cy[i],x,y),k+1)) return true;
	}
	return false;
}

int main()
{
	while(cin>>n>>hx>>hy>>dx>>dy && n!=0){
		for(int i=0;i<n;i++)
			cin>>cx[i]>>cy[i];
		memset(done,false,sizeof(done));
		if(dfs(hx,hy,0.0,0)) cout<<"YES\n";
		else cout<<"NO\n";

	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
{
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    int s=0,d=0;
    int p,sum=0;
    if(1<=n<=10000 && 1<=k<=10000 && 1<=y && y<x<=10000)
    {
    if(n<=k){
       printf("%d\n",n*x);
    }
    else if(n>k){
       p=n-k;
       s=k*x;
       d=p*y;
       sum=s+d;
       printf("%d\n",sum);
    }
    }
    return 0;
}


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

int main() {
int n;
cin>>n;
int a[n];
for (int i = 0; i < n; ++i) {
	cin>>a[i];
}
int minv=1000000001,maxv=-1000000002;

minv = a[0];
for (int j = 1; j < n; ++j) {
	  maxv = max(maxv,a[j]-minv);
	  minv = min(minv,a[j]);
}
cout<<maxv<<endl;
}

Measured memory_bytes: 3848
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    bool AB = false;
    long ans = 0;
    if(A+B > 2*C){
        AB = true;
    }
    int numAB = min(X,Y);
    if(AB){
        ans += numAB * 2 *C;
        X -= numAB;
        Y -= numAB;
        if(X == 0){
            if(B > 2*C){
                ans += Y * 2 *C;
            }else{
                ans += Y * B;
            }
        }else{
            if (A > 2*C){
                ans += X * 2 *C;
            }else{
                ans += X*A;
            }
        }
    }else {
        ans += X*A + Y*B;
    }
    cout << ans << endl;
    return 0;
}

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

int partition(int*,int,int);

int main(){
  int *A;
  int n, i, r;

  //input
  
  scanf("%d", &n);

  A = malloc(sizeof(int)*n);

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

  //main

  r = partition(A,0,n-1);
  
  //output
  
  for(i = 0; i < n-1; i++){
    if(i == r){
      printf("[%d] ",A[i]);
    }
    else printf("%d ",A[i]);
  }

  if(i == r){
      printf("[%d]\n",A[i]);
    }
  else printf("%d\n",A[i]);
 
  free(A);
  
  return 0;
}

int partition(int *A,int p,int r){
  int i, j, temp;
  int x = A[r];
  i = p-1;

  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;

  return (i + 1);
}
  




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

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        int N;
        long K;
        {long[] a = in.ll(); N = (int)a[0]; K = a[1];}
        int[] A = in.ii();
        int[] F = in.ii();
        Arrays.sort(A);
        Arrays.sort(F);
        
        long l = 0;
        long r = 1000000000000L;
        while(l < r){
            long m = (l+r)/2;
            long c = 0;
            for(int i = 0; i < N; i++){
                c += Math.max(A[N-1-i] - m/F[i], 0);
            }
            if(c <= K){
                r = m;
            } else {
                l = m+1;
            }
        }
        out.println(r);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 57968
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,ans=0;
  cin>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  sort(ALL(A));
  vi B;
  if(N%2==0){
    B.push_back(A[N/2]);
    rep(i,0,N/2-1){
      B.push_back(A[i]);
      B.push_back(A[N-1-i]);
      }
    B.push_back(A[N/2-1]);
  }
  else{
    if(A[N/2]-A[N/2-1]>A[N/2+1]-A[N/2]){
      B.push_back(A[N/2+1]);
      rep(i,0,N/2-1){
         B.push_back(A[i]);
         B.push_back(A[N-1-i]);
        }
      B.push_back(A[N/2-1]);
      B.push_back(A[N/2]);
      }
    else{
      B.push_back(A[N/2]);
      rep(i,0,N/2-1){
         B.push_back(A[i]);
         B.push_back(A[N-1-i]);
        }
      B.push_back(A[N/2+1]);
      B.push_back(A[N/2-1]);
      }
    }
  vi C;
  rep(i,1,N){
    ans+=abs(B[i]-B[i-1]);
    }
  if(N%2==0){
    C.push_back(A[N/2-1]);
    rep(i,0,N/2-1){
      C.push_back(A[N-1-i]);
      C.push_back(A[i]);
      }
    C.push_back(A[N/2]);
  }
  else{
    if(A[N/2]-A[N/2-1]>A[N/2+1]-A[N/2]){
      C.push_back(A[N/2]);
      rep(i,0,N/2-1){
         C.push_back(A[N-1-i]);
         C.push_back(A[i]);
        }
      C.push_back(A[N/2-1]);
      C.push_back(A[N/2+1]);
      }
    else{
      C.push_back(A[N/2-1]);
      rep(i,0,N/2-1){
         C.push_back(A[N-1-i]);
         C.push_back(A[i]);
        }
      C.push_back(A[N/2+1]);
      C.push_back(A[N/2]);
      }
    }
  int sum=0;
  rep(i,1,N){
    sum+=abs(C[i]-C[i-1]);
    }
  ans=max(sum,ans);
  cout<<ans<<endl;
  }




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

int n, q;

struct Node {
  int min = 0x7fffffff, lazy = -1;
} seg[800005];

void update(int u, int l, int r, int ql, int qr, int v) {
  if (seg[u].lazy != -1) {
    seg[u << 1].lazy =
      seg[u << 1 | 1].lazy =
      seg[u].lazy;
    seg[u].lazy = -1;
  }

  if (l == ql && r == qr) {
    seg[u].lazy = v;
    return;
  }

  int m = (l + r) >> 1;

  if (qr <= m)
    update(u << 1, l, m, ql, qr, v);
  else if (ql > m)
    update(u << 1 | 1, m + 1, r, ql, qr, v);
  else
    update(u << 1, l, m, ql, m, v), update(u << 1 | 1, m + 1, r, m + 1, qr, v);
  
  int lm = seg[u << 1].lazy != -1 ? seg[u << 1].lazy : seg[u << 1].min;
  int rm = seg[u << 1 | 1].lazy != -1 ? seg[u << 1 | 1].lazy : seg[u << 1 | 1].min;

  seg[u].min = min(lm, rm);
}

int query(int u, int l, int r, int ql, int qr) {
  if (seg[u].lazy != -1)
    return seg[u].lazy;

  if (l == ql && r == qr)
    return seg[u].min;  

  int m = (l + r) >> 1;
  if (qr <= m)
    return query(u << 1, l, m, ql, qr);
  else if (ql > m)
    return query(u << 1 | 1, m + 1, r, ql, qr);
  else
    return min(query(u << 1, l, m, ql, m),
        query(u << 1 | 1, m + 1, r, m + 1, qr));
}

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

  for (int i = 0; i < q; i++) {
    int o; cin >> o;
    if (o == 0) {
      // update
      int l, r, v; cin >> l >> r >> v;
      update(1, 0, n - 1, l, r, v);
    } else {
      int l, r; cin >> l >> r;
      cout << query(1, 0, n - 1, l, r) << endl;
    }
  }
}



Measured memory_bytes: 7216
from collections import *
r = set()
c = defaultdict(int)
n, m = map(int, input().split())
 
for _ in range(m):
  l = input().split()
  i = int(l[0])
  if l[1] == 'AC':
    r.add(i)
  elif i not in r:
    c[i] += 1
 
print(len(r), sum(v for k, v in c.items() if k in r))

Measured memory_bytes: 12268
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;
ll a[100000];
int main() {
	int n;
	cin>>n;
	ll min=10000000;
	for(ll i=0; i<n; i++) {
		cin>>a[i];
	}
	int flag=1;
	for(int i=n-1;i>0;i--){
		if(a[i-1]>a[i]){
			a[i-1]--;
		}
	}
	for(ll i=1;i<n;i++){
		if(a[i-1]>a[i]){
			flag=0;
		}
	}
	if(flag==1){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024