akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
c=[0]*n
d=0
sums=0
for j in range(n):
    if j-a[j]<1:
        das=0
    else:
        b[j-a[j]]=b[j-a[j]]+1
    if j+a[j]>n-2:
        das=0
    else:
        c[j+a[j]]=c[j+a[j]]+1
for k in range(n):
    d=b[k]*c[k]
    sums=sums+d
print(sums)

Measured memory_bytes: 32232
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

ll lcm(ll a,ll b)
{
  ll l,r;
  ll ta=a,tb=b;
  
  if(a<b)swap(a,b);

  r=a%b;

  while(r!=0)
    {
      a=b;
      b=r;
      r=a%b;
    }
 
  l=ta/b*tb;
  return l;
}

signed main(void)
{
  in(int,n);
  ll t[112]={};
  rep(i,n)cin>>t[i];
  ll l=1;
  rep(i,n)
    l=lcm(l,t[i]);
  cout<<l<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N, K; cin >> N >> K;
  int h[N]; rep(i,N) cin >> h[i];

  sort(h,h+N);

  int retval = 1000000009;
  rep(i,N-K+1) retval = min(retval, h[i+K-1]-h[i]);

  cout << retval << endl;



  

  // cout << fixed << setprecision(6);
  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

#define x first.first
#define y first.second
#define mp(a, b) make_pair(a, b)

typedef pair <int, int> Point;

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
string field[1280];
bool visited[1280][1280];
Point factory[10];
int h, w, n;

void visited_clear(void)
{
	for (int i = 0; i < 1280; i++){
		for (int j = 0; j < 1280; j++){
			visited[i][j] = false;
		}
	}
}

int calc(Point start, Point goal)
{
	long long ret = 0;
	queue < pair <Point, int> > q;
	q.push(mp(start, 0));

	while (!q.empty()){
		pair <Point, int> now = q.front();
		q.pop();
		// cout << now.x << " " << now.y << endl;
		if (visited[now.y][now.x]) continue;
		if (now.y == goal.second && now.x == goal.first){
			ret = now.second;
			break;
		}

		visited[now.y][now.x] = true;
		for (int i = 0; i < 4; i++){
			int ny = now.y + dy[i], nx = now.x + dx[i];
			if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
			if (field[ny][nx] == 'X') continue;
			q.push(mp(mp(nx, ny), now.second + 1));
		}
	}

	return ret;
}

int main(void)
{
	cin >> h >> w >> n;
	for (int i = 0; i < h; i++){
		cin >> field[i];
		for (int j = 0; j < w; j++){
			if (field[i][j] == 'S'){
				factory[0] = mp(j, i);
			}
			if ('1' <= field[i][j] && field[i][j] <= '9'){
				factory[field[i][j] - '0'] = mp(j, i);
			}
		}
	}

	long long ret = 0;
	for (int i = 0; i < n; i++){
		visited_clear();
		ret += calc(factory[i], factory[i + 1]);
	}

	cout << ret << endl;
}

Measured memory_bytes: 3868
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;

int main(){
    int H,W,K;
    cin>>H>>W>>K;
    int num=0;
    vector<vector<char> >c(H,vector<char>(W));
    for (int i=0;i<H;i++){
        for (int j=0;j<W;j++) cin>>c[i][j];
    }
    int ans=0;
    for (int i=0;i<(1<<H);i++){
        for (int j=0;j<(1<<W);j++){
            num=0;
            for (int k=0;k<H;k++){
                for (int l=0;l<W;l++){
                    if ((i&(1<<k))==0){
                        if  ((j&(1<<l))==0){
                            if (c[k][l]=='#') num+=1;
                        }
                    }   
                }
            }
            if (num==K) ans+=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
	int a,b,z[100],i,s,c;
	while(~scanf("%d%d",&a,&b))
	{
		s=0;
		c=1;
		for(i=0;i<a;i++)
		{
			scanf("%d",&z[i]);
			s+=z[i];
			if(s<=b)
			c++;
		}
		printf("%d\n",c);
	} 
	return 0;
 } 

Measured memory_bytes: 504
// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.
import java.util.*;
import java.io.*;

class Main
{
    public static void main(String[] args)
    {
		new Main().run();
    }
	
	void run(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A=new int[N];
		int[] A_diff=new int[2*N-1];
		int[] B=new int[N];
		int[] B_diff=new int[N];
		for(int i=0;i<N;++i)A[i]=sc.nextInt();
		for(int i=0;i<N;++i)B[i]=sc.nextInt();
		for(int i=0;i<N;++i)A_diff[i]=A[i]^A[(i+1)%N];
		for(int i=0;i<N;++i)B_diff[i]=B[i]^B[(i+1)%N];
		for(int i=0;i<N-1;++i)A_diff[i+N]=A_diff[i];
		boolean[] search=search(A_diff,B_diff);
		int ans=0;
		for(int i=0;i<N;++i){
			if(search[i]){
				System.out.println(i+" " +(B[0]^A[i]));
			}
		}
	}
	
	boolean[] search(int[] a,int[] b){
		int[] border=border(b);
		boolean[] ret=new boolean[a.length];
		int s=0,t=0,match=0;
		for(int i=0;i<a.length;++i){
			while(match>=0&&(match>=b.length||b[match]!=a[i]))match=(match==0?-1:border[match-1]);
			++match;
			if(match==b.length){ret[i-match+1]=true;}
		}
		return ret;
	}
	
	int[] border(int[] b){
		int n=b.length;
		int[] pat=new int[n];
		int match=0;
		for(int i=1;i<n;++i){
			while(match>=0&&b[i]!=b[match])
				match=(match==0?-1:pat[match-1]);
			++match;
			pat[i]=match;
		}
		return pat;
	}
	
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}

// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase


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

int h,w;
char s[400][400];

int cost[400][400];
int dp[400][400];

int calc(int t){
	memset(cost,0,sizeof(cost));
	memset(dp,0x3f,sizeof(dp));
	for(int i=h;i>=0;i--){
		for(int j=h-1;j>=0;j--){
			cost[i][h]+=(j-(h-i)>=0?s[j-(h-i)][t]==s[j][t+1]:0);
		}
		for(int k=1;k<=i;k++){
			cost[i-k][h-k]=cost[i-k+1][h-k+1]-(s[i-k][t]==s[h-k][t+1]);
		}
	}
	for(int i=h-1;i>=0;i--){
		for(int j=h-1;j>=0;j--){
			cost[h][i]+=(j-(h-i)>=0?s[j][t]==s[j-(h-i)][t+1]:0);
		}
		for(int k=1;k<=i;k++){
			cost[h-k][i-k]=cost[h-k+1][i-k+1]-(s[h-k][t]==s[i-k][t+1]);
		}
	}
	dp[h][h]=0;
	for(int i=h;i>=0;i--){
		for(int j=h;j>=0;j--){
			if(i)dp[i-1][j]=min(dp[i-1][j],dp[i][j]+cost[i][j]);
			if(j)dp[i][j-1]=min(dp[i][j-1],dp[i][j]+cost[i][j]);
		}
	}
	return dp[0][0];
}
int main(){
	scanf("%d%d",&h,&w);
	rep(i,h)scanf("%s",s[i]);
	int ans=0;
	rep(i,w-1){
		ans+=calc(i);
	}
	cout<<ans<<endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<vector<int>>	vec(N + 1, vector<int>(3));
	for (int i = 1; i <= N; i++)
	{
		rep(j, 3)
			cin >> vec.at(i).at(j);
	}
	for (int i = 1; i <= N; i++)
	{
		int	time_dif;
		time_dif = vec.at(i).at(0) - vec.at(i - 1).at(0);
		int distance;
		distance = abs(vec.at(i).at(1) - vec.at(i - 1).at(1)) + abs(vec.at(i).at(2) - vec.at(i - 1).at(2));
		while (time_dif > 0)
		{
			if (time_dif == distance)
				break;
			time_dif -= 2;
			if (distance > time_dif)
			{
				cout << "No" << endl;
				return (0);
			}
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int[]ABC=cin.ArrayInt(3,0);
        if(ABC[1]<ABC[2]||ABC[2]<ABC[0])Console.WriteLine("No");
      else Console.WriteLine("Yes");
        
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 13140
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var color="black,blue,lime,aqua,red,fuchsia,yellow,white".split(",");
for(var i=0;i<Arr.length;i++){
   if(Arr[i]=="0")break;
   var str=Arr[i].slice(1);
   var arr=[];
   str.replace(/(..)/g,function(v){
      arr.push(parseInt(v,16));
   });
   var r=arr[0];
   var g=arr[1];
   var b=arr[2];
   var R=Math.pow(r-255,2);
   var G=Math.pow(g-255,2);
   var B=Math.pow(b-255,2);
   var abc=[];
   abc.push(Math.sqrt(r*r+g*g+b*b));
   abc.push(Math.sqrt(r*r+g*g+B));
   abc.push(Math.sqrt(r*r+G+b*b));
   abc.push(Math.sqrt(r*r+G+B));
   abc.push(Math.sqrt(R+g*g+b*b));
   abc.push(Math.sqrt(R+g*g+B));
   abc.push(Math.sqrt(R+G+b*b));
   abc.push(Math.sqrt(R+G+B));
   var min=Math.min.apply(null,abc);
   console.log(color[abc.indexOf(min)]);
}

Measured memory_bytes: 10544
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;
const int INF=10000000LL;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,P> Pa;
int N,a,ans=0;
int A[105]={};
P C[35][35];
int main(){
	cin>>N;
	for(int i=0;i<N;++i){
		cin>>a;
		A[a]++;
	}
	for(int i=0;i<105;++i){
		if(A[i])++ans;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
/*{{{*/
//#define HOME
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define F first
#define S second

template<class T> void _R(T &_x) { cin >> _x; }
void _R(int &_x) { scanf("%d", &_x); }
void _R(int64_t &_x) { scanf("%" SCNd64, &_x); }
void _R(double &_x) { scanf("%lf", &_x); }
void _R(char &_x) { scanf(" %c", &_x); }
void _R(char *_x) { scanf("%s", _x); }
template<class T, class U> void _R(pair<T, U> &_x) {_R(_x.F); _R(_x.S);}
void R() {}
template<class T, class... U> void R(T &_head, U &... _tail) { _R(_head); R(_tail...); }

template<class T> void _W(const T &_x) { cout << _x; }
void _W(const int &_x) { printf("%d", _x); }
void _W(const int64_t &_x) { printf("%" PRId64, _x); }
void _W(const double &_x) { printf("%.16f", _x); }
void _W(const char &_x) { putchar(_x); }
void _W(const char *_x) { printf("%s", _x); }
template<class T, class U> void _W(const pair<T, U> &_x) {_W(_x.F); putchar(' '); _W(_x.S);}
template<class T> void _W(const vector<T> &_x) { for (auto i = _x.begin(); i != _x.end(); _W(*i++)) if (i != _x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &_head, const U &... _tail) { _W(_head); putchar(sizeof...(_tail) ? ' ' : '\n'); W(_tail...); }
template<class T, class... U> void DB(const T &_head, const U &... _tail) {
#ifdef HOME
    W('#', _head, _tail...);
#endif
}

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define RAN(x,n) (x).begin(), (x).begin()+(n)
#define UNIQUE(x) {sort(ALL(x)); (x).erase(unique(ALL(x)), (x).end());}

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
//#define ITER(i,t) for (auto i = t.begin(); i != t.end(); ++i)
#define IT3(i,st,ed) for (auto i = st; i != ed; ++i)
#define IT2(i,range) IT3(i,range)

#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define MS(X, v) memset((X), (v), sizeof((X)))

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

inline int LG (const unsigned int &_x) { return 31-__builtin_clz(_x); }  // floor: LG(x), ceil: LG(x-1)+1
/*}}}*/

int a, b;

int main(){
    R(a, b);
    if(1 <= a && a <= 9 && 1 <= b && b <= 9)
        W(a*b);
    else W(-1);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int s = sc.nextInt();
		int w = sc.nextInt();

		if(w >= s) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}

		sc.close();

	}

}


Measured memory_bytes: 35756
#include <iostream>
#include <vector>

using namespace std;

int main() {
		vector<int> odd(100001, 0);
		vector<int> even(100001, 0);

		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
				int v;
				cin >> v;
				if (i % 2) odd[v]++;
				else even[v]++;
		}

		int most_odd = 0, second_most_odd = 0;
		int most_odd_number;
		int most_even = 0, second_most_even = 0;
		int most_even_number;
		for (int i = 1; i <= 100000; i++) {
				if (most_odd < odd[i]) {
						second_most_odd = most_odd;
						most_odd = odd[i];
						most_odd_number = i;
				} else if ( second_most_odd < odd[i]) {
						second_most_odd = odd[i];
				}

				if (most_even < even[i]) {
						second_most_even = most_even;
						most_even = even[i];
						most_even_number = i;
				} else if ( second_most_even < even[i]) {
						second_most_even = even[i];
				}
		}

		if (most_odd_number == most_even_number) {
				cout << n - max(most_odd + second_most_even, most_even + second_most_odd) << endl;
		} else {
				cout << n - (most_odd + most_even) << endl;
		}

		return 0;
}


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

int main()
{
    int abcde[5];
    int k;
    for (int i = 0; i < 5; i++)
    {
        cin >> abcde[i];
    }
    cin >> k;

    bool ans = true;
    for (int i = 0; i < 5; i++)
    {
        for (int j = i + 1; j < 5; j++)
        {
            if(abcde[j] - abcde[i] > k)ans = false;
        }
    }
    
    if(ans)cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            int dataCnt = int.Parse(Console.ReadLine());
            List<int> inputData = new List<int>();

            foreach(string data in Console.ReadLine().Split(' '))
            {
                inputData.Add(int.Parse(data));

            }

            int minValue = int.MaxValue;
            for (int loop = 1; loop <= 100; loop++)
            {
                int currentCnt = 0;
                foreach (int man in inputData)
                {
                    if(man - loop != 0)
                    {
                        int tmpData = (int)Math.Pow(man - loop, 2);
                        currentCnt += tmpData;
                    }
                }
                if (currentCnt < minValue) {
                    minValue = currentCnt;
                }
            }

            Console.WriteLine(minValue);
        }
    }
}


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

int main() {
	ll a, b, c, d;
  	cin >> a >> b >> c >> d;
  
  	ll ans1=a*c;
  	ll ans2=a*d;
    ll ans3=b*c;
    ll ans4=b*d;
  
  	ll ans=max(ans1, max(ans2, max(ans3, ans4)));
  
  	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
ll X[15], Y[15], P[15];
vector<ll> x, y;

int t[16];

vector<ll> ans1[1<<15], ans2[1<<15];
ll ans[16];

signed main(){
    scanf("%d", &N);
    rep(i, N){
        scanf("%lld%lld%lld", &X[i], &Y[i], &P[i]);
        x.pb(X[i]);
        y.pb(Y[i]);
    }

    t[0] = 1;
    rep(i, N){
        t[i+1] = t[i]*3;
    }

    rep(i, (1<<N)){
        vector<ll> tmp(N, 1e16L);
        rep(j, N){
            rep(k, N){
                if((i>>k)&1){
                    tmp[j] = min(tmp[j], P[j]*abs(X[j]-x[k]));
                }
            }
            tmp[j] = min(tmp[j], P[j]*abs(X[j]));
        }
        ans1[i] = tmp;
    }

    rep(i, (1<<N)){
        vector<ll> tmp(N, 1e16L);
        rep(j, N){
            rep(k, N){
                if((i>>k)&1){
                    tmp[j] = min(tmp[j], P[j]*abs(Y[j]-y[k]));
                }
            }
            tmp[j] = min(tmp[j], P[j]*abs(Y[j]));
        }
        ans2[i] = tmp;
    }

    rep(i, N+1) ans[i] = 1e16L;
    rep(i, t[N]){
        int a = 0, b = 0, cnt = 0;
        rep(j, N){
            if((i/t[j])%3 == 1){
                a += (1<<j);
                cnt++;
            }
            if((i/t[j])%3 == 2){
                b += (1<<j);
                cnt++;
            }
        }
        if(cnt <= N){
            ll tmp = 0;
            rep(j, N){
                tmp += min(ans1[a][j], ans2[b][j]);
            }
            ans[cnt] = min(ans[cnt], tmp);
        }
    }
    rep(i, N+1) printf("%lld\n", ans[i]);
}

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

using namespace std;

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

    set<string> s;
    string str;
    for(int i=0; i<n; i++) {
        cin >> str;
        s.insert(str);
    }

    cout << s.size() << endl;

    return 0;
}


Measured memory_bytes: 19228
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define INF 1<<25
 
typedef long long ll;

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}

int N,ma,mb;
int a[41],b[41],c[41];
int dp[41][401][401];//iまでのa,bとなる最小値
const int nmax = 40, abmax = 10;
int main(){
	cin>>N>>ma>>mb;
	rep(i,N)cin>>a[i]>>b[i]>>c[i];
	rep(i,N+1)rep(j,401)rep(k,401)dp[i][j][k]=INF;
	dp[0][0][0]=0;
	rep(i,N){
		rep(j,401){
			rep(k,401){
				if(dp[i][j][k]==INF)continue;
				//not use
				dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
				//use 
				dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
			}
		}
	}
	int ans=INF;
	REP(i,1,401)REP(j,1,401)if(i*mb==j*ma)ans=min(ans,dp[N][i][j]);
	if(ans==INF)cout<<"-1"<<endl;
	else	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 25984
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(),v.end());
    int ans = 0;
    for (int i = 0; i < k; ++i) {
        ans += v[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3680
n, k = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(k)]
mod = 998244353

dp = [1]
acc = [0, 1]

for i in range(1, n):
  new = 0
  for l, r in LR:
    if i < l:
      continue
    r = min(r, i)
    new += acc[i-l+1] - acc[i-r]
    new %= mod
  dp.append(new)
  acc.append((acc[-1]+new) % mod)

print(dp[-1])

Measured memory_bytes: 100688
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c;
    cin >> a >> b >> c;
    if(a==b&&b!=c){
        cout << "Yes" << endl;
        return 0;
    }
    if (a == c && b != a)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (c == b && a != c)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n;
      map<ll,ll>m;
      ll sum=0;
      for(int i=0;i<n;i++)
      {
        ll x;
        cin>>x;
        sum+=x;
        m[x]++;
      }
      ll q;
      cin>>q;
      for(int i=0;i<q;i++)
      {
        ll x,y;
        cin>>x>>y;
        sum+=m[x]*y-m[x]*x;
        m[y]+=m[x];
        m[x]=0;
        cout<<sum<<endl;
      }
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = (a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (a); i <= (long long)(n); i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std;

struct Edge {
    int cost, to;
    Edge(int to_, int cost_) : 
        to(to_), cost(cost_) { } 
};

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

    v2_int dist(n, v_int(n, INF));
    v_int prev(n, -1);
    v_int a(m), b(m), c(m); 

    map<pii, bool> used_path;

    irep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }

    irep(i, n) { dist[i][i] = 0; }

    irep(k, n) {
        irep(i, n) {
            irep(j, n) {
                if(dist[i][j] > dist[i][k] + dist[k][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }

    int ans = m;
    irep(i, m) {
        bool shortest = false;
        irep(j, n) {
            if(dist[j][b[i]] == dist[j][a[i]] + c[i]) shortest = true; 
        }
        if(shortest) { ans--; }
    }
    cout << ans << endl;

    return 0;
}
/** atcoder **/


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

int main(){
    long long int K,N;
    cin >> K >> N;
    long long int A[N],B[N];
    for (long long int i=0;i<N;i++){
        cin >> A[i];
    }

    sort(A,A+N);

    long long int delta=K -(A[N-1] - A[0]);
    for(int i = N-1;i>0;i--){
        delta = max(delta,A[i] - A[i-1]);
    }
    cout << K - delta;

}

Measured memory_bytes: 1792
def is_unique(list):
    return len(list) == len(set(list))


def fn(n):
    return n // 2 if n % 2 == 0 else 3 * n + 1


s = int(input())
a = [s]

while True:
    a.append(fn(a[len(a) - 1]))
    if not is_unique(a):
        print(len(a))
        break


Measured memory_bytes: 3060
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;


using vi=vector<int>;
using vvi=vector<vi>;


void vvi_alloc(vvi& r, int w, int h, int v=0)
{
	r.resize(h);
	for(auto&re:r) re.assign(w, v);
}


int main(void)
{
	int h, w, q;
	vvi s, sh, sv, c;

	while(scanf("%d%d%d", &h, &w, &q)==3)
	{
		vvi_alloc(s, w, h);
		vvi_alloc(c, w+1, h+1);
		vvi_alloc(sv, w, h);
		vvi_alloc(sh, w, h);

		{
			vector<char> buf(w+1);
			for(int y=0;y<h;y++)
			{
				scanf("%s", &buf[0]);
				for(int x=0;x<w;x++) s[y][x]=(buf[x]=='1');
			}
		}

		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				c[y+1][x+1]=c[y+1][x]+s[y][x];
			}
		}

		for(int y=0;y<h;y++)
		{
			for(int x=0;x<=w;x++)
			{
				c[y+1][x]+=c[y][x];
			}
		}

		for(int y=0;y<h;y++)
		{
			for(int x=1;x<w;x++)
			{
				sh[y][x]=sh[y][x-1];
				if(s[y][x]==1 && s[y][x-1]==1) sh[y][x]++;
			}
		}

		for(int x=0;x<w;x++)
		{
			for(int y=1;y<h;y++)
			{
				sv[y][x]=sv[y-1][x];
				if(s[y][x]==1 && s[y-1][x]==1) sv[y][x]++;
			}
		}

/*
for(auto&se:sh)
{
	for(auto see:se) printf("%2d ", see);
	printf("\n");
}
printf("\n");
for(auto&se:sv)
{
	for(auto see:se) printf("%2d ", see);
	printf("\n");
}
printf("\n");
*/
		for(int y=1;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				sh[y][x]+=sh[y-1][x];
			}
		}

		for(int y=0;y<h;y++)
		{
			for(int x=1;x<w;x++)
			{
				sv[y][x]+=sv[y][x-1];
			}
		}
/*
for(auto&se:sh)
{
	for(auto see:se) printf("%2d ", see);
	printf("\n");
}
printf("\n");
for(auto&se:sv)
{
	for(auto see:se) printf("%2d ", see);
	printf("\n");
}
printf("\n");
*/
		for(int i=0;i<q;i++)
		{
			int l, t, r, b;
			int c_num=0, sh_num=0, sv_num=0;

			scanf("%d%d%d%d", &t, &l, &b, &r);
			t--;l--;b--;r--;
			c_num=(c[b+1][r+1]-c[b+1][l])-(c[t][r+1]-c[t][l]);

			sh_num=(sh[b][r]-sh[b][l]);
			if(t>0) sh_num-=(sh[t-1][r]-sh[t-1][l]);

			sv_num=(sv[b][r]-sv[t][r]);
			if(l>0) sv_num-=(sv[b][l-1]-sv[t][l-1]);

//			printf("c_num=%d  sh_num=%d  sv_num=%d\n", c_num, sh_num, sv_num);
			printf("%d\n", c_num-sh_num-sv_num);
		}
	}
	return 0;
}


Measured memory_bytes: 64768
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

class BinaryIndexedTree {
  vector<int64_t> container;

 public:
  BinaryIndexedTree(size_t size) : container(size + 1) {
    fill(container.begin(), container.end(), 0);
  }
  void add(size_t i, int64_t v) {
    size_t idx = i + 1;
    while (idx < container.size()) {
      container[idx] += v;
      idx += idx & -idx;
    }
  }
  int64_t find(size_t i) {
    size_t idx = i;

    int64_t result = 0;
    while (idx != 0) {
      result = container[idx] + result;
      idx -= idx & -idx;
    }
    return result;
  }
  size_t lower_bound(int64_t v) {
    if (v == 0) {
      return 0;
    }
    int64_t w = v;
    size_t x = 0;
    for (size_t k = msb(container.size() - 1); k > 0; k >>= 1) {
      if (x + k < container.size() && container[x + k] < w) {
        w -= container[x + k];
        x += k;
      }
    }
    return x + 1;
  }

 private:
  size_t msb(size_t x) {
    x |= x >> 1;
    x |= x >> 2;
    x |= x >> 4;
    x |= x >> 8;
    x |= x >> 16;
    return (x + 1) >> 1;
  }
};

int64_t dceil(int64_t, int64_t);
int64_t dfloor(int64_t, int64_t);

int64_t dceil(int64_t x, int64_t y) {
  if (y < 0) {
    return dceil(-x, -y);
  }
  if (x < 0) {
    return -dfloor(-x, y);
  }
  return (x + y - 1) / y;
}

int64_t dfloor(int64_t x, int64_t y) {
  if (y < 0) {
    return dfloor(-x, -y);
  }
  if (x < 0) {
    return -dceil(-x, y);
  }
  return x / y;
}

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

  vector<int> a(N);
  rep(i, N) { cin >> a[i]; }

  vector<int> quantile(a);
  sort(quantile.begin(), quantile.end());
  quantile.erase(unique(quantile.begin(), quantile.end()), quantile.end());

  rep(i, N) {
    a[i] =
        lower_bound(quantile.begin(), quantile.end(), a[i]) - quantile.begin();
  }

  int lb = -1, ub = quantile.size() - 1;
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;

    int64_t z = 0;
    vector<BinaryIndexedTree> bit(2, BinaryIndexedTree(2 * N + 2));
    int cnt = 0;
    bit[0].add(N + 1, 1);
    rep(i, N) {
      if (a[i] > mid) {
        cnt++;
      }

      int key = 2 * cnt - (i + 1) + N + 1;
      int p = (i + 1) % 2;

      z += bit[p].find(key + 1) + bit[1 - p].find(key);

      bit[p].add(key, 1);
    }
    const int64_t M = (int64_t)N * (N + 1) / 2;
    (z >= dceil(M, 2) ? lb : ub) = mid;
  }
  cout << quantile[ub] << endl;
  return 0;
}

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

long long mod = 1000000007;

class UnionFind
{
public:
   vector<int> parent;
   UnionFind(int N)
   {
      for (int i = 0; i < N; i++)
      {
         parent.push_back(-1);
      }
   }
   int root(int A)
   {
      if (parent[A] < 0)
         return A;
      return parent[A] = root(parent[A]);
   }
   int size(int A)
   {
      return -parent[root(A)];
   }

   bool unite(int A, int B)
   {
      A = root(A);
      B = root(B);
      if (A == B)
         return false;
      if (size(A) < size(B))
         swap(A, B);
      parent[A] += parent[B];
      parent[B] = A;
      return true;
   }
};

int main(void)
{
   int S;
   cin >> S;
   vector<long long> dp(S + 1, 0);
   for (int i = 3; i <= S; i++)
   {
      dp[i] = 1;
   }
   for (int j = 1; j <= S; j++)
   {
      for (int i = 3; i <= j - 3; i++)
      {
         dp[j] += dp[i];
      }
      dp[j] %= mod;
   }
   cout << dp[S] << endl;
   return 0;
}


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

#define MOD (long long)(1e9 + 7)
#define MAX 500000

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const {
    return ModInt(*this) += p;
  }
  ModInt operator-(const ModInt &p) const {
    return ModInt(*this) -= p;
  }
  ModInt operator*(const ModInt &p) const {
    return ModInt(*this) *= p;
  }
  ModInt operator/(const ModInt &p) const {
    return ModInt(*this) /= p;
  }
  bool operator==(const ModInt &p) const {
    return x == p.x;
  }
  bool operator!=(const ModInt &p) const {
    return x != p.x;
  }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ans(1), mul(x);
    while(n) {
      if(n & 1) ans *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ans;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

struct Combination {
  vector<ModInt<MOD>> _fact, _rfact, _inv;
  Combination(long long nsize = MAX)
      : _fact(nsize + 1), _rfact(nsize + 1),
        _inv(nsize + 1) {
    _fact[0] = _rfact[nsize] = _inv[0] = 1;
    for(int i = 1; i <= nsize; i++)
      _fact[i] = _fact[i - 1] * i;
    _rfact[nsize] /= _fact[nsize];
    for(int i = nsize - 1; i >= 0; i--)
      _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= nsize; i++)
      _inv[i] = _rfact[i] * _fact[i - 1];
  }
  inline ModInt<MOD> fact(int k) const { return _fact[k]; }

  inline ModInt<MOD> rfact(int k) const {
    return _rfact[k];
  }

  inline ModInt<MOD> inv(int k) const { return _inv[k]; }

  ModInt<MOD> P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  ModInt<MOD> C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
  ModInt<MOD> H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

long long n, k;
Combination com;

ModInt<MOD> solve();

int main() {
  cin >> n >> k;
  cout << solve() << endl;
  return 0;
}

ModInt<MOD> solve() {
  ModInt<MOD> res;
  for(int i = 0; i <= min(k, n); ++i) {
    res += com.C(n, i) * com.H(n - i, i);
  }
  return res;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	const int MAXN = 1e5;
	int n, m, h[MAXN], hmax[MAXN];
	cin >> n >> m;
	for(int i = 0; i < n; ++i) {
		cin >> h[i];
		hmax[i] = -1e9;
	}
	for(int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		hmax[a] = max(hmax[a], h[b]);
		hmax[b] = max(hmax[b], h[a]);
	}
	int cnt = 0;
	for(int i = 0; i < n; ++i) {
		if(h[i] > hmax[i]) ++cnt;
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 4476
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int a[100010];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,p;
    long long s=0;
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi();
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++) {
	if(a[i]>s+s) p=i;
	s+=a[i];
    }
    cout<<n-p+1;
    return 0;
}

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

using namespace std;

typedef long long  ll;

int Partition(vector<int> &a, int p, int r)
{
    int x = a[r], i = p - 1;

    for (int j = p; j < r; ++j)
        if (a[j] <= x)
            swap(a[++i], a[j]);

    swap(a[i + 1], a[r]);

    return i + 1;
}

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

    int n;

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

    int idx = Partition(a, 0, n - 1);

    for (int i = 0; i < n; ++i) {
        if (i == idx)
            cout << "[" << a[i] << "]";
        else
            cout << a[i];

        cout << (i == n - 1 ? '\n' : ' ');
    }

    return 0;
}

Measured memory_bytes: 1524
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
int a[maxn], tot;
int m, k, ed;

bool work(){
    ed = 1 << m;
    tot = 0;
    if (k == 0){
        for (int i=0;i<ed;i++) a[tot++] = i, a[tot++] = i;
        return true;
    }
    int sum = 0;
    for (int i=0;i<ed;i++) sum ^= i;
    if (sum || k >= ed) return false;
    for (int i=0;i<ed;i++) if (i != k) a[tot++] = i;
    a[tot++] = k;
    for (int i=ed-1;~i;i--) if (i != k) a[tot++] = i;
    a[tot++] = k;
    return true;
}
int main(){
    scanf("%d%d",&m,&k);
    if (!work()) puts("-1");
    else{
        for (int i=0;i<tot;i++) printf("%d%c",a[i],(i == tot-1 ? '\n' : ' '));
    }
    return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

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



int dp[101][401];
void solve() {
	dp[0][0] = 1;
	int x, y; cin >> x >> y;
	rep(i, x) {
		rep(j, 4*i+1) {
			dp[i + 1][j + 2] += dp[i][j];
			dp[i + 1][j + 4] += dp[i][j];
		}
	}
	if (dp[x][y] > 0) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
		return 0;
}


Measured memory_bytes: 3696
fn main() {
    let ab = read_vec::<i32>();
    println!("{}", [ab[0] + ab[1], ab[0] - ab[1], ab[0] * ab[1]].iter().max().unwrap());
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

Measured memory_bytes: 4352
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 2000000
#define MO 1000000007
using namespace std;
struct triple
{
	int a,b,c;
	triple(){};
	triple(int _a,int _b,int _c):a(_a),b(_b),c(_c){};
}a[4],b[4];
int PowMod(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)
			ret=1LL*ret*a%MO;
		a=1LL*a*a%MO;
		b>>=1;
	}
	return ret;
}
int fact[MAXN+5],inv[MAXN+5];
int x3,x4,y3,y4;
void prepare()
{
	fact[0]=1;
	for(int i=1;i<=MAXN;i++)
		fact[i]=1LL*fact[i-1]*i%MO;
	inv[MAXN]=PowMod(fact[MAXN],MO-2);
	for(int i=MAXN-1;i>=0;i--)
		inv[i]=1LL*inv[i+1]*(1LL*i+1LL)%MO;
}
int PathNum(int x1,int y1,int x2,int y2)
{return 1LL*fact[x2-x1+y2-y1]*inv[x2-x1]%MO*inv[y2-y1]%MO;}
int Solve(triple A,triple B)
{
	int x1=A.a,y1=A.b,x2=B.a,y2=B.b;
	int ret=0;
	for(int i=x3;i<=x4;i++)	ret=(1LL*ret+1LL*PathNum(x1,y1,i,y3-1)*PathNum(i,y3,x2,y2)%MO*(-i-y3)%MO)%MO;
	for(int j=y3;j<=y4;j++)	ret=(1LL*ret+1LL*PathNum(x1,y1,x3-1,j)*PathNum(x3,j,x2,y2)%MO*(-j-x3)%MO)%MO;
	for(int i=x3;i<=x4;i++)	ret=(1LL*ret+1LL*PathNum(x1,y1,i,y4)*PathNum(i,y4+1,x2,y2)%MO*(i+y4+1)%MO)%MO;
	for(int j=y3;j<=y4;j++)	ret=(1LL*ret+1LL*PathNum(x1,y1,x4,j)*PathNum(x4+1,j,x2,y2)%MO*(j+x4+1)%MO)%MO;
	return ret;
}
int main()
{
	prepare();
	int x1,x2,x5,x6;
	int y1,y2,y5,y6;
	scanf("%d %d %d %d %d %d",&x1,&x2,&x3,&x4,&x5,&x6);
	scanf("%d %d %d %d %d %d",&y1,&y2,&y3,&y4,&y5,&y6);
	a[0]=triple(x2,y2,1),a[1]=triple(x2,y1-1,-1),a[2]=triple(x1-1,y2,-1),a[3]=triple(x1-1,y1-1,1);
	b[0]=triple(x6+1,y6+1,1),b[1]=triple(x6+1,y5,-1),b[2]=triple(x5,y6+1,-1),b[3]=triple(x5,y5,1);
	int ans=0;
	for(int i=0;i<4;i++)
		for(int j=0;j<4;j++)
			ans=((1LL*ans+1LL*a[i].c*b[j].c*Solve(a[i],b[j])%MO)+MO)%MO;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 15744
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int h = sc.nextInt();
    int a = sc.nextInt();

    int remainder = h % a;
    int x = (int)(h/a);

    if( remainder > 0 ){
      x++;
    }
    
    System.out.println(x);
  }
}


Measured memory_bytes: 23504
l, r = gets.strip.split.map(&:to_i)

if (r - l) >= 2019
  puts(0)
  return
end

ans = 3000
(l..r).each do |i|
  ((i + 1)..r).each do |j|
    ans = [ans, (i * j) % 2019].min
  end
end

puts(ans)


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, T; cin >> n >> T;
    ll r = 0;
    ll ans = 0;
    rep(i, n) {
        ll t; cin >> t;
        ans += min(t + T - r, T);
        r = t + T;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int counter[26]={0};
	char ch;
	int i;
	
	while ( (ch=getchar()) != EOF ){
		if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')){
			ch |= 0x20;
			int num = ch - 'a';  // 文字 ch の番号
			counter[num]++;
		}
	}
	
	for(i=0;i<26;i++){
		printf("%c : %d\n","abcdefghijklmnopqrstuvwxyz"[i],counter[i]);
	}
	
	return 0;
}


