akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

class UnionFind {
public:
    vector<LL> parent;
    vector<LL> member;
    UnionFind(LL N) {
        parent.resize(N);
        REP(i, N) {
            parent[i] = i;
        }
        member.resize(N);
        fill(ALL(member), 1);
    }

    int root(LL x) {
        if(x == parent[x]) {
            return x;
        }
        return parent[x] = root(parent[x]);
    }

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

    LL size(LL x) {
        return member[root(x)];
    }

    void unite(LL x, LL y) {
        if(root(x) == root(y)) {
            return;
        }
        member[root(y)] += member[root(x)];
        parent[root(x)] = root(y);
    }
};

struct Edge {
    LL u;
    LL v;
};

int main() {
    LL N, M;
    cin >> N >> M;
    vector<Edge> edges;
    edges.resize(M);
    REP(i, M) {
        cin >> edges[i].u >> edges[i].v;
    }
    reverse(ALL(edges));

    UnionFind uf(N + 1);
    vector<LL> res;
    res.resize(M + 1);
    res[0] = N*(N - 1)/2;
    REP(i, M) {
        bool b = uf.same(edges[i].u, edges[i].v);
        if(!b) {
            LL x = uf.size(edges[i].u);
            LL y = uf.size(edges[i].v);
            res[i + 1] = res[i] - x*y;
            uf.unite(edges[i].u, edges[i].v);
        }else{
            res[i + 1] = res[i];
        }
    }
    reverse(ALL(res));
    FOR(i, 1, M + 1) {
        cout << res[i] << endl;
    }
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
int dp[1002][1002] = {0};
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    int h,w; cin>>h>>w;
    char vec[h+1][w+1];
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++) cin>>vec[i][j];
            int lavda = 0;
    // dp[i][j] is the number of paths to reach grid (i,j) from (0,0)
    for(int i=1;i<=h;i++)
    {
        if(vec[i][1] == '.') dp[i][1] = 1;
        else break;
    }
    for(int i=1;i<=w;i++)
    {
        if(vec[1][i] == '.') dp[1][i] = 1;
        else break;
    }
    for(int i=2;i<=h;i++)
    {
        for(int j=2;j<=w;j++)
        {
            if(vec[i][j] == '#') dp[i][j] = 0;
            else if(vec[i-1][j] == '#' && vec[i][j-1] == '#') dp[i][j] = 0;
            else if(vec[i-1][j] == '.' && vec[i][j-1] == '.') dp[i][j] = (dp[i-1][j] + dp[i][j-1])%M;
            else if(vec[i-1][j] == '.') dp[i][j] = dp[i-1][j];
            else if(vec[i][j-1] == '.') dp[i][j] = dp[i][j-1];
            else lavda++;
        }
    }
    cout<<dp[h][w]%M<<endl;
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
const int N = 200010;

int n, m;
pair<int, int> a[N];
int d[N][2];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= m; i++) scanf("%d%d",&a[i].first,&a[i].second);
	sort(a+1, a+1+m);
	for(int i = 1; i <= n; i++) d[i][0] = d[i][1] = 1;
	for(int i = 1; i <= m; i++)
	{
		int x = a[i].second;
		d[x][0] = max(d[x][0], d[x+1][0]+1);
		d[x+1][1] = max(d[x+1][1], d[x][1]+1);
	}
	for(int i = 1; i <= n; i++)
	{
		printf("%d",d[i][0]+d[i][1]-1);
		if(i != n) printf(" ");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 6312
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)	   for(int i = 0; i < (n); ++i)
#define all(c)		   begin(c), end(c)
#define rall(c)		   rbegin(c), rend(c)
#define SZ(a)		   ((ll) a.size())

typedef long long		   ll;
typedef unsigned long long ull;


int main(){
  int A,B,C;
  cin >> A >> B >>C;
  int count=0;
  while(1){
    if(A<B) swap(A,B);
    if(A<C) swap(A,C);
    if(B<C) swap(B,C);

    if(A==B){
      if(A==C){
        break;
      }
      else if(A<C){
        A++;
        B++;
      }
      else if((A-1)==C){
        A++;
        B++;
      }
      else{
        C+=2;
      }
    }
    else if(B==C){
      B++;
      C++;
    }
    else{
      C+=2;
    }

    count++;
  }
  cout << count;



}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;


