akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allg(v) v.begin(), v.end(), greater<int>()



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

  int w, h, n;
  cin >> w >> h >> n;
  int min_x = 0, min_y = 0;
  int max_x = w, max_y = h;
  
  int x, y, a;
  rep(i, 0, n) {
    cin >> x >> y >> a;
    if(a == 1) min_x = max(min_x, x);
    if(a == 2) max_x = min(max_x, x);
    if(a == 3) min_y = max(min_y, y);
    if(a == 4) max_y = min(max_y, y);    
  }
  if(max_x <= min_x or max_y <= min_y) 
    cout << 0 << "\n";
  else
    cout << (max_x-min_x)*(max_y-min_y) << "\n";

}

Measured memory_bytes: 256
import std.stdio;
import std.math;
import std.algorithm;
import std.typecons;
import std.functional;

const int C = 100000007;

alias Tuple!(int, "y", int, "x") Pair;

void main() {
    int r, c, a1, a2, b1, b2; readf("%d %d %d %d %d %d\n", &r, &c, &a1, &a2, &b1, &b2);
    Pair[] ps;
    foreach (i; -1 .. 1 + 1) {
        foreach (j; -1 .. 1 + 1) {
            ps ~= Pair(b1 + i * r, b2 + j * c);
        }
    }
    int d = int.max;
    int count = 0;
    int y, x;
    foreach (i; 0 .. 9) {
        int _y = max(a1, ps[i].y) - min(a1, ps[i].y);
        int _x = max(a2, ps[i].x) - min(a2, ps[i].x);
        if (d == _y + _x) {
            count++;
        }
        else if (d > _y + _x) {
            y = _y;
            x = _x;
            d = y + x;
            count = 1;
        }
    }
    y++; x++;
    int[][] dp = new int[][y];
    foreach (ref _; dp) _ = new int[x];
    foreach (i; 0 .. y) dp[i][0] = 1;
    foreach (j; 0 .. x) dp[0][j] = 1;
    foreach (i; 1 .. y) {
        foreach (j; 1 .. x) {
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % C;
        }
    }
    writeln(dp[y - 1][x - 1] * count % C);
}

Measured memory_bytes: 2092
import Control.Applicative ((<$>), (<*>))

main :: IO ()
main = solve <$> (map read <$> words <$> getLine) <*> (map read <$> words <$> getLine) >>= print

solve :: [Int] -> [Int] -> Int
solve [n, m, x] as
  | 2 * ln <= m = ln
  | otherwise = m - ln
  where
    ln = length $ filter (< x) as


Measured memory_bytes: 892
#include<stdio.h>
#include<string.h>

#define M 1046527
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M/* your task */; }
int h2(int key){ return 1 + (key % (M -1))/* your task */; }

int find(char str[]){
  long long key,i,h;

  key = getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
}

