akhauriyash/Code-Regression huggingface dataset:
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    a_list = li()
    a_list.sort()

    mode = 1
    if a_list[0] <= 0 <= a_list[n - 1]:
        max_sum = sum(list(map(abs, a_list)))
        print(max_sum)
        min_index = 0
        max_index = n - 1
    elif a_list[0] < 0:
        max_value = a_list[n - 1]
        max2_index = n - 2
        max2_value = a_list[max2_index]

        while max2_index - 1 >= 0 and max_value == max2_value:
            max2_index = max2_index - 1
            max2_value = a_list[max2_index]

        max_sum = sum(list(map(abs, a_list))) - abs(max_value) * 2
        print(max_sum)
        min_index = 0
        max_index = n - 1

        print(a_list[max_index], a_list[max2_index])
        a_list[max_index] = a_list[max_index] - a_list[max2_index]
        a_list.pop(max2_index)
        max_index = max_index - 1
    else:
        min_value = a_list[0]
        min2_index = 1
        min2_value = a_list[min2_index]

        while min2_index + 1 < n and min_value == min2_value:
            min2_index = min2_index + 1
            min2_value = a_list[min2_index]

        max_sum = sum(list(map(abs, a_list))) - abs(min_value) * 2
        print(max_sum)
        min_index = 0
        max_index = n - 1

        print(a_list[min_index], a_list[min2_index])
        a_list[min_index] = a_list[min_index] - a_list[min2_index]
        a_list.pop(min2_index)
        max_index = max_index - 1

    while True:
        if min_index + 1 == max_index:
            print(a_list[max_index], a_list[min_index])
            break
        if a_list[min_index + 1] <= 0:
            print(a_list[max_index], a_list[min_index])
            a_list[max_index] = a_list[max_index] - a_list[min_index]
            min_index = min_index + 1
        else:
            print(a_list[min_index], a_list[max_index])
            a_list[min_index] = a_list[min_index] - a_list[max_index]
            max_index = max_index - 1

# 正整数と不正数が両方ある場合は、絶対値和にできる
# 負　正と選んで正を１つ減らすか、正　負と選んで正を１つ減らす操作を行い
# 最後に正　負とできるようにすればよい

# 正整数だけの場合
# なるべくロスが少なくなるように負の数を作る
# １番小さい数と２番目に小さい数を使って　1-2とし、負の数を作る
# 全て同じ数の場合は、0を作って再試行する
# 後は同様の手順

# 負整数だけの場合
# なるべくロスが少なくなるように正の数を作る
# １番大きい数と２番目に大きい数を使って　1-2とし、正の数を作る
# 後は同様の手順


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

#define REP(i,n) for (int i=0; i<(n); i++)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9+7;

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> a(H,vector<char>(W));
  REP(i,H){
    REP(j,W){
      cin >> a.at(i).at(j);
    }
  }
  
  bool row[H];
  bool column[W];
  REP(i,H){
    row[i] = true;
    REP(j,W){
      if (a.at(i).at(j) == '#') row[i] = false;
    }
  }
  
  REP(i,W){
    column[i] = true;
    REP(j,H){
      if (a.at(j).at(i) == '#') column[i] = false;
    }
  }
  
  REP(i,H){
    if (row[i]) continue;
    REP(j,W){
      if (!column[j]) cout << a.at(i).at(j);
    }
    cout << endl;
  }
  
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,N) for (int (i) = 0; (i) < (N); (i)++)

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	
	int a, b; std::cin >> a >> b;

	int ans = 0;
	if ((a + b) % 2 == 0)ans = (a + b) / 2;
	else ans = (a + b) / 2 + 1;

	std::cout << ans;


	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();

		graph = new boolean[n][n];
		used = new ArrayList<>();
		varsize = n;
		for (int i = 0; i < m; i++) {
			graph[scanner.nextInt() - 1][scanner.nextInt() - 1] = true;
		}

		dfs(0, used);

		System.out.println(cnt);

	}

	static boolean graph[][];
	static List<Integer> used;
	static int cnt = 0;
	static int varsize;

	private static void dfs(int i, List<Integer> used) {
		if (used.contains(i)) {
			return;
		} else {
			used.add(i);
			if (used.size() == varsize) {
				cnt++;
			}
		}

		for (int j = 0; j < graph.length; j++) {
			if (graph[i][j] || graph[j][i]) {
				dfs(j, new ArrayList<>(used));
			}
		}
	}

}

