akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int n;
        cin >> n;
        priority_queue <double, vector <double>, greater <double> > Q;
        for( int i = 1; i <= n; i++ ) {
                double x;
                cin >> x;
                Q.push( x );
        }
        while( Q.size() > 1 ) {
                double x = Q.top(); Q.pop();
                double y = Q.top(); Q.pop();
                Q.push( ( x + y ) * 0.5 );
        }
        cout << setprecision(5) << fixed << Q.top() << endl;
        return 0;
}










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

int main(){
  int num;
  int a,b;
  cin >> num;
  a = num/100;
  b = num - num/100*100;
  bool A,B;
  A = 0<a&&a<13;
  B = 0<b&&b<13;
  
  if(A&&B){
    cout << "AMBIGUOUS" << endl;
  }else if(A && !B){
    cout << "MMYY"<< endl;
  }else if(!A && B){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define MOD 1000000007
#define MAXN 200001
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
using namespace std;

int main() {
    ll n;
    cin >> n;
    ll a[n-1],sub[n];
    memset(sub,0,sizeof(sub));
    f(i,0,n-1){
        cin >> a[i];
        sub[a[i]-1]++;
    }
    f(i,0,n){
        cout << sub[i]<<endl;
    }
}

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

int main() {
  int N, a, b, c, d;

  cin >> N;
  
  a = N / 1000;
  
  b = (N - a * 1000) / 100;
  
  c = (N - a * 1000 - b * 100) / 10;
  
  d = N - a * 1000 - b * 100 - c * 10;
    
  if (N % 1111 == 0) {
    cout << "Yes" << endl;
  }
  else if ((N - d) % 1110 == 0) {
    cout << "Yes" << endl;
  }
  else if ((N - a * 1000) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout  << "No" << endl;
  }
}

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

using namespace std;

int main ()
{
	string weather[3] = { "Sunny", "Cloudy", "Rainy"};
 	string input;
  cin >> input;
	int i = 0;
  while(i < 3)
  {
    if(weather[i] == input)
    {
      if(i == 2)
        i = -1;
      cout << weather[i + 1] << endl; 
      break;
    }
    i++;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
typedef long long ll;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <set>
#include <cstdio>

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  const int n = getInt();
  vector<int> v(n);
  REP(i,n) v[i] = getInt();

  ll high = 0;

  sort(v.begin(), v.end());

  REP(i,n){
    const ll nlow  = v[i];
    const ll nhigh = high + v[i];

    if(nlow > high + 1)
      break;

    high = nhigh;
  }

  cout << high + 1 << endl;

  return 0;
}

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

#define F first 
#define S second
#define PB push_back
#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 200010, M = 1010;

int n, d, a;
LL s[N];
PII mon[N];

int main()
{
    scanf("%d%d%d", &n, &d, &a);
    for (int i = 1; i <= n; i ++ ) 
    {
        int x, h;
        scanf("%d%d", &x, &h);
        mon[i] = {x, h};
    }
    sort(mon + 1, mon + 1 + n);

    LL res = 0;
    for (int i = 1, j = 1; i <= n; i ++ )
    {
        s[i] += s[i - 1];
        mon[i].S -= s[i];

        if (mon[i].S <= 0) continue;
        
        while (j <= n && mon[j].F - mon[i].F <= 2 * d) j ++ ;

        LL cnt = max(0LL, (LL)(mon[i].S + a - 1LL) / a);
        s[i] += cnt * (LL)a;
        s[j] -= cnt * (LL)a;
        res += cnt;
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 6944
import Data.List
import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  ss <- sortBy pairComp . map (\xs -> (head xs, length xs)) . group . sort <$> replicateM n getLine :: IO [(String,Int)]
  let maxN = snd $ head ss
  _ <- mapM putStrLn $ map fst $ filter (\(_,x) -> x == maxN) ss
  return ()

pairComp :: (Ord a, Ord b) => (a,b) -> (a,b) -> Ordering
pairComp (s,x) (t,y) = case compare y x of
                         LT -> LT
                         GT -> GT
                         EQ -> compare s t


Measured memory_bytes: 173948
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <algorithm>


using namespace std;

int main() {
	int n;
	cin >> n;
	while (n != 0) {
		vector<pair<int, int>> data(n);

		int price, bridge;
		for (int i = 0; i < n; i++) {
			cin >> price >> bridge;
			data[i] = make_pair(bridge, price);
		}

		sort(data.begin(), data.end());

		bool failed = false;
		int total = 0;
		for (int i = 0; i < n; i++) {
			if ((total + data[i].second) > data[i].first) {
				failed = true;
				break;
			}
			total += data[i].second;
		}
		if (failed)
		{
			cout << "No" << endl;
		} else
		{
			cout << "Yes" << endl;
		}

		cin >> n;
	}

	return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX_V 100005
#define MAX_E 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P> PQ;

struct Edge {
    ll from, to, cost;
};

Edge es[MAX_E];
ll d[MAX_V];
ll N, M;
bool negative[MAX_V];
void shortest_path(ll s) {
    ll i, j;
    for(i=0; i<N; i++) d[i]=INF;
    d[s]=0;
    
    for(i=0; i<N; i++) {
        for(j=0; j<M; j++) {
            Edge e=es[j];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost) {
                d[e.to]=d[e.from]+e.cost;
            }
        }
    }
    
    for(i=0; i<=N; i++) {
        for(j=0; j<M; j++) {
            Edge e=es[i];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost) {
                d[e.to]=d[e.from]+e.cost;
                negative[e.from]=true;
            }
            
            if(negative[e.from]==true)
                negative[e.to]=true;
        }
    }
     
}

int main(void) {
    cin >> N >> M;
    
    for(ll i=0; i<M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--; c=-c;
        es[i].from=a;
        es[i].to=b;
        es[i].cost=c;
    }
    
    shortest_path(0);
    
    if(negative[N-1])
        cout << "inf" << endl;
    else
        prin(-d[N-1]);
}


Measured memory_bytes: 256
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0]*(W+1) for i in range(N+1)]

for i in range(N):
    for g in range(W+1):
        if g >= w[i]:
            dp[i+1][g] = max(dp[i][g-w[i]]+v[i], dp[i][g])
        else:
            dp[i+1][g] = dp[i][g]

print(dp[N][W])


Measured memory_bytes: 119916
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  string s; cin >> s;
  int ans = 0;
  rep(i,(int)s.size()-1) if(s[i] != s[i+1]) ans++;
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3748
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();    
        int N, M;
        {int[] a = r.ii(); N = a[0]; M = a[1];}
        int[][] sw = new int[M][];
        for(int i = 0; i < M; i++)
            sw[i] = r.ii();
        int[] p = r.ii();
        int ans = 0;
        int caseNum = (int)Math.pow(2, N);
        loop: for(int i = 0; i < caseNum; i++){
            for(int j = 0; j < M; j++){
                int t = 0;
                int[] sj = sw[j];
                for(int k = 0; k < sj[0]; k++){
                    if(bin(i, N-sj[k+1]) == 1)
                        t++;    
                }
                if(t%2 != p[j])
                    continue loop;
            }            
            ans++;
        }
        println(ans);
    }
    static int bin(int n, int right){
        int temp = n >> right;
        return temp%2;
    }
    static void print(Object o){
        System.out.print(o.toString());
    }

    static void println(Object o){
        System.out.println(o.toString());
    }

    static int Int(String s){
        return Integer.parseInt(s);
    }

    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }

        long l() throws IOException{
            return Long(s());
        }

        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}


