akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char 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;}

int main() {
  int n, m;
  cin >> n >> m;
  string a[n], b[m];
  rep (i, n) {
    cin >> a[i];
  }
  rep (i, m) {
    cin >> b[i];
  }


  rep (i, n - m + 1) {
    rep (j, n - m + 1) {
      // cout << i << ", " << j << endl;
      int flag = 1;
      rep (k, m) {
        rep (l, m) {
          if (a[i + k][j + l] != b[k][l]) {
            flag = 0;
            break;
          }
        }
        if (flag == 0) break;
      }
      if (flag == 0) continue;
      Yes;
      return 0;
    }
  }
  No;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin>>N;
    cin>>S;
}
//=============================
void func(){}
//=============================
void solve()
{
    cout<<(N>=3200 ? S : "red")<<endl;

}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
from math import atan2, pi, sqrt
n = int(input())
p = []
xa = ya = 0
for i in range(n):
    x, y = map(int, input().split())
    angle = atan2(y, x)
    p.append((x, y, angle))
    p.append((x, y, angle + 2 * pi))
    xa += x
    ya += y

p.sort(key=lambda x: x[2])

r = 0
ans = 0
xs = ys = 0
for l in range(n):
    while p[r][2] < p[l][2] + pi:
        xs += p[r][0]
        ys += p[r][1]
        r += 1

    ans = max(ans, sqrt(xs**2 + ys**2), sqrt((xa - xs)**2 + (ya - ys)**2))

    xs -= p[l][0]
    ys -= p[l][1]

print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	int n;
	double ax, ay, bx, by, cx, cy, dx, dy;

	cin >> n;

	for ( int i = 0; i < n; i++ )
	{
		cin >> ax >> ay >> bx >> by >> cx >> cy >> dx >> dy;
		if ( ( by - ay ) / ( bx - ax ) == ( dy - cy ) / ( dx - cx ) )
		{
			cout << "YES";
		}
		else
		{
			cout << "NO";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int K, X;

	cin >> K >> X;
	for (int i = max(-1000000, X-K+1); i < X+K; i++)
	{
		cout << i << " ";
	}
	cout << endl;
}



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

int main()
{
    long long int n,a,b;
    cin>>n;
    cin>>a;
    cin>>b;
    if(n==1)
    {
        if(a==b)
        {
            cout<<"1"<<endl;
        }
        else
        {
            cout<<"0"<<endl;
        }

    }
    else if(a>b)
    {
        cout<<"0"<<endl;
    }
    else
    {
        long long int x=n-2;
        long long int y=(b-a);
        long long int res=y*x+1;

        cout<<res<<endl;
    }



}


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

int main() {
  bool a[256]={};
  string s;
  cin >> s;
  for ( char c:s ) {
    if ( a[c] ) {
      puts("no");
      return 0;
    }
    a[c]=1;
  }
  puts("yes");
  return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        bool unbalance = false;

        if (s[0] == s[1])
        { Console.WriteLine("1 2");
            return;
        }

        for (int i = 0; i < s.Length - 2 && !unbalance ; i++)
        {
            if (s[i] == s[i + 1] || s[i] == s[i + 2])
            {
                Console.WriteLine("{0} {1}",i+1,i+3);
                unbalance = true;
                break;
            }
        }
        if(!unbalance) Console.WriteLine("-1 -1");
    }

}


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

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

    if ((a+b)%2 ==0) {
        c=(a+b)/2;        
    } 
    else {
        c=(a+b)/2+1;
    }
    
    cout << c << endl;
}


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

int main(){
  int n;
  cin >> n;
  int k = 0,m = 0;
  k = n/100;
  m = n%100;
  if(k == 0 || k > 12){//上位2桁がMMでなければここに入る
    if(m == 0 || m > 12){//下位2桁がMMでなければここに入る
      cout << "NA" << endl;
    }
    else{
      cout << "YYMM" << endl;
    }
  }
  else if(m == 0 || m > 12){
    cout << "MMYY" << endl;
  }
  else{
    cout << "AMBIGUOUS" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100005
#define ll long long
using namespace std;
inline ll read(){
	ll x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
struct edge{
	int to,next;
}e[maxn<<1];
int last[maxn],cnt;
inline void insert(int x,int y){
	e[++cnt].to=y;e[cnt].next=last[x];last[x]=cnt;
}
int fa[maxn],dep[maxn],d[maxn];
void dfs(int x){
	for(int j=last[x];j;j=e[j].next){
		int y=e[j].to;dep[y]=max(dep[y],dep[x]+1);
		d[y]--;if(!d[y])dfs(y);
	}
}
void work(int x){
	for(int j=last[x];j;j=e[j].next){
		int y=e[j].to;if(dep[y]==dep[x]+1)fa[y]=x,work(y);
	}
}
int n,m;
int main(){
	n=read();m=read();
	for(int i=1;i<n+m;i++){
		int x=read(),y=read();
		d[y]++;insert(x,y);
	}int rt=0;dep[rt]=0;
	for(int i=1;i<=n;i++)if(!d[i]){rt=i;break;}
	dfs(rt);work(rt);
	for(int i=1;i<=n;i++)printf("%d\n",fa[i]);return 0;
}

Measured memory_bytes: 6272
import java.util.Scanner;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[] x = new int[m];
		for (int i = 0; i < m; i++)
			x[i] = in.nextInt();

		if (n >= m)
			System.out.println(0);
		else {
			Arrays.sort(x);
			int[] d = new int[m - 1];
			
			for (int i = 0; i < m - 1; i++)
				d[i] = x[i + 1] - x[i];
			
			Arrays.sort(d);
			int ans = 0;
			
			for (int i = 0; i < m - n; i++)
				ans += d[i];
			
			System.out.println(ans);
		}

	}

}

Measured memory_bytes: 49200
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, answer = INT_MAX;
  cin >> N;
  for (int i = 1; 1ll*i*i <= N; i++) {
    if (!(N%i)) {
      answer = min(answer,(long long)max(to_string(i).length(),to_string(N/i).length()));
    }
  }
  cout << answer;
}

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

