akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

	vvi kyoju(M, vi(2));

	REP(i, M) {
		cin >> kyoju[i][0] >> kyoju[i][1];
	}
	sort(ALL(kyoju));

	int ans = 0, right = 0;

	int maxr = 0;
	while(right < N) {
		REP(i, M) {
			if(kyoju[i][0] <= right+1) {
				maxr = max(maxr, kyoju[i][1]);
			}
		}
		if(maxr == right) {
			cout << "Impossible" << endl;
			return 0;
		} else {
			++ans;
			right = maxr;
		}
	}
	cout << ans << endl;

	return 0;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int s[8];
int l[8];
int n,a,b,c;
int ans=1e9;
int check(void){
    int sum=0;
    int a1=0,b1=0,c1=0;
    for(int i=0;i<n;i++){
        if(s[i]==1){
            if(a1!=0) sum+=10;
            a1+=l[i];
        }
        else if(s[i]==2){
            if(b1!=0) sum+=10;
            b1+=l[i];
        }
        else if(s[i]==3){
            if(c1!=0) sum+=10;
            c1+=l[i];
        }
    }
    if(a1==0 || b1==0 || c1==0) return 1e9;
    sum+=abs(a-a1)+abs(b-b1)+abs(c-c1);
    return sum;
}
int rec(int j){
    for(int i=0;i<4;i++){
        s[j]=i;
        if(j==n-1) ans=min(ans,check());
        else rec(j+1);
    }
}
int main(){
    cin>>n>>a>>b>>c;
    for(int i=0;i<n;i++) cin>>l[i];
    sort(l,l+n);
    rec(0);
    cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;

ll cnt[100001] = {};

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

    for (int i = 0; i < N; i++) {
        ll a, b;
        scanf("%lld %lld", &a, &b);
        cnt[a] += b;
    }

    for (int i = 1; i <= 100000; i++) {
        K -= cnt[i];
        if (K > 0) continue;
        cout << i << endl;
        break;
    }

    return 0;
}

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

def test(ans):
    f = True
    for i in range(1, n - 1):
        if ans[i] == 'S':
            if ans[i - 1] == 'S' and s[i] == 'o':
                ans += 'S'
            elif ans[i - 1] == 'S' and s[i] == 'x':
                ans += 'W'
            elif ans[i - 1] == 'W' and s[i] == 'o':
                ans += 'W'
            elif ans[i - 1] == 'W' and s[i] == 'x':
                ans += 'S'
        else:
            if ans[i - 1] == 'S' and s[i] == 'o':
                ans += 'W'
            elif ans[i - 1] == 'S' and s[i] == 'x':
                ans += 'S'
            elif ans[i - 1] == 'W' and s[i] == 'o':
                ans += 'S'
            elif ans[i - 1] == 'W' and s[i] == 'x':
                ans += 'W'

    # i = n-1
    if ans[n-1] == 'S' and s[n-1] == 'o':
        if ans[n-2] != ans[0]:
            f = False
    elif ans[n-1] == 'S' and s[n-1] == 'x':
        if ans[n-2] == ans[0]:
            f = False
    elif ans[n-1] == 'W' and s[n-1] == 'o':
        if ans[n-2] == ans[0]:
            f = False
    elif ans[n-1] == 'W' and s[n-1] == 'x':
        if ans[n-2] != ans[0]:
            f = False

    # i == 0
    if ans[0] == 'S' and s[0] == 'o':
        if ans[n-1] != ans[1]:
            f = False
    elif ans[0] == 'S' and s[0] == 'x':
        if ans[n-1] == ans[1]:
            f = False
    elif ans[0] == 'W' and s[0] == 'o':
        if ans[n-1] == ans[1]:
            f = False
    elif ans[0] == 'W' and s[0] == 'x':
        if ans[n-1] != ans[1]:
            f = False

    return ans, f


# SS
ans1, f1 = test('SS')
ans2, f2 = test('SW')
ans3, f3 = test('WW')
ans4, f4 = test('WS')

if f1:
    print(ans1)
elif f2:
    print(ans2)
elif f3:
    print(ans3)
elif f4:
    print(ans4)
else:
    print(-1)


Measured memory_bytes: 3828
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

bool A[100][100];

