akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair

typedef long long ll;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int main()
{
  ll h, w;
  cin >> h >> w;

  ll ans = linf, s[3];
  for(int i = 1; i < h; i++){
    s[0] = i*w;
    s[1] = ((h-i)/2)*w;
    s[2] = h*w-s[0]-s[1];

    sort(s, s+3);
    ans = min(ans, s[2] - s[0]);

    s[0] = i*w;
    s[1] = (h-i)*(w/2);
    s[2] = h*w-s[0]-s[1];

    sort(s, s+3);
    ans = min(ans, s[2] - s[0]);
  }

  for(int i = 1; i < w; i++){
    s[0] = h*i;
    s[1] = h*((w-i)/2);
    s[2] = h*w-s[0]-s[1];

    sort(s, s+3);
    ans = min(ans, s[2] - s[0]);

    s[0] = h*i;
    s[1] = (h/2)*(w-i);
    s[2] = h*w-s[0]-s[1];

 //   cout << s[0] << "," << s[1] << "," << s[2] << endl;

    sort(s, s+3);
    ans = min(ans, s[2] - s[0]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int h, w; cin >> h >> w;
  vector<string> a(h);
  rep(i, h) {
    cin >> a[i];
  }

  ll dp[h][w];
  rep(i, h) {
    rep(j, w) {
      dp[i][j] = 0;
    }
  }

  dp[0][0] = 1;

  rep(i, h) {
    rep(j, w) {
      if (a[i][j] == '#') continue;
      if (i > 0) {
        dp[i][j] += dp[i-1][j];
      }
      if (j > 0) {
        dp[i][j] += dp[i][j-1];
      }
      dp[i][j] %= mod;
    }
  }

  cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 9088
using System;

namespace abc131_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var items = input.Split(' ');
            var a = long.Parse(items[0]);
            var b = long.Parse(items[1]);
            var c = long.Parse(items[2]);
            var d = long.Parse(items[3]);

            // c,dの最大公約数
            var larger = Math.Max(c, d);
            var smaller = Math.Min(c, d);
            var mod = larger % smaller;
            while (mod != 0)
            {
                larger = smaller;
                smaller = mod;
                mod = larger % smaller;
            }
            var gcd = smaller;

            // c,dの最小公倍数
            var lcm = c * d / gcd;

            // 割り切れる個数は、c:d個おきに出てくる
            // 1からbまでのcで割り切れる個数
            var bcmod = b / c;
            // 1からbまでのdで割り切れる個数
            var bdmod = b / d;
            // 1からbまでのc,dの最小公倍数で割り切れる個数
            var bcdmod = b / lcm;

            // 1からa-1までのcで割り切れる個数
            var acmod = (a - 1) / c;
            // 1からa-1までのdで割り切れる個数
            var admod = (a - 1) / d;
            // 1からa-1までのc,dの最小公倍数で割り切れる個数
            var acdmod = (a - 1) / lcm;

            // aからbまでのcで割り切れる個数
            var cmod = bcmod - acmod;
            // aからbまでのdで割り切れる個数
            var dmod = bdmod - admod;
            // aからbまでのc,dの最小公倍数で割り切れる個数
            var cdmod = bcdmod - acdmod;

            // aからbまでの個数
            var n = b - a + 1;
            // aからbまでの割り切れない個数
            var answer = n - cmod - dmod + cdmod;
            Console.WriteLine($"{answer}");
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int com(int n,int r){
  if(r == 0) return 1;
  else return (n-r+1)*com(n,r-1)/r;
}

ll per(int n,int r){
	if(r == 0) return 1;
	else return (n-r+1)*per(n,r-1);
}

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  rep(i,N) cin >> h[i];
  int ans = 0;
  rep(i,N){
    if(h[i] >= K) ans++;
  }

  cout << ans << endl;




















}


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

K,S = inputIL()

ans = 0
for i in range(K+1):
  for j in range(K+1):
    k = S-i-j
    ans += (0<= k <= K)
    
print(ans)


Measured memory_bytes: 66392
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define MOD 1000000007
//#define MOD 998244353
//define MOD 1000000007000000
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    int n;
    string s;
    cin >> n >> s;
    if(n==1){
        cout<<1<<endl;
    }
    else{

    

    sort(all(s));
    ll memo=1;
    ll ans=1;
    rep(i,n){
        if(i==0){
            continue;
        }
        if(s[i]==s[i-1]){
            memo++;
        }
        else{
            memo++;
            ans*=memo;
            ans%=MOD;
            memo=1;
        }

        if(i==n-1){
            memo++;
            ans*=memo;
            ans%=MOD;
            memo=1;
        }

    }
    cout<<ans-1<<endl;
    }
    
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
typedef long long ll;
using namespace std;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if (C - B <= 0) {
        cout << (ll)C + B << endl;
    }
    else {
        cout << (ll)B + min(C,A+B+1) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (m, d) = input!(usize, usize);

    let mut count = 0;

    for day in 22..(d+1) {
        let d10 = day / 10;
        let d1 = day % 10;
        if d1 > 1 && d10 * d1 <= m {
            count += 1;
        }
    }

    println!("{}", count);
}

fn main() {
    solve();
}


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

#define rep(i,s,e) for(int i = (s);i <= (e);i++)
int n;
int a[100010];

int memo[100010];
int main()
{
	cin >> n;
	rep(i,0,n - 1)
	{
		int a;
		cin >> a;

		if(a > n)
		{
			cout << 0 << endl;
			return 0;
		}

		memo[a]++;
	}
	int start = 1 - (n % 2);

	int cou = 0;
	for(int i = start;i <= n;i+=2)
	{
		if((i == 0 && memo[i] == 1) || (i != 0 && memo[i] == 2))
		{
			cou += memo[i];
		}
		else
		{
			cout << 0 << endl;
			return 0;
		}
	}
	if(cou != n)
	{
		cout << 0 << endl;
		return 0;
	}

	long long result = 1;
	long long MOD = 1e9 + 7;
	rep(i,0,n / 2 - 1)
	{
		result = (result * 2) % MOD;
	}
	cout << result << endl;
	return 0;
}



Measured memory_bytes: 640
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
ans = 0
for i in range(n):
    while a[i] % 2 == 0:
        a[i] //= 2
        ans += 1
print(ans)

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

int main() {
  int N; cin >> N;
  int A[200];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int cnt = 0;
  int flag = 1;
  while (flag) {
    flag = 0;
    for (int i = N-1; i > 0; i--) {
      if (A[i] < A[i-1]) {
        int temp = A[i];
        A[i] = A[i-1];
        A[i-1] = temp;
        flag = 1;
        cnt++;
      }
    }
  }
  
  for (int i = 0; i < N; i++) {
    cout << A[i];
    if (i != N-1) {
      cout << " ";
    }
  }
  cout << endl << cnt << endl;
}




Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

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

   int n;
   string s;
   cin >> n >> s;
   vector<int> a(n);
   rep(i, 0, n) {
      if (s[i] == 'R') a[i] = 0;
      if (s[i] == 'G') a[i] = 1;
      if (s[i] == 'B') a[i] = 2;
   }
   vector<ll> cnt(3);
   rep(i, 0, n) cnt[a[i]]++;
   ll ans = 1;
   rep(i, 0, 3) ans *= cnt[i];
   rep(j, 0, n) {
      rep(i, 0, j) {
         int k = 2 * j - i;
         if (k < n) {
            if (a[i] == a[j] || a[i] == a[k] || a[k] == a[j]) continue;
            ans--;
         }
      }
   }
   cout << ans << endl;
   return 0;
}

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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);

    int id = 0;
    for(int i = 0; i < N; i++){
	cin >> A.at(i);
	if(A.at(i) == 1) id = i;
    }
    //cout << " id: " << id << endl;
    
    vector<int> B(K);
    for(int k = 0; k < K; k++){
	int l, r;
	l = id - (K-1) + k; r = id + k;
	int a = 0, b = 0;
	while(r < N-1){
	    a++;
	    r = r + (K-1);
	}
	while(l > 0){
	    b++;
	    l = l - (K-1);
	}
	B.at(k) = a + b + 1;
	//cout << " k=" << k << ", l=" << b << ", r=" << a << endl;
    }

    int ans = B.at(0);
    for(int i = 1; i < K; i++){
	ans = min(ans, B.at(i));
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 1024
n=int(input())

def ju(n):
    l=list(str(n))
    j=[0]*3
    f=0
    for i in range(len(l)):
        if l[i]=='3':
            j[0]=1
        elif l[i]=='5':
            j[1]=1
        elif l[i]=='7':
            j[2]=1
        else:
            f=1
    if sum(j)==3 and f==0:
        return 1
    else:
        return 0

zenbu=[3,5,7]

for i in range(8):
    tmp=[]
    for j in zenbu:
        tmp.append(j+3*(10**(i+1)))
        tmp.append(j+5*(10**(i+1)))
        tmp.append(j+7*(10**(i+1)))
        tmp.append(j)
    zenbu=tmp
  
ans=0
for i in zenbu:
    if i<=n and ju(i)==1:
        ans+=1
print(ans)
      


Measured memory_bytes: 55152
a = int(input())
b = int(input())
c = int(input())
x = int(input())

res = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                res += 1
print(res)

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

int main()
{
    int N,C,K; cin >> N >> C >> K;
    int T[100000];
    for (int i = 0; i < N; i++) cin >> T[i];
    sort(T,T+N);
    int res = 0;
    int count;
    for (int i = 0; i < N; i += count){
        count = 1;
        while (i + count < N && count < C && (T[i] + K) >= T[i+count]){
            count++;
        }
        res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 640
/*            AUTHOR - SHIVAM GUPTA
                       Jalpaiguri Govt. Engg College             */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<ll> ve[100005];
ll a[300005],dp[2][300005],n,z;

// ll f(ll i)
// {
//     cout<<i<<endl;
//     if(i>=n-1)
//     return a[n-1];
//     if(dp[i]!=-1)
//     return dp[i];
//     cout<<"check"<<i<<endl;
//     if(f(i+1)<=f(i+2))
//     z+=min(abs(a[i]-a[i+1]),abs(a[i]-a[i+2]));
//     return dp[i]=z;
// }

void solve()
{
    vector<ll> v;        vector<pair <ll,ll>> vp;
    map<ll,ll> mp;       set<ll> st;        multiset<ll> mst;
    ll m=0,i=0,j=0,k=0,c=0,l=0,r=0,p=0,q=0,x=0,y=0,z=0,flag=0,sum=0;
    // ll a[300005]={0},b[300005]={0},ans[300005];
    string s,t;
    cin>>n;
    for(i=1;i<=n;i++)
    cin>>a[i];
    memset(dp,-1,sizeof(ll));
    dp[0][1]=0;
    dp[1][1]=1e9+7;
    for(i=2;i<=n;i++)
    {
        dp[0][i]=min(dp[0][i-1]+abs(a[i]-a[i-1]),dp[1][i-1]);
        dp[1][i]=dp[0][i-1]+abs(a[i+1]-a[i-1]);
    }
    cout<<min(dp[0][n],dp[1][n-1])<<endl;
    
}
bool imp=false;int main()
{
    fio;
    int t=1;
    if(imp)
	cin>>t;
	ll j=t;
    while(t--){
    // cout<<"Case #"<<j-t<<": ";
    solve();}
    return 0;
}

Measured memory_bytes: 8448
n,m = map(int, input().split())
A = [list(map(int,input().split())) for _ in range(n)]
b = [int(input()) for _ in range(m)]
ans = [0]*n
for i in range(n):
    mul = 0
    for j in range(m):
        mul += A[i][j]*b[j]
    ans[i] = mul
for i in ans:
    print(i)


Measured memory_bytes: 6028
#include<bits/stdc++.h> //ABC 115_a
using namespace std;
int main(){
	int D;
	cin>>D;
	if(D==25)
		cout<<"Christmas";
	else if(D==24)
		cout<<"Christmas Eve";
	else if(D==23)
		cout<<"Christmas Eve Eve";
	else if(D==22)
		cout<<"Christmas Eve Eve Eve";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
#define pi       const int pi=3.1415926535
//桁数指定　cout << fixed << setprecision(2)
int main() {
  string ans="Yes";
  int n11,n12,n13,n21,n22,n23,n31,n32,n33;
  cin>>n11>>n12>>n13>>n21>>n22>>n23>>n31>>n32>>n33;
  int t1,t2,y1,y2;
  t1=0;t2=0;y1=0;y2=0;
  t1=n12-n11;
  t2=n13-n12;
  y1=n21-n11;
  y2=n31-n21;
  if((n22-n21)!=t1||(n32-n31)!=t1){
    ans="No";
    goto A;
  }
  if((n23-n22)!=t2||(n33-n32)!=t2){
    ans="No";
    goto A;
  }
  if((n22-n12)!=y1||(n23-n13)!=y1){
    ans="No";
    goto A;
  }
  if((n32-n22)!=y2||(n33-n23)!=y2){
    ans="No";
    goto A;
  }
A:cout<<ans;    
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]

N,M = list(map(int,input().split()))

e_list = [[] for i in range(N)]

for i in range(M):
    x,y,z = list(map(int,input().split()))
    x,y = x-1,y-1
    e_list[x].append(y)
    e_list[y].append(x)

from collections import deque

def BFS(vi,color,color_list):
    Q = deque([vi])
    color_list[vi]=color
    while len(Q)>0:
        v = Q.pop()
        for v1 in e_list[v]:
            if color_list[v1]==-1:
                color_list[v1]=color
                Q.appendleft(v1)

color_list = [-1]*N
color = 0

for i in range(N):
    if color_list[i]==-1:
        BFS(i,color,color_list)
        color+=1

print(color)

Measured memory_bytes: 62128
using System;

namespace _0017
{
    class Program
    {
        const int MAX_CHANGE_NUMBER = 25;

        static void Main(string[] args)
        {
            while (true)
            {
                var inputString = Console.ReadLine();

                if (string.IsNullOrEmpty(inputString))
                {
                    break;
                }

                for (int changeNumber = 0; changeNumber <= MAX_CHANGE_NUMBER; changeNumber++)
                {
                    inputString = Caesar(inputString);
                    if (inputString.Contains("the") || inputString.Contains("this") || inputString.Contains("that"))
                    {
                        Console.WriteLine(inputString);
                        break;
                    }
                }
            }
        }

        public static string Caesar(string sentence) 
        {
            char[] sentenceCharactor = sentence.ToCharArray();

            for (int i = 0; i < sentenceCharactor.Length; i++)
            {
                if (sentenceCharactor[i] >= 'a' && sentenceCharactor[i] <= 'z')
                {
                    if (sentenceCharactor[i] == 'z')
                    {
                        sentenceCharactor[i] = 'a';
                    }
                    else
                    {
                        sentenceCharactor[i] = (char)(sentenceCharactor[i] + 1);
                    }
                }
            }
            return new string(sentenceCharactor);
        }
    }
}

Measured memory_bytes: 6200
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
while True:
    for i in range(1,len(L)):
        L[i] %= L[0]
    L= filter(lambda x:x!=0,L)
    L= sorted(L)
    if len(L) == 1:
        break
print(L[0])


Measured memory_bytes: 14252
while True:
    counter=0
    n=int(input())
    if n==0:break
    a=1
    for i in range(1,n+1):
        a*=i
        
    while True:
        if a%10!=0:
            break
        else:
            a=a//10
            counter+=1
    print(counter)
        


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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll h, w;
  cin>>h>>w;
  if(h==1 || w==1){
    cout<<1<<'\n';
    return 0;
  }
  cout<<(h*w+1)/2<<'\n';
  return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    //lol result{0};
    lol x, y, z; cin >> x >> y >> z;
    //lol k; cin >> k;
    /*
    vector<lol> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */
    

    cout << z << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 3632
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class F> class rec_lambda {
  F f;

public:
  rec_lambda(F &&f) : f(std::move(f)) {}
  template <class... Args> auto operator()(Args &&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};
template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); }
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <string>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const usize A = scan<usize>();
  const usize B = scan<usize>();
  const usize M = scan<usize>();
  std::vector<u32> a(A), b(B);
  constexpr u32 Inf = std::numeric_limits<u32>::max();
  u32 amin = Inf, bmin = Inf;
  for (auto &e : a) {
    std::cin >> e;
    chmin(amin, e);
  }
  for (auto &e : b) {
    std::cin >> e;
    chmin(bmin, e);
  }
  u32 ans = amin + bmin;
  for (const usize i : rep(0, M)) {
    const usize x = scan<usize>() - 1;
    const usize y = scan<usize>() - 1;
    const u32 c = scan<u32>();
    chmin(ans, a[x] + b[y] - c);
  }
  std::cout << ans << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


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


int main(){
     string str1;
     cin >> str1;
     int count1 = 0;
     for (int i = 0; i <= (str1.size()) - 2;i++){
         if(str1.at(i) == 'C'){
         count1 ++;
         }
     } 
     if(str1.at(0) != 'A' || str1.at(1) == 'C' || count1 != 1 || str1.at(str1.size()-1) == 'C' )
     
     {
     cout << "WA" << endl;
     }
     else{
     int count2 = 0;
       for(int j = 1; j <=(str1.size()) -1; j++){
       if(('a' <= str1.at(j)  && str1.at(j) <= 'z') || str1.at(j) =='C'){
             count2 ++;
           } 
       }
       if(count2 != str1.size() -1){
          cout << "WA" << endl;
       }
       else{
          cout << "AC" << endl;
       }  
       
     }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

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; }

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

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll N, K;
	cin >> N >> K;

	ll ans = 0;

    for (ll k = K-1; k <= N; ++k)
    {
		ll lhs = k * (k+1) / 2;
		ll rhs = (2 * N - k) * (k + 1) / 2;

		ans += (1 + rhs - lhs);
		//cout << 1 + rhs - lhs << endl;
		ans %= MOD;
    }

	cout << ans << endl;
}


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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

const int MOD1=1000000007;
const int MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const int dx[]={0,1,0,-1,1,-1,1,-1};
const int dy[]={1,0,-1,0,1,1,-1,-1};

#define unless(a) if(!(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(n);i++)
#define bitrep(i,s,n) for(int i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}
long long cutup(long long a,long long b){return (a+b-1)/b;}
long long popcnt(long long a){return __builtin_popcountll(a);}
template<class T,class U> inline bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template<class T,class U> inline bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

struct edge{long long to,cost;};
struct edge2{long long from,to,cost;};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll w,h,n;
    ll l,u;
    l=u=0;
    cin>>w>>h>>n;
    rep(i,n){
        ll x,y,a;
        cin>>x>>y>>a;
        if(a==1){
            chmax(l,x);
        }else if(a==2){
            chmin(w,x);
        }else if(a==3){
            chmax(u,y);
        }else{
            chmin(h,y);
        }
    }
    if(u>=h||l>=w)cout<<0<<endl;
    else cout<<(h-u)*(w-l)<<endl;
}

Measured memory_bytes: 3616
N,M,X = (int(i) for i in input().split())
places = input()
placelistchar = places.split(" ")

placelist = []
for k in range(M):
    placelist.append(int(placelistchar[k]))


countbig = 0
countsmall = 0


for i in range(0,N):
    if(i in placelist):
        if i<X:
            countsmall += 1
        else:
            countbig += 1

print(min(countsmall,countbig))

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramC
    {
        static void Main()
        {
            int a = NextInt, b = NextInt, h = NextInt, m = NextInt;

            double theta = 2 * Math.PI * Math.Abs(60 * h - 11 * m) / 12 / 60;

            System.Console.WriteLine(
                Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(Math.Min(theta, 2 * Math.PI - theta)))
            );
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 28268
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n; cin >> n;
    string c; cin >> c;
    int cnt = 0;
    rep(i,n){
        if(c[i] == 'R') cnt++;
    }
    int cnt2 = 0;
    rep(i,cnt){
        if(c[i] == 'R') cnt2++;
    }
    cout << cnt-cnt2 << endl;
}


Measured memory_bytes: 3712
N = input().split()
A = int(N[1])
B = int(N[2])
N = int(N[0])
S = 0
for n in range(1,N+1):
  l = len(str(n))
  Sn = 0
  for j in range(l):
    Sn += int(str(n)[-j])
  if Sn >= A and Sn <= B:
    S += n
print(S)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
vector<int> v;
int flag=0;

void monmo(int k,int n){
    if(v[k]<0)v[k]=n;
    else if(v[k]!=n)flag=1;
}

int main(void){
    int n,m;
    int keta,num;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        v.push_back(-1);
    }
    for(int i=0;i<m;i++){
        cin>>keta>>num;
        monmo(keta-1,num);
    }
    
    if(n==1 && flag==0){
        if(m==0)cout<<0;
        else cout<<v[0];
        exit(0);
    }
    
    if(flag==1 || v[0]==0){
        cout<<-1;
        exit(0);
    }
    
    if(v[0]<0)v[0]=1;
    for(int i=0;i<n;i++){
        if(v[i]<0)cout<<0;
        else cout<<v[i];
    }
}


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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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; }

