akhauriyash/Code-Regression huggingface dataset:
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var t = o.a();
  var a = o.m(n).sort((a,b)=>a[0]-b[0]);
  var dp = xArray(0,t+3001);
  for(var i = 0; i < n; i++){
    for(var j = t; j--;){
      if(dp[j+a[i][0]] < dp[j] + a[i][1]){
        dp[j+a[i][0]] = dp[j] + a[i][1];
      }
    }
  }
  return Math.max(...dp);
}

Measured memory_bytes: 21912
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
#include<bitset>
#include<functional>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<random>
#include<ctime>
#include<complex>
using namespace std;
typedef long long LL;
mt19937 gene(233);
typedef complex<double> Complex;
#define fi first
#define se second
#define ins insert
#define pb push_back
inline char GET_CHAR(){
	const int maxn = 131072;
	static char buf[maxn],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++;
}
inline int getInt() {
	int res(0);
	char c = getchar();
	while(c < '0') c = getchar();
	while(c >= '0') {
		res = res * 10 + (c - '0');
		c = getchar();
	}
	return res;
}

inline LL fastpo(LL x, LL n, LL mod) {
	LL res(1);
	while(n) {
		if(n & 1) {
			res = res * (LL)x % mod;
		}
		x = x * (LL) x % mod;
		n /= 2;
	}
	return res;
}

inline string itoa(int x, int width = 0) {
  string res;
  if(x == 0) res.push_back('0');
  while(x) {
    res.push_back('0' + x % 10);
    x /= 10;
  }
  while((int)res.size() < width) res.push_back('0');
  reverse(res.begin(), res.end());
  return res;
}
template<const LL mod> struct MI{
	LL a;
	MI operator + (const MI & b) {
		MI res{a + b.a};
		if(res.a >= mod) res.a -= mod;
		return res;
	}
	MI operator - (const MI & b) {
		MI res{a - b.a};
		if(res.a <= 0) res.a += mod;
		return res;
	}
	MI operator * (const MI & b) {
		return MI{a * b.a % mod};
	}
	MI operator / (const MI & b) {
		return MI{a * fastpo(b.a, mod - 2, mod) % mod};
	}
};
const int N = 300033;
const int LOG = 20;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int a[N], b[N];
int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);
	}
	sort(a, a + n);
	sort(b, b + n);
	int ans = 0;
	if(n % 2 == 1) {
		ans = b[n / 2] - a[n / 2] + 1;
	}else {
		ans = (b[n / 2] + b[n / 2 - 1]) - (a[n / 2] + a[n / 2 - 1]) + 1;
	}
	cout << ans << endl;
}






Measured memory_bytes: 5224
import sys


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


mod = pow(10, 9)+7
N = int(input())
T = LI()
A = LI()
ans = 1
if N == 1:
    if T == A:
        print(1)
    else:
        print(0)
    sys.exit()
if N == 2:
    if T[1] == A[0]:
        print(1)
    else:
        print(0)
if T[N-1] != A[0]:
    print(0)
    sys.exit()
for i in range(1, N-1):
    if T[i-1] != T[i]:
        if A[i] < T[i]:
            print(0)
            sys.exit()
        continue
    if A[i] != A[i+1]:
        if A[i] > T[i]:
            print(0)
            sys.exit()
        continue
    ans = (ans * min(T[i], A[i])) % mod
print(ans)


Measured memory_bytes: 24872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		sc.close();
		
		int n = a * b;
		
		if (n%2 == 1) {
			System.out.println("Odd");
			
		 
		} else {
			System.out.println("Even");
		}
		
		
		
	}

}


Measured memory_bytes: 21844
object Main {
    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toDouble))
        in.foreach(x => println("%.3f %.3f".format((x(2)*x(4)-x(1)*x(5))/(x(0)*x(4)-x(1)*x(3))+0, (x(0)*x(5)-x(2)*x(3))/(x(0)*x(4)-x(1)*x(3))+0)))
    }
}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