int main(){
  int W, H, N;
  cin >> W >> H >> N;
  for(int i=0; i<N; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    if(a == 1) {
      for(int p=0; p<x; p++)
	for(int q=0; q<H; q++)
	  A[p][q] = true;
    } else if(a == 2) {
      for(int p=x; p<W; p++)
	for(int q=0; q<H; q++)
	  A[p][q] = true;
    } else if(a == 3) {
      for(int p=0; p<W; p++)
	for(int q=0; q<y; q++)
	  A[p][q] = true;
    } else if(a == 4) {
      for(int p=0; p<W; p++)
	for(int q=y; q<H; q++)
	  A[p][q] = true;
    }
  }
  int count = 0;
  for(int p=0; p<W; p++)
    for(int q=0; q<H; q++)
      if(!A[p][q])
	count++;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
local min = 100
local sum = 0
local n = io.read("*n")
for i = 1, n do
  local a = io.read("*n")
  sum = sum + a
  if a % 10 ~= 0 then
    min = math.min(a, min)
  end
end
if sum % 10 ~= 0 then
  print(sum)
else
  if min == 100 then
    print(0)
  else
    print(sum - min)
  end
end


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
	int n;
	cin >> n;
	string ans = "Yes";
	vector<int> h(n,0);

	int num;
	for (int i = 0; i < n; i++){
		cin >> num;
		h[i] = num;
	}

	int max = 0;
	for (int i = 0; i < n; i++){
		if (max > h[i]+1){
			// cout << h[i] << max << endl;
			ans = "No";
			break;
		};
		if (h[i] > max){
			max = h[i];
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
import math


def C(_mid):
    tmp = [x - B * _mid for x in h]
    explode_count = 0
    for i in range(0, len(tmp)):
        if tmp[i] <= 0:
            pass
        else:
            explode_count += math.ceil(tmp[i] / (A - B))

    if _mid < explode_count:
        return True
    else:
        return False


if __name__ == '__main__':
    N, A, B = list(map(int, input().split()))

    h = [int(input()) for i in range(N)]

    lb = 0
    ub = 1000000000
    while ub - lb > 1:
        mid = int((lb + ub) / 2)
        if C(mid):
            lb = mid
        else:
            ub = mid

    print(ub)


Measured memory_bytes: 11044
def answer(a: int, b: int, c: int, x: int) -> int:
    count = 0
    for i in range(0, a + 1):
        for j in range(0, b + 1):
            for k in range(0, c + 1):
                if x == i * 500 + j * 100 + k * 50:
                    count += 1

    return count


def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())
    print(answer(a, b, c, x))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9148
X,K,D = map(int,input().split())
X = abs(X)
if X-K*D >= 0:
    print(X-K*D)
    exit()
if X%D <= D-X%D:
    a = K-(X//D)
    X = X%D
else:
    a = K-(X//D + 1)
    X = D-X%D
if a%2 == 1:
    X = D-X
print(X)

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

int main() {
  long long A,ans;
  cin >>A;
  togo:
 for(int i=2;i<sqrt(A);i++){
   if(A%i==0){
     A++;
     goto togo;
   }
 }
  cout<<A<<endl;
}

Measured memory_bytes: 256
#include <iostream>

 int main() {

	 int n;
	 int m;
	 int x = 1;

	 std::cin >> n >> m;

	 for (int i = 0; i < m; ++i) {
		 x *= 2;
	 }

	 std::cout << x * (((n - m) * 100) + (m * 1900)) << std::endl;

	 return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  ll n,k;cin>>n>>k;
  vll dp(n+1,-1);
  
  rep(i,0,k){
    ll a;cin>>a;
    dp[a]=0;
  }
  if(dp[1]!=0){dp[1]=1;}
  dp[0]=1;
  rep(i,2,n+1){
    if(dp[i]==0)continue;
    dp[i]=dp[i-1]+dp[i-2];
    dp[i]%=MOD;
    
  }
  cout<<dp[n]<<endl;
}



Measured memory_bytes: 4032
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  const int N=2000;
  for(int n,t=1;cin>>n,n;t++){
    int dp[N+1];
    fill(begin(dp),end(dp),1<<29);
    dp[0]=0;
    int u[N+1]={};
    bool o=false;
    while(n--){
      int c;
      cin>>c;
      o|=c==1;
      for(int i=c;i<=N;i++){
	dp[i]=min(dp[i],dp[i-c]+1);
	u[i]=c;
      }
    }
    bool f=false;
    for(int i=1;i<=N;i++){
      f|=dp[i]-dp[i-u[i]]!=1;
    }
    cout<<"Case #"<<t<<": "<<(!o?"Cannot pay some amount":
			      f?"Cannot use greedy algorithm":
			      "OK")<<endl;
  }
}

Measured memory_bytes: 1184
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	string s;
	cin >> s;
	
	if(s[s.size()-1]=='s') cout << s << "es" << endl;
	else cout << s << 's' << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin >> a;
	int arr[a + 50][100] = {0};
	int cnt[100] = {0};
	for(int i=0; i<a; i++)
	{
		long long temp;
		cin >> temp;
		for(long long j=60; j >= 0; j--)
		{
			long long hehe = pow(2, j);
			if(temp >= hehe)
			{
				arr[i][j] = true;
				cnt[j] ++;
				temp -= hehe;
			}
		}
	}
	long long ans = 0, mod = 1e9 + 7, temp;
	for(int i=0; i<a; i++)
	{
		temp = 1;
		for(int j=0; j<=60; j++)
		{
			if(arr[i][j])
			{
				ans = (ans + ((a - cnt[j]) * temp) % mod + mod) % mod;
			}
			temp = temp * 2 % mod;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 117504
H, W = map(int, input().split())

S = [list(input()) for i in range(H)]

for line in S:
    line.insert(0, ".")
    line.append(".")
S.insert(0, ["."]*(W+2))
S.append(["."]*(W+2))

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == ".":
            count = S[i-1][j-1:j+2].count("#") + S[i][j-1:j+2].count("#") + S[i+1][j-1:j+2].count("#")
            S[i][j] = count

for i in range(1, H+1):
    for j in range(1, W+1):
        print(S[i][j], end="")
    print("")

Measured memory_bytes: 3444
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e5 + 7;
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e18;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

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

int n;
vector <int> gr[N];

void solve() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		gr[u].push_back(v);
		gr[v].push_back(u);
	}
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		gr[i].push_back(0);
		sort(all(gr[i]));
		while (gr[i].back() > i)
			gr[i].pop_back();
		ans += 1LL * i * (n - i + 1);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < size(gr[i]); j++)
			ans -= 1LL * (gr[i][j] - gr[i][j - 1]) * (size(gr[i]) - j) * (n - i + 1);
	}
	cout << ans;
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 15184
from collections import deque

s = deque(input())
q = int(input())
query = [input().split() for _ in range(q)]

reverse = False
for i in query:
    if len(i) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if reverse:
            if i[1] == '1':
                s.append(i[2])
            else:
                s.appendleft(i[2])
        else:
            if i[1] == '1':
                s.appendleft(i[2])
            else:
                s.append(i[2])
if reverse:
    s = reversed(s)
    s = ''.join(s)
    print(s)
else:
    s = ''.join(s)
    print(s)

Measured memory_bytes: 44532
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;
    ll z, n, m, k, i, j, x, y, p=0, s=0, h, f=0;
    cin>>n>>m;
    cin>>k;
    ll a[k];
    vl v[n];
    for(i=0; i<k; i++){
        cin>>a[i];
    }
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            v[i].pb(0);
        }
    }
    x=0, y=0;
    for(z=0; z<k; z++){
        p=a[z];
        for(i=x; i<n; i++){
            f=0;
            for(j=y; j<m; j++){
                v[i][j]=z+1;
                p--;
                if(p==0){
                    f=1;
                    break;
                }
            }
            if(f==1 && j==m-1){
                x++;
                y=0;
                break;
            }
            else if(f==1){
                y=j+1;
                break;
            }
            else if(j==m){
                x++;
                y=0;
            }
        }
    }
    for(i=0; i<n; i++){
        if(i%2==1){
            reverse(v[i].begin(), v[i].end());
        }
    }
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            cout<<v[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N, K;
ll DP[110][100010] = {};
ll SDP[110][100010] = {};

int main() {
    cin >> N;
    cin >> K;
    int a[N];
    REP(i, N) {
        cin >> a[i];
    }
    REP(i, N) {
        SDP[i][0] = 0;
    }
    DP[0][0] = 1;//累積.SDP[0][1] = DP[0][0]
    REP(i, N) {
        REP(j, K+1) {
            SDP[i][j+1] = SDP[i][j] + DP[i][j];
        }
        REP(j, K+1) {
            if (j-a[i] >= 0) {
                DP[i+1][j] = SDP[i][j+1] - SDP[i][j-a[i]];
                DP[i+1][j] %= MOD;
            } else {
                DP[i+1][j] = SDP[i][j+1] - SDP[i][0];
                DP[i+1][j] %= MOD;
            }
        }
    }
    cout << DP[N][K];

}

Measured memory_bytes: 162048
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	UnionFind uf(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		uf.unionSet(a,b);
	}
	int co=0;
	set<int>se;
	rep(i,n)se.insert(uf.root(i));
	co=se.size()-1;
	co*=2;
	if(se.size()==1){
		cout<<0<<endl;
		return 0;
	}
	vvi rt(n);
	rep(i,n){
		int t=uf.root(i);
		rt[t].pb(in[i]);
	}
	rep(i,n)sort(all(rt[i]));
//	rep(i,n){rep(j,rt[i].size())cout<<" "<<rt[i][j];cout<<endl;}
	int out=0;
	rep(i,n)if(rt[i].size()){
		out+=rt[i][0];
		co--;
	}
	vi sor;
	rep(i,n)loop(j,1,rt[i].size())sor.pb(rt[i][j]);
	sort(all(sor));
	if(co>sor.size()){
		cout<<"Impossible"<<endl;
	}else{
		rep(i,co)out+=sor[i];
		cout<<out<<endl;
	}
}










