akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a = map(int,input().split())
 
x = sorted(a)
ans = 1
for i in x:
    ans *= i
    if(ans == 0):
        break
    if(ans > 1e18):
        break
if(ans > 1e18):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 21600
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
typedef long long ll;
typedef double db;
const int MX=100005;
const int mod=1000000007;
const int inf=1e9;
int dp[MX],a[MX];
int main()
{
    FasterIO;
    int i,n;
    cin>>n;
    for(i=1;i<=n;i++)cin>>a[i];
    for(i=2;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),i!=2?dp[i-2]+abs(a[i]-a[i-2]):123456789);
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<stdlib.h>
#include<time.h>
#include<assert.h>
using namespace std;
string s;
int main(){
    cin>>s;
    s[0]='2';
    s[1]='0';
    s[2]='1';
    s[3]='8';
    cout<<s<<"\n";
    return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}


/*{
  }*/

class UnionFind
{
public:
  int n;
  vector<int> par, rnk, siz;

  UnionFind(int n_)
  {
    n = n_;
    par.resize(n);
    rnk.resize(n);
    siz.resize(n);
    for(int i = 0; i < n; i++){
      par[i] = i;
      rnk[i] = 0;
      siz[i] = 1;
    }
  }

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

  void unite(int x, int y)
  {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rnk[x] < rnk[y]){
      par[x] = y;
      siz[y] += siz[x];
    }else{
      par[y] = x; 
      siz[x] += siz[y];
      if(rnk[x] == rnk[y]) rnk[x]++;
    }
  }

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

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

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

//constexpr int mod = 1e9+7;
//constexpr int inf = 1<<30;

signed main(){
  int n, k, l;
  cin >> n >> k >> l;

  UnionFind uf1(n), uf2(n);
  rep(i, 0, k){
    int p, q;
    cin >> p >> q;
    uf1.unite(p-1, q-1);
  }

  rep(i, 0, l){
    int r, s;
    cin >> r >> s;
    uf2.unite(r-1, s-1);
  }

  map<P, int> cnt;
  rep(i, 0, n){
    cnt[P(uf1.find(i), uf2.find(i))]++;
  }

  rep(i, 0, n){
    cout << cnt[P(uf1.find(i), uf2.find(i))] << " \n"[i == n-1];
  }

  return 0;
}



Measured memory_bytes: 21120
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0),cin.sync_with_stdio(0),cout.tie(0),cout.sync_with_stdio(0);
	string s;
	cin>>s;
	if(s[0]==s[1] && s[1]==s[2])
		cout<<"No";
		else cout<<"Yes";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);
