akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <set>
#include <iostream>
#include <cassert>
#include <queue>
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define rep(i,a,b) for(int i = a;i < b; ++i)
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int id = 0;
    string s;
    vector<int> A(N+1);
    int succeed = 0, penalty = 0;
    for (int i = 0 ; i < M; ++i) {
        cin >> id >> s;
        if (A[id] == -1) continue; // already AC
        if (s[0] == 'A') {
            succeed++;
            penalty += A[id];
            A[id] = -1;
        }
        else A[id]++;
    }
    cout << succeed << " " << penalty << endl;
    return 0;
}

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

int main() {
	ll N,s=0;
	cin >> N;

	rep(i,N) {
		ll t=i+1;
		if(t%3 && t%5)
			s += t;
	}

	cout << s << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int all = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      all += vec.at(i)*vec.at(j);
    }
  }
  int same = 0;
  for (int i = 0; i < N; i++) {
    same += vec.at(i)*vec.at(i);
  }
  cout << (all-same)/2 << endl;      
}


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

int main() {
	int a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;

	if (a + b < a + c) {
		if (a + b < b + c) {
			cout << a + b << endl;
		}
		else {
			cout << b + c << endl;
		}
	}
	else {
		if (a + c < b + c) {
			cout << a + c << endl;
		}
		else {
			cout << b + c << endl;
		}
	}

}

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

vector <int> prime;
bool is_composite[999999];

void sieve (int n) {
	std::fill (is_composite, is_composite + n, false);
	for (int i = 2; i < n; ++i) {
		if (!is_composite[i]) prime.push_back (i);
		for (int j = 0; j < prime.size () && i * prime[j] < n; ++j) {
			is_composite[i * prime[j]] = true;
			if (i % prime[j] == 0) break;
		}
	}
}

int main(void) {
	sieve(100005);
	int n;
	cin >> n;
	int next = 0;
	int nextprime;
	for (int i = n; i < 100005; i++) {
		if (!is_composite[i]) {
			nextprime = i;
			break;
		} 
	}
	cout << nextprime;
}

Measured memory_bytes: 512
class Dice(object):

    def __init__(self, *args):
        self.faces = [None]
        self.faces.extend(args)
        self.top = self.faces[1]
        self.up = self.faces[5]
        self.down = self.faces[2]
        self.left = self.faces[4]
        self.right = self.faces[3]

    def roll(self, direction):
        if direction == "N":
            self.top, self.up, self.down = self.down, self.top, self.faces[7 - self.faces.index(self.top)]
        elif direction == "S":
            self.top, self.up, self.down = self.up, self.faces[7 - self.faces.index(self.top)], self.top
        elif direction == "W":
            self.top, self.left, self.right = self.right, self.top, self.faces[7 - self.faces.index(self.top)]
        elif direction == "E":
            self.top, self.left, self.right = self.left, self.faces[7 - self.faces.index(self.top)], self.top
        else:
            raise ValueError("{} is not valid direction.".format(direction))

    def get_top(self):
        return self.top


f = [int(i) for i in input().split()]
dice = Dice(*f)
for d in input():
    dice.roll(d)

print(dice.get_top())



Measured memory_bytes: 5612
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int x;
    cin >> x;
    rep(a,20000) rep(b,20000) {
            ll aa = (ll)a*a*a*a*a;
            ll bb = (ll)b*b*b*b*b;
            if(aa+bb == x) {
                cout << a << " " << -b << endl;
                return 0;
            } else if(aa-bb == x) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
}


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

int main(){
  
  int n,p,m[50];

  while(cin>>n>>p && n&&p){
    int w=p,i=0;
    for(int j=0;j<n;j++) m[j]=0;

    while(m[(i+n-1)%n]!=p){
      if(w) m[i]++,w--;
      else w+=m[i],m[i]=0;
      i=(i+1)%n;
    }
    cout<<(i+n-1)%n<<endl;

  }

  return 0;
}

Measured memory_bytes: 1160
#define MyDebug
#include <bits/stdc++.h>

#define rep(i, first, to) for(int i = first; i < to; ++i)
#define REP(i, first, to) for(int i = first; i <= to; ++i)

#ifdef MyDebug
	#define debug(x) cerr << #x << " : " << x << endl
	#define debugP(x) cerr << x << endl
#else
	#define debug(x)
	#define debugP(x)
#endif

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 2 * (int)1e5 + 1;

vector<P> pList;
vector<int> toList, fromList;

