akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200010


int main() {
	char a[N];
	char b[N];
	char c[N];
	char d[N];
	f(i, N) {
		a[i] = 0;
		b[i] = 0;
		c[i] = 0;
		d[i] = 0;
	}
	bool ab[4000];
	bool ac[4000];
	bool bc[4000];
	f(i, 4000) {
		ab[i] = true;
		ac[i] = true;
		bc[i] = true;
	}
	int na, nb, nc;
	int x, y;
	int ans;
	bool v = true;
	ans = 0;
	scanf("%s", a);
	na = strlen(a);
	scanf("%s", b);
	nb = strlen(b);
	scanf("%s", c);
	nc = strlen(c);
	f(i, 6000) {
		d[i] = '?';
	}
	f(i, na)d[2000 + i] = a[i];
	f(i, 4000) {
		f(j, nb) {
			if ((b[j] != '?') && (d[i + j] != '?') && (b[j] != d[i + j])) {
				ab[i] = false;
				break;
			}
		}
	}
	f(i, 6000) {
		d[i] = '?';
	}
	f(i, na)d[2000 + i] = a[i];
	f(i, 4000) {
		f(j, nc) {
			if ((c[j] != '?') && (d[i + j] != '?') && (c[j] != d[i + j])) {
				ac[i] = false;
				break;
			}
		}
	}
	f(i, 6000) {
		d[i] = '?';
	}
	f(i, nb)d[2000 + i] = b[i];
	f(i, 4000) {
		f(j, nc) {
			if ((c[j] != '?') && (d[i + j] != '?') && (c[j] != d[i + j])) {
				bc[i] = false;
				break;
			}
		}
	}

	ans = na + nb + nc;
	f(i, 8000) {
		f(j, 8000) {
			v = true;
			x = i - 2000;
			if ((x >= 0) && (x < 4000)) {
				if (!ab[x])v = false;
			}
			x = j - 2000;
			if ((x >= 0) && (x < 4000)) {
				if (!ac[x])v = false;
			}
			x = j - i + 2000;
			if ((x >= 0) && (x < 4000)) {
				if (!bc[x])v = false;
			}
			if (v) {
				x = min(4000, min(i, j));
				y = max(4000 + na, max(i + nb, j + nc));
				ans = min(ans, y - x);
			}
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int dp[100001][3]={0};
int a[100001][3];
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //freopen("input1.txt","r",stdin);
    //freopen("output1.txt","w",stdout);
	int n;
	
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	}
	
	
	for(int j=0;j<3;j++)
		dp[0][j]=a[0][j];
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			int m=0;
			for(int k=0;k<3;k++){
				if(j!=k)m=max(m,dp[i-1][k]);
				
			}
			dp[i][j]=m+a[i][j];
		}
		
	}
	int m2=0;
	for(int j=0;j<3;j++)
		if(m2<dp[n-1][j])m2=dp[n-1][j];
	cout<<m2<<endl;		
		

    return 0;
}


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

