akhauriyash/Code-Regression huggingface dataset:
from collections import namedtuple

Point = namedtuple('Point', ('x', 'y'))

def sign (p1, p2, p3):
  return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);

while True:
  try:
    x = list(map(float, input().split()))
    p1 = Point(x[0], x[1])
    p2 = Point(x[2], x[3])
    p3 = Point(x[4], x[5])
    pp = Point(x[6], x[7])
    b1 = sign(pp, p1, p2) < 0.0
    b2 = sign(pp, p2, p3) < 0.0
    b3 = sign(pp, p3, p1) < 0.0
    if (b1 == b2) and(b2 == b3):
      print('YES')
    else:
      print('NO')
  except:
    break 



Measured memory_bytes: 5996
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
int h,w;
cin >>h >> w;
char z[h][w];
for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        cin >> z[i][j];
    }
}
int dx [4] ={1,-1,0,0};
int dy [4] = {0,0,1,-1};
for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        int chea = 0;
        for(int k=0;k<4;k++){
            int x = dx[k]+j,y=dy[k]+i;
            if(0>x||x>=w||0>y||y>=h||z[i][j]=='.')continue;
            if(z[i][j]=='#'&&z[y][x]=='#')chea++;
        }
        if(chea==0&&z[i][j]=='#'){cout<<"No"<<endl;return 0;}
    }
}
cout <<"Yes"<<endl;
}

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

int main(){
	int a[5];
	for(int i = 0; i<5; i++){
		cin >> a[i];
	}
	sort(a, a + 5);
	for(int i = 4; i>0; i--){
		cout << a[i] << " ";
	}
	cout << a[0] << endl;
	return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge{
	int to,cap,rev;
	edge(){}
	edge(int tt,int cc,int rr){
		to=tt;
		cap=cc;
		rev=rr;
	}
};


class dinic{
public:
	const int INF=1000000;
	vector<edge> G[10001];
	int level[10001];
	int iter[10001];
	void add_edge(int from,int to,int cap){
		G[from].push_back(edge(to,cap,G[to].size()));
		G[to].push_back(edge(from,0,G[from].size()-1));
	}

	void bfs(int s){
		memset(level,-1,sizeof(level));
		queue<int> que;
		level[s]=0;
		que.push(s);
		while(que.size()){
			int v=que.front();
			que.pop();
			for(int i=0;i<G[v].size();i++){
				edge &e=G[v][i];
				if(e.cap>0 && level[e.to]<0){
					level[e.to]=level[v]+1;
					que.push(e.to);
				}
			}
		}
	}

	int dfs(int v,int t,int f){
		if(v==t)return f;
		int res=0;
		for(int &i=iter[v];i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0 && level[v]<level[e.to]){
				int d=dfs(e.to,t,min(e.cap,f));
				if(d>0){
					e.cap-=d;
					G[e.to][e.rev].cap+=d;
					res+=d;
					f-=d;
					if(f==0)break;
				}
			}
		}
		return res;
	}

	int max_flow(int s,int t){
		int flow=0;
		while(1){
			bfs(s);
			if(level[t]<0)return flow;
			memset(iter,0,sizeof(iter));
			int f;
			while((f=dfs(s,t,INF))>0){
				flow+=f;
			}
		}
	}
};

int n,m;
int a[101][101];
int b[101][101];
int c[101][101];
dinic di;

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	int S=n*2,T=S+1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			int deg=(a[i][j]-1)/m;
			di.add_edge(i,n+deg,1);
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			di.add_edge(S,j,1);
			di.add_edge(n+j,T,1);
		}
		di.max_flow(S,T);
		for(int j=0;j<n;j++){
			for(int k=0;k<di.G[j].size();k++){
				edge &e=di.G[j][k];
				if(e.to==S){
					e.cap=-2;
				}else if(e.cap==0){
					e.cap=-2;
					di.G[e.to][e.rev].cap=-2;
					for(int l=0;l<m;l++){
						int deg=(a[j][l]-1)/m;
						if(deg==(e.to-n)){
							b[j][i]=a[j][l];
							a[j][l]=n*m+10000;
							break;
						}
					}
				}
			}
		}
		for(int j=0;j<di.G[T].size();j++){
			edge &e=di.G[T][j];
			e.cap=-2;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			printf("%d%c",b[i][j],(j+1)==m?'\n':' ');
			int deg=(b[i][j]-1)/m;
			c[deg][j]=b[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			printf("%d%c",c[i][j],(j+1)==m?'\n':' ');
		}
	}
	return 0;
}


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

