akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

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

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



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

    map<int, int>f,s;
    for(int i=0;i<n;i++){
        if(i%2){
            f[a[i]]++;
        }else{
            s[a[i]]++;
        }
    }
    int fx=0, sx=0;
    int pf, ps;
    for(auto i : f){
        if(i.second>fx){
            pf=i.first;
            fx=max(fx, i.second);
        }
    }
    for(auto i:s){
        if(i.first!=pf&&i.second>sx){
            ps=i.first;
            sx=max(sx,i.second);
        }
    }

    int res1, res2;
    res1=n-fx-sx;

    fx=0, sx=0;
    for(auto i : s){
        if(i.second>sx){
            ps=i.first;
            sx=max(sx, i.second);
        }
    }
    for(auto i:f){
        if(i.first!=ps&&i.second>fx){
            pf=i.first;
            fx=max(fx,i.second);
        }
    }
    res2=n-fx-sx;

    cout<<min(res1,res2)<<endl;

    return 0;
}

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

	int main(){
      int a,b,c;
      cin >> a >> b >>c;
      int r;
      for (int i=0;i<b;i++){
        if (a*i%b==c){
          cout << "YES";
          return 0;
        }
      }
      cout << "NO";
    }


Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
map<int,vector<int> >yo;
map<int,int>vis;
vector<pi>vec;
map<int,vector<int> >nisi;
set<int>types;
 main()

{
    fast
    int n,k;
    cin>>n>>k;
    f(i,1,n)
    {
        int t,d;
        cin>>t>>d;
        yo[t].pb(d);
        vec.pb(mp(d,t));
        types.insert(t);
    }
    for(auto x:yo)
    {
        sort(yo[x.fi].begin(),yo[x.fi].end());
    }
    int ses=0;
    sort(vec.rbegin(),vec.rend());
    for(int i=0;i<k;i++)
    {
        int typ=vec[i].si;
        int val=vec[i].fi;
        ses+=val;
        nisi[typ].pb(val);
        vis[typ]=1;
    }
    vector<int>fre,nw;
    int sz=nisi.size();
    ses+=(sz*sz);
    int cost=ses;
    for(auto x:nisi)
    {

        sort(nisi[x.fi].begin(),nisi[x.fi].end());
        nisi[x.fi].pop_back();
        for(auto y:nisi[x.fi])
        {
            fre.pb(y);
        }
    }
    for(auto t:types)
    {
        if(vis.count(t)==0)
        {
            nw.pb(yo[t].back());
        }
    }
    sort(fre.rbegin(),fre.rend());
    sort(nw.rbegin(),nw.rend());
    for(auto x:nw)
    {
        if(fre.size()==0)break;
        ses-=(sz*sz);
        ses-=fre.back();
        fre.pop_back();
        ses+=x;
        sz++;
        ses+=(sz*sz);
        cost=max(cost,ses);
    }
    cout<<cost<<endl;
    return 0;

}






































Measured memory_bytes: 29892
import bisect
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
ans = 0
for i in range(n):
	if x-a[i] >= 0 and i != n-1:
		x = x-a[i]
		ans += 1
	elif i == n-1:
		if x-a[i]==0:
			ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
 
/*---------------------------------------------------------------------------------------------------*/
void solve()
{
    int n;
    cin >> n;

    int a[n], sum[n];

    cin >> a[0];
    sum[0] = a[0];

    fp (i, 1, n - 1) 
    {
        cin >> a[i];
        sum[i] = a[i] + sum[i - 1];
        // sum[i] %= mod;

    }

    int ans = 0;

    f (i, n)
    {
        int curr = sum[n - 1] - sum[i];
        curr %= mod;

        curr *= a[i];
        curr %= mod;
        ans += curr;
    }

    cout << ans % mod;
} 
 
signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--) solve();
  return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

string a, b, c;

int main(void) {
  // Here your code !
  cin >> a >> b >> c;

  printf("%c%c%c\n", a[0], b[1], c[2]);

  return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector <int> hs(n);
    rep(i,n) {
        cin>>hs[i];
    }
    int count=0;
    int max=0;
    rep(i,n) {
        if (hs[i]>=max) {
            max=hs[i];
            count+=1;
        }
    }
    cout<<count<<endl;
}

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