int main() {
    double w, h, x, y;

    cin >> w >> h >> x >> y;

    bool b = x == (w / 2) && y == (h / 2);

    printf("%.20f %d\n", w * h / 2, b ? 1 : 0);

}



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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;

    while(a>=b){
        b*=2;
        k--;
    }
    while(b>=c){
        c*=2;
        k--;
    }
    if(k>=0){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<iostream>
#include <algorithm>

using namespace std;

int main() {
	long int  a, b;
	while (cin >> a >> b) {
		/*cout << __gcd(a, b) << " " << a * b / gcd(a, b) << endl;*/

		cout << a * b / (a / __gcd(a, b)*b) << " " << a / __gcd(a, b)*b << endl;
	}

}

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


int main(){
    int a, b, c; cin >> a >> b >> c;
    if(a+b+c>= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  int cnt = n;
  ll ans = 1;
  int hoge = 0;
  for(int i=0;i<n;++i) {
    int tmp;cin >> tmp;
    if(tmp < 2*i+1-2*hoge) {
      ans *= i+1-hoge;
      ans %= MOD;
      cnt--;
      hoge++;
    }
  }
  while(cnt > 1) {
    ans *= cnt;
    ans %= MOD;
    cnt--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); //cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

using namespace std;
typedef long long ll;
typedef long double ld;

/* BIEN CUC BO BEGIN*/
	int t, n, A[100002], k;
	
	int DD[100002];
/* BIEN CUC BO END*/

int main(){ FIO;
	cin >> n >> k;
	
	DD[1] = 0;
	for (int i=1; i<=n; ++i){
		if(i > 1) DD[i] = INT_MAX;
		cin >> A[i];
		for (int j=1; j<=k; ++j){
			if (i-j >= 1){
				DD[i] = min(DD[i], DD[i-j] + abs(A[i]-A[i-j]));
			}
		}
	}
	cout << DD[n];
return 0;}	

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace _1130
{
    class Program
    {
        static int ret = 0;
        static bool[,] tile;
        static void bfs(int x,int y)
        {
            tile[x,y] = false; ret++;
            if (tile[x + 1,y]) bfs(x + 1,y);
            if (tile[x - 1,y]) bfs(x - 1,y);
            if (tile[x,y + 1]) bfs(x,y + 1);
            if (tile[x,y - 1]) bfs(x,y - 1);
        }
        static void Main(string[] args)
        {
            while (true)
            {
                ret = 0;
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x.Max() == 0) break;
                tile = new bool[x[1] + 2,x[0] + 2]; int[] start = new int[2];
                for (int i = 0; i < x[1]; i++)
                {
                    string s = Console.ReadLine();
                    for (int j = 0; j < x[0]; j++)
                    {
                        if (s[j] == '@')
                        {
                            start[0] = i + 1; start[1] = j + 1;
                        }
                        tile[i + 1,j + 1] = s[j] == '.';
                    }
                }
                bfs(start[0],start[1]);
                Console.WriteLine(ret);
            }
        }
    }
}


Measured memory_bytes: 9780
def buildmake(building) :
    for i in range(3):
        iroom = str(i) + "room"
        iroom = list()
        for j in range(10):
            iroom.append(0)
        building.append(iroom)
    buildings.append(building)

def showroom(floor):
    roomline = str()
    for s in floor:
        roomline += " " + str(s)
    print(roomline)

buildings = list()
building1 = list()
building2 = list()
building3 = list()
building4 = list()

buildmake(building1)
buildmake(building2)
buildmake(building3)
buildmake(building4)

n = int(input())

for i in range(n):
      b,f,r,v = map(int,input().split())
      buildings[b-1][f-1][r-1] += v
      
buildcount = 0
for building in buildings:
    
    for floor in building:
        showroom(floor)
  
    if buildcount == len(buildings) - 1:
        break
    else:
        buildcount += 1
        print("#"*20)


Measured memory_bytes: 5604
s=input()
if 'N' in s and not'S' in s:
    print('No')
    exit()
if not 'N' in s and 'S' in s:
    print('No')
    exit()
if 'W' in s and not'E' in s:
    print('No')
    exit()
if not 'W' in s and 'E' in s:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int s,w;
  cin >> s >> w;
  if( w >= s){
    cout << "unsafe" << endl;
  }else{
    cout << "safe" << endl;
  }
}

Measured memory_bytes: 3620
import sys


fin = sys.stdin.readline
N = int(fin())
X_list = [int(elem) for elem in fin().split()]
sorted_indices = sorted(range(N), key=lambda i: X_list[i])
org_pos_to_sorted = {org_p: sorted_p for sorted_p, org_p in enumerate(sorted_indices)}

left_mid = X_list[sorted_indices[N // 2 - 1]]
right_mid = X_list[sorted_indices[N // 2]]
result = []
for i in range(N):
    sorted_pos = org_pos_to_sorted[i]
    if sorted_pos >= N // 2:
        result.append(left_mid)
    else:
        result.append(right_mid)

print(*result, sep="\n")


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

int main(){
  double d,t,s; cin >>d >>t >>s;
  if(t>=d/s) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

typedef long long ll;
typedef long long ld;
typedef vector<int> vi;
typedef pair<ll, ll> pii;

struct Node
{
    int node, len;
    Node() {node = len = 0;}
    Node(int node, int len) {this -> node = node, this -> len = len;}
};
typedef vector<Node> vg;

#define MAX 1
#define NON 0
#define MOD 1000000007

#define FOR(type, i, a, b) for(type i = a; i < b; i++)
#define FORR(type, i, b, a) for(type i = b; i > a; i--)
#define FORE(type, i, a, b) for(type i = a; i <= b; i++)
#define FORRE(type, i, b, a) for(type i = b; i >= a; i--)

#define testBit(n, bit) ((n >> bit) & 1)
#define flipBit(n, bit) (n ^ (1ll << bit))
#define randomize mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m; cin >> n >> m;
    int height[n + 1]; FORE(int, i, 1, n) cin >> height[i];
    int ma[n + 1] = {};
    FORE(int, i, 1, m){
        int u, v; cin >> u >> v;
        ma[u] = max(ma[u], height[v]);
        ma[v] = max(ma[v], height[u]);
    }
    int ans = 0;
    FORE(int, i, 1, n)
        if (height[i] > ma[i]) ans++;
    cout << ans;
}

Measured memory_bytes: 4436
#include<bits/stdc++.h>
 using namespace std;
 const long long mod=1e9+7;

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

 vector<int>oks(N+1,true);
 for(int i=0;i<M;++i){
 int a;cin>>a;
 oks[a]=false;
 }
 vector<long long int>dp(N+1);
 dp[0]=1;
 for(int now=0;now<N;++now){
 for(int next=now+1;next<=min(N,now+2);++next){
 if(oks[next]){
 dp[next]+=dp[now];
 dp[next]%=mod;
 }
 }
 }

 cout<<dp[N]<<endl;
return 0;
 }

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

int main(){
    int x1,x2;
    cin >> x1 >> x2;
    if(x1<x2){
       cout << x2-x1 << endl;
    }
    else if(x2<x1){
        cout << x1-x2 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
N = int(input())
W = [input() for _ in range(N)]
s = set(W)
if len(s) != N:
    print("No")
    exit()
for i in range(N - 1):
    if W[i][-1] != W[i + 1][0]:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 2940
N = int(input())
x = 0
check = 0

for i in range(N) :
    a,b = map(int,input().split())
    if a == b :
        x += 1
    else :
        x = 0
    if  x == 3 :
        check = 1

if check == 1 :
    print("Yes")
else :
    print("No")



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

int main() {
  int A,B;
  cin>>A>>B;
  if((A==1&&B==2)||(A==2&&B==1)) cout<<3<<endl;
  if((A==2&&B==3)||(A==3&&B==2)) cout<<1<<endl;
  if((A==3&&B==1)||(A==1&&B==3)) cout<<2<<endl;
}


Measured memory_bytes: 256
/*
 KUNAL RAUT (ZUKONIT14)  :- "DO WHAT YOU DONT LIKE!"
 -PICT,PUNE! :)
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define inv (mod+1)/3
#define mod9 1000000009
#define pi 3.1415926535
#define MAXN 1000001
#define MAX2N 1*1000 + 10
#define all(v) v.begin(), v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define forci(p,n) for(ll i=p;i<(ll)n;i++)
#define forcj(p,n) for(ll j=p;j<(ll)n;j++)
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define bits(a) __builtin_popcount(a)
#define test ll t;cin>>t;while(t--)
ll zero=0;
ll one=1;
ll gcd(ll a,ll b){    if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) {    return (a/gcd(a,b)*b);}
ll expo(ll x, ll y) {ll res=1;x=x%mod;while(y>0){if(y&1)res=(1ll*res*x)%mod;
    y=y>>1;x=(1ll*x*x)%mod;} return res;}
ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime(ll n){ll i;for(i=2;i<=sqrt(n);i++){if(n%i==0)return false;}return true;}
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return(a.second<=b.second);}

//https://www.youtube.com/watch?v=k4V3Mo61fJM

ll rr[]={0,1,1,1,0,-1,-1,-1,};
ll cc[]={1,1,0,-1,-1,-1,0,1};

signed main()
{
    bolt;
    ll n,k;cin>>n>>k;
    ll a[n],sum=0;
    forci(0,n)
    cin>>a[i];
    sort(a,a+n);
    reverse(a,a+n);
    if(k>=n)
    return cout<<"0",0;
    forci(k,n)
    sum+=a[i];
    cout<<sum;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

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

        int count = 0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            sum -= value;
            min = Math.min(value, min);
            count++;
        }

        count += (sum / min);

        System.out.print(count);
    }
}


Measured memory_bytes: 21844
import java.io.*;
import java.util.*;
public class  Main{
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt()*sc.nextInt();
		int[][]cost=new int[10][10];
		for(int i=0;i<10;i++) {
			for(int j=0;j<10;j++) {
				cost[i][j]=sc.nextInt();
			}
		}
		for(int k=0;k<10;k++) {
			for(int i=0;i<10;i++) {
				for(int j=0;j<10;j++) {
					if(cost[i][j]>cost[i][k]+cost[k][j]) {
						cost[i][j]=cost[i][k]+cost[k][j];
					}
				}
			}		
		}
		int[]nums=sc.takearr(n);
		long ans=0;
		for(int i:nums) {
			if(i!=-1) {
				ans+=cost[i][1];
			}
		}
		pw.println(ans);
		pw.flush();
	}	
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 25684
#include <iostream>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main(){
  string S;
  cin >> S;
  
  vector<int> count(26, 0);
  
  for(int i = 0; i < S.length(); i++){
    count[S[i] - 'a']++;
  }

  char ans;
  int ind = 0;
  
  while(count[ind] != 0){
    ind++; 
  }
  ans = 'a' + ind;
  if (ind > 25) cout << "None" << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;

// #define DEBUG

int const intmax = 2147483647;

class RMQ
{
    vector<int> sgt;
    int n;
    int k;

public:
    RMQ(int n1)
    {
        int na = 1;
        int ka = 0;
        while (na < n1)
        {
            na *= 2;
            ka++;
        }
        for (int i = 0; i < 2 * na; i++)
            sgt.push_back(intmax);
        n = na;
        k = ka;
    }

    void update(int i, int x)
    {
        i += n;
        sgt[i] = x;
        while (i > 1)
        {
            i /= 2;
            sgt[i] = min(sgt[2 * i], sgt[2 * i + 1]);
        }
    }

    int getmin(int a, int b, int k = 1, int l = 0, int r = -1) //閉区間 l <= x < r とする
    {
        if (r == -1)
            r = n;
        if (r <= a || b <= l)
            return intmax;
        if (a == l && b == r)
            return sgt[k];
        else
            return min(getmin(a, min(b, (l + r) / 2), 2 * k, l, (l + r) / 2), getmin(max(a, (l + r) / 2), b, 2 * k + 1, (l + r) / 2, r));
    }
    void printsegtree()
    {
        for (int i = 0; i < 2*n; i++){
            cout << sgt[i] << " ";
        }
        cout << endl;
    }

};

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, q, k, c, x, y;
    cin >> n >> q;
    RMQ segtree(n);

    for (int i = 0; i < q; i++)
    {
        cin >> c >> x >> y;
        if (c == 0)
            segtree.update(x, y);
        else
            cout << segtree.getmin(x, y + 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 3932
#include<cstdio>
#include<algorithm>
using namespace std;
static const int MAX_W = 100000;
static const int MAX_H = 100000;

int N, W, H;
int memo1[MAX_W + 2], memo2[MAX_H + 2];
int memo21[MAX_W + 1], memo22[MAX_H + 1];

int main(){
	scanf("%d %d %d", &N, &W, &H);
	for(int i = 0; i < N; i++){
		int x, y, w;
		scanf("%d %d %d", &x, &y, &w);
		memo1[max(x - w, 0)]++;
		memo1[min(x + w + 1, W + 1)]--;
		memo2[max(y - w, 0)]++;
		memo2[min(y + w + 1, H + 1)]--;
		memo21[max(x - w, 0)]++;
		memo21[min(x + w, W)]--;
		memo22[max(y - w, 0)]++;
		memo22[min(y + w, H)]--;
	}
	bool flag = true, flag2 = true, flag3 = true, flag4 = true;
	for(int i = 0; i <= W; i++){
		if(i > 0) memo1[i] += memo1[i - 1];
		if(memo1[i] == 0) flag = false;
	}
	for(int i = 0; i <= H; i++){
		if(i > 0) memo2[i] += memo2[i - 1];
		if(memo2[i] == 0) flag2 = false;
	}
	for(int i = 0; i < W; i++){
		if(i > 0) memo21[i] += memo21[i - 1];
		if(memo21[i] == 0) flag3 = false;
	}
	for(int i = 0; i < H; i++){
		if(i > 0) memo22[i] += memo22[i - 1];
		if(memo22[i] == 0) flag4 = false;
	}
	if((!flag && !flag2) || (!flag3 && !flag4)) printf("No\n");
	else printf("Yes\n");
	return 0;
}



Measured memory_bytes: 4252
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #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 TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    // #define te    
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 100100;

    void solve() {
        ll n;
        cin >> n;
        ll ans = n*n*n;
        cout << ans << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //ll ti;   cin >> ti;  while(ti--) 
      solve();
      return 0;
    } 


Measured memory_bytes: 256
#include<bits/stdc++.h>
/******* MY EVERY AC WILL BE A TRIBUTE TO SSR ********/
#define vi vector
#define lli long long int
#define vli vi<lli>
#define pb push_back
#define pll pair<lli,lli>
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).begin(),(x).end(),greater<lli>()
#define clear(x) x.clear()
#define rep(i,n) for(lli i=0;i<(lli)n;i++)
#define rep1(i,n) for(lli i=1;i<=(lli)n;i++)
#define rep2(i,n) for(lli i=1;i<(lli)n;i++)
#define refor(i,n) for(lli i=(lli)n;i>=0;i--)
#define range(i,l,r) for(lli i=(lli)l;i<=(lli)r;i++)
#define big(x,y) (x>y)?x:y
#define small(x,y) (x<y)?x:y
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
using namespace std;
lli gcd(lli a,lli b) {return b==0?a:gcd(b,a%b);}
lli lcm(lli a,lli b) {return (a*b)/gcd(a,b);}
bool isprime(lli x) {for(lli i=2;i<=sqrt(x);i++) { if(x%i == 0) return false;} return true;}
lli modpow(lli x,lli y) {x%=mod;lli res=1;while(y>0){if(y&1) res*=x%mod; y=y>>1; x=x*x%mod;} return res%mod;}
lli ncr(lli n,lli k) {lli res=1; if(k>n-k) k=n-k; rep(i,k){res*=(n-i);res/=(i + 1);} return res;}
lli bintodec(lli n) {lli decimal=0,i=0,rem;while (n!=0){rem = n%10;n/=10;decimal += rem*pow(2,i);++i;}return decimal;}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
   
   lli t,s=0,a;
    cin>>a;
    s=a+(a*a)+(a*a*a);
    cout<<s<<'\n';
  
    return 0;
}











Measured memory_bytes: 3708
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
c=Counter(lis)
if n%2==1:
    flag=True
    if c[0]!=1:
        flag=False
    for i in c.keys():
        if i!=0 and c[i]!=2:
            flag=False
    if flag==False:
        print(0)
    else:
        print(pow(2,(n-1)//2,mod))
else:
    flag=True
    for i in c.keys():
        if c[i]!=2:
            flag=False
    if flag==False:
        print(0)
    else:
        print(pow(2,n//2,mod))
    
    

            

    
    
        


Measured memory_bytes: 14884
#include <queue>
#include <iostream>
#include <utility>

using namespace std;

int h,w,c,ans;

void dfs(int dep,int a[][8]){
	int x,y,dx[]={0,1,0,-1},dy[]={1,0,-1,0};
	if(dep==5){
		int t=1;
		if(c==a[0][0]){
			queue<pair<int,int> > q;
			q.push(make_pair(0,0));
			a[0][0]=-1;
			while(!q.empty()){
				x=q.front().first,y=q.front().second,q.pop();
				for(int i=0;i<4;i++){
					int nx=x+dx[i],ny=y+dy[i];
					if(nx<0||nx>=w||ny<0||ny>=h) continue;
					if(nx<0||nx>=w||ny<0||ny>=h||a[ny][nx]!=c) continue;
					t++;
					q.push(make_pair(nx,ny));
					a[ny][nx]=-1;
				}
			}
		}
		ans=max(ans,t);
		return;
	}
	int tmp[8][8];
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) tmp[i][j]=a[i][j];
	for(int col=1;col<=6;col++){
		if(a[0][0]==col) dfs(dep+1,a);
		else{
			int p = a[0][0];
			a[0][0]=col;
			queue<pair<int,int> > q;
			q.push(make_pair(0,0));
			while(!q.empty()){
				x=q.front().first,y=q.front().second,q.pop();
				for(int i=0;i<4;i++){
					int nx=x+dx[i],ny=y+dy[i];
					if(nx<0||nx>=w||ny<0||ny>=h||a[ny][nx]!=p) continue;
					q.push(make_pair(nx,ny));
					a[ny][nx]=col;
				}
			}
			dfs(dep+1,a);
		}
		for(int i=0;i<h;i++) for(int j=0;j<w;j++) a[i][j]=tmp[i][j];
		//memcpy(tmp,a,sizeof(a));
	}
	return;
}

int main(){
	int a[8][8];
	while(cin>>h>>w>>c,h||w||c){
		for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>a[i][j];
		ans=0;
		dfs(0,a);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 912
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include<unordered_map>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
#define all(x) x.begin(),x.end()
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        ll n, m, x;
        cin >> n >> m >> x;
        ll c[n];
        ll a[n][m];
        for(int i  =0; i < n; i++){
            cin >> c[i];
            for(int j = 0; j < m; j++){
                cin >> a[i][j];
            }
        }
        ll out = power1(10, 13);
        for(int i = 0; i < power1(2, n); i++){
            ll q = i;
            ll cnt[m] = {};
            ll st = 0;
            ll cost = 0;
            while(q){
                if(q%2){
                    cost += c[st];
                    for(int j = 0; j < m; j++){
                        cnt[j] += a[st][j];
                    }
                }
                q /= 2;
                st++;
            }
            bool f =true;
            for(int qw = 0;qw < m; qw++){
                if(cnt[qw] < x){
                    f = false;
                    break;
                }
            }
            if(f){
                out = min(out, cost);
            }
        }
        if(out == power1(10, 13)){
            cout << -1 << endl;
            return 0;
        }
        cout << out << endl;
    }
}


Measured memory_bytes: 3644
#include <stdio.h>
//#include <bits/stdc++.h>
int a[100001];
int b[100001][30];
int max_count = 0;
void two_sin(int i,int a_i)
{
	int count = 0;
	while(a_i != 0)
	{
		a_i = a_i /2 ;
		b[i][count] = a_i % 2;
		a_i = a_i / 2;
		count++;
		//if(count > max_count) max_count = count;
	}
}

int w(int N)
{
	int one_num = 0;
	int zero_num = 0;
	int ans = 0;
	for(int i = 0; i < 30 ; i++)
	{
		for(int j = 0; j < N ; j++){
			if(b[j][i] == 0) zero_num++;
			else one_num++;
		}
		if(one_num > 0){
			if(one_num == zero_num * 2)
			{
				ans  = 1;
			}
			else return 2;
		}
		else ans = 1;
		one_num = 0;
		zero_num = 0;
	}
	if(ans == 1) return 1;
}

int main(void)
{
	int N;
	scanf("%d",&N);
	int koko;
	int i = 0 ;
	for(i = 0; i < N; i++)
	{
		for(int j = 0; j < 100; j++)
		{
			b[i][j] = 0;
		}
	}
	for(i = 0; i < N; i++)
	{
		scanf("%d",&koko);
		a[i] = koko;
		two_sin(i,a[i]);
	}
	a[i+1] = a[0];
	
	int ans = w(N);
	if(ans == 1)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 12288
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
#import bisect
from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
#from collections import deque
from collections import defaultdict
# from collections import Counter
#from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())

class Dijkstra(object):
	"""
	ダイクストラ法（二分ヒープ）による最短経路探索
	計算量: O((E+V)logV)
	"""
	
	def __init__(self, graph, start):
		self.g = graph.graph
		
		# startノードからの最短距離
		# startノードは0, それ以外は無限大で初期化
		self.dist = defaultdict(lambda: float('inf'))
		self.dist[start] = 0
		
		# 最短経路での1つ前のノード
		self.prev = defaultdict(lambda: None)
		
		# startノードをキューに入れる
		self.Q = []
		heappush(self.Q, (self.dist[start], start))
		
		while self.Q:
			# 優先度（距離）が最小であるキューを取り出す
			dist_u, u = heappop(self.Q)
			if self.dist[u] < dist_u:
				continue
			for v, weight in self.g[u]:
				alt = dist_u + weight
				if self.dist[v] > alt:
					self.dist[v] = alt
					self.prev[v] = u
					heappush(self.Q, (alt, v))
	
	def shortest_distance(self, goal):
		"""
		startノードからgoalノードまでの最短距離
		"""
		return self.dist[goal]
	
	def shortest_path(self, goal):
		"""
		startノードからgoalノードまでの最短経路
		"""
		path = []
		node = goal
		while node is not None:
			path.append(node)
			node = self.prev[node]
		return path[::-1]


class Graph(object):
	"""
	隣接リストによる有向グラフ
	"""
	
	def __init__(self):
		self.graph = defaultdict(list)
	
	def __len__(self):
		return len(self.graph)
	
	def add_edge(self, src, dst, weight=1):
		self.graph[src].append((dst, weight))
	
	def get_nodes(self):
		return self.graph.keys()


def main():
	N=int(input())
	
	G=Graph()
	
	for i in range(N-1):
		u,v,w=map(int,input().split())
		u-=1
		v-=1
		
		G.add_edge(u,v,w)
		G.add_edge(v,u,w)
	
	D=Dijkstra(G,0)
	
	for i in range(N):
		print(D.shortest_distance(i)%2)
	
	
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 105948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, a[55], b[55], e[55][55]{};
    vector<int> ideg, odeg;
    bool ok = true;
    cin >> n;
    REP(i,n+1){
        cin >> a[i];
        REP(j,a[i])ideg.push_back(i);
    }
    REP(i,n+1){
        cin >> b[i];
        REP(j,b[i])odeg.push_back(i);
    }

    if(ideg.size()!=n || odeg.size()!=n) ok = false;
    else{
        reverse(ALL(odeg));
        vector<P> ls;
        REP(i,n) ls.push_back({ideg[i],i});

        // 残り入次数が多いものへ辺を張る
        REP(i,n){
            int cnt=0;
            SORT(ls);
            reverse(ALL(ls));
            REP(j,n){
                if(cnt==odeg[i])break;
                if(ls[j].first>0){
                    ls[j].first--;
                    e[i][ls[j].second] = 1;
                    cnt++;
                }
            }
            if(cnt!=odeg[i]){
                ok = false;
                break;
            }
        }
        // 入次数が余っているか
        SORT(ls);
        if(ls[n-1].first>0) ok = false;
    }
    if(ok){
        cout << "YES" << endl;
        REP(i,n)REP(j,n) cout << e[i][j] << " \n"[j==n-1];
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 3192
#include "bits/stdc++.h"
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
      cin >> a.at(i);
  }
    int now =0;
    int check =0;
    int put =0;
    while(1){
        check ++;
        if(a.at(now)==2){
            cout << check << endl;
            break;
        }
        else if(a.at(now) == -1){
            cout << -1 << endl;
            break;
        }
        else {
           
            put = a.at(now)-1; 
            a.at(now) = -1;
            now = put;
            
        }
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld\n",x) 
using namespace std;
const int N = 1e6+5;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
typedef long long ll;
ll inv(ll b)
{
	if(b == 1)
	return 1;
	return (mod-mod/b)*inv(mod%b)%mod;
}
ll fac[N];
ll C(ll n,ll m)
{
	ll t = (fac[m]*fac[n-m])%mod;
	return (fac[n]*inv(t))%mod;
}
ll ans[N][2];
int main()
{
	ll n,i,a,b,k;
	fac[0] = 1;
	fac[1] = 1;
	for(i = 2;i <= 3e5+5;i++)
	fac[i] = (fac[i-1]*i)%mod;
	sl(n);sl(a);sl(b);sl(k);
	ll cnt = 0;
	for(i = 0;i <= n;i++)
	{
		if(k-(i*a) >= 0 && (k-a*i)%b == 0 && (k-a*i)/b <= n)
		{
			ans[cnt][0] = i;
			ans[cnt++][1] = (k-a*i)/b;
		}
	}
	ll res=0;
	for(i = 0;i < cnt;i++)
	{
		res = (res+C(n,ans[i][0])*C(n,ans[i][1])%mod)%mod;
	}
	pl(res);
}


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 a, b, c;
    cin >> a >> b >> c;

    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
        cout << 0 << endl;
    } else {
        cout << min({ a * b, b * c, c * a }) << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

bool compareStr(string s1, string s2) {
	return s1 < s2;
}

void smallestLexico() {
	int* lengths = (int*)malloc(2 * sizeof(int));
	cin >>lengths[0]>>lengths[1];
	
	string allStrs[lengths[0]];
	
	for(int iL = 0; iL < lengths[0]; iL++) {
		cin >> allStrs[iL];
	}
	sort(allStrs, allStrs + lengths[0], compareStr);
	
	for(int i = 0; i < lengths[0]; i++)
		cout << allStrs[i];
}

int main() {
	smallestLexico();
	return 0;
}



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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<ll> b(n);
  for (ll i = 0; i < n; ++i) {
    cin >> b[i];
  }
  vector<ll> c(n);
  for (ll i = 0; i < n; ++i) {
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  sort(c.begin(), c.end());

  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    ll ac = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    ll cc = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    ans += ac*cc;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  string s;
  rep(i,0,4){
    string ss;
    cin>>ss;
    s+=ss;
  }
  sort(all(s));
  if(s=="1479"){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}

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

int main(){
  int n;
  cin>>n;
  int a[n];
  ll sum=0;
  REP(i,n){
    a[i]=0;
  }
  REP(i,n){
    if ((i+1)%5!=0&&(i+1)%3!=0)
    {
      /* code */
      sum+=(i+1);
    }
    
  }
   cout<<sum<<endl;
  }

Measured memory_bytes: 7480
n, a, b, c, d = list(map(int, input().split()))
if n%a == 0:
    ya = (n//a)*b
else:
    ya = ((n//a)+1)*b
if n%c == 0:
    yc = (n//c)*d
else:
    yc = ((n//c)+1)*d    
ans = min([ya, yc])
print(ans)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll allscore(int i, int d, vector<vector<int>>s, vector<vector<int>>t, vector<int>c) {
	ll res = 0;
	int fury = 0;
	for (int j = 0; j < d; j++) {
		if (t.at(i).at(j) == 1) {
			res += s.at(j).at(i);
			fury = 0;
		}
		else {
			fury++;
			res -= fury * c.at(i);
		}
	}
	return res;
}
ll fastscore(vector<int>bl,int date,int fury) {
	int l = -1;
	int r = bl.size();
	for (int i = date - 1; i >= 0; i--) {
		if (bl.at(i) == 1) {
			l = i;
			break;
		}
	}
	for (int i = date + 1; i < r; i++) {
		if (bl.at(i) == 1) {
			r = i;
			break;
		}
	}
	ll ans = (r - date) * (date - l) * fury;
	return ans;
}
vector<int>greedy(int d, vector<vector<int>>s) {
	vector<int>ans(d);
	for (int i = 0; i < d; i++) {
		int res = 0;
		int tmp = -1;
		for (int j = 0; j < 26; j++) {
			if (res < s.at(i).at(j)) {
				res = s.at(i).at(j);
				tmp = j;
			}
		}
		ans.at(i) = tmp;
	}
	return ans;
}
int main() {
	//input
	int d; cin >> d;
	vector<int>c(26);
	for (int i = 0; i < 26; i++)cin >> c.at(i);
	vector<vector<int>>s(d, vector<int>(26));
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < 26; j++)cin >> s.at(i).at(j);
	}
	vector<int>td = greedy(d, s);
	vector<vector<int>>t(26, vector<int>(d, 0));
	for (int i = 0; i < d; i++) {
		int x = td.at(i);
		t.at(x).at(i)++;
	}
	int m = 10000;
	vector<pair<int, int>>dq;
	for (int i = 0; i < m; i++) {
		int x = rand() % d;
		int y = rand() % 26;
		dq.push_back({ x, y });
	}
	//Q.B
	vector<int>sum(26,0);
	for (int i = 0; i < 26; i++) {
		sum.at(i) = allscore(i, d, s, t, c);
	}
	ll ans = 0;
	for (int i = 0; i < 26; i++)ans += sum.at(i);
	//Q.C
	for (int i = 0; i < m; i++) {
		int day = dq.at(i).first;
		int change = dq.at(i).second;
		if (t.at(change).at(day) == 1)continue;
		int before = td.at(day);

		//backup
		vector<vector<int>>tbu = t;
		vector<int>tdbu = td;
		//変更前と変更後について再計算、sumに反映
		t.at(before).at(day) = 0;
		t.at(change).at(day) = 1;
		td.at(day) = change;
		ll befs = fastscore(t.at(before), day, c.at(before)) + s.at(day).at(before);
		ll chgs = fastscore(t.at(change), day, c.at(change)) + s.at(day).at(change);
		if (-befs + chgs >= 0) {
			ans = ans - befs + chgs;
			sum.at(before) -= befs;
			sum.at(change) += chgs;
		}
		else{
			t = tbu;
			td = tdbu;
		}
	}
	for (int i = 0; i < d; i++)cout << td.at(i)+1 << endl;
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

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

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { 
        cin >> A[i];
    }
    sort(all(A));
    vector<ll> sum(N);
    sum[0] = A[0];
    rep(i, N-1) {
        sum[i+1] = sum[i] + A[i+1];
    }
    ll l = 0;
    ll r = N-1;
    while(r >= l) {
        ll mid = l + (r - l)/2;
        bool flag = true;
        for (ll i = mid; i < N-1; i++) {
            if (sum[i] * 2  < A[i+1]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    print(N-l);
    return 0;
} 

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

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
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 (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    ll score = 0;
    string m = "";
    map<char, char> t2m;
    map<char, int> m2score;
    t2m['r'] = 'p';
    t2m['p'] = 's';
    t2m['s'] = 'r';
    m2score['r'] = r;
    m2score['p'] = p;
    m2score['s'] = s;
    m2score['n'] = 0;

    rep(i, n)
    {
        if (i < k)
        {
            m += t2m[t[i]];
        }
        else{
            if(m[i-k]==t2m[t[i]]){
                m += 'n';
            }
            else{
                m+= t2m[t[i]];
            }
        }
    }

    rep(i,n){
        score += m2score[m[i]];
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b = 0, n, k;
string s, t;
//cout<<<<endl;


int main()
{
	int x, y;
	cin >> x >> y;
	int sum = 0;
	if (x < 4)
		sum += (4 - x) * 100000;
	if (y < 4)
		sum += (4 - y) * 100000;
	if (x == 1 && y == 1)
		sum += 400000;
	cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

long long bfs(long long num) {
	if (num / 10 == 0) {
		return num;
	}
	long long sum = num, t = 10;
	int len = log10(num) + 1;

	for (int i = 1; i < 10; i++) {
		if (num / t == 0) break;
		sum += bfs(num % t) + (num / t) * powl(2,i-1);
		t *= 10;
	}
	return sum;
}

int main() {
	long long s;

	std::cin >> s;

	std::cout << bfs(s) << std::endl;
	return 0;
}

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

int main(){
    cin >> n;
    stack<int> s;
    if ( n == 0 ) cout << 0;
    while( n!= 0){
        int x = n%(-2);
        n /= -2;
        if (x < 0){
            x += 2;
            n++;
        }
        s.push(x);
    }
    while(!s.empty()){
        cout << s.top();
        s.pop();
    }
}

Measured memory_bytes: 256