akhauriyash/Code-Regression huggingface dataset:
///-----Bismillahir Rahmanir Rahim-----///

#include<bits/stdc++.h>
using namespace std;

///---FAST I/O---///
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///---DATA TYPE---///
typedef long long ll;
typedef long long int lli;
///vector
typedef vector<int> vi;
typedef vector<ll> vl;
///pair
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;

///---LOOP---///
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)

///---I/O---///
#define sf scanf
#define pf printf

///---OTHERS---///
#define pb push_back
#define all(c)		c.begin(),c.end()
#define MK make_pair
#define F first
#define S second
#define endl '\n'


///---INITIALIZATION---//
#define mem(a,b) memset(a, b, sizeof(a) )

///---CALCULATE---///
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

///---BIT OPERATION---///
inline bool checkBit(ll n, int i)
{
    return n&(1LL<<i);
}
inline ll setBit(ll n, int i)
{
    return n|(1LL<<i);;
}
inline ll resetBit(ll n, int i)
{
    return n&(~(1LL<<i));
}

///------String/Char Related Functions-----///
string makeintString(int x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
string makellString(ll x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
char cpp(char c)
{
    return static_cast<char>(c + 1);
}

///---CONSTANT---///
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

int main()
{
    Boost();

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        ll n,x;
        cin>>n;
        ll a[n+5],sum=0;
        map<ll,ll>cnt;
        for(ll i=0; i<n; i++)
        {
            cin>>a[i];
            cnt[a[i]]++;
            sum+=a[i];
        }
        ll q;
        cin>>q;
        ll b,c;
        for(ll i=0; i<q; i++)
        {
            cin>>b>>c;
            ll minusKoro=b*cnt[b];
            ll plusKoro=c*cnt[b];
            cnt[c]+=cnt[b];
            cnt[b]=0;
            sum-=minusKoro;
            sum+=plusKoro;
            cout<<sum<<endl;
        }
        cnt.clear();
    }
    return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int m;
  cin >> m;
  int i,j;
  int lent,lenh,min;
  int anst = 0;
  int ansh = 0;
  for(i = 0;i < m;++i){
    char taro[100]; 
    char hana[100];
    cin >> taro; 
    cin >> hana;
    lent = strlen(taro);
    lenh = strlen(hana);
    if(lent > lenh){
      min = lenh;
    }else{
      min = lent;
    }
    for(j = 0;j < min;++j){
      if((int)taro[j] > (int)hana[j]){
        anst += 3;  break;
      }else if((int)taro[j] < (int)hana[j]){
        ansh += 3;  break;
      }else{
        continue;
      }
    }
    if(j < min){
      continue;
    }else if(lent == lenh){
      ++anst; ++ansh;
    }else if(lent > lenh){
      anst += 3;
    }else{
      ansh += 3;
    }
  }
  cout << anst << " " << ansh << endl;
  return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int a[5][5],n,b;
double A[5][5];
int main(){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(a[j][k]==b){
                    A[j][k]=true;
                }
            }
        }
    }
    if(A[0][0]==1&&A[0][1]==1&&A[0][2]==1){
        cout<<"Yes"<<endl;
        return 0;
    }if(A[1][0]==1&&A[1][1]==1&&A[1][2]==1){
        cout<<"Yes"<<endl;
        return 0;
    }if(A[2][0]==1&&A[2][1]==1&&A[2][2]==1){
        cout<<"Yes"<<endl;
        return 0;
    }if(A[0][0]==1&&A[1][0]==1&&A[2][0]==1){
        cout<<"Yes"<<endl;
        return 0;
    }if(A[0][1]==1&&A[1][1]==1&&A[2][1]==1){
        cout<<"Yes"<<endl;
        return 0;
    }if(A[0][2]==1&&A[1][2]==1&&A[2][2]==1){
        cout<<"Yes"<<endl;
        return 0;
    }if(A[0][0]==1&&A[1][1]==1&&A[2][2]==1){
        cout<<"Yes"<<endl;
        return 0;
    }if(A[0][2]==1&&A[1][1]==1&&A[2][0]==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf = 10234567;

int n; 
int P[200055];
int value[200055];
int totalPhigh = 0;

struct state{ int maxX, maxY, highX, highY; };
state cur = {0,0,0,0};

struct segment{
	int tree[400105];
	int N;
	
	void init(int _N){
		N = _N;
		for(int i = 0;i <= 2*N;i++) tree[i] = -inf;
	}
	
	void update(int i, int x){
		i += N;
		tree[i] = x;
		i >>= 1;
		while(i > 0){
			tree[i] = max(tree[i<<1], tree[i<<1|1]);
			i >>= 1;
		}
	}
	
	int query(int l, int r){
		int res = -inf;
		for(l += N, r += N;l < r;l >>= 1, r >>= 1){
			if(l&1) res = max(res, tree[l++]);
			if(r&1) res = max(res, tree[--r]);
		}
		return res;
	}
} odd, even;

bool verify(state S){
	
	///let a be all Phigh
	int target = totalPhigh + S.highX - S.highY;
	if(target >= 0){
		int best;
		if(target % 2 == 0) best = even.query(S.maxY, n+1);
		else best = odd.query(S.maxY, n+1);
		if(best >= target) return true;
	}
	
	///let b be all Phigh
	target = totalPhigh - S.highX + S.highY;
	if(target >= 0){
		int best;
		if(target % 2 == 0) best = even.query(S.maxX, n+1);
		else best = odd.query(S.maxX, n+1);
		if(best >= target) return true;
	}
	
	return false;
}

state addTo(state ori, int value, bool isX){
	state nxt = ori;
	if(isX){
		if(value > nxt.maxX){
			nxt.maxX = value;
			nxt.highX++;
		}
	}
	else{
		if(value > nxt.maxY){
			nxt.maxY = value;
			nxt.highY++;
		}
	}
	return nxt;
}

	
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	cin >> n;
	for(int i = 1;i <= n;i++) cin >> P[i];
	P[0] = 0;
	
	int maxValue = 0;
	for(int i = 0;i <= n;i++){
		if(maxValue < P[i]){
			maxValue = P[i];
			value[i] = 2;
			totalPhigh++;
		}
		else value[i] = 1;
	}
	
	odd.init(n+2); even.init(n+2);
	
	///do LDS from the back (LIS in normal order)
	for(int i = n;i >= 1;i--){
		int best1 = odd.query(P[i]+1, n+1) + value[i];
		int best2 = even.query(P[i]+1, n+1) + value[i];
		int best3 = value[i];
		
		int bestOdd = -inf, bestEven = -inf;
		
		if(best1 % 2 == 0) bestEven = max(bestEven, best1);
		else bestOdd = max(bestOdd, best1);
		
		if(best2 % 2 == 0) bestEven = max(bestEven, best2);
		else bestOdd = max(bestOdd, best2);
		
		if(best3 % 2 == 0) bestEven = max(bestEven, best3);
		else bestOdd = max(bestOdd, best3);
		
		even.update(P[i], bestEven);
		odd.update(P[i], bestOdd);
		//cout << P[i] << " " << best1 << " " << best2 << " " << best3 << "\n";
	}
		
	string ans = "";
	for(int i = 1;i <= n;i++){
		if(value[i] == 2) totalPhigh--;
		odd.update(P[i], -inf); even.update(P[i], -inf);
		
		if(P[i] < cur.maxX && P[i] < cur.maxY){
			ans += '0';
			continue;
		}
		
		///try to add to X
		state nxt = addTo(cur, P[i], true);
		
		///check if can be done
		if(verify(nxt)){
			ans += '0';
			cur = nxt;
		}
		else{
			ans += '1';
			cur = addTo(cur, P[i], false);
		}
	}
	
	if(cur.highX != cur.highY) ans = "-1";
	cout << ans;
}


