akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define TRACE(x) cerr << #x << " = " << x << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define SZ(x) (int)(x).size()
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
template<class Num>
Num mabs(Num A){
  if(A < 0) return -A;
  return A;
}

const int N = 2e5 + 10, mod = 998244353;

inline int add(int a, int b){
  int ret = a + b;
  if(ret >= mod) ret -= mod;
  return ret;
}

inline int sub(int a, int b){
  int ret = a - b;
  if(ret < 0) ret += mod;
  return ret;
}

int n, k;
int ways[N];
int l[N], r[N];

int main(){
  scanf("%d %d", &n, &k);

  for(int i = 0; i < k; i++)
    scanf("%d %d", &l[i], &r[i]);
  
  ways[1] = 1;
  
  for(int i = 2; i <= n; i++){
    for(int j = 0; j < k; j++){
      if(i - l[j] < 1) continue;
      int lef = max(0, i - r[j]);
      int rig = max(0, i - l[j]);
      if(rig != 0){
        lef = max(lef, 1); 
        ways[i] = add(ways[i], sub(ways[rig], ways[lef - 1]));
      }
    }
    
    ways[i] = add(ways[i - 1], ways[i]);
  }
  
  
  int ans = sub(ways[n], ways[n - 1]);
  
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
int a,b;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>a>>b;
	if (a>9||b>9)
		cout<<"-1";
	else 
		cout<<a*b;
	return 0;
}

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

using namespace std;

int main()
{
	int num[110] = {0};
	int n;
	int M = 0, ct = 0;
	
	while (cin >> n){
		num[n]++;
		ct++;
		M = max(M, num[n]);
	}
	
	for (int i = 0; i < ct; i++){
		if (M == num[i]){
			cout << i << "\n";
		}
	}
	return (0);
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int t1,xx,yy,n,t,x,y;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&t,&x,&y);
		int dx=abs(x-xx),dy=abs(y-yy);
		if(t-t1<dx+dy||(t-t1)%2!=(dx+dy)%2)
		{
			printf("No\n");
			return 0;
		}
		t1=t;xx=x;yy=y;
	}
	printf("Yes\n");
	return 0;
}
		


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
 
N,M = map(int,readline().split())
from collections import defaultdict
tasks = defaultdict(list)
for i in range(N):
  a,b = map(int,readline().split())
  tasks[a].append(b)
  
import heapq as hq
q = []
ans = 0
for i in range(1, M + 1):
  newtask = tasks[i]
  for t in newtask:
    hq.heappush(q,-t)
  if q:
    ans += -hq.heappop(q)
 
print(ans)

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

#define INF (1<<29)

int W,H;
int C[5];
int S[50][50];
int D[50][50][4];
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
int dc[]={0,1,2,3};

struct state{
  int x,y,d,c;
  bool operator<(const state& s) const {
    return c > s.c;
  }
};

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


void solve(){

  priority_queue<state> q;
  for(int i=0;i<=H;i++)for(int j=0;j<=W;j++)for(int k=0;k<4;k++)D[j][i][k]=INF;
  q.push( (state){0,0,1,0} );
  D[0][0][1] = 0;
  while( !q.empty() ){
    state p = q.top(); q.pop();
    if( D[p.x][p.y][p.d] < p.c ) continue;

    //    cout << p.x << "  " << p.y << " "<<p.d << endl;
    if( S[p.x][p.y] < 4 ){
      int nd = (p.d + dc[S[p.x][p.y]])%4;
      int nx = p.x + dx[nd], ny = p.y + dy[nd];
      if( !outcheck(nx,ny) ){ 
	if( D[nx][ny][nd] > p.c ){
	  D[nx][ny][nd] = p.c;
	  q.push( (state){nx,ny,nd,p.c} );
	}
      }
    }

    for(int i=0;i<4;i++){
      int nd = (p.d + dc[i])%4;
      int nx = p.x + dx[nd], ny = p.y + dy[nd];
      if( outcheck(nx,ny) ) continue;
      //  cout << D[nx][ny][nd] << " > " << p.c + C[i]<< " " << i  <<endl;
      if( D[nx][ny][nd] > p.c + C[i] ){
	//cout <<"next " << nx << " " << ny << " " << nd << endl;
	D[nx][ny][nd] = p.c+C[i];
	q.push( (state){nx,ny,nd,p.c+C[i]} );
      }
    }
  }
  int res = INF;
  for(int i=0;i<4;i++){
    res = min( res, D[W-1][H-1][i] );
  }
  cout << res << endl;
}

int main(){
  while( cin >> W>>H && (W||H ) ){
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> S[j][i];
      }
    }
    for(int i=0;i<4;i++) 
      cin >> C[i];

    solve();
  }
}

Measured memory_bytes: 1364
import itertools

def main():
	n=int(input())
	p=list(map(int, input().split()))
	q=list(map(int, input().split()))
	
	ptr=list(itertools.permutations(list(range(1,n+1))))
	# while a==0 and b==0:
	a=0
	b=0
	if p==q:
		print('0')
	else:
		for i in range(len(ptr)):
			if p == list(ptr[i]):
				a=a+i+1
		for j in range(len(ptr)):
			if q == list(ptr[j]): 
				b=b+j+1
		print(abs(a-b))
main()