int insert(char str[]){
  long long key,i,h;

  key = getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14916
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
int N,K;
int main(){
    cin >> N >> K;
    double an=0;
    for(int i=1;i<=N;i++){
        int count = 0;
        int j =i;
        while(j<K){
            j *= 2;
            count++;
        }
        double rui =pow(0.5,count);
        double n = 1/(double)N;
        an = an + n * rui;
    }
    printf("%.12lf\n",an);
}

Measured memory_bytes: 4108
#include <iostream>
#include <cstring>
using namespace std;
int main(){
    int h, w, a, b, arr[1005][1005];
    memset(arr, 0, sizeof(arr));
    cin >> h >> w >> a >> b;
    for(int i=1; i<=b; i++){
        for(int j=1; j<=a; j++){
            arr[i][j]=1;
        }
    }
    for(int i=b+1; i<=h; i++){
        for(int j=a+1; j<=w; j++){
            arr[i][j]=1;
        }
    }
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cout << arr[i][j];
            if(j==w){
                cout << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 7580
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		string S; cin >> S;
		ULL ans = (S.size() * (S.size() - 1)) / 2;
		UL C[256] = {};
		rep(i, S.size()) {
			ans -= C[S[i]];
			C[S[i]]++;
		}
		cout << (ans + 1) << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 644
import collections


class Dice():

    def __init__(self, labels):
        self.__pip = labels

    def roll_e(self): # 0352 → 3520
        self.__pip[0], self.__pip[3], self.__pip[5], self.__pip[2] = \
            self.__pip[3], self.__pip[5], self.__pip[2], self.__pip[0]

    def roll_n(self): # 0154 → 1540
        self.__pip[0], self.__pip[1], self.__pip[5], self.__pip[4] = \
            self.__pip[1], self.__pip[5], self.__pip[4], self.__pip[0]

    def roll_s(self): # 0451 →  4510
        self.__pip[0], self.__pip[4], self.__pip[5], self.__pip[1] = \
            self.__pip[4], self.__pip[5], self.__pip[1], self.__pip[0]

    def roll_w(self): # 0253 → 2530
        self.__pip[0], self.__pip[2], self.__pip[5], self.__pip[3] = \
            self.__pip[2], self.__pip[5], self.__pip[3], self.__pip[0]

    def roll_nn(self): # 0154 → 5401
        self.roll_n()
        self.roll_n()

    def turn_dice(self): # 1243 → 2431
        self.__pip[1], self.__pip[2], self.__pip[4], self.__pip[3] = \
            self.__pip[2], self.__pip[4], self.__pip[3], self.__pip[1]

    def roll_dice(self, c):
        if c != self.__pip[0]:
            if c == self.__pip[1]:
                self.roll_n()
            elif c == self.__pip[2]:
                self.roll_w()
            elif c == self.__pip[3]:
                self.roll_e()
            elif c == self.__pip[4]:
                self.roll_s()
            else:
                self.roll_nn()

    def get_top(self):
        return self.__pip[0]

    def get_front(self):
        return self.__pip[1]

    def get_right(self):
        return self.__pip[2]
        
    def get_left(self):
        return self.__pip[3]
        
    def get_behind(self):
        return self.__pip[4]
        
    def get_bottom(self):
        return self.__pip[5]

    def judge(self, dice_2):
        top = dice_2.get_top()
        self.roll_dice(top)
        for i in range(4):
            if dice_2.get_front() == self.__pip[1]:
                break
            if i == 3:
                return False
            self.turn_dice()
        if dice_2.get_right() != self.__pip[2] or \
            dice_2.get_left() != self.__pip[3] or \
            dice_2.get_behind() != self.__pip[4] or \
            dice_2.get_bottom() != self.__pip[5]:
            return False
        return True


def main():
    n = int(input())
    *lst, = [input().split() for i in range(n)]
    for i in range(n-1):
        for j in range(i+1, n):
            lst1 = lst[i]
            lst2 = lst[j]
            if len(set(lst1) ^ set(lst2)) != 0:
                break
            c = collections.Counter(lst2)
            dice1 = Dice(lst1)
            dice2 = Dice(lst2)
            dice2.roll_dice(c.most_common()[-1][0]) # 出現頻度の少ない数字の面を上にする
            if dice1.judge(dice2):
                print('No')
                return
    print('Yes')


if __name__ == "__main__":
    main()



Measured memory_bytes: 6036
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

using namespace std;

#define PI			3.14159265
#define OO			1e9
#define SS       	second
#define FF       	first
#define Trace(n)  	cout<< #n <<" = "<< n << endl;
#define ll			long long
#define endl		"\n"

//@formatter:off
int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
int dy[] = { -1, 1, 0, 0, 1, -1, 1, -1 };

void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

}
//@formatter:on

int main()
{
	fast();
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(a * b, c);
}


Measured memory_bytes: 256
N,A,B,C,D = map(int,input().split())
S = input()

if ('##' in S[A:C-1]):
    ans = 'No'
elif ('##' in S[B:D-1]):
    ans = 'No'
elif (C<D):
    ans = 'Yes'
else:
    if ('...' in S[B-2:D+1]):
        ans = 'Yes'
    else:
        ans = 'No'
    
print(ans)

Measured memory_bytes: 41072
import numpy as np

# 初期値を入力

N = int(input())

P = []
max = 0
number = 0

for i in range(N):
    p = int(input())

    if max < p:
        max = p
        number = i

    P.append(p)

# メインプログラム

P[number] = max/2

print(int(sum(P)))


Measured memory_bytes: 12500
#![allow(clippy::needless_range_loop)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

struct Geometric {
    current: usize,
    ratio: usize,
}

impl std::iter::Iterator for Geometric {
    type Item = usize;

    fn next(&mut self) -> Option<Self::Item> {
        let next = self.current;
        let (muled, overflowed) = self.current.overflowing_mul(self.ratio);
        if overflowed {
            return None;
        }
        self.current = muled;
        Some(next)
    }
}

impl Geometric {
    fn new(init: usize, ratio: usize) -> Self {
        Self {
            current: init,
            ratio
        }
    }
}

fn main() {
    input! {
        n: usize
    }
    let ans: usize = if n % 2 == 0 {
        Geometric::new(10, 5)
            .take_while(|x| *x <= n)
            .map(|x| n / x)
            .sum()
    } else {
        0
    };
    println!("{}", ans);
}


Measured memory_bytes: 2068
K,A,B = gets.split.map &:to_i
if B-A <= 2 || 1+[K-2, 0].max < A
  p 1+K; exit
end

k = K
n = 1
k -= A-1
n += A-1
if k % 2 == 1
  k -=1
  n += 1
end
p (k/2)*(B-A) + n

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

int main()
{
    KAKA
    ll d,t,s;
    cin>>d>>t>>s;
    if((s * t) >= d) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
}

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int a,b,c,d, A[100], B[100], C[100][100], D[100][100][100];
string s, t, r;




int main(){
	cin >> a;
	cout << (a%2?a*2:a) << 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;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    cout<<a[n-1]-a[0]<<endl;
} 


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import heapq
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def solve(N: int, x: "List[int]", y: "List[int]"):
    xy = []
    edges = [] # cost,node1,node2
    for i in range(N):
        xy.append((i,x[i],y[i]))

    x_xy = sorted(xy, key= lambda x:x[1])
    y_xy = sorted(xy, key= lambda x:x[2])
    
    for i in range(N-1):
        cur = x_xy[i]
        next = x_xy[i+1]
        edges.append((next[1]-cur[1],next[0],cur[0]))
        cur = y_xy[i]
        next = y_xy[i+1]
        edges.append((next[2]-cur[2],next[0],cur[0]))

    edges.sort(key= lambda x: x[0])
    uf = UnionFind(N)
    answer = 0
    
    for cost,node1,node2 in edges:
        if uf.same(node1,node2):
            continue

        answer += cost
        uf.union(node1,node2)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 50172
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
int n, m;
int mn[N][4], mx[N][4];
int f[N][N][N], ans;
const int MOD = 1000000007;
int check(int a, int b, int c)
{
    if (mn[a][1] <= mx[a][1]) if (mn[a][1] < b + 1) return 0;
    if (mn[a][2] <= mx[a][2]) if (mn[a][2] < c + 1 || b < mx[a][2]) return 0;
    if (mn[a][3] <= mx[a][3]) if (c < mx[a][3]) return 0;
    return 1;
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i)
        for (int j = 1; j <= 3; ++ j)
            mn[i][j] = n + 1;
    for (int i = 1; i <= m; ++ i)
    {
        int l, r, x;
        cin >> l >> r >> x;
        mn[r][x] = min(mn[r][x], l);
        mx[r][x] = max(mx[r][x], l);
    }
    f[0][0][0] = 1;
    for (int i = 0; i < n; ++ i)
        for (int j = 0; j <= i; ++ j)
            for (int k = 0; k <= j; ++ k)
            {
                if (check(i + 1, j, k)) (f[i + 1][j][k] += f[i][j][k]) %= MOD;
                if (check(i + 1, i, k)) (f[i + 1][i][k] += f[i][j][k]) %= MOD;
                if (check(i + 1, i, j)) (f[i + 1][i][j] += f[i][j][k]) %= MOD;
            }
    for (int j = 0; j <= n; ++ j)
        for (int k = 0; k <= j; ++ k)
            (ans += f[n][j][k]) %= MOD;
    cout << ans;
}


Measured memory_bytes: 108928
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = long.Parse(Console.ReadLine());
        var line = Console.ReadLine().Split(' ');

        var list = new List<int>();
        foreach(var l in line)
        {
            list.Add(int.Parse(l));

        }

        list.Sort((a, b) => b - a);

        long ans = 0;

        for(var i = 0; i < n; i++)
        {
            if (i == 0)
            {

            }
            else if(i == 1)
            {
                ans += (long)list[0];
            }
            else
            {
                ans += (long)list[i / 2];
            }
        }

        Console.WriteLine(ans);
        Console.ReadLine();
    }

}


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