void solve() {
	int n, m;
	cin >> n >> m;
	rep (i, 0, m) {
		int v1, v2;
		cin >> v1 >> v2;
		pList.push_back(P(v1, v2));
	}
	rep(i, 0, (int)pList.size()) {
		P tmp = pList[i];
		if (tmp.first == 1) toList.push_back(tmp.second);
		else if (tmp.second == n) fromList.push_back(tmp.first);
	}
	sort(toList.begin(), toList.end());
	for (auto &&tmp : fromList) {
		if (binary_search(toList.begin(), toList.end(), tmp)){
			cout << "POSSIBLE" << endl;
			return;
		}

	}
	cout << "IMPOSSIBLE" << endl;
}

int main() {
	solve();
	return 0;
}

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

int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    double ans = 0;
    int water = 0;
    int sugar = 0;
    for(int i=0;i*100*a<f;i++){
        for(int j=0;j*100*b<f;j++){
            for(int k = 0;k*c<f;k++){
                for(int l=0;l*d<f;l++){
                    //cout << i << " " << j << " " << k << " " << l << endl;
                    if(100*i*a+100*j*b+k*c+l*d > f){
                        continue;
                    }
                    if(i==0&&j==0){
                        continue;
                    }
                    double x = double(double(k*c+l*d)/double(i*100*a+j*100*b+k*c+l*d));
                   // cout << double(e)/double(100+e)<<endl;
                    //cout << d<<endl;
                    if(x>= ans && (a*i+b*j)*e>=(k*c+l*d)){
                        ans = x;
                        water = i*100*a+j*100*b+k*c+l*d;
                        sugar = k*c+d*l;
                      //  cout << "new" << endl;
                    }
                }
            }
        }
    }
    cout << water << " "<<sugar << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
xs = [int(x) for x in input().split()]
fs = [int(f) for f in input().split()]

def lower_bound(l, r, ok):
    if ok(l):
        return l
    else:
        return unsafe_lower_bound(l, r, ok)

def unsafe_lower_bound(l, r, ok):
    if l + 1 >= r:
        return r
    m = (l + r) // 2
    if ok(m):
        return lower_bound(l, m, ok)
    else:
        return lower_bound(m, r, ok)

