akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bitset>
using namespace std;

int R , C , K , ans;
string area[6];
void coba_row(int , int);
void coba_col(int , int , int);
int main(){
    cin >> R >> C >> K;
    for (int i = 0 ; i < R ; i++)
        cin >> area[i];
    coba_row(0 , 0);

    cout << ans << endl;
}
void coba_row(int i , int mask){
    if (i == R){
        coba_col(0 , 0 , mask);
        return;
    }
    coba_row(i + 1 , mask | (1 << i));
    coba_row(i + 1 , mask);
}
void coba_col(int i , int mask_col , int mask_row){
    if (i == C){
        bitset<6>c_row , c_col;
        for (int i = 0 ; i < R ; i++){
            if (mask_row & (1 << i))
                c_row[i] = 1;
        }
        for (int i = 0 ; i < C ; i++){
            if (mask_col & (1 << i))
                c_col[i] = 1;
        }
        int cnt = 0;
        for (int i = 0 ; i < R ; i++){
            if (c_row[i])
                continue;
            for (int j = 0 ; j < C ; j++){
                if(c_col[j])
                    continue;
                if (area[i][j] == '#')
                    ++cnt;
            }
        }
        if (cnt == K)
            ++ans;
        return;
    }
    coba_col(i + 1 , mask_col | (1 << i) , mask_row);
    coba_col(i + 1 , mask_col , mask_row);
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>

int main(){
    int n;
    long long g;
    scanf("%d",&n);
    long long h[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&h[i]);
        if(i>0){
            g=h[i]-h[i-1];
            if(g>=0){
                if(g==0){
                    h[i]=h[i-1];
                }
                else{
                    h[i]-=1;
                }
            }
            else{
                printf("No\n");
                exit(0);
            }
        }
    }
    printf("Yes\n");
}


Measured memory_bytes: 896
#include<stdio.h>

#define N 100

int selectionSort(int *, int);

int main(){

  int A[N],n,i,cunt;

  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&A[i]);

  cunt =  selectionSort(A,n);

  for(i=0;i<n-1;i++)printf("%d ",A[i]);
  printf("%d\n",A[i]);
  printf("%d\n",cunt);
  
  return 0;

}

int selectionSort(int A[], int n){
  int i,j,key,cunt = 0,minj;

  for(i=0;i<n;i++){
    minj = i;

    for(j=i;j<n;j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    key = A[i];
    A[i] = A[minj];
    A[minj] = key;
    if(i != minj)cunt++;
  }
  return cunt;
}

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

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

  vector<ll> a(n);
  
  double top=0,low=0;
  ll m=0;
  for(ll i=0;i<n;i++){
     cin >> a[i];
     m = max(a[i],m);
  }
  top = m;
  while((top-low)>0.01){
    double temp = (top+low)/2;
    ll cnt=0;
    for(ll i=0;i<n;i++){
      cnt = cnt + int(a[i]/temp-0.00000000001);
    }
    if(cnt<=k)  top = temp;
    else low = temp;
  }
  cout << ll(top+0.99999) << endl;
}

Measured memory_bytes: 4768
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

sx, sy, tx, ty = map(int, raw_input().split())

S = ''
S += 'R' * (tx - sx)
S += 'U' * (ty - sy)
S += 'L' * (tx - sx)
S += 'D' * (ty - sy)
S += 'D'
S += 'R' * (tx - sx + 1)
S += 'U' * (ty - sy + 1)
S += 'L'
S += 'U'
S += 'L' * (tx - sx + 1)
S += 'D' * (ty - sy + 1)
S += 'R'

print S

Measured memory_bytes: 2808
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main()
{
    double takaHP, takaAtk, AoHP, AoAtk;
    cin >> takaHP >> takaAtk >> AoHP >> AoAtk;
    
    int takaNum = ceil(takaHP / AoAtk);
    int AoNum = ceil(AoHP / takaAtk);

    if(takaNum >= AoNum) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3724
ans = [1]*365
for i in range(26*5):
    ans[i]=i%26 + 1

for i in range(26*5,26*10):
    ans[i]=i%13 + 1

for i in range(26*10,365):
    ans[i]=i%26 + 1

for i in range(365):
    print(ans[i])

Measured memory_bytes: 9108
#include <iostream>
using namespace std;
int main(void)
{
	char c[5];
	char n[] = "A";
	while(cin>>c){
		if(c[0]==n[0]) n[0] = c[2];
		else if( c[2] == n[0] ) n[0] = c[0];
	}
	putchar(n[0]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 0
function Main(input) {
    input = input.split("\n");
    var mem = input[0].split(" ");
    var arr = input[1].split(" ").map(Number);
    for (var p = 0; p < mem[1]; p++) {
        var tmp = new Array(arr.length).fill(0);
        for (var i = 0; i < arr.length; i++) {
            var n = arr[i];
            var min = i - n;
            var max = i + n+1;
            if (min < 0) min = 0;
            if (max > arr.length - 1) max = arr.length;
            tmp[max]--;
            tmp[min]++;
           // console.log(min,max)
            //imos法?
        }
        tmp.length = mem[0];
        for (var s = 1 ; s < tmp.length; s++) {
            tmp[s] += tmp[s - 1];
        }
     //   console.log(tmp)
        //  console.log(arr)
        var flag = true;
        //  console.log(arr.length)
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] != tmp[i]) flag = false;
            arr[i] = tmp[i];
        }
        //   console.log(arr.join(" "));
        if (flag) break;
    }
    console.log(arr.join(" "));
} Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


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

int const N = 2e5 + 10;

