akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = 1e-9;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	if (!b)return T(1);
	if (b & 1)return mypow(a, b - 1) * a;
	T memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int n,p[250010];
int a[510][510];
bool oc[510][510];
int f[]={0,1,0,-1};
int g[]={1,0,-1,0};
int main(){
	std::cin>>n;
	rep(i,n*n){
		std::cin>>p[i];
		p[i]--;
	}
	rep(i,n){
		rep(j,n){
			a[i][j]=std::min({i,j,n-i-1,n-j-1});
			oc[i][j]=true;
		}
	}
	int ans=0;
	rep(i,n*n){
		ans+=a[p[i]/n][p[i]%n];
		oc[p[i]/n][p[i]%n]=false;
		std::queue<P> que;
		que.push(std::make_pair(p[i]/n,p[i]%n));
		while(!que.empty()){
			P p=que.front();
			que.pop();
			rep(j,4){
				int nx=p.first+f[j],ny=p.second+g[j];
				if(nx<0||n<=nx||ny<0||n<=ny)continue;
				if(oc[p.first][p.second]&&chmin(a[nx][ny],a[p.first][p.second]+1)){
					que.push(std::make_pair(nx,ny));
				}
				else if(!oc[p.first][p.second]&&chmin(a[nx][ny],a[p.first][p.second])){
					que.push(std::make_pair(nx,ny));
				}
			}
		}
	}
	std::cout<<ans<<std::endl;
	return 0;
}


Measured memory_bytes: 5852
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = 1;
		long max = 1000000000000000000l;
		// System.out.println(max);
		List<Long> arr = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			arr.add(sc.nextLong());
		}
		Collections.sort(arr);
		for (int i = 0; i < n; i++) {
			long a = arr.get(i);
			if (a == 0) {
				ans = 0;
				break;
			}
			if (a > max) {
				ans = -1;
				break;
			}
			if (ans > max / a) {
				ans = -1;
				break;
			}
			ans *= arr.get(i);
		}
		System.out.println(ans);
	}
}








Measured memory_bytes: 61756
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	int N, S; cin >> N >> S; 
	int A[3010] = {}; 
	for(int i = 0; i < N; i++) cin >> A[i]; 
	long long mod = 998244353; 
	long long pow[3010] = {}; 
	pow[0] = 1; 
	for(int i = 1; i < 3005; i++) pow[i] = pow[i-1] * 2 % mod; 
	long long dp[3010][3010] = {}; 
	dp[0][0] = pow[N]; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= S; j++){
			if(dp[i][j] == 0) continue; 
			dp[i+1][j] += dp[i][j]; 
			dp[i+1][j] %= mod; 
			if(j + A[i] <= S){
				dp[i+1][j + A[i]] += dp[i][j] * 499122177;
				dp[i+1][j + A[i]] %= mod;
			}
		}
	}
	cout << dp[N][S] << "\n"; 
}

Measured memory_bytes: 74472
using System;
class Program {
  static void Main(string[] args) {
    int[] A = new int[200010];
    int n = int.Parse(Console.ReadLine());
    int pos = 0;
    for (int i = 0; i < n; ++i) {
      string[] line = Console.ReadLine().Split();
      int val;
      int q = int.Parse(line[0]);
      switch (q) {
        case 0:
          val = int.Parse(line[1]);
          A[pos] = val;
          ++pos;
          break;
        case 1:
          val = int.Parse(line[1]);
          Console.WriteLine(A[val]);
          break;
        case 2:
          --pos;
          break;
      }
    }
  }  
}



Measured memory_bytes: 20308
n, q = gets.chomp.split.map &:to_i

node = {}

(n-1).times{
	a, b = gets.chomp.split.map &:to_i

	if node[a] then
		node[a] << b
	else
		node[a] = [b]
	end
}

count = {}

q.times{
	p, x = gets.chomp.split.map &:to_i

	if count[p] == nil then
		count[p] = x
	else
		count[p] += x
	end
}

tmp = {}
next_tmp = {1 => 0}
result = {}

while next_tmp.keys.size > 0
	tmp = next_tmp
	next_tmp = {}
	tmp.each { |k, v|
		result[k] = v + (count[k] ? count[k] : 0)
		if node[k] then
			node[k].each{ |s|
				next_tmp[s] = result[k]
			}
		end
	}
end

output = []

(1..n).each{ |i|
	output << result[i]
}

puts output.join(" ")


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