Measured memory_bytes: 22228
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e3 + 5,MAXS = 2e5 + 2;
ll n,i,j,ans;
ll dp[MAXS];
struct S{
    ll w,s,v;
    bool operator < (const S& a) const {
        return w + s < a.w + a.s;
    }
} obj[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,0,n) cin>>obj[i].w>>obj[i].s>>obj[i].v;
    sort(obj,obj + n);
    rep(i,0,n){
        for(int w = min(obj[i].s,MAXS - 1 - obj[i].s);w >= 0;w -= 1)
            dp[w + obj[i].w] = max(dp[w + obj[i].w],dp[w] + obj[i].v);
    }
    rep(i,0,MAXS) 
        ans = max(ans,dp[i]);
    cout<<ans;
    return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    string ans = "";
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') {
            ans += '0';
        } else if (s[i] == '1') {
            ans += '1';
        } else {
            if (!ans.empty()) {
                ans.erase(ans.begin() + ans.size() - 1);
            }
        }
    }

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

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    ll n,p;cin>>n>>p;
    ll res = 1;
    map<ll,ll> mp;
    for(ll i=2;i*i<=p;i++){
        while(p%i==0){
            p /= i;
            mp[i]++;
        }
    }
    if(p!=1) mp[p]++;
    for(auto v:mp){
        res *= pow(v.first, v.second/n);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            var paramsList = Console.ReadLine().Split(' ').ToList();
            // abc
            var a = int.Parse(paramsList[0]);
            var b = int.Parse(paramsList[1]);
            var c = int.Parse(paramsList[2]);

            var canListen = b / a;
            var max = Math.Min(c, canListen);

            Console.WriteLine(max);
        }
    }

    public static class EnumerablePlus
    {
        ///<summary>出力文字列に変換。</summary>
        public static string MkString<T>(this IEnumerable<T> list)
        {
            return list.Aggregate(
                new System.Text.StringBuilder(),
                (a, b) => ((a.Length > 0) ? a.Append(' ') : a).Append(b)
                ).ToString();
        }

        ///<summary>添字付きfor。</summary>
        public static void ForEach<T>(this IEnumerable<T> list, Action<T, int> a)
        {
            int i = 0;
            foreach (var item in list)
            {
                a(item, i);
            }
        }

        ///<summary>指定回数デリゲートを呼び出す。</summary>
        public static IEnumerable<T> Repeat<T>(int n, Func<T> f)
        {
            for (int i = 0; i < n; i++)
            {
                yield return f();
            }
        }
    }

    public static class MathPlus
    {
        ///<summary>素因数分解。昇順。</summary>
        public static List<long> Prime(long a)
        {
            var res = new List<long>();

            for (long b = 2, c = (long)Math.Ceiling(Math.Sqrt(a)); b <= c; ++b)
            {
                while (a % b == 0)
                {
                    res.Add(b);
                    a = a / b;
                }
            }

            return res;
        }

        ///<summary>最小公倍数。</summary>
        public static long Lcm(IEnumerable<long> list)
        {
            return list.Aggregate(0L, (a, b) => a == 0L ? b : Lcm(a, b));
        }

        ///<summary>最小公倍数。</summary>
        public static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        ///<summary>最大公約数。</summary>
        public static long Gcd(IEnumerable<long> list)
        {
            return list.Aggregate(0L, (a, b) => a == 0L ? b : Gcd(a, b));
        }

        ///<summary>最大公約数。</summary>
        public static long Gcd(long a, long b)
        {
            if (a < b)
                Gcd(b, a);

            while (b != 0)
            {
                long rem = a % b;
                a = b;
                b = rem;
            }

            return a;
        }
    }

}


