akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
using namespace std;

int main(){
      
        ios::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
    
       int r;
       cin >> r;
       cout <<fixed<<setprecision(4)<< 2*3.14159*(float(r));
        return 0;}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    vector<vector<ll>> dp(n+1, vector<ll>(k+2, 0));
    dp[0][k] = 1;
    ll mod = 1000000007;
    rep(i, n){
        rep(j, k+1){
            (dp[i+1][max(0, j-a[i])] += dp[i][j]) %= mod;
            (dp[i+1][j+1] += - dp[i][j] + mod) %= mod; 
        }
        rep(j, k+1){
            (dp[i+1][j+1] += dp[i+1][j]) %= mod;
        }
    }
    cout << dp[n][0] << endl;
}

Measured memory_bytes: 83032
n=gets.to_i
c=gets.chomp.chars
if !c.include?("W")||!c.include?("R")
  puts 0
  exit
end
i=c.index("W")
jj=c.reverse.index("R")
j=n-1-jj
a=0
while i<j
  a+=1
  i+=1
  while c[i]=="R"
    i+=1
    break if i>n-1
  end
  j-=1
  while c[j]=="W"
    j-=1
    break if j<0
  end
end
puts a


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

int main(void) {
  int n, k; cin >> n >> k;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >> a[i];
  vector<int> ans(n, 0);
  
  for (int i=0; i<k; i++) {
    vector<long long> ls(n, 0);
    vector<long long> rs(n, 0);
    
    for (int j=0; j<n; j++) {
      int l = max(j - a[j], 0);
      int r = min(j + a[j], n-1) + 1;
      ls[l]++;
      if (r < n) rs[r]++;
    }
    
    ans[0] = ls[0] - rs[0];
    
    for (int j=1; j<n; j++) {
      ls[j] += ls[j-1];
      rs[j] += rs[j-1];
      ans[j] = ls[j] - rs[j];
    }
      
    for (int j=0; j<n; j++) a[j] = ans[j];
    if (i  > 5 * ceil(log(n))) break;
    
  }
  
  for (int i=0; i<n; i++) cout << ans[i] << " ";

}


Measured memory_bytes: 8248
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,b;
  cin>>n;
  vector<int> a(n+1);
  long long ans=0;
  rep(i,n+1) cin>>a[i];
  rep(i,n){
    cin>>b;
    ans+=min(a[i],b);
    b=max(0,b-a[i]);
    ans+=min(a[i+1],b);
    a[i+1]=max(0,a[i+1]-b);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3768
#include<iostream>
using namespace std;
int main(){
 int m,n,f=0;
 char a[51][51],b[51][51];
 cin>>n>>m;
 for(int i=0;i<n;i++)
  for(int j=0;j<n;j++)cin>>a[i][j];
 for(int i=0;i<m;i++)
  for(int j=0;j<m;j++)cin>>b[i][j];
                
 for(int i=0;i<n;i++){/*bの左上と一致する場所を調べる*/
  if(f==1)break;
  for(int j=0;j<n;j++){
   if(f==1)break;
   if(a[i][j]==b[0][0]){/*一致した*/
    int f2=0;
    if(i+m<=n&&j+m<=n)
     for(int l=0;l<m;l++){/*ｂの画像と一致するかどうか*/
      if(f2==1)break;
      for(int k=0;k<m;k++)
       if(a[i+l][j+k]==b[l][k])f=1;
       else if(a[i+l][j+k]!=b[l][k]){f=0;f2=1;break;}
      }
    }
  }
 }   
 if(f==1)cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
 return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0&&W==0) break;

            for(int i = 0; i < H ; i++){
                for(int j = 0; j < W ; j++){
                    if((i+j)%2 == 0) System.out.print('#');
                    else System.out.print('.');
                }
                System.out.println();
            }
            System.out.println();
        }
       
        sc.close();
    }
}



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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  set<int> st;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    st.insert(x);
  }
  if(st.size() % 2 == 0)cout << st.size() - 1 << endl;
  else cout << st.size() << endl;
	return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int K, A, B; cin >> K >> A >> B;
  string ans = "NG";
  for(int i = A; i <= B; ++i) {
    if(i % K == 0) ans = "OK";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    long long a;
    a = pow(10,9);
    long long b;
    b = 7;
    long long big;
    big = a+b;
    int n;
    cin >> n;
    long long pow=1;
    for(int i=1; i<=n; i++){
        pow = pow*i%big;
    }
    cout << pow << endl;
}



Measured memory_bytes: 3596
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

#define INF 1000000000

int H, W;
int dp[305][305];
int cost[305][305];

