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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}


int atcoder(){
    int ans;
    double n,ave=0,sa=1000.0;
    cin>>n;
    vector<double> v(n);
    REP(i,0,n){
        cin>>v[i];
        ave += v[i];
    }
    ave /= n;
    REP(i,0,n){
        if(abs(v[i]-ave)<sa){
            ans=i;
            sa=abs(v[i]-ave);
        }
    }
    cout<<ans<<ENT;
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    ll r=0;
    ll g=0;
    ll b=0;
    rep(i,n){
        if(s[i]=='R')r++;
        if(s[i]=='G')g++;
        if(s[i]=='B')b++;
    }
    ll ans=0;
    ans+=r*g*b;
    if(ans==0){cout << 0 << endl;return 0;}
    rep(i,n){
        rep(j,n){
            if(j+2*i>=n)continue;
            if(s[j]!=s[j+i]&&s[j+i]!=s[j+2*i]&&s[j+2*i]!=s[j])ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#Doubling lca
class Node
  attr_accessor :child, :depth, :parent
  def initialize
    @child = []
    @depth = 0
    @parent = []
  end
end

def dfs(root, g)
  stack = [root]
  g[root].depth = 0
  g[root].parent[0] = -1
  while stack.size > 0
    s = stack[-1]
    t = g[s].child.shift
    if t
      stack << t
      g[t].depth = g[s].depth + 1
      g[t].parent[0] = s
    else
      stack.pop
    end
  end
end

n = gets.to_i
g = Array.new(n){Node.new}
n.times{|i|
  g[i].child = gets.split.map(&:to_i)
  g[i].child.shift
}

dfs(0, g)
k = 0
while k < Math.log2(n)
  v = 0
  while v < n
    if g[v].parent[k] < 0
      g[v].parent[k+1] = -1
    else
      g[v].parent[k+1] = g[g[v].parent[k]].parent[k]
    end
    v += 1
  end
  k += 1
end

q = gets.to_i
known = Hash.new{|h, key| h[key] = {}}

q.times{
  u, v = gets.split.map(&:to_i)
  u, v = v, u if g[u].depth > g[v].depth
  uu = u
  vv = v
  unless known[uu][vv]
    k = 0
    while k < Math.log2(n) + 1
      if (g[v].depth - g[u].depth) >> k & 1 == 1
        v = g[v].parent[k]
      end
      k += 1
    end
    if u == v
      known[uu][vv] = u
    else
      k = (Math.log2(n) - 1).to_i
      while k >= 0
        if g[u].parent[k] != g[v].parent[k]
          u = g[u].parent[k]
          v = g[v].parent[k]
        end
        k -= 1
      end
      known[uu][vv] =  g[u].parent[0]
    end
  end
  puts known[uu][vv]
}

Measured memory_bytes: 88000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  vector<int> a1(n),a2(n);
  rep(i,n){
    cin >> a1.at(i);
  }
  rep(i,n){
    cin >> a2.at(i);
  }
  int ans=0;
  int sum=0,p;
  rep(i,n){
    sum+=a1.at(i);
    p=sum;
    for(int j=i;j<n;j++){
      p+=a2.at(j);
    }
    ans=max(ans,p);
  }
  cout << ans;
}
      
    
      
      

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

int main() {
    //freopen( "C:\\Users\\ehab\\Desktop\\problems\\in.txt" , "r" , stdin );

    int a , b , x;
    cin >> a >> b >> x;

    if ( a > x ) cout << "NO";
    else if ( a == x ) cout << "YES";
    else if ( a < x && a + b >= x ) cout << "YES";
    else if ( a < x && a + b <  x ) cout << "NO";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int a[1001];
 int n,k,min=0;
 cin>>n>>k;
 for(int i=1;i<=n;i++)
 {
 	cin>>a[i];
 	 for(int j=i;j>1;j--)
 	
 	  if(a[j]<a[j-1]) swap(a[j-1],a[j]); 
 } 
 for(int i=1;i<=k;i++)
 {
 	min+=a[i];
 }
 cout<<min;
 return 0;
 
 }

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

int maxi(int a,int b){if(a>b){return a;}return b;}

int main(void){
  int n, m, i, j;
  scanf("%d", &n);
  char s[n][11];
  for(i = 0; i < n; i++){
    scanf("%s", s[i]);
  }
  scanf("%d", &m);
  char t[m][11];
  int count = 0;
  int max = 0;
  for(i = 0; i < m; i++){
    scanf("%s", t[i]);
  }
  
  for(i = 0; i < n; i++){
    count = 0;
    for(j = 0; j < n; j++){
      if(strcmp(s[i], s[j]) == 0) count++;
    }
    for(j = 0; j < m; j++){
      if(strcmp(s[i], t[j]) == 0) count--;
    }
    max = maxi(max, count);
  }
  printf("%d\n", max);
  return 0;
}

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

int a1,b1,a2,b2,k;

int main() {
	cin>>a1>>b1>>a2>>b2>>k;
	int v=(a2-a1)*60-b1+b2-k;
	if(v>=0) cout<<v;
	else cout<<0;
	return 0;
}

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

long int myPow(long int _x, long int _n)
{
  long int ret = 1;
  while (0 < _n)
  {
    if ((_n % 2) == 0)
    {
      _x *= _x;
      _n >>= 1;
    }
    else
    {
      ret *= _x;
      --_n;
    }
  }
  return ret;
}

int main()
{

  long int H;
  long int result = 0;

  cin >> H;

  long int count = 0;

  while (H != 1)
  {
    H /= 2;
    count++;
  }

  for (long int i = 0; i < count + 1; i++)
  {
    result += myPow(2, i);
  }

  cout << result << endl;
}


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

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cinm(char, 6, m);
    Cout(m['1']);
}





Measured memory_bytes: 384
// https://abc070.contest.atcoder.jp/tasks/abc070_c
#include <iostream>
using namespace std;
typedef long long ll;

int N;
ll T;

ll gcd(ll x, ll y)
{
    ll tmp;
    if (y > x)
        return gcd(y, x);
    while (x % y > 0) {
        tmp = x % y;
        x = y;
        y = tmp;
    }
    return y;
}

ll lcm(ll x, ll y)
{
    return x / gcd(x, y) * y;
}

int main()
{
    cin >> N;
    ll acc = 1LL;
    for (int i = 0; i < N; ++i)
    {
        cin >> T;
        acc = lcm(acc, T);
    }
    cout << acc << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

int ans[200010];

signed main(){
    int n, k; cin >> n >> k;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    REP(i,k){
        vector<int> b(n,0);
        REP(j,n){
        b[max(0ll,j-a[j])]++;
        b[min(n,j+a[j]+1)]--;
        }
        REPS(i,n)b[i] += b[i-1];
        if(a == b)break;
        a = b;
    }
  	REP(i,n) cout <<a[i]<<" ";
}

Measured memory_bytes: 6424
#include <stdio.h>
int main(void){
    // Your code here!
    //整数 x, y について、x ≥ y ならば x と y の最大公約数は y と x % y の最大公約数に等しい。ここで x % y は x を y で割った余りである。
    int x, y , a;
    scanf( "%d %d" , &x , &y );
    
    a = x % y ;
    
    while( a != 0 ){
        a = x % y ;
        x = y;
        y = a;
        //printf("%d %d %d\n" , x , y , a );
    }
    printf( "%d\n" , x );
}



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

const int N = 200020;
int n, a[N], c[N];
int main() {
  scanf ("%d", &n);
  for (int i = 1; i <= n; ++i) scanf ("%d", &a[i]), ++c[a[i]];
  long long ans = 0;
  for (int i = 1; i <= n; ++i) ans += c[a[i]] - 1;
  ans /= 2;
  for (int i = 1; i<= n; ++i) {
    cout << ans - (c[a[i]] - 1) << "\n";
  }
}


Measured memory_bytes: 3712
import sys

n, m = map(int, sys.stdin.readline().split())
*p, = map(int, sys.stdin.readline().split())
xy = list(zip(*[map(int, sys.stdin.read().split())] * 2))

g = [[] for _ in range(n+1)]
for x, y in xy:
    g[x-1].append(y-1)
    g[y-1].append(x-1)

root = list(range(n))
height = [0] * n

def find_root(v):
    u = root[v]
    if u == v:
        return u
    w = find_root(u)
    root[v] = w
    return w

def unite(v, u):
    rv = find_root(v)
    ru = find_root(u)
    if root[rv] == root[ru]:
        return
    if height[rv] >= height[ru]:
        root[ru] = rv
        height[rv] = max(height[rv], ru+1)
    else:
        root[rv] = ru

def main():
    for x, y in xy:
        unite(x-1, y-1)

    for i in range(n):
        find_root(i)
    
    cnt = 0
    for i in range(n):
        cnt += (root[i] == root[p[i]-1]) & 1
    
    return cnt
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 43292
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int k=0,m,n,i=0,j=0,s=0,l,sum=0;
    long long arr[105][105],bb[105][1005],cc[105][105];
    cin>>n>>m>>l;
    
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            cin>>arr[i][j];
        }
    }
    for(i=0; i<m; i++)
        for(j=0; j<l; j++)
            cin>>bb[i][j];
    
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < l; j++)
        {
            for (int k = 0; k < m; k++)
            {
                cc[i][j]+=arr[i][k]*bb[k][j];
            }
            
            
        }
    }
    for(i=0; i<n; i++)
    {
        for(j=0; j<l; j++)
        {
            if(j==l-1)
                cout<<cc[i][j];
            else
                cout<<cc[i][j]<<" ";
        }
        cout<<endl;
        
        
    }
}







Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long N, GA, SA, BA, GB, SB, BB; 
	cin >> N >> GA >> SA >> BA >> GB >> SB >> BB; 
	bool g = 0, s = 0, b = 0; 
	int cnt = 0; 
	if(GA <= GB){
		g = 1; cnt ++; 
	}
	if(SA <= SB){
		s = 1; cnt ++; 
	}
	if(BA <= BB){
		b = 1; cnt ++; 
	}
	long long ans = N; 
	if(cnt == 0){
		swap(GA, GB); swap(SA, SB); swap(BA, BB); 
	}
	if(cnt == 3 || cnt == 0){
		for(long long i = 0; i * GA <= N; i++){
			for(long long int j = 0; j * SA + i * GA <= N; j++){
				long long m1 = GB * i; 
				long long m2 = SB * j; 
				long long nokori = N - (j * SA + i * GA); 
				long long m3 = nokori / BA * BB; 
				long long m4 = nokori % BA; 
				ans = max(ans, m1 + m2 + m3 + m4); 
			}
		}
	}
	if(cnt == 2){
		if(!s){
			swap(GA, SA); swap(GB, SB); 
		}
		if(!b){
			swap(GA, BA); swap(GB, BB); 
		}
		long long keika = N; 
		for(long long i = 0; i <= N; i++){
			long long m1 = i / SA * SB; 
			long long m2 = (N - i) / BA * BB; 
			long long m3 = i % SA + (N - i) % BA; 
			keika = max(keika, m1 + m2 + m3); 
		}
		ans = keika % GB + (keika / GB) * GA; 
	}
	if(cnt == 1){
		if(s){
			swap(GA, SA); swap(GB, SB); 
		}
		if(b){
			swap(GA, BA); swap(GB, BB); 
		}
		long long keika = N % GA + (N / GA) * GB; 
		for(long long i = 0; i <= keika; i++){
			long long m1 = i / SB * SA; 
			long long m2 = (keika - i) / BB * BA; 
			long long m3 = i % SB + (keika - i) % BB; 
			ans = max(ans, m1 + m2 + m3); 
		}
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int cnt(int64 n) {
  int ret = 0;
  for (; n; n /= 10) ++ret;
  return ret;
}

int main() {
  int64 n;
  cin >> n;
  int ret = 1 << 30;
  for (int64 i = 1; i * i <= n; ++i) {
    if (n % i) continue;
    int64 j = n / i;
    ret = min(ret, max(cnt(i), cnt(j)));
  }
  cout << ret << endl;
  return 0;
}


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

using namespace std;
using LL = long long;

const int N = 5005;
const int inf = 1e9;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
	string s;
	cin >> s;
	for (char &c : s) c -= '0';
	int a = s[0] * 10 + s[1];
	int b = s[2] * 10 + s[3];

	if (a >= 1 and a <= 12 and b >= 1 and b <= 12) {
		puts("AMBIGUOUS");
	}
	else if (a >= 1 and a <= 12) {
		puts("MMYY");
	}
	else if (b >= 1 and b <= 12) {
		puts("YYMM");
	} else {
		puts("NA");
	}

}

