akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it;}cout<<endl;}

int main() {
    ll n;
    cin>>n;
    vector<ll> v(n);
    rep(i, n) cin>>v[i];
    // prr(v);
    ll level = 1;
    rep(i, n) {
        if (i ==0)
        printf("node %ld: key = %ld, left key = %ld, right key = %ld, \n",i+1,v[i],v[(2*i+1)],v[(2*i+2)]);
        else if((2*i+2)<n)
        printf("node %ld: key = %ld, parent key = %ld, left key = %ld, right key = %ld, \n",i+1,v[i],v[(i+1)/2-1],v[(2*i+1)],v[(2*i+2)]);
        // cout << i+1 << " " << v[i] << " " << v[(2*i+1)] <<" "<< v[(2*i+2)] << endl;
        else if((2*i+1)<n)
        printf("node %ld: key = %ld, parent key = %ld, left key = %ld, \n",i+1,v[i],v[(i+1)/2-1],v[(2*i+1)]);
        // cout << i+1 << " " << v[i] << " " << v[(2*i+1)] << endl;
        else 
        printf("node %ld: key = %ld, parent key = %ld, \n",i+1,v[i],v[(i+1)/2-1]);
        // cout << i+1 << " " << v[i] << endl;
    }

}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(type)   std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
ll inf = 1e18;
vector<ll> v;
int main(){
	fast;
	ll n,k;cin>>n>>k;
	ll a[n+1];memset(a,0,sizeof(a));
	v.push_back(0);
	for(ll i=0;i<n;++i){
		ll k;cin>>k;
		v.push_back(k);
	}
	
	a[1] = 0;
	
	for(ll i=2;i<=n;++i){
		ll mn = MAX(ll);
		for(ll j=max(1ll,i-k);j<i;++j)
			mn = min(mn,abs(v[i]-v[j])+a[j]);
		a[i] = mn;
	}
	cout<<a[n];
	return 0;
}
/*

	for(ll i=1;i<=n;++i){
		cout<<a[i]<<" ";
	}
*/

Measured memory_bytes: 2168
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, l, i, j, t, a, b, count;
    int[] p;
    String[] d;
    String tmp;

    for(;;){
      n = sc.nextInt(); l = sc.nextInt();
      if(n == 0 && l == 0)break;
      d = new String[n]; p = new int[n];
      for(i = 0;i < n;i++){
        d[i] = sc.next(); p[i] = sc.nextInt();
      }
      a = -1; b = -1; count = 0;

      for(t = 0;;t++){
//        for(i = 0;i < n;i++)out.println(d[i] + p[i]);
        for(i = 0;i < n;i++){
          if("L".equals(d[i]))p[i]--;
          else p[i]++;
          if(p[i] == 0 || p[i] == l)count++;
        }
        for(i = 0;i < n;i++){
          for(j = i + 1;j < n;j++)if(p[i] == p[j]){
            tmp = d[i]; d[i] = d[j]; d[j] = tmp;
          }
        }
        if(count == n){
          for(i = 0;i < n;i++){
            if(p[i] == 0)a = i + 1;
            if(p[i] == l)b = i + 1;
          }
          break;
        }
      }


      if(a == -1)a = b;
      out.println((t + 1) + " " + a);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 22920
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, m; ll paths, mod = 1e9+7, memo[1002][1002];
char c[1002][1002];
ll fix_mod(ll x){
	return (mod + x % mod) % mod;
}
ll solve(int i, int j){
    if(c[i][j] == '#' || i >= n || j >= m) return 0;
    if(i == n-1 && j == m-1) return 1;
    if(memo[i][j] != -1) return memo[i][j];
    paths = fix_mod(solve(i, j+1) + solve(i+1, j));
    return memo[i][j] = paths;
}
int main()
{

    cin>> n>> m;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin>> c[i][j];
        }
    }
    memset(memo, -1, sizeof memo);
    cout<< solve(0, 0);
    return 0;
}


Measured memory_bytes: 9216
N = int(input())
a = input().split(" ")

def search():
	# import pdb; pdb.set_trace()
	search_start = 0
	for target in range(1, N+1):
		for j in range(search_start, N):
			if int(a[j]) == target:
				search_start = j + 1
				break
		else:
			# ここが実行できていると言うことは、右端まで探索が終わったということ
			# 従って、targetを返す必要がある
			if N != 1 and target == 1:
				return -1
			else:
				return N - (target - 1)
	else:
		# ここが実行できているということは、N個の数字全部の探索が終わったということ
		# すなわち、ブロックを壊す必要がない
		return 0
	return False

print(search())

