akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define INF 999999999
#define N 500000


int a[N],b[N],c=0;

void merge(int s[],int left,int mid,int right){
  int i,j,k;
  int n1,n2;
  
  n1=mid-left;
  n2=right-mid;
  
  for(i=0;i<n1;i++)a[i]=s[left+i];
  for(i=0;i<n2;i++)b[i]=s[mid+i];
  a[n1]=INF;
  b[n2]=INF;

  i=0;
  j=0;
  for(k=left;k<right;k++){
    c++;
    if(a[i]<=b[j]){
      s[k]=a[i];
      i++;
    }
    else {
      s[k]=b[j];
      j++;
    }
  }
}

void mergeSort(int s[],int left,int right){
  int mid;
  if (left+1 < right){
    mid = (left + right)/2;
    mergeSort(s, left, mid);
    mergeSort(s, mid, right);
    merge(s, left, mid, right);
  }
}

int main(){
  
  int n,i,s[N];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }

  mergeSort(s,0,n);

  for(i=0;i<n;i++){
    if(i)printf(" ");
    printf("%d",s[i]);
  }
  printf("\n%d\n",c);
  
  return 0;
}



Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N;
    cin >> N;
    
    vector<int> H(N);
    REP(i, N) cin >> H[i];
    
    int ans = 0;

    int tmp = 0;
    for(int i = N-2; i >= 0; i--) {
        if (H[i] >= H[i+1]) tmp ++;
        else {
            maxs(ans, tmp);
            tmp = 0;
        }
    }

    cout << max(ans, tmp) << endl;
    return 0;
}

Measured memory_bytes: 768
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160&lang=jp
// ????????¶????????£???????????????????????????????????°???????????£?????????
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int w, h, cnt;
int c[100][100], m[100][100];
int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int main() {
    while(scanf("%d%d",&w,&h)) {
        if (w==0&&h==0) break;
        memset(m, -1, sizeof(m)); cnt = 0;
        for (int i=0; i<h; i++) for (int j=0; j<w; j++) scanf("%d",&c[i][j]);
        for (int i=0; i<h; i++) for (int j=0; j<w; j++) {
            if (m[i][j] == -1 && c[i][j] == 1) {
                cnt++;
                queue<P> q;
                q.push(P(i,j));
                m[i][j] = 0;
                while(!q.empty()) {
                    P p = q.front(); q.pop();
                    for (int k=0; k<8; k++) {
                        int ny = p.first + dy[k];
                        int nx = p.second + dx[k];
                        if (nx >= 0 && nx < w && ny >= 0 && ny < h && m[ny][nx] == -1 && c[ny][nx] == 1) {
                            m[ny][nx] = 0;
                            q.push(P(ny,nx));
                        }
                    }
                }
            }
        }
        printf("%d\n",cnt);
    }
}

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

