akhauriyash/Code-Regression huggingface dataset:
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int main()
{
	int N, M;
	vector<string>data;
	while (cin >> N >> M, N || M)
	{
		data.clear();
		data.resize(N);
		for (size_t i = 0; i < N; i++)
		{
			cin >> data[i];
		}
		int nowx = 0, nowy = 0;
		while (data[nowx][nowy] != '.' && data[nowx][nowy] != 1)
		{
			switch (data[nowx][nowy])
			{
				case '>':{
						data[nowx][nowy] = 0;
						nowy++;
						break;
					}
				case '<':{
						data[nowx][nowy] = 0;
						nowy--;
						break;
					}
				case '^':{
						data[nowx][nowy] = 0;
						nowx--;
						break;
					}
				case 'v':{
						data[nowx][nowy] = 0;
						nowx++;
						break;
					}
				case 0:{
						data[nowx][nowy] = 1;
						break;
					}
				default:break;
			}
		}
		if (data[nowx][nowy] == 1) cout << "LOOP" << endl;
		else cout << nowy << " " << nowx << endl;
	}
	return 0;
}

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

using namespace std;

int main (void) {
    int X, Y;
    cin >> X >> Y;

    for ( int t = 0; t <= X; t++ ) {
        int c = X - t;
        if ( 4 * t + 2 * c == Y ) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 3636
// AOJ 1585 String in String
// 2018.5.20 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

int str(int *f, char *s)
{
	int x;
	char *p = s, c;

	*p++ = x = gc();
	while ((c = gc()) > ' ') {
		*p++ = c;
		if (c != x) x = -1;
	}
	*p = 0;
	*f = x;
	return p-s;
}

#define INF   0x10101010
#define MAX_L 100005

char text[MAX_L]; int len;
char pat[MAX_L]; int wp;
int  sa[MAX_L], rank[MAX_L<<1];

/* 接尾辞配列 */
// rank[i]～[i+k] と rank[j]～[j+k] を比較
int k; // comstruct_sa()内で設定
int compare_sa(int i, int j)
{
	if (rank[i] != rank[j]) return rank[i] < rank[j];
	return rank[i+k] < rank[j+k];
}

// for qsort()
int cmp(const void *a, const void *b)
{
	int i = *(const int *)a, j = *(const int *)b;
	
	if (rank[i] != rank[j]) return rank[i] - rank[j];
	return rank[i+k] - rank[j+k];
}

// 文字列Sの接尾辞配列saを構築。   len:　strlen(s)
int tmp[MAX_L];
void construct_sa(char *s, int *sa)
{
	int i;
	
	memset(rank, -1, sizeof(rank));
	for(i = 0; i <= len; i++) {
		sa[i] = i;
		if (i < len) rank[i] = s[i];
	}
	
	for(k = 1; k <= len; k *= 2) {
		qsort(sa, len+1, sizeof(int), cmp);
		
		tmp[sa[0]] = 0;
		for(i = 1; i <= len; i++) {
			tmp[sa[i]] = tmp[sa[i-1]] + compare_sa(sa[i-1], sa[i]);
		}
		for(i = 0; i <= len; i++) rank[i] = tmp[i];
	}
}

// 接尾辞配列を用いた文字列検索　len = strlen(s), wt = strlen(t)
int lower_bound(int l, int r, int wt, char *t)
{
	int m;
	while (l < r) {
		m = (l+r)>>1;
		if (memcmp(text+sa[m], t, wt) < 0) l = m+1; else r = m;
	}
	return l;
}

int upper_bound(int l, int r, int wt, char *t)
{
	int m;
	while (l < r) {
		m = (l+r)>>1;
		if (memcmp(text+sa[m], t, wt) <= 0) l = m+1; else r = m;
	}
	return l - (memcmp(text+sa[l], t, wt) != 0);
}

int main()
{
	int Q, l, r, ll, rr, ans;
	int xx, xp;

	len = str(&xx, text);
	if (xx < 0) construct_sa(text, sa);

	Q = in();
	while (Q--) {
		l = in(), r = in()+1, wp = str(&xp, pat);

		if (wp > r-l) goto done;
		if (wp == r-l) {
			if (memcmp(pat, text+l, wp)) goto done;
			pc('1'), pc('\n');
			continue;
		}
	
		if (xx > 0) {
			if (xp < 0 || xp != xx || wp > len) goto done;
			out(r-l+1-wp);
			continue;
		}

		rr = upper_bound(0, len, wp, pat);
		if (rr > len) goto done;

		ll = lower_bound(0, len, wp, pat);

		ans = 0;
		while (ll <= rr) {
			if (sa[ll] >= l && sa[ll] <= r-wp) ans++;
			ll++;
		}
		out(ans);
		continue;
done:	pc('0'), pc('\n');
	}
	return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
// ------------------ Debugging ------------------
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[ " << *it << " = " << a << " ] ";
    err(++it, args...);
}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}
template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}
// -----------------------------------------------