using P = pair<int,int>;
int main(){
    int n;
    cin >> n;
    vector<vector<P>> X(n);
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        for(int j=0;j<a;j++){
            int x,y;
            cin >> x >> y;
            x--;
            X[i].push_back(make_pair(x,y));
        }
    }
    int ans = 0;
    for (int bit = 0; bit < (1<<n); ++bit) {
        int cnt = 0;
        bitset<15> s(bit);
        for(int i=0;i<n;i++){
            if(s[i]) cnt++;
        }
        bool ok = true;
        //cout << s << endl;
        for(int i=0;i<n;i++){
            if(s[i]){
                for(int j=0;j<X[i].size();j++){
                    if(X[i][j].second == 1){
                        if(!s[X[i][j].first]) ok = false;
                    }
                    if(X[i][j].second == 0){
                        if(s[X[i][j].first]) ok = false;
                    }
                }
            }   
                   
        }
        if(ok) ans = max(ans,cnt);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
using namespace std;
#define FOR(i,n,F) for(int i = n;i < F;i++)

int N;


int main() {
	cin >> N;
	cout << ((N % 2 == 0 ? pow(N / 2, 2) : (N - 1) / 2 * (((N - 1) / 2) + 1))) << "\n";
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N, P[3], T[8];
int ans = 1145141919;

int main(){
    cin >> N;
    for(int i = 0; i < 3; i++)cin >> P[i];
    for(int i = 0; i < N; i++)cin >> T[i];
    for(int b = 0; b < (1 << (2 * N)); b++){
        int tmp = 0;
        int t[3] = {};
        for(int i = 0; i < N; i++){
            int p = 3 & (b >> (i*2));
            if(p < 3){
                if(t[p])tmp += 10;
                t[p] += T[i];
            }
        }
        for(int i = 0; i < 3; i++)tmp += abs(t[i] - P[i]);
        if(t[0] && t[1] && t[2])chmin(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
k = int(input())
s = input()

if k >= len(s):
    print(s)

else:
    for i in range(k):
        print(s[i], end = "")

    print("...")


Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 5100000;
const ll MOD = 1e9 + 7;

const double PI=3.14159265358979323846;


long long fac[MAX], finv[MAX], inv[MAX];

vector<double> cx, cy, c;
 ll MM = 1e12;

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;
    }
}

long long 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 modinv(ll a) {
    ll b = MOD, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

ll modpow(ll x, ll n) {
  ll ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= MOD;
    (x *= x) %= MOD;
    n >>= 1;
  }
  return ret;
}

struct Eratos {
    vector<int> primes;
    vector<bool> isprime;
    vector<int> min_factor;

    Eratos(int MAX) : primes(),
                      isprime(MAX+1, true),
                      min_factor(MAX+1, -1) {
        isprime[0] = isprime[1] = false;
        min_factor[0] = 0, min_factor[1] = 1;
        for (int i = 2; i <= MAX; ++i) {
            if (!isprime[i]) continue;
            primes.push_back(i);
            min_factor[i] = i;
            for (int j = i*2; j <= MAX; j += i) {
                isprime[j] = false;
                if (min_factor[j] == -1) min_factor[j] = i;
            }
        }
    }

    // prime factorization
    vector<pair<int,int>> prime_factorize(int n) {
        vector<pair<int,int> > res;
        while (n != 1) {
            int prime = min_factor[n];
            int exp = 0;
            while (min_factor[n] == prime) {
                ++exp;
                n /= prime;
            }
            res.push_back(make_pair(prime, exp));
        }
        return res;
    }
};

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

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

  

struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y); 
        if (rx == ry) return; 
        par[rx] = ry; 
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    string str;
    cin >> str;
    if(str == "ABC") cout << "ARC";
    else cout << "ABC";
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
	int a,b,N,s[105],f[105];
	cin >> a>>b>>N;
	for (int i = 0; i < N; i++){
		cin >> s[i] >> f[i];
		if (f[i]>a&&s[i]<b){
			cout << 1 << endl;
			return 0;
		}
		
	} 
	cout << 0<<endl;
	return 0;
}




Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int mm[9];
vector<int>cs[35];
int sai(int n,int mx){
  if(mx<=0){
    return 1;
  }
  int fl=0;
  for(int i=0;i<cs[n].size();i++){
    if(mm[cs[n][i]]==0){
      mm[cs[n][i]]=1;
      fl+=sai(cs[n][i],mx-1);
      mm[cs[n][i]]=0;
    }
  }
  return fl;
}
int main(){
  int n,m;
  cin>>n>>m;
  int a,b;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    cs[a].push_back(b);
    cs[b].push_back(a);
  }
  mm[1]=1;
  cout<<sai(1,n-1)<<endl;;
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstdlib>
#define INF 1000000
using namespace std;
typedef pair<int,int> P;
int H,W,N;
char field[1000][1000];
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
int d[1000][1000];
int ans=0;

void bfs(int sx,int sy,int n) {
  int x,y;
  queue<P> que;
  for(int i=0;i<H;i++) {
    for(int j=0;j<W;j++) {
      d[i][j] = INF;
    }
  }
  que.push(P(sx,sy));
  d[sx][sy] = 0;

  while(!que.empty()) {
    P p = que.front();que.pop();
    x = p.first;y = p.second;
    if(field[x][y] == n+'1') break; //???
    for(int i=0;i<4;i++) {
      int nx = x+dx[i],ny = y+dy[i];
      if(0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] != 'X' && d[nx][ny] == INF) {
	que.push(P(nx,ny));
	d[nx][ny] = d[x][y]+1;
      }
    }
  }

  ans += d[x][y];
  if(n < N-1)
    bfs(x,y,n+1);
  else
    return;
}

void solve() {
  for(int i=0;i<H;i++) {
    for(int j=0;j<W;j++) {
      if(field[i][j] == 'S') {
	bfs(i,j,0);
	cout << ans << endl;
	return;
      }
    }
  }
}

int main() {
  string str;
  cin >> H >> W >> N;
  getline(cin,str);
  for(int i=0;i<H;i++) {
    getline(cin,str);
    for(int j=0;j<W;j++) {
      field[i][j] = *str.substr(j,1).c_str();
    }
  }
  solve();
}

Measured memory_bytes: 5776
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
void solve(){
	int n;
	cin >> n;
	int cnt = 1;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		if (x == cnt) cnt++;
	}
	if (cnt == 1) cout << -1;
	else cout << n - cnt + 1;
}
int main(){
	speed;
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int h[] = new int[n];
		String str[] = br.readLine().split(" ");

		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(str[i]);
		}

		int res = 0;
		while (true) {
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			}
			if (max == 0)
				break;

			int i = 0;
			while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 32640
local mod = 1000000007
local mfl = math.floor
local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end
local n = io.read("*n")
local t = {}
for i = 1, n do t[i] = {io.read("*n"), 1} end
for i = 1, n do t[i + n] = {io.read("*n"), 2} end
table.sort(t, function(x, y) return x[1] < y[1] end)
local ret = 1
local state = 0
for i = 1, 2 * n do
  local cur = t[i]
  if cur[2] == 1 then
    if 0 <= state then
      state = state + 1
    else
      ret = bmul(ret, -state)
      state = state + 1
    end
  else
    if state <= 0 then
      state = state - 1
    else
      ret = bmul(ret, state)
      state = state - 1
    end
  end
end
print(ret)


Measured memory_bytes: 14848
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

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

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;

