akhauriyash/Code-Regression huggingface dataset:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N, M = map(int, input().split())
if N == 1 or N == 0:
    guu = 0
else:
    guu = combinations_count(N, 2)
if M == 1 or M == 0:
    kisu = 0
else:
    kisu = combinations_count(M, 2)
print(guu + kisu)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000;
int main(){
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    vector<int> HP(N);
    for (int i = 0; i < N; i++){
      cin >> HP[i];
    }
    int M;
    cin >> M;
    vector<long long> dpS(1000000, INF);
    dpS[0] = 0;
    vector<long long> dpA(1000000, INF);
    dpA[0] = 0;
    for (int i = 0; i < M; i++){
      string Name;
      int MP;
      string Target;
      int Damage;
      cin >> Name >> MP >> Target >> Damage;
      if (Target == "Single"){
        for (int j = 0; j < 1000000; j++){
          dpS[j] = min(dpS[j], dpS[max(j - Damage, 0)] + MP);
        }
      }
      if (Target == "All"){
        for (int j = 0; j < 1000000; j++){
          dpA[j] = min(dpA[j], dpA[max(j - Damage, 0)] + MP);
        }
      }
    }
    long long ans = INF;
    for (int i = 0; i < 1000000; i++){
      long long sum = dpA[i];
      for (int j = 0; j < N; j++){
        sum += dpS[max(HP[j] - i, 0)];
      }
      ans = min(ans, sum);
    }
    cout << ans << endl;
  }
}


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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e16;

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

  string ans = "ans";
  vector<string> s(3);
  FOR(i, 0, 3) { cin >> s[i]; }

  FOR(i, 0, 3) { ans[i] = toupper(s[i][0]); }

  cout << ans << '\n';

  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++)
typedef long long ll;
typedef vector<vector<int>> vv;
typedef pair<int, int> P;

// input
int N, M;
vector<int> X;


void input() {
    cin >> N >> M;
    X = vector<int>(M);
    rep(i, M) cin >> X[i];
}


int main() {
    input();
    sort(X.begin(), X.end());
    vector<int> d(M - 1);
    rep(i, M - 1) d[i] = X[i + 1] - X[i];
    sort(d.begin(), d.end());
    ll ans = 0;
    rep(i, M - N) ans += d[i];
    cout << ans << endl;
}


Measured memory_bytes: 3908
N = int(input())
Arr = map(int, input().split())

flags = [0] * N
limit = 0
for i, num in enumerate(Arr):

    if num  % 2 == 0:
        cnt = 1
        while True:
            num = num // 2
            if not num < 1 and not num % 2 == 0:
                break
            cnt += 1
        flags[i] = cnt

print(sum(flags))

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

int main(){
	string ans,s;
	cin >> s;

	for (int i = 0; i < s.size(); i++){
		if(s[i] == '0')
			ans += '0';
		else if(s[i] == '1')
			ans += '1';
		else if(s[i] == 'B' && ans != "")
			ans.pop_back();
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1LL << 60)
#define int long long
#define mod 1000000007
using namespace std;

char A[1000][1000];
int dp[1000][1000];
int32_t main(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		cin >> A[i];
	}
	dp[0][0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(A[i][j] == '#')
				continue;
			if(i != 0)
				dp[i][j] += dp[i-1][j];
			if(j != 0)
				dp[i][j] += dp[i][j-1];
			dp[i][j] %= mod;
		}
	}
	cout << dp[n-1][m-1];
}

Measured memory_bytes: 9088
#include<algorithm>

#include<iostream>

#include<string>

#include<vector>

#include<cmath>

using namespace std; 

int main(){

  string s;  

  while(cin>>s&&s!="#"){  

int n=s.size();

    int a[50];    

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

      if(s[i]=='y'||s[i]=='u'||s[i]=='i'||s[i]=='o'||s[i]=='p'||s[i]=='h'||s[i]=='j'||s[i]=='k'||s[i]=='l'||s[i]=='n'||s[i]=='m'){

    a[i]=0;

      }else{

    a[i]=1;

      }

    }

  

    int ans=0;

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

      if(a[i]==a[i+1]){

    continue;

      }else ans++;

    }

    cout<<ans<<endl;

  }

  return 0;

 

}

Measured memory_bytes: 3152
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main(){
    string s; cin >> s;
    string a, b;
    int q; cin >> q; bool rev = false;
    rep(i, q){
        int t; cin >> t;   
        if(t==1){
            if(rev)rev = false;
            else rev = true;
        }
        else{
            int f; char u; cin >> f >> u;
            if(f==1 && rev==false || f==2 && rev==true) a.push_back(u);
            else b.push_back(u);
        }
    }
    if(rev){
        reverse(all(b)); reverse(all(s)); cout << b << s << a << ln;
    }else{
        reverse(all(a)); cout << a << s << b << ln;
    }
    
}


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