Measured memory_bytes: 17980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int r,d,x;
  cin >> r >> d >> x;
  rep(i,10){
    cout << r*x-d << endl;
    x = r*x-d;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ri register int
using namespace std;
const int rlen = 1 << 20 | 5;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() (((ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin))), ib == ob ? -1 : *ib++)
#define pb push_back
#define rez resize
#define fi first
#define se second
typedef long long ll;
typedef pair <int, int> pii;
inline int read() {
  static int ans, f;
  static char ch;
  for (ans = 0, f = 1, ch = gc(); !isdigit(ch); ch = gc()) f ^= ch == '-';
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return f ? ans : -ans;
}
const int N = 2e5 + 5;
int n, a[N], m, mn[N][20], mx[N][20], Lg[N];
inline int qmn(int l, int r) {
  static int k;
  return k = Lg[r - l + 1], min(mn[l][k], mn[r - (1 << k) + 1][k]);
}
inline int qmx(int l, int r) {
  static int k;
  return k = Lg[r - l + 1], max(mx[l][k], mx[r - (1 << k) + 1][k]);
}
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  n = read(), m = read();
  for (ri i = 1; i <= n; ++i) mn[i][0] = mx[i][0] = a[i] = read();
  for (ri i = 2; i <= n; ++i) Lg[i] = Lg[i >> 1] + 1;
  for (ri j = 1; j < 20; ++j) for (ri i = 1; i + (1 << j) - 1 <= n; ++i) {
    mn[i][j] = min(mn[i][j - 1], mn[i + (1 << (j - 1))][j - 1]);
    mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]);
  }
  int res = 1, conc = 1;
  bool ff = 0;
  for (ri i = 2; i <= m; ++i) conc = a[i] > a[i - 1] ? conc + 1 : 1;
  if (conc == m) ff = 1;
  for (ri i = m + 1; i <= n; ++i) {
    conc = a[i] > a[i - 1] ? conc + 1 : 1;
    if (qmn(i - m, i) == a[i - m] && qmx(i - m, i) == a[i]) continue;
    if (conc >= m) {
      if (!ff) ff = 1, ++res;
      continue;
    }
    ++res;
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 37480
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int a,b;
  char op;
  cin >> a >> op >> b;
  while(op!='?'){
    int c;
    if(op=='+') c=a+b;
    if(op=='-') c=a-b;
    if(op=='*') c=a*b;
    if(op=='/') c=a/b;
    cout << c << endl;
    cin >> a >> op >> b;
  }
  return 0;
}



Measured memory_bytes: 3116
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]
count = 0
ans = 0
for i in range(n):
    for j in range(m):
        ans += a[i][j]*b[j]
    if ans + c > 0:
        count += 1
    ans = 0
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
	int q;
	int n;
	string s;
	string temp1,temp2;
	int num1,num2;
	int i1,i2;
	int max;
	int count;
	int check;

	cin >> q;

	for(i1=0;i1<q;i1++){
		cin >> n;

		vector<string> v;
		count = 0;
		check = 0;
		

		while(1){
			if(n/10==0) {
				check=1;
				break;
			}
			
			ostringstream ostr;
			ostr << n;
			s = ostr.str();

			if(!v.empty()){
				if(find(v.begin(), v.end(),s)!=v.end()) {
					check=8;
					break;
				}
			}

			v.push_back(s);
			max = 0;

			for(i2=1;i2<s.size();i2++){
				temp1 = s.substr(0,i2);
				temp2 = s.substr(i2);

				istringstream istr1(temp1);
				istr1 >> num1;
				istringstream istr2(temp2);
				istr2 >> num2;

				if(max<(num1*num2)) max = num1*num2;
			}

			n=max;
			count++;

		}

		if(check==8) cout << -1 << endl;
		else cout << count << endl;
	}
	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n,m;
  cin>>n>>m;
  vector<bool> broken(n+1);
  rep(i,m) {
    int a;
    cin>>a;
    broken[a]=true;
  }
  vector<ll> dp(n+1);
  const int p = 1e9+7;
  dp[0]=1;
  rep(i,n+1) {
    if(i+1<n+1&&!broken[i+1]) {
      dp[i+1]+=dp[i];
      dp[i+1]%=p;
    }
    if(i+2<n+1&&!broken[i+2]) {
      dp[i+2]+=dp[i];
      dp[i+2]%=p;
    }
  }
  cout << dp[n] << endl;
  return 0;
}


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