Measured memory_bytes: 256
N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))
ans = 0

for i in range(Q):
  def is_ok(idx):
    return S[idx] <= T[i]

  def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
      mid = (ok + ng) // 2
      if is_ok(mid):
        ok = mid
      else:
        ng = mid
    return ok
  
  if T[i] == S[meguru_bisect(N, -1)]:
    ans += 1
print(ans)


Measured memory_bytes: 16708
n=int(input())-1
A=list(map(int,input().split()))
i=0
for j in range(n):
 if A[j]<=A[-1]:A[i],A[j]=A[j],A[i];i+=1
A[i],A[n]='['+str(A[n])+']',A[i]
print(*A)


Measured memory_bytes: 16380
from collections import deque

X = input()

dq = deque()

for x in X:
    if not dq:
        dq.append(x)
    elif dq[-1] == "S" and x == "T":
        dq.pop()
    else:
        dq.append(x)
    
ans = len(dq)
print(ans)

Measured memory_bytes: 5096
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, t = 0, h = 0, sm = 1, tmp = 1;
  scanf("%lld", &n);
  ll ans = n * (n + 1) / 4 + 1;
  while(n + 10 > sm) sm *= 2;
  ll a[n], up[n], seg[sm * 2], las[sm * 2];
  for(i = 1; i < sm * 2; ++i) {
    if(tmp * 2 == i) tmp *= 2;
    las[i] = sm / tmp * (i - tmp + 1) - 1;
  }
  bool upo[n];
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    if(a[i] > t) t = a[i];
  }
  while(t != h + 1) {
    ll now = (t + h) / 2, sum = 0, cnt = 0;
    for(i = 0; i < sm * 2; ++i) seg[i] = 0;
    for(i = 0; i < n; ++i) up[i] = (a[i] > now ? 1 : 0), upo[i] = a[i] > now;
    for(i = 1; i < n; ++i) up[i] += up[i - 1];
    for(i = 2; i < n; ++i) up[i] -= i / 2;
    for(i = n - 1; i >= 0; --i) {
      if(!(i % 2)) {
        tmp = up[i] + n / 2 + sm + 1;
        if(upo[i]) --tmp;
        else sum++;
        while(tmp) sum += seg[tmp], tmp /= 2;
      }
      ll l = sm - 1;
      tmp = up[i] + n / 2 + sm + 1;
      while(1) {
        while(!(tmp % 2)) tmp /= 2;
        seg[tmp]++;
        if(las[tmp] == l) break;
        tmp++;
      }
    }
    for(i = 0; i < sm * 2; ++i) seg[i] = 0;
    for(i = 0; i < n; ++i) up[i] = (a[i] > now ? 1 : 0);
    for(i = 1; i < n; ++i) up[i] += up[i - 1];
    for(i = 3; i < n; ++i) up[i] -= (i - 1) / 2;
    for(i = n - 1; i >= 0; --i) {
      if(i % 2) {
        tmp = up[i] + n / 2 + sm + 1;
        if(upo[i]) --tmp;
        else sum++;
        while(tmp) sum += seg[tmp], tmp /= 2;
      }
      ll l = sm - 1;
      tmp = up[i] + n / 2 + sm + 1;
      while(1) {
        while(!(tmp % 2)) tmp /= 2;
        seg[tmp]++;
        if(las[tmp] == l) break;
        tmp++;
      }
    }
    if(sum >= ans) t = now;
    else h = now;
  }
  printf("%lld\n", t);
  return 0;
}