Measured memory_bytes: 30944
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

 
int main() {

    int a,b,c,k;
    cin >> a >> b >> c >> k;

    if(a>=k) {
            cout<<k<<endl;
    }
    else {
        if(a+b>=k) {
            cout<<a<<endl;
        }
        else {
            cout<<a+((k-(a+b))*(-1))<<endl;
        }
    }

    
 return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

  ll n;
  cin >> n;
  vector<ll> one(63, 0);
  vector<ll> zero(63, 0);
  rep(i, n) {
    ll a;
    cin >> a;

    for (int j = 0; j < 63; j++) {
      if ((a >> j) & 1) {
        one[j]++;
      } else {
        zero[j]++;
      }
    }
  }
/*
  rep(i, 60) {
    cerr << one[i] << " ";
  }
  cerr << endl;
  rep(i, 60) {
    cerr << zero[i] << " ";
  }
  cerr << endl;
*/
  ll ans = 0;
  for (ll i = 0; i < one.size(); i++) {
    ll base = (1l << i) % mod;
    ll x = (one[i] * zero[i]) % mod;
    ans += (x * base) % mod;
    ans %= mod;
  }

  cout << ans << 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 m = sc.nextInt();
        int q = sc.nextInt();
        int max = 0;
        int[] a = new int[q];
        int[] b = new int[q];
        int[] c = new int[q];
        int[] d = new int[q];
        for(int i = 0;i < q; i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }
        int[] nums = new int[n];
        for(int i = 0; i < n; i++) nums[i] = 1;
        do{
            int sum = 0;
            for(int j = 0; j < q; j++){
                if(nums[b[j] - 1] - nums[a[j] - 1] == c[j]) sum += d[j];
            }
            max = Math.max(max, sum);
        }while(next(nums, n, m));
        System.out.println(max);
    }
    public static boolean next(int[] nums, int n, int m){
        boolean bl = false;
        for(int i = n - 1; i >= 0; i--){
            if(nums[i] < m){
                nums[i]++;
                for(int j = i + 1; j < n; j++){
                    nums[j] = nums[i];
                }
                bl = true;
                break;
            }
        }
        return bl;
    }
}

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

const int N = 1e5 + 10;

int n, k, q, a[N], b[N];
int check(int mn, int mx) {
    int c1 = 0, c2 = 0;
    int ret = 0;
    for(int i = 1; i <= n; i++) {
        if(a[i] < mn) {
            ret += min(c1, max(0, c1 + c2 - k + 1));
            c1 = 0; c2 = 0;
        } else if(a[i] >= mn && a[i] <= mx) c1++;
        else c2++;
    }
    if(a[n] >= mn) ret += min(c1, max(0, c1 + c2 - k + 1));
    // printf("%d %d %d\n", mn, mx, ret);
    return ret;
}

int main() {
    cin >> n >> k >> q;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1, b + 1 + n);
    // for(int i = 1; i <= n; i++) {
    //     printf("b[%d]:%d\n", i, b[i]);
    // }
    int ans = 2e9;
    if(q == 1) ans = 0;
    for(int i = 1; i < n; i++) {
        int l = i + 1, r = n, res = -1;
        while(l <= r) {
            int mid = l + r >> 1;
            if(check(b[i], b[mid]) >= q) {
                res = mid;
                r = mid - 1;
            } else l = mid + 1;
        }
        if(res != -1) {
            ans = min(ans, b[res] - b[i]);
            // cout << b[res] - b[i] << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define mod 998244353
#define mx 1000009

ll ans[mx];
ll sumsq[mx];
ll sqsum[mx];

vector<int>v[mx];

ll bigmod(ll n,ll p)
{
    if(p==0)
        return 1;
    if(p==1)
        return (n+mod)%mod;
    if(p%2)
        return (bigmod(n,p-1)*n+mod)%mod;
    else
    {
        ll x=bigmod(n,p/2);
        return (x*x+mod)%mod;
    }
}

ll modinverse(ll n)
{
    return bigmod(n,mod-2)%mod;
}

void divisors()
{
    for(int i=1; i<mx; i++)
    {
        for(int j=i; j<mx; j+=i)
            v[j].push_back(i);
    }
}

///(a*b)/x+(b*c)/x+(c*a)/x=  (ab+bc+ca)/x
///(a+b+c)^2=a*a+b*b+c*c+2(ab+bc+ca)
///(ab+bc+ca)=((a+b+c)^2-(aa+bb+cc))/2


int main()
{
    divisors();

    int n;
    scanf("%d",&n);

    for(int i=0; i<n; i++)
    {
        int val;

        scanf("%d",&val);

        for(int it:v[val])
        {
            sumsq[it]=((sumsq[it]+val)%mod);
            sqsum[it]=(sqsum[it]+bigmod(val,2))%mod;
        }
    }

    ll re=0;

    for(ll i=mx-1; i>=1; i--)
    {
        ll cur=(bigmod(sumsq[i],2)-sqsum[i]);

        cur=(cur+mod)%mod;

        for(ll j=i+i; j<mx; j+=i)
        {
            cur-=ans[j];
            cur=(cur+mod)%mod;
        }

        ans[i]=cur;

        re=(re+(cur*modinverse(i))%mod)%mod;
    }

    re=(re*modinverse(2))%mod;

    printf("%lld\n",re);




    return 0;
}


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

int N;
int mod = 1e9 + 7;

int power(int a, int n){
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        int b = power(a, n / 2);
        return 1ll * b * b % mod;
    } else {
        return 1ll * a * power(a, n - 1) % mod;
    }
}

int inverse(int a) {
    if (a == 1) {
        return 1;
    }
    return power(a, mod - 2);
}

int factorial(int N) {
    if (N == 0) {
        return 1;
    } else {
        return 1ll * N * factorial(N - 1) % mod;
    }
}

int main() {
    cin >> N;
    vector<int> A(N), B(N, 1);  //B[i]: 1/(i+1)までの和
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (i > 0) {
            B[i] = (B[i - 1] + inverse(i + 1)) % mod;
        }
    }
    
    long long answer = 0ll;
    for (int i = 0; i < N; i++) {
        answer += 1ll * (B[i] + B[N - i - 1] - 1) * A[i] % mod;
        answer %= mod;
    }
    
    cout << answer * factorial(N) % mod << endl;
}

