akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N, M;


signed main(){
    cin >> N >> M;

    if(N == M) Yes;
    else No;

    return 0;
}

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

a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    
max_a = max(a_list)
new_b_list = []
for i in range(len(b_list)):
    if max_a <= b_list[i]:
        new_b_list.append(b_list[i])
    
count = 0
new_b_list = sorted(new_b_list, reverse=True)
for i in range(len(new_b_list)):
    H -= new_b_list[i]
    count += 1
    if H <= 0:
        print(count)
        exit()


count += (H-1) // max_a + 1

print(count)

Measured memory_bytes: 12832
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 5010
int d[2*N], n, k, a[N];

int main(){
	cin>>n>>k;
	rep(i, n) cin>>a[i];
	sort(a, a+n); reverse(a, a+n);
	int r = k;
	d[0] = 1;
	rep(i, n){
		if(a[i]>=k) continue;
		for(int j = k+a[i]-1; j >= a[i]; j--){
			if(j>=k && d[j-a[i]]==1) r = a[i];
			d[j] |= d[j-a[i]];
		}
	}
	ll res = 0;
	rep(i, n) if(a[i]<r) res++;
	cout<<res<<endl;
	return 0;
}


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

const int N = 2e5 + 5;
int n, a[N], q[N], cnt;

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	for (int i = 2; i <= n; ++i)
		if (a[i] == a[i - 1])
			q[++cnt] = a[i], ++i;
	cout << (long long)q[cnt] * q[cnt - 1] << endl;
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
using namespace std;

