akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
using namespace std;
#pragma warning (disable: 4996)
long long ret[26];
int main() {
	string S; cin >> S;
	for (int i = 0; i < S.size(); i++) ret[S[i] - 'a']++;
	long long ans = 1LL * (1LL * S.size())*(1LL * S.size() + 1LL) / 2LL; ans++;
	for (int i = 0; i < 26; i++) ans -= ret[i] * (ret[i] + 1) / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,A,B;
	scan(N>>A>>B);
	string S;
	scan(S);
	int Anow=0,Bnow=0;
	rep(i,N){
		if(S[i]=='a'){
			if(Anow+Bnow<A+B){
				prin("Yes");
				Anow++;
			}
			else prin("No");
		}
		else if(S[i]=='b'){
			if(Anow+Bnow<A+B&&Bnow<B){
				prin("Yes");
				Bnow++;
			}
			else prin("No");
		}
		else prin("No");
	}
	
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
int main() {
  long long int N,M;
  cin >> N >> M;
  if(abs(N - M) >= 2) {
    cout << 0 << endl;
    return 0;
  }
  long long int NS = 1;
  long long int MS = 1;
  for(int i = 1; i <= N; i++) {
    NS = (NS * i) % MOD;
  }
  for(int i = 1; i <= M; i++) {
    MS = (MS * i) % MOD;
  }
  if(abs(N - M) == 1) {
    cout << (NS * MS) % MOD << endl;
  } else {
    cout << (((NS * MS) % MOD) * 2) % MOD << endl;
  }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;


int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    cin >> s;
    for (int i = min(a, b); i <= max(c, d) - 1; i++) {
        if (s[i] == s[i + 1] && s[i] == '#') {
            puts("No");
            return 0;
        }
    }
    if (c > d) {
        int k = -1;
        for (int i = b; i < n - 1; i++)
            if (s[i - 1] == s[i] && s[i] == s[i + 1]) {
                k = i;
                break;
            }
        if (k == -1 || k > d) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <math.h>
#include<algorithm>
#include <utility>
using namespace std;
int main() {
	int  n, add, money = 100000;
	cin >> n;
	add = 0;
	money = 100000;
	for (int i = 0; i < n; i++) {
		add = money*0.05;
		money += add;
		if (money % 1000 != 0) {
			money /= 1000;
			money *= 1000;
			money += 1000;
		}
	}
	cout << money << endl;
	return 0;
}

Measured memory_bytes: 3068
S=input()
T='ATCG'

flag =0
ans =0
now =0

for i in range(len(S)):
    flag =0
    for j in range(4):
        if S[i] == T[j]:
            flag +=1
    if flag !=1:
        now =0
    else:
        now +=1
        ans = max(now, ans)
        


print(ans)

Measured memory_bytes: 8864
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
	cin>>s;
	int len=s.size();
	
	if(len%2==1){printf("No\n");return 0;}
	
	for(int i=0;i<len;++i)
	{
		if(i%2==0 && s[i]=='h');
		else if(i%2==1 && s[i]=='i');
		else{printf("No\n");return 0;}
	}
	
	printf("Yes\n");
	return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INF = 2147483647;
const long long LINF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int K;
vector<ll> cand;

void dfs(ll n, int d){
    if(d > 10) return;
    cand.push_back(n);
    ll t = n%10;
    if(n != 0) dfs(n*10 + t, d+1);
    else{
        REP(i,9) dfs(i+1,1);
    }
    if(t > 0) dfs(n*10 + t-1, d+1);
    if(t < 9) dfs(n*10 + t+1, d+1);
    return;
}

int main(void){
    cin >> K;
    dfs(0,0);
    SORT(cand);
    cand.erase(unique(cand.begin(), cand.end()), cand.end());
    ll ans = cand[K];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in ggt(in a, in b){
  if(b==0)
    return a;
  return ggt(b,a%b);
}
in n;
VVI d;
VI a;
VI usd;
VI ord;
void dfs(in u){
  usd[u]=1;
  ord.PB(u);
  forn(i,n){
    if(usd[i]||d[u][i])
      continue;
    dfs(i);
  }
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>n;
  a.resize(n);
  forn(i,n)
    cin>>a[i];
  usd.resize(n);
  sort(all(a));
  d.resize(n,VI(n));
  forn(i,n){
    forn(j,n){
      if(j==i)
	continue;
      if(ggt(a[i],a[j])==1)
	d[i][j]=1;
    }
  }
  forn(z,n){
    if(usd[z])
      continue;
    dfs(z);
  }
  VI blok(n);
  forn(i,n){
    for(in j=i+1;j<n;++j)
      if(!d[ord[i]][ord[j]])
	++blok[ord[j]];
  }
  VI rord;
  usd=VI(n,0);
  in pos;
  forn(z,n){
    for(in i=n-1;i>=0;--i){
      if(usd[i] || blok[i])
	continue;
      rord.PB(i);
      pos=0;
      while(ord[pos]!=i)
	++pos;
      for(in j=pos+1;j<n;++j){
	if(!d[i][ord[j]])
	  --blok[ord[j]];
      }
      usd[i]=1;
      break;
    }
  }
  forn(i,n)
    cout<<a[rord[i]]<<" ";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 31872
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,n;
    cin >> h >> n;
    int w[1005],v[1005];
    int dp[1005][20005];

    rep(i,n+1){
        rep(j,20001){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    rep(i,n) cin >> v[i] >> w[i];
    rep(i,n){
        rep(j,h+1){
            chmin(dp[i][min(j+v[i],h)],dp[i][j]+w[i]);
            chmin(dp[i+1][j],dp[i][j]);
        }
    }
    int ans = INF;
    PRINT(dp[n][h]);
}

Measured memory_bytes: 78464
#include <stdio.h>

int main(void)
{
	int a, b, c;

	scanf("%d%d%d", &a, &b, &c);

	if (a == b && a==c) {
		printf("No\n");
	}
	else if (a != b && a != c && b != c){
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}

	return 0;
}

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

int main(){
  int i;
  cin>>i;
  string A;
  A=to_string(i);
  for(int a=0;a<3;a++){
    if(A[a]=='7'){
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
}

Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

int a[10010];
int n, m, s;

int main() {
    read(n), read(m);
    for (int i = 1; i <= m; ++i)    read(a[i]), s += a[i];
    if (s <= n) printf("%d\n", n - s);
    else    printf("-1\n");
    return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int k;
    cin >> n >> k;
    int dis = 0;
    for(int i = 0;i < n;i++)
    {
        int x;
        cin >> x;
        dis += min(abs(x) * 2,abs(k-x) * 2);
    }
    cout << dis;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

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

long long int lcm(long long int a,long long int b)
{
    long long int g = gcd(a,b);
    return a / g * b;
}

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

    long long int ans = 1LL;

    for(int i=0;i < n;i ++)
    {
        long long int t;
        cin >> t;
        ans = lcm(ans,t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  ll ans=0;
  int a=1;
  for(int i=0;i<m;i++)
    a*=2;
  int aaa=(n-m)*100;
  ans+=(1900*m)*a+aaa*a;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
typedef vector<string> vs;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
const ll MOD=1000000007;
const ll mod=998244353;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void precompute(){

	return;
}
void solve(){
	string s;
	cin>>s;
	map<string,bool>m;
	m["AKIHABARA"]=1;
	m["KIHABARA"]=1;
	m["AKIHBARA"]=1;
	m["AKIHABRA"]=1;
	m["AKIHABAR"]=1;
	m["KIHBARA"]=1;
	m["KIHABRA"]=1;
	m["KIHABAR"]=1;
	m["AKIHBRA"]=1;
	m["AKIHBAR"]=1;
	m["AKIHABR"]=1;
	m["KIHBRA"]=1;
	m["KIHBAR"]=1;
	m["KIHABR"]=1;
	m["AKIHBR"]=1;
	m["KIHBR"]=1;
	if(m[s])cout<<"YES\n";
	else cout<<"NO\n";
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	precompute();
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3656
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    double p[n]; for (int i = 0; i < n; i++) cin >> p[i];
    double dp[3000][3000] = {};
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        dp[i][0] = dp[i-1][0] * (1 - p[i-1]);
        for (int k = 1; k <= i; k++) {
            dp[i][k] = dp[i-1][k] * (1-p[i-1]) + dp[i-1][k-1] * p[i-1];
        }
    }
    double ans = 0;
    for (int k = n/2+1; k <= n; k++) ans += dp[n][k];
    cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 70528
def main():
    H, W = map(int, input().split())
    coins = [list(map(int, input().split())) for _ in range(H)]
    moves = []
    for i in range(1, H+1):
        for j in range(1, W+1):
            if i == H and j == W:
                break
            if j == W:
                ni, nj = i+1, j
            else:
                ni, nj = i, j+1
            if coins[i-1][j-1] % 2 == 1:
                coins[i-1][j-1] -= 1
                coins[ni-1][nj-1] += 1
                moves.append((i, j, ni, nj))
    print(len(moves))
    for i, j, ni, nj in moves:
        print(i, j, ni, nj)


if __name__ == "__main__":
    main()


Measured memory_bytes: 71516
from collections import *
from heapq import*
import sys
input=lambda:sys.stdin.readline()


def BFS(point,d):
    cost=[1e7]*(n+1)
    cost[point]=0
    Q=[]
    heappush(Q,(0,point))
    
    while Q:
        c,p=heappop(Q)
        for np in d[p]:
            if cost[np]==1e7:
                cost[np]=c+1
                heappush(Q,(c+1,np))
    return cost

n=int(input())
d=[[]for i in range(n+1)]

for i in range(n-1):
    a,b=map(int,input().split())
    d[a].append(b)
    d[b].append(a)

x=BFS(1,d)[1:]
y=BFS(n,d)[1:]

#print(x,y)

F=0
S=0

for s,t in zip(x,y):
    if s<=t:
        F+=1
    else:
        S+=1

if F<=S:
    print("Snuke")
else:
    print("Fennec")


Measured memory_bytes: 95216
N,W = map(int,input().split())
import numpy as np
dp = np.full(N*1000 +1,W+1,dtype=np.int64)
dp[0]=0
for _ in range(N):
    w,v = map(int,input().split())
    dp[v:] = np.minimum(dp[:-v] + w, dp[v:])
print(np.max(np.where(dp <= W)))

Measured memory_bytes: 14904
import math

cou = 0
n = int(input())
A = [int(input()) for i in range(n)]

for i in range(n):
    a_sq = int(math.sqrt(A[i]))
    for j in range(2,a_sq+2):
        if(A[i]%j==0 and not(A[i]==j)):
            break
        if(j==a_sq+1):
            cou += 1

print(cou)



Measured memory_bytes: 6012
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define endl '\n'

long long qexp(long long b,long long p,int m){
    long long res=1;
    while (p){
        if (p&1) res=(res*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return res;
}


int n;
ll arr[200005];

map<ii,ll> memo;

const ll INF=1e18;

ll dp(int i,int j){
	if (i<0) return -INF;
	if (j==1) return arr[i];
	if (memo.count(ii(i,j))) return memo[ii(i,j)];
	if ((i%2==0 && i/2==j) || i/2==j-1){
		//cout<<i<<" "<<j<<endl;
		return memo[ii(i,j)]=max(dp(i-2,j-1),dp(i-3,j-1))+arr[i];
	}
	
	return -INF;
}

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

	cin>>n;
	
	for (int x=0;x<n;x++) cin>>arr[x];

	cout<<max(dp(n-3,n/2),max(dp(n-2,n/2),dp(n-1,n/2)));
}

Measured memory_bytes: 34864
def main():
    N, M = map(int, input().split())
    A = [0] * (N + 1)
    for _ in range(M):
        L, R = map(int, input().split())
        A[L - 1] += 1
        A[R] -= 1
    c = 0
    ans = 0
    for i, a in enumerate(A):
        c += a
        if c == M:
            ans += 1
    print(ans)


main()


Measured memory_bytes: 3956
import sys, itertools

N = int(input())
W = list(map(int, sys.stdin.readline().rsplit()))

S = list(itertools.accumulate(W))

res = 10 ** 9
for i in range(N):
    res = min(res, abs(S[i] - (S[-1] - S[i])))

print(res)


Measured memory_bytes: 9112
//AtCoder C - Pyramid
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
struct Dat{
    ll x,y;
    ll h;
};
int main() {
#if LOCAL&0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N; cin>>N;
    vector<Dat> dtbl(N);
    for(auto&& d:dtbl){
        cin>>d.x>>d.y>>d.h;
    }
    sort(dtbl.begin(),dtbl.end(),[](auto& a, auto& b){return a.h>b.h;});
    auto check_data = [&](const Dat& d,ll cx,ll cy){
        ll h=abs(d.x-cx)+abs(d.y-cy)+d.h;
        return h;
    };
    auto check2 = [&](const Dat& d,ll cx,ll cy, ll h){
        return (max(h-abs(d.x-cx)-abs(d.y-cy),(ll)0)==d.h);
    };
    for(ll cy=0;cy<=100;++cy){
        for(ll cx=0;cx<=100;++cx){
            ll h=check_data(dtbl[0],cx,cy);
            if (h<0) break;
            bool ok_flag=true;
            for(const auto& d:dtbl){
                ok_flag &= check2(d,cx,cy,h);
                if(!ok_flag) break;
            }
            if (ok_flag){
                cout<<cx<<" "<<cy<<" "<<h<<endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
a = list(map(int,input().split()))
appLeft = n%2!=0
i = 0
ans = deque()
while i < n:
    if appLeft:
        ans.appendleft(a[i])
    else:
        ans.append(a[i])
    appLeft = not appLeft
    i+=1
print(" ".join(list(map(str,list(ans)))))

Measured memory_bytes: 30784
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int n;
int a[100005];
int b[100005];
int dif[100005];
int ans;

signed main(){
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		scanf("%ld", &a[i]);
	}
	for(int i = 0; i < n; i++){
		scanf("%ld", &b[i]);
		dif[i] = a[i] - b[i];
	}
	std::sort(dif, dif+n);
	/*
	for(int i = 0; i < n; i++){
		printf("%ld ", dif[i]);
	}
	printf("\n");
	//*/
	int neg = 0, pos = 0, negcnt = 0;
	for(int i = 0; i < n; i++){
		if(dif[i] < 0){
			neg += -dif[i];
			negcnt++;
		}else{
			pos += dif[i];
		}
	}
	if(neg > pos){
		printf("-1\n");
		return 0;
	}
	int change = 0;
	if(neg == 0){
		printf("0\n");
		return 0;
	}
	for(int i = n-1; i >= 0; i--){
		change += dif[i];
		if(change >= neg){
			printf("%ld\n", n-i + negcnt);
			return 0;
		}
	}
	return 0;
}


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

int main() {
  int value1;
  int value2;
  
  cin >> value1 >> value2;
  
  if ((value1 * value2) % 2 == 0)
  {
    cout << "Even" << endl;
  }
  else
  {
    cout << "Odd" << endl;
  }
}



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

int main(void) {
	int N;
	cin >> N;
	int reg=0;
	for (int i=1;i<=N; i+=2) {
		int cnt=0;
		for (int j=1; j<=N; j+=2) {
			if (i%j==0) cnt++;
		}
		if (cnt==8) reg++;
	}
	cout << reg << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import product

def mat2_mul(X, Y):
	z = [[0, 0], [0, 0]]
	for (i, j, k) in product(range(2), range(2), range(2)):
		z[i][j] += X[i][k] * Y[k][j]
	return z

def mat2_pow(X, n):
	if n == 0:
		return [[1, 0], [0, 1]]
	elif n % 2:
		return mat2_mul(X, mat2_pow(X, n - 1))
	else:
		half_pow = mat2_pow(X, n / 2)
		return mat2_mul(half_pow, half_pow)

def fibona(n):
	if n == 0:
		return 0
	else:
		f = [[0, 1], [1, 1]]
	return mat2_pow(f, n - 1)[1][1]

def main():
    n, m = map(int,input().split())
    mlis = []
    for _ in range(m):
        a = int(input())
        mlis.append(a)
    ans = 1
    mae = 0

    infi = 10 ** 9 + 7
    for num in mlis:
        ans *= fibona(num-mae)
        ans %= infi
        mae = num + 1

    nobori = n - mae + 1
    ans *= fibona(nobori) 
    ans %= infi
    print(int(ans))
    



if __name__ == "__main__":
    main()

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

int main()
{
	string s; cin >> s;
	bool C=false, F=false;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'C')C = true;
		if (s[i] == 'F')if(C)F = true;
	}

	if (C&&F)cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
  int n, ans = 0;
  char s;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
      scanf("%c", &s);
      if (s == 'Y') ans = 1;
  }

  printf(ans == 0 ? "Three" : "Four");
  
  return 0;
}


Measured memory_bytes: 128
#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);
  }
  
  sort(vec.begin(),vec.end());
  cout<<vec.at(n-1)-vec.at(0)<<endl;
}

Measured memory_bytes: 256
open Batteries

let () =
  let n = Scanf.scanf "%d\n" (fun a -> a) in

  let arr = Array.make n 0 in
  for i = 0 to n-1-1 do
    let c = Scanf.scanf "%d " (fun c -> c) in
    Array.set arr i c
  done;
  let c = Scanf.scanf "%d\n" (fun c -> c) in
  Array.set arr (n-1) c;

  let s_arr = Array.copy arr in
  Array.sort compare s_arr;

  let mid1 = Array.get s_arr ((n/2)-1) in
  let mid2 = Array.get s_arr (n/2) in

  for i = 0 to n-1 do
    print_int (
      if ((Array.get arr i) <= mid1) then mid2
      else mid1
    );
    print_endline ""
  done;



Measured memory_bytes: 8448
#include<bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%mod)
#define mod 1000000007
#define pb push_back
#define pii pair<int, int>
#define mkpii make_pair
#define STREAM_FAST ios::sync_with_stdio(false)
using namespace std;
const int maxn = 1e6 + 7;
struct node
{
	int v, w, next;
	node(int v, int w) : v(v), w(w) {}
	node(){}
	bool operator < (const node &rhs) const 
	{
		return w > rhs.w;
	}
}e[maxn << 1];
map<pii, int> mp;
int n, m;
int head[maxn], tot = 0;
void add(int u, int v, int w)
{
	++tot; 
	e[tot].v = v; e[tot].w = w; 
	e[tot].next = head[u]; head[u] = tot;
}
int getid(int x, int y)
{
	pii tmp = mkpii(x, y);
	if (!mp.count(tmp)) mp[tmp] = ++n;
	return mp[tmp];
}
priority_queue<node>q;
int dis[maxn], vis[maxn];
int dijkstra(int s, int t)
{
	MEM(dis, 0x3f3f3f3f);
	q.push(node(s, 0)); dis[s] = 0;
	while (!q.empty())
	{
		int u = q.top().v; q.pop();
		if (vis[u]) continue; vis[u] = 1;
		for (int i = head[u]; i; i = e[i].next)
		{
			int v = e[i].v;
			if (dis[v] > dis[u] + e[i].w)
			{
				dis[v] = dis[u] + e[i].w;
				q.push(node(v, dis[v]));
			}
		}
	}
	return dis[t] >= 0x3f3f3f3f ? -1 : dis[t] / 2;
}
int main()
{
	scanf("%d%d", &n, &m);
	int s = 1, t = n;
	while (m--)
	{
		int u, v, c; scanf("%d%d%d", &u, &v, &c);
		int uc = getid(u, c), vc = getid(v, c);
		add(u , uc, 1); add(uc, u, 1);
		add(uc, vc, 0); add(vc, uc, 0);
		add(vc, v, 1); add(v, vc, 1);
	}
	printf("%d\n", dijkstra(s, t));
	return 0;
}


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

int main(){
	string s, p;
	cin >> s >> p;
	s += s;
	for(int i = 0; i < s.size(); i++) if(s[i] == p[0]){
		bool f = true;
		for(int j = 0; j < p.size(); j++){
			if(s.size() <= i + j){
				f = false;
				break;
			}
			f &= s[i + j] == p[j];
		}
		if(f){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
vector<long long> divisor(long long n){
    vector<long long> res;
    for(long long i = 1; i*i <= n; i++){
        if(n%i==0){
            res.push_back(i);
            if(n/i != i)res.push_back(n/i);
        }
    }
    return res;
}
int main(){ 
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  ll sum = 0;
  rep(i,n) cin >> a[i], sum += a[i];

  auto d = divisor(sum);
  ll res = 0;
  for (auto p : d) {
    vector<ll> cum(n+1,0);
    vector<int> b(n);
    for (int i = 0; i < n; i++) b[i] = a[i] % p;
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++) cum[i + 1] = cum[i] + b[i];
    bool ok = false;
    for (int i = 0; i <= n; i++) {
      ll r = p * (n - i) - (cum[n] - cum[i]);
      ll l = cum[i];
      if (max(r, l) <= k) ok = true;
    }
    if (ok) res = max(res, p);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int LCM(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,d; cin >> n >> d;
    int x[n][d];
    int ans = 0,cnt = 0;
    rep(i,n) rep(j,d) cin >> x[i][j];
    rep(i,n){
        FOR(j,i + 1,n){
            cnt = 0;
            rep(k,d) cnt += pow(x[i][k] - x[j][k],2);
          	if(floor(sqrt(cnt)) == sqrt(cnt)) ans++;
        }
    }
    ANS;

    return 0;
}

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

int main(){
	int tc, b, f, r, v;
	int one[5][15], two[5][15], three[5][15], four[5][15];
	
	for(int i=0; i<3; i++){
		for(int j=0; j<10; j++){	
			one[i][j]=two[i][j]=three[i][j]=four[i][j]=0;
		}
	}
	
	scanf("%d", &tc);getchar();
	for(int i=0; i<tc; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		if(b==1){
			one[f-1][r-1] += v;
		}
		else if(b==2){
			two[f-1][r-1] += v;
		}
		else if(b==3){
			three[f-1][r-1] += v;
		}
		else if(b==4){
			four[f-1][r-1] += v;
		}
		getchar();
	}
	
	for(int i=0; i<3; i++){
		for(int j=0; j<10; j++){
			printf(" %d", one[i][j]);
		}
		printf("\n");
	}
	printf("####################\n");
	
	for(int i=0; i<3; i++){
		for(int j=0; j<10; j++){	
			printf(" %d", two[i][j]);
		}
		printf("\n");
	}
	printf("####################\n");
	
	for(int i=0; i<3; i++){
		for(int j=0; j<10; j++){
			printf(" %d", three[i][j]);
		}
		printf("\n");
	}
	printf("####################\n");
	
	for(int i=0; i<3; i++){
		for(int j=0; j<10; j++){
				printf(" %d", four[i][j]);
			}
		printf("\n");
	}
	
}


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

dp = [float("INF") for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    dp[i+1] = min(dp[i] + (x[i+1] - x[i]) * a, dp[i] + b)

print(dp[-1])

Measured memory_bytes: 63000
#include<iostream>
using namespace std;
int main(){
    int n,count = 0;
    cin>>n;
    int l[100];
    for(int i = 0; i<n; i++){
        cin>>l[i];
    }
    for(int i = 0; i<n-1; i++){
        int minj = i;
      for(int j = i; j < n; j++){
          if(l[j]<l[minj]) minj = j;
      }
      if(l[minj]==l[i]) continue;
      int min = l[minj];
      l[minj] = l[i];
      l[i] = min;
      count++;
    }
    for(int k= 0; k<n-1; k++){
      cout<<l[k]<<" ";
    }
    cout<<l[n-1]<<endl;
    cout<<count<<endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> ll(n);
  for (int i = 0; i < n; ++i) {
    cin >> ll[i];
  }
  sort(ll.begin(), ll.end());
  int ans = 0;
  for (int i = 0; i < n-1; ++i) { 
    for (int j = i+1; j < n-1; ++j) { 
      int key = ll[i]+ll[j]-1;
      auto it = upper_bound(ll.begin(), ll.end(), key);
      int id = it-ll.begin();
      // cerr << i << " " << j << " " << key << " " << id << endl;
      if (id <= j) continue;
      ans += (id-j-1);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
S = int(input())


pre = S // 100
lat = S % 100

# pre is MM?
is_pre_mmable = False
if 0 < pre and pre <= 12:
    is_pre_mmable = True

is_lat_mmable = False
if 0 < lat and lat <= 12:
    is_lat_mmable = True

if is_pre_mmable and is_lat_mmable:
    print('AMBIGUOUS')
elif is_pre_mmable and not is_lat_mmable:
    print('MMYY')
elif not is_pre_mmable and is_lat_mmable:
    print('YYMM')
else:
    print('NA')



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

int main()
{
 int n;cin>>n;
  string s;cin>>s;
  int sum1=0,sum2=0;
  if(n%2!=0) cout<<"No"<<endl;
  else{
  for(int i=0,j=s.size()/2;i<s.size()/2;i++,j++)
  {
    sum1+=s[i];
    sum2+=s[j];
  }
    if(sum1==sum2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class B1DimensionalWorldsTale {
public:
	void solve(std::istream& in, std::ostream& out)
	{
        int n, m, x, y;
        in >> n >> m >> x >> y;
        vector<int> xv(n), yv(m);
        for(int i=0; i<n; i++){
            in >> xv[i];
        }
        for(int i=0; i<m; i++){
            in >> yv[i];
        }
        sort(xv.begin(), xv.end());
        sort(yv.begin(), yv.end());

        int left = xv[n-1];
        int right = yv[0];

        if(right <= x || y <= left || right <= left) out << "War" << endl;
        else out << "No War" << endl;
	}
};


int main() {
	B1DimensionalWorldsTale solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
/*===================*\
|ID : harryPotter_421  |
|      LANG: C++       |
\*====================*/
#include <iostream>
#include<bits/stdc++.h>
#define lli unsigned long long int
#define pb push_back
#define ld  double

#define f(j,m,n) for(lli j=m;j<n;j++)
#define harry ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define forn(n) for(i=0;i<n;i++);
#define vp vector<pair<lli,lli>>
using namespace std;
//int prime[10000005];







int main()
   {lli a,b;
    cin>>a>>b;
    cout<<a*b;
    
    }






















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

int main() {
    int K , S;
    cin>>K >> S ;

    int count=0;

    for(int X=0 ; X<=K ; X++){
        for(int Y=0; Y<=K ; Y++){
            if(S-X-Y<=K&&S-X-Y>=0) count++;
        }
    }

    cout << count << endl;
}

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a + b == c || b+c==a|| c +a==b){
    cout<<"Yes"<<endl;
  } else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  ll n;cin >> n;
  map<string,ll> m;

  rep(i,n)
  {
    ll buf;
    cin >> buf;

    if(buf <= 399)
    {
      m["Ash"]++;
    }
    else if(buf <= 799)
    {
      m["Brown"]++;
    }
    else if(buf <= 1199)
    {
      m["Green"]++;
    }
    else if(buf <= 1599)
    {
      m["Sky"]++;
    }
    else if(buf <= 1999)
    {
      m["Blue"]++;
    }
    else if(buf <= 2399)
    {
      m["Yellow"]++;
    }
    else if(buf <= 2799)
    {
      m["Orange"]++;
    }
    else if(buf <= 3199)
    {
      m["Red"]++;
    }
    else
    {
      m["Rainbow"]++;
    }
  }

  ll le = sz(m);

  ll hi = le;

  if(m["Rainbow"] > 0)
  {
    ll r = m["Rainbow"];
    hi = hi - 1 + r;
    le--;
    if(le == 0)le++;
  }

  cout << le << " " << hi << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

using ll = long long;
using namespace std;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);

#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}


void init();
void solve();

signed main()
{
	init();
	solve();
}

int x[26];

void init()
{
	int N;
	string s;
	cin >> N >> s;
	rep(i, s.length()) {
		x[s[i] - 'a']++;
	}
	ll res = 1;
	rep(i, 26) {
		res *= (x[i] + 1);
		res %= MOD;
	}
	res--;
	if (res < 0) res += MOD;
	cout << res << endl;
}

void solve()
{
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool chmax(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF 1000000007 //4000000000000000037
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int A,B,C,D;
  int num;
  cin>>num;
  A=num/1000; num%=1000;
  B=num/100; num%=100;
  C=num/10; num%=10;
  D=num/1;

  rep(i,8){
    int now=i;
    int ans=A;
    if(now>>0 &1) ans+=B;
    else ans-=B;
    if(now>>1 &1) ans+=C;
    else ans-=C;
    if(now>>2 &1) ans+=D;
    else ans-=D;

    if(ans==7){
      cout<< A<<( now>>0 &1 ? '+' : '-' )<<B<<( now>>1 &1 ? '+' : '-' )<<C<<( now>>2 &1 ? '+' : '-' )<<D<<"=7"<<"\n";
      return;
    }
  }

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

int main(){
	// sengen
	LL x,k,d;
	// nyuryoku
	cin >> x >> k >> d;
	LL dist = 0,count = 0;
	// keisan
	LL multi;
	if(abs(x)/d <= k){
		count = abs(x)/d;
		if(abs(x)%d != 0){
			count++;
			if(count > k){
				cout << abs(abs(x) - (count-1)*d) << endl;
				return 0;
			}
		}
	}else{
		cout << abs(abs(x) - k*d) << endl;
		return 0;
	}
	if(count == k){
		cout << abs(abs(x) - k*d) << endl;
		return 0;
	}
	k = k - count;
	if(k % 2 == 0){
		cout << abs(abs(x) - count*d) << endl;
	}else{
		cout << abs(abs(x) - count*d + d) << endl;
	}
	// syutsuryoku
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return input()
def n():
    return int(input())
def d():
    return float(input())

def ls():
    return input().split()
def ln():
    return map(int, input().split())
def ld():
    return map(float, input().split())

def fs():
    return [input() for i in range(input())]
def fn():
    return [int(input()) for i in range(input())]
def fd():
    return [float(input()) for i in range(input())]

K = n()

if K%2 == 0:
    ans = K//2 * K//2
else:
    ans = K//2 * (K//2 + 1)
print(ans)


Measured memory_bytes: 5456
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
typedef long long ll;
const int MAXN = 1e5 + 10;
const int MAX = 1e7;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e10 ;
map<int,int> mp ;
int main(){
    int A,B ;
    cin >>A>>B ;
    cout<<max(A+B,max(A*B,A-B))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sf1(x)      scanf("%d",&x)
#define pf1(x)      printf("%d\n",x)
#define pf1s(x)     printf("%d ",x)
#define FOR(i,x)    for(int i=0;i<x;i++)
using namespace std;
int main()
{
    int n;
    while(sf1(n)==1){
        int a[n];
        FOR(i,n)  sf1(a[i]);

    int cnt=0;
      FOR(i,n){
          int mn=i;
          for(int j=i ;j<n;j++){
              if(a[j]<a[mn])
                mn=j;
          }
          if(a[i]>a[mn])  {
                swap(a[i],a[mn]);
                cnt++;
          }
      }
      FOR(i,n-1)  pf1s(a[i]);
      pf1(a[n-1]);
      pf1(cnt);
    }

    return 0;
}

Measured memory_bytes: 3176
package main

import (
	"fmt"
)

func main() {
	var n, a, g int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		if i == 0 {
			g = a
		} else {
			g = gcd(g, a)
		}
	}
	fmt.Println(g)
}

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


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int x,y;
	cin>>x>>y;
	bool yes=false;
	auto g1=[&](int a){
		if((a<8&&a&1)||(a>=8&&a%2==0))return true;
		return false;
	};
	auto g2=[&](int a){
		if(a==4||a==6||a==9||a==11)return true;
		return false;
	};
	auto g3=[&](int a){
		if(a==2)return true;
		return false;
	};
	if(g1(x)&&g1(y))yes=true;
	else if(g2(x)&&g2(y))yes=true;
	else if(g3(x)&&g3(y))yes=true;
	cout<<(yes?"Yes"s:"No"s)<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
bool check(int x,int y){return x>=0&&x<4&&y>=0&&y<4;}
 
int main() {
  int n=8,m=4;
  P d[n];
  while(cin >> d[0].F >> d[0].S) {
    for(int i=1; i<m; i++) cin >> d[i].F >> d[i].S;
    for(int i=0; i<n; i++) {
      if(d[i].F<0) {
        d[i].F*=-1;
        d[i].S*=-1;
      }
      if(d[i].F==0&&d[i].S<0) d[i].S*=-1;
    }
    int ans=0;
    for(int t=0; t<(1<<(n*2)); t++) {
      P a[n];
      for(int i=0; i<n; i++) {
        int x=t/(1<<(i*2));
        x%=4;
        a[i]=d[x];
      }
      int c[m][m];
      memset(c,-1,sizeof(c));
      int k=0;
      for(int i=0; i<m; i++) {
        for(int j=0; j<m; j++) {
          if(c[i][j]==-1) {
            int x=i+a[k].F,y=j+a[k].S;
            if(!check(x,y)||c[x][y]!=-1) goto next;
            c[i][j]=k;
            c[x][y]=k;
            k++;
          }
        }
      }
      ans++;
    next:;
    }
    cout << ans << endl;
  }
  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7
using namespace std;
using ll = long long;

void solve()
{
	const ll MAX_SIZE = 1000005;

	bool num[MAX_SIZE];
	for(int i = 0; i < MAX_SIZE; ++i)
	{
		num[i] = false;
	}

	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	int ans = 0;
	for(int i = 0; i < n; ++i)
	{
		if(num[a[i]] == true)
		{
			continue;
		}

		if (!(i < n - 1 && a[i] == a[i + 1])) { ans++; }

		ll prime = 0;
		while(prime += a[i], prime < MAX_SIZE)
		{
			num[prime] = true;
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 5808
n, m = map(int, input().split())
drink=[]
for _ in range(n):
  drink.append(list(map(int, input().split())))
drink.sort(key=lambda x: x[0])
cnt=0
price=0
for d in drink:
  if cnt+d[1]<m:
    price+=d[0]*d[1]
    cnt+=d[1]
  else:
    price+=d[0]*(m-cnt)
    break
print(price)

Measured memory_bytes: 29024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009],cr[500009];
int main()
{
    ll a,b,c,i,j,k=0,z,x;
    string s,d;
    cin>>a>>b;
    for(i=1;i<=b;i++)
    {
        cin>>c>>s;
        if(s=="WA" && cr[c]==0)
        {
            ar[c]++;
        }
        else
        {
            br[c]++;
            k=k+ar[c];
            ar[c]=0;
            cr[c]=1;
        }
    }
    j=0;
    for(i=0;i<=100009;i++)
    {
        if(br[i]>0)
        {
            j++;
        }
    }
    cout<<j<<" "<<k<<endl;
}


Measured memory_bytes: 9216