int n, pos[N];
long long a[N];

void solve ()
{
	long long ans = 0;

	set <int> idx;
	set <int> :: iterator it;

	idx.insert (0);
	idx.insert (n+1);

	for (int i = 1; i <= n; i++)
	{
		idx.insert (pos[i]);

		it = idx.upper_bound (pos[i]);
		long long A = (*it) - pos[i];

		it = idx.find (pos[i]);
		it--;
		long long B = (pos[i]) - (*it); 
		
		ans += A * B * (long long) (i);
	}

	cout << ans << '\n';
}

int main ()
{
	cin.sync_with_stdio (false);

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		pos[a[i]] = i;
	}

	solve ();

	return 0;
}

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

int main() {
  int A,B,K,i,j;
cin>>A>>B>>K;
if(K%2==0){
for(i=0;i<K/2;i++){
if(A%2==1){
A=A-1;
}
A=A/2;
B=B+A;
if(B%2==1){
B=B-1;
}
B=B/2;
A=A+B;
}
} else{
for(j=0;j<K/2;j++){
if(A%2==1){
A=A-1;
}
A=A/2;
B=B+A;
if(B%2==1){
B=B-1;
}
B=B/2;
A=A+B;
}
if(A%2==1){
A=A-1;
}
A=A/2;
B=B+A;
}
cout<<A<<" "<<B<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, A, B, h[100010];

//f(x in [MIN, l]) = false, f(x in [r, MAX]) = true
long long binsearch(long long l, long long r, bool (*f)(long long)){
    if(f(l)) return l;
    while(r - l > 1){
        long long m = (l + r) / 2;
        if(f(m)) r = m;
        else l = m;
    }
    return r;
}

bool f(ll k){
    ll cnt = 0;
    REP(i, N){
        cnt += max(0LL, (h[i] - B * k + A - B - 1) / (A - B));
    }
    return cnt <= k;
}

signed main(){
    cin >> N >> A >> B;
    REP(i, N) cin >> h[i];
    PRINT(binsearch(0, (ll)(1e9 + 1), f));
    return 0;
}

Measured memory_bytes: 4308
mark = ['S','H','C','D']
card ={ (n,format(k)):0 for n in mark for k in range(1,14)}
n = int(input())
for num in range(n):
    card[tuple(input().split())] = 1
for m ,n in card.items():
    if n == 0:
        k,j = m
        print( "{} {}".format(k,j))


Measured memory_bytes: 5600
# coding:utf-8

import sys


input = sys.stdin.readline
INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

S = [0]
for i in range(N):
    S.append(S[-1] + A[i])

S.sort()
cnt = 1
prev = None
ans = 0
for s in S:
    if prev == s:
        prev = s
        cnt += 1
    else:
        prev = s
        ans += cnt * (cnt - 1) // 2
        cnt = 1

if cnt != 1:
    ans += cnt * (cnt - 1) // 2

print(ans)


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

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

  int total = 0;

  if(A > B){
      total += A;
      A--;
  }
  else{
      total += B;
      B--;
  }

  if(A > B){
      total += A;
      A--;
  }
  else{
      total += B;
      B--;
  }

    cout << total << endl;

}

Measured memory_bytes: 256
s=str(input())
def isPalin(l,r):
  if l >= r:
    return True
  if s[l]!=s[r]:
    return False
  return isPalin(l+1,r-1)
