akhauriyash/Code-Regression huggingface dataset:
use std::cmp;
use std::collections::*;
use std::io::{self, Read};

const MOD: usize = 1000000007;

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let a: i32 = sc.read().unwrap();
    let b: i32 = sc.read().unwrap();

    println!("{}", (a - 1) * (b - 1));
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }

    fn read_board(&mut self, n: usize) -> Option<Vec<Vec<char>>> {
        (0..n)
            .map(|_| {
                self.read::<String>()
                    .map(|s| s.chars().collect::<Vec<char>>())
            })
            .collect()
    }
}


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

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	int ans = 0;
	REP(i,n-2){
		int a = p[i-1];
		int b = p[i];
		int c = p[i+1];
		if((a < b && b < c) || (c < b && b < a)) ans++;
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3604
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        m1: i64,
        _d1: i64,
        m2: i64,
        _d2: i64,
    }
    let ans = if m1 != m2 { 1 } else { 0 };
    println!("{}", ans);
}


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

int main(){
  int W1,W2,S1,S2,sol,Wcap;
  cin >> W1 >> W2 >> S1 >> S2 >> sol >> Wcap;
  W1*= 100;
  W2*= 100;

  using aq= pair<int, int>;
  auto comp= [](aq a, aq b){
    auto [totA, sugarA]= a;
    auto [totB, sugarB]= b;
    return sugarA* totB < sugarB* totA;
  };

  aq ans= make_pair(W1, 0);
  for(int nW1=0; nW1*W1 <= Wcap; nW1++){
    for(int nW2=0; nW2*W2 + nW1*W1 <= Wcap; nW2++){
      int water= nW2*W2 + nW1*W1;
      if(water==0){ continue; }
      else{
        for(int nS2=0; nS2*S2 + water <= Wcap; nS2++){
          // nS1*S1 + nS2*S2 <= sol* (water/100)
          int rem_sugar_sat= min(sol*(water/100) - nS2*S2, Wcap- (water+ nS2*S2));
          if(rem_sugar_sat < 0){ break; }
          else{
            int nS1= rem_sugar_sat/ S1;
            int sugar= nS1*S1 + nS2*S2;
            aq cand= make_pair(water+sugar, sugar);
            if(comp(ans, cand)){
              ans= cand;
            }
          }
        }
      }
    }
  }
  
  auto [tot_ans, sugar_ans]= ans;
  cout << tot_ans <<" "<< sugar_ans << endl;
}

Measured memory_bytes: 3628
import numpy as np
C_vec = np.zeros(26)
N, K = map(int, raw_input().split())

for i in range(N):
    C_vec[ord((raw_input()[0])) - ord('A')] += 1


while True:
    m = int(C_vec.sum() / K)
    C_vec = np.minimum(C_vec, m)
    m_next = int(C_vec.sum() / K)
    if m_next == m:
        break
    else:
        m = m_next

print m


