akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;


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

    
    ll rc, gc, bc;
    rc = gc = bc = 0;

    for(ll i = 0;i < n;i++){
        if(s[i] == 'R'){
            rc++;
        }
        else if(s[i] == 'G'){
            gc++;
        }
        else{
            bc++;
        }
    }

    ll ans = rc * bc * gc;

    for(ll i = 1;i < n;i++){
        for(ll j = 0;j < n;j++){
            if(j + i * 2 < n){
                if(s[j] != s[j + i] && s[j + i] != s[j + i * 2] && s[j] != s[j + i * 2]){
                    ans--;
                }
            }
            else{
                break;
            }
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string.h>
#include <stdio.h>

using namespace std;

const int MAX_R = 10, MAX_C = 10000;
int osenbei[MAX_R][MAX_C];
int tosenbei[MAX_R][MAX_C];
int R, C;
int A;

void dfs(int depth, int turn){
    if(depth == R){
        int a = 0;
        memcpy(tosenbei, osenbei, sizeof(osenbei));
        for(int i=0; i<R; i++){
            if(turn & 1<<i){
                int *row = tosenbei[i];
                for(int j=0; j<C; j++)
                    row[j] ^= 1;
            }
        }
        for(int i=0; i<C; i++){
            int s = 0;
            for(int j=0; j<R; j++)
                s += tosenbei[j][i];
            a += max(s, R-s);
        }
        A = max(a, A);
    }else{
        dfs(depth + 1, turn);
        dfs(depth + 1, turn ^ (1<<depth));
    }
}

void solve(){
    A = 0;
    dfs(0, 0);
    cout << A << endl;
}

int main(){
    while(scanf("%d %d", &R, &C), R|C){
        for(int i=0; i<R; i++)
            for(int j=0; j<C; j++)
                scanf("%d", &osenbei[i][j]);
        solve();
    }
    return 0;
}

Measured memory_bytes: 1988
n = int(input())
five = 0
two = 0

if n % 2 == 1:
  print(0)
  exit()

x = 2
while x <= n:
  two += n // x
  x *= 2

x = 5
while x*2 <= n:
  five += n // (x*2)
  x *= 5

print(min(two, five))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
	unsigned short a,b;
	string s,t,u;
	cin>>s>>t>>a>>b>>u;
	if(s==u){
		cout<<(a-1)<<" "<<b;
	}
	else{
		cout<<a<<" "<<(b-1);
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*(n+1)+(j))

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int64 *dp=(int64 *)calloc((n+1)*(n+1),sizeof(int64));
  for(int len=2;len<=n;len++){
    for(i=0;i<=n-len;i++){
      int64 sum=0;
      int j;
      for(j=i;j<i+len;j++) sum+=a[j];
      int64 local=dp[POS(i,1)]+dp[POS(i+1,len-1)];
      for(j=2;j<len;j++) local=MIN(local,dp[POS(i,j)]+dp[POS(i+j,len-j)]);
      dp[POS(i,len)]=local+sum;
    }
  }
  printf("%lld\n",dp[POS(0,n)]);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

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

  int count = 0;

  for (int i = 0; i<n; i++){
    int tmp1, tmp2;
    double dist;
    cin >> tmp1 >> tmp2;
    dist = sqrt(pow(tmp1, 2) + pow(tmp2, 2));
    if (dist <=d){
      count +=1;
    }
  }

  cout << count << endl;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[] = new long[N];
		for(int i = 0 ; i < A.length ; ++i){
			A[i] = sc.nextLong();
		}
		int bs[] = new int[61];
		for(int i = 0 ; i < A.length ; ++i){
			long a = A[i];
			for(int b = 0 ; b < bs.length ; ++b){
				if((a & (1L << b)) != 0){
					bs[b]++;
				}
			}			
		}
//		System.out.println(Arrays.toString(bs));
		long S = 0;
		long MOD = 1000000007L;
		for(int b = 0 ; b < bs.length ; ++b){
			long B1 = bs[b];
			long B0 = N - bs[b];
			long BN = (B0 * B1) % MOD; 
			BN = (BN * ((1L << b) % MOD) ) % MOD;
			S = (S + BN) % MOD;
//			System.out.println(BN);
		}
		System.out.println(S);
		/*
		for(int i = 0 ; i < A.length ; ++i){
			for(int j = 0 ; j < A.length ; ++j){
				System.out.println(Long.toBinaryString(A[i] ^ A[j]));
			}
			System.out.println();
		}
		*/
	}
}


