akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define upb upper_bound
#define lwb lower_bound
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y){
    if(y<=0) return 1;
    ll ans = 1;
    x %= mod;
    while(y){
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = (a - b); if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = (a + b); if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

const ll N = 5e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

const int B = sqrt(N); // sqrt(n)

struct Q {
    int L, R, cmp, ind;
    bool operator<(const Q &temp) const {
        return cmp < temp.cmp;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);

	ll n, q;
	cin>>n>>q;
	ll a[n];
	map<ll, vi> mp;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]].pb(i);
	}
	
	int k=0;
	for(auto it : mp){
		for(auto x : it.second){
			a[x] = k;
		}
		k++;
	}
	vi cnt(k);
	
	vector<Q> que(q);
	for(int i=0;i<q;i++){
		cin>>que[i].L>>que[i].R;
		que[i].L--;
		que[i].R--;
		que[i].cmp = (que[i].L/B)*n + que[i].R;
		que[i].ind = i;
	}
	
	sort(all(que));
	
	int l=0, r=-1, dist=0;
	vi ans(q);
	
	auto add = [&](int i) { if (++cnt[i]==1) dist++; };
    auto rem = [&](int i) { if (--cnt[i]==0) dist--; };
    
	for(auto it : que){
		int l1 = it.L;
		int r1 = it.R;
		while(l<l1) rem(a[l++]);
		while(l>l1) add(a[--l]);
		while(r<r1) add(a[++r]);
		while(r>r1) rem(a[r--]);
		ans[it.ind] = dist;
	}

	for(int i=0;i<q;i++){
		cout<<ans[i]<<"\n";
	}
//	cout<<"\n";
	
    return 0;
}