int main(){
  int h,w;
  int i,j;
  int flag;
  while(cin>>h>>w,h|w){
    int taikaku;
    int tmph=1111,tmpw=1111;
    taikaku=h*h+w*w;
    flag=false;
    for(i=1;i<150;i++){
      for(j=1;j<150;j++){
	//if(i==4&&j==8) cout<<"a"<<endl;
	if(i>=j||(i==h&&j==w)) continue;
	if(i*i+j*j==taikaku) {
	  if(h<i){
	    tmph=i;
	    tmpw=j;
	    flag=true;
	    break;
	  }
	}
	else if(i*i+j*j>taikaku&&i*i+j*j<tmph*tmph+tmpw*tmpw) {
	  tmph=i;
	  tmpw=j;
	}
      }
      if(flag) break;
    }
    cout<<tmph<<" "<<tmpw<<endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main(void){
	string s;
	cin >> s;
	for(int i=0;i<s.length()-8;i++){
		cout << s.at(i) ;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def count(N,a,b):
    a_c = N//a+1
    b_c = N//b+1
    lcm = a*b//gcd(a,b)
    ab_c = N//lcm+1
    return a_c+b_c-ab_c

A,B,C,D = map(int,input().split())
print(B+1-count(B,C,D)-(A-count(A-1,C,D)))

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

string s;
const int M = 1000000007;
map<char, int> m;
int n;
int main()
{
    cin >> n >> s;
    for (int i = 0; i < s.length(); i++)
    {
        m[s[i]]++;
    }
    map<char, int>::iterator p;
    long long int ans = 1;
    for (p = m.begin(); p != m.end(); p++)
    {
        ans *= p->second + 1;
        ans %= M;
    }
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
	int A,B,i;
	scanf("%d",&A);
	scanf("%d",&B);
	for(i=1;i<=10000;i++){
		if(A==(int)i*8/100&&B==(int)i/10)break;
	}
	if(i<=10000)printf("%d",i);
	else printf("-1");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin>>n;
    cout<<(n)*(n-1)/2<<endl;

    return 0;
}


Measured memory_bytes: 764
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		int N = (int)reader.nextLong();
		int[] A = new int[N];
		for (int i=0; i<N; i++) {
			A[i] = (int)reader.nextLong();
		}
		solver(N, A);
	}

	public static void solver(int N, int[] A) {
		ArrayList<Integer> L = new ArrayList<Integer>();
		for (int i=0; i<N; i++) {
			if (L.size() == 0) {
				L.add(A[i]);
			} else if (L.size() == 1){
				if (A[i] <= L.get(0)) L.set(0, A[i]);
				else L.add(A[i]);
			} else if(L.get(L.size() - 1) < A[i]){
				L.add(A[i]);
			} else {
				Integer[] list = L.toArray(new Integer[0]);
				int search = Arrays.binarySearch(list, A[i]);
				if (search < 0) {
					search = ~search;
					if (search == L.size()) L.add(A[i]);
					else L.set(search, A[i]);
				}
			}
		}
		System.out.println(L.size());
	}

	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}

		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

Measured memory_bytes: 91592
#include <iostream>
 
using namespace std;
 
int main(void)
{
int h,w;
cin >> h >> w;
 
string board[50];
 
for(int i=0;i<h;++i)
  cin>>board[i];
 
const int dx[8]={1,0,-1,0,1,-1,-1,1};//現在位置の周囲8マスを探索(縦dx,横dy)
const int dy[8]={0,1,0,-1,1,1,-1,-1};
 
for(int i=0;i<h;i++){
  for(int j=0;j<w;j++){
    if(board[i][j]=='#') continue;
	
    int num=0;
    for(int k=0;k<8;k++){
        const int ni=i+dx[k];
        const int nj=j+dy[k];
      
      if(ni<0 or h<=ni)continue;
      if(nj<0 or w<=nj)continue;
      if(board[ni][nj]=='#')num++;
    }
    board[i][j]=char(num+'0');    
        
 }
}
for(int i=0;i<h;i++)cout<<board[i]<<endl;
 
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Asum,Aprod,Aint;
int n;
string A,B;

ll nCr(int n, int r){
  static ll mem[20][20]={};
  if(mem[n][r]!=0)return mem[n][r];
  if(r==0||n==r)return 1;
  ll a=1;
  for(int i=0;i<r;i++) a*=(n-i);
  for(int i=0;i<r;i++) a/=(i+1);
  return mem[n][r]=a;
}

ll Sum(string str){
  ll res=0;
  for(int i=0;i<str.size();i++)res+=str[i]-'0';
  return res;
}

ll Prod(string str){
  ll res=1;
  for(int i=0;i<str.size();i++)res*=str[i]-'0'+1;
  return res;
}

ll Int(string str){
  ll res=0;
  for(int i=0;i<str.size();i++)res=res*10+str[i]-'0';
  return res;
}

ll permutation(string str){
  ll n=str.size(),res=1;
  for(int i=0,cnt=1;i<n;i++){
    if(str[i]==str[i+1])cnt++;
    else res*=nCr(n-i+cnt-1,cnt),cnt=1;
  }
  return res;
}

ll permutation(vector<int> a){
  string str;
  for(int i=0;i<a.size();i++)while(a[i]--)str+=(char)(i+'0');
  return  permutation(str);
}

ll count(){
  ll res=0,m;
  vector<int>t(10),cnt(10);
  for(int i=0;i<n;i++)t[B[i]-'0']++;
  cnt=t;
  for(m=0;m<n&&t[A[m]-'0'];t[A[m++]-'0']--);
  
  for(int i=0;i<=m;i++){
    for(int j=0;j<A[i]-'0';j++)
      if(cnt[j])cnt[j]--,res+=permutation(cnt),cnt[j]++;
    cnt[A[i]-'0']--;
  }
  return res;
}



ll calc(){
  if(Asum!=Sum(B)) return (Sum(B)<Asum)*permutation(B);
  if(Aprod!=Prod(B))return (Prod(B)<Aprod)*permutation(B);
  return count();
}

ll dfs(int idx,int num,int sum){
  if(idx==n) return calc();
  if(num==10||idx==n) return 0;
  ll res=dfs(idx,num+1,sum);
  B[idx]=num+'0';
  return res+dfs(idx+1,num,sum+num);
}

int main(){
  cin>>A;
  n=A.size();
  Asum=Sum(A),Aprod=Prod(A),Aint=Int(A);
  B.resize(n);
  cout<<dfs(0,0,0)<<endl;
  return 0;
}

Measured memory_bytes: 3176
// finish date: 2018/01/06
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <limits>
#include <map>

using namespace std;

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

bool isExist(char c, string str) {
    rep(i, str.length()) {
        if (c == str[i]) return true;
    }
    return false;
}

int main() {
    int N;
    cin >>N;
    vector<int> d(101,0);
    int a;
    rep(i,N){
        cin >> a;
        d[a] = 1;
    }
    int sum = 0;
    rep(i,d.size()) sum += d[i];
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll ans=0;
    while(1){
        ll idx=max_element(ALL(a))-a.begin();
        if(a[idx]<n){
            cout<<ans<<endl;
            return 0;
        }
        ll p=a[idx]/n;
        ans+=p;
        a[idx]%=n;
        rep(i,n){
            if(i==idx) continue;
            a[i]+=p;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S, T; cin >> S >> T;
  int A, B; cin >> A >> B;
  string U; cin >> U;
  if(U == S){
    A--;
  }else{
    B--;
  }
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s == "Sunny")
    cout << "Cloudy" << endl;
  else if (s == "Cloudy")
    cout << "Rainy" << endl;
  else
    cout << "Sunny" << endl;
}

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

int main (){
    int n ;
    cin >> n ;
    vector<int> a (n) ;
    vector<int> b (n) ;
    vector<int> c (n) ;

    rep(i, n){
        cin >> a[i] ;
    }
    rep(i, n){
        cin >> b[i] ;
    }
    rep(i, n){
        cin >> c[i] ;
    }
    sort(a.begin(), a.end()) ;
    sort(b.begin(), b.end()) ;
    sort(c.rbegin(), c.rend()) ;
    ll ans = 0 ;
    rep(i, n){
        int k = b[i] ;
        ll lb = -1, ub = n  ;
        while (ub - lb > 1){
            int mid = (lb + ub)/2 ;
            if(c[mid] > k){
                lb = mid ;
            }
            else {
                ub = mid ;
            }
        }
        ll llb = -1, uub = n ;
        while(uub - llb > 1){
            int mid = (llb + uub) /2 ;
            if(a[mid] < k){
                llb = mid ;
            }
            else {
                uub = mid ;
            }
        }
        ans += (lb + 1) * (llb + 1) ;
    }      
    cout << ans << endl ;

}

Measured memory_bytes: 4596
/*
	ID: sixathofpain
	TASK: friday
	LANG: C++   

*/


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 998244353;
const int N = int(3e5) + 999;
#define int long long int

void print0(int x=0){
	cerr<<x<<endl;
	cout<<0<<endl;
	exit(0);
}
map<int,int> mp;

int32_t main(){
    IOS;
		
	int n,k;
	cin>>n>>k;
	int arr[n];
	int mn = n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		mn=min(arr[i],mn);
	}

	for(int i=1;i<=k and mn<n;i++){

		int tmp[n+1]={0};
		for(int j=0;j<n;j++){
			int l = max(0LL,j-arr[j]);
			int r = min(n,j+arr[j]);
			tmp[l]++;
			tmp[r+1]--;
		}
		mn = tmp[0];
		arr[0]=tmp[0];
		// int s=tmp[0];
		for(int j=1;j<n;j++){
			tmp[j]+=tmp[j-1];
			mn = min(mn,tmp[j]);
			arr[j]=tmp[j];
		}
		
	}

	for(auto it:arr)
		cout<<it<<" ";
	cout<<endl;


    return 0;
}

Measured memory_bytes: 6736
#include <bits/stdc++.h>
using namespace std;
const double pi=2*acos(0.0);
double inff=1.0/0.0;
#define ll           long long int
#define inf          1000000000LL
#define MOD          1000000007
#define pb           push_back
#define sz(x)        (int)x.size()
#define mp           make_pair
#define lbd          lower_bound
#define ubd          upper_bound
#define ipair        pair<ll,ll> 
#define all(v)       v.begin(),v.end()
#define watch(x)     cout<<(#x)<<" is "<<(x)<<endl;
#define rep(a,b,c)   for(a=(int)b;a<(int)c;a++)
#define rep2(a,b,c)  for(a=(int)b;a<(int)c;a+=2)  
#define bac(a,b,c)   for(a=(int)b;a>=(int)c;a--)
#define se           second
#define f            first
#define ios          ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
#define mem(a,val)   memset(a,val,sizeof a)
#define endl         "\n"
#define mxn          100005
#define vi           vector<ll>
#define vii          vector<ipair> 
#define si           set<ll> 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*Variables Start*/
ll x,y,n,i,z,j,k,w,u,q,m,t;
vi adj[mxn];vi root;ll vis[mxn],indeg[mxn],dp[mxn];
/*Variables End*/
void dfs(ll src)
{
  for(auto a:adj[src])
  {
    vis[a]++;
    dp[a]=max(dp[a],dp[src]+1);
    if(vis[a]==indeg[a]) dfs(a);
  }
}
void solve()
{
  cin>>n>>m;
  rep(i,0,m)
  {
    cin>>x>>y;
    adj[x].pb(y);
    indeg[y]++;
  }
  rep(i,1,n+1) if(!indeg[i]) root.pb(i);
  for(auto a:root)
  {
    dfs(a);
  }
  cout<<*max_element(dp+1,dp+1+n)<<endl;
}
int main() 
{ 
  int TESTS=1;
  ios;
  while(TESTS--)
  {
    solve();
  }  
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAX = 100001;
int n, k,arr[MAX], dp[MAX];
 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  cin >> n >> k;
  
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = 0;
  
  for(int i=0;i<n;i++)cin>>arr[i];
  for(int i=0;i<n;i++){
    for(int j=1;j<=k && i+j<n;j++){
      dp[i+j]=min(dp[i+j],dp[i]+abs(arr[i+j]-arr[i]));
    }
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, h, w;
    cin >> n >> h >> w;
    cout << (n-h+1)*(n-w+1) << endl;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int n= sc.nextInt(),maxv=0,min=0,x;
        for(int i=0;i<n;i++){
            if(i==0){min=sc.nextInt();continue;}
            if(i==1){x=sc.nextInt();maxv=x-min;min=Math.min(x,min);continue;}
            x=sc.nextInt();
            maxv=Math.max(maxv,x-min);min=Math.min(min,x);
        }
    System.out.println(maxv);
    }    
}


Measured memory_bytes: 99288
for a in iter(input,'0 0'):
 m=[input()for _ in[0]*int(a.split()[0])]
 y=x=0;s={(0,0)}
 while 1:
  u,v=x,y
  c=m[y][x]
  if c=='>':x+=1;
  if c=='v':y+=1;
  if c=='<':x-=1;
  if c=='^':y-=1;
  if c=='.':print(x,y);break
  if (x,y)in s:print('LOOP');break
  else:s|={(x,y)}


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

#define reg register

using namespace std;

string s;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0); 
	cin>>s;
	if(s=="AAA" || s=="BBB") puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 256
package main

import (
"fmt"
)

func main() {
	var N, Q int
	var S string
	fmt.Scan(&N, &Q, &S)

	ar := make([]int, N)
	bk := 'X'
	sum := 0
	for i, v := range S {
		if bk == 'A' && v == 'C' {
			sum++
		}
		ar[i] = sum
		bk = v
	}
	for i := 0; i < Q; i++ {
		var l, r int
		fmt.Scan(&l, &r)
		fmt.Println(ar[r-1] - ar[l-1])
	}
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

ll solve() {
    ll H, W, D, Q, a;
    cin >> H >> W >> D;
    ll HW = H * W;
    vector<pii> va(HW+1);
    for ( int h = 0; h < H; h++ ) {
        for ( int w = 0; w < W; w++ ) {
            cin >> a;
            va[a] = pii(h,w);
        }
    }
    cin >> Q;
    vector<ll> L(Q), R(Q);
    for ( int i = 0; i < Q; i++ ) {
        cin >> L[i] >> R[i];
    }
    
    vector<ll> ca(HW+1);
    ll cur = 0;
    for ( ll a = 0; a < HW+1; a++ ) {
        ll b = a - D;
        if ( b >= 1 ) {
            ca[a] = ca[b] + abs(va[a].first - va[b].first) + abs(va[a].second - va[b].second);
        }
    }
    vector<ll> ans(Q);
    for ( int q = 0; q < Q; q++ ) {
        ans[q] = ca[R[q]] - ca[L[q]]; 
    }

    for ( int q = 0; q < Q; q++ ) {
        cout << ans[q] << "\n";
    }
    
    return 0;
}

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

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

template<typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template<int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; }
    ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; }
    ModInt& operator*=(ModInt rhs) { x = (unsigned long long) x * rhs.x % mod; return *this; }
    ModInt& operator/=(ModInt rhs) { x = (unsigned long long) x * rhs.inv().x % mod; return *this; }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) { s << a.x; return s; }
    friend istream& operator>>(istream& s, ModInt<mod>& a) { s >> a.x; return s; }
};