#define INPUTSIZE 10

int main() {
    int a, b, sum, digit;

    while (cin >> a >> b) {
        sum = a + b;

        digit = 0;
        while (sum > 0) {
            sum /= 10;
            digit++;
        }
        cout << digit << endl;
    }

    return 0;
}

Measured memory_bytes: 3036
/// hi_im_manh :D
#include <bits/stdc++.h>
#define reset(a,n) memset(a,0,(n+1)*sizeof(int))
#define endl "\n"
#define llmin LLONG_MIN
#define llmax LLONG_MAX
#define intmax INT_MAX
#define intmin INT_MIN
#define ll long long
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define duckman "TASK"

#define input freopen(duckman".inp", "r", stdin);
#define output freopen(duckman".out", "w", stdout);

#define nmax 22000
using namespace std;

void max_self(ll &a, ll b) {
    a = max(a, b);
}
int main()
{
    fast;
//    input;
//    output;

    ll n, weight;
    cin >> n >> weight;
    vector<ll> dp(weight+1);
    for (int i = 0; i < n; ++i) {
        ll v, w;
        cin >> w >> v;
        for (ll weight_now = weight; weight_now - w >= 0; --weight_now) {
            max_self(dp[weight_now], dp[weight_now - w] + v);
        }
    }
    cout << dp[weight];
}