Measured memory_bytes: 8428
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
 
int main(void) {
    double a, b, c;
    cin >> a >> b >> c;
    if(b / a >= c){
        cout << c << endl;
    }else{
        cout << (int)(b / a) << endl;
    }
    return 0;
}


Measured memory_bytes: 3784
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
#define MOD (1e9+7)
typedef pair < ll, ll> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}
map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
vector<ll> divisor(ll n) {
	vector<ll>res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i != 0)continue;
		res.push_back(i);
		if (i * i != n)res.push_back(n / i);
	}
	return res;
}


ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}
std::vector<int> Eratosthenes(const int N)
{
	std::vector<bool> is_prime(N + 1);
	for (int i = 0; i <= N; i++)
	{
		is_prime[i] = true;
	}
	std::vector<int> P;
	for (int i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}
int sx, sy, tx, ty;
int main()
{
	cin >> sx >> sy >> tx >> ty;
	rep(i, ty - sy) {
		cout << 'U';
	}
	rep(i,tx - sx) {
		cout << 'R';
	}
	rep(j, ty - sy) {
		cout << 'D';
	}
	rep(j, tx - sx) {
		cout << 'L';
	}
	cout << 'L';
	rep(i, ty - sy+1) {
		cout << 'U';
	}
	rep(j, tx - sx + 1) {
		cout << 'R';
	}
	cout << 'D';
	cout << 'R';
	rep(j, ty - sy + 1) {
		cout << 'D';
	}
	rep(j, tx - sx + 1) {
		cout << 'L';
	}
	cout << 'U' << endl;
	
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 105
using namespace std;
int n,m,w[M],v[M];
long long dp[100005];
int main()
{
    while (~scanf("%d %d",&n,&m)) {
        REP(i,1,n) scanf("%d %d",&w[i],&v[i]);
        MSET(dp, -1);
        dp[0] = 0;
        REP(i,1,n) for (int j=m; j>=w[i]; j--)
            if (dp[j-w[i]] != -1)
                dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
        printf("%lld\n", *max_element(dp, dp+m+1));
    }
    
    return 0;
}



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

vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

int main(){
  int X;
  cin>>X;
  vector<int> primes;
  primes=sieve_of_eratosthenes(200000);
  int ans=0;
  for(int n=0;n<primes.size();++n){
    if(primes.at(n)>0 && n>=X){
      ans=n;
      break;
    }
  }

  cout<<ans<<endl;
}


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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// input
void input() {}
template <class Head, class... Tail>
void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

// outs
void outs() {}
template <class Head, class... Tail>
void outs(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  outs(forward<Tail>(tail)...);
}

template <class T>
void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void outs(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// outl
void outl() {}
template <class Head, class... Tail>
void outl(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  outl(forward<Tail>(tail)...);
}

template <class T>
void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// outn
void outn() {}
template <class Head, class... Tail>
void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

// dump
template <class T>
void dump_(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

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

  var(string, s);

  int day = stoi((s.substr(5, 2)));
  int month = stoi((s.substr(8, 2)));

  outl(day <= 4 && month <= 30 ? "Heisei" : "TBD");

  return 0;
}


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

int main() {
  long long X;
  cin >> X;
  long long R = 100;
  int ans = 0;
  for (int i = 0; i < 3760; i++) {
    R = R + R/100;
    if (R >= X) {
      ans = i + 1;
      break;
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3632
N, K = map(int, input().split())
D = []
A = []
for _ in range(K):
    d = int(input())
    a = list(map(int, input().split()))
    
    D.append(d)
    A.append(a)

check = [False] * N
for a in A:
    for aa in a:
        if not check[aa - 1]:
            check[aa - 1] = True


print(N - sum(check))


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

int main()
{

    long h,n;

    scanf("%ld%ld", &h,&n);

    long i,sum=0,a;

    for(i=0;i<n;i++) {
        scanf("%ld", &a);
        sum+=a;
    }

    if(h-sum<=0) {
        printf("Yes");
    }else {
        printf("No");
    }


    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define pb push_back
#define mod 1000000007
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};

ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

 // void dfs(ll node){
 // 	vis[node]=1;
 // 	res.pb(node);
 //    vector<ll> ans;


 // 	for(auto i:v[node]){
 // 		if(!vis[i]){
 // 			ans.pb(i);

 // 		}
 // 	}
 // 	sort(ans.begin(),ans.end());

 // 	for(auto i:ans){
 // 		if(!vis[i])
 // 			dfs(i);
 // 	}




 // }
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
bool sortbyme(const pair<int,int> &a, 
              const pair<int,int> &b){
	return (a.first+a.second > b.first+b.second);

}
ll dp[1000000];
ll tot=INT_MAX;


ll dmch(vector<ll> a,ll ind,ll x,ll n){



	if(ind>=n-1)return 0;
	else if(dp[ind]!=-1){
		return dp[ind];

	}
	else{
		ll ans=INT_MAX;
		for(ll i=1;i<=2;i++)
			if(i+ind<n)
			{
				ans=min(abs(a[ind]-a[ind+i])+dmch(a,ind+i,x,n),ans);

			}
			else
				break;

		// ans=min(a[ind]+dmch(a,ind+1LL,x,n),min(a[ind]+dmch(a,ind+2ll,x,n)+x,a[ind]+x*2+dmch(a,ind+3ll,x,n)));
		dp[ind]=ans;
		return dp[ind];

	}
}
void solve(){
	int n;int k;

	cin >> n;
	cin>>k;

	int arr[n];
	for(int& i : arr) cin >> i;
	int DP[n];
	DP[n-1] = 0;
	for(int i = n-2; i >=0; --i){
		int temp=INT_MAX;
		for(int j=1;j<=k;j++){
		   if(j+i<n){
		   	temp=min(DP[i+j]+abs(arr[i]-arr[i+j]),temp);
		   }
		   else
		   	break;

		}
		DP[i]=temp;

		// DP[i] = DP[i+1] + abs(arr[i] - arr[i+1]);
		// if(i+2 < n) DP[i] = min(DP[i], DP[i+2] + abs(arr[i] - arr[i+2]));
	}
	cout << DP[0] << endl;





return;
}



int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    

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



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}

Measured memory_bytes: 4440
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		int[] x = new int[100010];
		for(int i = 0 ; i < n ; i++) {
			x[a[i]]++;
		}
		int ans = 0;
		for(int i = 0 ; i < 100010 ; i++) {
			int cnt = 0;
			if(i == 0) {
				cnt = x[i] + x[i + 1];
			} else if(i == 100009) {
				cnt = x[i] + x[i - 1];
			} else {
				cnt = x[i - 1] + x[i] + x[i + 1];
			}
			ans = Math.max(ans, cnt);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 50736
#include<bits/stdc++.h>
using namespace std;
int main(){
  int D,N;
  cin >> D >> N; 
  int a=1; 
  int i=0;
  while(i<D){
    a=a*100;
    i++;
  }
  int ans;
  if(99 >= N){
    ans = a*N;
  }
  else {
    ans= 101*a;
  }
  cout << ans << endl;
  
}
  


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  
  double ans = (w*h)/2;
  
  int num = (w/2==x && h/2==y)? 1 : 0;
  
  printf("%.10f %d\n",ans,num);
  
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))

    while True:
        mina = min(A)
        mini = A.index(mina)
        A = A[:mini] + A[mini+1:]
        A = [a % mina for a in A if a % mina > 0]
        if not A:
            break
        A = A + [mina]
    print(mina)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
using namespace std;
int solve()
{
	int k,x;
	cin>>k>>x;
	if(k*500>=x)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;		
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}

Measured memory_bytes: 3568
#include <iostream>
#include <fstream>
#include <climits>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <list>

#define FOR(i , n)      for(int i = 0 ; i < n ; i++)
#define FORmn(i,m,n)	for(int i = m ; i < n ; i++)
#define FORrev(i,n,m)	for(int i = n - 1 ; i >= m ; i--)
#define ALL(a)		a.begin(),a.end()
#define pii			pair<long long int , long long int>
#define mp(a , b)	make_pair(a , b)

typedef long long int ll; 

using namespace std;

int main() {
	long n , a , b;
	cin>>n>>a>>b;
	if(abs(a - b) % 2l == 0) {
		cout<<abs(a - b) / 2l;
	}
	else {
		long anew = 1;
		long steps = a - 1;
		long bnew = b - ( a - 1 );
		if((bnew - anew) % 2 != 0) {
			steps++;
			bnew--;
		}
		steps += (bnew - anew) / 2;
		long ans = steps;
		bnew = n;
		steps = n - b;
		anew = a + ( n - b );
		if((bnew - anew) % 2 != 0) {
			steps++;
			anew++;
		}
		steps += (bnew - anew) / 2;
		cout<<min(steps , ans);
	}
}

Measured memory_bytes: 256
h, w, k = gets.split.map(&:to_i)
c = h.times.map { gets.chomp }
ans = 0
for bi in 0...(2 ** h) do
  for bj in 0...(2 ** w) do
    count = 0
    for i in 0...h do
      for j in 0...w do
        if c[i][j] == "#" && ((bi >> i) & 1) != 1 && ((bj >> j) & 1) != 1
          count += 1
        end
      end
    end
    ans += 1 if count == k
  end
end
puts ans


Measured memory_bytes: 14332
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
const int maxN=1005;
int x[maxN][3];
main(){
	//freopen("input.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=0;j<3;j++){
			cin>>x[i][j];
		}
	}
	int mx=0;
	for(int mask=0;mask<8;mask++){
		vector<int> all;
		for(int i=1;i<=n;i++){
			int t=mask;
			int val=0;
			for(int j=00;j<3;j++){
				if(t&1){
					val+=x[i][j];
				}
				else{
					val-=x[i][j];
				}
				t/=2;
			}
			all.push_back(val);
		}
		sort(all.begin(),all.end());
		reverse(all.begin(),all.end());
		int cur=0;
		for(int i=0;i<m;i++){
			cur+=all[i];
		}
		mx=max(mx,cur);
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC072C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = new int[N];
            int[] x = new int[100001];
            var target = Console.ReadLine().Split(' ');
            for(int i=0;i<N;i++) {
                a[i] = int.Parse(target[i]);
                x[a[i]]++;
            }
            Array.Sort(a);
            int max_count = 0;
            for(int i=a[0];i<a[a.Length-1]+1;i++){
                int count = x[i] + x[i+1];
                if(i != 0) count += x[i-1]; 
                if(count > max_count) max_count = count;
            }
            Console.WriteLine(max_count);
//            Console.WriteLine(String.Join(" ", a));

        }
    }
}


Measured memory_bytes: 18144
/*input
4
RRGB
*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<long,long>
#define vi          vector<long long>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repi(i,a,b) for(ll i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define fIO         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define tr(it, a)   for(auto it = a.begin(); it != a.end(); it++)
#define clr(x)      memset(x, 0, sizeof(x))
#define deb(x)      cout << #x << "=" << x << endl
#define deb2(x, y)  cout << #x << "=" << x << "," << #y << "=" << y << endl
#define TIME        cerr << "\nTime elapsed: "<<1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; 
//#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update>;

ll sub(ll a, ll b){return (a-b+hell)%hell;}
ll add(ll a, ll b){return (a+b)%hell;}
ll mul(ll a, ll b){return (a*b)%hell;}
vector<ll>adj[100005];
bool vis[100005];
ll siz,edges;
void dfs(ll i)
{
    vis[i]=1;
    //siz++;
    for(ll j=0;j<adj[i].size();j++)
    {        
        edges++;
        if(!vis[adj[i][j]])
            dfs(adj[i][j]);
    }
}
const ll mod = 1000000007;
ll mpow(ll base, ll exp) {
  base %= mod;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

int main()
{
fIO;
ll n,sum=0,t=1,m,ans;
//cin >> t;
while(t--){
  cin>>n;
  string s;
  cin>>s;
  ll r=0,g=0,b=0;
  rep(i,0,s.length()){
    if(s[i]=='R')r++;
    else if(s[i]=='G')g++;
    else b++;
  }
  ll sum=r*g*b;
  rep(i,0,n){
    rep(j,i+1,n){
      if(s[i]==s[j])continue;
      ll k=j+j-i;
      if(k>=n)continue;
      if(s[k]==s[i]||s[j]==s[k])continue;
      sum--;
    }
  }
  cout<<sum;












}
TIME;
    
}

Measured memory_bytes: 6192
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
string n;
int main()
{
    cin>>n;
    for(int i=2;i<n.length();i++)
    {
        if(n[i]==n[i-1]&&n[i]==n[i-2])
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

void MatrixChain(int, int[], int **, int **);
void print(int, int, int **);

int main()
{
    int n;
    cin >> n;
    int *tempP = new int[2 * n]; //p[0]为A1的行数；p[i]为Ai的列数
    
    int *p = new int[n + 1];    //p[0]为A1的行数；p[i]为Ai的列数
    int **m = new int *[n + 1]; //m[i][j]为Ai连乘到Aj的最少乘次数
    int **s = new int *[n + 1]; //s[i][j]为 Ai连乘到Aj的最优解的第一层断点
    for (int i = 1; i <= n; i++)
    {
        m[i] = new int[n + 1];
        s[i] = new int[n + 1];
    }
    
    for (int i = 0; i < 2 * n; i++)
    {
        cin >> tempP[i];
    }
    
    for (int i = 0; i <= n; i++)
    {
        p[i] = i == 0 ? tempP[0] : tempP[i*2-1];
    }
    
    // for (int i = 0; i <= n; i++)
    //     cin >> p[i];
    MatrixChain(n, p, m, s);
    cout    << m[1][n] << endl; //最优值存储在m[1][n]
        //print(1, n, s);
    
//    for (int idx = 1; idx <= n; idx++)
//    {
//        for (int jdx = 1; jdx <= n; jdx++)
//        {
//            cout << m[idx][jdx] << " ";
//        }
//        cout << endl;
//    }
    return 0;
}

void MatrixChain(int n, int p[], int **m, int **s)
{
    int i, j, k, temp;
    //以下双重循环对m[][]的上三角进行填表
    //填表顺序为自底向上，自左向右
    for (i = n; i >= 1; i--) //i表示行
    {
        for (j = i; j <= n; j++) //j表示列，因为只填上三角，所以j的初值为i
        {
            //以下按照矩阵连乘问题的递归公式来求每一个m[i][j]
            if (i == j)
            {
                m[i][j] = 0;
            }
            else
            {
                m[i][j] = m[i][i] + m[i + 1][j] + p[i - 1] * p[i] * p[j]; //若i与j不相等，m[i][j]的初值为断点为i时的最优值
                
                s[i][j] = i;                //记录当前断点位置为i
                for (k = i + 1; k < j; k++) //k用于尝试不同的断点
                {
                    temp = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
                    if (temp < m[i][j]) //当前k值作为Ai连乘到Aj的断点能获得更少计算量
                    {
                        m[i][j] = temp; //刷新最优值
                        s[i][j] = k;    //刷新相应断点
                    }
                }
            }
        }
    }
}

void print(int i, int j, int **s)
{
    if (i == j)
        cout << "A" << i;
    else
    {
        cout << "(";
        print(i, s[i][j], s);
        print(s[i][j] + 1, j, s);
        cout << ")";
    }
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200025,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,A,B;
int main(){
//	freopen("balance.in","r",stdin);
//	freopen("balance.out","w",stdout);
	n=read();m=read();B=read();A=read();
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++)
		putchar('0'+((i>A)^(j>B)));
		putchar('\n');
	}
	return 0;
}

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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
long long n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	long long ans = (n / 500ll) * 1000ll * 1ll ;
	n %= 500 ;
	ans += (n / 5ll) * 5ll ;
	return cout<<ans<<"\n" , 0 ;
}		

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  int a,b,c;
  cin >>a>>b>>c;
  
  cout << max(b+c-a,0) << endl;

}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};



int main() {
    int a[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1};
    int A, B;
    cin >> A >> B;
    int iA, iB;
    for (int i = 0; i < 13; i++) {
        if (a[i] == A) {
            iA = i;
        }
        if (a[i] == B) {
            iB = i;
        }
    }
    if (iA > iB) {
        cout << "Alice" << endl;
    } else if (iA < iB) {
        cout << "Bob" << endl;
    } else {
        cout << "Draw" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;

class Program2
{
    static void Main(string[] args)
    {
        string[] _strinput = Console.ReadLine().Split();
        int iA = int.Parse(_strinput[0]), iB = int.Parse(_strinput[1]), iM= int.Parse(_strinput[2]);
        string[] _stras= Console.ReadLine().Split();
        string[] _strbs = Console.ReadLine().Split();
        string[] _strxyc;
        int ixs , iys , ics;
        int iTotals = 200000;
        for (int i = 0; i < iM; i++) {
            _strxyc = Console.ReadLine().Split();
            ixs = int.Parse(_strxyc[0])-1;
            iys = int.Parse(_strxyc[1])-1;
            ics = int.Parse(_strxyc[2]);
            iTotals = Math.Min((int.Parse(_stras[ixs]) + int.Parse(_strbs[iys]) - ics), iTotals);
        }
        int iAs = 100000;
        int iBs = 100000;
        for (int i = 0; i < iA; i++)
        {
            iAs = Math.Min(int.Parse(_stras[i]),iAs);
        }
        for (int i = 0; i < iB; i++)
        {
            iBs = Math.Min(int.Parse(_strbs[i]), iBs);
        }
        iTotals = Math.Min((iAs + iBs), iTotals);
        iTotals =Math.Max(iTotals,0);
    Console.WriteLine(iTotals);
        

    }
}


Measured memory_bytes: 34908
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

vector<vector<int> > g;
bool dp[80][80][12800];
int dy[]={0,1};
int dx[]={1,0};

int main(){
  int H,W;
  cin >> H >> W;
  g.resize(H,vector<int>(W));
  vector<vector<int> > a(H,vector<int>(W));
  vector<vector<int> > b(H,vector<int>(W));
  rep(i,H) rep(j,W) cin >> a[i][j];
  rep(i,H) rep(j,W) cin >> b[i][j];
  rep(i,H) rep(j,W) g[i][j]=abs(a[i][j]-b[i][j]);
  queue<i_i> q;
  q.push(i_i(0,0));
  dp[0][0][g[0][0]]=1;
  rep(i,H){
    rep(j,W){
      rep(k,12800){
        if(dp[i][j][k]==1){
          if(i+1<H){
            dp[i+1][j][k+g[i+1][j]]=1;
            dp[i+1][j][abs(k-g[i+1][j])]=1;
          }
          if(j+1<W){
            dp[i][j+1][k+g[i][j+1]]=1;
            dp[i][j+1][abs(k-g[i][j+1])]=1;
          }
        }
      }
    }
  }
  int ans;
  rep(i,12800){
    if(dp[H-1][W-1][i]==1){
      ans=i;
      break;
    };
  }
  cout << ans << endl;
}

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

int main(){
    int n;
        cin>>n;
    int dp[n],arr[n];
    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    dp[0] = 0;
    dp[1] = abs(arr[0] - arr[1]);

    for(int i = 2; i < n; i++){
        dp[i] = min(abs(arr[i] - arr[i-2])+dp[i-2],abs(arr[i] - arr[i-1])+dp[i-1]);
        //cout<<dp[i]<<" ";
    }
        cout<<dp[n-1]<<endl;
return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cctype>
#include <vector>
 
using namespace std;
 
int len;
 
string UpperCamelCase(vector<string> v){
    string res = "";
 
    for(int i = 0 ; i < len ; i++){
	if(islower(v[i][0])){
	    v[i][0] = toupper(v[i][0]);
	}
	res += v[i];
    }
 
    return res;
}
 
string LowerCamelCase(vector<string> v){
    string res = v[0];
 
    for(int i = 1 ; i < len ; i++){
	if(islower(v[i][0])){
	    v[i][0] = toupper(v[i][0]);
	}
	res += v[i];
    }
 
    return res;
}
 
string Under(vector<string> v){
    string res = v[0];
 
    for(int i = 1 ; i < len ; i++){
	res += '_' + v[i];
    }
   
    return res;
}
 
int main(){
    string s;
    char order;
 
    while(cin >> s >> order, order != 'X'){
	if(isupper(s[0])){
	    s[0] = tolower(s[0]);
	}
	s += '_';
 
	vector<string> v;
	int pos = 0;
	len = (int)s.size();
 
	for(int i = 0 ; i < len ; i++){
	    if(isupper(s[i])){
		s[i] = tolower(s[i]);
		v.push_back(s.substr(pos,i-pos));
		pos = i;
	    }else if(s[i] == '_'){
		v.push_back(s.substr(pos,i-pos));
		pos = i + 1;
	    }
	}
 
	len = (int)v.size();
     
	if(order == 'U'){
	    cout << UpperCamelCase(v) << endl;
	}else if(order == 'L'){
	    cout << LowerCamelCase(v) << endl;
	}else{
	    cout << Under(v) << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 3184
/*
░░░░░░░▄▀▀▀▀▀▀▀▄▄░░░░░░
░░░░░░▐░░░▄▄▄▄▄░ ▀▀▄
░░░░░▐░$░▐▀░░░░▀▀▀▀▄▀
░░░░░▌░░▐░░░░░░░░░░▄▄
░░░░▐░░░░▀▄▄▄▄▄▄▀▀▀░▄▀
░░░░▌▒░▒░▒░▒░░░▄▄▄▀▀
░░░░▌▒▒░▒▒▒▒▄▄▀▀
░░░▐░░▒▒▒▄▀▀░░░░░░░
░░░▐░▒▒▒▐░░░░░░░░░
░░░▐▒▒▒▒▌░░░░░░░░
░░░▐▒▒▒░▐░░░░░░░░░▄▀▄
░░░▐▒▒░▒▐▄▄▀▀▀▀▄▄▄▀░▌
░░░▐░▒▒░▄▄▄▄▀▀▄▄▄▄▄▀
░░▐▒▒▄▒▒▀▄▄▄▄▄▀░░░▄▌░░
░░▌▒▐░▀▀▄▄▄▄▄▄▄▀▀▀░░░░
░▐▒▒▌░░░░░░░░░░░░░ 
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 800 + 7;

char c[N][N];
int d[N][N];

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

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    int n, m, k;
    cin >> n >> m >> k;
    int x = 0, y = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> c[i][j];
            d[i][j] = -1;
            if (c[i][j] == 'S')
            {
                x = i, y = j;
            }
        }
    }
    queue <pair <int, int> > q;
    d[x][y] = 0;
    q.push({x, y});
    while (!q.empty())
    {
        auto v = q.front();
        q.pop();
        int x = v.first, y = v.second;
        for (int t = 0; t < 4; t++)
        {
            if (x + dx[t] >= 0 && x + dx[t] < n && y + dy[t] >= 0 && y + dy[t] < m && 
            c[x + dx[t]][y + dy[t]] != '#' && d[x + dx[t]][y + dy[t]] == -1)
            {
                d[x + dx[t]][y + dy[t]] = d[x][y] + 1;
                q.push({x + dx[t], y + dy[t]});
            }
        }
    }
    int ans = 1e9;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (d[i][j] != -1 && d[i][j] <= k)
            {
                int f = 1;
                ans = min(ans, f + (i / k) + bool(i % k));
                ans = min(ans, f + (j / k) + bool(j % k));
                ans = min(ans, f + ((n - 1 - i) / k) + bool((n - 1 - i) % k));
                ans = min(ans, f + ((m - 1 - j) / k) + bool((m - 1 - j) % k));
            }
        }
    }
    cout << ans << '\n';
}


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

int main(){
	int x[10];
	for (int i = 0; i < 10; i++){
		cin >> x[i];
	}
	sort(begin(x), end(x));
	cout << x[9]<< endl;
	cout << x[8]<<endl;
	cout << x[7]<<endl;
	
}


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

#define INF 2000

int n;
int cost[110][110], mincost[110];
bool used[110];

int prim(){

  //initialization
  for(int i = 0;i < n;i++){
    mincost[i] = INF;
    used[i] = false;
  }

  //cost of starting position is 0
  mincost[0] = 0;
  int ans = 0;
  
  while(true){
    int v = -1;
    
    for(int u = 0;u < n;u++){
      if(!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
    }

    if(v == -1) break; //finish
    used[v] = true; //use v
    ans += mincost[v];

    //update mincost
    for(int u = 0;u < n;u++){
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  
  return ans;
}

int main(){

  //input
  cin >> n;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      cin >> cost[i][j];
      if(cost[i][j] == -1) cost[i][j] = INF;
    }
  }

  //output
  cout << prim() << endl;
  
  return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <string>

using namespace std;

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

    int idx_a, idx_z;
    int len = s.length();
    bool a = false, z = false;
    for (int i = 0; i < len; i++) {
        if (s[i] == 'A' && !a) {
            idx_a = i;
            a = true;
        }
        if (s[len-i-1] == 'Z' && !z) {
            idx_z = len-i-1;
            z = true;
        }
        if (a && z) break;
    }

    cout << (idx_z - idx_a + 1) << endl;
}

Measured memory_bytes: 640
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
maxlen = int(0)
maxi = 0
N = I()
LR =[[] for _ in range(N)]
LR2 =[]
for i in range(N):
    LR[i] = LI()
    C = LR[i][1] - LR[i][0]
    if C>maxlen:
        maxlen = C
        maxi = i
for i in range(N):
    if not i==maxi:
        LR2.append(LR[i])

LR.sort()
rightend = LR[0][1]
leftend  = LR[N-1][0]

live1 = [[] for _ in range(N)]
live2 = [[] for _ in range(N)]
live1[0] = LR[0]
live2[N-1] = LR[N-1]
#print(rightend)
#print(leftend)

cur1 = -1; cur2 = -1
for i in range(1,N):
    if live1[i-1][1]>LR[i][1]:
        rightend = LR[i][1]
    if rightend<LR[i][0]:
        cur1 = i-1
        break
    live1[i] = [max(live1[i-1][0],LR[i][0]),min(live1[i-1][1],LR[i][1])]

for i in range(N-2,-1,-1):
    if live2[i+1][1]<LR[i][0]:
        leftend = LR[i][0]
    if leftend>LR[i][1]:
        cur2 = i+1
        break
    live2[i] = [max(live2[i+1][0],LR[i][0]),min(live2[i+1][1],LR[i][1])]
#print(cur1,cur2)
#print(live1)
#print(live2)
#print(leftend)
if cur1==-1:
    cur1=N-2
if cur2==-1:
    cur2=1
ansC = [0]*N
for i in range(cur2,cur1+2):
    ansC[i] = (live1[i-1][1]-live1[i-1][0]+1) + (live2[i][1]-live2[i][0]+1)


LR2.sort()
live3 = LR2[0]
for i in range(1, N - 1):
    live3 = [max(live3[0], LR2[i][0]), min(live3[1], LR2[i][1])]
ansd = live3[1] - live3[0] + 1
anslen = max(ansd, 0) + maxlen+1

ans = max(max(ansC),anslen)
####################################################


#####################################################
LR.sort(key=lambda x:x[1])
rightend = LR[0][1]
leftend  = LR[N-1][0]

live1 = [[] for _ in range(N)]
live2 = [[] for _ in range(N)]
live1[0] = LR[0]
live2[N-1] = LR[N-1]
#print(rightend)
#print(leftend)

cur1 = -1; cur2 = -1
for i in range(1,N):
    if live1[i-1][1]>LR[i][1]:
        rightend = LR[i][1]
    if rightend<LR[i][0]:
        cur1 = i-1
        break
    live1[i] = [max(live1[i-1][0],LR[i][0]),min(live1[i-1][1],LR[i][1])]

for i in range(N-2,-1,-1):
    if live2[i+1][1]<LR[i][0]:
        leftend = LR[i][0]
    if leftend>LR[i][1]:
        cur2 = i+1
        break
    live2[i] = [max(live2[i+1][0],LR[i][0]),min(live2[i+1][1],LR[i][1])]
#print(cur1,cur2)
#print(live1)
#print(live2)
#print(leftend)
if cur1==-1:
    cur1=N-2
if cur2==-1:
    cur2=1
ansC = [0]*N
for i in range(cur2,cur1+2):
    ansC[i] = (live1[i-1][1]-live1[i-1][0]+1) + (live2[i][1]-live2[i][0]+1)

LR2.sort(key=lambda x:x[1])
live3 = LR2[0]
for i in range(1, N - 1):
    live3 = [max(live3[0], LR2[i][0]), min(live3[1], LR2[i][1])]
ansd = live3[1] - live3[0] + 1
anslen = max(ansd, 0) + maxlen+1

ans = max(max(ansC),anslen)


print(ans)
#print(ansC)

Measured memory_bytes: 115120
n = int(input())
s = input()

inv = {'S': 'W', 'W': 'S'}
# o と x
def check(t):
    for i in range(2, n):
        if t[i-1] == 'S':
            if s[i-1] == 'o':
                t.append(t[i-2])
            else:
                t.append(inv[t[i-2]])
        else:
            if s[i-1] == 'o':
                t.append(inv[t[i-2]])
            else:
                t.append(t[i-2])

    if t[0] == 'S':
        if s[0] == 'o' and t[1] != t[-1]:
            return "-1"
        elif s[0] == 'x' and t[1] == t[-1]:
            return "-1"
    else:
        if s[0] == 'o' and t[1] == t[-1]:
            return "-1"
        elif s[0] == 'x' and t[1] != t[-1]:
            return "-1"

    if t[-1] == 'S':
        if s[-1] == 'o' and t[0] != t[-2]:
            return "-1"
        elif s[-1] == 'x' and t[0] == t[-2]:
            return "-1"
    else:
        if s[-1] == 'o' and t[0] == t[-2]:
            return "-1"
        elif s[-1] == 'x' and t[0] != t[-2]:
            return "-1"

    return ''.join(t)

ans = "-1"
for t in [['S', 'S'], ['S', 'W'], ['W', 'S'], ['W', 'W']]:
    res = check(t)
    if res != "-1":
        ans = res
        break

print(ans)


Measured memory_bytes: 6416
/**
 *  author: mahfuzz
 *  created: 06.07.2020
**/
 
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define trace(x) cout << #x << ':' << x << "\n"
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    int n; cin >> n;
    int i = 1000;
    while(i < n)
        i += 1000;
    
    cout << i - n << "\n";
    
        
    return 0;
}



