akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <climits>
#include <queue>
#include <vector>
#include <utility>

const int N = 200000;

int n, a[N];
std::pair<int, int> mi[N << 1][2];

int get_id(int l, int r)
{
    return l + r | l != r;
}

void build(int l, int r)
{
    int id = get_id(l, r);
    if (l == r) {
        mi[id][0] = mi[id][1] = {INT_MAX, -1};
        mi[id][l & 1] = {a[l], l};
    } else {
        int m = l + r >> 1;
        build(l, m);
        build(m + 1, r);
        mi[id][0] = std::min(mi[get_id(l, m)][0], mi[get_id(m + 1, r)][0]);
        mi[id][1] = std::min(mi[get_id(l, m)][1], mi[get_id(m + 1, r)][1]);
    }
}

std::pair<int, int> query(int l, int r, int a, int b, int t)
{
    if (b < l || r < a) {
        return {INT_MAX, -1};
    }
    if (a <= l && r <= b) {
        return mi[get_id(l, r)][t];
    }
    int m = l + r >> 1;
    return std::min(query(l, m, a, b, t), query(m + 1, r, a, b, t));
}

struct Sum
{
    Sum(int l, int r)
        : l(l), r(r)
    {
        auto x = query(0, n - 1, l, r - 1, l & 1);
        auto y = query(0, n - 1, x.second + 1, r, (l & 1) ^ 1);
        i = x.second, j = y.second;
        k = std::make_pair(x.first, y.first);
    }

    int l, r, i, j;
    std::pair<int, int> k;
};

bool operator < (const Sum& a, const Sum& b)
{
    return a.k > b.k;
}

int main()
{
#ifdef LOCAL_JUDGE
    freopen("E.in", "r", stdin);
#endif
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; ++ i) {
            scanf("%d", a + i);
        }
        build(0, n - 1);
        std::priority_queue<Sum> heap;
        heap.push(Sum(0, n - 1));
        std::vector<int> result;
        while (!heap.empty()) {
            auto t = heap.top();
            heap.pop();
            result.push_back(t.k.first);
            result.push_back(t.k.second);
            if (t.l < t.i) {
                heap.push(Sum(t.l, t.i - 1));
            }
            if (t.i + 1 < t.j) {
                heap.push(Sum(t.i + 1, t.j - 1));
            }
            if (t.j < t.r) {
                heap.push(Sum(t.j + 1, t.r));
            }
        }
        for (int i = 0; i < n; ++ i) {
            printf("%d%c", result[i], " \n"[i == n - 1]);
        }
    }
}

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

#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
inline void Yes(bool f) {cout<<((f)?"Yes":"No")<<endl;}
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> v;
  return s;
}


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

    int N, A; cin >> N >> A;
    Yes(N%500<=A);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int TAM = 100003;

vector <int> adj[TAM];
int n, a, b, vis[TAM];
int pa [TAM], pb [TAM], sub[TAM], col[TAM];

int calc ( int x ){
    sub[x] = 1;
    for( int i = 0 ; i < adj[x].size() ; i ++ ){
        if( adj[x][i] == pa[x] ) continue;
        sub[x] += calc(adj[x][i]);
    }
    //cout << " calc :: " << x << " -> " << sub[x] << endl ;
    return sub[x];
}

