akhauriyash/Code-Regression huggingface dataset:
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::*;
use proconio::input;
use proconio::marker::*;
use std::*;
use cmp::Reverse;
use collections::{BinaryHeap, HashMap};

type Remainder = (Vec<u8>, bool); // Remaining string and bool whether the string is on the left side

fn is_parindrome(bytes: &[u8]) -> bool {
    bytes.iter().eq(bytes.iter().rev())
}

fn main() {
    input! {
        sc: [(Bytes, usize)]
    }

    let mut costs = HashMap::<Remainder, usize>::new();
    let mut queue = BinaryHeap::<(Reverse<usize>, Remainder)>::new();
    for ((s, c), &on_left) in iproduct!(&sc, &[false, true]) {
        let cost = *c;
        costs
            .entry((s.clone(), on_left))
            .and_modify(|cost_prev| *cost_prev = cost.min(*cost_prev))
            .or_insert(cost);
        queue.push((Reverse(cost), (s.clone(), on_left)));
    }

    // Dijkstra on Remainder
    while let Some((Reverse(cost), (orig, on_left))) = queue.pop() {
        let reversed: Vec<_> = orig.iter().rev().copied().collect();
        sc.iter()
            .flat_map(|(dest, cost)| {
                let on_right = !on_left;
                if on_left {
                    if reversed.ends_with(&dest) {
                        return Some((&orig[dest.len()..], true, cost));
                    }
                    if dest.ends_with(&reversed) {
                        return Some((&dest[..dest.len() - orig.len()], false, cost));
                    }
                }
                if on_right {
                    if reversed.starts_with(&dest) {
                        return Some((&orig[..orig.len() - dest.len()], false, cost));
                    }
                    if dest.starts_with(&reversed) {
                        return Some((&dest[orig.len()..], true, cost));
                    }
                }
                None
            })
            .for_each(|(dest, on_left, cost_diff)| {
                let remainder = (dest.into(), on_left);
                let cost_sum = cost + cost_diff;
                if let Some(mut_v) = costs.get_mut(&remainder) {
                    if *mut_v > cost_sum {
                        *mut_v = cost_sum;
                        queue.push((Reverse(cost_sum), remainder.clone()))
                    }
                } else {
                    costs.insert(remainder.clone(), cost_sum);
                    queue.push((Reverse(cost_sum), remainder.clone()))
                }
            });
    }

    let ans = costs
        .iter()
        .filter(|&((remaining, _), _)| is_parindrome(remaining))
        .map(|(_, &cost)| cost as isize)
        .min()
        .unwrap_or(-1);

    println!("{}", ans);
}


Measured memory_bytes: 2272
class Node:
    def __init__(self,parent,left,right):
        self.parent = parent
        self.left = left
        self.right = right

    def __repr__(self):
        return "{ "+ str(self.parent) + " " + str(self.left) + " " + str(self.right) + " }"



class BinarySearchTree:
    def __init__(self,size):
        self.tree = [Node(-1,-1,-1) for i in range(size+1)]
        self.root = -1

    def add(self,key,right,left):
        self.tree[key].left = left
        self.tree[key].right = right
        self.tree[left].parent = key
        self.tree[right].parent = key 
        #print(self.tree)
        

    def calcHeight(self,next,sum):
        if next == -1:
            return sum -1
        return max(self.calcHeight(self.tree[next].left,sum+1),self.calcHeight(self.tree[next].right,sum+1))

    def calcDepth(self,next):
        #print("height",next)
        if next == -1:
            return -1
        return 1 + self.calcDepth(self.tree[next].parent)
    
    def getType(self,node):
        if node.parent == -1:
            return "root"
        elif node.right == node.left == -1:
            return "leaf"
        return "internal node"
    
    def printAll(self):
        for idx, node in enumerate(self.tree):
            if node.parent == -1:
                self.root = idx
                break
        self.tree.pop()
        for idx, node in enumerate(self.tree):
            parent = node.parent
            sibling = self.tree[node.parent].left
            if sibling == idx:
                sibling = self.tree[node.parent].right
            degree = 0
            if node.left != -1:
                degree += 1
            if node.right != -1:
                degree += 1
            depth = self.calcDepth(idx)
            height = self.calcHeight(idx,0)
            typed = self.getType(node)
            print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(idx,parent,sibling,degree, depth, height,typed))