n = len(s)
if isPalin(0,n-1) and isPalin(0,n//2-1) and isPalin(n//2+1,n-1):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
n = int(input())
s = list(map(int,input().split()))
q = int(input())
t = list(map(int,input().split()))

# 二分探索
def binarySearch(A: [int], key: int):
    left = 0
    right = len(A)
    mid = 0
    while left < right:
        mid = (left+right)//2
        if key == A[mid]:
            return 1
        if key > A[mid]:
            left = mid + 1
        elif key < A[mid]:
            right = mid;
    return 0

c = 0
s.sort()
for i in range(len(t)):
    if binarySearch(s, t[i]):
        c += 1
print(c)


Measured memory_bytes: 16708
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 998244353

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

void add(long long &x, long long y){
    x = (x + y) % MOD;
}

int main(){
    int N, S;
    cin >> N >> S;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    vector<vector<vector<long long>>> dp(N+1, vector<vector<long long>>(S+1, vector<long long>(3)));

    dp[0][0][0] = 1;
    for(int i=0; i<N; i++){
        dp[i+1] = dp[i];
        add(dp[i+1][0][1], dp[i+1][0][0]);
        for(int j=S-A[i]; j>=0; j--){
            add(dp[i+1][j+A[i]][1], dp[i+1][j][1]);
        }
        for(int j=0; j<=S; j++){
            add(dp[i+1][j][2], dp[i+1][j][1]);
        }
    }
    long long ans = dp[N][S][2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 493056
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define ll long long
#define int long long
#define Size(v) (int)v.size()

using namespace std;
// using namespace __gnu_pbds;

// const int mask = (1 << 15);

const int nax = 1005;
const int constmask = (1 << 15);
int a[nax], b[nax];
int dp[nax][(1 << 15)]; // minimum cost to cover with first i item and mask "mask"
const int INF = 1e9;

int calc(int i, int mask) {
	if (i <= 0) {
		if (mask != 0) return INF;
		else if (mask == 0) return 0;
	}
	if (dp[i][mask] != -1) return dp[i][mask];

	int ret = INF;

	// chon cai thu i:
	int nmask = (mask ^ (mask & b[i]));

	// cerr << "nmask - mask - b[i]: " << nmask << ' ' << mask << ' ' << b[i] << '\n';

	ret = min(ret, calc(i - 1, nmask) + a[i]);
	ret = min(ret, calc(i - 1, mask));

	return (dp[i][mask] = ret);
}

void solve() {
	int n, m;

	cin >> n >> m;

	for (int i = 0; i < nax; ++i) {
		for (int m = 0; m < constmask; ++m) {
			dp[i][m] = -1;
		}
	}

	for (int i = 1; i <= m; ++i) {
		int num;
		cin >> a[i] >> num;

		for (int j = 1; j <= num; ++j) {
			int c;
			cin >> c;
			--c;

			b[i] |= (1 << c);
		}
	}

	cout << ((calc(m, (1 << n) - 1) != INF) ? calc(m, (1 << n) - 1) : -1);
}

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

	int t = 1;
	while (t--) 
		solve();
	return 0;
}

Measured memory_bytes: 260960
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
    int key;
    Node *next, *prev;
};

Node *null;//番兵セット

void init(){//初期化
    null = (Node *)malloc(sizeof(Node));
    null->next = null;
    null->prev = null;
}

void insert(int key){//挿入
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    //xをnullとnull->nextの間に挿入する
    x->next = null->next;
    null->next->prev = x;
    null->next = x;
    x->prev = null;
}

Node* listSearch(int key){//探索
    Node *cur = null->next;
    while (cur != null && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t){//削除
    if(t == null){
        return;
    }
    //tの前と後ろのlistを繋げる
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);//メモリー解放
}

void deleteFirst(){//最初のlistを消す
    deleteNode(null->next);
}

void deleteLast(){//最後のlistを消す
    deleteNode(null->prev);
}

void deletakey(int key){//特定のlistを消す
    deleteNode(listSearch(key));
}

void printList(){
    Node *cur = null->next;
        int isf = 1;
    while(1){
        if ( cur == null ){
        break;
        }
        if ( isf == 0){
        printf(" ");
        }
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
  printf("\n");
}

int main(){
    int key, n, i;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++){
        scanf("%s%d", com, &key);
        if(com[0] == 'i'){
            insert(key); np++;
        }
        else if (com[0] == 'd'){
            if(strlen(com) > 6){
                if (com[6] == 'F'){
                    deleteFirst();
                }
                else if (com[6] == 'L'){
                    deleteLast();
                }
            }else{
                deletakey(key); nd++;
            }
        }
    }
    printList();
    return 0;
}


Measured memory_bytes: 33832
#pragma once
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#define rep(i,n) for(auto i=0;i<(n);i++)
#define all(vs) (vs).begin(),(vs).end()
#define roundup(A,B) (A)/(B)+((A)%(B)==0?0:1)
#define read(type,name) type name;cin>>name
using namespace std;


/*
  予想と答えをすべて比較するのが最速。O(n)
*/
void A() {
	string s, t;
	cin >> s >> t;
	int answer = 0;
	rep(i, s.length()) {
		if (s[i] == t[i])answer++;
	}
	cout << answer << endl;
}

/*
  タップを使うごとにA-1ずつ増える。Bと1の距離をA-1で割った（切り上げ）のが答え。
  A,Bの値によらないのでO(1)の解法である。
*/
void B() {
	int A, B; cin >> A >> B;
	cout << roundup(B-1, A-1) << endl;
}

/*
  左から走査することで最大長を求めることができる。最大長を0で初期化し、
  左端からスタートする。右に進める限り現在の長さをincrementし、進めなくなったところで最大長を更新する。
  そして止まったところからリセットして再開する。これを繰り返すことで最大長を求めることができる。
  計算量はO(n)、空間量はO(1)となる。
*/
void C() {
	int n; cin >> n;
	int length = 0, max_length = 0;
	int prev = 0, current;
	rep(i, n) {
		cin >> current;
		if (prev >= current) {
			length++;
		} else {
			max_length = max(max_length, length);
			length = 0;
		}
		prev = current;
	}
	max_length = max(max_length, length);
	cout << max_length << endl;
}

/*
　剰余を最大にするのは、MをM+1で割った場合であるから、
 iに対して1つずれた順列を作れば最適である。配列の最後Nについては、
 N+1を用意することはできないので、1で剰余を取る（必ず10になる）。
 このやり方で和を求めた場合は、1からN-1までの和に等しいので(N-1)(N)/2となる。
 　　->これが最大っていうのはどうわかるの?
*/
void D() {
	read(long long, n);
	cout << n * (n - 1) / 2 << endl;
}

int main() { D(); }



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

public class Main{

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

		int N = sc.nextInt();
		int L[] = new int[2*N];

		for(int i = 0;i<2*N;i++){
			L[i] = sc.nextInt();

		}
		Arrays.sort(L);

		int ans = 0;
		for(int i = 0;i<N;i++){
			ans += L[2*i];
		}
		System.out.println(ans);
	}
}

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

int main(){
  
  int j = 0;
  while (1){
    string S;
    cin >> S;
    if (S.size()==0){break;}
    int g = 'a'-'A';
    if(j==0){j++;}
    else{cout << ' ';}
    for(int i=0; i<S.size(); i++){
      
      
        if(('Z'>=S[i])&&(S[i]>='A')){
           S[i] += g;
        }else if(('z'>=S[i])&&(S[i]>='a')){
          S[i] -= g;
        }
    }
    cout << S;
  }
  cout << endl;
}