Measured memory_bytes: 8052
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <utility>
  #include <numeric>
  #include <map>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)
  
  int main(){
   int n;
   string s;
   cin >> n;
   vector<int> v(n);
   rep(i,n) cin >> v[i];
   int ans =1 << 30;
   for (int i = (-100);i <= 100;i++){
     int cost=0;
     rep(h,n){
      cost+=(v[h]-i)*(v[h]-i);
     }
     ans=min(cost,ans);
   }
   cout << ans << endl;
   
    return 0;
  }



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

using namespace std;

long long sum(long long n){
    return (n*(n+1))/2;
}

int main(){
    long long n;
    cin>>n;
    long long ans;
    ans=sum(n)-sum(n/3)*3-sum(n/5)*5+sum(n/15)*15;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
s = input().strip()
t = input().strip()

def check1(ss):
    asdf = ''
    for i in range(len(t)):
        if i >= len(ss): return False
        if ss[i] != '?' and t[i] != ss[i]: return False
    return True

def lol(ss):
    return ''.join('a' if i == '?' else i for i in ss)
asdf =[]
for i in range(len(s)):
    if check1(s[i:]):
        ss = s[:i] + t + s[i + len(t):]
        asdf += [lol(ss)]
if asdf:
    print(asdf[-1])
else:
    print('UNRESTORABLE')


Measured memory_bytes: 3064
//39
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>

using namespace std;

int main(){
  for(int n,r;cin>>n>>r,n|r;){
    vector<vector<pair<int,int> > >v;
    for(int i=0;i<n;i++){
      int x,y,xx,yy;
      cin>>x>>y>>xx>>yy;
      if(v.size()<yy){
	v.resize(yy);
      }
      for(int j=y;j<yy;j++){
	pair<int,int> p=make_pair(x,xx);
	int ix=lower_bound(v[j].begin(),v[j].end(),p)-v[j].begin();
	v[j].insert(v[j].begin()+ix,p);
	int m=xx;
	int k;
	for(k=ix+1;k<v[j].size()&&v[j][k].first<=m;k++){
	  m=max(m,v[j][k].second);
	}
	v[j][ix].second=m;
	v[j].erase(v[j].begin()+ix+1,v[j].begin()+k);
	if(ix&&v[j][ix-1].second>=v[j][ix].first){
	  v[j][ix-1].second=max(v[j][ix-1].second,v[j][ix].second);
	  v[j].erase(v[j].begin()+ix);
	}
      }
    }
    int a=0;
    for(int i=0;i<v.size();i++){
      for(int j=0;j<v[i].size();j++){
	a+=v[i][j].second-v[i][j].first;
      }
    }
    cout<<a<<endl;
    if(r==2){
      int l=0;
      bool b[2][10000]={};
      for(int i=0;i<v.size();i++){
	l+=v[i].size()*2;
	fill(b[i&1],b[(i&1)+1],false);
	for(int j=0;j<v[i].size();j++){
	  for(int k=v[i][j].first;k<v[i][j].second;k++){
	    b[i&1][k]=true;
	  }
	}
	for(int j=0;j<10000;j++){
	  l+=b[i&1][j]^b[!(i&1)][j];
	}
      }
      l+=count(b[v.size()-1&1],b[(v.size()-1&1)+1],true);
      cout<<l<<endl;
    }
  }
  return 0;
}

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

int main() {
  int N,L;
  cin >> N >> L;
  
  int sum = 0;
  for(int i = 1;i <= N;i++){
    sum += L + i - 1;
  }
  if(L >= 0){
    cout << sum - L << endl;
  }
  else if(L + N - 1 < 0){
    cout << sum - (L + N - 1) << endl;
  }
  else{
    cout << sum << endl;
  }
  
    
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int t = Integer.parseInt(bf.readLine());

	 		StringTokenizer st = new StringTokenizer(bf.readLine());
	 		int n = Integer.parseInt(st.nextToken());
	 		int m = Integer.parseInt(st.nextToken());
	 	for(int i = n;i<=m;i++){
	 		if (i%t == 0){
	 			out.println("OK");
	 			out.close();
	 		}
	 	}
	 	out.println("NG");
	 	out.close();
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25460
import sys


INF = sys.maxsize

N, K = map(int, input().split())

heights = list(map(int, input().split()))

memo = [INF] * N

memo[0] = 0

for i in range(N):
  for k in range(1, K + 1):
    if i + k < N:
      memo[i + k] = min(
        memo[i + k],
        memo[i] + abs(heights[i] - heights[i + k])
      )
  
print(memo[N - 1])


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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr ll INF = 1LL<<60;

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    vector<vector<bool> > used(h, vector<bool>(w));
    vector<vector<int> > cnt(h, vector<int>(w));
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    queue<P> que[2];
    for(int i=1;i<h-1;i++){
        for(int j=1;j<w-1;j++){
            if(s[i][j] == '.') continue;
            for(int di=-1;di<=1;di++)for(int dj=-1;dj<=1;dj++){
                int ni = i+di, nj = j+dj;
                if(s[ni][nj] == '.') cnt[i][j]++;
            }
            if(cnt[i][j] >= s[i][j]-'0'){
                que[0].push(P(i,j));
            }
        }
    }
    bool update = true;
    int t = 0;
    while(update){
        update = false;
        while(!que[0].empty()){
            auto p = que[0].front();
            que[0].pop();
            int i = p.first, j = p.second;
            if(s[i][j] == '.') continue;
            if(used[i][j]) continue;
            if(cnt[i][j] >= s[i][j]-'0'){
                que[1].push(P(i,j));
                used[i][j] = true;
                update = true;
            }
        }
        while(!que[1].empty()){
            auto p = que[1].front();
            que[1].pop();
            int i = p.first, j = p.second;
            s[i][j] = '.';
            for(int di=-1;di<=1;di++)for(int dj=-1;dj<=1;dj++){
                int ni = i+di, nj = j+dj;
                if(s[ni][nj] == '.') continue;
                if(used[ni][nj]) continue;
                cnt[ni][nj]++;
                if(cnt[ni][nj] >= s[ni][nj]-'0') que[0].push(P(ni,nj));
            }
        }
        if(update) t++;
    }
    cout << t << endl;
    return 0;
}



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  map<char,int> mp;
  set<char> st;
  rep(i,s.size()){
    st.insert(s[i]);
    mp[s[i]]++;
  }
  if(st.size() != 2){
    cout << "No" << "\n";
    return 0;
  }else{
    for(char x : st){
      if(mp[x] != 2){
        cout << "No" << "\n";
        return 0;
      }
    }
    cout << "Yes" << "\n";
  }

  return 0;
}


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