Measured memory_bytes: 6016
#include<bits/stdc++.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long H,N;
    cin >> H >> N;
    vector<long> A(N);
  	for(long i=0;i<N;i++) cin >> A[i];
    if(H>accumulate(A.begin(),A.end(),0)) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 1024
// 2019.cpp : This file contains the 'main' function. Program execution begins and ends there.
//JANUARY: {1521, 1644} -> {1614, 1644} -> {1643, 1644} ->

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


#define int long long
#define all(a) a.begin(), a.end()
#define need_for_speed ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const int INF = 1e18;
int dp[26][26];
string s[26];


signed main()
{
	need_for_speed;
	int n; cin >> n; 
	int k; cin >> k;

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

	vector<int> dp(n, INF);
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i - j >= 0) {
				dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
			}
		}
		
	}
	cout << dp[n - 1];
}




Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}
 
int main(void){
    int N; cin >> N;
    string S; cin >> S;
    
    int ans = 0;
    for(int i = 0; i < N; i++){
        string X, Y;
        X = S.substr(0, i);
        Y = S.substr(i);
        int count = 0;
        map<char, int> mpX, mpY;
        for(int i = 0; i < X.size(); i++){
            mpX[X[i]]++;
        }
        for(int i = 0; i < Y.size(); i++){
            mpY[Y[i]]++;
        }
        for(char c = 'a'; c <= 'z'; c++){
            if(mpX[c] > 0 && mpY[c] > 0) count++;
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// ref. https://img.atcoder.jp/exawizards2019/editorial.pdf

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int dir = 0;
ll n, q;
string s;
vector<pair<char, char>> spells; // pair of <t, d>

// Check the destination of x. Return true if x does not reach to -1.
bool check(ll x) {
  rep(i, q) {
    char t, d;
    tie(t, d) = spells[i];
    if (s[x] == t) { // match
      if (dir == 0) {
        x = (d=='L') ? (x-1) : (x+1);
      } else { // reverse
        x = (d=='L') ? (x+1) : (x-1);
      }
    }
    if (x < 0) { return false; }
    if (x >= n) { return true; }
  }
  return true;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  cin >> n >> q;
  cin >> s;
  spells.resize(q);
  rep(i, q) {
    cin >> spells[i].first >> spells[i].second;
  }

  vector<ll> range(2);
  rep(k, 2) {
    // Here, we do binary search to calculate left boundary.
    ll l = -1, r = n;
    // search in (l, r]
    while (r-l > 1) {
      ll mid = (r+l)/2;
      if (check(mid)) { // mid does not go to -1
        r = mid;
      } else {
        l = mid;
      }
    }
    // Here, l is out. r is in.
    range[k] = r;
    reverse(all(s));
    dir ^= 1;
  }

  ll left  = range[0];
  ll right = n-1-range[1];

  if (right >= left) {
    cout << (right-left+1) << endl;
  } else {
    cout << 0 << endl;
  }
}


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

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

    //good luck, kittu
    map<string, int> m;
    m["SUN"] = 7;
    m["MON"] = 6;
    m["TUE"] = 5;
    m["WED"] = 4;
    m["THU"] = 3;
    m["FRI"] = 2;
    m["SAT"] = 1;
    string s; cin>>s;
    cout<<m[s]<<"\n";
    return 0;
}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n, m, x, y;
    cin>>n>>m>>x>>y;
    int a[n], b[m];

    int i, j, k;
    int a_max = -1000;
    int b_min = 1000;

    for(i=0; i<n; i++){
        cin>>a[i];
        if(a[i]>a_max){
            a_max = a[i]; 
        }
    }
    for(i=0; i<m; i++){
        cin>>b[i];
        if(b[i]<b_min){
            b_min = b[i];
        }
    }

    if(a_max<b_min){
        for(int z = a_max+1; z<=b_min; z++){
            if(x<z && z<=y){
                cout<<"No War"<<endl;
                return 0;
            }
        }
    }
    else{
        cout<<"War"<<endl;
        return 0;
    }

    cout<<"War"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <random>
#include <deque>
#define INF_LL 1e18
#define INF 1e9

typedef long long ll;

using namespace std;

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

  ll ppp[n];
  ll ppm[n];
  ll pmp[n];
  ll pmm[n];
  ll mpp[n];
  ll mpm[n];
  ll mmp[n];
  ll mmm[n];

  for (int i = 0; i < n; i++)
  {
    ll x, y, z;
    cin >> x;
    cin >> y;
    cin >> z;

    ppp[i] = x + y + z;
    ppm[i] = x + y - z;
    pmp[i] = x - y + z;
    pmm[i] = x - y - z;
    mpp[i] = -x + y + z;
    mpm[i] = -x + y - z;
    mmp[i] = -x - y + z;
    mmm[i] = -x - y - z;
  }

  sort(ppp, ppp + n, [](const ll &x, const ll &y) { return x > y; });
  sort(ppm, ppm + n, [](const ll &x, const ll &y) { return x > y; });
  sort(pmp, pmp + n, [](const ll &x, const ll &y) { return x > y; });
  sort(pmm, pmm + n, [](const ll &x, const ll &y) { return x > y; });
  sort(mpp, mpp + n, [](const ll &x, const ll &y) { return x > y; });
  sort(mpm, mpm + n, [](const ll &x, const ll &y) { return x > y; });
  sort(mmp, mmp + n, [](const ll &x, const ll &y) { return x > y; });
  sort(mmm, mmm + n, [](const ll &x, const ll &y) { return x > y; });

  cout << max({
              accumulate(ppp, ppp + m, 0LL),
              accumulate(ppm, ppm + m, 0LL),
              accumulate(pmp, pmp + m, 0LL),
              accumulate(pmm, pmm + m, 0LL),
              accumulate(mpp, mpp + m, 0LL),
              accumulate(mpm, mpm + m, 0LL),
              accumulate(mmp, mmp + m, 0LL),
              accumulate(mmm, mmm + m, 0LL),
          })
       << endl;

  return 0;
}

Measured memory_bytes: 256
[a,v] = list(map(int, input().split()))
[b,w] = list(map(int, input().split()))
t = int(input())
if v>w:
    if abs(a-b) % (v-w) == 0:
        tRE = abs(a - b) // (v - w)
        if tRE<=t:
            print('YES')
        else:
            print('NO')
    else:
        tRE = abs(a - b) / (v - w)
        if tRE<t:
            print('YES')
        else:
            print('NO')
else:
    print('NO')

Measured memory_bytes: 9208
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
//inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}int n,k,nxt[2][1<<21],F[21][1<<21],Lg[1<<21],tot;
char s[1<<20];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),k=read();
	Rep(i,0,n){scanf("%s",s);for(int j=0;j<1<<i;j++)if(s[j]==49)F[i][1<<i^j]=1;}
	Lg[0]=-1;for(int i=1;i<2<<n;i++)Lg[i]=Lg[i>>1]+1;
	for(int s=2;s<2<<n;s++){
		if(s>>(Lg[s]-1)&1)nxt[1][s]=s^1<<Lg[s],nxt[0][s]=nxt[0][nxt[1][s]];
		else nxt[0][s]=s^3<<Lg[s]-1,nxt[1][s]=nxt[1][nxt[0][s]];
	}Red(i,n,1)for(int s=1<<i;s<2<<n;s++)if(F[i][s]){
		int A=s>>i,B=(s&((1<<i)-1))^1<<i;
		if(nxt[0][B])F[Lg[nxt[0][B]]][(A<<1^1)<<Lg[nxt[0][B]]^nxt[0][B]]+=F[i][s];
		if(nxt[1][B])F[Lg[nxt[1][B]]][(A<<1^0)<<Lg[nxt[1][B]]^nxt[1][B]]+=F[i][s];
		F[0][A]+=F[i][s];
	}int Ans=1;
	for(int i=2;i<2<<n;i++)if(F[0][i]>=k&&Lg[i]>Lg[Ans])Ans=i;
	int j=n;for(;~Ans>>j&1;j--);for(;j--;)cout<<(Ans>>j&1);
	return 0;
}