Measured memory_bytes: 3172
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long


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

    int n; cin >> n;
    vector<int> p(n);
    for(int i = 0;i < n;i ++) cin >> p.at(i);

    int ans = 0;
    for(int i = 0;i < n;i ++) if(p.at(i) == i+1) ans ++;

    for(int i= 0;i < n-1;i ++){
        if(p.at(i) == i+1 && p.at(i+1) == i+2){
        ans --; 
        i ++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#define MAXN 100010
int n, ans, f[MAXN];
std::vector<int> next[MAXN];
void gao(int x, int fa) {
	int tmp = 0, all = 0;
	for (int y : next[x])
		if (y != fa) gao(y, x), tmp |= all & f[y], all |= f[y];
	if (!all) {
		f[x] = 1;
		ans = std::max(ans, 1);
	} else {
		int count = 0;
		while (((1 << count) < tmp) || ((all >> count) & 1)) count++;
		f[x] = (all >> count << count) | (1 << count);
		ans = std::max(ans, count);
	}
}
int main() {
	scanf("%d", &n);
	for (int u, v, i = 1; i < n; i++) scanf("%d%d", &u, &v), next[u].push_back(v), next[v].push_back(u);
	gao(1, 0);
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    ll h, w, n;
    cin >> h >> w >> n;
    map<P, int> mp;
    vector<int> x(n), y(n);
    vector<vector<int>> vx(w + 1);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
        mp[P(x[i], y[i])]++;
        vx[y[i]].push_back(x[i]);
    }
    for (int i = 1; i <= w; i++)
    {
        sort(vx[i].begin(), vx[i].end());
        vx[i].push_back(h + 1);
    }
    // dp[j] := j 列目に入れる最小の x 座標
    vector<int> dp(w + 1, h + 1);
    dp[1] = 1;
    int res = *(upper_bound(vx[1].begin(), vx[1].end(), 1));
    for (int j = 2; j <= w; j++)
    {
        for (int i = dp[j - 1] + 1; i <= h; i++)
        {
            if (mp[P(i, j)])
                continue;
            dp[j] = i;
            break;
        }
        auto itr = upper_bound(vx[j].begin(), vx[j].end(), dp[j]);
        if(itr==vx[j].end()) continue;
        res = min(res, *itr);
    }
    cout << res - 1 << endl;
}


Measured memory_bytes: 35968
n, total = map(int, input().split(" "))

x = -1
y = -1
z = -1

for x_tmp in range(0, n + 1):
    for y_tmp in range(0, (n - x_tmp) + 1):
        z_tmp = n - (x_tmp + y_tmp) if n >= (x_tmp + y_tmp) else 0
        if total == (x_tmp * 10000 + y_tmp * 5000 + z_tmp * 1000):
            x, y, z = x_tmp, y_tmp, z_tmp

print(x, y, z, sep = " ")


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
using namespace std;
const int INF = 10000000;
typedef pair<int,int> P;

int H,W;
char s[51][51];
int d[51][51];
int dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

int bfs(){
    queue<P> que;
    for(int i =0;i<H;i++){
        for(int j=0;j<W;j++){
            d[i][j] = INF;
        }
    }
    que.push(P(0,0));
    d[0][0] = 1;

    while(que.size()){
        P p = que.front();
        que.pop();
        if(p.first == H-1 && p.second == W-1) break;
        for(int i=0;i<4;i++){
            int nx = p.first + dx[i] , ny = p.second + dy[i];
            if( nx>=0 && nx <H && ny >=0 && ny < W && s[nx][ny] != '#' && d[nx][ny] == INF ){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] +1;
            }
        }
    }
    return d[H-1][W-1];
} 
int main(){
    int black =0;
    cin >> H >> W;
    for(int i=0;i<H;i++){
        for(int j =0;j<W;j++){
            cin >> s[i][j];
        }
    }
        for(int i=0;i<H;i++){
        for(int j =0;j<W;j++){
            if(s[i][j] == '#') black++;
        }
    }

    int white =bfs();
    if(d[H-1][W-1] != INF)cout << H*W -black -white <<endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
t_list = [list(map(int,input().split())) 
          for nesya in range(n)]
dame = 0
ti = 0
tx = 0
ty = 0
for t in t_list:
  time = t[0]
  x_t = t[1]
  y_t = t[2]
  d = abs(y_t-ty)+abs(x_t-tx)
  h = time - ti
  if d > h or (h-d)%2 == 1:
    dame += 1
    print('No')
    break
  ti = time
  tx = x_t
  ty = y_t
if dame == 0:
  print('Yes')

Measured memory_bytes: 27324
#include <iostream>
using namespace std;
typedef long long ll;
static const ll Z = 1 << 21;
#define rep(i,s,n)for(ll i = s;i<n;i++)
char s[101][101];
char t[Z];
int N, L;

void strcopy(char *s, const char* t) {
	while ((*s++ = *t++) != '\0');
}

void strswap(char *s, char *t) {
	char D[101];
	char* d = &D[0];
	strcopy(d, t);
	strcopy(t, s);
	strcopy(s, d);
}

int strcomp(const char *s, const char* t) {
	while (*s == *t) {
		if (*s == '\0') {
			return 0;
		}
		s++;
		t++;
	}

	return *s - *t;
}

int main() {
	cin >> N >> L;
	rep(i, 0, N) {
		cin >> s[i];
	}

	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (strcomp(s[i], s[j]) > 0) {
				strswap(s[i], s[j]);
			}
		}
	}
	rep(i, 0, N) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

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

int N,M,Q;
vector<int>a,b,c,d;
int ans;

