akhauriyash/Code-Regression huggingface dataset:
#[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)*}
    };
}

#[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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: i64,
        k: i64,
    }
    if k == 0 {
        println!("{}", n*n);
        return;
    }

    let mut ans = 0;
    for b in k+1..n+1 {
        ans += (b-k) * (n/b);
        ans += max(n%b-k+1, 0);
    }
    println!("{}", ans);
}


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

int main() {
    string s;
    cin >> s;
    int n = s.length() - 1;
    
    long long ans = 0;
    for(int bin=0; bin<(1 << n); bin++){
      int l = 0, r;
      for(r=0; r<n; r++){
        if(bin & 1 << r){
          string t = s.substr(l, r-l+1);
          ans += stoll(t);
          l = r + 1;
        }
      }
      string t = s.substr(l, r-l+1);
      ans += stoll(t);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
Av = sum(X) / len(X)
round=lambda x:(x*2+1)//2
Avg = round(Av)
p = 0
for i in range(N):
    S = (X[i] - Avg) **2
    p = p + S
print(int(p))

Measured memory_bytes: 3060
# D - Wizard in Maze
import sys
from collections import deque
from typing import List, Tuple


class WarpableMaze:
    __slots__ = ["height", "width", "road", "wall", "grid"]

    def __init__(
        self,
        height: int,
        width: int,
        grid: List[str],
        road: str = ".",
        wall: str = "#",
    ) -> None:
        # Values of start and goal must be 0-origin.
        self.height = height + 4
        self.width = width + 4
        self.road = road
        self.wall = wall
        self.grid = self._flatten_grid(grid)

    def _flatten_grid(self, grid: List[str]) -> str:
        flat_grid = self.wall * self.width * 2
        for row in grid:
            flat_grid += self.wall * 2 + row + self.wall * 2
        flat_grid += self.wall * self.width * 2
        return flat_grid

    def _flatten_dxy(self, x: int, y: int) -> int:
        return self.width * x + y

    def _flatten_coordinate(self, h: int, w: int) -> int:
        return self._flatten_dxy(h + 2, w + 2)

    def bfs(self, start_2d: Tuple[int, int], goal_2d: Tuple[int, int]) -> int:
        start = self._flatten_coordinate(*start_2d)
        goal = self._flatten_coordinate(*goal_2d)

        w = self.width
        flatten = lambda *dxy: tuple(self._flatten_dxy(*xy) for xy in dxy)
        move_to_warp = {
            -w: flatten((-2, -2), (-2, -1), (-2, 0), (-2, 1), (-1, -1)),
            w: flatten((1, 1), (2, -1), (2, 0), (2, 1), (2, 2)),
            -1: flatten((-1, -2), (0, -2), (1, -2), (1, -1), (2, -2)),
            1: flatten((-1, 1), (-2, 2), (-1, 2), (0, 2), (1, 2)),
        }

        unsearched = 1 << 30
        dist = [unsearched] * (self.height * self.width)
        dist[start] = 0
        queue = deque([start])
        while queue:
            x = queue.popleft()
            cur_dist = dist[x]
            if x == goal:
                break

            for move, warp in move_to_warp.items():
                nx = x + move
                if self.grid[nx] == self.road:
                    if dist[nx] > cur_dist:
                        dist[nx] = cur_dist
                        queue.appendleft(nx)
                    continue

                for dx in warp:
                    nx = x + dx
                    if self.grid[nx] == self.wall:
                        continue
                    if dist[nx] > cur_dist + 1:
                        dist[nx] = cur_dist + 1
                        queue.append(nx)

        return dist[goal] if dist[goal] != unsearched else -1

    def debug(self):
        print("<DEBUG>", file=sys.stderr)
        for row in zip(*[iter(self.grid)] * self.width):
            print(*row, file=sys.stderr)


def main():
    H, W, CH, CW, DH, DW, *S = open(0).read().split()
    maze = WarpableMaze(int(H), int(W), S)
    start, goal = (int(CH) - 1, int(CW) - 1), (int(DH) - 1, int(DW) - 1)
    print(maze.bfs(start, goal))
    # maze.debug()


if __name__ == "__main__":
    main()


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

#define MAX 500001
/*
struct Node{
  int p;
  int l;
  int r;
};

struct Node A[MAX];
*/
int heap_size;

int Parent(int i){
  return i/2;
}
int Left(int i){
  return 2*i;
}
int Right(int i){
  return 2*i+1;
}

void maxHeapify(int A[],int i){
  int l,r,largest;
  int temp;
  
  l = Left(i);
  r = Right(i);
  

  if((l <= heap_size) && (A[l] > A[i])){
    largest = l;
  }
  else {
    largest = i;
  }
  
  if((r <= heap_size) && (A[r] > A[largest])){
    largest = r;
  } 
  
  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    
    maxHeapify(A,largest);
  } 
}

void buildMaxHeap(int A[]){
  int i;

  for(i = heap_size/2 ; i >= 1 ; i--){
    maxHeapify(A,i);
  }
}

int main(void){
  int i,key[MAX];
  
  scanf("%d",&heap_size);
  
  for(i = 1 ; i <= heap_size ; i++){
    scanf("%d",&key[i]);  
  }
  
  buildMaxHeap(key);
  
  for(i = 1 ; i <= heap_size ; i++){
    printf(" %d",key[i]);
  }
  printf("\n");
  
  return 0;
}

Measured memory_bytes: 2356
using System;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int n=int.Parse(Console.ReadLine());
		int[] a=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int[][] c=new int[s[0]][];
		int q=0;
		for(int i=0;i<s[0];i++){
			c[i]=new int[s[1]];
			if(i%2==0){
				for(int j=0;j<s[1];j++){
					c[i][j]=q+1;
					a[q]--;
					if(a[q]==0){q++;}
				}
			}
			else{
				for(int j=s[1]-1;j>-1;j--){
					c[i][j]=q+1;
					a[q]--;
					if(a[q]==0){q++;}
				}
			}
			Console.WriteLine("{0}",string.Join(" ",c[i]));
		}
	}
}

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