int calc(vector< vector<char> >& field, int a, int b){
  rep(i,305) rep(j,305) dp[i][j] = INF;

  rep(i,H){
    vector<int> v;
    int sum = 0;
    rep(j,H-i){
      if(field[i+j][a] == field[j][b]){
        v.push_back(1);
        sum++;
      }else{
        v.push_back(0);
      }
    }
    rep(k,v.size()){
      cost[k][i+k] = sum;
      if(v[v.size()-1-k]==1) sum--;
    }
  }
  rep(i,H){
    vector<int> v;
    int sum = 0;
    rep(j,H-i){
      if(field[j][a] == field[i+j][b]){
        v.push_back(1);
        sum++;
      }else{
        v.push_back(0);
      }
    }
    rep(k,v.size()){
      cost[i+k][k] = sum;
      if(v[v.size()-1-k]==1) sum--;
    }
  }

  
  
  dp[0][0] = 0;
  rep(i,H){
    rep(j,H){
      /*
      int c = 0;
      REP(k,max(i,j),H){
        int l = k-i;
        int r = k-j;
        if(l>=0 && r>=0){
          if(field[l][a] == field[r][b]){
            c++;
          }
        }else break;
      }
      */
      //cout << i << " " << j << " " << c << " " << cost[i][j] << endl;
      //cout << "\t" << i << " " << j << " " << dp[i][j] << " " << cost << endl;
      dp[i+1][j] = min(dp[i+1][j], dp[i][j] + cost[i][j]);
      dp[i][j+1] = min(dp[i][j+1], dp[i][j] + cost[i][j]);
    }
  }
  int ret = INF;
  rep(i,H){
    ret = min(ret, dp[i][H]);
    ret = min(ret, dp[H][i]);
  }
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  cin >> H >> W;
  vector< vector<char> > field(H, vector<char>(W, '*'));
  rep(i,H){
    rep(j,W){
      cin >> field[i][j];
    }
  }

  int ret = 0;
  rep(i,W-1){
    ret += calc(field, i, i+1);
  }
  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;    
#define int long long        
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar) for(int pen=0;pen<sizeof(ar)/8;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rt return 0;
#define mod 1000000007
const int N= 8*1e5+ 10;
int st[N]={0};
void update(int ss, int se, int i, int diff, int si)  
{  
    // Base Case: If the input index lies outside the range of  
    // this segment  
    if (i < ss || i > se)  
        return;  
  
    // If the input index is in range of this node, then update  
    // the value of the node and its children  
    st[si] = st[si] + diff;  
    if (se != ss)  
    {  
        int mid = (ss+se)/2;  
        update(ss, mid, i, diff, 2*si);  
        update(mid+1, se, i, diff, 2*si + 1);  
    }  
}  
int get_sum(int ss, int se, int qs, int qe, int si)  
{  
    // If segment of this node is a part of given range, then return  
    // the sum of the segment  
    if (qs <= ss && qe >= se)  
        return st[si];  
  
    // If segment of this node is outside the given range  
    if (se < qs || ss > qe)  
        return 0;  
  
    // If a part of this segment overlaps with the given range  
    int mid = (ss+se)/2;
    return get_sum(ss, mid, qs, qe, 2*si) +  
        get_sum(mid+1, se, qs, qe, 2*si+1);  
}
int dp[3001][3001];
int cnt=0; 
int lcs( char X[], char Y[], int m, int n )  
{  
    //cout<<m<<" "<<n<<endl;

    if (m == 0 || n == 0)  
    {
        dp[m][n]=0;
       return 0;
    }
    if(dp[m][n]!=-1)
    {
        return dp[m][n];
    }  
    if (X[m-1] == Y[n-1])  
    {
        dp[m][n]=1+lcs(X,Y,m-1,n-1);
        
        // return 1 + lcs(X, Y, m-1, n-1);
        return dp[m][n];
    }  
    else
     {
         dp[m][n]= max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
        return dp[m][n];
     }  
} 
signed main()
{
    fastio;
    char s[3001],t[3001];
    cin>>s>>t;
    int m= strlen(s);
    int n= strlen(t);
    for(int i=0;i<=m+10;i++)
    for(int j=0;j<=n+10;j++)
    dp[i][j]=-1;

    int final=lcs(s,t,m,n);

   char lcs[final+1];
   lcs[final]='\0';
   int i=m;
   int j=n;
   while(i>0 && j>0){
       if(s[i-1]==t[j-1]){
           lcs[final-1]=s[i-1];
           i--;
           j--;
           final--;
       }
       else if(dp[i-1][j]>=dp[i][j-1]){
           i--;
       }
       else
       {
           j--;
       }
   }
   cout<<lcs<<endl;
}

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

#define int long long int
#define MOD 1000000007
#define N 1000003
#define pii pair<int,int>
#define MAX 1000000000000000000
#define _mp make_pair
#define pb push_back
#define _sort(v) sort(v.begin(),v.end())
#define _rsort(v) sort(v.rbegin(),v.rend())
using namespace std;

int32_t main(){

int n;
cin>>n;
vector<int> v(N,0),a(n);
for(int i=0;i<n;i++){
    cin>>a[i];
    if(v[a[i]]){
        ++v[a[i]];
        continue;
    }
    for(int j=a[i];j<N;j+=a[i]){
        ++v[j];
    }
}
int ans=0;
for(int i=0;i<n;i++){
    if(v[a[i]]==1)
    ans++;
}
cout<<ans;
return 0;
}

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

int out(vector<int> &A,int n){
	int i;
	for (i=0;i<=n-2;i++){
		cout << A[i] <<" ";
	}
	cout << A[n-1] <<endl;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,i,j;
	cin >> n;
	vector<int> A(n);
	for (i=0;i<n;i++){
		cin >> A[i];
	}
	
	const int k=10000;
	vector<int> C(k+1,0);
	vector<int> B(n);
	
	for (i=0;i<n;i++){
		C[A[i]]++;
	}
	
	for (j=1;j<k+1;j++){
		C[j]=C[j]+C[j-1];
	}
	
	for (i=n-1;i>-1;i--){
		B[C[A[i]]-1]=A[i];
		C[A[i]]--;
	}
	
	out(B,n);
	return 0;
}

Measured memory_bytes: 16768
#include<bits/stdc++.h>
#define Re register
using namespace std;

const int N=2020;

struct Node {
	int u,v,nxt;
}E[2*N];
int cnt,head[N];

int n;
char s[N];
int val[N],dis[N];
int f[N];
int Ans=-1;

inline int rd()
{
	char c=getchar();
	int x=0,f=1;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

void add(int x,int y)
{
	Node T={x,y,head[x]};
	E[++cnt]=T;
	head[x]=cnt;
}

void dfs(int u,int fa)
{
	val[u]=s[u]-'0';
	dis[u]=0;
	int Son=-1;
	for(int i=head[u];~i;i=E[i].nxt)
	{
		int ver=E[i].v;
		if(ver==fa) continue;
		dfs(ver,u);
		val[u]+=val[ver];
		dis[ver]+=val[ver];
		dis[u]+=dis[ver];
		if(!(~Son)||dis[Son]<dis[ver]) Son=ver;
	}
	if(!(~Son))
	{
		f[u]=0;
		return;
	}
	if(dis[u]-dis[Son]>=dis[Son]) f[u]=dis[u]/2;
	else f[u]=dis[u]-dis[Son]+min(f[Son]*2,2*dis[Son]-dis[u])/2;
}

int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	memset(head,-1,sizeof(head));
	for(Re int i=1;i<n;i++)
	{
		int u=rd();
		int v=rd();
		add(u,v);
		add(v,u);
	}
	for(Re int i=1;i<=n;i++)
	{
		dfs(i,0);
		if(f[i]*2==dis[i])
		{
			if(!(~Ans)) Ans=f[i];
			Ans=min(Ans,f[i]);
		}
	}
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 3892
Option Infer On
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = CInt(NextString())
        Dim M = Pow(10, 9) + 7

        Dim ans = 1L

        For i = 1 To N
            Dim j = i Mod M
            ans = (ans * j) Mod M
        Next

        WriteLine(ans)
    End Sub

    Function Pow(a As Long, b As Integer) As Long
        Dim result = 1L
        For i = 1 To b
            result *= a
        Next
        Return result
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 20552
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s;
int main() {
    cin>>s;

    ll ans=0;
    bool Removed=true;
    while(s.size()>=2 && Removed){
        Removed=false;

        REP(i, 0, s.size()-1){
            if(s[i]!=s[i+1]){
                ans+=2;
                s.erase(s.begin()+i);
                s.erase(s.begin()+i);
                Removed=true;
                break;
            }
        }
    }
  
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int N,D;
  cin>>N>>D;
  int X[N][D];
  for(int i=0;i<N;i++)
    for(int j=0;j<D;j++) cin>>X[i][j];
  int count=0;
  for(int i=0;i<N-1;i++)
    for(int j=i+1;j<N;j++){
      int sum=0;
      for(int k=0;k<D;k++) sum+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
      for(int i=1;i*i<=sum;i++) if(i*i==sum) count++;
    }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int n, m;

unordered_map <int, vector <int > > g[N];

unordered_map <int, int> d[N];

int c[N];

int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
    freopen ("E.out", "w", stdout);
	#endif
	Kazakhstan
	cin >> n >> m;
	rep(i, 1, m) {
		int a, b, c;
		cin >> a >> b >> c;
		g[a][c].pb(b);
    g[b][c].pb(a);
	}
	d[1][0] = 0;
	set < pair <int, pair <int, int> > > st;
	st.insert({0, {1, 0}});
  vector <bool> was(n + 1, 0);
	while (sz(st)) {
		int dist = st.begin() -> f;
		int v = st.begin() -> s.f, last = st.begin() -> s.s;
		st.erase(st.begin());
    
    if (!was[v]) {
      for (auto it : g[v]) {
        int C = it.f;
        for (auto to : it.s) {
          if (!d[to].count(C) || d[to][C] > dist + 1) {
            st.erase({d[to][C], {to, C}});
            d[to][C] = dist + 1;
            st.insert({d[to][C], {to, C}});
          }
        }
      }
      was[v] = 1;
    }

    if (sz(g[v][last])) {
      int C = last;
      for (auto to : g[v][last]) {
        if (!d[to].count(last) || d[to][last] > dist) {
          st.erase({d[to][C], {to, C}});
          d[to][C] = dist;
          st.insert({d[to][C], {to, C}});
        }
      }
      g[v][last].clear();
      g[v].erase(last);
    }
  }
  int ans = inf;
  for (auto it : d[n]) ans = min(ans, it.s);
  cout << (ans == inf ? -1 : ans);
	ioi
}


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

void build(int node, int start, int end, vector<int> &dp, vector<int> &a)
{
	if(start==end)
	{
		dp[node]=1;
	}
	else
	{
		int mid=start+(end-start)/2;
		build(2*node+1,start,mid,dp,a);
		build(2*node+2,mid+1,end,dp,a);
		if(dp[2*node+1]>dp[2*node+2])
			dp[node]=dp[2*node+1];
		else
			dp[node]=dp[2*node+2];
	}
}

void update(int node, int in, int val, int start, int end, vector<int> &dp)
{
	if(start==end){
		dp[node]=val;
		return;
	}

	int l=2*node+1;
	int r=2*node+2;
	int mid=start+(end-start)/2;
	if(start<=in && in<=mid)
		update(l,in,val,start,mid,dp);
	else
		update(r,in,val,mid+1,end,dp);
	if(dp[l]>dp[r])
		dp[node]=dp[l];
	else
		dp[node]=dp[r];
}

int query(int node, int start, int end, int l, int r, vector<int> &dp)
{
	if(l<=start && end<=r)
		return dp[node];
	if(r<start || l>end)
		return 0;
	int mid=start+(end-start)/2;
	int left=query(2*node+1,start,mid,l,r,dp);
	int right=query(2*node+2,mid+1,end,l,r,dp);
	if(left>right)
		return left;
	else
		return right;
}

int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int i=0; i<n; i++)
		cin>>a[i];
	vector<int> dp(10000000,0);
	//for(int i=0; i<n; i++)
		//dp[a[i]]++;

	//build(0,0,300000,dp,a);

	for(int i=0; i<n; i++)
	{
		int curr=query(0,0,300000,a[i]-k, a[i]+k, dp);
		update(0,a[i],curr+1,0,300000,dp);
	}
	cout<<query(0,0,300000,0,300000,dp)<<endl;
	return 0;
}