Measured memory_bytes: 12032
#include <stdio.h>

void swap (int *num1,int *num2)
{
	int num;
	num = *num1;
	*num1 = *num2;
	*num2 = num;
}

int main (void)
{
	int a,b,c;
	int ans1,ans2,ans3;
	char str[64];
  
	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d %d %d",&a,&b,&c);
	
	ans1 = a+b;
	ans2 = b+c;
	ans3 = c+a;
	
	if(ans2>ans3)
	{
		swap(&ans2,&ans3);
	}
	if(ans1>ans2)
	{
		swap(&ans1,&ans2);
	}
	
	printf("%d",ans1);
	return 0;
}



Measured memory_bytes: 128
def solve():
    MOD = 998244353

    N, S = map(int, input().split())
    As = list(map(int, input().split()))

    dp = [[0]*(3) for _ in range(S+1)]
    dp[0][0] = 1
    for A in As:
        for sm in reversed(range(S+1)):
            dp[sm][2] += dp[sm][1] + dp[sm][0]
            if sm-A >= 0:
                dp[sm][2] += dp[sm-A][1] + dp[sm-A][0]
            dp[sm][2] %= MOD
            dp[sm][1] += dp[sm][0]
            if sm-A >= 0:
                dp[sm][1] += dp[sm-A][1] + dp[sm-A][0]
            dp[sm][1] %= MOD

    print(dp[S][2])


