akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
 #include <cstdio>
 using namespace std;
 
 int main(){
 	int a, b, x;
 	int ans[10000];
 	
 	for(int i = 0; i <= 10000; i += 2){
 		cin >> a >> b;
 		if(a > b){
 			x = a;
 			a = b;
 			b = x;
 		}
 		ans[i] = a;
 		ans[i+1] = b;
 		if((a == 0) && (b == 0)){
 			break;
 		}
 	}
 	
 	for(int j = 0; j <= 10000; j += 2){
 		if((ans[j] == 0) && (ans[j+1] == 0)){
 			break;
 		}
 		printf("%d %d\n", ans[j], ans[j+1]);
 	}
 	
 	return 0;
 }

Measured memory_bytes: 1168
//	Author : amnptl 
//	   Godbless
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define NeedForSpeed() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD (1000000007); // 1e9+7
int main()
{
	NeedForSpeed();
	int n; cin>>n; ll ans = 0;
	for(int i=1; i<=n; i++)
		if(i%3!=0 && i%5!=0) ans += i;
	cout<<ans<<endl;	
	return 0;
}

Measured memory_bytes: 3640
def main():
	x, y, z, k = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))

	solve(a, b, c, x, y, z, k)

def solve(a, b, c, x, y, z, k):
	a.sort(reverse=True)
	b.sort(reverse=True)
	c.sort(reverse=True)
	stack = list()
	for p in range(x):
		for q in range(y):
			if (p+1)*(q+1) > k:
				break
			for r in range(z):
				if (p+1)*(q+1)*(r+1) > k:
					break
				stack.append(a[p]+b[q]+c[r])
	stack.sort(reverse=True)
	for i in range(k):
		print(stack[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 8708
#include<bits/stdc++.h>
using namespace std;
//priority_queue<node>q;
const int N=2e5+10,mod=998244353;
int fac[N],inv[N];
int n,m,k,ans;
int modpow(int x,int n,int mod);
void init(int n){
    inv[0]=inv[1]=1;
    fac[0]=fac[1]=1;
    for(int i=2;i<=n;++i){
        fac[i]=1ll*fac[i-1]*i%mod;
    }
    inv[n]=modpow(fac[n],mod-2,mod);
    for(int i=n-1;i>=2;--i){
        inv[i]=1ll*inv[i+1]*(i+1)%mod;
        //printf("i:%d fa:%d in:%d\n",i,fac[i],inv[i]);
    }
}
int c(int n,int m){
    if(m<0 || n<m)return 0;
    //printf("fa:%d in:%d in:%d\n",fac[n],inv[m],inv[n-m]);
    return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int modpow(int x,int n,int mod){
    int res=1;
    for(;n;n/=2){
        if(n&1)res=1ll*res*x%mod;
        x=1ll*x*x%mod;
    }
    return res;
}
int cal(int x){
    return 1ll*m*modpow(m-1,x-1,mod)%mod;
}
int main(){
    //int n,m,k,ans=0;
    init(N-5);
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<=k;++i){
            //printf("c:%d\n",c(n-1,i));
            //printf("ca:%d\n",cal(n-i));
        ans=(ans+1ll*c(n-1,i)*cal(n-i)%mod)%mod;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 5344
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=5000+10;
int a[maxn];
int n;
int k;
int num;
int x;
int ans=1;
int sum;
int main()
{
	scanf("%d%d",&n,&k);
	num=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x>=k)num--;
		else a[ans++]=x;
	}
	ans--;
	sort(a+1,a+num+1);
	while(num>=2)
	{
		sum+=a[num];
		if(a[num-1]+sum<k)
		{
			num--;
			continue;
		}
		if(a[1]+sum>=k)
		{
			ans=0;
			break;
		}
		int l=1,r=num-2;
		while(l+1<r)
		{
			int mid=(l+r)/2;
			if(sum+a[mid]>=k) r=mid;
			else l=mid;
		}
		ans=ans-(num-r);
		num=r;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <map> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)



int main(void) {
	int d1, d2, m1, m2;
	cin >> m1 >> m2 >> d1 >> d2;
	if (d2 == 1) cout << 1;
	else cout << 0;
}


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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

char change(char a) {
	return a<= 'z' ? a+'A'-'a' : a;
}
int main(){
	string a, b, c;
	cin >> a >> b >> c;
	cout<< change(a[0]) << change(b[0]) << change(c[0]) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

typedef long long int int64;
using namespace std ;

int main () {
  int64 K, A, B;
  cin >> K >> A >> B;

  if(K-A-1<0){
    cout << K+1 << endl;
    return 0;
  }

  if(B-A<3){
    cout << K+1 << endl;
    return 0;
  }

  int64 ans = 1;
  ans += A-1;
  if((K-A+1)%2==0){
    ans += (B-A)*((K-A+1)/2);
  }else{
    ans += (B-A)*((K-A+1)/2)+1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>
#include	<math.h>

int		main(void)
{
	double	x1, y1, x2, y2;
	double	x, y;
	double	dst;

	scanf("%lf",&x1);
	scanf("%lf",&y1);
	scanf("%lf",&x2);
	scanf("%lf",&y2);

	if(x1 == x2)
	{
		dst = abs(y2-y1);
	}
	else if(y1 == y2)
	{
		dst = abs(x2-x1);
	}
	x = x1 - x2;
	y = y1 - y2;

	dst = sqrt( pow(x,2) + pow(y,2) );
	printf("%8f",dst);

	return 0;
}

Measured memory_bytes: 656
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

int main() {
	int n=read(),m=read();
	if (n%3==0||m%3==0) { puts("0"); return 0; }
	ll ans=min(n,m);
	for (int i=1;i<n;++i) {
		ll S[3]={1ll*i*m,1ll*m/2*(n-i),1ll*(m-m/2)*(n-i)};
		sort(S,S+3);
		ans=min(ans,S[2]-S[0]);
	}
	for (int i=1;i<m;++i) {
		ll S[3]={1ll*i*n,1ll*n/2*(m-i),1ll*(n-n/2)*(m-i)};
		sort(S,S+3);
		ans=min(ans,S[2]-S[0]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
   int a,b,c;
   cin>>a>>b>>c;
   cout<<max({(10*a+b+c),(10*b+a+c),(10*c+b+a)})<<endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())

    xn = []
    yn = []
    hn = []

    for i in range(N):
        xi, yi, hi = map(int, input().split())
        if hi:
            xn.append(xi)
            yn.append(yi)
            hn.append(hi)

    if len(xn) == 1:
        print(xn[0], yn[0], hn[0])
        return

    for Cx in range(101):
        for Cy in range(101):

            last = None

            for i in range(len(xn)):
                H = abs(xn[i] - Cx) + abs(yn[i] - Cy) + hn[i]

                if H < 0:
                    continue
                if last:
                    if (last != H):
                        break

                last = H
            else:
                print(Cx, Cy, H)
                return


main()


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int m = Integer.parseInt(in[1]);
        in = br.readLine().split(" ");
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(in[i]);
        }
        int[] ans = new int[n];
        for (int i = 0; i < m; i++) {
            in = br.readLine().split(" ");
            int a = Integer.parseInt(in[0]) - 1;
            int b = Integer.parseInt(in[1]) - 1;
            if (h[a] < h[b]) {
                ans[a] = -1;
            } else if (h[a] > h[b]) {
                ans[b] = -1;
            } else {
                ans[a] = -1;
                ans[b] = -1;
            }
        }

        br.close();

        int cnt = 0;
        for (int a : ans) {
            if (a != -1) {
                cnt++;
            }
        }

        bw.write(String.valueOf(cnt));

        bw.flush();

    }
}

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

constexpr inline int op(int a, int b) {
    return max(a, b);
}

constexpr inline int e() {
    return 0;
}

const int mxn = 300001;
atcoder::segtree<int, op, e> st(mxn);

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int q = st.prod(max(x - m, 0), min(x + m + 1, mxn)) + 1;
        st.set(x, q);
        ans = max(ans, q);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 8344
using System;

namespace arc088d
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            int len = input.Length;
            int ans = input.Length;

            for (int i = 1; i < len; ++i)
            {
                if (input[i - 1] != input[i] && (ans > len - i && ans > i))
                {
                    ans = (i >= len - i ? i : len - i);
                }
            }

            Console.WriteLine(ans);
        }
    }
}


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

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var H = IO.GetLong();

            long ans = Hoge(H);

            Console.WriteLine(ans);
        }

        static long Hoge(long n)
        {
            if (n == 1) return 1;
            return 1 + Hoge(n / 2)*2;
        }



    }

    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 
 
