akhauriyash/Code-Regression huggingface dataset:
/**
*    author:  boutarou
*    created: 26.06.2020 09:04:00
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const double PI = 3.1415926535897932;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a;
    cin >> a;
    cout << a+ a*a + a*a*a << endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}
long comb(int N,int K)
{
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

    VVI A(3,VI(3)), C(3,VI(3,0));
    REP(i,3){
        REP(j,3){
            cin >> A[i][j];
        }
    }

    int N;
    cin >> N;

    VI b(N);
    REP(i,N){
        cin >> b[i];
        REP(j,3){
            REP(k,3){
                if (A[j][k] == b[i]) C[j][k] = 1;
            }
        }
    }

    int chk = 0;
    REP(i,3){
        if (C[i][0] && C[i][1] && C[i][2]) chk = 1;
        if(C[0][i] && C[1][i] && C[2][i]) chk = 1;
    }
    if (C[0][0] && C[1][1] && C[2][2]) chk = 1;
    if (C[0][2] && C[1][1] && C[2][0]) chk = 1;

    if(chk) cout << "Yes" << endl;
    else cout << "No" << endl;


    
}

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

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

  string ans = "UNRESTORABLE";
  if (s.length() < t.length()) {
    cout << ans << "\n";
    return 0;
  }

  int minNumQuestion = 1000000;
  int minNumQuestionIdx = -1;
  for (int i = s.length()-t.length(); i >= 0; i--) {
    string substr = s.substr(i, t.length());
    int cntQuestion = 0;
    bool isAble = true;
    for (int j = 0; j < t.length(); j++) {
      if (substr.at(j) == '?') {
        cntQuestion++;
        continue;
      } else if (substr.at(j) == t.at(j)) {
        continue;
      } else {
        isAble = false;
        break;
      }
    }

    if (isAble) {
      if (minNumQuestion > cntQuestion) {
        minNumQuestion = cntQuestion;
        minNumQuestionIdx = i;
      }

      if (i - 1 >= 0 && (s.at(i - 1) == '?' || s.at(i - 1) == 'a')) {
        break;
      }
    }
  }


  if (minNumQuestionIdx != -1) {
    ans = s.replace(minNumQuestionIdx, t.length(), t);
    for (int j = 0; j < ans.length(); j++) {
      if (s.at(j) == '?') {
        ans.replace(j, 1, "a");
      }
    }
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll const MOD=1'000'000'007;

int N,K;

int main(){
    cin>>N>>K;

    int ans=K;
    rep(i,N-1) ans*=K-1;

    cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

signed main(){
  int N, D;
  cin >> N >> D;
  int ans = 0;
  for( int i = 0; i < N; i++ ){
    int A, B;
    cin >> A >> B;
    if( (A*A)+(B*B) <= D*D ){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1LL<<60;
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(void) {
    int n; cin >> n;
    vector<int> l(n);
    REP(i, n) cin >> l[i];
    sort(ALL(l));
    int sum = 0;
    for (int low = 0; low < n; low++) {
        for (int mid = low + 1; mid < n; mid++) {
            auto itr = lower_bound(l.begin(), l.end(), l[low] + l[mid]);
            ll ng = distance(itr, l.end());
            //cout << low << " " << mid << " " << ng << endl;
            sum += n - 1 - mid - ng;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>

using namespace std;

char a[10];
char b[10];
char c[10];

int main()
{
	scanf("%s",&a);
	scanf("%s",&b);
	scanf("%s",&c);
	int lena = strlen(a);
	int lenb = strlen(b);
	int lenc = strlen(c);
	if(a[lena - 1] == b[0] && b[lenb - 1] == c[0]){
		printf("YES\n");
	}
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
n=int(input())
pos=[]
neg=[]
for i in range(n):
    s=input()
    bal=0
    mn=0
    for ch in s:
        if ch=='(':
            bal+=1
        if ch==')':
            bal-=1
        mn=min(mn,bal)
    if -mn<bal-mn:
        pos.append((-mn,bal-mn))
    else:
        neg.append((-mn,bal-mn))
def cmp(it):
    return -it[1]
pos.sort()
neg.sort(key=cmp)
bal=0
ok=True
for (m,b) in pos:
    if bal-m<0:
        ok=False
    bal+=b-m
for (m,b) in neg:
    if bal-m<0:
        ok=False
    bal+=b-m
if bal!=0:
    ok=False
if ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 173588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string S;
  cin >> S;
  ll co = 0;
  rep(i, S.size() / 2) {
    if(S.at(i) != S.at(S.size() - i - 1)) {
      co++;
    }
  }
  cout << co << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    b.at(i) = a.at(i);
  }
  
  sort(b.begin(), b.end());
  int max = b.at(n-1);
  
  int k;
  for (int i = 0; i < n; i++) {
    if (max == a.at(i)){
      k = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == k) cout << b.at(n-2) << endl;
    else cout << max << endl; 
  }
}

Measured memory_bytes: 3200
#include "bits/stdc++.h"

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

#define mod 1000000007

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int N,R;
	cin >> N >>R;

	if (N >= 10)print(R);
	else print(R + 100 * (10 - N));
	
	
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>

using namespace std;

int main()
{
	int N, K;
	string S;
	cin >> N >> K >> S;
	
	S[K-1] = S[K-1] + 32;
	
	cout <<S << endl;
	
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
// disco2020A.cpp :

#include <iostream>
using namespace std;

int main()
{
	int X, Y;
	cin >> X >> Y;
	int prize = 0;
	if (X==3)
	{
		prize += 100000;
	}
	if (Y == 3) {
		prize += 100000;
	}
	if (X==2)
	{
		prize += 200000;
	}
	if (Y==2)
	{
		prize += 200000;
	}
	if (X==1)
	{
		prize += 300000;
	}
	if (Y==1)
	{
		prize += 300000;
	}
	if (X == 1 && Y == 1) {
		prize = 1000000;
	}
	cout << prize << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int N, c[100], t[100], T, i, min = 1001;

	scanf("%d %d", &N, &T);
	for (i = 0; i < N; i++) {
		scanf("%d %d", &c[i], &t[i]);
		if (t[i] <= T && c[i] < min) {
			min = c[i];
		}
	}
	
	if (min == 1001) {
		printf("TLE");
	}
	else {
		printf("%d", min);
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v1(n + 1, 1), v2(n + 1, 0);
    v2[1] = 1;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if (v2[a] == 1) {
            v2[b] = 1;
        }
        if (v1[a] == 1) {
            v2[a] = 0;
        } 
        v1[a]--;
        v1[b]++;
    }
    cout << accumulate(v2.begin(), v2.end(), 0) << endl;
}




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

int main() {
  string s, t;
  cin >> s >> t;
  int res = 0;
  rep(i,s.size()) {
    res += s[i] != t[i];
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3916
#!/usr/bin/env python3
import sys
import numpy as np


def solve(A: int, B: int):
    if A-2*B<0:
        print(0)
    else:
        print(A-2*B)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20004
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	cout << ((N - M) * 100 + M * 1900)*(long long int)pow(2, M) << endl;
	return 0;
}

Measured memory_bytes: 256
program example
	implicit none

	character(15) S
    integer :: i=1,j,wa=0,k
    
    read(*,*) S
    
    k=len_trim(adjustl(S))
    
    do
    	if (i>k) then
        	exit
        end if
        
    	j=index(S(i:),"o")
        
    	if(j/=0) then
        	wa=wa+1
            i=i+j
        else
        	i=i+1
        end if
    end do
    
    if(wa>=8) then
    	write(*,*) "YES"

	else
    	if((15-k)+wa>=8) then
        	write(*,*) "YES"
    	else
        	write(*,*) "NO"
        end if
    end if
end program example

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>

using namespace std;  //このネームスペースを使う

int main(){
  int A;
  cin >> A ;
  
  if(A < 1000){
  	cout << "ABC" << endl;
  }
  else{
  	cout << "ABD" << endl;
  }

  
  return 0;
}



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

int main(){
    int N; cin >> N;
    int count_0 = 0, count_m = 0;
    vector<int> A(N);

    for(int i = 0; i < N; i++){
        int a; cin >> a;
        if(a == 0) count_0++;
        if(a < 0) count_m++;
        A[i] = abs(a);
    }

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

    ll sum = 0;
    if(count_m % 2 == 0 || count_0 != 0){
        for(auto a : A){
            sum += a;
        }
    }else{
        sum -= A[0];
        for(int i = 1; i < N; i++){
            sum += A[i];
        }
    }

    cout << sum << endl;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main() {
    ll n;
    cin >> n;
    vi h(n);
    rep(i, n) { cin >> h[i]; }

    int ans = 0;
    while (true) {
        // すべての花の高さを揃え終わったら終了
        if (count(all(h), 0) == n) break;
        // 調べる段の最初から
        int i = 0;
        while (i < n) {
            // 0ならば次の区間へ進む
            if (h[i] == 0) {
                i++;
            }
            // カウントする区間の開始
            else {
                ans++;
                while (i < n && h[i] > 0) {
                    h[i]--;
                    i++;
                }
                // カウントする区間の終了
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
s = np.array(list(input()))
t = np.array(list(input()))
dp = np.zeros((len(s)+1, len(t)+1), dtype=int)

equal = s[:, None] == t[None, :]

for i in range(len(s)):
    dp[i+1, 1:] = np.maximum(dp[i, :-1]+equal[i], dp[i, 1:])
    dp[i+1] = np.maximum.accumulate(dp[i+1])

i = len(s)
j = len(t)
ans = []

while i>0 and j>0:
    if s[i-1] == t[j-1]:
        ans.append(s[i-1])
        i -= 1
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else :
        j -= 1

print(''.join(ans[::-1]))


Measured memory_bytes: 106036
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A2 solver = new A2();
        solver.solve(1, in, out);
        out.close();
    }

    static class A2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int[] start = new int[n];
            int[] goal = new int[n];
            for (int i = 0; i < m; i++) {
                int a = Integer.parseInt(in.next()) - 1;
                int b = Integer.parseInt(in.next()) - 1;
                if (a == 0) {
                    start[b] = 1;
                } else if (b == (n - 1)) {
                    goal[a] = 1;
                }
            }
            boolean ok = false;
            for (int i = 0; i < n; i++) {
                if (start[i] >= 1 && goal[i] >= 1) ok = true;
            }
            out.println(ok ? "POSSIBLE" : "IMPOSSIBLE");

        }

    }
}



Measured memory_bytes: 65892
N = int(input())
A = [list(map(lambda x: int(x) - 1, input().split())) + [-1] for i in range(N)]

ans = 0
matched = 0
marker = [0] * N
que = list(range(N))

while matched < N * (N - 1) // 2:
    already_matched = set()
    next_que = []

    while que:
        player = que.pop()
        partner = A[player][marker[player]]

        if A[partner][marker[partner]] == player:
            if not ((player not in already_matched) and (partner not in already_matched)):
                continue

            matched += 1

            marker[player] += 1
            marker[partner] += 1

            already_matched.add(player)
            already_matched.add(partner)

            next_que.append(player)
            next_que.append(partner)

    if not next_que:
        print(-1)
        break

    ans += 1
    que = next_que[:]

else:
    print(ans)


Measured memory_bytes: 55388
#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 <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)
#define MOD 1000000007
int main() {
	string str;
	cin >> str;
	
	int a = (str[0] - '0') * 10 + (str[1] - '0');
	int b = (str[2] - '0') * 10 + (str[3] - '0');
	bool fa = false, fb = false;
	if (1 <= a && a <= 12)fa = true;
	if (1 <= b && b <= 12)fb = true;
	if (fa && fb)cout << "AMBIGUOUS" << endl;
	else if (fa)cout << "MMYY" << endl;
	else if (fb)cout << "YYMM" << endl;
	else cout << "NA" << endl;
	return 0;
}

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

const int N = 2e5+5 , INF = 20000;

int n  , m  , a , b ;
vector<pair<int,int> > v;
long long sol;

int main() {

    cin>>n>>m;
    for(int i = 0;i<n;i++)
    {
        cin>>a>>b;
        v.push_back({-b , a});
    }
    sort(v.begin() , v.end());
    int now = 0;
    set<int> s;
    for(int i = 0;i<m;i++)
        s.insert(i);
    for(int i = 0;i<n;i++)
    {
        auto it = s.lower_bound( m-v[i].second );

        if( it==s.end() ||  *it!= m-v[i].second )
        {
            if(it!=s.begin())
            {
                it--;
                s.erase( it );
                sol-=v[i].first;
            }
        }
        else{
            s.erase( it );
            sol-=v[i].first;
        }
    }
    cout<<sol;
    return 0;
}



Measured memory_bytes: 5748
#coding:utf-8
import bisect
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True



def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, t = LMIIS()
    ab = XLMIIS(n)

    dp1 = [[0]*t for _ in range(n)]
    for i in range(1, n):
        for j in range(1, t):
            if j < ab[i-1][0]:
                dp1[i][j] = dp1[i-1][j]
            else:
                dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-ab[i-1][0]] + ab[i-1][1])


    dp2 = [[0]*t for _ in range(n)]
    for i in range(1, n):
        for j in range(1, t):
            if j < ab[n - i][0]:
                dp2[i][j] = dp2[i-1][j]
            else:
                dp2[i][j] = max(dp2[i-1][j], dp2[i-1][j-ab[n-i][0]] + ab[n-i][1])

    ans = 0
    for i in range(n):
        for j in range(t - 1):
            ans = max(ans, dp1[i][j] + dp2[n - i - 1][t - j - 1] + ab[i][1])
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 176904
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL n;cin>>n;

    for(LL nn=1;nn<=n;nn++){
        LL result = 0;
        for(LL x=1; (x*x + 1 + 1 + x + 1 + x) <= nn; x++){
            for(LL y=1; (x*x + y*y + 1 + x*y + y + x) <= nn; y++){
                for(LL z=1; (x*x + y*y + z*z + x*y + y*z + z*x) <= nn; z++){
                    if((x*x + y*y + z*z + x*y + y*z + z*x) == nn){
                        //cerr<<x<<" "<<y<<" "<<z<<endl;
                        result++;
                    }
                }
            }
        }
        cout<<result<<endl;

    }
    
	return;
}

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

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <time.h>
#include <ctime>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int d, c[28], s[370][28], t[370], b[370][28];

int score() {
    int i, j, ans;

    for (i = 0; i < 26; i++) {
        b[0][i] = 1;
    }

    ans = 0;
    for (i = 0; i < d; i++) {
        ans += s[i][t[i]];
        b[i][t[i]] = 0;
        for (j = 0; j < 26; j++) {
            ans -= c[j] * b[i][j];
            b[i + 1][j] = b[i][j] + 1;
        }
    }

    return ans;
}

int delta(int chd, int cht) {
    int i, res;

    res = s[chd][cht] - s[chd][t[chd]];

    i = chd + 1;
    while (i < d && t[i] != t[chd]) {
        i++;
    }

    if (chd == 0) {
        res -= (i - chd) * c[t[chd]];
    }
    else {
        res -= (b[chd - 1][t[chd]] + 1) * (i - chd) * c[t[chd]];
    }

    i = chd;
    while (i < d && t[i] != cht) {
        i++;
    }

    res += b[chd][cht] * (i - chd) * c[cht];

    return res;
}

void change(int chd, int cht) {
    int i;

    i = chd;
    while (i < d && (i == chd || t[i] != t[chd])) {
        if (chd == 0) {
            b[i][t[chd]] = i + 1;
        }
        else {
            b[i][t[chd]] = b[i - 1][t[chd]] + 1;
        }
        i++;
    }

    i = chd;
    while (i < d && t[i] != cht) {
        b[i][cht] = i - chd;
        i++;
    }

    t[chd] = cht;
}

int main(void) {
    int i, j;

    clock_t start = clock(), end;
    double rtime;

    scanf("%d", &d);
    for (i = 0; i < 26; i++) {
        scanf("%d", &c[i]);
    }
    for (i = 0; i < d; i++) for (j = 0; j < 26; j++) {
        scanf("%d", &s[i][j]);
    }

    int scmax, scmi;

    for (i = 0; i < d; i++) {
        scmax = 0;
        scmi = 0;
        for (j = 0; j < 26; j++) {
            if (scmax < s[i][j]) {
                scmax = s[i][j];
                scmi = j;
            }
        }
        t[i] = scmi;
    }

    int before = score(), after, chd, cht;

    srand(time(nullptr));

    while (1) {
        end = clock();
        rtime = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
        if (rtime > 1950) {
            break;
        }

        chd = rand() % d;
        cht = rand() % 26;

        while (t[chd] == cht) {
            cht = rand() % 26;
        }

        after = before + delta(chd, cht);

        if (after > before) {
            change(chd, cht);
            before = after;
        }
    }

    for (i = 0; i < d; i++) {
        printf("%d\n", t[i] + 1);
    }
    
    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/27  Problem: ABC 115 D / Link: http://abc115.contest.atcoder.jp/tasks/abc115_d  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	VL lsum(100);
	VL lPsum(100);
	lsum[0] = 1;
	lPsum[0] = 1;
	FOR(i, 1, 51) {
		lsum[i] = 1 + lsum[i - 1] + 1 + lsum[i - 1] + 1;
		lPsum[i] = 0 + lPsum[i - 1] + 1 + lPsum[i - 1] + 0;
	}
	LL N, X; cin >> N >> X;
	function<LL(int, LL&)> dfs = [&](int LV, LL &leftX) {
		LL Pcnt = 0;
		if (leftX > 0) {// B
			leftX--;
		}
		if (leftX > 0) { // block
			if (leftX >= lsum[LV-1]) {
				Pcnt += lPsum[LV-1];
				leftX -= lsum[LV-1];
			}
			else {
				Pcnt += dfs(LV - 1, leftX);
			}
		}
		if (leftX > 0) { // P
			Pcnt++;
			leftX--;
		}
		if (leftX > 0) { // block
			if (leftX >= lsum[LV-1]) {
				Pcnt += lPsum[LV-1];
				leftX -= lsum[LV-1];
			}
			else {
				Pcnt += dfs(LV - 1, leftX);
			}
		}
		if (leftX > 0) {// B
			leftX--;
		}

		return Pcnt;
	};

	ans = dfs(N, X);
	cout << ans << "\n";

	return 0;
}


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

int main(){
	int H, W;
	while(1){
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		for(int y = 0; y < H; y++){
			for(int x = 0; x < W; x++){
				if(y % 2 == 0){
					if(x % 2 == 0) cout << "#";
					else cout << ".";
				}
				else{
					if(x % 2 == 0) cout << ".";
					else cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3100
N, M = gets.split.map(&:to_i)
UVs = M.times.map{gets.split.map(&:to_i)}
S, T = gets.split.map(&:to_i)

g = UVs.each_with_object(Hash.new{|h, k| h[k] = []}) do |(u, v), h|
  h[u] << v + N
  h[u + N] << v + 2*N
  h[u + 2*N] << v
end
q = [S]
f = []
while !q.empty?
  x = q.shift
  g[x].each do |y|
    if y == T
      c, z = 1, x
      until z == S do
        z = f[z]
        c += 1
      end
      puts c / 3
      exit
    elsif f[y].nil?
      f[y] = x
      q << y
    end
  end
end
puts -1

Measured memory_bytes: 41596
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
 
using namespace std;
 
const int MAXN = 16;

int N;
int nr[MAXN];
int honest[MAXN][MAXN];
int who[MAXN][MAXN];

bool isHonest[MAXN];

int ans = -1;

int checkSol() {
    int cnt = 0;

    bool maybeHonest[MAXN];
    bool assumed[MAXN];
    for (int i = 1; i <= N; i++) {
        maybeHonest[i] = true;
        assumed[i] = false;
        cnt += isHonest[i];
    }

    for (int i = 1; i <= N; i++) {
        if (isHonest[i]) {
            for (int j = 1; j <= nr[i]; j++) {
                int target = who[i][j];
                int is = honest[i][j];
                if (!is && isHonest[target] || (is && !isHonest[target])) return 0;
                if (assumed[target]) {
                    if (is != maybeHonest[target]) return 0;
                } else {
                    assumed[target] = true;
                    maybeHonest[target] = is;
                }

            }
        }
    }

    // for (int i = 0; i <= N; i++) if (isHonest[i]) cout << i << " ";
    // cout << endl;
    return cnt;

}

void backtrack(int step) {
    if (step > N) {

        ans = max(ans, checkSol());
        return ;
    }

    isHonest[step] = true;
    backtrack(step + 1);
    isHonest[step] = false;
    backtrack(step + 1);
}

int main() {

    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> nr[i];
        for (int j = 1; j <= nr[i]; j++) {
            cin >> who[i][j] >> honest[i][j];
        }
    }

    backtrack(1);

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EDGE
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            HashSet<Integer> hs = new HashSet<>();

            for (int i = 1; i <= 9; i++) {
                for (int j = 1; j <= 9; j++) {
                    if (!hs.contains(i * j))
                        hs.add(i * j);
                }
            }


            if (!hs.contains(n))
                out.println("No");
            else
                out.println("Yes");
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22740
#include <iostream>
#include<string>
#include<cmath>
#include<vector>
using std::cin;
using std::cout;
using std::vector;
int prime(int n)
{
	int flag=0,i,j;
	for(i=n;;i++)
	{
		flag=1;
		for(j=2;j*j<=n;j++)
		{
			if(i%j==0){
				flag=0;
				break;
			}
		}
		if(1==flag)
			break;
	}
	return i;
}
int main(){
	int n;
	cin>>n;
	cout<<prime(n);
	return 0;
}
			


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

const int N=1e6;
int INF=0x3f3f3f3f;
int a[N];
//memset(a,0x3f,sizeof(a));


int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	if(n>=0) cout<<a[n];
	for(int i=n-2;i>=1;i-=2){
		cout<<" "<<a[i];
	}
	if(n%2==0){
		for(int i=1;i<=n;i+=2){
		cout<<" "<<a[i];
		}
	}
	else{
		for(int i=2;i<=n;i+=2){
			cout<<" "<<a[i];
		}
	}
	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
using P = pair<int, int>;
int h, w, n, a, b, ans[11];
map<P,int> m;
int main(){
	scanf("%d%d%d", &h, &w, &n);
	rep(i,n){
		scanf("%d%d", &a, &b);
		rep(j,3) rep(k,3) if(3<=a+j && a+j<=h && 3<=b+k && b+k<=w) ans[m[P(a+j,b+k)]++]++;
	}
	printf("%lld\n", 1LL*(h-2)*(w-2)-ans[0]);
	rep(i,9) printf("%d\n", ans[i]-ans[i+1]);
}

Measured memory_bytes: 56448
S = input()
N = len(S)
L = [0 for i in range(N + 1)]
R = [0 for i in range(N + 1)]

t = 'ACGT'

cnt = 0
for i in range(N):
    if S[i] in t:
        cnt += 1
    else:
        cnt = 0
    L[i] = cnt
cnt = 0
for i in range(N - 1, -1, -1):
    if S[i] in t:
        cnt += 1
    else:
        cnt = 0
    R[i] = cnt

ans = L[0]
for i in range(1, N):
    ans = max(ans, L[i - 1] + R[i])

print(ans)




Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string S, T;
int main() {
	cin >> S >> T;
	if (S.size() >= T.size()) {
		for (int i = 0; i <= S.size() - T.size(); i++) {
			if (T == S.substr(i, T.size())) {
				printf("%d\n",i);
			}
		}
	}
}

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

int main(void) {
  char c[1011];
  int i;
  fgets(c, 1001, stdin);
  for(i = 0; i < strlen(c); ++i) {
    if(c[i] == 'a' && c[i + 1] == 'p' && c[i + 2] == 'p' && c[i + 3] == 'l' && c[i + 4] == 'e') 
      c[i] = 'p', c[i + 1] = 'e', c[i + 2] = 'a', c[i + 3] = 'c', c[i + 4] = 'h', i += 4;
    if(c[i] == 'p'&& c[i + 1] == 'e' && c[i + 2] == 'a' && c[i + 3] == 'c' && c[i + 4] == 'h') 
      c[i] = 'a', c[i + 1] = 'p', c[i + 2] = 'p', c[i + 3] = 'l', c[i + 4] = 'e', i += 4;
  }
  printf("%s", c);
  return 0;
}


Measured memory_bytes: 2492
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

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

  string s;
  cin >> s;

  vector<int> a(s.size()+1, 0);
  rep (i,s.size())   if(s[i] == '<') a[i+1] = max(a[i+1], a[i]+1);
  rrep(i,s.size(),0) if(s[i] == '>') a[i]   = max(a[i], a[i+1]+1);

  int64_t res = 0;
  rep(i,s.size()+1) res += a[i];

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2844
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
using namespace std ;
#define ll long long int
int main()
{

    ll n , m ;
    cin>>n>>m ;
    vector<vector<ll>>graph(n) ;
   ll check[n] ;
    memset(check , -1 ,sizeof(check)) ;

    for(ll i =0;i< m;i++ )
    {

        ll a , b  ;
        cin>>a>>b ;
        a-- ;
        b-- ;
        graph[a].push_back(b) ;
        graph[b].push_back(a) ;

    }

    queue<ll>arr ;

    arr.push(0) ;

    check[0]  =  0 ;
    while(!arr.empty())
    {

    ll tr= arr.front() ;
    arr.pop() ;
    for(auto i : graph[tr])
    {

        if(check[i]!=-1)
            continue ;

        arr.push(i) ;
        check[i] =tr ;



    }




    }

    ll flag = 1 ;
    for(auto i :  check )
    {

        if(i==-1 )
        {

            flag = 0 ;
            break ;
        }
    }
    if(flag ==1)
    {

        cout<<"Yes"<<endl ;

      for(int i = 1 ;i< n ;i++)
        cout<< check[i]+1<<endl ; 
      cout<<endl ;
    }else
    cout<<"No"<<endl ;


}


Measured memory_bytes: 12988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	vector<int> c(m);
	rep(i,m){
		cin >> a.at(i) >> b.at(i) >> c.at(i);
		a.at(i)--;
		b.at(i)--;
	}
	int MAX=1000000000;
	vector<vector<int>> dist(n,vector<int>(n));
	rep(i,n){
		rep(j,n){
			dist[i][j]=MAX;
		}
		dist[i][i]=0;
	}
	rep(i,m){
		dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
		dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
	}
	rep(k,n){
		rep(i,n){
			rep(j,n){
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	
	int ans=0;
	rep(i,m){
		if(dist[a[i]][b[i]]<c[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n/2);
    vector<int> b(n/2);
    rep(i, n) {
        if (i%2==0) cin >> a[i/2];
        else cin >> b[i/2];
    }
    map<int, int> ma;
    map<int, int> mb;
    int x1 = 0, y1 = 0;
    int x2 = 0, y2 = 0;
    rep(i, n/2) {
        ma[a[i]]++;
        mb[b[i]]++;
    }
    vector<P> va;
    vector<P> vb;
    for(auto m: ma) {
        va.push_back(m);
    }
    for (auto m: mb) {
        vb.push_back(m);
    }
    auto comp = [](P a, P b) {
        return a.second>b.second;
    };
    sort(whole(va), comp);
    sort(whole(vb), comp);
    int ans = 0;
    if (va[0].first!=vb[0].first) {
        ans = n - va[0].second - vb[0].second;
    }
    else {
        if (va.size()==1 && vb.size()==1) ans = n/2;
        else if (va.size()==1) {
            ans = n - va[0].second - vb[1].second;
        }
        else if (vb.size()==1) {
            ans = n - va[1].second - vb[0].second;
        }
        else {
            ans = n - va[0].second - vb[1].second;
            chmin(ans, n - va[1].second - vb[0].second);
        }
    }

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


Measured memory_bytes: 6520
n = int(input())
a = list(map(int, input().split()))

color = [False for _ in range(8)]
wild = 0
for i in a:
    if i < 3200:
        color[i // 400] = True
    else:
        wild += 1

mini = 0
for i in color:
    if i:
        mini += 1
if mini == 0:
    mini = 1
    maxi = wild
else:
    maxi = mini + wild
print(mini, maxi)


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>

using namespace std;

int main(void)
{
    long long num;
    long long product;
    int p_count;

    cin >> num >> product;

    if(num == 1){
        cout << product << endl;
        return 0;
    }

    long long common_divisor = 1;

    for(long long p = 2; p * p <= product; p++){
        p_count = 0;
        while(product % p == 0){
            product /= p;
            p_count = p_count + 1;
            if(p_count >= num){
                common_divisor *= p;
                p_count = 0;
            }
        }

    }

    cout << common_divisor << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int h, w; cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin>>s[i];

    //for(int i=0; i<h; i++) cout << s[i] << endl;

    ll ans=0;
    vector<vector<bool>> visited(h, vector<bool>(w, false));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            ll numb=0, numw=0;
            if(s[i][j]=='#'){
                
                numb++;
                visited[i][j]=true;
                queue<T> que;
                que.push(T(i, j, 1));
                while(que.size()){
                    T t=que.front(); que.pop();
                    ll cy, cx, ccost;
                    tie(cy, cx, ccost)=t;
                    //cout << cy << " " << cx << " " << ccost << endl;
            
                    for(int i=0; i<4; i++){
                        int ny=cy+dy[i], nx=cx+dx[i];
                        if(0<=ny && ny<h && 0<=nx && nx<w){
                            if(ccost%2==1 && s[ny][nx]=='.' && visited[ny][nx]==false){ // white
                                numw++;
                                visited[ny][nx]=true;
                                que.push(T(ny, nx, ccost+1));
                            }

                            if(ccost%2==0 && s[ny][nx]=='#' && visited[ny][nx]==false){ // black
                                numb++;
                                visited[ny][nx]=true;
                                que.push(T(ny, nx, ccost+1));
                            }
                        }
                    }
                }
            }
            ans+=numb*numw;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
/*Mrc01*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#define ll long long 
#define ull unsigned long long 
#define f(i,x,n) for(ll int i=x;i<n;i++) 
#define re(j,x,n) for(ll int j=x;j>=n;j--)
#define f1(k,x,n) for(ll int k=x;k<=n;k++)
#define mp make_pair
#define pb push_back
#define bit(x, i) (x >>(i - 1) & 1ll)
#define MAX 1000001
const int mod=1000000007;
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<ll int,ll int>,null_type, less<pair<ll int,ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
      new_data_set; 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int n;
     cin>>n;
    if(ceil((double(sqrt(n))))==floor((double(sqrt(n)))))
    {
      cout<<n;
    }
    else
    { 
      ll int temp=sqrt(n);
      cout<<temp*temp;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
from bisect import bisect_left
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = [0] + LIST()

acc = list(accumulate(A))
mid = sum(A) / 2
l = bisect_left(acc, mid) - 1
r = bisect_left(acc, mid)
l = acc[l]
r = acc[r]
print(int(min(mid-l, r-mid)*2))


Measured memory_bytes: 25916
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string s = to_string(N);
    bool f = true;
    rep(i, 1, s.size()) {
        if (s[i] == '9') continue;
        f = false;
    }
    if (f) {
        cout << (s[0] - '0') + (s.size() - 1) * 9;
        return 0;
    }
    int ans2 = s[0] - '0' - 1 + (s.size() - 1) * 9;
    cout << ans2 << endl;

    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000

using namespace std;

#define MAXN 999999

int tetrahedrons[MAXN];
int triangles[MAXN];

int dp[MAXN];
int odp[MAXN];

int main(){
  rep1(i, MAXN-1){
    triangles[i] = triangles[i-1] + i;
    tetrahedrons[i] = triangles[i] + tetrahedrons[i-1];
  }

  rep(i, MAXN)dp[i]=INF;
  dp[0]=0;
  rep(i, 2000){
    rep1(j, MAXN){
      int c = tetrahedrons[i];

      if(j-c>=0)dp[j] = min<ll>(dp[j], dp[j-c]+1);
    }
  }

  rep(i, MAXN)odp[i]=INF;
  odp[0]=0;
  rep(i, 2000){
    rep1(j, MAXN){
      int c = tetrahedrons[i];
      if(c%2==0)continue;

      if(j-c>=0)odp[j] = min<ll>(odp[j], odp[j-c]+1);
    }
  }

  while(true){
    int n;cin>>n;
    if(n==0)break;

    cout<<dp[n]<<' '<<odp[n]<<endl;

  }

  return 0;
}



Measured memory_bytes: 18620