akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

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

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  string s;
  int64 K;
  cin >> s >> K;
  int N = s.size();
  for (int i = 0; i < N - 1; i++) {
    if (s[i] == 'a') continue;
    int idx = s[i] - 'a';
    if (K >= 26 - idx) {
      K -= 26 - idx;
      s[i] = 'a';
    }
  }
  if (K != 0) {
    int64 tmp = (s[N - 1] - 'a' + K) % 26;
    s[N - 1] = tmp + 'a';
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3732
arr=list(map(int,input().rstrip().split()))
r=arr[0]
c=arr[1]
line=[]
for i in range(0,r):
    line.append(input())
s=[[0 for x in range(r)]for y in range(c)]
for i in range(0,r+2):
    for j in range(0,c+2):
        if i == 0 or i == r + 1 or j == 0 or j == c + 1:
            print("#",end="")
        else:
            z=line[i-1]
            print(z[j-1],end="")
    print()



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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  auto sum = accumulate(begin(a), end(a), 0LL);
  int cnt = 0;
  for (auto e : a) {
    cnt += 4 * m * e >= sum;
  }
  cout << (cnt >= m ? "Yes\n" : "No\n");
}


Measured memory_bytes: 256
fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    var list = readLine()!!.split(" ").map(String::toInt).toMutableList()

    list.sort()

    val half = list.size/2

    if(list[half-1] == list[half]){
        println(0)
    }
    else{
        println(list[half] - list[half-1])
    }
}

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

using namespace std;

template<typename T>void read(T&x){x=0;int fl=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')
fl=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}x*=fl;}
template<typename T,typename...Args>inline void read(T&t,Args&...args){read(t);read(args...);}

typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define mp(x, y) make_pair(x, y)
#define pb(x) emplace_back(x)

const int N = 200005;

int n, a, cnt[N];

int main(){
	read(n);
	for(int i = 2; i <= n; i++){
		read(a);
		cnt[a]++;
	}
	for(int i = 1; i <= n; i++)
		printf("%d\n", cnt[i]);
	return 0;
}

Measured memory_bytes: 4528
n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort(reverse = True,key = lambda x:x[0]+x[1])
ans = 0
for i in range(n):
    ans += (1-i%2)*AB[i][0] - (i%2)*AB[i][1]
print(ans)