int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0), cout.tie(0);

 vector<int> aa,bb,cc;
 int x,y,a,b,c;
 cin >> x >> y >> a >> b >> c;
 for(int i=0; i<a; i++){
 	int temp; cin >> temp;
 	aa.push_back(temp);
 }
 for(int i=0; i<b; i++){
 	int temp; cin >> temp;
 	bb.push_back(temp);
 }
 for(int i=0; i<c; i++){
 	int temp; cin >> temp;
 	cc.push_back(temp);
 }

 sort(aa.begin(),aa.end(),greater<int>());
 sort(bb.begin(),bb.end(),greater<int>());
 sort(cc.begin(),cc.end(),greater<int>());

 priority_queue<pair<int,int>> pq;

 for(auto i : aa){
 	pq.push({i,0});
 }
 for(auto i : bb){
 	pq.push({i,1});
 }
 for(auto i : cc){
 	pq.push({i,2});
 }

 long long sum = 0;
 int cnt[3];
 memset(cnt, 0, sizeof(cnt));
 for(int i=0; i<x+y; i++){
 	sum += 1ll * pq.top().first;
 	cnt[pq.top().second]++;
 	pq.pop();
 }

 if((cnt[0]<=x) && (cnt[1]<=y)){
 	cout << sum << "\n";
 }
 else if(cnt[0]>x){
 	for(int i=x; i<cnt[0]; i++){
 		sum -= 1ll * aa[i];
 	}
 	int idx = 0;
 	while(idx<cnt[0]-x){
 		if(pq.top().second != 0) {sum += 1ll * pq.top().first; idx++;}
 		pq.pop();
 	}
 	cout << sum << "\n";
 } else if(cnt[1]>y){
 	for(int i=y; i<cnt[1]; i++){
 		sum -= 1ll * bb[i];
 	}
 	int idx = 0;
 	while(idx<cnt[1]-y){
 		if(pq.top().second != 1) {sum += 1ll * pq.top().first; idx++;}
 		pq.pop();
 	}
 	cout << sum << "\n";
 }

}

Measured memory_bytes: 7664
def solve():
    S = input()
    if S[0] != 'A':
        return 'WA'
    cnt = 0
    for i in range(2, len(S)-1):
        if S[i] == 'C':
            cnt += 1
            C = i
    if cnt != 1:
        return 'WA'
    T = S[:C] + S[C+1:]
    Tset = set(list(T[1:]))
    sletter = set(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'])
    if sletter.union(Tset) != sletter:
        return 'WA'
    return 'AC'


def main():
    ans = solve()
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A,B,C,K;
  cin>>A>>B>>C>>K;
  long long m=0;
  if(K>A){
    m+=A;
  }else{
    m+=K;
    cout<<m<<endl;
    return 0;
  }
  if(K-A<=B){
    cout<<m<<endl;
    return 0;
  }
  if(K-A-B-C<=0){
    m-=K-A-B;
  }  
  cout<<m<<endl;
}



Measured memory_bytes: 3604
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-02-09 20:53:25
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  string s, t; cin >> s >> t;
  int a, b; cin >> a >> b;
  string u; cin >> u;
  if (s == u) {
    cout << a - 1 << " " << b << endl;
  } else {
    cout << a << " " << b - 1 << endl;
  }

  return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f(i,n) for(ll i=0;i<n;i++)
#define fi(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF LLONG_MAX
#define ALL(a) a.begin(),a.end()
#define MAX 200005