def ok(xs_asc, fs_desc, k, i):
    b = k
    for x, f in zip(xs_asc, fs_desc):
        over = x*f - i
        training = max(0, (over-1)//f+1)
        b -= training
    return b >= 0


def solve(xs, fs, k):
    xs_asc = sorted(xs)
    fs_desc = sorted(fs, reverse=True)
    l = 0
    r = xs_asc[-1] * fs_desc[0]
    return lower_bound(l, r, lambda i: ok(xs_asc, fs_desc, k, i))

print(solve(xs, fs, k))

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

int main(){
	int i=0;
	char a[1200]={'\0'};
	
	while(scanf("%c",&a[i])&&a[i]!='\n'){
			if(a[i]>=97&&a[i]<=122){
				a[i]=a[i]-32;
			}
			
			else if(a[i]>=65&&a[i]<=90){
				a[i]=a[i]+32;
			}
			i++;
	}
	printf("%s",a);
	return 0;
}



Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
//#include<stdlib.h>
using namespace std;
int main() {
	int y, n, t; string s;
	cin >>t;
	if (t > 1300||t<100) 
	{
      n = t % 100;
		if (n > 13||n==0) { s = "NA"; }
		else { s = "YYMM"; }
	}
	else 
	{
		 n = t % 100;
		if (n > 13||n==0) { s = "MMYY"; }
		else { s = "AMBIGUOUS"; }
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 256
function Main(input){
  
  var str = input.trim()
  
  if(str=="A"){
    console.log("T");
  }else if(str=="T"){
    console.log("A");
  }else if(str=="C"){
    console.log("G");
  }else if(str=="G"){
    console.log("C");
  }
 
}//function end
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
int m,n;
bool t[22][11000];
int dp[11000];
int main(){
while(cin>>m>>n,n||m){
rep(j,10000)dp[j]=0;
rep(i,22)rep(j,10000)t[i][j]=0;
rep(i,m){
	rep(j,n)cin>>t[i][j];
}

int ans=0,cnt=0;
rep(i,(1<<m)){

	cnt=0;
	rep(j,n){
		rep(k,m){
			if(i&(1<<k)&&t[k][j])dp[j]++;
			if((!(i&(1<<k)))&&!t[k][j])dp[j]++;
			
		}
	}
	rep(j,n)cnt+=max(dp[j],m-dp[j]);
	rep(j,n)dp[j]=0;
	ans=max(cnt,ans);
}

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


Measured memory_bytes: 3336
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

template <class F>
class fix_point: F {
public:
  explicit constexpr fix_point(F&& f) noexcept: F(std::forward<F>(f)) {}

  template <class... Args>
  constexpr decltype(auto) operator ()(Args&&... args) const {
    return F::operator ()(*this, std::forward<Args>(args)...);
  }
};

template <class F>
static inline constexpr decltype(auto) make_fix_point(F&& f) noexcept {
  return fix_point<F>{std::forward<F>(f)};
}

struct tree: std::vector<std::vector<size_t>> {
  tree(size_t n): std::vector<std::vector<size_t>>(n) {}

  void connect_with(size_t src, size_t dst) {
    (*this)[src].push_back(dst);
    (*this)[dst].push_back(src);
  }
};

std::vector<intmax_t> nya(const tree& g, intmax_t mod) {
  size_t n = g.size();
  std::vector<size_t> parent(n, -1);
  std::vector<std::vector<intmax_t>> dp0(n), dp1(n);
  std::vector<intmax_t> dp(n);
  for (size_t i = 0; i < n; ++i) {
    dp0[i].resize(g[i].size()+1, 1);
    dp1[i].resize(g[i].size()+1, 1);
  }

  [](auto f) {
    return [=](auto g) {
      return [=](auto&&... args) {
        return f(g(g), std::forward<decltype(args)>(args)...);
      };
    }([=](auto g) {
      return [=](auto&&... args) {
        return f(g(g), std::forward<decltype(args)>(args)...);
      };
    });
  }([&](auto f, size_t v, size_t p) -> intmax_t {
    intmax_t res = 1;
    for (size_t i = 0; i < g[v].size(); ++i) {
      size_t u = g[v][i];
      if (u == p) {
        parent[v] = i;
        continue;
      }
      intmax_t tmp = (f(u, v) + 1) % mod;
      (res *= tmp) %= mod;
      dp0[v][i+1] = tmp;
      dp1[v][i] = tmp;
    }
    return res;
  })(0, -1);

  make_fix_point([&](auto f, size_t v, size_t p, size_t pi) -> void {
    if (v != 0) {
      intmax_t tmp = (dp0[p][pi] * dp1[p][pi+1] + 1) % mod;
      dp0[v][parent[v]+1] = tmp;
      dp1[v][parent[v]] = tmp;
    }
    {
      for (size_t i = 1; i < dp0[v].size(); ++i)
        (dp0[v][i] *= dp0[v][i-1]) %= mod;
      for (size_t i = dp1[v].size()-1; i--;)
        (dp1[v][i] *= dp1[v][i+1]) %= mod;
      dp[v] = dp1[v][0];
    }
    for (size_t i = 0; i < g[v].size(); ++i) {
      size_t u = g[v][i];
      if (u != p) f(u, v, i);
    }
  })(0, -1, -1);

  return dp;
}

int main() {
  size_t N;
  intmax_t M;
  scanf("%zu %jd", &N, &M);

  tree g(N);
  for (size_t i = 1; i < N; ++i) {
    size_t x, y;
    scanf("%zu %zu", &x, &y);
    --x;
    --y;
    g.connect_with(x, y);
  }

  auto dp = nya(g, M);
  for (size_t i = 0; i < N; ++i)
    printf("%jd\n", dp[i]);
}

Measured memory_bytes: 26368
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vvi E(222222),E2(222222);
ll ver[222222];
void dfs(ll now,ll par){
  for(auto a:E[now]){
    if(a==par)continue;
    E2[now].pb(a);
    dfs(a,now);
  }
}
void dfs2(ll now,ll par){
  for(auto a:E2[now]){
    if(a==par)continue;
    ver[a]+=ver[now];
    dfs2(a,now);
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,q;cin>>n>>q;
  for(int i=0;i<n-1;i++){
    ll a,b;cin>>a>>b;
    E[--a].pb(--b);
    E[b].pb(a);
  }
  for(int i=0;i<q;i++){
    ll p,x;cin>>p>>x;
    ver[--p]+=x;
  }
  dfs(0,-1);
  dfs2(0,-1);
  for(int i=0;i<n;i++)
    cout<<ver[i]<<" ";
  cout<<endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    int ans = 1e9;
    for (int i = -100; i <= 100; i++) {
        int cost = 0;
        rep(j, n) cost += (a[j] - i) * (a[j] - i);
        ans = min(ans, cost);
    }

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


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

void search(const vector<vector<int>> &g, queue<int> &q, vector<bool> &tr, vector<int> &cnt, int k, int i)
{
    int l = q.size();
    for (int j = 0; j < l; j++)
    {
        int s = q.front(); q.pop();
        for (int t:g[s])
        {
            if (tr[t]) 
            {
                q.push(t);
                if (t > i) cnt[k]++;
                tr[t] = false;
            }
        }
    }
    if (q.size() < 1) return;
    else search(g, q, tr, cnt, k+1, i);
}

int main(void)
{
    int n, x, y; cin >> n >> x >> y;
    vector<vector<int>> g(n, vector<int>(0));
    for (int i = 0; i < n - 1; i++)
    {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    g[x - 1].push_back(y - 1);
    g[y - 1].push_back(x - 1);

    vector<int> cnt(n, 0);
    for (int i = 0; i < n; i++)
    {
        queue<int> q; q.push(i);
        vector<bool> tr(n, true); tr[i] = false;
        search(g, q, tr, cnt, 0, i);
    }
    for (int k = 0; k < n - 1; k++)
    {
        cout << cnt[k] << endl;
    }
}

Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
  int a,b,c,x;cin>>a>>b>>c>>x;
  int cnt=0;
  for (int i = 0; i < a+1; i++)
  {
    REP(j,b+1){
      REP(k,c+1){
        if (500*i+100*j+50*k==x)cnt++;
      }
    }
  }
  cout<<cnt<<endl;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    ll ans = INF;
    for (ll n = -100; n <= 100; n++) {
        ll s = 0;
        REP(i, N) {
            s += pow(A[i] - n, 2);
        }
        ans = std::min(ans, s);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// problem: "https://atcoder.jp/contests/abc160/tasks/abc160_c"

#include<bits/stdc++.h>

using namespace std;

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

    vector<int>V(n);
    int i;
    for(i=0;i!=n;i++)
        cin>>V[i];

    sort(V.begin(),V.end());
    int m = 0;
    for(i=1;i!=n;i++)
        m = max(m,V[i]-V[i-1]);

    m = max(m,k-V[n-1]+V[0]);
    cout<<k-m;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

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

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	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 { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	long long h, w;
	cin >> h >> w;
	bool ih, iw;
	ih = h % 2 == 0;
	iw = w % 2 == 0;
	if (h == 1 || w == 1)
	{
		cout << 1;
	}
	else if (!ih && !iw)
	{
		cout << w * h / 2 + 1;
	}
	else
	{
		cout << w * h / 2;
	}
}


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

int main() {
  string s;
  cin >> s;
  string kntl = "0168";
  if (s.back() == '3') {
    puts("bon");
  } else if (kntl.find(s.back()) != string::npos) {
    puts("pon");
  } else {
    puts("hon");
  }
  return 0;
}

Measured memory_bytes: 3596
import java.math.BigDecimal;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        BigDecimal[] a = new BigDecimal[n];
 
        BigDecimal result = new BigDecimal(1);
        BigDecimal max = new BigDecimal(1000000000000000000L);
        for(int i=0; i < n; i++){
            a[i] = sc.nextBigDecimal();
            if(a[i].compareTo(BigDecimal.ZERO) == 0) {
                System.out.println(0);
                return;
            }
        }
 
        for(int i=0; i < n; i++){
            result = result.multiply(a[i]);
            if(result.compareTo(max) > 0){
                System.out.println(-1);
                return;
            }
        }
 
        System.out.println(result);
    }
}

Measured memory_bytes: 66928
#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 repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#define YesNo(c) ((c) ? "Yes" : "No")
#ifdef LOCAL
#define dump(x) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] " << #x " = " << (x) << endl;
#else
#define dump(x)
#endif
using ll = long long;
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << ", " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.fst << ", " << p.snd << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.fst >> p.snd; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
////////////////////////////////
#define int ll

int n,q;
vector<vector<int> > g;
vector<int> v;

vector<int> used;
void dfs(int x) {
    used[x] = 1;
    for (int y : g[x]) if (!used[y]) v[y] += v[x], dfs(y);
}

int32_t main() {
    cin >> n >> q;
    g.resize(n);
    v.resize(n);
    used.resize(n);
    rep (i,n-1) {
        int a,b; cin >> a >> b; a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep (i,q) {
        int p,x; cin >> p >> x; p--;
        v[p] += x;
    }
    dfs(0);
    rep (i,n) cout << v[i] << " ";
    cout << endl;
}


Measured memory_bytes: 22784
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
// const long long INF = 1LL << 60;
const int INF = 1010101010;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<double> a(n);
  double sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  SORT(a);
  RSORT(a);  //大きい順にソート
  bool ok = true;
  rep(i, m) {
    if (a[i] < (double)sum / (double)(4 * m)) {
      ok = false;
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define int long long int
#define INF 1e18
#define vec vector<int>
#define REP(i,a,b) for(i=a;i<b;i++)
using namespace std;
main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,k;
  cin>>n>>k;
  int a[n+1],i;
  for(i=1;i<=n;i++)
    cin>>a[i];
    int j=1;
  for(i=k+1;i<=n;i++)
  {
    if(a[i]>a[j])
        cout<<"Yes\n";
    else
        cout<<"No\n";
    j++;
  }

}


Measured memory_bytes: 5228
N = int(input())

dp = [i for i in range(N+1)]
B6 = [6**i for i in range(1,8)]
B9 = [9**i for i in range(1,7)]
L = B6 + B9
L = sorted(list(set(L)))

for i in L :
    for j in range(i, N+1) :
        dp[j] = min(dp[j-i]+1, dp[j])
print(dp[-1])


Measured memory_bytes: 7064
#include <cstdio>

const int MAXN = 3005;
const int MOD = 1000000007;

char str[MAXN];
int f[2][MAXN];

int main() {
    int n;
    scanf("%d %s", &n, str + 1);

    int curr = 0, last = 1;
    f[curr][1] = 1;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= n; j++) {
            f[curr][j] += f[curr][j - 1];
            f[curr][j] >= MOD ? f[curr][j] -= MOD : 0;
        }

        curr ^= 1, last ^= 1;
        if (str[i] == '<') {
            for (int j = 1; j <= i + 1; j++)
                f[curr][j] = f[last][j - 1];
        } else {
            for (int j = 1; j <= i + 1; j++) {
                f[curr][j] = f[last][i] - f[last][j - 1];
                f[curr][j] < 0 ? f[curr][j] += MOD : 0;
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += f[curr][i];
        ans >= MOD ? ans -= MOD : 0;
    }

    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main (){
	long long int a;
	long long int hasil=0;
	scanf("%lld",&a);
	for (int i=1 ; i<=a ; i++){
	
	if (i%3==0 && i%5==0){
//		puts("Fizzbuzz");
	}
	else if (i%3==0){
//		puts ("Fizz");
	}
	else if (i%5==0){
//		puts("Buzz");
	}
	else{
		
	hasil=(hasil+i);
		
	}	
	
	}
	printf("%lld",hasil);
	return 0;
}

Measured memory_bytes: 1716
n, m = map(int, input().split())
l = [1 for i in range(n+1)]
b = [False for i in range(n+1)]
l[1] = 1
b[1] = True
for i in range(m):
    x, y = map(int, input().split())
    if b[x] == True:
        if l[x] == 1:
            b[x] = False
        b[y] = True
    l[x] -= 1
    l[y] += 1
cnt = 0
for i in range(1, n+1):
    if b[i] == True:
        cnt += 1
print(cnt)

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

int main (void) {
    int d;
    scanf("%d", &d);
    char s[100] = "Christmas";

    for (int i = 25 - d; i > 0; i--) {
        strcat(s, " Eve");
    }

    printf("%s", s);
    
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>

int main(void) {
    // int i;
    // FIX1: カウンタ変数はなるべく使わないように組む
    //     : ほとんどの場合は頑張れば使わなくても同じことができる（たぶん）
    int mod26[16];
    char name[16];
    int count = 0;
    long long N;

    scanf("%lld", &N);

    for (int i = 0; i < 16; i++) {
        mod26[i] = N % 26;
        count = i; // FIX: ここと

        // FIX
        if (mod26[i] == 0) {
            mod26[i] = 26;
            N--;
        }

        // FIX
        if (N <= 26) {
            break;
        }

        // FIX: N = N / 26; とおなじ
        N /= 26;

        if (N == 0) {
            break;
        }
    }
    count++; // FIX: ここでほぼ「count = i + 1;」

    // FIX: if -> while
    while (mod26[count - 1] == 0) {
        count--;
    }

    for (int i = 0; i < count; i++) {
        name[i] = 'a' + mod26[count - 1 - i] - 1;
        printf("%c", name[i]);
    }

    return 0;
}


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

#define ll long long
#define ar array
const int mxN=1e7;

int n, d[mxN+1];
ll ans=0;

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

	for (int i=1; i<=mxN; ++i)
		for (int j=i; j<=mxN; j+=i)
			++d[j];
	cin >> n;
	for (int i=1; i<=n; ++i)
		ans+=1ll*i*d[i];
	cout << ans;
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 42672
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
struct SegmentTree{
   private:
       int n;
       vector<ll> node;
   public:
       SegmentTree(int sz,ll init){
           n=1;
           while(n<sz)n*=2;
           node.resize(2*n-1,init);
       }
       void update(int k,ll x){
           k+=n-1;
           node[k]+=x;
           while(k>0){
               k=(k-1)/2;
               node[k]=node[2*k+1]+node[2*k+2];
           }
       }
       //[a,b)での和を返す
       ll get(int a,int b,int k=0,int l=0,int r=-1){
           if(r<0)r=n;
           if(r<=a||b<=l)return 0;
           if(a<=l&&r<=b)return node[k];
           ll xl=get(a,b,2*k+1,l,(l+r)/2);
           ll xr=get(a,b,2*k+2,(l+r)/2,r);
           return xl+xr;
       }
       int find(int a){
           int ret=0;
           while(ret<n-1){
               if(node[2*ret+1]>=a)ret=2*ret+1;
               else {
                   a-=node[2*ret+1];
                   ret=2*ret+2;
               }
           }
           return ret-n+1;
       }
   };


ll sum[101010];
int main(){
    int n,c;
    cin>>n>>c;
    vector<pli>  q1;
    vector<pli> q2;
    rep(i,n)q1.push_back({0,i});
    rep(i,c){
        int t;cin>>t;
        if(t){
            int x;cin>>x;
            q2.push_back({0,x});
        }
        else {
            ll x,y;cin>>x>>y;
            x--;
            sum[x]+=y;
            q1.push_back({-sum[x],x});
            q2.push_back({y,x});
        }
    }
    sort(q1.begin(),q1.end());
    rep(i,n)sum[i]=0;
    SegmentTree sg(q1.size(),0);
    rep(i,n){
        int idx=lower_bound(q1.begin(),q1.end(),pli{0,i})-q1.begin();
        sg.update(idx, 1);
    }
    for(auto e:q2){
        ll y=e.first,x=e.second;
        if(y){
            int idx=lower_bound(q1.begin(),q1.end(),pli{-sum[x],x})-q1.begin();
            sg.update(idx, -1);
            sum[x]+=y;
            idx=lower_bound(q1.begin(),q1.end(),pli{-sum[x],x})-q1.begin();
            sg.update(idx, 1);
        }
        else{
            int idx=sg.find(x);
            cout<<q1[idx].second+1<<" "<<-q1[idx].first<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 14420
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io;
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::mem::{replace, swap};

// [NOTE] つかうときには trim() 入れないと RE になるので注意
// abcde
fn read_as_line() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line
}

// 1 abc
fn read_as_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let s = read_as_line();
    let mut it = s.trim().split_whitespace();
    (
        it.next().unwrap().parse().ok().expect("failed to parse"),
        it.next().unwrap().parse().ok().expect("failed to parse"),
    )
}

fn main() {
    let (x, y): (usize, usize) = read_as_pair();
    let ans = x + y / 2;
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define elif else if
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

const int N = 3e5, M = N;
//=======================

ll int gcd(ll int a, ll int b) { 
    if (b == 0) return a; 
    return gcd(b, a % b);   
} 

void solve() {
  int n,ac(0),wa(0),tle(0),re(0);
  cin >> n;
  while(n--){
    string s;
    cin >> s;
    if(s=="AC") ac++;
    elif(s=="WA") wa++;
    elif(s=="TLE") tle++;
    elif(s=="RE") re++;
  }
  printf("AC x %d\n", ac);
  printf("WA x %d\n", wa);
  printf("TLE x %d\n", tle);
  printf("RE x %d\n", re);
}

int main() {
    //ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());

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

    return 0;
}




Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define     int                 ll
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
	int a; cin >> a;
	cout<<a+a*a+a*a*a<<'\n';
}

signed main() { 
    IO();
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}


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

int main() {
	int n, m;
	cin >> n >> m;
	map<P, bool> mp;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		mp[P(a, b)] = true;
		mp[P(b, a)] = true;
	}
	vector<int> def(n);
	iota(def.begin(), def.end(), 0);
	int ans = 0;
	do {
		bool elf = true;
		if (def[0] != 0) continue;
		rep(i, n - 1) {
			if (mp[P(def[i], def[i + 1])] || mp[P(def[i + 1], def[i])]) continue;
			elf = false;
		}
		if (elf) ans++;
	} while (next_permutation(def.begin(), def.end()));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	string s,t,u;
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if (s==u) --a;
	else --b;
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
rp, sp, pp = map(int, input().split())
t = list(input())
point = 0
pdic = {"r":pp, "s": rp, "p":sp}
dic = {"r":[0], "s":[0], "p":[0]}
for l in range(1,k+1,1):
    prev = None
    for m in range(0,(n+1)//k+1,1):
        if k*m+l <= n:    
            if t[k*m+l-1] == prev:
                dic[t[k*m+l-1]][-1] += 1
            else:
                dic[t[k*m+l-1]].append(1)
            prev=t[k*m+l-1]
# print(dic)
for key, value in dic.items():
    for v in value:
        if v == 1:
            point+=v*pdic[key]
        else:
            point+=(v//2+v%2)*pdic[key]
#     print("key....{},point.....{}".format(key, point))
print(point)

Measured memory_bytes: 5044
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  string s;
  bool f[26] = {};
  cin >> s;
  rep(i,0,s.size()){
    f[s[i]-'a']= true;
  }
  
  rep(i,0,26){
    if(!f[i]){
      P(char('a'+i));
      ret 0;
    }
  }

  P("None");
  ret 0;
}

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

int main() {
    int N;
    vector<int> a(N);

    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end(), greater<int>());

    int dif_score = 0;
    for(int i = 0; i < N; i++) {
        if(i % 2 == 0) {
            dif_score += a[i];
        } else {
            dif_score -= a[i];
        }
    }

    cout << dif_score << endl;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

using cat = long long;

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	cat N, M;
	cin >> N >> M;
	M /= 2;
	if(N > M) cout << M << "\n";
	else cout << (N+M)/2 << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,i,y,z,co=0;
	cin >>x>>y>>z;

	for(i=x;i<=y;i++)
    {
        if(z%i==0)
            co=co+1;
    }
cout<<co<<endl;
}





Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (max(a - c, c - a) <= d) Yes();
  else if (max(a - b, b - a) <= d && max(b - c, c - b) <= d) Yes();
  else No();
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int A,B,C,D;
		A = Character.getNumericValue(s.charAt(0));
		B = Character.getNumericValue(s.charAt(1));
		C = Character.getNumericValue(s.charAt(2));
		D = Character.getNumericValue(s.charAt(3));
		
			if(A+B+C+D==7)System.out.println(A+"+"+B+"+"+C+"+"+D+"=7");
			else if(A+B+C-D==7)System.out.println(A+"+"+B+"+"+C+"-"+D+"=7");
			else if(A+B-C+D==7)System.out.println(A+"+"+B+"-"+C+"+"+D+"=7");
			else if(A+B-C-D==7)System.out.println(A+"+"+B+"-"+C+"-"+D+"=7");
			else if(A-B+C+D==7)System.out.println(A+"-"+B+"+"+C+"+"+D+"=7");
			else if(A-B+C-D==7)System.out.println(A+"-"+B+"+"+C+"-"+D+"=7");
			else if(A-B-C+D==7)System.out.println(A+"-"+B+"-"+C+"+"+D+"=7");
			else if(A-B-C-D==7)System.out.println(A+"-"+B+"-"+C+"-"+D+"=7");
	}
}

Measured memory_bytes: 23764
//### In The Name Of GOD ###

//%% Remember; (((He))) is The (((Accepter))) %%

// GOD IS GREATER ...

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef long double ld ;

//#define int ll
#define pb push_back
#define bp pop_back
#define pf push_front
#define fp pop_front
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())
#define sg(a, b) (a + b - 1) /b

const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1 * 1000 * 1000 * 1000 + 200;
const int MAXN = 10  * 1000 * 1000 + 10;
const int MLOG = 30;
const int NMAX = 20;

signed main() {
	ll n, p;
	cin >> n >> p;
	if(n == 1) {
		cout << p;
		return 0;
	}
	map <int, int> mp;
	for(int i  = 2; i < MAXN; i++) {
		while(p % i == 0)
			p /= i, mp[i]++;
	}
	int ans = 1;
	for(auto v : mp) {
		v.Y /= n;
		for(int i = 0; i < v.Y; i++) ans *= v.X;
	}
	cout << ans;
}



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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct UF {
  vi e;
  UF(int n) : e(n, -1) {}
  bool sameSet(int a, int b) { return find(a) == find(b); }
  int size(int x) { return -e[find(x)]; }
  int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
  bool join(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return false;
    if (e[a] > e[b]) swap(a, b);
    e[a] += e[b]; e[b] = a;
    return true;
  }
};

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, m;
  cin >> n >> m;

  UF uf(n);

  rep(i,0,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    uf.join(a,b);
  }

  int ans = 0;
  rep(i,0,n) ckmax(ans, uf.size(i));
  cout << ans << '\n';
}

Measured memory_bytes: 4008
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include<map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef unsigned int ui;
typedef unsigned short us;
typedef unsigned long long ull;

using namespace std;


int inputValue() {
  int a;
  scanf("%d", &a);
  return a;
};
void inputVector(vector<int>* v) {
  //cin.tie(0);
  //ios::sync_with_stdio(false);
  int a;
  while (cin >> a) {
    if (a == -1)break;
    v->push_back(a);
  }
};

void inputVector(vector<int> * p, int a) {
  p->clear();
  p->shrink_to_fit();
  rep(i, a) {
    int input;
    cin >> input;
    p->push_back(input);
  }
}

void inputVector2(vector<vector<int>>& v, ui r, ui c) {
  int temp;
  for (size_t i = 0; i < r; i++)
  {
    for (size_t j = 0; j < c; j++)
    {
      scanf("%d", &temp);
      v[i][j] = temp;
    }
  }
}
void inputVector3(vector<int>* v0, vector<int>* v1) {
  int a;
  unsigned short count = 0b0;
  while (cin >> a) {
    if (a == -1)break;
    if (count)v0->push_back(a); else v1->push_back(a);
    count = count ^ 1;
  }
};

template <typename T>
void output(T a, int precision) {
  if (precision > 0) {
    cout << setprecision(precision) << a << "\n";
  }
  else {
    cout << a << "\n";
  }
}

template<template <class...> class map, typename T_0, typename T_1, typename... Args>
void inputMap(map<T_0, T_1, Args...>& mp) {
  T_0 a;
  T_1 b;
  while (cin >> a && a!=-1) {
    cin >> b;
    mp.insert(make_pair(a, b));
  }
}

int main(int argc, const char * argv[]) {
  ui n;
  ui m;
  scanf("%d %d", &n, &m);
  ui nokori = m;
  multimap<ui, ui> nanbon;
  ull kingaku = 0;
  inputMap(nanbon);
  for (auto entry : nanbon) {
    if (nokori > entry.second) {
      nokori -= entry.second;
      kingaku += (ull)entry.first * entry.second;
    }
    else {
      kingaku += (ull)entry.first * nokori;
      break;
    }
  }
  printf("%lld", kingaku);
  return 0;
}

Measured memory_bytes: 4992
def str_to_num(list_input, str_input):
    if str_input == 'S' and list_input[1] % 2 == 0:
        list_input[0] += 1
    if str_input == 'N' and list_input[1] % 2 == 0:
        list_input[0] -= 1
    if str_input == 'E' and list_input[0] % 2 == 0:
        list_input[1] += 1
    if str_input == 'W' and list_input[0] % 2 == 0:
        list_input[1] -= 1

dies = [[0, 0], [1, 0], [0, 1], [0, -1], [-1, 0], [2, 0]]
num = list(map(int, input().split()))
order = input()

for c in order:
    for i in dies:
        str_to_num(i, c)
        
[print(num[j]) for j in range(6) if (dies[j][0]+dies[j][1])%4 == 0]


Measured memory_bytes: 5604
import sys
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
n = int(input())
a = [int(x) for x in input().split()]
d = defaultdict(int)
for v in a:
    d[v] += 1
r = 0
for v in d:
    r += d[v] * (d[v] - 1) // 2
for v in a:
    if d[v] == 1:
        print(r)
    else:
        r1 = r - d[v] * (d[v] - 1) // 2 + (d[v] - 2) * (d[v] - 1) // 2
        print(r1)



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

def main():
    while True:
        a, l = input().strip().split()
        l = int(l)
        if l == 0:
            break
        a = a.zfill(l)
        check = [int(a)]
        j = 1
        ok = False
        while True:
            tmp = "".join(sorted(list(a)))
            # print(tmp)
            a = int(tmp[::-1]) - int(tmp)
            i = 0
            for i in range(j):
                if a == check[i]:
                    ok = True
                    break
            if ok:
                print(i, a, j-i)
                break
            else:
                check.append(a)
                a = str(a).zfill(l)
                j += 1




if __name__ == "__main__":
    main()



Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

void scoring(vector<int>& schedule);
int D;
vector<int> decline(26);
vector<vector<int>> satis(365, vector<int>(26));

void solve_greedy(vector<int>& schedule){
    for(int d = 0;d < D;d++){
        int sel = 0;
        for(int i = 0;i < 26;i++){
            if(satis[d][i] > satis[d][sel]){
                sel = i;
            }
        }
        schedule[d] = sel;
    }
}

int main(){
    cin>>D;
    for(int i = 0;i < 26;i++){
        int c;cin>>c;
        decline[i] = c;
    }
    for(int d = 0;d < D;d++){
        for(int i  = 0;i < 26;i++){
            int s;cin>>s;
            satis[d][i] = s;
        }
    }
    vector<int> schedule(D,0);
    solve_greedy(schedule);
    for(int i = 0;i < schedule.size();i++){
        cout<<schedule[i]+1<<endl;
    }
    // scoring(schedule);


}

void scoring(vector<int>& schedule){
    vector<int> lastHeld(26, 0);
    ll sat = 0;
    for(int d = 1;d <= D;d++){
        int contest = schedule[d-1];
        lastHeld[contest] = d;
        for(int i = 0;i < 26;i++){
            if(i == contest){
                sat += satis[d-1][i];
            }
            sat -= decline[i] * (d-lastHeld[i]);
        }
        cout<<sat<<endl;
    }
}

Measured memory_bytes: 3680