using namespace std;

int main() {
	int N;
	cin >> N ;
	map<int, int>map;
	for (int n = 0;n < N;++n) {
		int Num;
		cin >> Num;
		++map[Num];
	}
	cout << map.size() << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main() {
	int n;
	string s;
	cin >> n >> s;
	vector<int> e(n,0);
	vector<int> w(n,0);
	REP(i,n){
		if(s[i]=='E'){
			e[i]++;
		}
		if(i!=0){
			e[i]+=e[i-1];
		}
	}
	IREP(i,n){
		if(s[i]=='W'){
			w[i]++;
		}
		if(i!=n-1){
			w[i]+=w[i+1];
		}
	}
	int min=0;
	REP(i,n){
		int now;
		if(i==0){
			now=w[i+1];
		}
		else if(i==n-1){
			now=e[i-1];
		}
		else{
			now=w[i+1]+e[i-1];
		}
		if(now>min){
			min = now;
		}
	}
	cout << n-1-min << endl;
}

Measured memory_bytes: 5380
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define REP(i, n) for(int i = 0; i < n; i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
typedef long long ll;

int dsc(const void *a, const void *b){
  ll A = *(ll *)a, B = *(ll *)b;
  if(A > B) return -1;
  if(A < B) return  1;
  return 0;
}

int
main(int argc, char *argv[])
{
  int n; ll a[300000];
  scanf("%d", &n);
  REP(i, 3 * n) scanf("%lld", &a[i]);

  qsort(a, 3 * n, sizeof(ll), dsc);

  int k = 0; ll ans = 0;
  while(k < n){
    ans += a[2 * k + 1];
    k++;
  }
  printf("%lld\n", ans);
  return 0;
}
  


Measured memory_bytes: 4860
import itertools
N,K = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(K*2)]
B = list()
for i in range(1,K*2+1,2):
    B.append(A[i])
C = set(list(itertools.chain.from_iterable(B)))

print(N-len(C))

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  
  int h1, m1, h2, m2; cin >> h1 >> m1 >> h2 >> m2;
  int k; cin >> k;

  int left = h1 * 60 + m1;
  int right = h2 * 60 + m2;

  cout << (right - left) - k << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int>vec(N);
  for(int X=0;X<N;X++){
    cin>>vec.at(X);
  }
  int Y=1;
  for(int X=1;X<N;X++){
    Y=vec.at(Y-1);
    if(Y==2){
      cout<<X<<endl;
      break;
    }
  }
  if(Y!=2){
    cout<<-1<<endl;
  }
}

Measured memory_bytes: 3752
#include<iostream>
#include<stack>

using namespace std;

