akhauriyash/Code-Regression huggingface dataset:
N=int(input())
a=list(map(int,input().split()))

ball=[0]*N
for i in range(N-1,-1,-1):
  B=ball[i::i+1]
  if sum(B)%2!=a[i]:
    ball[i]=1

print(sum(ball))
if sum(ball)!=0:
  b=[]
  for i in range(N):
    if ball[i]==1:
      b.append(i+1)
  print(*b)

Measured memory_bytes: 16056
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
map<int,int>p;
int a[200000];
int main()
{
	int m,n,i,j,t,k;
	cin>>n;
	int d=0,b=0,c=0;
	d=n%10;
	b=n/10%10;
	c=n/100;
	if(d==7||b==7||c==7) cout<<"Yes";
	else cout<<"No";
 } 


Measured memory_bytes: 3636
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) return b;
    gcd(b, a%b);
}

template<typename U>
U gcd_multi(vector<U> A) {
    int n = A.size();
    if (n == 1) return A[0];
    int G = gcd(A[0], A[1]);
    if (n == 2) return G;
    for (int i = 2; i < n; ++i) G = gcd(G, A[i]);
    return G;
}

template<typename U>
U lcm(U a, U b) {
    U ans = a*b/gcd(a, b);
    return ans;
}

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

    //1からBまでの数を数える

    ll lcmx = lcm(c,d);

    ll bc = b/c;
    ll ac = (a-1)/c;

    ll abc = bc-ac;

    ll bd = b/d;
    ll ad = (a-1)/d;

    ll abd = bd-ad;

    ll bcd = b/lcmx;
    ll acd = (a-1)/lcmx;

    ll lcms = bcd-acd;
    ll all = b-a+1;

    ll ans = all-(abc+abd-lcms);
    cout << ans << endl;

    return 0;
}

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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0;
	rep(i,n){
		cin >> a[i];
		sum += a[i];
	}
	int count = 0;
	rep(i,n){
		if(a[i]*4*m >= sum) count++;
	}
	if(count >= m){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
    return 0;
}



Measured memory_bytes: 256
#include <limits.h>
#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 <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

vector<int> G[200005];
int memo[200005];

int dfs(int v) {
    if (memo[v] != -1) return memo[v];

    int res = 0;
    REP(i, G[v].size()) {
        res = max(res, dfs(G[v][i]) + 1);
    }

    return memo[v] = res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N, M;
    cin >> N >> M;
    REP(i, M) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        G[x].push_back(y);
    }

    REP(i, N) memo[i] = -1;

    int ans = 0;
    REP(i, N) {
        ans = max(ans, dfs(i));
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  vector<long long> sum(N + 1, 0);
  for (int i = 1; i < N + 1; i++) sum[i] = sum[i - 1] + A[i - 1];

  long long length = sum[N];
  long long ans = LLONG_MAX;
  for (int i = 1; i < N; i++) {
    long long dif = length - sum[i];
    ans = min(ans, abs(sum[i] - dif));
  }

  cout << ans << endl;
}

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

using namespace std;
#define ll long long 
int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   set<int> s;
s.insert(a);
s.insert(b);
s.insert(c);
if(s.size()==2)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;

    return 0;
}


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

char s[1005];

int main()
{
	scanf("%s", s+1);
	int n = strlen(s+1);
	bool bad = false;
	if(s[1] != 'A') bad = true;
	int cnt = 0;
	int dat = -1;
	for(int i = 3; i<= n-1; i++)
	{
		if(s[i] == 'C')
		{
			cnt++;
			dat = i;
		}
	}
	if(cnt != 1) bad = true;
	for(int i = 2; i<= n; i++)
	{
		if(i == dat) continue;
		if((s[i]>= 'A' && s[i]<= 'Z')) bad = true;
	}
	if(bad) puts("WA");
	else puts("AC");
}

Measured memory_bytes: 256
use std::io;
use std::str;

pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Scanner {
            reader: reader,
            buffer: Vec::new(),
        }
    }

    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("failed to parse token");
            }
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("failed to read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

static MODULO: usize = 1_000_000_007;

use io::Write;
fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut stdout = io::BufWriter::new(stdout);
    let mut scanner = Scanner::new(stdin.lock());

    let N: usize = scanner.token();
    let M: usize = scanner.token();

    //dp[i] := i段目への到達手段の全部の数
    //dp[0] = 1, dp[a_i] = 0;
    let mut dp: Vec<usize> = vec![0; N + 5];
    let mut notSafe: Vec<bool> = vec![false; N + 5];
    for _ in 1..M + 1 {
        notSafe[scanner.token::<usize>()] = true;
    }

    dp[0] = 1;
    if notSafe[1] == true {
        dp[1] = 0;
    } else {
        dp[1] = 1;
    }

    for i in 2..N + 2 {
        if notSafe[i] == true {
            continue;
        } else {
            dp[i] = (dp[i - 1] + dp[i - 2]) % MODULO;
        }
    }
    writeln!(&mut stdout, "{:?}", dp[N]);
}


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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  long long nt = 0;
  for (int i = n - 1; i >= 0; --i) {
    nt += (b[i] - (a[i] + nt) % b[i]) % b[i];
  }
  cout << nt << endl;
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> num( N );
  for ( int i = 0; i < N; i++ )
     cin >> num.at( i );
  sort(num.begin(), num.end());
  int size = num.at( 0 ), dan = 1;
  for ( int i = 1; i < N; i++ ) {
    if( size != num.at( i )) {
      size = num.at( i );
      dan++;
    }
  }
  cout << dan << endl;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;
  int sum = 0;
  rep(i, s.size()) sum += s[i]-'0';
  cout << (stoll(s)%sum ? "No" : "Yes") << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
B = [int(i) for i in input().split()] 

D = 0
if N >= 3:
	if B[0] < B[1]:
		D += min(B[0],B[1])
	else:
		D += max(B[0],B[1])
	for i in range(1,N-1,1):
		D += min(B[i-1],B[i])
	D += B[N-2]
else:
	D = 2*B[0]

print(D)

Measured memory_bytes: 3064
n, k = map(int, input().split())
bucket = [0] * 10 ** 5
for i in range(n):
    a, b = map(int, input().split())
    bucket[a - 1] += b

sum_b = 0
for i in range(len(bucket)):
    sum_b += bucket[i]
    if sum_b >= k:
        print(i + 1)
        break


Measured memory_bytes: 11568
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

const LL inf = 25000000000;
LL N, C, ans;
std::vector<LL>res1, res2, res3;