int main(){
    ll a,b;
    cin>>a>>b;
    ll sum=0,ans=0;
    if(b==1){
        cout<<ans<<endl;
        return 0;
    }
    sum+=a;
    ans++;
    if(sum>=b){
        cout<<ans<<endl;
        return 0;
    }
    for(;;){
        sum+=a-1;
        ans++;
        if(sum>=b){
            cout<<ans<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <iomanip>
#include <set>

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

using namespace std;

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,n) for(int i=1,i##_len=(n);i<=i##_len;++i)
#define rrep(i,n) for(int i=((int)((n)-1));i>=0;--i)
#define rreps(i,n) for(int i=((int)(n));i>0;--i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end());

// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#define DUMPOUT cout
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef LOCAL_
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif

typedef long long int lli;
typedef pair<int, int> ii;
typedef priority_queue<int, vector<int>, greater<int> > heapq;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

// #define int long long int
signed main() {
    int A, B;
    cin >> A >> B;
    cout << max(A + B, max(A - B, A * B)) << endl;
    return 0;
}


Measured memory_bytes: 888
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
q = deque([])
L = ''
for i in range(len(s)):
    if s[i] == '0':
        q.append('0')
    elif s[i] == '1':
        q.append('1')
    else:
        if q:
            q.pop()
while q:
    L += q.popleft()
print(L)

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

int main()
{
  ll w, h; cin >> w >> h;
  ll x, y; cin >> x >> y;

  double ans = (double)w*h/2.0;
  int p = 0;
  if (w == 2*x && h == 2*y) p = 1;
  printf("%.10lf %d\n", ans, p);

  return 0;
}


Measured memory_bytes: 256
n,m,x = map(int,input().split())
books = list(list(map(int,input().split())) for i in range(n))
mon_lis = []
for i in range(2**n):
    mon = 0
    exp = [0]*m
    check=[0]*m
    for j in range(n):
        if (i >> j) & 1:
            mon += books[j][0]
            for k in range(m):
                exp[k] += books[j][k+1]
    for k in range(m):
        if exp[k] >= x:
            check[k] = 1
    if not 0 in check:
        mon_lis.append(mon)
if not mon_lis:
    print(-1)
else:
    print(min(mon_lis))

Measured memory_bytes: 9240
#![allow(unused_mut, non_snake_case,unused_imports)]
use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::{swap};
use std::collections::{HashMap,BTreeMap,HashSet,BTreeSet,BinaryHeap,VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


fn main(){
    input!(n:i64,k:i64);
    if n > k {
        println!("0");
    }else{
        println!("1");
    }
}


Measured memory_bytes: 5024
import itertools as it
h, w, k = map(int, input().split())

c = [list(input()) for _ in range(h)]

hprols = list(it.product(range(2), repeat=h))
wprols = list(it.product(range(2), repeat=w))

ans = 0


for hpro in hprols:
    for wpro in wprols:
        tmpk = 0
        for i in range(len(hpro)):
            for j in range(len(wpro)):
                if hpro[i] == 0:
                    if wpro[j] == 0:
                        if c[i][j] == "#":
                            tmpk += 1
        if tmpk == k:
            ans += 1
            
print(ans)


Measured memory_bytes: 9204
#include <iostream>

using namespace std;

int main(){
    int h,w,n,tmp,count = 0;

    cin >> h >> w >> n;

    if(h < w)
        tmp = w;
    else
        tmp = h;
    

    while(n > 0){
        count++;
        n -= tmp;
    }

    cout << count << endl;
}

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

int main (void){

  int a,b,c,d;
  double e,f,g;
  scanf("%d%d",&a,&b);
  if(1<=a<1000000000 && 1<=b<=1000000000){
  c=a/b;
  d=a%b;

  g=(double)a/b;
  }
  printf("%d %d %f\n",c,d,g);
  
  return(0);
}



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

int main() {
	int A, B, C;


	cin >> A >> B >> C;
	int max_time = B / A;

	if (max_time > C) {
		cout << C << endl;
	}
	else {
		cout << max_time << endl;

	}


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    cout << max(max(a+b,a-b),a*b) << endl;
    
    return 0;
}


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

using namespace std;

typedef long long llint;

int h, w, n;
int dx[9] = {0, -1, -1, -1, 0, 1, 1, 1, 0};
int dy[9] = {0, -1, 0, 1, 1, 1, 0, -1, -1};
set < pair <int, int> > st, kand;
llint cnt[10], sum;

bool ok (int x, int y) {
    return x >= 2 && x <= h - 1 && y >= 2 && y <= w - 1;
}

int f (int x, int y) {
    int res = 0;
    for (int i = 0; i < 9; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (st.find({nx, ny}) != st.end()) res++;
    }
    return res;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w >> n;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        st.insert({x, y});
        for (int j = 0; j < 9; j++) {
            int nx = x + dx[j];
            int ny = y + dy[j];
            if (ok(nx, ny)) kand.insert({nx, ny});
        }
    }
    for (auto par : kand) {
        cnt[f(par.first, par.second)]++;
    }
    for (int i = 1; i <= 9; i++) {
        sum += cnt[i];
    }
    cnt[0] = (llint) (h - 2) * (w - 2) - sum;
    for (int i = 0; i <= 9; i++) {
        cout << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 47232
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int main() {
  string str;
  while (cin >> str) {
    int ans = 0;
    int head = str.length() - 1;
    int tail = 0;
    while (head >= tail) {
      if (head == tail) {
        if (str[head] != 'i' && str[head] != 'w') { ans++; }
      } else {
        if (str[head] == 'w' && str[tail] == 'w') {;}
        else if (str[head] == 'i' && str[tail] == 'i') {;}
        else if (str[head] == '(' && str[tail] == ')') {;}
        else if (str[head] == ')' && str[tail] == '(') {;}
        else { ans++; }
      }
      head--;
      tail++;
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 079
	// https://atcoder.jp/contests/abc079/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String s = sc.next();
		s = s.substring(0, 3) + "8" + s.substring(4);
		System.out.println(s);
	}

	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


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

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

            var aaa = Console.ReadLine().Split(' ');
            var n = int.Parse(aaa[0]);
            var q = int.Parse(aaa[1]);
            var str = Console.ReadLine();
            var s = new int[n];
            

            for(var i=0; i+1<n; ++i)
            {
                if (str[i].ToString() == "A" && str[i + 1].ToString() == "C")
                {
                    if(i == 0)
                    {
                        s[i + 1] = 0 + 1;
                    }
                    else
                    {
                        s[i + 1] = s[i] + 1;
                    }

                }
                else
                {
                    s[i + 1] = s[i];
                }
            }

            var ans = new List<int>();

            for(var i=0; i<q; ++i)
            {
                var qua = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                var anan = s[qua[1] - 1] - s[qua[0] - 1];

                ans.Add(anan);
            }

            foreach (var ch in ans)
            {
                Console.WriteLine(ch);
            }
        }
    }
}


Measured memory_bytes: 17472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define INF INT_MAX
#define INFLL _I64_MAX
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
int main(void)
{
	int n, ans;

	cin>>n;

	n--;

	vector<int> c(n), s(n), f(n);

	rep(i, n){
		cin>>c[i]>>s[i]>>f[i];
	}

	rep(i, n){
		ans=s[i];
		repr(j, i, n){
			if(ans<s[j]){
				ans=s[j];
			}else if(ans%f[j]!=0){
				ans+=(f[j]-ans%f[j]);
			}
			ans+=c[j];
		}
		cout<<ans<<endl;
	}
	cout<<0<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#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 = uint32_t;
using namespace std;

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

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){
    size_t n=G.size();
    vector<T> d(n, INF<T>);
    priority_queue<pair<T, int>,vector<pair<T, int>>,greater<>> Q;
    d[s]=0;
    Q.emplace(0,s);
    while(!Q.empty()){
        T cost; int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}

int main() {
    int n, m, k, s, p, q;
    cin >> n >> m >> k >> s >> p >> q;
    vector<vector<int>> G(n);
    queue<int> Q;
    vector<int> dist(n, INF<int>);
    for (int i = 0; i < k; ++i) {
        int x;
        scanf("%d", &x);
        x--;
        dist[x] = 0;
        Q.emplace(x);
    }
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    while(!Q.empty()){
        int i = Q.front(); Q.pop();
        for (auto &&j : G[i]) {
            if(dist[j] > dist[i]+1){
                Q.emplace(j);
                dist[j] = dist[i]+1;
            }
        }
    }
    vector<vector<edge<ll>>> G2(n);
    for (int i = 0; i < n; ++i) {
        for (auto &&j : G[i]) {
            if(!dist[j]) continue;
            if(j == n-1) G2[i].emplace_back(j, 0);
            else if(dist[j] <= s) G2[i].emplace_back(j, q);
            else  G2[i].emplace_back(j, p);
        }
    }
    auto ans = dijkstra(0, G2);
    cout << ans.back() << "\n";
    return 0;
}


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

int main(){
    int n,k;cin >> n >> k;
	vector<int> pl;
	vector<int> mi;
	for(int i=0;i<n;++i){
		int x;
		cin >> x;
		if(x>=0) pl.push_back(x);
		else mi.push_back(abs(x));
	}
	reverse(mi.begin(),mi.end());
	int ans;
	if(pl.size()>k-1) ans=pl.at(k-1);
	else ans=2000000000;
	if(pl.size()==0) ans=mi.at(k-1);
	else{
		for(int i=0;i<mi.size();++i){
			if(pl.size()>k-i-2 && k-i-2>=0){
				ans=min(ans,mi.at(i)*2+pl.at(k-i-2));
				ans=min(ans,mi.at(i)+pl.at(k-i-2)*2);
			}
		}
	}
	if(mi.size()>k-1) ans=min(ans,mi.at(k-1));
	cout << ans << endl;
}

Measured memory_bytes: 1020
import java.util.*

/**
 * Created by Shadab on 26-Nov-17.
 */
fun main(args: Array<String>){

    //Generating Lucas numbers array.
    var lucas: Array<Long?> = kotlin.arrayOfNulls<Long>(87)

    lucas.set(0, 2)
    lucas.set(1, 1)

    for (i in 2..86) {
        var total = lucas.get(i - 1) as Long + lucas.get(i - 2) as Long
        lucas.set(i, total)
    }

    //taking user input for Lucas number position
    var sc =  Scanner(System.`in`)

    while(sc.hasNext()) {

        var n = sc.nextInt();
        println(lucas.get(n))
    }

}


Measured memory_bytes: 31256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String msg = "Good";

		for (int i = 0; i < 3; i++) {
			if (s.substring(i, i + 1).equals(s.substring(i + 1, i + 2))) {
				msg = "Bad";
			}
		}

		System.out.println(msg);

	}
}


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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

bool board[111][111];

int main() {
	rep(i,111)rep(j,111)board[i][j]=true;
	li w,h;
	li n;
	cin>>w>>h>>n;
	li xmi=0, ymi=0, xma=w, yma=h;
	rin{
		li x,y,a;
		cin>>x>>y>>a;
		if(a==1){
			xmi=max(x,xmi);
		}else if(a==2){
			xma=min(xma,x);
		}else if(a==3){
			ymi=max(y,ymi);
		}else {
			yma=min(yma,y);
		}
	}
	//p4(xma,xmi,yma,ymi);
	if(xma-xmi<=0 || yma-ymi<=0){
		cout<<0<<endl;
		return 0;
	}
	cout<<max((xma-xmi)*(yma-ymi),0ll)<<endl;


	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    string s;
    cin >> s;
    deque<char> dq;
    for (int i = 0; i < (int)s.length(); i++) {
        dq.push_back(s[i]);
    }
    int type = 0;
    int Q;
    scanf("%d", &Q);
    while (Q--) {
        int T;
        scanf("%d", &T);
        if (T == 1) type ^= 1;
        else {
            int F;
            char c;
            scanf("%d %c", &F, &c);
            F--;
            if (F ^ type) dq.push_back(c);
            else dq.push_front(c);
        }
    }
    if (type) reverse(dq.begin(), dq.end());
    for (auto i : dq) printf("%c", i);
    puts("");

    return 0;
}


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

void push(int);
int pop(void);

int top,S[1000];

int main()
{
  int a=0,b=0,i,j;
  top = 0;
  char s[100];

while(1)
  {

    if((scanf("%s",s))==EOF)break;

    if(s[0]=='+')
    {
      a = pop();
      b = pop();
      push(a + b);
    }

    else if(s[0]=='-')
    {
      a = pop();
      b = pop();
      push(b - a);
    }

    else if(s[0]=='*')
    {
      a = pop();
      b = pop();
      push(a * b);
    }

    else push(atoi(s));

  }
  printf("%d\n",pop());
  return 0;
}

void push(int x)
{
 top=top+1;
 S[top] = x;
}

int pop()
{
  top=top-1;
  return S[top+1];
}



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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll N;
  scanf("%lld", &N);

  vector<ll> list;
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    list.emplace_back(v);
  }

  ll ans = 0;

  if (N <= 2) {
    cout << (0) << endl;
    return 0;
  }

  for (ll i1 = 0; i1 < N - 2; i1++) {
    for (ll i2 = i1 + 1; i2 < N - 1; i2++) {
      for (ll i3 = i2 + 1; i3 < N; i3++) {
        //
        ll l1 = list[i1];
        ll l2 = list[i2];
        ll l3 = list[i3];

        bool invalid = (l1 == l2 || l2 == l3 || l1 == l3);

        if (!invalid) {
          ll m = max(max(l1, l2), l3);

          if (m == l1 && l1 < l2 + l3) {
            ans++;
          } else if (m == l2 && l2 < l1 + l3) {
            ans++;
          } else if (m == l3 && l3 < l1 + l2) {
            ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x,y;
	cin >> x>> y;
    string ans;
    if((x+11)%13>(y+11)%13)ans="Alice";
    else if((x+11)%13<(y+11)%13)ans="Bob";
    else ans="Draw";
      cout << ans << endl;
}

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

int main(){
    ll n;
    cin >> n;
    vector<ll> x(n), y(n);
    rep(i, 0, n) cin >> x[i] >> y[i];
    int array[n];
    rep(i, 0, n) array[i] = i;
    double sum = 0;
    do{
        for(int i=0; i<n-1; i++){
            ll nxt = array[i+1];
            ll cur = array[i];
            double dx = x[nxt] - x[cur];
            double dy = y[nxt] - y[cur];
            sum += sqrt(dx * dx + dy * dy);
        }
    }while(next_permutation(array,array+n));
    double div = 1;
    rep(i, 1, n+1) div *= i;
    printf("%.20lf\n", sum/div);
    return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const ll INF=1000000000000001;
const double PI=3.141592653589;

int main(){
  int n; cin>>n;
  if(n<1000)
  cout<<"ABC"<<endl;
  else
  cout<<"ABD"<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  if(S=="SUN")
  {
    cout << 7 << endl;
    return 0;
  }
  vector<string> day(7);
  day = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
  rep(i,7)
  {
    if(S==day[i])
    {
      cout << 6-i << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
/*
      author  : nishi5451
      created : 15.08.2020 13:38:22
*/

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


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i=0; i<n-2; i++){
        if(s.substr(i,3)=="ABC") ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;


int n, M[MAX][MAX];

int prim()
{
    int u, minv;
    int d[MAX], p[MAX], color[MAX];
    int i;

    for (i = 0; i < n; i++) {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    d[0] = 0;

    while (1) {
        minv = INFTY;
        u = -1;
        for (i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) break;;
        color[u] = BLACK;

        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                if (d[v] > M[u][v]) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }

    int sum = 0;
    for (i = 0; i < n; i++) {
        if (p[i] != -1) sum += M[i][p[i]];
    }

    return sum;
}

int main()
{
    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int e; cin >> e;
            M[i][j] = (e == -1) ? INFTY : e;
        }
    }

    cout << prim() << endl;

    return 0;
}


Measured memory_bytes: 3128
N = int(input())
L = list(map(int,input().split()))
L.insert(0,0)
L.append(0)
sum = 0
for i in range (0,N+1):
	sum += abs(L[i] - L[i+1])
for i in range (1,N+1):
	a = sum
	a -= abs(L[i] - L[i-1])
	a -= abs(L[i] - L[i+1])
	a += abs(L[i+1] - L[i-1])
	print(a)

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

int main() {
  ll N;
  cin >> N;
  vector<string> lis(N);
  for (ll i = 0; i < N; i++) {
    cin >> lis[i];
    sort(lis[i].begin(),lis[i].end());
  }
  sort(lis.begin(),lis.end());
  ll anag = 0;
  ll k = 0;
  for (ll i = 1; i < N; i++) {
    if (lis[i-1] == lis[i]) {
      k += 1;
    }
    else {
      anag += k*(k+1)/2;
      k = 0;
    }
  }
  anag += k*(k+1)/2;
  cout << anag << endl;
}

Measured memory_bytes: 7296
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

ll setnum(ll n)
{
	switch (n) {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		return 1;
	case 4:
	case 6:
	case 9:
	case 11:
		return 2;
	case 2:
		return 3;
	}
}
int main()
{
	ll x = in(), y = in();
	cout << (setnum(x) == setnum(y) ? "Yes" : "No") << endl;
}

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

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

Measured memory_bytes: 256
pub fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let n: usize = buf.trim().parse().unwrap();
    use std::collections::HashSet;
    let mut set: HashSet<u64> = HashSet::with_capacity(n);
    buf.clear();
    std::io::stdin().read_line(&mut buf).unwrap();
    for w in buf.split_whitespace() {
        let a: u64 = w.parse().unwrap();
        if !set.insert(a) {
            println!("NO");
            return;
        }
    }
    println!("YES");
}

Measured memory_bytes: 10492
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main()
{
  int H[1000], W[1000];
  int i, j, k, l, num1=1, num2=1;
  H[0]=-1;
  W[0]=-1;
  while(H[num1-1] != 0 && W[num1-1] != 0){
    cin >>H[num1];
    cin >>W[num1];
    num1=num1+1;
  }

  while(H[num2] != 0 && W[num2] != 0){
      for(k=0;k<W[num2];k++){
        cout <<"#" ;
      }
      cout <<endl;
      for(i=0;i<H[num2]-2;i++){
        cout <<"#";
        for(j=0;j<W[num2]-2;j++){
          cout <<"." ;
        }
        cout <<"#" <<endl;
      }
      for(l=0;l<W[num2];l++){
        cout <<"#";
      }
      cout <<endl;
      cout <<endl;
      num2++;
  }
}

Measured memory_bytes: 1156
import java.util.*;
 class Main{

     public static void main(String []args){
      Scanner scan = new Scanner(System.in);
      String m = Integer.toString(scan.nextInt()) ;
      String n = Integer.toString(scan.nextInt()) ;
      int x = Integer.parseInt(m+n) ;
      
      if((Math.sqrt(x) - (int)Math.sqrt(x)) == 0){
          System.out.println("Yes");
      }else{
          System.out.println("No");
      }
      
    }
}

Measured memory_bytes: 22484
#import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#MOD = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n,x,m=INTM()
    bool=[False]*m
    mod=[]
    temp=x
    for i in range(m+1):
        if bool[temp]:
            break
        else:
            bool[temp]=True
            mod.append(temp)
            temp=(temp*temp)%m
    b=mod.index(temp)
    if b>0:
        sumt=sum(mod[0:b])
        mod=mod[b:]
    else:
        sumt=0
    lm=len(mod)
    sumr=0
    if (n-b)%lm!=0:
        sumr=sum(mod[0:(n-b)%lm])
    print(sumt+sumr+sum(mod)*((n-b)//lm))

if __name__=='__main__':
    do()

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

int main(){
  int a,b,c,d;cin >> a >> b >> c >> d;
  int l=a+b,r=c+d;
  if(l == r)cout <<"Balanced";
  else if(l>r)cout << "Left";
  else cout << "Right";
}

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

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> an(n);
  int total = 0;
  for (auto& ai : an) {
    cin >> ai;
    total ^= ai;
  }
  for (auto ai : an) {
    ai ^= total;
    cout << ai << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 4044
#include <stdio.h>
int main()
{
    long long a,b,c;
    char ch,ch1;
    scanf("%lld",&a);
    scanf("%c",&ch1);
    scanf("%c",&ch);
    scanf("%lld",&b);
    if(ch == '+') {
        c = a + b ;
        printf("%lld\n",c);
    }
    else printf("%lld\n",a-b);
    return 0;
}

Measured memory_bytes: 128
loop do
  map = []
  x, y, count = 0, 0, 0
  h, m = gets.split.map(&:to_i)
  break if h == 0 && m == 0
  
  h.times do
    t = []
    gets.chomp.chars {|c| t << c}
    map << t
  end
  
  while count < h * m
    case map[y][x]
    when '>'
      x += 1
    when '<'
      x -= 1
    when '^'
      y -= 1
    when 'v'
      y += 1
    else
      break
    end
    count += 1
  end

  puts count < h * m ? "#{x} #{y}" : 'LOOP'
end

Measured memory_bytes: 3888
N = int(input())
S = list(input())
E = [0]*N
W = [0]*N
ans = 10000*10000
for i in range(N-1):
    if S[i] == 'W':
        W[i+1] += W[i] + 1
    else:
        W[i+1] = W[i]
for i in range(N)[:0:-1]:
    if S[i] == 'E':
        E[i-1] += E[i] + 1
    else:
        E[i-1] = E[i]
for i in range(N):
    ans = min(ans,E[i]+W[i])
print(ans)

Measured memory_bytes: 19916
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 414514
int n;
vector<int> dat[MAX*2-1];
 
int query(int a,int b,int u,int d,int k=0,int l=0,int r=n){
  //cout<<a<<" "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
  if(r<=a||b<=l) return 0;
  if(a<=l&&r<=b) {
    //cout<<a<<" "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
    return upper_bound(dat[k].begin(),dat[k].end(),u)
      -lower_bound(dat[k].begin(),dat[k].end(),d);
  }
  return query(a,b,u,d,k*2+1,l,(l+r)/2)+query(a,b,u,d,k*2+2,(l+r)/2,r);
}
 
int x[MAX],l[MAX],r[MAX],e[MAX];
 
signed main(){
  int d,q;
  cin>>d;
  vector<int> v;
  for(int i=0;i<d;i++){
    cin>>x[i];
    v.push_back(x[i]);
  }
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>l[i]>>r[i]>>e[i];
    l[i]--;
    v.push_back(min(x[l[i]],x[r[i]-1])-e[i]);
    v.push_back(max(x[l[i]],x[r[i]-1])+e[i]);
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  map<int,int> m;
  for(int i=0;i<(int)v.size();i++) m[v[i]]=i;
   
  n=1;
  while(n<d) n*=2;
  //cout<<n<<endl;
   
  for(int i=0;i<d;i++){
    dat[n-1+i].push_back(m[x[i]]);
  }
   
  for(int i=n-2;i>=0;i--){
    for(int k=1;k<=2;k++){
      for(int j=0;j<(int)dat[i*2+k].size();j++)
    dat[i].push_back(dat[i*2+k][j]);
    }
    sort(dat[i].begin(),dat[i].end());
  }
  /*//
  for(int i=0;i<n*2-1;i++){
    cout<<i<<"-"<<endl;
    for(int j=0;j<(int)dat[i].size();j++){
      cout<<dat[i][j]<<" ";
    }
    cout<<endl;
  }
  //*/
  for(int i=0;i<q;i++){
    //cout<<r[i]-l[i]<<endl;
    int inner=query(l[i],r[i],
            m[max(x[l[i]],x[r[i]-1])+e[i]],
            m[min(x[l[i]],x[r[i]-1])-e[i]]);
    int outer=query(l[i],r[i],v.size(),0);
    //cout<<outer<<":"<<inner<<endl;
    cout<<outer-inner<<endl;
  }
   
  return 0;
}

Measured memory_bytes: 65596
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
using namespace std;

int main()
{
	int a[3];
	for(int i=0;i<3;i++){
		scanf("%d",&a[i]);
	} 
	sort(a,a+3);
	if(a[0]+a[1]==a[2]){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
}

Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())

X = I()
A = [1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1000]
for i in range(40,-1,-1):
    if A[i] <= X:
        print(A[i])
        exit()


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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	int n;
	cin >> n;
	int kol = 0;
	forn(i, n) {
		int a;
		cin >> a;
		if (a & 1) {
			kol++;
		}
	}
	if ((kol & 1) && n > 1) {
		puts("NO");
	} else {
		puts("YES");
	}
	return 0;
}


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

using namespace std;

int main()
{
    long long int t,n,x,flag,temp,i,j,sum=0;
   cin>>n;
   for(i=1;i<=n;i++)
   {
       if(i%3==0 || i%5==0)
       {
           
       }
       else
        sum+=i;
   }
    cout<<sum;
    
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    S = input()
    X = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

    for i in range(len(X)):
        if S == X[i]:
            print(7-i)






if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long ll;

const ll MAX = 4000010;
const ll MOD = 1e9 + 7;
long long fac[MAX], finv[MAX], inv[MAX];
 
 
void COMinit() {
 fac[0] = fac[1] = 1;
 finv[0] = finv[1] = 1;
 inv[1] = 1;
  for (ll i = 2; i < MAX; i++){
  fac[i] = fac[i - 1] * i % MOD;
  inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
       finv[i] = finv[i - 1] * inv[i] % MOD;
        }
      }
 
   long long COM(ll n, ll k){
  if (n < k){ return 0;}
  if (n < 0 || k < 0) {return 0;}
     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
     }
 






int main(){
int H,W,A,B; cin >> H >> W >> A >> B;
  
  COMinit();
  
  long long ans = 0;
  
  for(int j = B ; j < W; j++){
    ans += COM( H - A + j -1 , j ) * COM( A + W - j - 2 ,A - 1);
    
    
    ans %= MOD; }
  
  cout << ans << endl; return 0;}

Measured memory_bytes: 93952
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

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

  string s;
  int k;
  cin >> s >> k;

  set<string> stringSet;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j <= s.size(); j++) {
      string str = s.substr(j, i);
      if (str.size() != i) {
        break;
      }
      stringSet.insert(str);
    }
  }

  auto itr = stringSet.begin();
  for (int i = 1; i < k; i++) {
    itr++;
  }

  cout << *itr << endl;
}

Measured memory_bytes: 1664
<?php

// Dice1
$input = trim(fgets(STDIN));
$labels = explode(" ", $input);
$dice1 = new Dice($labels);

// Dice2
$input = trim(fgets(STDIN));
$labels = explode(" ", $input);
$dice2 = new Dice($labels);

$dice1_top = $dice1->getLabel("T");

$ans = "No";
$check_dirs = "NWSSSW";
foreach (str_split($check_dirs) as $dir)
{
  $dice2->roll($dir);
  $dice2_top = $dice2->getLabel("T");
  if ($dice1_top == $dice2_top) {
    for ($i = 0; $i < 4; $i++) {
      if ($dice1->isEqual($dice2)) {
        $ans = "Yes";
        break;
      }
      $dice2->roll("R");
    }
  }

  if ($ans === "Yes") {
    break;
  }
}

echo "${ans}" . PHP_EOL;

//========================================

class Dice
{
  private $labels;
  private $IDX_ROLL = array(
    array(4, 0, 2, 3, 5, 1),  // -> S
    array(3, 1, 0, 5, 4, 2),  // -> E
    array(2, 1, 5, 0, 4, 3),  // -> W
    array(1, 5, 2, 3, 0, 4),  // -> N
    array(0, 3, 1, 4, 2, 5),  // -> sidespin : right
    array(0, 2, 4, 1, 3, 5)   // -> sidespin : left
  );

  public function __construct($labels)
  {
    $this->labels = $labels;
  }

  public function roll($dirs)
  {
    foreach (str_split($dirs) as $dir) {
      $idx = strpos("SEWNRL", $dir);
      if ($idx === false) {
        continue;
      }

      $old = $this->labels;
      for ($i = 0; $i < 6; $i++) {
        $this->labels[$i] = $old[$this->IDX_ROLL[$idx][$i]];
      }
    }
  }

  public function isEqual($dice) {
    return ($this->labels == $dice->getLabels());
  }

  public function getLabel($dir) {
    $idx = strpos("TSEWNB", $dir);
    if ($idx !== false) {
      return $this->labels[$idx];
    }
    return false;
  }

  public function getLabels() {
    return $this->labels;
  }

  public function getDirection($number) {
    $idx = array_search($number, $this->labels);
    if ($idx !== false) {
      return "TSEWNB"[$idx];
    }
    return false;
  }
}

Measured memory_bytes: 15588
#include <stdio.h>

int main(){
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(a==1){
		if(b==1){
			puts("Open");
		}else{
			puts("Close");
		}
	}else{
		if(c==1){
			puts("Open");
		}else{
			puts("Close");
		}
	}
	return 0;
}

Measured memory_bytes: 584