void dfs(vector<int> A){
  /*
  for(int i=0;i<A.size();i++){
    printf("%d",A[i]);
    printf(",");
  }
  printf("\n");
  */
  if(A.size()==N+1){
    int now=0;
    for(int i=0;i<Q;i++){
      if(A[b[i]]-A[a[i]]==c[i])now+=d[i];
    }
    ans=max(ans,now);
    
    return;
  }
  
  A.push_back(A.back());
  
  while(A.back()<=M){
    dfs(A);
    A.back()++;
  }
}

int main(){
  cin>>N>>M>>Q;
  a=b=c=d=vector<int>(Q);
  
  rep(i,Q){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
  }
  dfs(vector<int>(1,1));
  cout<<ans<<endl;
  
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,L;
  cin >> N >> L;
  
  int a=N*(2*L+N-1)/2-L;
  int b=N*(2*L+N-1)/2-L-N+1;    
  int c=N*(2*L+N-1)/2;
           
  if(L>0){
    cout << a << endl;
    }else if(L+N-1<0){
    cout << b << endl;
    }else{
    cout << c << endl;
}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int X;
    int sum=0;
    scanf("%d",&X);
    if(X==0) printf("0\n");
    else if(X>0){
        int n=0;
        while(sum<X){
            n++;
            sum+=n;
        }
        printf("%d", n);
    }
    else{
        int n=0;
        while (X<sum) {
            n--;
            sum+=n;
           
        }
        printf("%d\n",-n);
        
    }
    return 0;
}

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

int main(void){
  int lena,lenb,lenc;
	char a[20]={}, b[20]={},c[20]={};
  scanf("%s %s %s",a,b,c);
  lena = strlen(a);
  lenb = strlen(b);
  lenc = strlen(c);
  if(a[lena-1]==b[0])
    if(b[lenb-1]==c[0])
    printf("YES");
      else
        printf("NO");
  else
    printf("NO");
}

Measured memory_bytes: 128
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def bsearch(val, _list):
    i_min = 0
    i_max = len(_list) - 1
    while True:
        i_mid = (i_min + i_max) // 2  # i_min + (i_max-i_min) // 2, if integer overflow can occur
        m_val = _list[i_mid]
        # print(val, m_val, i_mid, i_min, i_max)
        if val == m_val:
            return True
        elif val < m_val:
            i_max = i_mid - 1
            if i_max < i_min:
                return False
        else:
            i_min = i_mid + 1
            if i_min > i_max:
                return False

n = int(sys.stdin.readline())
s = list(map(int, sys.stdin.readline().split()))
q = int(sys.stdin.readline())
t = list(map(int, sys.stdin.readline().split()))

total = 0

for x in t:
    if bsearch(x, s):
        total += 1

print(total)



Measured memory_bytes: 16180
while True:
    n,x=map(int,input().split())
    sm=0
    if n==x==0:
        break
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    sm+= 1
    print(sm)



Measured memory_bytes: 5592
n, k = map(int, input().split())
x = list(map(int, input().split()))

time = []
for i in range(n - k + 1):
    l, r = x[i], x[i + k - 1]
    if l * r < 0:
        time.append(min(abs(l), r) + r - l)
    else:
        time.append(max(abs(l), abs(r)))
print(min(time))

Measured memory_bytes: 14252
# include <bits/stdc++.h>
# define int      long long
# define all(vc)   vc.begin(),vc.end()
# define all2(vc)  vc.rbegin(),vc.rend()
# define pb        push_back
# define vec       vector
# define fi        first 
# pragma GCC optimize "-O3"
# define se        second
# define speed     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define time      cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

using namespace std; 
map <int, int> mp;
void solve(){
    int n = 0, m = 0;
    cin >> n;
    vec <int> v(n);
    
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
        m += mp[ i - v[i] ];
        mp[ i + v[i] ]++;
    }
    cout << m;
}
int32_t main(){
    speed;
    int T = 1;
    //cin >> T;
    while( T-- ){
         solve();
         cout<<'\n';
    }
    time;
}
 

Measured memory_bytes: 27424
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 1
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <random>
#include <ctime>

#define MOD 1000000007

const long long INF = 10000000000000000;

using namespace std;


