akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}

//......................................@uthor_Alx..............................................

   public static void main(String[] args) throws  IOException{
	        		  assign();
	        		  	int n=int_v(read());
	        		  	int[] arr=int_arr();
	        		  	Arrays.sort(arr);
	        		  	int[] f=new int[1000001];
	        		  	for(int x:arr){f[x]++;}
	        		  	boolean[] b=new boolean[1000001];
	        		    boolean[] b1=new boolean[1000001];
	        		    Arrays.fill(b,true);
	        		   for(int i=0;i<n;i++){
	        		   	    if(!b[arr[i]]||b1[arr[i]]) continue;
	        		   	    b1[arr[i]]=true;
	        		   		for(int j=2*arr[i];j<1000001;j+=arr[i]){
	        		   			b[j]=false;
	        		   		}
	        		   }
	        		   int res=0;
	        		   for(int i=0;i<n;i++){
	        		   		if(b[arr[i]]&&f[arr[i]]==1){
	        		   			res++;
	        		   		}
	        		   }
	        		  	out.write(res+"");
                      out.flush();
	        		 
	}
}

Measured memory_bytes: 67268
#include <stdio.h>

int main()
{
        int n, i, j, k;
        long long a[5000], sum, max;

        while (scanf("%d", &n) && n != 0) {
                for (i = 0; i < n; i++)
                       scanf("%lld", &a[i]);

                max = -100000;
                for (j = 0; j < n; j++) {
                        sum = 0;
                        for (i = j; i < n; i++) {
                                sum = sum + a[i];
                                if (sum > max) {
                                        max = sum;
                                }
                        }
                }
                printf("%lld\n", max);
        }
        return 0;
}

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

using namespace std;

int N, x, y, z;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> N;
  for (int i = 1; i <= N; i ++) {
    int n = i, cnt = 0;
    for (int x = 1; x * x < n - 1; x ++)
      for (int y = 1; x * x + y * y < n; y ++)
        for (int z = 1; x * x + y * y + z * z + x * y + y * z + x * z <= n; z ++)
          if (x * x + y * y + z * z + x * y + y * z + x * z == n)
            cnt ++;
    cout << cnt << '\n';
  }
  return 0;
}


Measured memory_bytes: 3632
use proconio::input;
use std::collections::HashMap;

fn main() {
    input!(n: isize, s:[String; n]);
    let mut m = HashMap::new();
    for c in s {
        *m.entry(c).or_insert(0) += 1;
    }
    let s = ["AC", "WA", "TLE", "RE"].iter()
        .map(|s| (*s).to_owned()).collect::<Vec<String>>();

    for c in s {
        println!("{} x {}", c, m.get(&c).unwrap_or(&0))
    }
}


Measured memory_bytes: 7820
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;
typedef long long ll;

ll n, m, s, a[N], b[N], pr[N], c[N], ans[N];

ll f(ll p) {
	if(pr[p] == p) return p;
	return pr[p] = f(pr[p]);
}