int main(void){
  int x;
  stack<int>st;

  while(cin >> x){
    if(x==0 && !st.empty()){
      cout << st.top() << endl;
      st.pop();
    }
    else st.push(x);
  }
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll n, h, w;

struct UnionFind {
    vector<long long> par, cnt;

    UnionFind(long long n): par(n, -1), cnt(n) {}
    long long find(long long x) {
        if (par[x]<0) return x;
        return par[x] = find(par[x]);
    }
    bool same(long long i, long long j) {
        // iとjが同じグループかどうかを判別する
        return find(i) == find(j);
    }
    long long size(long long x) {
        return -par[find(x)];
    }

    bool unite(long long x, long long y) {
        // iとjを併合する
        x = find(x);
        y = find(y);
        bool ok = (-par[x]>cnt[x] || -par[y]>cnt[y]);
        if (x == y) {
            cnt[x]++;
        } else if (par[x] > par[y]) {
            par[y] += par[x];
            par[x] = y;
            cnt[y] += cnt[x]+1;
        } else {
            par[x] += par[y];
            par[y] = x;
            cnt[x] += cnt[y]+1;
        }
        return ok;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> h >> w;
    vll r(n), c(n), a(n);
    REP(i, n) cin >> r[i] >> c[i] >> a[i];
    vll ord(n); iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](ll x, ll y) {
      return a[x] > a[y];
    });
    ll ans = 0;
    UnionFind uf(h+w);
    for (ll i: ord) {
        --r[i]; --c[i];
        if (uf.unite(r[i], c[i]+h)) ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
int gcd(int A, int B) {
  if (A < B) {
	  return gcd(B, A);
	}
  if (B == 0) {
	  return A;
	}
  return gcd(B, A % B);
}

int main() {
  int N;
  cin >> N;
  vector <int> A(N + 1);
  for (int i = 1; i <= N; i++) {
	  cin >> A[i];
	}
  vector <int> ltor(N + 2);
  vector <int> rtol(N + 2);
  ltor[0]     = 0;
  rtol[N + 1] = 0;
  for (int i = 1; i <= N; i++) {
	  ltor[i]         = gcd(ltor[i - 1], A[i]);
	  rtol[N + 1 - i] = gcd(rtol[N + 2 - i], A[N + 1 - i]);
	}
  int ans = 1;
  for (int i = 1; i <= N; i++) {
	  ans = max(ans, gcd(ltor[i - 1], rtol[i + 1]));
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

bool isprime(ll x){
    for(ll i=2; i*i<=x; i++){
        if(x%i==0)return false;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    ll x = 9;
    while(n){
        if(isprime(x)){
            cout<<x<<" ";
            n--;
        }
        x+=10;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long a = scanner.nextInt(); // walk
		long b = scanner.nextInt(); // telaport
		
		long count = 0l;
		int tmp = scanner.nextInt(); // 始めの場所
		for (int i = 1; i < n; i++) {
			int pos = scanner.nextInt();
			long aMove = (pos - tmp) * a;
			if (aMove > b) {
				count += b;
			}else {
				count += aMove;
			}
			tmp = pos;
		}
		System.out.println(count);
	}
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int h1, m1; cin >> h1 >> m1;
    int h2, m2; cin >> h2 >> m2;
    int k; cin >> k;

    int m = 0;
    if (h2 >= h1) {
        m += (h2 - h1) * 60;
    } else {
        m += ((h2 + 24) - h1) * 60;
    }

    if (m2 >= m1) {
        m += m2 - m1;
    } else {
        m -= 60;
        m += (m2 + 60) - m1;
    }

    cout << m - k << endl;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0)
        cout << "Zero" << endl;
    else if (a < 0 && b < 0){
        if ((b - a + 1) % 2 == 0)
            cout << "Positive" << endl;
        else
            cout << "Negative" << endl;
    }
    else
        cout << "Positive" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
int main() {
	int x;
	rep(i, 5) {
		cin >> x;
		if (!x)
			cout << i+1 << endl;
	}
	return 0;
}




Measured memory_bytes: 3560
--url : https://devforum.roblox.com/t/commonly-used-tree-data-structures-in-lua/265673/2

----------

--[[
	Pairing Min Heap
	
	Binary Heap is faster for increasing and random pushes but this is faster for joining (merging) and decreasing pushes
	It is very optimized
	
	Use Kill to GC after finished using
	
--]]

--[[
	Node: {
	Key,
	LeftChild,
	NextSibling,
	}
	
--]]

-- Constants

-- cached variables

-- local variables

local tables={}
local tSize=0

local function merge(a,b)
	if not a then
		return b
	elseif not b then
		return a
	elseif a[1]<b[1]then
		-- inlined add child
		b[3]=a[2]
		a[2]=b
		
		return a
	else
		-- inlined add child
		a[3]=b[2]
		b[2]=a
		
		return b
	end
end

local function twopassmerge(a)
	local b=a and a[3]
	if b then
		local newnode=b[3]
		
		a[3]=false
		b[3]=false
		
		return merge(merge(a,b),twopassmerge(newnode))
	else
		return a
	end
end

local function empty(heap)
	return not heap.root
end

local function top(heap)
	return heap.root[1]
end

local function push(heap,key)
	local root=heap.Size+1
	heap.Size=root
	local t=heap.maxSize
	heap.maxSize=(root>t and root)or t
	
	-- inlined merge (optimized for insert)
	root=heap.root
	if not root then
		if tSize>0 then
			t=tables[tSize]
			tables[tSize]=nil
			tSize=tSize-1
			t[1]=key
			heap.root=t
		else
			heap.root={
				key,
				false,
				false,
			}
		end
	elseif root[1]<key then
		if tSize>0 then
			t=tables[tSize]
			tables[tSize]=nil
			tSize=tSize-1
			t[1]=key
			t[3]=root[2]
			root[2]=t
		else
			root[2]={
				key,
				false,
				root[2],
			}
		end
	else
		if tSize>0 then
			t=tables[tSize]
			tables[tSize]=nil
			tSize=tSize-1
			t[1]=key
			t[2]=root
			heap.root=t
		else
			heap.root={
				key,
				root,
				false,
			}
		end
	end
end

local function pop(heap)
	heap.Size=heap.Size-1
	local root=heap.root
	heap.root=twopassmerge(root[2])
	root[1]=false
	root[2]=false
	root[3]=false
	tSize=tSize+1
	tables[tSize]=root
end

local function join(heap1,heap2)
	-- assumes non empty heaps
	-- don't kill heap2 after merging
	
	local a=heap1.Size+heap2.Size
	heap1.Size=a
	local b=heap1.maxSize
	heap1.maxSize=(a>b and a)or b
	
	a=heap1.root
	b=heap2.root
	
	-- inlined merge
	if a[1]<b[1]then
		-- inlined add child
		b[3]=a[2]
		a[2]=b
	else
		-- inlined add child
		a[3]=b[2]
		b[2]=a
		
		heap1.root=b
	end
	
	return heap1
end

local function kill(heap)
	local nt=tSize-heap.maxSize+heap.Size
	for i=nt+1,tSize do
		tables[i]=nil
	end
	tSize=nt
end

local heap={
	empty=empty,
	top=top,
	push=push,
	pop=pop,
	join=join,
	kill=kill,
}

function heap.new(expectedspace)
	expectedspace=expectedspace or 0
	local nt=tSize+expectedspace
	for i=tSize+1,nt do
		tables[i]={false,false,false,}
	end
	tSize=nt
	
	return{
		empty=empty,
		top=top,
		push=push,
		pop=pop,
		join=join,
		kill=kill,
		
		Size=0,
		maxSize=expectedspace,
    }
end

----------

local n,m=io.read("n","n")
local a=heap.new(n)
for i=1,n do
    a:push(-io.read("n"))
end

for i=1,m do
    local x=-a:top()
    a:pop()
    a:push(-(x//2))
end

local total=0
for i=1,n do
    total=total-a:top()
    a:pop()
end
print(total)

Measured memory_bytes: 26216
from decimal import Decimal, ROUND_HALF_UP
n,k = map(int,input().split())
ans = 0
if k % 2 ==0:
    p = Decimal(n/k).quantize(Decimal('0'),rounding=ROUND_HALF_UP)
    ans = p**3 +(n//k)**3
else:
    ans = (n // k)**3
print(ans)

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

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

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,n2,i,j,v,G[100][100],x;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j] = 0;
    }
  }
      
  for(i=0;i<n;i++){
    scanf("%d%d",&x,&n2);
    x--;
    for(j=0;j<n2;j++){
      scanf("%d",&v);
      v--;
      G[x][v] = 1;
    }
  }

   for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j) printf(" ");
      printf("%d",G[i][j]);
    }
    printf("\n");
  }
   return 0;

}


Measured memory_bytes: 2052
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author varunvats32
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DBouquet solver = new DBouquet();
        solver.solve(1, in, out);
        out.close();
    }

    static class DBouquet {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            DBouquet.ModInt ac = comb(n, a);
            DBouquet.ModInt bc = comb(n, b);
            DBouquet.ModInt ec = (new DBouquet.ModInt(2)).pow(n);

            DBouquet.ModInt ans = DBouquet.ModInt.subtract(ec, DBouquet.ModInt.add(ac, bc));
            out.println(DBouquet.ModInt.subtract(ans, new DBouquet.ModInt(1)).x);
        }

        private DBouquet.ModInt comb(int n, int a) {
            DBouquet.ModInt ans = new DBouquet.ModInt(1);
            for (int i = n - a + 1, j = a; i <= n; i++, j--) {
                ans.multiply(new DBouquet.ModInt(i));
                ans.divide(new DBouquet.ModInt(j));
            }
            return ans;
        }

        public static class ModInt {
            private static final int mod = 1000000007;
            public long x;

            public ModInt(long x) {
                this.x = (x % mod + mod) % mod;
            }

            public static DBouquet.ModInt add(DBouquet.ModInt a, DBouquet.ModInt b) {
                DBouquet.ModInt c = new DBouquet.ModInt(a.x);
                if ((c.x += b.x) >= mod) c.x -= mod;
                return c;
            }

            public static DBouquet.ModInt subtract(DBouquet.ModInt a, DBouquet.ModInt b) {
                DBouquet.ModInt c = new DBouquet.ModInt(a.x);
                if ((c.x += mod - b.x) >= mod) c.x -= mod;
                return c;
            }

            public DBouquet.ModInt multiply(DBouquet.ModInt a) {
                x *= a.x;
                x %= mod;
                return new DBouquet.ModInt(x);
            }

            public DBouquet.ModInt inv() {
                return pow(mod - 2);
            }

            public DBouquet.ModInt divide(DBouquet.ModInt a) {
                return this.multiply(a.inv());
            }

            public DBouquet.ModInt pow(long p) {
                if (p == 0) return new DBouquet.ModInt(1);
                DBouquet.ModInt r = pow(p >> 1);
                r = r.multiply(r);
                if ((p & 1) == 1)
                    r = r.multiply(this);
                return r;
            }

        }

    }
}



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

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

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