int main()
{
    int N;
    cin >> N;
    vector<long int> A(N);
    for (int i = 0; i < N; ++i){
        cin >> A.at(i);
    }

    sort(A.begin(), A.end());

    for (int i = 0; i < N - 1; ++i){
        if(A.at(i) == A.at(i+1)){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 1792
from itertools import combinations_with_replacement as comb
n,m,q = map(int,input().split())
ans = 0
query = [[int(i) for i in input().split()] for _ in range(q)]
for A in comb(range(1,m+1),n):
    cnt = 0
    for i in range(q):
        a,b,c,d = query[i]
        if A[b-1]-A[a-1] == c: cnt += d
    ans = max(cnt,ans)
print(ans)


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  string s;
  cin >> n >> s;
  vector<int> W(n, 0), E(n, 0);
  for(int i = 0; i < n - 1; ++i)
  {
    W[i + 1] = W[i] + (s[i] == 'W');
  }
  int ans = W[n - 1];
  for(int i = n - 1; i >= 1; --i)
  {
    E[i - 1] = E[i] + (s[i] == 'E');
    ans = min(ans, W[i - 1] + E[i - 1]);
  }

  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 6112
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N,M;
  cin >>N>>M;
  int A[N];
  int count=0,sum=0,bod;
  for(int i=0;i<N;i++){
  	cin>>A[i];
    sum+=A[i];
  }
  bod=sum/(4*M);
  int mem=4*M;
  
  if(sum%mem==0){
  for(int i=0;i<N;i++){
  	if(A[i]>=bod){count++;}
  }
  }
  else{ 
    for(int i=0;i<N;i++){
  		if(A[i]>bod){count++;}
  	}
  }  
   
    
    
  if(count>=M){cout <<"Yes"<<endl;}
  else{cout <<"No"<<endl;}
}

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

int digitSum(int n)
{
	int ret=0;
	while (n > 0)
	{
		ret += n % 10;
		n /= 10;
	}

	return ret;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int sum, total=0;

	for (int i = 0; i <= n; i++)
	{
		sum = digitSum(i);
		if (sum >= a && sum <= b)
		{
			total += i;
		}
	}
	cout << total << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
long long a,k;
vector<int>n;
int main()
{
    cin>>a;
    for(int s=0;s<a;s++)
    {
        cin>>k;
        if((s+a+1)%2)n.push_back(k);
        else n.insert(n.begin(),k);
    }
    for(int s=0;s<a;s++)cout<<n[s]<<" ";
}

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    // Your code here!
    int A,B;
    char op;
    
    scanf("%d %c %d",&A,&op,&B);
    
    if(op=='+'){
        printf("%d\n",A+B);
    }
    else if(op=='-'){
        printf("%d\n",A-B);
    }
}


Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[100001][3]={0};//第i天选了第j种
int a[100001],b[100001],c[100001];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }
    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];
    for(int i=2;i<=n;i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][2],dp[i-1][0])+b[i];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    int ans = 0;
    for(int i=0;i<3;i++){
        ans = max(dp[n][i],ans);
    }
    printf("%d\n",ans);
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[100005];
LL sum[100005];

const int INF = int(1e9) + 123;

int main() {
    scanf("%d", &n);
    forn(i, n) scanf("%d", a + i);
    sort(a, a + n);
    sum[0] = 0;
    forn(i, n) {
        sum[i + 1] = sum[i] + a[i];
    }
    int ans = 0;
    forn(i, n) {
        LL cur = a[i];
        bool ok = true;
        while (2 * cur < INF && cur < sum[n]) {
            int ind = lower_bound(a, a + n, int(2 * cur + 1)) - a;
            if (cur == sum[ind]) {
                ok = false;
                break;
            }
            cur = sum[ind];
        }
        ans += ok;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> L(N);
	for (int i = 0; i < N; ++i) cin >> L[i];

	sort(L.begin(), L.end());
	long long ans = 0;
	for (int i = 0; i < N; i++) for (int j = i + 1; j < N; ++j) {
		int lbm1 = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin() - 1;
		//cout << L[i] + L[j] << endl;
		//cout << lbm1 << endl;
		ans += max(0, lbm1 - j);
	}

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

Measured memory_bytes: 3600
#include <stdio.h>

int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  if(a<b)printf("a < b\n");
  else if(a>b)printf("a > b\n");
  else if(a==b)printf("a == b\n");
  return 0;
}



Measured memory_bytes: 2116
n=int(input())
s=input()
ans=0

for i in range(1,n-1):
  cnt=0
  x=list(set(s[:i]))
  y=list(set(s[i:]))
  for j in x:
    if j in y:
      cnt+=1
  if ans<cnt:
    ans=cnt
print(ans)


Measured memory_bytes: 9164
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>v(n), mon(100005);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		++mon[v[i]];
		++mon[v[i] + 1];
		++mon[v[i] + 2];
	}
	sort(mon.rbegin(), mon.rend());
	cout << mon[0] << endl;
}