int main() {
	ll i, x, y;
	cin >> n >> m;
	for(i=1; i<=m; i++) scanf("%lld%lld", &a[i], &b[i]);
	for(i=1; i<=n; i++) pr[i] = i, c[i] = 1;
	s = n * (n-1) / 2;
	for(i=m; i; i--) {
		ans[i] = s;
		x = f(a[i]); y = f(b[i]);
		if(x != y) {
			s -= c[x] * c[y];
			pr[y] = x;
			c[x] += c[y];
		}
	}
	for(i=1; i<=m; i++) {
		printf("%lld\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >>N;
    long H[N];
    for(int i=0;i<N;i++) cin >>H[i];
    bool can=true;
    for(int i=0;i<N-1;i++){
        if(H[N-1-i]<H[N-2-i]){
            H[N-2-i] -=1;
        }
    }
    for(int i=0;i<N-1;i++){
        if(H[i+1]<H[i]){
            can = false;
            break;
        }
    }
    if(can) cout << "Yes" <<endl;
    else cout <<"No" <<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
int main()
{
    int N, a, b, ba, cnt;
    a = b = ba = cnt = 0;
    string s;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> s;
        int len = (int)s.size();
        for (int j = 0; j + 1 < len; j++)
        {
            if (s[j] == 'A' && s[j + 1] == 'B')
            {
                cnt++;
            }
        }
        if (s[0] == 'B')
        {
            b++;
        }
        if (s[len - 1] == 'A')
        {
            a++;
        }
        if (s[0] == 'B' && s[len - 1] == 'A')
        {
            ba++;
        }
    }
    cnt += min(a, b);
    if (a == ba && b == ba && b > 0)
    {
        cnt--;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string n;
    cin>>n;
    int f=0;
    for(int i=0;i<n.length();i++)
    {
        int a=n[i]-'0';
        if(a==7)
        {
            f=1;
            break;
        }
    }
    if(f==1)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}

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

int main() {
    int s;
    cin >> s;
    static bool fl[1000000];
    fl[s] = true;
    for(int i = 2;; ++i) {
        if(s % 2 == 0)
            s /= 2;
        else
            s = 3 * s + 1;
        if(fl[s] == true) {
            cout << i << endl;
            break;
        }
        fl[s] = true;
    }
    return 0;
}


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

string rev(string str){
    for(int i=0;i<str.length();i++){
        if(str[i]=='['){
            int j;
            int co=1;
            for(j=i+1;j<str.length();j++){
                if(str[j]=='[')co++;
                if(str[j]==']')co--;
                if(co==0)break;
            }
            string n=rev(str.substr(i+1,j-i-1));
            str=str.substr(0,i)+n+str.substr(j+1,str.length()-j-1);
        }
    }
    string tem="";
    for(int i=0;i<str.length();i++)
        tem+=str[str.length()-1-i];
    return tem;
}

string pm(string str){
    char c=str[str.length()-1];
    for(int i=0;i<str.length()-1;i++){
        if(str[i]=='+'){
            if(c=='Z')
                c='A';
            else c++;
        }
        if(str[i]=='-'){
            if(c=='A')
                c='Z';
            else c--;
        }
    }
    string tem="";
    tem+=c;
    return tem;
}

int main(){
    while(1){
        string str;
        cin>>str;
        if(str==".")break;
        for(int i=0;i<str.length();i++){
            if(str[i]=='+'||str[i]=='-'){
                int j;
                for(j=i+1;str[j]=='+'||str[j]=='-';j++);
                string n;
                if(str[j]=='?')n="A";
                else n=pm(str.substr(i,j-i+1));
                str=str.substr(0,i)+n+str.substr(j+1,str.length()-j-1);
            }
            if(str[i]=='?')str[i]='A';
           // cout<<str<<endl;
        }
        for(int i=0;i<str.length();i++){
            if(str[i]=='['){
                int j;
                int co=1;
                for(j=i+1;j<str.length();j++){
                    if(str[j]=='[')co++;
                    if(str[j]==']')co--;
                    if(co==0)break;
                }
                string n=rev(str.substr(i+1,j-i-1));
                //cout<<n<<endl;
                str=str.substr(0,i)+n+str.substr(j+1,str.length()-j-1);
            }
        }
        cout<<str<<endl;
    }
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

bool isp[225816];

int main(void){
	int i,j,x;
	fill(isp,isp+225816,true);
	isp[0] = false;
	isp[1] = false;
	for(i=2; i<225816; ++i){
		if(!isp[i]){
			continue;
		}
		for(j=i*2; j<225816; j+=i){
			isp[j] = false;
		}
	}
	cin >> x;
	while(!isp[x]){
		++x;
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {
	rapid_pleaseAC_fast;

	int a, b, k;
	cin >> a >> b >> k;
	int i = GCD(a,b);
	int j = 0;
	while (i > 0) {
		if (a % i == 0 && b % i == 0) {
			j++;
			if (k == j) {
				cout << i << rt;
				return 0;
			}
		}
		i--;
	}

	please AC;
}
//参考：---

Measured memory_bytes: 256
#include <stdio.h>

int main( void ) {
	int n, debt = 100000;

	scanf( "%d", &n );

	while ( n-- ) {
		debt *= 1.05;

		if ( debt % 1000 != 0 )
			debt = ( debt / 1000 + 1 ) * 1000;
	}

	printf( "%d\n", debt );

	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
// #define int long long
typedef long long ll;
#define fi first
#define se second
#define pii pair<ll,int>
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define y1 fdfbvfds
typedef long double f80;
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l,ll r){
    uniform_int_distribution<ll> uid(l, r);
    return uid(rng);
}

const int mod = 998244353;
int pwr(int a,int b) {
    int ans = 1;
    while(b) {
        if(b & 1) {
            ans = (ans * 1LL * a) % mod;
        }
        a = (a * 1LL * a) % mod;
        b >>= 1;
    }
    return ans;
}

const int N = 1e5 + 5;
vector<int> g[N];
int L[N], R[N];
bool done[N];

void dfs(int u,int p) {
    for(int v : g[u]) {
        if(v != p) {
            dfs(v, u);
            L[u] = max(L[u], L[v] - 1);
            R[u] = min(R[u], R[v] + 1);
        }
    }
}

void dfs1(int u,int p) {
    for(int v : g[u]) {
        L[u] = max(L[u], L[v] - 1);
        R[u] = min(R[u], R[v] + 1);
    }
    for(int v : g[u]) {
        if(v != p) {
            dfs1(v, u);
        }
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    fr(i, 1, n - 1) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int k;
    cin >> k;
    fr(i, 1, n) {
        L[i] = -1e9, R[i] = 1e9;
    }
    fr(i, 1, k) {
        int p, v;
        cin >> p >> v;
        L[p] = R[p] = v;
    }
    L[0] = -1e9, R[0] = 1e9;
    dfs(1, 0);
    dfs1(1, 0);
    set<pii> s;
    fr(i, 1, n) {
        s.insert({R[i] - L[i] + 1, i});
    }
    while(!s.empty()) {
        pii u = *s.begin();
        s.erase(s.begin());
        if(R[u.se] < L[u.se]) {
            cout << "No";
            return 0;
        }
        R[u.se] = L[u.se];
        done[u.se] = 1;
        for(int v : g[u.se]) {
            if(done[v]) continue;
            s.erase({R[v] - L[v] + 1, v});
            L[v] = max(L[v], L[u.se] - 1);
            R[v] = min(R[v], R[u.se] + 1);
            s.insert({R[v] - L[v] + 1, v});
        }
    }
    bool good = 1;
    fr(i, 1, n) {
        for(int v : g[i]) {
            if(abs(L[v] - L[i]) != 1)
                 good = 0;
        }
    }
    fr(i, 1, n) {
        if(R[i] < L[i]) good = 0;
    }
    if(!good) {
        cout << "No";
        return 0;
    }
    cout << "Yes" << endl;
    fr(i, 1, n) {
        cout << L[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 19840
N = int(input())
for i in range(N):
    B = C = 0
    yes = True
    a = list(map(int,input().split()))
    for j in range(10):
	    if a[j] > B:
		    B = a[j]
	    elif a[j] > C:
		    C = a[j]
	    else:
		    yes = False
    print("YES" if yes else "NO")


Measured memory_bytes: 5588
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Control.Applicative
import Data.List
import Data.Maybe
import Data.Bits
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed ((!))


findMidWithin :: V.Vector Int -> (Int,Int) -> Int
findMidWithin vec (from,to) =
    fromMaybe to $ testIndex
    <$> V.findIndex ((>= lohi) . (`shiftL` 1)) (V.slice from (to-from+1) vec)
    where
      len = V.length vec
      n = len - 1
      lohi = vec!0 + vec!n
      testIndex 0 = from
      testIndex j | lohi <= vec!(from+j-1) + vec!(from+j) = from+j-1
                  | otherwise                             = from+j

findMidIntvWithin :: V.Vector Int -> (Int,Int) -> (Int,Int) -> Int
findMidIntvWithin vec (intvFrom,intvTo) (withinFrom,withinTo)
  = intvFrom
    + findMidWithin (V.slice intvFrom (intvTo-intvFrom+1) vec)
       (withinFrom - intvFrom, withinTo - intvFrom)
                                 
query :: Int -> V.Vector Int -> Int
query n sums =
  V.minimum $ V.imap (curry $ uncurry (-) . maxmin . map diff . poss) inds
  where
    maxmin = foldl' (\(!mx,!mn) v -> (mx `max` v, mn `min` v))
                    (minBound,maxBound)
    diff (i,j) = sums!j - sums!i
    poss (j',(i,k)) = [(0,i),(i,j),(j,k),(k,n)]
      where j = j' + 2
    inds =
      V.unfoldrN (n-3)
                 (\(!i,!j,!k) ->
                    let j' = findMidIntvWithin sums (0,i) (j,i-1)
                        k' = findMidIntvWithin sums (i,n) (k,n-1)
                    in Just ((j',k'),(i+1,j',k'`max`(i+1))))
                 (2,1,3)
     
main :: IO ()
main = do
  n <- read <$> getLine
  ais <- V.unfoldrN n (B.readInt . B.dropWhile (==' ')) <$> B.getLine
  putStrLn $ show $ query n $ V.scanl (+) 0 ais


Measured memory_bytes: 6012
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll h,w,n;cin>>h>>w>>n;
    map<pair<ll,ll>,int> mp,mp1;
    map<ll,ll> mp2;
    rep(i,n){
        ll a,b;cin>>a>>b;a--;b--;
        mp[{a,b}]++;
        mp1[{a,b}]++;
    }
    int roty[9]={0,1,1,0,-1,-1,-1,0,1},rotx[9]={0,0,1,1,1,0,-1,-1,-1};
    for(auto& p:mp1){
        ll a=p.first.first,b=p.first.second;
        if(mp[{a,b}]==0)continue;
        rep(i,9){
            ll ny=a+roty[i],nx=b+rotx[i];
            if(0>ny||ny>=h||0>nx||nx>=w)continue;
            int sum=0;
            rep(j,9){
                ll nny=ny+roty[j],nnx=nx+rotx[j];
                if(0>nny||nny>=h||0>nnx||nnx>=w){
                    sum=-1;
                    break;
                }
                if(mp[{nny,nnx}]==1)sum++;
            }
            if(sum==-1)continue;
            mp2[sum]++;
        }
    }
    ll tot=0;
    rep(i,10){
        if(i==0)continue;
        tot+=mp2[i]/i;
    }
    cout<<(h-2)*(w-2)-tot<<endl;
    rep(i,10){
        if(i==0)continue;
        cout<<mp2[i]/i<<endl;
    }
}

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

constexpr long long INF = (1LL << 60);

int main() {
	int n;
	long long max_w;
	cin >> n >> max_w;
	vector<long long> v(n), w(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
	}
	
	const int n1 = n / 2;
	const int n2 = n - n1;
	
	vector<pair<long long, long long>> dat;
	for (int s = 0; s < (1 << n1); s++) {
		long long value = 0, weight = 0;
		for (int i = 0; i < n1; i++) {
			if (s & (1 << i)) {
				value += v[i];
				weight += w[i];
			}
		}
		dat.emplace_back(weight, value);
	}
	
	sort(dat.begin(), dat.end(), [](pair<long long, long long> &l, pair<long long, long long> &r) {
		if (l.first == r.first) return (l.second > r.second);
		return (l.first < r.first);
	});
	
	for (int i = 0; i + 1 < dat.size(); i++) {
		pair<long long, long long> &s = dat[i];
		pair<long long, long long> &t = dat[i + 1];
		if (s.first <= t.first and s.second >= t.second) t = s;
	}

	long long ans = 0;
	for (int s = 0; s < (1 << n2); s++) {
		long long value = 0, weight = 0;
		for (int i = 0; i < n2; i++) {
			if (s & (1 << i)) {
				value += v[n1 + i];
				weight += w[n1 + i];
			}
		}
		if (weight <= max_w) {
			long long res = prev(lower_bound(dat.begin(), dat.end(), make_pair(max_w - weight, INF)))->second;
			ans = max(ans, res + value);
		}
	}
	
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 19452
#include <bits/stdc++.h> 
#define ll long long int
#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;
using namespace std;
ll INF = 1e15;
ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b, k;
    cin>>a>>b>>k;
    ll first = a;
    ll second = b;
    first -= k;
    if(first>=0)
    {
        cout<<first<<" "<<second<<"\n";
    }
    else
    {
        second += first;
        if(second>=0)
        {
            cout<<0<<" "<<second<<"\n";
        }
        else
        {
            cout<<0<<" "<<0<<"\n";
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,k,a[100005],sum;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=n-k+1;i<=n;i++)
    	sum+=a[i];
    cout<<sum<<endl;
    return 0;
}

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


int main(void)
{
	int num;
	cin >> num;
	int test[205];
	int a = 0, ans = 0;

	for (int i = 0; i < num; i++) {
		cin >> test[i];
	}
	for (int j = 0; j < 1000; j++) {

		for (int i = 0; i < num; i++) {
			if (test[i] % 2 == 0)
				a++;
			test[i] /= 2;
		}
		if (a == num) {
			ans++;
		}
		else
			break;
		a = 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  print(n%1000 ? 1000-(n%1000) : 0);
}


Measured memory_bytes: 3648
n = int(input())
x = int(n / 4)
y = int(n / 7)
flag = False
for i in range(x + 1):
    for j in range(y + 1):
        if 4 * i + 7 * j == n:
            flag = True
            break
if flag == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
N = int(input())
A = [0] * N
for i in range(N):
  A_temp = input()
  A[i]= sorted([c for c in A_temp])
count = 0

B = sorted(A)
A_unique_count = 1

for i in range(N-1):
  if B[i] == B[i+1]:
    A_unique_count += 1
  else:
    count += A_unique_count * (A_unique_count -1) /2
#    print('i' + str(i))
#    print(count)
    A_unique_count = 1

count += A_unique_count * (A_unique_count -1) /2
print(int(count))
  

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

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp  make_pair

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2500 + 5;
const int mod = 1e9 + 7;
ll Pow(ll a , ll b){
    if(b == 0)return 1;
    ll r = Pow(a,b/2);
    if(b&1)return (ll)r * r * a;
    return r * r;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
	}
    int n , k;cin >> n >> k;
    ll res = log2(n) / log2(k);
    if(Pow(k,res) > n)cout << res;
    else cout << res + 1;
}



Measured memory_bytes: 384
N = int(input())
line = list(map(int,input().split()))

if line.count(0) > 0:
    a = 0
elif line.count(10**18) > 0:
    a = -1
else:
    a = line[0]
    for i in range(len(line)):
        if i == 0:
            pass
        else:
            a = a * line[i]
            if a > 10**18:
                a = -1
                break

print(a)

Measured memory_bytes: 21448
import sys,atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda:inp.readline().decode('ascii')
buf = BytesIO()
sys.stdout.write = lambda s: buf.write(s.encode('ascii'))
atexit.register(lambda:sys.__stdout__.buffer.write(buf.getvalue()))

from collections import defaultdict as dd, deque

n,m,k = map(int,input().split())

C = [[] for _ in range(n)]
B = [[] for _ in range(n)]

for _ in range(m):
    a,b = [int(x)-1 for x in input().split()]
    C[a].append(b)
    C[b].append(a)

for _ in range(k):
    a,b = [int(x)-1 for x in input().split()]
    B[a].append(b)
    B[b].append(a)

incluster = [-1]*n
for i in range(n):
    S = [i]
    while S:
        cur = S.pop()
        if incluster[cur] != -1:
            continue
        incluster[cur] = i
        for neigh in C[cur]:
            S.append(neigh)

clusters = dd(set)
for i in range(n):
    clusters[incluster[i]].add(i)

res =[]
for i in range(n):
    which = incluster[i]
    cluster = clusters[which]
    res.append(len(cluster) - sum(1 for b in B[i] if b in cluster) - len(C[i]) - 1)
print(*res)




Measured memory_bytes: 117996
def resolve():
    s = input()
    k = int(input())
    num_one = 0
    for i in range(len(s)):
        if s[i]=="1":
            num_one += 1
        else:
            left = s[i]
            break
    if k <= num_one:
        print("1")
    else:
        print(left)
        
resolve()

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

int main(){
  int n,m,c,count=0;
  cin>>n>>m>>c;
  vector<int> b(m);
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  int a[n][m];
  for(int i=0;i<n;i++){
    int sum=c;
    for(int j=0;j<m;j++){
      cin>>a[i][j];
      sum+=a[i][j]*b[j];
    }
    if(sum>0) count++;
  }
  cout<<count<<endl;
}

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

int main() {
    int n;
    double k,ans;

    cin >> n >> k;

    ans = 0;
    double a = 1.0 / n;   //サイコロの確率
    for (int i = 1;i <= n;++i) {
        double bb = log(k / i) / log(2);
        int b1 = ceil(log(k / i) / log(2)); //べき乗→コインの連続回数
        if (b1 > 0) {
            double b = pow(0.5, b1);
            ans += a * b;
        }
        else
            ans += a;
    }

    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 4232
#include<iostream>
using namespace std;
int main(){
int n,h,w;cin>>w>>h>>n;
int a,x,y,x0=0,y0=0;
for(int i=0;i<n;i++){
cin>>x>>y>>a;
switch(a){
case 1:x0=max(x0,x);break;
case 2:w=min(w,x);break;
case 3:y0=max(y0,y);break;
case 4:h=min(h,y);break;
}
}
cout<<max(0,(w-x0))*max(0,(h-y0))<<endl;
}

Measured memory_bytes: 256
'use strict'
function main(input) {
  input = input.trim().split('')
  const current = input.length
  const win = input.filter(v => v==='o').length
  console.log((win + (15 - current) >= 8) ? 'YES' : 'NO')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
import Control.Monad
import Data.IntMap (IntMap, (!))
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Bool
import Data.Maybe

-- 人数 -> (人i → (人j, 距離)) -> 答え 
solve :: Int -> IntMap [(Int,Int)] -> Bool
solve n nbr = isJust $ foldM f IM.empty [1..n] where
  -- Maybe (人→座標) -> 人i -> Maybe (人→座標)
  -- i の 位置が規定なら何もしない
  -- i の 位置が未定なら，0におく．矛盾なら Nothing
  f pos i
    | i `IM.member` pos = Just pos
    | otherwise = g i 0 pos
    where
      -- 人i -> 人iの座標pi -> Maybe (人→座標)
      -- 人i を pi におく．矛盾なら Nothing
      g i pi pos = foldM h (IM.insert i pi pos) (nbr!i) where
        -- (人→座標) -> (人j, 距離) -> Maybe (人→座標)
        -- 人j を 人i との距離情報に従っておく．矛盾なら Nothing
        h pos (j, d)
          | j `IM.member` pos =
              bool Nothing (Just pos) (pos!j == pj)
          | otherwise = g j pj pos
          where pj = pi + d

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine
  edge <- replicateM m readIntsLn
  let
    nbr = foldr f emps edge
    f [l,r,d] nbr
      = IM.adjust ((r,d):) l $ IM.adjust ((l,-d):) r nbr
    emps = IM.fromDistinctAscList $ zip [1..n] $ repeat [] 
  putStrLn $ bool "No" "Yes" $ solve n nbr

readIntsLn
  = unfoldr (B.readInt . B.dropWhile(==' ')) <$> B.getLine

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	vector<int> input;
	rep(i, n){
		int a;
		cin >> a;
		input.push_back(a);
	}

	sort(all(input));

	int ans = 0;

	rep(i, k){
		ans += input[i];
	}

	cout << ans;
	
	return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(){
  int x,y;
  int n,m;
 
  scanf("%d%d",&x,&y);
  if(x>y){
    n=x;
    x=y;
    y=n;
  }
  n=x;
  m=y;
  while(1){
   x=m%n;
   if(x==0)break;
   m=n;
   n=x;
   if(n==0)break;
  }

  printf("%d\n",n);

  return 0;
}

Measured memory_bytes: 592
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    private static int fact(int n) { int ans=1; for(int i=2;i<=n;i++) ans*=i; return ans; }
    
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int mx = (int)1e6+5;
        long ans[] = new long[mx];
        
        for(int i=1;i<mx;i++){
            if(i%3==0 || i%5==0) ans[i]=-1;
            else ans[i]=i;
        }
        for(int i=1;i<mx;i++){
            if(ans[i]==-1) ans[i]=ans[i-1];
            else ans[i]+=ans[i-1];
        }
        int n = in.nextInt();
        out.println(ans[n]);
        
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 40748
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		in := stdin.Text()
		out, _ := do(in)
		fmt.Println(out)
	}

}

func do(in string) (string, error) {
	s := strings.Split(in, " ")
	return s[1] + s[0], nil
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;


int N, M, Q;
vector<int>a, b, c, d;
vector<int> buf;
int sum;

int main() {

	ll A,B,X;
	cin >> A>>B>>X;
	ll x;
	
	ll big,tmp;
	big = 0;
	if (B == 1) {

		cout << 0;
		return 0;

	}
	ll tmp1;
	ll tmp2;
	ll i=1;
		if (i * (B - 1) <= X) {
			x = (B - 1) * i;
			tmp1 = (A * x) / B;
			tmp2 = x / B;
			tmp = tmp1 - A * tmp2;
			big = max(tmp, big);
		
		}
		else {

			x = X;
			tmp1 = (A * x) / B;
			tmp2 = x / B;
			tmp = tmp1 - tmp2 * A;
			big = max(tmp, big);
			
			
		}
		
	cout << big;
}



Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int n, m, ans, table[9][9];

int chack(){
	for(int i=0; i<n; i++){
		int tmp=0;
		for(int j=0; j<n; j++) tmp += table[i][j];
		if(tmp) return 0;
	}
	return 1;
}


void dfs(int x, int y){
	if(x < n-1) x++;
	else if(y < n-1){
		x=0;
		y++;
	} else{
		ans += chack();
		return;
	}

	if(x==0 && 0<y){
		int tmp =0;
		for(int i=0; i<n; i++) tmp += table[y-1][i];
		if(tmp) return;
	}

	if(table[y][x] == 0 && y != x){
		table[y][x] = 1;
		table[x][y] = -1;
		dfs(x, y);

		table[y][x] = -1;
		table[x][y] = 1;
		dfs(x, y);

		table[y][x] = table[x][y] = 0;
	} else dfs(x, y);
}


int main(void) {
	while(1) {
		cin >> n;
		if(!n) break;
		fill(table[0], table[8], 0);
		cin >> m;
		for(int i=0; i<m; i++){
			int x, y; cin >> x >> y;
			x--; y--;
			table[x][y] = 1;
			table[y][x] = -1;
		}

		ans = 0;
		dfs(0, 0);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int N = sc.nextInt();
    int n = 0;
    int y = 0;
    
    for(int i = 0;i < N;i++){
        int a = sc.nextInt();
        if(a % 2 == 0){
            if(a % 3 == 0 || a % 5 == 0){
                y++;
            }else{
                n++;
            }
        }else{

        }    
    }
    if(n > 0){
        System.out.println("DENIED");
    }else{
        System.out.println("APPROVED");
    }
  }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = 1000000007;

int main() {
    int N; cin >> N;
    vi A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(), A.end(), greater<int>());
    ll ans = A[0];
    rep(i,N-2){
        ans += A[i/2+1];
    }

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


Measured memory_bytes: 4052
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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


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


int main(){
int n;
cin>>n;
vector<long long>h(n);
for(int i=0;i<n;i++){
    cin>>h[i];
}
vector<long long>dp(n);
for(int i=0;i<n;i++){
    dp[i]=INF;
}
dp[0]=0;
for(int i=1;i<n;i++){
    chmin(dp[i],dp[i-1]+abs(h[i-1]-h[i]));
    if(i>1){
        chmin(dp[i],dp[i-2]+abs(h[i-2]-h[i]));
    }
}
cout<<dp[n-1]<<endl;
}

    










Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanString()
	fmt.Fprintln(wr, s[:3])
}


Measured memory_bytes: 1764
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define Cin cin>>a;

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main(void){
	string s;
	cin >> s;
	int a = stoi(s);
	vector<int>num(4);
	rep(i, 4) {
		num[i] = a % 10;
		a /= 10;
		//cout << num[i] << endl;
	}
	reverse(all(num));
	rep(i, 4) {
	//	cout << num[i] << endl;
	}
	bool my = false;
	bool ym = false;
	int form = num[0] * 10 + num[1];
	int latt = num[2] * 10 + num[3];
	if (form <=12&& form>=1) {
		if (latt>=0&&latt<=99) {
			my = true;
		}
	}

	if (latt <=12&& latt >=1) {
		if (form<=99&&form>=0) {
			ym = true;
		}
	}
	//if (my) {
		//cout << "my" << endl;
	//}
	//if (ym) {
		//cout << "ym" << endl;
	//}
	if (ym && my) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (ym) {
		cout << "YYMM" << endl;
	}
	else if (my) {
		cout << "MMYY" << endl;
	}
	else {
		cout << "NA" << endl;
	}
}


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

int main() {
  int N, X; cin >> N >> X;
  int count = 0;
  int L[110];
  int D[110];
  for (int i = 0; i < N; ++i) cin >> L[i];
  
  D[0] = 0;
  
  for (int i = 1; i <= N; ++i) {
    D[i] = D[i-1] + L[i-1];
  }
  
  for (int i = 0; i <= N; ++i) {
    if (D[i] <= X) count++;
  }
  
  cout << count << endl;
  

  
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
s = [input() for _ in range(n)]
tail_a = 0
head_b = 0
both_have = 0
ans = 0
for i in range(n):
    if s[i][0] == "B": head_b += 1
    if s[i][-1] =="A": tail_a += 1
    if s[i][0] == "B" and s[i][-1] =="A":
        both_have += 1
    ans += s[i].count("AB")
ans += min(tail_a,head_b)
if tail_a == head_b and tail_a == both_have:
    if both_have > 0:
        ans -= 1
print(ans)

Measured memory_bytes: 44888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const ll INF = (ll)1e18;

struct Stack {
	vector<ll> vals, maxs;

	Stack() : vals(), maxs({-INF}) {}

	void push(ll x) {
		vals.push_back(x);
		maxs.push_back(max(x, maxs.back()));
	}
	ll pop() {
		maxs.pop_back();
		ll x = vals.back();
		vals.pop_back();
		return x;
	}
	ll getMax() const {
		return maxs.back();
	}
	bool empty() const {
		return vals.empty();
	}
};
struct Queue {
	Stack A, B;

	Queue() : A(), B() {}

	void push(ll x) {
		A.push(x);
	}
	ll pop() {
		if (B.empty()) {
			while(!A.empty()) {
				B.push(A.pop());
			}
		}
		assert(!B.empty());
		return B.pop();
	}
	ll getMax() {
		return max(A.getMax(), B.getMax());
	}
};

const int N = 100100;
int n, m, k;
ll a[N];
ll dp[N];

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		dp[i] = a[i];
	}
	for (int it = 2; it <= k; it++) {
		Queue Q = Queue();
		for (int i = 0; i < n; i++) {
			ll x = dp[i];
			if (i - m - 1 >= 0) Q.pop();
			dp[i] = Q.getMax() + it * a[i];
			Q.push(x);
		}
	}
	ll ans = -INF;
	for (int i = 0; i < n; i++)
		ans = max(ans, dp[i]);
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 8764
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,a[400005],nx[200005],la[200005],b[200005],u[200005];
bool ok;
ll m;
int main(){
    scanf("%d%lld",&n,&m);
    for(int i=1;i<=n;++i)scanf("%d",a+i),a[n+i]=a[i];
    for(int i=n*2;i>n;--i)la[a[i]]=i;
    for(int i=n;i;--i)nx[i]=la[a[i]],la[a[i]]=i;
    memset(la,0,sizeof(la));
    int o=1,k=1;
    while(1){
        if(o>m){
            break;
        }
        if(o==m){
            int _=0;
            for(int i=k;i<=n;++i){
                if(u[a[i]]){
                    while(b[_]!=a[i])u[b[_--]]=0;
                    u[b[_--]]=0;
                }
                else{
                    u[b[++_]=a[i]]=1;
                }
            }
            if(!_) break;
            for(int i=1;i<_;++i)printf("%d ",b[i]);
            printf("%d\n",b[_]);
            break;
        }
        if(!ok&&la[k]){
            ok=1;
            int _=o-la[k];
            m-=((m-o-1)/_)*1ll*_;
        }
        else{
            la[k]=o;
            k=nx[k]+1;
            while(k>n)k-=n,++o;
        }
    }
    //ystem("pause");
    return 0;
}


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

#define pii pair<int, int>
#define mp make_pair

const int maxN = 505;

int n, mod, ans, m;
int f[maxN + 1][maxN + 1];

pii a[maxN + 1];

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

inline int SUB(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }

int main()
{
	scanf("%d %d", &n, &mod);
	
	int p = 2 * n - 1, q = 2 * n - 1;
	for(int i = 0; i < 2 * n; i++)
	{
		while(i * i + p * p > (2 * n) * (2 * n) && p >= 0) p --;
		while(i * i + q * q >= n * n && q >= 0) q --;
		if(q < 0) a[++ m] = mp(p + 1, 0);
		else a[++ m] = mp(q + 1, p + 1);
	}

	sort(a + 1, a + m + 1);

	for(int k = 0; k <= n; k++)
	{
		memset(f, 0, sizeof(f));
		f[0][0] = 1;
		int s0 = 0, s1 = 0;
		for(int i = 1; i <= m; i++)
		{
			for(int j = 0; j <= k; j++)
			{
				int res = f[i - 1][j];
				if(!a[i].second) f[i][j] = ADD(f[i][j], 1ll * res * (a[i].first - s0 - j) % mod);
				else
				{
					if(j < k) f[i][j + 1] = ADD(f[i][j + 1], 1ll * res * (a[i].first - s0 - j) % mod);
					f[i][j] = ADD(f[i][j], 1ll * res * (a[i].second - k - n - (s1 - j)) % mod);
				}
			}
			if(!a[i].second) s0 ++;
			else s1 ++;
		}
		ans = (k & 1) ? SUB(ans, f[m][k]) : ADD(ans, f[m][k]);
	}

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[100010],ans=0;
    cin>>n;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        if(a[a[i]-1]==i+1) ans++;
    }
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  int ans = 0;
  for(int i =0; i < (int)s.size(); ++i){
    if((int)s[i] == '1'){
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256