const int MOD = 1000'000'007;
const double EPS = 0.000'000'001;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

const int N = 1010;
int dp[N][N];
char grid[N][N];
int h, w;

int solve(int i, int j)
{
	if(i == h - 1 && j == w - 1) return 1;

	int& r = dp[i][j];

	if(r == -1)
	{
		r = 0;
		if(i + 1 < h && grid[i + 1][j] == '.')
			r = (r + 0LL + solve(i + 1, j)) % MOD;
		if(j + 1 < w && grid[i][j + 1] == '.')
			r = (r + 0LL + solve(i, j + 1)) % MOD;
	}

	return r;
}

int main()
{
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);
	cout.precision(10);
	
	cin >> h >> w;

	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			cin >> grid[i][j];	
	
	memset(dp, -1, sizeof(dp));

	cout << solve(0, 0) << endl;

	//cerr << "Tempo de execucao: " << (double)clock() / CLOCKS_PER_SEC << endl;
	return 0;
}

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

signed main()
{
  int N; cin>>N;
  vector<int> a(N+1),b(N);
  for(int i=0;i<N+1;i++){
    cin>>a[i];
  }
  for(int i=0;i<N;i++){
    cin>>b[i];
  }

  int ans=0;
  for(int i=0;i<N;i++){
    if(a[i]>=b[i]){
      ans+=b[i];
    }else{
      ans+=a[i]; b[i]-=a[i];
      if(a[i+1]>=b[i]){
        ans+=b[i]; a[i+1]-=b[i];
      }else{
        ans+=a[i+1]; a[i+1]=0;
      }
    }
  }
  cout<<ans<<endl;

  return 0;
}


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