template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void yesno(bool c) { OUT(c ? "yes" : "no"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int N, M;
	N = IN();
	vi T(N);
	REP(i, N)T[i] = IN();
	M = IN();
	vi P(M);
	vi X(M);
	REP(i, M) {
		P[i] = IN();
		X[i] = IN();
	}

	int St = accumulate(ALL(T), 0);
	REP(i, M) {
		int sum = St;
		sum -= T[--P[i]];
		sum += X[i];
		OUT(sum);
	}
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
mod=10**9+7
framod=[1]
def framod_calc(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
        framod.append(a)

def permmod(n, k, mod):
    a=framod[n]
    c=framod[n-k]
    return (a * pow(c, mod-2, mod)) % mod

def combmod(n, k, mod):
    a=framod[n]
    b=framod[k]
    c=framod[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
framod_calc(m, mod)

a=combmod(m,n,mod)*framod[n]
a%=mod
b=0
for k in range(n+1):
    b+=((((-1)**k)*combmod(n,k,mod)*combmod(m-k,n-k,mod))%mod*framod[n-k])%mod
    b%=mod
print(a*b%mod)

Measured memory_bytes: 114824
from math import *
from collections import *
mod = 10**9 + 7
test = 1
#test = int(input())
for __ in range(test):
	n,k = map(int,input().split())
	mins = 0
	maxs = 0
	for i in range(k):
		mins += i
		maxs += n-i
		mins %= mod
		maxs %= mod
	ans = (maxs-mins+1)%mod
	if(ans < 0): ans += mod
	for i in range(k,n+1):
		mins += i
		maxs += n-i
		mins %= mod
		maxs %= mod
		ans = (ans+maxs-mins+1)%mod
		if(ans < 0): ans += mod
	print(ans)

Measured memory_bytes: 68024
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 50010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
 
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
 
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


int main(){
    int i,j,k,n,m;
    ll a,b,c,d;
    ll ans=0;
    scanf("%lld%lld%lld%lld%d",&a,&b,&c,&d,&n);
    if(d<=2*c&&d<=4*b&&d<=8*a){
        ans=1LL*n/2*d;
        n%=2;
    }
    if(n){
        if(c<=2*b&&c<=4*a){
            ans+=c*n;
        }
        else{
            if(b<=2*a)ans+=b*2*n;
            else ans+=a*4*n;
        }
    }
    printf("%lld\n",ans);
    return 0;
}




Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
    
d = [0]*(n+1) #1から各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:1からの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(1,0,0)
for i in range(n):
    if d[i+1] % 2 == 0:
        print(1)
    else:
        print(0)

Measured memory_bytes: 82220
#include <stdio.h>
#include <string.h>
int main(void){
  int i, j=0, N, L;
  char s1[100][101], b;
  scanf("%d %d", &N, &L);
  for(i=0; i<N; i++){
    scanf("%s", s1[i]);
  }
  i=0;
    while(i < N-1){
      if(strcmp(s1[i],s1[i+1]) > 0){
        for(int k = 0; k<L; k++){
          b = s1[i][k];
          s1[i][k] = s1[i+1][k];
          s1[i+1][k] = b;
        }
        i=0;
        continue;
      }
      i++;
    }

  for(i = 0; i<N; i++){
    printf("%s", s1[i]);
  }
  return 0;
}

Measured memory_bytes: 128
S = input()
T = input()

out_str = "Yes"

indexes_s_all = []
indexes_t_all = []
for i in range(26) :
	c = chr(ord('a') + i)
	indexes_s = [n for n, x in enumerate(list(S)) if x == c]
	indexes_t = [n for n, x in enumerate(list(T)) if x == c]
	indexes_s_all.append(indexes_s)
	indexes_t_all.append(indexes_t)

indexes_s_all.sort()
indexes_t_all.sort()
if (indexes_s_all == indexes_t_all) :
	print("Yes")
else :
	print("No")

Measured memory_bytes: 20964
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <string>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll A, B, K;
    cin >> A >> B >> K;
    ll d = max((K - A), 0LL);
    A = max(A - K, 0LL);
    B = max(B - d, 0LL);
    cout << A << " " << B  << endl;
    return 0;
}

Measured memory_bytes: 3160
#include<stdio.h>

int main()
{
    int n,l,i,min,sum=0;
    scanf("%d%d",&n,&l);

    int apple[n];

    for(i=0;i<n;i++)
    {
        apple[i]=l+i;
    }

    min=l;

    for(i=0; i<n;i++)
    {
        if(abs(min)>abs(apple[i]))
        {
            min=apple[i];
        }
    }

    for(i=0;i<n;i++)
    {
        sum=sum+apple[i];
    }

    printf("%d\n",sum-min);
    return 0;
}

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

#define ll long long

using namespace std;

int main()
{
	ll n; cin>>n;
	map<ll, ll> sums;
	for(int i=0; i<n; i++){
		ll a; cin>>a;
		ll oa = a;
		for(int j=2; j*j<=a; j++){
			if (a%j==0){
				sums[j] += oa;
				while(a%j==0) a/=j;
			}
		}
		if (a!=1) sums[a] += oa;
	}
	ll ans=0;
	for(auto it=sums.begin(); it!=sums.end(); it++){
		ans = max(ans, it->second);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3168
"use strict";
    
const main = arg => {
    const N = arg.split("\n")[0];
    let list = [1, 2, 4, 8, 16, 32, 64];
    
    console.log(Math.max(...list.filter(n=>n<=N)));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
N = int(input())
A = list(map(int, input().split()))
B = {}
for a in A:
    if a not in B:
        B[a] = 0
    B[a] += 1

ans = 0
for b in B:
    v = B[b]
    if v >= b:
        ans += v - b
    else:
        ans += v
print(ans)


Measured memory_bytes: 17780
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}


int main()
{
	ll N = 0, K = 0, ans = 0x1000000000000000 ;
	scanf("%lld %lld", &N, &K);
	if ((N%K) == 0) {
		ans = 0;
	} else {
		ll temp = 0, temp2 = 0;
		temp = N%K;
		temp2 = K - temp;
		ans = MIN(temp, temp2);
	}
	printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,max,min,i,a[200005];
long long mid=0,avg=0,ans=-1,ans1=0;
int main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
		a[i]=a[i]-i-1;
	}
	sort(a,a+n);
	for(int j=-1;j<2;j++){
	avg=a[n/2+j];
	ans1=0;
	for(i=0;i<n;i++){
		if(a[i]>avg)
			ans1+=a[i]-avg;
		else
			ans1+=avg-a[i];
	}
	if(ans==-1)
		ans=ans1;
	if(ans>ans1)
		ans=ans1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <fstream>
#include <map>

using namespace std;

int w,d;
int front[1001];
int side[1001];


int main(){

    while(cin>>w>>d&&!(w==0&&d==0)){
        int sum=0;
        map<int,int> cnts;
        for(int i = 0; i < w; i++){
            cin>>front[i];
            sum+=front[i];
            cnts[front[i]]++;
        }
        for(int i = 0; i < d; i++){
            cin>>side[i];
            if(cnts.find(side[i])!=cnts.end()&&cnts[side[i]]>=1){
                cnts[side[i]]--;
            }
            else{
                sum+=side[i];
            }
        }
        cout<<sum<<endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int tot,id,n,q,dis[N],dep[N],root[N],head[N],nex[N<<1],to[N<<1],c[N<<1],wi[N<<1];
int fa[N][20],lg[N];
struct node
{
    int tot,sum,l,r;
}t[N*40];
void add(int u,int v,int x,int y)
{
    to[++tot]=v;nex[tot]=head[u];head[u]=tot;c[tot]=x;wi[tot]=y;
}
int build(int l,int r,int k)
{
    int p=++id;
    if(l==r) return p;
    int m=l+r>>1;
    t[p].l=build(l,m,k<<1);
    t[p].r=build(m+1,r,k<<1|1);
    return p;
}
int update(int l,int r,int k,int x,int v,int pre)
{
    int p=++id;
    if(l==r) {t[p].sum=t[pre].sum+v;t[p].tot=t[pre].tot+1;return p;}
    int m=l+r>>1;
    if(x<=m)
    {
        t[p].r=t[pre].r;
        t[p].l=update(l,m,k<<1,x,v,t[pre].l);
    }
    else
    {
        t[p].l=t[pre].l;
        t[p].r=update(m+1,r,k<<1|1,x,v,t[pre].r);
    }
    return p;
}
pair<int,int> query(int l,int r,int k,int x,int now,int pre)
{
    if(l==r) return {t[now].tot-t[pre].tot,t[now].sum-t[pre].sum};
    int m=l+r>>1;
    if(x<=m) return query(l,m,k<<1,x,t[now].l,t[pre].l);
    return query(m+1,r,k<<1|1,x,t[now].r,t[pre].r);
}
void dfs(int u,int p)
{
    dep[u]=dep[p]+1;
    fa[u][0]=p;
    for(int i=1;1<<i<=dep[u];i++)
        fa[u][i]=fa[fa[u][i-1]][i-1];
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];
        if(v==p) continue;
        root[v]=update(1,n-1,1,c[i],wi[i],root[u]);
        dis[v]=dis[u]+wi[i];
        dfs(v,u);
    }
}
int LCA(int u,int v)
{
    if(dep[u]<dep[v]) swap(u,v);
    while(dep[u]>dep[v])
        u=fa[u][lg[dep[u]-dep[v]]-1];
    if(u==v) return u;
    for(int k=lg[dep[u]]-1;k>=0;k--)
        if(fa[u][k]!=fa[v][k])
            u=fa[u][k],v=fa[v][k];
    return fa[u][0];
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=1;i<n;i++)
    {
        int u,v,x,y;
        scanf("%d%d%d%d",&u,&v,&x,&y);
        add(u,v,x,y);
        add(v,u,x,y);
    }
    for(int i=1;i<=n;i++)
        lg[i]=lg[i-1]+(1<<lg[i-1]==i);
    root[1]=build(1,n-1,1);
    dfs(1,0);
    while(q--)
    {
        int x,y,u,v;
        scanf("%d%d%d%d",&x,&y,&u,&v);
        int lca=LCA(u,v);
        if(dep[u]>dep[v]) swap(u,v);
        int ans=dis[v]-dis[lca]+dis[u]-dis[lca];
        pair<int,int>t1=query(1,n-1,1,x,root[v],root[lca]),t2=query(1,n-1,1,x,root[u],root[lca]);
        ans=ans-t1.second+t1.first*y-t2.second+t2.first*y;
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 51072
n = gets.rstrip.to_i

# dp    ; 0~n円の引き出しにかかる回数を全て算出する.
# 初期化; 100000より回数がかかることはないので初期値に設定. 0円は0回なので0.
dp = Array.new(n+1, 100000)
dp[0] = 0

(1..n).each do | i |
  # 1円引出でjumpできる先
  dp[i] = dp[i-1] + 1 < dp[i] ? dp[i-1] + 1 : dp[i]

  # 6円(** x), 9円(** y)引出でjumpできる先
  #   j は 6, 9 のどちらかの元の数字を保持. あとで累乗の計算できるように.
  #   k は累乗の結果を確認していく.
  #   jump元がdp配列の0番目以降になるように, i - k >= 0 を条件にする.
  [6, 9].each do | j |
    k = j
    while i - k >= 0
      dp[i] = dp[i-k] + 1 < dp[i] ? dp[i-k] + 1 : dp[i]
      k *= j
    end
  end
end
p dp[-1]

Measured memory_bytes: 2556
/*
     * drish1001
    */
    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp> 
    #include <functional>  
    #include <iostream> 
    using namespace __gnu_pbds; 
    using namespace std;
    #define     pb                 push_back
    #define     mp                 make_pair
    #define     ff                 first
    #define     ss                 second
    #define    MOD                1000000007
    #define     pll                pair<ll,ll>
    void        sorta(auto &v)     {sort(v.begin(),v.end());} 
    void        sortd(auto &v)     {sort(v.begin(),v.end(), greater<>());} 
    void        fast()            {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
    typedef        long long        ll;
    typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> magic; 
     
    //all variables and functions be1ow this ..
     
    int main() 
    {
		int n;
		cin >> n;
		vector<ll> x(n);
		vector<ll> y(n);
		vector<ll> sum(n);
		vector<ll> diff(n);
		for (int i = 0;i < n;i++) 
		{
			cin >> x[i] >> y[i];
			sum[i] = x[i] + y[i];
			diff[i] = x[i] - y[i];
		}
		sorta(sum);
		sorta(diff);
		cout << max(sum[n - 1] - sum[0], diff[n - 1] - diff[0]) << endl;
	}


Measured memory_bytes: 9548
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
	public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			var LArray = retreiveLongArray().OrderBy(x =>x).ToArray();


			var count = 0;

			for (int i = 0; i < N-2; i++) {
				var Li = LArray[i];
				for (int j = i+1; j < N-1; j++) {
					var Lj = LArray[j];
					for (int k = j+1; k < N; k++) {
						var Lk = LArray[k];
						if ((Li+Lj)>Lk && Li != Lj && Lj != Lk) {
							count++;
						}
					}
				}

			}

			//答えの出力
			var ans = count;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


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

activity =[]

for i in range(n):
    array = list(map(int,input().split()))
    activity.append(array)

dp = [[[0]for _ in range(3)] for _ in range(n)]

for i in range(3):
    dp[0][i] = activity[0][i]

for i in range(1, n):
    dp[i][0] = max(dp[i - 1][1] + activity[i][0], dp[i - 1][2] + activity[i][0])
    dp[i][1] = max(dp[i - 1][0] + activity[i][1], dp[i - 1][2] + activity[i][1])
    dp[i][2] = max(dp[i - 1][0] + activity[i][2], dp[i - 1][1] + activity[i][2])

print(max(dp[n-1]))

Measured memory_bytes: 76748
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 1012345678
#define NINF (-2147483647-1)
#define LLINF 9012337203685477580
using ll = long long;
using namespace std;

//ワーシャルフロイド法
const int MAX_V = 10;
int V; //頂点数
int d[MAX_V][MAX_V]; //最短距離(INFで初期化,d[i][i]=0,d[i][j]=辺ijのコスト)
void warshall_floyd() {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    V = 10;
    cin >> H >> W;
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cin >> d[i][j];
        }
    }
    warshall_floyd();
    int ans = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int A; cin >> A;
            if (A != -1) {
                ans += d[A][1];
            }
        }
    }
    cout << ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int par[100010],sz[100010];
void init(int n){
	for(int i=0;i<n;i++){
		par[i] = i; sz[i] = 1;
	}
}

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

void unite(int x, int y){
	x = find(x); y = find(y);
	if(x==y) return;
	if(sz[x]<sz[y]) swap(x,y);
	sz[x] += sz[y]; par[y] = x;
}

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

map<int,int> mp;
vector<int> v;
int zatu(){
	int now = 0;
	for(auto x:mp){
		v.push_back(x.first);
		now++;
	}
	for(int i=0;i<now;i++){
		mp[v[i]] = i;
	}
	return now;
}

vector<int> c,d;
int a[100010],b[100010];
bool flag[100010];
int ans = 0;
int main(){
	int i,n,x = 0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		c.push_back(a[i]); x ^= a[i];
	}
	a[n] = x; c.push_back(x);
	x = 0;
	for(i=0;i<n;i++){
		cin >> b[i];
		d.push_back(b[i]);x ^= b[i];
	}
	b[n] = x; d.push_back(x);
	sort(c.begin(),c.end()); sort(d.begin(),d.end());
	for(i=0;i<=n;i++){
		if(c[i]!=d[i]){
			cout << -1 << endl;
			return 0;
		}
	}
	for(i=0;i<n;i++){
		if(a[i]!=b[i]){
			ans++;
			mp[a[i]]++;
		}
	}
	mp[a[n]]++;
	if(ans==0){
		cout << 0 << endl;
		return 0;
	}
	ans++;
	int mx = zatu();
	init(mx);
	for(i=0;i<n;i++){
		if(a[i]!=b[i]){
			unite(mp[a[i]],mp[b[i]]);
		}
	}
	for(i=0;i<mx;i++){
		if(par[i]==i) ans++;
	}
	cout << ans - 2 << endl;
}

Measured memory_bytes: 7800
n, k = map(int, input().split())
X = set(); Y = set()
P = set()
for i in range(n):
    x, y = map(int, input().split())
    X.add(x); Y.add(y)
    P.add((x, y))

X = sorted(X); w = len(X)
Y = sorted(Y); h = len(Y)
MX = {x: i for i, x in enumerate(X)}
MY = {y: i for i, y in enumerate(Y)}
Q = {(MX[x], MY[y]) for x, y in P}
S = [[0]*(w+1) for i in range(h+1)]
for i in range(h):
    tmp = 0
    for j in range(w):
        if (j, i) in Q:
            tmp += 1
        S[i+1][j+1] = S[i][j+1] + tmp

ans = 10**100
for y1 in range(h):
    for x1 in range(w):
        for y2 in range(h):
            for x2 in range(w):
                count = S[y2+1][x2+1] - S[y2+1][x1] - S[y1][x2+1] + S[y1][x1]
                if count >= k:
                    ans = min(ans, (X[x2]-X[x1])*(Y[y2]-Y[y1]))
print(ans)

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

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

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

	int q;
	cin >> q;

	while(q--) {
		string a, b;
		cin >> a >> b;

		const int n = a.size();
		const int m = b.size();

		vector<vector<int>> dp(n + 2, vector<int>(m + 2, 0));
		for(int i = 0; i <= n; ++i) {
			for(int j = 0; j <= m; ++j) {
				if(a[i] == b[j]) {
					chmax(dp[i + 1][j + 1], dp[i][j] + 1);
				}
				else {
					chmax(dp[i + 1][j + 1], dp[i][j]);
					chmax(dp[i + 1][j], dp[i][j]);
					chmax(dp[i][j + 1], dp[i][j]);
				}
			}
		}

		cout << dp[n][m] << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 5044
A, B, C = map(int, input().split())
flag = False
count = 0
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    halfA = A // 2
    halfB = B // 2
    halfC = C // 2

    if A == (halfB + halfC) and B == (halfA + halfC) and C == (halfA + halfB):
        flag = True
        break
    else:
        A = halfB + halfC
        B = halfA + halfC
        C = halfA + halfB
        count += 1
if flag:
    print(-1)
else:
    print(count)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
 int main() {
int N;
cin>>N;
int ans;
ans=0;
     for(int i=0; i<N; i++){
char S;
cin >>S;
     if(S=='Y'){
     ans*=0;
     break;
     }
     else {
     ans++;
     }
}
if(ans>0){
cout<<"Three"<<endl;
}
else if(ans<=0){
cout<<"Four"<<endl;
}
}


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

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

    ll a = 0;
    ll b = 0;

    vector<ll> A(N + 1, 0);
    for (int i = 1; i < N + 1; i++) {
        ll tmp;
        cin >> tmp;
        a += tmp;
        A[i] = a;
    }

    vector<ll> B(M + 1, 0);
    for (int i = 1; i < M + 1; i++) {
        ll tmp;
        cin >> tmp;
        b += tmp;
        B[i] = b;
    }

    int j = M;
    int max = 0;
    for (int i = 0; i < N + 1; i++) {
        while (A[i] + B[j] > K && j > 0) {
            j--;
        }
        // cout << i << " " << j << " " << A[i] << " " << B[j] << endl;
        if (j + i > max && A[i] + B[j] <= K) {
            max = j + i;
        }
    }

    cout << max << endl;

    //      ll left;
    //      ll right;
    //
    //      ll max = 0;
    //      ll point = 0;
    //      ll old_point;
    //      for (int i = 0; i < N + 1; i++) {
    //          left = 0;
    //          right = M + 1;
    //          point = 0;
    //          while (1) {
    //              old_point = point;
    //              point = (right + left) / 2;
    //              if (B[point] + A[i] < K) {
    //                  left = point;
    //              } else if (B[point] + A[i] > K) {
    //                  right = point;
    //              } else {
    //                  // cout << "!!" << i << " " << point << endl;
    //                  break;
    //              }
    //              // cout << i << " " << point << " " << left << " " << right
    //              << " "
    //              //   << A[i] + B[point] << " " << (right + left) / 2 <<
    //              endl; if (point == old_point) {
    //                  break;
    //              }
    //          }
    //          // cout << i << " " << point << " " << A[i] + B[point] << endl;
    //          if (i + point > max && A[i] + B[point] <= K) {
    //              // cout << i << " " << point << " " << A[i] + B[point] <<
    //              endl; max = i + point;
    //          }
    //      }
    //      cout << max << endl;
    //
    return 0;
}


Measured memory_bytes: 6408
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int n = Integer.parseInt(sc.nextLine());
    String line = sc.nextLine();

    char[] c = line.toCharArray();

    int rNum = 0;
    for(int i=0; i<n; i++){
      if(c[i] == 'R') rNum++;
    }

    int rToMove = 0;
    int wToMove = 0;
    for(int i=0; i<n; i++){
      if( i < rNum && c[i] == 'W') wToMove++;
      else if ( i >= rNum && c[i] == 'R' ) rToMove++;
    }

    if(wToMove < rToMove){
      System.out.println(wToMove);
    }else{
      System.out.println(rToMove);
    }
    
    return;

  }
}

Measured memory_bytes: 41968
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    if (n >= 1000) cout << "ABD" << endl;
    else cout << "ABC" << endl;
    return 0;
}

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

#define ll long long
ll a,b;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b;
	if(abs(max(a,b) - (abs(b-a)/2)) == abs(min(a,b) + (abs(b-a)/2)))
		cout<<abs(max(a,b) - (abs(b-a)/2));
	else
		cout<<"IMPOSSIBLE";
	return 0;
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d ;
  if(a+b==c+d){
    cout << "Balanced" << endl;
    }
  else{
    if(a+b < c+d){
     cout << "Right" << endl;
      }
    else{
       cout << "Left" << endl;
      }
    }
  return 0;
  }

Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split(" "))