using mint = ModInt<1000000007>;

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

    int n, k;
    cin >> n >> k;

    vector<int> as(n);
    for (int i = 0; i < n; i++) cin >> as[i];

    mint ans = 0;
    vector<int> bs = as;
    sort(bs.begin(), bs.end());

    for (int i = 0; i < n; i++) {
        int a = as[i];
        int tmp = 0;
        for (int j = i + 1; j < n; j++) {
            if (as[j] < a) tmp++;
        }
        ans += 1ll * tmp * k;
        int cnt = lower_bound(bs.begin(), bs.end(), a) - bs.begin();
        ans += mint(1) * cnt * k * (k - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main(void) {

	string S, T;

	cin >> S >> T;

	int ans = 0;

	for (int i = 0; i <= 2; i++) {
		if (S[i] == T[i]) { ans++; }
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3","unroll-loops")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)

//{
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();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int n,m,k,a,b,c,ans,w,h;
string s,t;

main(){
	cin>>n>>w>>h;
	dump((n-w+1)*(n-h+1));
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }
    
    int sum[n];
    for(int i = 0; i < n; i++) {
        sum[i] = 0;
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(j <= i) {
                sum[i] += a[j];
            }
            if(j >= i) {
                sum[i] += b[j];
            }
        }
    }
    sort(sum,sum+n,greater<int>());
    cout << sum[0];
    return 0;
}



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

int main(){
	long long int   N;
	string S;
	cin >> S;
	
  	if(S == "RRR") cout << 3 << endl;
  	else if (S == "RRS" || S == "SRR") cout << 2 << endl;
  	else if (S == "RSS" || S == "SRS" || S == "SSR" || S == "RSR") cout << 1 << endl;
  	else cout << 0 << endl;
  
}


Measured memory_bytes: 3588
l = []
n = int(input())
for i in range(n):
    key, val = input().split()
    val = int(val)
    l.append((key, val, i+1))

for key in sorted( list(set([i[0] for i in l])) ):
    for i in sorted(l, key=lambda x: x[1],reverse=True):
        if key == i[0]:
            print(i[2])
    


Measured memory_bytes: 3060
#include <stdio.h>
#define MAX 25
#define NIL -1

typedef struct node{
  int left;
  int right;
  int p;
}Node;

Node tree[MAX];
int D[MAX];
int H[MAX];

int depth(int u , int p){
  D[u] = p;
	if (tree[u].right != NIL)
		depth(tree[u].right, p + 1);
	if (tree[u].left != NIL)
		depth(tree[u].left, p + 1);
}

int height(int u){
  int h1, h2;
  h1 = h2 = 0;
  if (tree[u].left != NIL)
    h1 = height(tree[u].left) + 1;
  if (tree[u].right != NIL)
    h2 = height(tree[u].right) + 1;
  if(h1 >= h2)return H[u] = h1;
  else return H[u] = h2;
}

int main(){
  int n;
  int i;
  int degree[MAX]={};
  int id;
  int l;
  int r;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    tree[i].left = NIL;
    tree[i].right = NIL;
    tree[i].p = NIL;
  }
  //set tree
  for(i = 0 ; i < n ; i++){
    scanf("%d" , &id);
    scanf("%d" , &l);
    scanf("%d" , &r);
    degree[id] = 0;

    if(l != NIL){
      tree[id].left = l;
      tree[l].p = id;
      degree[id] += 1;
    }
    if(r != NIL){
      tree[id].right = r;
      tree[r].p = id;
      degree[id] += 1;
    }
  }

  //find root
  int root = 0;
  while (tree[root].p != NIL) {
		root = tree[root].p;
	}

  depth(root , 0);
  height(root);

  //print out
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, ", i , tree[i].p);
    if(tree[i].p != NIL){
      if(tree[ tree[i].p ].left == i)printf("sibling = %d, " , tree[ tree[i].p ].right);
      else printf("sibling = %d, " , tree[ tree[i].p ].left);
    }
    else printf("sibling = -1, ");

    printf("degree = %d, depth = %d, height = %d, ",degree[i],D[i],H[i]);
    if(tree[i].p == NIL)printf("root\n");
    else if(degree[i] != 0)printf("internal node\n");
    else printf("leaf\n");
  }

  return 0;
}