int main()
{
    int n;
    cin >> n;
    n %= 1000;
    if(n == 0) cout << 0 << endl;
    else cout << 1000 - n << endl;
    
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        final int A = scan.nextInt();
        final String S = scan.next();
        scan.close();
        
        if (A < 3200) {
            System.out.println("red");
        } else {
            System.out.println(S);
        }

    }

}


Measured memory_bytes: 21844
h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

dp = [0] + [-1] * h
INF = 10**18
for hp in range(1, h+1):
    ret = INF
    for i in range(n):
        if hp - a[i] >= 0:
            ret = min(ret, dp[hp-a[i]] + b[i])
        else:
            ret = min(ret, b[i])
    dp[hp] = ret
print(dp[h])


Measured memory_bytes: 42092
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define ve vector

int main(){
    string s,t;
    cin >> s >> t;
    int ns = s.size(), nt = t.size();
    ve<ve<int>> dp(ns+1,ve<int>(nt+1,0));
    for(int i = 1; i<ns+1; i++){
        for(int j = 1; j< nt+1; j++){
            if(s[i-1]==t[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            }
            dp[i][j] = max(max(dp[i-1][j], dp[i][j-1]),dp[i][j]);
        }
    }

    string ans = "";
    int d = dp[ns][nt];
    int x = ns, y = nt;

    while(1){
        if(d==0)break;
        if(dp[x-1][y]==d)x--;
        else if(dp[x][y-1]==d)y--;
        else{
            ans += s[x-1];
            x--; y--; d--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[50]= {0};
    int cnt=0,now;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];

    }
    now=arr[0];
    for(int i=0; i<n; i++)
    {
        if(arr[i]>=now)
        {
            now=arr[i];
            cnt++;
        }
    }
    cout<<cnt;
    return 0;
}


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

#define MAX (100000)
#define INFTY (1<<30)

class Edge{
    public:
    int t,w;
    Edge(){}
    Edge(int t,int w):t(t),w(w){}
};

vector<Edge> G[MAX];
int n,d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s){
    for(int i=0;i<n;i++)d[i]=INFTY;
    queue<int> Q;
    Q.push(s);
    d[s]=0;
    int u;
    while(!Q.empty()){
        u=Q.front();Q.pop();
        for(int i=0;i<G[u].size();i++){
            Edge e=G[u][i];
            if(d[e.t]==INFTY){
                d[e.t]=d[u]+e.w;
                Q.push(e.t);
            }
        }
    }
}

void solve(){
    bfs(0);
    int maxv=0;
    int tgt=0;
    for(int i=0;i<n;i++){
        if(d[i]==INFTY)continue;
        if(maxv<d[i]){
            maxv=d[i];
            tgt=i;
        }
    }
    
    bfs(tgt);
    maxv=0;
    for(int i=0;i<n;i++){
        if(d[i]==INFTY)continue;
        maxv=max(maxv,d[i]);
    }
    cout<<maxv<<endl;
}

int main(void){
    int s,t,w;
    cin>>n;
    
    for(int i=0;i<n-1;i++){
        cin>>s>>t>>w;
        
        G[s].push_back(Edge(t,w));
        G[t].push_back(Edge(s,w));
    }
    solve();
}