int main(){
    int a, b, c, d;
    int left, right;

    cin >> a >> b >> c >> d;

    left = a + b;
    right = c + d;

    if (left > right){
        cout << "Left" << endl;
    }
    else if (left == right)
    {
        cout << "Balanced" << endl;
    }
    else
    {
        cout << "Right" << endl;
    }
    
    
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>

using namespace std;
bool vis[200];
int que[100],sum[100];
int tot;
void get(){
    tot=0;
    for(int i=2;i<=100;i++){
        int tmp=i*i;
        if(!vis[i]){
            que[++tot]=i;
            //cout<<i<<endl;
        if(tmp>100) continue;
            while(tmp<=100){
                vis[tmp]=true;
                tmp+=i;
            }
        }
    }
}
int main(){
    int n;
    get();
    scanf("%d",&n);
    int res=0,ans=0;
    for(int i=1;i<=tot;i++){
        int pp=0;
        for(int j=que[i];j<=n;j+=que[i]){
            int tmp=j;
            while(!(tmp%que[i])){
                pp++;
                tmp/=que[i];
            }
        }
        //cout<<pp<<' '<<i<<endl;
        sum[i]=pp;
        /*if(que[i]>=5){
            if(que[i]*4<=n) ans++,res++;
            else if(que[i]*2<=n) ans++;
        }
        else if(que[i]<5){
            if(que[i]*que[i]<=n) ans++,res++;
            else if(que[i]*2<=n) ans++;
        }*/
    }
    int a=0,b=0,c=0,d=0,p=0;
    //cout<<res<<' '<<ans<<endl;
    for(int i=1;i<=tot;i++){
        if(sum[i]>=74) p++;
        if(sum[i]>=24) a++;
        if(sum[i]>=14) b++;
        if(sum[i]>=4) c++;
        if(sum[i]>=2) d++;
    }
    //cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
    int ANS=a*(d-1);
    ANS+=b*(c-1);
    ANS+=((c-1)*c/2)*(d-2);
    ANS+=p;
    printf("%d\n",ANS);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <iterator>
#include <math.h>
#include <cstdlib>
#include <cmath>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
int main(){
  int A , B;
  cin >> A >> B;
  cout << max(A + B,max(A-B,A*B)) << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc081_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            bool flag = true;
            int ret = 0;
            while (flag)
            {
                for (int i = 0; i < n; i++)
                {
                    if (x[i] % 2 == 0)
                    {
                        x[i] /= 2;
                    }
                    else
                    {
                        flag = false;
                    }
                }
                ret++;
            }
            Console.WriteLine(ret - 1);
        }
    }
}

Measured memory_bytes: 11332
def main():
    N = int(input())
    div = pow(10, 9) + 7
    # AGC, A#GC, AG#C, GAC, ACG
    # #AG (-> C not allowed) done
    # A#G (-> C not allowed)
    # AG# (-> C not allowed) done
    # #GA (-> C not allowed) done
    # #AC (-> G not allowed)
    three = [""]
    for _ in range(3):
        temp = []
        for s in three:
            for c in "ACGT":
                temp.append(s + c)
        three = temp
    d = dict()
    for s in three:
        if s not in ["AGC", "GAC", "ACG"]:
            d[s] = 1
    for _ in range(3, N):
        temp = dict()
        for s in d:
            NotAllowed = forbidden(s)
            for c in "ACGT":
                if c not in NotAllowed:
                    temp[s[1:]+c] = temp.get(s[1:]+c, 0) + d[s]
        d = temp
    ans = 0
    for s in d:
        ans += d[s] % div
    return ans % div

def forbidden(s):
    if s[1:] == "AG" or s[1:]=="GA" or s[:2] == "AG" or (s[0]== "A" and s[2]== "G"):
        return ["C"]
    if s[1:] == "AC":
        return ["G"]
    else:
        return []


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		cs: Chars,
	}

	if cs[0] == '9' || cs[1] == '9' {
		println!("Yes");
	}
	else {
		println!("No");
	}
}



Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long N; cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	bool T = false;
	for (int i = 0; i < N-1; i++)
	{
		if (A[i] == A[i + 1])T = true;
	}
	if (T)cout << "NO";
	else cout << "YES";
}

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

#include <string>
#include <vector>
int main(){
    int x; cin >> x;
    int a,b;
    for(a=-118; a<=119; a++){
        int a5 = a*a*a*a*a;
        for(b=a-1; b>=-119; b--){
            if(x%(a-b))continue;
            if(x==a5-b*b*b*b*b){
                printf("%d %d\n",a,b);
                return 0;
            }
        }
    }
}

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

using namespace std;

void Main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<int> > c(H, vector<int>(W, 0));
    for (int i = 0; i < H; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < W; ++j) {
            c[i][j] = (s[j] == '#' ? 1 : 0);
        }
    }

    int ans = 0;
    for (int ih = 0; ih < (1 << H); ++ih) {
        for (int jw = 0; jw < (1 << W); ++jw) {
            vector<vector<int> > cred = c;
            bitset<6> bith(ih);
            bitset<6> bitw(jw);
            for (int i = 0; i < H; ++i) {
                if (bith[i]) {
                    for (int k = 0; k < W; ++k) {
                        cred[i][k] = 2;
                    }
                }
            }
            for (int j = 0; j < W; ++j) {
                if (bitw[j]) {
                    for (int k = 0; k < H; ++k) {
                        cred[k][j] = 2;
                    }
                }
            }

            int n = 0;
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    if (cred[i][j] == 1) {
                        ++n;
                    }
                }
            }
            if (n == K) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>