Measured memory_bytes: 2104
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

class UnionFind:
    """ Union-Find木 """

    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n
        self.tree = [True] * n
        self.grpcnt = n

    def find(self, x):
        """ 根の検索(グループ番号の取得) """
        t = []
        while self.par[x] != x:
            t.append(x)
            x = self.par[x]
        for i in t:
            self.par[i] = x
        return self.par[x]

    def union(self, x, y):
        """ 併合 """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            self.tree[x] = False
            return
        if not self.tree[x] or not self.tree[y]:
            self.tree[x] = self.tree[y] = False

        self.grpcnt -= 1
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def is_same(self, x, y):
        """ 同じ集合に属するか判定 """
        return self.find(x) == self.find(y)

    def get_size(self, x=None):
        if x is not None:
            """ あるノードの属する集合のノード数 """
            return self.size[self.find(x)]
        else:
            """ 集合の数 """
            return self.grpcnt
    
    def is_tree(self, x):
        """ 木かどうかの判定 """
        return self.tree[self.find(x)]

N, M = MAP()
A = LIST()
uf = UnionFind(N)
for i in range(M):
    a, b = MAP()
    uf.union(a, b)

L = uf.get_size()
K = (L-1) * 2 
if K > N:
    print('Impossible')
    exit()
elif K == 0:
    print(0)
    exit()