// X以下の正数N個与えられたときに、全て素因数分解するためのプログラム
const int X = 1e+6 + 10;
int N;
vector<int> A,D;

// 計算量　前処理 O(X) ?
// D[x] = y のとき、正数xの最小の素因数がyである。(xが素数のときD[x]=x)
void sieve() {
    iota(D.begin(),D.end(),0);
    for ( int i = 2; i * i < X; ++i){
        if ( D[i] < i ) continue;
        for ( int j = i * i; j < X; j += i){
            if ( D[j] == j ) D[j] = i;
        }
    }
}
// 各素因数分解 O(logX)
// Yの素因数分解を行う
vector<int> factor( int Y ){
    vector<int> f;
    while ( Y > 1 ){
        f.push_back(D[Y]);
        Y /= D[Y];
    }
    return f;
}

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    cin >> N;
    A.resize(N); D.resize(X);
    REP(i,N) cin >> A[i];
    
    sieve();
    
    map<int,int> m;
    bool pairwise = true;
    REP(i,N){
        vector<int> f = factor(A[i]);
        set<int> s;
        for ( auto a: f) s.insert(a);
        for ( auto a: s){
            //cout << i << " " << a << endl;
            m[a] = m[a] + 1;
            if ( m[a] > 1 ) {
                pairwise = false;
                break;
            }
        }
    }
    
    bool setwise = true;
    int p = A[0];
    for ( int i = 1; i < N; ++i){
        p = GCD(p,A[i]);
    }
    if ( p != 1 ) setwise = false;
    
    if ( pairwise ) cout << "pairwise coprime" << endl;
    else if ( setwise ) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
    
    return 0;
}


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