int main(){
    string s, t;
    cin >> s;
    cin >> t;
    for(size_t i = 0; i < s.length(); i++)
    {
        if (t == s.substr(i, s.length()-i) + s.substr(0,i))
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cassert>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define FL "a"
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int mod=1e9+7;
inline ll read(){
  ll d=0,w=1;char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  if(ch=='-')w=-1,ch=getchar();
  while(ch<='9'&&ch>='0')d=d*10+ch-48,ch=getchar();
  return d*w;
}
inline void file(){
  freopen(FL".in","r",stdin);
  freopen(FL".out","w",stdout);
}

int n,c[N],t[N],pre[N],dp[N];
inline void upd(int &a,int b){a+=b;if(a>=mod)a-=mod;}

int main()
{
  n=read();
  for(int i=1;i<=n;i++)c[i]=read();
  for(int i=1;i<=n;i++){pre[i]=t[c[i]];t[c[i]]=i;}
  dp[0]=1;
  for(int i=1;i<=n;i++){
    upd(dp[i],dp[i-1]);
    if(pre[i]&&pre[i]!=i-1)
      upd(dp[i],dp[pre[i]]);
    //printf("dp[%d]=%d\n",i,dp[i]);
  }
  printf("%d\n",dp[n]);
  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include <climits>
#include<vector>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A[i];
	bool flag = true;
	int res = 0;
	while (flag) {
		flag = false;
		for (int i = N - 1;i > 0;i--) {
			if(A[i-1]>A[i]){
				int tmp = A[i];
				A[i] = A[i - 1];
				A[i - 1] = tmp;
				flag = true;
				res++;
			}
		}
	}
	REP(i, N) {
		if (i < N - 1)cout << A[i] << " ";
		else cout << A[i] << "\n";
	}
	cout << res << "\n";

	return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

int compare(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void)
{
    int n;
    scanf("%d",&n);
    if(n<=111)printf("111");
    else if(n<=222)printf("222");
    else if(n<=333)printf("333");
    else if(n<=444)printf("444");
    else if(n<=555)printf("555");
    else if(n<=666)printf("666");
    else if(n<=777)printf("777");
    else if(n<=888)printf("888");
    else if(n<=999)printf("999");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
    
    ll N,V; cin>>N>>V;
    vector<ll> a(N),b(N),c(N),d(N);
    REP(i,N)cin>>a[i];
    REP(i,N)cin>>b[i];
    REP(i,N)cin>>c[i];
    REP(i,N)cin>>d[i];
    
    map<ll,ll> cnt;
    REP(i,N)REP(j,N){
        ll sum = a[i] + b[j];
        if(cnt.find(sum)==cnt.end())cnt[sum] = 1;
        else cnt[sum] ++;
    }
    
    ll ans = 0;
    REP(i,N)REP(j,N){
        ll sum = c[i] + d[j];
        ans += cnt[V-sum];
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 128096
# Algorithms and Data Structures 1
# Selection Sort
# Name: Ryuya Asada
# ID: s1260064


def SelectionSort(A: list):
    number_of_actual_swaps = 0
    for i in range(0, len(A)):
        minj = i
        for j in range(i, len(A)):
            if A[j] < A[minj]:
                minj = j

        A[i], A[minj] = A[minj], A[i]
        if i != minj:
            number_of_actual_swaps += 1

    print(*A, sep=" ")
    print(number_of_actual_swaps)


def main():
    length = int(input())
    A = [int(e) for e in input().split()]
    SelectionSort(A)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  int h, w;
  cin >> h >> w;
  string a[h];
  rep (i, h) cin >> a[i];

  const int INF = 3000;

  vector<vector<int>> grid(h, vector<int>(w, INF));
  rep (i, h) rep (j, w) if (a[i][j] == '#') grid[i][j] = 0;

  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    if (i) {
      chmin(grid[i][j], grid[i - 1][j] + 1);
    }
    if (j) {
      chmin(grid[i][j], grid[i][j - 1] + 1);
    }
  }
  for (int i = 0; i < h; i++) for (int j = w - 1; j >= 0; j--) {
    if (i) {
      chmin(grid[i][j], grid[i - 1][j] + 1);
    }
    if (j != w - 1) {
      chmin(grid[i][j], grid[i][j + 1] + 1);
    }
  }
  for (int i = h - 1; i >= 0; i--) for (int j = 0; j < w; j++) {
    if (i != h - 1) {
      chmin(grid[i][j], grid[i + 1][j] + 1);
    }
    if (j) {
      chmin(grid[i][j], grid[i][j - 1] + 1);
    }
  }
  for (int i = h - 1; i >= 0; i--) for (int j = w - 1; j >= 0; j--) {
    if (i != h - 1) {
      chmin(grid[i][j], grid[i + 1][j] + 1);
    }
    if (j != w - 1) {
      chmin(grid[i][j], grid[i][j + 1] + 1);
    }
  }

  int ans = -1;
  rep (i, h) rep (j, w) chmax(ans, grid[i][j]);

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5248
#include<stdio.h>
int main(void)
{
	int i,j,count=0;
    long int n,m,min;
	scanf("%ld %ld",&n,&min);
	for(i=1;i<n;i++)
	{
		scanf("%ld",&m);
		if(m>min)
		{
			count++;
		}
		else min=m;
	}
	printf("%ld",n-count);
	return 0;
}

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

typedef long long ll;

string S;
int N;
int cnt[26], odd = 0;
vector<int> oppo;

struct BIT {
    vector<int> tree;
    void init() {
        tree = vector<int>(4*N, 0);
    }
    void upd(int idx, int val, int l, int r, int n) {
        if(idx < l || r < idx) return;
        if(l == r) {
            tree[n] += val;
            return;
        }
        int m = (l + r)>>1;
        upd(idx, val, l, m, 2*n);
        upd(idx, val, m + 1, r, 2*n + 1);
        tree[n] = tree[2*n] + tree[2*n + 1];
    }
    int quer(int a, int b, int l, int r, int n) {
        if(b < l || r < a) return 0;
        if(a <= l && r <= b) return tree[n];
        int m = (l + r)>>1;
        int L = quer(a, b, l, m, 2*n);
        int R = quer(a, b, m + 1, r, 2*n + 1);
        return L + R;
    }
} bit;

int main() {
    cin >> S;
    N = S.size();

    for(int i = 0; i < S.size(); i++) cnt[S[i] - 'a']++;
    for(int i = 0; i < 26; i++) if(cnt[i] % 2) odd++;
    if(odd > 1) {
        cout << -1;
        return 0;
    }

    oppo = vector<int>(N, -1);

    for(int i = 0; i < 26; i++) {
        int pos = (int)S.size() - 1;
        for(int j = 0; j < S.size() && j <= pos; j++) {
            if(S[j] - 'a' != i) continue;
            while(S[pos] - 'a' != i) pos--;
            oppo[j] = pos;
            oppo[pos] = j;
            pos--;
        }
    }

    ll ans = 0;

    bit.init();
    for(int i = 0; i < N; i++) {
        if(oppo[i] < i) {
            ans += bit.quer(oppo[i] + 1, N - 1, 0, N - 1, 1);
            bit.upd(oppo[i], -1, 0, N - 1, 1);
        }
        else if(oppo[i] > i) {
            bit.upd(i, 1, 0, N - 1, 1);
        }
    }
    bit.init();
    for(int i = 0; i < N; i++) {
        if(i <= oppo[i]) {
            ans += bit.quer(0, i - 1, 0, N - 1, 1) / (i == oppo[i]? 2 : 1);
        }
        if(i >= oppo[i]) {
            bit.upd(oppo[i], (i == oppo[i]? 1 : 2), 0, N - 1, 1);
        }
    }
    cout << ans;
}


Measured memory_bytes: 7556
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91
#include <algorithm>
#include <utility>
#include <vector>

namespace n91 {

template <class T> std::vector<T> divisors(const T &n) {
  std::vector<T> ret;
  T i = static_cast<T>(1);
  while (i * i < n) {
    if (n % i == static_cast<T>(0)) {
      ret.push_back(i);
      ret.push_back(n / i);
    }
    ++i;
  }
  if (i * i == n) {
    ret.push_back(i);
  }
  std::sort(ret.begin(), ret.end());
  ret.shrink_to_fit();
  return std::move(ret);
}

} // namespace n91

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <utility>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const double a = scan<double>();
  const double b = scan<double>();
  const double x = scan<double>() / a;
  double ans;
  if (2 * x >= a * b) {
    const double d = 2 * b - 2 * x / a;
    ans = std::atan(d / a);
  } else {
    const double d = 2 * x / b;
    ans = std::atan(b / d);
  }
  std::cout << std::setprecision(10) << ans / std::acos(-1) * 180 << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll n,m,N,k,X;
char vec[10][10];
bool vis[10][10];
ll call(ll pos,ll c)
{
    if(pos>N)
    {
        if((X-c)==k)
        {
            //cout<<c<<endl;
            return 1;
        }
        return 0;
    }
    ll a,b,i,x,l;
    vector<ll>v;
    x=0;
    if(pos<=n)
    {
        x=call(pos+1,c);
        a=0;
        for(i=1;i<=m;i++)
        {
            if(vec[pos][i]=='#' && vis[pos][i]==true)
            {
                a++;
                v.push_back(i);
                vis[pos][i]=false;
            }
        }
        x+=call(pos+1,c+a);
        l=v.size();
        for(i=0;i<l;i++)
        {
            b=v[i];
            vis[pos][b]=true;
        }
    }
    else
    {
        x=call(pos+1,c);
        a=0;
        for(i=1;i<=n;i++)
        {
            if(vec[i][pos-n]=='#' && vis[i][pos-n]==true)
            {
                a++;
                v.push_back(i);
                vis[i][pos-n]=false;
            }
        }
        x+=call(pos+1,c+a);
        l=v.size();
        for(i=0;i<l;i++)
        {
            b=v[i];
            vis[b][pos-n]=true;
        }
    }

    return x;
}
int main()
{
    ll a,b,c,d,e,i,j,l,x,y,t,p;
    cin>>n>>m>>k;
    N=n+m;
    X=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            cin>>vec[i][j];
            if(vec[i][j]=='#')
            {
                X++;
            }
        }
    }
    //cout<<X<<endl;
    //cout<<k<<endl;
    memset(vis,true,sizeof(vis));
    x=call(1,0);
    cout<<x<<endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s;
    cin >> s;
    int a=10000000,z;
    rep(i,s.size()){
        if(s[i] == 'A') a = min(a,i);
        else if(s[i] == 'Z') z = i;
    }
    cout << z - a +1 <<endl;
}

Measured memory_bytes: 640
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = list(map(int,ipt().split()))
    a.sort(reverse=True)
    d = defaultdict(int)
    ans = 0
    for i in a:
        if d[i]:
            ans += 1
            d[i] -= 1
        else:
            nl = len(format(i,"b"))
            d[(i^(2**(nl)-1))+1] += 1

    print(ans)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 128444
n, d = map(int, input().split())
p = []
count = 0

for i in range(n):
    x = list(map(int, input().split()))
    p.append(x)

for i in range(n):
    for j in range(i+1, n):
        # Check distance between p[i] and p[j]!
        # Check (p[i][0] - p[j][0])^2 + (p[i][1] - p[j][1])^2 is double of some int!
        total = 0
        for h in range(d):
            total += (p[i][h] - p[j][h]) ** 2

        pownum = total ** 0.5

        if pownum.is_integer():
            count += 1

print(count)


Measured memory_bytes: 38384
#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 oset tree < int ,  null_type ,  less ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define endl '\n'
#define int long long int
#define db long double
#define str string
#define mod 1000000007
#define ff first
#define ss second
#define PQi priority_queue<int>
#define Vi vector<int>
#define Si set<int>
#define Li list<int>
#define mk make_pair
#define pii pair<int,int>
#define all(x) (x.begin(),x.end())
#define pb(x) push_back(x)
#define For(i,n,s) for(int i=s;i<n;i++)
#define mat2D(T,r,c) vector<vector<int> > T(r,vector<int>(c))
#define vec2D vector<vector<int> >
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define getVal(x) {int val;cin>>val;x.pb(val);}
#define debug(x) {for(auto i :x) cout << i << " ";cout << endl;}

void solve(){
    int n;
    cin >> n;
    int a[100005];
    For(i,105,1){
        For(j,105,1){
            For(k,105,1){
                int v = (i*i+j*j+k*k+i*j+j*k+k*i);
                if (v < 100005){
                    a[v] += 1;
                }
            }
        }
    }
    For(i,n,0)
        cout << a[i+1] << endl;
}

int32_t main(){
    fastIO;
    solve();
    return 0;
}


Measured memory_bytes: 4136
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  int N, M;
  cin >> N >> M;
  if (abs(N-M)>1) {
    cout << 0 << '\n';
    return 0;
  }
  long ans = 1;
  if (N==M)
    ans *= 2;
  for (int i=1; i<=N; i++) {
    ans *= i;
    ans %= MOD;
  }
  for (int i=1; i<=M; i++) {
    ans *= i;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 1e5 + 5;

int n, k;
int a[N], dp[N];

void getDP() {
    for(int idx = 1; idx <= n; idx++) {
        int &sol = dp[idx];
        if(idx == 1) sol = 0;
        else {
            sol = INF;
            for(int i = 1; i <= k; i++) {
                if(idx >= i + 1) 
                    sol = min(sol, dp[idx - i] + abs(a[idx] - a[idx - i]));
            }
        }
    }
}

void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    getDP();
    cout << dp[n] << "\n";
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 4424
//File Name: arc082_a.cpp
  //Created Time: 2017年10月01日 星期日 17时27分10秒
                                   
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
int a[MAXN];
int main(){
	int n;
	scanf("%d",&n);
	for(int i(1),u;i<=n;++i){
		scanf("%d",&u);
		++a[u];
		++a[u + 1];
		++a[u + 2];
	}
	int res(0);
	for(int i(0);i<MAXN;++i)
		res = max(res,a[i]);
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
int a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll ans1=1,ans2=n;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ans1=i;
            ans2=n/i;
        }
    }
    ll ans3=ans1+ans2-2;
    cout<<ans3<<'\n';


}


Measured memory_bytes: 3644
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<28)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " <<  x << " " << y;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
struct Query {
    int a, b, c, d;
    Query(int aa = 0, int bb = 0, int cc = 0, int dd = 0)
    : a(aa), b(bb), c(cc), d(dd) {}
};