int main()
{
    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    f(i,n)
    cin>>a[i]>>b[i]>>c[i];
    
    ll dp[n][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    
    fi(i,1,n)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int mod  = 1e9+7;
const int maxn = 1e3+10;

int W,H;
char x;
int m[maxn][maxn];
int dp[maxn][maxn];
int solve(int w,int h)
{
	if (dp[w][h]!=-1)
		return dp[w][h];
	if (w<1||h<1)
		return 0;
	if (m[w][h]==0)
		return 0;
	int tem1=solve(w-1,h);
	int tem2=solve(w,h-1);
	dp[w][h]=(tem1+tem2)%mod;
	return dp[w][h];
}
void check()
{
	for (int i=1;i<=W;i++)
	{
		for (int j=1;j<=H;j++)
			cout<<setw(4)<<dp[i][j];
		cout<<endl;
	}
}
int main()
{
	cin>>W>>H;
	for (int i=1;i<=W;i++)
	{
		for (int j=1;j<=H;j++)
		{
			dp[i][j]=-1;
			cin>>x;
			if (x=='.')
				m[i][j]=1;
			else
				m[i][j]=0;
		}
	}
	if (m[1][2]!=0)
		dp[1][2]=1;
	if (m[2][1]!=0)
		dp[2][1]=1;
	dp[1][1]=1;
	cout<<solve(W,H);
	//check();
	return 0;
}


Measured memory_bytes: 11568
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int A;
    int B;
    int C;
    int N;
    
    cin >> A;

    cout << 3 * A * A << endl;    
    

}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main()
{
    int k;
    cin>>k;
    if(k<10)
    {
        cout<<k<<endl;
        return 0;
    }
    queue<ll> q;
    for (ll i = 1; i <=9; i++) q.push(i);
    int count=k-9;
    while (count>0)
    {
        ll x=q.front();q.pop();
        if(x%10!=0) 
        {
            q.push(10*x+(x%10)-1);
            count--;
        }
        if(count<=0)break;
        q.push(10*x+(x%10));
        count--;
        if(count<=0)break;
        if(x%10!=9)
        {
            q.push(10*x+(x%10)+1);
            count--;
        }
    }
    ll x=q.back();
    cout<<x<<endl;
    
    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;


int main(){
	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll ans = LLONG_MAX;
	for(ll i = 0; i <= max(x, y); ++i){
		ll ea = max(x - i, (ll)0), eb = max(y - i, (ll)0);

		ll value = c * i * 2 + a * ea + b * eb;
		ans = min(ans, value);
	}

	cout << ans << endl;

}

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

using namespace std;

int main()
{
   int a, b, c, d, e, k;

   cin >> a >> b >> c >> d >> e >> k;

   if(b - a > k || c - a > k || d - a > k || e - a > k) cout << ":(" << endl;
   else if(c - b > k || d - b > k || e - b > k) cout << ":(" << endl;
   else if(d - c > k || e - c > k) cout << ":(" << endl;
   else if(e - d > k) cout << ":(" << endl;
   else cout << "Yay!" << endl;

   return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && A!= C)
    cout << "Yes" << endl;
  else if (B == C && A!= B)
    cout << "Yes" << endl;
  else if (A == C && B!= C)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<utility>
#include<string>

using namespace std;

char ko[1005][1005];
int used[1005][1005];
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
int sx,sy;
int maxx,maxy;
int n;
int ans;

typedef struct{
  int x,y;
  int c;
}P;

int rat(int na);
int fatoi(char a);

main(){
  int i,j,temp; 
  cin >> maxy >> maxx;
  cin >> n;
  for(i=0;i<maxy;i++){
    for(j=0;j<maxx;j++){
      cin >> ko[j][i];
      if(ko[j][i]=='S'){
	sx=j;
	sy=i;
      }
    }
  }
  for(i=1;i<=n;i++) ans+=rat(i);
  cout << ans << endl;

}

int rat(int na){
  //  puts("B");
  memset(used,0,sizeof(used));
  queue<P> que;
  que.push((P){sx,sy,0});
  used[sx][sy]=1;
  while(que.size()>0){
    //  puts("C");
    P p=que.front();
    que.pop();
    //    cout << p.c << '_' << ko[p.x][p.y] << '_' << na << endl;
    if(fatoi(ko[p.x][p.y])==na){
      //      puts("A");
      sx=p.x;
      sy=p.y;
      //      cout << p.c << '_' << ko[p.x][p.y] << '_' << na << endl;
      return(p.c);
    }
    for(int i=0;i<4;i++){
      int mx=p.x+dx[i];
      int my=p.y+dy[i];
      if(0<=mx && mx < maxx && 0<=my && my<maxy){
	if(ko[mx][my]!='X' && used[mx][my]!=1){
	  used[mx][my]=1;
	  que.push((P){mx,my,p.c+1});
	}
      }
    }
  }
  return (-1);
}

int fatoi(char a){
  if(a=='0') return 0;
  if(a=='1') return 1;
  if(a=='2') return 2;
  if(a=='3') return 3;
  if(a=='4') return 4;
  if(a=='5') return 5;
  if(a=='6') return 6;
  if(a=='7') return 7;
  if(a=='8') return 8;
  if(a=='9') return 9;
  return -1;
}

Measured memory_bytes: 0
n=int(input())
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)


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

Measured memory_bytes: 75776
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for( j = p ; j < r ; j++ ){
    if( A[j] <= x ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}

int main(){
  int i, q;

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

  q = partition(0, n-1);

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

  return 0;
}



Measured memory_bytes: 2108
#create date: 2020-08-07 07:40

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def check(k, n):
    a = k * (k + 1) // 2
    if n <= a:
        return True
    else:
        return False


def main():
    n = ni()

    # bisect
    l = 1; r = n
    while l + 1 < r:
        k = (l + r) // 2
        if check(k, n):
            r = k
        else:
            l = k
    
    no = r * (r + 1) // 2 - n
    for i in range(1, r+1):
        if i == no:
            continue
        print(i)

if __name__ == "__main__":
    main()

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

using namespace std;

struct Matrix
{
	int r,c;
};

int main()
{
	Matrix Mat[100]; 
	int n,dp[100][100];
	memset(dp,0,sizeof(dp));
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d%d",&Mat[i].r,&Mat[i].c);
	for(int i=1;i<n;i++)
		for(int j=0;i+j<n;j++)
		{
			dp[j][i+j]=INT_MAX;
			for(int k=j;k<i+j;k++)
				dp[j][i+j]=min(dp[j][i+j],dp[j][k]+dp[k+1][i+j]+Mat[j].r*Mat[i+j].c*Mat[k].c);
		}
	printf("%d\n",dp[0][n-1]);
	return 0;
}

Measured memory_bytes: 3208
#include<stdio.h>

#define MAX 100

void print(int A[],int);

int main(){
  int i,j,n,key,A[MAX];

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

  print(A,n);

  for(i=1;i<n;i++){
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = key;
    print(A,n);
  }
  return 0;
}

void print(int A[],int n){
  int i;

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

Measured memory_bytes: 600
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for ai in a:
    d[ai] += 1

cand = [k for k, v in d.items() if v >= 2]
cand.sort()

ans = 0
if len(cand) >= 1 and d[cand[-1]] >= 4:
    ans = cand[-1] ** 2
elif len(cand) >= 2:
    ans = cand[-1] * cand[-2]

print(ans)


Measured memory_bytes: 18600
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<P,int> PP;


int n;
int a[1010][1010],depth[1010][1010],h[1010][1010];
vector<P> G[1010][1010];



void solve(){
    cin >> n;
    rep(i,n){
        rep(j,n-1){
            cin >> a[i][j];a[i][j]--;
            depth[i][j]=-1;
            h[i][j]=0;
        }
    }
    rep(i,n){
        rep(j,n-2){
            int a_=a[i][j],b_=i;
            int next_a=a[i][j+1],next_b=i;
            if (a_<b_) swap(a_,b_);
            if (next_a<next_b) swap(next_a,next_b);
            G[a_][b_].push_back(P(next_a,next_b));
            h[next_a][next_b]+=1;
        }
    }
    queue<PP> que;
    int ans=1,num=0;
    rep(i,n){
        rep(j,i){
            if (h[i][j]==0) {
                que.push(PP(P(i,j),1));
                num+=1;
            }
        }
    }
    while (!que.empty()){
        P s=que.front().first;
        int k=que.front().second;
        que.pop();
        depth[s.first][s.second]=k;
        rep(i,G[s.first][s.second].size()){
            P t=G[s.first][s.second][i];
            h[t.first][t.second]-=1;
            if (h[t.first][t.second]==0){
                ans=k+1;
                num+=1;
                que.push(PP(t,k+1));
            }
        }
    }

    //cout << num << " " << ans << endl;

    if (num!=n*(n-1)/2) cout << -1 << endl;
    else cout << ans << endl;
}

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

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

int main()
{
    string s;
    cin >> s;
    ll ans = 700;
    if (s[0] == 'o') ans += 100;
    if (s[1] == 'o') ans += 100;
    if (s[2] == 'o') ans += 100;
    cout << ans << endl;



}


Measured memory_bytes: 3592
import java.util.*

fun slideMin(a: List<Int>, k: Int): ArrayList<Int> {
  val res = arrayListOf<Int>()
  val deq: Deque<Int> = LinkedList()
  for (r in 0 until a.size) {
    val l = r - k + 1
    while (!deq.isEmpty() && a[deq.getLast()] >= a[r]) deq.removeLast()
    deq.add(r)
    if (l < 0) continue
    res.add(deq.getFirst())
    if (deq.getFirst() == l) deq.removeFirst()
  }
  return res
}

fun slideMax(a: List<Int>, k: Int): ArrayList<Int> {
  val res = arrayListOf<Int>()
  val deq: Deque<Int> = LinkedList()
  for (r in 0 until a.size) {
    val l = r - k + 1
    while (!deq.isEmpty() && a[deq.getLast()] <= a[r]) deq.removeLast()
    deq.add(r)
    if (l < 0) continue
    res.add(deq.getFirst())
    if (deq.getFirst() == l) deq.removeFirst()
  }
  return res
}

fun main(args: Array<String>) {
  val (n, k) = readLine()!!.split(" ").map { it.toInt() }
  val p = readLine()!!.split(" ").map { it.toInt() }
  val isUp = IntArray(n) { 
    if (it == 0) {
      0
    } else {
      if (p[it - 1] < p[it]) 1 else 0
    }
  }
  val cs = mutableListOf<Int>(0)
  isUp.reduce { buf, value ->
    cs.add(buf + value)
    buf + value
  }

  var sorted = 0
  var ans = 0
  val mn = slideMin(p, k + 1)
  val mx = slideMax(p, k + 1)
  for (i in 0..n - k) {
    val d = cs[i + k - 1] - cs[i]
    if (d == k - 1) {
      sorted = 1 
      continue
    }
    if (i > 0 && mn[i - 1] == i - 1 && mx[i - 1] == i + k - 1) continue
    ans++
  }
  println(ans + sorted)
}


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

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

    int32_t n = s.length();
    int32_t a[n];

    for (int32_t i = 0; i < n; i++) {
        a[i] = 0;
    }

    int32_t r = 0;
    int32_t l = 0;
    for (int32_t i = 0; i < n; i++) {
        int32_t j;
        if (s.at(i) == 'R') {
            r++;
            if (s.at(i + 1) == 'L') {
                j = i;
            }
        } else {
            l++;
            if (i == n - 1 || s.at(i + 1) == 'R') {
                a[j] = (r + 1) / 2 + l / 2;
                a[j + 1] = r / 2 + (l + 1) / 2;
                r = 0;
                l = 0;
            }
        }
    }

    for (int32_t i = 0; i < n; i++) {
        cout << a[i];
        if (i < n - 1) {
            cout << ' ';
        } else {
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string.h>

using namespace std;

typedef unsigned long long ull;

const int p = 131;

int N;
char s[60];
ull x,Hash[60],po[60];

int main(){
	scanf("%d",&N);
	scanf("%s",s);
	x='A'*p*p+'B'*p+'C';
	
	Hash[0]=s[0],po[0]=p;
	for(int i=1;i<N;i++){
		Hash[i]=Hash[i-1]*p+s[i];
		po[i]=po[i-1]*p;
	}
	
	int cnt=0;
	for(int i=2;i<N;i++){
		if(Hash[i]-Hash[i-3]*po[2]==x) cnt++;
	}
	printf("%d",cnt);
	return 0;
}


Measured memory_bytes: 3704
#include <stdio.h>

int main() {

int n,i,j,k;
int b,f,r,v;
int t[4][3][10];

for (i = 0;i < 4; i++){
for (j = 0;j < 3; j++){
for (k = 0;k < 10; k++){
t[i][j][k] = 0;
}
}
}
scanf("%d\n", &n);

for (i = 0; i < n; i++){
   scanf("%d %d %d %d\n", &b, &f, &r, &v);
   t[b-1][f-1][r-1] += v;
}

for (b = 0; b < 4; b++){
for (f = 0; f < 3; f++){
for (r = 0; r < 10; r++){
printf(" %d", t[b][f][r]);
}
printf("\n");
}
if (b != 3){ 
for (i = 0; i < 20; i++) printf("#");
printf("\n");}
}
}


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

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int W, n, dp[1024];

int main() {
    for (int _q = 0;; _q++) {
        scanf("%d", &W);
        if (W == 0) return 0;
        scanf("%d", &n);
        memset(dp, 0, sizeof(dp));
        rep (i, n) {
            int v, w;
            scanf("%d,%d", &v, &w);
            for (int i = W-w; i >= 0; i--) {
                dp[i+w] = max(dp[i+w], dp[i]+v);
            }
        }
        int ansv = 0, answ = 0;
        rep (i, W+1) if (ansv < dp[i]) {
            ansv = dp[i];
            answ = i;
        }
        printf("Case %d:\n", _q+1);
        printf("%d\n", ansv);
        printf("%d\n", answ);
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define INF 1000000000
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PP = pair<P, int>;

class UnionFindTree{
	private:
		int N;
		unique_ptr<int[]> parent;
		unique_ptr<int[]> rank;
		unique_ptr<int[]> size;
	public:
		UnionFindTree(int N){
			this -> N = N;
			this -> parent = make_unique<int[]>(N);
			this -> rank = make_unique<int[]>(N);
			this -> size = make_unique<int[]>(N);
			for(int i = 0; i < (int) N; i++){
				parent[i] = i; rank[i] = 0; size[i] = 1;
			}
		}
		void init(){
			for(int i = 0; i < (int) N; i++){
				parent[i] = i; rank[i] = 0; size[i] = 1;
			}
		}
		int find(int x){
			if(parent[x] == x) return x;
			else return parent[x] = find(parent[x]);
		}
		void unite(int x, int y){
			x = find(x); y = find(y);
			if(x == y) return;

			if(rank[x] < rank[y]){
				parent[x] = y;
				size[y] += size[x];
			}else{
				parent[y] = x;
				size[x] += size[y];
				if(rank[x] == rank[y]) rank[x]++;
			}
		}
		bool same(int x, int y){
			return find(x) == find(y);
		}
		int count(int x){
			return size[find(x)];
		}
};

struct edge{
	int from, to, cost;
};

bool comp(PP p1, PP p2){
	return p1.first.second < p2.first.second;
}

bool compEdge(edge e1, edge e2){
	return e1.cost < e2.cost;
}

int main(void){
	int N; cin >> N;
	vector<PP> points(N);
	for(int i = 0; i < N; i++){
		cin >> points[i].first.first >> points[i].first.second;
		points[i].second = i;
	}

	sort(begin(points), end(points));
	vector<edge> G;
	for(int i = 0; i < N-1; i++){
		PP p1 = points[i], p2 = points[i+1];
		int c = min(abs(p1.first.first - p2.first.first), abs(p1.first.second - p2.first.second));
		edge e = {p1.second, p2.second, c};
		G.push_back(e);
	}

	sort(begin(points), end(points), comp);
	for(int i = 0; i < N-1; i++){
		PP p1 = points[i], p2 = points[i+1];
		int c = min(abs(p1.first.first - p2.first.first), abs(p1.first.second - p2.first.second));
		edge e = {p1.second, p2.second, c};
		G.push_back(e);
	}

	UnionFindTree uf(N);
	sort(begin(G), end(G), compEdge);
	ll res = 0;
	for(int i = 0; i < (int)G.size(); i++){
		edge e = G[i];
		if(not uf.same(e.from, e.to)){
			uf.unite(e.from, e.to);
			res += e.cost;
		}
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 6132
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
//////////////

void solve() {
	int N, M;
	cin >> N >> M;
	vector<pair<LL, LL>> A;
	pair<LL, LL> temp;
	temp.second = 1;
	for (int i = 0; i < N; ++i) {
		cin >> temp.first;
		A.push_back(temp);
	}
	for (int i = 0; i < M; ++i) {
		cin >> temp.second >> temp.first;
		A.push_back(temp);
	}
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	int len = A.size();
	LL nokori = N;
	LL sum = 0;
	for (int i = 0; i < len && nokori; ++i) {
		if (nokori >= A[i].second) {
			sum += A[i].first * A[i].second;
			nokori -= A[i].second;
		}
		else {
			sum += A[i].first * nokori;
			nokori = 0;
		}
	}
	cout << sum << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i;
	cin>>k>>n;
	int arr[n];
	for(i=0 ; i<n ; i++){
		cin>>arr[i];
	}
	sort(arr,arr+n);
	int minm=k+1,cur;
	for(i=0 ; i<n ; i++){
		if(i==0){
			cur=arr[n-1] - arr[i];
		}
		else{
			cur= k - (arr[i] - arr[i-1]);
		}
		minm=min(cur,minm);
	}
	cout<<minm<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct cmp1 {
  bool operator () (const int& x,const int& y) {
    return x > y;
  }
};
struct cmp2 {
  bool operator () (const int& x,const int& y) {
    return x < y;
  }
};
priority_queue<int,vector<int>,cmp1> q1;
priority_queue<int,vector<int>,cmp2> q2;
const int N = 3 * 100010, INF = 1ll << 60;
int n,a[N],mx[N],mn[N],tmp;
signed main() {
  scanf("%lld",&n);
  for (int i = 1 ; i <= n * 3 ; ++ i)
    scanf("%lld",&a[i]);
  while (!q1.empty()) q1.pop();
  for (int i = 1 ; i <= n ; ++ i)
    q1.push(a[i]), tmp += a[i];
  mx[n] = tmp;
  for (int i = n + 1 ; i <= n * 2 ; ++ i) {
    if (a[i] > q1.top()) {
      tmp += a[i] - q1.top();
      q1.pop();
      q1.push(a[i]);
    }
    mx[i] = tmp;
  }
  tmp = 0;
  while (!q2.empty()) q2.pop();
  for (int i = n * 3 ; i > n * 2 ; -- i)
    q2.push(a[i]), tmp += a[i];
  mn[n * 2 + 1] = tmp;
  for (int i = n * 2 ; i > n ; -- i) {
    if (a[i] < q2.top()) {
      tmp += a[i] - q2.top();
      q2.pop();
      q2.push(a[i]);
    }
    mn[i] = tmp;
  }
  int ans = -INF;
  for (int i = n ; i <= n * 2 ; ++ i)
    ans = max(ans,mx[i] - mn[i+1]);
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 7668
//============================================================================
// Name        : ITP_1_6_B.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int main() {
	int total,num;
	char mark,marks[4]={'S','H','C','D'};
	vector<vector<int> > a(4,vector<int>(13));
	for(int i=0;i<4;++i) {
		for(int j=0;j<13;++j) {
			a[i][j]=0;
		}
	}
	cin >> total;
	for(int i=0;i<total;++i) {
		cin >> mark >> num;
		switch(mark) {
		case 'S' :
			a[0][num-1]=1;
			break;
		case 'H' :
			a[1][num-1]=1;
			break;
		case 'C' :
			a[2][num-1]=1;
			break;
		case 'D' :
			a[3][num-1]=1;
			break;
		}
	}
	for(int i=0;i<4;++i) {
		for(int j=0;j<13;++j) {
			if (a[i][j]==0) {
				printf("%c %d\n",marks[i],j+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    ll a, b;
    while(cin >> a >> b){
        cout << gcd(a, b) << " " << lcm(a, b) << "\n";
    }
}
/*⠀⠀⠀⠀⠀⢀⣀⣀⣀    
⠀⠀⠀⠰⡿⠿⠛⠛⠻⠿⣷
⠀⠀⠀⠀⠀⠀⣀⣄⡀⠀⠀⠀⠀⢀⣀⣀⣤⣄⣀⡀
⠀⠀⠀⠀⠀⢸⣿⣿⣷⠀⠀⠀⠀⠛⠛⣿⣿⣿⡛⠿⠷
⠀⠀⠀⠀⠀⠘⠿⠿⠋⠀⠀⠀⠀⠀⠀⣿⣿⣿⠇
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠁

⠀⠀⠀⠀⣿⣷⣄⠀⢶⣶⣷⣶⣶⣤⣀
⠀⠀⠀⠀⣿⣿⣿⠀⠀⠀⠀⠀⠈⠙⠻⠗
⠀⠀⠀⣰⣿⣿⣿⠀⠀⠀⠀⢀⣀⣠⣤⣴⣶⡄
⠀⣠⣾⣿⣿⣿⣥⣶⣶⣿⣿⣿⣿⣿⠿⠿⠛⠃
⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄
⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡁
⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁
⠀⠀⠛⢿⣿⣿⣿⣿⣿⣿⡿⠟
⠀⠀⠀⠀⠀⠉⠉⠉
*/

//library//
ll mod_fact(ll a, ll mod){
    ll ans = 1;
    while(a > 1){
        ans = ans * a % mod;
        a--;
    }
    return ans; 
}
ll mod_pow(ll a, ll b, ll mod){
    ll ans = 1;
    while(b > 0){
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll mod_inv(ll a, ll mod){
    return mod_pow(a, mod - 2, mod);
}
ll gcd(ll a, ll b){
    while(a % b){
        return gcd(b, a % b);
    }
    return b;
}
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}



Measured memory_bytes: 3044
#include<iostream> 
#include <list> 
#include <limits.h> 

using namespace std;

class Graph
{
	int V;     
	list<int> *adj;    
	bool isCyclicUtil(int v, bool visited[], bool *rs);  
public:
	Graph(int V);    
	void addEdge(int v, int w);    
	bool isCyclic();    
};

Graph::Graph(int V)
{
	this->V = V;
	adj = new list<int>[V];
}

void Graph::addEdge(int v, int w)
{
	adj[v].push_back(w);  
}


bool Graph::isCyclicUtil(int v, bool visited[], bool *recStack)
{
	if (visited[v] == false)
	{
		visited[v] = true;
		recStack[v] = true;

		list<int>::iterator i;
		for (i = adj[v].begin(); i != adj[v].end(); ++i)
		{
			if (!visited[*i] && isCyclicUtil(*i, visited, recStack))
				return true;
			else if (recStack[*i])
				return true;
		}

	}
	recStack[v] = false; 
	return false;
}

bool Graph::isCyclic()
{
	bool *visited = new bool[V];
	bool *recStack = new bool[V];
	for (int i = 0; i < V; i++)
	{
		visited[i] = false;
		recStack[i] = false;
	}

	for (int i = 0; i < V; i++)
		if (isCyclicUtil(i, visited, recStack))
			return true;

	return false;
}

int main()
{
	int V, E, s, t;

	cin >> V >> E;

	Graph g(V);
	
	for (int i = 0; i < E; i++) {
		cin >> s >> t;
		g.addEdge(s, t);
	}

	if (g.isCyclic())
		cout << 1 << endl;
	else
		cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3140
// SeeAlso: https://atcoder.jp/contests/abc144/tasks/abc144_e

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

ll N, K;
vector<ll> A,F;
 
bool judge(ll lim){
  ll res=0;
  for(int i=0;i<N;i++){
    ll z=lim/F[i];
    if(z>=A[i]) continue;
    res+=(A[i]-z);
    if(res>K) return false; 
  }
  return true;
}

int main() {

    cin >> N >> K;

    A.resize(N);
    F.resize(N);
    rep(i,N) cin>>A[i];
    rep(i,N) cin>>F[i];
 
    sort(A.begin(),A.end());
    sort(F.begin(),F.end());
    reverse(F.begin(),F.end());
 
    ll ok=1e15,ng=-1;
    while(ok-ng>1){
        ll mid=(ok+ng)/2;
        if(judge(mid)) ok=mid;
        else ng=mid;
    }

    print(ok);
    return 0;
}


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

int main() {
	string a, b;
	int ans = 0;
	cin >> a;
	for (int b = 0; b < 4; b++) {
		if (a[b] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
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
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int dp[100005][3];

int main() {
	int n;
	scanf("%d", &n);
	REP(i, n) {
		int abc[3];
		scanf("%d%d%d", &abc[0], &abc[1], &abc[2]);
		REP(j, 3) {
			REP(k, 3) {
				if (j == k)continue;
				dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[k]);
			}
		}
	}
	printf("%d\n", max(dp[n][0], max(dp[n][1], dp[n][2])));
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n],b[n];
  for(int i = 0;i < n;i++){
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b,b+n);
  int n1 = b[n-1],n2 = b[n-2];
  for(int i = 0;i < n;i++){
    if(a[i] == n1){
      cout << n2 << endl;
    }
    else{
      cout << n1 << endl;
    }
  }
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
 
int main(){
  int N,M;
  cin>>N>>M;
  VL A(N);
  rep(i,N) cin>>A[i];
  sort(all(A),greater<ll>());
  ll sum=0;
  rep(i,N) sum+=A[i];
  if(A[M-1]*4*M<sum) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define N 100005
using namespace std;

typedef long long ll;
ll n, m, v[N], c[3];
vector<ll> gr[N];

bool f(ll p, ll q) {
	ll i;
    if (v[p]) return v[p] == q;
    v[p] = q;
    for (i = 0; i < gr[p].size(); i++) {
		if (!f(gr[p][i], 3 - q)) return 0;
    }
    return 1;
}

int main()
{
	ll i, t1, t2;
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		scanf("%lld %lld", &t1, &t2);
		gr[t1].push_back(t2);
		gr[t2].push_back(t1);
	}
    if (f(1, 1)) {
		for (i = 1; i <= n; i++) c[v[i]]++;
		cout << c[1] * c[2] - m << endl;
    } else {
		cout << n * (n - 1) / 2 - m << endl;
    }
    return 0;
}

Measured memory_bytes: 7424
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  static int[] list;
  static int[] dpa;
  static int[] dpb;

  static {
    list = new int[1000];
    for (int i = 0; i < 1000; ++i) {
      list[i] = ((i + 1) * (i + 2) * (i + 3)) / 6;
    }
    dpa = new int[1000000];
    Arrays.fill(dpa, 1 << 28);
    dpa[0] = 0;
    for (int i = 0; i < 1000; ++i) {
      for (int j = 0; j < 1000000; ++j) {
        if (j + list[i] >= 1000000) {
          break;
        }
        dpa[j + list[i]] = Math.min(dpa[j + list[i]], dpa[j] + 1);
      }
    }

    dpb = new int[1000000];
    Arrays.fill(dpb, 1 << 28);
    dpb[0] = 0;
    for (int i = 0; i < 1000; ++i) {
      if (list[i] % 2 != 1) {
        continue;
      }
      for (int j = 0; j < 1000000; ++j) {
        if (j + list[i] >= 1000000) {
          break;
        }
        dpb[j + list[i]] = Math.min(dpb[j + list[i]], dpb[j] + 1);
      }
    }
  }

  void run() {
    for (; ; ) {
      int n = ni();
      if (n == 0) {
        break;
      }

      System.out.println(dpa[n] + " " + dpb[n]);
    }
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

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

using namespace std;

signed main()
{
	string s;
	cin >> s;
	int n = (int)s.size();
	string res = "";
	for (int i = 0; i < n; i++)
		if (res.size() > 0 && s[i] == 'B')
			res.pop_back();
		else if (s[i] == '1')
			res += "1";
		else if (s[i] == '0')
			res += "0";
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int M,N;
  cin>>M>>N;
  vector<pair<pair<int,int>,int>> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i].first.second>>A[i].first.first;
    A[i].second=i;
  }
  sort(A.begin(),A.end());
  vector<int> B(M+1,1),C(N),D(N);
  for(int i=0;i<N;i++){
    C[A[i].second]=B[A[i].first.second];
    B[A[i].first.second]++;
    D[A[i].second]=A[i].first.second;
  }
  for(int i=0;i<N;i++){
    for(int j=to_string(D[i]).size();j<6;j++)
      cout<<0;
    cout<<D[i];
    for(int j=to_string(C[i]).size();j<6;j++)
      cout<<0;
    cout<<C[i]<<endl;
  }
}

Measured memory_bytes: 5612
fun main(args: Array<String>) {
    val (m, d) = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0
    for(month in 1..m) {
        for(day in 1..d) {
            val d10 = day / 10
            val d1 = day % 10
            if(d10 * d1 == month && d10 > 1 && d1 > 1) {
                ans++
            }
        }
    }
    println(ans)
}

Measured memory_bytes: 37616
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0
for i in range(K):
    t = T[i::K]
    dp = [[0] * 3 for _ in range(len(t) + 1)]
    for i in range(len(t)):
        if t[i] == "r":
            dp[i + 1][0] = max(dp[i][1], dp[i][2])
            dp[i + 1][1] = max(dp[i][0] + P, dp[i][2] + P)
            dp[i + 1][2] = max(dp[i][0], dp[i][1])
        elif t[i] == "p":
            dp[i + 1][0] = max(dp[i][1], dp[i][2])
            dp[i + 1][1] = max(dp[i][0], dp[i][2])
            dp[i + 1][2] = max(dp[i][0] + S, dp[i][1] + S)
        else:
            dp[i + 1][0] = max(dp[i][1] + R, dp[i][2] + R)
            dp[i + 1][1] = max(dp[i][0], dp[i][2])
            dp[i + 1][2] = max(dp[i][0], dp[i][1])
    ans += max(dp[-1])
print(ans)


Measured memory_bytes: 16396
import java.io.IOException;
import java.util.NavigableSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			NavigableSet<Integer> taro = new TreeSet<Integer>();
			NavigableSet<Integer> hana = new TreeSet<Integer>();
			for (int i = 0; i < n; i++)
				taro.add(scanner.nextInt());
			for (int i = 1; i <= n * 2; i++)
				hana.add(i);
			hana.removeAll(taro);
			NavigableSet<Integer> pc = taro;
			Integer table = null;
			while (!taro.isEmpty() && !hana.isEmpty()) {
				if (table == null)
					table = pc.pollFirst();
				else {
					if ((table = pc.higher(table)) != null)
						pc.remove(table);
				}
				pc = pc.equals(taro) ? hana : taro;
			}
			System.out.println(hana.size());
			System.out.println(taro.size());
		}
	}
}

Measured memory_bytes: 20708
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);
using namespace std;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    int ans = 0;
    map<char, int> m;
    m['r'] = r;
    m['s'] = s;
    m['p'] = p;
    vector<bool> gaman(n);
    for (int i = 0; i < n; i++) {
        char c;
        if (t[i] == 'r') c = 'p';
        if (t[i] == 's') c = 'r';
        if (t[i] == 'p') c = 's';

        if (i < k)
            ans += m[c];
        else {
            if (t[i - k] == t[i]) {
                if (!gaman[i - k]) {
                    gaman[i] = true;
                } else {
                    ans += m[c];
                }
            } else {
                ans += m[c];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 2e9;

class UnionFind {
public:
	vector<int> par;
	UnionFind(int n) {
		par = vector<int>(n, -1);
	}
	int root(int a) {
		if (par[a] < 0) {
			return a;
		}
		else {
			return par[a] = root(par[a]);
		}
	}
	int size(int a) {
		return -par[root(a)];
	}
	bool connect(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) {
			return false;
		}
		if (size(a) < size(b)) {
			swap(a, b);
		}
		par[a] += par[b];
		par[b] = a;
		return true;
	}
};


int main() {
	int n, k, l; cin >> n >> k >> l;
	UnionFind road(n), train(n);
	rep(i, 0, k) {
		int p,q; cin >> p >> q;
		p--; q--;
		road.connect(p, q);
	}
	rep(i, 0, l) {
		int p, q; cin >> p >> q;
		p--; q--;
		train.connect(p, q);
	}
	map<P, int> mp;
	rep(i, 0, n) {
		mp[{road.root(i), train.root(i)}]++;
	}
	rep(i, 0, n) {
		printf("%d ", mp[{road.root(i), train.root(i)}]);
	}
	return 0;
}


Measured memory_bytes: 13568
import numpy as np
import sys
input = sys.stdin.readline
 
N = int(input())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
C = np.array(input().split(), dtype=np.int64)

A.sort()
C.sort()

A_cnt = np.searchsorted(A, B, side='left')
C_cnt = np.searchsorted(C, B, side='right')

ans = (A_cnt * (N-C_cnt)).sum()

print(ans)

Measured memory_bytes: 26760