Measured memory_bytes: 32224
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
const int MOD=1e9+7;
int main() {
  int n;
  cin >> n;
  int a[n]={},b[n]={};
  long long ans=1;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  sort(a,a+n,greater<int>());
  if(n%2==0) {
    int j=0;
    for(int i=n-1; i>=1; i-=2) {
      b[j]=b[j+1]=i;
      j+=2;
    }
  }
  else {
    int j=0;
    for(int i=n-1; i>=0; i-=2) {
      if(i==0) {
        b[j]=i;
      }
      b[j]=b[j+1]=i;
      j+=2;
    }
  }
  for(int i=0; i<n; i++) {
    if(a[i]!=b[i]) {
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i=0; i<n/2; i++) {
    ans=(ans*2)%MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

void inp_str(int*);

int main(void) {

int input1[100];
inp_str(input1);

int r,D,x;

r=input1[0];
D=input1[1];
x=input1[2];

int a;
int xx;

for(a=0;a<10;a=a+1){
	xx=r*x-D;
	printf("%d\n",xx);
	x=xx;
}


    return 0;

}


void inp_str(int instr[]){
char *ptr;
int z,i,count;
char str[100]={'\0'};
char *ln;

fgets(str, 100, stdin); // 入力："123456\n"
ln = strchr(str, '\n'); /* 改行文字を検索 */
if (ln != NULL) { /* 改行が読み取られていたかどうか */
   *ln = '\0';    /* 改行文字を終端文字に置き換える */
}
else {            /* 入力ストリーム上に文字が残ってる場合 */
   while (1) {    /* 改行文字が読み取られるまで空読みする */
       z = getchar();
      if (z == '\n' || z == EOF) break;
   }
}
	count=0;
    ptr = strtok(str, " ");
    i = atoi(ptr);
    instr[count]=i;
    count=count+1;
    // 2回目以降
    while(ptr != NULL) {
        // strtok関数により変更されたNULLのポインタが先頭
        ptr = strtok(NULL, " ");
        // ptrがNULLの場合エラーが発生するので対処
        if(ptr != NULL) {
		    i = atoi(ptr);
    instr[count]=i;
    		count=count+1;
        }
    }
}



Measured memory_bytes: 128
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

void dfs(vector<llong>& v, llong cur_d, llong d, llong x) {
  if (d == 1) {
    for (int i = -1; i <= 1; ++i) {
      llong cur = cur_d + i;
      if (cur >= 0 && cur <= 9) {
        llong xx = x + cur * d;
        v.push_back(xx);
      }
    }
  } else {
    for (int i = -1; i <= 1; ++i) {
      llong cur = cur_d + i;
      if (cur >= 0 && cur <= 9) {
        llong xx = x + cur * d;
        dfs(v, cur, d / 10, xx);
      }
    }
  }
}


void DLunlunNumber(std::istream& in, std::ostream& out) {
  int k;
  in >> k;
  vector<llong> lunlun;
  for (int i = 1; i < 10; ++i) {
    lunlun.push_back(i);
  }
  llong d = 10;
  while (lunlun.size() < 100050) {
    for (int i = 1; i <= 9; ++i) {
      dfs(lunlun, i, d / 10, d * i);
    }
    d *= 10;
  }

    out << lunlun[k - 1];
}

int main(int argc, char** argv) { DLunlunNumber(cin, cout); return 0; }


Measured memory_bytes: 3052
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>

using ll = long long int;
using P = std::pair<int, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int x[334334],y[334334],c[334334],d[334334];
P a[334334],b[334334];

int main(void){
	int h,w,m,n,i,ans;
	ll p = 0ll, q = 0ll, r = 0ll;
	std::cin >> h >> w >> m;
	for(i=0; i<h; ++i){
		a[i].second = i;
	}
	for(i=0; i<w; ++i){
		b[i].second = i;
	}
	for(i=0; i<m; ++i){
		std::cin >> x[i] >> y[i];
		--x[i]; --y[i];
		++c[x[i]]; ++d[y[i]];
		++a[x[i]].first; ++b[y[i]].first;
	}
	std::sort(a,a+h,std::greater<P>());
	std::sort(b,b+w,std::greater<P>());
	for(i=0; i<h; ++i){
		if(a[0].first == a[i].first){
			++p;
		}
	}
	for(i=0; i<w; ++i){
		if(b[0].first == b[i].first){
			++q;
		}
	}
	ans = a[0].first + b[0].first;
	for(i=0; i<m; ++i){
		if(c[x[i]]==a[0].first && d[y[i]]==b[0].first){
			++r;
		}
	}
	if(p*q<=r){
		--ans;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 12948
def s(n, d):
    a = n // d
    return a * (a + 1) // 2 * d

n = int(input())
a = n * (n + 1) // 2
fb = s(n, 15)
f = s(n, 3)
b = s(n, 5)
print(a - f - b + fb)

Measured memory_bytes: 9184
import sys
input = sys.stdin.readline

N = int(input())
a = [input()[:-1] for _ in range(N)]
row_white = [0]*N
col_white = [0]*N

for i in range(N):
    for j in range(N):
        if a[i][j]=='.':
            row_white[i] += 1

for i in range(N):
    for j in range(N):
        if a[j][i]=='.':
            col_white[i] += 1

if row_white==[N]*N:
    print(-1)
    exit()

ans = 10**18
C = 0

for i in range(N):
    if col_white[i]>0:
        C += 1

for i in range(N):
    if col_white[i]<N:
        ans = min(ans, row_white[i]+C)
    else:
        ans = min(ans, row_white[i]+1+C)

print(ans)

Measured memory_bytes: 40816
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

bool solve(){
	string s;
	cin >> s;
	int n = s.size();
	if(n < 7){ return false; }
	for(int i = 0; i < 7; ++i){
		string t = s.substr(0, i) + s.substr(n - 7 + i);
		if(t == "keyence"){ return true; }
	}
	return false;
}

void mainmain(){
	cout << (solve() ? "YES\n" : "NO\n");
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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

long gcd( long x, long y ){
 if( x<y ){
   swap(x,y);
 }
 while( y>0 ){
  int r = x%y;
  x = y;
  y = r;
 }

 return x;
}

int main(){
 long x, y;
 cin >> x >> y;

 cout << gcd(x,y) << endl;

 return 0;
}


Measured memory_bytes: 3092
var heights = [];

process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (height) {
    height.trim().split('\n').forEach(function(line){
        heights.push(parseInt(line));
    });
});

process.stdin.on('end', function () {
    heights.sort(function(a, b){
        if(a > b){
            return -1;
        } else if (a == b){
            return 0;
        } else {
            return 1;
        }
    });
    for(var i = 0; i < 3; i++ ){
        console.log(heights[i]);
    };
});

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

#define ll long long
#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d", &a, &b)
#define fto(i, a, b) for(int i = a; i <= b; ++i)
#define fdto(i, a, b) for (int i = a; i >= b; --i)
#define ff first
#define ss second
#define sz(a) (int)a.size()
#define pri(a) printf("%d ", a)
#define pril(a) printf("%d\n", a)
#define maxN 500005
#define oo 1000000007

//+=

using namespace std;

pair <int, ii> canh[maxN];
int p[maxN];
ii doc[maxN], ngang[maxN];

int findSet(int i) {
    if (p[i] == i) return i;
    return p[i] = findSet(p[i]);
}

void unionSet(int u, int v) {
    int x = findSet(u);
    int y = findSet(v);

    p[x] = y;
}

int isSameSet(int u, int v) {
    return (findSet(u) == findSet(v));
}

int main() {


    int n; sci(n);
    fto(i, 1, n) p[i] = i;
    fto(i, 1, n) {
        int x, y; scii(x, y);
        ngang[i] = mp(x, i);
        doc[i] = mp(y, i);
    }
    sort(doc+1, doc+n+1); sort(ngang+1, ngang+n+1);
    int m = 0;
    fto(i, 1, n) {
        int u = doc[i].ss;
        if (i > 1) {
            int v = doc[i-1].ss;
            int w = abs(doc[i-1].ff - doc[i].ff);
            ++m;
            canh[m].ss = mp(u, v);
            canh[m].ff = w;
        }
        if (i < n) {
            int v = doc[i+1].ss;
            int w = abs(doc[i+1].ff - doc[i].ff);
            ++m;
            canh[m].ss = mp(u, v);
            canh[m].ff = w;
        }
        u = ngang[i].ss;
        if (i > 1) {
            int v = ngang[i-1].ss;
            int w = abs(ngang[i-1].ff - ngang[i].ff);
            ++m;
            canh[m].ss = mp(u, v);
            canh[m].ff = w;
        }
        if (i < n) {
            int v = ngang[i+1].ss;
            int w = abs(ngang[i+1].ff - ngang[i].ff);
            ++m;
            canh[m].ss = mp(u, v);
            canh[m].ff = w;
        }
    }
    ll ans = 0;
    sort(canh+1, canh+m+1);
    fto(i, 1, m) {
        int u = canh[i].ss.ff;
        int v = canh[i].ss.ss;
        if (isSameSet(u, v)) continue;
        unionSet(u, v);
        ans += (ll)canh[i].ff;
    }
    cout << ans;

    return 0;
}



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

using namespace std;

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

using llong = long long;
using ld = long double;
using ii = pair<int, int>;
using ull = unsigned long long;
using pll = pair<llong, llong>;
using vi = vector<int>;


#define endl "\n"
#define fi first
#define se second
#define left LEVO
#define right PRAVO
#define time CHAS
#define all(a) (a).begin(), (a).end()
#define prev PAPEREDNIKXD
#define next NASTUPNIKXD
#define pb push_back
#define deb cout<<"CHECK\n";
#define last(a) (a)[(a).size()-1]

#define elif else if
#define cclear cout<<flush;
#define fclear fflush(stdout);
#define x_files freopen("exam.in","r",stdin);freopen("exam.out","w",stdout);
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
const llong over999 = 1e14;
const ld eps = 1e-9;
const int base = 1000*1000;
const ld Pi = acos(-1);
const llong md = 1e9+7;
const llong ya = 0;

/*.st*/

llong n, m;
int main() {
    kchay;   
    //x_files;
    
    cin >> n >> m;
    
    n--;
    m--;
    
    cout << n*m << endl;
    
    return 0;
}

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

int main(){
    int i,zero,one;
    string S;
    cin>>S;
    zero=0;
    one=0;
    for(i=0;i<S.size();i++){
        if(S[i]=='0')zero++;
        if(S[i]=='1')one++;
    }
    cout<<2*min(zero,one)<<endl;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var x int
	fmt.Scan(&x)
	if x >= 30 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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


Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y;
  cin >> x>>y;
  int sub;
  int turu=0;
  int kame=0;
  sub = 4 * x;
  kame = x;
  int ans = 0;
  if(sub == y){
    ans = 1;
  }else{
    sub = sub - y;
    if(sub%2==0){
      turu = sub/2;
     // cout << turu << endl;
      kame -= sub/2;
     // cout << kame << endl;
      ans = 1;
    }else{
      ans = 0;
    }
  }
  
  if(ans == 0 || turu*kame < 0){
  cout << "No" <<endl;
  }else if (turu + kame == x){
  cout << "Yes" << endl;
  }else{
  cout << "No" <<endl;
  }
}

Measured memory_bytes: 3632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var (N, X) = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var m = Range(0, N).Select(i => int.Parse(ReadLine())).ToArray();

        var ans = N + (X - m.Sum()) / m.Min();

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28308
#include <bits/stdc++.h>
using namespace std;
long long dp[2010][2010];
int main () {
    long long N;
    cin >> N;
    long long x;
    cin >> x;
    vector<long long> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    for (int i = 0; i < N; i++) {
        long long k = INT_MAX;
        for (int j = 0; j < N; j++) {
            if (i != 0) {
                dp[i][j] = dp[i-1][j];
            }
            else {
                dp[i][j] = x*j;
            }
            k = min(k, a[(i-j+N)%N]);
            dp[i][j] += k;
        }
    }
    long long ans = LLONG_MAX;
    for (int i = 0; i < N; i++) {
        ans = min(ans, dp[N-1][i]);
    }
    cout << ans << endl;
}

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

int main(){
    int n; scanf("%d", &n);
    int cnt = 0;
    bool flag = false;
    for (int i = 0; i < n; i++){
        int d1, d2; scanf("%d%d", &d1, &d2);
        if (d1 == d2) cnt++;
        else cnt = 0;
        if (cnt >= 3) flag = true;
    }
    puts(flag ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 3756
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int x[202020], y[202020];
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0); 
  int n, w, h;
  cin >> n >> w >> h;
  for (int i = 0; i < n; i++) {
    int xx , yy, ww;
    cin >> xx >> yy >> ww;
    x[xx + ww]--;
    x[max(0, xx - ww)]++;
    y[yy + ww]--;
    y[max(0, yy - ww)]++;
  }
  for (int i = 1; i <= w; i++) {
    x[i] += x[i - 1];
  }
  for (int i = 1; i <= h; i++) {
    y[i] += y[i - 1];
  }
  bool ok = true;
  for (int i = 0; i < w; i++) {
    if (x[i] == 0) ok = false;
  }
  for (int i = 0; i < h; i++) {
    if (!ok && y[i] == 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 4720
N = int(input())
A = list(map(int,input().split()))
A.sort()
n = A[-1]

d = n
r = -1
for a in A[:-1]:
    if n%2==0:
        t = abs(a - n//2)
        if t < d:
            d = t
            r = a
    else:
        t = min(abs(a - n//2), abs(a - (n//2+1)))
        if t < d:
            d = t
            r = a
print(n,r)

Measured memory_bytes: 19880
//
// Created by HSK on 2017. 10. 14..
//

#include <bits/stdc++.h>
using namespace std;

const int MAX_H = 51;
const int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int H, W;
char board[MAX_H][MAX_H];
int mine[MAX_H][MAX_H];

bool InRange(int y, int x) { return y >= 0 && y < H && x >= 0 && x < W; }

void solve(int y, int x) {
  if (board[y][x] == '#') {
    return;
  }

  for (int dir = 0; dir < 8; dir++) {
    int ny = y + dy[dir], nx = x + dx[dir];
    if (InRange(ny, nx) && board[ny][nx] == '#') {
      mine[y][x]++;
    }
  }
}

int main() {
  cin >> H >> W;
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      cin >> board[y][x];
      if (board[y][x] == '#') {
        mine[y][x] = '#';
      }
    }
  }

  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      solve(y, x);
    }
  }

  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (mine[y][x] == '#') {
        cout << "#";
      } else {
        cout << mine[y][x];
      }
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
#define FOr(i, a, b) for (int i=a; i<(b); i++)
#define For(i, a) for (int i=0; i<(a); i++)
#define FOrr(i,a,b) for (int i = (b)-1; i >= a; i--)
#define Forr(i,a) for (int i = (a)-1; i >= 0; i--)
/////////////////////////// ..... ///////////////////////////
#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args){
cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }
/////////////////////////// ..... ///////////////////////////
#define int ll
#define pb(x) push_back(x)
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////
const int N = 1e5+2;
int dp[N+1][3];
int a[N+1],b[N+1],c[N+1];
/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	int n ; cin >> n ;
	For(i,n)cin >> a[i] >> b[i] >> c[i];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	For(i,n){
		dp[i+1][0] = a[i+1] + max({dp[i+1][0],dp[i][1],dp[i][2]});
		dp[i+1][1] = b[i+1] + max({dp[i+1][1],dp[i][0],dp[i][2]});
		dp[i+1][2] = c[i+1] + max({dp[i+1][2],dp[i][0],dp[i][1]});
	}
	cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) <<"\n";
}

int32_t main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("TC", "r", stdin);
		//freopen("output.txt","w",stdout);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	for(int tt=1;tt<=t;tt++){
		//cout << "Case #"<<tt<<": ";
		solve();
	}
	#ifndef ONLINE_JUDGE
    	cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
    #endif
}

Measured memory_bytes: 8276
import sys
def solve():
    sys.setrecursionlimit(100000)
    input = sys.stdin.readline
    N = int(input())
    if N % 2 == 0:
        print(int(N / 2 - 1))
    else:
        print((N // 2))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int n,y,ans,ic,uc,hc;
int main(){
    cin>>n>>y;


    for(int i=0;i<n+1;i++){
        if(1000*i>y||i>n)break;
        for(int u=0;u<n+1;u++){
            if(1000*i+5000*u>y||i+u>n)break;
            for(int h=0;h<n+1;h++){
                if(1000*i+5000*u+10000*h>y||i+u+h>n)break;
                if(1000*i+5000*u+10000*h==y&&i+u+h==n){
                    ic=h;
                    uc=u;
                    hc=i;
                    ans=1;
                    break;
                }
            }if(ans)break;
        }if(ans)break;
    }

    for(int i=0;i<100000000;i++){
        int aho;
    }








    if(ans==1){
        cout<<ic<<" "<<uc<<" "<<hc<<endl;
    }else{
        cout<<"-1 -1 -1"<<endl;
    }
}


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

int main() {
  char ch;

  set < char > s;

  for(int i=0;i<4;i++)
  {
    cin >> ch;
    s.insert(ch);
  }
if(s.size()==2) cout << "Yes";
else cout << "No";

 return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

ll Q, H, S, D;
ll n;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> Q >> H >> S >> D;
    cin >> n;
    ll one = min(4 * Q, min(H * 2, S));
    ll two = min(one * 2, D);
    ll ans = n / 2 * two + (n & 1) * one;
    cout << ans << endl;
    return 0;
}


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

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

    for(int i=3; i<n+1; i++)
    {
        int x = i;
        if(i%3 == 0)
        {
            cout << ' ' << i;
            continue;
        }

        while(x != 0)
        {
            if(x%10 ==3)
            {
                cout << ' ' << i;
                break;
            }
            else x /= 10;
        }
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 	
 	int k; cin >> k;
 	string s; cin >> s;
 	if((int)s.size() <= k)
 		cout << s << '\n';
 	else
 		cout << s.substr(0, k) << "...\n";

	return 0;
}

Measured memory_bytes: 3652
#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int a[maxn];
int b[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+n);
    int cn=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
            cn++;
    }
    if(cn<=2)
    {
        printf("YES");
    }
    else printf("NO");

    return 0;
}


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    r, D, x = il()

    for n in range(10):
        x = r * x - D
        print(x)



if __name__ == '__main__':
    main()


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

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X0 = sc.nextInt();
		if (X0 == 0) {
			System.out.println(0);
			return;
		}
		long DIV = 1L << 52;
		long SHIFT = -(Long.MIN_VALUE / DIV);
		int[] c = new int[(int) (Long.MAX_VALUE / DIV + SHIFT + 1)];
		long x = X0;
		for (int i = 0; i < N; ++i) {
			c[(int) (x / DIV + SHIFT)]++;
			x ^= x << 13;
			x ^= x >>> 7;
			x ^= x << 17;
		}
		int pos = 0;
		while (true) {
			K -= c[pos];
			if (K <= 0) {
				K += c[pos];
				break;
			}
			++pos;
		}
		long[] list = new long[c[pos]];
		int ai = 0;
		x = X0;
		for (int i = 0; i < N; ++i) {
			int idx = (int) (x / DIV + SHIFT);
			if (idx == pos) list[ai++] = x;
			x ^= x << 13;
			x ^= x >>> 7;
			x ^= x << 17;
		}
		Arrays.sort(list);
		System.out.println(list[K - 1]);
	}

}

Measured memory_bytes: 21760
def resolve():
    N = int(input())
    V = list(map(int, input().split()))
    import itertools
    ans = 0
    for i in range(N-1):
        V = sorted(V, reverse=True)
        v1 = V.pop()
        v2 = V.pop()
        V.append((v1+v2)/2)
    print(V[0])
    


    
if '__main__' == __name__:
    resolve()

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

const long long INF = 1LL << 60;


long long dp[100010];

int main(void){
    int N;
    cin >> N;
    vector<int> height(N);
    for(int i=0;i<N;i++) cin >> height[i];

    for(int i=0;i<N;i++) dp[i] = INF;    

    dp[0] = 0; dp[1] = abs(height[1] - height[0]);

    for(int i=2;i<N;i++){
        dp[i] = min(dp[i],dp[i-1]+abs(height[i]-height[i-1]));
        dp[i] = min(dp[i],dp[i-2]+abs(height[i]-height[i-2]));
    }
    cout << dp[N-1] << endl;
}

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

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<char>> vec(h+2, vector<char>(w+2, '#'));
  
  for (int i = 0; i < h; i++)
  { 
    for (int j = 0; j < w; j++)
    {
      cin >> vec.at(i+1).at(j+1);
    }
    
  }

  for (int i = 0; i < h + 2; i++)
  {
    for (int j = 0; j < w + 2; j++)
    {
      cout << vec.at(i).at(j);
    }
    cout << endl;
  }
  
  
  
  	
}

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