/*

*/


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

int main(){
	vector<int> V;
	for (int i = 0; i < 3; ++i)
	{
		int x;cin>>x;
		V.push_back(x);
	}
	sort(V.begin(), V.end());
	vector<int> W{5,5,7};
	if(W==V)cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      
      int H = sc.nextInt();
      int N = sc.nextInt();
      int[] A = new int[N];
      int sum = 0;
      for (int i = 0; i < N; i++) {
        A[i] = sc.nextInt();
        sum += A[i];
      }
      sc.close();
      if (sum < H) {
        System.out.println("No");
      } else {
 	     System.out.println("Yes");
      }  
    }
}

Measured memory_bytes: 49908
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

double width(int *x, int *y, int size, double given_x){
    double max_point = -1000.0, min_point = 1000.0;
    for(int i = 0; i < size; i++){
        double x1 = x[i], y1 = y[i], x2 = x[(i+1)%size], y2 = y[(i+1)%size];
        if((x1-given_x)*(x2-given_x) <= 0 && x1 != x2){
            double value = (y2-y1) * (given_x-x1) / (x2-x1) + y1; 
            max_point = max(value, max_point);
            min_point = min(value, min_point);
        }
    }
    return max_point - min_point;
}

int main(){
    int m, n;
    while(cin >> m >> n && m > 0){
        int xy[100];
        int y[100];
        int xz[100];
        int z[100];
        int max_xy = -105;
        int min_xy = 105;
        for(int i = 0; i < m; i++){
            cin >> xy[i] >> y[i];
            max_xy = max(max_xy, xy[i]);
            min_xy = min(min_xy, xy[i]);
        }
        int max_xz = -105;
        int min_xz = 105;
        for(int i = 0; i < n; i++){
            cin >> xz[i] >> z[i];
            max_xz = max(max_xz, xz[i]);
            min_xz = min(min_xz, xz[i]);
        }
        int xmin = max(min_xy, min_xz);
        int xmax = min(max_xy, max_xz);
        vector<int> v;
        for(int i = 0; i < m; i++){
            v.push_back(xy[i]);
        } 
        for(int i = 0; i < n; i++){
            v.push_back(xz[i]);
        } 
        sort(v.begin(), v.end());
        double ans = 0;
        for(int i = 0; i < n+m-1; i++){
            double a = v[i], b = v[i+1];
            if(xmin <= a && a <= xmax && xmin <= b && b <= xmax){
                double mid = (a + b) / 2.0;
                double va = width(xy, y, m, a) * width(xz, z, n, a);
                double vb = width(xy, y, m, b) * width(xz, z, n, b);
                double vm = width(xy, y, m, mid) * width(xz, z, n, mid);
                ans += (b-a)/6 * (va + 4*vm + vb);
            }
        }
        cout << fixed << setprecision(4) << ans << endl;
    }
}

Measured memory_bytes: 3188
import java.io.*;

public class Main{
    public static void main(String[] args)throws IOException{
	BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
	while(true){
	    String s=r.readLine();
	    String[] t=s.split(" ");
	    int[] n=new int[t.length];
	    for(int i=0;i<2;i++){
		n[i]=Integer.parseInt(t[i]);
	    }
	    if(n[0]==0 &&n[1]==0){
		System.exit(0);
	    }
	    String u=r.readLine();
	    String[] p=u.split(" ");
	    int[] ing=new int[n[1]];
	    for(int j=0;j<n[1];j++){
		ing[j]=Integer.parseInt(p[j]);
	    }
	    int[] count=new int[n[1]];
	    for(int nm=0;nm<n[1];nm++){
		count[nm]=0;
	    }
	    for(int k=0;k<n[0];k++){
		String a=r.readLine();
		String[] alpha;
		alpha=a.split(" ");
		int[] number=new int[n[1]];
		for(int l=0;l<n[1];l++){
		    number[l]=Integer.parseInt(alpha[l]);
		    count[l]+=number[l];
		}
	    }
	    int ans=0;
	    for(int q=0;q<n[1];q++){
		if(count[q]<=ing[q]){
		    ans++;
		}
	    }
	    if(ans==n[1]){
		System.out.println("Yes");
	    }else{
		System.out.println("No");
	    }
	}
    }
}

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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    if (N <  A + B - 1 || N > 1LL * A*B) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> T;
	int S=N-A;
	int cur=N;
	rep(i,A) {
		int num=min(B-1,S)+1;
		S-=num-1;
		rep(j,num) T.push_back(cur-num+1+j);
		cur-=num;
	}
	reverse(T.begin(), T.end());
	for(auto v : T) cout<<v<<" ";
	cout<<endl;
    return 0;
}