int main()
{
	in >> N >> C;
	std::vector<std::vector<LL>>D(C, std::vector<LL>(C)), c(N, std::vector<LL>(N));
	rep(i, C) rep(j, C) in >> D[i][j];
	rep(i, N) rep(j, N) in >> c[i][j];
	for (int i = 1; i <= C; ++i)
	{
		LL res = 0;
		for (int x = 1; x <= N; ++x)
		{
			for (int y = 1; y <= N; ++y)
			{
				if ((x + y) % 3 == 2) res += D[c[x - 1][y - 1] - 1][i - 1];
			}
		}
		res1.push_back(res);
	}
	for (int i = 1; i <= C; ++i)
	{
		LL res = 0;
		for (int x = 1; x <= N; ++x)
		{
			for (int y = 1; y <= N; ++y)
			{
				if ((x + y) % 3 == 1) res += D[c[x - 1][y - 1] - 1][i - 1];
			}
		}
		res2.push_back(res);
	}
	for (int i = 1; i <= C; ++i)
	{
		LL res = 0;
		for (int x = 1; x <= N; ++x)
		{
			for (int y = 1; y <= N; ++y)
			{
				if ((x + y) % 3 == 0) res += D[c[x - 1][y - 1] - 1][i - 1];
			}
		}
		res3.push_back(res);
	}
	ans = inf;
	rep(i, C)
	{
		rep(j, C)
		{
			rep(k, C)
			{
				if (i != j && i != k && j != k) ans = std::min(ans, res1[i] + res2[j] + res3[k]);
			}
		}
	}
	out << ans << std::endl;
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define clr(A, x) memset(A, x, sizeof(A))
#define cpy(A, B) memcpy(A, B, sizeof(B))
#define g(s) getline(cin, s) ///ai grija la fin/cin ///
#define FASTIO ios_base::sync_with_stdio(0)
const long long INFLL = 2 * 1e18 + 100;
const int INFINT = 2 * 1e9 + 100;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//ifstream fin("dijkstra.in");
//ofstream fout("dijkstra.out");
void die()
{
    cout << "-1";
    exit(0);
}
const int NMAX = 2* 1e5 + 5;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

ll n, a, b;

int main()
{
    FASTIO;
    cin >> n >> a >> b;
    cout << max(0LL, b * (n - 1) + a - (n - 1) * a - b + 1);

    return 0;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
A = [input() for i in range(H)]

x = ms = 0
for i in range(H):
    for j in range(x,W):
        if A[i][j] == '.':
            if i==H-1:
                print('Impossible')
            else:
                break
        else:
            x = j
            ms += 1

cs = sum(row.count('#') for row in A)

print('Possible' if cs==ms else 'Impossible')

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	for i := 1; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	answer := calcSubordinates(n, a)
	for _, v := range answer {
		fmt.Println(v)
	}
}

func calcSubordinates(n int, a []int) []int {
	subordinates := make([]int, n)
	for i := 1; i < n; i++ {
		subordinates[a[i]-1]++
	}
	return subordinates
}


Measured memory_bytes: 8076
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll c[10][10];

ll digit(ll n){
    ll ans = 0;
    while(n>=10){
        n/=10;
        ans++;
    }
    return ans+1;
}

ll ten[10];
 
int main(void){
    ll n;
    cin>>n;
    ten[0]=1;
    for(ll i=0;i<10;i++)ten[i+1]=10*ten[i];
    for(ll i=1;i<=n;i++){
        ll d = digit(i);
        ll prev = i;
        while(prev>=ten[d-1])prev-=ten[d-1];
        //cout<<i<<" "<<d<<endl;
        prev = (i-prev)/ten[d-1];
        ll back = i%10;
        //cout<<i<<" "<<prev<<" "<<back<<endl;
        c[prev][back]++;
    }
    ll ans = 0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            ans+=c[i][j]*c[j][i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>

#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


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

    if(s == "RRR") cout << 3 << endl;
    else if(s == "RRS" || s == "SRR") cout << 2 << endl;
    else if(s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR") cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 3596
#ABC140C
N = int(input())
B = list(map(int,input().split()))

A = []

for i in range(N):
    if i == 0:
        A.append(B[i])
    elif i == N-1:
        A.append(B[i-1])
    else:
        A.append(min(B[i-1],B[i]))

print(sum(A))

Measured memory_bytes: 3064
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    dp = [[0] * (N + 1) for _ in range(N + 1)]
    ans = 0

    for i in range(N - 1, -1, -1):
        for j in range(N - 1, i, -1):
            if S[i] == S[j]:
                dp[i][j] = dp[i + 1][j + 1] + 1
            if ans < min(dp[i][j], j - i):
                ans = min(dp[i][j], j - i)

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main(void) {
  int N; cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  for (int i = 0; i < N; i++) cin >> V.at(i);
  for (int i = 0; i < N; i++) cin >> C.at(i);

  int a = 0;
  for (int i = 0; i < N; i++) if (V.at(i)-C.at(i) > 0) a += V.at(i)-C.at(i);
  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
const int MAXN = 2e5 + 5, MAXM = 2e3 + 5, BOUND = 2e5, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-3;
#define mid l + ((r-l)>>1)
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define lc(x) ch[x][0]
#define pii pair<int,int>
#define rc(x) ch[x][1]
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n, q;
char s[MAXN], t[MAXN], d[MAXN];
bool check1(int m) {
	rep(i, 1, q) {
		if (m < 1 || m > n)break;
		if (t[i] == s[m]) {
			if (d[i] == 'L')m--;
			else m++;
		}
	}
	if (m < 1)return true;
	return false;
}
bool check2(int m) {
	rep(i, 1, q) {
		if (m < 1 || m > n)break;
		if (t[i] == s[m]) {
			if (d[i] == 'L')m--;
			else m++;
		}
	}
	if (m > n)return true;
	return false;
}
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> q;
	cin >> (s + 1);
	int ans = 0;
	rep(i, 1, q) cin >> t[i] >> d[i];
	int l1 = 0, l2 = 0, r1 = n + 1, r2 = n + 1, m1, m2;
	while (l1 < r1) {
		m1 = (l1 + r1 + 1) / 2;
		if (check1(m1))l1 = m1;
		else r1 = m1 - 1;
	}
	while (l2 < r2) {
		m2 = (l2 + r2) / 2;
		if (check2(m2))r2 = m2;
		else l2 = m2 + 1;
	}
	cout << l2 - l1 - 1 << '\n';
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   
    ll n;
    cin >> n;
    vector <ll> order, point, bonus;
    for(ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        order.push_back(tmp);
    }
    for (ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        point.push_back(tmp);
    }
    for (ll i=0;i<n-1;i++){
        ll tmp;
        cin >> tmp;
        bonus.push_back(tmp);
    }
    ll ans = 0;
    for (ll i=0;i<n;i++){
        ans += point[order[i]-1];
        if(i != 0 and order[i-1] == order[i] - 1){
            ans += bonus[order[i-1] - 1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

void isRightTriangle(int a,int b,int c){
	if(a*a == b*b + c*c){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
}
int main(void){
	int n,i;
	int x,y,z;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		scanf("%d%d%d", &x, &y, &z);
		if(x > y && x > z){
			isRightTriangle(x,y,z);
		}else if(y > x && y > z){
			isRightTriangle(y,x,z);
		}else{
			isRightTriangle(z,y,x);	
		}
	}
	return 0;
}

Measured memory_bytes: 580
import java.io.*;
import java.util.*;


public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new A().doIt();
	}
	class A{
		String str;
		int pos;
		void doIt(){
			int n = sc.nextInt();
			for(int i = 0;i < n;i++){
				str = sc.next();
				pos = 0;
				System.out.println(exp());
			}
		}
		int exp() {
			int res = term();
			while(true){
				char op = str.charAt(pos);
				if(op != '+' && op != '-')break;
				int old = res;
				pos++;
				res = term();
				if(op == '+')res = old + res;
				else res = old - res;
			}
			return res;
		}
		
		int term(){
			int res = fact();
			while(true){
				char op = str.charAt(pos);
				if(op != '*' && op != '/')break;
				int old = res;
				pos++;
				res = fact();
				if(op == '*')res = old * res;
				else res = old / res;
			}
			return res;
		}
		
		int fact(){
			if(Character.isDigit(str.charAt(pos))){
	            int t = str.charAt(pos) - '0';
	            pos++;
	            while(Character.isDigit(str.charAt(pos))){
	                t = t * 10 + (str.charAt(pos) - '0');
	                pos++; 
	            }
	            return t; 
	        }
	        else if(str.charAt(pos) == '('){
	            pos++;
	            int res = exp();
	            pos++;
	            return res;
	        }
			return 0;
		}
	}
}

Measured memory_bytes: 25908
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
m=c.most_common()
t=sorted(m,key=lambda m:m[0],reverse=True)
w=0
b=0
for i in range(len(t)):
    if(t[i][1]>=4):
        if(w==b==0):
            w=t[i][0]
            b=t[i][0]
        elif(w==0):
            w=t[i][0]
        elif(b==0):
            b=t[i][0]
    elif(t[i][1]>=2):
        if(w==0):
            w=t[i][0]
        elif(b==0):
            b=t[i][0]
print(w*b)

Measured memory_bytes: 23204
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int h,w,n;
    cin>>h>>w>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int cnt=0,now=1;
    for(int i=0; i<h; ++i){
        if(i%2==0){
            for(int j=0; j<w; ++j){
                if(cnt<a[now-1]){cnt++; cout<<now<<" ";}
                else{now++; cnt=1; cout<<now<<" ";}
            }
            cout<<endl;
        }
        else{
            string s;
            for(int j=w-1; j>=0; --j){
                if(cnt<a[now-1]){cnt++; s=to_string(now)+" "+s;}
                else{now++; cnt=1; s=to_string(now)+" "+s;}
            }
            cout<<s<<endl;
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc107_c() {
	ll N, K;

	cin >> N >> K;

	vector<ll> x(N);
	rep(i, N) cin >> x[i];

	ll ans, tmp;
	ans = INF;
	for (int i = 0; i + K - 1 < N; i++) {
		if (x[i] < 0 && x[i + K - 1] < 0) {
			tmp = abs(x[i]);
		}
		else if (x[i] < 0 && x[i + K - 1] > 0) {
			if (abs(x[i]) > abs(x[i + K - 1])) {
				tmp = abs(x[i]) + 2 * abs(x[i + K - 1]);
			}
			else {
				tmp = 2 * abs(x[i]) + abs(x[i + K - 1]);
			}
		}
		else {
			tmp = abs(x[i + K - 1]);
		}
		ans = min(ans, tmp);
	}

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

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

	solve_abc107_c();

	return 0;
}

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

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

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  int ans = 0;

  FOR (i, 0, s.size() + 1) {
    FOR (j, 1, s.size() - i + 1) {
      regex re("[ATGC]+");
      string text = s.substr(i, j);
      bool flag = regex_match(text, re);
      if (flag && ans < text.size()) {
        ans = text.size();
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n, m = [int(_) for _ in input().split(' ')]
b = [False] * (n + 1)
for _ in range(m):
    b[int(input())] = True

M = 1000000007

dp = [0] * (n + 1)
dp[0] = 1
if not(b[1]):
    dp[1] = 1
for i in range(2, n + 1):
    if b[i]:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % M
print(dp[n])


Measured memory_bytes: 7668
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long t;//Long.parseLong(br.readLine());
    cin>>t;
	long long tt=t%500;
	long long ans=(t/500)*1000;
	ans+=(tt/5)*5;
	cout<<ans;
	return 0;
}


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

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

	int n;
	cin >> n;
	vector<string> v(n);
	rep(i, n)
		cin >> v.at(i);
	rep(i, n - 1)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (v.at(i) == v.at(j))
			{
				cout << "No" << endl;
				return (0);
			}
		}
	}
	rep(i, n - 1)
	{
		if (v.at(i).at(v.at(i).size() - 1) != v.at(i + 1).at(0))
		{
			cout << "No" << endl;
			return (0);
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
n, m, c = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)
count = 0

n.times do
  ip = 0
  array = gets.split.map(&:to_i)
  array.length.times do |i|
    ip += array[i] * bs[i]
  end

  if ip + c > 0
    count += 1
  end
end

puts count

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
  int A,B,H,M;
  cin>>A>>B>>H>>M;
  ld h=(ld)H/12*360+(ld)M/2;
  ld mi=(ld)M/60*360;
  ld tmp=abs(h-mi);
  tmp=min(tmp,360-tmp);
  ld ans=0; 
    tmp=(tmp*M_PI)/180;
    ans=A*A+B*B-2*A*B*cos(tmp);
    cout<<fixed<<setprecision(10)<<sqrt(ans)<<endl;
}

Measured memory_bytes: 4164
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    // fastio
    ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s,h;
    string str,str1;
    cin>>n;
    while(n)
    {
        if(n%10==7)
        {
            cout<<"Yes";
            return 0;        
        }
        n/=10;
    }
    cout<<"No";
}

Measured memory_bytes: 3628
card = []
result = [["n"]*3 for _ in range(3)]

for _ in range(3):
    a_list = [int(a) for a in input().split()]
    card.append(a_list)

N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if card[i][j] == b:
                result[i][j] = "y"

def solve():
    if result[0][0] == result[1][1] == result[2][2] == "y":
        return True
    elif result[0][2] == result[1][1] == result[2][0] == "y":
        return True

    for row in result:
        if row == ["y", "y", "y"]:
            return True

    for i in range(3):
        if result[0][i] == result[1][i] == result[2][i] == "y":
            return True

    return False

if solve():
    print("Yes")
else:
    print("No")

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second

typedef long long LL;

int n ,m;
long long ans;

int main() {
    //freopen("test.txt","r",stdin);
    cin >> n >> m;
    if ( n > m +1 || m > n +1) {
        cout << 0 ;
        return 0;
    }
    ans = 1;
    for (int i = 1 ; i <= n ; i++) {
        ans *= i;
        ans = ans % 1000000007;
    }
    for (int i = 1 ; i <= m ; i++) {
        ans *= i;
        ans = ans % 1000000007;
    }
    if ( n == m ) ans *= 2;
    ans = ans % 1000000007;
    cout << ans;
}


Measured memory_bytes: 256
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


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

div_c = (b // c) - ((a - 1) // c)
div_d = (b // d) - ((a - 1) // d)
div_c_and_d = (b // lcm(c, d)) - ((a - 1) // lcm(c, d))
div_c_or_d = div_c + div_d - div_c_and_d
print((b - a + 1) - div_c_or_d)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int happiness[N][3];
  int max_happiness[N][3];
  #define swim 0
  #define insect 1
  #define homework 2
  for(int i=0;i<N;i++){
    cin >> happiness[i][swim] >> happiness[i][insect] >> happiness[i][homework];
    max_happiness[i][swim] = 0;
    max_happiness[i][insect] = 0;
    max_happiness[i][homework] = 0;
  }
  max_happiness[0][swim]=happiness[0][swim];
  max_happiness[0][insect]=happiness[0][insect];
  max_happiness[0][homework]=happiness[0][homework];
  for(int date=0;date<N-1;date++){
    if(max_happiness[date+1][swim] <= max_happiness[date][insect] + happiness[date+1][swim])
      max_happiness[date+1][swim] = max_happiness[date][insect] + happiness[date+1][swim];
    if(max_happiness[date+1][swim] <= max_happiness[date][homework] + happiness[date+1][swim])
      max_happiness[date+1][swim] = max_happiness[date][homework] + happiness[date+1][swim];
    if(max_happiness[date+1][insect] <= max_happiness[date][swim] + happiness[date+1][insect])
      max_happiness[date+1][insect] = max_happiness[date][swim] + happiness[date+1][insect];
    if(max_happiness[date+1][insect] <= max_happiness[date][homework] + happiness[date+1][insect])
      max_happiness[date+1][insect] = max_happiness[date][homework] + happiness[date+1][insect];
    if(max_happiness[date+1][homework] <= max_happiness[date][insect] + happiness[date+1][homework])
      max_happiness[date+1][homework] = max_happiness[date][insect] + happiness[date+1][homework];
    if(max_happiness[date+1][homework] <= max_happiness[date][swim] + happiness[date+1][homework])
      max_happiness[date+1][homework] = max_happiness[date][swim] + happiness[date+1][homework];
  }
  cout << max({max_happiness[N-1][swim],max_happiness[N-1][insect],max_happiness[N-1][homework]}) << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"

signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    
    cin>>n;
    int a[n],b[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    
    sort(a,a+n);
    sort(b,b+n);
    
    if(n%2)
    {
        temp = a[n/2];
        temp1 = b[n/2];
        
        ans = temp1-temp+1;
    }
    
    else
    {
        double temp=0.0,temp1=0.0;
        temp = a[n/2] + a[n/2 - 1];
        temp = temp/2;
        
        temp1 = b[n/2] + b[n/2 - 1];
        temp1=temp1/2;
        
        ans = 2*(temp1-temp) + 1;
    }
    
    cout<<ans<<endl;
    
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int N, l, r, sum;
    cin >> N;
    sum = 0;
    rep(i,  N){
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}

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

signed main(){
  int n,k,r,s,p;string t;cin>>n>>k>>r>>s>>p>>t;
  int ans=0;
  for(int i=0;i<k;i++){
    vector<char> q;
    for(int j=i;j<n;j+=k){
      q.push_back(t[j]);
    }
    bool pass=true;
    for(int i=0;i<q.size();i++){
      if(!pass&&i&&q[i]==q[i-1]){
        pass=true;
        continue;
      }
      if(q[i]=='r')ans+=p;
      if(q[i]=='s')ans+=r;
      if(q[i]=='p')ans+=s;
      pass=false;
    }
    //cout<<ans<<endl;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 640
#if WATCH_RUNTIME
	#include <ctime>
	clock_t startTime;
#endif

#include <cstdio>
#include <cstring>

int main(void)
{
	#if DEBUG 
	freopen("_in","r",stdin);
	#endif
	#if WATCH_RUNTIME
	startTime=clock();
	#endif
	bool winFlag;
	int i,j,N;
	char msg[200],patten[100];
	scanf("%s",msg);
	scanf("%s",patten);
	N=strlen(msg);
	for(i=0;i<N;i++)
	{
		msg[N+i]=msg[i];
	}
	msg[N+i]='\0';
	for(i=0;i<N;i++)
	{
		winFlag=true;
		for(j=0;patten[j];j++)
		{
			if(patten[j]!=msg[i+j])
			{
				winFlag=false;
				break;
			}
		}
		if(winFlag)
			break;
	}
	printf("%s\n",winFlag?"Yes":"No");

	#if WATCH_RUNTIME
	printf("----------\n");
	printf("\n+===============+\n");
	printf("|RUNTIME =%3dms.|\n",clock()-startTime);
	printf("+===============+\n");
	#endif

	return 0;
}

Measured memory_bytes: 128
n=int(input())
#a,b=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

thre=10**18

if al.count(0)>=1:
    ans=0
else:
    ans=al[0]
    for i in range(1,n):
        ans=ans*al[i]
        if ans >thre:
            ans=-1
            break
print(ans)



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

using namespace std;

void Main() {
    string S;
    cin >> S;
    cout << "2018" << S.substr(4, 9) << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=0; i<(int)n; i++)
ll power(ll x,ll n);
bool isprime(ll n);
ll mod=1e9+7;


void test_case()
{
    string s,t;
    cin>>s>>t;
    int n=s.size(),cnt=0;
    for(int i=0;i<n;i++)
        if(s[i]!=t[i])
            cnt++;
    cout<<cnt;
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}
ll power(ll x,ll n)
{
    ll ans=1;
    while(n>0) {
        if(n&1)
            ans*=x;
        n>>=1;
        x*=x;
    }
    return ans;
}

bool isprime(ll n)
{
    if(n==2 || n==3)
        return true;
    if(n<=1 || n%2==0 || (n%6!=1 && n%6!=5))
        return false;
    for(int i=3;i*i<=n;i+=2) {
        if(n%i==0)
            return false;
    }
    return true;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    if(n&1){
        rep(i,1,m+1){
            cout<<i<<' '<<n-i<<endl;
        }
    }else{
        int count = 0;
        int a = 1, b = n/2;
        while(a<b&&count<m){
            cout<<a%(n+1)<<' '<<b<<endl;
            a++;b--;
            count++;
        }
        int c = n/2 + 1, d = n-1;
        while(c<d&&count<m){
            cout<<c<<' '<<d<<endl;
            c++;d--;
        }
    }
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<set>
typedef long long ll;
using namespace std;

int main(void) {
	int n;
	cin >> n;
	ll m = 1000000007;
	ll ans = 1;
	for (ll i = 1;i <= n;i++)ans = (ans*i) % m;
	cout << ans << endl;
	/*ll n, m, ans = 0;
	cin >> n >> m;
	if (n == m) {
		if (n == 1) {
			cout << ans << endl;
		}
		else {
			while (m >= 2) {
				ans++;
				m -= 2;
			}
			cout << ans << endl;
		}
	}
	else {
		if (n > m) {
			if (m == 1) {
				cout << ans << endl;
			}
			else {
				while (m >= 2) {
					ans++;
					m -= 2;
				}
				cout << ans << endl;
			}
		}
		else {
			while (true) {
				n--;
				m -= 2;
				ans++;
				if (m < 2) {
					cout << ans << endl;
					return 0;
				}
				if (n == 0)break;
			}
			while (m >= 4) {
				m -= 4;
				ans++;
			}
			cout << ans << endl;
		}
	}*/
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

vi color;
vll a;
vector<priority_queue<ll, vll, greater<ll>>> qs;
vector<vi> G;

void dfs(int v, int c){
    color[v] = c;
    qs[c].push(a[v]);

    for(auto& nv : G[v]){
        if(color[nv] != -1) continue;
        dfs(nv, c);
    }
}

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

    int n, m; cin >> n >> m;
    a = vll(n); for(auto& e : a) cin >> e;

    if(m == n - 1){
        cout << 0 << endl;
        return 0;
    }
    if(2 * m < n - 2){
        cout << "Impossible" << endl;
        return 0;
    }

    G = vector<vi>(n);
    rep(loop, m){
        int a, b; cin >> a >> b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    color = vi(n, -1);
    int N = 0;
    qs = vector<priority_queue<ll, vll, greater<ll>>>(n);
    rep(v, n){
        if(color[v] != -1) continue;
        dfs(v, N);
        N++;
    }

    ll res = 0;
    vll tbl;
    rep(i, N){
        res += qs[i].top(); qs[i].pop();
        while(qs[i].size()){
            tbl.emplace_back(qs[i].top()); qs[i].pop();
        }
    }
    sort(_all(tbl));

    rep(i, 2 * (n - 1 - m) - N){
        res += tbl[i];
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 12404
#include<bits/stdc++.h>
#define FOR(a,b,n) for(a=b;a<=(n);a++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define fs first
#define sc second

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

int a[12];
int main()
{
   int w;
   cin>>w;
   a[0]=1;
   for(int i=0;i<11;i++) a[i+1]=a[i]*3;

   int i[12];
   FOR(i[0],-1,1) FOR(i[1],-1,1) FOR(i[2],-1,1) FOR(i[3],-1,1) FOR(i[4],-1,1)
   FOR(i[5],-1,1) FOR(i[6],-1,1) FOR(i[7],-1,1) FOR(i[8],-1,1) FOR(i[9],-1,1)
   FOR(i[10],-1,1) FOR(i[11],-1,1){
         int sum=0;
         rep(j,12){
            sum+=a[j]*i[j];
         }
         if(sum==w){
            int j=11;
            while(i[j]==0) j--;
            for(;j>=0;j--){
               if(i[j]==-1) cout<<'-';
               else if(i[j]==0) cout<<'0';
               else cout<<'+';
            }
         }
   }
   cout<<endl;
   return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define L 3003

string s, t;
int n, m;
int pp[L][L], qq[L][L], rr[L][L];
int memo[L][L];

int dfs(int i, int j) {
  if(i >= n || j >= m) return 0;
  if(memo[i][j] != -1) {
    return memo[i][j];
  }
  int r0 = dfs(i+1, j), r1 = dfs(i, j+1), r;
  int p0, q0, rr0 = 0;
  if(r0 < r1) {
    p0 = i; q0 = j+1; r = r1;
  } else {
    p0 = i+1; q0 = j; r = r0;
  }
  if(s[i] == t[j]) {
    int r2 = dfs(i+1, j+1) + 1;
    if(r < r2) {
      r = r2; rr0 = 1; p0 = i+1; q0 = j+1;
    }
  }
  pp[i][j] = p0; qq[i][j] = q0; rr[i][j] = rr0;
  return memo[i][j] = r;
}

int main() {
  cin >> s >> t;
  n = s.length(); m = t.length();
  rep(i, n+1) rep(j, m+1) memo[i][j] = -1;
  dfs(0, 0);
  int i = 0, j = 0;
  while(i < n && j < m) {
    int i0 = pp[i][j], j0 = qq[i][j];
    if(rr[i][j]) {
      printf("%c", s[i]);
    }
    i = i0; j = j0;
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 141568
fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();

    let mut max: i32 = a;
    if b > max {
        max = b
    }
    if c > max {
        max = c
    }

    if max == a {
        println!("{}", b+c);
    } else if max == b {
        println!("{}", a+c);
    } else {
        println!("{}", a+b);
    }
}



use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed toparse token")
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  if(n * 2 >= m) {
    ans = m / 2;
  } else {
    m -= n * 2;
    ans = n;
    ans += m / 4;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n;
	cin>>n;
	vl v(n);
	rep(i, n) cin>>v[i];
	ll ans = 0LL;
	ll m = 1LL;
	rep(i, n){
		if(v[i] == m) {
			m++;
			continue;
		}
		else{
			ans += (v[i]-1)/m;
			m = max(m, 2LL);
		}
		//cout<<" "<<v[i]<<" "<<m<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        ans += __gcd(i, __gcd(j, k));
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3652
A, B = map(int, input().split())
score = 0
score_a = A * 2
score_b = B * 2
a = A
b = B

while True :
    score_b -= a
    if score_b <= 0 :
        break
    else :
        score += 1
        if score_b < b :
            b = score_b
    
    score_a -= b
    if score_a <= 0 :
        break
    else :
        score += 1
        if score_a < a :
            a = score_a
            
ans = score

a = A
b = B
score = 0
score_a = a * 2
score_b = b * 2

while True :
    score_b -= a
    if score_b <= 0 :
        break
    else :
        score += 1
        if score_b < b and A < B :
            b = score_b
        elif score_b < b and A > B :
            if score_b % 2 == 0 :
                b = score_b // 2
            else :
                b = score_b // 2 + 1
    
    score_a -= b
    if score_a <= 0 :
        break
    else :
        score += 1
        if score_a < a and A > B :
            a = score_a
        elif score_a < a and A < B:
            if score_a % 2 == 0 :
                a = score_a // 2
            else :
                a = score_a // 2 + 1

if ans < score :
    print(ans)
else :
    print(score)


Measured memory_bytes: 5604