Measured memory_bytes: 2036
#include <algorithm>
#include <climits>
#include <iostream>
#include <random>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using std::cin;
using std::cerr;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
using std::stack;
using std::string;
using std::unordered_set;
using std::vector;
using std::lower_bound;
using std::upper_bound;

bool is_palindrome(const string& s) {
  string r = s;
  reverse(r.begin(), r.end());
  return s == r;
}

int main(int argc, char* argv[]) {
  string s;
  cin >> s;
  const int n = s.size();
  if (is_palindrome(s) && is_palindrome(s.substr(0, (n - 1) / 2)) && is_palindrome(s.substr((n + 3) / 2 - 1))) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		//入力
		int n = sc.nextInt();
		long[] a = new long[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextLong();
		}
		sc.close();

		//処理
		long ans = -1;
		for(int pat = 0; pat < 2; pat++){
			long sum = 0;
			long temp = 0;
			for(int i = 0; i < n; i++){
				sum += a[i];
				if(i % 2 == pat){
					if(sum <= 0){
						temp += Math.abs(sum) + 1;
						sum = 1;
					}
				}else{
					if(sum >= 0){
						temp += Math.abs(sum) + 1;
						sum = -1;
					}
				}
			}

			if(ans == -1){
				ans = temp;
			}else{
				ans = Math.min(ans, temp);
			}
		}

		//出力	
		out.println(ans);
		out.flush();
	}

	static class Pair{
		int w,v;
		public Pair(int a, int b){
			this.w = a;
			this.v = b;
		}
	}
}