Measured memory_bytes: 13268
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  int sum = 0;
  for(int i = 0;i <= 8;i++){
    sum += ((N%Math.pow(10,i+1))/Math.pow(10,i));
  }
  if(N%sum == 0)System.out.println("Yes");
  else System.out.println("No");
}}

Measured memory_bytes: 21716
import itertools

def list_add(in1, in2):
   return list(map(sum, zip(in1, in2)))

N, M ,X = map(int, input().split())
C = [0] * N
A = [[] * M] * N
for i in range(N):
    T = list(map(int, input().split()))
    C[i] = T[0]
    A[i] = T[1:]

n = [i for i in range(N)]
c_sum = 0
min_sum = 12 * 10e5
for i in range(N):
    flag = 0
    for v in itertools.combinations(n,i+1):
        c_sum = 0
        At = [0] * M
        for j in range(len(v)):
            At = list_add(At, A[v[j]])
            c_sum += C[v[j]]
        overX = [k for k in At if k >= X]
        if len(overX) == M:
            flag = 1
            min_sum = min([min_sum, c_sum])
if flag == 1:
    print(min_sum)
else:
    print(-1)

Measured memory_bytes: 9260
# A - Takahashi Calendar
def calc_product(str_day):
	product = 1
	
	for d in str_day:
		if int(d) < 2:
			return 0
		else:
			product *= int(d)
		
	return product


M, D = map(int, input().split())
ans = 0

for m in range(1, M + 1):
	for d in range(22, D + 1):
		if calc_product(str(d)) == m:
			#print(str(m) + '月' + str(d) + '日')
			ans += 1

print(ans)

Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