Measured memory_bytes: 78116
#include <iostream>
using namespace std;
int main()
{
    int N,X;
    cin >> N >> X;
    int L[100];
    int D[101];
    int count=0;
    for(int i=0; i<=N; i++)
    {
        if(i==0)
        {
            D[0]=0;
        }
        else
        {
            cin >> L[i-1];
            D[i]=D[i-1]+L[i-1];
        }
        if(D[i]>X) break;
        else count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
ll gcd(ll a,ll b){
  if(a<b) return gcd(b,a);
  if(b==0) return a;
  else return gcd(a%b,b);
}

int main(){
  ll k;
  cin>>k;
  ll sum=0;
  ll x=0;
  ll y=0;
  rep(i,k){
    rep(j,k){
        x=gcd(i+1,j+1);
      rep(l,k){
        y=gcd(x,l+1);
        sum+=y;
      }
    }
        }
        cout<<sum<<endl;
}


Measured memory_bytes: 3636
N, M = list(map(int, input().split()))
A, B = [], []
for _ in range(N):
  a, b = list(map(int, input().split()))
  A.append(a)
  B.append(b)
  
C = sorted(zip(A,B), key=lambda x:x[0])

total=0
i=0
while M>0:
  a = C[i][0]
  b = C[i][1]
  if M<=b:
    total = total + a*M
    M = 0
  else:
    total = total + a*b
    M = M-b
  i+=1
print(total)
   
  


Measured memory_bytes: 19768
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
    std::vector<int> vec(3);
    for (int i = 0; i < vec.size(); i++) {
        std::cin >> vec.at(i);
    }
    std::sort(vec.begin(), vec.end());
    for (int i = 0; i < vec.size(); i++) {
        std::cout << vec.at(i);
        if (i != vec.size() - 1) {
            std::cout << ' ';
        }
    }
    std::cout << std::endl;
}



Measured memory_bytes: 3136
import math
a, b = map(int, input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if a>=2 and b>=2:
  print(combinations_count(a,2)+combinations_count(b,2))  
elif a>=2:
  print(combinations_count(a,2))
elif b>=2:
  print(combinations_count(b,2))
else:
  print("0")

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

#define rep(i,n)  for(int i=0;i<n;++i)
#define sc1(a)  scanf("%d",&a)

int main(){
    int mod=1000000007;
    int n,p,ans=-mod;
    sc1(n);
    sc1(p);
    rep(i,n-1) {
        int r;
        sc1(r);
        ans=max(ans,r-p);
        p=min(p,r);
    }
    printf("%d\n",ans);
    return 0;
}



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

public class Main {

	public class Dice {

		int[] diceInit = new int[6];
		int[] dice = new int[6];

		/**
		 * サイコロを用意する
		 * @param nums
		 */
		public Dice(int[] nums) {
			dice = nums;
			diceInit = nums;
		}

		/**
		 * サイコロの状態を確認
		 */
		public int[] checkSurface() {
			return dice;
		}


		/**
		 * 入力された方向に移動
		 * @param order
		 */
		public void move(String order) {

			for(Character s : order.toCharArray()) {
				int buf;
				switch(s){
				case 'N':{
					buf = dice[0];
					dice[0] = dice[1];
					dice[1] = dice[5];
					dice[5] = dice[4];
					dice[4] = buf;
					break;
				}
				case 'E':{
					buf = dice[0];
					dice[0] = dice[3];
					dice[3] = dice[5];
					dice[5] = dice[2];
					dice[2] = buf;
					break;
				}
				case 'W':{
					buf = dice[0];
					dice[0] = dice[2];
					dice[2] = dice[5];
					dice[5] = dice[3];
					dice[3] = buf;
					break;
				}
				case 'S':{
					buf = dice[0];
					dice[0] = dice[4];
					dice[4] = dice[5];
					dice[5] = dice[1];
					dice[1] = buf;
					break;
				}
				case 'R': {
					buf = dice[1];
					dice[1] = dice[2];
					dice[2] = dice[4];
					dice[4] = dice[3];
					dice[3] = buf;
				}
				}
			}
		}

		/**
		 * 指定された状態になるまで回転を行う
		 * @param upper
		 * @param flont
		 * @return dice サイコロの状態
		 */
		public int[] checkRight(int upper, int front) {

			// サイコロを初期状態にリセット
			dice = diceInit;

			// 上面が指定の面になるまで回転
			for(int i=0; i<3; i++) {
				if(dice[0] == upper) break;
				move("W");
			}
			if(dice[0] != upper) {
				for(int i=0; i<3; i++) {
					if(dice[0] == upper) break;
					move("N");
				}
			}

			// 正面が指定の面になるまで回転
			for(int i=0; i<3; i++) {
				if(dice[1] == front) break;
				move("R");
			}

			return dice;
		}

	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		Boolean diffFlag = true;

		// 入力数分サイコロ面を用意する
		int diceNum = sc.nextInt();
		int[][] nums = new int[diceNum][6];
		for(int i=0; i<diceNum; i++) {
			for(int j=0; j<6; j++) {
				nums[i][j] = sc.nextInt();
			}
		}

		sc.close();

		// はじめに入力されたものとその他のものが同じかどうかをチェック
		Dice firstDice = new Main().new Dice(nums[0]);
		int[] firstDiceSurface = firstDice.checkSurface();

		for(int i=1; i<diceNum; i++) {
			Dice checkDice = new Main().new Dice(nums[i]);
			int[] otherDiceSurface = checkDice.checkRight(nums[0][0], nums[0][1]);
			if(Arrays.equals(firstDiceSurface, otherDiceSurface)) {
				diffFlag = false;
				break;
			}
		}

		if(diffFlag) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}



Measured memory_bytes: 28508
#include<stdio.h>
 
int main()
{
   int n, x, i, j, k;
   int A;
 
   while(1) {
      scanf("%d %d", &n, &x);
      A = 0;
      if(n==0 && x==0)
         break;
      for(i=1; i<=n-2; i++) {
         for(j=i+1; j<=n-1; j++) {
            for(k=j+1; k<=n; k++) {
               if(i+j+k == x) {
                  A++;
               }
            }
         }
      }
      printf("%d\n", A);
   }
   return 0;
}
 
                      

Measured memory_bytes: 600
#include <iostream>
#include <string>

using namespace std;

int main () {
   int N;
   cin>>N;
   string S;
   cin>>S;
   if (((N%2==0)) and (S.compare(0,N/2,S,N/2,N/2)==0))
           cout<<"Yes";
   else
       cout<<"No";
   return 0;}


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


int main(){
    int n; cin >> n;
    ll ma = -1;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        if(ma < a[i]) ma = a[i];
    }

    ll pre = 300;
    ll sum = 1000,cnt = 0;
    rep(i,n){

        if(pre < a[i] && cnt>0){
            sum += a[i] * cnt;
            cnt = 0;
        }
        if(pre!=300) sum += pre * cnt;
        if(ma > a[i] && sum / a[i]>0){
            cnt = sum / a[i];
            sum -= a[i] * cnt;
            pre = a[i];
        }
    }
    sum += pre * cnt;
    cout << sum << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
typedef long long int ll;


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  long long sum,O=0;
  cin>>N;
  vector<int> d(N,0);
  for(int i=0;i<N;i++){
    cin>>d[i];
    sum+=d[i];
  }
  for(int i=0;i<N-1;i++){
    sum-=d[i];
    O+=d[i]*sum;
  }
  cout<<O<<endl;
}

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

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const long long INF = ((1<<31) -1);
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

//セグメント木によるRMQの実装(Range Minimum Query)
//セグメント木はモノイド（例:和、積、min, max, gcd, lcm)に使える((a*b)*c=a*(b*c) かつ 単位元eが存在)
//関数は、init, update, query
const int MAX_N = 1 << 17;
int n_edited; //頂点数
int seg_dat[2 * MAX_N - 1];

void init(int n_){ //初期化、要素数を２のべき乗(n_edited)にする
    n_edited=1; // n_editedの初期化
    while(n_edited<n_){
        n_edited *= 2;
    }
    for(int i=0; i<2*n_edited-1;i++){
        seg_dat[i] = INF; //最小値を求めるから、INFで初期化
    }
}

void update(int k, int a){ //k(0-indexed)番目の値をaに変更
    k += n_edited-1;
    seg_dat[k] = a;
    while(k>0){
        k = (k-1)/2;
        seg_dat[k] = min(seg_dat[k*2+1],seg_dat[k*2+2]); //最小値なので
    }
}

int query(int a,int b,int k,int l,int r){ //[a,b)の最小値を求める、外側からは query(a,b,0,0,n_edited) で呼ぶ
    // kは
    if(r<=a || b <= l){
        return INF; //最小値なので
    }
    if(a<=l && r<= b){
        return seg_dat[k];
    }
    else{
        int vl = query(a,b,k*2+1,l,(l+r)/2);
        int vr = query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr); //最小値なので
    }
}

signed main(){
    int n,q;
    cin >> n >> q;
    init(n);
    REP(i,q){
        int c1,x1,y1;
        cin >> c1 >> x1 >> y1;
        if(c1==0){
            update(x1,y1);
        }
        else{
            cout << query(x1,y1+1,0,0,n_edited) << endl;
        }
    }

    



    return 0;
}


Measured memory_bytes: 5148
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int n;
  cin >> n;
  if(n < 1200) cout << "ABC" << endl;
  else if(n < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl; 

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

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

  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i += 2) {
    map<ll, int> mp = prime_factor(i);
    int c = 1;
    for (auto m : mp)
      c *= m.second + 1;
    if (c == 8)
      ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3624
#include<stdio.h>
int main(void)
{
	int t,n,i,g;
	for (i=0;i<4;i++){
		scanf("%d%d",&t,&n);
		if (t==1){
			g=6000*n;
			printf("%d\n",g);
		}
		else if (t==2){
			g=4000*n;
			printf("%d\n",g);
		}
		else if (t==3){
			g=3000*n;
			printf("%d\n",g);
		}
		else if (t==4){
			g=2000*n;
			printf("%d\n",g);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

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

	int count = 0;
	for(int i=1; i<=N; i++)
	{
		int p;
		cin >> p;

		if(p != i)
		{
			count++;
		}
	}
	if((count == 0) || (count == 2))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort()
r = 10**20
for xi0 in range(N - K + 1):
  for xi1 in range(K + xi0 - 1, N):
    x = XY[xi1][0] - XY[xi0][0]
    XY_ys = sorted(XY[xi0:xi1 + 1], key=lambda a: a[1])
    for yi0 in range(len(XY_ys) - K + 1):
      y = XY_ys[yi0 + K - 1][1] - XY_ys[yi0][1]
      r = min(r, x * y)
print(r)

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

int main() {
	int A, B;

	cin >> A >> B;

	int ans = 0;
	if( A >= 13 ) {
		ans = B;
	}
	else if( A >= 6 ) {
		ans = B / 2;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import numpy as np
i8 = np.int64
i4 = np.int32

def solve(A, N):
    MOD = 1000000007
    x = 0
    y = 0
    z = 0
    count = 1
    for i in range(N):
        if A[i] == x:
            if x == y and x == z:
                count = (count * 3) % MOD
            elif x == y:
                count = (count * 2) % MOD
            x += 1
        elif A[i] == y:
            if y == z:
                count = (count * 2) % MOD
            y += 1
        elif A[i] == z:
            z += 1
        else:
            return 0
    return count

def main2():
    stdin = open('/dev/stdin')
    N = int(stdin.readline())
    A = np.empty(N, i8)
    for i, c in enumerate(map(int, stdin.readline().split())):
        A[i] = c
    print(solve(A, N))

main2()

Measured memory_bytes: 19600
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var xab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(Abs(xab[0] - xab[1]) < Abs(xab[0] - xab[2]) ? "A" : "B");
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <math.h>
 
int isprime(int);
 
int main(){
 
  int seisu[10000],i,r,s=0,n;
 
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&seisu[i]);
    
  }
 
  for(i=0;i<n;i++){
    r=isprime(seisu[i]);
    if(r==1) s++;
  }
 
  printf("%d\n",s);
 
  return 0;
}
 
 
 
int isprime(int x){
  int i;
    
  if(x==2) return 1;
  else if(x<2 || x%2==0) return 0;
   
  i=3;
  while(i<=sqrt(x)){
    if(x%i==0) return 0;
      i=i+2;
  }
         return 1;
     
  } 

Measured memory_bytes: 628
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    int n, m, s;
    cin >> n >> m >> s;
    int u, v, a, b, amax = 0;
    vector<vector<pair<int, PLL>>> graph(n+1);
    vector<PLL> ex(n+1);
    for (int i = 0; i < m; i++) {
        cin >> u >> v >> a >> b;
        amax = std::max(amax, a);
        graph[u].push_back({v, {a, b}});
        graph[v].push_back({u, {a, b}});
    }
    for (int i = 1; i <= n; i++) {
        cin >> u >> v;
        ex[i] = {u, v};
    }

    map<pair<int, int>, ll> dist;
    set<pair<ll, pair<int, int>>> pq;
    set<pair<int, int>> visited;
    s = min(s, amax*n);

    dist[{1, s}] = 0;
    pq.insert({0, {1, s}});

    int count = 0, l = 0, edges = 0;

    while (!pq.empty()) {
        auto it = pq.begin();
        auto top = *it;
        pq.erase(it);
        visited.insert(top.second);

        int vertex = top.se.fi;
        ll coins = top.se.se;
        ll time = top.fi;
        
        if (coins + ex[vertex].fi < amax*n) {
            PLL state = {vertex, coins + ex[vertex].fi};
            if (visited.find(state) == visited.end() and ((dist.find(state) == dist.end()) or (dist[state] > time + ex[vertex].se))) {
                pq.erase({dist[state], state});
                dist[state] = time + ex[vertex].se;
                pq.insert({dist[state], state});
            }
        }

        for (auto x : graph[vertex]) {
                if (coins < x.se.fi)
                    continue;
                PII state = {x.fi, coins - x.se.fi};
                if ((visited.find(state) == visited.end()) and ((dist.find(state) == dist.end()) or (dist[state] > time + x.se.se))) {
                    pq.erase({dist[state], state});
                    dist[state] = time + x.se.se;
                    pq.insert({dist[state], state});
                }
            }

    }

    vector<ll> ans(n+1, LLONG_MAX);
    for (auto x : dist) {
        ans[x.fi.fi] = min(ans[x.fi.fi], x.se);
    }
    for (int i = 2; i <= n; i++)
        cout << ans[i] << "\n";
}



Measured memory_bytes: 17888
h,w=map(int,input().split())

if h%3==0 or w%3==0:
    print("0")
    exit()
#print(h*w)
ans=10**100**2
    #hが大きい方とみなす
if h<w:
    comp=h
    h=w
    w=comp
ans=min(ans,(h//3+1)*w-h//3*w)
#print(ans)
#print(h*w)
for i in range(1,w):
    green = h*i 
    red   = (h//2) * (w-i)
    blue  = h*w-red-green#三等分に分ける
    #print(green,red,blue)
    ma=max(green,red,blue)#一番大きい長方形
    mi=min(green,red,blue)#一番小さい長方形
    #print(green,red,blue,ma-mi)
   
    ans=min(ans,ma-mi)
comp=w
w=h
h=comp
for i in range(1,w):
    green = h*i 
    red   = (h//2) * (w-i)
    blue  = h*w-red-green#三等分に分ける
    ma=max(green,red,blue)#一番大きい長方形
    mi=min(green,red,blue)#一番小さい長方形
    #print(green,red,blue,ma-mi)
   
    ans=min(ans,ma-mi)

print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int S[100100];
int main(){
    int N, M;
    cin >> N >> M;
    REP(i,M){
        int l, r;
        cin >> l >> r;
        l--, r--;
        S[l]++;
        S[r+1]--;
    }

    REP(i,N){
        S[i+1] += S[i];
    }

    ll ans = 0;
    REP(i,N){
        int s = S[i];
        if(s == M){
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}


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

namespace Hello
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            int b;
            int h;
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            h = int.Parse(Console.ReadLine());
            //Console.WriteLine("台形の面積:"+((a+b)*h)/2);
            Console.WriteLine(((a + b) * h) / 2);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 2776
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<int>;


int main()
{
	ll N, A, B;
	cin >> N >> A >> B;

	vec h(N);
	for (int i = 0; i < N; ++i)cin >> h[i];

	ll ans = 0;

	for (int i = 31; i >= 0; --i)
	{
		ll x = ans + (1ll << i);

		ll count = 0;
		for(const auto hp : h)
		{
			count += max(0ll, (hp - B*x + A - B - 1) / (A - B));
		}
		
		if (count > x)ans = x;
	}

	cout << ans+1 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
     
     
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;

unordered_map<ll, ll> memo1{};
unordered_map<ll, ll> memo2{};

ll as[3];
ll bs[3];

ll dp1(ll x){
  if(x == 0) return 0;
  if(memo1.count(x) > 0) return memo1[x];

  ll tmp_max = -1;
  for(int i = 0; i < 3; i++){
    if(x >= as[i]){
      ll tmp_val = dp1(x - as[i]) + bs[i];
      if(tmp_max < tmp_val) tmp_max = tmp_val;
    }
  }

  if(tmp_max < x) tmp_max = x;

  memo1[x] = tmp_max;
  return tmp_max;
}

ll dp2(ll x){
  if(x == 0) return 0;
  if(memo2.count(x) > 0) return memo2[x];

  ll tmp_max = -1;
  for(int i = 0; i < 3; i++){
    if(x >= bs[i]){
      ll tmp_val = dp2(x - bs[i]) + as[i];
      if(tmp_max < tmp_val) tmp_max = tmp_val;
    }
  }

  if(tmp_max < x) tmp_max = x;  

  memo2[x] = tmp_max;
  return tmp_max;
}

int main(){
  ll N;

  cin >> N;

  for(int i = 0; i < 3; i++){
    cin >> as[i];
  }

  for(int i = 0; i < 3; i++){
    cin >> bs[i];
  }
  

#ifdef DEBUG
  cout << N << endl;
  cout << "as: ";
  for(int i = 0; i < 3; i++){
    cout << as[i] << " ";
  }
  cout << endl;

  cout << "bs: ";
  for(int i = 0; i < 3; i++){
    cout << bs[i] << " ";
  }
  cout << endl;
#endif

  ll dp1[N+1];
  for(int i = 0; i < N+1; i++){
    ll tmp_max = i;
    for(int j = 0; j < 3; j++){
      if(i >= as[j]){
	ll tmp_val = dp1[i - as[j]] + bs[j];
	if(tmp_max < tmp_val) tmp_max = tmp_val;
      }
    }
    dp1[i] = tmp_max;
  }

  ll dp2[dp1[N]+1];
  for(int i = 0; i < dp1[N]+1; i++){
    ll tmp_max = i;
    for(int j = 0; j < 3; j++){
      if(i >= bs[j]){
  	ll tmp_val = dp2[i - bs[j]] + as[j];
  	if(tmp_max < tmp_val) tmp_max = tmp_val;
      }
    }
    dp2[i] = tmp_max;
  }

  cout << dp2[dp1[N]] << endl;
  
  return 0;
}


Measured memory_bytes: 195584
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let N = Number(xs[0]);
   let K = Number(xs[1]);
   let x = xs[2].split(' ').map(v=>parseInt(v,10));
   
   let ans = 0;
   let sum = 0;
  
   for(let i=0; i<N; i++){
     let x1 = x[i];
     let x2 = K-x[i];
     
     if(x1>x2){
        sum = x2*2;
        ans +=sum; 
     }else{
        sum = x1*2;
        ans +=sum;
     }
   }
   console.log(ans);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

int main() {
  int N;
  cin >> N;
  
  int A, count;
  int min = -1;
  for (int i=0; i<N; i++) {
    cin >> A;
    count = 0;
    while (A % 2 == 0) {
      A /= 2;
      count++;
    }
    if (min > count || min < 0) {
      min = count;
      if (min == 0)
        break;
    }
  }
  cout << min << endl;
}
        


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  ll N, R;
  cin >> N >>R;
  if(N >= 10)cout<<R<<endl;
  else cout<<R+100*(10-N)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    char s[10];
    scanf("%s",&s);
    
    if(s[0]=='S'){
        printf("Cloudy");
    }
    if(s[0]=='C'){
        printf("Rainy");
    }
    if(s[0]=='R'){
        printf("Sunny");
    }
    return 0;
}


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

using namespace std;

const int N = 200100;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);


int lis(int a[], int n){
	vector <int> A(n, INF);
	for(int i = 0; i < n; i++){
		*lower_bound(A.begin(), A.end(), a[i]) = a[i];
	}
	return find(A.begin(), A.end(), INF) - A.begin();
}

int main(){

	int x1, y1, x2, y2;
	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	int W = abs(x2-x1), H = abs(y2-y1);
	bool flipx = x1 > x2, flipy = y1 > y2;
	int N;
	scanf("%d", &N);
	vector <pair<int,int> > points;
	for(int i = 0; i < N; i++){
		int X, Y;
		scanf("%d%d", &X, &Y);
		X -= x1; Y -= y1;
		if(flipx) X = -X;
		if(flipy) Y = -Y;
		if(0 <= X && X <= W && 0 <= Y && Y <= H){
			points.push_back(make_pair(X, Y));
		}
	} 
	sort(points.begin(), points.end());
	vector <int> vy;
	for(auto p : points){
		vy.push_back(p.second);
	}
	int num = vy.empty() ? 0 : lis(vy.data(), (int)vy.size());
	double ans = (W+H)*100.0;
	if(num < min(W,H) + 1){
		ans -= num * (20 - PI*5.0);
	} 
	else{
		ans -= (num - 1) * (20 - PI*5.0);
		ans += (10*PI - 20);
	}
	printf("%.10lf", ans);
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1,y1,x2,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
int vx=x2-x1, vy=y2-y1;
int x3,y3,x4,y4;
x3=x2 + -vy;
y3=y2 + vx;
x4=x3 -vx;
y4=y3-vy;
printf("%d %d %d %d",x3,y3,x4,y4);
cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main(){
	while(1){
		int a;
		cin>>a;
		
		if(a==-1)break;
		
		
		double x = 1;
		double y = 1;
		
		for(int i=0;i<a-2;i++){
			double len = sqrt(x*x + y*y);
			
			double dx = x / len;
			double dy = y / len;
			
			double nx = -dy;
			double ny = dx;
			
			x += nx;
			y += ny;
			
			
		}
		printf("%lf\n%lf\n",x,y);
	}
	
	
}

Measured memory_bytes: 1192
#include <stdio.h>
#include <math.h>
int main(){
	int i,n,a[10000],max=-1000000,min=1000000;
	long sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		min=fmin(min,a[i]);
		max=fmax(max,a[i]);
		sum+=a[i];
	}
	printf("%d %d %ld\n",min,max,sum);
	return 0;
}
		

Measured memory_bytes: 1892
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{a:[u64;3]};
    let mut a = a;
    a.sort();
    println!("{}", if a.iter().filter(|&x| *x%2==0).count() != 0 {0} else {a[0]*a[1]});
}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;

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

  int ps[N];
  int maxPrice;
  for (int i = 0; i < N; i++) {
    cin >> ps[i];
    maxPrice = max(maxPrice, ps[i]);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (ps[i] == maxPrice) {
      ps[i] /= 2;
      maxPrice = 0;
    }
    ans += ps[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};//URDL
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

class Edge{
public:
  int to;
  int distance;
  int cost;
  int road_idx;
  Edge(int _t,int _d,int _c,int _r) : to(_t),distance(_d),cost(_c),road_idx(_r) {}
  Edge() {}
  bool operator<(const Edge& e) const{
    return distance < e.distance;
  }

  bool operator>(const Edge& e) const{
    return distance > e.distance;
  }
};

class State {
public:
  int city;
  int total_distance;
  int total_cost;
  int prev_road;
  State(int _c,int _td,int _tc,int _pr) : city(_c), total_distance(_td), total_cost(_tc),prev_road(_pr) {}
  bool operator<(const State& s) const{
    return total_distance < s.total_distance;
  }
  bool operator>(const State& s) const{
    return total_distance > s.total_distance;
  }
};

int main(){
  int total_cities;
  int total_roads;
  while(~scanf("%d %d",&total_cities,&total_roads)){
    if(total_cities == 0 &&  total_roads == 0) break;

    vector<Edge> edges[20001];

    int road_cost[20001];
    memset(road_cost,0,sizeof(road_cost));

    for(int road_idx = 0; road_idx < total_roads; road_idx++){
      int from,to,distance,cost;
      scanf("%d %d %d %d",&from,&to,&distance,&cost);
      edges[from-1].push_back(Edge(to-1,distance,cost,road_idx));
      edges[to-1].push_back(Edge(from-1,distance,cost,road_idx));
      road_cost[road_idx] = cost;
    }
    
    int dp[20001];
    memset(dp,0x3f,sizeof(dp));

    priority_queue<State,vector<State>,greater<State> > que;
    que.push(State(0,0,0,-1));
    
    while(!que.empty()){
      State s = que.top();
      que.pop();

      if(dp[s.city] <= s.total_distance) continue;
      dp[s.city] = s.total_distance;

      for(int i=0;i<edges[s.city].size();i++){
	int to = edges[s.city][i].to;
	int next_distance = edges[s.city][i].distance;
	int next_cost = edges[s.city][i].cost;

	que.push(State(to,s.total_distance + next_distance,s.total_cost + next_cost,i));
      }
    }

    int res = 0;
    for(int to=1; to<total_cities; to++){
      int min_v = INF;
      for(int from_idx=0; from_idx<edges[to].size(); from_idx++){
	int from = edges[to][from_idx].to;
	int distance = edges[to][from_idx].distance;
	int cost = edges[to][from_idx].cost;
	
	//check whether the path is corresponding to the dijkstra's shortest path or not
	if(dp[from] + distance == dp[to] && cost < min_v){
	  min_v = cost;
	}
      }
      res += min_v;
    }

    printf("%d\n",res);
  }
}

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

int main(){
	ll  w, h;
	cin >> w >> h;
  	if(w==1 || h==1){
      cout << 1;
    }else{
		cout << (w*h+1)/2;
    }
	
		
	
}


Measured memory_bytes: 256
import itertools

N = int(input())
S = [str(input()) for _ in range(N)]

#MARCH
L = [0]*5
for i in range(N):
    if S[i][0]=="M":
        L[0] += 1
    elif S[i][0]=="A":
        L[1] += 1
    elif S[i][0]=="R":
        L[2] += 1
    elif S[i][0]=="C":
        L[3] += 1
    elif S[i][0]=="H":
        L[4] += 1

res = 0
for l in itertools.permutations(L,3):
    c = 1
    for x in l:
        c *= x
    res += c
print(res//6)

Measured memory_bytes: 9776
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007

using namespace std;
typedef long long ll;

int num, k;

ll Inverse(ll a) {
	ll i = MOD - 2, ans = 1;
	while (i > 0) {
		if (i & 1) {
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		i >>= 1;
	}
	return ans;
}

ll Combi(ll a, ll b, vector<ll> &d) {
	if (a < b)
		return 0;
	if (b == a || b == 0)
		return 1;
	ll ans = d[a];
	ans *= Inverse(d[b]);
	ans %= MOD;
	ans *= Inverse(d[a - b]);
	ans %= MOD;
	return ans;
}

void Ini(vector<ll> &d) {
	ll a = 1, i;
	for (i = 1; i <= num; i++) {
		a *= i;
		a %= MOD;
		d[i] = a;
	}
	return;
}

int main(void) {
	ll ans;
	cin >> num >> k;
	vector<ll> d(num), fac(num + 1);
	Ini(fac);
	for (int i = 1; i <= k; i++) {
		ans = Combi(num - k + 1, i, fac);
		ans *= Combi(k - 1, i - 1, fac);
		ans %= MOD;
		cout << ans << "\n";
	}
	return 0;
}

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

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	
	int cnt = 0;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'B') cnt++;
		else ans += cnt;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1156
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    long long  n,m=0,k=0,i,x=1E10,sum=0,y;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>y;
        if(y<0)
            m++;
        sum+=abs(y);

        x=min(abs(y),x);
    }
        if(m%2==0)
            cout<<sum<<endl;
        else
            cout<<sum-x*2<<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;
typedef long long ll;
typedef pair<int,int> P;

int main() {
    int a, b; cin >> a >> b;
    if((a+b)%2==0) cout << (a+b)/2 << endl;
    else cout << "IMPOSSIBLE" << endl; 
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
string x="Possible\n",y="Impossible\n";
int main() {
	int a,b;
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0)
	cout<<x;
	else cout<<y;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <limits>
#include <iomanip>

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

int main() {
    char c;
    cin >> c;
    cout << char(c+1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(ll i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(ll i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

#define print(d, arr) REP(i, d) cout << arr[i] << " "; cout << endl;
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }

int main() {
    ll A, B;
    cin >> A >> B;
    
    if ((A + B) % 2 == 0) {
        cout << (A + B) / 2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
M, N = map(int, input().split())
K = int(input())
P = ['_' * (N + 1) for _ in range(M + 1)]
for mi in range(1, M + 1):
    P[mi] = '_' + input()
# for p in P:
#     print('p', p)

J = [[0 for _ in range(N + 1)] for _ in range(M + 1)]
O = [[0 for _ in range(N + 1)] for _ in range(M + 1)]
I = [[0 for _ in range(N + 1)] for _ in range(M + 1)]
for i in range(1, M + 1):
    ji, oi, ii = 0, 0, 0
    for j in range(1, N + 1):
        ji += P[i][j] == 'J'
        oi += P[i][j] == 'O'
        ii += P[i][j] == 'I'
        J[i][j] = J[i - 1][j] + ji
        O[i][j] = O[i - 1][j] + oi
        I[i][j] = I[i - 1][j] + ii
# for j in J:
#     print('j', j)
# for o in O:
#     print('o', o)
# for i in I:
#     print('i', i)


def cum(mat, a, b, c, d):
    a -= 1
    b -= 1
    return mat[a][b] + mat[c][d] - mat[a][d] - mat[c][b]


for k in range(K):
    a, b, c, d = map(int, input().split())
    j = cum(J, a, b, c, d)
    o = cum(O, a, b, c, d)
    i = cum(I, a, b, c, d)
    print(j, o, i)



Measured memory_bytes: 126736
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;
const int maxn=15;
const int mod=2e5;

int dp[maxn][maxn],k,tot[maxn];

int add(int &a,int b){
	a=(a+b)%mod;
}

int main(){
	cin>>k;
	for(int t=0;t<10;t++) dp[1][t]=1;
	for(int i=1;i<=10;i++){
		for(int t=0;t<10;t++){
			if(t-1>=0) add(dp[i+1][t-1],dp[i][t]);
			if(t+1<=9) add(dp[i+1][t+1],dp[i][t]); 
			add(dp[i+1][t],dp[i][t]);
		}
		for(int t=1;t<10;t++){
			add(tot[i],dp[i][t]);
		}
		add(tot[i],tot[i-1]);
	}
	int len=1,sum=0;
	for(;;){
		for(int t=1;t<10;t++){
			sum+=dp[len][t];
		}
		if(sum>=k) break;
		len++;
	}
	int mini=0,maxi=9;
	dp[len][0]=tot[len-1];
	string ans="";
	for(int i=len;i>=1;i--){
		for(int t=mini;t<=maxi;t++){
			if(dp[i][t]>=k){
				mini=max(0,t-1);
				maxi=min(9,t+1);
				ans+=char('0'+t);
				break;
			}
			else{
				k-=dp[i][t];
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define Int int64_t
using namespace std;

int N,M,A,B,C,K;
int main()
{
    cin>>N>>M;
    vector<Int> A(M);
    for(auto &x:A) cin>>x;
    Int sum=0;
    sort(A.begin(),A.end());
    vector<Int> diff;
    for(int i=1;i<M;++i){
        sum=A[i]-A[i-1];
        diff.pb(sum);
    }
    sort(diff.begin(),diff.end());
    Int ans=accumulate(diff.begin(),diff.end(),0);
    int j=diff.size();int k=0;
    for(int i=j-1;i>=0&&k<N-1;--i,++k) ans-=diff[i];
    cout<<ans<<"\n";
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long int x,long long int y)
{
   return x>y;
}
int main(void)
{
   long long int t,n,x,y,a[100001];
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq;
   priority_queue< long long int,vector<long long int>,greater<long long int> > lpq;
   priority_queue< pair<long long int,long long int>,vector< pair<long long int,long long int> >,greater< pair <long long int,long long int> > > plpq;
   string s;
   cin>>x>>y;
   cout<<x*y;
   return 0;
}


Measured memory_bytes: 3624
// JavaProgram.cpp
// Author : Priydarshi Singh (@dryairship)
// One cat just leads to another. One bug leads to two others.

#include <bits/stdc++.h>
using namespace std;

// I like my types defined.
typedef long long           ll;
typedef pair<int, int>      pii;
typedef pair<ll, ll>        pll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef vector<pii>         vii;
typedef vector<pll>         vll;
typedef set<int>            si;
typedef map<string, int>    msi;
typedef map<int, int>       mii;

// Traditional science is all about finding "hashtag define"s.
#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n, c)        for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define fill1(a)            memset(a, -1, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define ff                  first
#define ss                  second
#define pb                  push_back 
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

// When you realize MOD > INF...
int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const ll LINF    =          1e18;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

// I'D SPAM. Hehe.
ll gcdEx                    (ll a, ll b, ll *x, ll *y){if(!a){*x=0;*y=1;return b;} 
ll x1,y1,gcd=gcdEx          (b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
ll modI(ll b, ll m)         {ll x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}
ll modD(ll a, ll b)         {return (modI(b,MOD)*(a%MOD))%MOD;}
ll modS(ll a, ll b)         {return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;} y=y>>1; x=(x*x)%MOD;} return r;}
ll modA(ll a, ll b)         {return ((a%MOD)+(b%MOD))%MOD;}
ll modM(ll a, ll b)         {return ((a%MOD)*(b%MOD))%MOD;}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(int TEST_CASE){
    string s,t;
    cin >>s;
    cin >> t;
    if(t.length()!=s.length()+1){
        cout << "No";
        return;
    }
    fr(i,s.length()){
        if(s[i]!=t[i]){
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>

int vis[51][51];

void emp(){
  int i,j;
for(i=0;i<51;i++){
    for(j=0;j<51;j++){
      vis[i][j]=0;
    }
  }
}
  
  
void dfs(int i,int j){
  if(vis[i][j]==0)return;
  vis[i][j]=0;
  
      dfs(i-1,j-1);
      dfs(i-1,j);
      dfs(i-1,j+1);
      dfs(i,j-1);
      dfs(i,j+1);
      dfs(i+1,j-1);
      dfs(i+1,j);
      dfs(i+1,j+1);
}

int main(){
  int i,j,w,h,cnt;
  
  while(1){
    emp();
    cnt=0;
    scanf("%d%d",&w,&h);
    if(w==0 && h==0)break;
    
    for(i=1;i<h+1;i++){
      for(j=1;j<w+1;j++){
	scanf("%d",&vis[i][j]);
      }
    }
    
    for(i=1;i<h+1;i++){
      for(j=1;j<w+1;j++){
	if(vis[i][j]!=0){
	  cnt++;
	}
	dfs(i,j);
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}  

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,m;
  cin>>n>>m;
  if(m<=n){
    cout<<0<<endl;
    return 0;
  }
  vector<int> v(m);
  vector<int> diff;
  for(int i=0;i<m;i++)cin>>v[i];
  sort(v.begin(), v.end());

  for(int i=1;i<m;i++){
    int p=abs(v[i]-v[i-1]);
    diff.push_back(p);
  }

  sort(diff.begin(), diff.end());
  ll res=0;
  int cnt=0;
  for(auto t : diff){
    res += t;
    cnt++;
    if(cnt==m-n)break;
  }
  cout<<res<<endl;

  return 0;
}


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

using namespace std;

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF 1000000007
#define PI 3.141592653
#define inf 100007
#define P pair<ll,ll>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

int ans=inf;
void opr(string s,int count,char c){
    int cr=0;
    string p="";
    pan(i,(int)s.size()-1){
        if(s[i]==c || s[i+1]==c) p+=c;
        else{
            cr++;
            p+=s[i];
        }
    }
    count++;
    if(cr!=0)
        opr(p,count,c);
    else {
        ans=min(ans,count);
    }
}

int main(){
    string s;
    cin>>s;
    int count=0;
    pan(i,(int)s.size()-1){
        if(s[i]==s[i+1]) count++;
    }
    if(count==(int)s.size()-1) cout<<0;
    else{
        for(int i=0;i<26;i++){
            char c='a'+i;
            opr(s,0,c);
        }
        cout<<ans;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define show(x) cout<<#x" = "<<x<<endl;
#define show2(x,y) cout<<#x" = "<<x<<" "<<#y<<" = "<<y<<endl;
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> iipair;
typedef pair<unsigned,unsigned> uupair;
typedef vector<int> vec;
typedef vector<unsigned> uvec;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    unsigned n;
    cin>>n;
    cout<<(n/2 + (n&1));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100010
using namespace std;
long long n,a[N],b,p,i,ans=0;
int main(){
	cin>>n;
	for(i=0;i<=n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		cin>>b;
		ans+=min(b,a[i]+a[i+1]);
		p=a[i];
		a[i]-=min(a[i],b);
		b-=min(p,b);
		a[i+1]-=min(a[i+1],b);
		b=0;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
import sys

def solve():
    input = sys.stdin.readline
    W, H, x, y = map(int, input().split())
    xleft, xright = x * H, (W - x) * H
    ydown, yup = W * y, W * (H -y)
    if x == W / 2 and y == H / 2: print(W * H /2, 1)
    else: print(W * H / 2, 0)
    return

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064