int main(){
int a;
  cin>>a;
  vector<int>op(a);
  vector<int>ab(a);
  for(int i=0;i<a;i++)
  {
  int x;
    cin>>x;
    op.at(i)=x;
   
  } 
  for(int i=0;i<a;i++)
  {
  int x;
    cin>>x;
    ab.at(i)=x;
   
  }
  
  int b=1;
  for(int i=1;i<a+1;i++)
  {
 b=b*i; 
  }
   vector<int>start(a);
  for(int i=0;i<a;i++)
  {
  
    start.at(i)=i+1;
   
  } 
    

   int g=1;
  while(op!=start)
  {
    next_permutation(start.begin(),start.end());
    g++;
   
  } 
        for(int i=0;i<a;i++)
  {
  
    start.at(i)=i+1;
   
  } 
  int h=1;
  while(ab!=start)
  {
    next_permutation(start.begin(),start.end());
    h++;
   
  } 
cout<<fabs(g-h);
}
 
 

Measured memory_bytes: 256
#define ll long long
#define ld long double
#define MOD 1000000007
#define MOD2 998244353
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
ll a[105][105];
ll vis[105][105] = {0};
ll dp[105][105];
ll h, w;
ll dfs(ll x, ll y)
{
    vis[x][y] = 1;
    if (x == h && y == w)
    {
        dp[x][y] = a[x][y];
        return dp[x][y];
    }
    if (y + 1 <= w && !vis[x][y + 1])
        dp[x][y + 1] = dfs(x, y + 1);
    if (x + 1 <= h && !vis[x + 1][y])
        dp[x + 1][y] = dfs(x + 1, y);

    if (a[x][y + 1] == a[x][y] && y + 1 <= w)
        dp[x][y] = dp[x][y + 1];
    else if (a[x][y] == 1 && y + 1 <= w)
        dp[x][y] = 1 + dp[x][y + 1];
    else if (a[x][y] == 0 && y + 1 <= w)
        dp[x][y] = dp[x][y + 1];

    if (a[x][y] == a[x + 1][y] && x + 1 <= h)
        dp[x][y] = min(dp[x][y], dp[x + 1][y]);
    else if (a[x][y] == 1 && x + 1 <= h)
        dp[x][y] = min(dp[x][y], 1 + dp[x + 1][y]);
    else if (a[x][y] == 0 && x + 1 <= h)
        dp[x][y] = min(dp[x][y], dp[x + 1][y]);

    return dp[x][y];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> h >> w;
    for (int i = 1; i < 105; i++)
        for (int j = 1; j < 105; j++)
            dp[i][j] = INT_MAX;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            char ch;
            cin >> ch;
            if (ch == '#')
                a[i][j] = 1;
            else
                a[i][j] = 0;
        }
    }
    cout << dfs(1, 1);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    vector<string> s(3); cin >> s;
    VI itr(3);
    int now = 0;
    while (1) {
        if (s[now].length() <= itr[now])break;
        ++itr[now];
        now = s[now][itr[now] - 1] - 'a';
    }
    cout << char('A' + now) << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int calc(int a, int b){
    int res = 0, c = 0;
    while(a || b){
        res += (a%10)*(b%10)+c;
        c = (a%10)+(b%10)+c>=10;
        a /= 10;
        b /= 10;
    }
    return res+c;
}
 