Measured memory_bytes: 97648
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
const int maxn = 1e5+7;
int n;
long long m;
long long a[maxn];
long long sum[maxn];
long long test(int x)
{
    long long ret = 0;
    int p1 = 1;
    int p2 = n;
    for(;p2>=p1;--p2)
    {
        while(p1 <= p2 && a[p1] + a[p2] < x)
            p1++;
        if(p1 > p2)
        {
            break;
        }
        ret += (p2-p1+1)*2 - 1 ;
    }
    return ret;
}
long long count(int x)
{
    long long ret = 0;
    int p1 = 1;
    int p2 = n;
    for(;p2>=p1;--p2)
    {
        while(p1 <= p2 && a[p1] + a[p2] < x)
            p1++;
        if(p1 > p2)
        {
            break;
        }
        ret += (sum[p2-1]-sum[p1-1]) * 2 + a[p2] * (p2-p1+1)*2 ;
    }
    return ret;
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;++i)cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=n;++i)sum[i]=a[i]+sum[i-1];
    int l = 0, r = 2e5;
    while(l<r)
    {
        int mid = (l+r)/2;
        if(test(mid) <= m)
        {
            r = mid;
        }else 
        {
            l = mid + 1;
        }
    }
    if(test(l) < m)
    {
        l--;
    }
    long long ans = count(l);
    if(test(l) > m)
    {
        ans -= l * (test(l) - m);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
function Main(input) {
  	inputArr = input.split("\n");
	var n = parseInt(inputArr[0], 10);
	var d = inputArr[1].split(" ");
    var dd = 
        d.map(function (value) {
      		return parseInt(value, 10);
    	}).sort(function(a,b){
        	if( a < b ) return -1;
       	 	if( a > b ) return 1;
        	return 0;
		});

    var center = dd.length / 2;
    console.log(dd[center] - dd[center - 1]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#ifdef DONLINE_JUDGE
//freopen("a.in", "r", stdin);
//freopen("a.out","w",stdout); // console output is better (in most cases)
#else
// add i/o method of specific testing system
#endif

using namespace std;

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

    int m, n;
    while (cin >> m >> n, m || n)
    {
        for (int i = 0; i < m; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3132
A, B, C, D, E, F = [int(x) for x in input().split()]
a_water = 0
a_sugar = 0
a_conc = 0
max_conc = 100 * E / (100 + E)
for i in range(F//(100*A) + 1):
    for j in range((F-i*100*A)//(100*B) + 1):
        water = i * 100 * A + j * 100 * B
        if water == 0:
            continue
        for k in range((F-water)//C + 1):
            for l in range((F-water-C*k)//D + 1):
                sugar = k * C + l * D
                conc = 100 * sugar / (water + sugar) if water + sugar > 0 else 0
                if water + sugar <= F and conc <= max_conc and a_conc <= conc:
                    a_water = water
                    a_sugar = sugar
                    a_conc = conc
                else:
                    pass
print(a_water + a_sugar, a_sugar)


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

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 h, w;
    cin >> h >> w;

    vector<vector<i64>> m(h, vector<i64>(w, -1));
    queue<p64> q;
    for (i64 i = 0; i < h; i++) {
        for (i64 j = 0; j < w; j++) {
            char c;
            cin >> c;
            if (c == '#') {
                m[i][j] = 0;
                q.emplace(i, j);
            }
        }
    }

    i64 ans = 0;
    vector<i64> dxy { 0, 1, 0, -1, 0 };
    while (!q.empty()) {
        i64 y, x;
        tie(y, x) = q.front(); q.pop();

        for (i64 i = 0; i < 4; i++) {
            i64 ny = y + dxy[i], nx = x + dxy[i + 1];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if (m[ny][nx] != -1) continue;
            m[ny][nx] = m[y][x] + 1;
            ans = max(ans, m[ny][nx]);
            q.emplace(ny, nx);
        }
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 24500
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

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

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// 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 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())

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

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

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

void solve(long long N, long long A, long long B, long long C, long long D,
           long long E) {
  vector<long long> arr;
  arr.PB(A);
  arr.PB(B);
  arr.PB(C);
  arr.PB(D);
  arr.PB(E);
  SORT(arr);
  LL minimum = arr[0];
  LL blocks =N / minimum;
    if(N % minimum != 0){
      blocks++;
    }
  long long ans = blocks+4;
  cout<<ans<<endl;

           }

int main() {
  long long N;
  scanf("%lld", &N);
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  long long D;
  scanf("%lld", &D);
  long long E;
  scanf("%lld", &E);
  solve(N, A, B, C, D, E);
  return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int H, N, A[100100];

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

  std::cin >> H >> N;

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

  if(std::accumulate(A, A + N, 0) >= H){
      std::cout << "Yes" << std::endl;
  }else{
      std::cout << "No" << std::endl;
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#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(void)
{
    string s;
    cin >> s;

    if(s.back()=='s'){
        cout << s << "es" << endl;
    }else{
        cout << s << "s" << endl;
    }

    return 0;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int N;
string S[101];
int P[101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> S[i] >> P[i];

	vector<int> ans;
	rep(i, 0, N) ans.push_back(i);
	sort(all(ans), [&](int a, int b) {
		if (S[a] != S[b]) return S[a] < S[b];
		return P[a] > P[b];
	});

	fore(i, ans) cout << (i + 1) << endl;
}















Measured memory_bytes: 256
from sys import stdin
# stdin = open("testdata.txt", "r")

def input():
	return stdin.readline().strip()

from collections import defaultdict, deque

R, C = map(int, input().split())

grid = [None]*R

for i in range(R):
	temp = input()
	grid[i] = temp

def get_neighs(r, c):
	is_valid = lambda x, y: 0 <= x < R and 0 <= y < C and grid[x][y]=='.'
	dr = [-1, 0, 1, 0]
	dc = [0, 1, 0, -1]
	return [(r+dr[i], c+dc[i]) for i in range(4) if is_valid(r+dr[i], c+dc[i])]


def get_max(r0, c0):
	visited = {(r0, c0),}
	dq = deque()
	dq.append((r0, c0, 0))
	max_steps = 0
	while dq:
		r, c, steps = dq.popleft()
		max_steps = max(max_steps, steps)
		for _r, _c in get_neighs(r, c):
			if (_r, _c) not in visited:
				dq.append((_r, _c, steps+1))
				visited.add((_r, _c))
	return max_steps

ans = 0
for r in range(R):
	for c in range(C):
		if grid[r][c]=='.':
			ans = max(get_max(r, c), ans)
print(ans)

Measured memory_bytes: 61020
function main(input) {
    const nums = input.split(" ");
    var count5 = 0, count7 = 0;
    
    nums.forEach( num => {
        if(num == 5) {
            count5 += 1;
        }
        if(num == 7) {
            count7 += 1;
        }
    })
    console.log(count5 == 2 && count7 == 1 ? "YES" : "NO");
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int digsum (int n) {
  int cnt = 0;
  while(n) {
    cnt += n % 10;
    n /= 10;
  }
  return cnt;
}

int main() {
  int n,a,b,sum;
  int ans= 0;
  cin >> n >> a >> b;
  
  for (int i = 1; i <= n; i++) {
    if (a <= digsum(i) && digsum(i) <= b) {
      ans += i;      
    }
  }  
  cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
char s[1000];
char t[1000];
int l;
int main()
{
	cin>>s+1;
	cin>>t+1;
	l=strlen(s+1);
	for(int i=1;i<=l;i++)s[i+l]=s[i];
	for(int i=1;i<=l;i++)
	{
		for(int j=1;j<=l;j++)
		{
			if(s[j+i-1]!=t[j])goto v;
		}
		cout<<"Yes"<<endl;
		return 0;
		v:;
	}
	cout<<"No";
	return 0;
}

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

int8_t main(void) {
    uint8_t buffer[11], max_acgt_len = 0, cur_acgt_len = 0;
    if (fgets(buffer, 11, stdin) != NULL) {
        for (uint8_t i = 0; i < strlen(buffer); i++) {
            if ((strchr("ACGT", buffer[i])) != NULL) {
                cur_acgt_len += 1;
                if (cur_acgt_len > max_acgt_len) {
                    max_acgt_len = cur_acgt_len;
                }
            } else {
                cur_acgt_len = 0;
            }
        }
    }
    printf("%d",max_acgt_len);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n;
    double t,a,h,tmp,ans=99999.0,cnt;
    cin >> n >> t >> a;
    rep(i,n){
        cin >> h;
        tmp=t-h*0.006;
        if(abs(tmp-a)<ans){
            ans=abs(tmp-a);
            cnt=i;
        }
    }
    cout << cnt+1 << endl;
	return 0;
}


Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
	double L;
	cin >> L;

    cout << setprecision(10) << fixed << (L/3)*(L/3)*(L/3) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int INF = 100000000;
int main(){
  int N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  int mxpos = 0;
  int mnpos = 0;
  for (int i = 0; i < N; i++){
    if (a[i] > a[mxpos]){
      mxpos = i;
    }
    if (a[i] < a[mnpos]){
      mnpos = i;
    }
  }
  if (a[mxpos] + a[mnpos] > 0){
    cout << N * 2 - 1 << endl;
    for (int i = 0; i < N; i++){
      cout << mxpos + 1 << ' ' << i + 1 << endl;
    }
    for (int i = 0; i < N - 1; i++){
      cout << i + 1 << ' ' << i + 2 << endl;
    }
  } else {
    cout << N * 2 - 1 << endl;
    for (int i = 0; i < N; i++){
      cout << mnpos + 1 << ' ' << i + 1 << endl;
    }
    for (int i = N - 2; i >= 0; i--){
      cout << i + 2 << ' ' << i + 1 << endl;
    }
  }
}

Measured memory_bytes: 3628
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>

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

int a[12][12];
const int INF = 1001001001;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    
    rep(i,n) {
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }

    int ans = INF;

    rep(s, 1<<n) {
        int cost = 0;
        vector<int> d(m);
        rep(i,n){
            if(s>>i&1) {
                cost += c[i];
                rep(j,m) d[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j,m) if (d[j] < x) ok = false;
        if (ok) ans = min(ans, cost);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(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)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    LL ans = LLINF;
    LL H;
    cin >> H;
    LL W;
    cin >> W;

    // 縦-縦
    {
        LL p1_w = (W + 1) / 3;
        LL p2_w = (W - p1_w) / 2;
        LL p3_w = W - p1_w - p2_w;
        LL min_w = min(min(p1_w, p2_w), p3_w);
        LL max_w = max(max(p1_w, p2_w), p3_w);
        ans = min_w ? min(ans, H * (max_w - min_w)) : ans;
    }
    // 縦-横
    {
        LL p1_w = (W + 1) / 3;
        LL p2_h = H / 2;
        LL p2_w = W - p1_w;
        LL p3_h = H - p2_h;
        LL p1 = p1_w * H;
        LL p2 = p2_h * p2_w;
        LL p3 = p3_h * p2_w;
        LL p_min = min(min(p1, p2), p3);
        LL p_max = max(max(p1, p2), p3);
        ans = p_min ? min(ans, p_max - p_min) : ans;
    }
    // 横-横
    {
        LL p1_h = (H + 1) / 3;
        LL p2_h = (H - p1_h) / 2;
        LL p3_h = H - p1_h - p2_h;
        LL min_h = min(min(p1_h, p2_h), p3_h);
        LL max_h = max(max(p1_h, p2_h), p3_h);
        ans = min_h ? min(ans, W * (max_h - min_h)) : ans;
    }
    // 横-縦
    {
        LL p1_h = (H + 1) / 3;
        LL p2_w = W / 2;
        LL p2_h = H - p1_h;
        LL p3_w = W - p2_w;
        LL p1 = p1_h * W;
        LL p2 = p2_h * p2_w;
        LL p3 = p2_h * p3_w;
        LL p_min = min(min(p1, p2), p3);
        LL p_max = max(max(p1, p2), p3);
        ans = p_min ? min(ans, p_max - p_min) : ans;
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

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

int main(){
  int n,sum=0; cin>>n;
  vector<int>T(n);
  for(int i=0;i<n;i++){
    int t; cin>>t;
    sum+=t;
    T[i]=t;
  }
  int m; cin>>m;
  vector<pair<int,int>>P;
  for(int i=0;i<m;i++){
    int p,x; cin>>p>>x;
    P.push_back(make_pair(p,x));
  }
  for(int i=0;i<m;i++){
    int ans=sum;
    int f=P[i].first;
    int s=P[i].second;
    ans=sum-T[f-1]+s;
    cout<<ans<<endl;
  }
}

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

#define int long long

#define F first
#define S second
#define all(x) (x).begin(), (x).end()

using namespace std;

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

//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    const int mod = 1e9+7;
    int n, s = 0, ans = 0;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i], s += a[i];
    for(int i = 0; i < n; i++) {
        s -= a[i];
        ans = ( ans + ( a[i] * ( s % mod ) ) ) % mod;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 5216
INF = 10**30
def solve(n, x, d):
    if d == 0:
        if x == 0:
            return 1
        else:
            return n+1
    D = {}
    for k in range(n+1):
        l = k*x + (k-1)*k//2*d
        r = k*x + (n*k - k*(k+1)//2)*d
        c = k*x % d
        if not c in D:
            D[c] = []
        l = (l - c) // d
        r = (r - c) // d
        if l > r:
            l, r = r, l
        D[c].append((l, r))
    res = 0
    for v in D.values():
        threshold = -INF
        for l, r in sorted(v):
            l = max(l, threshold)
            res += max(0, r-l+1)
            threshold = max(threshold, r+1)
    return res

n, x, d = map(int, input().split())
print(solve(n, x, d))

Measured memory_bytes: 70516
using System;

public class Test
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split();

        int a = int.Parse(line[0]);
        int b = int.Parse(line[1]);
        int c = int.Parse(line[2]);

        if (a+b+c == 17)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}


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

int main() {
	// your code goes here
	int x;
	int y;
	int z;
	int b = 0;
	cin >> x >> y >> z;
	for (int a = x; a <= y; a++)
	{
		if (z%a == 0)
		{
			b++;
		}
	}
	cout << b << endl;
	return 0;
}


Measured memory_bytes: 3088
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
     long x = sc.nextLong();
     long t = sc.nextLong();
     if(x>=t){
       System.out.println(x-t);
     }else{
       System.out.println(0);
     }
 }
}


Measured memory_bytes: 21844
alp = 'abcdefghijklmnopqrstuvwxyz'
s = input()
if s == alp[::-1]:
    print(-1)
elif len(s) == 26:
    for i in range(len(s)-1,0,-1):
        if s[i] > s[i-1]:
            for j in alp:
                if j not in s[:i] and j > s[i-1]:
                    print(s[:i-1]+j)
                    break
            break
else:
    for i in alp:
        if i not in s:
            print(s+i)
            break


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[200010];//適宜変える
	int id[100010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	return 0;
}

int cnt[100010];
G g;
void readgraph(){
	//適宜変える
	ll n;
	scanf("%lld",&n);
	int m=0;
	rep(i,0,n){
		ll x,y,k;
		scanf("%lld%lld",&x,&k);
		while(k--){
			scanf("%lld",&y);
			cnt[y]++;
			g.e[m].s=x;
			g.e[m].g=y;
			m++;
			g.e[m].s=y;
			g.e[m].g=x;
			m++;
		}
	}
	g.vcnt=n;
	g.ecnt=m;
	qsort(g.e,g.ecnt,sizeof(E),esort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}



//dfs
int a[100010];
ll dfs(int v,int pre){
	rep(i,g.id[v],g.id[v+1]){
		if(g.e[i].g!=pre){
			//hoge
			a[g.e[i].g]=a[v]+1;
			dfs(g.e[i].g,v);
		}
	}
}

int main(){
	readgraph();
	int r;
	rep(i,0,g.vcnt)if(cnt[i]==0)r=i;
	dfs(r,-1);
	rep(i,0,g.vcnt){
		int t=-1;
		rep(j,g.id[i],g.id[i+1])if(a[g.e[j].g]<a[i]){
			t=g.e[j].g;
			break;
		}
		
		printf("node %d: parent = %d, depth = %d, ",i,t,a[i]);
		
		if(i==r)printf("root, ");
		else if(g.id[i]+1==g.id[i+1])printf("leaf, ");
		else printf("internal node, ");
		
		printf("[");
		int flag=0;
		rep(j,g.id[i],g.id[i+1])if(a[g.e[j].g]>a[i])printf(flag++?", %d":"%d",g.e[j].g);
		puts("]");
	}
}


Measured memory_bytes: 7244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=2e5+5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,k,ans=0;
	cin>>n>>k;
	while(n){
		ans++;
		n/=k;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int ll
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
typedef vector<int> vi;
typedef vector<vi> vvi;
inline int in() { int x; cin >> x; return x; }

void solve() {
  int n = in(), k = in();
  vi p(n+1, 0); FOR(i,0,n) p[i+1] = in();
  int e = 0, maxe = 0;
  FOR(i,0,k) e += p[i]+1;
  FOR(i,k,n+1) {
    e += p[i]-p[i-k];
    if (maxe<e) maxe = e;
  }
  cout << fixed << setprecision(5) << (double)maxe/2 << endl;
}
#undef int
int main() {
  solve();
  return 0;
}


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

int main(){
  long n,k;
  cin >> n >> k;
  vector<long> a(n);
  vector<long> f(n);
  rep(i,n) cin >> a.at(i);
  rep(i,n) cin >> f.at(i);
  sort(a.begin(),a.end());
  sort(f.begin(),f.end(),greater<long>());
  long left = -1;
  long right = 1e12;
  while(right - left > 1){
    long mid = (left + right)/2;
    long cnt = 0;
    rep(i,n){
      cnt += max((a.at(i) - mid/f.at(i)),long(0));
      if(cnt > 1e18){
        break;
      }
    }
    //cout << mid << ":" << cnt << endl;
    if(cnt <= k) right = mid;
    else left = mid;
  }
  cout << right << endl;
  /*long ans = 0;
  rep(i,n){
    long tmp = (right/f.at(i))*f.at(i);
    ans = max(ans,tmp);
  }
  cout << ans << endl;*/
}

Measured memory_bytes: 3328
#include <iostream>
#include <cmath>
#include <vector>
#include <unordered_map>
using namespace std;

typedef long long ll;

int main() {
    int n;
    string s;
    cin >> n;
    unordered_map<string,int> anagram_counter;
    vector<int> counter(26);
    ll total = 0;

    for (int i = 0; i < n; ++i) {
        cin >> s;
        fill(counter.begin(), counter.end(), 0);
        
        for (auto c : s) {
            counter[c-'a']++;
        }
        string num = "";
        for (int b : counter) {
            num += to_string(b);
        }

        if (anagram_counter.find(num) == anagram_counter.end()) {
            anagram_counter[num] = 1;
        } else {
            total += anagram_counter[num];
            anagram_counter[num]++;
        }
        
    }
    cout << total << endl;
}

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

s = list(input().rstrip())

G = 0 # グーの回数
P = 0 # パーの回数
ans = 0 # 勝ち-負け

for i in range(len(s)):
    if i == 0:
        if s[i] == "g":
            G += 1
        else:
            ans -= 1
            G += 1
    else:
        if s[i] == "g":
            if G > P:
                ans += 1
                P += 1
            else:
                G += 1
        else:
            if G > P:
                P += 1
            else:
                ans -= 1
                G += 1

print(ans)


Measured memory_bytes: 49392
n = int(input())
H = list(map(int, input().split()))

low = [0 for _ in range(n-1)]

for i in range(n-1):
    if H[i] >= H[i+1]:
        low[i] = 1


def count(ind):
    cnt = 0
    while ind < n-1 and low[ind] == 1:
        low[ind] = 0
        ind += 1
        cnt += 1
    return cnt

ans = 0
for i in range(n-1):
    if low[i]   == 1:
        ans = max(ans, count(i))
print(ans)

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

using namespace std;

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

	int n1 = s.length();

	if (n >= n1) cout << s;
	else {
		cout << s.substr(0, n) + "...";
	}
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int num1 = 1;
		int num2 = 1;
		for(int i = 0;; ++i) {
			num1 = scan.nextInt();
			num2 = scan.nextInt();
			if(num1 == 0 && num2 == 0) break;
			if(num1 < num2) System.out.println(num1 + " " + num2);
			else System.out.println(num2 + " " + num1);
		}
 }
}

Measured memory_bytes: 27208
#include <iostream>

int main() {
  int N;
  std::cin >> N;

  int a = N % 10;
  if (a == 7) {
    std::cout << "Yes" << '\n';
    return 0;
  }

  int b = (N - a) / 10 % 10;
  if (b == 7) {
    std::cout << "Yes" << '\n';
    return 0;
  }

  int c = (N - N % 100) / 100;
  if (c == 7) {
    std::cout << "Yes" << '\n';
    return 0;
  }

  std::cout << "No" << '\n';
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int z;
  while(cin>>z,z){
    int ans=0;
    for(int x=1;x<=z;x++){
      for(int y=1;y<=z;y++){
	if(x*x*x+y*y*y>z*z*z) continue;
	ans=max(ans,x*x*x+y*y*y);
      }
    }
    cout<<z*z*z-ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3044
#include<iostream>
#include<vector>
#include<string>
#include<iomanip>
#include<set>

using namespace std;

#define MOD 1000000007

int main()
{
	string l;
	cin >> l;
	long long n=l.size();
	
	vector<vector<long long> > dp(n,vector<long long>(2,0));

	dp[0][0]=1;
	dp[0][1]=2;

	for(int i=1;i<n;i++)
	{
		if(l[i]=='1')
		{			
			dp[i][0]=dp[i-1][0]*3+dp[i-1][1]*1;
			dp[i][1]=dp[i-1][1]*2;
		}
		else
		{
			dp[i][0]=dp[i-1][0]*3;
			dp[i][1]=dp[i-1][1]*1;
		}
		dp[i][0]%=MOD;
		dp[i][1]%=MOD;
	}

	long long ans=dp[n-1][0]+dp[n-1][1];
	ans%=MOD;

	cout << ans << endl;



}

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

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

  int max=0;
  int sum=0;
for(int i=0; i<N ;i++){
  sum +=seg[i];
  if(seg[i]>max) max=seg[i];
}
  
if(max < sum-max) cout << "Yes" <<endl;
if(max >= sum-max) cout << "No" << endl;

}

Measured memory_bytes: 256
/*#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n;

int main(){
  ll ans=0;
  cin >> n ;
  vi x(n),y(n),p(n);
  REP(i,n){
    cin>>x[i]>>y[i]>>p[i];
  }
  cout<<ans<<endl;
  return 0;
}
*/

#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll a,b,c,k;

int main(){
  ll ans=0;
  cin >> a >> b>>c>>k;

  for(int i=0;i<11;i++){
    if (a>=b)
    {
      b*=2;
      k--;
    }
  }
  
  for(int i=0;i<11;i++){
    if (b>=c)
    {
      c*=2;
      k--;
    }
  }
  

  if (k<0)
  {
    cout<<"No"<<endl;
    return 0;
  }
  else
  {
    cout<<"Yes"<<endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	string s; cin >> s;
	deque<char>dq;
	int cnt = 0;
	REP(i, s.size()) {
		if (dq.empty()) {
			dq.push_back(s[i]);
		}
		else if (dq.back() == s[i]) {
			dq.push_back(s[i]);
		}
		else {
			dq.pop_back();
			cnt += 2;
		}

	}
	print(cnt);


	return 0;
}


Measured memory_bytes: 512
n,k = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
l,r = 0, 10**18
if sum(A)<=k:
    print(0)
else:
    while r-l!=1:
        mid = (r+l)//2
        ex = 0
        for i in range(n):
            need = mid // F[i]
            ex += max(0, A[i]-need)
        if ex <= k:
            r = mid
        else:
            l = mid
    print(r)

Measured memory_bytes: 119500
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var s = ReadLine();
        var K = int.Parse(ReadLine());

        var h = new HashSet<string>();
        for (int i = 0; i < s.Length; i++)
        {
            for (int j = 1; j <= K; j++)
            {
                if (i + j - 1 < s.Length) h.Add(s.Substring(i, j));
            }
        }

        var a = new List<string>(h);
        a.Sort();
        WriteLine(a[K - 1]);
    }
}

Measured memory_bytes: 14688
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var S = ReadLine();
            S = S.Replace("eraser", "*");
            S = S.Replace("erase", "*");
            S = S.Replace("dreamer", "*");
            S = S.Replace("dream", "*");
            if (S.Any(s => s != '*'))
                WriteLine("NO");
            else
                WriteLine("YES");
        }
    }
}

Measured memory_bytes: 27344
n,M = list(map(int,input().split()))

m = [[] for _ in range(n)]
dp = [0]*n
from collections import deque
que = deque()
for _ in range(M):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  m[a].append(b)
  m[b].append(a)
  if a == 0:
    que.append(b)
    dp[b] = 1
  if b == 0:
    que.append(a)
    dp[a] = 1

while que:
  c = que.popleft()
  for i in m[c]:
    if dp[i] == 0 :
      dp[i] = c+1
      que.append(i)

#[exit(print('No')) for i in range(1,n)  if dp[i] == 0]

print('Yes')
[print(dp[i]) for i in range(1,n)]


Measured memory_bytes: 37948
#include <iostream>

using namespace std;

int main()
{
    long long int h,w,l1,l2;
    cin>>h>>w;
if(h==1||w==1)
{
cout<<"1";
}
else
{
    l1=(h/2)*(w/2);
    l2=(h-h/2)*(w-w/2);
    cout<<l1+l2;
}
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll number[1000001];
    rep(i, 1000001){
        number[i] = 0;
    }

    ll m = 1;
    while(1){
        if(number[s] == 1){
            break;
        }
        number[s] = 1;
        s = (s % 2 == 0 ? s / 2 : 3 * s + 1);
        m++;
    }

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 11436
#include<stdio.h>
#include<stdlib.h>
int IsPrime(int);
int main() {
  int i,count=0,n,*sosu;
    scanf("%d",&n);
    
    sosu = (int *)malloc(n * sizeof (int));
    
   
    
    for(i=n-1;i>=0;i--){
        scanf("%d",&sosu[i]);
        if(IsPrime(sosu[i]) == 1) count++;
    }
    printf("%d\n",count);
    return 0;
}

 int   IsPrime(int n){


    


   int i;

    if (n < 2)
        return 0;
    else if (n == 2)
        return 1;

    if (n % 2 == 0)
        return 0;

    for (i = 3; i <= n / i; i += 2)
         if (n % i == 0)
            return 0;
    return 1;

}



Measured memory_bytes: 2072
#include<stdio.h>
int main(){
  int a,b,c,d,e;
  scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
  a*=e;
  if(c<e)b+=(e-c)*d;
  if(a>b)a=b;
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 596
n=int(input())

x=list(input().split() for _ in range(n))

for i in range(n):
	x[i][1]=int(x[i][1])
	x[i].append(i)
    
y=sorted(x,key=lambda a:(a[0],-a[1]))

for i in range(n):
	print(y[i][2]+1)

Measured memory_bytes: 3060
#include <iostream>
#include <set>
int main(){
  int N,Y;
  std::cin >> N >> Y;
  
  for(int i=0;i<=N;++i){
  for(int j=0;j<=N-i;++j){
    int k= N - (i + j);
    if(i * 10000 + j * 5000 + k * 1000 == Y){
      std::cout << i << " " << j << " " << k;
      return 0;
    }
  }
  }
  std::cout << "-1 -1 -1";
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys

input = iter(sys.stdin.read().splitlines()).__next__

a, b, c, d = map(int, input().split())

A = [a, b]
if a < 0 and b > 0:
   A.append(0)

B = [c, d]
if c < 0 and d > 0:
   B.append(0)

res = -1000000000000000001
for x in A:
   for y in B:
      res = max(res, x*y)

print(res)


Measured memory_bytes: 8988
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = A[:]

copy.remove(maxa)

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)


Measured memory_bytes: 14080
#include <iostream>
#include <string>

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) cout << 'x';
    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  vi a(3);
  rep(i, 3) cin >> a[i];
  sort(ALL(a));
  if (a[0]+a[1] == a[2]) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


vector <int> treeconstruction(vector <int> d) {
  const int MAX = 111;
  vector<int> res,NG;
  int n=d.size();
  int m=0;
  int t[MAX]={};
  queue<int> q[MAX];
  for(int i=0;i<n;i++){
    t[d[i]]++;
    q[d[i]].push(i);
    m=max(m,d[i]);
  }
  bool f=1;
  for(int i=0;i<(m+1)/2;i++) f&=t[m-i]>=2;
  if(m%2) f&=t[m/2+1]==2;
  else f&=t[m/2]==1;
  for(int i=0;i<n;i++){
    if(m%2) f&=d[i]>=m/2+1;
    else f&=d[i]>=m/2;
  }
  if(!f) return NG;

  bool used[MAX]={};
  int b[MAX][2]={};

  if(m%2){
    for(int i=0;i<=m/2;i++){
      b[m-i][0]=q[m-i].front();q[m-i].pop();
      b[m-i][1]=q[m-i].front();q[m-i].pop();
      used[b[m-i][0]]=1;
      used[b[m-i][1]]=1;
      if(i){
        res.push_back(b[m-i+1][0]);
        res.push_back(b[m-i][0]);
        res.push_back(b[m-i+1][1]);
        res.push_back(b[m-i][1]);
      }
      if(i==m/2){
        res.push_back(b[m-i][0]);
        res.push_back(b[m-i][1]);
      }
    }
    for(int i=0;i<n;i++){
      if(used[i]) continue;
      res.push_back(i);
      res.push_back(b[d[i]-1][0]);
    }
  }else{
    for(int i=0;i<m/2;i++){
      b[m-i][0]=q[m-i].front();q[m-i].pop();
      b[m-i][1]=q[m-i].front();q[m-i].pop();
      used[b[m-i][0]]=1;
      used[b[m-i][1]]=1;
      if(i){
        res.push_back(b[m-i+1][0]);
        res.push_back(b[m-i][0]);
        res.push_back(b[m-i+1][1]);
        res.push_back(b[m-i][1]);
      }
    }
    b[m/2][0]=q[m/2].front();q[m/2].pop();
    used[b[m/2][0]]=1;
    res.push_back(b[m/2+1][0]);
    res.push_back(b[m/2][0]);
    res.push_back(b[m/2+1][1]);
    res.push_back(b[m/2][0]);

    for(int i=0;i<n;i++){
      if(used[i]) continue;
      res.push_back(i);
      res.push_back(b[d[i]-1][0]);
    }
  }
  return res;
}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i];
  cout<<(treeconstruction(as).empty()?"Impossible":"Possible")<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
#include <cmath>
int main() {
    static const double pi = acos(-1);
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double th = 2 * pi * (H * 60 + M) / 720;
    double tm = 2 * pi * M / 60;
    double theta  = th - tm;
    double ans;
    ans = sqrt(A * A + B * B - 2 * A * B * cos(theta));

    printf("%.10f\n",ans);
      
    return 0;
}

Measured memory_bytes: 4124
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter syso = new PrintWriter(System.out);
		String a=sc.next();
		long ans=0;
		for(int i=0;i<a.length();i++) {
			ans+=Integer.parseInt(a.charAt(i)+"");
		}
		if(ans%9==0)syso.println("Yes");
		else syso.println("No");
        syso.close();
    }
    
 
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
		public int[] nextArr(int n) throws IOException{
			int arr[]=new int[n];
			for(int i=0;i<n;i++)arr[i]=nextInt();
			return arr;
		}
		public BigInteger BigInteger(String s) throws IOException{
			BigInteger a=new BigInteger(s);
			return a;
		}
 
	}
}

Measured memory_bytes: 44368
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#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 MOD 1000000007
#define INF 1000000000

using namespace std;
bool dp[51][51];
bool visited[51];
int n, m;

void dfs(int st) {
	visited[st] = true;

	FOR(i, 1, n) {
		if (dp[st][i] == false) {
			continue;
		}
		if (visited[i] == true) {
			continue;
		}
		dfs(i);
	}
}

int main(void) {
	int count = 0;

	cin >> n >> m;

	FOR(i, 0, 50) {
		FOR(t, 0, 50) {
			dp[i][t] = false;
		}
	}
	FOR(i, 1, m) {
		int a, b;
		cin >> a >> b;
		dp[a][b] = dp[b][a] = true;
	}
	
	
	FOR(i, 0, 50) {
		visited[i] = false;
	}


	FOR(i, 1, n) {
		FOR(t, 1, n) {
			if (dp[i][t] == true) {

				FOR(u, 0, 50) {
					visited[u] = false;
				}

				dp[i][t] = dp[t][i] = false;
				dfs(1);

				FOR(u, 1, n) {
					if (visited[u] == false) {
						count++;
						break;
					}
				}
				dp[i][t] = dp[t][i] = true;

			}
		}
	}
	if (count % 2 == 0) {
		cout << count / 2 << endl;
	}
	else {
		cout << count / 2 + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256