int main() {
  int n, m;
  vector<int> a_vec(110);
  int pic = 0;
  int a_sum = 0;
  
  cin >> n >> m;
  for(int i = 0; i < n;i++){
    cin >> a_vec.at(i);
    a_sum += a_vec.at(i);
  }
  
  for(int j = 0; j < n;j++){
    if(a_vec.at(j) >= (a_sum / (4.0 * m))){
      pic++;
    }
  }
  
  if(pic < m){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

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

int main() {
    char c[101];
    cin >> c;
    int count = 0;

    cout << c[0] << flush;
    for (int i = 1; c[i] != '\0'; i++) {
        count++;
    }
    cout << count-1 << c[count] << endl;

}

Measured memory_bytes: 256
use v5.18;
use warnings;
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

use constant {
  CAKE => 4,
  DONUTS => 7,
};

my $n = read_line;
say rec(0, 0) ? 'Yes' : 'No';

sub rec {
  my ($x, $y) = @_;
  return 0 if (CAKE * $x + DONUTS * $y) > 100;
  return 1 if (CAKE * $x + DONUTS * $y) == $n;
  rec($x + 1, $y) || rec($x, $y + 1);
}


Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=2e5+500;
char st[N];
int n,s[N][2];
int main()
{
	scanf("%d",&n);
	scanf("%s",st+1);
	for(int i=1;i<=n;i++)s[i][0]=s[i-1][0]+(st[i]=='W'),s[i][1]=s[i-1][1]+(st[i]=='R');
	int ans=10000000;
	for(int i=1;i<=n+1;i++)
	{
		int ln=s[i-1][0],rn=s[n][1]-s[i-1][1];
		ans=min(ans,max(ln,rn));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4932
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll power(ll a,ll b)
{
	ll res = 1;
	for(ll i = 1 ; i <= b ; i++)
	res *= 	a;
	return res;
}
 
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll n,p;
	cin >> n >> p;
	map <ll,ll> m;
	for(ll i = 2 ; i*i <= p ; i++)
	{
		while(p % i == 0)
		{
			m[i]++;
			p /= i;
		}
	}
	if(p > 1)
		m[p]++;
	ll ans = 1;
	for(auto i = m.begin() ; i != m.end() ; i++)
	{
		ans *= power(i->first,(i->second/n));
	}
	cout << ans ;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val B = readLine()!!.split(" ").map { it.toInt() }


    val A = IntArray(N)
    A[N - 1] = B[N - 2]
    (N-2 downTo 1).forEach {
        A[it] = Math.min(B[it - 1], B[it])
    }
    A[0] = B[0]

    println(A.sum())
}

Measured memory_bytes: 38084
n,m=map(int,input().split())
a=[list(map(int,input().split()))for i in range(m)]
s=[[float("inf")]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
    s[i][i]=0
for i in range(m):
    s[a[i][0]][a[i][1]]=a[i][2]
    s[a[i][1]][a[i][0]]=a[i][2]
for h in range(1,n+1):
    for i in range(1,n+1):
        for j in range(1,n+1):
            if s[i][j]>s[i][h]+s[h][j]:
                s[i][j]=s[i][h]+s[h][j]
c=0
for i in range(m):
    for j in range(1,n+1):
        if s[j][a[i][0]]!=float("inf"):
            if s[j][a[i][0]]+a[i][2]==s[j][a[i][1]]:
                break
    else:
        c+=1
print(c)

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

int main(){
	ll l, r;
	cin >> l >> r;
	int ans = 2019;
  if (r-l >= 2019) { cout << 0 << endl; return 0; }
  for (ll i = l; i < r; i++) {
    for (ll j = i + 1; j <= r; j++) {
      ans = min(ans, (int)(i*j%2019));
      if (ans == 0){ cout << 0 << endl; return 0; }
    }
  }
  cout << ans << endl;
}

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


int main(){

  int n;
  cin>>n;
  
  int num[4][3][10] = {};
  for(int i=0;i<n;i++){
  int b,f,r,v;
  cin>>b>>f>>r>>v;
  num[b-1][f-1][r-1] += v;
  }

  for(int i=0;i<4;i++){
   if(i) cout<<"####################"<<endl;
 

   for(int j=0;j<3;j++){
    for(int k=0;k<10;k++){
     cout<<" "<<num[i][j][k];
     }
    cout<<endl;
   }
  }

  return 0;
}


Measured memory_bytes: 3088
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
#define N 100010
long long int gcd(long long a, long long b) {
    return a%b==0?b:gcd(b,a%b);
}
int main(){
    int n,s;
    int t,l,r,d;
    while (scanf("%d %d %d",&l,&r,&d)!=EOF) {
        int ans = 0;
        for (int i=l;i<=r;i++) {
            if (i%d==0)
                ans++;
        }
        cout << ans << endl;

    }

    return 0;
}
/*
5
1 2 3 4 5
4
1 1 1 1
1 1 1 2
1 2 5 1
1 3 5 2
*/


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
#define fi first
#define se second
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,q;
    cin>>a>>b>>q;
    vector<ll> s(a),t(b);
    vector<P> x(q);
    for(ll i=0;i<a;i++)cin>>s.at(i);
    for(ll i=0;i<b;i++)cin>>t.at(i);
    for(ll i=0;i<q;i++){
        ll  x1;
        cin>>x1;
        x.at(i)=P(x1,i);
    }
    sort(x.begin(),x.end());
    int j=0,k=0;
    vector<ll> ans(q);
    for(ll i=0;i<q;i++){
        ll pos=x.at(i).fi;
        while(j+1<a&&pos>s.at(j))j++;
        while(k+1<b&&pos>t.at(k))k++;
        ll ans1=inf,ans2=inf,ans3=inf,ans4=inf,ans5=inf,ans6=inf,ans7=inf;
         if((s.at(j)>=pos&&t.at(k)>=pos)||(s.at(j)<pos&&t.at(k)<pos)){ans1=max(abs(s.at(j)-pos),abs(t.at(k)-pos));
         if(!(s.at(j)<pos&&t.at(k)<pos)){
         if(j-1>=0)ans2=min(pos-s.at(j-1),t.at(k)-pos)+abs(s.at(j-1)-t.at(k));
        if(k-1>=0)ans3=min(s.at(j)-pos,pos-t.at(k-1))+abs(s.at(j)-t.at(k-1));
        if(j-1>=0&&k-1>=0)ans4=max(pos-s.at(j-1),pos-t.at(k-1));
         }
         }
         else {
             ans5=min(abs(s.at(j)-pos),abs(t.at(k)-pos))+abs(s.at(j)-t.at(k));
             if(s.at(j)>pos&&pos>t.at(k)&&j-1>=0)ans6=pos-min(s.at(j-1),t.at(k));
             else if(t.at(k)>pos&&pos>s.at(j)&&k-1>=0)ans7=pos-min(s.at(j),t.at(k-1));
         }
        ans.at(x.at(i).se)=min(min(ans1,min(ans2,ans3)),min(min(ans4,ans5),min(ans6,ans7)));
    }
    for(ll i=0;i<q;i++){
        cout<<ans.at(i)<<endl;
    }
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 20000000000000000
#define mod 998244353
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
//knight and king//
int dr[]= {2,2,-2,-2,1,-1,1,-1};
int dc[]= {1,-1,1,-1,2,2,-2,-2};
int dr1[]= {0,0,1,1,1,-1,-1,-1};
int dc1[]= {1,-1,1,0,-1,0,1,-1};
int dr2[]= {0,0,1,-1};
int dc2[]= {1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 2000005

ll a[ma],b[ma],c[ma],d[ma],max1=0,n,m,q;
ll pr[ma];
void cal(ll x,ll v)
{
    if(x>n)
    {
        ll s=0;
        for(ll i=1;i<=q;i++)
        {
            ll x=a[i],y=b[i];
            if(pr[y]-pr[x]==c[i])s+=d[i];
        }
        max1=max(max1,s);
        return ;
    }
    for(ll i=v;i<=m;i++)
    {
        pr[x]=i;
        cal(x+1,i);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,x,y;
    while(cin>>n>>m>>q)
    {
     for(i=1;i<=q;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
     cal(1,1);cout<<max1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
/*
    quid-pro-quo: LOGIC for AC
    written by: codercell07
    LANG: C++ 11
    Problem: random
*/
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL)
#define testcases freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
#define ui unsigned int
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sz(x) (int)x.size()
#define pq priority_queue /*maxim at top(max-heap)*/
#define pqmax priority_queue<int, vector<int>, greater<int>> /*minim at top(min-heap)*/
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define asc(x) sort(all(x))
#define desc(x) sort(all(x), greater<int>())
#define time_el (double)time/CLOCKS_PER_SEC
using namespace std;
const int MAX=2e6; //dummy, make sure change as per constraints
const ll M=1e9+7, inf=1e18;
const char nl='\n';
 
ll apbmc(ll a, ll b, ll c){ a%=c; ll res=1; while(b){ if(b&1) res=res*a%c; a=a*a%c; b>>=1; } return res;}
ll apb(ll x, ll y){ ll temp; if(y==0) return 1;  temp=apb(x, y/2); if(y%2==0) return temp*temp;  else return temp*temp*x;}
 

void solve(){   
    //clock_t time;
    ll n, w; cin>>n>>w;
    vector<pll> v(n);
    for(auto &i: v) cin>>i.F>>i.S;
    asc(v);
    vvll dp(n+1, vll(w+1));
    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=w; j++){
            if(j-v[i-1].F<0){
                dp[i][j]=dp[i-1][j];
            }else{
                dp[i][j]=max(v[i-1].S+dp[i-1][j-v[i-1].F], dp[i-1][j]);
            }
        }
    }
    cout<<dp[n][w];

}
int main(){
    fastio;
    // #ifndef ONLINE_JUDGE
    //     testcases;
    // #endif // !DEBUG
    cout<<fixed<<setprecision(9);
    
    //int t; cin>>t; while(t--) solve();    
    solve();

    return 0;
}
//points to check:
//  * check for constraints, mainly array!
//  * EDGE CASES
//  * check for integer overflow, use long long!
//  * learn, do, solve, share something, NOW!

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

int main()
{
  int n, i, m = 0;
  int h[100000];
  int cnt = 0;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> h[i];
  for (i = 0; i < n-1; i++) {
    if (h[i] >= h[i+1]) {
      cnt += 1;
    }
    else
      cnt = 0;
    if (cnt > m)
      m = cnt;
  }
  cout << m << endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

struct edge{int to, cost; };

int N;
int M;
int L[200000];
int R[200000];
int D[200000];

vector<edge> G[200000];
long long d[200000];
bool changed[200000];


bool bfs(int s){
	queue<int> q;
	q.push(s);
	changed[s] = true;
	while(!q.empty()){
		int u =q.front(); q.pop();
		for(int i=0;i<G[u].size();i++){
			int to = G[u][i].to;
			int cost = G[u][i].cost;
			if(!changed[to]){
				d[to] = d[u] + cost;
				changed[to] = true;
				q.push(to);
			}else{
				if(d[to] != d[u] + cost) return false;
			}
		}
	}
	return true;
}


int main(){
	scanf("%d %d", &N, &M);
	for(int i=0;i<M;i++) scanf("%d %d %d", &L[i],&R[i],&D[i]);
	for(int i=0;i<M;i++){
		struct edge e;
		L[i]--;
		R[i]--;
		e.cost = D[i];
		e.to = R[i];
		G[L[i]].push_back(e);
		//
		struct edge e2;
		e2.cost = -D[i];
		e2.to = L[i];
		G[R[i]].push_back(e2);
		//
	}
	for(int i=0;i<N;i++) changed[i] = false;

	for(int i=0;i<N;i++){
		if(changed[i]) continue;
		d[i] = 0;
		if(!bfs(i)){
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");
	return 0;
}


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

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

int main() {
  int n;
  cin>>n;
  string st;
  vector<string> s(n);
  map<string,long long> m;
  long long a=0;

  rep(i,n){
    cin>>st;
    sort(st.begin(),st.end());
    s.at(i)=st;
    m[st]++;
  }

  rep(i,n){
    st=s.at(i);
    if(m[st]!=0) a+=m[st]-1;
    m[st]--;
  }

  cout<<a;
  return 0;
}


Measured memory_bytes: 16640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			int N = scn.nextInt();
			int K = scn.nextInt();

			int[] A = new int[N];
			int[][] ak = new int[K][N+1];

			for(int i = 0; i < K; i++) {
				ak[i][0] = scn.nextInt();
				for(int j = 1; j <= ak[i][0]; j++) {
					ak[i][j] = scn.nextInt();
				}
			}

			for(int i = 0; i < K; i++) {
				for(int j = 1; j <= ak[i][0]; j++) {
					A[ak[i][j]-1] = 1;
				}
			}


			int cnt = 0;
			for(int i = 0; i < N; i++) {
				if(A[i] == 0) cnt++;
			}

			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 37520
#include <stdio.h>

int main(void){

  char s[5];
  scanf("%s", s);
  int number = 0;
  for (int i = 0; i < 4; i++) {
    if (s[i] == '+') {
      number++;
    } else {
      number--;
    }
  }
  printf("%d\n", number);

  return 0;
}

Measured memory_bytes: 128