Query qs[55];
int N, M, Q;
long long ans = 0;
int nums[15];
vector<int> vec;
void dfs(int i) {
        if (vec.size() == N + 1) {
            long long summ = 0;
            for (int k = 1; k <= Q; ++k) {
                if (vec[qs[k].b] - vec[qs[k].a] == qs[k].c) {
                    summ += qs[k].d;
                }
            }
            ans = max(ans, summ);
            return ;
        } 
    for (int j = vec[i - 1]; j <= M; ++j) {
        vec.push_back(j);
        dfs(i + 1);
        vec.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin >> N >> M >> Q;
    for (int i = 1; i <= Q; ++i) {
        cin >> qs[i].a >> qs[i].b >> qs[i].c >> qs[i].d;
    }
    for (int i = 1; i <= M; ++i)
        nums[i] = i;
    vec.push_back(1);
    dfs(1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a[12];
	cin>>a;
	long long n,m,l=strlen(a),k=0;
	for(int i=0;i<1<<(l-1);i++)
	{
		m=0;
		n=0;
		for(int j=0;j<l;j++)
		{
			m=m*10LL;
			m+=a[j]-'0';
			if(j<l-1 && i>>j&1)
			{
				n+=m;
				m=0;
			}
		}
		n+=m;
		k=k+n;
	}
	cout<<k<<'\n';
	return 0;
}


Measured memory_bytes: 256
from collections import deque
N = int(input())
a = [int(i) for i in input().split()]
b = deque()
for i in range(N):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if N % 2 == 1:
    [print(b[i], end=' ') for i in reversed(range(len(b)))]
else:
    [print(b[i], end=' ') for i in range(len(b))]


Measured memory_bytes: 25532
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void)
{
    long long a,b,c;
    while(scanf("%lld%lld%lld",&a,&b,&c)==3)
    {
        long long ans;
        if(c % 2 == 0)
            ans = 0;
        else
            ans = a*b;
        if(a % 2 == 0)
            ans = 0;
        else
            ans = min(ans,b*c);
        if(b % 2 == 0)
            ans = 0;
        else
            ans = min(ans,a*c);
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;
 
int main() {
    ll x;
    cin >> x;
    auto n = x / 100;
    auto r = x % 100;
    if (r <= n * 5) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
c=[]
S=[]
lst=[]
import string
a=string.ascii_letters
import collections
try:
    while True:
        lst=lst+list(input())
        
        #S += collections.Counter(c)
except EOFError:
    pass
c = collections.Counter(lst)

for i in range(26):
    print(a[i]+" : "+str(c[a[0+i]]+c[a[26+i]]))



Measured memory_bytes: 6688
using System;
using System.IO;
using System.Collections.Generic;

namespace _132
{
    class Program
    {
        static void Main(string[] args)
        {
            solve_132B();
        }


        public static void solve_132B()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] test = Console.ReadLine().Split(' ');

            int[] p = Array.ConvertAll(test, int.Parse);
            int count = 0;
            for (int i = 1; i < n; i++)
            {
                if (i < n - 1 && ((p[i] > p[i - 1] && p[i] < p[i + 1]) || (p[i] > p[i + 1] && p[i] < p[i - 1])))
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
        public static void solve_132A()
        {
            string a = Console.ReadLine();

            char[] str = a.ToCharArray();

            Array.Sort(str);
            
            string ansewr = "Yes";
            if (str[0] != str[1] || str[2] != str[3] || str[0] == str[2])
            {
                ansewr = "No";
            }

            Console.WriteLine(ansewr);
        }
    }
}


Measured memory_bytes: 11220
import java.util.Scanner;

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

		if (3200 <= a) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}
	}
}


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

namespace IO {
    template <typename Tp> inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-')
                y = -1;
            c = getchar();
        }
        if (c == EOF)
            return 0;
        while ('0' <= c && c <= '9')
            x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); }
}; // namespace IO
using namespace IO;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1)
                ans = mul(ans, x);
        return ans;
    }
}; // namespace modular
using namespace modular;