int main(){
  int n;cin >> n;
  ll ans = 0;
  int b;
  for (int a = 1; a < n; a++)
  {
    b = n / a;
    if (a * b >= n)
    {
      b--;
      if (b <= 0)
      {
        continue;
      }
      
    }
    ans += b;
    
  }
    
    
  
  cout << ans << endl;
}

Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys


def solve(N: int, l: "List[int]", r: "List[int]"):
    ans = 0
    for _l, _r in zip(l, r):
        ans += _r - _l + 1
    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    l = [int()] * (N)  # type: "List[int]"
    r = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, l, r)


if __name__ == "__main__":
    main()


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

int main()
{
	int n;
	cin >> n;
	
	char s[n];
	int west[n];
	int east[n];

	int wcount = 0, ecount = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
		if (s[i] == 'W') wcount++;
		if (s[i] == 'E') ecount++;
	}
	
	west[0] = wcount;
	east[n - 1] = ecount;
	
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'W')
		{
			wcount--;
		}
		west[i] = wcount;
	}
	
	for (int i = n - 1; i >= 0; i--)
	{
		if (s[i] == 'E')
		{
			ecount--;
		}
		east[i] = ecount;
	}
	
	int maximum = 0;
	
	for (int i = 0; i < n; i++)
	{
		maximum = max(maximum, west[i] + east[i]);
	}
	
	cout << n - maximum - 1 << endl;

	return 0;
}

Measured memory_bytes: 2944
# /usr/bin/python
# -*- coding: utf-8 -*-
import math


N = int(input())
An = list(map(int, input().split()))
MX = max(max(An),1)
Bn = [0 for _ in range(MX+2)]
for i in range(N):
  Bn[An[i]] += 1

ans = 0
for i in range(1,MX+1):
  ans = max(ans, Bn[i-1]+Bn[i]+Bn[i+1])
print(ans)