Measured memory_bytes: 1024
// https://atcoder.jp/contests/keyence2019/tasks/keyence2019_b
// B - KEYENCE String
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w, ans = 0, count = 0, flag = 0;
  string s, t, target = "keyence";
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> s;

  if (s == target)
  {
    cout << "YES" << endl;
    return 0;
  }

  rep(i, 0, s.size())
  {
    rep(j, i, s.size())
    {
      string z = "";
      rep(k, 0, s.size())
      {
        if (i <= k && k <= j)
        {
          continue;
        }
        else
        {
          z.pb(s[k]);
        }
      }
      // cout << z << endl;
      if (z == target)
      {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N =sc.nextInt();
      
      int v[] =new int[N];
        for(int i=0; i<N; ++i){
        v[i] =sc.nextInt();
        }
      
      int c[] =new int[N];
        for(int i=0; i<N; ++i){
        c[i] =sc.nextInt();
        }
      
      int a =0;
      for(int i=0; i<N; ++i){
        if(v[i]>c[i]){
          a +=v[i]-c[i];
        }
      }
      System.out.println(a);
    }
}

Measured memory_bytes: 21844
n = int(input())

lis = [[0]*10 for _ in range(10)]
ans = 0

for i in range(1,n+1):
      l = str(i)
      lis[int(l[0])][int(l[-1])] += 1

for i in range(10):
     for j in range(10):
          ans += lis[i][j] * lis[j][i]



print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
using namespace std;
string a[110];
int main()
{
    int n,i,j,k,t,f=0;
    cin >> n;
    cin >> a[i];
    for(i=1;i<n;i++)
    {
    	cin >> a[i];
    	if(a[i][0]!=a[i-1][a[i-1].size()-1])
    		f=1;
	}
	if(!f)
	{
		for(i=0;i<n;i++)
		{
			if(f)
				break;
			for(j=i+1;j<n;j++)
			{
				if(a[i].size()!=a[j].size())
					continue;
				t=0;	
				for(k=0;k<a[i].size();k++)
				{
					if(a[i][k]!=a[j][k]) 
					{
						t=1;
						break;
					}
				}
				if(t==0)
					f=1;
			}
		}
	}
	
	if(f)
    	cout << "No" << endl;
    else
    	cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/


int main() {

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	// 1,2番目の大きいのを持ってくる
	// もし1番目に大きい数字だったら二番目に大きい数字を返す
	auto copyA = a;
	sort(allof(copyA), greater<int>());

	rep(i, n) {
		if (a[i] == copyA[0]) cout << copyA[1] << endl;
		else cout << copyA[0] << endl;
	}

	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    string s;
    cin >> s;
    int sum = 0;
    for (auto c : s) {
        (sum += c - '0') %= 9;
    }
    puts(sum == 0 ? "Yes" : "No");
}

Measured memory_bytes: 3696
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;

int a,b,n,c[100010],tmp[100010];

int check(int u)
{
	for(int i=1;i<=n;i++)
	{
		tmp[i]=c[i]-u*b;
	}
	int res=0;
	for(int i=1;i<=n;i++)
	{
		if(tmp[i]>0)
		{
			res+=(tmp[i]+a-1)/a;
		}
	}
	return res<=u;
}

signed main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	a-=b;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&c[i]);
	}
	int l=1,r=1e9+1,mid;
	while(l<r)
	{
	    mid=(l+r)>>1;
		if(check(mid))
		{
			r=mid;
		}
		else
		{
			l=mid+1;
		}
	}
	printf("%lld\n",l);
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	string stones;
	cin >> stones;

	int red = 0, white = 0;
	int valid = true;
	for (int i = 0; i < n; ++i) {
		if (stones[i] == 'R') {
			++red;
		} else {
			++white;
		}

		if (i > 0 && stones[i] == 'R' && stones[i - 1] == 'W') {
			valid = false;
		}
	}

	if (!white || !red || valid) {
		cout << "0\n";
		return 0;
	}

	int red_left = red, white_left = white;
	int ans = min(red, white);
	int i = 0, j = n - 1;
	int swaps = 0;
	while (i < j) {
		if (stones[i] == 'W' && stones[j] == 'R') {
			--red_left;
			--white_left;
			++i;
			while (i < j && stones[i] == 'R') {
				++i;
				--red_left;
			}

			--j;
			while (j > i && stones[j] == 'W') {
				--j;
				--white_left;
			}

			++swaps;
			ans = min(ans, min(swaps + red_left, swaps + white_left));
		} 
		else if (stones[i] == 'R') {
			++i;
			--red_left;
		}
		else {
			--j;
			--white_left;
		}
	}

	cout << ans << "\n";

	return 0;

}

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