#include <ctime>
#include <numeric>
#include <cstdlib>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
int A, B;
int P;
int X[3];

int main(){
	
	cin>>N>>A>>B;
	REP( i, N ){
		cin>>P;
		if( P <= A ){		X[0]++;}
		else if( P <= B ){	X[1]++;}
		else{			X[2]++;}
	}
	
	cout<<min( X[0], min(X[1], X[2]) )<<endl;
	
	return 0;
	
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
m =max(a)
arr = [0]*(m+1)

for i in a:
  for j in range(i,m+1,i):
    arr[j]+=1

cnt = 0
for i in a:
  if arr[i] ==1:
    cnt += 1

print(cnt)

Measured memory_bytes: 32188
import sys, math
def input(): return sys.stdin.readline().strip()


def main():
    K = int(input())
    ans = 0
    add = 0
    for a in range(1, K + 1):
        for b in range(a + 1, K + 1):
            d = math.gcd(a, b)
            add += d
            for c in range(b + 1, K + 1):
                ans += math.gcd(d, c)
    ans *= 6
    ans += add * 6
    ans += K * (K + 1) // 2
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 67768
#include<stdio.h>

int n;
int a[1000] = {0};
int main(void){
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)	scanf("%d",&a[i]);
int cnt = 0;
  	for(int i = 1;i <= n;i++){
    	if(i % 2 == 1 && a[i] % 2 == 1) cnt++;
    }

 printf("%d",cnt);

}


Measured memory_bytes: 1728
N,K = map(int,input().split())
h_list = list(map(int,input().split()))

costs = [float("inf") for _ in range(N+K) ]
costs[0] = 0
h_list += [0 for _ in range(K)]

for i in range(N):
    for j in range(i+1,i+K+1):
        cost = abs(h_list[i] - h_list[j])
        costs[j] = min(costs[i]+cost, costs[j])

print(costs[N-1])

Measured memory_bytes: 56928
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  ns <- inpi $ split toInt
  mapM_ print $ solve ns

solve :: [[Int]] -> [Int]
solve = map sumOfNthDecimalPlaces

sumOfNthDecimalPlaces :: [Int] -> Int
sumOfNthDecimalPlaces [a, b, n] = so1dp 0 n (a `mod` b)
  where so1dp acc c x | c == 0 = acc
                      | otherwise = so1dp (acc + (10 * x) `div` b) (c - 1) ((10 * x) `mod` b)

toInt :: String -> Int
toInt s = read s

split :: (String -> a) -> String -> [a]
split f = map f . words

inpi :: (String -> a) -> IO [a]
inpi f = map f . lines <$> getContents

Measured memory_bytes: 4140
a, b = map(int,input().split())

if a == 1 and b == 1:
    print("Draw")
elif a == 1 or b == 1 :
    if a == 1:
        print("Alice")
    else:
        print('Bob')
else:
    if a == b :
        print("Draw")
    else:
        if a > b :
            print("Alice")
        else:
            print("Bob")        


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int w,h,mp[20][20],sx,sy,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};

int dfs(int x,int y,int d){
  if(d==10)return 11;
  int res=11;
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0||w<=nx||ny<0||h<=ny||mp[ny][nx]==1)continue;
    while(0<=nx&&nx<w&&0<=ny&&ny<h&&mp[ny][nx]!=1){
      if(mp[ny][nx]==3)return d+1;	    
      nx+=dx[i],ny+=dy[i];
    }
    if(nx<0||w<=nx||ny<0||h<=ny)continue;
    mp[ny][nx]=0;
    res=min(res,dfs(nx-dx[i],ny-dy[i],d+1));
    mp[ny][nx]=1;
  }
  return res;
}