Measured memory_bytes: 3572
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,K,X,Y;
  cin>>N>>K>>X>>Y;
  if(N<=K)cout<<N*X<<endl;
  else cout<<K*X+(N-K)*Y<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N, ans = 0;
vector<int> p_vec, pf_vec;

bool is_primitive(int n) {
    for (int j = 2; j * j <= n; j++) {
        if(n % j == 0) return false;
    }
    return true;
}

int main(void) {
    cin >> N;

    for (int i = 2; i <= N; i++) {
        if(is_primitive(i)){
            p_vec.push_back(i);
        }
    }
  
    for (int i = 0; i < p_vec.size(); i++) {
        int n = N;
        pf_vec.push_back(0);
        while(n > 1){
            n /= p_vec[i];
            pf_vec[i] += n;
        }
    }

	// p^2 * q^4 * r^4
    int p = 0, q = 0;
    for (int i = 0; i < pf_vec.size(); i++) {
        if (pf_vec.at(i) >= 2) p++;
        if (pf_vec.at(i) >= 4) q++;
    }
    ans += q * (q - 1) / 2 * (p - 2);
    
    // p^2 * q^24
    p = q = 0;
    for (int i = 0; i < pf_vec.size(); i++) {
        if (pf_vec.at(i) >= 2) p++;
        if (pf_vec.at(i) >= 24) q++;
    }
    ans += (p -1) * q;
    
    // p^4 * q^14
    p = q = 0;
    for (int i = 0; i < pf_vec.size(); i++) {
        if (pf_vec.at(i) >= 4) p++;
        if (pf_vec.at(i) >= 14) q++;
    }
    ans += (p -1) * q;
    
    // p^74
    p = 0;
    for (int i = 0; i < pf_vec.size(); i++) {
        if (pf_vec.at(i) >= 74) p++;
    }
    ans += p;

    cout << ans << endl;
}

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