adjli = [[] for i in range(N)]
for i in range(N):
    root = uf.find(i)
    adjli[root].append(A[i])

ans = 0
B = []
for i in range(N):
    if adjli[i]:
        adjli[i].sort(reverse=1)
        ans += adjli[i].pop()
        B += adjli[i]
        K -= 1

B.sort()
ans += sum(B[:K])
print(ans)


Measured memory_bytes: 28928
a, b, c, d = map(int, input().split())
cc, dd, e = c, d, 1
for i in range(2, int(min(cc, dd)**0.5) + 1):
    if cc%i == 0 and dd%i == 0:
        while cc%i == 0 and dd%i == 0:
            cc //= i
            dd //= i
            e *= i
e *= cc*dd
print(b-a+1 - b//c + (a-1)//c - b//d + (a-1)//d + b//e - (a-1)//e)

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

using namespace std;

int h,n;

void solve(){
    int i,j;
    string str;
    cin >> h >> n;
    long long ans = 0;
    for(i = 0;i < n;i++){
        cin >> j;
        ans += j;
    }
    if(ans < h){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}

int main(){
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
    int ans = 0, len = 0;
    string input;
    cin >> input;
    for (int i = 0; i < input.size(); i++)
    {
        if (input[i] == 'A' || input[i] == 'C' || input[i] == 'G' || input[i] == 'T')
        {
            len++;
        }
        else
        {
            if (ans < len) ans = len;
            len = 0;
        }
    }
    if (ans < len) ans = len;
    cout << ans;
}

Measured memory_bytes: 3624
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
t = S()
ans = 0
for i in range(len(s)):
    if s[i] != t[i]:
        ans += 1
print(ans)

Measured memory_bytes: 75676
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int n;
  vector<ll> a;
  
  cin >> n;
  
  while (n--) {
    ll k;
    cin >> k;
    a.pb(k);
  }
  
  for (int i = 0; i < a.size()-1; ++i) {
    if (i == 0) {
      a[i]--;
    } else {
      if (a[i]-1 >= a[i-1]) {
        a[i]--;
      }
      /*
      if (a[i] < a[i+1]) {
        if (a[i]-1 >= a[i-1]) {
          a[i]--;
        }
      } else if (a.at[i] == a.at[i+1]) {
        if (a[i]-1 >= a[i-1]) {
          a[i]--;
        } else {
          // not possible
          // ex: 3 2 2 -> 2 2 2 -> 2 1 2?
        }
      } else {
        if (a[i]-1 <= a[i+1]) {
          if (a[i]-1 >= a[i-1]) {
            a[i]--;
          } else {
            // not possible
            // ex: 4 3 2 -> 2 3 2 
          }
        } else {
          // not possible
          // ex: 4 2 -> 3 2?
        }
      }
      */
    }
  }
  
  bool res = true;
  
  for (int i = 0; i < a.size()-1; ++i) {
    if (a.at(i) > a.at(i+1)) {
      res = false;
    }
  }
  
  if (res) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  
  cout << endl;
  return 0;
}

Measured memory_bytes: 4264
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector< int > z_algorithm(const string &s) {
  vector< int > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}
string s, s1;
int n, m;
vector<int> v;
int main()
{
  cin>>s;
  n=s.size()/2;
  s1=s.substr(0, n);
  ll l, r;
  cin>>l>>r;
  l--;
  v=z_algorithm(s1);
  int d=0;
  for(int k=1; k<n; k++){
    if(n%k!=0) continue;
    if(v[k]==n-k){
      d=k;
      break;
    }
  }
  for(int i=1; i<n; i++){
    if(v[i]==n-i){
      m=i; break;
    }
  }
  if(m==0) d=n;
  if(d){
    ll cnt[26]={};
    for(int i=0; i<d; i++){
      cnt[s[i]-'a']+=(r-1-i+d)/d;
      cnt[s[i]-'a']-=(l-1-i+d)/d;
    }
    for(int i=0; i<26; i++){
      cout<<cnt[i]<<" ";
    }
    cout<<endl;
    return 0;
  }
  ll cnt[26]={};
  ll xl[100];
  xl[0]=n-m, xl[1]=m;
  ll xc[100][26]={};
  for(int i=0; i<n; i++){
    if(i<m) xc[1][s[i]-'a']++;
    else xc[0][s[i]-'a']++;
  }
  int c=2;
  const ll MAX=1e18;
  for(int i=2; i<100; i++){
    if(xl[i-1]>MAX){
      c=i; break;
    }
    xl[i]=xl[i-1]+xl[i-2];
    for(int j=0; j<26; j++){
      xc[i][j]=xc[i-1][j]+xc[i-2][j];
    }
  }
  auto solve=[&](auto solve, ll k, bool myon)->void{
    if(k<=n){
      for(int i=0; i<k; i++){
        if(myon) cnt[s[i]-'a']++;
        else cnt[s[i]-'a']--;
      }
      return;
    }
    int t=upper_bound(xl+2, xl+c, k)-xl-1;
    for(int i=0; i<26; i++){
      if(myon) cnt[i]+=xc[t][i];
      else cnt[i]-=xc[t][i];
    }
    solve(solve, k-xl[t], myon);
  };
  solve(solve, r, 1);
  solve(solve, l, 0);
  for(int i=0; i<26; i++){
    cout<<cnt[i]<<" ";
  }
  cout<<endl;
	return 0;
}

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

typedef struct{
    int p;
    int l;
    int r;
}Node;

Node node[28];

void preParse(int u){
    if (u == -1) return;
    printf(" %d", u);
    preParse(node[u].l);
    preParse(node[u].r);
}
void inParse(int u){
    if (u == -1) return;

    inParse(node[u].l);
    printf(" %d", u);
    inParse(node[u].r);
}
void postParse(int u){
    if (u == -1) return;

    postParse(node[u].l);
    postParse(node[u].r);
    printf(" %d", u);
}


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

    for(int i=0; i<n; i++){
        node[i].p = -1;
    }

    int id;
    for(int i=0; i<n; i++){
        scanf("%d", &id);
        scanf("%d %d", &node[id].l, &node[id].r);
        if(node[id].l!=-1 && node[id].r!=-1){
            node[node[id].l].p = id;
            node[node[id].r].p = id;
        }
        else{
            if(node[id].l!=-1 && node[id].r==-1){
                node[node[id].l].p = id;
            }
            if(node[id].l==-1 && node[id].r!=-1){
                node[node[id].r].p = id;
            }
        }
    }
    int root;
     for(int i=0;i<n;i++)if(node[i].p==-1)root=i;

     printf("Preorder\n");
    preParse(root);
    printf("\n");

     printf("Inorder\n");
    inParse(root);
        printf("\n");

     printf("Postorder\n");
    postParse(root);
        printf("\n");

    return 0;
}


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

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        String c[] = new String[3];
        c[0] = sc.next();
        c[1] = sc.next();
        c[2] = sc.next();
        for (int i = 0; i < 3; i++) {
            System.out.print(c[i].charAt(i));
        }
        System.out.println();
    }

}