int main(){
  int n;
  cin >> n;
  ll a[n], b[n];
  ll ans = 0, r = INF;
  rep(i,n) {
    cin >> a[i] >> b[i];
    ans += a[i];
    if(a[i] > b[i]) r = min(b[i],r);
  }
  if(r == INF) cout << 0 << endl;
  else cout << ans - r << endl;
  return 0;
}

Measured memory_bytes: 512
import collections

N = int(input())

if N == 1:
    print(1)
    exit()

x_y = []
for _ in range(N):
    x_y.append(list(map(int, input().split())))

x_y.sort(key=lambda x: (x[0], x[1]))
pq_cand = []
for i in range(N):
    for j in range(i + 1, N):
        pq_cand.append((x_y[j][0] - x_y[i][0], x_y[j][1] - x_y[i][1]))

pqc = collections.Counter(pq_cand)
_, x = max(pqc.items(), key=lambda x: x[1])
print(N - 1 - x + 1)


Measured memory_bytes: 3572
function Main(input) {
    var C = 1e+9 + 7;
    var C2 = 1e+5;
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    let N = parseInt(input[0][0], 10);
    let seven = 1;
    let eight = 2;
    let nine = 1;
    for (let i = 0; i < N; i++){
        seven = kakeruR(seven, 8, C, C2);
        eight = kakeruR(eight, 9, C, C2);
        nine = kakeruR(nine, 10, C, C2);
    }
    console.log(mod(nine + seven - eight, C));
}


