akhauriyash/Code-Regression huggingface dataset:
N = int(input())
flag = 0
for i in range(int((8*N+1)**0.5)+1):
    if i*(i-1)==2*N:
        flag = 1
        k = i
        break
if flag==0:
    print("No")
else:
    print("Yes")
    S = [[] for _ in range(k)]
    cnt = 1
    for i in range(k-1):
        for j in range(i+1,k):
            S[i].append(cnt)
            S[j].append(cnt)
            cnt += 1
    print(k)
    for i in range(k):
        print(len(S[i]),*S[i])

Measured memory_bytes: 76988
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 7;
int main(){
    char a;
    cin >> a;
    cout << char(a+1);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

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

int main() {
  int H, W, h, w; cin >> H >> W >> h >> w;
  cout << H * W - (h * W + w * H - h * w) << endl;
  return 0;
}


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

int main()
{
	int n, p = 0;
	int a[200000];
	string s;

	cin >> n >> s;

	for (int i = 0; i < n; i++) {
		if (s[i] == '.')
			p++;

		a[i] = p;
	}

	int m = p;

	for (int i = 0; i < n; i++)
		m = min(p + i + 1 - a[i] * 2, m);	

	cout << m << endl;

	return 0;
}


Measured memory_bytes: 1412
s = gets.chomp
l = s.length
c = "Yes"

(l/2).times {|i|
  if s[i] == s[-i-1] then
  else
    c = "No"
    break
  end
}

if c == "Yes" then
  s[0..((l/2)-1)].length.times {|i|
    if s[0..((l/2)-1)][i] == s[0..((l/2)-1)][-i-1] then
    else
      c = "No"
      break
    end
  }
end

if c == "Yes" then
  s[((l+1)/2)..(l-1)].length.times {|i|
    if s[((l+1)/2)..(l-1)][i] == s[((l+1)/2)..(l-1)][-i-1] then
    else
      c = "No"
      break
    end
  }
end
print(c)

Measured memory_bytes: 1788
n, h = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda ab: (-ab[0], ab[1]))  # aの大きいやつを取り出す
maxa = ab[0][0]
maxa_b = ab[0][1]
ab[0][0] = 0
ab[0][1] = 0
# print()
# print(maxa, maxa_b)

ab = sorted(ab, key=lambda ab: (-ab[1]))
# print(ab)
ans = 0
for i in range(n-1):
    if h <= 0:
        print(ans)
        break

    if h <= maxa_b:
        ans += 1
        print(ans)
        break

    if maxa < ab[i][1]:
        h -= ab[i][1]
        ans += 1
    else:
        h -= maxa
        ans += 1
    # print(h)
else:
    # print(h, ans, "SDFGH")
    ans += 1
    h -= maxa_b
    if h <= 0:
        print(ans)
    else:
        if h % maxa == 0:
            ans += h//maxa
        else:
            ans += h//maxa+1
        print(ans)


Measured memory_bytes: 38652
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<pair<string,int>, int>> R;

    for (int i = 0; i < n; ++i) {
        string s;
        int sc;
        cin >> s >> sc;
        R.emplace_back(make_pair(s, -sc), i);
    }
    sort(R.begin(), R.end());

    for (int i = 0; i < n; ++i) {
        cout << R[i].second + 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int k, s, z;
int main() {
	cin >> k >> s;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (0 <= s - i - j && s - i - j <= k) {
				z++;
			}
		}
	}
	printf("%d\n", z);
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}


enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int H, W;
    scan(H, W);
    auto c = iota(10).map!(i => readln.split.to!(int[])).array;
    foreach (k ; 0 .. 10) {
        foreach (i ; 0 .. 10) {
            foreach (j ; 0 .. 10) {
                chmin(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    auto a = iota(H).map!(i => readln.split.to!(int[])).array;
    int ans;
    foreach (i ; 0 .. H) {
        foreach (j ; 0 .. W) {
            if (a[i][j] != -1) ans += c[a[i][j]][1];
        }
    }
    writeln(ans);
}


Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<int> a(n);
    vector<int> b(n);
    const int sz = 200010;
    vector<int> c(sz, 0), d(sz, 0);
    REP(i, 0, n) {
        cin, a[i];
        c[a[i]]++;
    }
    REP(i, 0, n) {
        cin, b[i];
        d[b[i]]++;
    }

    int ans = 0;
    REP(i, 1, sz) {
        if (c[i] + d[i] > n) {
            print("No");
            return 0;
        }
        c[i] += c[i - 1];
        d[i] += d[i - 1];
        chmax(ans, c[i] - d[i - 1] + n);
    }
    ans %= n;

    rotate(b.begin(), b.begin() + n - ans, b.end());
    print("Yes");
    REP(i, 0, n) {
        cout << b[i] << " \n"[i + 1 == n];
    }

    return 0;
}


Measured memory_bytes: 6344
#include <iostream>
#include<string.h>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;


int main()
{
    int t,count=0,x;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
    	cin>>x;
    	if(i%2!=0&&(x)%2!=0)
    	{
    		
    			count++;
    			
			
		}
	}
	cout<<count;
    return 0;
}

Measured memory_bytes: 3520
fn getline() -> String{
    let mut __ret=String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

const MOD: i64 = 1000000007;

fn mpermu(a: i64, num: i64) -> i64 {
    match num {
        0 => 1,
        _ => a * mpermu(a - 1, num - 1) % MOD
    }
}

fn mpow(x: i64,  y: i64) -> i64 {
    match y {
        0 => 1,
        _ => (x.pow((y % 2) as u32) * mpow(x * x % MOD, y / 2)) % MOD
    }
}

fn main(){
    let s=getline();
    let a:Vec<_>=s.trim().split(' ').collect();
    let n:i64=a[0].parse().unwrap();
    let m:i64=a[1].parse().unwrap();
    
    let mut v: i64 = m;
    let mut r: i64 = 1;
    let mut div: i64 = 2;
    
    while div * div <= m {
        let mut rd = 0;
    
        while v % div == 0 {
        v /= div;
            rd+=1;
        }
        r = (r * mpermu((rd + n - 1) % MOD, rd) % MOD) * mpow(mpermu(rd, rd), MOD - 2) % MOD;
        div+=1;
    }
    if v > 1 {
        r = (r * (1 + n - 1)) % MOD;
    }
    
    println!("{}", r);
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
//------------------------------------------------------------
		int h = sc.nextInt();
		int a = sc.nextInt();
		int ans =0;
		boolean con = true;
		while (con) {
			ans ++;
			h -= a;
			if (h<=0) {
				con =false;
			}
		}
		System.out.println(ans);
//------------------------------------------------------------
	}
}

Measured memory_bytes: 22996
var input= require('fs').readFileSync('/dev/stdin', 'utf8').split("\n").map(Number);
var part = [];
input.some(function(x) {
  if (x == 0) return true;
  part.push(x);
});
console.log(part.map(function(x, i) {
  return x == 0 ? '' : 'Case ' + (i + 1) + ': ' + x;
}).join('\n').trim());

Measured memory_bytes: 19488
{-# LANGUAGE BangPatterns               #-}
{-# LANGUAGE DerivingStrategies         #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE UndecidableInstances       #-}

import           Control.Monad.State
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import qualified Data.Vector.Unboxing  as VU

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- VU.map fromIntegral <$> readLnAsUVecWith unconsInt n :: IO (VU.Vector IntMod)

  let partsum = VU.tail $ VU.postscanr' (+) 0 as
      partprod = VU.foldl1' (+) $ VU.zipWith (*) as partsum

  print partprod

modulus :: Int
-- modulus = 10^9 + 7
modulus = 1000000007

newtype IntMod = IntMod Int deriving Eq deriving newtype VU.Unboxable

fromIntegralIntIntMod :: Int -> IntMod
fromIntegralIntIntMod n = IntMod (n `mod` modulus)
{-# RULES
"fromIntegral/Int->IntMod"
    fromIntegral = fromIntegralIntIntMod
#-}

instance Show IntMod where
  show (IntMod x) = show x

instance Num IntMod where
  IntMod x + IntMod y = IntMod ((x + y) `mod` modulus)
  IntMod x - IntMod y = IntMod ((x - y) `mod` modulus)
  IntMod x * IntMod y = IntMod ((x * y) `mod` modulus)
  fromInteger n = IntMod (fromInteger (n `mod` fromIntegral modulus))
  abs = undefined
  signum = undefined

unconsInt :: StateT BS.ByteString Maybe Int
unconsInt = StateT $ BS.readInt . BS.dropWhile isSpace

readLnAsUVecWith :: VU.Unboxable a => StateT BS.ByteString Maybe a -> Int -> IO (VU.Vector a)
readLnAsUVecWith !st !n = VU.unfoldrN n (runStateT st) <$> BS.getLine


Measured memory_bytes: 13680
#include <assert.h>
#include <stdio.h>
#define INF 1001001001
int min(int x, int y) {
	return x > y ? y : x;
}
int max(int x, int y) {
	return x < y ? y : x;
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	int dp[1 << 12];
	for (int i = 0; i < 1 << n; i++) {
		dp[i] = INF;
	}
	dp[0] = 0;
	int t[1000], a[1000];
	for (int i = 0; i < m; i++) {
		int b, c[20];
		scanf("%d%d", &a[i], &b);
		int te = 0;
		for (int j = 0; j < b; j++) {
			scanf("%d", &c[j]);
			c[j]--;
			te += 1 << c[j];
		}
		// printf("%d\n", te);
		t[i] = te;
	}
	for (int i = 0; i < 1 << n; i++) {
		for (int j = 0; j < m; j++) {
			dp[i | t[j]] = min(dp[i | t[j]], dp[i] + a[j]);
		}
	}
	int ans = dp[(1 << n) - 1];
	if (ans == INF) {
		ans = -1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n;
  cin >> n;

  int ans = (n + 2 - 1) / 2;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define max_size (int)(1e5 + 1)

int main(){
	char *s = (char *)malloc(sizeof(char) * max_size);
	int i;
	scanf("%s", s);
	for(i = 0; s[i + 1] != '\0'; i++){
		if(s[i] == s[i + 1]){
			printf("%d %d\n", i + 1, i + 2);
			return 0;
		}
		else if(s[i] == s[i + 2]){
			printf("%d %d\n", i + 1, i + 3);
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
 
int main()
{
	ios_base::sync_with_stdio(false);
	ll n,i;
	cin>>n;
	ll h[n+2];
	for(i=0;i<n;i++)
		cin>>h[i];
	ll a = 0,b = abs(h[0]-h[1]);
	for(i=2;i<n;i++)
	{
		ll temp = min(b+abs(h[i]-h[i-1]), a+abs(h[i]-h[i-2]));
		a=b;
		b=temp;
	}
	cout<<b<<nl;
	return 0;
}

Measured memory_bytes: 4392
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < (int)n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
#endif

int N, M;
int A[1000], B[1000], C[1000];
int D[100][100];
int P[100][100];
bool used[100][100];


int main() {
	cin >> N >> M;
	REP(i, 0, N) {
		REP(j, 0, N) {
			D[i][j] = INF;
		}
	}
	
	REP(i, 0, M) {
		cin >> A[i] >> B[i] >> C[i];
		--A[i]; --B[i];
		D[A[i]][B[i]] = D[B[i]][A[i]] = C[i];
	}
	REP(i, 0, N) {
		REP(j, 0, N) {
			P[i][j] = D[i][j];
		}
	}

	REP(k, 0, N) {
		REP(i, 0, N) {
			REP(j, 0, N) {
				P[i][j] = min(P[i][j], P[i][k] + P[k][j]);
			}
		}
	}
	int count = 0;
	REP(i, 0, N) {
		REP(j, 0, N) {
			if (P[i][j] == D[i][j]) ++count;
		}
	}
	cout << M - count / 2 << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const int BITSIZE = 100010;


int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int q; cin >> q;
    deque<ll> dq;
    REP(i, q){
        int a; cin >> a;
        if(a==0){
            int b, c; cin >> b >> c;
            if(b==0) dq.push_front(c);
            else dq.push_back(c);
        }
        if(a==1){
            int b; cin >> b;
            cout << dq[b] << endl;
        }
        if(a==2){
            int b; cin >> b;
            if(b==0) dq.pop_front();
            else dq.pop_back();
        }
    }
            
	return 0;
}


Measured memory_bytes: 6328
#include <stdio.h>

main(){
  int k,data[5000];
  int temp,i,sum;

  while(1){
    scanf("%d", &k);
    if(k==0) break;

    temp=k*(k-1)/2;

    for(i=0;i<temp;i++){
      scanf("%d", &data[i]);
    }

    sum=0;

    for(i=0;i<temp;i++){
      sum+=data[i];
    }


    printf("%d\n", sum/(k-1));
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
li =  [ int(it) -1 for it in input().split() ] 

import sys
sys.setrecursionlimit(10000000)

from functools import lru_cache
MOD = 1000000007
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
@lru_cache(maxsize=None)
def modinv(a):
    (inv, q, gcd_val) = egcd(a, MOD)
    return inv % MOD

fac_li = [0]*( 1000009 )
if True:
  s = 1
  for i in range(1,1000001):
    s = (s*i)%MOD
    fac_li[i] = s
def factorial(k):
  if (k<=1):
    return 1
  return fac_li[k]
@lru_cache(maxsize=None)
def combination(n,m):
  return (factorial(n)*modinv(factorial(m))*modinv(factorial(n-m)))%MOD

#print ( factorial(5),factorial(3) )
#print ( combination(5,3) )

import collections as col
c = col.Counter( li ).items()
a = [ it for it in c if it[1] == 2][0][0]
p1 = li.index(a)
p2 = li[p1+1:].index(a) + 1 + p1
#print ( p1 , p2 )
H = p1 + (N-p2)
#print ( H )

li=[]
for i in range(1,N+2):
  a =  (combination(N+1,i) - (combination(H,i-1)if (i-1)<=H else 0))%MOD
  li.append(a)
print ( "\n".join( map(str,li) ) )
  

Measured memory_bytes: 130336
import sys
import copy
from collections import deque
sys.setrecursionlimit(20000)
N,relation=input().split()
N,relation=int(N),int(relation)
g = [set() for i in range(N)]

def BFS(a,b):
    bfs = deque([a])
    grp={a:None}
    grp2={a}
    while bfs:
        i=bfs.popleft()
        for j in g[i]:
            if j not in grp2:
                grp[j]=a
                grp2.add(j)
                bfs.append(j)
    return grp,grp2


for i in range(relation):
    kari=[]
    j,k=list(map(int,input().split()))
    g[j].add(k)
    g[k].add(j)
group=[]
tansaku=int(input())
for i in range(tansaku):
    a,b=list(map(int,input().split()))
    for k in range(len(group)):
        if a in group[k] and b in group[k]:
            print("yes")
            break
        elif a in group[k]:
            print("no")
            break
    else:
        grp,grp2=(BFS(a,b))
        grp=set(grp.keys())
        if b in grp:
            print("yes")
        else:print("no")
        group.append(grp)


Measured memory_bytes: 51472
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    int n;
    cin >> n;
    int p[n];
    rep(i, n) cin >> p[i];
    vector<int> ord(n);
    rep(i, n) ord[i] = i;
    sort(ord.begin(), ord.end(), [&](int x, int y) {
        return p[x] > p[y]; // argsort 降順
    });
    multiset<int> st;
    ll ans = 0;
    // 番兵
    st.insert(n);
    st.insert(n);
    st.insert(n);
    st.insert(-1);
    st.insert(-1);
    // Pの要素を大きい順に見ていくと、ある時点までに見たすべての要素はその時点で
    // 見た要素より大きい要素となる
    for (auto i : ord) {
        auto itr = st.lower_bound(i);
        ll idx1 = *itr;
        ++itr;
        ll idx2 = *itr;
        --itr;
        --itr;
        ll idx3 = *itr;
        --itr;
        ll idx4 = *itr;
        ans += p[i] * (idx2-idx1)*(i-idx3);
        ans += p[i] * (idx3-idx4)*(idx1-i);
        st.insert(i);
    }
    
    cout << ans << "\n";
}


Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.math.*;

public class Main {
    private static Scanner sc;

    public static void main(final String[] args) {
        final Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null)
                br.close();
        }

        public String next() throws IOException {
            if (i < s.length)
                return s[i++];
            String st = br.readLine();
            while (st == "")
                st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }

        public long[] nextLongArray(int n) throws NumberFormatException, IOException {
            long[] ret = new long[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextLong();
            }
            return ret;
        }

        public int[] nextIntArray(int n) throws NumberFormatException, IOException {
            int[] ret = new int[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextInt();
            }
            return ret;
        }
    }

    private void solve() {
        try {
            int x = sc.nextInt();
            int n = sc.nextInt();
            if(n==0){
                System.out.println(x);
                return;
            }
            List<Integer> list =new ArrayList<>();
            for(int i=0;i<n;i++){
                list.add(sc.nextInt());
            }

            
            for(int i=0;i<100;i++){
               if(!list.contains(x-i)){
                System.out.println(x-i);
                return;
               }else if(!list.contains(x+i)){
                System.out.println(x+i);
                return;
               }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}


Measured memory_bytes: 32692
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n,x,t;
    cin >> n >> x >> t;
    cout << t * (n / x + (n % x != 0));
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
using namespace std;int n;void d(int *a, bool f){for(int k=0;k<n;k++){if(f)cin >> a[k];cout << a[k];cout << (k == n-1?"\n":" ");}}int main(){cin >> n;int a[n];d(a,1);for(int i=0;i<n-1;i++){int j=i;while(j>=0&&a[j]>a[j+1]){swap(a[j],a[j+1]);j--;}d(a,1);}return 0;}



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

using namespace std;
int main()
{
    int a,e,j=0;
 	cin>>a;
 	for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            if(j*i==a)
                {
                    cout<<"Yes";
                    j++;
                    exit(0);
                }
        }
    }
    if(j==0)
        cout<<"No";
}


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

int main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin>>s;
    bool b=true;
    int h=0, ii=0;
    for(int i=0; i<s.length(); i++){
        if(i%2==0 && s[i]!='h' )  {b=false; break;}
        else if(i%2!=0 && s[i]!='i') {b=false; break;}
        h+= (s[i]=='h');
        ii+= (s[i]=='i');
 
    }

    cout<<(b && (h==ii) ? "Yes" : "No");
}


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

int n;
int x[100],y[100];
int m;
char s[30];int l;

int main(){
	int i,j;
	
	while( cin >> n ){
		if( !n )break;
		for( i = 0; i < n; i++ ){
			cin >> x[i] >> y[i];
		}
		
		int befx = 10, befy = 10;
		int nowx = 10, nowy = 10;
		bool flag[100] = {false};
		cin >> m;
		for( i = 0; i < m; i++ ){
			cin >> s >> l;
			if( s[0] == 'N' ){
				nowy += l;
				for( j = 0; j < n; j++ ){
					if( nowx == x[j] && befy <= y[j] && y[j] <= nowy )
						flag[j] = true;
				}
			}
			if( s[0] == 'S' ){
				nowy -= l;
				for( j = 0; j < n; j++ ){
					if( nowx == x[j] && nowy <= y[j] && y[j] <= befy )
						flag[j] = true;
				}
			}
			if( s[0] == 'E' ){
				nowx += l;
				for( j = 0; j < n; j++ ){
					if( nowy == y[j] && befx <= x[j] && x[j] <= nowx )
						flag[j] = true;
				}
			}
			if( s[0] == 'W' ){
				nowx -= l;
				for( j = 0; j < n; j++ ){
					if( nowy == y[j] && nowx <= x[j] && x[j] <= befx )
						flag[j] = true;
				}
			}
			befx = nowx;
			befy = nowy;
		}
		for( i = 0; i < n; i++ ){
			if( flag[i] == false )
				break;
		}
		if( i < n )
			cout << "No" << endl;
		else
			cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(int i=0; i<n; i++)

int main() {
  int N;
  cin >> N;
  vvi food(N, vi(3) );
  rep(i,N) {
    cin >> food[i][0];
  }
  rep(i,N) {
    cin >> food[i][1];
  }
  rep(i,N-1) {
    cin >> food[i][2];
  }

  int ans = 0;
  rep(i,N) {
    ans += food[food[i][0]-1][1];
    if(i>0 && (food[i][0]-1) == food[i-1][0]) {
      ans += food[food[i-1][0]-1][2];
    }
    
  }
  cout << ans << endl;
  // cout << food[food[0][0]-1][1] << endl;

  return 0;
}

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

int main(){
    int n;

    while(cin >> n){
        int result = 0;
        vector<int> p;
        int tmp;
        for(int i=1; i<=n; i++){
            cin >> tmp;
            p.push_back(tmp);
        }
        sort(p.begin(), p.end());
        tmp = 0;
        for(int i=1; i<=n; i++){
            result += tmp + p[i-1];
            tmp += p[i-1];
        }
        cout << result << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cmath>
#include <cfloat>
#include <algorithm>
using namespace std;

int main() {
  char buf[200];
  int r[12];
  double p[12][12];
  double dp[1<<12][12];
  double ans;
  int w;
  int n, iread, ibuf;
  int v;
  while (fgets(buf, sizeof(buf), stdin)) {
    n = 0;
    ibuf = 0;
    sscanf(buf, "%d%n", &w, &iread);
    ibuf += iread;
    while (n < 12 && sscanf(buf+ibuf, "%d%n", &r[n], &iread) == 1) {
      n++;
      ibuf += iread;
    }

    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
        if (i==j) {
          p[i][j] = 0.0;
        } else {
          p[i][j] = 2.0 * sqrt(r[i] * r[j]);
        }
      }
    }
    for (int i=0; i<(1<<n); i++) {
      for (int j=0; j<n; j++) {
        dp[i][j] = DBL_MAX;
      }
    }

    v = (1<<n)-1;
    for (int i=0; i<n; i++) dp[v][i] = r[i];
    --v;
    while (v) {
      for (int i=0; i<n; i++) {
        if (!(v & (1<<i))) continue;
        for (int j=0; j<n; j++) {
          if (v & (1<<j)) continue;
          dp[v][i] = min(dp[v][i], dp[v|(1<<j)][j]+p[i][j]);
        }
      }
      --v;
    }
    ans = DBL_MAX;
    for (int i=0; i<n; i++) {
      ans = min(ans, dp[1<<i][i]+r[i]);
    }
    if (ans <= w) {
      printf("OK\n");
    } else {
      printf("NA\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1404
# solution

data=int(input())

dp=[10**5]*(data+1)

dp[0]=0

for i in range(data+1):
    pow=1
    while pow<=data:
        dp[i]=min(dp[i],dp[i-pow]+1)
        pow*=6
    pow=1
    while pow<=data:
        dp[i]=min(dp[i],dp[i-pow]+1)
        pow*=9
print(dp[data])


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

vector < vector<int> > hyou(1010, vector<int>(1010, -10));
int dh[] = {0, 1, 0, -1};
int dw[] = {1, 0, -1, 0};

typedef pair<int, int> P;
typedef pair<int, P> Q;

int search(int h, int w, int n) {
	int counter = 0;
	queue<Q> que;
	Q p;
	(p.second).first = h;
	(p.second).second = w;
	p.first = 0;
	que.push(p);
	if (hyou[h][w] == 0) {
		hyou[h][w] = -11;
	} else {
		hyou[h][w] = - hyou[h][w];
	}
	while (!que.empty()) {
		Q pp = que.front();
		que.pop();
		bool hantei = false;
		for (int i = 0; i < 4; i++) {
			if (hyou[(pp.second).first+dh[i]][(pp.second).second+dw[i]] >= 0 ) {
				Q pq;
				(pq.second).first = (pp.second).first+dh[i];
				(pq.second).second = (pp.second).second+dw[i];
				pq.first = pp.first+1;
				if (hyou[(pq.second).first][(pq.second).second] == n) {
					counter = pq.first;
					hantei = true;
					break;
				} else {
					if (hyou[(pq.second).first][(pq.second).second] == 0) {
						hyou[(pq.second).first][(pq.second).second] = -11;
					} else if (hyou[(pq.second).first][(pq.second).second] > 0) {
						hyou[(pq.second).first][(pq.second).second] = -hyou[(pq.second).first][(pq.second).second];
					}
				}
				que.push(pq);
			}
		}
		if (hantei) {
			break;
		}
	}
	for (int i = 0; i < 1010; i++) {
		for (int j = 0; j < 1010; j++) {
			if (hyou[i][j] == -11) {
				hyou[i][j] = 0;
			} else if (hyou[i][j] > -10 && hyou[i][j] < 0) {
				hyou[i][j] = -hyou[i][j];
			}
		}
	}
	return counter;
}

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	char c;
	int sh, sw;
	int data[9][2];
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> c;
			if (c == '.') {
				hyou[i][j] = 0;
			} else if (c == 'S') {
				hyou[i][j] = 0;
				sh = i;
				sw = j;
			} else if (c == 'X') {
				hyou[i][j] = -10;
			} else {
				int d = c - '0';
				hyou[i][j] = d;
				data[d-1][0] = i;
				data[d-1][1] = j;
			}
		}
	}
	int counter = 0;
	for (int i = 0; i < n; i++) {
		counter += search(sh, sw, i+1);
		sh = data[i][0];
		sw = data[i][1];
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 4968
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll n, k;
static ll a[1200000];
ll mae = 0, usiro = 0;
ll kaisu = 0;


ll kiri(ll a, ll b) {
	return (a + (b - 1)) / b;
}

int main() {

	cin >> n >> k;
	//REP(i, n) {
	//	cin >> a[i];
	//}

	//bool start = false;
	//REP(i, n) {
	//	if (start==false) {
	//		if (a[i] == 1) {
	//			start = true;
	//		}
	//		else {
	//			mae++;
	//		}
	//	}
	//	else {
	//		usiro++;
	//	}
	//}

	////もし、前がk-1より少ないなら
	//if (k - 1 > mae) {
	//	usiro -= (k - 1) - mae;
	//}

	//kaisu = kiri(mae, k - 1) + kiri(usiro, k - 1);

	//cout << kaisu << endl;

	ll kaisu = 0;
	while (1) {
		if (n - k <= 0) {
			kaisu++;
			cout << kaisu << endl;
			return 0;
		}
		else {
			kaisu++;
			n -= k - 1;

		}
	}

	return 0;
}


Measured memory_bytes: 256
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    d = collections.defaultdict(int)
    s = [str(input().rstrip('\n')) for _ in range(n)]
    for i in range(n):
        if i != 0:
            if s[i][0] != s[i-1][-1] or s[i] in d:
                print("No")
                exit()
        d[s[i]]
    print("Yes")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<ll> cnt(n+1);
    cnt[0] = 0;
    for(ll i = 1; i <= n; i++) {
        if(s[i-1] == 'A' && s[i] == 'C') cnt[i] = cnt[i-1] + 1;
        else cnt[i] = cnt[i-1];
    }
    rep(i, 0, q) {
        ll l, r;
        cin >> l >> r;
        l--, r--;
        cout << max(0LL, cnt[r] - cnt[l]) << endl;
    }
}

Measured memory_bytes: 1792
ary = []
while true
  i = STDIN.gets.split
  break if i[1] == '?'
  i[0] = i[0].to_i
  i[2] = i[2].to_i
  ary.push i
end

ary.each do |a|
  puts case a[1]
  when '+' then a[0] + a[2]
  when '-' then a[0] - a[2]
  when '*' then a[0] * a[2]
  when '/' then a[0] / a[2]
  end
end

Measured memory_bytes: 6100
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
#include <queue>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}

int N,K;
vector<ll> h;

ll dp[100010];

void func(int n)
{
	if(dp[n] < INF) return;
	if(n == N + 1) return;

	for(int k = 1; k <= K && n - k >= 0; k++)
	{
		chmin(dp[n], dp[n - k] + abs(h[n] - h[n - k]));
	}
	func(n + 1);
}

int main()
{
	cin >> N >> K;
	h.resize(N);
	for(int i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	for(int i = 0; i < 100010; i++) dp[i] = INF;
	dp[0] = 0;
	func(1);
	cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1792
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

vi  g[10005]; 
bool vis[10005];

inline void solve(){
	int n,ans = 0; cin>>n; 
    vi c(n),res(n+1); 
    for (int i=0;i<n-1;i++){ 
    	int  u, v ; 
    	cin >> u >> v ; 
    	g[u].pb(v) ; 
    	g[v].pb(u) ; 
    } 
    for (int i=0;i<n;i++) cin >> c[i] ; 
    sort(all(c)) ; 
	int  i = n-2 ; 
    function < void(int) > dfs = [&] (int u){
    	if (vis[u]) return ; 
    	vis[u] = true;
    	for (auto &it: g[u]){
    		if (!vis[it]){
    			ans += res[it] = c[i--] ; 
    			dfs(it); 
    		}
    	}
    };
    res[1] = c[n-1] ; 
    dfs(1) ; 
    co (ans) ; 
    for (int i=1;i<=n;i++) 
    	cout << res[i] << " " ; 
    cout << endl; 
}

signed main()
{
    solve();
    return 0;
}
/* 

5 
1 2 
1 3 
3 4 
3 5 
2 3 4 5 6 

		ans -> 14 



*/

Measured memory_bytes: 4912
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String W[] = new String[N];
    for(int i=0;i<N;i++){
      W[i]=sc.next();
    }
    for(int i=0;i<N-1;i++){
      if(!W[i].substring(W[i].length()-1,W[i].length()).equals(W[i+1].substring(0,1))){
        System.out.println("No");
        return;
      }
    }
    Arrays.sort(W);
    for(int i=0;i<N-1;i++){
      if(W[i].equals(W[i+1])){
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
         
  }
  

  
}

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

int main() {
  int n,m;
  cin>>n>>m;
  string a[n],b[m];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<m;i++) cin>>b[i];
  bool ans=false;
  for(int i=0;i<=n-m;i++){
    for(int j=0;j<=n-m;j++){
      int cnt=0;
      for(int k=0;k<m;k++){
        if(b[k]==a[i+k].substr(j,m)) cnt++;
      }
      if(cnt==m) {
        ans=true;
        break;
      }
    }
    if(ans) break;
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	string A;
  	cin >> A;
  
  	if(A=="RRR"){
    	cout << 3 << endl;
    }
  	else if(A=="RRS" ){
    	cout << 2 << endl;
    }
  	else if(A=="RSR" ){
    	cout << 1 << endl;
    }
  	else if(A=="SRR"){
    	cout << 2 << endl;
    }
  	else if(A=="RSS" ){
    	cout << 1 << endl;
    }
  	else if(A=="SRS" ){
    	cout << 1 << endl;
    }
  	else if(A=="SSR" ){
    	cout << 1 << endl;
    }
  	else if(A=="SSS" ){
    	cout << 0 << endl;
    }
 
}


Measured memory_bytes: 3620
fun main(args: Array<String>) {
    var s = readLine()!!.toList().map{Character.getNumericValue(it)}
    var remainders = Array(2019){0}
    var remainder = 0
    var ten = 1
    var ans = 0L
    for ((i, si) in s.reversed().withIndex()) {
        remainder = (ten * si + remainder)%2019
        remainders[remainder] += 1
        ten *= 10
        ten %= 2019
    }
    for (r in remainders) {
        if (r>1) {
            ans += r*(r-1)/2L  
        }
    }
    ans += remainders[0]
    println(ans)
}



Measured memory_bytes: 45944
var i = 0

fun main(args: Array<String>) {
    val hwkList = readLine()!!.split(" ").map(String::toInt)
    val cList: MutableList<MutableList<Boolean>> = MutableList(hwkList[0]) {
        val x = readLine()!!.toString()
        val list = mutableListOf<Boolean>()
        x.forEach {
            if (it == '#') {
                list.add(true)
            } else {
                list.add(false)
            }
        }
        list
    }
    var res = if (calc(cList) == hwkList[2]) 1 else 0
    res += calcCol(cList, 0, hwkList[2], 9999)
    res += calcRow(cList, 0, hwkList[2])
    println(res)
}

fun calcRow(arg: MutableList<MutableList<Boolean>>, index: Int, k: Int): Int {
    var res = 0
    for (i in index until arg.size) {
        val tmpList = arg.toMutableList()
        tmpList.removeAt(i)
        val calc = calc(tmpList)
        if (calc == k) {
            res++
        }
        if (tmpList.size > 0 && calc >= k) {
            res += calcRow(tmpList, i, k)
            res += calcCol(tmpList, 0, k, i)
        }


    }
    return res
}

fun calcCol(arg: MutableList<MutableList<Boolean>>, index: Int, k: Int, row: Int): Int {
    var res = 0

    for (i in index until arg[0].size) {
        val tmpList = arg.map {
            val tmp = it.toMutableList()
            tmp.removeAt(i)
            tmp
        }.toMutableList()
        val calc = calc(tmpList)
        if (calc == k) {
            res++
        }
        if (calc >= k) {
            res += calcCol(tmpList, i, k, row)
        }


    }
    i++

    return res
}

fun calc(arg: MutableList<MutableList<Boolean>>): Int {
    var res = 0
    arg.forEach { row ->
        row.forEach { cal ->
            if (cal) res++
        }
    }
    i++
    return res
}


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

using namespace std;

typedef pair<int,int> pi;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll A, B, W, V, T;
	cin >> A >> V;
	cin >> B >> W;
	cin >> T;
	if (W >= V || abs(B-A) > T*(V-W)) cout << "NO\n";
	else cout << "YES\n";
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<iostream>

using namespace std;

int W,H,N;
int x[110],y[110],a[110];
int main(){
    cin >> W >> H >> N;
    for(int i=0; i<N; i++) cin >> x[i] >> y[i] >> a[i];
    int minh = 0, minw = 0;
    for(int i=0; i<N; i++){
        if( a[i] == 1 ) minw = max( x[i], minw);
        if( a[i] == 2 ) W = min( x[i], W);
        if( a[i] == 3 ) minh = max( y[i], minh);
        if( a[i] == 4 ) H = min( y[i], H);
    }
    cout << ( max( W - minw, 0) ) * ( max( H - minh, 0) )  << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
const ld eps = 1e-4;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int d; cin >> d;
    int c[26];
    REP(i,26) cin >> c[i];
    int lsum = 0;
    REP(i,26) lsum += c[i];
    int v[d][26];
    REP(i,d)REP(j,26) cin >> v[i][j];
    V<> sol(d);
    V<> loss(26,0);
    REP(i,d){
        V<pair<ld,ll>> score(26,{0.0,0});
        REP(j,26) score[j] = {v[i][j] + loss[j] + c[j] * eps, j};
        sort(rall(score));
        int r = score[0].second;
        sol[i] = r;
        REP(j,26){
            if(j == r) loss[j] = 0;
            else loss[j] += c[j];
        }
    }
    REP(i,26) loss[i] = 0;
    ll nowres = 0;
    REP(i,d){
        nowres += v[i][sol[i]];
        REP(j,26){
            if(j == sol[i]) loss[j] = 0;
            else loss[j] += c[j];
            nowres -= loss[j];
        }
    }
    int Q = 245000;
    random_device rnd;
    int newi, newsol, old;
    ll newres;
    while(Q--){
        newi = rnd() % 365;
        newsol = rnd() % 26;
        if(sol[newi] == newsol) continue;
        old = sol[newi];
        sol[newi] = newsol;
        REP(i,26) loss[i] = 0;
        newres = 0;
        REP(i,d){
            newres += v[i][sol[i]];
            REP(j,26){
                if(j == sol[i]) loss[j] = 0;
                else loss[j] += c[j];
                newres -= loss[j];
            }
        }
        if(newres <= nowres) sol[newi] = old;
        else nowres = newres;
    }
    REP(i,d) cout << sol[i] + 1 << '\n';
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926

int a[3];

int main(){
    char a;
    cin >> a;
    if(a == 'A')
        cout << "T";
    else if(a == 'C')
        cout << "G";
    else if(a == 'T')
        cout << "A";
    else if(a == 'G')
        cout << "C";
}
	


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

###
# main
if(__name__ == '__main__'):
    # input
    n = int(input())
#    li = []
    min_list = []
    max_list = []
    for _ in range(n):
        a, b = map(int, input().split(" "))
#        li.append([a, b])
        min_list.append(a)
        max_list.append(b)

    min_list.sort()
    max_list.sort()

    min_val2 = 1
    max_val2 = 1
    if n%2 == 0:
        cent1 = n//2-1
        cent2 = n//2
        min_val2 = min_list[cent1] + min_list[cent2]
        max_val2 = max_list[cent1] + max_list[cent2]
    else:
        cent = (n+1)//2-1
        min_val2 = min_list[cent]
        max_val2 = max_list[cent]

    ans = max_val2 - min_val2 + 1
    print(ans)

# else:
    # do nothing


Measured memory_bytes: 25348
# -*- coding: utf-8 -*-

import itertools

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

menu = (a, b, c ,d , e)
l_menu = list(itertools.permutations(menu))
t = 0
min_t =1000000

for i in range(len(l_menu)):
    for j in range(5):
        t += l_menu[i][j]
        if t % 10 > 0 and j <4:
            t += 10 - (t % 10)
    if min_t > t:
        min_t = t
    t = 0

print(min_t)

Measured memory_bytes: 3064
#include<stdio.h>
int A[1000000];
int main()
{
    int H,N;
    scanf("%d%d",&H,&N);
    for (int i=0;i<N;i++)
    {
         scanf("%d",&A[i]);
         H-=A[i];
    }

    if(H<=0)
    {
        printf("Yes");
    }
    else
    {
           printf("No");

    }
        return 0;
}


Measured memory_bytes: 512
W, H, N = map(int, input().split())
x, y, a = [], [], []
for i in range(N):
    ex, ey, ea = map(int, input().split())
    x.append(ex)
    y.append(ey)
    a.append(ea)

down = 0
up = H
left = 0
right = W

for i in range(N):
    if a[i] == 1:
        left = max(left, x[i])
    elif a[i] == 2:
        right = min(right, x[i])
    elif a[i] == 3:
        down = max(down, y[i])
    else:
        up = min(up, y[i])

print(max(right-left, 0) * max(up-down, 0))

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

#define MAX 50
typedef pair<int,int> P;
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};

int main() {
  int H, W;
  char M[MAX][MAX];
  int D[MAX][MAX];
  int wcnt = 0;

  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> M[i][j];
      if (M[i][j] == '.') ++wcnt;
      D[i][j] = -1;
    }
  }

  --wcnt;
  queue<P> que;
  que.push(P(0,0));
  D[0][0] = 0;
  bool ok = false;
  while (que.size()) {
    P p = que.front(); que.pop();
    if (p.first == H - 1 && p.second == W - 1) {
      ok = true;
      break;
    }

    for (int i = 0; i < 4; ++i) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (0 <= ny && ny < H &&
          0 <= nx && nx < W &&
          M[ny][nx] == '.' &&
          D[ny][nx] == -1) {
        que.push(P(ny,nx));
        D[ny][nx] = D[p.first][p.second] + 1;
      }
    }
  }

  if (ok) {
    cout << wcnt - D[H-1][W-1] << endl;
  } else {
    cout << "-1" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
//		String[] tmpArray = br.readLine().split(" ");
//		double r = Double.parseDouble(tmpArray[0]);
//		int b = Integer.parseInt(tmpArray[1]);
//		int c = Integer.parseInt(tmpArray[2]);
//		int y = Integer.parseInt(tmpArray[3]);
//		int r = Integer.parseInt(tmpArray[4]);
		
		while(true){
			String[] tmpArray = br.readLine().split(" ");
			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[2]);
			if(tmpArray[1].equals("?")){
				break;
			}
			String op = tmpArray[1];
			if(op.equals("+")){
				System.out.println(a+b);
			}
			if(op.equals("-")){
				System.out.println(a-b);
			}
			if(op.equals("*")){
				System.out.println(a*b);
			}
			if(op.equals("/")){
				System.out.println(a/b);
			}
			
		}

		//		int[] array = new int[3];
//		array[0] = a; array[1] = b; array[2] = c;
//
//		Arrays.sort(array);
//		System.out.printf("%d %d %d\n", array[0], array[1], array[2]);
		/*
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}*/
	}

}

Measured memory_bytes: 24240