int main(){
  string s;cin >> s;
  int w,i=0;cin >> w;
  while(s.length() > i){
    cout << s[i];
    i += w;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int a, b; cin >> a >> b;
    string in; cin >> in;

    bool res = true;
    rep(i, a+b+1){
        if(i == a){
            if(in[i] != '-') res = false;
        }
        else {
            if(in[i] == '-') res = false;
        }
    }

    cout << (res ? "Yes":"No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll n;
    cin >> n;
    map<pii, ll> mp;
    ll ans = 0;
    rep(i, n)
    {
        ll x; cin >> x;
        if(mp[{x, i+1}]) ans++;
        mp[{i+1, x}] = 1;
    }
    cout << ans;
}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);


int n; cin >> n;
while(n--){
	int a;cin >> a;
	if(a%2==0){
		if(a%3==0 || a%5==0) continue;
		else{
			cout <<"DENIED";
			return 0;
		}
	}
}
cout <<"APPROVED";
	
	return 0;
}

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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


const int INF = 1 << 29;

auto solve() {
    int N;
    cin >> N;
    vi a(N);
    for (auto &&e: a) cin >> e;
    sort(all(a));
    int mn = a[0];
    int mx = a[N - 1];

    map<int, int> nums;
    for (auto &&e: a) nums[e]++;

    if (mx % 2 == 0) {
        if (mx / 2 != mn || nums[mn] != 1)
            return false;
    } else {
        if ((mx + 1) / 2 != mn || nums[mn] != 2)
            return false;
    }

    FOR(i, mn, mx+1) {
        if(nums[i] == 0)
            return false;
    }

    return true;
}


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

    cout << (solve() ? "Possible" : "Impossible") << endl;
//    solve();
    return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  
  
}

Node treeSearch(Node u, int k){
  
  
}

Node treeSuccessor(Node x){
  
  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key)
      x=x->left;
    else
      x=x->right;
  }
  z->parent=y;
  if(y==NIL)
    root=z;
  else if(z->key<y->key)
    y->left=z;
  else
    y->right=z;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    if(u==root){
      printf(" %d",u->key);
      preorder(u->left);
      preorder(u->right);
    }
    else{
      printf(" %d",u->key);
      preorder(u->left);
      preorder(u->right);
    } 
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}

Measured memory_bytes: 24036
N, T = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

max_diff = 0
cnt = 0
min_a = A[0]
for i in range(1, N):
    a = A[i]
    if min_a > a:
        min_a = a
        continue

    if max_diff < a - min_a:
        max_diff = a - min_a
        cnt = 1
    elif max_diff == a - min_a:
        cnt += 1
print(cnt)


Measured memory_bytes: 20088
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

typedef long long ll;
typedef pair<int, int> P;


#define INF 1000000000
#define EPS 1e-10

#define MAX_N 20000
#define MAX_M 16

int N, M;
int C[MAX_M];
int x[MAX_N];

ll dp[MAX_N + 1][256];

vector<ll> ans_list;