solve()


Measured memory_bytes: 42092
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char) 
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
    
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let l: f64 = read();
  println!("{}", (l / 3f64).powf(3f64));
}

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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	ll n, m;
	ll a;
	string s;
	ll l_ans = 0;
	double d_ans = 0;
	
	cin >> n >> m;

	if (m < 2) {
		l_ans = 0;
	}
	else if (2 * n <= m) {
		l_ans = n + (m - 2 * n) / 4;
	}
	else {
		l_ans = m / 2;
	}

	cout << l_ans << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(15);

	solve_abc_c();

	return 0;
}


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

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

  long long n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  vector<ll> dp(n);
  for(int i=0;i<n;i++){
    dp[i]=-1;
  }
  for(int i=0;i<n;i++){
    long long l=-1,r=n-1;
    while(r-l>1ll){
      long long mid=(r+l)/2ll;
      if(dp[mid]<a[i]){
        r=mid;
      }else{
        l=mid;
      }
    }
    dp[r]=a[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(dp[i]==-1) break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
n = int(input())

l = []
for i in range(n):
  x,y = map(str,input().split())
  l.append((x,y, i))


L = []

for i in range(n):
  L.append((l[i][0], int(l[i][1]), l[i][2]))

L.sort(key = lambda L:(L[0],-L[1]))


for i in range(n):
  print(L[i][2] + 1)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;

int main(){

    string s; cin >> s;
    int ok = 1;
    for(int i = 0; i+1 < s.size(); i++)
        if(s[i] == s[i+1])
            ok = 0;
    if(ok) cout << "Good" << endl;
    else cout << "Bad" << endl;

	return 0;
}


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


int main(){
    int koku, suu, ei, ri;
    int sum_a, sum_b;

    cin >> koku >> suu >> ei >> ri;
    sum_a = koku + suu + ei + ri;

    cin >> koku >> suu >> ei >> ri;
    sum_b = koku + suu + ei + ri;

    if (sum_a > sum_b) cout << sum_a << endl;
    else cout << sum_b << endl;


    return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const llong MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
// Calculate "pow(N,P) % Mod"
// NOTE:もうちょっといい感じの実装がしたい。そもそもMODの計算を全てクラスかなんかでやりたい。
long long int repeat_squared(long long int N,long long int P,long long Mod) {
	if (P == 0)
		return 1;
	if (P % 2 == 0) {
		long long int sqrt_N = repeat_squared(N, P / 2, Mod);
		return sqrt_N * sqrt_N % Mod;
	}
	return (N * repeat_squared(N, P - 1, Mod)) % Mod;
}
int main() {
	/*llong ans0 = repeat_squared(6, MOD - 2, MOD);
	llong ans1 = modpow(6, MOD - 2, MOD);
	cout << ans0 << " " << ans1 << endl;*/


	llong n, a, b;
	cin >> n >> a >> b;
	llong Xa = 1, Ya = 1, Xb = 1, Yb = 1;
	for (llong i = 0; i < a; ++i) {
		Xa *= (n - i);
		Xa %= MOD;
		Ya *= (a - i);
		Ya %= MOD;
	}
	for (llong i = 0; i < b; ++i) {
		Xb *= (n - i);
		Xb %= MOD;
		Yb *= (b - i);
		Yb %= MOD;
	}
	llong nca_mod = (Xa * repeat_squared(Ya, MOD - 2, MOD)) % MOD;
	llong ncb_mod = (Xb * repeat_squared(Yb, MOD - 2, MOD)) % MOD;
	llong pow2n_mod = repeat_squared(2, n, MOD);

	llong ans = (pow2n_mod - 1) % MOD;
	ans = (ans - nca_mod) % MOD;
	ans = (ans - ncb_mod) % MOD;
	if (ans < 0)
		ans += MOD;
	// 2 ** n -1 - n C a - nCb
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int can_view(int N,int *H){
  int i,j,result=0,frag=1; 
  for(i=0;i<N;i++){
    frag = 1;
    if(i==0){
      result++;
    }else{
      for(j=i-1;j>=0;j--){
	if(H[j] > H[i]){
	  frag = 0;
	  break;
	}
      }
      if(frag){
	result ++;
      }
    }
  }
  return result;
}
  


int main(){
  int N,i;
  int H[20];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&H[i]);
  }
  printf("%d\n",can_view(N,H));
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import fractions as f
from functools import reduce

def lcm2(x,y):
    return (x * y)//f.gcd(x,y)

def count2f(a):
    i=0
    while a%2==0:
        a//=2
        i+=1
    return i


def solve(N: int, M: int, a: "List[int]"):
    for i in range(N):
        a[i]//=2

    st=count2f(a[0])
    a[0]//=2**st
    for i in range(1, N):
        sti=count2f(a[i])
        a[i]//=2**st
        if st!=sti:
            print(0)
            return
    M//=2**st

    l=1
    for i in range(N):
        l=lcm2(l, a[i])
        if l>10**9:
            print(0)
            return

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


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 17668
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
#define ENDL "\n"
typedef long long int llint;
int intinput()
{
  int x;
  scanf("%d", &x);
  return x;
}

int checked[1000][1000];

int main()
{
  llint ans = 0;
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  for (int r = 0; r <= N; r += R)
  {
    for (int g = 0; g <= N; g += G)
    {
      int b = N - r - g;
      if (b >= 0 && (b % B) == 0)
      {
        ans++;
      }
    }
  }
  cout << ans << ENDL;
}


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

int main(){
  int S, h, m, s, ho;
  cin>>S;
  h = S / 3600;
  ho = S % 3600;
  m = ho / 60;
  s = ho % 60;
  cout<< h << ":" << m << ":" << s <<endl;
  return 0;
}



Measured memory_bytes: 3076
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
#define MAX 510000
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}
 
int main(){
    COMinit();
 
    ll n, k;
    cin >> n >> k;
    ll cnk = COM(n, k);
 
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
 
    sort(ALL(a));

    ll ans = 0;
    rep(i, n){
        ll kake = cnk - COM(i+1, k) - COM(n-1-i, k);
        kake %= MOD;
        ans += mod((a[i+1]-a[i])*kake, MOD);
        ans %= MOD;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair/n#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  ll n=s.size();
  ll ans=0;
  char now='!';
  now=s[0];
  for(int i=1;i<n;i++){
    if(now==s[i]){
      if(n-1==i){
	i++;
      }else{
	ans++;
	i++;
	now='!';
      }
    }else{
      ans++;
      now=s[i];
    }
  }
  cout<<ans+1<<endl;
  return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n=0;
    scanf("%d", &n);
    string s;
    cin>>s;
    int max=0;
    for(int i=1;i<n-1;i++){
        int sum=0;
        int arr[150]={};
        int mat[150]={};
        for(int j=0;j<i;j++){
            arr[s[j]]+=1;
        }
        for(int j=i;j<n;j++){
            mat[s[j]]+=1;
        }
        for(int j=0;j<150;j++){
            if (arr[j]!=0 && mat[j]!=0){
                sum+=1;
            }
        }
        if (sum>max){
            max=sum;
        }
    }
    printf("%d", max);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] Arguments) throws IOException 
	{
		BufferedReader BR = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer ST = new StringTokenizer(BR.readLine());
		long N = Long.parseLong(ST.nextToken()), K = Long.parseLong(ST.nextToken());
		if (K > N)
		{
			N = Math.min(Math.abs(N - K), N);
			System.out.println(N);
		}
		else if (N > K)
		{
			N %= K;
			N = Math.min(Math.abs(N - K), N);
			System.out.println(N);
		}
		else //if (N == K)
		{
			System.out.println("0");
		}
	}
}


Measured memory_bytes: 20564
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;

int main() {
	string O, E, str;
	cin >> O >> E;
	if (O.size() - E.size() == 0) {
		for (int i = 0;i < O.size();i++) {
			str += O[i];
			str += E[i];
		}
		cout << str << endl;
		return 0;
	}
	if (O.size() - E.size() == 1) {
		for (int i = 0;i < E.size();i++) {
			str += O[i];
			str += E[i];
		}
		str += O[O.size() - 1];
		cout << str << endl;
		return 0;
	}
	return 0;
}

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int ans = 0;
  for ( int i = 0; i <= A ; i++){
    for ( int j = 0 ; j <= B ; j++){
      for (int k = 0 ; k <= C ; k++){
        int total = 500 * i + 100 * j + 50 * k;
        if ( X == total) ans++;
      }
    }
  }
  cout << ans << endl;  
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  string S;
  while (cin >> N >> S) {
    int res = 0;
    for (int i = 0; i + 3 <= N; i++) {
      string sub = S.substr(i, 3);
      if (sub == "ABC") ++res;
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
    // int t;
    // cin>>t;
    // while(t--){
    // }
    ll n,k;
    cin>>n>>k;
    ll a[n],t,sum=0;
    for(int i=0;i<k;i++)
    {
        cin>>t;
        sum+=t;
    }
    // cout<<s
    if(sum>=n)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 384
<?php
list($x) = ints();
echo intdiv(lcm($x, 360), $x);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 最大公約数（2つ）
function gcd($m, $n)
{
    if (!$n) return $m;
    return gcd($n, $m % $n);
}

// 最大公約数（3つ以上）
function gcdAll($arr)
{
    $gcd = array_pop($arr);
    foreach ($arr as $a) {
        $gcd = gcd($gcd, $a);
    }
    return $gcd;
}

// 最小公倍数（2つ）
function lcm($m, $n)
{
    return (int) ($m / gcd($m, $n) * $n); // オーバーフローしないように先に割り算
}

// 最小公倍数（3つ以上）
function lcmAll($arr)
{
    $lcm = array_pop($arr);
    foreach ($arr as $a) {
        $lcm = lcm($lcm, $a);
    }
    return $lcm;
}


Measured memory_bytes: 16144
import java.util.Scanner;

public class Main {

    private static final int MOD = 1000000007;
    private static long[] fac = new long[1000000];
    private static long[] finv = new long[1000000];
    private static long[] inv = new long[1000000];

    public static void nCkInit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < 1000000; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[(MOD % i)] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    public static long nCk(int n, int k) {
        if (n < k) {
            return 0;
        }
        if (n < 0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        if ((x + y) % 3 != 0) {
            System.out.println(0);
            return;
        }
        int n = (2 * y - x) / 3;
        int m = (2 * x - y) / 3;
        nCkInit();
        System.out.println(nCk(n + m, n));
    }

}


Measured memory_bytes: 46676
import sys
N=int(input())
H=list(map(int,input().split()))
A=0
for i in range(N-1):
    if H[i]-H[i+1]>1 :
        print('No')
        sys.exit()
    elif H[i]-H[i+1]==1:
        H[i+1]=H[i+1]+1
    else:
        continue
print('Yes')

Measured memory_bytes: 15020
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define ld long double
    #define MOD 1000000007
    #define mod9 1000000009
    #define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #define mp make_pair
    #define pb push_back
    #define ct ll t;cin>>t;while(t--)
    #define bi begin()
    #define ei end()
    #define fi first 
    #define se second  
    #define foe(i,a,b) for(ll i=a;i<b;i++)
    #define rfoe(i,a,b) for(ll i=a;i>=0;i--)
    #define sz(s) s.size() 
    #define mem(a,s) memset(a,s,sizeof(a)) 
    #define all(v) v.bi,v.ei
    #define MAX             8000000000000000064LL
    #define MIN            -8000000000000000064LL   

    typedef pair<ll,ll> pii;
    
    ll add(ll a, ll b){return (a%MOD + b%MOD + ((MAX)/MOD)*MOD)%MOD;}
    ll sub(ll a, ll b){return (a%MOD - b%MOD + ((MAX)/MOD)*MOD)%MOD;}
    ll mul(ll a, ll b){return ((a%MOD)*(b%MOD) + ((MAX)/MOD)*MOD)%MOD;}
    ll lcm(ll a,ll b){return(a*b)/__gcd(a,b);}
    ll fact[1000007 ]={0};
    ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
    y=y>>1;x=(1ll*x*x)%MOD;} return res;}
    void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%MOD;}
    ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],MOD-2)))%MOD; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res;}
    ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
    int const N=2e5+9;
    ll const INF = 2e18+5;
    ll dx[8]={0,0,1,-1,1,1,-1,-1};
    ll dy[8]={1,-1,0,0,-1,1,-1,1};
    long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = mul(res,a);
        a = mul(a,a);
        b >>= 1;
    }
    return res;
}
    void solve()
    {  
        ll n;
        cin>>n;
        ll a[n];
        vector<ll>b(n);
        foe(i,0,n)cin>>a[i];
        foe(i,0,n)cin>>b[i];
        reverse(all(b));
        ll l=-1,r=-1,c=-1;
        foe(i,0,n)
        {
            if(a[i]==b[i])
            {
                c=a[i];
                if(l==-1)
                {
                    l=i;
                }
                r=i;
            }
        }
        if(c!=-1)
        {
            foe(i,0,n)
            {
                if(a[i]!=c&&b[i]!=c&&l<=r)
                {
                    swap(b[i],b[l]);
                    l++;
                }
            }
        }
        if(l<=r&&c!=-1)
        {
            cout<<"No\n";
        }
        else
        {
            cout<<"Yes\n";
            foe(i,0,n)cout<<b[i]<<" ";
        }
        
    }
    int main()
    {
        fast
        // facto();
        // Sieve();
    //    ct    
        { 
            solve();
        }
    }