Measured memory_bytes: 22228
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=3e5+10,M=3e5;
int n,k,f[N],t[N*4],ans;
void Change(int x,int L,int R,int pos,int val){
	if(L==R){
		t[x]=val;
		return;
	}
	int mid=(L+R)>>1;
	if(pos<=mid)Change(x*2,L,mid,pos,val);
	else Change(x*2+1,mid+1,R,pos,val);
	t[x]=max(t[x*2],t[x*2+1]);
}
int Ask(int x,int L,int R,int l,int r){
	if(L==l&&R==r)
		return t[x];
	int mid=(L+R)>>1;
	if(r<=mid)return Ask(x*2,L,mid,l,r);
	if(l>mid)return Ask(x*2+1,mid+1,R,l,r);
	return max(Ask(x*2,L,mid,l,mid),Ask(x*2+1,mid+1,R,mid+1,r));
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		int x;scanf("%d",&x);
		f[i]=Ask(1,1,M,max(1,x-k),min(M,x+k))+1;
		Change(1,1,M,x,f[i]);
		ans=max(ans,f[i]);
	}
	printf("%d",ans);
}

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

int main()
{
   // freopen("input.txt","r",stdin);
    ll a,b,c,d,e,f,g,h,k,l,m,n,x,y,z,x1,y1,z1,t,mx,mn;
    e=d=g=k=0;

    map<ll,ll>mp,pm;
    vector<ll>vp,vc;
    cin>>t;
     for(ll i=2;i<=t;i++)
     {
         cin>>c;
         mp[c]++;
     }
      for(ll i=1;i<=t;i++)
     {
         cout<<mp[i]<<endl;
     }
}