print(
    math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(
        math.radians(
            min(abs(30 * h + (360 * (m / 60) / 12) - 360 *
                    (m / 60)), 360 - abs(30 * h + (360 * (m / 60) / 12) - 360 *
                                         (m / 60)))))))


Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(ll x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,MOD;
ll ans[100004],sub[100004];
vector<int>t[100004],g[100004];
ll num[100004],num1[100004];
int lcnt[100004],cnt;
void dfs(int x){
	sub[x]=1;
	for (int i=0;i<g[x].size();i++){
		dfs(g[x][i]);
		sub[x]=sub[x]*(sub[g[x][i]]+1)%MOD;
	}
}
void dfs1(int x,ll now){
	lcnt[x]=cnt;cnt+=g[x].size();
	for (int i=0;i<g[x].size();i++){
		num[lcnt[x]+i]=(sub[g[x][i]]+1)%MOD;
		if (i!=0) num[lcnt[x]+i]=num[lcnt[x]+i]*num[lcnt[x]+i-1]%MOD;
	}
	for (int i=g[x].size()-1;i>=0;i--){
		num1[lcnt[x]+i]=(sub[g[x][i]]+1)%MOD;
		if (i!=g[x].size()-1) num1[lcnt[x]+i]=num1[lcnt[x]+i]*num1[lcnt[x]+i+1]%MOD;
	}
	ans[x]=sub[x]*(now+1)%MOD;
	for (int i=0;i<g[x].size();i++){
		ll go=1; 
		if (i!=0)go=num[lcnt[x]+i-1];
		if (i!=g[x].size()-1) go=go*num1[lcnt[x]+i+1]%MOD;
		go=go*(now+1)%MOD;
		dfs1(g[x][i],go);
	}
}
void mktree(int x,int par){
	for (int i=0;i<t[x].size();i++) if (t[x][i]!=par){
		g[x].push_back(t[x][i]);
		mktree(t[x][i],x); 
	}
}
int main(){
	read(n),read(MOD);
	for (int i=1;i<n;i++){
		int x,y;read(x),read(y);
		t[x].push_back(y),t[y].push_back(x);  
	}
	mktree(1,-1);
	dfs(1);
	dfs1(1,0);
	for (int i=1;i<=n;i++) write(ans[i]),puts("");
}

Measured memory_bytes: 20864
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        String S = scan.next();
        char sArray[] = S.toCharArray();

        int i = 1;
        for (char s :sArray) {
            if(i % 2 == 1) {
                if(s == 'R' || s == 'U' || s == 'D') {
                    i++;
                    continue;
                } else {
                    os.println("No");
                    return;
                }
            } else {
                if(s == 'L' || s == 'U' || s == 'D') {
                    i++;
                    continue;
                } else {
                    os.println("No");
                    return;
                }
            }
        }
        os.println("Yes");

    }
}