N = int(input())
ans=0
for i in range(1,N+1,2):
    j = 1
    cnt=0
    while j <= int(i**0.5):
        if i%j==0:
            cnt+=1
            if i//j!=j:
                cnt+=1
        j+=1
    if cnt==8:
        ans+=1
print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define per(i,s,t) for(int i=((t)-1);i>=s;--i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define lepb(i,s,t) for(int i=(s);i>=(t);--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
#define mst(a,b) memset(a,b,sizeof(a))
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'
#define fi first
#define se second
#define sq(x) ((x)*(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int inf = 0x3f3f3f3f;
const ll inff = 4557430888798830399ll;
const db eps = 1e-10;
const db pi = acos(-1.0);
const ll mod = 1e9+7;

#define maxn 100005

map<ll,int> id;
int n,sz[maxn],p[maxn];
int fa(int n){return n==p[n]?n:p[n]=fa(p[n]);}
ll dis[maxn],dis1[maxn];vector<int> N[maxn];

void dfs(int u)
{
	for(auto v:N[u])dfs(v),dis[u]+=dis[v]+sz[v];
}

void dfs1(int u,ll d)
{
	dis1[u]=dis[u]+d;
	for(auto v:N[u])dfs1(v,d+dis[u]-(dis[v]+sz[v])+(n-sz[v]));
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int u,v;ll x,y;vector<pair<ll,int> > D,Z;vector<pii> E;
	cin>>n;
	repb(i,1,n){cin>>x;D.pb({x,i});id[x]=i;}
	sort(all(D));reverse(all(D));mst(sz,0);
	rep(i,0,sz(D)-1)
	{
		x=D[i].fi;u=D[i].se;sz[u]+=1;
		y=x-n+2*sz[u];v=id[y];
		if(v==0||y>=x){cout<<-1<<endl;return 0;}
		E.pb(mp(min(u,v),max(u,v)));sz[v]+=sz[u];N[v].pb(u);
	}
	repb(i,1,n)p[i]=i;sort(all(E));
	rep(i,0,sz(E))if(fa(E[i].fi)!=fa(E[i].se))p[fa(E[i].fi)]=fa(E[i].se);
	repb(i,1,n)if(fa(i)!=fa(1)){cout<<-1<<endl;return 0;}
	dfs(D.back().se);dfs1(D.back().se,0);
	repb(i,1,n)Z.pb({dis1[i],i});
	sort(all(Z));reverse(all(Z));
	if(Z!=D){cout<<-1<<endl;return 0;}
	rep(i,0,sz(E))cout<<E[i].fi<<" "<<E[i].se<<endl;
}

Measured memory_bytes: 22128
#include <iostream>
using namespace std;
int main(){
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (x+r<=W&&y+r<=H&&x-r>=0&&y-r>=0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
using namespace std;

ll a[1010], n, f[1010], pre[1010];
vector<int>ans;

void dfs(int x){
  if (!pre[x]){
    for (int i=1;i<x;++i) ans.push_back(1);
    return;
  }
  int p=pre[x], las=x-p;
  for (;las>2;las-=2) ans.push_back(p+2);
  ans.push_back(p+1);
  dfs(p);
}

int main(){
  cin>>n;
  for (int i=1;i<=n;++i) cin>>a[i];
  memset(f,-33,sizeof f);
  f[0]=0; f[1]=a[1];
  for (int i=2;i<=n;++i){
    f[i]=a[i]; pre[i]=0;
    for (int j=i&1;j<i;j+=2){
      if (f[j]+a[i]>f[i]){
        f[i]=f[j]+a[i];
        pre[i]=j;
      }
    }
  }
  
  int p=max_element(f+1,f+n+1)-f;
  cout<<f[p]<<endl;
  for (int i=n;i>p;--i) ans.push_back(i);
  dfs(p);
  cout<<ans.size()<<endl;
  for (vector<int>::iterator it=ans.begin();it!=ans.end();++it)
    cout<<*it<<endl;
}

Measured memory_bytes: 256