Measured memory_bytes: 56260
function Main(input) {
  input = input.split("\n");
  n = parseInt(input[0], 10);

  if(n == 25) {
    console.log("Christmas")
  } else if(n == 24) {
    console.log("Christmas Eve");
  } else if(n == 23) {
    console.log("Christmas Eve Eve");
  } else if(n == 22) {
    console.log("Christmas Eve Eve Eve");
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//みなさん天才すぎないすか

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline ll getint() {
	ll A = 0;
	if (ci - cn + 24 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}


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


	int N = getint();
	ll kazu[20] = {};
	const int mod = 1e9 + 7;
	const ll m = 1 + (1 << 20) + (1ll << 40);
	//???
	const int hatena = 2;
	rep(i, N / hatena) {
		ll a[hatena];
		rep(j, hatena) a[j] = getint();
		rep(j, 20) {
			rep(k, hatena) kazu[j] += a[k] >> j & m;
		}
	}
	rep(i, N % hatena) {
		ll a = getint();
		rep(j, 20) kazu[j] += a >> j & m;
	}

	ll kotae = 0;
	const ll m2 = (1 << 20) - 1;
	rep(j, 20) {
		ll tmp = (1ll << j) % mod;
		ll tmpk = (kazu[j] & m2);
		tmpk = tmpk * (N - tmpk) % mod;
		kotae += tmp * tmpk % mod;

		tmp = (1ll << (j + 20)) % mod;
		tmpk = (kazu[j] >> 20 & m2);
		tmpk = tmpk * (N - tmpk) % mod;
		kotae += tmp * tmpk % mod;

		tmp = (1ll << (j + 40)) % mod;
		tmpk = (kazu[j] >> 40 & m2);
		tmpk = tmpk * (N - tmpk) % mod;
		kotae += tmp * tmpk % mod;
	}

	printf("%lld", kotae% mod);

	Would you please return 0;
}

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int N,T,t[200000],ans;

main() {
    cin >> N >> T >> t[0];
    rep1(i,N-1) {
        cin >> t[i];
        if (t[i-1]+T < t[i]) ans -= t[i]-(t[i-1]+T);
    }
    ct(ans+t[N-1]+T)
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n,x;
    cin >> n >> x;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    int ans = 0;
    rep(i,n)ans = __gcd(ans,abs(a[i]-x));
    cout << ans << endl;
}

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

int main() {
int N;
cin >> N;
vector <int> all(N);
for (int i = 0;i<N;i++){
    cin >> all.at(i);
}
int wa = 0;
int big = 0 ;
for (int i = 0;i<N;i++){
    if(all.at(i) > big)
    big = all.at(i);
}
for(int i = 0;i<N;i++){
    wa += all.at(i);
}

if (big < wa - big){
    cout << "Yes" << endl;
}
else{
    cout << "No" <<endl;
}

}


Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] h = new int[N + 1];

        for(int i=0; i<N; i++){
            h[i] = sc.nextInt();
        }

        h[N] = 0;

        int ans = 0;
        int sum = 0;
        for(int i=0; i<=100; i++){
            for(int j=0; j<=N; j++){
                if(j>0 && h[j]==0 && h[j-1]!=0){
                    sum++;
                }
            }
            for(int j=0; j<=N; j++){
                if(h[j]!=0){
                    h[j]--;
                }
            }
            ans += sum;
            sum = 0;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;
const ll mod = 1000 * 1000 * 1000 + 7;

vector<ll> dp[2];
vector<int> v;

int main() {
	int n, k; cin >> n >> k; v.resize(n);
	dp[0].resize(k + 1, 0); dp[1].resize(k + 1);
	dp[0][0] = 1; for (auto &x : v) { cin >> x; }

	for (int i = 1; i <= n; i++) {
		int prev = (i ^ 1) & 1;
		partial_sum(dp[prev].begin(), dp[prev].end(), dp[prev].begin());
		for (int j = 0; j <= k; j++) {
			if (v[i - 1] >= j) { dp[i & 1][j] = dp[prev][j] % mod; continue; }
			dp[i & 1][j] = (dp[prev][j] - dp[prev][j - v[i - 1] - 1]) % mod;
		}
	}
	cout << dp[n & 1][k] << '\n';
	cin.ignore(2); return 0;
}

Measured memory_bytes: 4744
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
int s2i(string str){
  istringstream is(str);
  int n;
  is >> n;
  return n;
}
long long s2ll(string str){
  istringstream is(str);
  long long  n;
  is >> n;
  return n;
}
struct lstr{
  string str;
  string out(){
    string s;
    int c=0;
    while(str[c]=='0') c++;
    for(int i=c;i<str.size();i++) s+=str[i];
    return s;
  }
  bool operator<(const lstr& a )const{
    return (str.size()==a.str.size()) ? str.compare(a.str)<0 : str.size() < a.str.size();
  }
};
int main(){
  int i,j,k;
  int w,h;
  cin >> w >> h;
  while(w!=0){
    char ma[75][75]={{}};
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	cin >> ma[i][j]; 
	if('9'<ma[i][j]) ma[i][j]=-1;
      }
    }
    lstr val[75][75]={{}};
    lstr buf;
    lstr o;
    o.str="0";
    for(i=h-1;i>=0;i--){
      for(j=w-1;j>=0;j--){
	if(ma[i][j]!=-1){
	  int f=0;
	  if(ma[i+1][j]!=-1){
	    val[i][j].str=ma[i][j]+val[i+1][j].str;
	    f=1;
	  }
	  if(ma[i][j+1]!=-1){
	    if(f==0){
	      val[i][j].str=ma[i][j]+val[i][j+1].str;
	      f=1;
	    }else{
	      buf.str=ma[i][j]+val[i][j+1].str;
	      if(val[i][j]<buf) val[i][j].str=buf.str;
	    }	  
	  }
	  if(f==0) val[i][j].str=ma[i][j];
	  //cout << val[i][j] << endl;
	}
      }
      
    }
    
    lstr lb;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	lb.str=val[i][j].out();
	if(o<lb) o.str=lb.str;
      }
    }
    cout << o.str << endl;

    cin >> w >> h;
  }  
  return 0;
}

Measured memory_bytes: 1368
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long w = sc.nextInt();
		long h = sc.nextInt();
		long x = sc.nextInt();
		long y = sc.nextInt();
		long area = w * h;
		int multi;

		if (w/2.0 == x && h/2.0 == y ) {
			multi = 1;
		} else {
			multi = 0;
		}

		System.out.println(area / 2.0);

		System.out.println(multi);
	}

}


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

int main(){
  int n; cin >> n;
  vector<int> A(n), B(n), perm(n);
  for(int i = 0; i < n; i++){
    cin >> A[i];
  }
  for(int i = 0; i < n; i++){
    cin >> B[i];
    perm[i] = i + 1;
  }
  
  int a, b, count = 1;
  do{
    if(A == perm) a = count;
    if(B == perm) b = count;
    count++;
  }while (next_permutation(perm.begin(), perm.end()));
  cout << abs(a - b) << endl;
}


Measured memory_bytes: 256
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

kouho = set()
done = set()


def f(t):
    x, y, z = t
    if x >= X or y >= Y or z >= Z:
        return 0
    return A[x] + B[y] + C[z]


def main():
    start = (f((0, 0, 0)), (0, 0, 0))
    kouho.add(start)
    done.add(start)

    for k in range(K):
        d = max(kouho)
        kouho.remove(d)

        x, y, z = d[1]
        toadd = [(x, y, z+1), (x, y+1, z), (x+1, y, z)]
        for ta in toadd:
            t = (f(ta), ta)
            if t in done:
                continue
            kouho.add(t)
            done.add(t)

        print(d[0])


if __name__ == '__main__':
    main()


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n,k;
  cin>>n>>k;
  if(k==1)
    cout<<0<<endl;
  else
    cout<<n-k<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int m,n,k,t,o,l,r,d[90001];