int main() {
  int n;
  cin >> n;
  map<int, int> list;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    list[a]++;
  }
  int ans = 0;
  for (auto i = list.begin(); i != list.end(); i++) {
    int tmp = i->first;
    int num = i->second;
    if (num < tmp) {
      ans += num;
    }
    else {
      ans += num - tmp;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define N 127
int n,m,a[N][N],f[N][N][N<<1],ans=0x3f3f3f3f;char sc[N];
int main(){
	scanf("%d%d",&n,&m);int i,j,k;
	for(i=1;i<=n;i++){scanf("%s",sc+1);for(j=1;j<=m;j++)a[i][j]=(sc[j]=='#');}
	memset(f,0x3f,sizeof(f));
	for(i=0;i<=n+m-1;i++)f[0][1][i]=f[1][0][i]=i;
	for(i=1;i<=n;i++)
	for(j=1;j<=m;j++)
	{
		for(k=0;k<=n+m-1;k++)
		{
			f[i][j][k]=min(min(f[i-1][j][k],f[i][j-1][k]),min(f[i-1][j][k+1],f[i][j-1][k+1]));
			if(k)f[i][j][k]=min(f[i][j][k],min(f[i-1][j][k-1],f[i][j-1][k-1])+1);
		}
		for(k=a[i][j]^1;k<=i+j-1;k+=2)f[i][j][k]=0x3f3f3f3f;
	}
	for(i=0;i<=n+m-1;i++)ans=min(ans,f[n][m][i]);printf("%d",ans);return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> b(m);
    REP(i, m) cin >> b[i];

    vector<int> dp(n + 1, INF);
    dp[0] = 0;
    REP1(i, n) {
        REP(j, m) {
            if (i - b[j] >= 0) {
                chmin(dp[i], dp[i - b[j]] + 1);
            }
        }
    }
    cout << dp[n] << endl;
}



Measured memory_bytes: 3268
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

const int INF=100005;

int n;
vector<int> s1,s2;

pair<pair<int,int>,pair<int,int> > calc(vector<int> &t){
    int ans1=-1,ans2=-1;
    int a1=-1,a2=-1;
    int p=0,tmp=1;
    for(int i=1;i<t.size();i++){
        if(t[i]==t[i-1]) tmp++; else{
            if(tmp>ans1){
                ans2=ans1;
                ans1=tmp;
                a2=a1;
                a1=t[i-1];
            }
            else if(tmp>ans2) ans2=tmp,a2=t[i-1];
            tmp=1;
        }
    }
    if(tmp>ans1){
        ans2=ans1;
        ans1=tmp;
        a2=a1;
        a1=t[t.size()-1];
    }
    else if(tmp>ans2) ans2=tmp,a2=t[t.size()-1];
    return make_pair(make_pair(a1,ans1),make_pair(a2,ans2));
}

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int tmp;
        scanf("%d",&tmp);
        if(i%2==0) s1.push_back(tmp); else s2.push_back(tmp);
    }
    sort(s1.begin(),s1.end());
    sort(s2.begin(),s2.end());
    pair<pair<int,int>,pair<int,int> > ans1=calc(s1),ans2=calc(s2);
    int ans;
    if(ans1.first.first!=ans2.first.first) ans=n-ans1.first.second-ans2.first.second;
    else{
        if(ans1.second.second!=-1 && ans2.second.second!=-1) ans=min(n-ans1.second.second-ans2.first.second,n-ans2.second.second-ans1.first.second);
        else if(ans1.second.second!=-1) ans=n-ans1.second.second-ans2.first.second;
        else if(ans2.second.second!=-1) ans=n-ans2.second.second-ans1.first.second;
        else ans=n/2;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 892
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int A = s.nextInt();
        int B = s.nextInt();
        int C = s.nextInt();
        int D = s.nextInt();
        
        int De=Math.min(A,B);
        int Bu=Math.min(C,D);
        
        System.out.println(De+Bu);
    }
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main()
{
	long long h, w;
	cin >> h >> w;
	if (h == 1 || w == 1) {
		cout << 1 << endl;

		return 0;
	}
	unsigned long long ans = h * w + 1;
	cout << ans / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
temp = input().rstrip().split(" ")
N = int(temp[0])
K = int(temp[1])
list = []

for i in range(N):
    list.append(int(input()))
list.sort()
#print(list)

DIF = []
for i in range(N - K + 1):
    DIF.append(abs(list[i] - list[i + K - 1]))
print(min(DIF))

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    string s;
    cin >> s;
    string trans = "";
    rep(i, s.size() - 1) {
        if (s[i] == 'B' && s[i + 1] == 'C') {
            i++;
            trans.push_back('X');
        } else {
            trans.push_back(s[i]);
        }
    }

    ll ans = 0;
    ll cnt_A = 0;
    rep(i, trans.size()) {
        if (trans[i] == 'A')
            cnt_A++;
        else if (trans[i] == 'X') {
            ans += cnt_A;
        } else {
            cnt_A = 0;
        }
    }

    out(ans);
}


Measured memory_bytes: 776
from decimal import Decimal
n,m = map(int,input().split())
A = list(map(int,input().split()))
border = float(sum(A)/(4*m))
border2 = str(border)
border3 = Decimal(border2)
ans = 0
judge = 0
for i in range(n):
  if A[i] >= border3:
    ans+=1
if ans >= m:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 9924
#include <iostream>
using namespace std;
int main() {
    int N;
    cin >>  N;
    for(int i = 1; i <= 9; i++){
        if(N % i == 0){
            if(1 <= N / i && N / i <= 9){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import kotlin.math.*
import kotlin.system.exitProcess

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() //single long

private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map{it.toLong()} // list of longs

fun main(){
    val (x, n) = readInts()
    if (n == 0){
        val empty = readLn()
        println(x)
        exitProcess(0)
    }
    val list = readInts()

    if(!list.contains(x)){
        println(x)
        exitProcess(0)
    }

    for(i in 1..100){
        if(!list.contains(x - i)){
            println(x-i)
            exitProcess(0)
        }
        else if(!list.contains(x + i)){
            println(x+i)
            exitProcess(0)
        }
    }
}


Measured memory_bytes: 36660
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define x first
#define y second
using ll = long long;
#define int ll

const int N = 64;
int n;
vector<pair<int, int>> g[N];
int b[N];

bool dfs(int v, int p, int aim, int bit) {
    if (v == aim) {
        return true;
    }
    for (auto u : g[v]) {
        if (u.x == p) {
            continue;
        }
        if (dfs(u.x, v, aim, bit)) {
            b[u.y] |= bit;
            return true;
        }
    }
    return false;
}

int dp[1 << 21];

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif // LC
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int v, u;
        cin >> v >> u;
        g[v].emplace_back(u, i);
        g[u].emplace_back(v, i);
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int v, u;
        cin >> v >> u;
        dfs(v, v, u, 1 << i);
    }
    dp[0] = 1;
    for (int i = 0; i < n - 1; ++i) {
        for (int v = (1 << m) - 1; v >= 0; --v) {
            dp[v | b[i]] += dp[v];
        }
    }
    cout << dp[(1 << m) - 1] << endl;
    return 0;
}


Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

bool comp(tuple<string, int, int> a, tuple<string, int, int> b){
    string p = get<0>(a), q = get<0>(b);
    int A = get<1>(a), B = get<1>(b);
    if(p == q) return A > B;
    return p < q;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n;
    cin>>n;
    vector<tuple<string, int, int> > a;
    f(i, n){
        string s;
        int p;
        cin>>s>>p;
        a.pb(make_tuple(s, p, i + 1));
    }
    sort(all(a), comp);
    f(i, n) {
        cout<<get<2>(a[i])<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;
ll MOD=998244353;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll N;
    cin>>N;
    map<string,ll> mp;
    for(ll i=0;i<N;i++){
        string s;cin>>s;
        mp[s]++;
    }
    ll res=0;
    for(auto p:mp){
        res++;
    }
    cout<<res<<endl;

}


Measured memory_bytes: 19180
import sys
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

input = sys.stdin.buffer.readline
int1 = lambda x: int(x) - 1

N, M = map(int, input().split())
frm, to = [], []
for _ in range(M):
    a, b = map(int1, input().split())
    frm.append(a)
    to.append(b)

matr = csr_matrix(([1] * M, (frm, to)), shape=(N, N))
p, _ = connected_components(matr)
print(p - 1)


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

#define int long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"

int fn(int a, int b)
{
	int ans = a / b;
	if (a % b)
		ans++;
	return ans;
}

int32_t main()
{
	IOS;
	int n, t, a, x, y;
	cin >> n;
	cin >> t >> a;
	//int t = T,a = A;
	n--;
	while (n--)
	{
		cin >> x >> y;
		int f = max(fn(t, x), fn(a, y));
		//cout << "f " << f << endl;
		t = f * x, a = f * y;
	}
	cout << t + a << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>

using namespace std;
void helper(int N);
int p[10005];
int main(){
    int n;
    cin >> n;
    helper(n);
    for(int N=1;N<=n;N++){
        cout << p[N] << endl;
    }

    return 0;
}



void helper(int N){
    for(int x=1;x<=58;x++){
        for(int y=x;y<=100;y++){
            if(x*x+y*y+x*y > N){break;}
            for(int z=y;z<=100;z++){
                int ns = x*x + y*y + z*z + x*y + y*z + z*x;
                if(ns >= 10005){break;}
                if(x == y && y == z){
                    p[ns] += 1;
                }else if(x == y || y == z || z == x){
                    p[ns] += 3;
                }else{
                    p[ns] += 6;
                }
            }
        }
    }
}


Measured memory_bytes: 3564
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define r_rep(i, n) for(int i = (int)n-1; i >= 0; i--)
#define ll long long int
#define pb push_back
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int a, b, c, x, y, sum = 0;
  cin >> a >> b >> c >> x >> y;
  int z = min(x, y);
  int w = max(x, y);

  if(a+b < c*2){
    sum += a*x + b*y;
  } else {    
    sum += c*2*z;
    x -= z;
    y -= z;
    int left = x*a + y*b;
    if((w-z)*c*2 < left){
      sum += (w-z)*c*2;
    } else {
      sum += left;
    }
  }
  print(sum);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000009LL
#define endl "\n"

struct COM{
  ll modpow(ll x, ll nn){
    ll res = 1;
    while(nn > 0){
      if(nn & 1) res = res * x % MOD;
      x = x * x % MOD;
      nn >>= 1;
    }
    return res;
  }
  vll fact, ifact;
  COM(ll n): fact(n+1), ifact(n+1){
    assert(n < MOD);
    fact[0] = 1LL;
    for(ll i = 1; i <= n; i++) fact[i] = fact[i-1]*i%MOD;
    ifact[n] = modpow(fact[n], MOD-2);
    for(ll i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i%MOD;
  }
  ll operator()(int n, int k){
    if(k < 0 || k > n) return 0;
    return fact[n]*ifact[k]%MOD*ifact[n-k]%MOD;
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand((unsigned)time(NULL));
  COM c(200010);
  string S;
  cin >> S;
  ll N = S.size();
  vll count(2019, 0LL);
  ll num = 0LL;
  ll keta = 1LL;
  for(int i = N-1; i >= 0; i--){
    num += keta * (S.at(i)-'0') % 2019;
    num %= 2019;
    count.at(num)++;
    keta *= 10;
    keta %= 2019;
  }
  count.at(0)++;
  ll ans = 0;
  for(int i = 0; i < 2019; i++){
    ans += c(count.at(i), 2);
  }
  cout <<ans << endl;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  string s;
  cin >> s;
  bool can = true;

  int l = 0, r = s.size() - 1;
  while (l <= r) {
    if (s[l] != s[r]) can = false;
    l++;
    r--;
  }

  l = 0;
  r = (s.size() - 1) / 2 - 1;
  while (l <= r) {
    if (s[l] != s[r]) can = false;
    l++;
    r--;
  }

  l = (s.size() + 3) / 2 - 1;
  r = s.size() - 1;
  while (l <= r) {
    if (s[l] != s[r]) can = false;
    l++;
    r--;
  }
  if (can)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();

        int T = Math.min(A,B);
        int V = Math.min(C,D);

        System.out.println((T+V));

    
    
    
    }



}

Measured memory_bytes: 23764
# AtCoder
from collections import Counter
N, M = map(int, input().split())
A = Counter(list(map(int, input().split())))

for i in range(M):
    b, c = map(int, input().split())
    A[c] += b

A = sorted(A.items(), reverse=True, key=lambda x: x[0])

ans = 0
for n, c in A:
    if N > c:
        ans += n*c
        N -= c
    else:
        ans += n*N
        print(ans)
        exit()


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

using namespace std;

typedef long long int64;
typedef pair< int64, int64 > Pi;
const int64 INF = 1LL << 60;

Pi operator-(Pi &a, Pi &b)
{
  return {a.first - b.first, a.second - b.second};
}


int64 cross(Pi a, Pi b)
{
  return (a.first * b.second - b.first * a.second);
}

vector< int64 > beet(vector< Pi > point)
{
  auto f = [](vector< Pi > st)
  {

    vector< int64 > area(st.size(), 0);
    vector< Pi > upper;
    upper.emplace_back(st[0]);
    upper.emplace_back(st[1]);
    for(int i = 2; i < st.size(); i++) {
      area[i] += area[i - 1];
      while(upper.size() >= 2) {
        int sz = (int) upper.size();
        if(cross(upper[sz - 1] - upper[sz - 2], st[i] - upper[sz - 1]) >= 0) break;
        if(upper.size() > 2) area[i] -= cross(upper[upper.size() - 2] - upper[0], upper.back() - upper[0]);
        upper.pop_back();
      }
      upper.push_back(st[i]);
      if(upper.size() > 2) area[i] += cross(upper[upper.size() - 2] - upper[0], upper.back() - upper[0]);
    }
    return (area);
  };

  vector< int64 > latte(point.size(), 0LL);
  sort(begin(point), end(point));
  auto lala = f(point);
  for(int i = 0; i < point.size(); i++) point[i].second *= -1;
  auto rara = f(point);
  for(int i = 0; i < point.size(); i++) latte[i] += lala[i];
  for(int i = 0; i < point.size(); i++) latte[i] += rara[i];
  return (latte);
}

int main()
{
  int N;
  cin >> N;
  vector< Pi > P(N);
  for(int i = 0; i < N; i++) {
    cin >> P[i].first >> P[i].second;
  }
  auto pp = beet(P);
  for(auto &p : P) p.first *= -1;
  for(auto &p : P) p.second *= -1;
  auto qq = beet(P);
  for(auto &p : P) p.first *= -1;
  for(auto &p : P) p.second *= -1;
  sort(begin(P), end(P));
  reverse(begin(qq), end(qq));
  int64 ret = min(pp.back(), qq.front());
  for(int i = 1; i < N; i++) {
    if(P[i - 1].first != P[i].first) {
      ret = min(ret, pp[i - 1] + qq[i]);
    }
  }
  cout << (ret + 1) / 2 << endl;
}

Measured memory_bytes: 14240
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        ans += a - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = [int(_) for _ in input().split()]
ans = 0

for i in range(N):
    if i != 0:
        if a[i]+a[i-1] > x:
            ans += a[i] - (x - a[i-1])
            a[i] = x - a[i-1]
    else:
        if a[i] > x:
            ans += a[i] - x
            a[i] = x

print(ans)

Measured memory_bytes: 14052
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,d,r,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> r >> d >> x;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));
	for(i=1;i<=10;i++) {
		x = r*x-d;
		cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
  return (x%y==0)? y:gcd(y,x%y);
}

int main()
{
  int X,Y;
  bool flag=true;
  cin>>X>>Y;
  if(gcd(X,Y)==Y){
    flag=false;
  }
  int ans=0,i=2;
  if(flag){
    while(ans==0){
      if(i*X%Y==0) {
        i++;
        continue;
      }
      ans=i*X;
    }
  }
  cout<<((flag)? ans:-1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("outp.txt","w",stdout);
    #endif
    string s;cin>>s;
  if(s=="ARC")
    cout<<"ABC";
  else
    cout<<"ARC";
}

    


Measured memory_bytes: 3604
# Dubious Document 2
s_d = list(str(input()))
t = list(str(input()))

def check(s, t):
    flag = True
    for j in range(len(t)):
        if s[j] == t[j] or s[j] == "?":
            continue
        else:
            flag = False
    return flag

flag = False
for i in range(len(s_d) - len(t)+1):
    flag = check(s_d[len(s_d) - i - len(t):len(s_d) - i], t)
    if flag:
        for idx, j in enumerate(range(len(s_d) - i - len(t), len(s_d)-i)):
            s_d[j] = t[idx]
        break
for i in range(len(s_d)):
    if s_d[i] == "?":
        s_d[i] = "a"
if flag:
    print("".join(s_d))
else:
    print("UNRESTORABLE")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(long long int i=0;i<n;i++)
#define lli long long int
#define ll long long 
#define dd double
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define limit 1000000000000000000
const double pi=3.14159265358;
const double pie=2*acos(0.0);
	
using namespace std;
lli power(lli a,lli b)
{
	lli res=1;
	while(b>0)
	{
		if(b%2!=0)
		{
			b--;
			res=(res%mod*a%mod)%mod;
		}
		else
		{
			a=(a%mod*a%mod)%mod;
			b/=2;
		}
	}
	return res%mod;
}
bool sortinrev(const pair<lli,lli> &a,  
               const pair<lli,lli> &b) 
{ 
       return (a.first > b.first); 
}

int main() {
	fast
	lli n,k,sum=0;
	cin>>n>>k;
	lli ar[n];
	rep(i,n)cin>>ar[i];
	sort(ar,ar+n);
	rep(i,k)sum+=ar[i];
	cout<<sum<<endl;
	
}

Measured memory_bytes: 3664
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> k;
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  ans = LINF;
  rep(i, n - k + 1) { ans = min(ans, a[i + k - 1] - a[i]); }
  Cout(ans);
  return 0;
}

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

class Main{

 public static void main(String[] args){

 Scanner scan = new Scanner(System.in);

 String S = scan.next();
 String[] split = S.split("");     
  
   
    if (split[2].equals(split[3])){
   if (split[4].equals(split[5])) {
   System.out.println("Yes");
 }
   else {
  System.out.println("No");
   }
 }
  else{ 
   System.out.println("No");
  }
 }
}

Measured memory_bytes: 23764
A,B,C,D,E = [int(input()) for _ in range(5)]
a = (10-A) % 10
b = (10-B) % 10
c = (10-C) % 10
d = (10-D) % 10
e = (10-E) % 10
if a == b == c == d == e == 0:
  print(A+B+C+D+E)
else:
  print(A+B+C+D+E+a+b+c+d+e-max(a,b,c,d,e))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<cstring>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int           long long
#define umapii        unordered_map<int,int>
#define ps(x,y)       fixed<<setprecision(y)<<x // sets precision upto required digits
#define arr(a,n)      int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define outarr(a,n)   for(int i=0;i<n;i++){cout<<a[i]<<" ";}
#define mod           1000000007
#define ff            first
#define big           1e15
#define ss            second
#define add           push_back
#define remove        pop_back
#define mapii         map<int,int>
#define large         *max_element
#define small         *min_element
#define float         double
#define pqi           priority_queue<int>
#define mpqi          priority_queue<int,vector<int>,greater<int>>
#define in(n)         int n;cin>>n;
#define w(t)          int t;cin>>t;while(t--)
#define vi            vector<int>
#define vivi          vector<vector<int>>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>pbds;

int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
#endif

    in(a); in(b); in(c); in(k);
    int sum = 0;
    int x = min(a, k);
    k -= x;
    sum += x;
    k -= min(b, k);
    int y = min(c, k);
    k -= y;
    sum -= y;
    cout << sum << endl;

}

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

int main() {
  
  string s;
  cin >> s;
  
  if(s > "2019/04/30") cout << "TBD" << endl;
  else cout << "Heisei" << endl;  
  
}


Measured memory_bytes: 256
a,b,c,x,y = map(int, input().split())

if a+b >= 2*c:
    if x <= y:
        ans = 2*c*x
        y -= x
        if 2*c <= b:
            ans += 2*c*y
        else:
            ans += b*y
    else:
        ans = 2*c*y
        x -= y
        if 2*c <= a:
            ans += 2*c*x
        else:
            ans += a*x
else:
    ans = a*x + b*y
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define F(i, x, y) for (int i = (x); i <= (y); ++i)
#define Fr(i, x, y) for (int i = (x); i < (y); ++i)
using namespace std;
typedef long long ll;

const int N = 500005;
int n, q, D, d[N], dist[N], far[N];
int main() {
	scanf ("%d%d", &n, &D);
	for (int i = 1; i <= n; ++i)
		scanf ("%d", &d[i]);
	dist[0] = D;
	for (int i = 1; i <= n; ++i) {
		if (dist[i - 1] <= d[i] / 2) dist[i] = dist[i - 1];
		else dist[i] = abs(dist[i - 1] - d[i]);
	}
	far[n + 1] = 1;
	for (int i = n; i >= 1; --i) {
		if (far[i + 1] <= d[i] / 2) far[i] = far[i + 1];
		else far[i] = d[i] + far[i + 1];
	}
	scanf ("%d", &q);
	while (q--) {
		int x;
		scanf ("%d", &x);
		puts(far[x + 1] <= dist[x - 1] ? "YES" : "NO");
	}
	return 0; 
} 

Measured memory_bytes: 9616
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[5],i,c=0,b[5],j;
for(i=0;i<3;i++)
{
cin>>a[i];
}
b[0]=a[0];
for(i=0;i<2;i++)
{
for(j=(i+1);j<3;j++)
{
if(a[i]!=a[j])
{
c++;
b[c]=a[j];
}
}
}
if(c==0)
c=1;
cout<<c<<endl;

}

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

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

  if (N < 1200){
    cout << "ABC" << endl;
  }
  else
  {
    cout << "ARC" << endl;
  }
  
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,s,e) for(ll i=(s);(s>e)?i>e:i<e;(s>e)?i--:i++)
ll mod1 = 1e9 + 7;
ll mod2 = 998244353;
ll mul(ll x,ll y){
    return (1ll* (x%mod1)*(y%mod1));
}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
//ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    //freopen("error.txt" , "w" , stderr) ;
    #endif
    ll a;
    cin>>a;
    ll b = 100;
    double p = 1.01;
    for(ll i = 1;i<=3761;i++){
        b*=p;
        if(b>=a){
            cout<<i<<endl;
            break;
        }
        
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};


int main(){
  int n,W; cin >> n >> W;
  vi value(n), weight(n); rep(i,n) cin >> value[i] >> weight[i];

  vvi dp(n+1,vi(W+1));

  rep(i,n) rep(w,W+1) {
    //i 番目の品物を選ぶ余地があるなら入れない場合と比較する
    if(w >= weight[i]) dp[i+1][w] = max(dp[i][w], dp[i][w-weight[i]] + value[i]);
    else dp[i+1][w] = dp[i][w];
  }

  cout << dp[n][W] << endl;
}



Measured memory_bytes: 6828
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n;
    cin>>n;
    V vec(n);
    rep(i,n)cin>>vec[i];
    ll res=0;
    rep(i,n){
        rep(j,n){
            rep(k,n){
                if(vec[i]==vec[j]||vec[j]==vec[k]||vec[k]==vec[i]){
                    continue;
                }
                if(vec[i]+vec[j]>vec[k]&&vec[j]+vec[k]>vec[i]&&vec[k]+vec[i]>vec[j]){
                    res++;
                }
            }
        }
    }
    cout<<res/6<<endl;
}


