akhauriyash/Code-Regression huggingface dataset:
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.function.Predicate;

public class Main {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        sc.close();
        List<String> strs = new LinkedList<>();
        for(int i = input.length() - 1;i > -1;i--)
            strs.add(input.substring(0,i));
        strs.stream().filter(check).max(Comparator.comparing(String::length)).ifPresent(e -> System.out.println(e.length()));
    }
    static Predicate<String> check = str -> {
        if(str.length() % 2 != 0)
            return false;
        else
        {
            int half = str.length() / 2;
            return (str.substring(0,half).equals(str.substring(half,str.length())));
        }
    };
}


Measured memory_bytes: 26964
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int n,m;
    cin >>n>>m;
    cout << (n-1)*(m-1) << endl;



}


Measured memory_bytes: 256
# Frog2
N, K = map(int, input().split())
h = list(map(int, input().split()))
inf = float("inf")
dp = [inf for _ in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1, K+1):
        if i + j >= N:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i+j]))
print(dp[-1])

Measured memory_bytes: 91032
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, q;
  cin >> n >> q;
  
  queue<pair<string, int> > que;
  string name;
  int time;
  
  int now = 0;
  
  rep(i, 0, n) {
    cin >> name >> time;
    que.push({name, time});
  }
  
  while(!que.empty()) {
    if(que.front().second -q <= 0) {
      now += que.front().second;
      cout << que.front().first << " " << now << "\n";
      que.pop();
    }
    else {
      now += q;
      que.front().second -= q;
      que.push(que.front());
      que.pop();
    }    
  }
}



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

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//typedef long long ll;


int main(){
    int N,M,Q,L,R,r;
    cin >> N >> M >> Q;
    int S[Q],T[Q];

    vector<vector<int>> v(N+1,vector<int> (N+1,0));
    for (int i=0;i<M;++i){
        cin >> L >> R;
        v[L][R] += 1;
    }
    for (int i=0;i<Q;++i){
        cin >> S[i] >> T[i];
    }

    

    for (int i=1;i<=N;++i){
        for (int j=1;j<=N;++j){
            v[i][j] = v[i][j-1]+v[i][j];
        }
    }

    for (int i=1;i<=N;++i){
        for (int j=1;j<=N;++j){
            v[i][j] += v[i-1][j];
        }
    }
    int p,q;
    for (int i=0;i<Q;++i){
        p=S[i];
        q=T[i];
        r = v[q][q] -v[p-1][q] - v[q][p-1]  + v[p-1][p-1];
        cout << r << endl;
    }

}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod=1e9+7;
       

int main(){
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5]){cout << "Yes" << endl;}else{cout << "No" << endl;}
}

Measured memory_bytes: 256
# include <iostream>
# include <vector>


using namespace std;