int main(){
	cin>>m>>n>>k;
	vector<pair<int,int> > a(90001);
	for(int i=0;i<m;i++)
	for(int j=0;j<n;j++){
		cin>>t;
		a[t].first=i;
		a[t].second=j;
	}
	for(int i=k+1;i<=m*n;i++)
	d[i]=d[i-k]+fabs(a[i].first-a[i-k].first)+fabs(a[i].second-a[i-k].second);
	cin>>o;
	for(int i=0;i<o;i++){
		cin>>l>>r;
		if(l==r)
		cout<<0<<endl;
		else
		cout<<d[r]-d[l]<<endl;
	}
} 

Measured memory_bytes: 4284
N = gets.to_i
p = gets.split.map(&:to_i)
pSort = p.sort
i = 0
batsu = 0
while i < p.size
  batsu += 1 if p[i] != pSort[i]
  i += 1
end
if batsu == 0 || batsu == 2
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll n,cnt = 0;
    cin >> n;
    vector<ll> a(n),ans(n);
    rep0(i, n)cin >> a[i];
    for (ll i = n - 1; i > 0; i -= 2) {
        ans[cnt] = a[i];
        ++cnt;
    }
    ans[cnt] = a[0];
    ++cnt;
    if (n%  2 == 1) {
        for (ll i = 1; i < n; i += 2) {
            ans[cnt] = a[i];
            ++cnt;
        }
    }else{
        for (ll i = 2; i < n; i += 2) {
            ans[cnt] = a[i];
            ++cnt;
        }
    }
    rep0(i, n)cout << ans[i] << " ";
    return 0;
}


Measured memory_bytes: 5248
(* 重複なし順列 *)
let rec perm n ls =
  if n = 0 then [[]]
  else flatmap (fun x -> List.map (fun y -> x :: y)
                                  (perm (n - 1) (remove x ls)))
               ls
and remove x ls = List.filter (fun y -> x <> y) ls
and flatten = function
  [] -> []
| x::xs -> x @ (flatten xs)
and flatmap func ls = flatten (List.map func ls)


let t = Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c -> [a; b; c])
let c = Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c -> [a; b; c])
let b = Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c -> [a; b; c])

let bingo_list = [t; c; b; 
    [List.hd t; List.nth c 1; List.nth b 2];
    [List.nth t 2; List.nth c 1; List.hd b];

    [List.hd t; List.hd c; List.hd b];
    [List.nth t 1; List.nth c 1; List.nth b 1];
    [List.nth t 2; List.nth c 2; List.nth b 2];
    ]

let n = read_int ()

let rec read_lines_to_int_list count =
    match count with
    | 0 -> []
    | _ -> read_int () :: read_lines_to_int_list (count-1)

let value_list = read_lines_to_int_list n
let all_perms = perm 3 value_list

let rec ans lst = match lst with
     [] -> false
    | first :: rest -> if List.exists (fun x -> x = first) all_perms then true else ans rest

let () = if ans bingo_list then print_endline "Yes" else print_endline "No"


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int A[314514];
    cin >> N;
    REP(i,N){
        cin >> A[i];
    }
    int Ans=0;
    int k=1;
    int e=0;
    while(1){
        e=0;
        bool stop=false;
        REP(i,N){
            if(A[i]>0)stop=true;
            if(A[i]%2==1){
                e++;
            }
            A[i]/=2;
        }
        if(stop==false)break;
        int num=(e*(N-e))%MOD;
        num=(num*k)%MOD;
        Ans=(Ans+num)%MOD;
        //cout << Ans << endl;
        k*=2;
        k%=MOD;
    }
    cout << Ans << endl;
    return 0;
}



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

namespace ABC156
{
	class C
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			var Xn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

			var midpoint = Xn.Average();
			var upper = GetTotalDistance(Xn, Math.Floor(midpoint));
			var lower = GetTotalDistance(Xn, Math.Ceiling(midpoint));

			var result = GetEfficientPoint(upper, lower);
			Console.WriteLine(result);
		}

		private static double GetEfficientPoint(double upper, double lower)
		{
			if(upper > lower)
			{
				return lower;
			} else
			{
				return upper;
			}
		}

		private static double GetTotalDistance(int[] xn, double average)
		{
			double sum = 0;
			foreach (var x in xn)
			{
				sum += Math.Pow(x - average, 2);
			}

			return sum;
		}
	}
}


Measured memory_bytes: 13396
import sys
input = sys.stdin.buffer.readline

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)

from collections import deque
q = deque()
visit = [-1]*n
q.append(0)
visit[0] = 0
while q:
    v = q.popleft()
    for u in g[v]:
        if visit[u] == -1:
            visit[u] = visit[v]+1
            q.append(u)

ans = [0]*n
for v in range(1, n):
    for u in g[v]:
        if visit[u] == visit[v]-1:
            ans[v] = u+1
print('Yes')
for i in range(1, n):
    print(ans[i])


Measured memory_bytes: 91076
#include <iostream>

using namespace std;