Measured memory_bytes: 195968
import java.util.Scanner;

class Main
{
  public static void main(String args[])
  {
    Scanner scanner = new Scanner(System.in);
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    if(A==7&&B==5&&C==5||A==5&&B==7&&C==5||A==5&&B==5&&C==7)
    {
      System.out.println("YES");
    }
    else
    {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 22100
import java.util.Scanner;

/**
 * TITLE : Bishop
 * URL : https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_b
 */
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long W = sc.nextLong();
        if (H == 1 || W == 1) {
            System.out.println(1);
        } else {
            System.out.println((H * W / 2) + (H * W % 2));
        }
        sc.close();
    }
}

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

int main(){
    int N;
    cin>>N;
    vector<int> H(N);
    for(int i=0;i<N;i++){
        cin>>H.at(i);
    }
    int maxvalue=0;
    int cnt=0;
    for(int i=0;i<N-1;i++){
        if(H.at(i)>=H.at(i+1)){
            cnt++;
            if(i==N-2){
                if(cnt>maxvalue){
                    maxvalue=cnt;
                }
            }
        }
        else if(maxvalue<cnt){
            maxvalue=cnt;
            cnt=0;
        }
        else{
            cnt=0;
        }
    }
    cout<<maxvalue<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cmath>


using namespace std;

int main(){

	int H,W;
	string S[55][55],temp;

	cin>>H>>W;

	for(int j=0; j<H; j++){
		cin>> temp;
		for(int i=0; i<W; i++){

			
			S[i][j] =temp[i];


		}
	}

	bool can=1,can2=0;

	for(int j=0; j<H; j++){
		for(int i=0; i<W; i++){
			
			
			if(S[i][j]  == "#"){
				
				for(int l=-1; l<2;l++){
					for(int k=-1; k<2;k++){

						if(i-k >=0 && j-l>=0 && S[i-k][j-l] =="#" &&abs(l+k) ==1 ){
						

							can=1;
							//cout <<i <<" "<<j <<" " <<k <<" " << l <<" "<<can<< " "<< abs(l+k) <<" "<<"aa" <<endl;
							break;
							
						}

						
							
						else{
							can=0;

							//cout <<i <<" "<<j <<" " <<k <<" " << l <<" "<< abs(l+k) <<" "<<can<<endl;

						}


					}
					if(can ==1) break;
				}
					

			}

			if (can ==0) {
				
				cout <<"No" <<endl; 
				return 0;
			}

		}
	
	}

	if(can) cout <<"Yes" <<endl;
	else cout <<"No" <<endl;

}


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

class MainClass
{
    static long[,] d;
    static int[] r;
    static void Main()
    {
        var NMR = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = NMR[0], M = NMR[1], R = NMR[2];
        r = Console.ReadLine().Split().Select(_=>int.Parse(_)-1).ToArray();
        d = new long[N, N];
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if (i == j) continue;
                d[i, j] = long.MaxValue/128;
            }
        }
        for (int i = 0; i < M; i++)
        {
            var abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = abc[0] - 1;
            int b = abc[1] - 1;
            int c = abc[2];
            d[a, b] = c;
            d[b, a] = c;
        }

        for (int k = 0; k < N; k++)
        {
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
                }
            }
        }

        long ans = long.MaxValue;
        used = new bool[N];
        foreach (var item in r)
        {
            used[item] = true;
            ans = Math.Min(Search(1, item, 0), ans);
            used[item] = false;
        }
        Console.WriteLine(ans);
    }

    static bool[] used;
    static long Search(int count,int now,long cost)
    {
        if (count == r.Length)
        {
            return cost;
        }
        
        long ans = long.MaxValue;
        foreach (var i in r)
        {
            if (!used[i])
            {
                used[i] = true;
                ans = Math.Min(ans, Search(count+1, i, cost + d[now, i]));
                used[i] = false;
            }
                
        }

        return ans;
    }
}