#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define all(x) (x).begin(), (x).end()

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int MOD = 1000000007;
int N;
double P[3000];
double DP[3001][3001];
double fun(int i, int K) {
    if(i == N) return 1;
    if(DP[i][K] != -1) return DP[i][K];

    double ans1;
    if(N - i == K) {
        ans1 = P[i] * fun(i + 1, K - 1);
        return DP[i][K] = ans1;
    }
    if(K == 0) {
        ans1 = ((1 - P[i]) * fun(i + 1, K));
        return DP[i][K] = ans1;
    }
    ans1 = P[i] * fun(i + 1, K - 1);
    ans1 += ((1 - P[i]) * fun(i + 1, K));
    return DP[i][K] = ans1;
}

int main() {
    IOS;
    cin >> N;
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= N ; j++) {
            DP[i][j] = -1;
        }
    }
    for (int i = 0; i < N; ++i) {
        cin >> P[i];
    }
    double ans = 0;
    for(int i = N; i > N / 2; i--) {
        ans += fun(0, i);
    }
    cout << fixed << setprecision(10) << ans;
    return 0;
}

Measured memory_bytes: 70784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) {
				break;
			}
			if(a < b) {
				System.out.printf("%d %d\n", a, b);
			}
			else {
				System.out.printf("%d %d\n", b, a);
			}
		}
		
	}
}



Measured memory_bytes: 40364
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll a,v;
	ll b,w;
	ll t;
	cin>>a>>v>>b>>w>>t;
	if(a < b){
		if(v <= w){
			cout<<"NO"<<endl;
		}
		else {
			if(a + v*t >= b+ w*t){
				cout<<"YES"<<endl;
			}
			else cout<<"NO"<<endl;
		}
	}
	else if(a > b){
		if(v <= w){
			cout<<"NO"<<endl;
		}
		else {
			if(a - v*t <= b - w*t){
				cout<<"YES"<<endl;
			}
			else cout<<"NO"<<endl;	
		}
	}
	else cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
	int h,r,f;
	scanf("%d %d",&h,&r);
	
	if(h>=0)	f=1;
	else{
			if(h+r>0) f=1;
			else if(h+r==0) f=0;
			else f=-1;
	}
	printf("%d\n",f);
	return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
//ofstream cout("output.out");

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }

using ll = long long;
const int mod = 1e9 + 7;

int main()
{
	fast();
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int s  = 0;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		s += a[i];
	}
	sort(a.begin(), a.end());
	int vote = s / (4 * m);
	if(s % (4*m)) vote ++;
	reverse(a.begin(), a.end());
	bool check = 0;
	for(int i = 0; i < m; ++i){
		if(a[i] < vote) check = 1;
	}
	if(check) cout << "No\n";
	else cout <<"Yes\n";
}			


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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

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

    ll a;
    multiset<ll> s;
    for(ll i=0; i<N; i++) {
        cin >> a;
        s.insert(a);
    }

    for(ll i=0; i<M; i++) {
        auto itr = s.end();
        itr--;
        auto v = *itr / 2;
        s.erase(itr);
        s.insert(v);
    }

    ll ans = 0;
    for(auto itr = s.begin(); itr != s.end(); ++itr) {
        ans += *itr;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int N; cin >> N;
  int S = 0, M = 0;
  rep(i,N) {
    int p;
    cin >> p;
    S += p;
    M = max(M,p);
  }
  int ans = S - M/2;
  cout << ans << endl;
}

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

#define Omar45 ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define pb push_back
#define F first
#define S second
#define endl '\n'
const ll mod = 1e9 + 7;
const ll maxN = 1e5 + 5;
const ll INF = 1e18;

int n, k, dp[maxN], val[maxN], arr[103];

int main() {
	Omar45
    int n, k; cin >> n >> k;
    vector <ll> arr(n);
    for (int i=0; i<n; i++) cin >> arr[i];
    vector < vector <ll> > dp(n+1, vector <ll> (k+1, 0));
    dp[0][0] = 1;
    for (int child=0; child<n; child++) {
        ll sum = 0;
        for (int usedCandy = 0; usedCandy<k+1; usedCandy++) {
            sum += dp[child][usedCandy];
            if (usedCandy > arr[child])
                sum -= dp[child][usedCandy-arr[child]-1];
            sum = (sum + mod) %mod;
            dp[child+1][usedCandy] = (dp[child+1][usedCandy] % mod + sum % mod ) % mod;
        }
    }
    cout << dp[n][k] << endl;
}