int n;
main(){
    cin >> n;
    vector<int> d(n), s(n+1);
    for(int i=0;i<n;i++){
        cin >> d[i];
        s[i+1] = (s[i] + d[i]);
    }
    vector<vector<int> > dp(n+1, vector<int>(n+1, 1000000000));
    for(int i=0;i<n;i++) dp[i][i+1] = 0;
    for(int j=2;j<=n;j++)for(int i=0;i+j<=n;i++){
        for(int k=1;k<j;k++){
            dp[i][i+j] = min(dp[i][i+j], dp[i][i+k] + dp[i+k][i+j] + calc(s[i+k]-s[i], s[i+j]-s[i+k]));
        }
    }
    cout << dp[0][n] << endl;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;

	int n = N;
	int d = 0;
	while (n > 0) {
		n /= 10;
		++d;
	}

	Int ans = 0;
	for (int x = 1; x < 10; ++x) {
		for (int y = 1; y < 10; ++y) {
			Int cntA = 0, cntB = 0;
			// 1桁
			if (x == y && x <= N) {
				++cntA;
				++cntB;
			}
			// 2桁
			if (y * 10 + x <= N) { ++cntA; }
			if (x * 10 + y <= N) { ++cntB; }

			// N の桁数未満
			for (int i = 3; i < d; ++i) {
				Int add = 1;
				for (int j = 0; j < i - 2; ++j) { add *= 10; }
				cntA += add;
				cntB += add;
			}

			// N と同じ桁数
			Int A = y, B = x;
			Int m = 1;
			for (int i = 0; i < d - 1; ++i) {
				A *= 10;
				B *= 10;
				m *= 10;
			}
			A += x;
			B += y;
			while (d > 2 && A <= N) {
				++cntA;
				A += 10;
				if (A / m != y) { break; }
			}
			while (d > 2 && B <= N) {
				++cntB;
				B += 10;
				if (B / m != x) { break; }
			}

			ans += cntA * cntB;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  if(s[len(s)-1] != 's') cout << s +'s' << endl;
  else cout << s + 'e' + 's' << endl;
  return 0;
}


Measured memory_bytes: 3604
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

res=0
back=-1

for a in A:
	res=res+B[a-1]					#listは０スタート
	if a-1==back:					#A内の今考えている変数が前のと同じなら
		res=res+C[back-1]			#listは０スタート
	back=a
    
print(res)

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   ll n, a, b;
   cin >> n >> a >> b;

   if (a > b) {
      cout << 0 << endl;
      return 0;
   }
   if (n==1) {
      if (a == b) {
         cout << 1 << endl;
      } else {
         cout << 0 << endl;
      }
      return 0;
   }

   cout << (b-a) * (n-2) + 1 << endl;

   return 0;
}

Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  res=1;
  ll tmp=1;
  rep(i,0,n){
    res*=3;
    if(a[i]&1)tmp*=1;
    else tmp*=2;
  }
  cout<<res-tmp<<endl;
  return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int ans = 0;
    int active = 0;

    rep(i, n) {
        if (active >= h[i]) {
            active = h[i];
        } else {
            ans += h[i] - active;
            active = h[i];
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N;
  long long  ans = 0;
  int ansflgCntn = 0;
  int cnt=0;
  int ansflg2 = 0;
  long long maxv = 0;

  cin >> N;

  vector<long long > H(N);
  for(int i = 0; i < N; i++){
    cin >> H[i];

    if((maxv-2) >=H[i]){
      ansflg2++;
      // cout << "ansflg++" << endl;
    }
    maxv = max(maxv, H[i]);

    // cout << "max = " << maxv << endl;
  }

  if(ansflg2 > 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}


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

int main(){
    string a,b;
    bool ok=true;
    cin >> a >> b;
    if(a.size()<b.size()){cout << "LESS" << endl;}
    else if(a.size()>b.size()){cout << "GREATER" << endl;}
    else {
        for(int i=0;i<a.size();i++){
            if(a[i]<b[i]){ok=false;cout << "LESS" << endl;break;}
            if(a[i]>b[i]){ok=false;cout << "GREATER" << endl;break;}
        }
        if(ok){cout << "EQUAL" << endl;}
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <time.h>
#include <complex>
 
using namespace std;
 
#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

typedef long long ll;
 
const ll MOD = 998244353;
//const ll MOD = 1e9 + 7;
 
ll n, k;
ll last[500000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    vector<int> a(n);
    vector<int> next(n);
    fill(last, last + 500000, -1);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = n - 1; i >= 0; i--)
    {
        last[a[i]] = i + n;
    }
    for (int i = n - 1; i >= 0; i--)
    {
        next[i] = last[a[i]];
        last[a[i]] = i;
    }
    long long pointer = 0;
    long long cycle = 0;
    while(1)
    {
        ll i = pointer;
        ll j = next[i] + 1;
        while (j >= n)
        {
            cycle++;
            j -= n;
        }
        pointer = j;
        if (pointer == 0) break;
    }
    k %= cycle;
    vector<int> ans;
    pointer = 0;
    cycle = 0;
    while (pointer < n * k)
    {
        ll i = pointer % n;
        ll j = next[i];
        while (j >= n) j -= n;
        
        ll np = pointer;
        if (j > i)
           np += j - i;
        else
           np += n - abs(i - j);
        if (np < n * k)
        {
            pointer = np + 1;
        }
        else
        {
            //cout << pointer << " " << i << " " << j << " : " << np <<endl;
            ans.push_back(a[i]);
            pointer++;
        }
    }
    F(i, ans.size()) cout << ans[i] << " ";
}


Measured memory_bytes: 10224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie acos(-1)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x) for(auto &a:x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define w 100005

void solve()
{
    int n,m;
    cin>>n>>m;
    
    cout<<n*(n-1)/2+m*(m-1)/2;
    //else if(n==1)
    
}
int main() {
	// your code goes here
	io;

    solve();
	return 0;
}


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const int INF = 1e9;

int N, M;
int a[1010], b[1010], c[1010][14];

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
int main(void){
	
	cin >> N >> M;
	
	rep(i, M){
		cin >> a[i] >> b[i];
		rep(j, b[i])
			cin >> c[i][j];
	}
	
	vector<int>	dp(5000, INF);

	dp[0] = 0;

	rep(i, M) {
		int now = 0;
		rep(j, b[i])
			now |= (1 << (c[i][j] - 1));
		rep(bits, (1 << N))
			chmin(dp[bits | now], dp[bits] + a[i]);
	}
	
	if(dp[(1 << N) - 1] == INF)
		dp[(1 << N) - 1] = -1;
	
	cout << dp[(1 << N) - 1] << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
      int ws[23],sum,num,dp[50003];cin >> sum >> num;
      for (int i = 0;i<num;i++)cin >> ws[i];
      for (int i = 0;i <= sum ; i ++ )dp[i] = i;
      for(int i = 1;i < num ;i++)for(int j = ws[i];j <= sum;j++)dp[j] = min(dp[j],dp[j-ws[i]]+1);
      cout << dp[sum]<<endl;
}

Measured memory_bytes: 1356
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int bit=0;
        for(int i=0;i<N;i++){
            bit|=sc.nextInt();
        }
        System.out.println(Integer.numberOfTrailingZeros(bit));
    }
}

Measured memory_bytes: 22868
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, m, t;
    cin >> n >> m >> t;
    VI d(t);
    REP(i,n){
        int a;
        cin >> a;
        d[a-m]++;
        if (a+m < t) d[a+m]--;
    }
    REP(i,t-1) d[i+1] += d[i];
    int ans = 0;
    REP(i,t) ans += (d[i] == 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3144
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
typedef long long int ll;
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define pb push_back 
#define mp make_pair 
#define sc second 
#define f first 
#define kek cout<<"\n" 
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
const ll MOD = 1e9 + 7;
const int N = 100005;
const ll INF = 1e9;
using namespace std;
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	string cur;
	if (s == "ABC")
	{
		cout << 1;
		return 0;
	}
	for (int i = 0; i < n - 2; i++)
	{
		cur = s.substr(i, 3);
		if (cur == "ABC") ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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






int main(){
    int A, B, C; cin >> A >> B >> C;
    cout << ((A==B && B==C) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 

 
int main(void){
    ll ans = 0;
    ll now = 0;
    ll past = 0;
    ll n,t;
    cin>>n>>t;
    for(int i=0;i<n;i++){
        ll ti;
        cin>>ti;
        if(ti>now){
            ans += now-past;
            past = ti;
            now = ti+t;
        }
        else{
            now = ti+t;
        }
    }
    cout<<ans+now-past<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
x = RI()

a = sorted(x)
M = a[n//2]
m = a[n//2-1]

for i in range(n):
    if x[i]<=m:
        print(M)
    else:
        print(m)
exit()

Measured memory_bytes: 99616
<?php
$l1 = fgets(STDIN);
$l2 = fgets(STDIN);
$l3 = fgets(STDIN);
$n = $l1;
$arr2 = explode(' ', $l2);
$arr3 = explode(' ', $l3);
$t = $arr2[0];
$a = $arr2[1];
$ret = 10000;
$ans = 0;
for ($i = 1; $i <= count($arr3); $i++) {
    $ave = $t - $arr3[$i-1] * 0.006;
    $ret_tmp = abs($a - $ave);
    if ($ret_tmp < $ret) {
        $ret = $ret_tmp;
        $ans = $i;
    }
}

echo $ans . PHP_EOL;


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int a,b;
  cin>>a>>b;
  cout<<max(a+b,max(a-b,a*b))<<endl;
}

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

unsigned int xor128(){
	static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; 
	unsigned int t=(x^(x<<11));
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}

class Nothing{};

template<class Key,class Val=Nothing>
class Treap{
	struct Node{
		unsigned int priority;
		Key key;
		Val value;
		Node *left,*right;
		int size;
		Node(const Key& k,const Val& v)
			:priority(xor128()),key(k),value(v),left(0),right(0),size(1){}
		~Node(){
			if(left)delete left;
			if(right)delete right;
		}
		Node *rotate_right(){
			Node *s=left;
			left=s->right;
			s->right=this;
			return s;
		}
		Node *rotate_left(){
			Node *s=right;
			right=s->left;
			s->left=this;
			return s;
		}
		Node *insert(Node *t){
			if(!this)return t;
			if(!t)return this;
			Node *s=this;
			if(t->key < key){
				left = left->insert(t);
				if(priority < left->priority)s=rotate_right();
			}else if(key < t->key){
				right = right->insert(t);
				if(priority < right->priority)s=rotate_left();
			}else return this;
			s->update();
			return s;
		}
		Node *find(const Key& k){
			return !this?NULL:k==key?
				this:k<key?left->find(k):right->find(k);
		}
		Node *erase(const Key& k){
			if(!this)return NULL;
			Node *s=this;
			if(k==key){
				if(!left&&!right){
					delete this;
					return NULL;
				}
				if(left && (!right || left->priority > right->priority)){
					s=rotate_right();
					s->right=s->right->erase(k);
				}else{
					s=rotate_left();
					s->left=s->left->erase(k);
				}
			}
			else if(k<key)left = left->erase(k);
			else right = right->erase(k);
			s->update();
			return s;
		}
		Node *nth_element(int n){
			if(size<=n)return NULL;
			Node *t=this;
			while((t->left?t->left->size:0)!=n){
				if(t->left && n<=t->left->size){
					t=t->left;
				}else {
					if(t->left)n-=t->left->size;
					n--;
					t=t->right;
				}
			}
			return t;
		}
		void update(){
			left->update_size();
			right->update_size();
			update_size();
		}
		void update_size(){
			if(!this)return;
			size = 1 + (left?left->size:0) + (right?right->size:0);
		}
	} *root;
public:
	Treap():root(0){}
	~Treap(){if(root)delete root;}
	void insert(const Key& k,const Val& v=Nothing()){
		root=root->insert(new Node(k,v));
	}
	Val* find(const Key& k){
		Node *p=root->find(k);
		if(p)return &p->value;
		return NULL;
	}
	void erase(const Key& k){
		root=root->erase(k);
	}
	Key nth_element(int n)const{
		return root->nth_element(n)->key;
	}
	int size()const{
		return root->size;
	}
};

int main(){
	int n,k,m;
	while(cin>>n>>k>>m,n|k|m){
		Treap<int> t;
		for(int i=1;i<=n;i++)t.insert(i);
		m--;
		while(1<t.size()){
			t.erase(t.nth_element(m));
			m=(m+k-1)%t.size();
		}
		cout<<t.nth_element(0)<<endl;
	}
	return 0;
}

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

const int MOD = 1e9+7;


int main(){
    int S; cin >> S;

    vector<long long> dp(2010, 0);
    dp[0] = 1;
    dp[3] = 1;
    dp[4] = 1;
    dp[5] = 1;
    
    for(int i=6; i<=S; ++i){
        for(int j=0; j<=i-3; ++j){
            dp[i] += dp[j];
            dp[i] %= MOD;
        }
    }

    cout << dp[S] << endl;
}


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

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	ll N; cin >> N;

	ll ans = 0;

	for (int i = 1; i <= N; i++) {
		for (int j = i; j <= N; j += i) {
			ans += j;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 998244353;

int main() {
	int n, s;
	cin >> n >> s;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(s+1, vector<ll>(3)));
	// dp[0][0][0] = 1;
    rep(i,n+1) dp[i][0][0] = 1;
	rep(i,n) rep(j,s+1) {
        // a[i]を選ばない場合
        // (dp[i+1][j][0] += dp[i][j][0]) %= MOD;
        (dp[i+1][j][1] += dp[i][j][0] + dp[i][j][1]) %= MOD;
        (dp[i+1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2]) %= MOD;
		if(j + a[i] <= s) { // a[i]を選ぶ場合
            (dp[i+1][j+a[i]][1] += dp[i][j][0] + dp[i][j][1]) %= MOD;
            (dp[i+1][j+a[i]][2] += dp[i][j][0] + dp[i][j][1]) %= MOD;
		}
	}
	cout << dp[n][s][2] << endl;
	return 0;
}


Measured memory_bytes: 493056
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int Partition(int a[], int p, int r) {
	int x = a[r];
	int i = p-1;
	for(int j = p; j < r; j++) {
		if(a[j] <= x) {
			i++;
			int temp = a[i];
			a[i] = a[j];
			a[j] = temp;
		}
	}
	int temp = a[i+1];
	a[i+1] = x;
	a[r] = temp;
    return i+1;
}



int main() {
	int n;
	cin >> n;
	int a[n];
	for( int i = 0; i < n; i++) cin >> a[i];
	int b = Partition(a, 0, n-1);
	for( int i = 0; i < n; i++) {
		if(i == b) {
			if( i ) cout << " [" <<a[i] << "]";
			else cout << "[" << a[i] << "]";
		} else if( i ) cout << " " <<a[i];
		else cout << a[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1548
import scala.collection.mutable

object Main extends App {
  val max = 7368791
  scala.io.Source.stdin.getLines
    .map(_.split(" ").map(_.toInt))
    .map { case Array(m, n) => (m, n) }
    .filter { case (m, _) => m != 0 }
    .map { case (m, n) => f(m, n) }
    .foreach(println)

  def f(m: Int, _n: Int): Int = {
    val set = mutable.BitSet()
    var n = _n
    set ++= m to max
    var i = m
    while (true) {
      if (set.contains(i)) {
        if (n == 0) return i
        set --= i to max by i
        n -= 1
      }
      i += 1
    }
    0
  }
}



Measured memory_bytes: 568068
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXLEN 1001
#define MAX(a, b) ((a) < (b) ? (b) : (a))

int
lcs(char *xs, int _xl, char *ys, int _yl)
{
	int i, j;
	int xl = _xl + 1, yl = _yl + 1;
	static int *buf = NULL;
	static int buflen = 0;

	if (buflen < xl * yl) {
		if (buf != NULL)
			free(buf);
		buf = (int *)malloc(sizeof(int) * xl * yl);
		if (buf == NULL)
			return -1;
		buflen = xl * yl;
	}

#define BUF(i, j) buf[(j) * xl + (i)]
	for (j = 0; j < yl; j++)
		BUF(0, j) = 0;

	for (i = 1; i < xl; i++) {
		BUF(i, 0) = 0;
		for (j = 1; j < yl; j++) {
			if (xs[i-1] == ys[j-1])
				BUF(i, j) = BUF(i-1, j-1) + 1;
			else
				BUF(i, j) = MAX(BUF(i, j-1), BUF(i-1, j));
		}
	}
#ifdef DEBUG
	for (j = 0; j < yl; printf("\n"), j++)
		for (i = 0; i < xl; i++)
			printf("%d ", BUF(i, j));
#endif

	return BUF(xl-1, yl-1);
#undef BUF
}

int
main(void)
{
	int i, n, xl, yl, v;
	char xs[MAXLEN];
	char ys[MAXLEN];

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s%s", xs, ys);
		xl = strlen(xs);
		yl = strlen(ys);
		if (xl < yl)
			v = lcs(xs, xl, ys, yl);
		else
			v = lcs(ys, yl, xs, xl);
		if (v < 0)
			return 1;
		printf("%d\n", v);
	}


	return 0;
}



Measured memory_bytes: 5700
#include <iostream>
using namespace std;
typedef long long ll;
ll a,b,c;
int main()
{
    cin>>a>>b>>c;
    for(int i=1;i<=10000000;i++)
    {
        if((i*a)%b==c)
        {
            cout<<"YES\n";
            return 0;
        }
    }
    cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;

const int N = 30000 + 1 ;	
int n , m ,  k;
int a[N];
int sum1 = 0 , sum2 = 0;

main(){
	
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	cin >> n;
	sum1 = 1;
	ld tmp = 0;
	for(int i = 1 ; i <= n; i++){
		cin >> a[i];
		sum1 *= a[i];
		tmp += 1.0L / a[i];
	}

	for(int i = 1 ; i <= n ; i++){
		sum2 += sum1/a[i];
	}

	
	cout << setprecision(9) << fixed << ( 1.0L / tmp); 
}

Measured memory_bytes: 256
n,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in range(n)]
# 座圧
x,y=zip(*xy)
xsort=list(x)
ysort=list(y)
xsort.sort()
ysort.sort()
from bisect import bisect_left
x=[bisect_left(xsort,xi) for xi in x]
y=[bisect_left(ysort,yi) for yi in y]
xy=list(zip(x,y))
pmap=[[0]*(n) for _ in range(n)]
for x,y in xy:
  pmap[x][y]+=1
#print(pmap)
for i in range(n):
  tmp=0
  for j in range(n):
    tmp+=pmap[i][j]
    pmap[i][j]=tmp
    if i!=0:
      pmap[i][j]+=pmap[i-1][j]
def func(x1,y1,x2,y2):
  if x1==x2 or y1==y2:return 0
  if x1>x2:x1,x2=x2,x1
  if y1>y2:y1,y2=y2,y1
  if x1==0 and y1==0:
    return pmap[x2][y2]
  elif x1==0:
    return pmap[x2][y2]-pmap[x2][y1-1]
  elif y1==0:
    return pmap[x2][y2]-pmap[x1-1][y2]
  else:
    return pmap[x2][y2]-pmap[x1-1][y2]-pmap[x2][y1-1]+pmap[x1-1][y1-1]

ans=float('inf')
for x1 in range(n-1):
  for x2 in range(x1+1,n):
    for y1 in range(n-1):
      for y2 in range(1,n):
        c=func(x1,y1,x2,y2)
        if func(x1,y1,x2,y2)>=k:
          #print(xsort[x1],xsort[x2],xsort[y1],xsort[y2])
          b=abs(xsort[x1]-xsort[x2])*abs(ysort[y1]-ysort[y2])
          ans=min(ans,b)
print(ans)
#print(pmap)

Measured memory_bytes: 76836
#include<iostream>
using namespace std;
int main()
{
  long long a, b, x;
  cin >> a >> b >> x;
  if(x > b && a != 0)
  {
    cout << 0;
    return 0;
  }
  if(a == b && b % x != 0)
  {
    cout << 0;
    return 0;
  }
  long long k = a / x;
  if(a % x != 0)
    k++;
  long long t = b / x;
  cout << t - k + 1;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101010;
int n , K , a[N] , ans , Max[N];
vi g[N];

void dfs(int c,int dep){
    Max[c] = dep;
    for(auto e : g[c]){
        dfs(e , dep + 1);
        Max[c] = max(Max[c] , Max[e]);
    }
    if(Max[c] - dep + 1 >= K && a[c] != 1)
        Max[c] = dep - 1 , ans++;
}

int main(){
    scanf("%d%d",&n,&K);
    for(int i=1;i<=n;++i) scanf("%d",a + i);
    if(a[1] != 1) a[1] = 1 , ans++;
    for(int i=2;i<=n;++i) g[a[i]].pb(i);
    dfs(1,0);
    printf("%d\n",ans);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  bool b[10010] = {false};
  b[n] = true;
  for(int i=2;;i++) {
    if(n%2 == 0) n=n/2;
    else n=3*n+1;

    if(b[n]) {cout << i << endl; break;}
    else b[n] = true;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
 
    int a[100],i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=n-1;i>=0;i--){
        printf("%d",a[i]);
        if(i!=0)    printf(" ");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600