Measured memory_bytes: 61420
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		int n = s.length();

		int count = 1;

		String mae = s.substring(0, 1);
		for (int i = 1; i < n; i++) {
			int len = mae.length();
			if (len == 2) {
				i++;
			}
			if (i < n) {
				String ato = s.substring(i, i + 1);
				if (len == 1 && mae.equals(ato)) {
					if (i + 2 <= n) {
						ato = s.substring(i, i + 2);
					}
				}

				if (!mae.equals(ato)) {
					count++;
//					System.out.print(ato + " ");
				}

				mae = ato;
			}
		}

		System.out.println(count);

		sc.close();
	}
}

Measured memory_bytes: 35916
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s; 
	int n = s.size();
	bool flag = true;
	for( int i = 0; i < n; ++i ){
		if( s[i] != s[n-i-1] ) flag = false;
	}
	for( int i = 0; i < (n-1)/2; ++i ){
		if( s[i] != s[(n-1)/2-i-1] ) flag = false;
	}
	/*
	for( int i = (n+1)/2; i < n; ++i ){
		if( s[i] != s[n-i-1+(n+1)/2] ) flag = false;
	}
	*/
	if( flag ) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[0]*(n+1)
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            t=x**2+y**2+z**2+x*y+y*z+z*x
            if t<=n:
                a[t-1]+=1
print(*a[:n],sep='\n')

Measured memory_bytes: 9516
A, B, C, X, Y = map(int, input().split())
ans = float('INF')
for i in range(0, 2*max(X, Y)+1, 2):
  ans = min(ans, int(A*max(0, X-i/2)+B*max(0, Y-i/2)+C*i))
print(ans)


Measured memory_bytes: 9072