Measured memory_bytes: 80256
import java.util.*;class Main{public static void main(String[]z){int[]c=new int[6];int t;Scanner s=new Scanner(System.in);for(t=s.nextInt();t-->0;)++c[(int)Math.max(0,Math.min(s.nextFloat()/5-32,5))];String r="";for(t=0;t++<6;System.out.println(r))for(r=t+":";c[t-1]-->0;)r+="*";}}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define sf sacnf
#define pf printf
#define ll long long
#define ull unsigned long long
#define ii pair <int,int>
#define iii pair <int,ii>
#define pll pair <ll,ll>
#define plll pair <ll,pll>
#define Ziru 0
using namespace std;

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

    cout<<s/3600<<":";
    int a=s%3600;
    cout<<a/60<<":";
    a=a%60;
    cout<<a<<endl;

    return Ziru;
}



Measured memory_bytes: 3096
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

/* ??\??????????????????nionFind?????¨ */
const int INF = 1<<28;
class UnionFindW {
    int[] parent;
    int[] value;
    this(int N) {
        parent = new int[N + 1]; parent[] = -1;
        value = new int[N + 1];
    }
    alias P = Tuple!(int, "index", int, "dist");
    /* 
     * root :: ??§?????????????????£??§?????§??? -> (???????????????????????§?????????????????£??§?????§???, ??????????????????????????????????±¬)
     */
    P root(int x) {
        if (parent[x] == -1) return P(x, 0);
        int p = parent[x];
        int v = value[x];
        P proot = root(p);
        parent[x] = proot.index;
        value[x] = v + proot.dist;
        return P(parent[x], value[x]);
    }
    /* 
     * query :: (??§?????????????????£??§?????§???x, ??§?????????????????£??§?????§???y) -> y?????¨x????????????
     */
    int query(int x, int y) {
        P xroot = root(x),
          yroot = root(y);
        if (xroot.index != yroot.index) return INF;
        return yroot.dist - xroot.dist;
    }
    /*
     * merge :: (??§?????????????????£??§?????§???x, ??§?????????????????£??§?????§???y, y?????¨x????????????w(=y-x)) -> ()
     *
     * x?????¨y??????????????§?????????????????£?????????????¬??????????????????????,?????´??????????????£?????§???????????£????????°?????°??¶?????¨?????????     */
    void merge(int x, int y, int w) {
        P xroot = root(x),
          yroot = root(y);
        if (xroot.index == yroot.index) {
            assert(query(x, y) == w);
            return;
        }
        int px = xroot.index, py = yroot.index;
        int dx = xroot.dist, dy = yroot.dist;
        /* value[y] - value[x] = w
         * value[x] - value[px] = dx
         * value[y] - value[py] = dy
         * value[py] - value[px] = (value[y] - dy) - (value[x] - dx)
         *                       = (value[y] - value[x]) - (dy - dx)
         *                       = w - dy + dx
         */
        parent[py] = px;
        value[py] = w - dy + dx;
    }
}

void main() {
    int N, M;
    bool input() {
        readf("%d %d\n", &N, &M);
        if (N == 0 && M == 0) return false;
        return true;
    }
    void solve() {
        auto uf = new UnionFindW(N);
        foreach (_; 0 .. M) {
            auto input = readln.chomp.split(" ").array;
            int a = input[1].to!int;
            int b = input[2].to!int;
            if (input[0] == "!") {
                int w = input[3].to!int;
                uf.merge(a, b, w);
            } else { assert(input[0] == "?");
                int ans = uf.query(a, b);
                if (ans == INF) {
                    writeln("UNKNOWN");
                } else {
                    writeln(ans);
                }
            }
        }
    }
    while (input()) solve();
}

Measured memory_bytes: 14348
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ull Pow(ull a , ull b){
	if(b == 0) return 1 ;
	ull c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c) % mod)) % mod;
	return (c * c) % mod ;
}
vi Digit(ll x){
	vi res ;
	while(x){
		res.pb(x % 10) ;
		x /= 10 ;
	}
	return res ;
}
		