signed main(){

    fastIO

    int n, ans = 0, rcnt = 0, wcnt = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') rcnt++;
        else wcnt++;
    }

    string fin = string(rcnt, 'R');
    fin += string(wcnt, 'W');
    for (int i = 0; i < n; i++) {
        if (s[i] != fin[i]) {
            ans++;
        }
    }
    ans /= 2;
    cout << ans << endl;

    return 0;
}

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

int main(){
    int X;

    cin >> X;

    if(X >= 400 && X <= 599){
        cout << 8;
    }else if(X >= 600 && X <= 799){
        cout << 7;
    }else if(X >= 800 && X <= 999){
        cout << 6;
    }else if(X >= 1000 && X <= 1199){
        cout << 5;
    }else if(X >= 1200 && X <= 1399){
        cout << 4;
    }else if(X >= 1400 && X <= 1599){
        cout << 3;
    }else if(X >= 1600 && X <= 1799){
        cout << 2;
    }else if(X >= 1800 && X <= 1999){
        cout << 1;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int v2( int n ) {
  if ( n <= 10 ) {
	return 140 * n;
  } else {
	return 1400 + 160 * ( n - 10 );
  }
}

int v1( int n ) {
  if ( n <= 10 ) {
	return 125 * n;
  } else {
	return 1250 + v2( n - 10 );
  }
}

int solve( int n ) {
  if ( n <= 10 ) {
	return 1150;
  } else {
	return 1150 + v1( n - 10 );
  }
}

int main() {
  while( true ) {
	int n;
	cin >> n;
	if ( n == -1 ) break;
	cout << 4280 - solve( n ) << endl;
  }  
}

Measured memory_bytes: 1160
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


a = input()
n = len(a)
coutn1 = [0] * (n+1)
coutn2 = [0] * (n+1)

for i in range(n):
    if a[i] == "<":
        coutn1[i+1] = coutn1[i] + 1
for i in range(n-1, -1, -1):
    if a[i] == ">":
        coutn2[i] = coutn2[i+1] + 1

total = 0

for i in range(n+1):
    total += max(coutn1[i], coutn2[i])
print(total)


Measured memory_bytes: 29348
import copy
import heapq
N = int(input())
A = list(map(int, input().split()))

h1 = copy.deepcopy(A[:N])
x = sorted(A[N:])
h2 = x[N:]
x = x[:N]

now_w = sum(h1) - sum(x)
ans = now_w
used = []
heapq.heapify(h1)
heapq.heapify(h2)
heapq.heapify(used)

for i in range(N):
  now = A[N+i]
  heapq.heappush(h1, now)
  left = heapq.heappop(h1)
  while True:
    right_cand = heapq.heappop(h2)
    if len(used) > 0:
      x = heapq.heappop(used)
      if x == right_cand:
        continue
      else:
        heapq.heappush(used, x)
    break
      
  if right_cand >= now:
    right = right_cand
  else:
    right = now
    heapq.heappush(h2, right_cand)
    heapq.heappush(used, now)
  now_w = now_w - left + 2*now - right
  #print(ans, i, now_w, left, now, right)
  ans = max(ans, now_w)
  
print(ans)

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

int main() {
    int S, W;
    cin >> S >> W;
    if (S <= W) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}


Measured memory_bytes: 3604
#include<iostream>
using namespace std;
 
int Dice[100][6];
 
void shake(int n, char c){
  if(c == 'E'){
    swap(Dice[n][0], Dice[n][3]);
    swap(Dice[n][3], Dice[n][5]);
    swap(Dice[n][5], Dice[n][2]);
  }
  if(c == 'N'){
    swap(Dice[n][0], Dice[n][1]);
    swap(Dice[n][1], Dice[n][5]);
    swap(Dice[n][5], Dice[n][4]);
  }
  if(c == 'S'){
    swap(Dice[n][1], Dice[n][0]);
    swap(Dice[n][0], Dice[n][4]);
    swap(Dice[n][4], Dice[n][5]);
  }
  if(c == 'W'){
    swap(Dice[n][3], Dice[n][0]);
    swap(Dice[n][0], Dice[n][2]);
    swap(Dice[n][2], Dice[n][5]);
  }
}
int main(){
  int i, j, n, judge[100];
  char direction[10] = {"NNNNENNNN"};
  cin >> n;
  for(i = 0; i < 6; i++) cin >> Dice[0][i];
  for(j = 1; j < n; j++){
    for(i = 0; i < 6; i++) cin >> Dice[j][i];
    for(i = 0; i < 10; i++){
      if(Dice[0][1] == Dice[j][1]) break;
      shake(j,direction[i]);
    }
    if(Dice[0][1] != Dice[j][1] && Dice[0][4] != Dice[j][4]) judge[j] = 0;
    else{
      for(i = 0; i < 4; i++){
        if(Dice[0][0] == Dice[j][0] && Dice[0][2] == Dice[j][2] && Dice[0][3] == Dice[j][3] && Dice[0][5] == Dice[j][5]){
          judge[j] = 1;
          break;
        }
        shake(j,'E');
        if(i == 3) judge[j] = 0;
      }
    }
  }
  for(j = 1; j < n; j++){
    if(judge[j] == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1160
/*#include<stdio.h>

int checkPrime(int i)
{
     int p;
    for ( p = 2 ; p <= i - 1 ; p++ )
    {
        if ( i%p == 0 )
            return 0;
    }
    if ( p == i )
        return 1;
}
int main()
{
    int n,sum=0,count=0,rem,i;
    while(scanf("%d",&n)!= EOF){
        for(i=2;i<n-1;++i)
        {
           if(checkPrime(i)==1);
              count++;

        }
        printf("%d",count);
    }
    return 0;
}

/*#include<stdio.h>

int main()
{
   int n, i = 3, count, c;

   printf("Enter the number of prime numbers required\n");
   scanf("%d",&n);

   if ( n >= 1 )
   {
      printf("First %d prime numbers are :\n",n);
      printf("2\n");
   }

   for ( count = 2 ; count <= n ;  )
   {
      for ( c = 2 ; c <= i - 1 ; c++ )
      {
         if ( i%c == 0 )
            break;
      }
      if ( c == i )
      {
         printf("%d\n",i);
         count++;
      }
      i++;
   }

   return 0;
}
*/
/*#include<stdio.h>
#include<math.h>
int main(){

    int n;
    while(scanf("%d",&n)!=EOF){
    int num,i,count=0;
    for(num = 2;num<=n;num++){
         int flag = 1;
         int len = (int) (sqrt(num));
         //printf("%d\n",len);
         for(i=2;i<=len;i++){
             if(num%i==0){
                flag = 0;
                 break;
             }
        }
        if(flag==1)
            count++;
    }
    printf("%d\n",count);
    }

   return 0;
}

*/
#include<stdio.h>
#include<string.h>

bool mark [1000000];
 void sieve ()
 {
    int N = 1000000;
    memset (mark, true, N + 2);

    mark [0] = mark [1] = false;

    for ( int i = 4; i < N + 2; i += 2 )
        mark [i] = false;

    for ( int i = 3; i * i <= N + 2; i += 2 ) {
        if ( mark [i] == true ) {
            for ( int j = i * i; j < N + 2; j += 2 * i )
                mark [j] = false;
        }
    }
 }
int main()
{
    int n;
    sieve();
    while(scanf("%d",&n)!=EOF){
        int count = 0,i;
        for(i=2;i<=n;++i)
        {
            if(mark[i]==true)
                count++;
        }
        printf("%d\n",count);
   }
}

Measured memory_bytes: 3568
var k,s,i,j,z,ans:longint;
begin
    readln(k,s);
    for i:=0 to k do
    begin
        for j:=0 to k do
        begin
            if (s-i-j<=k)and(s-i-j>=0) then ans:=ans+1;
            if j>s then break; 
        end;
    end;
    writeln(ans);
end.


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

using namespace std;

int main()
{ 
	int a;
	cin>>a;
	int b,c;
	b=a%10;
	a=a/10;
	c=a%10;
	if(b==9||c==9){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
		
}

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

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n;
    n %= 10;
    
    if (n == 2 || n == 4|| n == 5 || n == 7 || n == 9)
        cout << "hon" << endl;
    else if (n == 0 || n == 1 || 6 == n || n == 8)
        cout << "pon" << endl;
    else 
        cout << "bon" << endl;
    return 0;
}

Measured memory_bytes: 3676
#include<stdio.h>

void trace(int A[], int N){
	int i;
	for (i=0;i<N;i++) {
		if(i>0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void insertionSort(int A[], int N) {
	int j,i,v;
	for (i=1;i<N;i++){
		v=A[i];
		j=i-1;
		while(j>=0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1]=v;
		trace(A, N);
	}
}

int main(void)
{
	int N, i;
	int A[100];
	
	scanf("%d", &N);
	for(i=0;i<N;i++) scanf("%d", &A[i]);
	
	trace(A, N);
	insertionSort(A, N);
	
	return 0;
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

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

Measured memory_bytes: 3716
'use strict';

function Main(input) {
    const str = input.split('');
    let res = 0;
    for ( let i = 0; i < Math.ceil(str.length / 2); i++) {
        if (str[i] !== str[str.length-1-i]) {
            res++;
        }
    }
    console.log(res);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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


int main() {
    string s, t;
    int i = 0, flg = 0;

    cin >> s >> t;

    for (i = 0; i < s.size(); i++)
    {
        if (t[i] == s[i])
        {
            flg = 1;
        }
        else
        {
            flg = 0;
            break;
        }

    }

    if (flg == 1) {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3620
#include <stdio.h>

int main()
{
  int amount = 700;
  char a, b, c;
  scanf("%c%c%c", &a, &b, &c);

  if (a == 'o') {
    amount += 100;
  }
  if (b == 'o') {
    amount += 100;
  }
  if (c == 'o') {
    amount += 100;
  }

  printf("%d\n", amount);

  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>

typedef struct node {
    long v;
    node *parent;
    node *left;
    node *right;
} Node;

typedef struct {
    Node *root;
} Tree;

Tree T = {NULL};

void insertTree(Node *node) {
    Node *y = NULL;
    Node *x = T.root;
    while (x != NULL) {
        y = x;
        if (node->v < x->v) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    node->parent = y;
    if (y == NULL) {
        T.root = node;
    } else if (node->v < y->v) {
        y->left = node;
    } else {
        y->right = node;
    }
}

Node * find(long v) {
    Node *x = T.root;
    while (x != NULL) {
        if (x->v == v) return x;
        else if (x->v < v) x = x->right;
        else x = x->left;
    }
    return NULL;
}

void Transplant(Node *u, Node *v) {
    if (u->parent == NULL) {
        T.root = v;
    } else if (u == u->parent->left) {
        u->parent->left = v;
    } else {
        u->parent->right = v;
    }
    if (v != NULL) {
        v->parent = u->parent;
    }
}

Node *TreeMinimum(Node *x) {
    while (x->left != NULL) {
        x = x->left;
    }
    return x;
}

void deleteNode(Node *z) {
    if (z->left == NULL) {
        Transplant(z, z->right);
    } else if (z->right == NULL) {
        Transplant(z, z->left);
    } else {
        Node *y = TreeMinimum(z->right);
        if (y->parent != z) {
            Transplant(y, y->right);
            y->right = z->right;
            y->right->parent = y;
        }
        Transplant(z, y);
        y->left = z->left;
        y->left->parent = y;
    }
}

void Preorder(Node *n) {
    if (n != NULL) {
        printf(" %ld", n->v);
        Preorder(n->left);
        Preorder(n->right);
    }
}

void Inorder(Node *n) {
    if (n != NULL) {
        Inorder(n->left);
        printf(" %ld", n->v);
        Inorder(n->right);
    }
}

int main () {
    long n;
    scanf("%ld", &n);
    char command[10];
    long value;
    for (long i=0; i<n; i++) {
        scanf(" %s %ld", command, &value);
        if (command[0] == 'i') {
            Node *node = (Node *)malloc(sizeof(Node));
            node->v = value;
            node->parent = NULL;
            node->left = NULL;
            node->right = NULL;
            insertTree(node);
        } else if (command[0] == 'f') {
            Node *found = find(value);
            if (found != NULL) printf("yes\n");
            else printf("no\n");
        } else if (command[0] == 'd') {
            Node *z = find(value);
            deleteNode(z);
        } else {
            Inorder(T.root);
            printf("\n");
            Preorder(T.root);
            printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 19792
n, m = map(int, raw_input().split())

yueshu = []
state = 0
if m % n == 0:
    print m / n
else:
    for i in range(1, int(m**0.5)+1):
        if m % i == 0:
            yueshu.insert(0, m/i)
            if i >= n:
                print m / i
                state = 1
                break
    if state == 0:
        for i in yueshu:
            if m % i == 0:
                if i >= n:
                    print m / i
                    state = 1
                    break
    if state == 0:
        print 1





Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

    ll s;
    ll x;
    cin>>s;
    if(s%1000000000==0)
        x=0;
    else x=(1000000000-s%1000000000);

    ll y=s+x;
    cout<<0<<" "<<0<<" "<<y/1000000000<<" "<<1<<" "<<x<<" "<<1000000000;
    return 0;
}


Measured memory_bytes: 256
$N=<>;
<>=~/ (.*) /,$
$`{$1}=$$1{$`}=$' for 2..$N;
@s=<>=~$"*$';
map{$d[$_]or$d[$_]=$d[$u]+$$u{$_},push@s,$_}keys%$u while$u=pop@s;
/ /,print$d[$`]+$d[$'],$/for<>

Measured memory_bytes: 125696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 200005;

int n, k;
map<int, int> cnt1, cnt2, cnt3;

ll a[MAXN], p[MAXN];

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> n >> k;

    ll ans = 0;

    REP1 (i, n) {
        if (i >= k+1) {
            cnt1[p[i-k]-(i-k)]--;
        }
        cin >> a[i];
        p[i] = p[i-1] + a[i];
        p[i] %= k;
        ans += p[i] == i;

        ans += cnt1[p[i]-i];
        ans += cnt1[p[i]-i+k];

        cnt1[p[i]-i]++;

        debug(p[i], p[i]-i);

    }


    cout << ans << endl;

    return 0;
}


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

int main(void) {
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    int out = max({a1, a2, a3}) - min({a1,a2,a3});

    cout << out << endl;

    return 0;
}

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

int a, b, c;

int main(){
	scanf("%d%d%d", &a, &b, &c);
	int i = 0;
	for ( ; i < 1000000 && !(a & 1) && !(b & 1) && !(c & 1); ++ i){
		int x = a + b >> 1, y = b + c >> 1, z = a + c >> 1;
		a = x, b = y, c = z;
	}
	return printf("%d\n", i > 900000 ? -1 : i), 0;
}

Measured memory_bytes: 256
N=list(map(int,input().split()))
data=[0]*(N[1]*2)
for n in range(N[1]*2):
    data[n]=list(map(int,input().split()))
sunuke=[0]*(N[0]+1)
sunuke[0]=1
for i in range(N[1]):
    for j in range(len(data[2*i-1])):
        sunuke[data[2*i-1][j]]+=1

ans=0
for k in range(len(sunuke)):
    if sunuke[k]==0:
        ans+=1

print(ans)

Measured memory_bytes: 9216
#include<iostream>
using namespace std;
int main() {
	long long N, x;
	cin >> N >> x;
	long long a[100001];
	for (long long i = 0; i < N; ++i) {
		cin >> a[i];
	}
	long long sum = 0;
	long long nextscore[100001];
	if (a[0] > x) {
		sum += a[0] - x;
		a[0] = x;
	}
	for (long long i = 0; i < N-1; ++i) {
		nextscore[i] = a[i] + a[i + 1];
		if (nextscore[i] > x) {
			sum += a[i] + a[i + 1] - x;
			a[i + 1] = x - a[i];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <random>
#include <string>
#include <stack>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

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

  int H, W, c[11][11], A[201][201];

  cin >> H >> W;

  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> c[i][j];
    }
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> A[i][j];
    }
  }

  for (int k = 0; k < 10; ++k) {
    for (int i = 0; i < 10; ++i) {
      for (int j = 0; j < 10; ++j) {
        c[i][j] = std::min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }

  int ans = 0;

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (A[i][j] != -1 && A[i][j] != 1) {
        ans += c[A[i][j]][1];
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int N, res;
vector<int> L;

int main() {
    cin >> N;
    for (int i=0; i<N; i++) {
        int l;
        cin >> l;
        L.push_back(l);
    }
    sort(L.begin(), L.end());
    for (int i=0; i<N-2; i++) {
        for (int j=i+1, k=j+1; j<N-1; j++) {
            for (; k<N && L[i]+L[j]>L[k]; k++);
            res += k-j-1;
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e6 + 10;

LL dp[10][12], k, num[12], cnt = 0, pos;

void dfs(int ind, int l)
{
    if (ind > pos)
        return;
    if (ind == 1)
    {
        for (int i = 1; i <= 9; i++)
        {
            if (k > dp[i][pos - ind + 1])
            {
                k -= dp[i][pos - ind + 1];
            }
            else
            {
                cout << i;
                dfs(ind + 1, i);
                break;
            }
        }
    }
    else
    {
        for (int i=l-1;i<=l+1;i++) {
            if (i<0||i>9) continue;
            if (k>dp[i][pos-ind+1]) {
                k-=dp[i][pos-ind+1];
            }
            else {
                cout<<i;
                dfs(ind+1,i);
                break;
            }
        }
    }
}

int main()
{
    /*
    dp[i][j]= dp[i-1 i i+1 ][ j-1 ]
    dp[1~9][j] sum > K
    dp[2][2]>=K
    len=2
    dp[k][1]=1
    */
    cin >> k;
    for (int i = 0; i <= 9; i++)
        dp[i][1] = 1;
    for (int j = 2; j <= 10; j++)
    {
        for (int i = 0; i <= 9; i++)
        {
            if (i == 0)
                dp[i][j] = dp[i][j - 1] + dp[i + 1][j - 1];
            else if (i == 9)
                dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
            else
                dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1] + dp[i + 1][j - 1];
            // if (j<=2)
            // cout<<"i:"<<i<<" "<<dp[i][j]<<" ";
        }
        // cout<<endl;
    }
    for (int i = 1; i <= 10; i++)
    {
        LL sum = 0;
        for (int j = 1; j <= 9; j++)
            sum += dp[j][i];
        if (k > sum)
        {
            k -= sum;
        }
        else
        {
            pos = i;
            break;
        }
    }
    dfs(1, 0);
    return 0;
}

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

#define repfrom(i, from, n) for (ll i = (from); i < (n); i++)
#define rep(i, n) repfrom(i, 0, n)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)

using namespace std;

using ll = long long;
using p  = pair<ll, ll>;
constexpr ll INF = 1LL << 62;

bool board[100][100];

void paint(ll N, bool color) {
    ll offset = color ? 50 : 0;
    rep(i, 100) repfrom(j, offset, offset + 49) if (N && i % 2 && j % 2) {
        N--;
        board[i][j] = color;
    }
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll A, B;
    cin >> A >> B;
    
    rep(i, 100) rep(j, 50) {
        board[i][j] = true;
    }
    
    paint(A - 1, true);
    paint(B - 1, false);
    
    cout << "100 100" << endl;
    rep(i, 100) {
        rep(j, 100) {
            cout << (board[i][j] ? '.' : '#');
        }
        cout << endl;
    }
    
    return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  vi a, b;
  REP(i, n + 1) { a.PB(read()); }
  REP(i, n) { b.PB(read()); }
  int ans = 0;
  REP(i, n) {
    ans += min(a[i], b[i]);
    if (a[i] < b[i]) {
      ans += min(b[i] - a[i], a[i + 1]);
      a[i + 1] -= min(b[i] - a[i], a[i + 1]);
    }
  }
  print(ans);
}


Measured memory_bytes: 2548
#include<iostream>
#include<algorithm>

using namespace std;

void print(const string &str, int s, int e){
    for(int i = s; i <= e; ++i){
        cout << str[i];
    }
    cout << endl;
}

string str, op, rep;
int main(){
    cin >> str;
    int n, s, e;
    cin >> n;
    while(n--){
        cin >> op >> s >> e;
        if(op == "print") print(str, s, e);
        else if(op == "reverse"){
            rep.assign(str,s,e - s + 1);    //将要翻转的部分取出来
            reverse(rep.begin(), rep.end()); //利用STL的函数reverse翻转字符串rep
            str.replace(s, e -s + 1, rep);  //替换原字符串要翻转的部分
        }else if(op == "replace"){
            cin >> rep;
            str.replace(s, e - s + 1, rep);
        }
    }
    return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 3e5 + 5;
const ll MOD = 998244353;
ll fac[MAX_N], inv[MAX_N];
ll power(ll x, ll n) {
    ll res = 1LL;
    x %= MOD;
    while (n) {
        if (n & 1LL) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1LL;
    }
    return res;
}
ll C(int n, int m) {
    return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
int main() {
    fac[0] = inv[0] = 1;
    for (int i = 1; i <= 3e5; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = power(fac[i], MOD - 2);
    }
    int n;
    ll a, b, k, sum = 0, x, y;
    scanf("%d%lld%lld%lld", &n, &a, &b, &k);
    for (int i = 0; i <= n; i++) {
        if ((k - i * a) % b == 0) {
            x = i, y = (k - i * a) / b;
            if (y <= n && y >= 0) {
                //printf("x = %lld, y = %lld\n", x, y);
                sum = (sum + C(n, x) * C(n, y) % MOD) % MOD;
                //
            }
        }
    }
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 4992
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

K,X = imn()

print('Yes' if K * 500 >= X else 'No')

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

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

// [debug]

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int n; string s;
  cin >> n >> s;
  int ans = 1;
  rep(i, n-1) if (s[i+1] != s[i]) ans++;
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 512
# https://atcoder.jp/contests/abc092/tasks/abc092_b


N = gets.to_i
D, X = gets.split.map(&:to_i)
As = Array.new(N) { gets.to_i }
sum = X

N.times do |i|
  sum += (D.to_f / As[i]).ceil
end

puts sum


Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<unordered_map>
#define P pair<int,int>//?¨????  ?????°
using namespace std;

vector<P>d[10000];
int k[10000];
int main() {
	int n, m; cin >> n >> m;
	int a, b, c;
	while (scanf("%d%d%d",&a,&b,&c), (a | b) || c) {
		a--; b--;
		d[a].push_back(P(b, c));
	}
	cin >> a;
	for (b = 0; b < a; b++) {
		for (int i = 0; i < m; i++)scanf("%d", &k[i]);
		for (int i = 0; i < n; i++) {
			if (i)cout << " ";
			int q = 0;
			for (P s : d[i]) {
				q += k[s.first] * s.second;
			}
			cout << q;
		}
		cout << endl;
	}
}

Measured memory_bytes: 4184
#include<stdio.h>

int is_shichigosan(long long x);

int shichigosan(long long x, long long n){
  if(x > n) return 0;
  int count = is_shichigosan(x) ? 1 : 0;
  count += shichigosan(x * 10 + 7, n);
  count += shichigosan(x * 10 + 5, n);
  count += shichigosan(x * 10 + 3, n);
  return count;
}

int is_shichigosan(long long x){
  int qi = 0;
  int wu = 0;
  int san = 0;
  while(x > 0){
    switch(x % 10){
      case 7:
        qi++;
        break;
      case 5:
        wu++;
        break;
      case 3:
        san++;
        break;
    }
    x /= 10;
  }
  
  return qi && wu && san;
}

int main(){
  long long n;
  scanf("%lld", &n);
  printf("%lld\n", shichigosan(0, n));
}

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

int main(){
	int a, b, c, ans;
	while ( cin >> a >> b ) {
		c = a + b;
		ans = 0;
		while( c > 0 ){
			c /= 10;
			ans++;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int modPow(long long a, long long n, long long p) {
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

ll comb(ll n, ll p) {
	if (p * 2 > n) p = n - p;
	if (p > n - p) p = n - p;
	ll a = 1, b = 1;
	rrep(i, p + 1) {
		a = (a * (n - i + 1)) % mod;
		b = (b * i) % mod;
	}
	return a * (modPow(b, mod - 2, mod)) % mod;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a, b;
	cin >> n >> a >> b;
	ll res1 = modPow(2, n, mod);
	ll res2 = comb(n, a);
	ll res3 = comb(n, b);
	ll ans = ((res1 - res2 - res3 - 1) % mod + mod) % mod;
	dunk(ans);
	return 0;
}


Measured memory_bytes: 256
N, H, W = map(int, (input().split(" ")))

alloy = []
for _ in range(N):
	n,m = map(int, input().split(" "))
	alloy.append([n,m])

i = 0
for x, y in alloy:
	if x>=H and y>=W:
		i += 1


print(i)

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

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

    if (C >= A && C <= B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int b[N],n,m[N];
char s[N];
vector<int>a[N];
long long ans;
int add(int x,int v)
{
	while(x<=n)
	{
		b[x]+=v;
		x+=x&(-x);
	}
}
int query(int x)
{
	int v=0;
	while(x)
	{
		v+=b[x];
		x-=x&(-x);
	}
	return v;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
		a[s[i]-'a'].push_back(i),add(i,1);
	int f=0;
	for(int i=0;i<26;i++)
		if(a[i].size()&1)
			f++;
	if(f>1)
	{
		puts("-1");
		return 0;
	}
	for(int i=0;i<26;i++)
		for(int j=0;j<a[i].size();j++)
			m[a[i][j]]=a[i][a[i].size()-j-1];
	for(int i=1;i<=n;i++)
	{
		ans+=(query(n)-query(m[i]));
		add(m[i],-1);
	}
	printf("%lld\n",ans/2);
	return 0;
}

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

typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define MAX_N 1002

const int INF = 114514810;
int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
int h, w, n;
char f[MAX_N][MAX_N];
int d[MAX_N][MAX_N] ;
vector<P> cheese(12);

bool ng(int x, int y) {
    return x<0 or x>=w or y<0 or y>=h;
}

int bfs(P start, P goal) {
    queue<P> q;
    rep(y,h) rep(x,w) d[y][x] = INF;

    q.push(start);
    d[start.second][start.first] = 0;

    while(!q.empty()) {
        P p = q.front(); q.pop();
        if(p.first == goal.first and p.second == goal.second) break;
        rep(i,4) {
            int nx = p.first+dx[i], ny = p.second+dy[i];
            if(!ng(nx,ny) and f[ny][nx] != 'X' and d[ny][nx] >= INF) {
                q.push(P(nx,ny));
                d[ny][nx] = d[p.second][p.first] + 1;
            }
        }
    }

    return d[goal.second][goal.first];
}

int main() {
    cin >> h >> w >> n;
    rep(y,h) rep(x,w) cin >> f[y][x];

    rep(y,h) rep(x,w) {
        char c = f[y][x];
        if(c == 'S') {
            cheese[0] = make_pair(x, y);
        } else if(c != '.' and c != 'X') {
            cheese[c - '0'] = make_pair(x, y);
        }
    }

    int ans = 0;
    rep(i,n) ans += bfs(cheese[i], cheese[i+1]);
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6116
package main

import "fmt"

func isOdd(x int) bool {
	return x%2 != 0
}

func main() {
	var h, w int
	fmt.Scan(&h)
	fmt.Scan(&w)

	if h == 1 || w == 1 {
		fmt.Println(1)
		return
	}

	if isOdd(w) {
		if isOdd(h) {
			fmt.Println((h / 2 * w) + (w/2 + 1))
		} else {
			fmt.Println(h / 2 * w)
		}
	} else {
		fmt.Println((w / 2) * h)
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

template<typename T, typename E> class SegmentTree {
public:
  typedef function<T (T, T)> Operator;
  typedef function<T (T, E)> Apply;

  vector<T> data;
  ll n;
  T e;
  Operator op;
  Apply apply;

  SegmentTree(ll _n, T e, Operator op, Apply apply): e(e), op(op), apply(apply) {
    for(n = 1; n < _n; n *= 2);
    data.resize(n * 2 - 1, e);
  }

  T query(ll a, ll b) { return query(a, b, 0, 0, n); }
  T query(ll a, ll b, ll k, ll l, ll r) {
    if(r <= a || b <= l) return e;
    if(a <= l && r <= b) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return op(vl, vr);
  }

  void update(ll k, E x) {
    k += n - 1;
    data[k] = apply(data[k], x);
    while(k > 0) {
      k = (k - 1) / 2;
      data[k] = op(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
};

const ll INF = 1LL << 60;

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  SegmentTree<ll, ll>::Operator op = [](ll a, ll b) { return max(a, b); };
  SegmentTree<ll, ll>::Apply apply = [](ll a, ll x) { return x; };
  SegmentTree<ll, ll> segtree(N + 1, -INF, op, apply);
  segtree.update(0, 0);

  REP(i, 0, N) {
    ll v = segtree.query(0, A[i]);
    segtree.update(A[i], v + A[i]);
  }
  cout << N * (N + 1) / 2 - segtree.query(0, N + 1) << endl;
}


Measured memory_bytes: 5760
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yarrr
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>

class STring {
public:
	void solve(std::istream& in, std::ostream& out) {
		std::string letters;
		in >> letters;
		std::vector<char> stack;
		for (char c : letters) {
			stack.push_back(c);
			while (stack.size() >= 2 && stack[stack.size() - 2] == 'S' && stack[stack.size() - 1] == 'T') {
				stack.pop_back();
				stack.pop_back();
			}
		}
		out << stack.size() << std::endl;
	}
};


int main() {
	STring solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,high,ans;
  ans=0;
  cin>>n>>k;
  for(int i=0; i<n; i++){
    cin>>high;
    if(high>=k){
      ans=ans+1;
    }
  }
  cout<<ans;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n, a, t=0, ans=0;
    cin >> n;
    REP(i,n){
        cin >> a;
        ans += (a+t)/2;
        t = (a+t)%2;
        if(!a)t=0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

from collections import defaultdict

class BIT:
    # 1-indexedに注意！
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
# 使用例
# bit = BIT(10)     # 要素数を与えてインスタンス化
# bit.add(2, 10)    # a2に10を加える
# bit.add(5, 5)     # a5に 5を加える
# print(bit.sum(3)) # a1～a3の合計を返す => 10
# print(bit.sum(6)) # a1～a6の合計を返す => 15
# bit.add(3, -6)    # a3に-6を加える
# print(bit.sum(6)) # a1～a6の合計を返す => 9
# print(bit.sum(6) - bit.sum(3))  # a4～a6の合計 => 5
# bit.add(10,7)     # a10に7を加える
# print(bit.sum(10))# a1〜a10の合計を返す => 16

bit = BIT(n)

b = sorted(a)
# print(b)

d = defaultdict(int)
for i in range(n):
    d[b[i]] = i
# print(list(d))

ans = 0
for i in range(n):
    t = a[i]
    ind = d[t] + 1
    ans += i - bit.sum(ind)
    bit.add(ind,1)

print(ans)


Measured memory_bytes: 40252
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#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 REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s,t; cin>>s>>t;
  ll n = s.size();
  VVI C;
  rep(i,26){
    VI c; C.PB(c);
  }
  rep(i,s.size()) C[s[i]-'a'].PB(i);

  bool can = true;
  rep(i,t.size()) if(C[t[i]-'a'].size()==0) can = false;
  if(!can){
    cout << -1 << endl;
    return 0;
  }

  int len[26]; CLR(len);
  int k = 0; ll rep = 0; ll idx=-1;
  while(k<t.size()){
    if(len[t[k]-'a']==C[t[k]-'a'].size()){
      cerr << "case1" << endl;
      CLR(len); rep++;
    }
    else if(idx>C[t[k]-'a'][len[t[k]-'a']]){
      cerr << "case2" << endl;
      bool flg = true;
      while(true){
        len[t[k]-'a']++;
        if(len[t[k]-'a']==C[t[k]-'a'].size()){
          flg = false; break;
        }
        if(idx<C[t[k]-'a'][len[t[k]-'a']]) break;
      }
      if(!flg){
        CLR(len); rep++;
      }
    }
    idx = C[t[k]-'a'][len[t[k]-'a']];
    len[t[k]-'a']++; k++;
    cerr << rep SP idx << endl;
  }
  ll ans = n*rep+idx+1;
  cout << ans << endl;
  return 0;
}


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

int solve(int n){
  int res = 0;

  while(n >= 10){
    int maxVal = 0;

    for(int i = 10; i <= n; i *= 10){
      maxVal = max(maxVal, (n / i) * (n % i));
    }

    n = maxVal;
    res++;
  }

  return res;
}

int main(){
  int T;
  cin >> T;

  while(T--){
    int n;
    cin >> n;
    cout << solve(n) << endl;
  }
}

Measured memory_bytes: 1160