akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

//最小公倍数
lint GCD(lint a, lint b)
{
	if (a == 0)
		return b;

	if (b == 0)
		return a;
	if (a < b)
		swap(a, b);

	for (;;)
	{
		lint m = a % b;
		if (m == 0)
			return b;
		a = b;
		b = m;
	}
}

void execute()
{
	int N;
	cin >> N;

	vector<int> data(N);
	vector<int> cum_left(N + 1);
	vector<int> cum_right(N + 1);

	cum_left[0] = 0;
	cum_right[0] = 0;

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

	for (int i = 0; i < N; i++)
	{
		cum_left[i + 1] = GCD(cum_left[i], data[i]);
		cum_right[i + 1] = GCD(cum_right[i], data[N - i - 1]);
	}

	lint ans = 1;

	for (int i = 0; i < N; i++)
	{
		ans = max(ans, GCD(cum_left[i], cum_right[N - 1 - i]));
	}

	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 1408
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int pieces = cin.nextInt();
    int num = cin.nextInt();

    if (pieces >= num) {
      System.out.println(0);
      return;
    }

    int[] pos = new int[num];

    for (int i=0;i<num;i++) {
      pos[i] = cin.nextInt();
    }

    Arrays.sort(pos);
    int[] div = new int[num-1];
    for (int i=0;i<div.length;i++) {
      div[i] = pos[i+1]-pos[i];
    }
    Arrays.sort(div);
    int sum = pos[pos.length-1] - pos[0];
    for (int i=0;i<pieces-1;i++) {
      sum-=div[div.length-1-i];
    }
    System.out.println(sum);
//    Arrays.sort(div, (o1, o2) -> o1.val-o2.val);
//    Arrays.sort(div, Comparator.comparingInt(o -> o.val));
//    int count = 0;
//    while (count < pieces) {
//      int divPos = div[div.length-1-count].index;
//
//    }


  }

}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    if((n-k)%(k-1)==0)
        cout << ((n-k)/(k-1))+1 << endl;
    else{
        cout << ((n-k)/(k-1))+2 << endl;
    }

}

Measured memory_bytes: 3700
N=gets.to_i

arr = Array.new(N+1,0)
1.upto(100) do |x|
    1.upto(100) do |y|
        1.upto(100) do |z|
            n = x*x + y*y + z*z + x*y + y*z + z*x
            arr[n] += 1 if n <= N
        end
    end
end

puts arr[1..-1]

Measured memory_bytes: 14308
/* This code is written by Nemlit */
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)
#define drep(i, a, b) for(re int i = (b); i >= (a); -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define int long long
#define D double
#define inf 1023456789
#define mod 1000000007
#define lb(x) (x)&(-(x))
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
#define ls k * 2
#define rs k * 2 + 1
#define maxn 200005
namespace Graph {
	int head[maxn], cnt;
	struct edge { int v, next; }e[maxn << 1];
	il void add(int u, int v) { e[++ cnt] = (edge){v, head[u]}, head[u] = cnt; }
}
//using namespace Graph;
int n, m;
string c[maxn];
map<string, int>a;
signed main() {
	n = read();
	rep(i, 1, n) {
		cin >> c[i];
		if(a[c[i]] == 0) ++ m, a[c[i]] = 1;
	}
	cout << m;
	return 0;
}


Measured memory_bytes: 25476
s=input()
c=0
m=0
flg=False
for x in s:
    if x=="R" and flg:c+=1;m=max(m,c)
    if x=="R" and not flg:
        flg=True
        c=1
        m=max(m,c)
    if x=="S":
        flg=False
        c=0
print(m)

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int n, m;
	cin >> n >> m;
	int ans = ((n - m) * 100 + m * 1900) * pow(2, m);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,i,max,min;
    long long sum=0;
    int a[100000];
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i];
        sum=sum+a[i];
        if(i==1){
            max=a[i];
            min=a[i];
        }
        else{
            if(max<a[i]){
                max=a[i];
            }
            if(min>a[i]){
                min=a[i];
            }
        }
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
}


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

int main(){
  string s="";
  long long cnt=0;
  cin>>s;
  for (int i=0;i<s.size();i++)  {
    if(s[i]=='?') s[i]='D';
    if(s[i]=='D'){
      cnt++;
      if(s[i-1]=='P') cnt++;
    }
  }
  cout<<s;
  //cout<<cnt<<endl;
  
  
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A , B , C , D;
  cin >> A >> B >> C >> D;
  int E = A + B;
  int F = C + D;
  if (E == F){
    cout << "Balanced" << endl;
  }
  if (E < F){
    cout << "Right" << endl;
  }
  if (E > F){
    cout << "Left" << endl;;
  }
}

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

#define MAXN 100010

using namespace std;

class Union_Find {
public:
	Union_Find(int n = 0) : d(n, -1) {}

	int find(int x)
	{
		if (d[x] < 0) return x;
		return d[x] = find(d[x]);
	}