Measured memory_bytes: 35260
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll N, K; cin >> N >> K;
  if (N%K) {
    println(1);
  } else {
    println(0);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long int ll;
int main()
{
	ll n,f=0,g=0,x,y;
	cin>>n;
	std::vector<ll> a(n);
	for (int i = 0; i < n; ++i)
		{
			cin>>a[i];
		}	
		std::vector<ll> v;
		v=a;
		sort(v.begin(),v.end());
	for (int i = 0; i < n; ++i)
	{
		if(a[i]!=v[i] && f==0)
		{
			x=a[i];
			y=v[i];
			f++;
		}
		 else if(a[i]!=v[i] && f==1)
		{
			if(x==v[i] && y==a[i])
				g=1;
			else{
				g=-1;
				break;
			}
			f++;
		}
		 else if(a[i]!=v[i])
		{
			g=-1;
			break;
		}

	}
	if(g==-1)
		cout<<"NO\n";
	else 
		cout<<"YES\n";
}

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

int a[26] = {0};
int main() {
	string s;
	while (cin >> s) {
		for (int i = 0; i < s.size(); i++){
			if (s[i] >= 'a' && s[i] <= 'z')
				a[s[i]-97] += 1; 
			if (s[i] >= 'A' && s[i] <= 'Z')
				a[s[i]-65] += 1; 
		}
	} 
	for (char c = 'a'; c <= 'z'; c++){
		cout << c << " : " << a[c-97] << endl;
	}
}


Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vector<ll> num(n+1, 0);
  for(int i=2;i<=n;i++){
    ll a;std::cin >> a;
    num[a]++;
  }
  for(int i=1;i<=n;i++) std::cout << num[i] << '\n';
  return 0;
}