function mod(i, j) {
    return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
}

function kakeruR(a, b, C, C2){
    var tmpQ, tmpR, ans;
    tmpQ = (Math.floor(b / C2));  // CAUTION!!
    tmpR = b - (tmpQ * C2);
    ans = (a * tmpQ % C) * C2 % C + (a * tmpR);
    ans %= C;
    return ans;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 33240
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
#define ar array 


void test_case() {
	ll a , b , c , d;
	cin >> a >> b >> c >> d;
	ll ans = max({a*c,a*d,b*c,b*d});
	cout<<ans;
		
	
	
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T = 1;
	//cin >> T;
	while(T--){
		test_case();
	}
}


Measured memory_bytes: 3644
n = int(input())
s = input().split()
t = [0]*n
ans = 0
anses = []

for i in range(n-1):
    
    t[i]=int((int(s[i]) >= int(s[i+1])))

for i in range(n):
    
    if t[i] == 1:    
        ans+=1
    else:
        anses.append(ans)
        ans=0
        
print(max(anses))

Measured memory_bytes: 12944
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;

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

    return 0;
}



Measured memory_bytes: 3132
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int K = input.nextInt();
		long sum = 0;
		for (int i = 1; i <= K; i++) {
			sum+=i;
		}
		for (int a = 1; a <= K; a++) {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		}
		System.out.println(sum);
	}
	public static long GCD(int a, int b, int c) {
		long max = 1;
		int min = Math.min(Math.min(a, b),c);
		for (long i = 2; i <= min; i++) {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} 
		return max;
	}
	public static boolean Prime(int n) {
		for (int i = 2; i <= Math.sqrt(n); i++) {
			if (n%i==0) return false;
		}
		return true;
	}
}