Measured memory_bytes: 3660
//JOI君がどう移動したらよいか貪欲に求めるのは難しい…
//全探索しよう。正確に言うと、線形探索をしよう。で、移動できなければ枝を刈ろう。
#include<iostream>
using namespace std;

int w,h;
int data[100][100];
int dy[4] = {1,0,-1,0};
int dx[4] = {0,1,0,-1};

//入った時点ではまだ割っていない
int dfs( int y, int x, int dep=0 ){
	int ret = -114514893;
	if( data[y][x] == 0 )
		return dep;
	data[y][x] = 0;
	for( int i = 0; i < 4; i++ ){
		int ny = y+dy[i];
		int nx = x+dx[i];
		if( ny < 0 || ny >= h || nx < 0 || nx >= w )
			continue;
		int tmp = data[ny][nx];
		ret = max( ret, dfs(ny,nx,dep+1) );
		data[ny][nx] = tmp;
	}
	return ret;
}

int main(){
	int i,j;
	while( cin >> w >> h ){
		if(!w)break;
		for( i = 0; i < h; i++ ){
			for( j = 0; j < w; j++ ){
				cin >> data[i][j];
			}
		}
		
		int ans = -114514810;
		for( i = 0; i < h; i++ ){
			for( j = 0; j < w; j++ ){
				int tmp = data[i][j];
				ans = max( ans, dfs( i, j, 0 ) );
				data[i][j] = tmp;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <float.h>
using namespace std;

#define N 100000

int n;
int a[N];

int cost( int aa, int i )
{
	int l = 0;
	if( i > 0 ) {
		l = a[i - 1];
	}
	int r = 0;
	if( i < n - 1 ) {
		r = a[i + 1];
	}
	if( l <= aa && aa <= r || l >= aa && aa >= r ) {
		return 0;
	}

	return min( abs(aa - l), abs(r - aa) ) * 2;
}

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

	for( int i = 0; i < n; i++ ) {
		int s = 0;
		if( i > 0 ) {
			s = a[i-1];
		}
		sum += abs( a[i] - s );
	}
	sum += abs(a[n-1]);

	for( int i = 0; i < n; i++ ) {
		ans = sum - cost( a[i], i );
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M  = sc.nextInt();

        char templateA[][] = new char[N][N];
        char templateB[][] = new char[M][M];

        for(int i=0;i<N;i++){
            String tmp = sc.next();
            for(int j=0;j<N;j++){
                templateA[i][j] = tmp.charAt(j);
            }
        }


        for(int i=0;i<M;i++){
            String tmp = sc.next();
            for(int j=0;j<M;j++){
                templateB[i][j] = tmp.charAt(j);
            }
        }

        boolean foundFlag = false;
        for(int i =0;i<=N-M&&!foundFlag;i++){
            for(int j=0;j<=N-M&&!foundFlag;j++){
                boolean same = true;
                for(int k=0;k<M&&same;k++){
                    for(int l=0;l<M&&same;l++){
                        if(templateA[i+k][j+l]!=templateB[k][l]){
                            same = false;
                        }
                    }
                }
                if(same) foundFlag = true;
            }
        }

        if (foundFlag){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }

        sc.close();
    }

}

Measured memory_bytes: 23764
N = int(input())
a = sorted([int(x) for x in input().split()])
i,ans = 0,0
while i < N:
    if a[i] > N:
        ans += N-i
        break
    c = a.count(a[i])
    if c > a[i]:
        ans += c-a[i]
    elif c < a[i]:
        ans += c
    i += c

print(ans)



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

#define N 100000

int BITs[N+1], BITt[N+1];

int sum(int i, int *bit){
	int s=0;
	
	while(i > 0){
		s += bit[i];
		i -= i & -i;
	}

	return s;
}

void add(int i, int x, int *bit, int n){
	while(i <= n){
		bit[i] += x;
		i += i & -i;
	}
}

int main(void){
	char s[N+1], t[N+1], c;
	int lens=0, lent=0;
	int q, abcd[4];
	int i, j;
	
	while((c = getchar()) != '\n'){
		s[lens++] = c;
	}
	s[lens] = '\0';
	while((c = getchar()) != '\n'){
		t[lent++] = c;
	}
	t[lent] = '\0';
	for(i=0; i<lens; i++){
		if(s[i] == 'A') add(i+1, 1, BITs, lens);
		else add (i+1, 2, BITs, lens);
	}
	for(i=0; i<lent; i++){
		if(t[i] == 'A') add(i+1, 1, BITt, lent);
		else add(i+1, 2, BITt, lent);
	}
	
	scanf("%d", &q);
	for(i=0; i<q; i++){
		for(j=0; j<4; j++){
			scanf("%d", &abcd[j]);
		}
		if((sum(abcd[1], BITs)-sum(abcd[0]-1, BITs))%3 == (sum(abcd[3], BITt)-sum(abcd[2]-1, BITt))%3)
			printf("YES\n");
		else printf("NO\n");
	}
	


	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#ifdef WIN32
#define ld "%I64d"
#else
#define ld "%lld"
#endif
using namespace std;
int n,a,b,q[300010];
int main(){
	int i,j,k,l,p;
	scanf("%d%d%d",&n,&a,&b);
	if(a > n || b > n){
		puts("-1");
		return 0;
	}
	if(a + b > n + 1){
		puts("-1");
		return 0;
	}
	if(a == 1){
		if(b != n){
			puts("-1");
			return 0;
		}
		for(i = n;i;--i) printf("%d ",i);
		return 0;
	}
	if(b == 1){
		if(a != n){
			puts("-1");
			return 0;
		}
		for(i = 1;i <= n;++i) printf("%d ",i);
		return 0;
	}
	if(a == n && b != 1){
		puts("-1");
		return 0;
	} 
	if(b == n && a != 1){
		puts("-1");
		return 0;
	} 
	if(1ll * a * b < n){
		puts("-1");
		return 0;
	}
	j = n - a + 1;
	int nw;
	for(i = 1,k = j;k <= n;++i,++k) q[i] = k;
	nw = n - a + 1;
	while(nw > b){
		p = nw - b + 1;
		//if(p == a) --p;
		if(p > a) p = a;
		for(k = j - p,l = 1;l <= p;++i,++k,++l) q[i] = k;
		j -= p;
		nw -= p - 1;
	}
	for(k = j - 1;i <= n;++i,--k) q[i] = k;
	for(i = 1;i <= n;++i) printf("%d ",q[i]);
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main(){
  int n,m; cin >> n >> m;
  char a[55][55];
  char b[55][55];
  for(int y=0;y<n;y++){
    for(int x=0;x<n;x++) cin >> a[y][x];
  }
  for(int y=0;y<m;y++){
    for(int x=0;x<m;x++) cin >> b[y][x];
  }
  
  bool ans = false;
  // Bの平行移動を考える.
  for(int dy=0;dy<n;dy++){
    for(int dx=0;dx<n;dx++){
      // BがAから出てしまう場合.
      if(dy+m-1>n-1 || dx+m-1>n-1) continue;
      
      bool match = true;
      for(int y=0;y<m;y++){
        for(int x=0;x<m;x++){
          if(a[dy+y][dx+x]!=b[y][x]) match = false;
        }
      }
      //この平行移動でAとBが一致したかどうか
      if(match) ans = true;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
import bisect
import sys
input=lambda : sys.stdin.readline().rstrip()
a,b,q=map(int,input().split())
s=sorted([int(input()) for i in range(a)])
t=sorted([int(input()) for i in range(b)])
out=[]
for i in range(q):
    ans=999999999999
    x=int(input())
    w=bisect.bisect_left(s,x)
    for j in range(2):
        if not 0<=w-j<len(s):
            continue
        z=bisect.bisect_left(t,s[w-j])
        for k in range(2):
            if not 0<=z-k<len(t):
                continue
            ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k]))
    w=bisect.bisect_left(t,x)
    for j in range(2):
        if not 0<=w-j<len(t):
            continue
        z=bisect.bisect_left(s,t[w-j])
        for k in range(2):
            if not 0<=z-k<len(s):
                continue
            ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k]))
    out.append(ans)
print(*out,sep='\n')

Measured memory_bytes: 18524
#include<bits/stdc++.h>
#define ll long long int
#define st string
#define con continue
#define br break
#define rt return 0
#define fr first
#define sec second
using namespace std;
int main(){
//ll tc; cin>>tc; while(tc--){
ll n,m,mn=INT_MAX,i,x,j,a=0,t,k,b=-1,mx=-1,cnt=0,c=0; 
 st s,str; char strn;
cin>>n; //a=n; n-=1; 
//ll ara[n+1],bra[n+1],taj[n+1];

//for(i=1;i<=n;i++) cin>>ara[i]; 
  for(i=1;i<=n;i++)
   {
     cin>>x;
    if(x%2 && i%2)a++;
   }      
              

        
     cout<<a<<endl;
    
 
    rt;
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
#define l1 long long 
int main(){
	 string s,t;
	  cin>>s>>t;
	  int n=0;
	  for(int i=0;i<s.length();i++){
	  	if(s[i]!=t[i])n++;
	  }
	  cout<<n;
}

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

typedef long long ll;
const ll MOD = 1000000007;

int main(){
  int n;
  cin >> n;
  static bool dp[100010];
  dp[0] = true;
  for(int i = 0 ; i < 100010 ; i ++){
    for(int j = 100 ; j <= 105 ; j ++){
      if(dp[i] && i+j < 100010)dp[i+j]=true;
    }
  }
  if(dp[n])puts("1");
  else puts("0");
}

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

long long ma(pair<long long,long long> x,pair<long long,long long> y){
    return max(x.first,y.first)-min(x.first,y.first)+max(x.second,y.second)-min(x.second,y.second);
}

int main(){
    int W,A,B;
    cin >> W >> A >> B;
    if(A+W<B)
    cout << B-A-W << endl;
    else if(A<=B+W)
    cout << 0 << endl;
    else
    cout << A-B-W << endl;
}

Measured memory_bytes: 256