Measured memory_bytes: 16128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    vector <int> a(n), l(n, -1), r(n, n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    {
    vector <int> s;
    for (int i = 0; i < n; ++i) {
        while (s.size() && a[s.back()] > a[i]) {
            r[s.back()] = i;
            s.pop_back();
        }
        s.app(i);   
    }   
    }
    {
    vector <int> s;
    for (int i = n - 1; i >= 0; --i) {
        while (s.size() && a[s.back()] > a[i]) {
            l[s.back()] = i;
            s.pop_back();
        }   
        s.app(i);
    }   
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += (i - l[i]) * (r[i] - i) * a[i];
    }   
    cout << ans << endl;
}

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

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int count=0;
  int count_b=0;
  for(int i=0;i<n;i++){
    if(s.at(i) == 'a' && count < a+b){
      count++;
      cout << "Yes" <<endl;
    }
    else if (s.at(i) == 'b' && count < a+b && count_b < b){
      count++;
      count_b++;
      cout << "Yes" << endl;
    }
    else
      cout << "No" << endl;
  }      
}


Measured memory_bytes: 3748
//おまじない
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn=100000;

//UnionFind
class UnionFind {
public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;
    
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        
        A = root(A);
        B = root(B);
        if (A == B) {
            
            return false;
        }
        if (size(A) < size(B)) swap(A, B);
        