Measured memory_bytes: 43348
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var L = ReadArrayInt();
            var max = L.Max();
            var sum = L.Sum();

            Console.WriteLine(max < sum - max ? "Yes" : "No");
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13396
main :: IO ()
main = interact $ (++ "\n") . unwords . map show . (\(ts,hs) -> [sum ts, sum hs]) . unzip . map (score . words) . tail . lines

score :: [String] -> (Int, Int)
score [t,h] = case compare t h of GT -> (3,0); EQ -> (1,1); LT -> (0,3)


Measured memory_bytes: 4248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ld ans = 0;
    ll cnt = 0;
    ll N, M, D;
    cin >> N >> M >> D;
    if(D==0)ans = (M - 1) / (ld)N;
    else ans = (N - D) *2* (M - 1) / (ld)N / (ld)N;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		long[] vals = new long[N];
		for (int i = 0; i < N; i++) {
			vals[i] = sc.nextLong();
		}
		Arrays.sort(vals);
		long ans = vals[N-1];
		int rem = N - 2;
		for (int i = N - 2; i >= 0 && rem > 0; i--) {
			rem--;
			ans += vals[i];
			if (rem > 0) {
				rem--;
				ans += vals[i];
			}
		}
		out.println(ans);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 57716
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, T;
    cin >> n >> T;
    int mn = INF;
    for(int i =0 ; i < n; i++){
        int c, t;
        cin >> c >> t;
        if(t <= T) mn = min(mn, c);
    }
    if(mn == INF) cout << "TLE";
    else cout << mn;
}

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