int main() {

	while (true){
		cin >> N >> M;
		if (N == 0 && M == 0)
			break;

		for (int i = 0; i < M; i++){
			cin >> C[i];
		}

		for (int i = 0; i < N; i++){
			cin >> x[i];
		}

		for (int i = 0; i < N + 1; i++){
			for (int j = 0; j <= 255; j++){
				dp[i][j] = INF;
			}
		}

		dp[0][128] = 0;

		for (int i = 0; i < N; i++){
			for (int j = 0; j <= 255; j++){
				for (int k = 0; k < M; k++){
					int num = j + C[k];
					if (num < 0)
						num = 0;
					if (num > 255)
						num = 255;
					dp[i+1][num] = min(dp[i+1][num], (x[i] - num) * (x[i] - num) + dp[i][j]);
				}
			}
		}

		ll ans = INF;

		for (int i = 0; i <= 255; i++){
			ans = min(ans, dp[N][i]);
		}

		ans_list.push_back(ans);

	}
	
	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}
	

	return 0;
}

Measured memory_bytes: 41288
#include<stdio.h>
#include<math.h>
int N,X[105],Y[105],i;
double D;
 
double d(int p)
{
    int i;
    for(D=0.0,i=0;i<N;i++)
    {
        if(p==4)D=D>abs(X[i]-Y[i])?D:abs(X[i]-Y[i]);
        else D+=pow(1.0*abs(X[i]-Y[i]),p);
    }
    return p==4?D:pow(D,1.0/p);
}
 
int main()
{
    scanf("%d",&N);
    for(i=0;i<N;i++)scanf("%d",X+i);
    for(i=0;i<N;i++)scanf("%d",Y+i);
    for(i=1;i<5;i++)printf("%lf\n",d(i));
    return 0;
}


Measured memory_bytes: 2112
using System;
using System.Collections.Generic;
using System.Linq;
 
public class Solution
{
    public static void Main()
    {
      int N = int.Parse(Console.ReadLine());
      string str1 = Console.ReadLine();
      string[] strA = str1.Split(' ');
      long[] A = new long[N];
      long ans = 0;
      int cnt = 0;
      for (int i = 0; i < N; i++)
      {
        A[i] = long.Parse(strA[i]);
        if (A[i] < 0L)
        {
          A[i] = A[i] * (-1L);
          cnt++;
        }
        ans += A[i];
      }
      // LINQでソート
      var dst = A.OrderBy(a => a).ToList();
      if (cnt % 2 == 1)
      {
        ans -= dst[0];
        ans -= dst[0];
      }

      Console.WriteLine($"{ans}");
    }
}