int main() {
    long long n, k, s; cin >> n >> k >> s;

    vector<long long> a(n, s);
    for (int i=0; i<n-k; i++) {
        if (s == 1e9) {
            a[i]--;
        }
        else {
            a[i]++;
        }
    }

    for (auto a_i: a) cout << a_i << ' '; cout << endl;

    return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>
int min(int a,int b){
  return a<b?a:b;
}
int main(void){
  int a[4]={0},i;
  char s[301];
  scanf("%s",s);
  for(i=0;s[i];i++){
    switch(s[i]){
    case 'K':a[0]++;break;
    case 'U':a[1]++;break;
    case 'P':a[2]++;break;
    case 'C':a[3]++;break;
    }
  }
  printf("%d\n",min(a[0],min(a[1],min(a[2],a[3]))));
  return 0;
}

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

int main(){
	int i;
	string S;
	cin >> S;
	int o = 15 - S.size();
	for(i = 0; i < S.size(); i++){
		if(S[i] == 'o'){
			o++;
		}
	}
	if(o >= 8){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b,c;
int ab[100000],ac[100000],bc[100000];
inline int ok(char x,char y){return (x=='?'||y=='?'||x==y);}
int main()
{
	cin>>a>>b>>c;
	int A=a.size(),B=b.size(),C=c.size();
	for(int i=0;i<A;i++)
		for(int j=0;j<B;j++)
			if(!ok(a[i],b[j]))ab[i-j+50000]=true;
	for(int i=0;i<A;i++)
		for(int j=0;j<C;j++)
			if(!ok(a[i],c[j]))ac[i-j+50000]=true;
	for(int i=0;i<B;i++)
		for(int j=0;j<C;j++)
			if(!ok(b[i],c[j]))bc[i-j+50000]=true;
	int ans=6000;
	for(int i=-4000;i<=4000;i++)
		for(int j=-4000;j<=4000;j++)
			if(!(ab[i+50000]||ac[j+50000]||bc[j-i+50000]))	
				ans=min(ans,max(A,max(B+i,C+j))-min(0,min(i,j)));
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << fixed << setprecision(15);
  cout << 0.5L*H*W << ' ';
  if (x * 2 == W && y * 2 == H) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <stdio.h>
typedef long long ll;
ll MOD = 1000000007;
ll pow(ll a, ll n)
{
	if (n == 0) return 1;
	if (n == 1) return a;
	ll c = (pow(a, n / 2)) % MOD;
	ll temp = c * c % MOD;
	if (n % 2) return temp * a % MOD;
	else return temp;
}
int main()
{
	ll n;
	scanf("%lld", &n);
	printf("%lld", ((pow(10, n) - 2 * pow(9, n) + MOD * 2) % MOD + pow(8, n) % MOD) % MOD);
}

Measured memory_bytes: 3168
#include <iostream>
#include <list>
#include <cstdint>
#include <string>
#include <algorithm>

typedef std::list<std::uint64_t> DType;

int main() {
	DType D;
	std::uint64_t N;
	std::uint64_t C;
	std::string S;
	std::cin >> C;

	for (std::size_t i = 0; i < C; i++) {
		if (!(std::cin >> S)) break;
		if (S[0] == 'i' ||S[0] == 'I') {//insert
			std::cin >> N;		
			D.insert(D.begin(),N);
			continue;
		}
		if (S.size() == 6) {//delete
			std::cin >> N;	
			auto it=std::find(D.begin(), D.end(), N);
			if(it!= D.end())D.erase(it);
			continue;
		}
		if (S.size() == 11) {//deletefirst
			D.pop_front();
			continue;
		}
		if (S.size() == 10) {//deletelast
			D.pop_back();
			continue;
		}
	}

	for (auto it = D.begin(); it != D.end(); it++) {
		if(it!=D.begin())std::cout << ' ';

		std::cout << *it;
	}

	std::cout<<std::endl;

	return 0;
}

Measured memory_bytes: 34340
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    int N;
    cin>>N;
    vector<int>A(N);
    rep(i,N){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    cout<<abs(A[N-1]-A[0])<<endl;
}



Measured memory_bytes: 3576
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]

for i in range(n-1):
  t=l[i][1]
  t+=l[i][0]
  for j in range(i+1,n-1):
    if t<l[j][1]:
      t=l[j][1]
    elif t%l[j][2]!=0:
      t+=l[j][2]-t%l[j][2]
    t+=l[j][0]

  print(t)
print(0)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n=5,m;
ll a[5];

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

  cin>>m;
  ll mn=INF;
  rep(i,n){
    cin>>a[i];
    minch(mn,a[i]);
  }
  cout<<(5+(m-1)/mn)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[100], i, n;
	
		scanf("%d", &n);
		for(i = 0; i < n; i++){
			scanf("%d", &a[i]);
		}
		for(i = n-1; i >=0; i--){
			printf("%d",a[i]);
			if(i == 0){
				break;
			}
			printf(" ");
		}
		
		printf("\n");
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
	int a,b; cin>>a>>b;
	Yes(a*b%2);
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
def main():
    n,k=map(int,input().split())
    H=list(map(int,input().split()))
    dp=[10**9]*(n)
    dp[0]=0
    for i in range(n):
        for j in range(1,k+1):
            if i-j>=0:
                dp[i]=min(dp[i],dp[i-j]+abs(H[i]-H[i-j]))
            
    print(dp[-1])        

main()

Measured memory_bytes: 52444
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

odd = 0

for a in A:
    if a % 2 == 1:
        odd += 1

print("YES") if odd % 2 == 0 else print("NO")


Measured memory_bytes: 84816
n=int(input())
h=list(map(int,input().split()))
count=0
M_count=0
for i in range(n-1):
  if h[i]>=h[i+1]:
    count+=1
  elif h[i]<h[i+1]:
    count=0
  if count>=M_count:
    M_count=count
print(M_count)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=3e3+5;
const int mod=1e9+7;
const ll oo=1e18+5;

int cnt[10][10];
int ans;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;++i){
		int ff,ss;
		if(i>=1&&i<=9) ff=i,ss=i;
		else{
			ss=i%10;
			int num=i;
			while(num){
				ff=num%10;
				num/=10;
			}
		}
		++cnt[ff][ss];
	}  
	for(int i=1;i<=n;++i){
		int ff,ss;
		if(i>=1&&i<=9) ff=i,ss=i;
		else{
			ss=i%10;
			int num=i;
			while(num){
				ff=num%10;
				num/=10;
			}
		}
		ans+=cnt[ss][ff];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    string S;
    cin >> S;
    bool ok = true;
    if(S[0] != 'A') ok = false;
    int count = 0;
    for(int i = 2; i <= S.size() - 2; i++){
        if(S[i] == 'C') {
            count++;
            S[i] = 'c';
        }
    }
    if(count != 1) ok = false;
    for(int i = 1; i < S.size(); i++){
        if(S[i] < 'a' or 'z' < S[i])  ok = false;
    }
    if(ok) puts("AC");
    else puts("WA");
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int n,a[105];
typedef unsigned long long ull;
ull v=1000;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n-1;i++)
		if(a[i]<a[i+1])
		{
			ull t=v%ull(a[i]);
			v/=ull(a[i]);
			v=t+v*ull(a[i+1]);
		}
	cout<<v<<endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define _USE_MATH_DEFINES
#define f first
//#define s second
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF 1000000000000000000
#define MAXN (int)(1e7)+1
#define MOD 1000000007

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pwi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<pair<ll,ll > > > wGraph;
typedef vector<vector<ll> > graph;
//typedef vector<vector<ll> > matrix;



int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(2);

    int n;
    cin>>n;

    if(n%1000) cout<<1000-(n%1000)<<endl;
    else cout<<0<<endl;

    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int A = sc.nextInt();
		final int B = sc.nextInt();
		if (A * B % 2 == 1) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

typedef long long ll;
ll ss = 1e9+7;

int main() {
	ll N;
	cin >> N;
	ll ans=1;

	for (ll i = 1; i <= N; i++) {
		ans = ans%ss;
		ans *= i;
		
	}
	cout << ans%ss << endl;
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int a;
    int l = 0;
    int r = 0;
    for (int i = 0; i < m; i++) {
        cin >> a;
        if (a < x) {
            l++;
        } else {
            r++;
        }
    }
    cout << min(l, r) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);
  string s = "";
  char a,b,c;
  cin>>a>>b>>c;
  s += a;
  s += b;
  s += c;

  cout << (stoi(s) % 4 == 0 ? "YES" : "NO") << LF;

  return 0;
}



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

using namespace std;

bool comp(char a, char b)
{
    return a > b;
}

int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), comp);
    if (s < t)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> D(K);
  
  for(int i = 0; i < K; i++){
    cin >> D.at(i);
  }
  
  bool A = true;
  
  for(int i = 0; i < 10; i++){
    for(int j = 0; j < K; j++){
      if(i == D.at(j)){
        A = false;
        break;
      }
    }
    if(A == true && i >= N){
      cout << i << endl;
      return 0;
    }
    A = true;
  }
  
  A = true;
  
  for(int i = 10; i < 100; i++){
    for(int j = 0; j < K; j++){
      if(i / 10 == D.at(j) || i - i / 10 * 10 == D.at(j)){
        A = false;
        break;
        }
    }
    if(A == true && i >= N){
      cout << i << endl;
      return 0;
    }
    A = true;
  }
  
  A = true;
  
  for(int i = 100; i < 1000; i++){
    for(int j = 0; j < K; j++){
      if(i / 100 == D.at(j) || ((i - i / 100 * 100) / 10 == D.at(j)
         || i - i / 10 * 10 == D.at(j))){
        A = false;
        break;
      }
    }
    if(A == true && i >= N){
      cout << i << endl;
      return 0;
    }
    A = true;
  }
  
  A = true;
  
  for(int i = 1000; i < 10000; i++){
    for(int j = 0; j < K; j++){
      if(i / 1000 == D.at(j) || ((i - i / 1000 * 1000) / 100 == D.at(j)
         || ((i - i / 100 * 100) / 10 == D.at(j) || i - i / 10 * 10 == D.at(j)))){
        A = false;
        break;
      }
    }
    if(A == true && i >= N){
      cout << i << endl;
      return 0;
    }
    A = true;
  }
  
  for(int i = 10000; i < 100000; i++){
    for(int j = 0; j < K; j++){
      if(i / 10000 == D.at(j) || ((i - i / 10000 * 10000) / 1000 == D.at(j)
         || ((i - i / 1000 * 1000) / 100 == D.at(j) 
             || ((i - i / 100 * 100) / 10 == D.at(j) 
                 || i - i / 10 * 10 == D.at(j))))){
        A = false;
        break;
      }
    }
    if(A == true && i >= N){
      cout << i << endl;
      return 0;
    }
    A = true;
  }
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int a[26];
	rep(i, 26) a[i] = 0;
	string w;
	cin >> w;
	
	rep(i, w.size()) a[w[i]-'a']++;
	
	rep(i, 26) if(a[i]%2 == 1){
		cout << "No" << endl;
		return 0;
	}
	
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main() {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val result = calc(s)
    println(result)
}