Measured memory_bytes: 4360
#include <bits/stdc++.h>
#define M ((ll)1e9+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi acos(-1)


typedef long long ll;
using namespace std;
vector<map<int,int>> v;
 
int n;
/*map<pair<int,int>,int> m;*/
void dfs(int c,int p,int color)
{
    int co=1;
    for(auto it=v[c].begin();it!=v[c].end();it++)
    {
        if(it->F!=p)
        {
            if(co==color)
            co++;
            v[c][it->F]=co;
            v[it->F][c]=co;
            dfs(it->F,c,co);
            co++;
        }
    }
}
void solve(){
       cin>>n;int a,b;
       v.resize(n+1);
       //v1.resize(n-1);
       vector<pair<int,int>> v1;
       for(int i=0;i<n-1;i++)
       {
           cin>>a>>b;
           v[a][b]=-1;
           v[b][a]=-1;
           v1.pb({a,b});
       }
       
       //cout<<1<<endl;
      /* for(int i=0;i<n-1;i++)
       cout<<v1[i].F<<" "<<v1[i].S<<endl;*/
       dfs(1,0,0);
       /*for(int i=1;i<=n;i++)
       {
           for(auto it=v[i].begin();it!=v[i].end();it++)
           cout<<it->F<<" "<<it->S<<"/";
           cout<<endl;
       }*/int ma=0,h[n-1];
       for(int i=0;i<n-1;i++)
       {
           h[i]=max(v[v1[i].F][v1[i].S],v[v1[i].S][v1[i].F]);ma=max(ma,h[i]);
       }
       cout<<ma<<endl;
       for(int i=0;i<n-1;i++)
       cout<<h[i]<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;}

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