int main(void){
    
    unsigned long H,W;
    cin >> H >> W;
    
    if(H%2 == 1 && W%2 == 1){
        if(H == 1 || W == 1){
            cout << 1 << endl;
        }
        else{
            cout<< H*W/2 + 1 <<endl;
        }
        
    }
    else{
        if(H == 1 || W == 1){
            cout << 1 << endl;
        }
        else{
            cout<< H*W/2 <<endl;
        }
        
    }
   
}

Measured memory_bytes: 3572
def main():
  N = int(input())
  ps = [i for i in map(int, input().split())]
  cou = 0

  for i in range(N):
    if ((i+1) != ps[i]) and cou==0:
      tp = i+1
      cou += 1
    elif ((i+1) != ps[i]) and cou==1:
      if ps[i] != tp:
        return('NO')
      cou += 1
    elif ((i+1) != ps[i]) and cou==2:
      return('NO')
  return('YES')
if __name__ == '__main__':
  print(main())

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int ws[10],ks[10];
    for(int i=0;i<10;i++)scanf("%d",&ws[i]);
    for(int i=0;i<10;i++)scanf("%d",&ks[i]);
    sort(ws,ws+10);
    sort(ks,ks+10);
    printf("%d %d\n",ws[7]+ws[8]+ws[9],ks[7]+ks[8]+ks[9]);
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n,m;
  while(cin>>n>>m, n||m) {
    string s[n];
    int a[n];

    REP(i,n) {
      cin >> s[i] >> a[i];
    }
    int res = 0;
    REP(i,m) {
      string b;
      cin >> b;
      REP(k, n) {
        bool f = 1;
        REP(j, 8) {
          if (s[k][j] != '*' && s[k][j] != b[j]){
            f = 0;
            break;
          }
        }
        if (f) {
          res += a[k];
        }
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 928
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int ans;
  cin >> s;
  if(s=="SUN") ans=7;
  if(s=="MON") ans=6;
  if(s=="TUE") ans=5;
  if(s=="WED") ans=4;
  if(s=="THU") ans=3;
  if(s=="FRI") ans=2;
  if(s=="SAT") ans=1;
  cout << ans <<endl;
  return 0;
}


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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i, k , n) for(int i = k; i <= n; i++)
typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;


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

   int n; cin >> n;
   map<char, int> m;
   rep(i, n)
   {
      char x; cin >> x;
      m[x]++;
   }
   if(m.size() == 3)
      cout << "Three" << nl;
   else
      cout << "Four" << nl;
   return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define ll long long

int main(void)
{
    ll i,a,mi,ma,su;
    mi = 10e9;
    ma = -10e9;
    su=0;
    scanf("%lld",&i);
    for(;i>0;i--)
    {
        scanf("%lld",&a);
        mi = MIN(a,mi);
        ma = MAX(a,ma);
        su +=a;
    }
    printf("%lld %lld %lld\n",mi,ma,su);
    return 0;
}




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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int N;
    int x[110000], y[110000], t[110000];
    cin >> N;
    x[0] = y[0] = t[0] = 0;
    REP(i, N) cin >> t[i+1] >> x[i+1] >> y[i+1];

    bool can = true;
    REP(i, N){
        int dt = t[i+1]-t[i];
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        if (dt < dist) can = false;
        if (dt%2 != dist%2) can = false;
    }

    if (can) cout << "Yes" << "\n";
    else cout << "No" << "\n";

    return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = II()
    ans = 0
    for i in range(a + 1):
        ans += i
    print(ans)
    return

#B
def B():
    s = S()
    ans = []
    for si in s:
        if si == "B":
            ans = ans[:-1]
            continue
        ans.append(si)
    print("".join(ans))
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 38512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	int a; cin >> a; cout << a * a * 3 << endl;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program {
    static void Main() {
        var s = NextString();
        var dic = new HashSet<char>[s.Length];
        var flg = false;

        foreach (var i in Enumerable.Range(0, s.Length)) {
            dic[i] = new HashSet<char> { s[i] };
        }

        while (true) {
            for (var c = 'a'; c <= 'z'; c++) {
                foreach (var i in Enumerable.Range(0, dic.Length)) {
                    if (!dic[i].Contains(c)) {
                        goto exitLoop;
                    }
                }
                flg = true;
                exitLoop: ;
            }
            foreach (var i in Enumerable.Range(0, dic.Length - 1)) {
                foreach (var v in dic[i + 1]) {
                    dic[i].Add(v);
                }
            }
            if (flg) {
                break;
            }
            dic = dic.Take(dic.Length - 1).ToArray();
        }
        WriteLine(s.Length - dic.Length);
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 13408
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
long long ceil(long long a,long long b){// a以上でｂの倍数の最小値//
    return (a+b-1)/b*b;
}
int main(void){
   long long n;
   cin>>n;
   vector<long long> v(n,0),t(n,0);
   rep(i,n) cin>>v[i]>>t[i];
   long long sum=0;

   for(int j=n-1;j>=0;j--){
           sum+=ceil(v[j]+sum,t[j])-(v[j]+sum);
   }

   cout<<sum<<endl;
   return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

// 足場iまで移動するのにかかる最小コスト
int dp[100010];
int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i=0; i<N; i++) cin >> h[i];
    // 0-indexed 足場0までの最小コストは0
    dp[0] = 0;
    for(int i=1; i<N; i++){
        // 足場1には0から来るしかない
        if(i == 1) dp[i] = dp[0] + abs(h[0] - h[1]);
        else{
            dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), // 足場i-1からくる
                        dp[i-2] + abs(h[i-2]-h[i]));  // 足場i-2からくる
        }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
object Main extends App{
  import scala.io.StdIn._
  import scala.math.abs
  val t = readLine.trim.toInt
  for (_ ← 0 until t){
    val Array(a, b, c, d) = readLine.trim.split(' ').map(_.toLong)
    if (a < b || d < b) println("No")
    else if (c >= b) println("Yes")
    else{// B > rest > C
      // B > A + xD - yB > C
      // B - A > xD - yB > C - A
      // A - C > yB - xD > A - B
      val diff = (a % b)
      val g = gcd(b, d)
      println(
        if ((a - c - 1) / g != (a - b) / g) "No"
        else "Yes"
      )
    }
  }
  def gcd(a:Long, b:Long):Long = {
    b match{
      case 0 ⇒ a
      case _ ⇒ gcd(b, a % b)
    }
  }
}

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

template <class T> T* serchL(T* begin, T* end, T num) {
	T *p = begin;
	for (; p < end;p++) {
		if (&p >= num) {
			return p;
		}
	}

	return NULL;
}

int main() {
	ios::sync_with_stdio(false);
	int A, B, C;
	cin >> A >> B >> C;
	if (A>C && B<C) {
		cout << "Yes\n";
		return 0;
	}

	else if (A<C && B>C) {
		cout << "Yes\n";
		return 0;
	}

	else{
		cout << "No\n";
		return 0;
	}

	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  s <- getLine
  if s == "ABC"
    then putStrLn "ARC"
    else putStrLn "ABC"


Measured memory_bytes: 3652
n,c,k = map(int, input().split())
l=[int(input()) for x in range(n)]
l.sort()
flg=l[0]
bus=1
capa=1
for i in range(1,n):

    if capa==c:
        bus+=1
        capa=1
        flg=l[i]
    
    elif flg <= l[i] <= flg+k:
            capa+=1
    else:
        bus+=1
        capa=1
        flg=l[i]    
print(bus)

Measured memory_bytes: 7384
#include <stdio.h>

void swap(int *x, int *y) {
  int t = *x;
  *x = *y;
  *y = t;
}

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  if (a > b) swap(&a, &b);
  if (b > c) swap(&b, &c);
  if (a > b) swap(&a, &b);
  printf("%d %d %d\n", a, b, c);
  return 0;
}


Measured memory_bytes: 2028
#include <stdio.h>

int main(void){
	int min=100,sum=0;
	int a,i;
	for(i=0;i<4;i++){
		scanf("%d",&a);
		if(min>a)
			min=a;
		sum+=a;
	}
	sum-=min;min=100;
	for(i=0;i<2;i++){
		scanf("%d",&a);
		if(min>a)
			min=a;
		sum+=a;
	}
	sum-=min;
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <string.h>
int main(void) {
	int n, i, j, k;
	char cp;
	scanf("%d", &n);
	char S[n][100];
	int count[26] = {};
	int ans[26] = {};
	int flag = 0;
	for (i = 0; i < n; i++) {
		scanf("%s", S[i]);
		
		/*for (k = 0; k < strlen(S[i]) - 1; k++) {
			for (j = strlen(S[i]) - 1; j > k; j--) {
				if (S[i][j] < S[i][j - 1]) {
					cp = S[i][j - 1]; S[i][j - 1] = S[i][j]; S[i][j] = cp;
				}
			}
		}*/

	}

	for (i = 0; i < n; i++) {
		for (k = 0; k < 26; k++)count[k] = 0;
		for (j = 0; j < strlen(S[i]); j++) {
			//printf("%d",strlen(S[i]));
			count[S[i][j] - 'a']++;
		}
		for (k = 0; k < 26; k++) {
			if (flag == 0) {
				ans[k] = count[k];
			}
			else if (ans[k] > count[k]) {
				ans[k] = count[k];
			}
			//printf("%c:%d\n", 'a' + k, count[k]);
		}
		flag = 1;
	}

	for (i = 0; i < 26; i++) {
		for (; ans[i] != 0; ans[i]--) printf("%c", 'a' + i);
	}
	printf("\n");



	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <math.h>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#include <list>
#include <ctype.h>
#include <cassert>
#include <stack>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <functional>
#include <ctime>
#include <limits>
#include <tuple>
#include <complex>

using namespace std;

#define snd second
#define fst first
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define left _left
#define right _right

const ld pi = acos(-1.0l);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
void chmin(T &x, T y) {
    x = min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
    x = max(x, y);
}

template<typename U, typename V>
ostream &operator<<(ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const vector<U> &x) {
    s << "[";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "]";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const set<U> &x) {
    s << "{";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "}";
    return s;
}

template<int sz>
ostream operator<<(ostream &s, const bitset<sz> &x) {
    for (int i = 0; i < sz; i++) {
        s << x[i];
    }
    return s;
}


//-----------------------------------------------------------------------------



int main() {
    srand(time(NULL));

    retry:
#ifdef LOCAL
    //gen();
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
#endif

    string s;
    cin >> s;
    int was[4] = { 0, 0, 0, 0 };

    for (char c : s) {
        if (c == 'N') {
            was[0] = 1;
        } else if (c == 'S') {
            was[1] = 1;
        } else if (c == 'E') {
            was[2] = 1;
        } else {
            was[3] = 1;
        }
    }

    bool good = (!was[0] || (was[0] && was[1]));
    good &= (!was[1] || (was[0] && was[1]));
    good &= (!was[2] || (was[2] && was[3]));
    good &= (!was[3] || (was[2] && was[3]));

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


    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())

def okikae(t, k):
    if k==0:
        print(t)
    elif int(k/2)+1 > t:
        print(t)
    elif t%k==0:
        print(0)
    elif t>k and t%k > 0:
        t = k+(t%k)
        okikae(abs(t-k), k)
    else:
        okikae(abs(t-k), k)

okikae(N, K)

Measured memory_bytes: 3060
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int X = scanner.nextInt();
		int Y = scanner.nextInt();

		if (K >= N) {
			System.out.println(N*X);
		} else {
			System.out.println(K*X+(N-K)*Y);
		}
		scanner.close();
	}

}


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

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define FORR(i, a, b) for (long long i = (a); i >= (b); i--)
#define REPR(i, N) for (long long i = n; i >= 0; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(s) (s).begin(), (s).end()
#define pb(a) push_back(a)

#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

bool check(string s, string ans, ll i, ll N){
    if(s[i] == 'o'){
        if(ans[i] == 'S' and ans[(i+1)%N] == ans[(i-1+N)%N]){
            return true;
        }else if(ans[i] == 'W' and ans[(i+1)%N] != ans[(i-1+N)%N]){
            return true;
        }
    }else {
        if(ans[i] == 'W' and ans[(i+1)%N] == ans[(i-1+N)%N]){
            return true;
        }else if(ans[i] == 'S' and ans[(i+1)%N] != ans[(i-1+N)%N]){
            return true;
        }
    }
    return false;
}

int main()
{
    ll N;
    string s;
    cin >> N;
    cin >> s;
    string ans;
    string init_pattern[4] = {"SS", "SW", "WS", "WW"};
    for(string p: init_pattern){
        ans = "";
        ans += p;
        FOR(i,2,N+2){
            if(s[(i-1)%N] == 'o'){
                if(ans[i-1] == 'S'){
                    ans += ans[i-2];   
                }else{
                    ans += (ans[i-2] == 'S') ? 'W' : 'S';
                }
            }else {
                if(ans[i-1] == 'S'){
                    ans += (ans[i-2] == 'S') ? 'W' : 'S';
                }else{
                    ans += ans[i-2]; 
                }
            }
        }
        if (ans[0] == ans[N] && ans[1] == ans[N+1]){
            break;
        }
        ans = "-1";
    }
    cout << ans.substr(0,N) << endl;
}


Measured memory_bytes: 768
#include<stdio.h>

int main(){
	//freopen("in/0004.txt","r",stdin);
	int a,b,c,d,e,f;
	float x,y;
	while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)!=EOF){
		x=a*e-b*d;
		y=(a*f-d*c)/x;
		x=(c*e-f*b)/x;
		x=x==0? 0.0:x;
		y=y==0? 0.0:y;
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 636
n = int(input())
s = list(input())

r = 0
g = 0
b = 0

for i in range(n):
    if s[i] == 'R':
        r += 1
    elif s[i] == 'G':
        g += 1
    else:
        b += 1

ans = r*g*b

for i in range(1, n//2+1):
    for j in range(n):
        if j+2*i < n:
            if s[j] != s[j+i] and s[j+i] != s[j+2*i] and s[j] != s[j+2*i]:
                #print(j, j+i, j+2*i)
                ans -= 1
print(ans)


Measured memory_bytes: 68396
import numpy as np

def multi_input():
    return map(int, input().split())

l = np.array(list(multi_input()))
l = np.abs(l - max(l))
l.sort()

ans = 0
if (l[2] - l[1]) % 2 == 0:
    ans += l[1] + (l[2] - l[1]) // 2
else:
    t = (l[2] - l[1] - 1) // 2
    ans += t + (l[2] - 2 * t + 1)  
print(ans)

Measured memory_bytes: 12500
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        Set<Integer> A = new HashSet<Integer>();
        for (int i = 0; i < N; i++) {
            A.add(scanner.nextInt());
        }
        int ans = (A.size() % 2 != 0)? A.size(): A.size() - 1;
        System.out.println(ans);
    }

}


Measured memory_bytes: 64544
N = int(input())
A = list(map(int, input().split()))

A.sort()
if A[0] == 0:
    print(0)
else:
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 10 ** 18:
            ans = -1
            break

    print(ans)

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

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    if (a > 0) {
        cout << "Positive\n";
    } else if (b >= 0) {
        cout << "Zero\n";
    } else {
        if ((b - a) % 2) {
            cout << "Positive\n";
        } else {
            cout << "Negative\n";
        }
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class E
{
	public static void Main()
	{
		int N = GetInt();
		int M = GetInt();

		UnionFind uf = new UnionFind(N+1);
		int start = 0;
		for(int i = 0; i < M; i++)
		{
			int X = GetInt();
			int Y = GetInt();
			int Z = GetInt();
			uf.unite(X, Y);			
			start = X;
		}

		bool[] usedPar = new bool[N+1];
		int numConnected = 0;
		int numRest = N;
		for(int i = 1; i <= N; i++)
		{
			int par = uf.find(i);
			if(usedPar[par])
				continue;
			usedPar[par] = true;
			numConnected++;
			numRest -= uf.GetWeight(par);
		}
		Console.WriteLine(numConnected + numRest);
	}
}


public class UnionFind
{
	public int N { get; private set; } = 0;
	private int[] par = null;
	private int[] rank = null;
	private int[] weight = null;
	
	public UnionFind(int n)
	{
		if(n <= 0)
			throw new Exception();
		N = n;
		par = new int[N];
		rank = new int[N];
		weight = new int[N];
		for(int i = 0; i < N; i++)
		{
			par[i] = i;
			rank[i] = 0;
			weight[i] = 1;
		}
	}
	
	public int find(int x)
	{
		if(par[x] == x)
		{
			return x;			
		}
		else
		{
			return (par[x] = find(par[x]));
		}
	}
	
	public void unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if(x == y)
			return;
		
		if(rank[x] < rank[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if(rank[x] == rank[y])
				rank[x]++;			
		}
		int tmp = weight[x] + weight[y];
		weight[x] = tmp;
		weight[y] = tmp;
	}
	
	public bool same(int x, int y)
	{
		return (find(x) == find(y));
	}

	public int GetWeight(int x)
	{
		return weight[x];
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





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

int main() {
  int64_t A,B,C,ans=1;
  cin >> A >> B;
  while(B!=0){
    A%=B;
    swap(A,B);
  }
  C = A;
  for (int64_t i=2; i*i<=C; i++) {
        if (C%i == 0) {
          ans++;
          while(C%i==0) {
            C /= i;
          }
        }
    }
  if (C > 1) {
    ans++;
  } 
  cout << ans << endl;
}



Measured memory_bytes: 256
#![allow(non_snake_case)]

use proconio::input;

fn main() {
    input! {
        X: i64,
        Y: i64,
    }
    let m = (Y - 2 * X) / 2;
    if Y % 2 == 0 && 0 <= m && m <= X {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2168
#include<iostream>
using namespace std;
int main(){
    int n;
    int a[100010];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int cnt = 0;
    for(int i=0;i<n-1;i++){
        cnt += a[i]<a[i+1];
    }
    cout << cnt << endl;
    return(0);
}


Measured memory_bytes: 3488
main :: IO()
main = do
    _ <- getLine
    pls <- map read . words <$> getLine
    print $ getsolve pls
    
    
getsolve :: [Int] -> Int
getsolve pls
    | length pls < 3    = 0
    | pls!!1 == maximum( take 3 pls )    = getsolve $ tail pls
    | pls!!1 == minimum( take 3 pls )    = getsolve $ tail pls
    | otherwise                         = 1 + getsolve (tail pls)

Measured memory_bytes: 508
#include<iostream>
#include <string>
#include<vector>

using namespace std;

int main(){

	int n, k, x, y;
	cin >> n >> k >> x >> y;
	if(n-k <=0){
		cout << n*x << endl;
	}
	else{
		cout << k*x + (n-k)*y << endl;
	}

	return 0;


}

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

ans = len(S)
for i in range(len(S)-len(T)+1):
    T_ = S[i:i+len(T)]
    count = 0
    for j in range(len(T)):
        if T[j] != T_[j]:
            count += 1
    # print(T_, T, count)
    ans = min(count, ans)
print(ans)

Measured memory_bytes: 9140
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#define ll long long
#define str string
#define rtn return
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define db long double
#define MOD 1000000007
#define INF 1e18
#define EPS 1e-15
#define pll pair <ll, ll>
#define vi vector<ll>
#define vpll vector<pll>
#define value_at find_by_order
#define index_of order_of_key
#define fill(a,v) memset(a,v,sizeof(a))
#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 per(i,n) for(ll i=n-1;i>=0;--i)
#define loop1(i, n) for (int i=1;i<=n;++i)
#define loop(i, begin, end) for (__typeof(end) i = (begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif

template<class T> void remin(T &a, T b) {a = min(a, b);}
template<class T> void remax(T &a, T b) {a = max(a, b);}
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define N 100005

ll dp[3005][3005];
str s, t;

ll solve(int i, int j) {
  if (i == s.size() || j == t.size()) rtn 0;
  if (dp[i][j] != -1) rtn dp[i][j];
  dp[i][j] = 0;
  if (s[i] == t[j]) {
    remax(dp[i][j], 1 + solve(i + 1, j + 1));
  }
  remax(dp[i][j], solve(i + 1, j));
  remax(dp[i][j], solve(i, j + 1));
  rtn dp[i][j];
}

int main() {
  FAST_IO;
  fill(dp, -1);
  cin >> s >> t;
  solve(0, 0);
  int i = 0, j = 0;
  str lc = "";
  while (i < s.size() && j < t.size()) {
    if (s[i] == t[j]) {
      lc += s[i];
      i++, j++;
    } else if (solve(i + 1, j) > solve(i, j + 1)) i++;
    else j++;
  }
  cout << lc;
  rtn 0;
}


Measured memory_bytes: 71168
n, m = list(map(int, input().split()))
lr = [list(map(int, input().split())) for i in range(m)]

maxl = max(lr[j][0] for j in range(len(lr)))
minr = min(lr[j][1] for j in range(len(lr)))
if n > minr:
    print(max(minr - maxl + 1,0))
else:
    print(max(n - maxl + 1,0))

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int r1,r2;
int main() {
	cin >> r1 >> r2;

	printf("%.10f\n",(double)r1*r2/(r1+r2));
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define nl '\n'
#define qquery int query;cin>>query;while(query--)
#define benfero freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int lcs[3005][3005];
int main(){
ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//benfero
	string s,t;
	cin >>s;
	cin >>t;
	int n=s.length(),m=t.length();
	for(int i=0;i<n+1;i++){
		for(int j=0;j<m+1;j++){
			if(i==0||j==0){
				lcs[i][j]=0;
			}
			else if(s[i-1]==t[j-1]){
				lcs[i][j]=lcs[i-1][j-1]+1;
			}
			else{
				lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
			}
		}
	}
	int neredeyiz=lcs[n][m]-1;
	char ans[lcs[n][m]+1];
	ans[neredeyiz+1]='\0';
	while(n && m && neredeyiz>-1){
		if(s[n-1]==t[m-1]){
			ans[neredeyiz]=s[n-1];
			neredeyiz--;n--;m--;
		}
		else{
			if(lcs[n-1][m]>lcs[n][m-1]){
				n--;
			}
			else{
				m--;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    //ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int a[N] = {0},b[N] = {0};
    for(int i = 0; i < N ; i++){
        cin >>a[i] >> b[i];
    }
    int ans = 0;
    for(int i = 0;i < N; i++){
        ans += b[i] - a[i] + 1;
    }
    cout << ans << endl;
}

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

const int M=100010;

struct Edge
{
	int u,v,c;
	bool operator < (const Edge &b) const {return c<b.c;}
}e[M<<1];

struct Point
{
	int x,y,id;
}a[M];

int n,tot;
long long ans;
int f[M];

bool cmp1(Point a,Point b) {return a.x<b.x;}
bool cmp2(Point a,Point b) {return a.y<b.y;}
inline int getf(int x) {return f[x]==x?x:f[x]=getf(f[x]);}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i].x>>a[i].y,a[i].id=i;
	sort(a,a+n,cmp1);
	for(int i=0;i+1<n;i++)
		e[tot++]=(Edge){a[i].id,a[i+1].id,abs(a[i].x-a[i+1].x)};
	sort(a,a+n,cmp2);
	for(int i=0;i+1<n;i++)
		e[tot++]=(Edge){a[i].id,a[i+1].id,abs(a[i].y-a[i+1].y)};
	for(int i=0;i<n;i++)
		f[i]=i;
	sort(e,e+tot);
	for(int i=0;i<tot;i++)
	{
		int u=e[i].u,v=e[i].v;
		if(getf(u)!=getf(v))
			ans+=e[i].c,f[getf(u)]=getf(v);
	}
	cout<<ans;
	return 0;
}

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

int main(){
  char a[111],b[111];
  int ans=0;
  scanf("%s%s",a,b);
  if(strlen(a)==strlen(b)){
    ans=strcmp(a,b);
  }
  else if(strlen(a)>strlen(b)){
    ans++;
  }
  else {
    ans--;
  }
  puts(ans?ans>0?"GREATER":"LESS":"EQUAL");
}

Measured memory_bytes: 128
N = int(input())
A,B = map(int,input().split())
P = input().split(' ')
P = [int(x) for x in P]

prg1 = [i for i, x in enumerate(P) if x <= A]
prg2 = [i for i, x in enumerate(P) if x >= A+1 and x <= B]
prg3 = [i for i, x in enumerate(P) if x >= B+1]

if prg1==0 or prg2==0 or prg3==0:
  result = 0
else:
  result = min([len(prg1),len(prg2),len(prg3)])
print(result)

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

int main(int argc, char *argv[]) {
	std::string word_a;
	std::string word_b;
	std::string word_c;

	std::cin >> word_a;
	std::cin >> word_b;
	std::cin >> word_c;

	bool is_siritori(false);
	is_siritori = (
		word_a[word_a.size() - 1] == word_b[0]
	 && word_b[word_b.size() - 1] == word_c[0]
	); 

	std::cout << ((is_siritori) ? "YES" : "NO") << std::endl;
	return 0;
}


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

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t;cin>>t;while(t--)
#define X first
#define Y second
#define pb push_back
#define all(s) s.begin(),s.end()

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

const int MOD = 1e9+7;

int h,w;
ll dp[1001][1001];
char mat[1001][1001];

void find(int i, int j){
    if(i==h && j==w){
        if(mat[i][j]=='#')
            dp[i][j] = 0;
        else
            dp[i][j] = 1;
        return;
    }
    if(dp[i][j]!=-1) return;

    dp[i][j] = 0;
    if(mat[i+1][j]=='.'){
        find(i+1,j);
        dp[i][j] += dp[i+1][j];
        dp[i][j] %= MOD;
    }
    if(mat[i][j+1]=='.'){
        find(i,j+1);
        dp[i][j] += dp[i][j+1];
        dp[i][j] %= MOD;    
    }
    
}


void solve(){
    cin >> h >> w;
    memset(dp,-1,sizeof(dp));

    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            cin >> mat[i][j];
    if(dp[1][1]=='#')
        dp[1][1] = 0;
    else
        find(1,1);
    cout << dp[1][1]%MOD;



}

int main(){
    FIN;   
    // test
    solve();
}

Measured memory_bytes: 9216
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

func main() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	n := scanInt()
	m := make(map[int]bool, n)
	for i := 0; i < n; i++ {
		a := scanInt()
		_, ok := m[a]
		if ok {
			fmt.Println("NO")
			return
		}

		m[a] = true
	}

	fmt.Println("YES")
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

// greatest common divisor(最大公約数)
func gcd(a, b int) int {

	if a < b {
		a, b = b, a
	}

	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    bool flag;
    for (int i=s.size()-t.size(); i>=0; --i) {
        flag = true;
        rep(j, t.size()) {
            if (s[i+j] == '?' || s[i+j] == t[j]) continue;
            else flag = false;
        }
        if (!flag) continue;
        // overwrite
        rep(j, t.size()) {
            if (s[i+j] == '?' || s[i+j] == t[j]) {
                s[i+j] = t[j];
            }
        }
        if (flag) break;
    }
    if (!flag) {puts("UNRESTORABLE"); return 0;}
    rep(i, s.size()) {
        if (s[i] == '?') s[i] = 'a';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n,w,R = map(int,input().split())
r = list(map(int,input().split()))
d = [[float("inf") for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
for i in range(R):
    r[i] -= 1
d = warshall_floyd(d)

res = float("inf")
for v in itertools.permutations(r,R):
    sumd = 0
    for j in range(1,R):
        sumd += d[v[j-1]][v[j]]
    res = min(res,sumd)
print(res)

Measured memory_bytes: 56028
x,k,d=map(int,input().split())

if x<0:
  x=-x
#print(x,k,d)

if x>=k*d:
  print(x-k*d)
else:
  kr=k-x//d
  r=x%d
  if kr%2==0:
    print(r)
  else:
    print(d-r)


Measured memory_bytes: 9164
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct T{int X,Y,P;};
T A[20];
set<pair<int,int>> S;
int N,ans[100],h[1<<20][20],w[1<<20][20];
void a(int n,int x,int y,int k){
  if(n==N){
    int cnt=0;
    for(int i=0;i<N;i++)
      cnt+=min(h[x][i],w[y][i])*A[i].P;
    ans[S.size()-2]=min(ans[S.size()-2],cnt);
    return;
  }
  int s=S.size();
  S.insert({0,A[n].X});
  a(n+1,x+k,y,k*2);
  if(s!=S.size())S.erase({0,A[n].X});
  s=S.size();
  S.insert({1,A[n].Y});
  a(n+1,x,y+k,k*2);
  if(s!=S.size())S.erase({1,A[n].Y});
  a(n+1,x,y,k*2);
}
signed main(){
  S.insert({0,0});
  S.insert({1,0});
  cin>>N;
  for(int i=0;i<N;i++)
    cin>>A[i].X>>A[i].Y>>A[i].P;
  for(int bit=0;bit<(1<<N);bit++){
    for(int i=0;i<N;i++)h[bit][i]=abs(A[i].X),w[bit][i]=abs(A[i].Y);
    bitset<20> B(bit);
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
        if(B.test(j)){
          h[bit][i]=min(h[bit][i],abs(A[i].X-A[j].X));
          w[bit][i]=min(w[bit][i],abs(A[i].Y-A[j].Y));
        }
  }
  for(int i=0;i<=N;i++)ans[i]=1000000000000000000;
  a(0,0,0,1);
  int n=1000000000000000000;
  for(int i=0;i<=N;i++){
    n=min(n,ans[i]);
    cout<<n<<endl;
  }
}

Measured memory_bytes: 13820
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()

set<int> AC;
int WA[100005];
int32_t main(){
	int n,m;
	cin>>n>>m;
	int pen=0;
	for(int i=1;i<=m;i++){
		int t; string s;
		cin>>t>>s;
		unless(AC.count(t)){
			if(s=="AC"){
				AC.insert(t);
				pen+=WA[t];
			}
			else {
				WA[t]++;
			}
		}
	}
	cout<<AC.size()<<" "<<pen;
}


Measured memory_bytes: 4992
//#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
int a,b,c;
int main()
{
	fast;
	cin>>a>>b>>c;
	if (b+c>a)
	   cout<<c-(a-b)<<endl;
    else
       cout<<0<<endl;
	return 0;
}

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

int solution(int N,int M,int n,int m){
  int ans = (N - n) * (M - m);
  return ans;
}

int main()
{
  int N = 3, M = 3, n = 2, m = 2;
  cin>>N>>M>>n>>m;
  int res = solution(N, M, n, m);
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256