#define reg register
#define MAX_N 200007
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
typedef long long ll;

int N;
int a[MAX_N], sum[MAX_N], nxt[MAX_N][3], f[MAX_N];
char s[MAX_N];

inline void solve() {
    bool flag = false;
    lep(i, 1, N) if (s[i] == s[i + 1]) flag = true;
    if (!flag)
        return puts("1"), void();
    rep(i, 1, N) a[i] = (s[i] == 'a' ? 1 : 2), sum[i] = (sum[i - 1] + a[i]) % 3;
    nxt[N][0] = nxt[N][1] = nxt[N][2] = N + 1;
    irep(i, N - 1, 0) {
        rep(j, 0, 2) nxt[i][j] = nxt[i + 1][j];
        nxt[i][sum[i + 1]] = i + 1;
    }
    int res = 0;
    f[0] = 1;
    rep(i, 0, N) {
        rep(j, 1, 2) inc(f[nxt[i][(sum[i] + j) % 3]], f[i]);
        if (i && sum[i] == sum[N])
            inc(res, f[i]);
    }
    printf("%d\n", res);
}

int main() {
#ifdef LOCAL
    FIN("in");
#endif
    scanf("%s", s + 1);
    N = strlen(s + 1);
    solve();
    return 0;
}


Measured memory_bytes: 4224
//<MIHIR KHAMBHATI/>
#include <bits/stdc++.h>
using namespace std;
#define _                             \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define ideb \
    int _p_; \
    cin >> _p_;