Measured memory_bytes: 6352
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 2e5+5;
ll a[M];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		a[i] += a[i-1];
	ll ans = 1e18;
	for(int i=1;i<n;i++)
	{
		ans = min(ans, abs(a[n]-2*a[i]));
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5036
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x[] = new int[n];
		for(int i=0; i<n; i++){
			x[i]  = sc.nextInt();
		}
		int y[] = new int[m];
		for(int i=0; i<m; i++){
			y[i]  = sc.nextInt();
		}

		long yoko = 0;
		for(int i=0; i<n; i++){
			yoko += (long)i * x[i];
			if(yoko>=0){
				yoko %= 1000000007;
			}else{
				yoko = - (-yoko % 1000000007);
			}
			yoko -= (long)(n-i-1) * x[i];
			if(yoko>=0){
				yoko %= 1000000007;
			}else{
				yoko = - (-yoko % 1000000007);
			}
		}
		long tate = 0;
		for(int i=0; i<m; i++){
			tate += (long)i * y[i];
			if(tate>=0){
				tate %= 1000000007;
			}else{
				tate = - (-tate % 1000000007);
			}
			tate -= (long)(m-i-1) * y[i];
			if(tate>=0){
				tate %= 1000000007;
			}else{
				tate = - (-tate % 1000000007);
			}
		}

		long ans = yoko * tate;
		
		ans %= 1000000007;
		
		System.out.print(ans);
	
	}

}