N = int(input())
BST = BinarySearchTree(N)
for i in range(N):
    Q = list(map(int, input().split()))
    BST.add(Q[0],Q[1],Q[2])
BST.printAll()

            



Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

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

int N;
int A[1000];
vector<int> v;
int ans = 0;

int dp[6000000];

void f(int divisor) {
    v.clear();
    int sum = 0;
    for(int i = 0; i < N; i++) {
        if(A[i] % divisor != 0) continue;
        int b = A[i] / divisor;
        if(__builtin_popcount(b) != 1) continue;
        v.push_back(b);
        sum += b;
    }
    for(int i = 0; i <= sum; i++) dp[i] = -1e9;
    dp[0] = 0;
    int maxi = 0;
    for(int i = 0; i < v.size(); i++) {
        for(int before = maxi; before >= 0; before--) {
            if(before == 0) {
                int to = before + v[i];
                chmax(maxi, to);
                chmax(dp[to], dp[before] + 1);
            } else if(__builtin_ffs(before) >= __builtin_ffs(v[i])) {
                int to = before + v[i];
                chmax(maxi, to);
                chmax(dp[to], dp[before] + 1);
            }
        }
    }
    for(int i = 0; i <= sum; i++) {
        if(__builtin_popcount(i) == 1) {
            chmax(ans, dp[i]);
        }
    }
}

void solve() {
    ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int val = 1; val <= 500; val++) {
        f(val);
    }
    cout << ans << endl;
}

int main() {
    while(cin >> N) {
        if(N == 0) break;
        solve();
    }
    return 0;
}


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





int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for (int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  cout<<vec.at(N-1)-vec.at(0)<<endl;
  
    
    
  
  
}













Measured memory_bytes: 256
using System;

namespace AtCoder
{
    internal static class Program
    {
        private static void Main()
        {
            long[] HW = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            long res = (long) Math.Ceiling((double) HW[0] * HW[1] / 2);

            if (HW[0] > 1 && HW[1] > 1)
                Console.WriteLine(res);
            else
                Console.WriteLine(1);
        }
    }
}

Measured memory_bytes: 11092
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr())
Aabs = np.abs(A)
negative = np.count_nonzero(A < 0)
answer = Aabs.sum()
if negative&1:
    answer -= 2 * np.min(Aabs)

print(answer)
#


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

int popcount(int n) {
  int res = 0;
  while(n) {
    if(n % 2) res++;
    n /= 2;
  }
  return res;
}

ll Pow(ll x, ll n, ll mod){
  if(n == 0) return 1;
  if(n % 2 == 0) return Pow(x*x % mod,n/2,mod);
  else return x * Pow(x,n-1,mod) % mod;
}

int main(){
  ll n;
  cin >> n;
  string x;
  cin >> x;
  int cnt = 0;
  rep(i,n) {
    if(x[i] == '1') cnt++;
  }
  ll modm = 0, modp = 0;
  ll digp = 1, digm = 1;
  rep(i,n) {
    if(x[n-1-i] == '1') {
      if(cnt > 1) (modm += digm) %= cnt-1;
      (modp += digp) %= cnt+1;
    } 
    (digp *= 2) %= (cnt+1);
    if(cnt > 1) (digm *= 2) %= (cnt-1);
  }
  int ans[n];
  rep(i,n) {
    int v = 0;
    if(x[i] == '1') {
      if(cnt > 1) {
        v = (modm - Pow(2,n-1-i,cnt-1)) % (cnt-1);
        if(v < 0) v += cnt-1;
        ans[i] = 1;
      } else {
        ans[i] = 0;
      }
    } else {
      v = (modp + Pow(2,n-1-i,cnt+1)) % (cnt+1);
      ans[i] = 1;
    }
    while(v) {
      v %= popcount(v);
      ans[i]++;
    }
  }
  rep(i,n) cout << ans[i] << endl;
  return 0;
}


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