int main() {
	int n, l;
	cin >> n >> l;
	string inputs[n];
	for (int i = 0; i < n; i++) {
		cin >> inputs[i];
	}
	sort(inputs, inputs + n);
	for (int i = 0; i < n; i++) {
		cout << inputs[i];
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define N_MAX 2000002

using namespace std;
typedef long long ll;
int K;
string S;
const ll MOD = 1000000007;


ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

template <typename T>
T pow(T a, ll n) {
	T ans = 1;
	T tmp = a;
	for (int i = 0; i <= 60; i++) {
		ll m = (ll)1 << i;
		if (m & n) {
		ans *= tmp;
		ans %= MOD;
		}
		tmp *= tmp;
		tmp %= MOD;
	}
	return ans;
}

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll comb(ll n, ll r){
  ll ans;
  if(n < r){
      ans = 0;
  }else{
      ans = (fac[n]*finv[r])%MOD;
      ans = (ans*finv[n-r])%MOD;
      ans = (ans+MOD)%MOD;
  }
  return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    cin >> K >> S;
    ll N = S.size();
    ll ans = 0;
    for(int i = 0; i <= K; i++){
        ll p1 = pow<ll>(26, i);
        ll p2 = pow<ll>(25, K-i);
        ll cb = comb(N+K-i-1, N-1);
        ans += (((p1*p2)%MOD)*cb)%MOD; 
        ans %= MOD;
    }
    cout << ans << endl;
}

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

int main() {
 	string s;
  	cin >> s;
  	int n = s.size();
  	for(long long i = 0; i < n; i++) {
      	if(s[i] != s[n - i - 1]) {
          	cout << "No" << endl;
          	return 0;
        }
    }
  	long long x = (n - 1) / 2;
  	for(long long i = 0; i < x; i++) {
      	if(s[i] != s[x - i - 1]) {
          	cout << "No" << endl;
          	return 0;
        }
    }
  	x = (n + 3) / 2;
  	//cout << x << endl;
  	for(long long i = x - 1; i < n; i++) {
      	if(s[i] != s[n - i + x - 2]) {
          	cout << "No" << endl;
          	return 0;
        }
    }
 	cout << "Yes" << endl;
  	return 0;
}


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

using namespace std;

const int N = 2e5 + 5;
const int mod = 998244353;

void add (int &x, int y) {
    x = (x + y) % mod;
}

int dp[N][3][4][2];
string s;
bool a = false, b = false, c = false, adj = false;
set <string> res;

void bt (string s) {
    if (res.find(s) != res.end()) return;
    res.insert(s);

    for (int i = 1; i < s.length(); i++) {
        string t = s;
        if (t[i] != t[i - 1]) {
            if (t[i] == 'a' && t[i - 1] == 'b') t[i] = t[i - 1] = 'c';
            else if (t[i] == 'a' && t[i - 1] == 'c') t[i] = t[i - 1] = 'b';
            else if (t[i] == 'b' && t[i - 1] == 'c') t[i] = t[i - 1] = 'a';
            else if (t[i] == 'b' && t[i - 1] == 'a') t[i] = t[i - 1] = 'c';
            else if (t[i] == 'c' && t[i - 1] == 'a') t[i] = t[i - 1] = 'b';
            else t[i] = t[i - 1] = 'a';
        }
        bt(t);
    }
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> s;
    int sum = 0;
    for (int i = 0; i < s.length(); i++) a |= (s[i] == 'a'), b |= (s[i] == 'b'), c |= (s[i] == 'c'), sum += (s[i] - 'a');
    for (int i = 1; i < s.length(); i++) adj |= (s[i] == s[i - 1]);
    if ((a && !b && !c) || (!a && b && !c) || (!a && !b && c)) return cout << 1, 0;

    if (s.length() <= 3) {
        bt(s);
        cout << res.size();
    }
    else {
        dp[0][0][3][0] = 1;
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k <= 3; k++) {
                    for (int l = 0; l < 2; l++) {
                        if (dp[i][j][k][l]) {
                            for (int m = 0; m < 3; m++) {
                                add(dp[i + 1][(j + m) % 3][m][(k == m) | l], dp[i][j][k][l]);
                            }
                        }
                    }
                }
            }
        }

        int ans = 0;
        for (int i = 0; i < 3; i++) add(ans, dp[s.length()][sum % 3][i][1]);
        cout << ans + (!adj);
    }
    return 0;
}


Measured memory_bytes: 19348
#include<iostream>
#include<algorithm>
#define fs first
#define sc second
using namespace std;

typedef pair<short,short> P;
typedef pair<short,P> E;

short n,m,i,j,cnt;
E e[11000];
short par[110],rank[110];

inline int find(int x){
  if(par[x] == x)return x;
  return par[x] = find(par[x]);
}