Measured memory_bytes: 9880
def divisor(n,N): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i*N)
            table.append(n//i*N)
        i += 1
    table = list(set(table))
    return table
from bisect import bisect_right
#b = bisect_left(A,C)

N,M = [int(x) for x in input().split()]
table = divisor(M,N)
table.sort()
b = bisect_right(table,M)
print(table[b-1]//N)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define endl '\n'
#define IO; ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

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

    if(k<=a) cout<<k<<endl;
    else if(k<=a+b) cout<<a<<endl;
    else{
        cout<<a-(k-(a+b))<<endl;
    }
    return 0;
}



Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>
int main(void){
    char str[200001];
    int start=0;
    scanf("%s",str);
    int end=strlen(str)-1;
    while(str[start]!='A') start++;
    while(str[end]!='Z') end--;
    printf("%d\n",end-start+1);
}


Measured memory_bytes: 384
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

LL a[200005];
LL s[200005];
LL ts[200005];

struct BIT {
	vector<int> data;
	BIT(int size) : data(size, 0) {}
	void add(int idx, int x) {
		for (int i = idx; i <= data.size() - 1; i += i & -i)data[i] += x;
	}
	int sum(int idx) {
		int s = 0;
		for (int i = idx; i > 0; i -= i & -i)s += data[i];
		return s;
	}
};

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	REP(i, n)scanf("%lld", &a[i]);
	REP(i, n)s[i + 1] = s[i] + a[i] - k;
	map<LL, int> idx;
	memcpy(ts, s, sizeof(s));
	sort(ts, ts + n+1);
	int tn = unique(ts, ts + n+1) - ts;
	REP(i, tn)idx[ts[i]] = i;
	BIT bit(tn+1);
	LL ret = 0;
	REP(i, n+1) {
		ret += bit.sum(idx[s[i]] + 1);
		bit.add(idx[s[i]] + 1, 1);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 18176
#include <iostream>
using namespace std;
int main(void){
    // Your code here!]
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = a + b;
    int ans1 = c + d;
    if(ans > ans1){
        cout << "Left" << endl;
    }
    else if(ans == ans1){
        cout << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }
}


Measured memory_bytes: 3624
H,W,n=map(int,input().split())
h,w=map(int,input().split())
s=list(input())
t=list(input())
sr=0
sl=0
su=0
sd=0
tr=0
tl=0
tu=0
td=0

rl=W-w
ll=w-1
ul=h-1
dl=H-h
nr=w
nl=w
nu=h
nd=h
ans="YES"

for i in range(n):
    if s[i]=="R":
        nr+=1
        sr+=1
    if s[i]=="L":
        nl-=1
        sl+=1
    if s[i]=="U":
        nu+=1
        su+=1
    if s[i]=="D":
        nd-=1
        sd+=1
    if i!=0:
        if t[i-1]=="R":
            nl+=1
            if -lp<rl:
                tr+=1
        if t[i-1]=="L":
            nr-=1
            if -rp<ll:
                tl+=1
        if t[i-1]=="U":
            nd+=1
            if -dp<ul:
                tu+=1
        if t[i-1]=="D":
            nu-=1
            if -up<dl:
                td+=1
    rp=sr-tl
    lp=sl-tr
    up=su-td
    dp=sd-tu
    
    if rl<rp or ll<lp or ul<up or dl<dp:
        ans="NO"
print(ans)

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

#define ll long long
#define ull unsigned long long
#define ld long double

#define tiii tuple < int, int, int >
#define pii pair < int, int >
#define pll pair < ll, ll >
#define pci pair < char, int >
#define psi pair < string, int >
#define pis pair < int, string >

#define vi vector < int >
#define vd vector < double >
#define vld vector < ld >
#define vll vector < ll >
#define vs vector < string >
#define vc vector < char >
#define vpi vector < pii >
#define vpll vector < pll >
#define vpis vector < pis >

#define pb push_back
#define mt make_tuple
#define gt0 get < 0 >
#define gt1 get < 1 >
#define gt2 get < 2 >

#define pi acos(-1)

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 9;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    fast;

    int n;

    cin >> n;

    int a[n + 5];

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

    int cnt = 0;

    for(int i = 0; i < n - 2; i++){
        for(int j = i + 1; j < n - 1; j++){
            for(int k = j + 1; k < n; k++){
                int x = (a[i] + a[j]), y = (a[i] + a[k]), z = (a[j] + a[k]);

                if(x > a[k] && y > a[j] && z > a[i] && a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3652
import numpy
N,A,B = map(int,input().split())

lisN=list(range(1,N+1))
lisW=[0]*N

for i in lisN:
	dignum=numpy.array(list(str(i)),dtype=int)
	lisW[i-1]=sum(dignum)

arN=numpy.array(lisN)
arW=numpy.array(lisW)
ans=sum(arN[(A<=arW)&(arW<=B)])
print(ans)



Measured memory_bytes: 13032
#include <stdio.h>
int main()
{
    int h, x, y[610], n, i, y1;
    while(scanf("%d", &h) != EOF){
        n = 600 / h;
        x = 0;
        y[0] = 0;
        y1 = 0;
        for(i = 1; i < n; i++){
            x = x + h;
            y[i] = x*x;
            y1 = y1 + y[i];
        }
        printf("%d\n", y1*h);
    }
    return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include <queue>
using namespace std;
using ll = long long;

int N;
ll T[110];

ll gcd(ll x, ll y) {
	if (x % y == 0) {
        return y;
    } else {
        return gcd(y, x % y);
    }
}

ll lcm(ll x, ll y) {
    ll g = gcd(x, y);
    g = x / g * y;
    return g;
}


int main(void){

    ll ans = 0;

    cin >> N;
    for (int i = 1; i <= N;i++) cin >> T[i];

    ans = T[1];
    for (int i = 1; i < N;i++){
        ll com = T[i+1];
        ll L = lcm(ans,com);
        ans = L;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		map<int,pair<long long,int> > m; // id,price,appear
		for(int i=0;i<n;i++){
			int id,price,num;
			cin>>id>>price>>num;
			m[id].first+=(long long)price*num;
			if(m[id].second==0)
				m[id].second=i+1;
		}
		
		map<int,int> m2; // first,id
		for(map<int,pair<long long,int> >::iterator i=m.begin();i!=m.end();i++)
			if(i->second.first>=1000000)
				m2[i->second.second]=i->first;
		
		for(map<int,int>::iterator i=m2.begin();i!=m2.end();i++)
			cout<<i->second<<endl;
		if(m2.size()==0)
			cout<<"NA"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n>=1&&n<=1998)
    {
        if(n<=999&&n>=1)
        {
            printf("ABC");
        }
        else if(n>999&&n<=1998)
        {
            printf("ABD");
        }
    }
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=1e5+5;
const ll inf=1e17;




int main()
{
    idfc;

    int d,t,s;
    cin>>d>>t>>s;

    int p=t*s;
    if(p>=d)cout<<"Yes";
    else cout<<"No";

    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, c, x[100010], v[100010], l[100010], r[100010], l2[100010], r2[100010];
signed main() {
	cin >> n >> c;
	rep(i, n)cin >> x[i] >> v[i];
	rep(i, n) {
		if (i)l[i] = l[i - 1] + v[i] - (x[i] - x[i - 1]);
		else l[i] = v[i] - x[i];
		if (i)l2[i] = max(l2[i - 1], l[i]);
		else l2[i] = max((ll)0, l[i]);
	}
	for (int i = n - 1; i >= 0; i--) {
		if (i != n - 1)r[i] = r[i + 1] + v[i] - (x[i + 1] - x[i]);
		else r[i] = v[i] - (c - x[i]);
		if (i != n - 1)r2[i] = max(r2[i + 1], r[i]);
		else r2[i] = max((ll)0, r[i]);
	}
	int ans = 0;
	rep(i, n - 1)ans = max(ans, l2[i] + r2[i + 1] - min(x[i], c - x[i + 1]));
	ans = max(ans, r2[0]);
	ans = max(ans, l2[n - 1]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for _ in range(N)]

P = [[0 for _ in range(N)] for _ in range(8)]
for i, (x, y, z) in enumerate(XYZ):
    P[0][i] = x + y + z
    P[1][i] = x + y - z
    P[2][i] = x - y + z
    P[3][i] = x - y - z
    P[4][i] = -x + y + z
    P[5][i] = -x + y - z
    P[6][i] = -x - y + z
    P[7][i] = -x - y - z
ans = 0
for k in range(8):
    a = sum(sorted(P[k], reverse=True)[:M])
    ans = max(ans, a)
print(ans)


Measured memory_bytes: 3572
def main():
    _ = input()
    aa = map(int, input().split())
    counts = [0] * 9
    for a in aa:
        a //= 400
        counts[min(a, 8)] += 1
    color = sum(map(lambda c: 1 if c > 0 else 0, counts[:-1]))
    if counts[-1] == 0:
        print(color, color)
    else:
        print(max(color, 1), color + counts[-1])


if __name__ == '__main__':
    main()


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

const int MOD = (int)1e9+7;

int main(){
	int N;
	cin >> N;
	vector<long long> h(N);
	for(int i=0;i<N;i++)	cin >> h.at(i);

	vector<long long> dp(N,1e18);
	dp.at(0)=0;
	for(int i=1;i<N;i++){
		dp.at(i)=min(dp.at(i),dp.at(i-1)+abs(h.at(i)-h.at(i-1)));
		if(i>=2)	dp.at(i)=min(dp.at(i),dp.at(i-2)+abs(h.at(i)-h.at(i-2)));
	}
	cout << dp.at(N-1) << endl;

	return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n; string s;
	cin >>n >>s;
	vector<VI> sk(3);
	string mt = "RGB";
	VI r(n+1), b(n+1), g(n+1);
	rep(i, n){
		r[i+1] = r[i];b[i+1]=b[i];g[i+1]=g[i];
		if(s[i]=='R') r[i+1]++;
		if(s[i]=='G') g[i+1]++;
		if(s[i]=='B') b[i+1]++;
	}
	ll ans = 0;
	rep(i, n-2) rep2(j, i+1,n-1){
		if(s[i]==s[j]) continue;
		ll w = 0;
		if((s[i]=='G' && s[j]=='B' )||( s[i]=='B' && s[j]=='G')){
			w = r[n] - r[j+1];
			if(2*j-i <n && s[2*j-i]=='R') w--;
		}else if((s[i]=='G' && s[j]=='R') || (s[i]=='R' && s[j]=='G')){
			w = b[n] - b[j+1];
			if(2*j-i <n && s[2*j-i]=='B') w--;
		}else if((s[i]=='B' && s[j]=='R') || (s[i]=='R' && s[j]=='B')){
			w = g[n] - g[j+1];
			if(2*j-i <n && s[2*j-i]=='G') w--;
		}
		//dbg(i, j, w);
		ans += w;
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 3628
INF = 10 ** 18
N, M = map(int, input().split())
abc = []
d = [INF] * N
d[0] = 0
loop = [False] * N

for i in range(M):
    a, b, c = map(int, input().split())
    abc.append([a - 1, b - 1,  -c])

for j in range(N):
    for i in range(M):
        if d[abc[i][1]] > d[abc[i][0]] + abc[i][2]:
            d[abc[i][1]] = d[abc[i][0]] + abc[i][2]
ans = -1 * d[-1]

for i in range(N):
    for j in range(M):
        if d[abc[j][1]] > d[abc[j][0]] + abc[j][2]:
            d[abc[j][1]] = d[abc[j][0]] + abc[j][2]
            loop[abc[j][1]] = True

        if loop[abc[j][0]] == True:
            loop[abc[j][1]] = True

if loop[N - 1]:
    print('inf')
else:
    print(ans)

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int W, H, N, ix, iy, ox, oy;
bool movable[55][55][4];

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

bool in_range(int x, int y) { return 0 <= x && x < W && 0 <= y && y < H; }

struct State { int x, y; };

int step[55][55];

int bfs() {
	memset(step, -1, sizeof(step));
	
	queue< State > que;
	que.push(State{ix, iy});
	
	while (!que.empty()) {
		State s = que.front(); que.pop();
		
		for_(d,0,4) {
			if (!movable[s.y][s.x][d]) continue;
			
			int nx = s.x + dx[d], ny = s.y + dy[d];
			
			if (!in_range(nx, ny)) continue;
			
			if (step[ny][nx] == -1) {
				step[ny][nx] = step[s.y][s.x] + 1;
				que.push(State{nx, ny});
			}
		}
	}
	
	return step[oy][ox];
}

void solve() {
	int ini = bfs(), ans = 0;
	
	for_(y,0,H) for_(x,0,W) {
		if (x > 0 && movable[y][x][3]) {
			movable[y][x][3] = movable[y][x - 1][1] = false;
			ans = max(ans, bfs() - ini);
			movable[y][x][3] = movable[y][x - 1][1] = true;
		}
		
		if (y > 0 && movable[y][x][2]) {
			movable[y][x][2] = movable[y - 1][x][0] = false;
			ans = max(ans, bfs() - ini);
			movable[y][x][2] = movable[y - 1][x][0] = true;
		}
	}
	
	cout << ans << endl;
}

int main() {
	cin >> W >> H >> N;
	
	for_(y,0,H) for_(x,0,W) for_(d,0,4) movable[y][x][d] = true;
	
	for_(i,0,N) {
		int sx, sy, ex, ey;
		cin >> sx >> sy >> ex >> ey;
		
		if (sx > ex) swap(sx, ex);
		if (sy > ey) swap(sy, ey);
		
		if (sy > 0) for_(x,sx,ex) movable[sy][x][2] = movable[sy - 1][x][0] = false;
		if (sx > 0) for_(y,sy,ey) movable[y][sx][3] = movable[y][sx - 1][1] = false;
	}
	
	cin >> ix >> iy;
	cin >> ox >> oy;
	
	solve();
}

Measured memory_bytes: 1244
#include <bits/stdc++.h> 
using namespace std;
const int INF = 1e9+5;

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> heights(N);
	for(int i=0; i<N; ++i){
		cin >> heights[i];
	}
	vector<int> dp(N,INF);
	dp[0] = 0;
	for(int i=0; i<N; ++i){
		for(int j=i+1; j<=i+K; ++j){
			if(j<N){
				dp[j] = min(dp[j],dp[i]+abs(heights[j]-heights[i]));
			} else{break;}
		}
	}
	cout << dp[N-1] << endl;
	return 0;
}

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

using lli = long long int;

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

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

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

#define MAX_N 3000

int n, x, y;
vector<vector<int>> g(MAX_N);
queue<int> q;
vector<bool> seen(MAX_N);
int d[MAX_N][MAX_N];

void init(int n){
    rep(i, n){
        rep(j, n){
            d[i][j] = INT_MAX;
        }
    }
}

int main(void){
    cin >> n >> x >> y;
    rep(i, n-1){
        g[i].push_back(i+1);
        g[i+1].push_back(i);
    }
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);

    init(n);
    rep(i, n){
        rep(i, n) seen[i] = false;
        q.push(i);
        d[i][i] = 0;
        while(!q.empty()){
            int node = q.front();
            q.pop();
            seen[node] = true;
            for(auto next_node : g[node]){
                if(seen[next_node] == true) continue;
                q.push(next_node);
                seen[next_node] = true;
                d[i][next_node] = d[i][node] + 1;
            }
        }
    }
    
    vector<int> res(n+1);
    rep(i, n){
        rep(j, n){
            res[d[i][j]]++;
        }
    }
    rep(i, n-1){
        cout << res[i+1]/2 << endl;
    }
    return 0;
}


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

using namespace std;

long long a[100005];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    long long c[2],j=0,p;
    for(int i=n-1;i>=1;i--)
    {
        p=0;
        if(a[i]==a[i-1])
        {
            c[j]=a[i-1];
            i--;
            j++;
        }
        if(j==2)
        {
            p=1;
            break;
        }
    }
    if(p==1)
        cout<<c[0]*c[1];
    else
        cout<<"0";
    return 0;
}


Measured memory_bytes: 1024
N, M, X, Y = [int(i) for i in input().split()]
x_list  = [int(i) for i in input().split()]
y_list  = [int(i) for i in input().split()]

x_max = max(x_list)
y_min = min(y_list)

z_list = range(X+1, Y+1)

war = 1

if x_max >= y_min:
    pass
else:
    for i in range(x_max+1, y_min+1):
        if i in z_list:
            war = 0
            break

if war == 0:
    print("No War")
else:
    print("War")
           

Measured memory_bytes: 3064