Measured memory_bytes: 27420
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    char c;
    cin >> c;
    if(c >= 'A' && c <= 'Z') cout << "A";
    else cout << "a";
    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
#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;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
bool is_prime[123456*2+10];
void prime(){
    ll p=0;
    for(int i=0;i<123456*2+10;i++) is_prime[i]=true;
    for(int i=2;i<=123456;i++){
        if(is_prime[i]){
            for(int j=2*i;j<123456*2+10;j+=i) is_prime[j]=false;
        }
    }
}
int main(){
    prime();
    while(1){
        cin>>n;
        //cout<<n<<" start"<<endl;
        if(n==0) break;
        int ans=0;
        for(int i=n+1;i<=2*n;i++){
            if(is_prime[i]) {
                //cout<<i<<" ";
                ans++;
            } 
        }
        //cout<<"ans ";
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3292
n=int(input())
A=list(map(int,input().split()))

A=[0]+A+[0]
all=0
for i in range(n+1):
  all+=abs(A[i]-A[i+1])
  
for i in range(1,n+1):
  tmp=abs(A[i]-A[i-1])+abs(A[i+1]-A[i])-abs(A[i+1]-A[i-1])
  print(all-tmp)

Measured memory_bytes: 14176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl

const ll INF=1e9+7;
const ll N = 302;
ll n,ans=0;
string s[N],sw;

bool ok(){
	sw=s[0];
	FOR(i,0,n-1){
		s[i]=s[i+1];
	}
	s[n-1]=sw;
	bool r=true;
	FOR(i,0,n){
		FOR(j,i,n){
			if(s[i][j]!=s[j][i]){
				r=false;
				return r;
			}
		}
	}
	return r;
}




int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	FOR(i,0,n){
		cin>>s[i];
	}
	FOR(i,0,n){
		if(ok())ans++;
	}
	pri(ans*n);
	return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1
{
    class ITP1_2_C
    {
        static void Main(string[] args)
        {
            string outputLine = "";

            List<int> numberList = Console.ReadLine().Split().Select(int.Parse).ToList<int>();

            numberList.Sort();            

            foreach (int item in numberList)
            {
                outputLine += (item.ToString() + " ");
            }

            Console.WriteLine(outputLine.Trim());
        }
    }
}



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

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    vector<vector<int>> mem(n+1, vector<int>(m+1, 0));
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j<= m; j++) {
            if(s[i-1] == t[j-1]) {
                mem[i][j] = mem[i-1][j-1] + 1;
            }
            else {
                mem[i][j] = max(mem[i-1][j], mem[i][j-1]);
            }
        }
    }
    // for(int i = 0; i <= n; i++) {
    //     for(int j = 0; j <= m; j++) {
    //         cout <<mem[i][j] <<" ";
    //     }
    //     cout <<endl;
    // }
    int j = m, i = n;
    string result = "";
    while(j > 0 && i > 0) {
        if(s[i-1] == t[j-1]) {
            result.push_back(s[i-1]);
            j--;
            i--;
        }
        else if(mem[i][j] == mem[i-1][j]) {
            i--;
        }
        else {
            j--;
        }
    }
    reverse(result.begin(), result.end());
    cout <<result;
    return 0;
}

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