int main(){
  while(cin>>w>>h,w){
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin>>mp[i][j];
	if(mp[i][j]==2)sx=j,sy=i;
      }
    int ans=dfs(sx,sy,0);
    if(ans==11)ans=-1;
    cout<<ans<<endl;
  }
  return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int k; cin >> k;
    string ans = "";
    rep(_,k){
        string s = "ACL";
        ans += s;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
# Palindromic Numbers
import sys

A, B = map(int, input().split())

def getAns(a, b) :
    cnt = 0
    for x in range(a, b + 1) :
        L = [0] * 5
        wkX = x
        for _ in range(0, 5) :
            L[_] = wkX % 10
            wkX = wkX // 10
        if L[0] == L[4] and L[1] == L[3] :
            cnt += 1
    return cnt

print(getAns(A, B))

Measured memory_bytes: 3064
t,*g=open(0);h,w=map(int,t.split());v=[[0]*w for _ in range(h)];v[0][0]=1;q=[(0,0)]
while q:
	a,b=q.pop(0)
	for c,d in((-1,0),(0,-1),(1,0),(0,1)):
		x=a+c;y=b+d
		if w>x>=0<=y<h and v[y][x]<1 and g[y][x]==".":q+=[(x,y)];v[y][x]=v[b][a]+1
t=v[-1][-1];print((-1,sum(c.count(".")for c in g)-t)[t>0])


Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
    cin>>a>>b>>c;
    if(a==b&&a!=c)cout<<"Yes"<<endl;
    else if(a==c&&a!=b)cout<<"Yes"<<endl;
    else if(b==c&&a!=b)cout<<"Yes"<<endl;
    
    else if(a!=c&&a!=b&&b!=c)cout<<"No"<<endl;
    else if(a==c&&a==b)cout<<"No"<<endl;
}


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