Measured memory_bytes: 10672
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n, m;
	cin >> n >> m;
	vector<string> a(n), b(m);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < m; ++i) {
		cin >> b[i];
	}
	bool ans = false;
	for (int i = 0; i + m <= n; ++i) {
		for (int j = 0; j + m <= n; ++j) {
			bool ok = true;
			for (int k = 0; k < m; ++k) {
				if (a[i + k].substr(j, m) != b[k]) {
					ok = false;
				}
			}
			if (ok) {
				ans = true;
			}
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
if len(S)%2 == 1:
    print('No'); exit()

for i in range(len(S)//2):
    if S[2*i:2*(i+1)] != 'hi':
        print('No'); exit()

print('Yes')


Measured memory_bytes: 3060
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

ans = 0
for i in range(0,N):
    for j in range(0,M):
        mul = 2
        if i == 0 or j == 0:
            mul = 1

        ans += mul * (N -i) * (M -j) * (i+j)

ans *= combinations_count(N*M-2,K-2)
ans %= 10**9 + 7
print(ans)

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

int main(){
  ll i,j,cnt=0;
  int L,R;
  cin>>L>>R;
  if(L+2018<=R){
    cout<<0;
    return 0;
  }
  ll mi=INT_MAX;
  for(i=L;i<=R;i++){
    for(j=i+1;j<=R;j++){
      mi=min(mi,i*j%2019);
    }
  }
  cout<<mi<<endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}



fn main() {
    let a: f64 = read();
    let b: f64 = read();

    let d = (a / b) as i64;
    let r = a % b;
    let f = a / b;

    println!("{} {} {:.5}", d, r, f);
}



Measured memory_bytes: 5156
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
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 (a > b) { a = b; return 1; }
	return 0;
}

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

	int n;
	cin >> n;

	ll ans = 1, div = 1, div2 = 1;
	REP(i, n) {
		ans *= 10;
		ans %= MOD;

		div *= 8;
		div %= MOD;

		div2 *= 9;
		div2 %= MOD;
	}
	ans = (ans + MOD * 2 - (div2*2-div)) % MOD;

	cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,x;
  cin >> n >> m >>x;
  int ans = 1<<30;
  int sum1 = 0;
  int sum2 = 0;
  for(int i = 0;i<m;i++){
    int c;
    cin >> c;
    if( c <x){
      sum1++;
    }
    else{
      sum2++;
    }
    
    if(i==m-1){
      ans = min(sum1,sum2);
    }
  }
  cout << ans;
}

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

using namespace std;

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

const double EPS = 1e-14;

struct building {
	double l, r, h;
};

void solve() {
	double r;int N; cin >> r >> N;
	if (r==0&&N == 0)exit(0);
	vector<building>v;
	REP(i, N) {
		double L, R, H; cin >> L >> R >> H;
		v.push_back({ L,R,H });
	}
	double ok = 0, ng = 1000;
	REP(_, 50) {

		double mid = (ok + ng) / 2;
		/*cout << mid << endl;*/
		double d = 2 * r / 200000;
		REP(c, 200001) {
			double x = -r + d * c;
			//cout << "x:" << x << endl;
			if (r*r - x * x < 0 + EPS)continue;
			double y = sqrt(r*r - x * x)-r+mid;
			if (y < EPS)continue;
			//cout << "y:" << y << endl;
			bool good = false;

			REP(i, N) {
				if (v[i].l < x + EPS && x - EPS < v[i].r&&y - EPS < v[i].h) {
					good = true;
					break;
				}
			}
			if (!good) {
				ng = mid;
				goto END;
			}
		}
		ok = mid;
	END:;
	}
	printf("%.3lf\n",ok);
}

signed main() {
	while (true)solve();
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int x;cin>>x;
  int cont=x/11;
  int n=x-11*cont;
  int ans=cont*2;
  if(n<=0){
    cout<<ans<<endl;
    return 0;
  }
  if(cont%2==0){
    n-=6;ans++;
    if(n>0)ans++;
  }else{
    n-=5;ans++;
    if(n>0)ans++;
  }

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


Measured memory_bytes: 256
let () = Scanf.scanf "%d %d %d" @@ fun n a b ->
  Printf.printf "%d\n" @@
  if a mod 2 = b mod 2
  then abs (a - b) / 2
  else begin
    min
      ( let x = min a b in
        x + (max a b - x - 1) / 2 )
      ( let x = n - max a b + 1 in
        x + (n - min a b - x) / 2 )
  end


Measured memory_bytes: 384
#!/usr/bin/perl -w
#https://atcoder.jp/contests/abc145/tasks/abc145_b

chomp(my $n = <>);
my @string = split(//, <>);

if ($n % 2 != 0) {
  print "No\n";
  exit;
}

if ($n == 2) {
  if ($string[0] eq $string[1]) {
    print "Yes\n";
  }else{
    print "No\n";
  }
  exit;
}
#
my @front = @string[   0    .. ($n/2-1)];
my @back  = @string[ ($n/2) .. ($n-1)];

my $a = join('',@front);
my $b = join('',@back);

if ($a eq $b) {
  print "Yes\n";
}else{
  print "No\n";
}

#my @string_front = splice(@string,($n/2));
#print @string;
#print @string_front;
#if (@string_front eq @string) {
#  print "Yes";
#}else{
#  print "No";
#}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int f(int n, int k){
    if(n == 1) return 0;
    return (f(n - 1, k) + k) % n;
}

int main(){

    while(1){
        int n, k, m; cin >> n >> k >> m;
        if(n == 0) break;

        cout << (f(n - 1, k) + m) % n + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll mod = 1e9+7 ;
const ld error = 1e-9;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll

inline ll MOD(ll x, ll m = mod){
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1e18+1;
const int nmax = 1e3+10;
///===========================================  template  =======================================================

char grid[nmax][nmax];

int dist[nmax][nmax];

#define valid(x, y) (unsigned(x) < n && unsigned(y) < m)
typedef pair<int, int> pii;
void dijkstra(int n, int m){
    for(int i = 0; i<n; i++){
        for(int j = 0; j<m; j++){
            dist[i][j] = inf;
        }
    }
    dist[0][0] = ((grid[0][0] == '#') ? 1 : 0);
    priority_queue<pair<int, pii>> pq;
    pq.emplace(-dist[0][0], make_pair(0, 0));
    while(!pq.empty()){
        pii p;
        int d;
        tie(d, p) = pq.top();
        pq.pop();
        d = -d;
        if(d != dist[p.first][p.second]) continue;

//        debug(p.first);
//        debug(p.second);
//        debug(d);

        int x = p.first, y = p.second;
        if(valid(x+1, y)){
            int tmp = (grid[x][y] == '.' && grid[x+1][y] == '#');
            if(dist[x+1][y] > tmp + d){
                dist[x+1][y] = tmp+d;
                pq.emplace(-dist[x+1][y], make_pair(x+1, y));
            }
        }
        if(valid(x, y+1)){
            int tmp = (grid[x][y] == '.' && grid[x][y+1] == '#');
            if(dist[x][y+1] > tmp + d){
                dist[x][y+1] = tmp+d;
                pq.emplace(-dist[x][y+1], make_pair(x, y+1));
            }
        }
    }
    return;
}

int main(){
    FASTIO;
    int n, m;
    cin>>n>>m;
    for(int i = 0; i<n; i++){
        cin>>grid[i];
    }

    dijkstra(n, m);

    cout<<dist[n-1][m-1];
    return 0;
}


Measured memory_bytes: 2688
S = input()
T = input()

def compute_overlap(W1, W2):
    return sum([w1 != w2 for w1, w2 in zip(W1, W2)])

res = len(T)
for i in range(len(S)-len(T)+1):
    rep = compute_overlap(S[i:i+len(T)], T)
    res = min(res, rep )

print(res)


Measured memory_bytes: 9112
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let h: usize = s.next().unwrap().parse().unwrap();
	let w: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();

	let mut horz = vec![0; h];
	let mut vert = vec![0; w];
	let mut set = std::collections::HashSet::new();

	for _ in 0..m {
		let y: usize = s.next().unwrap().parse::<usize>().unwrap() - 1;
		let x: usize = s.next().unwrap().parse::<usize>().unwrap() - 1;
		horz[y] += 1;
		vert[x] += 1;
		set.insert(y << 32 | x);
	}

	let horzmax = *horz.iter().max().unwrap();
	let vertmax = *vert.iter().max().unwrap();
	let ys: Vec<_> = horz
		.iter()
		.enumerate()
		.filter(|(_, &c)| c == horzmax)
		.map(|(i, _)| i)
		.collect();
	let xs: Vec<_> = vert
		.iter()
		.enumerate()
		.filter(|(_, &c)| c == vertmax)
		.map(|(i, _)| i)
		.collect();
	let mut crossed = true;
	'a: for y in ys.iter() {
		for x in xs.iter() {
			if set.contains(&(y << 32 | x)) {
				continue;
			}
			crossed = false;
			break 'a;
		}
	}
	println!("{}", horzmax + vertmax + if crossed { -1 } else { 0 });
}


Measured memory_bytes: 19620
module Point = struct

  type t = { x : float; y : float }

  let make x y = { x; y }

  let equal_p a b = abs_float (a.x -. b.x) < 1e-10 && abs_float (a.y -. b.y) < 1e-10

  let sum a b = { x = a.x +. b.x; y = a.y +. b.y }

  let diff a b = { x = a.x -. b.x; y = a.y -. b.y }

  let multi p k = { x = p.x *. k; y = p.y *. k }

  let div p k = { x = p.x /. k; y = p.y /. k }

  let norm p = p.x *. p.x +. p.y *. p.y

  let abs p = norm p |> sqrt

  let dot a b = a.x *. b.x +. a.y *. b.y

  let cross a b = a.x *. b.y -. a.y *. b.x

  let project p1 p2 p =
    let base = diff p2 p1 in
    dot (diff p p1) base /. norm base
    |> multi base
    |> sum p1

  let reflect p1 p2 p =
    multi (diff (project p1 p2 p) p) 2.
    |> sum p

  let parallel_p (p0, p1) (p2, p3) =
    let a = diff p0 p1 in
    let b = diff p2 p3 in
    cross a b = 0.

  let orthogonal_p (p0, p1) (p2, p3) =
    let a = diff p0 p1 in
    let b = diff p2 p3 in
    dot a b = 0.

end

module IO = struct

  (* @since 4.04.0 *)
  let split_on_char sep s =
    let open String in
    let r = ref [] in
    let j = ref (length s) in
    for i = length s - 1 downto 0 do
      if get s i = sep then begin
        r := sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    sub s 0 !j :: !r

  let read_fs () = read_line () |> split_on_char ' ' |> List.map float_of_string

end

open Point

let eps = 1e-10

let ccw p0 p1 p2 =
  let a = diff p1 p0 in
  let b = diff p2 p0 in
  let c = cross a b in
  if c > eps then 1
  else if c < (-. eps) then (-1)
  else if dot a b < (-. eps) then 2
  else if norm a < norm b then (-2)
  else 0

let intersect_p (p0, p1) (p2, p3) =
  ccw p0 p1 p2 * ccw p0 p1 p3 <= 0 && ccw p2 p3 p0 * ccw p2 p3 p1 <= 0

let () =
  let q = read_int () in
  for _ = 0 to q - 1 do
    match IO.read_fs () with
    | x0 :: y0 :: x1 :: y1 :: x2 :: y2 :: x3 :: y3 :: _ ->
      let s = (make x0 y0, make x1 y1) in
      let t = (make x2 y2, make x3 y3) in
      print_endline (if intersect_p s t then "1" else "0")
    | _ -> assert false
  done

Measured memory_bytes: 3120
#include<stdio.h>
#include<cstring>
#include<algorithm>
char temp[200005];
long long int num[30]={0};
int main(){
	scanf("%s", temp);
	long long int siz=strlen(temp);
	for(int i=0; i<siz; i++){
		num[int(temp[i]-'a')]++;
	}
	long long int ans=siz*(siz-1)/2;
	for(int i=0; i<26; i++){
		ans-=num[i]*(num[i]-1)/2;
	}
	ans++;
	printf("%lld", ans);
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 21 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

int n;
int a[maxN][maxN];
int dp[23][1 << 21]; // we need only 1<<21 as in 1<<x we have x+1 digits

// in mask -> set bit will represent that the woman hasn't found any particular match

ll solve(ll idx, ll mask) {
	if (idx == n) {
		if (mask == 0) //  means all the women have been paired up with different men
			return 1;
		else
			return 0;
	}
	if (dp[idx][mask] != -1)
		return dp[idx][mask];
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[idx][i] == 1 && (mask & (1 << i))) {
			ans = (ans % MOD +  solve(idx + 1, mask ^ (1 << i)) % MOD) % MOD;
		}
	}
	return dp[idx][mask] = ans;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	FIO
	memset(dp, -1, sizeof(dp));
	cin >> n;
	FOR(i, n) {
		FOR(j, n)
		cin >> a[i][j];
	}
	cout << solve(0, (1 << n) - 1);
	return 0;
}


Measured memory_bytes: 192024
#include<bits/stdc++.h>
using namespace std;
const int N=200010;
int n,m,a[N],b[N];
map<int,int> cnt;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);cnt[a[i]]++;
	}
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		scanf("%d",&b[i]);
		if(!cnt[b[i]]) return puts("NO"),0;
		cnt[b[i]]--;
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 13056
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N, K;
    cin >> N >> K;
    if(K == 0){
        cout << N * N << endl;
        return 0;
    }

    long long ans = 0;
    for(long long b=K+1; b<=N; b++){
        long long nmx;
        long long tmp = N - b + 1;
        if(tmp % b == 0) nmx = tmp / b;
        else nmx = tmp / b + 1;
        long long tmp2 = nmx*(b-1-K+1) + max(0LL, (N-nmx*b-K+1));
        ans += tmp2;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
    freopen("op.txt", "w", stdout);
#endif
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	int dp[n +1] = {0};

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

	for(int i = 1; i < n; ++i){
		dp[i] = INT_MAX;
		for(int j = i -1; j >= max(0, i - k); --j){
			dp[i] = min(dp[i], abs(a[i] - a[j]) + dp[j]);
		}
	}

	cout << dp[n -1] << endl;

}