int main() {
	string s; getline(cin, s);
	regex re("apple");
	s=regex_replace(s, re, "???");
	regex re2("peach");
	s=regex_replace(s, re2, "apple");
	regex re3("???");
	s=regex_replace(s, re3, "peach");
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3208
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
char s[105];
int len;
int ans;
int cc;
int maxn;
int main(){
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i <= len; i++)
	{
		if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G')   
		{
			ans++;
		maxn = max(maxn,ans);
		}
		else ans = 0;
	}
	printf("%d\n", maxn);
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	VLL A(N);
	for (LL n = 0; n < N; n++) {
		cin >> A[n];
	}
	VLL check(1e6 + 1, 0);
	LL ans = 0;
	sort(A.begin(), A.end(), [](LL a, LL b) {
		return a < b;
	});
	vector<PLL> AA;
	AA.push_back(PLL(A[0], 1));
	for (LL n = 1; n < N; n++) {
		if (AA.back().first == A[n])AA.back().second++;
		else AA.push_back(PLL(A[n], 1));
	}
	for (PLL pll:AA) {
		LL n = pll.first;
		bool flag = false;
		if (check[1] != 0)flag = true;
		for (LL p = 2; p * p <= n && !flag; p++) {
			if (n % p != 0)continue;
			if (check[p] != 0)flag = true;
			if (check[n / p] != 0)flag = true;
		}
		if (!flag && pll.second ==1)ans += 1;
		check[n]++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 16340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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; }

ll a[MAXN];



const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main() {
    COMinit();

    ll n, k;
    cin >> n >> k;
    rep(i, n) {
        cin >> a[i];
    }

    ll ans = 0;

    sort(a, a+n);
    
    rep(re, 2) {

        for(int i=0; i<n; ++i) {
                ll now = COM(i, k-1);
                if (re == 1) now = -now;
                ans += now * a[i];
                ans %= mod;
        }
        reverse(a, a+n);
    }

    cout << ans << endl;

}



Measured memory_bytes: 24832
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * n
dp[0] = 0
for i in range(1, n):
    for j in range(max(i - k, 0), i):
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
print(dp[-1])

Measured memory_bytes: 84620
package main

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

var mod uint64 = 1000000007

func main() {
	var n uint64
	fmt.Scan(&n)

	NewReader(int(n))
	a := ReadInts64(" ")

	var ans uint64
	for k := uint(0); k < 60; k++ {
		var x, y uint64
		for _, i := range a {
			if (uint64(i)>>k)&1 == 1 {
				x++
			} else {
				y++
			}
		}

		sum := (x * y) % mod
		for i := uint(0); i < k; i++ {
			sum = (sum * 2) % mod
		}

		ans = (ans + sum) % mod
	}

	fmt.Println(ans)
}

type Reader struct {
	rdr  *bufio.Reader
	size int
}

var reader *Reader

func NewReader(size int) {
	reader = &Reader{
		bufio.NewReaderSize(os.Stdin, size),
		size,
	}
}

func ReadLine() string {
	buf := make([]byte, 0, reader.size)
	for {
		line, isPrefix, err := reader.rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}

func ReadStrs(sep string) []string {
	return strings.Split(ReadLine(), sep)
}

func ReadInts64(sep string) []int64 {
	a := ReadStrs(sep)
	n := make([]int64, 0)
	for _, v := range a {
		if i, e := strconv.ParseInt(v, 10, 64); e == nil {
			n = append(n, i)
		}
	}
	return n
}


Measured memory_bytes: 28160
a = [int(input()) for i in range(5)]
m=1000
for i in range(5):
    tmp = a[i]
    for j in range(5):
        if i!=j:
            if a[j]%10==0: tmp+=a[j]
            else: tmp+=(a[j]+10-a[j]%10)
    m = min(m,tmp)
print(m)

Measured memory_bytes: 3060
#include"stdio.h"
int main()
{
    int i,j,k;
    scanf("%d %d",&i,&j);
    if(i<=j)
    {
        for(k=0;k<j;k++)
            printf("%d",i);
    }
    else
    {
        for(k=0;k<i;k++)
            printf("%d",j);
    }
    return 0;
}


Measured memory_bytes: 128
const M:u64=1000000007;
fn main(){
    proconio::input!{
        n:usize,
        abs:[(i64,i64);n]
    }
    let mut o=M-1;
    let mut mp=Vec::new();
    for ab in abs{
        let (mut a,mut b)=ab;
        if a==0&&b==0{o+=1}
        else
        {
            let g=num::integer::gcd(a,b);
            a/=g;
            b/=g;
            if a<0||a==0&&b>0{a=-a;b=-b}
            let mut f=0;
            if b<0{
                let t=a;
                a=-b;
                b=t;
                f=1;
            }
            mp.push((a,b,f))
        }
    }
    mp.sort();
    let mut i=0usize;
    let mut ans=1;
    while i<mp.len(){
        let j=i;
        let mut x=1;
        let mut y=1;
        while i<mp.len()&&mp[j].0==mp[i].0&&mp[j].1==mp[i].1{
            if mp[i].2==0{x=x*2%M}else{y=y*2%M}
            i+=1
        }
        ans=ans*(x+y-1)%M;
    }
    println!("{}",(ans+o)%M)
}


Measured memory_bytes: 17536
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

string sn;
int k;
ll powll(ll base,ll power){
    ll ans = 1;
    while (power){
        if (power&1) ans = (base*ans)%mod;
        base = (base*base)%mod;
        power >>= 1;
    }
    return ans;
}
ll facts[100010],invs[100010];

int ncr(int ni, int ri){
    return ni < ri ? 0 : facts[ni] * invs[ri] % mod * invs[ni-ri] % mod;
}
signed main(){
    int n = 500;
    ll f = 1;
    facts[0] = 1;
    FOR(i,1,n+1){
        f *= i;
        f %= mod;
        facts[i] = f;
    }
    ll inv = powll(f,mod-2);
    invs[n] = inv;
    REPNS(i,n){
        inv *= i;
        inv %= mod;
        invs[i-1] = inv;
    }

    cin >> sn;
    cin >> k;
    int count = 0;
    for (auto c : sn) count += c != '0';
    int l = sz(sn);
    int ret = count >= k;
    REP(i,l){
        if (!k) break;
        if (sn[i] == '0') continue;
        ret += ncr(l-i-1,k) * powll(9,k);
        cerr << ret << endl;

        ret += (sn[i] - '1') * ncr(l-i-1,k-1) * powll(9,k-1);
        cerr << ret << endl;
        k--;
    }

    cout << ret << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

    constexpr ll M = 3;
    vector<ll> rate_A(M), rate_B(M);

    for (ll i = 0; i < M; i++) {
        cin >> rate_A[i];
    }
    for (ll i = 0; i < M; i++) {
        cin >> rate_B[i];
    }

    //Aでの行動
    vector<ll> priority = { 0, 1, 2 };
    ll b_max = N;
    for (ll i = 0; i * rate_A[0] <= N; i++) {
        for (ll j = 0; j * rate_A[1] <= N - i * rate_A[0]; j++) {
            ll tmp = i * rate_B[0] + j * rate_B[1];
            ll rem = N - (i * rate_A[0] + j * rate_A[1]);
            if (rate_B[2] > rate_A[2]) {
                ll num = rem / rate_A[2];
                tmp += rem % rate_A[2] + num * rate_B[2];
            } else {
                tmp += rem;
            }
            b_max = max(b_max, tmp);
        }
    }

    //Bでの行動
    constexpr ll d = 5000;
    ll ans = b_max;
    do {
        for (ll i = b_max / rate_B[priority[0]]; i >= max(b_max / rate_B[priority[0]] - d, (ll)0); i--) {
            ll remainder = b_max - i * rate_B[priority[0]];
            for (ll j = remainder / rate_B[priority[1]]; j >= max(remainder / rate_B[priority[1]] - d, (ll)0); j--) {
                ll tmp = i * rate_A[priority[0]] + j * rate_A[priority[1]];
                ll rem = b_max - (i * rate_B[priority[0]] + j * rate_B[priority[1]]);
                if (rate_A[priority[2]] > rate_B[priority[2]]) {
                    ll num = rem / rate_B[priority[2]];
                    tmp += rem % rate_B[priority[2]] + num * rate_A[priority[2]];
                } else {
                    tmp += rem;
                }
                ans = max(ans, tmp);
            }
        }

    } while (next_permutation(priority.begin(), priority.end()));

    cout << ans << endl;
}

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

if n%2 == 0:
    for i in range(n):
        if i%2 == 0:
            if not A[i] == i+1:
                print(0)
                break
        else:
            if not A[i] == i:
                print(0)
                break
    else:
        print(2**(n//2)%(10**9+7))
else:
    if not A[0] == 0:
        print(0)
    else:    
        for i in range(1,n):
            if i%2 == 0:
                if not A[i] == i:
                    print(0)
                    break
            else:
                if not A[i] == i+1:
                    print(0)
                    break
        else:
            print(2**((n-1)//2)%(10**9+7))
            

Measured memory_bytes: 14008
def modinv2(a,m):
    return pow(a,m-2,m)

def modcomn(n,r,m):
    modcom = [0 for _ in range(n)]
    for i in range(n):
        if i < r-1:
            continue
        if i == r-1:
            modcom[i] = 1
        elif i == r:
            modcom[i] = (i+1)%m
        else:
            div = modinv2(i-r+1,m)
            modcom[i] = (modcom[i-1]*div%m)*(i+1)%m
    return modcom

N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
P = 10**9+7

com = modcomn(N-1,K-1,P)

#print(com)
ans = 0

for i in range(N):
    if i >= K-1:
        ans = (ans+A[i]*com[i-1]%P)%P
    if i <= N-K:
        ans = (ans-A[i]*com[N-i-2]%P+P)%P

print(ans)


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

int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    long long sum = a + b;
    long long times = n / sum;
    long long remain = n - (times * sum);
    long long numOfBlue = a * times;
    if(remain < a){
        numOfBlue += remain;
    }
    else{
        numOfBlue += a;
    }

    cout << numOfBlue << endl;
}

Measured memory_bytes: 256
def check_rank(eye)
  return 0 if eye >= 11
  return 1 if eye >= 6
  return 2 if eye >= 2
  return 3
end

### main

rank = Array.new(4){[0, 0]}

while (line = gets)
  le, re = line.strip.split(" ").map do |s|
    s0, s1 = s.split(".")
    s0.to_i * 10 + s1.to_i
  end

  lr = check_rank(le)
  rr = check_rank(re)

  rank[lr][0] += 1
  rank[rr][1] += 1
end

for rn in rank
  puts "#{rn[0]} #{rn[1]}"
end

Measured memory_bytes: 6100
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m,sm,bi,k,i,l;
  cin>>n>>m;
  sm=0;
  bi=1000000;
  for(i=0; i<m; i++){
    cin>>k>>l;
    if(k>sm){
      sm=k;
    }
    if(l<bi){
      bi=l;
    }
  }
  if(sm>bi){
    n=0;
  }
  else{
    n=bi-sm+1;
  }
 
  cout<<n;
}

Measured memory_bytes: 256
import numpy as np
def f(n):
    counts = [0]*n
    x_max = int(np.sqrt(n))
    for x in range(1,x_max+1):
        y_max = int(np.sqrt(n-x**2))
        for y in range(1,y_max+1):
            z_max = int(np.sqrt(n-x**2-y**2))
            for z in range(1,z_max+1):
                if x**2+y**2+z**2+x*y+y*z+z*x <= n:
                    counts[x**2+y**2+z**2+x*y+y*z+z*x-1] += 1
    return counts
 
N = int(input())
counts = f(N)
for i in range(N):
    print(counts[i])

Measured memory_bytes: 27092
import Control.Applicative
import Data.List

getInt :: IO Int
getInt = (\a -> read a :: Int) <$> getLine

getInteger :: IO Integer
getInteger = (\a -> read a :: Integer) <$> getLine

count :: String -> Bool
count "" = True
count [_] = False
count (x:y:xs)
    | x == y = count xs
    | otherwise = False

main = do
    putStrLn =<< (((\a -> if a then "Yes" else "No") . count . sort) <$> getLine)


Measured memory_bytes: 508
#include<stdio.h>
int main(void)
{
	char op;
	int a,b;
	do{
	scanf("%d %c %d",&a,&op,&b);
	if(0<=a && b<=20000){
	if(op=='+'){
		printf("%d\n",a+b);
	}
	else if(op=='-'){
		printf("%d\n",a-b);
	}	
	else if(op=='*'){
		printf("%d\n",a*b);
	}	
	else if(op=='/'){
		printf("%d\n",a/b);
	}
	}
	}while(op!='?');
return 0;
}

Measured memory_bytes: 600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

int comb(int n, int k) {
    int ret = 1;
    for (int i = n; i > n - k; i--) ret *= i;
    for (int i = 1; i <= k; i++) ret /= i;
    return ret;
}


int main(void) {
    int n, m;
    cin >> n >> m;

    cout << comb(n, 2) + comb(m, 2) << endl;


    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  int start = n;
  for (int i = n - 1; i >= 0; i--) {
    int cur = i - a[i];
    if (cur < 0 || cur > start) {
      cout << -1 << '\n';
      return 0;
    }
    if (cur != start) {
      ans += a[i];
      start = cur;
    }
  }
  cout << ans << '\n';
  return 0;
}

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

int main() {
	int a,b,c,d,p;
	cin >> a >> b >> c >> d >> p;
	int x = a*p ;
	int y = b;
	if(p>c){
		y = b+d*(p-c);
	}
	if(x>y){
		cout << y << endl;
	}
	else{
		cout << x << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int inf=1e9;
typedef long long ll;
int M,N;
string board[505];

int hit(int hity,int hitx)
{
    int ret=0;
    char up='-',down='-',right='-',left='-';
    int leftx,rightx,upy,downy;
    for(int y=hity;y>=0;y--)
    {
        if(board[y][hitx]!='.')
        {
            up=board[y][hitx];
            upy=y;
            break;
        }
    }
    for(int y=hity;y<M;y++)
    {
        if(board[y][hitx]!='.')
        {
            down=board[y][hitx];
            downy=y;
            break;
        }
    }
    for(int x=hitx;x>=0;x--)
    {
        if(board[hity][x]!='.')
        {
            left=board[hity][x];
            leftx=x;
            break;
        }
    }
    for(int x=hitx;x<N;x++)
    {
        if(board[hity][x]!='.')
        {
            right=board[hity][x];
            rightx=x;
            break;
        }
    }
    if(right!='-')
    {
        if(right==left) board[hity][rightx]='.',board[hity][leftx]='.',right='-',left='-',ret+=2;
        else if(right==up) board[hity][rightx]='.',board[upy][hitx]='.',right='-',up='-',ret+=2;
        else if(right==down) board[hity][rightx]='.',board[downy][hitx]='.',right='-',down='-',ret+=2;
    }
    if(left!='-')
    {
        if(left==right) board[hity][leftx]='.',board[hity][rightx]='.',left='-',right='-',ret+=2;
        else if(left==up) board[hity][leftx]='.',board[upy][hitx]='.',left='-',up='-',ret+=2;
        else if(left==down) board[hity][leftx]='.',board[downy][hitx]='.',left='-',down='-',ret+=2;
    }
    if(up!='-')
    {
        if(up==right) board[upy][hitx]='.',board[hity][rightx]='.',up='-',right='-',ret+=2;
        else if(up==left) board[upy][hitx]='.',board[hity][leftx]='.',up='-',left='-',ret+=2;
        else if(up==down) board[upy][hitx]='.',board[downy][hitx]='.',up='-',down='-',ret+=2;
    }
    if(down!='-')
    {
        if(down==right) board[downy][hitx]='.',board[hity][rightx]='.',up='-',right='-',ret+=2;
        else if(down==left) board[downy][hitx]='.',board[hity][leftx]='.',up='-',left='-',ret+=2;
        else if(down==up) board[upy][hitx]='.',board[downy][hitx]='.',up='-',down='-',ret+=2;
    }
    return ret;
}

int check()
{
    int change=0;
    for(int i=0;i<M;i++)
    {
        for(int j=0;j<N;j++)
        {
            if(board[i][j]=='.') 
            {
                change+=hit(i,j);
            }
        }
    }
    return change;
}   

int main()
{
	while(cin >> M >> N && M)
    {
        int ans=0;
        for(int i=0;i<M;i++)
        {
            cin >> board[i];
        }
        while(1)
        {
            int inc=check();
            ans+=inc;
            if(inc==0)break;
        }
        cout << ans << endl;
    }
	
}



Measured memory_bytes: 3364
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <set>
#define MAX 100000
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;

int main(void)
{
	int N; cin >> N;
	string S; cin >> S;
	vector<int> w(N, 0), e(N, 0);
	int ans = N;
	rep(i, 0, N - 1)w[i + 1] += (w[i] + (S[i] == 'W' ? 1 : 0));
	rep(i, 0, N - 1)e[N - i - 2] += (e[N - i - 1] + (S[N - i - 1] == 'E' ? 1 : 0));
	rep(i, 0, N)ans = min(ans, w[i] + e[i]);
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3076
import sys

input = sys.stdin.readline

def main():
    n,m = map(int, input().split())
    a = [0]*n
    b = [0]*n
    c = [0]*m
    d = [0]*m
    ans = [1]*n
    for i in range(n):
        a[i], b[i] = map(int, input().split())
    for i in range(m):
        c[i], d[i] = map(int, input().split())
    for i in range(n):
        temp = abs(a[i]-c[0]) + abs(b[i]-d[0])
        for j in range(1,m):
            cur = abs(a[i]-c[j]) + abs(b[i]-d[j])
            if temp > cur:
                temp = cur
                ans[i] = j+1
        print(ans[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(void){
    vector< pair<int, int> > res;
    while(1) {
        int h, w;
        cin >> h >> w;
        if(w == 0) break;
        vector< pair<int, int> > d[100100];
        int min_ = h*h+w*w;
        int ans = 1 << 30;
        for(int i = 2; i < 150; i++) {
            for(int j = 1; j < i; j++) {
                if(min_ <= i*i+j*j && ans >= i*i+j*j) {
                    if(min_ != i*i+j*j) {
                        ans = i*i+j*j;
                        d[ans].push_back(make_pair(j, i));
                    }
                    else if(j > h) {
                        ans = i*i+j*j;
                        d[ans].push_back(make_pair(j, i));
                    }
                }
            }
        }
        sort(d[ans].begin(), d[ans].end());
        for(pair<int, int> p : d[ans]) {
            res.push_back(make_pair(p.first, p.second));
            //cout << p.first << " " << p.second << endl;
            break;
        }
    }
    for(int i = 0; i < res.size(); i++) {
        cout << res[i].first << " " << res[i].second << endl;
    }
    return 0;
}


Measured memory_bytes: 5416
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
#define ll long long
static const int MAX = 1000010;
static const ll INFTY = 1e12;
static const int NUMMAX = 300;


int main(){

  string S;
  string ans = "Yes";

  cin >> S;

  REP(i, S.length()){
    if( i % 2 == 0 ){
      if( S[i] == 'L' ){
        ans = "No";
        break;
      }
    }else {
      if( S[i] == 'R' ){
        ans = "No";
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;

void solve() {
	int n; cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; ++i) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	int mid = d[(n / 2) - 1];
	int index = 0;
	for (int i = 0; i < n; ++i) {
		if (d[i] > mid) {
			index = i;
			break;
		}
	}
	if (index != (n / 2)) {
		cout << 0 << endl;
		return;
	}
	int ans = d[index] - d[(n / 2) - 1];
	cout << ans << endl;
	return;
}

int main() {
	solve();
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
typedef long long ll;
#define FOR(i,n) for(int i=0;i<n;i++)
//map<key,value>

int main(){
  int k,x;
  cin >> k >> x;
  for(int i=x-k+1;i<=x+k-1;i++){
    cout << i << " ";
  }
  return 0;
}


Measured memory_bytes: 256
import sys
def lcs(X, Y):
    indices = [0]
    for c in Y:
        for i in range(len(indices) - 1, -1, -1):
            tmp = X.find(c, indices[i])
            if tmp + 1:
                if i + 1 < len(indices):
                    indices[i + 1] = min(indices[i + 1], tmp + 1)
                else:
                    indices.append(tmp + 1)
    return len(indices) - 1

q = int(input())
for i in range(q):
    X = sys.stdin.readline().rstrip('\r\n')
    Y = sys.stdin.readline().rstrip('\r\n')
    print(lcs(X, Y))

Measured memory_bytes: 7732
package main
import(
  "fmt"
)
func main(){
  var(
    a,b,count,max int
  )
  fmt.Scan(&a)
  for i:=0;i<a;i++{
    fmt.Scan(&b)
    if b>=max{
      max=b
      count+=1
    }
  }
  fmt.Println(count)
}

Measured memory_bytes: 512