akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
using namespace std;

bool prime[1000000];
int main(){
	int n;
	while (cin >> n, n){
		long long sum = 0;
		int cntprime = 0;
		for (int i = 2;; i++){
			if (prime[i]) continue;
			cntprime++;
			sum += i;
			if (cntprime == n){
				printf("%d\n", sum);
				break;
			}
			for (int j = 2; i*j < 1000000; j++){
				prime[i * j] = true;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2120
fn main() {
    let sa = read::<String>().chars().collect::<Vec<_>>();
    let sb = read::<String>().chars().collect::<Vec<_>>();
    let sc = read::<String>().chars().collect::<Vec<_>>();
    let mut v = vec![sa, sb, sc];

    let mut turn = 0;
    loop {
        if v[turn].len() == 0 {
            break;
        }
        let x = v[turn].remove(0);
        match x {
            'a' => turn = 0,
            'b' => turn = 1,
            'c' => turn = 2,
            _ => panic!(),
        }
    }
    match turn {
        0 => println!("A"),
        1 => println!("B"),
        _ => println!("C"),
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int>v1(n);
	vector<int>v2(n-1);
	for(int i=0;i<n-1;++i){
		cin>>v2[i];
		v1[v2[i]-1]++;
	}
	for(int i=0;i<n;++i){
		cout<<v1[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.length();i++)
       sum+=s[i]-'0';
    if(sum%9==0)
       cout<<"Yes\n";
    else
       cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T int
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
auto clk=clock();
 
ll mexp(ll a, ll b, ll m){
    ll ans=1;
    a%=m;
    while(b){
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}

int main(){
    IOS
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int h, n;
    cin >> h >> n;
    ll sum = 0;
    int x;
    FOR(i,1,n){
        cin >> x;
        sum += x;
    }
    if(sum >= h){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    cerr<<endl<<endl<<"Time: "<<fixed<<setprecision(12)<<(long double)(clock()-clk)/CLOCKS_PER_SEC<<" ms"<<endl<<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
//2つの数値の最大公約数を求める問題
int gcd(int a, int b);
int main(){
	int a, b;
	cin >> a >> b;
	cout << gcd(a, b) << endl;
}
int gcd(int a, int b){//a >= b ならb, a % bの最大公約数がa,bの最大公約数
	if(a % b != 0) return gcd(b, a % b);
	return b;
}



Measured memory_bytes: 3092
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int n;
	cin >> n;
	ll ans = 1145148101919;
	REP(i, n) {
		ll a;
		cin >> a;
		a = countpow(a, 2);
		if (a < ans)ans = a;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) 
{
  int a,b;
  cin >> a >> b;
  if(a > b) { cout << "a > b" << endl; }
  else if(a < b) { cout << "a < b" << endl; }
  else { cout << "a == b" << endl; }
}




Measured memory_bytes: 3088
S = input()

len_s = len(S)
bases = ('A', 'C', 'G', 'T')

ans = 0
cnt = 0

for i in range(len_s):
  if S[i] in bases:
    cnt += 1
  else:
    ans = max(ans, cnt)
    cnt = 0
if cnt > 0:
  ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 3060
s = gets.to_i
digits = []
original_s = s
begin
  digits.unshift s % 10
  s /= 10
end while s > 0
(4 - digits.length).times do
  digits.unshift 0
end
first = digits[0] * 10 + digits[1]
second = digits[2] * 10 + digits[3]
if first > 0 && first < 13 && second > 0 && second < 13
  puts "AMBIGUOUS"
elsif first > 0 && first < 13
  puts "MMYY"
elsif second > 0 && second < 13
  puts "YYMM"
else
  puts "NA"
end

Measured memory_bytes: 1788
MOD = 10**9 + 7


def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter()
    for a in A:
        s = "{:0>63b}".format(a)[::-1]
        for i, s in enumerate(s):
            c[i] += int(s)
    ans = sum(A) * (N-1)
    for k, v in c.items():
        if v > 1:
            ans -= 2*(2**k)*(v*(v-1)//2)
    print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 115620
#include<iostream>
#include<vector>

using std::cin;
using std::cout;
using std::endl;

// Range Minimum, Range Add
template<class T>
struct lazy_segment_tree{
  std::vector<T> data,lazy;
  T identity1,identity2;
  int n;
  lazy_segment_tree(){}
  lazy_segment_tree(int sz,T ide1,T ide2):identity1(ide1),identity2(ide2){
    n = 1;
    while(n<sz)n<<=1;
    data.resize(2*n-1,identity1);
    lazy.resize(2*n-1,identity2);
  }
  lazy_segment_tree(std::vector<T> const& vec,T ide1,T ide2):identity1(ide1),identity2(ide2){
    int sz = vec.size();
    n = 1;
    while(n<sz)n<<=1;
    data.resize(2*n-1);
    lazy.resize(2*n-1,identity2);
    for(int i=0;i<sz;++i){
      data[i+n-1] = vec[i];
    }
    for(int i=n-2;i>=0;--i){
      data[i] = std::min(data[2*i+1],data[2*i+2]);
    }
  }
  void eval(int k){
    if(lazy[k]==identity2)return;
    if(k<n-1){
      lazy[2*k+1] += lazy[k];
      lazy[2*k+2] += lazy[k];
    }
    data[k] += lazy[k];
    lazy[k] = identity2;
  }
  void add_impl(int a,int b,T x,int k,int l,int r){
    eval(k);
    if(a<=l&&r<=b){
      lazy[k] += x;
      eval(k);
    }
    else if(l<b&&a<r){
      add_impl(a,b,x,2*k+1,l,(l+r)/2);
      add_impl(a,b,x,2*k+2,(l+r)/2,r);
      data[k] = std::min(data[2*k+1],data[2*k+2]);
    }
  }
  T query_impl(int a,int b,int k,int l,int r){
    eval(k);
    if(r<=a||b<=l){
      return identity1;
    }
    if(a<=l&&r<=b){
      return data[k];
    }
    else{
      T vl = query_impl(a,b,2*k+1,l,(l+r)/2);
      T vr = query_impl(a,b,2*k+2,(l+r)/2,r);
      return std::min(vl,vr);
    }
  }
  void add(int a,int b,T x){
    add_impl(a,b,x,0,0,n);
  }
  T query(int a,int b){
    return query_impl(a,b,0,0,n);
  }
  T operator[](int i){
    return query_impl(i,i+1,0,0,n);
  }
};

signed main(){
  int n,q;
  cin>>n>>q;
  std::vector<int> a(n);
  lazy_segment_tree<int> data(a,1<<29,0);
  
  while(q--){
    int c;cin>>c;
    if(c==0){
      int s,t,x;cin>>s>>t>>x;
      data.add(s,t+1,x);
    }else{
      int s,t;cin>>s>>t;
      cout<< data.query(s,t+1) <<endl;
    }
    
  }
}


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

int main(){
  int N, N2;
  cin >> N;
  N2 = 1 << N;

  vector<int> S(N2);
  for (int i = 0; i < N2; i++) cin >> S[i];
  sort(S.begin(), S.end());

  vector<int> s;
  s.push_back(S.back());
  S.back() = -1;

  for(int i = 0; i < N; i++){
    vector<int> p = s;
    sort(p.begin(), p.end());
    
    int Si = N2 - 1;
    while (p.size() > 0 && Si >= 0){
      if (S[Si] == -1){
        --Si;
        continue;
      }
      if (S[Si] < p.back()){
        s.push_back(S[Si]);
        p.pop_back();
        S[Si] = -1;
      }
      --Si;
    }
    if (p.size() > 0){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

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

#ifndef DEBUG
#define DEBUG false
#endif

#define REP(t,i,a,b) for(t i = a; i < b; ++i)

typedef long long ll;

using std::cin;
using std::cout;
using std::endl;
using std::vector;

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

    int n;
    cin >> n;
    vector<long> a(n);
    vector<long> b(n-1);
    REP(int, i, 0, n-1) cin >> b[i];

    a[n-1] = b[n-2];
    for(int i=n-2; i>=1; --i) {
        a[i] = b[i-1];
        if (a[i] > b[i]) a[i] = b[i];
    }
    a[0] = b[0];

    long score = 0;
    REP(int, i, 0, n) {
        if(DEBUG) cout << a[i] << endl;
        score += a[i];
    }
    cout << score << endl;

    return 0;
}



Measured memory_bytes: 256
using System;

namespace abc144_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] list = Console.ReadLine().Split(' ');

            int a = int.Parse(list[0]);
            int b = int.Parse(list[1]);

            int ans = -1;

            if (1<= a&& a<= 9
                && 1 <= b && b <= 9)
            {
                ans = a * b;
            }





            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>

int main(void)
{
  int n;
  scanf("%d",&n);

  int i,j;
  for(i=0;i<=n/4;i++){
    for(j=0;j<=(n-4*i)/7;j++)
      if((4*i+7*j)==n){
        printf("Yes\n");


	return 0;
      }
  }

  printf("No\n");
  return 0;
}

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

using ll = long long;

int main()
{
    int N, K; cin >> N >> K;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
    }
    set<int> sx(X.begin(), X.end());
    set<int> sy(Y.begin(), Y.end());
    map<int,int> x2i, i2x, y2i, i2y;
    
    {
        int i = 0;
        for (auto it = sx.begin(); it != sx.end(); it++) {
            x2i[*it] = i;
            i2x[i] = *it;
            i++;
        }
    }
    {
        int i = 0;
        for (auto it = sy.begin(); it != sy.end(); it++) {
            y2i[*it] = i;
            i2y[i] = *it;
            i++;
        }
    }
    vector<vector<int>> c(sx.size(), vector<int>(sy.size(), 0));
    for (int i = 0; i < N; i++) {
        c[x2i[X[i]]][y2i[Y[i]]]++;
    }
    vector<vector<int>> s(sx.size(), vector<int>(sy.size(), 0));
    for (int i = 0; i < sx.size(); i++) {
        for (int j = 0; j < sy.size(); j++) {
            s[i][j] = c[i][j];
            if (i > 0) s[i][j] += s[i-1][j];
            if (j > 0) {
                s[i][j] += s[i][j-1];
                if (i > 0) {
                    s[i][j] -= s[i-1][j-1];
                }
            }
        }
    }

    ll ans = LLONG_MAX;
    for (int ixl = 0; ixl < sx.size()-1; ixl++) {
        for (int ixr = ixl+1; ixr < sx.size(); ixr++) {
            for (int iyl = 0; iyl < sy.size()-1; iyl++) {
                for (int iyr = iyl+1; iyr < sy.size(); iyr++) {
                    int pts = s[ixr][iyr];
                    if (ixl > 0) pts -= s[ixl-1][iyr];
                    if (iyl > 0) {
                        pts -= s[ixr][iyl-1];
                        if (ixl > 0) {
                            pts += s[ixl-1][iyl-1];
                        }
                    }
                    if (pts >= K) {
                        int w = i2x[ixr] - i2x[ixl];
                        int h = i2y[iyr] - i2y[iyl];
                        ll a = (ll)w * h;
                        if (a < ans) ans = a;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


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

int n, s, cnt, a[100005];
int main()
{
	int i;
//	freopen ("input.txt", "r", stdin);
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf ("%d", &a[i]);
	}
	for (i = 1; i <= n; i++) {
		if (a[a[i]] == i) cnt++;
	}
    cout << cnt / 2 << endl;
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define d1(x) cout<<#x<<" "<<x<<endl;
#define d2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define d2i(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve(){

  //  ll ans=0,n,m,q;
   // cin>>n>>m>>q;
   double n;
   cin>>n;
 //  n/=100.0;
    ll k=0;
    double f=1.01;
   ll c=100;
    while(c<n){
        c=c+c*0.01;
        k++;
    }

 cout<<k;
}


int main(){
   ll t=1;
   //cin>>t;
   while(t--){
    solve();
    cout<<endl;
   }
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int X,Y;cin >> X >> Y;
    bool ans = false;
    rep(i,X+1) {
        int tmp = 4*i + 2*(X-i);
        if(tmp == Y)ans = true;
    }
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3540
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt() ;
		HashMap<Integer, Integer> hm = new HashMap<>();
		int tmp = 0;
		for(int i = 0; i < n; i++) {
			tmp = sc.nextInt();
			if(hm.containsKey(tmp)) {
				hm.put(tmp, hm.get(tmp) + 1);
			}else {
				hm.put(tmp, 1);
			}
		}
		sc.close();
		int count = 0;
		for(int i: hm.keySet()) {
			if(hm.get(i) > i) {
				count = count + (hm.get(i) - i);
			}else if(hm.get(i) < i) {
				count = count + hm.get(i);
			}
		}

		System.out.println(count);
	}
}

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

int main() {
  string a, b;
  cin >> a >> b;
  if (a.at(0) == b.at(2) && a.at(1) == b.at(1) && a.at(2) == b.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# 約数列挙
def make_divisors(value):
    divisors = []
    # int(n ** 0.5) は valueの平方根（小数点以下切り捨て）
    for i in range(1, int(value ** 0.5) + 1):
        if value % i == 0:
            divisors.append(i)              # 約数の下半分を追加
            if i != value // i:             # iが中央値なら下記を飛ばす
                divisors.append(value//i)   # 約数の上半分を追加
    # ソートする場合は下記コメントをはずす
    # divisors.sort()
    return divisors
 
N = int(input())
a = list(map(int, input().split()))
memo = [0] * N
anser = []
for i in range(N - 1, -1, -1):
    if (a[i] == 1 and memo[i] == 0) or (a[i] == 0 and memo[i] == 1):
        anser.append(i + 1)
        # iの約数を抽出
        divisors = make_divisors(i + 1)
        for j in divisors:
            memo[j - 1] = (memo[j - 1] + 1) % 2
 
print(len(anser))
if len(anser) >=  1:
    print(" ".join(map(str, anser)))

Measured memory_bytes: 86896
#include <iostream>

int memo[40][40];

using namespace std;

int fanc(int x, int y)
{
	if (x < 0 || y < 0){
		return (0);
	}
	if (memo[x][y] != -1){
		return (memo[x][y]);
	}
	if (x == 0 && y == 0){
		return (1);
	}
	
	
	memo[x][y] = fanc(x - 1, y) + fanc(x, y - 1);
	return (memo[x][y]);
}

int main(void)
{
	int x, y;
	int n;
	
	while (1){
		for (int i = 0; i < 40; i++){
			for (int j = 0; j < 40; j++){
				memo[i][j] = -1;
			}
		}
		
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		cin >> n;
		for (int i = 0; i < n; i++){
			int x, y;
			cin >> x >> y;
			memo[x - 1][y - 1] = 0;
		}
		
		cout << fanc(x - 1, y - 1) << endl;
		
	}
	return (0);
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
int map[10][105];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1;i <= 2;i++)
		for (int j = 1;j <= n;j++)
			scanf("%d", &map[i][j]);
		for (int j = n;j >= 1;j--)
			map[2][j] += map[2][j + 1];
	int maximum = 0;
	int sum = 0;
	for (int i = 1;i <= n;i++)
	{
		int tmp = sum + map[1][i];
		tmp += map[2][i];
		maximum = max(maximum, tmp);
		sum += map[1][i];
	}
	cout << maximum << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
arr = list(map(int, input().split()))
if N == 2:
    print(0)
    sys.exit(0)


def update(start):
    dic = dict()
    for i in range(start, N, 2):
        if arr[i] in dic:
            dic[arr[i]] += 1
        else:
            dic[arr[i]] = 1
    return sorted(dic.items(), key=lambda ele: ele[1], reverse=True)


tuple_1 = update(0)
tuple_2 = update(1)

what_1, mx_1 = tuple_1[0]
what_2, mx_2 = tuple_2[0]

if what_1 == what_2:
    if len(tuple_1) == 1 and len(tuple_2) == 1:
        print(N//2)
    elif len(tuple_1) == 1:
        print(N//2 - tuple_2[1][1])
    elif len(tuple_2) == 1:
        print(N//2 - tuple_1[1][1])
    else:
        ans1 = N - tuple_1[0][1] - tuple_2[1][1]
        ans2 = N - tuple_1[1][1] - tuple_2[0][1]
        print(min(ans1, ans2))
else:
    print(N - mx_1 - mx_2)


Measured memory_bytes: 19932
import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
quad = [i for i in ac if ac[i] >= 4]
if quad:
    ans = max(quad) ** 2
else:
    ans = 0
twice = sorted([i for i in ac if ac[i] >= 2])
if len(twice) >= 2:
    ans = max(ans, twice[-1] * twice[-2])
print(ans)

Measured memory_bytes: 18600
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 *1000 + 7;
const LL LINF = INF * (LL)INF;

typedef pair<vector<PII>, LL> Q;

const int MAX = 100100;
const int MIN = 3000;

LL A[MAX];

bool isPrime(int x)
{
	for (int i = 2; i*i <= x; i++)
	{
		if (x % i == 0) return false;
	}
	return true;
}

VI pr;
Q get(LL x)
{
	vector<PII> a;
	LL b;
	FOR (i, 0, SZ(pr))
	{
		int y = pr[i];
		if (x % y == 0)
		{
			int cnt = 0;
			while(x % y == 0)
			{
				x /= y;
				cnt++;
			}

			cnt %= 3;
			if (cnt) a.PB(MP(y, cnt));
		}
	}

	b = x;

	return MP(a, b);
}

LL sq(LL x)
{
	double m = x * (double) x;
	if (m > 1e18) return LINF;
	return x * x;
}

Q inverse(Q a)
{
	FOR (i, 0, SZ(a.first))
	{
		a.first[i].second = 3 - a.first[i].second;
	}

	a.second = sq(a.second);
	return a;
}

map<Q, int> M;

int main()
{
	//freopen("in.txt","r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	/*FOR (i, 100000, 100000+100)
	{
		if (isPrime(i)) cout<<i<<endl;
	}

	return 0;*/


	FOR (i, 2, MIN)
	{
		if (isPrime(i)) pr.PB(i);
	}

	int n;
	scanf("%d", &n);

	FOR (i, 0, n)
	{
		scanf("%lld", &A[i]);
	}

	FOR (i, 0, n)
	{
		M[get(A[i])]++;
		/*Q q = get(A[i]);
		cout<<A[i]<<": ";
		FOR (i, 0, SZ(q.first))
		{
			cout<<"("<<q.first[i].first<<' '<<q.first[i].second<<") ";
		}
		cout<<": "<<q.second<<endl;*/
	}

	int res = 0;

	ITER(it, M)
	{
		const Q& cur = it->first;
		int cnt = it->second;

		Q inv = inverse(cur);
		map<Q, int>::iterator iter = M.find(inv);

		if (iter == M.end())
		{
			res += cnt;
			continue;
		}

		cnt = max(cnt, iter->second);

		if (cur.first.empty() && cur.second == 1) cnt = min(cnt, 1);

		res += cnt;
		it->second = 0;
		iter->second = 0;
	}

	cout<<res<<endl;

}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    pair<int, int> xy[n];
    for (int i = 0, x, y; i < n; i++) {
        cin >> x >> y;
        xy[i] = make_pair(x, y);
    }
    sort(xy, xy+n);
    double sum = 0;
    int cnt = 0;
    do {
        cnt++;
        double t;
        for (int i = 1; i < n; i++) {
            t = pow(xy[i - 1].first - xy[i].first, 2) + pow(xy[i - 1].second - xy[i].second, 2);
            sum += sqrt(t);
        }
    } while (next_permutation(xy, xy+n));
    sum /= cnt;
    cout << fixed << setprecision(10) << sum << endl;
}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
	return (b ? gcd(b, a % b) : a);
}

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

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

    string k = "keyence";

    bool flg = false;
    for(int i = 0; i <= k.size(); i++) {
	string a = "";
	string b = "";
	for(int j = 0; j < i; j++) a += k[j];
	for(int j = i; j < k.size(); j++) b += k[j];

	bool be = true, af = true;
	for(int j = 0; j < a.size(); j++) if(a[j] != s[j]) be = false;
	for(int j = 0; j < b.size(); j++) if(b[j] != s[s.size() - b.size() + j]) af = false;
	
	if(be && af) flg = true;
    }

    if(flg) co << "YES" << en;
    else co << "NO" << en;
    
  
    return 0;
}


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

int main (){
int N, K;
cin >>N >>K;
int x;
int r=0;  
for(int i;i<N;i++){
  cin >>x;
 r=r+min(x,K-x)  ;
   
}  
  
cout <<r*2<< endl ;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int N;
	int l[100010], r[100010];
	cin >> N;
	REP(i, 0, N) cin >> l[i] >> r[i];

	int cnt = 0;
	REP(i, 0, N) {
		cnt += (r[i] - l[i] + 1);
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fr(i,p,n) for(ll i=p;i<n;i++)
#define fr1(i,p,n) for(ll i=p;i>=n;i--)
#define pb push_back
#include <stdio.h>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define precise cout << std::setprecision(10) << std::fixed;
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n],b[n],c[n];
        ll dp[3][n];
        fr(i,0,n) cin>>a[i]>>b[i]>>c[i];
        dp[0][0]=a[0];
        dp[1][0]=b[0];
        dp[2][0]=c[0];
        fr(i,1,n)
        {
            dp[0][i]=max(dp[1][i-1]+a[i],dp[2][i-1]+a[i]);
            dp[1][i]=max(dp[0][i-1]+b[i],dp[2][i-1]+b[i]);
            dp[2][i]=max(dp[0][i-1]+c[i],dp[1][i-1]+c[i]);
        }
        cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<endl;
    }
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
//
	
	string s;
	cin >> s;
	int s1 = 0;
	int s2 = 0;
	int s3 = 0;
	rep0(i, 2) {
		if (s[i] == 'a') {
			++s1;
		}
		else if (s[i] == 'b') {
			++s2;
		}
		else if (s[i] == 'c') {
			++s3;
		}
	}
	cout <<((s1 == 1 && s2 == 1 && s3 == 1) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		vi a(n);
		rep(i,n)
			cin>>a[i];
		int res=0;
		for(int i=n;i--;)
			for(int j=0;j<i;j++)
				if(a[j]>a[j+1]){
					swap(a[j],a[j+1]);
					res++;
				}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,d,x;
    scanf("%d %d %d",&r,&d,&x);
    int z=(r*x)-d;
    printf("%d\n",z);
    for(int i=1;i<=9;i++)
    {
        int y=r*z-d;
        printf("%d\n",y);
        z=y;
    }
    return 0;
}


Measured memory_bytes: 256
N, K = list(map(int,input().split()))
S = input()

n = 1
c = []
if S[0]=='0': c.append(0)
for i in range(1,N):
    if S[i]!=S[i-1]:
        c.append(n)
        n=1
    else:
        n+=1
c.append(n)
if S[-1]=='0': c.append(0)

t = sum(c[:2*K+1])
m = t
for i in range(2*K+1, len(c), 2):
    t += c[i] + c[i+1] - c[i-(2*K+1)] - c[i+1-(2*K+1)]
    m = max(m,t)

print(m)


Measured memory_bytes: 4468
#include <cstdio>
#include <string>
#include <math.h>

int main(void) {
	int N, D, X;
	scanf("%d", &N);
	scanf("%d %d", &D, &X);

	int A2;
	double d2 = D -1;
	int sum = 0;

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A2);

		sum += floor(d2 / A2) + 1;
	}
	sum += X;
	
	printf("%d", sum);

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
	char str[1001], odr[8], rev[1001], rpl[1001];
	int i, j, k, q, a, b;
	scanf("%s", str);
	scanf("%d", &q);
	for (i=0; i<q; i++) {
		scanf("%s", odr);
		if (strcmp("print", odr) == 0) {
			scanf("%d%d", &a, &b);
			for (j=0; j<b-a+1; j++) printf("%c", str[a+j]);
			puts("");
		}
		else if (strcmp("reverse", odr) == 0) {
			scanf("%d%d", &a, &b);
			for (j=0; j<b-a+1; j++) rev[j] = str[a+j];
			for (j--, k=0; j>=0; j--, k++) str[a+k] = rev[j];
		}
		else if (strcmp("replace", odr) == 0) {
			scanf("%d%d", &a, &b);
			scanf("%s", rpl);
			for (j=0; j<b-a+1; j++) str[a+j] = rpl[j];
		}
	}
	return 0;
}

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

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

	vector<int> l(q);
	vector<int> r(q);

	for (int i = 0; i < q; i++)
	{
		cin >> l[i] >> r[i];
	}

	vector<int> hoge(n+1);

	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'A' && s[i + 1] == 'C') {
			hoge[i + 1] = hoge[i] + 1;
		}
		else
		{
			hoge[i + 1] = hoge[i];
		}
		//cout << hoge[i] << ", ";
	}
	//cout << endl;

	for (int i = 0; i < q; i++)
	{
		cout << hoge[r[i]-1] - hoge[l[i]-1] << endl;
	}
}

Measured memory_bytes: 2176
nb = int(input())
liste = [int(x) for x in input().split()]
compteur = 0
for loop in range(nb-2):
    if (liste[loop+1]>liste[loop] and liste[loop+1]<liste[loop+2]) or (liste[loop+1]<liste[loop] and liste[loop+1]>liste[loop+2]):
        compteur +=1
print(compteur)


Measured memory_bytes: 9116
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        x: i64,
    };
    for a in -1000..1000i64 {
        let aa = a.pow(5);
        for b in -1000..1000i64 {
            if aa - b.pow(5) == x {
                println!("{} {}", a, b);
                return;
            }
        }
    }
}


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

using i_i = pair<int, int>;

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int H, W, M;
set<i_i> st;

void input() {
    cin >> H >> W >> M;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        st.insert({a, b});
    }
}

void solve() {
    map<int, int> mph, mpw;
    int hmaxval = 0;
    int wmaxval = 0;
    vector<int> hmax, wmax;
    for (auto tmp : st) {
        chmax(hmaxval, ++mph[tmp.first]);
        chmax(wmaxval, ++mpw[tmp.second]);
    }
    for (auto tmp : mph) {
        if (hmaxval == tmp.second) hmax.push_back(tmp.first);
    }
    for (auto tmp : mpw) {
        if (wmaxval == tmp.second) wmax.push_back(tmp.first);
    }
    int ANS = hmaxval + wmaxval - 1;
    for (auto h : hmax) {
        for (auto w : wmax) {
            if (st.find({h, w}) == st.end()) {
                ANS++;
                cout << ANS << endl;
                return;
            }
        }
    }
    cout << ANS << endl;
}

int main() {
    input();
    solve();
    return 0;
}

Measured memory_bytes: 49576
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
	int n;
	std::cin >> n;
	std::vector<int> vec(n);
	for (auto &v : vec) std::cin >> v;
	int q; std::cin >> q;
	for (auto i = 0; i < q; ++i) {
		int k;
		std::cin >> k;
		std::cout << std::lower_bound(vec.begin(), vec.end(), k) - vec.begin() << ' ' <<  std::upper_bound(vec.begin(), vec.end(), k) - vec.begin() << std::endl;
	}
}


Measured memory_bytes: 3100
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main() {
    val (h, w, k) = intList()
    val hw = Array(h) { readLine()?.toCharArray()?.map { it.toString() }?.toTypedArray() ?: return }
    val emptyLines = Array(h) {
        hw[it].all { it == "." }
    }
    var index = 1
    0.until(h).forEach { i ->
        0.until(w).forEach { j ->
            if (hw[i][j] == "#") {
                // 左右
                val kName = index.toString()
                hw[i][j] = kName
                var l = 1
                while (j - l >= 0) {
                    if (hw[i][j - l] == ".") {
                        hw[i][j - l] = kName
                    } else {
                        break
                    }
                    l++
                }
                var r = 1
                while (j + r < w) {
                    if (hw[i][j + r] == ".") {
                        hw[i][j + r] = kName
                    } else {
                        break
                    }
                    r++
                }

                // 上下
                var u = 1
                while (i - u >= 0) {
                    if (emptyLines[i - u] && hw[i - u][j] == ".") {
                        hw[i - u][j] = kName
                        1.until(l).forEach {
                            hw[i - u][j - it] = kName
                        }
                        1.until(r).forEach {
                            hw[i - u][j + it] = kName
                        }
                    } else {
                        break
                    }
                    u++
                }
                var d = 1
                while (i + d < h) {
                    if (emptyLines[i + d] && hw[i + d][j] == ".") {
                        hw[i + d][j] = kName
                        1.until(l).forEach {
                            hw[i + d][j - it] = kName
                        }
                        1.until(r).forEach {
                            hw[i + d][j + it] = kName
                        }
                    } else {
                        break
                    }
                    d++
                }
                index++
            }
        }
    }
    buildString {
        hw.forEach {
            appendln(it.joinToString(" "))
        }
    }.let {
        println(it.trimIndent())
    }
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, sumtop;

struct T {
  int top;
  int mn;
};

bool cmp1(T a, T b) {
  return a.mn > b.mn;
}

bool cmp2(T a, T b) {
  return a.top - a.mn > b.top - b.mn;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<T> a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int top = 0, mn = 0;
    for (auto &ch : s) {
      if (ch == '(') {
        top++;
      } else {
        top--;
      }
      mn = min(mn, top);
    }
    if (top >= 0) {
      a.push_back({top, mn});
    } else {
      b.push_back({top, mn});
    }
    sumtop += top;
  }
  if (sumtop != 0) {
    cout << "No\n";
    return 0;
  }
  sort(a.begin(), a.end(), cmp1);
  sort(b.begin(), b.end(), cmp2);
  int cur = 0;
  for (auto &it : a) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  for (auto &it : b) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  cout << "Yes\n";
  return 0;
}


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

using namespace std;
typedef long long LL;
const int maxn = 1e5+15;
LL dp[maxn][2],a[maxn];
int n;
int main(){
    cin >> n;
    for(int i = 1;i <= n; ++i) cin >> a[i];
    dp[2][1] = -a[1]-a[2];
    dp[2][0] = a[1]+a[2];
    for(int i = 3;i <= n; ++i){
        dp[i][1] = max(dp[i-1][1]+a[i-1]-(-a[i-1]+a[i]),dp[i-1][0]-a[i-1]-(a[i-1]+a[i]));
        dp[i][0] = max(dp[i-1][1]+a[i-1]+(-a[i-1]+a[i]),dp[i-1][0]-a[i-1]+(a[i-1]+a[i]));
        //cout << dp[i][1] << " " <<dp[i][0] << endl;
    }
    cout << max(dp[n][1],dp[n][0]) << '\n';
    return 0;
}




Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

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

	boolean check(TreeSet<int[]> C, int[] S) {
		int[] Sl = C.lower(S);
		if (Sl != null && Sl[1] < S[1]) {
			return true;
		} else {
			return false;
		}
	}

	@SuppressWarnings("unchecked")
	void solve(int N, int[][] S) {
		TreeSet<int[]>[] C = new TreeSet[N];
		for (int i = 0; i < N; ++i) {
			C[i] = new TreeSet<>(new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					if (o1[0] != o2[0]) {
						return Integer.compare(o1[0], o2[0]);
					} else {
						return -Integer.compare(o1[1], o2[1]);
					}
				}
			});
		}
		C[0].add(S[0]);
		int maxLen = 1;
		for (int i = 1; i < N; ++i) {
			int left = -1;
			int right = maxLen;
			while (right - left > 1) {
				int middle = (right + left) / 2;
				if (check(C[middle], S[i])) {
					left = middle;
				} else {
					right = middle;
				}
			}

			// C[left+1]???S???????????????
			if (left + 1 == maxLen) {
				C[left + 1].add(S[i]);
				++maxLen;
				continue;
			} else {
				int[] tmp = C[left + 1].floor(S[i]);
				if (tmp != null && tmp[1] == S[i][1])
					continue;
				tmp = C[left + 1].higher(S[i]);
				while (tmp != null && S[i][1] <= tmp[1]) {
					C[left + 1].remove(tmp);
					tmp = C[left + 1].higher(S[i]);
				}
				C[left + 1].add(S[i]);
			}
		}
		System.out.println(maxLen);
	}

	int nextA(int a, int M) {
		return 36969 * (a & M) + (a >> 16);
	}

	int nextB(int b, int M) {
		return 18000 * (b & M) + (b >> 16);
	}

	int nextVal(int a, int b, int C) {
		return (C & ((a << 16) + b)) % 1000000;
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int m = sc.nextInt();
			int n = sc.nextInt();
			int A = sc.nextInt();
			int B = sc.nextInt();
			if (m == 0 && n == 0 && A == 0 && B == 0)
				break;
			int[][] S = new int[m + n][3];
			for (int i = 0; i < m; ++i) {
				S[i][0] = sc.nextInt();
				S[i][1] = sc.nextInt();
				S[i][2] = sc.nextInt();
			}
			int a = A, b = B, C = ~(1 << 31), M = (1 << 16) - 1;
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < 3; ++j) {
					a = nextA(a, M);
					b = nextB(b, M);
					S[i + m][j] = nextVal(a, b, C);
				}
			}
			Arrays.sort(S, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					if (o1[0] != o2[0])
						return Integer.compare(o1[0], o2[0]);
					else if (o1[1] != o2[1]) {
						return -Integer.compare(o1[1], o2[1]);
					} else {
						return -Integer.compare(o1[2], o2[2]);
					}
				}
			});

			int[][] tmp = new int[m + n][2];
			for (int i = 0; i < m + n; ++i) {
				tmp[i][0] = S[i][1];
				tmp[i][1] = S[i][2];
			}
			solve(m + n, tmp);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 489792
e=enumerate
n,a=open(0)
n=int(n)
d=[0]+[-1e18]*n
for j,(a,i)in e(sorted((int(a),i)for i,a in e(a.split()))[::-1]):d=[max(t+a*abs(~i-j+k+n),d[k-1]+a*abs(~i+k))for k,t in e(d)]
print(max(d))

Measured memory_bytes: 73168
#include<stdio.h>

int main(void) {
	char s[4];
	char t[4];
	scanf("%s", &s);
	scanf("%s", &t);
	int c = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) {
			c++;
		}
	}
	printf("%d", c);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val mountains = parseList(sc, n)
    val result = greatViewingCount(mountains.first(), mountains)
    println(result)
}

private fun parseList(scanner: Scanner, length: Int): List<Int> {
    return (0 until length).map {
        scanner.nextInt()
    }
}

private fun greatViewingCount(threshold: Int, mountains: List<Int>): Int {
    val filteredMountains = mountains.filter { threshold <= it }
    var count: Int = 1
    filteredMountains.reduce { acc, i ->
        return@reduce if (acc <= i) {
            count++
            i
        } else {
            acc
        }
    }
    return count
}

Measured memory_bytes: 31516
#include<iostream>
using namespace std;
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B==C+D){
    cout<<"Balanced"<<endl;
  }else{
    cout<<(A+B>C+D?"Left":"Right")<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

void solve(void){
    double ans = 0;
    ll n;
    cin >> n;
    rep(i,0,n){
        double x;
        string s;
        cin >> x >> s;
        if(s == "JPY")ans+=x;
        else ans+=x*380000;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 256
p=[]
for i in range(2,10001):
        for j in range(2,int(i**0.5)+1):
            if not i%j:break
        else:p+=[i]
b=[0]*5736397
for i in range(len(p)):
    c=0
    for j in range(i,len(p)):
        c+=p[j]
        b[c]+=1
while 1:
    n=int(input())
    if n==0:break
    print(b[n])

Measured memory_bytes: 52160
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int t=N%10;
    if(t==2||t==4||t==5||t==7||t==9){
        cout << "hon";
    }
    else if(t==0 ||t==1||t==6||t==8){
        cout << "pon";
    }
    else{
        cout << "bon";
    }
}



Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
using namespace std;
int c[200005],k,n,maxx=0x7fffffff;
int main(){
	scanf("%d%d",&k,&n);
	for(int i=0;i<n;++i){
		scanf("%d",c+i);
	}
	sort(c,c+n);
	for(int i=0;i<n;++i){
		maxx=min(maxx,k-abs(i==0?k+c[i]-c[n-1]:c[i]-c[i-1]));
		maxx=min(maxx,k-abs(i==n-1?k+c[0]-c[i]:c[i+1]-c[i]));
	}
	printf("%d\n",maxx);
	return 0;
}


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

import sys
from operator import itemgetter

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

S = input()
N = len(S) + 1

A = []
s = 0
for i in range(N-2):
    if S[i] != S[i+1]:
        A.append((i+1-s, S[i], s, i+1))
        s = i + 1
A.append((N-1-s, S[-1], s, N-1))

A.sort(key=itemgetter(0), reverse=True)

B = [-1] * N
for n, s, l, r in A:
    cnt = 0
    if s == '<':
        for i in range(l, r+1):
            if B[i] == -1:
                B[i] = cnt
            cnt += 1
    else:
        for i in range(r, l-1, -1):
            if B[i] == -1:
                B[i] = cnt
            cnt += 1
print(sum(B))


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;


// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m;
string s,t;
vll a;
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> s;
	vll cnt(26,0);
	for(auto ch : s) {
		cnt[ch-'a']++;
	}
	n = s.length();
	ll ans = n*(n-1)/2 + 1;

	for(ll i=0;i<26;i++) ans -= cnt[i]*(cnt[i]-1)/2;

	cout<<ans;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}



Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    bool can=false;
    while(1){
        c-=b;
        if(c<=0){can=true;break;}
        a-=d;
        if(a<=0){can=false;break;}
    }
    if(can)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3628