int main() {
	//ios::sync_with_stdio(false);
	int num[3];
	cin >> num[0] >> num[1] >> num[2];
	sort(num, num + 3);
	cout << num[0] + num[1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

const int MAX = 16 * 64 * 1024;
int id[MAX];
int idCnt;
int segTree[MAX * 2];
map<int, int> dict;

int q;
int lim;

void init(){
  idCnt = 0;
  memset(segTree, 0, sizeof(segTree));
  dict.clear();
}

void update(int pos, int val){
  pos += MAX;
  segTree[pos] = val;
  while(pos){
    pos = (pos - 1) / 2;
    segTree[pos] = segTree[2 * pos + 1] + segTree[2 * pos + 2];
  }
}

int nthId(int n){
  int pos = 0;

  n += 1;

  while(pos < MAX){
    int left = pos * 2 + 1;
    int right = pos * 2 + 2;

    //printf("n=%d l=%d r=%d\n", n, segTree[left], segTree[right]);

    if(segTree[left] >= n){
      pos = left;
    }else{
      pos = right;
      n -= segTree[left];
    }
  }

  if(n != 1 || segTree[pos] != 1){
    printf("error: n=%d segTree[%d]=%d %d\n", n, pos, segTree[pos], pos - MAX);
  }

  return pos - MAX;
}

void delId(int i){
  update(nthId(i), 0);
}

void delVal(int i){
  update(dict[i], 0);
}

void addId(int i){
  id[idCnt] = i;
  dict[i] = idCnt;
  update(idCnt, 1);
  if(segTree[0] > lim)
    delId(0);
  idCnt++;
}

int main(){
  while(true){
    q = getInt();
    lim = getInt();

    if(q == 0) break;

    init();

    while(q --> 0){
      int query = getInt();
      int x     = getInt();

      switch(query){
      case 0:
        addId(x);
        break;
      case 1:
        delId(x - 1);
        break;
      case 2:
        printf("%d\n", id[nthId(x - 1)]);
        break;
      case 3:
        delVal(x);
        break;
      }

      //printf("query: %d %d\n", query, x);
      //printf("alive: %d\n", segTree[0]);
      //REP(i, idCnt) printf("%d(%d) ", id[i], segTree[i+MAX]); puts("");
    }

    puts("end");
  }

  return 0;
}

Measured memory_bytes: 22000
N = int(input())
*h, = map(int, input().split())

dp = [0] * N
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    c1, c2 = abs(h[i - 1] - h[i]) + dp[i - 1], abs(h[i - 2] - h[i]) + dp[i - 2]
    if c1 < c2:
        dp[i] = c1
    else:
        dp[i] = c2

print(dp[N - 1])


Measured memory_bytes: 52272
N,Q=gets.split.map(&:to_i)

tree = {}
(N-1).times do
  a,b = gets.split.map(&:to_i)
  tree[a] ||= []
  tree[a] << b
  tree[b] ||= []
  tree[b] << a
end

score = Array.new(N+1,0)
Q.times do
  p,x = gets.split.map(&:to_i)
  score[p] += x
end

q = [[1, score[1]]]
until q.empty?
  n, s = q.shift
  next if tree[n].nil?
  score[n] = s
  tree[n].each { |c| q << [c,s+score[c]] }
  tree[n] = nil
end

puts score[1..-1].join(' ')


Measured memory_bytes: 48508
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

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

int main(){
  int64 n;
  cin>>n;
  int64 t[n];
  rep(i,n){
    cin>>t[i];
  }
  int64 ans=t[0];
  rep(i,n){
    ans=ans/gcd(ans,t[i]);
    ans*=t[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

signed main () {
    int n;cin >> n;
    string s;cin >> s;
    int ans =0 ;
    for(char i = '0';i<='9';i++){
        for(char j='0';j<='9';j++){
            for(char k='0';k<='9';k++){
                bool iflag=false,jflag=false,kflag=false;
                for(char t : s){
                    if(!iflag){
                        if(t==i)iflag=true;
                    } else if(!jflag){
                        if(t==j)jflag=true;
                    } else if(!kflag){
                        if(t==k)kflag=true;
                    }
                    if(kflag){
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}//https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

Measured memory_bytes: 3640
import sys
readline=sys.stdin.readline

N = int(readline())
A = sorted(list(map(int,readline().split())))
M = A[-1]
from collections import Counter
counter = Counter(A)
dp = set()
ans = 0
for a in A:
  if a in dp:
    continue
  if counter[a] == 1:
    ans += 1
  for i in range(a * 2, M + 1, a):
    dp.add(i)
print(ans)

Measured memory_bytes: 92360
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ARC069
{
    public class D
    {
        private string F(int kind, string S)
        {
            bool isLastSheep = ((kind & 1) != 0);
            bool isFirstSheep = ((kind & 2) != 0);

            var builder = new StringBuilder();
            bool isPrevSheep = isLastSheep;
            bool isCurrentSheep = isFirstSheep;
            bool isNextSheep;
            for (int i = 0; i < S.Length - 2; ++i)
            {
                builder.Append(isCurrentSheep ? 'S' : 'W');
                if (isCurrentSheep)
                {
                    isNextSheep = ((S[i] == 'o') == isPrevSheep);
                }
                else
                {
                    isNextSheep = ((S[i] == 'o') != isPrevSheep);
                }
                isPrevSheep = isCurrentSheep;
                isCurrentSheep = isNextSheep;
            }

            if (isCurrentSheep != ((S[S.Length - 2] == 'o') == (isPrevSheep == isLastSheep))) { return null; }
            builder.Append(isCurrentSheep ? 'S' : 'W');

            if (isLastSheep != ((S[S.Length - 1] == 'o') == (isCurrentSheep == isFirstSheep))) { return null; }
            builder.Append(isLastSheep ? 'S' : 'W');
            return builder.ToString();
        }

        private void Run()
        {
            var N = int.Parse(Console.ReadLine().Trim());
            var S = Console.ReadLine().Trim();

            Console.WriteLine(Enumerable.Range(0, 4).Select(i => F(i, S)).FirstOrDefault(s => s != null) ?? "-1");
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new D().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


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

int main() {
  ll Ans = 0;  // 回答：

  int N; cin >> N;  // 夏休み数
  int M; cin >> M;  // 課題数
  vector<int> A(M); // 課題日数

  Ans = N;
  int wk_A;
  rep(i,M){
    cin >> wk_A;
    Ans -= wk_A;
    if(Ans <0 ){Ans =-1;break;}
  }

  cout << Ans << endl;
}


Measured memory_bytes: 3604
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Deque;
public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner scan = new Scanner(System.in);
String S=scan.next();
        String T=scan.next();
int M=0;
        for(int i=0;i<S.length()-T.length()+1;i++){
            String J=S.substring(i,i+T.length());
            int m=0;
            for(int j=0;j<T.length();j++){
                if(T.substring(j,j+1).equals(J.substring(j,j+1))){m++;}
            }
            if (m>M){M=m;}
        }
        System.out.println(T.length()-M);
    }}

Measured memory_bytes: 44112
#include<stdio.h>

int main(void)
{
  int i,j,M,N,k,s1,s2,s3,s4,J[1000][1000],O[1000][1000],x,y,z;
  char m[1000];

  scanf("%d%d",&M,&N);
  scanf("%d",&k);
  for(i=0;i<=M-1;i++)
  {
  	J[i][0]=0;
	O[i][0]=0;
	scanf("%s",m);
  	for(j=0;j<=N-1;j++)
	{
		if(m[j]=='J')
		{
			J[i][j]++;
		}
		if(m[j]=='O')
		{
			O[i][j]++;
		}
		J[i][j+1]=J[i][j];
		O[i][j+1]=O[i][j];
	}
  }

  for(j=0;j<=k-1;j++)
    {
      x=0;
	  y=0;
      scanf("%d%d%d%d",&s1,&s2,&s3,&s4);
	  z=(s4-s2+1)*(s3-s1+1);
	  for(i=s1-1;i<=s3-1;i++)
	  {
	  	if(s2>=2)
		{
	  	   x+=J[i][s4-1]-J[i][s2-2];
		   y+=O[i][s4-1]-O[i][s2-2];
		}
		else
		{
			x+=J[i][s4-1];
			y+=O[i][s4-1];
		}
	  }
	  printf("%d %d %d\n",x,y,z-x-y);
    }
  return 0;
}

Measured memory_bytes: 8380
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    foreach(n;stdin.byLine().map!(to!int).array().until(0).array())
    {
        auto m = new int[][](n,n);
        int x=n/2, y=x+1;
        m[y][x]=1;
        foreach(i;2..n*n+1)
        {
            x=(x+1)%n,y=(y+1)%n;
            while(m[y][x]!=0) x=(x-1+n)%n,y=(y+1)%n;
            m[y][x]=i;
        }
        m.map!(a=>a.map!(v=>format("%4d",v)).join("")).join("\n").writeln();
    }
}

Measured memory_bytes: 1240
#include <stdio.h>

int main()
{
	int inputN, inputA;
	scanf("%d", &inputN);
	int intArray[100];

	// Create an array to store the input
	for (int i = 0; i < inputN; i++)
	{
		scanf("%d", &inputA);
		intArray[i] = inputA;
	}

	// Check for values inside the loop
	for (int i = 0; i < inputN; i++)
	{
		if (intArray[i] % 2 == 0)
		{
			if (intArray[i] % 3 == 0 || intArray[i] % 5 == 0)
			{
				continue;
			}
			else
			{
				printf("DENIED \n");
				return 0;
			}
		}
	}
	printf("APPROVED \n");

	return 0;
}

Measured memory_bytes: 128
S = input()

# case 01010101...
count01 = 0
pattern = False
for i in list(S):
  if bool(int(i)) is pattern:
    count01 += 1
  pattern = not(pattern)
# case 10101010...
count10 = 0
pattern = True
for i in list(S):
  if bool(int(i)) is pattern:
    count10 += 1
  pattern = not(pattern)

print(min(count01, count10))


Measured memory_bytes: 3956
import java.util.*;
public class Main  {
   public static void main(String[] args)  {
      Scanner sc = new Scanner(System.in);
      
      String s = sc.next();
      
      int count = 0;
      
      if (s.length() % 2 != 0) {
         System.out.println("No");
         count = 1;
      } 
      
      if (count == 0) {
      
         for (int i = 0; i < s.length(); i = i + 2) {
            
            if (s.substring(i, i+2).equals("hi")) {
               count = 0;
            } else {
               count = 2;
               break;
            }
         }
      }
      
      if (count == 0) {
         System.out.println("Yes");
      } else if (count == 2) {
         System.out.println("No");
      }
               
   }        
}


Measured memory_bytes: 21972
fun main() {

    val n = readLine()!!.toInt()

    val list = readLine()!!.split(" ").map(String::toInt).toMutableList()

    var count = 0

    for (i in 0 until n) {
        while (list[i]%2==0){
            list[i] = list[i]/2
            count++
        }
    }
    println(count)
}

Measured memory_bytes: 43124
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int N;
    int *d;
    int K1,K2;
    int i;
    
    cin >> N;
    d = new int[N];
    for(i=0;i<N;i++){
        cin >> d[i];
    }
    sort(d,d+N);
    K1 = d[N/2];
    K2 = d[N/2-1];
    cout << K1 - K2 << endl;
}


Measured memory_bytes: 888
#include "stdio.h"

int main(void){
  int r,g,b;

  scanf("%d %d %d", &r, &g, &b);

  if((100*r + 10*g + b) % 4 == 0){
    printf("YES\n");
  }else{
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

using Graph = vector<vector<int> >;

vector<int> seen;

void dfs(const Graph &G, int v, int c){
  seen[v] = c;

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

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

  Graph G(n);
  rep(i, m){
    int a, b; cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  seen.assign(n, -1);
  int c = 0;
  rep(i, n){
    if(seen[i] == -1){
      dfs(G, i, c);
      c++;
    }
  }

  int q; cin >> q;
  rep(i, q){
    int s, t; cin >> s >> t;
    cout << (seen[s] == seen[t] ? "yes" : "no") << endl;
  }

  return 0;
}




Measured memory_bytes: 13360
import sys
x,n=map(int,input().split())
if n==0:
    print(x)
    sys.exit()
else:
    p=list(map(int,input().split()))
    res=1000
    ans=0
    for i in range(101,-101,-1):
        p.append(i)
        if len(p)==len(set(p)):
            if res>=abs(x-i):
                res=abs(x-i)
                ans=i
        del p[-1]
    print(ans)

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

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif


signed main()
{
	int a, b, c;
	cin >> a >> b >> c;
	PRINT(b-a==c-b);
}



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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String w = sc.next();
        int[] count = new int[26];
        for(int i=0;i<w.length();i++){
        	count[w.charAt(i)-'a']++;
        }
        for(int a=0;a<26;a++){
        	if(count[a]%2!=0){
        	    System.out.println("No");
        	    return;
        	}
        }
        System.out.println("Yes");
    }
}

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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif

using namespace std;

void solve(ll n, vector<ll> v) {
    map<int, int> cnt[2];
    for (int i = 0; i < n; i++) {
        cnt[i % 2][v[i]]++;
    }
    vector<pair<int, int> > items[2];
    items[0].push_back({0, -1});
    items[1].push_back({0, -2});

    for (int k = 0; k < 2; k++) {
        for (auto e : cnt[k]) {
            items[k].push_back({e.second, e.first});
        }
        sort(items[k].rbegin(), items[k].rend());
    }
    int ans = 1e9;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            if (items[0][i].second != items[1][j].second) {
                ans = min(ans, (int) n - items[0][i].first - items[1][j].first);
            }
        }
    }
    cout << ans << endl;
}


void main_(istream &cin) {
    ll n;
    cin >> n;
    vector<ll> v(n - 1 + 1);
    for (int i = 0; i <= n - 1; i++) {
        cin >> v[i];
    }
    solve(n, v);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 7676
#include<stdio.h>
int main(void){
int s[10],t[10];
  scanf("%s",&s);
  scanf("%s",&t);
  int a,b;
  scanf("%d%d",&a,&b);
  char u[10];
  scanf("%s",&u);
  if(strcmp(s,u)==0){
    printf("%d %d",a-1,b);
  }
  if(strcmp(t,u)==0){
    printf("%d %d",a,b-1);
  }
  return 0;
}

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

int sum(int n){
  int A = 0;
  while(n > 0){
    A += n % 10;
    n /= 10;
  }
  return A;
}

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  int total = 0;
  for(int i = 1; i <= N; i++){
    int SUM = sum(i);
    if(SUM >= A && SUM <= B) total += i;
  }
  cout << total << endl;
  return 0;
}
    
  

Measured memory_bytes: 256
// ABC048 A - AtCoder *** Contest
#include <stdio.h>

int main(void) {
    char S[101];
    char a[8];
    char c[8];
    scanf("%s", a);
    scanf("%s", S);
    scanf("%s", c);

    printf("A%cC\n", S[0]);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
using namespace std;
int main(){
    int K=0;
    string s;
    cin >> s;
    cin >> K;
    int l = s.length();
    string* ans = new string[K*(2*l-K+1)/2];
    int tmp = 0;
    for(int i=1;i<=K;i++){
        for(int j = 0;j+i<=l;j++){
            ans[tmp] = s.substr(j,i);
            tmp++;
        }
    }
    sort(ans,ans+(tmp));
    if(K==1){
        cout << ans[0] << endl;
        return 0;
    }else{
        int a = 1;
        for(int i=1;i<tmp;i++){
            if(ans[i]!=ans[i-1]){
                a++;
                if(a==K){
                    cout << ans[i] << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 1664
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

#define MOD 1000000007
#define INF INT_MAX
#define ll long long

int main()
{
	string s;

	cin >> s;

	sort(s.begin(), s.end());

	char j = 'a';
	for (int i = 0; i < s.size(); i++) {
		if (s[i] <= j) {
			if (s[i] == j) {
				j++;
			}
		}
		else {
			cout << j << endl;
			return(0);
		}
	}
	if (j == 'z' + 1) {
		cout << "None" << endl;
	}
	else {
		cout << j << endl;
	}
	


	return (0);
}

Measured memory_bytes: 512
object Main extends App {
  val (a, b, k) = readLine.split(" ").map(_.toInt) match {
    case Array(a, b, k) => (a, b, k)
  }

  case class State(t: Int, a: Int, isTakahashi: Boolean) {
    def next = {
      if (isTakahashi) State(t / 2, a + t / 2, false) else State(t + a / 2, a / 2, true)
    }
  }

  val res = (1 to k).foldLeft(State(a, b, true))((acc, _) => acc.next)
  println(res.t + " " + res.a)
}

Measured memory_bytes: 25552
#include <iostream>
#include <map>

int main() {
    std::string S, T;
    std::cin >> S >> T;

    std::map<char, int> mS, mT;
    int idS = 0, idT = 0;

    for (int i = 0; i < S.size(); i++) {
        if (mS.count(S[i]) == 0) {
            mS[S[i]] = idS++;
        }
        if (mT.count(T[i]) == 0) {
            mT[T[i]] = idT++;
        }
        if (mS[S[i]] != mT[T[i]]) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;

    return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main() {
	char a, b;
	cin >> a >> b;
	if (a == b)
		cout << 'H' << endl;
	else
		cout << 'D' << endl;
}

Measured memory_bytes: 256
url = "https://atcoder.jp//contests/abc160/tasks/abc160_c"

def main():
    lake, house = list(map(int, input().split()))
    dis = list(map(int, input().split()))
    ans = []
    for i in range(1, len(dis)):
        ans.append(dis[i] - dis[i - 1])
    ans.append(lake - dis[-1] + dis[0])
    print(sum(ans) - max(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 26420
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Segment_Tree{
	private:
	int n;
	vi date;
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vi(2*n-1);
	}
	void Update(int k,int x){
		k+=n-1;
		date[k]+=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=date[k*2+1]+date[k*2+2];
		}
	}
	int Query(int a,int b){
		a+=n-1;b+=n-1;
		int m=0;
		while(a<b){
			if(a%2==0) m+=date[a++];
			if(b%2==0) m+=date[--b];
			a/=2;b/=2;
		}
		return m;
	}
	int Open(int k){return date[k+n-1];}
};

const int M=500005;
ll n,F[M],m=0;
vl a,b;

int main(){
	cin>>n;
	F[0]=1;
	a=b=vl(n);
	fill(b.begin(),b.end(),1);
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
	ll res=0,t=0,sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
		if(a[i]<0) m++;
		else b[a[i]]--;
	}
	for(int i=1;i<n;i++) b[i]+=b[i-1];
	Segment_Tree st(n);
	for(int i=n-1;i>=0;i--){
		if(i<n-1){
			ll tmp;
			if(a[i]>=0) tmp=(st.Query(0,a[i])*F[m]+(t?t*b[a[i]]%mod*F[m-1]:0))%mod;
			else tmp=(F[m]*(mod/2+1)%mod*t+sum*F[m-1])%mod;
			(res+=tmp*F[n-i-1])%=mod;
		}
		if(a[i]>=0) st.Update(a[i],1),(sum+=m-b[a[i]])%=mod;
		else t++;
	}
	cout<<(res+F[m])%mod<<endl;
}

Measured memory_bytes: 16128
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=3e3+10,mod=998244353;

int main ()
{
    FASTIO;
    ll n;
    cin >> n;
    vll a(n+1),Pre(n+1);
    for(auto &x:a)cin >> x;
    if(n==0){
        cout << (a[0]==1 ? 1 : -1) << endl;
        return 0;
    }
    if(a[0]!=0)return cout << -1 << endl,0;
    Pre[n] = a[n];
    for(int i=n-1;i>=0;i--){
        Pre[i] = Pre[i+1]+a[i];
    }
    ll ans=1,last=1;
    for(int i=1;i<=n;i++){
        if(a[i] > last*2)return cout << -1 << endl,0;
        ans += min(last*2,Pre[i]);
        last = min(last*2,Pre[i])-a[i];
    }
    cout << ans << endl;
    return 0;
}
/**


*/


Measured memory_bytes: 4760
#include<bits/stdc++.h>
#define ll long long int

using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int num=0;
    for(int i=a;i<=b;i++)
    {
        if(i%c==0) num++;
    }

    cout<<num<<endl;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  long long ans = 0;
  long long A[N];
  for (int i = 0; i < N; i++) cin >> A[i], ans ^= A[i];
  for (int j = 0; j < 60; j++) {
    int cnt = 0;
    for (int i = 0; i < N; i++) cnt += (A[i] >> j) & 1;
    if (cnt & 1)
      for (int i = 0; i < N; i++) A[i] = A[i] & (A[i] ^ (1ll << j));
  }
  vector<long long> bases;
  for (int i = 0; i < N; i++) {
    for (long long b : bases) A[i] = min(A[i], A[i] ^ b);
    if (A[i]) bases.push_back(A[i]);
  }
  sort(bases.rbegin(), bases.rend());
  long long tmp = 0;
  for (long long b : bases) tmp = max(tmp, tmp ^ b);
  ans += tmp << 1;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4452
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
	 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    
    ll n;
    cin>>n;
    ll a=0,b=0,c=0,d=0;
    for(ll i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s=="AC")
        {
            a++;
        }
        else if(s=="WA")
        {
            b++;
        }
        else if(s=="TLE")
        {
            c++;
        }
        else
        {
            d++;
        }
            
    }
    cout<<"AC"<<" "<<"x"<<" "<<a<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<b<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<c<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<d<<endl;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main()
{
    long long x;
    cin >> x;
    long long m = x / 11;
    long long d = x - m * 11;
    long long ans;
    if(d == 0){
        ans = 2 * m;
    }
    else {
        ans = 2 * m + ((d <= 6) ? 1 : 2);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>

using namespace std;

int main()
{
    vector<int> v(3);
    for(int i=0; i<3; i++)
        cin >> v[i];
    sort(v.begin(), v.end());
    
    if(v[2] == v[0]+v[1])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
W, H, N = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
i, j = 0, 0
w, h = W, H
for x, y, a in L:
    if a == 1:
        i = max(i, x)
    if a == 2:
        w = min(w, x)
    if a == 3:
        j = max(j, y)
    if a == 4:
        h = min(h, y)
if w <= i or h <= j:
    print(0)
else:
    print((w - i) * (h - j))


Measured memory_bytes: 3064
n = int(input())
a = 0
for i in range(1,n+1):
    if i//100000:
        pass
    elif i//10000:
        a += 1
    elif i//1000:
        pass
    elif i//100:
        a += 1
    elif i//10:
        pass
    elif i//1:
        a += 1
print(a)

Measured memory_bytes: 2940
// C++ program to print all prime factors  
#include <bits/stdc++.h> 
using namespace std; 
  
// A function to print all prime  
// factors of a given number n  
 #define ll long long 
ll a,b,y;ll ans;


int main()  
{  
   vector<pair<ll,ll>>v;
 cin>>a>>y; 
 for(ll i=1;i<=a;i++){
    ll x;
    cin>>x;if(x>=y){ans++;}
    
 }cout<<ans;
     
}  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	int a,b;cin>>a>>b;
	if(a%500<=b){
		puts("Yes");
	}
	else puts("No");
}

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

int main()
{
   /// BISMILLAHIR RAHMANIR RAHIM
	int n;
	cin >> n;
	ll ans = 1;
	ll a[n+1];
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		if (a[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 0;i < n;i++) {
		ans = ans * a[i];
	}
	if (ans <= 1000000000000000000 && ans > 0) {
		cout << ans << endl;
	}
	else cout << -1 << endl;
	return 0;

    /// ALHAMDULILLAH
}


Measured memory_bytes: 4368