	bool unite(int x, int y)
	{
		x = find(x); y = find(y);
		if (x == y) return false;
		if (-d[x] < -d[y]) swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}

	int size(int x)
	{
		return -d[find(x)];
	}

private:
	vector<int> d;
};

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

	Union_Find uf(n);
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		
		uf.unite(x, y);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (uf.same(i, a[i])) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <cstdio>
#define maxn 100005
using namespace std;
int n,k;
int a[maxn];
int gcd(int a,int b){
	if(a == 0) return b;
	return gcd(b%a,a);
}
int x;
int main(){
	//freopen("main.in","r",stdin);
	scanf(" %d%d",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf(" %d",&a[i]);
	}
	x = a[1];
	for(int i = 2; i <= n; i++){
		x = gcd(x,a[i]);
	}
	for(int i = 1; i <= n; i++){
		if(a[i] >= k && (a[i] - k) % x == 0){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <math.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    REP(i, s.length()) {
        if (s[i] == t[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int H, W;
  cin >> H >> W;
  
  vector<string> S(H);
  for (int i = 0; i < H; i++){
    cin >> S.at(i);
  }
  
  vector<vector<int>> dp(120, vector<int>(120, 0));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (i == 0 && j == 0){
        if (S.at(0).at(0) == '#'){
          dp.at(0).at(0) = 1;
        }
        else{
          dp.at(0).at(0) = 0;
        }
      }
      else if (i == 0){
        if (S.at(0).at(j) == '#' && S.at(0).at(j - 1) == '.'){
          dp.at(0).at(j) = dp.at(0).at(j - 1) + 1;
        }
        else{
          dp.at(0).at(j) = dp.at(0).at(j - 1);
        }
      }
      else if (j == 0){
        if (S.at(i).at(0) == '#' && S.at(i - 1).at(0) == '.'){
          dp.at(i).at(0) = dp.at(i - 1).at(0) + 1;
        }
        else{
          dp.at(i).at(0) = dp.at(i - 1).at(0);
        }
      }
      else{
        int down = 0, right = 0;
        if (S.at(i).at(j) == '#' && S.at(i).at(j - 1) == '.'){
          right = 1;
        }
        
        if (S.at(i).at(j) == '#' && S.at(i - 1).at(j) == '.'){
          down = 1;
        }
            
        dp.at(i).at(j) = min(dp.at(i).at(j - 1) + right, dp.at(i - 1).at(j) + down);
      }
    }
  }
            
  /*for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cout << dp.at(i).at(j) << ' ';
    }
    cout << endl;
  }*/
  cout << dp.at(H - 1).at(W - 1) << endl;
}

Measured memory_bytes: 3708
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int H, W;
    cin >> H >> W;
    rep(i, H) rep(j, W) {
        string s;
        cin >> s;
        if(s == "snuke"){
            cout << (char)('A' + j) << i + 1 << endl;
        }
    }
    
    
    
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s.at(2)==s.at(3)&&s.at(4)==s.at(5))
  cout << "Yes";
  else
  cout << "No";
  return 0;
}


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

int h, w;

int used[400][400];

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

void dfs(int x, int y) {
	used[x][y] = 1;
	for (int i = 0; i < 4; i++) {
		int tx = x + dx[i], ty = y + dy[i];
		if (0 <= tx && tx < h && 0 <= ty && ty < w && !used[tx][ty]) {
			dfs(tx, ty);
		}
	}
}

int main()
{
	int n;
	while (cin >> n, n) {
		vector<int> a(n), b(n), c(n), d(n), xs, ys;
		for (int i = 0; i < n; i++) {
			cin >> a[i] >> b[i] >> c[i] >> d[i];
			if (a[i] > c[i]) swap(a[i], c[i]);
			if (b[i] > d[i]) swap(b[i], d[i]);
			a[i] *= 2;
			b[i] *= 2;
			c[i] *= 2;
			d[i] *= 2;
			for (int x = -1; x <= 1; x++) {
				xs.push_back(a[i] + x);
			}
			for (int x = -1; x <= 1; x++) {
				ys.push_back(b[i] + x);
			}
			for (int x = -1; x <= 1; x++) {
				xs.push_back(c[i] + x);
			}
			for (int x = -1; x <= 1; x++) {
				ys.push_back(d[i] + x);
			}
		}
		sort(xs.begin(), xs.end());
		xs.erase(unique(xs.begin(), xs.end()), xs.end());
		sort(ys.begin(), ys.end());
		ys.erase(unique(ys.begin(), ys.end()), ys.end());
		h = xs.size();
		w = ys.size();
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				used[i][j] = 0;
			}
		}
		for (int i = 0; i < n; i++) {
			a[i] = lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin();
			b[i] = lower_bound(ys.begin(), ys.end(), b[i]) - ys.begin();
			c[i] = lower_bound(xs.begin(), xs.end(), c[i]) - xs.begin();
			d[i] = lower_bound(ys.begin(), ys.end(), d[i]) - ys.begin();
			for (int y = b[i]; y <= d[i]; y++) {
				used[a[i]][y] = 1;
			}
			for (int x = a[i]; x <= c[i]; x++) {
				used[x][b[i]] = 1;
			}
			for (int y = b[i]; y <= d[i]; y++) {
				used[c[i]][y] = 1;
			}
			for (int x = a[i]; x <= c[i]; x++) {
				used[x][d[i]] = 1;
			}
		}
		int res = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (!used[i][j]) {
					++res;
					dfs(i, j);
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 5168
import numpy as np

x,y=map(int, input().split())

a = np.array([[2, 4], [1, 1]])
b = np.array([y, x])
ans = np.linalg.solve(a, b)
if ans[0] >= 0 and ans[0].is_integer() == True and ans[1] >= 0 and ans[1].is_integer() == True:
    print("Yes")
else:
    print("No")


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

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

void solve()
{
    int d, n;
    cin >> d >> n;
    int div = -1;
    if (d == 0)
        div = 1;
    else if (d == 1)
        div = 100;
    else if (d == 2)
        div = 10000;
    int cnt = 0;
    for (int i = div;; i += div)
    {
        if (i == 100 * div)
            continue;
        if (i % div == 0)
            cnt++;
        if (cnt >= n)
        {
            cout << i << endl;
            return;
        }
    }
}

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

int main()
{
    // srand((unsigned)time(NULL));
    // int bt = clock();
    solve();
    // double et = 1.0 * (clock() - bt) / CLOCKS_PER_SEC;
    // printf("Execution Time: %.4lf sec\n", et);
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <bitset>
#include <cmath>

#define ll long long
#define repp(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define repm(i,a,b) for(int i=(int)(a);i>(int)(b);--i)

using namespace std;

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

    map<string, int> counter;
    ll ans = 0;
    repp(i,0,N) {
        string s; cin >> s;
        sort(s.begin(), s.end());
        if (counter.count(s)) {
            ans += counter[s];
            ++counter[s];
        } else {
            counter[s] = 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int find(int x, VI *par) {
    if ((*par)[x] == x) {
        return x;
    }
    return (*par)[x] = find((*par)[x], par);
}

int same(int x, int y, VI *par) {
    return find(x, par) == find(y, par);
}

void unite(int x, int y, VI *par) {
    x = find(x, par);
    y = find(y, par);
    if (x != y) (*par)[x] = y;
}

map<P, int> m;

int main() {
    VI rail(202020), road(202020);
    
    REP(i,202020) {
        rail[i] = i;
        road[i] = i;
    }
    
    int n, k, l;
    cin >> n >> k >> l;
    REP(i,k) {
        int p, q;
        cin >> p >> q;
        unite(p, q, &road);
    }
    REP(j,l) {
        int r, s;
        cin >> r >> s;
        unite(r, s, &rail);
    }
    
    REP(i,202020) {
        find(i, &road);
        find(i, &rail);
    }
    
    REP(i,202020) {
        m[P(road[i],rail[i])]++;
    }
    
    REPI(i,1,n) {
        cout << m[P(road[i],rail[i])] << " ";
    }
    cout << m[P(road[n],rail[n])] << endl;
}



Measured memory_bytes: 16000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Enumerable.Repeat(0, n).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        int[][] costs = Enumerable.Repeat(0, n).Select(_ => Enumerable.Repeat(int.MaxValue / 4, n).ToArray()).ToArray();
        for (int i = 0; i < n; i++)
            costs[i][i] = 0;
        for (int i = 0; i < n; i++)
            for (int j = i - 1; j >= 0; j--)
                for (int k = j; k < i; k++)
                    costs[j][i] = Min(costs[j][i], costs[j][k] + costs[k + 1][i] + a[j][0] * a[i][1] * a[k][1]);         
        Console.WriteLine(costs[0][n - 1]);
    }
}



Measured memory_bytes: 18324
#include <iostream>

const long N = 100;
const long M = 100;
const long L = 100;

int main(void) {
  long n = 0;
  long m = 0;
  long l = 0;

  long a[N][M] = {0};
  long b[M][L] = {0};
  long c[N][L] = {0};

  std::cin >> n >> m >> l;

  for (long i = 0; i < n; i++) {
    for (long j = 0; j < m; j++) {
      std::cin >> a[i][j];
    }
  }

  for (long i = 0; i < m; i++) {
    for (long j = 0; j < l; j++) {
      std::cin >> b[i][j];
    }
  }
  
  for (long i = 0; i < n; i++) {
    for (long j = 0; j < l; j++) {
      for (long k = 0; k < m; k++) {
	c[i][j] += (a[i][k] * b[k][j]);
      }

      std::cout << c[i][j];
      
      if (j < (l - 1)) {
      	std::cout << " ";
      }
    }
    
    std::cout << std::endl;
  }
      
  
  return 0;
}

Measured memory_bytes: 1404
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	void	 solve() {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		ArrayList<P> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			list.add(new P(in.nextInt(), in.nextInt()));
		}
		if(n == 1) {
			System.out.println(list.get(0).a + list.get(0).b);
			return;
		}
		list.sort(new Comparator<P>() {
			public int compare(P p1, P p2){
				return p1.a > p2.a ? 1 : -1;
			}
		});
		long sum = 0;
		int beforeA = 0, beforeB = 0;
		for(int i = 0; i < list.size(); i++) {
			P l = list.get(i);
			if(i == 0) {
				sum += l.a;
			}else if(i == list.size() - 1) {
				sum += Math.min(l.a - beforeA, beforeB - l.b);
				sum += l.b;
			}else {
				sum += Math.min(l.a - beforeA, beforeB - l.b);
				//System.out.println((l.a - beforeA) + ":" + (beforeB - l.b));
				//System.out.println(beforeB);
			}
			beforeA = l.a; beforeB = l.b;
		}
		System.out.println(sum);
	}
	public static void main(String[] args) throws Exception{
		new Main().solve();
	}
}
class P{
	int a, b;
	public P(int a, int b) {
		this.a = a;
		this.b = b;
	}
}

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


int main() {
    //input
    int n;
    std::cin >> n;

    string str;
    int a[n],b[n];
    for (int i = 0; i < n+1; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    //
    long long count = 0;
    for (int i = 0; i < n; i++) {
        if(a[i] >= b[i]){
            count += b[i];
            //a[i] -= b[i];
        }else{
            count += a[i];
            b[i] -= a[i];
            if(a[i+1] >= b[i]){
                count += b[i];
                a[i+1] -= b[i];
            }else{
                count += a[i+1];
                a[i+1] = 0;
                //b[i] -= a[i+1];
            }

        }
    }

    cout <<  count;
    //std::cout << ans << std::endl;
    //for (int i=0;i<n;i++){
    //    std::cout << vec.at(i) << std::endl;
    //}


    return 0;
}

Measured memory_bytes: 1024
/*
[abc116] B - Collatz Problem
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int s;
map<int, int> m;

ll solve() {
    m[s] = 1;
    int a = s;
    for (int i = 2; i <= 1000000; i++) {
        a = (a % 2 == 0) ? a / 2 : 3 * a + 1;
        if (m[a] > 0) {
            return i;
        }
        m[a] = i;
    }
    return -1;
}

int main() {
    cin >> s;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int N,sn=0,t;
  cin >> N;
  t=N;
  while(t!=0){
    sn += t%10;
    t /= 10;
  }
  if(N%sn==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
Y1 = Y[:N//2]
Y2 = Y[N//2:]
ans1 = Y1[-1]
ans2 = Y2[0]
for i in range(N):
  if X[i] <= ans1:
    print(ans2)
  else:
    print(ans1)
  

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

using namespace std;

int N, p[(1 << 18) + 10], aux[(1 << 18) + 10], l[(1 << 18) + 10], r[(1 << 18) + 10];
vector < int > prv[(1 << 18) + 10], nxt[(1 << 18) + 10], ev[(1 << 18) + 10];

void fail ()
{
    printf ("NO\n");
    exit (0);
}

void solve (int pos, int length)
{
    if (length == 1)
        return ;
    solve (pos, length / 2);
    solve (pos + length / 2, length / 2);
    for (int i=pos; i<pos + length; i++)
        aux[i] = p[i];
    for (int i=pos, j=pos; i<pos + length / 2; i++, j+=2)
        p[j] = aux[i];
    for (int i=pos + length / 2, j=pos + 1; i<pos + length; i++, j+=2)
        p[j] = aux[i];
}

void read ()
{
    scanf ("%d", &N);
    for (int i=0; i<(1 << N); i++)
    {
        scanf ("%d", &p[i]);
        if (p[i] == 0) l[i] = 1, r[i] = 1 << N;
        else l[i] = r[i] = p[i];
    }
}

void buildGraph ()
{
    for (int i=0; i<(1 << N); i++)
        for (int j=0; j<N; j++)
            if ((i & (1 << j)) == 0)
                nxt[i].push_back (i ^ (1 << j)),
                prv[i ^ (1 << j)].push_back (i);
}

void buildLR ()
{
    for (int i=0; i<(1 << N); i++)
        for (auto j : prv[i])
            l[i] = max (l[i], l[j] + 1);
    for (int i=(1 << N) - 1; i>=0; i--)
        for (auto j : nxt[i])
            r[i] = min (r[i], r[j] - 1);
}

void assignValues ()
{
    for (int i=0; i<(1 << N); i++)
        if (l[i] > r[i] || r[i] < 0 || l[i] > (1 << N))
            fail ();
    for (int i=0; i<(1 << N); i++)
        ev[l[i]].push_back (i);
    priority_queue < pair < long long, int > > PQ;
    for (int i=1; i<=(1 << N); i++)
    {
        for (auto j : ev[i])
            PQ.push ({-r[j], j});
        if (PQ.empty ())
            fail ();
        auto curr = PQ.top ();
        PQ.pop ();
        if (-curr.first < i)
            fail ();
        p[curr.second] = i;
    }
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

read ();
buildGraph ();
buildLR ();
assignValues ();
printf ("YES\n");
solve (0, 1 << N);
for (int i=0; i<(1 << N); i++)
    printf ("%d ", p[i]);
printf ("\n");
return 0;
}


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

int main() {
//	cout<<"GfG!";
    string s;
    cin>>s;
    int n = s.length();
    int a =0;
    int b =n-1;
    int cnt=0;
    while(a<b)
    {
        if(s[a]!=s[b])
        {
            cnt++;
        }
        a++;
        b--;
    }
    cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var d int
	fmt.Scan(&d)

	switch d {
	case 22:
		fmt.Println("Christmas Eve Eve Eve")
	case 23:
		fmt.Println("Christmas Eve Eve")
	case 24:
		fmt.Println("Christmas Eve")
	case 25:
		fmt.Println("Christmas")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ri register int
#define fi first
#define se second
using namespace std;
inline int read(){
	#define gc getchar
	bool f=1;
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))f^=ch==gc(),ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return f?ans:-ans;
	#undef gc
}
const int mod=998244353;
typedef long long ll;
inline int add(int a,int b){return (a+=b)<mod?a:a-mod;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline int mul(int a,int b){return (ll)a*b%mod;}
inline void Add(int&a,int b){(a+=b)<mod?a:a-=mod;}
inline void Dec(int&a,int b){(a-=b)<0?a+=mod:a;}
inline void Mul(int&a,int b){a=(ll)a*b%mod;}
inline int ksm(int a,int p){int ret=1;for(;p;p>>=1,Mul(a,a))if(p&1)Mul(ret,a);return ret;}
const int N=2505;
int n,m,P,cnt[N];
vector<int>e[N],val[N];
ll dis[N];
bool ban[N],in[N];
const double eps=1e-7;
inline bool check(double x){
	queue<int>q;
	for(ri i=1;i<=n;++i)in[i]=0,cnt[i]=0,dis[i]=-1e9;
	dis[1]=0,q.push(1);
	while(q.size()){
		int x=q.front();
		q.pop();
		in[x]=0;
		for(ri i=0,v;i<e[x].size();++i){
			if((dis[v=e[x][i]])<dis[x]+val[x][i]){
				if(ban[v])continue;
				dis[v]=dis[x]+val[x][i];
				if(!in[v]){
					in[v]=1;
					++cnt[v];
					if(cnt[v]>=n){
						puts("-1");
						exit(0);
					}
					q.push(v);
				}
			}
		}
	}
	cout<<max(0ll,dis[n]);
}
inline bool dfs(int p){
	if(in[p])return 0;
	if(p==n)return 1;
	in[p]=1;
	for(ri i=0;i<e[p].size();++i)if(dfs(e[p][i]))return 1;
	return 0;
}
int main(){
	n=read(),m=read(),P=read();
	for(ri i=1,u,v,w;i<=m;++i){
		u=read(),v=read(),w=read()-P;
		e[u].push_back(v),val[u].push_back(w);
	}
	for(ri i=1;i<=n;++i){
		memset(in,0,sizeof(in));
		if(!dfs(i))ban[i]=1;
	}
	check(0);
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const ll INF = 1e18;
int N, W;
int w[110], v[110];
map<int, int> dp[110];
int main(){
  cin >> N >> W;
  for (int i = 1; i <= N; i++) {
    cin >> w[i] >> v[i];
  }
  dp[0][0] = 0;
  for (int i = 1; i <= N; i++) {
    for (auto p: dp[i - 1]) {
      if (dp[i][p.first] < p.second)
        dp[i][p.first] = p.second;
      if (p.first + w[i] <= W) {
        if (dp[i][p.first + w[i]] < p.second + v[i]) {
          dp[i][p.first + w[i]] = p.second + v[i];
        }
      }
    }
  }
  int ans = 0;
  for (auto p: dp[N]) {
    ans = max(ans, p.second);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4864
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<bool> A(1100001,true);
    A[0] = A[1] = false;
    for (int i = 2; i*i <= 1100000; i++) {
        if (A[i]) {
            for (int j = 2; j*i <= 1100000; j++) {
                A[i*j] = false; 
            }
        }
    }
    int ans = 0;
    for (int i = N; i <= 1100000; i++) {
        if (A[i]) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
from collections import deque
a=int(input())
list=deque([])

for i in range(a):
    order=input().split()
    if order[0]=="insert":
        list.appendleft(order[1])
    elif order[0]=="delete":
        if order[1] in list:
            list.remove(order[1])
    elif order[0]=="deleteFirst":
        list.popleft()
    elif order[0]=="deleteLast":
        list.pop()

print(*list)


Measured memory_bytes: 69736
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner reader = new Scanner(System.in);
		int a,b,c, temp;
		while(reader.hasNextInt()){
		 a = reader.nextInt();
		 b = reader.nextInt();
		 c = a + b;
		 temp = c;
		 for(int i = 1; i <= 10; i++){
			 temp = temp / 10;
			 if(temp <= 0){
				 System.out.println(i);
				 break;
			 }
		 }
		}
	}
}

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


int main(){
    int n;
    cin >> n;
    vector<int> x(n),y(n);
    rep(i,n) cin >> x[i] >> y[i];
    vector<int> fact(n+1);
    fact[0] = 1;
    rep(i,n) fact[i+1] = fact[i]*(i+1);

    double ans = 0;
    for(int i=0; i<n; i++){
        for(int j= i+1; j<n; j++){
            ans += 2*fact[n-1]*sqrt( ((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j])) );
        }
    }
    printf("%.12lf\n",ans/fact[n]);
    return 0;
}

Measured memory_bytes: 3792
#include <stdio.h>

int main(){
    int data[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;

    scanf("%d",&K);

    printf("%d\n",data[K-1]);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main() {
    int n, a;
    long long int otv = 0;
    long long int sum = 0;
    long long int sq=0;
    cin >> n;
    for (int i=0; i<n; i++){
        cin >> a;
        sum+=a;
        sq += a*a;
    }
    sum = sum*sum;
    otv = (sum - sq)/2;
    cout << otv;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

using namespace std;

int n,a[109];

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


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

using namespace std;

typedef long long ll;
const int N=2e5+100;
int mod=998244353;

ll fac[N],inv[N];
int n,m,k;
ll qpow(ll x,ll n)
{
    //if(x==0) return 0;
    x%=mod;
    ll sum=1;
    while(n){
        if(n&1) sum=sum*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return sum;
}
void init()
{
    fac[0]=1;
    for(int i=1;i<=N-1;i++) fac[i]=fac[i-1]*i%mod;
    inv[N-1]=qpow(fac[N-1],mod-2);
    for(int i=N-2;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
ll get(int x,int y)
{
    return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    init();
    ll ans=0;
    for(int i=0;i<=k;i++)
        ans=(ans+m*get(n-1,i)%mod*qpow(m-1,n-1-i))%mod;
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 6888
#include<bits/stdc++.h>
#define REP(i,n) for(long long i = 0;i < n;++i)
#define FOR(i,a,b) for(long long i = a;i < b;++i)
using namespace std;
using ll = long long;
using point = pair< int,int >;

int main(){
    int a,b;
    scanf("%d%d", &a, &b);
    printf("%s\n", a <= 8 && b <= 8 ? "Yay!" : ":(");
    return 0;
}



Measured memory_bytes: 256
s = input()

for i in range(1,len(s)):
  x = s[:-i]
  if len(x)%2 !=0:
    continue
  else :
    a = x[:len(x)//2]
    b = x[len(x)//2:]
    if a ==b :
      print(len(x))
      exit()
      

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

ans = 'No'
count = 0
for _ in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        count += 1
    else:
        count = 0
    if count == 3:
        ans = 'Yes'
        break

print(ans)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main(){
  int n;
  cin>>n;
  int x=1;
  
  for(int i=1;i<=1000;i++){
    if(1000*i>=n) {
       x=i;
      break;
    }
   
  }
  cout<<1000*x-n;
    
  

}


Measured memory_bytes: 3640
from fractions import gcd

def lcm(a, b):
  return a * b // gcd(a, b)
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
l = 1
for i in range(len(A)):
  c = 0
  a = A[i]
  while(a%2 == 0):
    a //= 2
    c += 1
  if i == 0:
    c0 = c
  else:
    if c0 != c:
      print(0)
      exit()
  l = lcm(l,A[i]//2)

print((M+l)//(2*l))


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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    ll a[n],b[n],m,ans=0;
    for(int i=0;i<n;i++){
         cin>>a[i]>>b[i];   
    }
    for(int i=n-1;i>=0;i--){
        m=(a[i]+ans)%b[i];
        if(m!=0){
            ans+=b[i]-m;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,k;
    cin>>n>>k;
    double ans=0.0;
    for(int i=1;i<=n;i++){
        int score=i;
        double tmp=1.0/n;
        while(score<k){
            score*=2;
            tmp*=0.5;
        }
        ans+=tmp;
    }
    printf("%0.12f\n",ans);
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const a = parseInt(arg[0].split(" ")[0]);
    const b = parseInt(arg[1].split(" ")[0]);
    const h = parseInt(arg[2].split(" ")[0]);
    
    console.log(((a + b) * h) / 2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <iostream> 
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <cstring>

#define mp make_pair
#define s second
#define f first
#define ll long long
using namespace std;
const ll MAX = 100002;
ll dp[100003], ans;
bool b[100003];

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

	int n, m;
	cin >> n >> m;
	
	for (int i=1; i<MAX; i++)
		dp[i] = 10e12;
	
	dp[0] = 0;
	for (int i=0; i<n; i++) {
		ll weight, value; 
		cin >> weight >> value;
		for (int j=MAX; j>=value; j--) {
			dp[j] = min(dp[j], dp[j-value] + weight);
		}
	}
	
	for (int i=MAX-2; i>=0; i--) {
		if (dp[i] <= m) {
			cout << i;
			break;
		}
	}
	
return 0;	
}




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

using namespace std;

typedef long long ll;
typedef vector<ll> Vec;

ll solve(Vec &a, Vec &b, ll idx, ll k, ll c)
{
    if (idx == (int)a.size()) return 0;
        
    ll res = 0;
    ll A = a[idx], B = b[idx];
    if (A - c >= B) {
        ll C = (A - c - B) * pow(10, idx);
        res = solve(a, b, idx + 1, k, 0) + C;
    } else {
        ll C = (A - c + 10 - B) * pow(10, idx);
        res = solve(a, b, idx + 1, k, 1) + C;        
        if (k > 0) {
            res = max(res, solve(a, b, idx + 1, k-1, 0) + C);
        }
    }
    return res;
}

int main()
{
    string A, B;
    ll K;
    cin >> A >> B >> K;
    vector<ll> a, b; 
    for (ll i = (ll)A.size()-1; i >= 0; i--) {
        a.push_back(A[i]-'0');
    }

    for (ll i = (ll)B.size()-1; i >= 0; i--) {
        b.push_back(B[i]-'0');
    }

    while (b.size() != a.size()) b.push_back(0);
    
    cout << solve(a, b, 0, K, 0) << endl;
    return 0;
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<map>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n;
	cin>>n;
	int arr[n];
	int brr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>brr[i];
	}
	int sum =0;
	for(int i=0;i<n;i++)
	{
		int diff = arr[i] - brr[i];
		if(diff > 0)
		{
			sum += diff;
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int dp[100010][5];

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

    dp[1][0] = 1;
    dp[1][1] = 1;
    int ans=0;
    for(int i=1; i<n; i++){
        if(a[i] != a[i-1]){
            dp[i+1][0] = dp[i][0] + 1;
            dp[i+1][1] = dp[i][1] + 1;
            dp[i+1][2] = dp[i][2] + 1;
        }
        if(a[i] == a[i-1]){
            dp[i+1][0] = 1;
            dp[i+1][1] = dp[i][0] + 1;
            dp[i+1][2] = dp[i][1] + 1;
        }

        chmax(ans, max(dp[i+1][0], dp[i+1][2]));
    }

    /*
    for(int i=1; i<=n; i++){
        cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
    }
    */

    cout << ans << endl;
}


Measured memory_bytes: 5128
#include<iostream>
using namespace std;
int main () {
	int n, x, count;
	cin >> n >> x;
	while ((n!=0) || (x!=0)) {
		count = 0;
	 	for (int a=1;a<=n;a++) {
			for (int b=1;b<=n;b++) {
				for (int c=1;c<=n;c++) {
					if ((a < b) && (b < c)) {
				  		if (a+b+c==x) {
				      	count++;
			        }
				}	
			}
		}
	} 
	cout << count << endl;
	cin >> n >> x;
	}
	return 0;
}


Measured memory_bytes: 3032
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int N, M;
long long int num[20];
long long int box[20];
long long int ans = LLONG_MAX;

void Search(long long int f, long long int r, list<long long int>l) {
	if (r) {
		for (long long int i = f + 1; i < N; i++) {
			l.push_back(i);
			Search(i, r - 1, l);
			l.pop_back();
		}
	}
	if (!r) {
		long long int bag = num[0];
		long long int fig = 0;
		for (auto i : l) {
			bag = max(bag + 1, box[i]);
			fig += bag - num[i];
		}
		//cout << fig << endl;
		ans = min(ans, fig);
	}
	return;
}

int main(){
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		if (i)box[i] = max(box[i - 1], num[i]);
	}
	list<long long int>www;
	Search(0, M-1, www);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// Written By NewbieChd
#include <cstdio>
#include <cctype>
#include <vector>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 100003, yyb = 1000000007;
int k, ans, fac[maxN], invFac[maxN];
vector <int> g[maxN];

inline int power(int x, int y) {
    int o = 1;
    while (y) {
        if (y & 1)
            o = 1ll * o * x % yyb;
        x = 1ll * x * x % yyb, y >>= 1;
    }
    return o;
}

void dfs(int x, int f) {
    int cnt = 0, tmp = x > 1 ? k - 2 : k - 1;
    for (auto y : g[x])
        if (y != f)
            dfs(y, x), ++cnt;
    if (tmp < cnt)
        ans = 0;
    else
        ans = 1ll * ans * fac[tmp] % yyb * invFac[tmp - cnt] % yyb;
}

int main() {
    int n, i, x, y;
    n = read(), k = read();
    for (i = 1; i < n; ++i)
        x = read(), y = read(), g[x].push_back(y), g[y].push_back(x);
    n = max(n, k), fac[0] = 1;
    for (i = 1; i <= n; ++i)
        fac[i] = 1ll * fac[i - 1] * i % yyb;
    invFac[n] = power(fac[n], yyb - 2);
    for (i = n; i; --i)
        invFac[i - 1] = 1ll * invFac[i] * i % yyb;
    ans = k, dfs(1, 0);
    printf("%d\n", ans);
    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  //b,a
  ll H, W;
  cin >> H >> W;
  
  vector<vector<char>> gridmap(H, vector<char>(W));
  vector<bool> h_mask(H, true);
  
  REP(h, H){
    bool mask_flag = true;
    
    REP(w, W){
      cin >> gridmap[h][w];
      if(gridmap[h][w]=='#')
        mask_flag = false;
    }
    if(mask_flag)
      h_mask[h] = false;
  }
  
  vector<bool> w_mask(W, true);
  REP(w, W){
    bool mask_flag = true;
    
    REP(h, H){
      if(gridmap[h][w]=='#')
        mask_flag = false;
    }
    if(mask_flag)
      w_mask[w] = false;
  }
  
  
  REP(h, H){
    if(h_mask[h]){
    REP(w, W){
      if(w_mask[w])
        cout << gridmap[h][w];
    }
    cout << "\n";
    }
  }

}

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

a = input().split()
A = input().split()

for i in range(0, len(a)):
    a[i] = int(a[i])

for i in range(0, len(A)):
    A[i] = int(A[i])

count = 0
for i in range(0, len(A)):
    if(A[i] < a[2]):
        count = count + 1


if(count > (len(A) -  count)):
        count = len(A) -  count

print("{0}".format(count))


Measured memory_bytes: 3064
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);
const lint MOD = 1000000007;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> k(M), p(M);
    vector<vector<int>> s;
    s = vector<vector<int>>(M, vector<int>(N, 0));
    rep(i, M)
    {
        cin >> k[i];
        rep(j, k[i]) cin >> s[i][j];
    }
    rep(i, M) cin >> p[i];
    int cnt = 0;
    bool chk = true;
    reps(i,0, pow(2, N)-1)
    {
        rep(j,M) {
            int sum = 0;
            rep(l, k[j]) {
                sum+=(i / (int)(pow(2, s[j][l] - 1))) - (i / (int)(pow(2, s[j][l]))) * 2;
            } 
            if(sum%2!=p[j]) {
                chk = false;
                break;
            }
        }
        if (chk) cnt++;
        chk = true;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.Scanner;

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int M = scan.nextInt();
        int[] a = new int[A];
        int[] b = new int[B];
        int min_a = Integer.MAX_VALUE;
        for (int i = 0; i < A; i++) {
            a[i] = scan.nextInt();
            min_a = Math.min(min_a, a[i]);
        }
        int min_b = Integer.MAX_VALUE;
        for (int i = 0; i < B; i++) {
            b[i] = scan.nextInt();
            min_b = Math.min(min_b, b[i]);
        }
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        queue.add(min_a + min_b);
        for (int i = 0; i < M; i++) {
            int x = scan.nextInt()-1;
            int y = scan.nextInt()-1;
            int c = scan.nextInt();
            queue.add(a[x] + b[y] - c);
        }
        System.out.println(queue.poll());
    }
}


Measured memory_bytes: 152428
n = int(input())
a_list = [int(input()) for _ in range(n)]

cnt = 0
for i in range(n-1):
    cnt += a_list[i] // 2
    a_list[i] = a_list[i] % 2

    if a_list[i] == 1 and a_list[i+1] >= 1:
        cnt += 1
        a_list[i] = 0
        a_list[i+1] -= 1

# 最後に末尾のやつを処理する
cnt += a_list[n-1] // 2

print(cnt)

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

int main() {
	long long n, sum = 0;
	cin >> n;
	for (long long i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		sum += i;
	}
	cout << sum << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	int n,i;
	cin>>n>>i;
	cout<<(n-i+1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <random>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	ll n,a,b;
	cin >> n >> a >> b;
	ll d = b*(n-1)+a, c = a*(n-1)+b;
	cout << max(0LL,d-c+1) << "\n";
	return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define endl "\n"

set<ll> adj[100005];
vector<ll> a[100005]; 
map<pair<ll,ll>,ll> hm;

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

    // cout<<fixed<<setprecision(15);

    ll n,a,b;
    cin>>n>>a>>b;

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

}

Measured memory_bytes: 7296