fun calc(s: String): Int {
    var cnt = 0
    var maxLen = 0
    s.forEach {
        if(it == 'R') {
            cnt++
        } else {
            if(maxLen < cnt) { maxLen = cnt }
            cnt = 0
        }
    }
    return if(maxLen < cnt) cnt else maxLen
}


Measured memory_bytes: 36356
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    ll int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    ll int dis = abs(a-b);
    ll int speed = v - w;

    if(speed * t >= dis) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
 
int main()
{
    int n, s[1001], p[1001], q[1001], r[1001];
 
    while( cin >> n )
    {
        if( n == 0 )
            break;
 
        for( int i = 0; i < n + 1; i++ )
            cin >> s[i] >> p[i] >> q[i] >> r[i];
 
        bool j = false;
        for( int i = 0; i < n; i++ )
        {
            if( p[i] <= s[n] && q[i] <= p[n] && r[i] <= q[n] && p[i] * 4 + q[i] * 9 + r[i] * 4 <= r[n] )
            {
                cout << s[i] << endl;
                j = true;
            }
        }
        if( j == false )
            cout << "NA" << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll n;
    string s;
    cin >> n;
    cin >> s;
    set<ll> R, G, B;
    for (ll i = 0; i < n; ++i) {
        char c = s[i];
        switch (c)
        {
        case 'R':
            R.insert(i+1);
            break;
        case 'G':
            G.insert(i+1);
            break;
        case 'B':
            B.insert(i+1);
            break;
        default:
            break;
        }
    }

    ll res = 0;
    for (auto & r : R) {
        for (auto & g : G) {
            auto p = max(r, g);
            auto q = min(r, g);
            res += B.size();
            if (B.find(p + (p - q)) != B.end()) {
                --res;
            }
            if (B.find(q - (p - q)) != B.end()) {
                --res;
            }
            if ((p-q)%2==0 && B.find(q + (p-q)/2) != B.end()) {
                --res;
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3792
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int K = Integer.parseInt(sc.next());
	int ans = 0;
	for(int i = 1; i<=K ;i++){
		for(int j = 1; j<=K ;j++){
			for(int l = 1; l<=K ;l++){
				ans +=gcd(gcd(i,j),l);
			}
		}
	}
    System.out.print(ans);
    return;
  }

  static int gcd(int a, int b){
    int max= Math.max(a,b);
    int min= Math.min(a,b);
    if(max%min==0){
      return min;
    }else{
      return gcd(max%min, min);
    }
  }  
  
}




Measured memory_bytes: 35744
use strict;
use warnings;

sub main {
    chomp(my $N = <STDIN>);
    chomp(my $Z = <STDIN>);
    my @A = split(/ /,$Z);
    print solver($N,\@A);
}
main() unless caller;

sub solver {
    my ($N,$A) = @_;
    my %x;
    $x{$_} = 1 for @$A;
    my $ans = scalar(keys %x);
    if($ans % 2 == 0){
        $ans--;
    }
    return $ans;
}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef unsigned int  UI;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;

template <typename T> using VT = vector<T>;
template <typename T> using VVT = VT<VT<T>>;
template <typename T> using VVVT = VT<VT<VT<T>>>;
template <typename T> using VVVVT = VT<VT<VT<VT<T>>>>;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
    int n;
    scanf("%d", &n);
    VT<PII> xs(n);
    rep(i, n) {
        scanf("%d", &xs[i].fst);
        xs[i].snd = i;
    }

    sort(ALL(xs));

    VT<int> ans(n);

    rep(i, n) {
        ans[xs[i].snd] = i < n / 2 ? xs[n / 2].fst : xs[n / 2 - 1].fst;;
    }
    
    rep(i, n) {
        printf("%d\n", ans[i]);
    }

    return 0;
}



Measured memory_bytes: 4480
package main

import "fmt"

func main() {
	var N, K, X, Y int
	fmt.Scan(&N, &K, &X, &Y)

	if N <= K {
		fmt.Println(N * X)
	} else if N > K {
		fmt.Println(K*X + ((N - K) * Y))
	}
}


Measured memory_bytes: 512
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
    int i,j;
    int h,w;
    
    while(1){
        scanf("%d %d",&h,&w);
        if (h==0 && w ==0) break;
        for(i=0; i < h; i++){
            for(j=0; j < w; j++){
                if ((i + j)%2 == 0)
                {putchar('#');}
                else {putchar('.');}
            }
            putchar('\n');
        }
        putchar('\n');
        }
    return 0; 
}


Measured memory_bytes: 2004
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<functional>
#include<cstring>
#include<iterator>
#define MAX_N 100000
#define F first
#define S second 
#define MP make_pair
using namespace std;
typedef pair<int, int> P;

const int INF = 1e9;

int main() {
	int n, m, pp, q, r;

	while (cin >> n&&n){	
		int save = -1, ans = 0;
		vector<int>vep, vep2, vep3;
		vep.push_back(1);
		vep.push_back(n);
	    vector<int> vec, vec2, vec3;
		vec.push_back(1);
		vec.push_back(n);
		cin >> m >> pp >> q >> r;
		for (int i = 0; i < m; i++) {
			int x, y, p, p2;
			scanf("%d%d", &x, &y);
			p = lower_bound(vec.begin(), vec.end(), x) - vec.begin();
			if (vec[p] != x) {
				vec.insert(vec.begin() + p, x);
				vep.insert(vep.begin() + p, vec[p] - vec[p - 1] + vep[p - 1]);
			}
			if (vec[p] + 1 != vec[p + 1]) {
				vec.insert(vec.begin() + p + 1, x + 1);
				vep.insert(vep.begin() + p + 1, vep[p] + 1);
			}
			p2 = lower_bound(vec.begin(), vec.end(), y) - vec.begin();
			if (vec[p2] != y) {
				vec.insert(vec.begin() + p2, y);
				vep.insert(vep.begin() + p2, vec[p2] - vec[p2 - 1] + vep[p2 - 1]);
			}
			if (vec[p2] + 1 != vec[p2 + 1]) {
				vec.insert(vec.begin() + p2 + 1, y + 1);
				vep.insert(vep.begin() + p2 + 1, vep[p2] + 1);
			}
			for (int j = p2 + 1; j < vec.size(); j++) {
				vec2.push_back(vec[j] - vec[p2 + 1] + 1);
				vep2.push_back(vep[j]);
			}
			int size = vec2[vec2.size() - 1];
			for (int j = p + 1; j < p2 + 1; j++) {
				vec2.push_back(vec[j] - vec[p + 1] + 1 + size);
				vep2.push_back(vep[j]);
			}
			size = vec2[vec2.size() - 1];
			for (int j = 0; j < p + 1; j++) {
				vec2.push_back(vec[j] - vec[0] + 1+size);
				vep2.push_back(vep[j]);
			}
			vec3 = vec;
			vep3 = vep;
			vec = vec2;
			vep = vep2;
			vec2 = vec3;
			vep2 = vep3;
			vec2.clear();
			vep2.clear();
			/*cout << endl;
			for (int i = 0; i < vec.size(); i++) {
				cout << vec[i] << "  " << vep[i] << endl;
			}
			cout << endl;*/
		}
		int p, p2;
		p = lower_bound(vec.begin(), vec.end(), pp) - vec.begin();
		
		if (vec[p] != pp) {
			vec.insert(vec.begin() + p, pp);
			vep.insert(vep.begin() + p, vec[p] - vec[p - 1] + vep[p - 1]);
		}
		if (vec[p] + 1 != vec[p + 1]) {
			vec.insert(vec.begin() + p + 1, pp + 1);
			vep.insert(vep.begin() + p + 1, vep[p] + 1);
		}
		p2 = lower_bound(vec.begin(), vec.end(), q) - vec.begin();
		if (vec[p2] != q) {
			vec.insert(vec.begin() + p2, q);
			vep.insert(vep.begin() + p2, vec[p2] - vec[p2 - 1] + vep[p2 - 1]);
		}
		if (vec[p2] + 1 != vec[p2 + 1]) {
			vec.insert(vec.begin() + p2 + 1, q + 1);
			vep.insert(vep.begin() + p2 + 1, vep[p2] + 1);
		}
		for (int i = p; i <= p2; i++) {
			if (i + 1<=p2 && vep[i + 1] - vep[i] == vec[i + 1] - vec[i]) {
				if (vep[i + 1] <= r) {
					ans += vep[i + 1] - vep[i];
					if (save != vep[i])
						ans++;
					save = vep[i + 1];
				}
				if (vep[i] <= r&&vep[i + 1] > r) {
					ans += r - vep[i];
					if (save != vep[i])
						ans++;
					save = q;
				}
			}
			else{
				if (vep[i] <= r&&save != vep[i]) {
					ans++;
					save = vep[i];
				}
			}
	}
		cout << ans << endl;
	}
}// 0 172 

Measured memory_bytes: 1764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCode
{
    class Class1
    {
        static void Main(string[] args)
        {
            string Input = Console.ReadLine();
            int InputLength = Input.Length;
            int flg = 0;
            char Pick = new char();
            string tmpInput = Input;
            string UseMoji = null;
            int Total = 0;
            int flg2 = 0;
            for (int i = 0; i < InputLength; i++)
            {
                Pick = tmpInput[0];
                tmpInput = tmpInput.Remove(0, 1);
                flg = tmpInput.IndexOf(Pick);
                if (flg != -1)
                {
                    UseMoji += Pick;
                    flg2 = 1;
                }

            }
            flg = 1;
            if (flg2 == 1) {
                for (int i = 0; i < UseMoji.Length; i++)
                {
                    Pick = UseMoji[i];
                    Total = CountChar(UseMoji, Pick);
                    if (Total % 2 != 1)
                    {
                        flg = 0;
                    }
                }
            }
            else
            {
                flg = 0;
            }
            if (flg == 0)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }
    
}

Measured memory_bytes: 13140
/* ABC156_B
    Stuartyg */

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>


int main(void){
        int num,base_num; /*n,kのこと*/
        double ans = 0;

        scanf("%d %d",&num,&base_num);

        ans = log(num)/log(base_num);/*logの公式より底の変換*/
        printf("%d",(int)ans+1); /*型キャスト*/

        return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, pair<T, T> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n, m;
  cin >> n >> m;
  VEC<pair<int, int>> a(m);
  REP(i, 0, m) { cin >> a[i].first >> a[i].second; }
  sort(ALL(a));
  DUMP(a);
  VEC<int> cnt(n, 0);

  REP(i, 0, m) {
    cnt[a[i].first - 1]++;
    cnt[a[i].second - 1]++;
  }
  REP(i, 0, n) { cout << cnt[i] << endl; }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int inf = INT_MAX / 2;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
 
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    string S;
    cin >> S;
    
    int a = 0;
    int ans = 0;
    rep(i, 3) {
        if (S[i] == 'R') a++;
        else {
            chmax(ans, a);
            a = 0;
        }
    }
    if (ans == 0) ans = a;
 
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

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

    vector<int> cost(n + 1, 0);
    vector<int> idx;
    rep(i, 0, n) {
        cin >> cost[i];
        // if (i > 0) {
        //     if (cost[i] < cost[i - 1]) {
        //         idx.push_back(i);
        //     }
        // }
    }

    vector<int> sumcost(n + 1, 0);
    rep(i, 0, n) {
        if (i == 0) {
            sumcost[i] = abs(cost[i]);
        } else {
            sumcost[i] = sumcost[i - 1] + abs(cost[i - 1] - cost[i]);
        }
    }
    sumcost[n] = sumcost[n - 1] + abs(cost[n - 1] - 0);

    // print
    // cout << "----" << endl;
    // for (int _val : sumcost) {
    //     cout << _val << endl;
    // }
    // cout << "----" << endl;

    int sum = sumcost[n];

    rep(i, 0, n) {
        int sublen1 = i > 0 ? abs(cost[i] - cost[i - 1]) : abs(cost[i]);
        int sublen2 = abs(cost[i] - cost[i + 1]);
        int addlen  = i > 0 ? abs(cost[i - 1] - cost[i + 1]) : abs(cost[i + 1]);

        int ans = sum - sublen1 - sublen2 + addlen;
        // printf("%d = %d - %d - %d + %d\n", sum, sublen1, sublen2, addlen);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}


typedef string::const_iterator State;
int number(State&);
pair<int,bool> factor(State&);
pair<int,bool> term(State&);
pair<int,bool> expression(State&);

bool invalid;

// 数字の列をパースして、その数を返す。
int number(State &begin) {
	if(not isdigit(*begin)){
		invalid = true;
		return 0;
	}

	int ret = 0;

	while (isdigit(*begin)) {
		ret *= 2;
		ret += *begin - '0';
		begin++;
	}

	if(ret >= 1024){
		invalid = true;
		return 0;
	}
	return ret;
}

// 括弧か数をパースして、その評価結果を返す。
pair<int,bool> factor(State &begin) {
	if(invalid) return make_pair(0,0);
	if (*begin == '(') {
		begin++; // '('を飛ばす。
		pair<int,bool> ret = expression(begin);
		if(not ret.second) {
			invalid = true;
		}
		begin++; // ')'を飛ばす。
		ret.second = 0;
		return ret;
	} else {
		return make_pair(number(begin), 0);
	}
	return make_pair(0, 0);
}

// 乗算除算の式をパースして、その評価結果を返す。
pair<int,bool> term(State &begin) {
	if(invalid) return make_pair(0,0);
	pair<int,bool> ret = factor(begin);

	for (;;) {
		if (*begin == '*') {
			begin++;
			ret.second = true;
			ret.first *= factor(begin).first;
			if(ret.first >= 1024) {
				invalid = true;
				return make_pair(0,0);
			}
		} else {
			break;
		}
	}

	return ret;
}

// 四則演算の式をパースして、その評価結果を返す。
pair<int,bool> expression(State &begin) {
	if(invalid) return make_pair(0,0);
	pair<int,bool> ret = term(begin);

	for (;;) {
		if (*begin == '+') {
			begin++;
			ret.second = true;
			ret.first += term(begin).first;
			if(ret.first >= 1024) {
				invalid = true;
				return make_pair(0,0);
			}
		} else if (*begin == '-') {
			begin++;
			ret.second = true;
			ret.first -= term(begin).first;
			if(ret.first < 0) {
				invalid = true;
				return make_pair(0,0);
			}
		} else {
			break;
		}
	}

	return ret;
}


const string c = "01+-*()";

int dfs(string& s, int i){
	if(i == s.size()){
		invalid = false;
		State tmp = s.begin();

		pair<int,bool> ans = expression(tmp);
		if(ans.first >= 1024 or ans.first < 0 or tmp != s.end()) return -1e5;
		return invalid ? -1e5 : ans.first;
	}

	while(s[i] != '.' and i < s.size()){
		i++;
	}

	if(s[i] == '.'){
		int res = -1e5;
		rep(j,c.size()){
			s[i] = c[j];
			res = max(res, dfs(s, i));
			s[i] = '.';
		}
		return res;
	}else{
		return dfs(s, i);
	}
}

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

	int ans = dfs(s, 0);
	cout << (ans == -1e5 ? -1 : ans) << endl;
}



Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;

int main() {
	int n, c, k;;
	int t[100000];
	cin >> n >> c >> k;
	for (int i = 0; i < n; i++) cin >> t[i];
	sort(t, t + n);
	int lim = t[0] + k;
	int ans = 1;
	int n_wait = 1;
	for (int i = 1; i < n; i++) {
		if (t[i] > lim || n_wait >= c) {
			lim = t[i] + k;
			n_wait = 0;
			ans++;
		}
		n_wait++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.buffer.readline
from math import log

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]

for i in range(n):
    for y in range(int(log(a[-1],2))+2):
        table[i][y] = a[i]//pow(2,y)
        if a[i]//pow(2,y) == 0:
            break

s_table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]
for i in range(n):
    s_table[i][0] = table[i][0]

import heapq
hq = []
heapq.heapify(hq)
h_push = heapq.heappush
h_pop = heapq.heappop

for i in range(n):
    for y in range(1,int(log(a[-1],2))+2):
        s_table[i][y] = table[i][y]-table[i][y-1]
        h_push(hq,table[i][y]-table[i][y-1])
        if table[i][y]-table[i][y-1] == -1:
            break


ans = sum(a)

for i in range(m):
    if not hq:
        print(0)
        exit()
    ans += h_pop(hq)
    
print(ans)




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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

bool in(vll l, ll p){
    rep(i, l.size()) if(l[i]==p) return true;
    return false;
}

ll calc(ll n){
    return n*(n-1)/2;
}

int main(){

    ll n; cin >> n;
    vll a(n);
    vll cnt(n, 0);
    rep(i, n){
        cin >> a[i];
        cnt[a[i]-1]++;
    }

    ll sum = 0;
    rep(i, n) sum += calc(cnt[i]);

    rep(i, n) cout << sum-(cnt[a[i]-1]-1) << endl;

    return 0;
}

Measured memory_bytes: 6416
from operator import mul
from functools import reduce

n, p = map(int, input().split())
A = list(map(int, input().split()))

even = 0
odd = 0
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1


def cmb(n, r):
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


ans = 2**even
cnt = 0
if p == 0:
    for i in range(0, odd+1, 2):
        cnt += cmb(odd, i)
else:
    for i in range(1, odd+1, 2):
        cnt += cmb(odd, i)

print(ans*cnt)


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

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var a = new List<int>();
        for (int i = 0; i < s.Length; i++)
            if (s[i] == 'W') a.Add(i);
        var ans = getAns(a);
        Console.WriteLine(ans);

    }
    static long getAns (List<int> a)
    {
        var n = a.Count();
        var p = 0;  var ans = 0L;
        for (int i = 0; i < n; i++)
        {
            ans += a[i] - p;
            p++;
        }
        return ans;

    }
}


Measured memory_bytes: 12768
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	
	int n, k; cin >> n >> k;
	vi h(n); rep(i, n) cin >> h[i];
	vector<ll> dp(n, 1e18);
	dp[0] = 0;
	rep(i, n) rep(j, k){
		if(i - j - 1 >= 0) dp[i] = min(dp[i], dp[i - j - 1] + abs(h[i] - h[i - j - 1]));
	}
	cout << dp[n - 1] << endl;
	
	return 0;
}

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