int main(void){
    int a, b, cnt=0, tmp;
    cin >> a >> b;
    for (int i=a; i<=b; i++){
        vector<char> str;
        bool flag = true;
        tmp = i;
        while (tmp != 0){
            str.emplace_back(tmp % 10 - '0');
            tmp /= 10;
        }
        for (int i=0; i<str.size()/2; i++){
            if (str[i] != str[str.size()-1-i]) flag = false;
        }
        if (flag) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>

using namespace std;


int main() {
    int N,K;
    double T,U,V,L;
    cin >> N >> K >> T >> U >> V >> L;
    int have=0;
    double time=0;
    double next,now=0,prev=0;
    double nokori=0;
    cin >> next;
    time += (next/U);

    now = T*V + next;
    prev = next;
    for(int i= 1; i < N ; i++){
        cin >> next;
        if(next <= now){
            if(have < K){
                have++;
                time += (next - prev)/V;
                prev = next;
            }else{
                now = next +T*V;
                time +=(next - prev)/V;
                prev = next;
            }
        }else{
            for(;now<next && have>0;have--){
                now+=(T*V);
            }
            if(now >= next){
                time += (next-prev)/V;
                prev = next;
                have++;
            }else{
                time += (now - prev)/V;
                time += (next-now)/U;
                now = T*V + next;
                prev = next;
            }
        }
    }
    next = L;
    if(next <= now){
        if(have < K){
            have++;
            time +=(next - prev)/V;
            prev = next;
        }else{
            now = next +T*V;
            time +=(next - prev)/V;
            prev = next;
        }
    }else{
        for(;now<next && have>0;have--){
            now+=(T*V);
        }
        if(now >= next){
            time += (next-prev)/V;
            prev =next;
        }else{
            time += (now - prev)/V;
            time += (next-now)/U;
            now = T*V + next;
            prev = next;
        }
    }
    cout << fixed << setprecision(7) << time << endl;
    return 0;
}



Measured memory_bytes: 3260
n=int(input())
data={
	'S':[int(x) for x in range(1,14)],
	'H':[int(x) for x in range(1,14)],
	'C':[int(x) for x in range(1,14)],
	'D':[int(x) for x in range(1,14)]
	}
	

for i in range(0,n):
	s,r=input().split()
	r=int(r)
	data[s].remove(r)

for i in('S','H','C','D'):
	for v in data[i]:
		print(i,v)

Measured memory_bytes: 6724
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
     
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
     
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;
     
int find(int i, vector<int> &par)
{
  if (par[i] == i)
    return i;
  else
    return par[i] = find(par[i], par);
}
     
void merge(int i, int j, vector<int> &par, vector<int> &rank)
{
  int x = find(i,par);
  int y = find(j,par);
  if (x != y) 
    {
      if (rank[x] > rank[y]) 
    	{
    	  par[y] = x;
    	  rank[x] += rank[y];
    	}
      else 
    	{
    	  par[x] = y;
    	  rank[y] += rank[x];
    	}	  
    }
}
     
int main(void){
  int N, K, L;
  cin >> N >> K >> L;
  VI cars(N+1, 0);
  VI trains(N+1, 0);
  VI rank(N+1,1);
  REP(i,1,N+1)
    {
      cars[i] = i;
      trains[i] = i;
    }
  REP(i,1,K+1)
    {
      ll p , q;
      cin >> p >> q;
      merge(p, q, cars,rank);
    }
  REP(i,1,L+1)
    {
      ll p , q;
      cin >> p >> q;
      merge(p, q, trains,rank);
    }
  map<PI,int> pair;
  REP(i,1,N+1)
    if (pair.find(PI(find(i,cars),find(i,trains)))!=pair.end())
      pair[PI(find(i,cars),find(i,trains))]++;
    else
      pair[PI(find(i,cars),find(i,trains))] = 1;
  REP(i,1,N+1)
    cout << pair[PI(find(i,cars),find(i,trains))] << " ";
  
  cout << endl;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=200010,INF=1e9;
struct Point {
	ll x,h,v,id;
}p[MAXN];
int n,d,a;
ll c[MAXN],tmp,ans;
bool cmp (Point a,Point b) {return a.x<b.x;}
bool cmp2 (Point a,Point b) {return a.id<b.id;}
void add (int pos,ll v) {
	for (int i=pos;i<=n;i+=(i&(-i))) {c[i]+=v;}
	return;
}
ll query (int pos) {
	ll res=0;
	for (int i=pos;i;i-=(i&(-i))) {res+=c[i];}
	return res;
}
int ser (ll v) {
	if (p[n].x<=v) {return n;}
	int l=1,r=n;
	while (l<r) {
		int mid=(l+r+1)>>1;
		if (p[mid].x<=v) {l=mid;}
		else {r=mid-1;}
	}
	return l;
}
int main () {
	scanf("%d%d%d",&n,&d,&a);
	for (int i=1;i<=n;i++) {
		scanf("%d%d",&p[i].x,&p[i].h);
		p[i].id=i;
	}
	sort(p+1,p+n+1,cmp);
	p[1].v=1;
	for (int i=2;i<=n;i++) {p[i].v=p[i-1].v+(p[i].x!=p[i-1].x);}
	for (int i=1;i<=n;i++) {add(p[i].v,p[i].h),add(p[i].v+1,-p[i].h);}
	for (int i=1;i<=n;i++) {
		if ((tmp=query(p[i].v))>0) {
			ll tmp2=(tmp-1)/a+1;
			ans+=tmp2;
			int t=ser(0ll+p[i].x+d+d);
			add(1,-1ll*tmp2*a);
			add(p[t].v+1,1ll*tmp2*a);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
int main(void)

{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, c;
    cin >> n >> m >> c;
    vector<vector<int>> v(n);
    vector<int> b(m);
    rep(i, 0, m) cin >> b[i];
    rep(i, 0, n)
    {
        rep(j, 0, m)
        {
            int temp;
            cin >> temp;
            v[i].push_back(b[j] * temp);
        }
    }
    int res = 0, ans = 0;
    rep(i, 0, n)
    {
        res = c;
        rep(j, 0, m) res += v[i][j];
        if (res > 0)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author PRANJAL AGNIHOTRI
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            int max = 0;
            int gcd = 0;
            for (int i = 0; i < N; i++) {
                int a = in.nextInt();
                max = Math.max(max, a);
                gcd = findGCD(gcd, a);
            }
            if (K <= max && K % gcd == 0) {
                out.println("POSSIBLE");
            } else {
                out.println("IMPOSSIBLE");
            }
        }

        private int findGCD(int a, int b) {
            while (b > 0) {
                int t = a % b;
                a = b;
                b = t;
            }
            return a;
        }

    }
}



Measured memory_bytes: 47900
n = int(input())
MOD = int(1e9 + 7)

dp = [1, 0, 0, 0]
for _ in range(n):
    dp[3] = (dp[1] + dp[2] + 10 * dp[3]) % MOD
    dp[2] = (dp[0] + 9 * dp[2]) % MOD
    dp[1] = (dp[0] + 9 * dp[1]) % MOD
    dp[0] = (8 * dp[0]) % MOD
print(dp[3])

Measured memory_bytes: 64288