int main(){
	IOS;
	cout.precision(30) ;
	int n , m ; cin >> n >> m ;
	vector<vi> a(m);
	int p , y ;
	for(int i = 0 ; i < m ; i++){
		cin >> p >> y;
		a[i] = {p , y , i} ;
	}
	sort(a.begin() , a.end()) ;
	vi occ(n + 1, 1) ;
	vector<pii> ans(m) ;
	for(int i = 0 ; i < m ; i++){
		ans[a[i][2]] = mp(a[i][0] , occ[a[i][0]]) ;
		occ[a[i][0]]++ ;
	}
	for(int i = 0 ; i <m ; i++) printf("%06d%06d\n",ans[i].x,ans[i].y) ;
		
	return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include<utility>
using namespace std;
using ll = long long;


int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << (a[2] - a[1]) + (a[1] - a[0]) << endl;
	return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a,b;
	int digib;
	cin >> a >>b;
	if(b/100>0){digib = 3;}
	else if(b/10>0){digib = 2;}
	else{digib = 1;}
	
	
	for(int i=0;i<500;i++)
	{
		if(i*i == a*pow(10,digib)+b)
		{
			cout << "Yes" <<endl;
			return 0;
		}
	}
	
	cout << "No";
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll a,b;
int32_t main(){
CODE_START;
cin>>a;
cin>>b;
if(a==b){
    rc(1);
}
if((a-b)%2==0){
        rc(a-(a-b)/2);
}
rc("IMPOSSIBLE");
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;

class Program {
    static void Main (string[] args) {
        var tempstr = Console.ReadLine ().Split (' ');
        int N = int.Parse (tempstr[0]);
        long D = long.Parse (tempstr[1]);
        D = D * D;
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            var tempstr2 = Console.ReadLine ().Split (' ');
            long x = long.Parse (tempstr2[0]);
            long y = long.Parse (tempstr2[1]);
            if (x * x + y * y <= D) {
                cnt++;
            }
        }
        Console.WriteLine (cnt);

    }

}

//dotnet run --project test

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

using namespace std;
typedef bitset<200009> bset;

int main() {
    int n, m;
    cin >> n >> m;
    bset first, second;
    for(int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        if(a==1) first[b] = true;
        if(b==n) second[a] = true;
    }
    for(int i=1; i<=n; i++) {
        if(first[i] && second[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
const int INFI=2147483647;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int main() {
  int a,b; cin >>a >>b;
  cout <<a * b <<" " <<2 * a + 2 * b <<endl;
}



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

int main(){
  long a, b, c, d;
  long e;
  cin >> a >> b >> c >> d;
  vector<long> x = {a*c, a*d, b*c, b*d};
  e = a * c;
  for(int i = 0; i < 4; i++){
    if(e < x.at(i)){
      e = x.at(i);
    }
  }
  cout << e << endl;
}

Measured memory_bytes: 3612
W, H, N =  map(int, raw_input().split())
result = [0, W, 0, H]
for n in range(N):
    x, y, a =  map(int, raw_input().split())
    if a == 1:
        result[0] = max(result[0], x)
    if a == 2:
        result[1] = min(result[1], x)
    if a == 3:
        result[2] = max(result[2], y)
    if a == 4:
        result[3] = min(result[3], y)

print int(max(0, (result[1]-result[0]))*max(0, (result[3]-result[2])))

Measured memory_bytes: 2696
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<set>
#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,a,b) for(int i = (a); i < (b); i++)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
using namespace std;

static const ll mod  = 1e9 + 7;
static const ll inf  = 1e18;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

void pvector(vector<int> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    ll anssum = 0, min = 0, ansx = 0;
    int Q;
    int q;
    ll a, b;
    multiset<ll> av;
    cin >> Q;
    //ll cnt = 0;
    cin >> q;
    cin >> a >> b;
    
    av.insert(a);
    ansx = a;
    anssum = b;
    auto itr = av.begin();
    FOR(i, 1, Q){
        cin >> q;
        if(q == 2){
            p2(ansx, anssum);
        }else{
            cin >> a >> b;
            min += b;
            av.insert(a);
            if(av.size() % 2 == 0){//奇数から偶数
                if(*itr > a){
                    auto tmpitr = itr;
                    itr--;
                    ansx = *itr;
                    anssum += b + llabs(*tmpitr - a);
                }else if(*itr < a){
                    anssum += b + llabs(*itr - a);
                }else{
                    anssum += b;
                }
            }else{//偶数こから奇数個
                if(*itr < a){
                    itr++;
                    ansx = *itr;
                    anssum += b + llabs(*itr - a);
                }else if(*itr > a){
                    anssum += b + llabs(*itr - a);
                }else{
                    itr++;
                    anssum += b;
                }
            }
        }
    }
}

Measured memory_bytes: 9600
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 1e6 + 6, mod = (int) 1e9 + 7;
int f[N], g[N];
int main() {
	int n;
	cin >> n;
	f[0] = 1;
	f[1] = n;
	g[0] = 1;
	g[1] = 1;
	int sum = 0;
	for (int j = 2; j <= n; ++j) {
//		g[j] = (g[j - 1] + f[j - 1]) % mod;
		f[j] = (f[j - 1] + sum) % mod;
		f[j] = (f[j] + (n - 1) * (LL) (n - 1)) % mod;
		f[j] = (f[j] + (n - j + 1)) % mod;
 		/*
		g[j] = (n - 1) * (LL) f[j - 1] % mod + (LL) (n - 1) * (n - 1) % mod;
		g[j] %= mod;
		*/
		if (j >= 2) sum = (sum + f[j - 2]) % mod;
	}
	cout << f[n] << endl;;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    int a[N+2];
    int b[N+2];
    int c[M+2];
    int d[M+2];
    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i];
    }
    for(int i=0;i<M;i++){
        cin >> c[i] >> d[i];
    }

    int dest;
    for(int i=0;i<N;i++){
        dest = 0;
        for(int j=0;j<M;j++){
            if(abs(a[i] - c[j]) + abs(b[i] - d[j]) < abs(a[i] - c[dest]) + abs(b[i] - d[dest])){
                dest = j;
            }
        }
        cout << dest+1 << endl;
    }
    return 0;
}  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef  long long ll;


int main(){
  int N;
  ll a;

  ll ans = 0;

  cin >> N;

  for(int i = 0; i < N; i++){
    cin >> a;
    while(a%2 == 0){
      a /=2;
      ++ans;
    }
  }

  cout << ans << endl;
  
  
  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
int n;
int d[400][400];
int iran[400][400];
int ans;
signed main(){
  cin >> n;
  REP(i,n){
    REP(j,n){
      cin >> d[i][j];
    }
  }
  int f = 0;
  REP(i,n){
    REP(j,n){
      if(d[i][j] != d[j][i]) f = 1;
    }
  }
  if(f==1){
    cout << -1 <<endl;
    return 0;
  }

  REP(i,n){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        int wa = d[i][j] + d[j][k] + d[k][i];
        int mx = max({d[i][j],d[j][k],d[k][i]});
        if(wa- mx < mx){
          cout << -1 << endl;
          return 0;
        }
        if(wa - mx == mx){
          //cout << i << " " << j << " " << k << endl;
          if(mx == d[i][j]) iran[i][j] = 1, iran[j][i] = 1;
          else if (mx == d[j][k]) iran[j][k] = 1, iran[k][j] = 1;
          else if (mx == d[k][i]) iran[k][i] = 1, iran[i][k] = 1;
        }
      }
    }
  }
  REP(i,n){
    for(int j=i;j<n;j++){
      if(iran[i][j] == 0) ans += d[i][j];
    }
  }
  cout <<ans << endl;
  return 0;
}


Measured memory_bytes: 2176
#!/usr/bin/env python3

def main():
    n, k = map(int, input().split())
    pi = list(map(int, input().split()))
    kitai = [(x + 1) * 0.5 for x in pi]
    kitai_acc = [0]  # acc[i] = sum(kitai[0:i])
    for i in range(n):
        kitai_acc.append(kitai_acc[-1] + kitai[i])
    res = 0
    for i in range(n + 1 - k):
        x = kitai_acc[i + k] - kitai_acc[i]
        res = max(res, x)
    print(res)

main()


Measured memory_bytes: 25060
import std.algorithm;
import std.stdio;

void main() {
	long n, k;
	readf(" %s %s", &n, &k);
	auto h = new long[n];

	foreach (ref e;h) {
		readf(" %s", &e);
	}

	if (k >= h.length) {
		writeln("0");
		return;
	}

	sort(h);

	h[0..$ - k].reduce!"a + b".writeln;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	string s;
	int a,z;
	cin >> s;
	for(int i = 0;i < s.length();i++){
		if(s[i] == 'A'){
			a = i;
			break;
		}
	}
	for(int i = s.length() - 1;i >= 0;i--){
		if(s[i] == 'Z'){
			z = i;
			break;
		}
	}
	cout << z - a + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    ll n,k;
    while(cin>>n>>k)
    {
        int ans=0;
        while(n)
        {
            ans++;
            n/=k;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main() 
{
	int a,b;
	cin>>a>>b;
	if(a>0)
	{
		cout<<"Positive";
	}
	else
	{
		if(b<0)
		{
			if((b-a+1)%2==0)
			{
				cout<<"Positive";
			}
			else
			{
				cout<<"Negative";
			}
		}
		else
		{
			cout<<"Zero";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
ll f[maxn],g[maxn];
struct point{
	int x,y,z,v;
	bool operator <(const point &rhs) const{
		return v>rhs.v;
	}
}a[maxn];
priority_queue<point> q;
int main(){
	int A=read(),B=read(),C=read();
	int n=A+B+C;
	REP(i,1,n) a[i].x=read(),a[i].y=read(),a[i].z=read(),a[i].v=a[i].x-a[i].y;
	sort(a+1,a+n+1);
	REP(i,1,n) a[i].v=a[i].x-a[i].z;
	REP(i,1,A) q.push(a[i]),f[i]=f[i-1]+a[i].x;
	REP(i,A+1,A+C){
		q.push(a[i]);
		point u=q.top();q.pop();
		f[i]=f[i-1]+a[i].x-u.v;
	}
	while(!q.empty()) q.pop();
	REP(i,1,n) a[i].v=a[i].y-a[i].z;
	DREP(i,n,n-B+1) q.push(a[i]),g[i]=g[i+1]+a[i].y;
	DREP(i,n-B,n-C-B+1){
		q.push(a[i]);
		point u=q.top();q.pop();
		g[i]=g[i+1]+a[i].y-u.v;
	}
	ll ans=0;
	REP(i,A,A+C) chkmax(ans,f[i]+g[i+1]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4724
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n, m, s = nm()
N = n * 3001
G = [list() for _ in range(N)]
for _ in range(m):
    u, v, a, b = nm()
    u -= 1; v -= 1
    for j in range(0, N, n):
        if v + j - a * n >= 0:
            G[u + j].append((v + j - a * n, b))
        if u + j - a * n >= 0:
            G[v + j].append((u + j - a * n, b))
for u in range(n):
    c, d = nm()
    for j in range(0, N, n):
        G[u + j].append((min(u + j + c * n, u + N - n), d))

import heapq as hq

def dijkstra(G, s, t=None):
    """
    G[v] = [(x1, c1), (x2, c2), ...]
    """
    dist = [-1]*len(G)
    dist[s] = 0
    q = [(0, s)]
    while q:
        d, v = hq.heappop(q)
        if d > dist[v]: continue
        for x, c in G[v]:
            if dist[x] < 0 or dist[x] > d + c:
                dist[x] = d + c
                hq.heappush(q, (d + c, x))
    if t is None:
        return dist
    else:
        return dist[t]

dist = dijkstra(G, min(s, 3000) * n)
for i in range(1, n):
    print(min(dist[i::n]))


Measured memory_bytes: 115328
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/30/2019 11:03:37 PM
*************************************************************************/
//#pragma GCC optimize(3)
//#pragma GCC diagnostic error "-std=c++11"
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#ifdef WindCry1
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#endif
#define lowbit(x) x&(-x)
#define ls u<<1
#define rs u<<1|1
using namespace std;
template<typename T> inline T MIN(const T &a,const T &b) {return a<b?a:b;}
template<typename T> inline T MAX(const T &a,const T &b) {return a>b?a:b;}
template<typename T,typename ...Args> inline T MIN(const T &a,const T &b,Args ...args) {return MIN(MIN(a,b),args...);}
template<typename T,typename ...Args> inline T MAX(const T &a,const T &b,Args ...args) {return MAX(MAX(a,b),args...);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
ll sum(ll h){
	if(h==1) return 1;
	return 2*sum(h/2)+1;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef WindCry1
	freopen("C:\\Users\\LENOVO\\Desktop\\in.txt","r",stdin);
#endif
	ll h;cin>>h;
	cout<<sum(h)<<endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a, b;
		int max = 0, ans = 0;
		for(int i = 0; i < n; i++){
			a = sc.nextInt();
			b = sc.nextInt();
			if(max < a) {
				max = a;
				ans = a + b;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 58152
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<" ";
  cout<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}


ll n,k,x,y;


//moddivとnCk
//c剰余下でaをbで割った値
ll moddiv(ll a,ll b,ll c){
	ll x0=c,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0LL) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%c;
      if (x2==1LL){
        ans=(n2+c)%c;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%c)*b-t)/b;
}
//剰余の割ざん

//aのn乗 mod c
ll expmod(ll a,ll n,ll c){
  ll ans=1LL,aa=a,beki=n;
  for(int i=0;i<64;i++){
    if (beki%2==1LL) ans=ans*aa%c;
    aa=aa*aa%c;
    beki/=2LL;
    if (beki==0LL)break;
  }
  return ans;
}

//nCk
vi mulmod(500001);//0!,1!,2!,3!,4!,,,,
void first_nCk(){
  mulmod[0]=1LL;
  for(ll i=1;i<500001;i++){
    mulmod[i]=mulmod[i-1]*i%MOD;
  }
}
ll nCk(ll nn,ll kk){
  return moddiv(mulmod[nn],mulmod[kk]*mulmod[nn-kk]%MOD,MOD);
}

ll modinv(ll a,ll b){
  return moddiv(1,a,b);
}

ll garner(ll a,ll b,ll ar,ll br){
  return ar+(br-ar+b)%b*modinv(a,b)%b*a;
}
ll garner2(ll a,ll b,ll ar,ll br){
  ar%=a;
  br%=b;
  ll ret=(ar+(br-ar)%b*moddiv(1,a,b)%b*a)%(a*b);
  return ret;
}

ll gcd(ll a,ll b){
  ll r = a % b;
  while(r!=0LL){
    a = b;
    b = r;
    r = a % b;
  }
return b;
}





int main(){
  ll ans=0;
  cin >> n;

  if (n==1){
    cout<<1<<endl;
    return 0;
  }
  if (n%2==0){
    ans=2*n-1;
  }else{
    ans=n-1;
  }

  n*=2;
  for(ll i=2;i<=n+2;i++){
    if (i*i>n)break;
    if (n%i==0){
      ll val0=i;
      ll val1=n/i;
      if (val0==1)continue;
      if (val1==1)continue;
      if (gcd(val0,val1)==1){
        ll ans0=garner2(val0,val1,1,0)-1+val0*val1;
        ll ans1=garner2(val0,val1,0,1)-1+val0*val1;
        ans0%=val0*val1;
        ans1%=val0*val1;
        if (ans0>1)
          ans=min(ans,ans0);
        if (ans1>1)
          ans=min(ans,ans1);
      }
    }
  }


  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7024
K = 1000000007
N = int(input())
A = [int(a) for a in input().split()]
li = [0] * 60
for n in range(N):
    li = [li[i] + (A[n] >> i & 1) for i in range(60)]
ans = 0
for i in range(60):
    ans += (1 << i) * li[i] * (N - li[i])
    ans %= K
print(ans)

Measured memory_bytes: 122960
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;


#define endl '\n'
#define int ll

signed main() {
	fast;

	int h,w;
	cin>>h>>w;

	pii v[200002];
	for(int i=0;i<h;i++) cin>>v[i].f>>v[i].s;

	map<int,int> mp;
	for(int i=1;i<=w;i++) mp[i] = 0;

	map<int,int> mini = {{0,w}};

	for(int i=0;i<h;i++) {
		int r = v[i].s;

		auto it = mp.lower_bound(v[i].f);


		if(r==w) {
			while(it!=mp.end() && it->f <= r) {
				auto it1 = it++;
				auto it2 = mini.find(it1->s);
				if(it2->s==1) mini.erase(it2);
				else it2->s --;
				mp.erase(it1);
			}
		}
		else {
			int mn = inf;

			while(it!=mp.end() && it->f <= r) {
				mn = min(mn, r+1-(it->f)+(it->s));
				auto it1 = it++;
				auto it2 = mini.find(it1->s);
				if(it2->s==1) mini.erase(it2);
				else it2->s --;
				mp.erase(it1);
			}

			if(mn<inf) {
				if(it!=mp.end() && it->f == r + 1) {
					if(it->s > mn) {
						auto it1 = mini.find(it->s);
						if(it1->s ==1) mini.erase(it1);
						else it1->s --;
						mini[mn]++;
						it->s = mn;
					}
				}
				else {
					mp.insert({r+1,mn});
					mini[mn]++;
				}
			}
		}

		if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
		else cout<<-1<<endl;

	}
}

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

int main(){
	int n;
	cin >> n;
	int a[100000]{};
	while(n--){
		int i;
		cin >> i;
		a[i]++;
	}
	int ans = max(a[0] + a[1], a[99998] + a[99999]);
	for(int i = 1; i < 99999; i++){
		ans = max(ans, a[i - 1] + a[i] + a[i + 1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
ptree = {"a": list(input()), "b": list(input()), "c": list(input())}

nxt = "a"
winner = "A"
while True:
    if len(ptree[nxt]) == 0:
        winner = nxt.upper()
        break
    nxt = ptree[nxt].pop(0)

print(winner)


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc082/tasks/arc087_a

"""
import sys
from sys import stdin
from collections import Counter
input = stdin.readline


def solve(A):
    ans = 0
    for v, f in Counter(A).most_common():
        if v > f:
            ans += f
        elif f > v:
            ans += (f - v)
    return ans


def main(args):
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = solve(A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
    


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

using namespace std;
#define ll long long
#define ld long double

#define endl '\n'
#define FAST                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;
ll fastPow(ll x, ll b)
{
    if (b == 0)
        return 1;
    else if (!(b & 1))
    {
        return fastPow(x * x, b / 2);
    }
    else
        return x * fastPow(x * x, (b - 1) / 2);
}
//__builtin_popcount ();
struct def
{
    string h = ">";
};
int main()
{
    FAST
        string h;
    cin >> h;
    vector<int> v;
    int ans = 0;
    int l = 0,r=0;
    for (int i = 0; i < h.length(); i++)
        if (h[i] == 'A')
        {
            l = i;
            break;
        }
    for (int i = h.length() - 1; i >= 0;i--)
    if(h[i]=='Z')
    {
        r = i;
        break;
    }
    cout << (r - l + 1) << endl;

    return 0;
}

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

int main() {
    /* Input */
    int N;
    cin >> N;
    
    vector<int> L(N);
    rep (i, N) {
        cin >> L.at(i);
    }
    
    /* Main Logic */
    sort(L.begin(), L.end());
    int ans = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            for (int k = j + 1; k < N; k++) {
                if (L.at(i) + L.at(j) > L.at(k) && L.at(k) + L.at(i) > L.at(j) && L.at(j) + L.at(k) > L.at(i)) {
                    if (!(L.at(i) == L.at(j) || L.at(j) == L.at(k) || L.at(k) == L.at(i))) {
                        ans++;
                    }
                } else {
                    break;
                }
            }
        }
    }

    /* Output */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
import java.util.Scanner

object Main {
  val in = new Scanner(System.in)

  def main(args: Array[String]): Unit = {
    val N = in.nextInt()
    val D = (0 :: (0 until N).map(_ => in.nextInt()).toList).sorted

    def check(X: Int): Boolean = {
      var min = 0
      var max = 0
      var arranged = D.map { d =>
        val right = d - max
        val left = d + min
        val ret = if (left < X && right < X) {
          d
        } else if (left < X) {
          d
        } else if (right < X) {
          -d
        } else if (right < left) {
          d
        } else {
          -d
        }
        min = math.min(min, ret)
        max = math.max(max, ret)
        ret
      }
      arranged = arranged.sorted

      (0 until (N + 1)).forall(i => {
        val x = arranged(i)
        var y = arranged((i + 1) % (N + 1))
        if (x >= 0 && y < 0) {
          y += 24
        }
        val d = math.abs(x - y)
        math.min(d, 24 - d) >= X
      })
    }

    var ans = 0
    for (i <- 12 to 0 by -1) {
      if (check(i)) {
        ans = math.max(i, ans)
      }
    }

    println(ans)
  }
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

template<class T>
class BinaryIndexedTree {
    private:
        int N;
        std::vector<T> dat;
    public:
        BinaryIndexedTree(int n) : N(n), dat(n+1, static_cast<T>(0)) {}
        // a is 1-indexed
        void add(int a, const T v) {
            while (a <= N) {
                dat[a] += v;
                a += (a & -a);
            }
        }
        // return sum of [1, a]
        // a is 1-indexed
        T sum(int a) const {
            T res = static_cast<T>(0);
            while (a > 0) {
                res += dat[a];
                a -= (a & -a);
            }
            return res;
        }
        // return sum of [a. b)
        // a and b are 1-indexed
        T sum(int a, int b) const {
            return sum(b-1) - sum(a-1);
        }
};

void solve() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    vector<ll> b(N+1);
    for (int i=1; i<N+1; ++i) b[i] = b[i-1] + a[i-1];
    for (ll i=1; i<N+1; ++i) b[i] -= i * K;

    vector<ll> comp = b;
    sort(comp.begin(), comp.end());
    comp.erase(unique(comp.begin(), comp.end()), comp.end());
    for (int i=0; i<N+1; ++i) b[i] = lower_bound(comp.begin(), comp.end(), b[i]) - comp.begin() + 1;

    ll res = 0;
    BinaryIndexedTree<int> bit((int)comp.size());
    for (int i=0; i<N+1; ++i) {
        res += bit.sum(b[i]);
        bit.add(b[i], 1);
    }
    cout << res << '\n';
}

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

    solve();

    return 0;
}


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

N, K = map(int, input().split())
a = list(map(int, input().split()))

cs = [0] * (N + 1)
for i in range(N):
  cs[i + 1] = cs[i] + a[i]
lrsums = []
for i in range(N):
  for j in range(i, N):
    lrsums.append(cs[j + 1] - cs[i])
lrsums.sort()
#print(lrsums)
def check(m):
  c = 0
  for x in lrsums:
    if x & m == m:
      c += 1
  return c >= K
x = lrsums[-1].bit_length()
res = 0
while x > 0:
  if check(res + pow(2, x - 1)):
    res += pow(2, x - 1)
  x -= 1
print(res)

Measured memory_bytes: 69756
object Main extends App {
  val sc = new java.util.Scanner(System.in) 
  val k = sc.nextInt()
  val n = sc.nextInt()
  sc.useDelimiter("\n")
  val a = sc.next().split(" ").map(_.toInt).toList
  val d1 = a.zip(a.tail).map{case (x, y) => y -x}.toList
  val d2 = a(0) + k - a(n-1)
  val d = d1 :+ d2
  println(d.sum - d.max)
  
}

Measured memory_bytes: 85264