Measured memory_bytes: 5336
#include<stdio.h>

int main(){
    int a,b,n,ans=0,i;
    scanf("%d %d",&a,&b);
    n = b-a;
    for(i=1;i<=n;i++){
        ans += i;
    }
    ans -= b;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
// AOJ 0661 Coin Collecting
// 2019.3.28 bal4u

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

//// 入力の高速化
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()    // 整数の入力（負数対応）
{
	int n = 0, c = gc();
	if (c == '-') {
		c = gc();
		do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define ABS(a)   ((a)>=0?(a):-(a))
#define MIN(a,b) ((a)<=(b)?(a):(b))

//// 本問題関連
int cnt[100005][2]; int N, N2;

int main()
{
	int i, x, y, t, d1, d2;
	long long ans;

	ans = 0; N = in(), N2 = N << 1;
	for (i = 0; i < N2; i++) {
		x = in(), y = in();

		if (x > N) ans += x - N, x = N;
		else if (x < 1) ans += 1 - x, x = 1;

		if (y > 2) ans += y - 2, y = 2;
		else if (y < 1) ans += 1 - y, y = 1;

		cnt[x][y]++;
	}

	d1 = d2 = 0;
	for (x = 1; x <= N; x++) {
		d1 += cnt[x][1] - 1, d2 += cnt[x][2] - 1;
		if (d1 > 0 && d2 < 0) {
			t = MIN(d1, -d2);
			ans += t, d1 -= t, d2 += t;
		}
		if (d1 < 0 && d2 > 0) {
			t = MIN(-d1, d2);
			ans += t, d1 += t, d2 -= t;
		}
		ans += ABS(d1) + ABS(d2);
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
    string S, T; cin >> S >> T;
    int ans = T.size();
    for (int i = 0; i + (int)T.size() <= (int)S.size(); i++) {
        int c = 0;
        for (int j = 0; j < (int)T.size(); j++) {
            c += (S[i + j] != T[j]);
        }
        if (ans > c)
            ans = c;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    ll n,m; cin >> n >> m;
    ll lcm = 1;
    vector<ll> a(n);
    bool ok = true;
    for (int i = 0; i < n; i++) {
        cin >> a[i], a[i] /= 2;
        lcm = lcm / GCD(lcm,a[i]) * a[i];
    }
    ll res = m / lcm;
    ll ans;
    for (int i = 0; i < n; i++) {
        if (lcm / a[i] % 2 == 0) {
            ok = false;
            break;
        }
    }
    if (ok) ans = (res + 1) / 2;
    else ans = 0;
    cout << ans << "\n";
}

Measured memory_bytes: 1024
import queue
h, w = map(int, input().split())
d=[(0, 1), (1, 0), (0, -1), (-1, 0)]
s=[list(input()) for i in range(h)]
m=[[-1]*w for i in range(h)]
m[0][0]=1
q = queue.Queue()
q.put((0, 0))
while not q.empty():
    p=q.get()
    for i in range(4):
        x=p[0]+d[i][0]
        y=p[1]+d[i][1]
        if 0<=x<h and 0<=y<w and m[x][y]<0 and s[x][y]=='.':
            q.put((x, y))
            m[x][y]=m[p[0]][p[1]]+1
dis=m[h-1][w-1]
c=sum(si.count('.') for si in s)
print(c-dis if dis>0 else -1)

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

void solve(){
	int n;
	cin >> n;
	while(n>0) {
		if(n%10 == 7) {
			cout << "Yes" << en;
			return ;
		}
		n /= 10;
	}
	cout << "No" << en;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
    int t = 1; 
	// cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    string N; cin >> N;
    if(N == "RRR"){AA(3);}
    else if(N == "SSS"){AA(0);}
    else if(N == "RSS" || N == "SRS" || N == "SSR" ||N == "RSR"){AA(1);}
    else AA(2);
    return 0;
}

Measured memory_bytes: 3632
n = int(input())
a = list(map(int,input().split()))
flg = True

for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            continue
        else:
            flg = False
            break

if flg:
    print('APPROVED')
else:
    print('DENIED')

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

using namespace std;
typedef long long ll;

int main()
{
  int n, k;
  cin >> n >> k;
  vector<ll> v;

  ll x;
  for (int i = 0; i < n; i++)
  {
    cin >> x;
    v.push_back(x);
  }

  ll res = 1000000000;
  for (int i = 0; i <= n - k; i++)
  {
    ll tmp = std::min(abs(v[i]) + abs(v[i + k - 1] - v[i]), abs(v[i + k - 1]) + abs(v[i] - v[i + k - 1]));
    res = std::min(tmp, res);
  }

  cout << res << endl;
}

Measured memory_bytes: 1400
n = int(input())
data = list(map(int, input().split()))
counter = 0
for i in range(n):
    num_min = float('inf')
    num_index = i
    for j in range(i, n):
        if data[j] < num_min:
            num_min = data[j]
            num_index = j
    if data[i] != data[num_index]:
        data[i], data[num_index] = data[num_index], data[i]
        counter += 1
print(*data)
print(counter)



Measured memory_bytes: 5616
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 200000000000;


    ll W,H;
    ll ans=INF;
    bool f=false;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>H>>W;
    if(H%3==0||W%3==0){
        cout<<"0";
        f=true;
    }else{
        EREP(i,W){
            ll S1=i*H,S2,S3;
            if(H%2==0){
                 S2=S3=H/2*(W-i);
            }else{
                 S2=H/2*(W-i);
                 S3=(H/2+1)*(W-i);
            }
            ans=min((max(S1,S3)-min(S1,S2)),ans);
            DEB(i)DEB(ans)DEB((max(S1,S3)-min(S1,S2)))END
        }
        END
        EREP(i,H){
            ll S1=i*W,S2,S3;
            if(W%2==0){
                 S2=S3=W/2*(H-i);
            }else{
                 S2=W/2*(H-i);
                 S3=(W/2+1)*(H-i);
            }
            ans=min((max(S1,S3)-min(S1,S2)),ans);
            DEB(i)DEB(ans)DEB((max(S1,S3)-min(S1,S2)))END
        }
        ans=min(W,ans);
        ans=min(H,ans);
    }
    if(!f)cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int i;long long m=0;
	for(i=0;i<s.size();i++)
	m+=s[i]-'0';
	if(m%9==0)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

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

typedef long long ll;
using namespace std;

int main(){
	
	int n;
	cin >> n;
	vector <int> a;
	
	for(int i=0 ; i< n; i++){
		int t;
		cin >> t;
		a.push_back(t);
	}

	int m = a[0];
	int c= 0;
	for(int i=0; i < n; i++ ){
		if(a[i] >= m){
			c++;
		}
		m = max(m,a[i]);
	}

	cout << c;


	return 0;

}

Measured memory_bytes: 256
def nextg(x, place):
    if x[place] == 1:
        x[place] = 0
        if place == 0:
            return x
        return nextg(x, place-1)
    if x[place] == 0:
        x[place] = 1
        return x
n, m, t = map(int,input().split())
generator = [0]*n
books = []
for i in range(0, n):
    books.append(list(map(int,input().split())))
min = 0
for i in range(0, n):
    min+=books[i][0]
flag = 0
for i in range(0, pow(2,n)):
    found = False
    for k in range(1, m+1):
        sum = 0
        for j in range(0, n):
            sum+=books[j][k]*generator[j]
        if sum<t:
            break
        elif k == m:
            found = True
            flag = 1         
    cost = 0
    for p in range(0, n):
        cost+=books[p][0]*generator[p]
    if found == True and cost<min:
        min = cost
    generator = nextg(generator, n-1)
if flag == 1:
    print(min)
else:
    print(-1)
    


Measured memory_bytes: 9260
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    s = input()

    x = 0
    for c in s:
        x = (x+int(c)) % 9
    
    print("Yes" if x == 0 else "No")

main()

Measured memory_bytes: 69160
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int a,b,c,d,e=0;
string s[1100][1100];
signed main()
{
	cin>>a>>b>>c>>d;
	rep(i,d/a+1){
		rep(j,d/b+1){
			if((d-(a*i+b*j))%c==0&&d-a*i-b*j>=0){
				e++;
			}
		}
	}
	cout<<e;
}

Measured memory_bytes: 9728
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
char s[4005];
int n,cnt[105];
ll ans;
int main(){
    read(n);
    cin>>s+1;
    fr(i,1,n)++cnt[s[i]-'A'];
    ans=1ll*cnt['R'-'A']*cnt['G'-'A']*cnt['B'-'A'];
    fr(i,1,n){
    	int i1=i-1,i2=i+1;
    	while(i1&&i2<=n){
    		if(s[i1]!=s[i2]&&s[i2]!=s[i]&&s[i1]!=s[i])--ans;
    		--i1,++i2;
		}
	}
	cout<<ans;
	return 0;
}


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

int main() {
    string S;
    cin >> S;

    for (int i = 0; i < 2; i++)
    {
        if (S[i] != S[i + 1])
        {
            cout << "Yes" << endl;
            return 0;
        }
        
    }
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf = 1LL<<50;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
    int n; cin >> n;
    vll a(n + 2), b(n + 2);
    rep(i, 1, n + 1) cin >> a[i];
    rep(i, 1, n + 1) cin >> b[i];
    a[n + 1] = b[n + 1] = inf;

    ll res = 1LL;
    rep(i, 1, n + 1){
        ll h = -1LL;
        if(a[i - 1] != a[i]) h = a[i];
        if(b[i + 1] != b[i]){
            if(h != -1LL and h != b[i]){
                res = 0LL;
                break;
            }
            h = b[i];
        }
        if(h != -1LL and (h > a[i] or h > b[i])) {
            res = 0LL;
            break;
        }

        ll cur = 1LL;
        if(h == -1LL){
            cur = min(a[i], b[i]);
        }

        res = MUL(res, cur, mod);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <random>
#include <sstream>
#include <stack>
#include <deque>

using namespace std;

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

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

int main() {
    // cin >> N >> M;
    int a, b;
    cin >> a >> b;
    if (a > b) cout << a - 1 << endl;
    else cout << a << endl;
    
    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define y1 secondy1
#define rank tipa_rank
#define pb push_back
#define mp make_pair
#define pow10 tipa_pow10
#define ll long long
#define INF 1000000000
#define EPS 1e-9
#define EPS2 1e-8
#define PI acos(-1.0)
using namespace std;
const int MOD = INF + 7;
int a = 1;
deque<int> permut;
void f(ll X)
{
	if(X == 1)
		return;
	int v = a++;
	if(not(X % 2))
	{
		f(X / 2);
		permut.push_back(v);
	}
	else
	{
		permut.push_back(v);
		f(X - 1);
	}
}
int main()
{
	ll N;
	cin >> N;
	N++;
	f(N);
	int x = permut.size();
	for(int i = 0; i < x; i++)
	{
		permut[i] = x - permut[i] + 1;
	}
	for(int i = 0; i < x; i++)
		permut.push_back(i + 1);
	cout << permut.size() << endl;
	for(int i = 0 ; i < permut.size(); i++)
		cout << permut[i] << " ";
	cout << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> idx(N);
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(), [&](int a, int b) { return A[a] < A[b]; });
  for (auto &v : idx) {
    cout << v + 1 << (&v == &idx.back() ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 1664
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);
  
  int a,b,x; cin >> a >> b >> x;
  if (a+b>=x && x>=a){cout << "YES" << endl;}
  else {cout << "NO" << endl;}

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007;
typedef long long ll;
using namespace std;
#include<stack>
int BiggestRectangle(int N,int buf[]){
	buf[N]=0;
	stack<pair<int,int> >st;
	int ret=0;
	for(int i=0;i<=N;i++){
		if(st.empty())st.push(make_pair(buf[i],i));
		else if(st.top().first<buf[i])st.push(make_pair(buf[i],i));
		else if(st.top().first>buf[i]){
			int pnt=i;
			while(!st.empty()){
				int height=st.top().first;
				int index=st.top().second;
				if(height<buf[i])break;
				st.pop();
				ret=max(ret,height*(i-index));
				pnt=index;
			}
			st.push(make_pair(buf[i],pnt));
		}
	}
	return ret;
}
int dp[1410][1410];
int main(){
  int h,w;
  cin>>h>>w;
  lol(i,h){
    lol(j,w){
      int a;cin>>a;
      if(i==0)dp[i][j]=(a==0);
      else{
	if(a==0)dp[i][j]=dp[i-1][j]+1;
	else dp[i][j]=0;
      }
    }
  }
  int ans=0;
  lol(i,h){
    ans=max(ans,BiggestRectangle(w,dp[i]));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 10724
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> t(n);
    ll ans = 0;
    rep(i, n){
        cin >> t[i];
        ans += t[i];
    }
    int m;
    cin >> m;
    vector<int> p(m), x(m);
    rep(i, m){
        cin >> p[i] >> x[i];
    }

    rep(i, m){
        ll tmp = ans;
        tmp -= t[p[i]-1];
        tmp += x[i];
        cout << tmp << endl;
    }
}

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

typedef long long ll;
const int mod=1e9+7;
const int N=1e5+5;
int a[N],b[N],c[N];

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        for(int i=0; i<n; i++)
            scanf("%d",&b[i]);
        sort(b,b+n);
        for(int i=0; i<n; i++)
            scanf("%d",&c[i]);
        sort(c,c+n);
        ll ans=0;
        for(int i=0;i<n;i++)
        {
            ll pos1=lower_bound(a,a+n,b[i])-a;
            ll pos2=upper_bound(c,c+n,b[i])-c;
            ans+=(pos1*(n-pos2));
        }
        printf("%lld\n",ans);
    }
    return 0;
}
/**
2
1 5
2 4
3 6
3
1 1 1
2 2 2
3 3 3
6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288
**/


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,w;
    char c;
    cin>>h>>w;
    int count=0;
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            cin>>c;
            if (c=='#') {
                count++;
            }
        }
    }
    if (count==h+w-1) {
        cout<<"Possible"<<endl;
    } else {
        cout<<"Impossible"<<endl;
    }
}

Measured memory_bytes: 3576
class _in{struct my_iterator{int it;const bool rev;explicit constexpr my_iterator(int it_, bool rev=false):it(it_),rev(rev){}constexpr int operator*(){return it;}constexpr bool operator!=(my_iterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const my_iterator i,n;public:explicit constexpr _in(int n):i(0),n(n){}explicit constexpr _in(int i,int n):i(i,n<i),n(n){}constexpr const my_iterator& begin(){return i;}constexpr const my_iterator& end(){return n;}};

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

const int INF = 1e9;
int dist[100][100];
int cost[100][100];
inline void chmin(int& a, int b) { a = min(a, b); }
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    for(int N, M; cin >> N >> M && N; ) {
        for(int i : _in(100)) {
            fill_n(dist[i], 100, INF);
            fill_n(cost[i], 100, INF);
            dist[i][i] = cost[i][i] = 0;
        }
        for(int _ : _in(N)) {
            int a, b, co, di;
            cin >> a >> b >> co >> di;
            --a;
            --b;
            chmin(dist[a][b], di);
            chmin(dist[b][a], di);
            chmin(cost[a][b], co);
            chmin(cost[b][a], co);
        }
        for(int k : _in(M)) for(int i : _in(M)) for(int j : _in(M)) {
            chmin(dist[i][j], dist[i][k] + dist[k][j]);
            chmin(cost[i][j], cost[i][k] + cost[k][j]);
        }
        int K; cin >> K;
        while(K--) {
            int p, q, r;
            cin >> p >> q >> r;
            --p;
            --q;
            cout << (r == 0 ? cost[p][q] : dist[p][q]) << '\n';
        }
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const int MAX_N = 18, MAX_POWN = 1 << MAX_N;
const ll MOD = 1e9 + 7;

ll sq(ll x) { return x * x % MOD; }
ll qpow(ll a, ll b) { return b ? sq(qpow(a, b / 2)) * (b & 1 ? a : 1) % MOD : 1; }
ll inv(ll x) { return qpow(x, MOD - 2); }

int N, M, A[MAX_POWN];
ll fac[MAX_POWN], ifac[MAX_POWN];
ll dp[MAX_N][MAX_POWN];

ll comb(int n, int m) { return n >= m && m >= 0 ? fac[n] * ifac[n - m] % MOD * ifac[m] % MOD : 0; }

int main() {
    scanf("%d%d", &N, &M);
    for (int i = 1; i <= M; i++) scanf("%d", &A[i]);
    fac[0] = 1;
    for (int i = 1; i <= 1 << N; i++) fac[i] = fac[i - 1] * i % MOD;
    ifac[1 << N] = inv(fac[1 << N]);
    for (int i = 1 << N; i; i--) ifac[i - 1] = ifac[i] * i % MOD;
    dp[M + 1][0] = 1;
    for (int i = M; i; i--) {
        for (int j = 0; j < 1 << N; j++) {
            dp[i][j] = dp[i + 1][j];
            for (int k = 0; k < N; k++) {
                if (j >> k & 1) {
                    (dp[i][j] += dp[i + 1][j - (1 << k)] * comb((1 << N) - A[i] - (j - (1 << k)), (1 << k) - 1) % MOD * fac[1 << k]) %= MOD;
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < 1 << N; i++) {
        ll coe = 1;
        for (int j = 0; j < N; j++)
            if (i >> j & 1) coe = MOD - coe;
        (ans += coe * dp[1][i] % MOD * fac[(1 << N) - 1 - i]) %= MOD;
    }
    (ans *= 1 << N) %= MOD;
    printf("%lld\n", ans);
}


Measured memory_bytes: 39296
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
ans = ''
while n > 0:
    n += -1
    rem = n % 26
    n = n // 26
    ans += chr(ord('a') + (rem))
print(ans[::-1])

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200010
#define lim9 1000000010

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

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

	for(int a = -1000; a <= 1000; a++) {
		for(int b = -1000; b <= 1000; b++) {
			if (pow(a, 5) - pow(b, 5) == x) {
				outt(a, b);
				return 0;
			}
		}
	}
    return 0;
}


Measured memory_bytes: 3936