Measured memory_bytes: 67668
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <stdexcept>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>
 
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
 
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define fill(x, y) memset(x, y, sizeof(x))
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define itn int
#define re return
#define prev PREV
#define next NEXT
 
#define sz(x) ((int)x.size())
 
const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int maxn = 2*1000005;
const int mod = 1000000007;
 
#define FILENAME ""
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector <double> dp(n + 1);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        double x;
        cin >> x;
        for (int j = i + 1; j >= 0; j--) {
            dp[j] = (j == 0 ? 0 : dp[j - 1]*x) + dp[j]*(1 - x);
        }
    }
    double ans = 0;
    for (int i = 0; i <= n; i++) {
        int tails = n - i;
        if (i > tails) {
            ans += dp[i];
        }
    }
  	cout << fixed << setprecision(10);
    cout << ans;
    return 0;
}

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

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n;
    cin >> n;

    ll ma = 0;
    map<ll, ll> d;
    rep(i, 0, n){
        ll tmp;
        cin >> tmp;
        if(i == 0 && tmp != 0){
                cout << 0 << endl;
                return 0;
        }
        if(i != 0 && tmp == 0){
                cout << 0 << endl;
                return 0;
        }
        d[tmp]++;
        ma = max(ma, tmp);
    }

    ll sum = 0;
    rep(i, 0, ma + 1){
        if(i == 0){
            sum = 1;
        }else{
            if(d[i-1] == 0){
                cout << 0 << endl;
                return 0;
            }else{
                rep(j, 0, d[i]){
                    ll tmp = d[i-1] % 998244353;
                    sum *= tmp;
                    sum %= 998244353;
                }
            }
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 6528
import java.util.*;
import java.util.stream.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class Main {

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

	static void solve() {
		while (true) {
			int x = in.nextInt();
			int y = in.nextInt();
			if (x == 0 && y == 0) break;
			if (x < y)
				out.println(x + " " + y);
			else
				out.println(y + " " + x);
		}
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}


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

using namespace std;

bool IsPrime(int num)
{
    for (int i = 3; i*i <= num; i+=2){
      if(num%i == 0) return false;
    }

    return true;
}

int main() {
#ifdef  DEBUG
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif  // for local.
  int x; cin >> x;
  if (x == 2) {
    cout << 2 << endl;
    return 0;
  }
  
  if (x % 2 == 0) x++;
  for (int i = x; ; ) {
    if (IsPrime(i)) {
      cout << i << endl;
      return 0;
    } 
    i += 2;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  long long H, W; cin >> H >> W;
  long long ans = (H * W + 1) / 2;
  if (H == 1 || W == 1){
    ans = 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256