int main(void){
    long long N, H, la=0, th = 0, to=0;
    cin >> N;
    for(long long i = 0; i < N; i++){
        cin >>H;
        if(la >= H) th++;
        else{
            to = max(to,th);
            th = 0;
        }
        //cout << th;
        la = H;
    }
    to = max(to, th);
    cout << to << endl;
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


//iCj = i-1Cj-1 + i-1Cj
vector<vector<ll>> dp(60,vector<ll>(60,0));

void com_init(){
    REP(i,55){
        dp[i][0] = 1;
        dp[i][i] = 1;
    }
    FOR(n,1,55){
        FOR(k,1,n){
            dp[n][k] = dp[n-1][k-1] + dp[n-1][k];
        }
    }
}

ll com(int n, int k){
    
    return dp[n][k];
}


int main() {
    com_init();
    int N,A,B; cin >> N >> A >> B;
    map<ll,int> V;

    ll v_max = 0;
    REP(i,N){
        ll v; cin >> v;
        v_max = max(v_max, v);
        V[-v]++;
    }

    int cnt = 0;
    double ans = 0.0;
    for(auto v: V){
        if(A <= cnt + v.second){
            if((-v.first) == v_max){
                cout << fixed << setprecision(6) << (double)-v.first << endl;

                ll num = 0;
                FOR(k,A,min(v.second,B)+1){
                    num += com(v.second,k);
                }
                cout << num << endl;
                return 0;
            }else{
                ans += -v.first * (A-cnt);
                cout << fixed << setprecision(6) << ans/A << endl;
                cout  << com(v.second, A-cnt) << endl;
                return 0;
            }
        } else{
            cnt += v.second;
            ans += -v.first * v.second;
        }
    }
    return 0;
}

Measured memory_bytes: 3872
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>


using namespace std;

#define ASIZE 100010

void dfs(const int& i, const int& start, const int& rootW,  const int& n, vector< pair<int,bool> > (&ad)[ASIZE], vector<bool>& visited, vector<bool>& ans) {
    if ( visited[i] ) return;
    visited[i] = true;
    ans[i] = rootW%2==0 ? ans[start] : !ans[start];

    for (auto v : ad[i] ) {
        dfs(v.first, start, rootW + v.second, n, ad, visited, ans);
    }
}

int main() {
    int n;
    cin >> n;
    vector < pair<int,bool> > ad [ASIZE];
    vector <bool> visited (ASIZE, false);
    vector <bool> ans (ASIZE, false);

    for (int i=1; i<n; i++) {
        int u,v,w;
        cin >> u >> v >> w;
        // ad[u][v] = ad[v][u] = w;
        ad[u].push_back( make_pair(v,w%2) );
        ad[v].push_back( make_pair(u,w%2) );
    }
    

    for (int i=1; i<=n; i++) {
        if ( visited[i] ) continue;
        ans[i] = true;
        dfs(i, i, 0, n, ad, visited, ans);
    }

    for (int i=1; i<=n; i++) {
        cout << ans[i] << endl;
    }
    // cout << endl;
  
}

Measured memory_bytes: 10368
N = gets.to_i

ans = []
def func(s, ans, n)
  ans.push(s.to_i) if s.to_i >= 357 && (s.chars & ['3', '5', '7']).length == 3

  [3, 5, 7].each do |i|
    v = s + i.to_s
    return if v.to_i > N

    func(v, ans, n)
  end
end

func('', ans, N)
p ans.length


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  N , x , y,ans;
  cin >> N ;  
  x = 0;
  y = 0;
  ans = 0;

 for (int i = 0; i < N; i++) {
   cin >> x >> y ;
   ans += y - x + 1;
 }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

const int INF = 1e9;

int main() {
  ios::sync_with_stdio(false);
  int k, s;
  cin >> k >> s;
  int cnt = 0;
  for (int x=0; x<=k; x++) {
    for (int y=0; y<=k; y++) {
      int z = s - x - y;
      if (z >= 0 && z <= k) {
        cnt += 1;
      } else if (z < 0) {
        break;
      }
    }
  }
  cout << cnt;

}

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

int n,k;
int D[10] = {};

bool check(int x)
{
  bool f = true;
  while (x > 0) {
    int tmp = x%10;
    for (int i = 0; i < k; i++) { if (D[i] == tmp) f = false; }
    x /= 10;
  }
  return f;
}

int main()
{
  cin >> n >> k;
  for (int i = 0; i < k; i++) cin >> D[i];

  int ans = n;
  for ( ; ; ++ans) {
    if (check(ans)) {
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }
#define INF (ll)1000000007

struct UnionFind{
    vector<int> par; // par[i]:iの親の番号
    
    UnionFind(int N) : par(N) {
        for(int i=0; i<N; i++) par[i] = i;
    }
    
    int root(int x){ // xが属する木の根
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y){ // xとyの木を併合
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
    }
    
    bool same(int x, int y){ // xとyが同じ木に属するかどうか
        return root(x) == root(y);
    }
};

int main(void){

    int N, K, L;
    cin >> N >> K >> L;
    int p[K], q[K], r[L], s[L];
    REP(i,K){cin >> p[i] >> q[i]; p[i]--; q[i]--;}
    REP(i,L){cin >> r[i] >> s[i]; r[i]--; s[i]--;}

    UnionFind bridge(N), rail(N);

    REP(i,K) bridge.unite(p[i], q[i]);
    REP(i,L) rail.unite(r[i], s[i]);

    int ar[N], br[N];
    REP(i,N){ar[i] = bridge.root(i); br[i] = rail.root(i);}

    map<pair<int, int>, int> m;
    REP(i,N){
        pair<int, int> p(ar[i], br[i]);
        if(m.find(p) != m.end()) m[p]++;
        else m[p] = 1;
    }

    REP(i,N){
        cout << m[MP(ar[i], br[i])] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 16640
N = int(input())
if N % 4 == 0 or N % 7 == 0:
    print('Yes')
    exit()
for i in range(N // 4 + 1):
    for j in range(N // 7 + 1):
        if 4 * i + 7 * j == N:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
  
signed main() {
    fast;
    int n,x,y;
    cin>>n>>x>>y;
    int disti[n]={0};
    for (int i=1;i<=n;i++)
    {
        for (int j=i+1;j<=n;j++)
        {
            int dist=min((abs(x-i)+abs(j-y)+1),j-i);
            /*if (j>=y && i<=x)
            {
                dist=(x-i)+1+(j-y);
            }
            else
            {
                dist=(j-i);
            }*/
            disti[dist]++;
        }
    }
    for (int i=1;i<n;i++)
    {
        cout<<disti[i]<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 41;
const int mod = 1e9 + 7;
#define sz(v) ((int)v.size())

int n, m, px, py;
char str[MAXN][MAXN];
int sum[MAXN][MAXN];
int dp[MAXN][MAXN][MAXN][MAXN];

bool has(int sx, int ex, int sy, int ey){
	return sx <= px && px < ex && sy <= py && py < ey;
}

int gs(int sx, int ex, int sy, int ey){
	return sum[ex][ey] - sum[sx][ey] - sum[ex][sy] + sum[sx][sy];
}

int f(int sx, int ex, int sy, int ey){
	if(ex - sx == 1 && ey - sy == 1) return 0;
	if(~dp[sx][ex][sy][ey]) return dp[sx][ex][sy][ey];
	int ret = min({
		gs(sx, px + 1, sy, py + 1),
		gs(px, ex, py, ey),
		gs(sx, px + 1, py, ey),
		gs(px, ex, sy, py + 1)});
	for(int i=sx+1; i<ex; i++){
		int x1 = has(sx, i, sy, ey) ? f(sx, i, sy, ey) : gs(sx, i, sy, ey);
		int x2 = has(i, ex, sy, ey) ? f(i, ex, sy, ey) : gs(i, ex, sy, ey);
		ret = min(ret, x1 + x2);
	}
	for(int i=sy+1; i<ey; i++){
		int x1 = has(sx, ex, sy, i) ? f(sx, ex, sy, i) : gs(sx, ex, sy, i);
		int x2 = has(sx, ex, i, ey) ? f(sx, ex, i, ey) : gs(sx, ex, i, ey);
		ret = min(ret, x1 + x2);
	}
	for(int i=sx+1; i<ex; i++){
		for(int j=sy+1; j<ey; j++){
			if(has(sx, i, sy, j)){
				ret = min(ret, f(sx, i, sy, j) + gs(i, ex, sy, j) + gs(sx, i, j, ey));
			}
			if(has(i, ex, sy, j)){
				ret = min(ret, f(i, ex, sy, j) + gs(i, ex, j, ey) + gs(sx, i, sy, j));
			}
			if(has(sx, i, j, ey)){
				ret = min(ret, f(sx, i, j, ey) + gs(sx, i, sy, j) + gs(i, ex, j, ey));
			}
			if(has(i, ex, j, ey)){
				ret = min(ret, f(i, ex, j, ey) + gs(sx, i, j, ey) + gs(i, ex, sy, j));
			}
		}
	}
	return dp[sx][ex][sy][ey] = ret;
}

int main(){
	cin >> n >> m;
	for(int i=0; i<n; i++){
		cin >> str[i];
		for(int j=0; j<m; j++){
			if(str[i][j] == 'P'){
				px = i;
				py = j;
			}
			if(str[i][j] == '#') sum[i+1][j+1]++;
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
		}
	}
	memset(dp, -1, sizeof(dp));
	cout << f(0, n, 0, m) << endl;
}


Measured memory_bytes: 11392
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P 1000000007LL
const ll P2 = P*P;
#define MAXN 200010
 
ll mod(ll &a){
	return ((a >= P) ? (a % P) : (a));
}
 
struct state {
	ll c0, c1, c2;
	state(){
		c0 = 1, c1 = 1, c2 = 0;
	}
 
	struct state& operator += (const state &a){
		c2 = (a.c1 + a.c2) *(c1 + c2) + a.c0*c2 + c0*a.c2;
		c1 = a.c1*c0 + a.c0*c1;
		c0 = a.c0*c0;
 
		c0 = mod(c0);
		c1 = mod(c1);
		c2 = mod(c2);
	}
};
 
vector<state> ans[MAXN];
int id[MAXN];
 
int level[MAXN];
int cnt[MAXN];
 
int p[MAXN];
vector<int> gr[MAXN];
 
void dfs(int u){
	if(gr[u].size() == 0){
		id[u] = u;
		ans[u].push_back(state());
		return;
	}
 
	int ma = -1;
	int me = 0;
	int i_ma = 0;
	for(auto &v : gr[u]){
		level[v] = level[u]+1;
		cnt[level[v]]++;
		dfs(v);
		if((int)ans[id[v]].size() > ma){
			ma = ans[id[v]].size();
			i_ma = v;
		}
	}
 
	int aux = id[u] = id[i_ma];
	int t = ans[aux].size();

	for(auto &v : gr[u]){
		if(v == i_ma) continue;
		int t1 = ans[id[v]].size();
		me = max(me, t1);
		for(int i = 0; i < t1; i++){
			ans[aux][t-1- i ] += ans[id[v]][t1-1 - i];
		}
	}
	for(int i = 0; i < me; i++){
		ans[aux][t - 1 - i].c0 += ans[aux][t - 1 - i].c2;
		if(ans[aux][t - 1 - i].c0 >= P) ans[aux][t - 1 - i].c0 -= P;
		ans[aux][t - 1 - i].c2 = 0;
	}
 
	//cout << u << "\n";
 
	ans[aux].push_back(state());
	//for(auto &x : ans[aux]) cout << "(" << x.c0 << ", " << x.c1 << ", " << x.c2 << ") ";
	//cout << "\n";
}
 
ll pot2[MAXN];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	pot2[0] = 1;
	for(int i = 1; i < MAXN; i++){
		pot2[i] = pot2[i-1] << 1;
		if(pot2[i] >= P ) pot2[i] -= P;
	}
	int N;
	cin >> N;
 
	p[0] = -1;
	cnt[0] = 1;
	
	for(int i = 1; i <= N; i++) {
		cin >> p[i];
		gr[p[i]].push_back(i);
	}
 
	dfs(0);
	ll sol = 0;
	int t = ans[id[0]].size();
	for(int l = 0; l < t; l++){
		sol += ans[id[0]][t-1-l].c1 * pot2[N + 1 - cnt[l]];
		if(sol >= P2) sol -= P2;
		
	}
	sol %= P;
	cout << sol << "\n";
 
 
	return 0;
}

Measured memory_bytes: 56304
n = int(input())
div = [1, ]
for i in range(2, int(n ** 0.5) + 1):
    if n % i == 0:
        div.append(i)
m = div[-1]
if m == 1:
    print(len(str(n)))
else:
    print(max(len(str(n//m)), len(str(m))))


Measured memory_bytes: 9372
<?php
	
$s = trim(fgets(STDIN));
$w = ['eraser','erase','dreamer','dream'];

for($i=0; $i<4; $i++){
 	$s = explode($w[$i], $s);
	if ($i<3) $s = implode($s);
}

$s = array_unique($s);

echo count($s) == 1 && $s[0] == '' ? 'YES' : 'NO';

?>

Measured memory_bytes: 4728
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    int n = in.size();
    cout << in[0] << n - 2 << in.back() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
const int MAX = static_cast<int>(1e9);

int main()
{
	int H, W, K;
	cin >> H >> W >> K;
	vector<vector<bool>> board(H, vector<bool>(W));
	pair<int, int> S;
	for (int i = 0; i < H; i++) {
		string A;
		cin >> A;
		for (int j = 0; j < W; j++) {
			if (A[j] == 'S') {
				S = make_pair(i, j);
			} else if (A[j] == '#') {
				board[i][j] = true;
			}
		}
	}
	auto calc_score = [H, W](const pair<int, int>& p) {
		return min({ p.first, (H - 1) - p.first, p.second, (W - 1) - p.second });
	};
	auto calc_ans = [K](int score) {
		return ((score + K - 1) / K) + 1;
	};
	vector<vector<int>> step(H, vector<int>(W, MAX));
	typedef pair<int, int> t;
	queue<t> q;
	q.emplace(S);
	step[S.first][S.second] = 0;
	int ans = MAX;
	while (!q.empty()) {
		pair<int, int> pos;
		pos = q.front(); q.pop();
		int score = calc_score(pos);
		ans = min(ans, calc_ans(score));
		if (score == 0) {
			break;
		}
		if (step[pos.first][pos.second] >= K)
			continue;
		static const int dx[4] = { 1, 0, -1, 0 };
		static const int dy[4] = { 0, 1, 0, -1 };
		for (int d = 0; d < 4; d++) {
			auto p2 = pos;
			p2.first += dy[d];
			p2.second += dx[d];
			if (!board[p2.first][p2.second] && step[p2.first][p2.second] == MAX) {
				q.emplace(p2);
				step[p2.first][p2.second] = step[pos.first][pos.second] + 1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        while (s.hasNextInt()) {
            int h = s.nextInt();
            int w = s.nextInt();
            if (h == 0 && w == 0) break;
            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; j++) {
                    System.out.print((((i + j) % 2) == 0) ? '#' : '.');
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 28756
class Stack:
    def __init__(self, Max=50000):
        self.top = 0
        self.Max = Max
        self.S = []

    def isFull(self):
        return self.top >= self.Max - 1

    def isEmpty(self):
        return self.top == 0

    def push(self, x):
        if self.isFull():
            assert ValueError('max')
        self.top += 1
        self.S.append(x) 

    def pop(self):
        if self.isEmpty():
            assert ValueError('Empty')
        self.top -= 1
        
        return self.S.pop()


formula = list(map(str, input().split()))
S = Stack()

for f in formula:
    # print(S.S)
    if f == '+':
        a = int(S.pop())
        b = int(S.pop())
        S.push(a + b)

    elif f == '-':
        a = int(S.pop())
        b = int(S.pop())
        S.push(b - a)

    elif f == '*':
        a = int(S.pop())
        b = int(S.pop())
        S.push(a * b)
    else:
        S.push(int(f))
        
print(S.pop())



Measured memory_bytes: 5600
#include <iostream>
#include <string>

int h, w;
int dx[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy[] = {-1, -1, -1, 0, 1, 1, 1, 0};
std::string map[50];

void che(int y, int x){
    int cnt = 0;
    int xx, yy;
    for(int i = 0; i < 8; i++){
        xx = x + dx[i];
        yy = y + dy[i];

        if(xx < 0 || xx >= w || yy < 0 || yy >= h) continue;

        if(map[yy][xx] == '#') cnt++;
    }
    std::cout << cnt;
}

int main(){
    std::cin >> h >> w;

    for(int i = 0; i < h; i++){
        std::cin >> map[i];
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(map[i][j] == '#'){
                std::cout << "#";
                continue;
            }
            che(i, j);
        }
        std::cout << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256