int main()
{
  int64_t H, W, N, a, b;
  cin >> H >> W >> N;
  map<pair<int64_t, int64_t>, int64_t> mp;
  int dh[9] = {0, -1, -1, -1, 0, 0, 1, 1, 1};
  int dw[9] = {0, -1, 0, 1, -1, 1, -1, 0, 1};
  for (int i = 0; i < N; i++)
  {
    cin >> a >> b;
    for (int j = 0; j < 9; j++)
    {
      if (a + dh[j] <= 1 || a + dh[j] >= H || b + dw[j] <= 1 || b + dw[j] >= W)
        continue;
      mp[{a + dh[j], b + dw[j]}]++;
    }
  }
  vector<int64_t> ans(10, 0);
  ans[0] = (H - 2) * (W - 2) - mp.size();
  for (auto it = mp.begin(); it != mp.end(); it++)
  {
    ans[it->second]++;
  }
  for (auto i : ans)
  {
    cout << i << endl;
  }
}

Measured memory_bytes: 59800
#include<iostream>
using namespace std;main(){string r, k="hijklmnopyu";while(cin>>r,r!="#"){bool f,s;int ans=0,i=0;f = ~(k.find(r[0]));for(;i<r.size();i++){s=~(k.find(r[i]));if(f^s)ans++;f=s;}cout<<ans<<endl;}}

