akhauriyash/Code-Regression huggingface dataset:
import Data.List

main = do
  (_:m:_) <- getInts
  as <- getInts
  let sigma = scanl (+) 0 as
  print $ sum $ map (_C2.length) $ group.sort $ map (`mod` m) sigma
 where _C2 n = (n * (n-1)) `div` 2
       
getInts = map read.words <$> getLine :: IO [Int]

Measured memory_bytes: 38268
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())

for j in range(N-K):
    if T[K+j] == T[j]:
        T[K+j] = 0
print(sum([T.count("r")*P, T.count("s")*R, T.count("p")*S]))

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int ka[1214514],inv[1214514];
void setkaijo(int n){
	ka[0]=1;
	for(int i=1;i<=n;i++){
		ka[i] = ka[i-1] * i;
		ka[i] %= inf;
	}
}
int modpow(int x,int k){
	// x ^ k mod inf
	int res = 1;
	while(k>0){
		if(k%2)res = (res*x)%inf;
		x = (x*x)%inf;
		k >>=1;
	}
	return res;
}
void setinv(int n){
	for(int i=0;i<=n;i++){
		inv[i] = modpow(ka[i],(ll)inf-2);
	}
}
int comb(int n,int k){
	if( k<0 || n<0 || k>n)return 0;
	if(k==0 || k==n)return 1;
	int res = (ka[n] * inv[k]) % inf;
	res = (res*inv[n-k]) % inf;
	return res;
}
int dp[1145140],sum[1145140],kais[1145140];
signed main(){
	int n,h,d;
	cin>>n>>h>>d;
	setkaijo(1100000);
	dp[0]=1;
	sum[0]=1;
	kais[0]=0;
	for(int i=1;i<=n;i++){
		kais[i] = kais[i-1]+ka[i];
		kais[i]%=inf;
	}
	for(int i=1;i<=h;i++){
		if( i <= d ){
			dp[i] += ka[n];
			dp[i] += kais[n] * ( sum[i-1] - sum[0] + inf);
			dp[i] %= inf;
		}
		else{
			dp[i] = kais[n] * ( sum[i-1] - sum[i-d-1] + inf );
			dp[i] %= inf;
		}
		sum[i] = sum[i-1] + dp[i];
		sum[i] %= inf;
	}
	cout<<dp[h]<<endl;
	return 0;
}

Measured memory_bytes: 37120
n = int(input())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))

for p in range(1,5):
    if p != 4:
        D = 0.0
        for i in range(n):
            D += ((abs(X[i]-Y[i]))**p)
        D = D**(1/p)
        print("{:.6f}".format(D))
    else:
        print("{:.6f}".format(max(abs(x-y)for x,y in zip(X,Y))))



Measured memory_bytes: 5660
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