inline void unite(int a,int b){
  a = find(a); b = find(b);
  if(a==b)return;
  if(rank[a]<rank[b])par[b] = a;
  else{
    par[a] = b;
    if(rank[a]==rank[b])rank[b]++;
  }
}

int main(){
  while(cin >> n >>m,n||m){
    for(i=0;i<m;i++)cin >> e[i].sc.fs >> e[i].sc.sc >> e[i].fs;
    sort(e,e+m);

    int res = -1;
    for(i=0;i<m;i++){
      for(j=1;j<=n;j++){par[j] = j; rank[j] = 0;}

      cnt = 0;
      for(j=i;j<m;j++){
	if(find(e[j].sc.fs)!=find(e[j].sc.sc)){
	  unite(e[j].sc.fs,e[j].sc.sc);
	  cnt++;
	  if(cnt==n-1)break;
	}
      }
      if(cnt==n-1 && (res<0 || res>e[j].fs-e[i].fs))res = e[j].fs-e[i].fs;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1228
<?php
list($Z1[0],$Z1[1],$Z2[0],$Z2[1]) = explode(" ",trim(fgets(STDIN)));
$x = $Z2[0] - $Z1[0];
$y = $Z2[1] - $Z1[1];
$Z3[0] = $Z2[0] - $y;
$Z3[1] = $Z2[1] + $x;
$Z4[0] = $Z3[0] - $x;
$Z4[1] = $Z3[1] - $y;
echo "$Z3[0]"." "."$Z3[1]"." "."$Z4[0]"." "."$Z4[1]";


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 300005;

int a[N], b[N];
vector<int> G[N];
int val[N << 2];
void update(int u, int l, int r, int x, int v) {
    if (l == r) {
        val[u] += v;
        return;
    }
    int mid = l + r >> 1;
    if (x <= mid)
        update(u << 1, l, mid, x, v);
    else
        update(u << 1 | 1, mid + 1, r, x, v);
    val[u] = max(val[u << 1], val[u << 1 | 1]);
}
int main() {
    int n, m, g;
    scanf("%d%d%d", &n, &m, &g);
    for (int i = 0; i < g; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        a[x]++;
        update(1, 1, m, y, 1);
        G[x].push_back(y);
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (auto y : G[i]) update(1, 1, m, y, -1);
        ans = max(ans, a[i] + val[1]);
        for (auto y : G[i]) update(1, 1, m, y, 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 25480
use proconio::{input, fastout};

#[fastout]
fn main() {
  input!{
    n:usize,
    l:[i64;n]
  }
  let mut ans = 0;
  for i in 0..n {
    for j in i+1..n {
        for k in j+1..n {
            if l[i] != l[j] && l[j] != l[k] && l[k] != l[i] && l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i] {
                ans += 1;
            }
        }
    }   
  }
  println!("{}",ans);
}


Measured memory_bytes: 2144
#include<stdio.h>

signed main()
{
  int r,d,x;
  scanf("%d %d %d",&r,&d,&x);

  for( int i = 0; i < 10; ++i ){
    printf("%d\n",( r * x ) - d );
    x = ( r * x ) - d;
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;

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

  int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << A[K-1] << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include <math.h>
using namespace std;

int main()
{
    int n, nh, ans = 0;
    string S;
    cin >> S;
    n = S.size();
    nh = n / 2;
    for(int i = 0; i < nh; ++i)
    {
        if(S.at(i) != S.at(n - i - 1)) ans++; 
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int q, x;
  char com[20];
  // 標準ライブラリよりlist を使用
  list<int> v;
  scanf("%d", &q);
  for ( int i = 0; i < q; i++ ) {
    scanf("%s", &com);
    if ( com[0] == 'i' ) {  // insert
      scanf("%d", &x);
      v.push_front(x);
    } else if ( com[6] == 'L' ) {  // deleteLast
      v.pop_back();
    } else if ( com[6] == 'F' ) {  // deleteFirst
      v.pop_front();
    } else if ( com[0] == 'd' ) {  // delete
      scanf("%d", &x);
      for ( list<int>::iterator it = v.begin(); it != v.end(); it++ )
        if ( *it == x ) {
          v.erase(it);
          break;
        }
    }
  }
  int i = 0;
  for ( list<int>::iterator it = v.begin(); it != v.end(); it++ ) {
    if ( i++ ) printf(" ");
    printf("%d", *it);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 33948
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    ans = 0
    cur = 1
    pre = A[0]
    for a in A[1:]:
        if pre == a:
            cur += 1
        else:
            ans += cur//2
            cur = 1
        pre = a
    else:
        ans += cur//2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
# encoding: utf-8
import sys
# input = sys.stdin.readline
inf = 10 ** 18

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())

S = list(input())
T = list(input())

y_t = y_b = sr
x_r = x_l = sc

ans = 'NO'
for i, (Si, Ti) in enumerate(zip(S, T)):
    # tak
    if Si == 'L':
        x_l -= 1
    elif Si == 'R':
        x_r += 1
    elif Si == 'U':
        y_t -= 1
    else:
        y_b += 1
    # check
    if x_l < 1: break
    if y_t < 1: break
    if x_r > W: break
    if y_b > H: break
    # aok
    if Ti == 'L':
        x_r = max(1, x_r - 1)
    elif Ti == 'R':
        x_l = min(W, x_l + 1)
    elif Ti == 'U':
        y_b = max(1, y_b - 1)
    else:
        y_t = min(H, y_t + 1)
else:
    ans = 'YES'
        
print(ans)

Measured memory_bytes: 6764
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const ll inf=1000000007;
const ll MOD=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};


int main(){
	string s;
	cin>>s;
	int S=0;
	int ans=0;
	rep(i,0,s.size()){
		ans++;
		if(s[i]=='S')S++;
		if(s[i]=='T'){
			if(S>0){
				S--;
				ans-=2;
			}
		}
	}
	print(ans);
}

	


Measured memory_bytes: 1156
// Aizu Vol0 0079: Area of Polygon
// 2017.7.29

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double area3(double x1, double y1, double x2, double y2, double x3, double y3)
{
	double a, b, c, z;

	a = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
	b = sqrt((x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3));
	c = sqrt((x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3));
	z = (a + b + c) / 2.0;
	return sqrt(z*(z - a)*(z - b)*(z - c));
}

int main()
{
	double x0, y0, x1, y1, x2, y2;
	double s;

	scanf("%lf,%lf", &x0, &y0);
	scanf("%lf,%lf", &x1, &y1);
	s = 0.0;
	while (scanf("%lf,%lf", &x2, &y2) == 2) {
		s += area3(x0, y0, x1, y1, x2, y2);
		x1 = x2, y1 = y2;
	}
	printf("%.8lf\n", s);
	return 0;
}

Measured memory_bytes: 656
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	if(b-a>=k*2){
		for(int i=0;i<k;i++){
			cout<<a+i<<endl;
		}
		for(int i=0;i<k;i++){
			cout<<b-k+1+i<<endl;
		}
	}else{
		for(int i=0;i<b-a+1;i++){
			cout<<a+i<<endl;
		}
	}
 
 
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int S=s.size();
    int T=t.size();
    vector<vector<int>> dp(S+1,vector<int> (T+1,0));
    for(int i=0;i<s.size()+1;i++)
    {
        for(int j=0;j<t.size()+1;j++)
        {
            if(i==0||j==0)
            {
                dp[i][j]=0;
            } 
            else if(s[i-1]==t[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    // for(int i=0;i<S+1;i++)
    // {   
    //     for(int j=0;j<T+1;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    string ans="";
    bool flag=1;
    for(int i=S;i>0;)
    {
        for(int j=T;j>0;)
        {
            if(s[i-1]==t[j-1])
            {
                ans+=s[i-1];
                i--;
                j--;
            }
            else 
            {
                if(i==0||j==0)
                {
                    break;
                    flag=0;
                }
                if(dp[i][j-1]>dp[i-1][j])
                {
                    j--;
                }
                else
                {
                    i--;
                }
            }
            if(i==0||j==0)
            {
                flag=0;
                break;
            }
        }
        if(flag==0)
        break;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}

Measured memory_bytes: 38312
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


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


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 998244353;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };
int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/


char mp[105][105];
int cnt[105][105];

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);


	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> mp[i][j];
			cnt[i][j] = INF;
		}
	}

	deque<pii> dq;

	dq.push_back(pii(0, 0));
	if (mp[0][0] == '#') {
		cnt[0][0] = 1;
	}
	else
	{
		cnt[0][0] = 0;
	}



	while (!dq.empty()) {

		int nowy = dq.front().first;
		int nowx = dq.front().second;
		dq.pop_front();
		if (cnt[nowy][nowx] == INF)continue;

		for (int i = 0; i < 2; i++)
		{
			int ny = nowy + dy2[i];
			int nx = nowx + dx2[i];

			if (0 <= ny && ny < h && 0 <= nx && nx < w) {

				if (mp[nowy][nowx] == '.') {

					if (mp[ny][nx] == '#') {//white to black
						if (cnt[ny][nx] > cnt[nowy][nowx] + 1) {

							cnt[ny][nx] = cnt[nowy][nowx] + 1;
							dq.push_back(pii(ny, nx));
						}
					}
					else
					{
						//white to white
						if (cnt[ny][nx] > cnt[nowy][nowx]) {

							cnt[ny][nx] = cnt[nowy][nowx];
							dq.push_front(pii(ny, nx));
						}

					}
				}
				else
				{
					//other
					if (cnt[ny][nx] > cnt[nowy][nowx]) {
						cnt[ny][nx] = cnt[nowy][nowx];
						dq.push_front(pii(ny, nx));
					}
				}
			}
		}
	}


	cout << cnt[h - 1][w - 1] << endl;




	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.length();
    bool maki=true;
    for(int i=0;i<n/2;i++){
    	if(s[i]!=s[n-i-1])maki=false;
    	if(s[i]!=s[(n-3)/2-i])maki=false;
    }
    for(int i=n/2+1;i<n;i++){
    	if(s[i]!=s[n-i-1])maki=false;
    }
    cout << ((maki)?"Yes":"No") <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
#define INF	100000000
#define pb	push_back
#define fi first
#define sec second
#define SS stringstream
using namespace std;
typedef pair<int, int> P;
typedef long long int	ll;

int sosuu[60001] = {false};

int main(){
	int a = 60000;
	int n;
	int x;
	x = floor(sqrt(a));
	for(long long int i = 2; i < x+1; i++){
		if(sosuu[i] == true){
			continue;
		}
		for(long long int j = 2*i; j < a+1; j = j+i){
			sosuu[j] = true;
		}
	}
	while(cin >> n){
		int s, l;
		for(int i = 1;; i++){
			if(sosuu[n-i] == false){
				s = n-i;
				break;
			}
		}
		for(int i = 1;; i++){
			if(sosuu[n+i] == false){
				l = n+i;
				break;
			}
		}
		cout << s << " " << l << endl;
	}
}

Measured memory_bytes: 1392
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int n; cin >> n;
	string s; cin >> s;

	vector<int> white(n, 0);
	white[0] = (s[0] == 'W');
	for (int i = 1; i <= n - 1; i++) white[i] = (white[i - 1] + (s[i] == 'W'));

	if (white[n - 1] == 0 or white[n - 1] == n) {
		cout << 0;
		return 0;
	}
	debug(white);

	int ans = INT_MAX;

	for (int i = 0; i <= n - 1; i++) {
		int left_w = white[i],
		    right_w = white[n - 1] - white[i],
		    left_r = i + 1 - left_w,
		    right_r = n - 1 - i - right_w;

		debug(i, left_w, left_r, right_w, right_r);

		int curr_cost = left_w + right_r - min(left_w , right_r);
		ans = min(ans, curr_cost);
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N; cin >> N;
  int ev = 0, od = 0;
  for(int i = 0; i < N; i++) {
    ll x;
    cin >> x;
    x % 2 == 0 ? ev++ : od++;
  }
  if(od % 2 == 1) cout << "NO" << endl;
  else cout << "YES" << endl;
}

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

typedef long long ll;

int a[1000005];
int K;

bool cmp(int a, int b)
{
	a=(a>K-a)?K-a:a;
	b=(b>K-b)?K-b:b;
	return a<b;
}

int main()
{
	int N;
	cin >> K;
	cin >> N;
	for(int i=1;i<=N;i++)
		cin >> a[i];
	sort(a+1, a+1+N);
	int  max1=0;
	for(int i=1;i<=N-1;i++)
	{
		 max1=max(max1, a[i+1]-a[i]);
	}
    int tem=a[1]+K-a[N];
	max1==max(max1,tem);
	max1=(max1>tem)?max1:tem;
	cout << K-max1;


	return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{

	ll N;
	cin >> N;
	ce(N*(N-1)/2)
    return 0;
}



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

using namespace std;
#define PI acos(-1)

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

	int num = 0;



	if (S[0] == 'R' || S[1] == 'R' || S[2] == 'R')
	{
		num = 1;
	}

	if ( S[1] == 'R' && S[0] == 'R'  )
	{
		num = 2;
	}
	if (S[1] == 'R' && S[2] == 'R')
	{
		num = 2;
	}
	if (S[0] == 'R' && S[1] == 'R' && S[2] == 'R')
	{
		num = 3;
	}
	
	cout << num;

	
}



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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  int i;
  for(i=0;i<n;i++){
    cin >> h.at(i);
  }
  
  int c,m;
  c=0,m=0;
  for(i=0;i<n-1;i++){
    if(h.at(i)>=h.at(i+1)){
      c++;
    }else{
      m=max(m,c);
      c=0;
    }
  }
  m=max(m,c);
  cout << m << endl;
}

Measured memory_bytes: 3800
import java.util.Scanner;

public class Main {

	static final long CONST = 1000000007;

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int numN = scan.nextInt();
		long numK = scan.nextLong();

		int[] numAList = new int[numN];

		int[] little1 = new int[numN];
		int[] little2 = new int[numN];

		for (int i = 0; i < numN; i++) {
			numAList[i] = scan.nextInt();
		}

		for (int i = 0; i < numN; i++) {
			int count = 0;
			for (int j = 0; j < numN; j++) {
				if (numAList[i] > numAList[j]) {
					count++;
				}
			}
			little1[i] = count;
		}

		for (int i = 0; i < numN; i++) {
			int count = 0;
			for (int j = i + 1; j < numN; j++) {
				if (numAList[i]> numAList[j]) {
					count++;
				}
			}
			little2[i] = count;
		}

		long sum1 = 0;
		long sum2 = 0;

		for (int i = 0; i < numN; i++) {
			sum1 += little1[i];
			sum2 += little2[i];
		}

		long result1 = ((long) sum1 * (((numK * (numK -1)) / 2L) % CONST)) % CONST;
		long result2 = ((long) sum2 * (numK % CONST)) % CONST;

		System.out.println((result1 + result2) % CONST);
	}
}


Measured memory_bytes: 25896
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}
/*
ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}*/
int main() {
	cin >> n;
	ll res = 0;
	for (ll i = 1; i <= n; i += 2) {
		ll cnt = 0;
		for (ll j = 1; j <= i; j += 2) {
			if (i % j == 0) {
				++cnt;
			}
		}
		if (cnt == 8) {
			++res;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 3692
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n + 1];
		int b[] = new int[n + 1];
		int pos;
		int cnt = 0;

		if (n % 2 == 0)
			pos = n / 2;
		else
			pos = n / 2 + 1;

		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
			if (i > pos) {
				b[i] = a[i];
				if(a[i]==1)cnt++;
			}
		}

		for (int i = pos; i >= 1; i--) {
			int ballCnt = 0;
			for (int j = i; j <= n; j += i)
				ballCnt += b[j];
			if (ballCnt % 2 != a[i]) {
				b[i] = 1;
				cnt++;
			}
		}
		System.out.println(cnt);
		for (int i = 1; i <= n; i++) {
			if (b[i] == 1)
				System.out.println(i);
		}
    }
}

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

int fact[200010], inv[200010], factinv[200010];
int nCr(int x, int y) {
    if(x<0 || y<0 || x<y) return 0;
    return 1LL*fact[x] * factinv[y] % mod * factinv[x-y]%mod;
}

int main(void){
    int H, W, A, B;

    fact[0] = 1;
    for(int i=1; i<200010; ++i) fact[i] = 1LL*fact[i-1]*i%mod;
    inv[1] = 1;
    for(int i=2; i<200010; ++i) inv[i] = 1LL*inv[mod%i] * (mod-mod/i) % mod;
    factinv[0] = 1;
    for(int i=1; i<200010; ++i) factinv[i] = 1LL*factinv[i-1]*inv[i]%mod;

    cin >> H >> W >> A >> B;
    int ret = 0;
    for(int i=0; i<W-B; ++i) {
        int res = 1LL * nCr(A+i-1, i) * nCr(W-i+H-A-2, H-A-1) % mod;
        ret = (ret+res)%mod;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

void swap(int *, int *);

int main()
{
int n, p[100002]={0}, cnt, i, min;

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

cnt = 0;
 for(i=1; i<=n-1; i++){
if(p[i] == i){
swap(&p[i], &p[i+1]);
cnt++;
}
 }
if(p[i] == i){
swap(&p[i-1], &p[i]);
cnt++;
}

printf("%d\n", cnt);

return 0;
}

void swap(int *x, int *y)
{
int t;
t = *x;
*x = *y;
*y = t;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
	int W, H, x, y, r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if ((x >= r && x <= W - r ) && (y >= r && y <= H - r))
		printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <string.h>

void MaxSort(char *s);
void MinSort(char *s);

int main(){
    char s[101], t[101];
    scanf("%s", s);
    scanf("%s", t);

    MinSort(s);
    MaxSort(t);

    printf((strcmp(s, t) < 0) ? "Yes\n" : "No\n");
    return 0;
}

void MaxSort(char *s){
    char tmp;
    int maxnum, n = strlen(s);
    for(int i = 0; i < n; i++){
        maxnum = i;
        for(int j = i; j < n; j++){
            if(s[j] > s[maxnum]){
                maxnum = j;
            }
        }
        tmp = s[i];
        s[i] = s[maxnum];
        s[maxnum] = tmp;
    }
}

void MinSort(char *s){
    char tmp;
    int minnum, n = strlen(s);
    for(int i = 0; i < n; i++){
        minnum = i;
        for(int j = i; j < n; j++){
            if(s[j] < s[minnum]){
                minnum = j;
            }
        }
        tmp = s[i];
        s[i] = s[minnum];
        s[minnum] = tmp;
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10;
ll A[N];
int main() {
	int n,k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> A[i];
	
	for (int i = k+1; i <= n; i++) {
		if (A[i] > A[i-k])
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 5192
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    println!("{}", n / 3);
}


Measured memory_bytes: 4352
#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; }

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

    int a[] = {1, 2, 3, 4, 5, 6, 7, 8};


    int tmp;
    vector<int> p, q;

    rep(i, n) {
        cin >> tmp;
        p.push_back(tmp);
    }

    rep(i, n) {
        cin >> tmp;
        q.push_back(tmp);
    }

    ll x, y;
    ll cnt = 0;
    do {
        bool flag_x=true, flag_y=true;
        rep(i, n) {
            if (p[i] != a[i]) flag_x = false;
            if (q[i] != a[i]) flag_y = false;
        }

        if (flag_x) x = cnt;
        if (flag_y) y = cnt;

        cnt++;
    } while (next_permutation(a, a+n));

    cout << abs(x-y) << endl;
            

}



Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int R,G,B,N;
	scan(R>>G>>B>>N);
	int ans=0;
	for(int r=0;r*R<=N;r++){
		for(int g=0;r*R+g*G<=N;g++){
			if((N-(r*R+g*G))%B==0) ans++;
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()

ll dfs(ll cur, vector<vector<ll>>& net){
    vector<ll> tmp;
    for(ll nxt : net.at(cur)){
        tmp.push_back(dfs(nxt, net));
    }
    sort(ALL(tmp));
    ll ans = tmp.size();
    for(ll i = tmp.size() - 1; i >= 0; --i){
        ans = max(tmp.at(i) + (ll)tmp.size() - i, ans);
    }
    return ans;
}

int main(){
    ll n;
    cin >> n;
    vector<vector<ll>> net(n);
    for(ll i = 1; i < n; ++i){
        ll ai;
        cin >> ai;
        ai--;
        net.at(ai).push_back(i);
    }
    cout << dfs(0, net) << endl;
    return 0;
}


Measured memory_bytes: 13568
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

vl search_(vl &A, vl &acc, ll s, ll e) {
  ll l = s;
  ll r = e;
  ll m = (l + r) / 2;

  vl pq(2);
  pq[0] = acc[m] - acc[s];
  pq[1] = acc[e] - acc[m];

  ll diffMin = abs(pq[0] - pq[1]);

  ll cnt = 0;

  while (l <= r) {
    cnt++;

    ll lSum = acc[m] - acc[s];
    ll rSum = acc[e] - acc[m];

    if (lSum < rSum) {
      l = ++m;
    } else {
      r = --m;
    }

    m = (l + r) / 2;

    ll pq0 = acc[m] - acc[s];
    ll pq1 = acc[e] - acc[m];
    if (abs(pq0 - pq1) < diffMin) {
      diffMin = abs(pq0 - pq1);
      pq[0] = pq0;
      pq[1] = pq1;
    }
  }

  return pq;
}

vl search(ll n, vl &A, vl &acc) {
  vl pqrs(4);

  vl pq = search_(A, acc, 0, n);
  vl rs = search_(A, acc, n, acc.size() - 1);

  pqrs[0] = pq[0];
  pqrs[1] = pq[1];
  pqrs[2] = rs[0];
  pqrs[3] = rs[1];

  return pqrs;
}

ll calc(vl pqrs) {
  ll maxN = max(max(pqrs[0], pqrs[1]), max(pqrs[2], pqrs[3]));
  ll minN = min(min(pqrs[0], pqrs[1]), min(pqrs[2], pqrs[3]));
  return maxN - minN;
}

void solve(long long N, std::vector<long long> A) {
  vl acc(N + 1);
  rep(n, 1, N + 1) { acc[n] = acc[n - 1] + A[n - 1]; }

  ll ans = INF;
  rep(n, 2, N - 1) {
    vl pqrs = search(n, A, acc);
    ans = min(ans, calc(pqrs));
  }
  print(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 3328