int main(){
	int N,T;
	cin>>N>>T;
	vector<int> t(N);
	for(int i=0;i<N;i++){
		cin>>t[i];
	}
	
	long long ans=0;
	for(int i=1;i<N;i++){
		if((t[i]-t[i-1])>=T){
			ans+=T;
		}else{
			ans+=(t[i]-t[i-1]);
		}
	}
	ans+=T;
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
using ll = long long;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using pll = pair<ll, ll>;

bool need_time(const vector<ll>& A, const ll div, const ll K) {
	priority_queue<ll, vector<ll>, greater<ll>> pq;
	for (auto num : A)pq.push(num % div);

	ll k = K;
	while (!pq.empty() && pq.top() <= k) {
		k -= pq.top();
		pq.pop();
	}

	ll can = K - k;
	ll need = 0;
	while (!pq.empty()) {
		need += (div - pq.top()) % div;
		pq.pop();
	}
	return need <= can;
}

int main()
{
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	rep(i, N)cin >> A[i];

	ll sum = accumulate(A.begin(), A.end(), 0ll);
	ll res = 0;
	REP(i, 1, sqrt(sum) + 2)if (sum%i == 0) {
		if (need_time(A, i, K))res = max(res, i);
		if (need_time(A, sum / i, K))res = max(res, sum / i);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <iomanip>
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std ;
inline int read() {
	int x = 0 , f = 1 ;
	char ch = getchar() ;
	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
	return x * f ;
}
char s1[61],s2[61],s3[61];
int l1,l2,flag;

inline void error() {
	puts("UNRESTORABLE");
	exit(0);
}

inline void W(int x) {
	For(i, 1, l1) s3[i] = s1[i];
	For(i, 1, l2) 
		s3[x+i-1] = s2[i];
	For(i, 1, l1) if(s3[i]=='?') s3[i]='a';
	printf("%s",s3+1);
	exit(0); 
}

int main() {
	scanf("%s",s1+1); l1 = strlen(s1+1);
	scanf("%s",s2+1); l2 = strlen(s2+1);
	if(l1<l2) error();
	Dow(i, l1-l2+1, 1) {
		flag = 0;
		For(j, 1, l2) 
		  if(s1[i+j-1]!='?' && s1[i+j-1]!=s2[j]) flag = 1;
		if(flag==0) W(i);
	}
	error();
	return 0;
}









Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
#define int long long
int32_t main()
{
  int r;
  cin>>r;
  cout<<r*r;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void sort(int array[]) {
	int sorted = 10, last;
	int i, temp;

	while(sorted) {
		last = 0;
		for(i = 0; i < sorted - 1; i++) {
			if(array[i] < array[i + 1]) {
				temp = array[i];
				array[i] = array[i + 1];
				array[i + 1] = temp;

				last = i + 1;
			}
		}
		sorted = last;
	}
}

int main(void) {
	int w[10], k[10];
	int wp[3] = {0}, kp = {0};
	int i;

	for(i = 0; i < 10; i++)
		scanf("%d", &w[i]);

	for(i = 0; i < 10; i++)
		scanf("%d", &k[i]);

	sort(w), sort(k);

	printf("%d %d\n", w[0] + w[1] + w[2], k[0] + k[1] + k[2]);
	return 0;
}

Measured memory_bytes: 596
#%%
import fractions
def gcd_base(x, y):
    return fractions.gcd(x, y)

def gcd_list(l):
    tmp = l[0]
    for i in range(1, len(l)):
        tmp = gcd_base(tmp, l[i])
    return tmp

import fractions
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(l):
    tmp = l[0]
    for i in range(1, len(l)):
        tmp = lcm_base(tmp, l[i])
        if tmp > 10**9:
            tmp = -1
            break
    return tmp

n, m = map(int, input().split())
a = list(map(lambda x: int(x)//2 , input().split()))
f1 = True

lcm = lcm_list(a)
if lcm == -1:
    ans = 0
else:
    for i in range(n):
        if (lcm // a[i]) % 2 == 0:
            ans = 0 
            f1 = False
            break
    if f1:
        ans = (m + lcm) // (2 * lcm)
print(ans)


Measured memory_bytes: 16280
n,m = map(int,input().split())
res = 0

q = []
for i in range(m):
    q.append(list(map(int,input().split())))
p = list(map(int,input().split()))

for s in range(2**n):
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1,len(q[i])):
            w = q[i][j]
            if s>>(w-1) &1 == 1:
                cnt += 1
        if cnt % 2 != p[i]:
            judge = False
    if judge:
        res += 1
print(res)

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

void solve()
{
    int n, x, t;
    cin >> n >> x >> t;
    int ans = ceil(((double)n) / ((double)x)) * t;
    cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    solve();

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <atcoder/all>
#include<random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<double, lint> Pa;
typedef pair<plint, lint> tlint;
struct edge {
	lint cost;
	lint u, v;
};

using namespace atcoder;

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

template< typename T >
T extgcd(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    else {
        x = 1;
        y = 0;
    }
    return d;
}
lint N;
int main() {
	cin >> N;
    auto mp = prime_factor(N * 2);
    vector<lint> vec;
    for (auto itr : mp) {
        lint curr = 1;
        REP(i, itr.second) {
            curr *= itr.first;
        }
        vec.push_back(curr);
    }
    if (N <= 1000000) {
        REP(i, 1000001) {
            if (i != 0 && i * (i + 1) % (2 * N) == 0) {
                cout << i << endk;
                return 0;
            }
        }
    }
    lint minv = N - 1;
    REP(i, 1 << SZ(vec)) {
        lint a1 = 1, a2 = 1;
        REP(j, SZ(vec)) {
            if ((i >> j) % 2 == 0) {
                a1 *= vec[j];
            }
            else {
                a2 *= vec[j];
            }
        }
        lint x, y;
        extgcd(a1, a2, x, y);
        if (y != 1 && y != 0) {
            chmin(minv, min(abs(a1* x), abs(a2* y)));
        }
    }
    cout << minv << endk;
}


Measured memory_bytes: 3672
N = int(input())
ans = [0]*N
for x in range(1, int(N**0.5)+2):
  for y in range(1, int(N**0.5)+2):
    for z in range(1, int(N**0.5)+2):
      a = x**2 + y**2 + z**2 + x*y + y*z + z*x 
      if a <= N:
        ans[a-1] += 1
for i in range(N):
  print(ans[i])

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class ModTools:
    """ 階乗たくさん使う時用のテーブル準備 """

    def __init__(self, MAX, MOD):
        """ MAX：階乗に使う数値の最大以上まで作る """
        
        MAX += 1
        self.MAX = MAX
        self.MOD = MOD
        # 階乗テーブル
        factorial = [1] * MAX
        factorial[0] = factorial[1] = 1
        for i in range(2, MAX):
            factorial[i] = factorial[i-1] * i % MOD
        # 階乗の逆元テーブル
        inverse = [1] * MAX
        # powに第三引数入れると冪乗のmod付計算を高速にやってくれる
        inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
        for i in range(MAX-2, 0, -1):
            # 最後から戻っていくこのループならMAX回powするより処理が速い
            inverse[i] = inverse[i+1] * (i+1) % MOD
        self.fact = factorial
        self.inv = inverse
    
    def nCr(self, n, r):
        """ 組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく) """

        if n < r: return 0
        # 10C7 = 10C3
        r = min(r, n-r)
        # 分子の計算
        numerator = self.fact[n]
        # 分母の計算
        denominator = self.inv[r] * self.inv[n-r] % self.MOD
        return numerator * denominator % self.MOD

H, W, Y2, X1 = MAP()

Y1 = H - Y2
X2 = W - X1
mt = ModTools(H+W, MOD)
ans = 0
for x in range(1, X2+1):
    # 上の方の通り数
    cnt1 = mt.nCr(Y1+X1+x-2, Y1-1)
    # 下の方の通り数
    cnt2 = mt.nCr(Y2+X2-x-1, Y2-1)
    ans += cnt1 * cnt2
    ans %= MOD
print(ans)


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int k = scn.nextInt();
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = scn.nextInt();
		}
		Arrays.parallelSort(arr);
		int ans = 0;
		for (int i = 0; i < k; i++) {
			ans = ans + arr[i];
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 30120
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

string ans;

int main() {
    ios_base::sync_with_stdio(0);
    ll n; cin >> n; n--;

    ll b = 26, dig = 1;
    while (n>=b) n -= b, b *= 26, dig++;

    while (dig--) {
        ans += (char)('a'+n%26);
        n /= 26;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 3620
N, M = map(int, input().split())
ACed = [False] * N
wa = [0] * N
for i in range(M):
  p, s = input().split()
  p = int(p)-1
  if s == "AC":
    if not ACed[p]:
      ACed[p] = True
  else:
    if not ACed[p]:
      wa[p] += 1

was = 0
for i in range(N):
  was += ACed[i] * wa[i]

print(sum(ACed), was)

Measured memory_bytes: 4596
s = input()
n = 0
for i in range(2**(len(s)-1)):
    b = list("{0:010b}".format(i))
    b.reverse()
    
    index = 0
    for j in range(len(s)):
        if b[j] == "1":
            n += int(s[index:j+1])
            index = j+1
    if index != j+1:
        n += int(s[index:j+1])
    
print(n)


Measured memory_bytes: 3060
import math

# inpult
# 人数　n
n = input();
# i番目の人が住んでいる座標x
x_list = list(map(int, input().split()));

#座標Pを求める（座標の合計の平均を算出）
sum_p = 0;
for i in x_list:
    sum_p = sum_p + i;

# 平均を算出する関数roundを作成
round_ave = lambda x:(x*2+1)//2;

p = round_ave(sum_p/len(x_list));

# 各要素からpを引いて2乗した数の和を算出する
result = 0;
for i in x_list:
    result = result + (i - p)**2

# 小数点以下を削除して表示
print(math.floor(result))
    

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  vl a(n), b;
  rep(i, n) {
    cin >> a[i];
    if(i==0 or a[i-1]!=a[i]) b.push_back(a[i]);
  }
  ll bs=b.size();
  
  ll money=1000, stock=0, f=0;
  rep(i, bs-1) {
    if(b[i]<b[i+1] and f!=1) {
      f=1;
      stock += money/b[i];
      money %= b[i];
    }
    
    if(b[i]>b[i+1] and f!=-1) {
      f=-1;
      money += b[i]*stock;
      stock = 0;
    }
  }
  money += b[bs-1]*stock;
  stock = 0;
  
  cout << money << newl;
  return 0;
}

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

using namespace std;

int main() {
	string a,b;
	cin >> a >> b;
	if (a == "H") {
		if (b == "H") {
			puts("H");
		} else {
			puts("D");
		}
	} else {
		if (b == "H") {
			puts("D");
		} else {
			puts("H");
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
  string s;
  cin >>s;
  int p=100000;
  for(int i=0;i<=s.size()-3;i++){
       string t;
       for(int j=0;j<3;j++){
         t+=s[i+j];
       }
       int a=stoi(t);
       p=min(abs(a-753),p);
      }
  cout << p<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int main()
{
	int N,T,A,B;
	while( scanf(" %d %d",&N,&T) != EOF ){
		scanf(" %d",&A);
		int sum = 0;
		for( int i = 1 ; i < N ; i++ ){
			scanf(" %d",&B);
			if( B - A > T )
				sum += T;
			else
				sum += (B - A);
			A = B;
		}
		sum += T;
		printf("%d\n",sum);
	}
}

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

using namespace std;
#define ll long long
int main()
{
	int h,w,n;
	cin>>h>>w>>n;
	int x=max(h,w);
	if(n%x)
    {
        cout<<n/x+1<<endl;
    }
    else
        cout<<n/x<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
void print_array(const int* array, int num) {
    int i;
    for (i = 0; i < num; i++) {
        printf(" %d" + !i, array[i]);
    }
    putchar('\n');
}
 
int main(void) {
    int N;
    int A[128];
    int i, j;
    if (scanf("%d", &N) != 1) return 1;
    for (i = 0; i < N; i++) {
        if (scanf("%d", &A[i]) != 1) return 1;
    }
    print_array(A, N);
    for (i = 1; i < N; i++) {
        int v = A[i];
        for (j = i - 1; j >= 0 && A[j] > v; j--) A[j + 1] = A[j];
        A[j + 1] = v;
        print_array(A, N);
    }
    return 0;
}


Measured memory_bytes: 2040
#![allow(unused_imports)]
#![allow(dead_code)]

use std::thread;
use std::io::{ self, Read };
use std::fmt;
use std::iter::Iterator;
use std::cmp::*;
use std::collections::*;
use std::str::*;

#[derive(Default)]
struct Input {
    buf: Vec<String>
}

impl Input {
    fn new() -> Input {
        Input { buf: Vec::new() }
    }

    fn read<T: FromStr>(&mut self) -> T 
    where <T as FromStr>::Err: fmt::Debug {
        self.next().unwrap().parse::<T>().unwrap()
    }

    fn read_bytes(&mut self) -> Vec<u8> {
        self.next().unwrap().into_bytes()
    }

    fn read_n<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where <T as FromStr>::Err: fmt::Debug {
        let mut v = Vec::new();
        for _ in 0..n { v.push(self.read::<T>()); }
        v
    }
}

impl Iterator for Input {
    type Item = String;
    fn next(&mut self) -> Option<String> {
        while self.buf.is_empty() {
            let mut s = String::new();
            let _res = io::stdin().read_line(&mut s);
            self.buf = s.split_whitespace().map(|s| s.to_owned()).collect::<Vec<_>>();
            self.buf.reverse();
        }
        self.buf.pop()
    }
}

fn dfs(u: usize, c:usize, e: &[Vec<i64>], s: &mut [bool]) -> i64 {
    if s[u] { return 0; }
    if c == e.len() - 1 { return 1; }
    s[u] = true;
    let mut y = 0;
    for v in 1..e.len() {
        if e[u][v] > 0 { y += dfs(v, c + 1, e, s); }
    }
    s[u] = false;
    y
}

fn run() {
    let mut ip = Input::new();
    let n = ip.read::<usize>();
    let m = ip.read::<usize>();
    let mut e = vec![vec![0; n + 1]; n + 1];
    for _ in 0..m {
        let u = ip.read::<usize>();
        let v = ip.read::<usize>();
        e[u][v] = 1;
        e[v][u] = 1;
    }
    let mut s = vec![false; n + 1];
    let y = dfs(1, 1, &e, &mut s);
    println!("{}", y);
}

fn main() {
    let _ = thread::Builder::new()
        .stack_size(10 * 1024 * 1024)
        .spawn(run).unwrap()
        .join();
}

Measured memory_bytes: 8572
# https://atcoder.jp/contests/abc094/tasks/arc095_a

import itertools
import collections
import bisect
import copy

def main():
    N = int(input())
    X = list(map(int, input().split()))
    Y = sorted(X)
    for i in range(N):
        pos = bisect.bisect(Y, X[i])
        if pos <= N//2:
            print(Y[N//2])
        else:
            print(Y[N // 2 - 1])


if __name__ == '__main__':
    main()
    

Measured memory_bytes: 27156
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

S = input()
if S[0] == '0':
    res1 = S[::2].count('1')+S[1::2].count('0')
    res2 = S[1::2].count('1')+S[::2].count('0')
else:
    res1 = S[::2].count('1')+S[1::2].count('0')
    res2 = S[1::2].count('1')+S[::2].count('0')
print(min(res1,res2))



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

int n;
vector<string> ans;
void dfs(string s,int a){
  vector<int> v;
  for(int i=0;i<n;i++)if(s[i]=='#')v.push_back(i);
  int A=v.size();
  if(!A)ans.push_back(s);
  else{
    s[v[0]]=(char)('a'+a);
    for(int i=0;i<(1<<A-1);i++){
      string t=s;
      for(int j=0;j<A-1;j++)if((i>>j)&1)t[v[j+1]]=(char)('a'+a);
      dfs(t,a+1);
    }
  }
}

int main(){
  cin>>n;
  dfs(string(n,'#'),0);
  sort(ans.begin(),ans.end());
  for(string p:ans)cout<<p<<endl;
}


Measured memory_bytes: 7796
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    int k;
    cin >> S >> k;
    rep(i, S.size()) {
        if(S.at(i) != 'a' && k >= 'z' - S.at(i) + 1) {
            k -= 'z' - S.at(i) + 1;
            S.at(i) = 'a';
        }
    }
    k %= 26;
    S.back() += k;
    cout << S << endl;
}

Measured memory_bytes: 592
a,b = map(int,input().split())
c = 0

for i in range(a,b+1):
  I = list(str(i))
  q=I[0]
  w=I[1]
  e=I[2]
  r=I[3]
  t=I[4]
  y = t+r+e+w+q
  if int(y) == i:
    c += 1
    
print(c)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    ll n, s;    cin >> n >> s;
    ll mod = 998244353;
    ll *a = new ll[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    ll **dp = new ll*[n+1];
    for (ll i = 0; i < n+1; i++)
        dp[i] = new ll[s+1];

    dp[0][0] = 1;
    for (ll i = 1; i < s+1; i++)
        dp[0][i] = 0;

    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < s+1; j++) {
            if (j >= a[i])
                dp[i+1][j] = (2 * dp[i][j] % mod + dp[i][j-a[i]]) % mod;
            else 
                dp[i+1][j] = 2 * dp[i][j] % mod;
        }
    }

    cout << dp[n][s] << endl;

    return 0;
}

Measured memory_bytes: 74004
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define sz(x) (int)x.size()
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define F first
#define S second
#define watch(x) cerr << "\n" << (#x) << " = " << (x) << "\n"
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(max(a * c, b * d), max(a * d, b * c));
	return 0;
}

Measured memory_bytes: 3648