int main() {
    ll n, q; cin >> n >> q;
    queue< pair<string,ll> > s;
    string s1; ll time;
    for( int i = 0; i < n; i++ ) {
        cin >> s1 >> time;
        s.push(make_pair(s1,time));
    }
    queue< pair<string,ll> > ans;
    ll clock = 0;
    while( !s.empty() ) {
        s1 = s.front().first; time = s.front().second; s.pop();
        if( time > q) {
            time -= q;
            clock += q;
            s.push(make_pair(s1,time));
        } else {
            clock += time;
            ans.push(make_pair(s1, clock));
        }
    }

    while( !ans.empty() ) {
        cout << ans.front().first << ' ' << ans.front().second << endl; ans.pop();
    }
    return 0;
}



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

int N, Q;
const int INF = INT_MAX;
struct LazySegmentTree {
private:
    int n;
    vector<int> node, lazy;
    vector<bool> lazyFlag;

public:
    LazySegmentTree(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, INF);
        lazyFlag.resize(2*n-1, false);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }

    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }

    void update(int a, int b, int x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    int find(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return INF;
        if(a <= l && r <= b) return node[k];
        int vl = find(a, b, 2*k+1, l, (l+r)/2);
        int vr = find(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main() {
    cin >> N >> Q;
    vector<int> aa(N, INF);
    LazySegmentTree seg( aa );
    for(int i=0; i<Q; i++) {
        int query; cin >> query;
        if(query == 0) {
            int s, t, x; cin >> s >> t >> x;
            seg.update(s, t+1, x);
        }
        else {
            int s, t; cin >> s >> t;
            cout << seg.find(s, t+1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int BIG = 2e9 + 55;

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

    string s;   cin >> s;
    int n = (int)s.size();

    stack<pair<char, ll> > stak;

    ll fRes = 0;
    for(int i = n - 1; i >= 0; i--){
        if(s[i] == 'W'){
            stak.push(make_pair(s[i], 1));
        } else {
            ll cnt = 0;
            while(!stak.empty() && (stak.top().first == 'W')){
                cnt += stak.top().second;
                stak.pop();
            }
            fRes += cnt;
            stak.push(make_pair('B', 1));
            if(cnt){
                stak.push(make_pair('W', cnt));
            }
        }
    }
    cout << fRes << '\n';

    return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
int f[100010],d[100010];
int findd(int x)
{
    if(f[x]==x) return x;
    int a=f[x];
    int b=findd(f[x]);
    d[x]+=d[a];
    f[x]=b;
    return b;
}
bool unit(int x,int y,int c)
{
    int fx=findd(x);
    int fy=findd(y);
    if(fx==fy)
    {
        if(d[y]-d[x]==c) return 1;
        else return 0;
    }
    f[fy]=fx;
    d[fy]=d[x]+c-d[y];
    return 1;
}
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        int flag=0;
        int l,r,d;
        for(int i=1;i<=n;i++)f[i]=i;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d",&l,&r,&d);
            if(!unit(l,r,d))
            {
                flag=1;
            }
        }
        if(flag) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n,m;
  cin >> n >> m;
  vector<int> city(n,0);
  REP(i,m){
    int a,b;
    cin >> a >> b;
    city[a-1]++;
    city[b-1]++;
  }
  REP(i,n){
    cout << city[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
import heapq
n,m = (int(x) for x in input().split())
a1 = []
a2 = []
for i in range(1, int(m**0.5)+1):
  if(m%i == 0):
    a1.append(i)
    a2.append(m//i)
    
a1.extend(a2[::-1])
i = 0

while(i <= len(a1)):
  if(a1[i] >= n):
    print(m//a1[i])
    break
  i += 1
    

    

Measured memory_bytes: 3064
n = gets.to_i
a = gets.split(' ').map(&:to_i)


a.delete(0)
min = a.min
while !(a.uniq.count == 1)
	break if min == 1
	flag = 0
	#p a
	a = a.map do |i|
		if i == min && flag == 0
			flag = 1
			i
		else
			i % min
		end
	end
	#p a
	a.delete(0)
	min = a.min if a.min < min
end

puts min

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

const long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

int main() {
    ll N; cin >> N;
    ll mini = INF;
    ll A[5];
    for (int i = 0; i < 5; i++) {
        cin >> A[i];
        chmin(mini, A[i]);
    }

    ll sum = (N + mini - 1) / mini;
    sum += 4;

    cout << sum << endl;
}

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

int N, M;
vector < int > G[5006];
int cnt[5006] = {};
int main()
{
    queue < int > que;
    int flag = 0;
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1); cnt[b - 1]++;
    }
    for(int i = 0; i < N; i++) {
        if(cnt[i] == 0) que.push(i);
    }
    while(!que.empty()) {
        if(que.size() >= 2) flag = 1;
        int v = que.front(); que.pop();
        cout << v + 1 << endl;
        for(int i = 0; i < G[v].size(); i++) {
            int u = G[v][i];
            cnt[u]--;
            if(cnt[u] == 0) que.push(u);
        }
    }
    cout << flag << endl;
    return (0);
}



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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    long double n, m, d; cin >> n >> m >> d;

    if(d > 0){

        cout << setprecision(9) << fixed << 2 * (n - d) * (m - 1) / (n * n) << "\n";

    } else {

        cout << setprecision(9) << fixed << (m - 1) / n << "\n";

    }

    return 0;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=10000;
const ll INF=1000000010;
const int MAX=100001;
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
int sum[10010][1300];
int main(){
	int N,M;
	while(cin>>N>>M,N){
		memset(sum,0,sizeof(sum));
		int r;
		cin>>r;
		for(int i=0;i<r;i++){
			int t,n,m,s;
			cin>>t>>n>>m>>s;m--;
			if(s){
				sum[m][t]++;
			}else{
				sum[m][t]--;
			}
		}
		for(int i=0;i<M;i++){
			for(int j=1;j<=1260;j++){
				sum[i][j]+=sum[i][j-1];
			}
		}	
		int q;
		cin>>q;
		while(q--){
			int t1,t2,m;
			cin>>t1>>t2>>m;m--;
			int ans=0;
			for(int i=t1;i<t2;i++){
				if(sum[m][i]>0){
					ans++;
				}
			}
			cout<<ans<<endl;
		}		
	}
	return 0;
}



Measured memory_bytes: 53904
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<vector<int> > v(n+1,vector<int>(3));
    for(int i=1;i<=n;i++)
    {
        cin>>v[i][0]>>v[i][1]>>v[i][2];
    }
    vector<vector<int> > v1(n+1,vector<int>(3));
    v1[n][0]=v[n][0];
    v1[n][1]=v[n][1];
    v1[n][2]=v[n][2];
    for(int i=n-1;i>0;i--)
    {
        for(int j=0;j<3;j++)
        {
            v1[i][j]=max(v[i][j]+v1[i+1][(j+1)%3],v[i][j]+v1[i+1][(j+2)%3]);
        }
    }
    cout<<max(v1[1][0],max(v1[1][1],v1[1][2]))<<endl;
    return 0;
}


Measured memory_bytes: 14048
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll r = 0;
    for (int k = 0; k < 60; k++) {
        int c = 0;
        for (int i = 0; i < n; i++) {
            c += a[i] >> k & 1;
        }
        r += (1LL << k) % P * c % P * (n - c) % P;
    }
    r %= P;

    cout << r << endl;

    return 0;
}

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

signed main(void)
{
	int n, d, x, cnt;
	cin >> n >> d >> x;
	cnt = x;
	rep(i, n)
	{
		int a;
		cin >> a;
		cnt += d / a;
		if (d % a != 0) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
ll n;
cin>>n;
ll count=0;
for(ll i=1;i<=n;i++)
{
	count+=i*(((n/i)*(n/i+1))/2);
}
cout<<count<<endl;
return  0;
}






Measured memory_bytes: 3624
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		int kari;
		
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		
		if (a > b){
			kari = a;
			a = b;
			b = kari;}
		
		if (b > c){
			kari = b;
			b = c;
			c = kari;}
		
		if (a > b){
			kari = a;
			a = b;
			b = kari;}
		
		System.out.println(a+" "+b+" "+c);
	}
}


Measured memory_bytes: 26308
import java.util.*;
public class Main{
  static double[][][] dp;
  static int n;
  static double solve(int i,int j,int k){
    if(dp[i][j][k]!=-1)return dp[i][j][k];
    if(i<0||j<0||k<0)return 0;
    if(i==0&&j==0&&k==0)return 0;
    double d = n;
    if(i>0)d+=solve(i-1,j,k)*(double)i;
    if(j>0)d+=solve(i+1,j-1,k)*(double)j;
    if(k>0)d+=solve(i,j+1,k-1)*(double)k;
    d/=(double)(i+j+k);
    return dp[i][j][k]=d;
  }
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    dp = new double[301][301][301];
    for(int i=0;i<=300;i++)
      for(int j=0;j<=300;j++)Arrays.fill(dp[i][j],-1);
    int one = 0;
    int two = 0;
    int three = 0;
    for(int i=1;i<=n;i++){
      int a = sc.nextInt();
      if(a==1)one++;
      if(a==2)two++;
      if(a==3)three++;
    }
    System.out.println(solve(one,two,three));
  }
}

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

using namespace std;

#define ll long long int
#define loop(a,b,c) for(ll a=b; a<c; a++)
#define eloop(a,b,c) for(ll a=b; a<=c; a++)
#define nl printf("\n")

int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    ll ans = 0, max =0, mf = b/a;
    if(b> n){
        ans =  ((a*n) / b);
    }
    else {
         ans = ((a * (b-1))/ b );
       /* for(ll i =1; i<b; ){
            ll t = floor((a*i) / b) ;
            if(t > max) max = t;
            i += mf;

        }
        ans = max;
        */
    }
    
        cout << ans << endl;

    return 0;
}    

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int INF = INT_MAX/2;

// メモ用 DP
vector<int> dp(100010);

// inputs
int N, K;
vector<int> v(100010);

int rec(int x) {
	// メモ済み
	if (dp[x] < INF) return dp[x];
	if (x == 0) return 0;

	int t = INF;
	rep1(i, K) {
		if (x-i < 0) break;
		chmin(t, rec(x-i) + abs(v[x]-v[x-i]));
	}

	// メモしながら返す
	return dp[x] = t;
}

int main() {
	cin >> N >> K;
	rep(i, N) {
		cin >> v.at(i);
	}

	fill(all(dp), INF);
	cout << rec(N-1) << '\n';
}


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

typedef long long ll;
ll n, a[100010], l, r, fact[100010], invfact[100010], mod = 1e9+7, ans;

ll modinv(ll a, ll m){
	ll b = m, u = 1, v = 0;
	while(b){
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if(u < 0) u += m;
	return u;
}

ll comb(ll n, ll r){
	if(n == 0 && r == 0) return 1;
	if(n == 0 || n < r) return 0;
//	cout << n << " " << r << "\n";
	ll res = fact[n];
	res *= invfact[r];
	res %= mod;
	res *= invfact[n-r];
	res %= mod;
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=n+1; ++i){
		ll t;
		cin >> t;
		if(a[t] != 0){
			l = a[t];
			r = i;
		}
		a[t] = i;
	}
//	cout << l << " " << r << "\n";
	fact[0] = 1;
	invfact[0] = 1;
	for(int i=1; i<=n+1; ++i){
		fact[i] = (fact[i-1] * i) % mod;
		invfact[i] = modinv(fact[i], mod);
	}
//	for(int i=0; i<10; ++i)
//		cout << fact[i] << " " << invfact[i] << "\n";
	for(int k=1; k<=n+1; ++k){
		ans = comb(n+1, k) - comb(n+l-r, k-1);
		if(ans < 0) ans += mod;
		cout << ans << "\n";
	}
}

Measured memory_bytes: 3584
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        mut v: [usize; n]
    }
    v.sort();
    if v[n - 1] - v[0] > 1 {
        println!("No");
    } else if v[0] == v[n - 1] {
        if v[0] <= n / 2 || v[0] == n - 1 {
            println!("Yes");
        } else {
            println!("No");
        }
    } else {
        let mut a = 0;
        for &x in &v {
            if x == v[0] {
                a += 1;
            } else {
                break;
            }
        }
        if a <= v[0] && v[0] + 1 <= (n - a) / 2 + a {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


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

using namespace std;

int main(){
    int K;
    cin >> K;
    string S;
    cin >> S;
    
    if(S.size()<=K){
        cout << S << endl;
    }else{
        cout << S.substr(0,K) << "..." << endl;
    }
}

Measured memory_bytes: 3628
N,K = map(int, input().split())
S = list(input())
if S[K-1] == 'A':
    S[K-1] = 'a'
elif S[K-1] == 'B':
    S[K-1] = 'b'
else:
    S[K-1] = 'c'
print(''.join(S))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#include <algorithm>
#include <complex>
#include <map>
#include <cmath>
#include <string>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <istream>

using namespace std;

//--------------------------------------------------------------//

int a, b, c;

int main() {
	cin >> a >> b >> c;

	if (a == b + c) {
		cout << "Yes" << endl;
	}
	else if (b == a + c) {
		cout << "Yes" << endl;
	}
	else if (c == a + b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

cul = [0]
for x in a:
    cul.append(cul[-1]+x)

dp = [[10**13 for i in range(n+1)] for j in range(n+1)]
# dp[i][j] [i,j)の答え ans = dp[0][n]
for i in range(n):
    dp[i][i+1] = 0
for w in range(2,n+1): # w:区間の長さ
    for i in range(n):
        j = i + w # [i,j)で考える
        if j > n:break
        for k in range(i,j):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]+cul[j]-cul[i])

print(dp[0][n])

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

int main(){
    int n;
    cin >> n;
    string a,b,c;
    cin >> a >> b >> c;
    int ans = 0;
    for(int i=0;i<n;i++){
        if(a[i]==b[i] && a[i]!=c[i]) ans++;
        else if(a[i]==c[i] && a[i]!=b[i]) ans++;
        else if(b[i]==c[i] && a[i]!=b[i]) ans++;
        else if(a[i]!=b[i] && b[i]!=c[i] && c[i]!=a[i]) ans += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i,j,m,H,W;
    m = 1;
    while(1){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0)break;
        for(j = 0;j < H; j++){
            for(i = 0;i < W; i++){
            printf("#");
            }
            printf("\n");
        } 
        printf("\n");
    
    m++;
    }
    
    
  return 0;

 }


Measured memory_bytes: 2100
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		System.out.println(Math.max(C-(A-B),0));
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21076
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

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

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll x,y; cin >> x >> y;
    rep(i,0,x+1){
        if(i * 2 + (x - i) * 4 == y){
            YES(true);
            return 0;
        }
    }
    YES(false);
}

Measured memory_bytes: 3652
MOD = 10 ** 9 + 7
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

x_sum = 0
for i in range(N):
    x_sum = (x_sum + X[i] * (N - i - 1) - X[i] * i) % MOD

y_sum = 0
for i in range(M):
    y_sum = (y_sum + Y[i] * (M - i - 1) - Y[i] * i) % MOD

result = (x_sum * y_sum) % MOD

print(result)


Measured memory_bytes: 18624
#include<stdio.h>
#include<iostream>

using namespace std;

string s;
int main(){
    cin >> s;
    int x=0,y=0,xx=0,yy=0;
    for(int i=0; i<s.length(); i++) {
        if(s[i]=='E') x = 1;
        if(s[i]=='N') y = 1;
        if(s[i]=='W') xx = 1;
        if(s[i]=='S') yy = 1;
    }
    cout << ( (x == xx &&y == yy) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
def main():
    n, m = map(int, input().split())
    sc = [tuple(map(int, input().split())) for _ in range(m)]

    for i1 in range(1000):
        i1 = str(i1)
        if len(i1) != n:
            continue
        else:
            for s, c in sc:
                if int(i1[s-1]) != c:
                    break
            else:
                print(int(i1))
                sys.exit()
    print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9204
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair

using namespace std;

int main(){
    int X,A;
    cin >> X >> A;
    if(X>=A){
        cout << 10 << endl;
    }
    else{
        cout << 0 << endl;
    }
    return 0;
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

string s;
bool isPalin() {
	if(sz(s) % 2 == 1)
		return false;
	string a = s.substr(0, sz(s) / 2);
	string b = s.substr(sz(s) / 2, sz(s));
	return a == b;
}
int longest()
{
	do
	{
		s.pop_back();
	}while(isPalin() == false);
	return sz(s);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    cin >> s;

	cout << longest() << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int a, b, k;
string ans[4] = {"NA", "YYMM", "MMYY", "AMBIGUOUS"};
int main() {
	scanf("%2d%2d", &a, &b);
	if(a>=1 && a<=12) k += 2;
	if(b>=1 && b<=12) k += 1;
	cout << ans[k];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
long long a=0,b=0,x=0,c=0;
cin>>a>>b>>x;
if(a>0){
	a-=1;
	c=(b/x)-(a/x);
} 
else{
	c=b/x;
	c++;
}
cout<<c;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<vector>
#include<memory>
#include<iterator>

int main() {
  using namespace std;

  auto n = 0;
  cin >> n;

  vector<int> balls;
  multimap<int, int> mballs;
  for(int i = 0; i < n; i++)
  {
    int num = 0;
    cin >> num;
    balls.push_back(num);
    mballs.emplace(num, i);
  }

  unordered_set<int> uniqueBalls(balls.begin(),balls.end());
  if (n == uniqueBalls.size()) {
    for (int i = 0; i < n; i++) 
    {
      cout << 0 << endl;
    }
    return 0;
  }

  // value, count
  unordered_map<int, int> countBalls;
  long long cxcm1A = 0;
  for (const auto &b : uniqueBalls)
  {
    const auto c = mballs.count(b);
    countBalls.emplace(b, c);
    cxcm1A += c * (c - 1);
    mballs.erase(b);
  }

  for(int i = 0; i < n; i++)
  {
    const int kCount = countBalls.at(balls[i]);
    const long long && count = -(2 * kCount - cxcm1A - 2) / 2;
    cout << count << endl;
  }
}

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

int N;

int main(){
	cin >> N;
	int h[N + 10], dp[N + 10];
	for (int i = 1; i <= N; i++){
		cin >> h[i];
		dp[i] = 1e9 + 7;
	}
	dp[1] = 0;
	for (int i = 1; i <= N; i++){
		dp[i + 1] = min(abs(h[i] - h[i + 1]) + dp[i], dp[i + 1]);
		dp[i + 2] = min(abs(h[i] - h[i + 2]) + dp[i], dp[i + 2]);
	}
	cout << dp[N] << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s1 = in.next();
        String s2 = in.next();
        System.out.println(editDistance(s1, s2));
    }

    private static int editDistance(String s1, String s2) {
        int l1 = s1.length();
        int l2 = s2.length();
        char[] chars1 = s1.toCharArray();
        char[] chars2 = s2.toCharArray();
        int[][] distance = new int[l1+1][l2+1];
        for (int i = 0; i <= l1; i++) {
            distance[i][0] = i;
        }
        for (int j = 1; j <= l2; j++) {
            distance[0][j] = j;
        }

        for (int i = 1; i <= l1; i++) {
            for (int j = 1; j <= l2; j++) {
                int substitutionCost;
                int deletionCost = distance[i-1][j] + 1;
                int insertionCost = distance[i][j-1] + 1;
                if (chars1[i-1] == chars2[j-1]) {
                    substitutionCost = distance[i-1][j-1];
                } else {
                    substitutionCost = distance[i-1][j-1] + 1;
                }
                distance[i][j] = Math.min(Math.min(deletionCost, insertionCost), substitutionCost);
            }
        }
        return distance[l1][l2];
    }
}



Measured memory_bytes: 30844
#include <bits/stdc++.h>
#define foru(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
int t;
int n,d;
int main() {
//   freopen("input.txt","r",stdin);
   cin >> t;
   while (t--){
      int n, d;
      cin>>n>>d;
      int ans = 0;
      for(int i=0;i<7;++i){
         int bit=(d>>i)&1;
         if(bit==1){
            if(n%2==1)ans+=n*(1<<i);
            else ans+=(n-1)*(1<<i);
         }
         else{
            if(n%2==0)ans+=n*(1<<i);
            else ans+=(n-1)*(1<<i);
         }
//         cout<<ans<<endl;
      }
      cout<<ans<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
d = list(map(int,input().split()))
mod = 998244353

c = Counter(d)
if c[0] != 1 or d[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(1,max(d) + 1):
        ans *= c[i-1]**c[i]
        ans %= mod
    print(ans)

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a%2 == 0 || b%2 == 0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
/**
 * Created by hiramekun at 20:50 on 2019-10-19.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll a, b;
    cin >> a >> b;
    cout << max(0LL, a - b * 2) << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        for(int i=n; i>=0; i--){
            if(Math.sqrt(i)==(int)Math.sqrt(i)){
                System.out.println(i);
                break;
            }
        }
        
	}
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    string s;
    int x = INF, y = 0;
    cin >> s;
    FOR(i, 0, s.size() - 1)
        if(s[i] == 'A') x = min(x, i);
        else if(s[i] == 'Z') y = max(y, i);
    cout << y - x + 1;
    return 0;
}


Measured memory_bytes: 720
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getint():
    return int(input())
def getints():
    return [int(i) for i in input().split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
f = getintslines(n)
p = getintslines(n)

# すべての営業パターンについて、全探索(1024通りなので全体で10^5オーダーであり間に合う)
# |profit| <= NP_{i,j}なので絶対値はたかだか10^9
profit = -10**10

for sale in range(1,1025):
    shops = [0]*n
    pattern = format(sale, '010b')
    for i, time in enumerate(pattern):
        if time == '1':
            for j in range(n):
                shops[j] += f[j][i]
    tmp = 0
    for i, s in enumerate(shops):
        tmp += p[i][s]
    profit = max(tmp, profit)
    
print(profit)


Measured memory_bytes: 3064
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#pragma GCC optimize ("O3")
	#define NDEBUG
#endif
// #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

const array<int, 4> dx = {0, 1, 0, -1};
const array<int, 4> dy = {1, 0, -1, 0};


typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	string s;
	while(cin >> s) {
		vector<int> ans(SZ(s));
		int pre = 0;
		int cnt = 0;
		REP(i, SZ(s)) {
			if(s[i] == 'L') {
				if(cnt % 2 == 0) {
					ans[pre+1]++;	
				} else {
					ans[pre]++;
				}
				cnt++;
			} else {
				pre = i;
				cnt = 0;
			}
		}
		pre = SZ(s) - 1;
		cnt = 0;
		RREP(i, SZ(s)) {
			if(s[i] == 'L') {
				cnt = 0;
				pre = i;
			} else {
				if(cnt % 2 == 0) {
					ans[pre - 1]++;
				} else {
					ans[pre]++;
				}
				cnt++;
			}
		}
		pite(ALL(ans));
	}
	return 0;
}


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

using namespace std;

const int md = 1e9 + 7;

string s;
int n, m;
int a[55];
long long f[55];

int main(){
//	freopen("input.inp", "r", stdin);
	cin >> n >> s;
	for(int i = 0; i < n; ++i){
		++m;
		if (i + 1 < n && s[i + 1] == s[i]) ++a[m], ++i;
	}
	if (a[1]) f[1] = 6; else f[1] = 3;
	for(int i = 2; i <= m; ++i){
		if (a[i] == 1 && a[i - 1] == 0) f[i] = f[i - 1] * 2 % md;
		if (a[i] == 1 && a[i - 1] == 1) f[i] = f[i - 1] * 3 % md;
		if (a[i] == 0 && a[i - 1] == 0) f[i] = f[i - 1] * 2 % md;
		if (a[i] == 0 && a[i - 1] == 1) f[i] = f[i - 1];
	}
	printf("%d",f[m]);
	return 0;
}

Measured memory_bytes: 256