int main(){
    int n;
    cin>>n;
    int nb=n,fn=0;
    while(nb!=0){
        fn+=nb%10;
        nb/=10;
    }
    cout<<(n%fn==0?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort(ALL(c))
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


int main() {
    LL N;
    cin >> N;
    LL n_inside = 0, n_both = 0, n_suf_a = 0, n_pre_b = 0;
    REP(i, N) {
        string S;
        cin >> S;
        if (S[0] == 'B' && S[SZ(S) - 1] == 'A') {
            n_both++;
        } else if (S[SZ(S) - 1] == 'A') {
            n_suf_a++;
        } else if (S[0] == 'B') {
            n_pre_b++;
        }
        REP(j, SZ(S) - 1) {
            if (S[j] == 'A' && S[j + 1] == 'B') {
                n_inside++;
            }
        }
    }
    /*dump(n_inside);
    dump(n_both);
    dump(n_suf_a);
    dump(n_pre_b);*/
    LL ans = n_inside;
    if (n_both > 1) {
        ans += n_both - 1;
    }
    if (n_both > 0) {
        if (n_suf_a > 0 && n_pre_b > 0) {
            ans += 2;
            n_suf_a--;
            n_pre_b--;
        } else if (n_suf_a > 0 || n_pre_b > 0) {
            ans++;
        }
    }
    if (n_suf_a > 0 && n_pre_b > 0) {
        ans += min(n_suf_a, n_pre_b);
    }
    cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 256
def equal(n, available):
  return n in available 

def less(n, available):
  return n < sorted(available, reverse=True)[0]

def greater(n, available):
  return n > sorted(available, reverse=True)[0]
  

#less(n, available) == True であること
def upper_next(n, available):  
  for v in sorted(available):
    if n < v:
      return v
  return 1/0

  
n_str, _ = [v for v in input().split()]
n_s = [0]
n_s.extend([int(n_str[i:i+1]) for i in range(len(n_str))])
#print(n_s)
d_s = [int(v) for v in input().split()]

available = set(list(range(10))) - set(d_s)

#print("n", n_s, "d", d_s, "u", available)

min_available = sorted(available)[0]
max_available = sorted(available, reverse=True)[0]
#print(min_available, max_available)
ans = [0]
ans.extend([min_available] * (len(n_s) - 1))

eq = True
for i in range(1, len(n_s)):
  #print(ans)
  if eq:
    if equal(n_s[i], available):
      ans[i] = n_s[i]
      continue
    else:
      eq = False
      #print(n_s[i], available)
      if less(n_s[i], available):
        ans[i] = upper_next(n_s[i], available)
        #残りは最小値詰め
        break
      else:
        for j in range(i - 1, -1, -1):
          #print(ans)
          if ans[j] == max_available:
            ans[j] = min_available
          else:
            #print(ans)
            ans[j] = upper_next(ans[j], available)
            #print(ans)
            break
        break

#print(ans)
begin = 0
if ans[0] == 0:
  begin = 1
ans_val = "".join(map(lambda x:str(x), ans[begin:]))

print(ans_val)

Measured memory_bytes: 3064
import sys

s=input()
c_count=0
flag=False


for ss in s:
    if ss.isupper():
        if ss!='A' and ss!='C':
            print('WA')
            sys.exit()

if s[0]=='A':
    for i in range(2,len(s)-1):
        if s[i]=='C':
            c_count+=1

if c_count==1:
    flag=True

if flag:
    print("AC")
else:
    print("WA")
    


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#define MAX 101
#define max(a, b) ((a>b) ? (a) : (b))
#define min(a, b) ((a<b) ? (a) : (b))
int main(void) {
    long long i, j, len, a[11], t, sum=0;
    char s[11];
    scanf("%s", s);
    len = strlen(s);
    
    for(i=0; i<len; i++)
        a[i] = s[i] - '0';
    
    for(i=0; i<1<<(len-1); i++) {
        t=a[0];
        for(j=0; j<len-1; j++) {
            if(1&i>>j) {
                sum += t;
                t = a[j+1];
                
            }else {
                t *= 10;
                t += a[j+1];
                
            }
        }
        sum += t;
    }
    printf("%lld\n", sum);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef tuple<int, int, int> t3;

int N, W, w[110], v[110];

void solve(){
	scanf("%d%d", &N, &W);
	for(int i=0;i<N;i++)scanf("%d%d", w+i, v+i);
	ll ans = 0;
	for(int i=1;i<=N;i++){
		if((ll)w[0] * i > W) break;
		int t = W - w[0] * i;
		ll d[330][330] = {};
		for(int j=1;j<330;j++)d[0][j] = -1e18;
		for(int j=0;j<N;j++){
			int tw = w[j] - w[0];
			int tv = v[j];
			for(int k=j+1;k;k--){
				for(int u=tw;u<=3*k;u++){
					d[k][u] = max(d[k][u], d[k-1][u-tw] + tv);
				}
			}
		}
		for(int j=0;j<=3*N && j<=t;j++)ans = max(ans, d[i][j]);
	}
	printf("%lld\n", ans);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

bool substring_search(string s,string key){
    int count=0;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]==key[count]) count++;
        if(count==(int)key.size()) return true;
    }
    return false;
}

int main()
{
	ll n,ans=0;
	string s;
	cin >> n >> s;
	string a[]={"0","1","2","3","4","5","6","7","8","9"};
	rep(i,10){
		rep(j,10){
			rep(k,10){
				string t=a[i]+a[j]+a[k];
				if(substring_search(s,t)) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
n=int(input())
s=[]
m=0
a=0
r=0
c=0
h=0
for i in range(n):
  b=str(input())[0]
  if b=="M":m+=1
  elif b=="A":a+=1
  elif b=="R":r+=1
  elif b=="C":c+=1
  elif b=="H":h+=1
  s.append(b)

ans=0

ans+=m*a*r
ans+=m*a*c
ans+=m*a*h
ans+=m*r*c
ans+=m*r*h
ans+=m*c*h
ans+=a*r*c
ans+=a*r*h
ans+=a*c*h
ans+=r*c*h     
print(ans)

Measured memory_bytes: 3884
n,k = map(int,input().split())
s = input()
a = []
b = []
c = 0
d = "1"
for i in s:
  if d == i:
    c += 1
  else:
    if d == "1":
      b.append(c)
      d = "0"
      c = 1
    else:
      a.append(c)
      d = "1"
      c = 1
if d == "1":
  b.append(c)
else:
  a.append(c)
  b.append(0)
if k >= len(a):
  print(n)
else:
  e = sum(a[:k])+sum(b[:k+1])
  ans = e
  for i in range(len(a)-k):
    e = e-a[i]-b[i]+a[i+k]+b[i+k+1]
    ans = max(ans,e)
  print(ans)

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

A=[0]+list(map(int,input().split()))

for i in reversed(range(1,n+1)):
    if sum(A[::i])%2!=A[i]:
        A[i]^=1
        
print(sum(A))
if sum(A)!=0:
    for i,a in enumerate(A):
        if a==1:
            print(i)

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int h, w, n, x, y;
  cin >> h >> w >> n;

  auto inside = [&](int x, int y) { // not on edge
    return 0 < x && x < h - 1 && 0 < y && y < w - 1;
  };

  map< pair<int,int>, int > g;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    x--; y--;
    for (int j = -1; j <= 1; j++) {
      for (int k = -1; k <= 1; k++) {
        if (inside(x + j, y + k)) {
          g[make_pair(x + j, y + k)]++;
        }
      }
    }
  }

  cout << (long long) (h - 2) * (w - 2) - g.size() << '\n';
  vector<int> num(10);
  for (auto i : g) {
    num[i.second]++;
  }
  for (int i = 1; i < 10; i++) {
    cout << num[i] << '\n';
  }
  return 0;
}

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

int main() {
  int n; cin >>n;
  vector<int> h(n);
  for (int i=0; i<n; i++) cin >>h.at(i);
  int buf = 0;
  int ans = 0;
  for (int i=0; i<n; i++){
    if (h.at(i) >= buf) ans += h.at(i) - buf;
    buf = h.at(i);
  }
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;

const int MOD=1e9+7;

int search(int b[], int m, int s){
	int start=0,end=m-1;
	bool flag=false;
	while(start<=end){
		int mid=(start+end)/2;
		if(b[mid]==s){
			flag=true;
			return mid;
		}
		else if(b[mid]>s) end=mid-1;
		else if(b[mid]<s) start=mid+1;
	}
	if(flag==false) return m;
}

long long int pow(long long int a, long long int b){
	if(b==0) return 1;
	long long int res=pow(a,b/2);
	if(b%2 ==1) return res*res*a;
	else if(b%2 ==0) return res*res;
}

int main(){

	long long int a,b,n; cin>>a>>b>>n;
	long long int prod=a*min(n,b-1);

	cout<<prod/b<<endl;

	return 0;
} 

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

using namespace std;

bool check(string s)
{
    string t = s;
    reverse(s.begin(),s.end());
    if(t == s)
        return true;
    return false;
}
int main()
{
    string s, g, z; cin >> s;
    int n = s.size();
    g = s.substr(0, n/2);
    z = s.substr((n+1)/2, n);
    if(check(s) and check(g) and check(z))
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end());
#define fill(a,x) memset(a,x,sizeof(a))
#define zero(a) fill(a,0)
#define minus(a) fill(a,-1)
#define dbg(x) cout << #x"=" << x << endl

const int INF=INT_MAX/3;
const int LIMIT=pow(10,5);

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};

int n;
int a[LIMIT];
int pat=0;
int ans=1;

int main(){
  cin>>n;
  rep(i,n)cin>>a[i];
  rep(i,n-1){
    if(pat==0){
      if(a[i]==a[i+1]);
      else if(a[i]>a[i+1]) pat=1;
      else pat=-1;
    }else if(pat==-1){
      if(a[i]>a[i+1]){
        ans++;
        pat=0;
      }
    }else if(pat==1){
      if(a[i]<a[i+1]){
        ans++;
        pat=0;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

int main(){
	ll N; cin>>N;
    ll cnt=0;
    vector<ll> a(N+1);
    vector<ll> b(N+1,0);//箱
    rep1(i,N) cin>>a[i];
    for(int i=N;i>=(N/2)+1;i--){
        b[i]=a[i];
        if(b[i]==1) cnt++;
    }
    for(int i=N/2;i>=1;i--){
        ll tmp=0;
        for(int j=i*2;j<=N;j+=i){
            tmp+=b[j];
        }
        b[i]=a[i]^(tmp%2);
        if(b[i]==1) cnt++;
    }
    cout<<cnt<<endl;
	for(int i=1;i<=N;i++){
        if(b[i]==1) printf("%d ",i);
    }
}

Measured memory_bytes: 3968
import kotlin.math.max
import kotlin.math.min

class LoopSequenceSum(untilLoop: LongArray, inLoop: LongArray, private val mod: Long) {
    private val mUntilLoop: LongArray = LongArray(untilLoop.size + 1){0L}
    private val mInLoop: LongArray = LongArray(inLoop.size + 1) {0L}
    private val untilLoopSize = untilLoop.size
    private val loopSize = inLoop.size
    init {
        for (i in untilLoop.indices) {
            mUntilLoop[i + 1] = untilLoop[i] + mUntilLoop[i]
        }
        for (i in inLoop.indices) {
            mInLoop[i + 1] = inLoop[i] + mInLoop[i]
        }
    }
    operator fun get(length: Long): Long {
        if (length <= untilLoopSize) return mUntilLoop[length.toInt()]
        return mUntilLoop.last() + getInLoop(length - untilLoopSize)
    }
    private fun getInLoop(length: Long): Long {
        val loopCount = length / loopSize
        val rest = length % loopSize
        return loopCount * mInLoop.last() + mInLoop[rest.toInt()]
    }
    companion object {
        operator fun invoke(x: Int, m: Int): LoopSequenceSum {
            val prev = IntArray(m.toInt()){-1}
            var count = 0
            var current = x.toLong()
            while (prev[current.toInt()] == -1) {
                prev[current.toInt()] = count++
                current = (current * current) % m
            }
            val untilLoop = LongArray(prev[current.toInt()]){0}
            val inLoop = LongArray(count - untilLoop.size){0}
            current = x.toLong()
            for (i in untilLoop.indices) {
                untilLoop[i] = current
                current = (current * current) % m
            }
            for (i in inLoop.indices) {
                inLoop[i] = current
                current = (current * current) % m
            }
            return LoopSequenceSum(untilLoop, inLoop, m.toLong())
        }
    }
}

fun main() {
    val (n, q) = readLine()!!.trim().split(' ').map(String::toInt)
    var right = n
    var bottom = n
    val rowMax = IntArray(n + 1){0}
    val columnMax = IntArray(n + 1){0}
    repeat(q) {
        val (type, x) = readLine()!!.trim().split(' ').map(String::toInt)
        when (type) {
            1 -> {
                columnMax[x] = bottom
                right = min(x, right)
            }
            2 -> {
                rowMax[x] = right
                bottom = min(x, bottom)
            }
            else -> TODO()
        }
    }
    var rMax = 0
    var cMax = 0
    var sum = (n.toLong() - 2) * (n.toLong() - 2)
    for (r in rowMax) {
        if (r == 0) continue
        rMax = max(rMax, r)
        sum -= rMax - 2
    }
    for (c in columnMax) {
        if (c == 0) continue
        cMax = max(cMax, c)
        sum -= cMax - 2
    }
    println(sum)
}

Measured memory_bytes: 71648
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s;
    cin >> s;
    int n = (int) s.size();
    vector<int>dp(n+1,1<<30);
    vector<int> h(1 << 26, 1<<30);//ハッシュ値がxとなるものでdpの値の最小値
    h[0] = 0;
    int k = 0;
    rep(i,n){
        k ^= (1 << (s[i] - 'a'));
        rep(j,26){
            int sub = 1 << j;
            int kk = k ^ sub;
            if(h[kk] == 1<<30)continue;
            dp[i + 1] = min(dp[i + 1], h[kk] + 1);
        }
        h[k] = min(h[k], dp[i+1]);
    }
    cout << (k == 0 ? 1 : dp[n]) << endl;
}

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

using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	
	int l1 = s.size(), l2 = t.size(), f = 0, z = -1;
	
	for (int i = l1-l2; i >= 0; i--)
	{
		f = 1;
		
		for (int j = i; j < i+l2; j++)
			f &= (s[j] == '?' || s[j] == t[j-i]);
			
		if (f)
		{
			z = i;
			break;
		}
	}
	
	if (z < 0)
	{
		cout << "UNRESTORABLE";
		return 0;
	}
	
	for (int i = 0; i < l1; i++)
		if (s[i] != '?')
			cout << s[i];
		else if (s[i] == '?' && (i < z || i >= z+l2))
			cout << "a";
		else
			cout << t[i-z];
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        scanner.close();
        if (a+b == c || a+c == b || b+c == a){
            System.out.println("Yes");
        }
        
        else{
            System.out.println("No");
        }
        
    }
}

Measured memory_bytes: 21460
import java.util.*

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)

    val n = argList.nextInt()
    val d = argList.nextInt()

    val e = GoldenApple()
    println(e.execute(n, d))

}

class GoldenApple {
    fun execute(n: Int, d: Int): Int {
        var amount = 0

        var currentTreeAmount = n

        while (currentTreeAmount > 0) {
            amount++

            currentTreeAmount -= (d * 2 + 1)
        }

        return amount
    }
}

Measured memory_bytes: 31272
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    ll A[N], S[N], T[N];
    rep(i, N){
        cin >> A[i];
    }
    S[0] = A[0], T[0] = A[N-1];
    rep2(i, 1, N-1) S[i] = S[i-1]+A[i];
    rep2(i, 1, N-1) T[i] = T[i-1]+A[N-1-i];
    //[0,i]を[0,a[i]]と(a[i], i]に分ける
    int a[N];
    rep(i, N){
        int n = upper_bound(S, S+N, S[i]/2) - S;
        if(n != 0){
            if(S[n] > S[i]-S[n-1]) n--;
        }
        a[i] = n;
    }
    //[N-1-i,N-1]を[N-1-i,N-1-b[i])と[N-1-b[i],N-1]
    int b[N];
    rep(i, N){
        int n = upper_bound(T, T+N, T[i]/2) - T;
        if(n != 0){
            if(T[n] > T[i]-T[n-1]) n--;
        }
        b[i] = n;
    }
    ll ans = INF;
    //まず[0, N)を[0,i)と[i,N)に分ける
    rep2(i, 2, N-2){
        ll tmp[4];
        tmp[0] = S[a[i-1]];
        tmp[1] = S[i-1] - tmp[0];
        tmp[2] = T[b[N-1-i]];
        tmp[3] = T[N-1-i] - tmp[2];
        sort(tmp, tmp+4);
        ans = min(ans, tmp[3]-tmp[0]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <algorithm>
#include <functional>
#include <stack>
#include <cmath>
using namespace std;

#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 llong long long

int main() {
  int a[5];
  REP(i,5) scanf("%d",a+i);
  sort(a,a+5,greater<int>());
  REP(i,4) printf("%d ",a[i]);
  printf("%d\n",a[4]);
  return 0;
}

Measured memory_bytes: 2788
class Integer
  def combination(k)
    return 1 if k.zero?

    (self - k + 1..self).inject(:*) / k.factorial
  end

  def permutation(k)
    return 1 if k.zero?

    (self - k + 1..self).inject(:*)
  end

  def factorial
    return 1 if self.zero?

    (1..self).inject(:*)
  end
end

n = gets.to_i
d = gets.split.map(&:to_i)

flag = 1

flag = 0 if d[0] != 0
ds = Hash.new(0)
d.each do |dn|
  ds[dn] += 1
end
prek = -1
ds.sort.each do |k,v|
  flag = 0 if k == 0 && 1 < v
  if prek != -1
    flag = 0 if prek+1 != k
  end
  prek = k
end

if flag == 1
  ans = 1
  prev = 1
  ds.sort.each do |k,v|
    if k >= 1
      ans *= prev**v
      prev = v
    end
  end
  puts ans % 998244353
else
  puts 0
end

Measured memory_bytes: 64772
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        double d = sc.nextDouble();
        double e = sc.nextDouble();
        double f = sc.nextDouble();
        double baseConcentration = (100 * e) / (100 + e);
        double concentration;
        double maxConcentration = 0;
        int maxSugar = 0;
        int maxSagerWater = 0;
        for(int i = 0; i * a * 100 <= f; i++) {
            for(int j = 0; j * b * 100 <= f; j++) {
                double water = i * a * 100 + j * b * 100;
                for(int k = 0; k * c <= f; k++) {
                    for(int l = 0; l * d <= f; l++) {
                        double sugar = c * k + d * l;
                        double sugarWater = sugar + water;
                        if(sugar ==  0 || water == 0) {
                            concentration = 0;
                        } else {
                            concentration = (100 * sugar) / (sugarWater);
                        }
                        if(sugarWater <= f && concentration <= baseConcentration && concentration >= maxConcentration) {
                            if(water == 0 && sugar != 0) continue;
                            maxConcentration = concentration;
                            maxSugar = (int)sugar;
                            maxSagerWater = (int)sugarWater;
                        }
                    }
                }
            }
        }
        System.out.println(maxSagerWater + " " + maxSugar);
    }
}




Measured memory_bytes: 24148
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

int main() {
	int a, b;
	cin >> a >> b;
	cout << ceil((double)(a + b) / 2) << endl;
}
	


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

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
void put_ull(long long n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[20];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
long long merge_sort(int *first, int *last) {
    const int N = (int)(last - first);
    if(N < 2) return 0;
    int *mid = first + N / 2;
    const int N1 = (int)(mid - first);
    const int N2 = (int)(last - mid);
    int *left = malloc(sizeof(int) * (N1 + 1));
    int *right = malloc(sizeof(int) * (N2 + 1));
    memcpy(left, first, sizeof(int) * (N1 + 1));
    memcpy(right, mid, sizeof(int) * (N2 + 1));
    left[N1] = right[N2] = 1 << 30;

    long long cnt = 0;
    cnt += merge_sort(left, left + N1);
    cnt += merge_sort(right, right + N2);

    for(int *it = first, i = 0, j = 0; it != last; ++it) {
        if(left[i] <= right[j]) *it = left[i++];
        else *it = right[j++], cnt += N / 2 - i;
    }
    free(left);
    free(right);
    return cnt;
}
int main(int argc, char **argv) {
    int n = get_uint();
    int a[200001];
    for(int i = 0; i < n; ++i) a[i] = get_uint();
    put_ull(merge_sort(a, a + n));
    putchar_unlocked('\n');
    return 0;
}



Measured memory_bytes: 3864
#include<stdio.h>
int i, w[20100];
int A[20100], B[20100], n;
int main(){
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
        A[i] = i*n*2;
        B[i] = (n+1-i)*n*2;
    }
    for(i=1;i<=n;i++){
        A[w[i]] += (i-1);
    }
    for(i=1;i<=n;i++)printf("%d ",A[i]);
    printf("\n");
    for(i=1;i<=n;i++)printf("%d ",B[i]);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;

int main(){
  string s; cin>>s;
  int cnt=0;
  int len=s.length();
  REP(i,len-1) if(s[i]!=s[i+1]) cnt++;
  cout<<cnt<<endl;
}


Measured memory_bytes: 512
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //String str = sc.next();
        int N1 = sc.nextInt();
        int N2 = sc.nextInt();
        int N3 = sc.nextInt();
        int N4 = sc.nextInt();
        
        if(N4==1){
            System.out.println(1);
        }else{
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 35660