#define mod 1000000007ll
typedef long long int ll;
typedef unsigned long long int ull;

vector<vector<char>> v(1002, vector<char>(1002));
ll dp[1002][1002];
bool vis[1002][1002];
ll ans;
int n, m;

ll go(int x, int y)
{
    if (x >= n || y >= m || v[x][y] == '#')
        return 0;

    if (vis[x][y])
    {
        //        ans = (dp[x] [y] + 1) % mod;

        return dp[x][y];
    }

    ll a = go(x + 1, y);
    ll b = go(x, y + 1);
    dp[x][y] = (a % mod + b % mod) % mod;
    vis[x][y] = 1;

    return dp[x][y];
}

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

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> v[i][j];
        }
    }

    vis[n - 1][m - 1] = 1;
    dp[n - 1][m - 1] = 1;
    int t = go(0, 0);

    cout << dp[0][0];
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main() {
    ll a,b,c,k;cin >>a>>b>>c>>k;
    ll ans;
    if(a-b<=1e18){
        ans=a-b;
    }
    else {
        puts("Unfair");
        return 0;
    }
    if(k%2==1)ans*=-1;
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <functional>
#include <sstream>
#include <vector>
using namespace std;

int main(){
  string s, high, low, now;
  int L;
  vector<string> check;

  while(cin >> s >> L){
    if(s == "0" && L == 0) break;
    int cnt = 0;
    for(int i = s.size() ; i < L ; i++){
      s += '0';
    }
    
    check.clear();
    check.push_back(s);
    high = low = s;
    bool flag = 0;
    while(1){
      cnt++;

      sort(high.begin(), high.end());
      sort(low.begin(), low.end());
      reverse(low.begin(), low.end());

      int l = atoi(high.substr(0, high.size()).c_str());
      int h = atoi(low.substr(0, low.size()).c_str());
      //cout << low << ' ' << high << endl;
      // cout << h << ' ' << l << endl;
      int res = h - l;
      ostringstream os;
      os << res;
      //cout << os.str() << endl;
      for(int i = 0 ; i < check.size() ; i++){
	if(os.str() == check[i]){
	  cout << i << ' ' << os.str() << ' ' << cnt-i << endl;
	  flag = 1;
	  break;
	}
      }
      if(flag) break;
      check.push_back(os.str());
      high = low = os.str();
      
      for(int i = high.size() ; i < L ; i++){
	high += '0';
	low += '0';
      }
    }
  }
  return 0;
}

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

const int INF = 1 << 21;
const int MAX = 103;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int n, G[MAX][MAX];

int prim() {
  int u, minv;
  int d[MAX], p[MAX], color[MAX];

  fill((int*)d, (int*)(d+MAX), INF);
  memset(p, -1, sizeof(p));
  memset(color, WHITE, sizeof(color));

  d[0] = 0;
  while (true) {
    minv = INF;
    u = -1;
    rep(i,n) {
      if (minv > d[i] && color[i] != BLACK) {
	u = i;
	minv = d[i];
      }
    }
    if (u == -1) break;
    color[u] = BLACK;
    rep(v,n) {
      if (color[v] != BLACK && G[u][v] != INF) {
	if (d[v] > G[u][v]) {
	  d[v] = G[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  
  int sum = 0;
  rep(i,n) {
    if (p[i] != -1) sum += G[i][p[i]];
  }
  return sum;
}

int main() {
  cin >> n;
  rep(i,n) rep(j,n) {
    int e;
    cin >> e;
    G[i][j] = (e == -1) ? INF : e;
  }

  cout << prim() << endl;
  return 0;
}



Measured memory_bytes: 3112
# Setup
import sys
sys.setrecursionlimit(4100000)

n,k= [int(i) for i in input().split()]
pts = {}
pts["s"],pts["p"],pts["r"] = [int(i) for i in input().split()]
t = input()
take,notake, chose = [0 for _ in range(n)], [0 for _ in range(n)], ["w" for _ in range(n)]
for i in range(len(t)):
    if i == 0:
        take[0] = pts[t[i]]
        notake[0] = 0
        chose[0] = t[i]
    else:
        if t[i] == chose[i-k]:
            take[i] = max(take[i-1],notake[i-1])
            notake[i] = max(take[i-1],notake[i-1])
        else:
            take[i] = take[i-1] + pts[t[i]]
            notake[i] = max(take[i-1],notake[i-1])
            chose[i] = t[i]
#     print(take,notake,chose)
# print(take,notake,chose,pts)
print(max(take[-1],notake[-1]))

Measured memory_bytes: 51312
#pragma region
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define dump(x) cerr << #x << " = " << x << endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);
int dig(int n){return (int)(log10(n) + 1);}
int abc(char x){return (int)(x)-(int)('a');} // 0~25
char abc(int x){return (char)(x+(int)('a'));} 
int ABC(char x){return (int)(x)-(int)('A');}
char ABC(int x){return (char)(x+(int)('A'));}
void solve();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}
#pragma endregion

void solve() {
	int N, M;
	int ans = 0;
	int tmp = 0;
	int f = 1;
	string S;
	cin >> N >> M;
	vi a(N);
	rep(i, N) cin >> a[i];
	rep(i, N) tmp += a[i];
	rep(i, N) {
		if (4 * M * a[i] >= tmp) {
			ans++;
		}
	}
	// cout << ans << endl;
	if (ans >= M) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import math
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom
"""
int(input())
map(int,input().split())
list(map(int,input().split()))
"""


            
       

t=1
for term in range(1,t+1):
    n=int(input())
    A=list(map(int,input().split()))
    d={}
    for i in range(n-1):
        if(A[i] not in d):
            d[A[i]]=0
        d[A[i]]+=1
    for i in range(1,n+1):
        if(i in d):
            print(d[i])
        else:
            print(0)
        
            
            

Measured memory_bytes: 33628
#include<bits/stdc++.h>
using namespace std;
const int N=200010,INF=0x3f3f3f3f;
int a[N],hd[N],to[N<<1],nxt[N<<1];
int tot,n,t;
int ans[N],q[N];
stack<int> dp[N];
void add(int x,int y){
	to[++tot]=y;
	nxt[tot]=hd[x];
	hd[x]=tot;
}
template <class T> inline void chk(T &a,T b){if(b>a) a=b;}
void dfs(int x,int f){
	int l=1,r=n,mid,updt;
	while(l<=r){
		mid=(l+r)>>1;
		if(dp[mid].top()>=a[x]) r=mid-1;
		else l=mid+1;
	}
	dp[l].push(a[x]);updt=l;
	l=1,r=n;
	while(l<=r){
		mid=(l+r)>>1;
		if(dp[mid].top()>=INF) r=mid-1;
		else l=mid+1;
	}
	ans[x]=r;
	for(int i=hd[x];i;i=nxt[i]){
		if(to[i]!=f){
			dfs(to[i],x);
		}
	}
	dp[updt].pop();
}
int main()
{
	//freopen("in.txt","r",stdin);
	scanf("%d",&n);
	//printf("%d\n",n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	//for(int i=1;i<=n;++i) printf("%d ",a[i]);
	//printf("\n");
	q[0]=INF;
	for(int i=1;i<=n;++i) dp[i].push(INF);
	for(int i=1,x,y;i<n;++i){
		scanf("%d %d",&x,&y);
		//printf("%d %d\n",x,y);
		add(x,y);
		add(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;++i) printf("%d\n",ans[i]);
}

Measured memory_bytes: 155600
/* ex7_3
    sachiyan*/

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

int main(void){
    int height, width; //変数の定義
    int i, j;
    char **matrix; //入力の表を記憶する二次元配列
    int *row ,*col; //それぞれの行に#があるか記憶する配列

    scanf("%d%d", &height, &width); //行数列数の読み取り

    //二次元配列matrixのメモリの動的確保
    matrix = (char**)calloc(height, sizeof(char*));
    if(matrix == NULL){ //メモリが足りない場合のエラー処理
        exit(1);
    }
    for(i = 0; i < height; i++){
        matrix[i] = (char*)calloc(width+1, sizeof(char));
        if(matrix[i] == NULL){
            exit(1);
        }
    }

    for(i=0; i<height; i++){ //入力の表を二次元配列に記憶
        for(j=0; j<width+1; j++){
            scanf("%c", &matrix[i][j]);
        }
    }

    //一次元配列rowのメモリの動的確保
    row = (int*)calloc(height, sizeof(int));
    if(row ==NULL){
        exit(1);
    }
    //一次元配列colのメモリの動的確保
    col = (int*)calloc(width, sizeof(int));
    if(col ==NULL){
        exit(1);
    }

    for(i=0; i<height; i++){ //二次元配列を全探索して、#がある行、列をrow,colに記憶
        for(j=0; j<width+1; j++){
            if (matrix[i][j] == '#'){
                row[i] = 1;
                col[j] = 1;
            }
        }
    }
    for(i=0; i<height; i++){
        if(row[i] == 1){ //i番目の行に#が含まれている場合
            for(j=0; j<width+1; j++){
                if(col[j] == 1){ //j番目の列にも#が含まれている場合
                    printf("%c", matrix[i][j]);//出力
                }
            }
            printf("\n"); //一行出力したら改行
        }
    }

    //matrix,row,colのメモリの開放
    for(i = 0; i < height; i++){
        free(matrix[i]);
    }
    free(matrix);

    free(row);
    free(col);
    

    return 0;
}

Measured memory_bytes: 1624
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dpX[4001][16001];
int dpY[4001][16001];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int x, y; cin >> x >> y;
    S.push_back('T');
    int i = 0;
    while(S[i] == 'F') i++;
    x -= i;

    vector<int> aryX;
    vector<int> aryY;

    int turn = 0;
    int progress = 0;
    while(S[i] == 'T') {
        i++;
        turn = 1 - turn;
    }    
    while(i < S.length()) {
        while(S[i] == 'F') {
            i++;
            progress++;
        }
        if (progress > 0) {
            if (turn == 1) aryY.push_back(progress);
            else aryX.push_back(progress);
        }
        progress = 0;
        while(S[i] == 'T') {
            i++;
            turn = 1 - turn;
        }
    }
    /*
    rep(i, aryX.size()) cout << dpX[i] << endl;
    cout << endl;
    rep(i, aryY.size()) cout << dpY[i] << endl;
    */

    dpX[0][8000] = 1;
    rep(i, aryX.size()) {
        REP(j, 0, 16000) {
            if(dpX[i][j] == 1) {
                dpX[i+1][j-aryX[i]] = 1; 
                dpX[i+1][j+aryX[i]] = 1;
            } 
        }
    }
    dpY[0][8000] = 1;
    rep(i, aryY.size()) {
        REP(j, 0, 16000) {
            if(dpY[i][j] == 1) {
                dpY[i+1][j-aryY[i]] = 1; 
                dpY[i+1][j+aryY[i]] = 1;
            } 
        }
    }
    if (dpX[aryX.size()][x+8000] && dpY[aryY.size()][y+8000]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }






    return 0;
}


Measured memory_bytes: 252288
#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main(){
	int n, a[110], t;
	while(cin >> n, n) {
		rep(i,n) {
			cin >> a[i];
		}
		cin >> t;
		int lo = 0, hi = n-1, cnt = 0, mid = -1;
		while(hi >= lo) {
			mid = (hi+lo) / 2;
			cnt++;
			if(a[mid]==t) break;
			else if(a[mid]<t) lo = mid+1;
			else hi = mid-1;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
/*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
const int mx=1e5+5;
const int MOD=1e9+7;
int ara[mx];
int main ()
{
    int i,n,a,b;
    ll ans=0;
    scanf ("%d %d %d",&n,&a,&b);
    scanf ("%d",&ara[0]);
    for (i=1;i<n;i++) {
        scanf ("%d",&ara[i]);
        ll x=ara[i]-ara[i-1];
        x*=a;
        ans+=min(x,(ll)b);
    }
    printf ("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

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

        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                A[i][j] = sc.nextLong();
            }
        }

        boolean[][] memo = new boolean[N][N];
        
        for(int k=0; k<N; k++){
            for(int i=0; i<N; i++){
                for(int j=0; j<N; j++){
                    if(A[i][j]>A[i][k]+A[k][j]){
                        System.out.println(-1);
                        return;
                    }
                    else if(A[i][j]==A[i][k]+A[k][j] && i!=k && j!=k){
                        memo[i][j] = true;
                    }
                }
            }
        }

        long ans = 0;
        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                if(!memo[i][j]){
                    ans += A[i][j];
                    memo[i][j] = true;
                    memo[j][i] = true;
                }
            }
        }
        System.out.println(ans);
    }
}

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

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> ans;
    for (int i = 1; i <= min(A, B); i++){
        if (A % i == 0 && B % i == 0){
            ans.push_back(i);
        }
    }
    int size;
    size = ans.size();
    cout << ans.at(size - K) << endl;
}

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

using namespace std;

typedef pair<int,int> PII;
map<int,PII> a;
int s[100100];
int b[100100];

int main()
{
    int h,w,d,i,m,j,l,r,q;
    cin >> h >> w >> d;
    for(i = 0; i < h; i ++)
    {
        for(j = 0; j < w; j ++)
        {
            scanf("%d",&m);
            a[m] = {i,j};
        }
    }
    for(i = d; i <= h*w; i ++)
    {
        s[i] = s[i-d] + abs(a[i-d].first - a[i].first);
        s[i] += abs(a[i-d].second - a[i].second);
    }
    cin >> q;
    for(i = 0; i < q; i ++)
    {
        scanf("%d%d",&l,&r);
        b[i] = s[r] - s[l];
    }
    for(i = 0; i < q; i ++)
    {
        cout << b[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 7552
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

int main() {
  vector<int> x;
  for (int i = 0; i < 5; i++) {
    int tmp;
    cin >> tmp;
    x.push_back(tmp);
  }

  for (int i = 0; i < 5; i++) {
    if (x.at(i) == 0) {
      cout << i + 1 << endl;
      break;
    }
  }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

struct UnWeightedGraph {
  struct Edge {
    int to;
    Edge(int to) : to(to) {}
  };
  vector<vector<Edge>> edges;
  int n;
  UnWeightedGraph(int n) : n(n) {
    edges.assign(n, vector<Edge>());
  }
  void add_edge(int v, int u) {
    edges[v].emplace_back(u);
  }
  vector<Edge> &operator[](int x) {
    return edges[x];
  }
};

void solve() {
  int n, U, V;
  cin >> n >> U >> V;
  U--, V--;
  UnWeightedGraph g(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g.add_edge(a, b);
    g.add_edge(b, a);
  }
  vi32 u_dist(n), v_dist(n);
  function<void(vi32 &, int, int, int)> dfs = [&](vi32 &dist, int u, int p, int d) {
    dist[u] = d;
    each(e, g[u]) {
      if (e.to == p) continue;
      dfs(dist, e.to, u, d + 1);
    }
  };
  dfs(u_dist, U, -1, 0);
  dfs(v_dist, V, -1, 0);
  int ans = 0;
  rep(i, n) {
    if (u_dist[i] < v_dist[i]) amax(ans, v_dist[i] - 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 14208