Measured memory_bytes: 4004
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  long long n,a[100005]={},ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n; i++) {
    ans+=a[i]/2;
    if(a[i]%2==1&&a[i+1]>0) {
      ans++;
      a[i+1]--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#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 sz(a) int((a).size())
	#define pb push_back
	#define mod 1000000007
	#define inf 1000000000000000001
	#define all(c) (c).begin(),(c).end()
	#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
	#define present(c,x) ((c).find(x) != (c).end())
	#define cpresent(c,x) (find(all(c),x) != (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 FOR(i, a, b) for (int i=a; i<(b); i++)
	#define F0R(i, a) for (int i=0; i<(a); i++)
	
	using namespace std;
	
	int main()
	{
		ios::sync_with_stdio(0);
    	cin.tie(0);
    	cout.tie(0);

		ll n; cin >> n;
		string s; cin >> s;
		ll ans=0;
		F0R(i,n-1) {
			if(s[i]!=s[i+1]) {
				ans++;	
			}
		}
		ans++;
		cout << ans;
		
		return 0;
	}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int f(int n){
  return (n*n+4)/8;
}

int main(){
  deque<char> dq;
  string s; cin >> s;
  for(int i = 0; i < (int)s.size(); ++i){
    if(s[i] == '0' || s[i] == '1'){
      dq.push_back(s[i]);
    } else if(!dq.empty()){
      dq.pop_back();
    }
  }
  for(auto e:dq)cout << e;
  cout << endl;
}



Measured memory_bytes: 3592
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
x = I()
if x < 1200:
    print('ABC')
else:
    print('ARC')

Measured memory_bytes: 74600
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//
		int n = sc.nextInt();
		int k = sc.nextInt();
		int result = 1;
		for(int i=0; i<n; i++){
			result = (result * 2 < result + k) ? result * 2 : result + k;
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 35652
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;

int A,B,C,K,res;
int main(){
	cin>>A>>B>>C>>K;
	res+=min(A,K);
	K=max(0,K-A-B);
	res-=K;
	cout<<res<<endl;
}


Measured memory_bytes: 3636
/*
problem's name:
statue:
writer:Patrick_y
*/
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#include <cctype>
#include <sstream>
#include <math.h>
#include <stdio.h>
#include <time.h>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF=20050208;
/*------------main part------------*/




int main()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k%2==0)
	{
		cout<<a-b;
	}
	else
	{
		cout<<b-a;
	}
	return 0;
}


Measured memory_bytes: 256
require 'pp'

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.chars
end

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

N = gets_i
S = gets_nsp_list

max = 0
(1...N).each do |n|
  left  = S[0,n]
  right = S[n,N]
  max = [max, (left.uniq & right.uniq).size].max
end
puts max


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

int main() {
	
	string a,b;
	int i, j;
	
	string pat[2][2] = {
		{ "H", "D" } ,
		{ "D", "H" }
	};
	
	cin >> a;
	cin >> b;
	
	i = ( a == "H" ) ? 0 : 1;
	j = ( b == "H" ) ? 0 : 1;
	
	cout << pat[i][j] << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
d,g=map(int,input().split())
pc=[list(map(int,input().split())) for i in range(d)]

ans=float('inf')

for bit in range(1<<d):
  count=0
  sum=0
  nokori=set(range(1,d+1))
  
  for i in range(d):
    if bit&(1<<i):
      sum+=pc[i][0]*(i+1)*100+pc[i][1]
      count+=pc[i][0]
      nokori.discard(i+1)
      
  if sum<g:
    use=max(nokori)
    n=min(pc[use-1][0], -(-(g-sum)//(use*100)))
    count+=n
    sum+=n*use*100
    
  if sum>=g:
    ans=(min(ans,count))

print(ans)

          



Measured memory_bytes: 3064
import sys
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()
a.sort(reverse=True)

tmp = 0
for i in range(N-1):
  tmp = (a.pop()+a.pop())/2
  a.append(tmp)
  a.sort(reverse=True)

print(a[-1])

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

int n, u, v;
double ans[150051], dp[150051];
int child[150051];
vector<int> graph[150051];

void dfs1(int v, int p)
{
  for (int cv : graph[v])
  {
    if (cv == p)
      continue;
    dfs1(cv, v);
    dp[v] += dp[cv] + 1;
    child[v] += 1;
  }
  if (child[v] > 1)
    dp[v] /= child[v];
}

void dfs2(int v, int p)
{
  // vを根とした状態になってる

  double sum = 0.0;
  for (int cv : graph[v])
  {
    sum += dp[cv] + 1;
  }
  dp[v] = sum / graph[v].size();
  ans[v] = dp[v];

  for (int cv : graph[v])
  {
    if (cv == p)
      continue;
    dp[v] = sum - dp[cv] - 1;
    if (graph[v].size() > 1)
    {
      dp[v] /= graph[v].size() - 1;
    }
    dfs2(cv, v);
    dp[v] = sum / graph[v].size();
  }
}

int main()
{
  cin >> n;
  for (int i = 0; i < n - 1; ++i)
  {
    cin >> u >> v;
    --u, --v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  dfs1(0, 0);
  dfs2(0, 0);

  cout << fixed << setprecision(10);
  for (int i = 0; i < n; ++i)
    cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 19200
n,k=map(int,input().split())
x=[int(q) for q in input().split()]

d=[]

for i in range(1,len(x)):
    d.append(x[i]-x[i-1])
    
d.append(min(x[-1]-x[0], n-x[-1]+x[0]))
print(n-max(d))

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

int N, datas[7][105], memo[7][105];

int solve(int Y, int X)
{
	int ret=datas[Y][X];
	if(Y > 1 || X >=N) return  -1000000000;
	if(Y==1 && X==(N-1)) return ret;
	if(memo[Y][X]!=-1) return memo[Y][X];
	ret+=max(solve(Y+1, X), solve(Y, X+1));
	return memo[Y][X]=ret;
}

int main()
{
	cin>>N;
	for(int a=0;a<2;a++)
	{
		for(int b=0;b<N;b++)
		{
			cin>>datas[a][b];
		}
	}
	memset(memo, -1, sizeof(memo));
	cout<<solve(0, 0);
	return 0;
}

Measured memory_bytes: 256
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
for i in range(N):
    res = i
    if x > A[i]:
        x -= A[i]
    elif x == A[i]:
        res += 1
        break
    else:
        break
print(res)


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

using namespace std;
using ll = long long;

int n, q;


int f(string s, vector<pair<char,char>> op) {

    if(!count(op.begin(), op.end(), make_pair(s[0],'L'))) {
        return 0;
    }
    
    int lef = 0, rig = n; //oooooxxx
    while(rig - lef > 1) {
        int mid = (lef + rig) / 2;
        int pos = mid;
        bool ok = false;
        for(int i = 0; i < q; i++) {
            if(op[i].first == s[pos]) {
                if(op[i].second == 'R' ? pos++ : pos--);
                if(pos < 0){ok = true;break;}
                if(pos >= n)break;
            }
        }
        (ok ? lef : rig) = mid;
    }
    return rig;
}


int main()
{
    string s;
    cin >> n >> q >> s;
    vector<pair<char,char>> op(q);
    for(int i = 0; i < q; i++)cin >> op[i].first >> op[i].second;

    int lef = f(s, op); //xxxoooで何個落ちるか
    reverse(s.begin(), s.end());
    for(int i = 0; i < q; i++)op[i].second = (op[i].second == 'R' ? 'L' : 'R');
    int rig = f(s, op); //xxxoooの右端


    cout << n - min(rig + lef, n) << endl;


}

Measured memory_bytes: 4484
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0)
typedef pair<int,int> ii;
typedef long long int ll;
typedef vector<int> vi;
vi dp;
vi h;
int n,k;
// dp[i] = minimo pra ir dali ate o final
int solve(int i){
	if(i == n-1) return 0; 
	if(dp[i] != -1) return dp[i];
	int ret = 2e9;
	for(int k1 = 1 ; k1 + i < n && k1 <= k; k1++){
		ret = min(ret,solve(i+k1) + abs(h[i] - h[i+k1]));
	}
	dp[i] = ret;
	return ret;
}
 
int main(){
	fast;
	cin >> n >> k;
	h.resize(n);
	dp.resize(n,-1);
	for(int i = 0 ; i < n ; i++){
		cin >> h[i];
	}
	cout << solve(0) << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;cin>>n;
	ll a,c=0;
	int ls=0;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(a==0) 
		{
			ls=0;
			continue;
		}
		c+=(a+ls)/2;
		ls=(a+ls)%2;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, m;
    std::cin >> n >> m;
    std::multiset<i64> s;
    for (int i = 0; i < n; i++) {
        i64 in;
        std::cin >> in;
        s.insert(-in);
    }

    for (int i = 0; i < m && !s.empty(); i++) {
        auto it = s.begin();
        auto p = -*it;
        s.erase(it);
        p /= 2;
        if (p) s.insert(-p);
    }

    i64 ret = 0;
    for (auto e : s) ret += -e;
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int  main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int cnt=0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
            cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll h,w,mini=100000000;
    cin>>h>>w;
    for(ll i=1;i<h;i++){
        mini=min(mini,max(w*i,max((h-i)/2*w,(((h-i)/2+(h-i)%2))*w))-min(w*i,min((h-i)/2*w,((h-i)/2+(h-i)%2)*w)));
        mini=min(mini,max(w*i,max((h-i)*(w/2),(h-i)*((w/2)+(w%2))))-min(w*i,min((h-i)*(w/2),(h-i)*((w/2)+(w%2)))));
    }
    swap(h,w);
    for(ll i=1;i<h;i++){
        mini=min(mini,max(w*i,max((h-i)/2*w,(((h-i)/2+(h-i)%2))*w))-min(w*i,min((h-i)/2*w,((h-i)/2+(h-i)%2)*w)));
        mini=min(mini,max(w*i,max((h-i)*(w/2),(h-i)*((w/2)+(w%2))))-min(w*i,min((h-i)*(w/2),(h-i)*((w/2)+(w%2)))));
    }
    cout<<mini<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define mt make_tuple
#define fi first
#define se second
#define endl "\n"

using namespace std;
using ll = long long;
using ld = long double;

const int INF = 987654321;
ll A, B;

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

	cin >> A >> B;
	cout << max({ A + B, A - B, A * B }) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

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 reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int h, w;
	cin >> h >> w;
	vs s(h);
	rep(i, h)cin >> s[i];
	int dx[4] = { 1,0,-1,0 };
	int dy[4] = { 0,1,0,-1 };

	bool f = true;
	rep(i, h) {
		rep(j, w) {
			bool ft = false;
			if (s[i][j] == '#') {
				rep(k, 4) {
					if (i + dy[k] < 0 || i + dy[k] >= h)continue;
					if (j + dx[k] < 0 || j + dx[k] >= w)continue;
					if (s[i + dy[k]][j + dx[k]] == '#') ft = true;
				}
				if (!ft) f = false;
			}
			
		}
	}

	if (f) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 1000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e6+10;
const double eps=1e-6;



int main(){
    #ifdef ONLINE_JUDGE
    #else
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    #endif
 
    string s;
    cin>>s;
    if(s.size()<4){
    	cout<<"No"<<endl;
    	return 0;
    }
    if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;

    return 0;	
}

Measured memory_bytes: 256
#include<stdio.h>

#define ll long long

int main()
{
  unsigned ll n,d,ans;
  	scanf("%llu %llu",&n,&d);
  	d=2*d+1;
  	if(n%d==0)
    {ans=n/d;}
  	else
      	ans=(n/d )+1;
  	
  	printf("%llu",ans);
  return 0;
}

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

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

	int ret = 0;
	int n = 4;
	for (int i = 0; i < n; ++i) {
		if (s[i] == '+') {
			ret++;
		}
		else if (s[i] == '-') {
			ret--;
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
N,M =map(int, input().split())
a = [input().split() for l in range(M)]

for i in range(1000):
    flag = 1
    b = str(i)
    if len(b)!= N:
        flag = 0
        continue
    for j in range(M):
        if b[int(a[j][0])-1] != a[j][1]:
            flag = 0
            break
    if flag == 1:
        print(i)
        sys.exit()

print("-1")

Measured memory_bytes: 3064
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5 + 10;


int main(){
	int s , w;
	scanf("%d%d" , &s , &w);
	if(s > w){
		printf("safe\n");
	}
	else{
		printf("unsafe\n");
	}
}


Measured memory_bytes: 3656
using System;

namespace Project
{
	class Dice
	{
		public int face;
		public int N;
		public int E;
		public int S;
		public int W;
		public int back;

		public Dice(int a1, int a2, int a3, int a4, int a5, int a6)
		{
			face = a1;
			N = a5;
			E = a3;
			S = a2;
			W = a4;
			back = a6;
		}
		public void roll(char D)
		{
			int pface = face;
			int pN = N;
			int pE = E;
			int pW = W;
			int pS = S;
			int pback = back;
			switch (D)
			{
				case 'N':
					face = pS;
					N = pface;
					S = pback;
					back = pN;
					break;
				case 'E':
					face = pW;
					E = pface;
					W = pback;
					back = pE;
					break;
				case 'W':
					face = pE;
					E = pback;
					W = pface;
					back = pW;
					break;
				case 'S':
					face = pN;
					N = pback;
					S = pface;
					back = pS;
					break;
			}
		}
	}

	class MainClass
	{
		public static void Main(string[] args)
		{
			string[] s = Console.ReadLine().Split(' ');
			int[] a = new int[6];
			for (int i = 0; i < 6; i++)
			{
				a[i] = int.Parse(s[i]);
			}
			Dice dice1 = new Dice(a[0], a[1], a[2], a[3], a[4], a[5]);
			s = Console.ReadLine().Split(' ');
			for (int i = 0; i < 6; i++)
			{
				a[i] = int.Parse(s[i]);
			}
			Dice dice2 = new Dice(a[0], a[1], a[2], a[3], a[4], a[5]);
			int count = 0;
			while (count < 10)
			{
				if (checkdice(dice1, dice2)) break;
				dice1.roll('N');
				if (checkdice(dice1, dice2)) break;
				dice1.roll('N');
				if (checkdice(dice1, dice2)) break;
				dice1.roll('N');
				if (checkdice(dice1, dice2)) break;
				dice1.roll('N');
				if (count == 4) dice1.roll('N');
				dice1.roll('W');
				count++;
			}
			if(count == 10) Console.WriteLine("No");
			else Console.WriteLine("Yes");


		}

		public static bool checkdice(Dice dice1, Dice dice2)
		{
			if (dice1.face == dice2.face && dice1.N == dice2.N && dice1.E == dice2.E && dice1.S == dice2.S && dice1.W == dice2.W && dice1.back == dice2.back) return true;
			else return false;
		}

	}
}

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

int sum(int a, int b){
    if(a == b){
        return a;
    }
    int s = sum(a, b-1);
    return s + b;
}

int main(void){
    int K, N;
    cin >> K >> N;
    vector<int> a(N);
    for(int i = 0; i<N; i++){
        cin >> a[i];
    }
    int ma = K-a[N-1]+a[0];
    for(int i = 0; i < N-1; i++){
        ma = max(a[i+1]-a[i],ma);
    }
    
    printf("%d\n",K-ma);
    
}

Measured memory_bytes: 1024
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    _ <- getLine
    as <- getIntList
    print $ solve as

solve as = 1 / (sum (map (\a -> 1 / (fromIntegral a)) as))

Measured memory_bytes: 508
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        boolean[][] g = input();
        boolean[] visited = new boolean[g[0].length];
        Arrays.fill(visited,false);
        visited[0] = true;
        System.out.println(dfs(g,0,visited));
    }

    private static boolean[][] input(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[][] ret = new boolean[n][n];
        for(int i = 0; i < m;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            ret[a-1][b-1] = ret[b-1][a-1] = true;
        }
        sc.close();
        return ret;
    }

    private static int dfs(boolean[][] g, int s, boolean[] bools){
        boolean all_true = true;
        for(boolean b: bools){
            if(!b){
                all_true = false;
                break;
            }
        }
        if(all_true){
            return 1;
        }
        int ans = 0;
        for(int i = 0; i < bools.length; i++){
            if(!g[s][i] || bools[i]) continue;
                bools[i] = true;
                ans += dfs(g,i,bools);
                bools[i] = false;
        }
        return ans;
    }
}

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

#define all(x) (x).begin(),(x).end()
using namespace std;

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

    set<int> a,b,c;
    int n,m;
    int x;

    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a.insert(x);
    }

    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>x;
        b.insert(x);
    }

    set_difference(all(a),all(b),inserter(c,c.end()));

    for(int i:c)
    {
        cout<<i<<endl;
    }

    return 0;
}





Measured memory_bytes: 31292
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a, b;
    cin >> x >> a >> b;
    cout << (abs(x - a) < abs(x - b) ? "A" : "B") << endl;
}

Measured memory_bytes: 256
module Main where

import           Control.Monad
import           Data.List
import           Data.Ord
import           Data.List.Split
import qualified Data.Vector.Unboxed as V

solve [] = 0
solve (as:ass)
  | length as < head as = length as + solve ass
  | otherwise = length as - head as + solve ass

main :: IO ()
main = do
  _ <- getLine
  ass <- group . sortOn Down . map read . words <$> getLine
  print $ solve ass


Measured memory_bytes: 44028
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define fori(a,b) for(int i=a;i<b;i++)
#define forj(a,b) for(int j=a;j<b;j++)
#define ford(b,a) for(int i=b;i>=a;i--)
typedef pair<int, int> pi;
#define PI 3.14159265359
#define vi vector<int>
long long mod=1000000007;
//int count=INT_MAX;
 
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testcases=1;
    //cin>>testcases;
    //cout<<t;
    //scanf("%d",&t);
    int t=testcases;
    while(testcases--){  
        ll x,k,d;
        cin>>x>>k>>d;
        x=(ll)abs(x);
        if(x<=d){
            if(k%2LL==0LL){
                cout<<x<<endl;
                continue;
            }
            else{
                cout<<d-x<<endl;
                continue;
            }
        }
        ll q=x/d;
        if(q>=k){
            cout<<x-(k*d)<<endl;
            continue;
        }
        k-=q;
        x=x-(q*d);
        if(k%2LL==0LL){
            cout<<x<<endl;
        }
        else{
            cout<<d-x<<endl;
        }
    }               

    
    return 0;
}

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

using namespace std;

string x;
int a, b, c, d;

int main() {
	cin >> x;
	a = x[0] - '0';
	b = x[1] - '0';
	c = x[2] - '0';
	d = x[3] - '0';
	if(a + b + c + d == 7) {
		cout << a << "+" << b << "+" << c << "+" << d << "=7";
	} else if(a + b + c - d == 7) {
		cout << a << "+" << b << "+" << c << "-" << d << "=7";		
	} else if(a + b - c + d == 7) {
		cout << a << "+" << b << "-" << c << "+" << d << "=7";	
	} else if(a + b - c - d == 7) {
		cout << a << "+" << b << "-" << c << "-" << d << "=7";		
	} else if(a - b + c + d == 7) {
		cout << a << "-" << b << "+" << c << "+" << d << "=7";		
	} else if(a - b + c - d == 7) {
		cout << a << "-" << b << "+" << c << "-" << d << "=7";	
	} else if(a - b - c + d == 7) {
		cout << a << "-" << b << "-" << c << "+" << d << "=7";
	} else {
		cout << a << "-" << b << "-" << c << "-" << d << "=7";
	}
	return 0;
}


Measured memory_bytes: 256