int main(){

    scanf("%d",&n);
    for( int i = 0 ; i < n-1 ; i ++ ){
        scanf("%d%d",&a,&b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    queue <int> bfs;
    bfs.push(1);
    pa[1] = 1;
    vis[1] = 1;
    int act, nxt;
    while( bfs.size() ){
        act = bfs.front();
        bfs.pop();

        for( int i = 0 ; i < adj[act].size() ; i ++ ){
            nxt = adj[act][i];
            if( vis[nxt] != 1 ){
                vis[nxt] = 1;
                pa[nxt] = act;
                //cout << " pa :: " << nxt << " -> " << pa[nxt] << endl ;
                bfs.push(nxt);
            }
        }
    }
    calc(1);

    bfs.push(n);
    pb[n] = n;
    vis[n] = 2;
    while( bfs.size() ){
        act = bfs.front();
        bfs.pop();

        for( int i = 0 ; i < adj[act].size() ; i ++ ){
            nxt = adj[act][i];
            if( vis[nxt] != 2 ){
                vis[nxt] = 2;
                pb[nxt] = act;
                //cout << " pb :: " << nxt << " -> " << pb[nxt] << endl ;
                bfs.push(nxt);
            }
        }
    }

    col[1] = 1;
    col[n] = 2;
    int ta = 1, tb = 1, ca = 1, cb = n, ra, rb;
    while( true ){
        if( col[pb[ca]] == 0 ){
            ca = pb[ca];
            col[ca] = 1;
            ta ++;
        }else{
            ra = sub[1] - sub[cb] - ta;
            rb = sub[cb] - tb;
            if( ra > rb ) printf("Fennec\n");
            else printf("Snuke\n");
            return 0;
        }
        if( col[pa[cb]] == 0 ){
            cb = pa[cb];
            col[cb] = 2;
            tb ++;
        }else{
            ra = sub[1] - sub[cb] - ta;
            rb = sub[cb] - tb;
            if( ra >= rb ) printf("Fennec\n");
            else printf("Snuke\n");
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 12416
#include<bits/stdc++.h>
   using namespace std;
   //int dp[100005];
   int visited[100005];
   vector<int> l[100005];
   long long int mod=1000000000+7;
   long long int dp[100005][2];

   void dfs(int n)
   {
      visited[n]=1;

      dp[n][0]=1;
      dp[n][1]=1;

      for(int i=0;i<l[n].size();i++)
      {
         if(visited[l[n][i]]==0)
         {
            dfs(l[n][i]);
         
         dp[n][0]=(dp[n][0]%mod*(dp[l[n][i]][0]%mod+dp[l[n][i]][1]%mod))%mod;
         dp[n][1]=(dp[n][1]%mod*dp[l[n][i]][0]%mod)%mod;
         }
      }

   }

  int main()
  {   
    int n;
    cin>>n;
    int x,y;
    for(int i=0;i<n-1;i++)
    {
       cin>>x>>y;
      l[x].push_back(y);
      l[y].push_back(x);
    }
   //  queue< pair< int,pair<int,int> > > q;
   //  q.push(make_pair(1,make_pair(1,1)));  
   //  int ans=0;
   //  while(!q.empty())
   //  {
   //    pair< int,pair<int,int> > temp=q.front();
   //    q.pop();
   //    int f=temp.first;
   //    int sf=temp.second.first;
   //    int ss=temp.second.second;
   //   // cout<<f<<" "<<sf<<" "<<ss<<"\n";
   //    visited[f]=1;
   //    if(l[f].size()==1)
   //    {
   //       ans=ans+sf+ss;
   //    }
   //    for(int i=0;i<l[f].size();i++)
   //    {
   //       if(visited[l[f][i]]==0)
   //       q.push(make_pair(l[f][i],make_pair(sf+ss,sf)));
   //    }   
    
      dfs(1);
      cout<<(dp[1][0]+dp[1][1])%mod;
    //  cout<<ans;
    

  }



Measured memory_bytes: 11776
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MAXN = 200005;
const int MAXT = 530000;
using lint = long long;
using pi = pair<int, int>;

int n, a[MAXN];
lint dp[MAXN], dsum[MAXN];

struct seg{
	lint tree[MAXT];
	int lim;
	void init(int n){
		memset(tree, 0x3f, sizeof(tree));
		for(lim = 1; lim <= n; lim <<= 1);
	}
	void upd(int x, lint v){
		x += lim;
		tree[x] = min(tree[x], v);
		while(x > 1){
			x >>= 1;
			tree[x] = min(tree[x], v);
		}
	}
	lint query(int s, int e){
		s += lim; e += lim;
		lint ret = 1e18;
		while(s < e){
			if(s%2 == 1) ret = min(ret, tree[s++]);
			if(e%2 == 0) ret = min(ret, tree[e--]);
			s >>= 1; e >>= 1;
		}
		if(s == e) ret = min(ret, tree[s]);
		return ret;
	}
}seg1, seg2;

lint solve(int x, int y){
	vector<int> v;
	a[0] = x;
	for(int i=1; i<=n; i++){
		dsum[i] = dsum[i-1] + abs(a[i] - a[i-1]);
	}
	for(int i=0; i<=n; i++) v.push_back(a[i]);
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	seg1.init(n);
	seg2.init(n);
	for(int i=n-1; i>=0; i--){
		dp[i] = dsum[n] - dsum[i + 1];
		auto l = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
		dp[i] = min(dp[i], seg1.query(l, n) - a[i] - dsum[i+1]);
		dp[i] = min(dp[i], seg2.query(0, l) + a[i] - dsum[i+1]);
		l = lower_bound(v.begin(), v.end(), a[i+1]) - v.begin();
		seg1.upd(l, dp[i] + a[i+1] + dsum[i]);
		seg2.upd(l, dp[i] - a[i+1] + dsum[i]);
	}
	return dp[0] + abs(y - a[1]);
}

int main(){
	int x, y;
	scanf("%*d %d %d %d",&n,&x,&y);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	cout << min(solve(x, y), solve(y, x)) << endl;
}


Measured memory_bytes: 14180
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

uint32_t getCode(const std::string& str) {
  uint32_t code = 0;
  for (size_t i = 0; i < str.size(); i++) {
    if (str[i] == 'A')
      code += 0;
    else if (str[i] == 'C')
      code += 1;
    else if (str[i] == 'G')
      code += 2;
    else if (str[i] == 'T')
      code += 3;

    code = code << 2;
  }
  return code | (str.size() << 24);
}

uint32_t hash(uint32_t code, uint32_t count, uint32_t p) {
  return ((code % p) + count * (1 + code % (p - 1))) % p;
}

int main() {
  uint32_t n = 0;
  std::cin >> n;

  const uint32_t p = 1'249'999;
  std::vector<uint32_t> dict(p, 0);
  for (size_t i = 0; i < n; i++) {
    std::string command, op;
    std::cin >> command >> op;

    if (command == "insert") {
      uint32_t count = 0;
      while (dict[hash(getCode(op), count, p)] != 0) count++;
      dict[hash(getCode(op), count, p)] = getCode(op);
    } else {
      uint32_t count = 0;
      while (true) {
        auto value = dict[hash(getCode(op), count, p)];
        if (value == getCode(op)) {
          std::cout << "yes" << std::endl;
          break;
        } else if (value == 0 || count >= n) {
          std::cout << "no" << std::endl;
          break;
        }
        count++;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 7964
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
int A[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	vector<vector<int>> V;
	V.push_back({0,1,0});
	for(i=1;i<=N+1;i++) {
		if(i!=N+1) cin>>A[i];
		vector<vector<int>> W;
		
		if(A[i]==A[i-1]) {
			continue;
		}
		if(A[i]>A[i-1]) {
			int D=A[i]-A[i-1];
			FORR(v,V) {
				W.push_back({0,v[0],v[2]+2});
				W.push_back({v[0],v[0]+D,v[2]+1});
				W.push_back({v[0]+D,A[i]+1,v[2]});
			}
		}
		else {
			int D=A[i-1]-A[i];
			FORR(v,V) {
				W.push_back({0,min(max(v[0]-D,0),A[i]+1),v[2]+2});
				W.push_back({min(max(v[0]-D,0),A[i]+1),min(v[0],A[i]+1),v[2]+1});
				W.push_back({min(v[0],A[i]+1),A[i]+1,v[2]});
			}
		}
		
		sort(ALL(W));
		V.clear();
		//cout<<"!"<<i<<endl;
		FORR(w,W) {
			if(w[0]==w[1]) continue;
			while(V.size() && V.back()[2]>=w[2]) {
				if(V.back()[0]>=w[0]) {
					V.pop_back();
				}
				else {
					V.back()[1]=w[0];
					break;
				}
			}
			if(V.size()&&V.back()[2]<=w[2]) continue;
			V.push_back(w);
		}
		//FORR(v,V) cout<<v[0]<<" "<<v[1]<<" "<<v[2]<<endl;
	}
	
	cout<<V[0][2]<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1024
from sys import stdin
input = stdin.readline
def BFS(K,path,N):
  """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す"""
  from collections import deque
  dist=[-1]*N
  dist[K]=0
  que=deque()
  que.append(K)
  while que:
    label=que.popleft()
    for i,c in path[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        que+=[i]
  return dist
 
N=int(input())
path=[ [] for i in range(N)]
for i in range(N-1):
  a,b,c=map(int,input().split())
  path[a-1].append((b-1,c))
  path[b-1].append((a-1,c))
Q,K=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(Q)]
distance=BFS(K-1,path,N)
for i in range(Q):
  print(distance[xy[i][0]-1]+distance[xy[i][1]-1])

Measured memory_bytes: 68024
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_077
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] arrayA = ReadInts();
            int[] arrayB = ReadInts();
            int[] arrayC = ReadInts();
            Array.Sort(arrayA);
            Array.Sort(arrayB);
            Array.Sort(arrayC);
            int itrA = 0;
            int itrB = 0;
            long[] ABpatterns = new long[n];
            for (; itrB < n; itrB++)
            {
                while (itrA < n && arrayA[itrA] < arrayB[itrB])
                {
                    itrA++;
                }
                ABpatterns[itrB] = itrB == 0
                    ? itrA : ABpatterns[itrB - 1] + itrA;
            }

            itrB = 0;
            int itrC = 0;
            long[] BCpatterns = new long[n];
            for (; itrC < n; itrC++)
            {
                while (itrB < n && arrayB[itrB] < arrayC[itrC])
                {
                    itrB++;
                }
                if (itrB == 0)
                {
                    BCpatterns[itrC] = 0;
                }
                else
                {
                    BCpatterns[itrC] = itrC == 0
                        ? ABpatterns[itrB - 1]
                        : BCpatterns[itrC - 1] + ABpatterns[itrB - 1];
                }
            }

            Console.WriteLine(BCpatterns[n - 1]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 38820
from heapq import heappush, heappop

R = lambda: map(int, input().split())
n, m = R()
c = [[] for _ in range(m)]
for _ in range(n):
    a, b = R()
    if a <= m:
        c[m - a].append(b)
r=0
h = []
for l in reversed(c):
    for x in l:
        heappush(h, -x)
    if h:
        r -= heappop(h) 
print(r)


Measured memory_bytes: 18388
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,a;
    cin >> n >> a;
    if(n%500 <= a) cout << "Yes"<<endl;
    else cout << "No" << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

long long myabs(long long a) {
  if (a >= 0) {
    return a;
  } else {
    return -a;
  }
}

int main() {
  int n, i;
  scanf("%d", &n);
  long long a[200010];
  long long left[200010];
  long long right[200010];
  scanf("%lld", &a[0]);
  left[0] = a[0];
  long long min_dif = 2000000001;
  for (i = 1; i < n; i++) {
    scanf("%lld", &a[i]);
    left[i] = left[i-1] + a[i];
  }
  right[n-1] = a[n-1];
  for (i = n-2; i >= 0; i--) {
    right[i] = right[i+1] + a[i];
  }
  for (i = 0; i < n-1; i++) {
    if (myabs(left[i] - right[i+1]) <= min_dif) {
      min_dif = myabs(left[i] - right[i+1]);
    }
  }
  printf("%lld", min_dif);
  return 0;
}


Measured memory_bytes: 4864
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d,x,flag=0;
  cin>>a>>b;
  cout<<a-b+1<<'\n';
  
  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

const ll INF = 1001001001;
ll h, w, k, ans = INF;
string s[10] = {};

int main() {
	cin >> h >> w >> k;
	rep(i, h)cin >> s[i];
	rep(i, 1 << h - 1) {
		ll box = 0, id[10] = {}, cnt[10] = {};
		bool ok = true;
		rep(j, h) {
			id[j] = box;
			if (i >> j & 1)box++;
		}
		ll res = box;
		box++;
		auto add = [&](ll j) {
			ll cnt2[10] = {};
			rep(l, h) {
				cnt2[id[l]] += s[l][j] - '0';
				if (cnt2[id[l]] > k)return false;
			}
			rep(l, box)cnt[l] = 0;
			res++;
			return true;
		};
		rep(j, w) {
			rep(l, h)cnt[id[l]] += s[l][j] - '0';
			rep(l, box) {
				if (cnt[l] > k) {
					if (add(j)) {
						j--;
					}
					else {
						ok = false;
						break;
					}
				}
				if (!ok)break;
			}
		}
		if (ok)ans = min(ans, res);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))

template <class T>
constexpr T modp(T x, T y)
{
    return (y + x % y) % y;
}
template <class T>
constexpr T sq(T x)
{
    return x * x;
}
template <class T>
constexpr double divd(T x, T y)
{
    static_cast<double>(x) / static_cast<double>(y);
}

template <class T>
T nextInput()
{
    T t;
    cin >> t;
    return t;
}

#define netint nextInput<ll>()
#define netstr nextInput<string>()

template <class T>
void print(T&& t)
{
    cout << forward<T&&>(t) << endl;
}

void print(double t) { cout << fixed << setprecision(14) << t << endl; }

//

int main()
{
    //
    ll N = netint;
    print(N / 3);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
int main() {
	init();

	ll N, K; cin >> N >> K;
	vector<int>A(N);
	rep(i, 0, N) cin >> A[i];
    mint ans = 0;
    rep(i, 0, N) {
        ll a = 0;
        rep(j, i + 1, N) {
            if (A[i] > A[j])ans += 1 * K;;
        }
    }
    rep(i, 0, N) {
        mint cnt = 0;
        rep(j, 0, N) {
            if (A[i] > A[j])cnt += 1;
        }
        cnt = ((cnt + cnt * (K - 1)))/2 * (K - 1);

        ans += cnt;
    }
    cout << ans.x << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int n, m,ans = 0;
	cin >> n >> m;
	REP(i, n + 1) {
		REP(j, n + 1) {
			if (i + j <= m and m - i - j <= n) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <math.h>
int prime(int val){
    if (val==2) return 1;
    if (val==3) return 1;
    int count = 0;
    for (int i = 2; i < sqrt(val) + 1; i++){
        if(val%i == 0){
            count++;
        }
    }
    if ( count > 0) return 0;
    else return 1;
}



int main(){
    
    int Num;
    scanf("%d",&Num);
    int a[10000+5]; 
    for(int i = 0; i < Num; i++){
        
        scanf("%d",&a[i]);
        
    }
    int count = 0;
    int total= 0;
    for(int i = 0; i < Num; i++){
        int isprime =prime(a[i]);
        if(isprime == 1)total++;
    }
    printf("%d\n",total);
    return 0;
}


Measured memory_bytes: 2108
from itertools import permutations

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(N)]

t = [[0]*C for _ in range(3)]
for i in range(N):
    for j in range(N):
        t[(i+j)%3][c[i][j]-1] += 1

ans = 1001001001
for i, j, k in permutations(range(C), 3):
    tmp = 0
    for l in range(C):
        tmp += D[l][i] * t[0][l]
    for l in range(C):
        tmp += D[l][j] * t[1][l]
    for l in range(C):
        tmp += D[l][k] * t[2][l]
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 5620
#include<stdio.h>
#include<limits.h>
#include<algorithm>

using namespace std;

int main(void){
  int n;
  long long int R[200001];
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%lld", &R[i]);
  }
  long long int maxv = LLONG_MIN;
  long long int minv = R[0];
  for(int i = 1; i < n; i++){
    maxv = max(R[i] - minv, maxv);
    minv = min(R[i], minv);
  }

  printf("%lld\n", maxv);

  return 0;
}



Measured memory_bytes: 4292
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
	ll n;
    cin >> n;
    vll h(n);
    ll tmp = 0, cnt = 0;
    REP(i, n){
        cin >> h[i];
        if(h[i] >= tmp){
            tmp = h[i];
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<double >    vecd;
typedef vector<vector<int> >  vec2int;
typedef vector<vector<double> >  vec2d;
typedef vector<ll >     vecll;
typedef vector<string > vecstr;
typedef vector<bool > vecbool;
typedef vector<vector< bool > > vec2bool;
typedef vector<bool > vecbool;
////////////////////////////////////////////////
int main()
{
  ll a, b, c; cin >> a >> b >> c;
  ll v1 = a*b*(c - c/2) - a*b*(c/2);
  ll v2 = a*c*(b - b/2) - a*c*(b/2);
  ll v3 = b*c*(a - a/2) - b*c*(a/2);
  cout << min(v1,min(v2, v3)) << endl;
}

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

int main() {
    int n; cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    // ここで昇順になるため，任意のa=l[i]より右にあるものb, cは b+c>aを満たす
    sort(ALL(l));   // nlogn
    int ans = 0;
    rep(i, n) {
        int a = l[i];
        for (int j=i+1; j<n; ++j) {
            int b = l[j];
            for (int k=j+1; k<n; ++k) {
                int c = l[k];
                if (a+c<=b) {
                    break;
                } else if (a+b<=c) {
                    break;
                } else {
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
 
int main() {
 
  int a;
  string b,c;
  cin >> a;
  cin >> b >> c;
  std::string str(a*2, 'd');
  
  for (int i = 0; i < a; i++) {
	  str.at(i*2) = b.at(i);
	  str.at(i*2+1) = c.at(i);
}
  cout << str << endl;
 
}

Measured memory_bytes: 384
# 3.4.3

import re
from collections import deque
from functools import reduce
from heapq import heappop
from heapq import heappush
from itertools import permutations
from math import pi
from operator import itemgetter
from operator import mul
from operator import xor
from os import linesep
from sys import stdin


def rline() -> str:
    return stdin.readline().strip()


def rlines(hint: int = 1):
    ret = ['' for i in range(hint)]
    for i in range(hint):
        ret[i] = rline()
    return ret


def htokens(hint: int = 1):
    lns = rlines(hint)
    ret = list(map(lambda ln: ln.split(), lns))
    return ret


def vtokens(hint: int = 1):
    m, _ = htokens()
    wint = len(m)
    ret = [[None] * hint for i in range(wint)]
    for y in range(hint):
        if y != 0:
            m, _ = htokens()
        # convert horizontal to vertical
        x = 0
        for v in m:
            ret[x][y] = v
            x += 1
    # if return value has one and only one element(list),
    if wint == 1:
        # then add an empty list.
        ret.append([])
    return ret


def rint(radix: int = 10) -> int:
    return int(rline(), radix)


def hints(hint: int = 1, radix: int = 10):
    ret = htokens(hint)
    for i in range(len(ret)):
        ret[i] = list(map(lambda v: int(v, radix), ret[i]))
    return ret


def vints(hint: int = 1, radix: int = 10):
    ret = vtokens(hint)
    for i in range(len(ret)):
        ret[i] = list(map(lambda v: int(v, radix), ret[i]))
    return ret


def mat(hint: int, wint: int):
    return [[None]*wint for i in range(hint)]


def filllist(lst, value: int) -> None:
    # destructive.
    for i in range(len(lst)):
        lst[i] = value


def isprime(n: int) -> bool:
    if n <= 1:
        return False
    if n in (2, 3, 5):
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    lst = int(n**0.5)
    f = 5
    while f <= lst:
        if n % f == 0:
            return False
        if n % (f + 2) == 0:
            return False
        f += 6
    return True


def strmat(matrix, lnsep: str = linesep, fieldsep: str = ' ') -> str:
    return lnsep.join(map(lambda row: fieldsep.join(map(str, row)), matrix))


def strbool(boolval: int) -> str:
    return ['No', 'Yes'][boolval]


def solve() -> None:
    # read here
    (n, m) = hints()[0]
    ab_s = hints(n)

    # solve here

    # delay asc, prize desc
    ab_s.sort(key=itemgetter(1), reverse=True)
    ab_s.sort(key=itemgetter(0), reverse=False)

    ans = 0
    tasks = []
    ti = 0
    for t in range(m + 1):
        # from (m days after) to today
        while ti < n and ab_s[ti][0] == t:
            a, b = ab_s[ti]
            ti += 1
            heappush(tasks, -b)
        if tasks:
            # do task
            ans -= heappop(tasks)

    # print here
    print(ans)


if __name__ == '__main__':
    solve()


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

main()
{
	priority_queue<int> q;
	int n,k,m,i,j,len;
	int flag=0;
	int alice=0,bob=0;
	int flip=1;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&len);
		q.push(len);
	}
	
	while(!q.empty())
	{
		if(flip==1)
		{
			alice+=q.top();
			flip*=-1;
		}
		else if(flip==-1)
		{
			bob+=q.top();
			flip*=-1;
		}
		q.pop();
	}
	printf("%d",alice-bob);
}

Measured memory_bytes: 256
import sys
import math
from collections import deque
n,m = map(int, input().split())

q = [0]*(n+1)

graph = [[] for _ in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [-1] * (n+1)
dist[0] = 0
dist[1] = 0

# if m == 0:
#     print(1)
#     exit()

d = deque()
a = 0
for l,j in enumerate(q):
    b = set()
    if j == 0:
        d.append(l)
        while d:
            v = d.popleft()
            b.add(v)
            q[v] = -1

            for i in graph[v]:
                b.add(i)
                q[i] = -1

                if dist[i] != -1:
                    continue
                dist[i] = dist[v] + 1
                d.append(i)
        a = max(a,len(b))
print(a)

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

int main() {
	string s;cin>>s;
	char back='i';
	int cnt=0;
	for(char c:s){
		if(back!=c){
			cnt++;
			back=c;
		}
	}
	cnt--;
	if(*s.begin()=='o'&&*s.rbegin()=='o')puts(cnt&1?"x":"o");
	else puts(cnt&1?"o":"x");
}

Measured memory_bytes: 3132
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
     ll x,m=100,cnt=0;
     cin>>x;
     while(x>m){
           m+=m/100;
           cnt++;
     }
     cout<<cnt<<endl;
}

Measured memory_bytes: 3620
#include<stdio.h>
#define N 500001

void maxHeap(int*,int,int);
void buildMaxHeap(int *,int);

int main()
{
  int n,i,A[N];
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
  buildMaxHeap(A,n);
  for(i=1;i<=n;i++)
    printf(" %d",A[i]);
  printf("\n");

  return 0;
}

void maxHeap(int*A,int i,int n)
{
  int l,r,largest,x;
  l = i*2;
  r = i*2+1;
  /* 左の子、自分、右の子で値が最大のノードを選ぶ*/
if (l<=n && A[l]>A[i])
  largest = l;
else
  largest = i;

if(r<=n && A[r] > A[largest])
  largest = r;
 if (largest != i)
   {x=A[i];
    A[i]=A[largest];
    A[largest]=x;

   maxHeap(A, largest,n);/* 再帰的に呼び出し*/ }
}

void buildMaxHeap(int *A,int n)
{
  int i;
  for(i=n/2;i>0;i--)
    maxHeap(A,i,n);
}





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

int N, P, A[51];
long long DP[51][2];     //i番目の袋までのみ考えた場合の場合の数,第二引数でPの値による場合分け
int main() {
    cin >> N >> P;
    for (int i=1; i<=N; ++i) cin >> A[i];    //読み込み

    for (int i=0; i<=N; ++i) 
        for (int j=0; j<2; ++j) 
            DP[i][j] = 0;           //0で初期化    
    DP[0][0] = 1;                   //一枚も食べないという場合の1通り

    for (int i=1; i<=N; ++i) {      //袋の数だけDP
        DP[i][0] += DP[i-1][0];     
        DP[i][1] += DP[i-1][1];     //i番目の袋かを食べない場合
        if (A[i] % 2 == 0) {        //食べる場合は偶奇で場合分けが必要
            DP[i][0] += DP[i-1][0];
            DP[i][1] += DP[i-1][1];
        }
        else {                      //i番目を食べると偶奇が入れ替わる
            DP[i][0] += DP[i-1][1]; 
            DP[i][1] += DP[i-1][0];
        }
    }
    cout << DP[N][P] << endl;
}
    




Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(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 SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

    int n;
    cin >> n;

    vector<int> a(n);
    unordered_map<int, int> rev;
    rep(i, n){
        cin >> a[i];
        rev[a[i]] = i;
    }

    SORT(a);

    unordered_map<int, int> pos;
    rep(i, n){
        pos[a[i]] = i;
    }

    int ans = 0;
    rep(i, n){
        ans += ((rev[a[i]] & 1) ^ (pos[a[i]] & 1));
    }
    ans = (ans + 1) >> 1;

    cout << ans << endl;

    return 0;
}

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


int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  int ans = 0;
  rep(j,n)rep(i,j){
    int ij = vec[i] + vec[j];
    int r = lower_bound(vec.begin(), vec.end(), ij) -vec.begin();
    int l = j+1;
    ans += max(0, r-l);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100000001
#define dmp make_pair
#define dpb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[5001], b[5001], dp[5001][2];
int main(){
	int n, m, t = 0, ans = 0;
	scanf("%d%d", &n, &m);
	rrep(i,n)scanf("%d", &a[i]);
	rrep(i,m)scanf("%d", &b[i]);
	for(int j = 1;j <= m;j++){
		for(int i = 1;i <= n;i++){
			if(a[i] == b[j])dp[i][j%2] = dp[i-1][(j-1)%2]+1;
			else dp[i][j%2] = dp[i-1][j%2];
			ans = max(ans, dp[i][j%2]);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

#define N 26
#define MAX_T 1.9

const int INF = 1 << 30;
const double mean = 0.0;
const double stddev = 1.0;

int c[N];
int s[365][N];
int last[N];
std::chrono::time_point<std::chrono::steady_clock> start, endt;
random_device rd;
mt19937 generator(rd());
uniform_real_distribution<> dist_real(0.0, 1.0);
uniform_int_distribution<> dist_int(0, RAND_MAX);

struct ContestInfo {
	int D;
	long score;
	long best_score;
	vector<int> t;
	vector<int> best_t;
	set<int> held[N];
	ContestInfo(int dd) : D(dd), score(0) {
		t.resize(D, -1);
		for (int i = 0; i < N; i++) {
			held[i].insert(-1);
			held[i].insert(D);
			score -= c[i] * D * (D + 1) / 2;
		}
	}

	void add(int dd, int qq) {
		if (t[dd] != -1) {
			cout << "Add faild!" << endl;
			exit(1);
		}

		t[dd] = qq;
		score += s[dd][qq];
		held[qq].insert(dd);
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score -= c[qq] * range(*litr, *ritr);
		score += c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
	}

	void erase(int dd) {
		if (t[dd] == -1) {
			cout << "Erase faild!" << endl;
			exit(1);
		}
		int qq = t[dd];
		t[dd] = -1;
		score -= s[dd][qq];
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score += c[qq] * range(*litr, *ritr);
		score -= c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
		held[qq].erase(itr);
	}

	void change(int dd, int qq) {
		erase(dd);
		add(dd, qq);
	}

	void save() {
		best_t = t;
		best_score = score;
	}

	void output() {
		for (int i = 0; i < D; i++)
			cout << best_t[i] + 1 << endl;
		// cout << best_score << endl;
	}
};

double dice() {
	return dist_real(generator);
}

double prob(double rem) {
	return 1.0 / pow(3, rem);
}

void tic() {
	start = std::chrono::steady_clock::now();
}

double toc() {
	endt = std::chrono::steady_clock::now();
	std::chrono::duration<double> elapsed_seconds = endt - start;
	return elapsed_seconds.count();
}

int main() {
	int d;
	cin >> d;
	for (int i = 0; i < N; i++)
		cin >> c[i];
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < N; j++) {
			cin >> s[i][j];
		}
	}

	tic();
	int t;
	ContestInfo ci(d);
	for (int i = 0; i < d; i++) {
		t = max_element(s[i], s[i] + N) - s[i];
		ci.add(i, t);
	}

	int current_score = ci.score;
	int best_score = current_score;
	ci.save();

	int dd, qq;
	while (toc() < MAX_T) {
		dd = dist_int(generator) % d;
		qq = dist_int(generator) % N;
		int old_q = ci.t[dd];
		ci.change(dd, qq);
		long new_score = ci.score;
		current_score = new_score;
		// if (new_score < current_score || prob(MAX_T - toc()) < dice())
		if (new_score < current_score)
			ci.change(dd, old_q);
		else
			current_score = new_score;
		if (best_score < current_score) {
			best_score = current_score;
			ci.save();
		}
	}
	ci.output();
}

Measured memory_bytes: 3788
def main():
    n = int(input())
    count = 0
    m = dict()
    for i in range(1, n + 1):
        tmp = str(i)
        t = (tmp[0], tmp[-1])
        if t in m:
            m[t] += 1
        else:
            m[t] = 1
    for i in range(1, n + 1):
        tmp = str(i)
        t = (tmp[-1], tmp[0])
        if t in m:
            count += m[t]
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
local mmi, mma = math.min, math.max
local h, w = io.read("*n", "*n")
if h % 3 == 0 or w % 3 == 0 then print(0)
else
  local mincand = 0
  if 2 < h then
    mincand = w
  end
  if 2 < w then
    if mincand == 0 then mincand = h
    else mincand = mmi(h, mincand)
    end
  end
  if mincand == 0 then
    -- 2 x 2
    print(1)
  else
    local h_cut_pos = h // 3
    if 0 < h_cut_pos then
      local cut1 = h_cut_pos * w
      local rem_h = h - h_cut_pos
      local cut2 = rem_h * (w // 2)
      local cut3 = rem_h * w - cut2
      mincand = mmi(mincand, mma(cut3 - cut2, cut3 - cut1))
    end
    h_cut_pos = h_cut_pos + 1
    do
      local cut1 = h_cut_pos * w
      local rem_h = h - h_cut_pos
      local cut2 = rem_h * (w // 2)
      local cut3 = rem_h * w - cut2
      mincand = mmi(mincand, mma(cut3 - cut2, cut1 - cut2))
    end
    local w_cut_pos = w // 3
    if 0 < w_cut_pos then
      local cut1 = w_cut_pos * h
      local rem_w = w - w_cut_pos
      local cut2 = rem_w * (h // 2)
      local cut3 = rem_w * h - cut2
      mincand = mmi(mincand, mma(cut3 - cut2, cut3 - cut1))
    end
    w_cut_pos = w_cut_pos + 1
    do
      local cut1 = w_cut_pos * h
      local rem_w = w - w_cut_pos
      local cut2 = rem_w * (h // 2)
      local cut3 = rem_w * h - cut2
      mincand = mmi(mincand, mma(cut3 - cut2, cut1 - cut2))
    end
    print(mincand)
  end
end


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

typedef long long ll;
int main() {
    int n, x;
    cin >> n >> x;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    int index = 0;
    while (x > 0 && index < n) {
        if (x >= a[index]) {
            ans++;
            x -= a[index];
            if (index == n - 1 && x > 0) {
                ans--;
                x = 0;
            }
        }
        index++;
    }
    cout << ans;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long l = sc.nextLong();
        long r = sc.nextLong();

        int p = (int) (l % 2019);
        int q = (int) (r % 2019);

        if (r - l >= 2019) {
            System.out.println(0);
            return;
        }

        if (p > q ) {
            System.out.println(0);
            return;
        }

        long min = 1000000;
        for (int i = (int) l ; i < r ; i++) {
            for (int j = i + 1 ; j <= r ; j++) {
                min = Math.min((long) i * j % 2019, min);
            }
        }



        System.out.println(min);

    }

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    string s;
    cin>>s;
    ll n=s.length();
    bool ans=true;
    f(i,0,n){
        if(i%2==0){
            if(s[i]!='h'){
                ans=false;
            }
        }
        else {
            if(s[i]!='i'){
                ans=false;
            }
        }
    }
    if(n%2!=0){
        ans=false;
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
S=raw_input()
N=len(S)
i,k=0,0
while i<N:
    L=[0]*3
    s="JOI"
    for j in range(len(s)):
        while i<N and S[i]==s[j]:
            L[j]+=1
            i+=1
    if L[0]>=L[1] and L[2]>=L[1]:
        k=max(L[1],k)
print k

Measured memory_bytes: 5320
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int dp[50010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    rep(i, 0, 50010) dp[i] = INF;
    vector<int> c(m);
    rep(i, 0, m) cin >> c[i];
    dp[0] = 0;
    rep(i, 0, m){
        rep(j, 0, 50010){
            if(j + c[i] > 50000) continue;
            dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1);
        }
    }
    cout <<  dp[n] << endl;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  int cnt[50]={};
  cin >> n >> m ;
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    cnt[--a]++;
    cnt[--b]++;
  }
  for(int i=0;i<n;i++){
    cout << cnt[i] << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	char x[1002];
	int i;
	char *p;
	
	while(1){
		i=0;
		fgets(x,1002,stdin);
		if(x[0]=='0')break;
		p=x;
		while(*p!='\n'){
			i = i + (*p-'0');
			p++;
		}
		printf("%d\n",i);
	}
		
	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    long long int x, y;
    cin >> x >> y;
    long long int cnt = 0;
    for(long long int i = x;i <= y;i *= 2){
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

/**
 *
 * @author beris
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a, b, c, a1 = 0, b1 = 0, c1 = 0, a2 = 0, b2 = 0, c2 = 0;
        for(int i=0;i<n;i++){
            a = scanner.nextInt();
            b = scanner.nextInt();
            c = scanner.nextInt();
            a1 = a + Math.max(b2, c2);
            b1 = b + Math.max(a2, c2);
            c1 = c + Math.max(a2, b2);
            a2 = a1; b2 = b1; c2 = c1;
        }
        System.out.println(Math.max(a1, Math.max(b1, c1)));
    }
}


Measured memory_bytes: 89736
A = [[] for i in range(8)]
A[0] = list(map(int,input().split()))
A[1] = list(map(int,input().split()))
A[2] = list(map(int,input().split()))
A[3] = [A[0][0],A[1][0],A[2][0]]
A[4] = [A[0][1],A[1][1],A[2][1]]
A[5] = [A[0][2],A[1][2],A[2][2]]
A[6] = [A[0][0],A[1][1],A[2][2]]
A[7] = [A[0][2],A[1][1],A[2][0]]

N = int(input())
b = [int(input()) for i in range(N)]

for i in range(8):
    bingo = True
    for j in range(3):
        if not A[i][j] in b:
            bingo = False
    if bingo:
        print('Yes')
        exit()
print('No')




Measured memory_bytes: 38256