typedef long double ld;

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

	ld a, b;
	cin >> a >> b;
	cout << (long long)(a * b) << endl;
}

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

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

	for(int w, d; cin >> w >> d, w;) {
		vector<int> hw(w), hd(d);
		for(int i = 0; i < w; ++i)
			cin >> hw[i];

		for(int i = 0; i < d; ++i)
			cin >> hd[i];

		vector<int> cnt(21, 0);

		int ans = 0;
		for(int i = 0; i < w; ++i) {
			ans += hw[i];
			++cnt[hw[i]];
		}

		for(int i = 0; i < d; ++i) {
			if(cnt[hd[i]])
				--cnt[hd[i]];

			else
				ans += hd[i];
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef RUS_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef RUS_HOME
    freopen("input", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


void smain() {
    int n,k,s;
    cin>>n>>k>>s;
    if(s==1000000000) {
        for(int i=0;i<k;i++)
            cout<<s<<" ";
        for(int i=0;i<n-k;i++)
            cout<<s-1<<" ";
    }else{
        for(int i=0;i<k;i++)
            cout<<s<<" ";
        for(int i=0;i<n-k;i++)
            cout<<s+1<<" ";
    }

}

Measured memory_bytes: 3612
D=list(map(int,input().split()))

D.sort()

A=D[2]-D[1]
D[1]+=A
D[0]+=A
result=A

if (D[1]-D[0])%2==0:
    result+=(D[1]-D[0])//2
else:
    result+=(D[1]-D[0])//2+2

print(result)




Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

#include <iostream>

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	if (B >= A * C) { cout << C << endl; }
	else { cout << B/A << endl; }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int mod = n % 10;

		if (mod == 2 || mod == 4 || mod == 5 ||mod == 7 || mod==9 ){
			System.out.println("hon");
		} else if (mod == 3){
			System.out.println("bon");
		} else {
			System.out.println("pon");
		}


	}


}

Measured memory_bytes: 35776
#include <stdio.h>

int prime[1000000] = {0};

int main(void)
{
	int n[30];
	int ans[30] = {0};
	int cnt = 0;
	int i, j;
	
	prime[0] = prime[1] = 1;
	
	for (i = 2; (i * i) < 1000000; i++){
		for (j = 2; (i * j) < 1000000; j++){
			prime[i * j] = 1;
		}
	}
	
	i = 0;
	while (scanf("%d", &n[i]) != EOF){
		for (j = 0; j <= n[i]; j++){
			if (prime[j] == 0){
				ans[i]++;
			}
		}
		cnt++;
		i++;
	}
	
	for (i = 0; i < cnt; i++){
		printf("%d\n", ans[i]);
	}
	
	return (0);
}

Measured memory_bytes: 4500
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#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=1<<30;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[8]={1,0,-1,0,1,1,-1,-1} , dy[8]={0,1,0,-1,1,-1,1,-1} ;

struct UnionFind{
   vector<int> par;
   vector<ll> ran;
   UnionFind(int n):par(n,-1),ran(n){}
   int find(int x){
       if(par[x]<0)return x;
       int y = find(par[x]);
      ran[x] += ran[par[x]];
      return par[x] = y;
   }
   bool unite(int x,int y,ll z,int k){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       ran[x]-=z*par[y];
       ran[y]-=z*par[x];
       par[k]=par[x]+par[y];
       par[x]=k;
       par[y]=k;
       return true;
   }

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


int main(){
    int n;
    cin>>n;
    vector<pair<ll,pint>> v;
    rep(i,n-1){
        int x,y,z;
        cin>>x>>y>>z;
        v.push_back({z,{x-1,y-1}});
    }
    UnionFind uf(2*n);
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    rep(i,n-1){
        uf.unite(v[i].second.first, v[i].second.second, v[i].first,n+i);
    }
    rep(i,n){
        uf.find(i);
        cout<<uf.ran[i]<<endl;
    }
}

Measured memory_bytes: 5616
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
    int a;
    cin >> a;

    if(a == 1) {
        cout << "Hello World" << endl;
    }
    else {
        int b, c;
        cin >> b >> c;
        cout << b + c << endl;
    }
    return 0;
}


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

ll gcd(ll m, ll n) {//最大公約数
    if (n == 0)return m;
    return gcd(n, m % n);
}

int main() {
  int k;
  cin>>k;
  ll ans = 0;
  for(int p=1; p<=k; p++){
    for(int q=1; q<=k; q++){
      for(int r=1; r<=k; r++){
        ans+=gcd(p,gcd(q,r));
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include <math.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

constexpr long long INFLL = 1e18;

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans;
  if (b <= 0 && d <= 0) {
    ans = a * c;
  } else if (a >= 0 && c >= 0) {
    ans = b * d;
  } else {
    if (b < 0 && c > 0) {
      ans = b * c;
    } else if (a > 0 && d < 0) {
      ans = d * a;
    } else {
      ll temp1, temp2;
      temp1 = a * c;
      temp2 = b * d;
      ans = max(temp1, temp2);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3184
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int n;

vector<int> va;

map<int,int> idx, sortidx;

int main() {
    GI(n);

    int a;

    FORN(i, n) {
        GI(a); va.PB(a);
        idx[a] = i;
    }

    sort(va.begin(), va.end());

    FORN(i, n) {
        sortidx[va[i]] = i;
    }

    int res = 0;

    for (auto& kv : idx) {
        res += abs(kv.SS - sortidx[kv.FF]) % 2;
    }

    cout << res / 2 << "\n";
    
    return 0;
}

Measured memory_bytes: 9976
//abc097_a.cpp
//Sat May 12 20:38:48 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;

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

	if (abs(c-a)<=d){
		cout << "Yes" << endl;
	}else if (abs(b-a)<=d && abs(c-b)<=d){
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
n, q = list(map(int, input().split()))
ps = []
for i in range(n):
    pi, qi = input().split()
    ps.append([pi, int(qi), 0])
time = 0
num = 0
while num != n:
    if ps[num][1] == 0:
        ps.append([ps[num][0], ps[num][1], ps[num][2]])
        del(ps[num])
    elif ps[num][1] <= q:
        time += ps[num][1]
        ps[num][2] = time
        ps[num][1] = 0
        num += 1
    else:
        time += q
        ps[num][1] -= q
        ps.append([ps[num][0], ps[num][1], ps[num][2]])
        del (ps[num])
ps = sorted(ps, key=lambda x: x[2], reverse=False)
for i in range(n):
    print(ps[i][0], ps[i][2])


Measured memory_bytes: 15408
import copy

N = int(input())
P = list(map(int, input().split()))
X = copy.copy(P)

X.sort()
ans = "NO"


for i in range(N):
    for j in range(N):
        Y = copy.copy(P)
        a = copy.copy(P[i])
        b = copy.copy(P[j])
        Y[i] = b
        Y[j] = a
        #print(Y)
        if Y == X:
            ans =  "YES"


print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> PII;
int a,b;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MAX(a,b) a>b? a:b
#define MIN(a,b) a>b? b:a

int MINN(vector<int>a,int k){
int min=1e9;
REP(i,k){
  if(a[i]<=min)min=a[i];
}
return min;
}

int main(){
int sum=0;
string s;
REP(i,3){
cin>>s[i];
if(s[i]=='1')sum++;
}
cout<<sum<<endl;
return 0;
}

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

int main(){
  int n;
  cin >> n;
  int t[n+1], x[n+1], y[n+1];
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  for(int i=0; i<n;i++){
    cin >> t[i+1] >> x[i+1] >> y[i+1];
  }
  bool res = true;
  for(int i=0; i<n; i++){
    int time = t[i+1]-t[i];
    int move = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
    if(time%2 == 0){
      if(move>time || move%2 == 1) res = false;
    }
    else{
      if(move>time || move % 2 == 0) res = false;
    }
  }
  if(res) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

int main() {
  int a, b, c ;
  while (cin >> a >> b >> c) {
    cout << min(a + b, min(b + c, c + a)) << endl;
  }
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
string tmp[10]={"0","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"};
int main(){
      string s;
      while(cin>>s){
            int cnt=0,k=0;
            string ans="";
            while(k<s.size()){
                  cnt=0;
                  char t=s[k];
                  if(t=='0'){
                        while(k<s.size()&&t==s[k]){
                              ans+=' ';
                              k++;
                        }
                  }
                  t=s[k];
                  while(k<s.size()&&t==s[k]){
                        k++;
                        cnt++;
                  }
                  int tt=t-'0';
                  ans+=tmp[tt][cnt-1];
                  if(s[k]=='0')k++;

            }
            cout<<ans<<endl;
      }
}

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

#define int long long

using namespace std;

const int maxn = 70;
int par[maxn], lca[maxn][maxn], mark[maxn][maxn], n, m;
int tin[maxn], tout[maxn], timer;
vector<int> adj[maxn];
vector<pair<int, int>> res, edge;

void dfs(int u = 1, int p = 1)
{
    par[u] = p;
    tin[u] = timer++;
    for (int v : adj[u])
        if (v != p)
            dfs(v, u);
    tout[u] = timer++;
}

bool is_anc(int u, int v)
{
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

int shift(int u = 1, int p = 0)
{
    for (int v : adj[u])
        if (v != p)
            mark[p][u] += shift(v, u);
    return mark[p][u];
}

signed main()
{
    ios::sync_with_stdio(false);
    cin >> n;

    for (int i = 0, u, v; i < n - 1; i++)
        cin >> u >> v, adj[u].push_back(v), adj[v].push_back(u),
            edge.push_back({u, v});
    dfs();

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            int u = i, v = j;
            if (u == v)
            {
                lca[u][v] = u;
                continue;
            }
            if (is_anc(v, u))
                swap(u, v);
            if (is_anc(u, v))
            {
                lca[u][v] = lca[v][u] = u;
                continue;
            }

            int l = u;
            while (!is_anc(l, v))
                l = par[l];
            lca[u][v] = lca[v][u] = l;
        }

    cin >> m;
    for (int i = 0, u, v; i < m; i++)
        cin >> u >> v, res.push_back({u, v});

    int ans = 0;
    for (int mask = 0; mask < (1 << m); mask++)
    {
        memset(mark, 0, sizeof mark);
        for (int i = 0; i < m; i++)
            if (mask >> i & 1)
            {
                int u = res[i].first, v = res[i].second, l = lca[u][v];

                if (l == v)
                    swap(u, v);
                if (l == u)
                    ++mark[par[v]][v], --mark[par[u]][u];
                else
                    ++mark[par[v]][v], ++mark[par[u]][u], ----mark[par[l]][l];
            }
        shift();

        int cnt = 0;
        for (auto e : edge)
            cnt += mark[e.first][e.second] == 0 && mark[e.second][e.first] == 0;
        ans += __builtin_popcount(mask) & 1 ? -(1ll << cnt) : (1ll << cnt);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    string s; cin >> s;
    int num = atoi(s.c_str());
    int start = num/100;
    int end = num%100;
    string res;

    if((0<start && start <= 12) && (end > 12 || end == 0)){
        res = "MMYY";
    } else if((start > 12 || start == 0) && (0<end && end <= 12)) {
        res = "YYMM";
    } else if((0<start && start<=12) && (0<end && end<=12)){
        res = "AMBIGUOUS";
    } else {
        res = "NA";
    }
    cout << res << endl;
}


Measured memory_bytes: 256
N = int(input())
V = input().split(" ")
V = [int(i) for i in V]
C = input().split(" ")
C = [int(i) for i in C]
list = [0]
ans = 0
X = 0
Y = 0
for i in range(N):
    if V[i] - C[i] > 0:
        X = V[i]
        Y = C[i]
        list.append(X - Y)
print(sum(list))

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int MAX_N = 1000010;
int INF = INT_MAX>>1;
vector<vector<P>> G;
vector<ll> dist;

void dijkstra(int s) {
    priority_queue<P,vector<P>,greater<P>> que;
    dist[s] = 0;
    que.push(P(0,s));
 
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v =  p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0;i < G[v].size();++i) {
            P e = G[v][i];
            if (dist[e.first] > dist[v]+e.second) {
                dist[e.first] = dist[v]+e.second;
                que.push(P(dist[e.first],e.first));
            }
        }
    }
}

struct edge {
	ll u,v,c;
};

int main() {
	ll n,m;
	cin >> n >> m;
	vector<edge> a(m);
	unordered_map<ll,int> mp;
	for (int i = 0;i < m;++i) {
		cin >> a[i].u >> a[i].v >> a[i].c;
		a[i].u--;a[i].v--;
		mp[a[i].u*10000000+a[i].c] = 0;
		mp[a[i].v*10000000+a[i].c] = 0;
	}
	for (ll i = 0;i < n;++i) mp[i*10000000] = 0;
	{
		int i = 0;
		for (auto& p : mp) {
			p.second = i;
			i++;
		}
	}
	G.resize(mp.size());
	dist.resize(mp.size(),INF);
	for (edge& e : a) {
		G[mp[e.u*10000000+e.c]].push_back(P(mp[e.v*10000000+e.c],0));
		G[mp[e.v*10000000+e.c]].push_back(P(mp[e.u*10000000+e.c],0));
		G[mp[e.u*10000000+e.c]].push_back(P(mp[e.u*10000000],0));
		G[mp[e.u*10000000]].push_back(P(mp[e.u*10000000+e.c],1));
		G[mp[e.v*10000000+e.c]].push_back(P(mp[e.v*10000000],0));
		G[mp[e.v*10000000]].push_back(P(mp[e.v*10000000+e.c],1));
	}
	dijkstra(mp[0]);
	if (dist[mp[(n-1)*10000000]] == INF) cout << "-1" << endl;
	else cout << dist[mp[(n-1)*10000000]] << endl;
	// p_map(mp,it);
	// p_ary(dist,0,dist.size(),i);
	return 0;
}

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

using namespace std;
typedef  long long ll;

#define pf printf
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) for(int i=(n-1);i>=(0);--i)
#define REPSZ(i,v) REP(i,SZ(v))
#define pll pair <ll, ll>

const ll mxn = 1e5+5;
ll mod = 1e9+7;
ll arr[mxn];
ll brr[mxn];
vector<ll>v;
bitset<mxn>used;
double eps = 1e-7;
ll n,m,k,cont,tc;
void print(vector <ll> &v){cout << v.size() << endl;for(int i = 0; i < v.size(); i++){pf("%lld ", v[i]);}pf("\n");}
void print(vector <pll> &v){ cout << v.size() << endl; for(int i = 0; i < v.size(); i++){pf("%lld %lld\n", v[i].first, v[i].second);}}
void print(set<ll> s){set <ll> :: iterator itr;for (itr = s.begin(); itr != s.end(); ++itr){cout << *itr << " ";}cout << endl;}
void print(double d){cout << fixed << setprecision(2) << d << endl;}
void print (ll *arr){REP(i,n)cout << arr[i] << " "; cout << endl;}

void from_file(void){ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);}

/* ------------------main section-------------! */
ll Power(ll a, ll b) {
    a %= mod;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

ll NcR(int n, int r) 
{ 
  
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
  
            ll m = __gcd(p, k); 
            p /= m; 
            k /= m; 
  
            n--; 
            r--; 
        } 
    } 
  
    else
        p = 1; 
    return p;
} 

void solve()
{
    
}

void run() {
    fastio;
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans1 = max(a*c, a*d);
    ll ans2 = max(b*c, b*d);
    cout << max(ans1,ans2) << endl;
}

int main() {
    #ifndef ONLINE_JUDGE
       from_file();
    #endif
    run();
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli a;
    long double b;
    cin>>a>>b;
    cout<<(lli)(a*b);
    return 0;
}

Measured memory_bytes: 3748
N, X, M = map(int, input().split())
Flag = [True]*(M)

A = []
temp = X

while Flag[temp]:
  A.append(temp)
  Flag[temp] = False
  temp = (temp**2)%M
  last = temp

I = A.index(last)
looplen = len(A) - I
loop, cnt = divmod(max(N-I, 0), looplen)

ans = 0
if N <= I+1:
  ans += sum(A[:N])
else:
  ans += sum(A[:I])
  ans += loop*sum(A[I:])
  ans += sum(A[I:I+cnt])

print(ans)

Measured memory_bytes: 12124
d = input()
list = d.split("/")
if int(list[0]) > 2019:
    print('TBD')
elif int(list[0]) < 2019:
    print('Heisei')
else:
    if int(list[1]) < 4:
        print('Heisei')
    elif int(list[1]) > 4:
        print('TBD')
    else:
        print('Heisei')


Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = sum(b)
for i in range(n-1):
  if a[i]+1 ==a[i+1]:
    ans += c[a[i]-1]
print(ans)


Measured memory_bytes: 3064
import numpy as np
n = int(input())
a = list(map(int, input().split()))

result = 0
height = 0

while True:
    zero_cnt = 0
    area = 0
    area_flg = True
    for i in range(n):
        if a[i] > height:
            if area_flg:
                area += 1
                area_flg = False
        else:
            area_flg = True
            zero_cnt += 1
    if zero_cnt == n:
        print(result)
        break
    result += area
    height += 1


Measured memory_bytes: 13192
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
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 Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
void dfs(int x, Graph& tree, V& count, V& counter, vector<bool>& visited) {
	counter[x] += count[x];
	visited[x] = true;
	for (auto c : tree[x]) {
		if (!visited[c]) {
			counter[c] += counter[x];
			dfs(c, tree, count, counter, visited);
		}
	}
}
int main() {
	int n, q;
	cin >> n >> q;
	Graph tree(n);
	rep(i,n - 1) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	V count(n, 0);
	rep(i, q) {
		int a, b;
		cin >> a >> b;
		a--;
		count[a] += b;
	}
	V counter(n, 0);
	vector<bool> visited(n, false);
	dfs(0, tree, count, counter, visited);
	rep(i, n) cout << counter[i] << " ";
	return 0;
}

Measured memory_bytes: 30592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  string a,b;
  cin >> a >> b;
  bool flag = false;
  if(a.size()==b.size()){
    rep(i,a.size()){
      if(a[i]>b[i]){
        cout << "GREATER" << endl;
        return 0;
      }else if (a[i] < b[i]){
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
    return 0;
  }else if (a.size() > b.size()){
    cout << "GREATER" << endl;
    return 0;
  }else{
    cout << "LESS" << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

string s;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	s[3] = '8';
	cout << s << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

template<long long mod = 1000000007>
struct modint{
	long long a;

	modint() : a(0){}
	modint(long long t){
		a = t % mod;
		if(a < 0) a += mod;
	}

	operator long long() const{ return a; }

	bool operator==(const modint &x) const{ return a == x.a; }
	bool operator!=(const modint &x) const{ return a != x.a; }

	modint operator-() const{ return modint(a ? (mod - a) : 0); }
	modint operator~() const{ return pow(mod - 2); }

	modint operator+(const modint &x) const{ return modint(*this) += x; }
	modint operator-(const modint &x) const{ return modint(*this) -= x; }
	modint operator*(const modint &x) const{ return modint(*this) *= x; }
	modint operator/(const modint &x) const{ return modint(*this) /= x; }

	modint &operator+=(const modint &x){
		a += x.a;
		if(a >= mod) a -= mod;
		return *this;
	}
	modint &operator-=(const modint &x){
		a -= x.a;
		if(a < 0) a += mod;
		return *this;
	}
	modint &operator*=(const modint &x){
		a = a * x.a % mod;
		return *this;
	}
	modint &operator/=(const modint &x){
		a = a * (~x).a % mod; 
		return *this;
	}

	friend ostream &operator<<(ostream &os,const modint &x){
		return os << x.a;
	}
	friend istream &operator>>(istream &is,modint &x){
		long long t;
		is >> t;
		x = modint(t);
		return is;
	}

	modint pow(long long x) const{
		modint ret = 1,tmp = a;
		for(;x;tmp *= tmp,x >>= 1){
			if(x & 1) ret *= tmp;
		}
		return ret;
	}
};

signed main(){
	int n,x[100010];
	cin >> n;
	for(int i = 0;i < n;i++) cin >> x[i];
	modint<> fact = 1,ans = 0,sum = 0;
	for(int i = 1;i < n;i++) fact *= i;
	for(int i = 0;i < n - 1;i++){
		sum += fact / modint<>(i + 1);
		ans += modint<>(x[i + 1] - x[i]) * sum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
from collections import deque

n = int(input())

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

mx_color = 0    
for i in range(n):
    mx_color = max(mx_color,len(adj[i]))

dist = [-1]*n

res = [-1]*(n-1)

q = deque([])
q.append([0,-1])
dist[0] = 0

while len(q) > 0:
    v,c = q.popleft()
    color = 1
    
    if color == c:
        color += 1
        
    for nv,nc in adj[v]:
        if dist[nv] == -1:
            dist[nv] = dist[v] + 1
            q.append([nv,color])
            res[nc] = color
            color += 1
            if color == c:
                color += 1

print(mx_color)

for i in res:
    print(i)

Measured memory_bytes: 108540
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();
    let mut a: Vec<isize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    const MOD: isize = 1_000_000_007;

    if k == n {
        let mut ans: isize = 1;
        for i in 0..n {
            ans = ans * a[i] % MOD;
        }
        return if ans >= 0 {
            ans.to_string()
        } else {
            (ans + MOD).to_string()
        }
    }

    if k % 2 == 1 && a.iter().all(|it| *it < 0) {
        a.sort();
        a.reverse();

        let mut ans: isize = 1;
        for i in 0..k {
            ans = ans * a[i] % MOD;
        }
        return if ans >= 0 {
            ans.to_string()
        } else {
            (ans + MOD).to_string()
        }
    }

    a.sort_by_key(|it| it.abs());

    let mut is_minus = false;
    let mut is_zero = false;
    let mut b: Vec<isize> = Vec::new();
    for _ in 0..k {
        let ai = a.pop().unwrap();
        if ai < 0 {
            is_minus = !is_minus;
        } else if ai == 0 {
            is_zero = true;
        }
        b.push(ai);
    }

    if !is_minus || is_zero {
        let mut ans = 1;
        for bi in b {
            ans = ans * bi % MOD;
        }
        return if ans >= 0 {
            ans.to_string()
        } else {
            (ans + MOD).to_string()
        }
    }

    let mut lp = None;
    for bi in b.iter().rev() {
        if *bi >= 0 {
            lp = Some(*bi);
            break;
        }
    }

    let mut lm = None;
    for bi in b.iter().rev() {
        if *bi < 0 {
            lm = Some(*bi);
            break;
        }
    }

    let mut np = None;
    for ai in a.iter().rev() {
        if *ai >= 0 {
            np = Some(*ai);
            break;
        }
    }

    let mut nm = None;
    for ai in a.iter().rev() {
        if *ai < 0 {
            nm = Some(*ai);
            break;
        }
    }

    if lp != None && nm != None && lm != None && np != None {
        if lp.unwrap() * np.unwrap() >= lm.unwrap() * nm.unwrap() {
            b.remove(b.iter().position(|x| *x == lm.unwrap()).unwrap());
            b.push(np.unwrap());
        } else {
            b.remove(b.iter().position(|x| *x == lp.unwrap()).unwrap());
            b.push(nm.unwrap());
        }
    } else if lp != None && nm != None {
        b.remove(b.iter().position(|x| *x == lp.unwrap()).unwrap());
        b.push(nm.unwrap());
    } else if lm != None && np != None {
        b.remove(b.iter().position(|x| *x == lm.unwrap()).unwrap());
        b.push(np.unwrap());
    }

    let mut ans = 1;
    for bi in b {
        ans = ans * bi % MOD;
    }
    return if ans >= 0 {
        ans.to_string()
    } else {
        (ans + MOD).to_string()
    }
}


Measured memory_bytes: 8092
#include <stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int i, j, k;
  int n1 = mid -left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  i=0, j=0;
  for(k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  int mid;
  if(left+1 < right) {
    mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);

  return 0;
}


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

int main() {
	int a, b;
	while (true) {
		cin >> a >> b;
		if (a == 0 && b == 0)break;
		else if (a < b)cout << a << " " << b << endl;
		else cout << b << " " << a << endl;
	}
	return 0;
}


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

int main(){
	int n,m;
	vector<string> u;
	cin >> n;
	for(int i=0;i<n;i++){
		string U;
		cin >> U;
		u.push_back(U);
	}
	cin >> m;
	int ans=0;
	for(int i=0;i<m;i++){
		string T;
		cin >> T;
		int judge=0;
		for(int j=0;j<u.size();j++){
			if(T==u[j]){
				ans++;
				judge++;
			}
		}
		if(judge==0) cout << "Unknown " << T << endl;
		else if(ans%2==1) cout << "Opened by " << T << endl;
		else if(ans%2==0&&judge!=0) cout << "Closed by " << T << endl;
	}

}

Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define itrep(itr, base) for (auto itr = base.begin(); itr != base.end(); itr++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  string s, t;
  cin >> s >> t;
  int restoreFlag = 0;
  drep(i, s.size() - t.size() + 1) {
    int flag = 1;
    rep (j, t.size()){
      if (s[i + j] != '?' && s[i + j] != t[j]) {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      restoreFlag = 1;
      rep (j, t.size()){
        s[i + j] = t[j];
      }
      break;
    }
  }

  if (restoreFlag == 0) {
    P("UNRESTORABLE");
  } else {
    rep (i, s.size()) {
      if (s[i] == '?') s[i] = 'a';
    }
    P(s);
  }

  return 0;
}



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

int main()
{
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200) cout << s << endl;
  else cout << "red" << endl;
  return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.length();

    map<char, int> M;
    rep(i, n)
    {
        M[s[i]]++;
    }

    //存在しないとき
    if (s == "zyxwvutsrqponmlkjihgfedcba")
    {
        cout << -1 << endl;
        return 0;
    }

    //付け加える形のとき
    for (int i = 97; i <= 122; i++)
    {
        char c = i;
        if (M[c] == 0)
        {
            s += c;
            cout << s << endl;
            return 0;
        }
    }

    //それ以外の形
    rep(j, n)
    {
        M[s[n - 1 - j]] = 0;
        char c1 = s[s.length() - 1];
        s = s.substr(0, s.length() - 1);
        for (int i = c1 + 1; i <= 122; i++)
        {
            char c2 = i;
            if (M[c2] == 0)
            {
                s += c2;
                cout << s << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3580
N,K = (int(i) for i in input().split())
string = input()
S = list(string)

if S[K-1] == "A":
    S[K-1] = "a"
if S[K-1] == "B":
    S[K-1] = "b"
if S[K-1] == "C":
    S[K-1] = "c"

result = "".join(S)
print(result)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define MAX 1000000007
#define ll long long int
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // int t;
    // cin>>t;

    // while(t--){
    // }

    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    cout<<max({a*c,b*d,a*d,b*c})<<endl;

    // if((a<0 && b<=0 && c<0 && d<=0) || (c<0 && d<=0 && a<0 && b<=0)){
    //     ll ans = a*c;
    //     cout<<ans<<endl;
    // }
    // else if((a<=0 && b>=0 && c<=0 && d<=0) || (c<=0 && d>=0 && a<=0 && b<=0)){
    //     ll ans = max(b*d,a*c);
    //     cout<<ans<<endl;
    // }
    // else if((a<=0 && b>=0 && c<=0 && d>=0) || (c<=0 && d>=0 && a<=0 && b>=0)){
    //     ll ans = max(a*c, b*d);
    //     cout<<ans<<endl;
    // }
    // else if((a<=0 && b<=0 && c>=0 && d>=0) || (c<=0 && d<=0 && a>=0 && b>=0)){
    //     ll ans = max(a*c,b*d);
    //     cout<<ans<<endl;
    // }
    // else if((a<=0 && b>=0 && c>=0 && d>=0) || (c<=0 && d>=0 && a>=0 && b>=0)){
    //     ll ans = b*d;
    //     cout<<ans<<endl;
    // }
    // else if((a>=0 && b>=0 && c>=0 && d>=0) || (c>=0 && d>=0 && a>=0 && b>=0)){
    //     ll ans = b*d;
    //     cout<<ans<<endl;
    // }

    return 0;
}

Measured memory_bytes: 3652
S_=input()
T=input()
N=len(S_)
M=len(T)
posi=[]

for i in range(N-M+1):
  flag=True
  for j in range(i,i+M):
    if S_[j]!=T[j-i] and S_[j]!="?":
      flag=False
  if flag==True:
    posi.append(S_[:i]+T+S_[i+M:])
#print(posi)
    
if posi==[]:
  print("UNRESTORABLE")
else:
  ans_list=[]
  for item in posi:
    ans=""
    for str in item:
      if str=="?":
        ans += "a"
      else:
        ans += str
    ans_list.append(ans)
  ans_list.sort()
  print(ans_list[0])

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

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    int r; cin >> r;

    if (r < 1200) cout << "ABC";
    else if (r <2800) cout << "ARC";
    else cout << "AGC";

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long int lli;

int main(int argc, char const *argv[]) {
  lli n, m, ans=0;
  cin >> n >> m;

  if (m>=2*n) {
    ans += n;
    m-=2*n;
    n=0;
  }
  else {
    ans += m/2;
    n -= m/2;
    m -= ((m + 1) / 2)*2;
  }
  if (n==0 and m>=4) {
    ans += m/4;
    m = 0;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    string s;
    cin >> s;
    map<char,int> m;
    rep(i,3)m[s[i]]++;
    if(m.size() == 2)cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
# define INF 0x3f3f3f3f
#define MOD 1000000007
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d%d",&x,&y)
#define siii(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d%d",x,y)
#define piii(x,y,z) printf("%d%d%d",x,y,z) 
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld%lld",&x,&y)
#define slll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld%lld",x,y)
#define plll(x,y,z) printf("%lld%lld%lld",x,y,z) 
 
#define ll long long
#define mp make_pair
#define pb push_back
#define pp pop_back
#define nl printf("\n");
#define sf scanf
#define pf printf
#define rep(i,n) for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int>
#define tci int t;scanf("%d",&t);while(t--)
const int maxn=10e6+4;

int main()
{
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }
    
    int a,b;
    sii(a,b);
    string s;
    cin>>s;
    int te=0,t=1;
    rep(i,s.size())
    {
        if(i==a) 
        {
            if(s[i]=='-')
            {
                te=1;
            }

        }
        else
        {
            if(s[i]<'0' || s[i]>'9')
            {
                t=0;
            }
        }
    }   
    if(te==1 && t==1)
    {
        cout<<"Yes\n";
    }
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    ans = defaultdict(int)
    for a in A:
        if a in ans:
            ans.pop(a)
        else:
            ans[a] += 1

    print(len(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 16636
n,m = map(int,input().split())
h = [0] + list(map(int,input().split()))

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

#print(l)

ans = 0
for i in range(1,n+1):
    arr = []
    for ele in l[i]: arr.append(h[ele])
    no1 = max(arr) if arr else 0
    if h[i] > no1 : ans += 1

print(ans)


Measured memory_bytes: 29988