Measured memory_bytes: 1188
import bisect
import sys,io
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():

    N,K = isRaw()
    Ps = isRaw()
    Cs = isRaw()
    ans = max(Cs)
    for n in range(N):
        curPos = n
        cycles =[]
        visited = {}
        lastCost = 0
        vidx = 0
        loopStart = -1
        while True:
            visited[curPos] = vidx
            lastCost = lastCost+Cs[curPos]
            cycles.append(lastCost)
            curPos= Ps[curPos]-1
            
            if curPos in visited:
                loopStart = visited[curPos]
                break
        
        c_len = len(cycles)
        c_score = cycles[-1]
        if K>=c_len:
            ans = max(ans,c_score*(K//c_len))
        for c in range(0,min(c_len,K)):
            n_cycle = (K-c-1)//c_len
            score = cycles[c]+max(0,c_score*n_cycle)
            ans = max(score,ans)
    print (ans)

         
main()


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

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

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (s.substr(i, 3) == "ABC") {
            cnt++;
            i += 2;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)


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

    ll ans = 0;
    ll cnt = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i]=='B'){
            break;
        }else{
            cnt++;
        }
    }
    for(int i = 0; i < s.size()-1; i++){
        if(s[i]=='B' && s[i+1]=='W'){
            ans += i+1-cnt;
            cnt++;
            s[i+1] = 'B';
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int N , A;
  int S2 = 0;
  cin >> N;
  for(int i = 0; i < N ; i++){
    cin >> A;
    int S1 =0;
    for (int x = 1; A%2 == 0; x++){
      A /= 2;
      S1 = x;
    }

    if(i==0){
      S2 = S1;
    }
    else if(S1 <= S2){
      S2 = S1;
    }
  }
  cout << S2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
int a,b,c,d,e,f,i,j;
string s[100];
int x[30]={1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47};
int y[30]={50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96};
int main()
{ 
  cin >> a >> b;
    c=(a-1)/24;
    d=(b-1)/24;
    e=(a-1)%24;
    f=(b-1)%24;
  for(i=0;i<49;i++){s[i]="#################################################";
                    }
  for(i=49;i<98;i++){s[i]=".................................................";
                     }
  for(i=0;i<c;i++){s[x[i]]="#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#";
                  }
  for(j=0;j<e;j++){s[x[i]].replace(x[j],1,".");
                  }
  for(i=0;i<d;i++){s[y[i]]=".#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.";
                  }
  for(j=0;j<f;j++){s[y[i]].replace(x[j],1,"#");
                  }
  cout << 98 << " " << 49 << endl;
  for(i=0;i<98;i++){cout << s[i] << endl;
                   }
} 

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include  <cassert>
#include <fstream>
#include <codecvt>

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
//#define int ll
//const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


string s;
int N[4];
bool solved = false;

void dfs(int i, string s) {
	if (i == 3) {
		int tmp = N[0];
		rep(j, 3) {
			if (s[j] == '+') {
				tmp += N[j+1];
			}
			else {
				tmp -= N[j+1];
			}
		}
		if (tmp == 7 and !solved) {
			cout << N[0] << s[0] << N[1] << s[1] << N[2] << s[2] << N[3] <<  "=7" << endl;
			solved = true;
		}
		return;
	}
	dfs(i + 1, s + "+");
	dfs(i + 1, s + "-");
}

signed main() {
	ios::sync_with_stdio(true);
	cin >> s;
	N[0] = (int)(s[0] - '0');
	N[1] = (int)(s[1] - '0');
	N[2] = (int)(s[2] - '0');
	N[3] = (int)(s[3] - '0');
	string a = "";
	dfs(0,a);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  double n,c,k;
  cin >> n >> c >> k;
  vector<int> t(n);
  for(int i=0;i<n;i++) cin >> t[i];
  sort(t.begin(), t.end());
  int cnt = 0, buf = t[0], rem = 1;
  for(int i=1;i<n;i++){
    if(buf+k < t[i] || rem == c){
      cnt++;
      buf = t[i];
      rem = 1;
    }else rem++;
  }
  
  cout << ++cnt << endl;
}

Measured memory_bytes: 640
src = []
src.append(list(map(int, input().split())))
src.append(list(map(int, input().split())))
src.append(list(map(int, input().split())))
for n1, n2 in zip([0, 1, 2], [1, 2, 0]):
    if not len(set(s[n1] - s[n2] for s in src)) == 1 or\
       not len(set(s1 - s2 for s1, s2 in zip(src[n1], src[n2]))) == 1:
        dst = "No"
        break
else:
    dst = "Yes"
print(dst)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;

const int N = 2*10e5+2;
vi   r[N],t[N];				
map<pair<int,int>,int > ans;	
int c1[N],c2[N],o=0;
bool mark[N];


void dfs1(int i){
	mark[i] = 1;
	c1[i]=o;
	rep(j,r[i].size()){
		if(!mark[r[i][j]]) dfs1(r[i][j]);
	}
}
void dfs2(int i){
	mark[i] = 1;
	c2[i]=o;
	ans[{c1[i],c2[i]}]++;
	rep(j,t[i].size()){
		if(!mark[t[i][j]]) dfs2(t[i][j]);
	}
}

int main(){
    int n,k,l;
    cin>>n>>k>>l;
    int s,e;
    rep(i,k){
        cin>>s>>e;
        r[s-1].pb(e-1);
        r[e-1].pb(s-1);
    }
    rep(i,l){
        cin>>s>>e;
        t[s-1].pb(e-1);
        t[e-1].pb(s-1);
    }

    rep(i,n){
    	if(!mark[i]){
    		o++;
    		dfs1(i);
    	}
    }
    memset(mark,0,sizeof(mark));
    o=0;
    rep(i,n){
    	if(!mark[i]){
    		o++;
    		dfs2(i);
    	}
    }
    rep(i,n){
    	cout<<ans[{c1[i],c2[i]}]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 114304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    char a; cin >> a;
    if(a<95) cout << "A\n";
    else cout << "a\n";
}


Measured memory_bytes: 3644