Measured memory_bytes: 33756
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            for (int i = 0; i < S.Length; i++)
            {
                char offset = (char)(((S[i] - 'A' + N) % 26) + 'A');
                Console.Write(offset);
            }
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
const int INF = 1e9;
int main() {
	ll n, k;
	cin >> n >> k;
	if (k % 2 == 0) {
		ll a = n / k;
		ll b = (n + (k / 2)) / k;
		cout << a * a*a + b * b*b << endl;
	}
	else {
		ll a = n / k;
		cout << a * a*a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <vector>
#include <string>
#include <limits.h>
#include <set>
#define ll long 
using namespace std;


int main()
{
ios_base::sync_with_stdio(false);
    
  #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    int num;
    cin>>num;
    int d;
    int n = num;
    int count = 0;
    while(n>0)
    {
    	d = n%10;
    	if(d==7)
    	{
    		count++;
    	}
    	n = n/10;
    }
    if(count==0)
    	cout<<"No\n";
    else
    	cout<<"Yes\n";
  return 0;
}


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

using namespace std; 

typedef long long ll;

int main(){


    // brute force this

    ll n;
    cin >> n;

    ll grid[2][n];

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

    ll res = -1;
    ll topRes = 0;

    for (int i = 0; i < n; i++) {
        topRes += grid[0][i];

        ll bottomRes = topRes;
        for (int j = i; j < n; j++){
            bottomRes += grid[1][j];
        }
        res = max(res, bottomRes);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


H, W, K = list(map(int, sys.stdin.buffer.readline().split()))
S = [list(sys.stdin.buffer.readline().decode().rstrip()) for _ in range(H)]
S = np.array(S, dtype='U1') == '#'
ans = np.zeros((H, W), dtype=int)

p = 0
for i, row in enumerate(S.cumsum(axis=1)):
    if row[-1] != 0:
        row += p
        row[row == p] += 1
        ans[i] = row
        p = row[-1]

for i in range(1, H):
    if 0 in ans[i]:
        ans[i] = ans[i - 1]

for i in reversed(range(H - 1)):
    if 0 in ans[i]:
        ans[i] = ans[i + 1]
for r in ans:
    print(*r)


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

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 330;
const long long MX = sqrt(N);
const long long H = 17;
const long long MAGIC = 1000;
const long long mod = 1e9 + 7;

using namespace std;

void solve()
{
        int a, b, c, cnt = 0;
        cin >> a >> b >> c;
        while(!(a % 2 || b % 2 || c % 2) && !(a == b && a == c)){
                int na = (a + b) / 2, nb = (a + c) / 2, nc = (b + c) / 2;
                a = na, b = nb, c = nc;
                cnt++;
        }
        if(a == b && a == c && a % 2 == 0){
                cout << -1 << endl;
        }
        else{
                cout << cnt << endl;
        }
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("landscape.in");
        //fout("landscape.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


Measured memory_bytes: 256
H,W = map(int, input().split())
A = [list(input()) for i in range(H)]
Flag = True
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            if A[max(0, i-1)][j] == '#' or A[min(H-1,i+1)][j] == '#' or A[i][max(0,j-1)] == '#' or A[i][min(W-1,j+1)] == '#':
                pass
            else:
                Flag = False
                break
    if Flag == False:
        break
if H == 1 and W == 1 and A[0][0] == '#':
    Flag = False
if Flag == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n,m,c=0,p,q;
cin>>n>>m;
while(n--)
{
long long int x,y;
double k;
cin>>x>>y;
p=(x*x);
q=(y*y);
k=sqrt(p+q);
if(k<=m)
c++;
}
cout<<c;
}


Measured memory_bytes: 3612
N, M = gets.split.map(&:to_i)
F = Array.new(M+1, 0)
(1 .. N).each do |i|
  k, *f = gets.split.map(&:to_i)
  f.each do |j|
    F[j] += 1
  end
end
puts (1 .. M).count{|j| F[j] == N }


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

  int ans = 1;
  rep(i, 1, n) {
    if (s[i - 1] != s[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#!/usr/bin/env python3

n = int(input())
h = list(map(int, input().split()))

h.reverse()


ans = 0
for i in range(1, len(h)):
    if h[i-1]-h[i] >= 0:
        continue
    elif h[i-1]-h[i] == -1:
        h[i] -= 1
    else:
        print("No")
        exit()

print("Yes")


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


int main(){
  ll N, ans = 0;
  cin >> N;
  vector<int>F(N,1);
  rep(i, N){
   F[i] = i + 1;
   //cout << F[i] << endl;
   if(F[i] % 3 != 0 && F[i] % 5 != 0){
    ans += (i + 1);
   }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

typedef long long ll;

#define fio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);
#define cio() ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

const int mod = 1e9+7;
template<typename T>
void amax(T& a, T b) { a=a>b?a:b; }
template<typename T>
void amin(T& a, T b) { a=a<b?a:b; }

using namespace std;

int a,b,x;
int main() {
    cio();
    cin >> a >> b;
    int ok = true;
    if(b&1) ok = false;
    else {
        int mx = b/2;
        int mn = (b+3)/4;
        if(!(a<=mx && a>=mn)) ok = false;
    }
    cout << (ok?"Yes":"No") << endl;
    return 0;
}



Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

#define INFI 1e9;

int main() {
	int n;
	while (1) {
		cin >> n;
		if (n == 0)break;
		int* w = new int[n];
		for (int i = 0;i < n;i++) {
			cin >> w[i];
		}
		int** dp = new int*[n];
		for (int i = 0;i < n;i++) {
			dp[i] = new int[n - i];
			dp[i][0] = 1;
			if (i != n - 1) {
				if (abs(w[i] - w[i + 1]) <= 1) {
					dp[i][1] = 0;
				}
				else {
					dp[i][1] = 2;
				}
			}
				
		}
		for (int i = 2;i < n;i++) {
			for (int j = 0;j < n - i;j++) {
				if (dp[j + 1][i - 2] == 0 && abs(w[j] - w[j + i]) <= 1) {
					dp[j][i] = 0;
				}
				else {
					dp[j][i] = INFI;
					for (int k = 0;k < i;k++) {
						dp[j][i] = min(dp[j][i], dp[j][k] + dp[j + k + 1][i - k - 1]);
					}
				}
			}
		}
		cout <<n - dp[0][n - 1] << endl;
	}
	
}


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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if((a+b) == (c+d)){
        cout << "Balanced";
    } else if((a+b) > (c+d)){
        cout << "Left";
    } else {
        cout << "Right";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

static const double pi = 3.14159265358979323846;

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

  vector<int> v_found;
  for(int i=0; i<26; i++) v_found.push_back(0);

  for(int i=0; i<S.size(); i++) ++v_found[S[i]-'a'];

  for(int i=0; i<26; i++){
    if(v_found[i] == 0){
      cout << (char)('a' + i) << endl;
      return 0;
    }
  }

  cout << "None" << endl;

  return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<cstring>
using namespace std;
int main(){
    char a[105],b[105];
    int len1,len2;
    scanf("%s",a);
    scanf("%s",b);
    len1 = strlen(a);
    len2 = strlen(b);
    if(len1 > len2)
        printf("GREATER");
    if(len1 < len2)
        printf("LESS");
    if(len1 == len2){
        for(int i = 0;i <= len1-1;i++){
        if(a[i] > b[i]){
            printf("GREATER");
            break;}
        if(a[i] < b[i]){
            printf("LESS");
            break;}
        if((a[i] = b[i])&&(i == len1-1)){
            printf("EQUAL");
            break;}
        }

    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}
ll n,k;
ll arr[1000000];
ll dp[1000000];
ll solve(ll i)
{
    
    if(i==n-1)
      return 0;
    if(dp[i]!=-1)
       return dp[i];
       ll m=INT32_MAX;
   for(ll j=i+1;j<=min(n-1,i+k);j++)
   {
      m=min(m,abs(arr[j]-arr[i])+solve(j));
   }
    return dp[i]=m;
}
void pk()
{
    cin>>n>>k;
    memset(dp,-1,sizeof dp);
    for(ll i=0;i<n;i++)
       cin>>arr[i];
    cout<<solve(0);
   
}
int main() 
{ 
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
    //cin>>t;
    while(t--)
    {
        pk();
    }
} 

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

#define ALL(c) (c).begin(),(c).end()

int main() {
	int M; cin >> M;
	while(M--) {
		string s;
		cin >> s;
		vector<string> v;
		for(int i = 0; i < (int)s.length() - 1; i++) {
			string front = s.substr(0, i + 1);
			string back = s.substr(i + 1);

			v.push_back(front + back);
			v.push_back(back + front);

			reverse(ALL(front));
			v.push_back(front + back);
			v.push_back(back + front);

			reverse(ALL(front));
			reverse(ALL(back));
			v.push_back(front + back);
			v.push_back(back + front);

			reverse(ALL(front));
			v.push_back(front + back);
			v.push_back(back + front);
		}
		sort(ALL(v));
		v.erase(unique(ALL(v)), v.end());

#if 0
		cerr << "-----" << endl;
		for(vector<string>::const_iterator iter = v.begin(); iter != v.end(); ++iter)
			cerr << *iter << endl;
		cerr << "-----" << endl;
#endif

		cout << v.size() << endl;
	}
}

Measured memory_bytes: 1008
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


/*
--------------------------------------------

	type

--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;

/*
--------------------------------------------

	container

--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())

/*
--------------------------------------------

	repetition

--------------------------------------------
*/
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

/*
--------------------------------------------

	constant

--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

/*

	Optimizer

*/
//#pragma GCC optimize("Ofast")


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

  string s;
  cin >> s;

  if(s[0] == '9' || s[1] == '9') {
    cout << "Yes\n";
  }
  else {
    cout << "No\n";
  }

  return 0;
}


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

#define ll long long
#define ull unsigned long long

#define pii pair < int, int >
#define pll pair < ll, ll >
#define pci pair < char, int >
#define psi pair < string, int >

#define vi vector < int >
#define vll vector < ll >
#define vs vector < string >
#define vc vector < char >
#define pvi vector < pii >
#define pvll vector < pll >

#define pb push_back

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

int main()
{
    fast;

    int n;

    cin >> n;

    int ac = 0, wa = 0, tle = 0, re = 0;

    for(int i = 0; i < n; i++){
        string s;

        cin >> s;

        if(s == "AC") ac++;
        else if(s == "WA") wa++;
        else if(s == "TLE") tle++;
        else re++;
    }

    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", ac, wa, tle, re);

    return 0;
}



Measured memory_bytes: 3744
#include <string>
#include <iostream>
#include <cstdio>
#include <queue>
#include <tuple>

using namespace std;

char Black = '#';
char White = '.';
int dir_x[4] = {1, 0, -1, 0};
int dir_y[4] = {0, 1, 0, -1};

int main(int argc, char const *argv[])
{
    int H = 0;
    int W = 0;
    int step = 0;
    scanf("%d %d", &H, &W);
    int memo[1001][1001] = {};
    int count = H * W;
    queue<tuple<int, int>> q;
    // printf("debug");
    for (int y = 0; y < H; y++)
    {
        string temp;
        cin >> temp;
        for (int x = 0; x < W; x++)
        {
            if (temp[x] == Black)
            {
                memo[y][x] = 0;
                q.push(make_tuple(y, x));
                count--;
            }
            else
            {
                memo[y][x] = -1;
            }
        }
    }
    // printf("debug");
    while (count > 0)
    {
        step++;
        queue<tuple<int, int>> next_queue;
        while (!q.empty())
        {
            tuple<int, int> temp_tuple = q.front();
            q.pop();
            int ly = get<0>(temp_tuple);
            int lx = get<1>(temp_tuple);
            for (int i = 0; i < 4; i++)
            {
                int temp_x = lx + dir_x[i];
                int temp_y = ly + dir_y[i];
                if (temp_x >= 0 && temp_x < W && temp_y >= 0 && temp_y < H)
                {
                    if (memo[temp_y][temp_x] < 0)
                    {
                        memo[temp_y][temp_x] = step;
                        count -= 1;
                        next_queue.push(make_tuple(temp_y, temp_x));
                    }
                }
            }
        }
        q = next_queue;
    }

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


Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200000 + 10;
const int mod = 2019;
map<int, int> M;
char s[maxn];
int n;
ll ans;
int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	reverse(s + 1, s + n + 1);
	int cur = 0, base = 1;
	M[0] = 1;
 	for(int i = 1; i <= n; ++i)
 	{
 		cur = (base * (s[i] - '0') + cur) % mod;
 		base = base * 10 % mod;
 		//cout << cur << endl; 
 		ans += M[cur];
 		++M[cur];
 	}
 	cout << ans << endl;
 	return 0;
 }

Measured memory_bytes: 4060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int i,n,k;
		int str[],goal[],in[];
		while(true){
			n=sc.nextInt();
			k=0;
			str=new int[n];
			goal=new int[n];
			in=new int[n];
			if(n==0) break;
			for(i=0;i<n;i++){
				in[i]=sc.nextInt();
			}
			for(i=0;i<n-1;i++){
				if(k==0) str[0]=in[0];
				if(in[i]!=in[i+1]-1){
					goal[k]=in[i];
					k++;
					str[k]=in[i+1];
				}
			}
			if(n==1) str[0]=in[0];
			goal[k]=in[i];
			k++;
			boolean f=false;
			for(i=0;i<k;i++){
				if(!f){
					if(str[i]!=goal[i]){
						System.out.print(str[i]+"-"+goal[i]);
					}
					else{
						System.out.print(str[i]);
					}
					f=true;
				}
				else if(f){
					if(str[i]!=goal[i]){
						System.out.print(" "+str[i]+"-"+goal[i]);
					}
					else{
						System.out.print(" "+str[i]);
					}
				}
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 12000
R,G,B,N = map(int, input().split())
ans = 0
for i in range(N//R+1):
  for j in range((N-i*R)//G+1):
    b = (N-R*i-G*j)/B
    if b%1 == 0 and b >= 0:
      ans += 1
print(ans)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

bool bitget(int a,int b){
    return a&(1<<b);
}

int main(){
    int H,W,K;
    cin >> H >> W >> K;
    vector<vector<char>> A(W,vector<char>(H,0));
    for(int i=0;i<H;i++)for(int j=0;j<W;j++){
        cin >> A[j][i];
    }
    
    int ans=0;
    
    for(int i=0;i<(1<<H);i++){
        
        for(int j=0;j<(1<<W);j++){
            
            int count=0;
            for(int k=0;k<H;k++){
                
                for(int l=0;l<W;l++){
                    
                    if(bitget(i, k)||bitget(j, l))continue;
                    count+=(A[l][k]=='#');
                    
                }
                
            }
            
            ans+=(count==K);
            
        }
        
        
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3636