Measured memory_bytes: 2560
import bisect
import itertools


N = int(input())
st = [input().split() for _ in range(N)]
s, t = list(zip(*st))
t = [int(i) for i in t]
X = input()

t_cumsum = list(itertools.accumulate(t))
sleep = s.index(X)
ans = t_cumsum[-1] - t_cumsum[sleep]
print(ans)

Measured memory_bytes: 38480
#pragma region header
#ifndef TEMPLATE_HPP
#define TEMPLATE_HPP
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())
using namespace std;
using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename U> vector<U> make_vector(T&& n, U&& val) { return vector<U>(forward<T>(n), forward<U>(val)); }
template <typename T, typename... Args> decltype(auto) make_vector(T&& n, Args&&... args) { return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...)); }
const int INF = 1001001001;
const i64 LINF = 1001001001001001001ll;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
#endif
#pragma endregion

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vi32> rg(n);
  vi32 deg(n);
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    rg[v].push_back(u);
    deg[u] += 1;
  }
  vi32 x;
  rep(i, n) if (deg[i] == 0) {
    x.push_back(i);
  }
  for (int i = 0; i < sz(x); i++) {
    int v = x[i];
    for (int u : rg[v]) {
      deg[u] -= 1;
      if (deg[u] == 0) {
        x.push_back(u);
      }
    }
  }
  vi32 dp(n);
  rep(i, n) {
    int v = x[i];
    for (int u : rg[v]) {
      amax(dp[u], dp[v] + 1);
    }
  }
  int ans = 0;
  rep(i, n) amax(ans, dp[i]);
  cout << ans << endl;
}

#pragma region footer
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  solve();
  return 0;
}
#pragma endregion

Measured memory_bytes: 9756
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;