using namespace std;

typedef long long int li;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

vi par;

li root(li a)
{
    while(a!=par[a])
    {
        par[a]=par[par[a]];
        a=par[a];
    }

    return a;
}

void unio(li a,li b)
{
    par[root(a)]=root(b);
}



    
int main()
{    
   

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s,t;

    cin>>s>>t;

    cout<<t+s;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var dict = new Dictionary<string, int>();
            var prev = Console.ReadLine();
            dict[prev] = 1;
            for (var i = 1; i < n; i++)
            {
                var w = Console.ReadLine();
                if (dict.ContainsKey(w) || prev[prev.Length - 1] != w[0])
                {
                    Console.WriteLine("No");
                    return;
                }
                dict[w] = 1;
                prev = w;
            }
            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13152
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [INT() for _ in range(N)]
zipped = {x:i+1 for i, x in enumerate(sorted(set(A)))}
A = [zipped[x] for x in A]

print(sum(x%2==0 for x in A[::2]))


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

#define ll long long

int word(string s,string t){
    // cout << s<<' ' << t << endl;
    vector<int>exist('z'+1);
    for(int i=0;i<exist.size();i++){
        exist[i] = 0;
    }
    int cnt=0;
    for(int i=0;i<s.length();i++){
        for(int j=0;j<t.length();j++){
            if(s[i]==t[j]) {
                exist[s[i]] = 1;
                break;
            }
        }
    }
    int ans = accumulate(exist.begin(),exist.end(),0);
    // cout << ans <<' '<<endl;
    return ans;
}

int main(void){
    int n;
    cin >> n;
    string s;
    cin >>s;
    int len = s.length();
    int ans = 0;
    for(int i=1;i<s.length();i++){
        string a = s.substr(0,i);
        string b = s.substr(i,len-i);
        int tmp = word(a,b);
        if (ans < tmp) ans = tmp;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  double Rz,Wz,C,R,ans = 0;

  while(true){
    cin >> Rz >> Wz >> C >> R;

    if(Rz == 0 && Wz == 0 && C == 0 && R == 0) break;

    ans = 0;
    while(true){
      if(C == Rz/Wz) break;
      
      if(C > Rz/Wz){
	Rz+= R;
	++ans;
      }
      
      if(C < Rz/Wz){
       break;
      }
    }

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



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

int main() {
	
	int a,b,c;
	cin>>a>>b>>c;
	
	int sum = 0;
	int MIN = min(a,min(b,c));
	int MAX = max(a,max(b,c));
	int MID = a+b+c-MIN-MAX;
	
	sum+=(MAX-MID);
	MIN+=sum;
	MID+=MAX-MID;
	sum+=((MAX-MIN)/2 + (MAX-MIN)%2);
	MIN += 2*(((MAX-MIN)/2 + (MAX-MIN)%2));
	
	if((MAX != MID or MID != MIN or MAX != MIN))
	{
		sum++;
	}
	
	cout<<sum;
	
	return 0;
}

Measured memory_bytes: 3608