        Parent[A] += Parent[B];
        Parent[B] = A;
        
        return true;
    }
};

vector<pair<ll,pair<ll,int>>> edgh;
pair<ll,int> x[maxn];
pair<ll,int> y[maxn];
ll ans = 0;
int n;

int main(){
    
    cin >> n;
    rep(i,n){
        ll px,py;
        cin >> px >> py;
        x[i]=make_pair(px,i);
        y[i]=make_pair(py,i);
    }
    
    sort(x,x+n);
    sort(y,y+n);
    
    rep(i,n-1){
        ll cost = x[i+1].first-x[i].first;
        edgh.push_back(make_pair(cost,make_pair(x[i].second,x[i+1].second)));
    }
    
    rep(i,n-1){
        ll cost = y[i+1].first-y[i].first;
        edgh.push_back(make_pair(cost,make_pair(y[i].second,y[i+1].second)));
    }
    
    UnionFind Uni(n);
    
    sort(all(edgh));
    
    int cnt = 0;
    int idx = 0;
    //cout << edgh.size()<<endl;
    while(cnt<n-1){
        //cout << idx<<endl;
        if(Uni.root(edgh[idx].second.first)!=Uni.root(edgh[idx].second.second)){
            //cout << "Yes"<<endl;
            Uni.connect(edgh[idx].second.first,edgh[idx].second.second);
            ans += edgh[idx].first;
            cnt++;
        }
        //cout << "ans "<<ans<<endl;
        idx++;
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 11632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

#define debug printf("This is Debug")

using namespace std;

char mp[305][305]; 

int main(){
	
	int n;
	scanf("%d",&n);
	
	getchar();
	for(int i=0; i<n; ++i){
		for(int j=0;j<n;++j){
			scanf("%c",&mp[i][j]);
		}
		getchar();
	}
	int ans = 0;
	int flag = 0;
	for(int a=0; a<n; ++a){
	//	for(int b=0;b<n; ++b){
		int b = 0;
			
			for(int i=0; i<n;++i){
				for(int j=0;j<n;++j){
					if( mp[ (i+a)%n ][(j+b)%n] != mp[(j+a)%n][(i+b)%n]){
						flag = 1;
						
						break;
					}
					if(flag == 1) break;
				}
			}
			if(flag == 0){
				ans+= (n - a);
			}
			flag = 0;			 
	//	}
	}
	
	//for(int a=0; a<n; ++a){
	for(int b=1;b<n; ++b){
		int a = 0;
			
			for(int i=0; i<n;++i){
				for(int j=0;j<n;++j){
					if( mp[ (i+a)%n ][(j+b)%n] != mp[(j+a)%n][(i+b)%n]){
						flag = 1;
						
						break;
					}
					if(flag == 1) break;
				}
			}
			if(flag == 0){
				ans+= (n - b);
			}
			flag = 0;			 
	//	}
	}
	
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 512
W, H, N = gets.chomp.split.map(&:to_i)

ans = W * H
a1 = 0
a2 = W
a3 = 0
a4 = H
N.times do
  x, y, a = gets.chomp.split.map(&:to_i)
  if a == 1
    a1 = x if x > a1
  elsif a == 2
    a2 = x if x < a2
  elsif a == 3
    a3 = y if y > a3
  elsif a == 4
    a4 = y if y < a4
  end
end

puts [a2 - a1, 0].max * [a4 - a3, 0].max

Measured memory_bytes: 1788