void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto edges = new int[][](N);
    foreach (_; 0..M) {
        s = readln.split.map!(to!int);
        auto a = s[0] - 1;
        auto b = s[1] - 1;
        edges[a] ~= b;
        edges[b] ~= a;
    }

    auto used = new bool[](N);
    foreach (i; edges[0]) {
        foreach (j; edges[i]) {
            used[j] = true;
        }
    }

    writeln(used[N - 1] ? "POSSIBLE" : "IMPOSSIBLE");
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  for(auto& i : p) cin >> i;
  vector<int> a = p;
  sort(p.begin(), p.end());
  
  bool fl = a == p;
  for(int i = 0; i < n - 1; ++i)
  {
    for(int j = i; j < n; ++j)
    {
      if(fl) break;
      if(i != 0 && i == j) continue;
      swap(a[i], a[j]);
      fl = a == p;
      swap(a[i], a[j]);
    }
    if(fl) break;
  }
  cout << (fl ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
t = 1
# t = input()
# t = int(t)
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	n = input()
	n =int(n)
	ans = 0.5
	if n%2 == 1:
		# print("a")
		ans = (n//2 + 1.0)/(n*1.0)
	print(ans)
	# n,x = map(int,input().strip().split())
	# v = list(map(int,input().strip().split()))[0:n]
	# m = {}
	# for i in v:
	# 	temp = x/i
	# 	if(x%i != 0):
	# 		temp += 1
	# 	m[i] += 1
	# ans = 0
	# rem = 0


Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    int N;
    cin>>N;
    vector<ll> A(N),B(N);
    priority_queue<P> PQ;
    rep(i,N)cin>>A[i];
    rep(i,N){
        cin>>B[i];
        PQ.push({B[i],i});
    }
    ll ans = 0;
    while(!PQ.empty()){
        ll b = PQ.top().first;
        ll idx = PQ.top().second;
        PQ.pop();
        ll a = B[(idx-1+N)%N];
        ll c = B[(idx+1+N)%N];
        ll wa = a+c;
        ll diff = b - A[idx];
        if(diff == 0){
            continue;
        }
        else if(diff<0){
            cout<<-1<<endl;
            return 0;
        }
        else{
            if(diff/wa<=0){
            cout<<-1<<endl;
            return 0;
            }
            //print(A);
            //print(B);
            //cerr<<diff<<" "<<wa<<endl;
            ans += diff/wa;
            b -= (diff/wa)*wa;
            B[idx] = b;
        }
        PQ.push({b,idx});
    }
    if(A!=B){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5492
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = long long;
int main(){
    i64 R,D,X;
    cin >> R >> D >> X;

    i64 ans = X;
    for(int i=0;i<10;i++){
        ans = R*ans - D;
        cout << ans << endl; 
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> vec(1);
  int a = -1, b = -1, c = -1;
  int acount = 0, bcount = 0, ccount = 0;
  for(int i=0; i<n; i++){
    int num;
    cin >> num;
    if(i == 0) a = num;
    else if(a != num && b == -1) b = num;
    else if(a != num && b != num && c == -1) c = num;
    else if(a != num && b != num && c != num){
      cout << "No" << endl;
      return 0;
    }
    if(a == num) acount++;
    if(b == num) bcount++;
    if(c == num) ccount++;
  }
  if(a != -1 && b != -1 && c != -1 && acount == n/3 && bcount == n/3 && ccount == n/3 && (a ^ b) == c){
    cout << "Yes" << endl;
    return 0;
  }else if(c == -1 && ((a == 0 && bcount - acount == acount) || (b == 0 && acount - bcount == bcount))){
    cout << "Yes" << endl;
    return 0;
  }else if(a == 0 && b == -1 && c == -1){
    cout << "Yes" << endl;
    return 0;
  }else{
    cout << "No" << endl;
    return 0;
  }
}


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

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    map<int,int> q;
    vector<bool> a(n);
    int ans=0;
    for(int i=0;i<m;i++){
        int p;
        cin >> p;
        p--;
        string s;
        cin >> s;
        if(s=="WA" && a[p]==false){
            q[p]++;
        }
        else if(s=="AC" && a[p]==false){
            a[p]=true;
            ans++;
        }
    }
    cout << ans <<' ';
    int cnt=0;
    for(auto x:q){
        if(a[x.first]==true){
          cnt+=x.second;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K; cin>>N>>K;
    vector<long> a(N);
    for(int i=0;i<N;i++)
        cin>>a[i];
    vector<long> s;
    for(int i=0;i<N;i++){
        long sum=0;
        for(int j=i;j<N;j++){
            sum+=a[j];
            s.push_back(sum);
        }
    }
    long flag=0;
    for(int i=40;i>=0;i--){
        long temp=flag|(long)pow(2,i);
        long count=0;
        for(auto x:s){
            if((temp&x)==temp)
                count++;
        }
        if(count>=K)
            flag+=(long)pow(2,i);
    }
    cout<<flag;
}

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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string c;
    cin >> c;

    vector<int> cumR(n + 1, 0), cumW(n + 1, 0);
    rep(i, n) {
        cumR[i + 1] = cumR[i] + static_cast<int>(c[i] == 'R');
        cumW[i + 1] = cumW[i] + static_cast<int>(c[i] == 'W');
    }

    int ans = INF;
    rep(i, n + 1) ans = min(ans, max(cumR[n] - cumR[i], cumW[i]));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5136
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
int a[55][55]={};
int w,h;
void dfs(int y,int x){
  a[y][x]=0;
  int dy[8]={-1,-1,-1,0,0,1,1,1};
  int dx[8]={-1,0,1,-1,1,-1,0,1};
  for(int i=0;i<8;i++){
    int ny=y+dy[i];
    int nx=x+dx[i];
    if(nx<0||ny<0||nx>=w||ny>=h)continue;
    if(a[ny][nx]==0)continue;
    dfs(ny,nx);
  }
}
int main(){
  while(1){
    int ans=0;
    cin>>w>>h;
    if(w==0&&h==0)break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>a[i][j];
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(a[i][j]==0)continue;
	ans++;
	dfs(i,j);
      }
    }
    cout<<ans<<endl;
  }
}

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

int ans[101][101];

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int h, w, n;
  cin >> h >> w >> n;
  vector < int > a(n + 1, 0);
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  int k = 1;
  for (int i = 0; i < h; ++i) {
    if (i && ans[i - 1][0] != k) {
      for (int j = w - 1; j >= 0; --j) {
        if (!a[k]) 
          ++k;
        ans[i][j] = k;
        --a[k]; 
      }
    }
    else {
      for (int j = 0; j < w; ++j) {
        if (!a[k]) 
          ++k;
        ans[i][j] = k;
        --a[k]; 
      }
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j)
      cout << ans[i][j] << ' ';
    cout << '\n';
  }
}

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


int func_power2(int num) {
  int beki=0;
  while (num % 2 == 0) {
    num /= 2;
    ++beki;
  }
  return beki;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int count = 0;
  for (int i=0; i<N; ++i) {
    cin >> A.at(i);
    count += func_power2(A.at(i));
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926

int a[3];

int main(){
    int x;
    cin >> x;
    if(x == 7 || x == 5 || x == 3)
        cout << "YES";
    else    
        cout << "NO";
    
}
	


Measured memory_bytes: 256
#include <math.h>
#include <bits/stdc++.h>
#include <deque>
#include<vector>
#define ll long long
#define l long double
#define pi 3.14159265358979323846
#define mod 1000000007
#define vali 1000000000000000000
using namespace std;
int main()
{
    ll a[6];
    for(int i=1;i<=5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        cout<<i<<endl;
    }
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6+5;
const ll N = 1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    if(m>=n) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}

Measured memory_bytes: 3048
S = str(input())
N = len(S)

def is_kaibunn(s):
    n = len(s)
    if n==2:
        return False
    a = ""
    b = ""
    for i in range(int((n-1)/2)):
        a += s[i]
        b += s[n-i-1]
    if a==b:
        return True
    else:
        return False

X = S[0:int((N-1)/2)]
Y = S[int((N+3)/2)-1:N]
if is_kaibunn(S) and is_kaibunn(X) and is_kaibunn(Y):
    print("Yes")
else:
    print("No")

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl a(n),b(n),c(n);
  REP(i,n) cin >> a[i];
  ll samecount = 0;
  REP(i,n){
    cin >> b[i];
    c[i] = b[i];
    if(a[i]==b[i]) samecount++;
  }
  vl cand;
  REP(i,n){
    if(c[i]!=a[i] && c[i]>c[(i-1+n)%n]+c[(i+1)%n]) cand.push_back(i);
  }
  ll ans = 0;
  while(cand.size()>0){
    //cout << "cand : ";
    //REP(i,cand.size()) cout << cand[i] << ",";
    //cout << endl;
    //REP(i,n) cout << c[i] << ",";
    //cout << endl;
    //cout << endl;
    vl nextCand;
    for(int i=0;i<(ll)cand.size();i++){
      ll ind = cand[i];
      ll diff = c[(ind-1+n)%n]+c[(ind+1)%n];
      ll tmp = (c[ind]-a[ind])/diff;
      ans += tmp;
      c[ind] -= tmp*diff;
      if(c[ind]==a[ind]){
        samecount++;
      }
      if(c[(ind-1+n)%n]!=a[(ind-1+n)%n] && c[(ind-1+n)%n]>c[(ind-2+n)%n]+c[ind]) nextCand.push_back((ind-1+n)%n);
      if(c[(ind+1+n)%n]!=a[(ind+1+n)%n] && c[(ind+1+n)%n]>c[(ind+2+n)%n]+c[ind]) nextCand.push_back((ind+1+n)%n);
    }
    cand = nextCand;
  }
  if(samecount==n) cout << ans<< endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 6516
use std::vec::Vec;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (a, b) = {
      let v: Vec<i64> = read_vec();
      (v[0], v[1])
    };

    let ans: i64 = calc(b+1)^calc(a);
    println!("{}", ans);

}


// xorは A xor B = C => C xor A = B が成り立つので0~Aのxorを求められればいい
// 各桁のビットは各桁の１がの個数で決まる
// 偶数 -> 0
// 奇数 -> 1
// 0~a-1の排他的論理和を求める
fn calc(a: i64) -> i64 {
  let mut res: i64 = 0;
  // i桁目の１の個数を求める
  for i in 0..50 {
    let lop: i64 = (1 << (i + 1));
    // 周期が a/loop 回あって, そのうち1が立っているのは次に繰り上がってくる loop/2 回まで
    let mut cnt: i64 = (a / lop) * (lop / 2);

    // 周期になっていないあまりの部分の長さは a%loop そのうち先頭から loop/2は連続して0なので引く
    cnt += cmp::max(0, a % lop - lop / 2);
    if cnt % 2 == 0 {
      res += (1 << i);
    }
  }
  return res;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
typedef long long ll;
const int  N = 1e6+10;
int const mod = 1e9+7;
using namespace std;

int gcd(int a,int b)
{
    if (b == 0)
        return a;
    return gcd(b, a%b);
}
 int n,x,vis[N],cnt[N],cntm=0;

int main()
{
  cin>>n;
  bool tmam=1;
  int GCD=0;
	for(int i=0;i<n;i++)
    {
        cin>>x;
        cnt[x]++;
        GCD=gcd(GCD,x);
    }
    for(int i=2;i<N;i++)
    {
        cntm=0;
        if(vis[i]==0){
        for(int j=i;j<N;j+=i)
        {
            vis[j]=1;
            cntm+=cnt[j];
        }
        if(cntm>1)
            tmam=0;
        }
        if(!tmam)
            break;
    }
    if(tmam)
        cout<<"pairwise coprime"<<"\n";
    else if (!tmam&&GCD ==1)
        cout<<"setwise coprime"<<"\n";
    else
        cout<<"not coprime"<<"\n";
	return 0;
}

Measured memory_bytes: 11444
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
struct Node{
	int x;
	int y;
}a[2000005];
int n;
bool cmp(Node x,Node y){
	return x.y<y.y;
}
int main(){
	in(n);
	for(int i=1;i<=n;i++)in(a[i].x),in(a[i].y);
	sort(a+1,a+1+n,cmp);
	int now=0;
	for(int i=1;i<=n;i++){
		now+=a[i].x;
		if(now>a[i].y){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        if(a.equals(b)){
            System.out.println("H");
        }else{
            System.out.println("D");
        }
    }
}


Measured memory_bytes: 35764
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
#define LLINF 1LL << 60
#define fi first
#define se second
typedef pair<int,int> Pi;
#define pb push_back


int N, M, K, S;
int P, Q;
int mc[100005];

vector<int> G[100005];
queue<int>que;
int flag[100005] = {0};

void bfs()
{
  while(!que.empty()) {
    int v = que.front(); que.pop();
    Rep(i, G[v].size()) {
      int u = G[v][i];
      if(mc[u] == LLINF) {
	flag[u] = 1;
	mc[u] = mc[v] + 1;
	if(mc[u] < S) que.push(u);
      }
    }
  }
}

void Dijkstra()
{
  priority_queue<Pi, vector<Pi>, greater<Pi> >pq;
  
  fill_n(mc, 100005, LLINF);
  mc[0] = 0;
  
  pq.push(Pi(0, 0));

  while(!pq.empty()) {
    int v = pq.top().se, w = pq.top().fi; pq.pop();
    if(w > mc[v]) continue;
    Rep(i, G[v].size()) {
      int u = G[v][i], nw = w;
      if(flag[u] == 2)continue;
      if(u != N - 1) {
	if(flag[u] == 1)nw += Q;
	else nw += P;
      }
      if(nw < mc[u]) {
	mc[u] = nw;
	pq.push(Pi(nw, u));
      }
    }
  }
}

signed main()
{
  int A, B;
  
  cin >> N >> M >> K >> S;
  cin >> P >> Q;
  
  fill_n(mc, 100005, LLINF);
  while(K--) {
    cin >> A; --A;
    que.push(A); mc[A] = 0, flag[A] = 2;
  }

  while(M--) {
    cin >> A >> B; --A, --B;
    G[A].pb(B); G[B].pb(A);
  }

  bfs();
  Dijkstra();

  cout << mc[N - 1] << endl;
  return 0;
}

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


using namespace std ; 

int main ( ) 
{
	int x ; 
	string m ; 
	int counter = 0 ;
	cin >> x >> m ; 
	int max = 0 ;
	for  ( int i = 0 ; i<=x; i++)
	{	if (x==0) 
	{
		break ;
	}
	else if (m[i] == 'I') 
		{
			counter ++;
			if (counter > max) 
			{
				max = counter ;
			}
		}
		else if (m[i] =='D') 
		{
			counter-- ;
		}
	}
	cout << max ; 
		return 0 ; 
}

Measured memory_bytes: 256
import math

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

per  =  0
for i in range(1, N+1):
  omote = max(int(math.ceil(math.log2(K/i))), 0)
  per += (1 / N) * (0.5 ** omote)
  #print(omote)
print(per)

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

struct edge {
	int u, v; edge() {}
	edge(int _u, int _v) :
		u(_u), v(_v) {}
};

struct node { vector<edge> edges; };

struct graph {
	vector<node> nodes; int n;
	graph(int _n) : n(_n) { nodes.resize(n); }

	void add_edge(int u, int v) {
		edge e1(u, v);
		nodes[u].edges.push_back(e1);
	}

	void dfs(int u, vector<int> &visited, vector<int> &ans) {
		visited[u] = true;
		for (auto x : nodes[u].edges) {
			int v = x.v;
			if (!visited[v]) { dfs(v, visited, ans); }
		}
		ans.push_back(u);
	}
	vector<int> topological_sort() {
		vector<int> visited(n, false), ans;
		for (int i = 0; i < n; ++i)
			if (!visited[i]) { dfs(i, visited, ans); }
		reverse(ans.begin(), ans.end());		
		return move(ans);
	}

	int longestPath(vector<int>& topSort) {
		vector<int> DP(n, 0);
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (auto &e : nodes[topSort[i]].edges) {
				DP[e.v] = max(DP[e.v], DP[e.u] + 1);
				ans = max(ans, DP[e.v]);
			}
		}
		return ans;
	}
};

int main() {
	int N, M; cin >> N >> M;
	graph g(N);
	for (int i = 0; i < M; i++) {
		int u, v; cin >> u >> v; u--; v--;
		g.add_edge(u, v);
	}

	vector<int> topSort = g.topological_sort();
	cout << g.longestPath(topSort) << endl;
}

Measured memory_bytes: 7804
b=input()
f=int(b)
# a=input()
c=[]
# for i in range(b):
#     c.append(a[i])
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))
N = 0
for i in range(len(b)):
    c.append(int(b[i]))
d = f//int(sum(c))
e = f/int(sum(c))

if d==e:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 9048
/*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.

___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !


___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard

*/

#include <bits/stdc++.h>

#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2)+1)
#define fuck(x) cout << #x << " : " << x << "   ";
#define findLowVec(v,x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v,x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a,n,x) (lower_bound(a, a+n, x) - a)
#define findUpArr(a,n,x) (upper_bound(a, a+n, x) - a)
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;

template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p)
{return out << "(" << p.first << ", " << p.second << ")";}

template<class A> ostream& operator <<(ostream& out, const vector<A> &v)
{out << "[";for(int i = 0; i < v.size(); i++) {if(i) out << ", ";out << v[i];}return out << "]";}

template<class A,class B> ostream& operator <<(ostream& out, const set<A,B> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

template<class A> ostream& operator <<(ostream& out, const set<A> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

const int mod = 1e9 + 7;

int32_t SALI()
{
    int n,m; cin >> n >> m;
    string a[n]; for(int i = 0; i < n; i++) cin >> a[i];
    int dp[n][m];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(j+1 < m && a[i][j+1] == '.'){
                dp[i][j+1] += dp[i][j];
                dp[i][j+1] %= mod;
            }
            if(i+1 < n && a[i+1][j] == '.'){
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= mod;
            }
        }
    }
    cout << dp[n-1][m-1];
}


/**< WRITEN BY ALI ADELKHAH */



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

int main()
{
	int num = 0, sum = 0;
	char c;
	
	while ((c = getchar()) != EOF){
		if ('0' <= c && c <= '9'){
			num *= 10;
			num += c - '0';
		}
		else {
			sum += num;
			num = 0;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 1120
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	vector<pair<ll, ll>> ab(n);
	rep(i, n) cin >> ab[i].first >> ab[i].second;
	sort(all(ab));

	ll res = 0;
	rep(i, n) {
		res += ab[i].second;
		if (res >= k) {
			dunk(ab[i].first);
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a) for (int i = (a); i >= 0; --i)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    UnionFind(int size) : par(size), rank(size) {
        REP(i, size) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
    bool same(int x, int y) { return find(x) == find(y); }
};

int N, M;
int p[100005];

signed main() {
    cin >> N >> M;
    REPS(i, N) cin >> p[i];

    UnionFind uf(N + 1);
    REPS(i, M) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }

    int ans = 0;
    REPS(i, N) {
        if (uf.same(i, p[i])) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
N = int(input())
xu = [0]*N
for i in range(N):
    xu[i]=input().rstrip().split()



sum = 0
for i in range(N):
    if xu[i][1]=='BTC':
        sum += 380000.0*float(xu[i][0])
    else:
        sum += int(xu[i][0])


print(sum)




Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    string s;
    cin >> s;
    int res = 0;
    int n = s.size();
    int l = 0;
    int r = 0;
    for(int i=0;i-l<n-1-i+r;++i){
        if(s[i-l]=='x'&&s[n-1-i+r]=='x'){
            
        }else if(s[i-l]=='x'){
            res++;
            r++;
        }else if(s[n-1-i+r]=='x'){
            res++;
            l++;
        }else if(s[i-l]!=s[n-1-i+r]){
            put(-1);
            return 0;
        }
    }
    put(res);
    return 0;
}




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

int main()
{
  int64_t N, H, cnt = 0;
  cin >> N >> H;
  vector<int64_t> A(N), B(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i) >> B.at(i);
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  int64_t hp = 0;
  for (int i = N - 1; i >= 0; i--)
  {
    if (A.at(N - 1) >= B.at(i))
      break;
    hp += B.at(i);
    cnt++;
    if (hp >= H)
      break;
  }
  if (hp < H)
    cnt += ((H - hp) % A.at(N - 1) == 0) ? ((H - hp) / A.at(N - 1)) : ((H - hp) / A.at(N - 1)) + 1;
  cout << cnt << endl;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<pair<pair<string,int>,int>> d;
    for (int i = 0; i < n; ++i) {
        string s;
        int j;
        cin>>s>>j;
        d.emplace_back(make_pair(s,-j),i+1);
    }
    sort(d.begin(),d.end());
    for(auto i:d)cout<<i.second<<endl;
    return 0;
}

Measured memory_bytes: 256
m[100],a[100],b[100],i,j,M,B;main(n){for(;scanf("%d",&n)*n;puts(B?"NG":"OK")){for(i=n;i--;B=0)scanf("%d%d%d",m+i,a+i,b+i);for(i=n;i--;B|=M>150)for(M=0,j=n;j--;)M+=a[i]>=a[j]&a[i]<b[j]?m[j]:0;}}

Measured memory_bytes: 0
def gcd(a,b):
    a,b=max(a,b),min(a,b)
    while b>0:
        a,b=b,a%b
    return(a)

k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            ans += gcd(i,gcd(j,k))
print(ans)


Measured memory_bytes: 75160
n,m = map(int,input().split())
S = []
for i in range(m):
    k,*s = map(int,input().split())
    S.append(s)
P = list(map(int,input().split()))
ans = 0
for i in range(2**n):
    switch = [0]*n
    for j in range(n):
        if (i>>j) & 1:
            switch[j] = 1
    for k in range(m):
        cnt = 0
        for l in range(n):
            if switch[l]:
                if (l+1) in S[k]:
                    cnt += 1
        if cnt%2 != P[k]:
            break
    else:
        ans += 1
print(ans)

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

const int N = (5e3) + 5;
const ll OO = 1e15;
int U[N], V[N];
ll W[N];
int n, m, p;
ll dist[N], old[N];

int bellman(int s, int type) {
  dist[s] = 0;
  int it = 0, relax;
  while (it < n) {
    relax = -1;
    for (int j = 0; j < m; ++j) {
      if (dist[U[j]] == OO) continue;
		  if (dist[V[j]] > dist[U[j]] + W[j]) {
	      if (type == 0) {
	        dist[V[j]] = max(-OO, dist[U[j]] + W[j]);
	      } else {
	        dist[V[j]] = -OO;
	      }
	      relax = V[j];
		  }
		}
    it++;
    if (relax == -1) break;
  }
  if (it == n and relax != -1) return relax;
  return -1;
}

ll sp(int s, int e) {
  for (int i = 0; i < n; ++i) {
  	dist[i] = OO;
  }
  int tmp = bellman(s, 0);
  if (dist[e] == OO) return -1; 
  tmp = bellman(s, 1);
  if (dist[e] == -OO) return -1;
  return max(0LL, -dist[e]);
}

// claudio van
int main() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 0; i < m; ++i) {
		scanf("%d %d", &U[i], &V[i]);
		U[i]--; V[i]--;
		scanf("%lld", &W[i]);
		W[i] = p - W[i];
  }
  printf("%lld\n", sp(0, n - 1));
  return 0;
}

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


int main()
{
	int n,y;
	scanf("%d%d",&n,&y);
	
	for(int i=0; i<=n; i++)
		for(int j=0; j<=n; j++)
				if(y==i*10000+j*5000+(n-i-j)*1000 && n-i-j>=0){
					printf("%d %d %d",i,j,n-i-j);
					return 0;
				}
	printf("-1 -1 -1");					
	return 0;
}

Measured memory_bytes: 256
#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 ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//adds two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]
#define ll long long
#define ld long double
#define vv vector
#define pp pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
typedef pair<ll, ll> pll;
typedef vv<bool> vbool;
typedef vv<ll> vll;
typedef vv<ld> vld;
typedef vv<pll> vpll;
#ifdef LOCAL
#include "prettyprint.hpp"
#define LG(args...)                           \
{                                             \
	string _s = #args;                        \
	replace(_s.begin(), _s.end(), ',', ' ');  \
	stringstream _ss(_s);                     \
	err(istream_iterator<string>(_ss), args); \
	cerr << endl;                             \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "(" << *it << ":" << a << ") ";
	err(++it, args...);
}
#define fastio
#else
#define LG(...)
#define fastio                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);
#define endl "\n"
#endif
//:::::::::::::::::::::::::::::::::::::::::::::
const ll INF = 9e18;
const ll MOD = 1e9 + 7;

int main(){
	fastio;
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll tw = 0;
	for(ll i=0; i<n; i++){
		if(s[i] =='W')
			tw++;
	}
	ll ans =0;
	for(ll i=n; i>= (n-tw); i--){
		if(s[i] == 'R')
			ans++;
	}
				cout<<ans;
}

Measured memory_bytes: 3768
#include <stdio.h>
#include <string.h>

#define LEN(x) (strlen(x))
int main(){
  int n, i, j, fp, sp, ans[100], carry;
  char f[1000], s[1000];
  scanf("%d", &n);
  while(n--){
    scanf("%s%s", f, s);
    if(LEN(f) > 80 || LEN(s) > 80){
      puts("overflow");
      continue;
    }

    fp = LEN(f) - 1;
    sp = LEN(s) - 1;
    j = carry = 0;
    while(fp >= 0 || sp >= 0){
      ans[j] = carry;
      if(fp >= 0) ans[j] += f[fp] - '0';
      if(sp >= 0) ans[j] += s[sp] - '0';
      carry = ans[j] / 10;
      ans[j] %= 10;
      j++;
      fp--;
      sp--;
    }
    if(carry) ans[j] = 1;
    else j--;
    if(j >= 80){
      puts("overflow");
      continue;
    }

    for(;j >= 0;j--)
      printf("%d", ans[j]);
    puts("");
  }
  return 0;
}

Measured memory_bytes: 612
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val A = sc.next().toLong()
        val B = sc.next().split(".")
        val Bn = B[0].toInt() * 100 + B[1].toInt()
        pw.println(A * Bn / 100)
    }
}


Measured memory_bytes: 37676
// https://atcoder.jp/contests/abc177/tasks/abc177_c
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
// using cpp_dec = boost::multiprecision::cpp_dec_float_50;
using cpp_int = boost::multiprecision::cpp_int;

using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)
const int MOD = 1e9 + 7;

void solve() {
    int N;
    cin >> N;
    cpp_int s1 = 0, s2 = 0;
    REP(i, N) {
        cpp_int t;
        cin >> t;
        s1 += t;
        s2 += t * t;
    }
    cout << (s1 * s1 - s2) / 2 % MOD << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
int main() {
   int d, n;
   cin >> d >> n;
   int c = 1;
   if(d == 0){
       if(n == 100){
           cout << 101 << endl;
           return 0;
       } else {
           cout << n << endl;
           return 0;
       }
   }
   for(int i = 1; i <= d; i++){
       c *= 100;
   }
   if(n == 100){
       cout << (c * n) + c << endl;
   } else {
       cout << c * n << endl;
   }
   return 0;
}


Measured memory_bytes: 256