Measured memory_bytes: 22740
import java.util.Scanner;

public class Main{
	
	

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

	double N=sc.nextInt();
	double K=sc.nextInt();
	
	double result=0;
	
	for(int i=1;i<=N;i++) {
		int j=0;
		while(true) {
			if(i*Math.pow(2, j)>=K) {
				
				result+=Math.pow(0.5, j)*(1/N);
				break;
			}
			j++;
		}
		
	}
	System.out.println(result);
	

		
	}
	

	
}
		

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

int main()
{
    string s;
    cin >> s;
    if(s == "Sunny")
    {
        cout << "Cloudy\n";
    }
    else if(s == "Cloudy")
    {
        cout << "Rainy\n";
    }
    else
    {
        cout << "Sunny\n";
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[5555][5555],n,m;
long long ans;
const int mod=1e9+7;
char s[5555];
int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	m=strlen(s);
	dp[0][0]=1;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<=i;j++)
		{
			if (!dp[i][j]) continue;
			dp[i+1][j+1]=(dp[i+1][j+1]+(dp[i][j]*2%mod))%mod;
			if (j>=1) dp[i+1][j-1]=(dp[i+1][j-1]+dp[i][j])%mod;
			else dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
		}
	}
	ans=(long long)dp[n][m];
	for (int i=1;i<=m;i++)
	{
		ans=(ans*(long long)((mod+1)/2))%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 107136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;
  scanf("%d", &n);
  vector<ll> a(n), b(n), c(n);
  ll ans=0;
  for(int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    c[i] = a[i] + b[i];
    ans -= b[i];
  }
  sort(c.begin(), c.end(), greater<ll>());
  for(int i = 0; i < n; i++) {
    if(i%2==0){
      ans+=c[i];
    }
  }
  cout << ans << "\n";
  
  return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;


int main() {
    int x,y;cin>>x>>y;

    int ans=0;
    if(x==1){
        ans+=300000;
    }
    if (x==2){
        ans+=200000;
    }
    if (x==3) {
        ans+=100000;
    }
    if(y==1){
        ans+=300000;
    }
    if (y==2){
        ans+=200000;
    }
    if (y==3) {
        ans+=100000;

    }
    if (x==1&&y==1) {
        ans+=400000;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int x,y,r,i;
	scanf("%d %d",&x,&y);
	
	r=x%y;
	
	while(r!=0)
	{
		x=y;
		y=r;
		r=x%y;
	}
	
	printf("%d\n",y);
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> L(n);
    REP(i, n) cin >> L[i];
    // int n = 2000;
    // vector<int> L(n);
    // random_device rnd;
    // REP(i,n)L[i] = rnd() % 100;


    sort(L.begin(),L.end());
    int ans = 0;
    for(int a = 0; a < n - 2; a++) {
        for(int b = a + 1; b < n - 1; b++) {
            int sum_ab = L.at(a) + L.at(b);
            int left = lower_bound(L.begin(),L.end(),sum_ab) - L.begin();
            int right = b + 1;
            ans += left - right; 
        }
    }
    cout << ans << endl;
}



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

int main(){
  int D, C;
  cin >> D >> C;
  vector<int> p(D);
  vector<int> c(D);
  rep(i, D){
    cin >> p[i] >> c[i];
  }

  int ans = 999999;
  int solve, sum;

  for(int bit = 0; bit < (1 << D); bit++){
    solve = 0;
    sum = 0;
    for(int i = 0; i < D; i++){
      if(bit & (1 << i)){
        sum += (i+1) * 100 * p[i] + c[i];
        solve += p[i];
      }
    }
    if(sum >= C){
      ans  = min(ans, solve);
    }else{
      for(int i = D-1; i >= 0; i--){
        if(bit & (1 << i)){
          continue;
        }else{
          for(int j = 0; j < p[i]; j++){
            if(sum >= C) break;
            sum += (i+1) * 100;
            solve++;
          }
        }
      }
    }
    ans = min(ans, solve);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n-1; i >= 0; i--)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd2(i, s, n) for (ll i = n-1; i >= (s); i--)

int main() {
    ll d, t, s;
    cin >> d >> t >> s;
    if (d <= t*s) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3644
n = int(input())
a = list(map(int,input().split()))
x = 1

a = sorted(a)

if a[0]==0:
    print(0)

else:
    for i in range(n):
        x = x*a[i]
    
        if x > 10**18:
            print('-1')
            break
        if i == n-1:
            print(x)
            break

Measured memory_bytes: 21484
import sys
import itertools
N, M, Q = map(int, input().split())
ABCD = [list(map(int, sys.stdin.readline().split())) for i in range(Q)]
A = list(itertools.combinations_with_replacement(range(1, M + 1), r = N))
ans = 0
for i in A:
    s = 0
    for j in ABCD:
        if i[j[1] - 1] - i[j[0] - 1] == j[2]:
            s += j[3]
    ans = max(ans, s)
print(ans)

Measured memory_bytes: 21440