akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

//---------------------------

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

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

using namespace std;
typedef long long int ll;

int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(b>a && c>b)
    {
        cout<<"Yes";
        return 0;
    }
    if(b<=a)
    {
        while(b<=a && k>0)
        {
            b = b*2;
            k--;
        }
        if(b<=a)
        {
            cout<<"No";
            return 0;
        }
    }
    if(c<=b)
    {
        while(c<=b && k>0)
        {
            c =c*2;
            k--;
        }
        if(c<=b)
        {
            cout<<"No";
            return 0;

        }
    }
    cout<<"Yes";
    return 0;



}


Measured memory_bytes: 3588
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
ans = r*g*b

for i in range(N-2):
    for j in range(i+1, N):
        k = j+(j-i)
        if k > (N-1):
            break
        if S[i] != S[j] != S[k] != S[i]:
            ans -= 1
print(ans)


Measured memory_bytes: 67636
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    if(s.matches(".*keyence")||s.matches("k.*eyence")||s.matches("ke.*yence")||
       s.matches("key.*ence")||s.matches("keye.*nce")||s.matches("keyen.*ce")||
       s.matches("keyenc.*e")||s.matches("keyence.*")){
      //正規表現のパターンの前後に「任意の文字がいくつかある」という意味の「.*」
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 23124
/*
Miles Morales : When will I know I'm ready?
Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith.
*/
//KEEP IT SIMPLE STUPID
/*#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define print(o) for(auto it=(o).begin();it!=(o).end();it++) cout<<*it<<" ";
#define vll vector<ll>
#define pb push_back
#define FOR(n) for(ll i=0;i<=n;i++)
#define FORd(n) for(ll i=n;i>=0;i--)
#define FORrd(a,b) for(ll i=a;i>=b;i--)
#define FORr(a,b) for(ll i=a;i<=b;i++)
#define all(x) (x).begin(),(x).end()
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define ff first
#define ss second
#define w(t) ll t;cin>>t;while(t--)

int main()
{
    FIO;
    ll n,k;
    cin>>n>>k;
    vll a(n),p(n);
    FOR(n-1)
    {
        cin>>a[i];
    }
    sort(all(a));
    p[0]=a[0];
    FORr(1,n-1)
    {
        p[i]=p[i-1]+a[i];
    }
    if(k>=n)
    {
        cout<<0<<'\n';
    }
    else{
        cout<<p[n-k-1]<<'\n';
    }
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int d = scanner.nextInt();
        int t = scanner.nextInt();
        int s = scanner.nextInt();
        System.out.println(s * t >= d ? "Yes" : "No");
    }
}

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

int main() {
  int N;
  cin >> N;
  bool a = false, b = false, c = false, d = false;

  for (int i = 0; i < N; i++) {
    string S;
  	cin >> S;
    
    if (S == "P") {
      a = true;
    }
    else if (S == "W") {
      b = true;
    }
    else if (S == "G") {
      c = true;
    }
    else if (S == "Y") {
      d = true;
    }
  }
  
  if (a == true && b == true && c == true && d == true) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}


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

bool check_upper(char c);

int main()
{
    char c;
    std::cin >> c;

    if( check_upper(c) )
    {
        std::cout << "A";
        return 0;
    }
    std::cout << "a";
    return 0;
}

bool check_upper(char c)
{
    if('A'<= c && c <='Z')
    {
        return true;
    }
    return false;
}

Measured memory_bytes: 3596
x, k, d = map(int, input().split())
x = abs(x)
t = x // d 
if k <= t:
    print(x - d * k)
else:
    if (t + k) % 2 == 0:
        if k >= t + 2:
            print(min(x % d, -1 * (x % d - 2 * d)))
        else:
            print(x % d)
    else:
        if k >= t + 1:
            print(min(x % d + d, -1 * (x % d - d)))
        else:
            print(x % d + d)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
#define endl "\n"
 
const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
 
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1005;

char g[N][N];
int h, w, sx, sy, ex, ey, dist[N][N];

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

bool valid(int x, int y) {
    return x >= 0 && x < h && y >= 0 && y < w && g[x][y] != '#';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> h >> w >> sx >> sy >> ex >> ey;

    --sx, --sy;
    --ex, --ey;

    for (int i = 0; i < h; ++i) 
        for (int j = 0; j < w; ++j) 
            cin >> g[i][j];

    memset(dist, -1, sizeof(dist));

    deque<pii> q;
    q.push_back({sx, sy});
    dist[sx][sy] = 0;
    while (!q.empty()) {
        auto r = q.front();
        int x = r.first;
        int y = r.second;
        q.pop_front();
        for (int i = 0; i < 4; ++i) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (valid(nx, ny) && (dist[nx][ny] == -1 || dist[nx][ny] > dist[x][y])) {
                q.push_front({nx, ny});
                dist[nx][ny] = dist[x][y];
            }
        }
        for (int i = -2; i <= 2; ++i) {
            for (int j = -2; j <= 2; ++j) {
                int nx = x + i;
                int ny = y + j;
                if (!valid(nx, ny) || ~dist[nx][ny])
                    continue;
                q.push_back({nx, ny});
                dist[nx][ny] = dist[x][y] + 1;
            }
        }
    }

    cout << dist[ex][ey] << endl;
}


Measured memory_bytes: 8692
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int p = 0;
    for(int i = 0; i < 5; i++) {
      int v = sc.nextInt();
      if(v == 0) p = i+1;
    }
    sc.close();
    System.out.println(p);
  }
}

Measured memory_bytes: 35688
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

#define ld long double

int32_t main()
{
    usaco();
    ld n;
    cin >> n;
    vector <ld> p(n+1);
    for (int i = 1; i <= n; ++i) cin >> p[i];
    vector <vector <ld>> dp(n+1, vector <ld> (n+1));
    dp[1][0] = ((ld)1)-p[1];
    dp[1][1] = p[1];
    for (int i = 2; i <= n; ++i)
    {
        dp[i][0] = dp[i-1][0] * (((ld)1)-p[i]);
        dp[i][i] = dp[i-1][i-1] * p[i];
    }
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j < i; ++j)
            dp[i][j] = dp[i-1][j] * (((ld)1)-p[i]) + dp[i-1][j-1] * p[i];
    ld ans = 0;
    for (int i = n/2+1; i <= n; ++i) ans += dp[n][i];
    cout << fixed << setprecision(10) << ans << '\n';
}


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

int main(){
	int N;
  	cin >> N;
  	vector<int> A(N);
  	for(int i=0; i<N;i++){
      cin >> A.at(i);
    }
  
  	int judge=1;
  	
  	for(int i=0;i<N;i++){
      if(A.at(i) % 2 == 0){
        if(A.at(i) % 3 != 0 && A.at(i) % 5 != 0){
          judge = 0;
        }
      }
    }
  
  	if(judge == 1){
		cout << "APPROVED" << endl;
    }else{
      	cout << "DENIED" << endl;
    }
  
  return(0);
        
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;

    ll L = lcm(N, M);
    ll n = L / N;
    ll m = L / M;
    vector<char> sn;
    for(ll i = 0; i < N; i += m) {
        sn.push_back(S[i]);
    }
    vector<char> tm;
    for(ll i = 0; i < M; i += n) {
        tm.push_back(T[i]);
    }
    bool flag = false;
    for(ll i = 0; i < sn.size(); i++) {
        if (sn[i] != tm[i]) flag = true;
    }
    if (flag) {
        print(-1);
    } else {
        print(L);
    }
    return 0;
}

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

int main(){
    int y,m,d;
    long long a;
    while(cin>>y>>m>>d){
        a=d+100*m+10000*y;
        if(a<18680908)cout<<"pre-meiji"<<endl;
        else if(a>=18680908&&a<=19120729){
            cout<<"meiji "<<y-1867<<' '<<m<<' '<<d<<endl;
        }
        else if(a>=19120730&&a<=19261224){
            cout<<"taisho "<<y-1911<<' '<<m<<' '<<d<<endl;
        }
        else if(a>=19261225&&a<=19890107){
            cout<<"showa "<<y-1925<<' '<<m<<' '<<d<<endl;
        }
        else{
            cout<<"heisei "<<y-1988<<' '<<m<<' '<<d<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    string a;
    cin >> a ;
    //*/
    
    a.at(3) = '8';
    
    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    /*
    if(a == 0){
        cout << "" << endl;
    } else if(a > 0){
        cout << "" << endl;
    } else {
        cout << "" << endl;
    }
    */
    
    cout << a << endl;

    return 0; 
}


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

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))

typedef unsigned long long ull;
const ull c = 1145148931919LL;

ull ro[1000100];
ull tei[1000100];
int nn;
bool check(int a, int b, int c, int d) {
	if(a < 0 || c < 0) return false;
	if(nn <= b || nn <= d) return false;
	ull aa = ro[b];
	ull bb = ro[d];
	if(a) aa += -ro[a - 1] * tei[b - a + 1];
	if(c) bb += -ro[c - 1] * tei[d - c + 1];
	return aa == bb;
}



template<class T>
struct RollingHash {
	static const int NN = 2; // the number of hash table
	T base[NN] = {1009, 1007};
	T PMOD[NN] = {1000000007, 1000000009};
	vector<T> hash[NN];
	vector<T> mypow[NN];
	int sz;
	void init(string s) {
		sz = s.size();
		for(int i = 0; i < NN; i++) {
			hash[i].assign(sz + 1, 0);
			mypow[i].assign(sz + 1, 0);
			mypow[i][0] = 1;
		}
		for(int i = 0; i < NN; i++) {
			for(int j = 0; j < sz; j++) {
				hash[i][j + 1] = (hash[i][j] * base[i] + s[j]) % PMOD[i];
				mypow[i][j + 1] = mypow[i][j] * base[i] % PMOD[i];
			}
		}
	}
	RollingHash() {
	}
	T get(int l, int r, int t) {
		T ret = (hash[t][r + 1] - hash[t][l] * mypow[t][r - l + 1] % PMOD[t] + PMOD[t]) % PMOD[t];
		return ret;
	}
	bool comp(int a, int b, int c, int d) {
		if(a < 0 || sz <= b || c < 0 || sz <= d) return false;
		for(int i = 0; i < NN; i++) {
			if(get(a, b, i) != get(c, d, i)) return false;
		}
		return true;
	}
};

RollingHash<long long> rhash1;

int calc1(int l, int r) {
	int ll = 0;
	int rr = INT_MAX / 10;
	while(rr - ll > 1) {
		int mid = (ll + rr) / 2;
		if(rhash1.comp(l, l + mid - 1, r, r + mid - 1)) {
			ll = mid;
		}
		else {
			rr = mid;
		}
	}
	return ll;
}

int calc2(int l, int r) {
	int ll = 0;
	int rr = INT_MAX / 10;
	while(rr - ll > 1) {
		int mid = (ll + rr) / 2;
		if(rhash1.comp(l - mid + 1, l, r - mid + 1, r)) {
			ll = mid;
		}
		else {
			rr = mid;
		}
	}
	return ll;
}

int main() {
	string s, t;
	cin >> s >> t;
	string a = s + t;
	nn = a.size();
	int n = s.size();
	int m = t.size();
	int ans = 0;
	rhash1.init(a);
	rep(i, n) {
		if(i + m - 1 >= n) break;
		int l = calc1(i, n);
		int r = calc2(i + m - 1, n + m - 1);
		if(l + r + 1 == m) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 18492
#include<iostream>
#include<algorithm>
#include<complex>
using namespace std;
int dp[201][201],h[201],a[201],b[201],c[201];
int main(){
	int d,n;
	cin>>d>>n;
	for(int i=0;i<d;i++){cin>>h[i];for(int j=0;j<n;j++)dp[i][j]=0;}
	for(int i=0;i<n;i++){cin>>a[i]>>b[i]>>c[i];}
	for(int i=1;i<d;i++)for(int j=0;j<n;j++)if(h[i]>=a[j]&&h[i]<=b[j])for(int k=0;k<n;k++){if(h[i-1]>=a[k]&&h[i-1]<=b[k])dp[i][j]=max(dp[i][j],abs(c[j]-c[k])+dp[i-1][k]);}
	int ans=0;
	for(int i=0;i<n;i++)ans=max(ans,dp[d-1][i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1320
#include <stdio.h>

int main(void)
{
	int n, i, a, ans = 0;

	scanf("%d" ,&n);

    for (i = 0; i < n; i++)
	{
		scanf("%d" ,&a);
		if (a == ans + 1)
			ans++;
	}

	printf("%d" ,!ans ? -1 : n - ans);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x)      x.begin(), x.end()
#define rep(i,n)    for (i64 i = 0; i < (n); ++i)
#define reps(i,s,t) for (i64 i = (s); i <= (t); ++i)
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
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;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    int N;
    i64 a[10010];
    i64 b[10010];

    cin >> N;
    rep(i, N) {
        cin >> a[i];
    }
    rep(i, N) {
        cin >> b[i];
    }

    i64 cnt = 0;
    rep(i, N) {
        if (a[i] > b[i]) {
            cnt += a[i] - b[i];
            b[i] = a[i];
        }
    }

    rep(i, N) {
        if (a[i] < b[i]) {
            i64 d = (b[i] - a[i]);
            i64 t = min<i64>(cnt, d / 2);
            cnt -= t;
        }
    }

    cout << ((cnt <= 0) ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 512
N = int(input())
s = []
for _ in range(N):
    s.append(input())

in_str = 0
BX = 0
XA = 0
BA = 0
for str in s:
    in_str += str.count('AB')
    if str[0] == 'B' and str[-1] != 'A':
        BX += 1
    elif str[0] != 'B' and str[-1] == 'A':
        XA += 1
    elif str[0] == 'B' and str[-1] == 'A':
        BA += 1

ans = in_str
if min(XA, BX) >= 1:
    ans += BA + min(XA, BX)
elif max(BX, XA) == 0:
    ans += max(0, BA - 1)
else:
    ans += 1 + BA - 1
print(ans)

Measured memory_bytes: 44376
<?php
	$n = fgets(STDIN);

	for ($i = 1; $i <= $n; $i++) {
		$x = $i;
		if ($x % 3 == 0) {
			print " $i";
			continue;
		}

		while ($x) {
			if ($x % 10 == 3) {
				print " $i";
				break;
			}

			$x /= 10;
		}
	}

	print "\n";

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;

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

  std::cin >> N;

  bool ok = true;

  for(int i=0;i<N;++i){
      int A;
      std::cin >> A;

      if(A % 2 == 0 && A % 3 != 0 && A % 5 != 0){
          ok = false;
          break;
      }
  }

  if(ok){
      std::cout << "APPROVED" << std::endl;
  }else{
      std::cout << "DENIED" << std::endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool dp[5010][5010];

int main(){
  
    ll n;
    string s;
    cin>>n>>s;
    
    //0S 1W
    bool t=0;
    bool tt=0;
    for(int i=0;i<2;i++){
        t=!t;
        for(int j=0;j<2;j++){
            tt=!tt;
            
            vector<bool> v(n+1);
            v[0]=t;
            v[1]=tt;
            for(int l=1;l<n;l++){
                if(s[l]=='o'){
                    if(v[l]==0){
                        v[l+1]=v[l-1];
                    }else{
                        v[l+1]=!v[l-1];
                    }
                }else if(s[l]=='x'){
                        if(v[l]==0){
                            v[l+1]=!v[l-1];
                        }else{
                            v[l+1]=v[l-1];
                        }
                }
            }
            
            bool flag=0;
            if(v[n]==v[0]){
            if(s[0]=='o'){
                if(v[0]==0){
                    if(v[n-1]==v[1]){flag=1;}
                }else{
                    if(v[n-1]!=v[1]){flag=1;}
                }
            }else if(s[0]=='x'){
                if(v[0]==0){
                    if(v[n-1]!=v[1]){flag=1;}
                }else{
                    if(v[n-1]==v[1]){flag=1;}
                }
            }
            if(flag==1){
                for(int k=0;k<n;k++){
                    if(v[k]==0){cout<<'S';}else{cout<<'W';}
                }cout<<endl;return 0;
            }
        }
        }
        
    }
    
    cout<<-1<<endl;
   
    
 
    
return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

int main()
{
	int n, d, x;
	int a[105];
	cin >> n >> d >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		for (int j = 1; j <= d; j += a[i]) {
			x++;
		}
	}
	cout << x << endl;
}

Measured memory_bytes: 256
from itertools import combinations
L,R = (int(x) for x in input().split())
ans = 2018
if (R-L) // 2018 >= 1:
    print('0')
else:
    for x in combinations(range(L,R+1),2):
        ans = min(ans,x[0]*x[1]%2019)
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
  for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair
// inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;} 
int main(){
  fio; cout<<fixed<<setprecision(25);	
  int n; cin >> n;
  ll ans = 0;
  for(int c = 1; c <= n-1 ; ++c){
    int z = n-c;
    for(int i =1 ; i*i <= z ; ++i){
      if(i*i == z) ++ans;
      else if(z%i == 0) ans += 2;
    }
    //cout << ans << endl;
  }
  cout << ans << endl;
  
}


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

int main(){
  string s,t;
  cin>>s>>t;
  int index=-1;
  for(int i = 0; i < s.size()-t.size()+1; i++){
    bool ok=1;
    for(int j = 0; j < t.size(); j++){
      if(s[i+j] != t[j] && s[i+j] != '?') ok=0;
    }
    if(ok) index = i;
  }
  if(index==-1) cout<<"UNRESTORABLE"<<endl;
  else{
    string ans;
    int tmp=0;
    for(int i = 0; i < s.size(); i++){
      if(i >= index && index+t.size() > i){
        ans+=t[tmp];
        tmp++;
      }else{
        if(s[i]=='?') ans+='a';
        else ans+=s[i];
      }
    }
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 3612
// D.c
//  C_Grid_Repainting_2
//    - https://abc096.contest.atcoder.jp/tasks/abc096_c#


# include <stdio.h>


#define HSIZE 50
#define WSIZE 50


void solve(int H, int W, char s[HSIZE][WSIZE]);

int main()
{
  //----------------------------------------
  //  Parameter Declaration
  //----------------------------------------
  int H, W;
  char s[HSIZE][WSIZE];
  char output[3];  // "yes" or "no"

  //----------------------------------------
  //  Input Data
  //----------------------------------------
  scanf("%d %d", &H, &W);
  for (int i=0; i<H; i++){
    scanf("%s", s[i]);
  }

  //----------------------------------------
  //  Run Algorithm
  //----------------------------------------
  solve(H, W, s);
  return 0;
}


//--------------------------------------------------------------------------------
//  solve()
//--------------------------------------------------------------------------------
void solve(int H, int W, char s[HSIZE][WSIZE])
{
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (s[i][j] == '#'){

        // 一つ上のマスを確認
        if ( ( i > 0 ) && (s[i-1][j] == '#') ){
            continue;
        }
        // 一つ下のマスを確認
        if ( ( i < H-1 ) && (s[i+1][j] == '#') ){
            continue;
        }

        // 一つ左のマスを確認
        if ( ( j > 0 ) && (s[i][j-1] == '#') ){
            continue;
        }
        // 一つ右のマスを確認
        if ( (j < W-1) && (s[i][j+1] == '#') ){
            continue;
        }

        printf("%s\n", "No");
        return;
      }
    }
  }
  printf("%s\n", "Yes");
  return;
}



Measured memory_bytes: 128
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int a, b, h;
    cin >> a >> b >> h;

    cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())

    count = dict()
    for i in range(N):
        s = input()
        try:
            count[s] += 1
        except:
            count[s] = 1
    
    sort_ = sorted(count.items(), key=lambda x:x[1], reverse=True)

    max_value = sort_[0][1]
    item = []
    for key,value in sort_:
        if value == max_value:
            item.append(key)
        else:
            break
    
    item.sort()
    for ans in item:
        print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 45784
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] input = sc.nextLine().split(" ");
        List<String> list = Arrays.<String>asList(input);
        String frequency = getFrequency(list);
        String longest = getLongest(list);
        System.out.println(longest + " " + frequency);
    }

    private static String getLongest(List<String> list) {
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        for (String s : list) {
            if (!map.containsKey(s)) {
                map.put(s, 1);
            } else {
                map.put(s, map.get(s) + 1);
            }
        }

        int max = 0;
        String res = "";
        for (String key : map.keySet()) {
            if (max < map.get(key)) {
                max = map.get(key);
                res = key;
            }
        }
        return res;
    }

    private static String getFrequency(List<String> list) {
        int max = 0;
        String res = "";
        for (String s : list) {
            if (max < s.length()) {
                max = s.length();
                res = s;
            }
        }
        return res;
    }

}

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

int main(){
	ll n;
	cin>>n;
	ll a[n],v[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
		v[i]=0;
	}
	v[0]=a[0];
	for(ll i=1;i<n;i++){
		v[i]+=a[i]+v[i-1];
	//	cout<<"i:"<<i<<" v:"<<v[i]<<endl;
	}
	ll res=1000000000000000001;
	for(ll i=0;i<n-1;i++){
		res = min(res,abs((v[n-1]-v[i])-v[i]));
	}
	cout<<res<<endl;
}


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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string a;
    cin >> a;
    int n = (int) a.size();
    for (int i = 0; i < n; i++) {
        cout << 'x';
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()

	sum := 0
	for i := 1; i <= n; i++ {
		if i%15 != 0 && i%5 != 0 && i%3 != 0 {
			sum += i
		}
	}
	fmt.Println(sum)

}


Measured memory_bytes: 1756
#include<bits/stdc++.h>
using namespace std;
/*bool cmp(const node &x,const node &y){
	
}*/
int main(){
	int n,b;
	scanf("%d %d",&n,&b);
int Min=min(n,b);
int temp=max(n,b);
for(int i=0;i<temp;++i){
	cout<<Min;
}
	return 0;
} 

Measured memory_bytes: 256
//?????°??¢??°????????°??????????????????????????§DP?????????????????????????????????
//??????????????£????????????????????¨???????????¶????????????????????°????????\??¬????????§?????§????????????????????§???????????¢??????????????????
//??????S, T????????£?????????????????°??¨???????????????????????£???????????§???????????????????????°??????????????°??¢??°????????£??????IOI????????¨???????????????????????§?????????
//?????¨???????????§???????????¶???????????°??????????????£?????¨???????????¢??????????????????????????°O(NM(N+M))?????????????????????
//?????????
//IOI????????¨??????????????????????????????????????????(??°???DP?????´?????????????????????????????§??????????????¨?????????????????§?????????
//S, T????????£?????????????????°x, y??¨?¬???????????????????????????????(I???O)??????????????????????????§????????£????????????????????????????????????
//???????????????????????????????????????????????°???????????????????????????
//?????°???????????????????????\???????????§????????°??§???????????¨???????????¨???O(NM)????????§???DP??????????????????????????????????????????????????????????????????????????¢??°????????????
//????????????????????????????????¨????????????DP?????????????????????????????????????????£??????????????????????????????????????????????£???§?????????
//??¢?????????????????¶??????????????????????\???°, ?????????I)????????????????????????main??´??§??????????????´?????????
//IOI???????????????
//
#include <iostream>
#include <string>
using namespace std;

int m, n;
string s, t;
int dp[2001][2001][2];

//s[x]??????OK, t[y]??????OK, ?¬????c?????£???
int dfs(int x, int y, char c){		
	if( x >= m && y >= n )
		return 0;
	
	if( dp[x][y][c=='I'] > 0 )
		return dp[x][y][c=='I'];
		
	int ret = 0;
	if( x < m && s[x] == c )
		ret = max(ret, dfs(x + 1, y, c == 'I' ? 'O' : 'I') + 1);
	if( y < n && t[y] == c )
		ret = max(ret, dfs(x, y + 1, c == 'I' ? 'O' : 'I') + 1);
	return (dp[x][y][c=='I'] = ret);
}

int main(){
	int ans = 0;
	
	cin >> m >> n >> s >> t;
	for( int i = 0; i < m; i++ ){
		for( int j = 0; j < n; j++ ){
			dp[0][i][j] = -1;
			dp[1][i][j] = -1;
		}
	}
	
	for( int i = 0; i < m; i++ ){
		for( int j = 0; j < n; j++ ){
			ans = max(ans, dfs(i, j, 'I'));
		}
	}
	if( ans > 0 ){
		ans -= (ans + 1) % 2;	//?\???°????????????
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 32796
#include<iostream>
#include<bitset>

int main(void){
    int n, m;
    std::cin >> n >> m;

    std::bitset<200100> A;
    std::bitset<200100> B;

    for(int i = 0; i < m; i++){
        int a, b;
        std::cin >> a >> b;
        a--;
        b--;

        if(a == 0) A[b] = 1;
        if(b == n-1) B[a] = 1;
    }

    A&=B;

    for(int i = 0; i < n; i++){
        if(A[i]){
            std::cout << "POSSIBLE" << std::endl;
            return 0;
        }
    }
    std::cout << "IMPOSSIBLE" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
 
int main()
{
    std::uint32_t n;
    std::cin >> n;
    std::uint64_t factorial = 1;
    while (n > 0) {
        factorial *= n--;
    }
    std::cout << factorial << std::endl;
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,i,ans=0;
  cin>>n;
  vector<int> a(n),b(n-1);
  for(i=0;i<n-1;i++) cin>>b.at(i);
  for(i=0;i<n;i++){
    if(i==0) a.at(i)=b.at(0);
    else if(i==n-1) a.at(i)=b.at(n-2);
    else a.at(i)=min(b.at(i-1),b.at(i));
    ans+=a.at(i);
  }
  cout<<ans<<endl;
}

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

int main(void){

    int H;
    int W;

    while(1) {
        std::cin >> H >> W;
        if(H == 0 && W == 0) {
            break;
        }
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if(i == 0 || i + 1 == H || j == 0 || j + 1 == W) {
                    cout << "#";
                } else {
                    cout << ".";
                }
                
            }
            cout << endl;
        }
        cout << endl;
    }
        
    return 0;
    
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define maxn 100005
#define pii pair<int,int>
#define INF 1234567891
#define ll long long
using namespace std;
struct point {
	int x,y;
}arr[maxn];
struct node {
	int pos,num;
	bool operator < (const node& a) const{
		return pos != a.pos ? pos < a.pos : num < a.num;
	}
};
bool vis[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,a,b;
	cin >> n >> a >> b;
	for(int i=1;i<=n;i++)
		cin >> arr[i].x >> arr[i].y;
		
	map<int,set<pii> > idxs[2];
	for(int i=1;i<=n;i++) {
		int x = arr[i].x , y = arr[i].y;
		idxs[0][x-y].insert(pii{arr[i].x,i});
		idxs[1][x+y].insert(pii{arr[i].x,i});
	}
	map<int,set<node> > ptrs[2];
	for(int i=0;i<2;i++)
		for(auto now : idxs[i]) {
			int cnt = 0;
			for(pii idx : now.second)
				ptrs[i][now.first].insert(node{idx.first,cnt++});
		}
		
	int len = abs(arr[a].x - arr[b].x) + abs(arr[a].y - arr[b].y);
	queue<int> wait;
	for(int st : {a,b}) {
		wait.push(st);
		int x = arr[st].x , y = arr[st].y;
		idxs[0][x-y].erase(pii{x,st});
		idxs[1][x+y].erase(pii{x,st});
	}
	ll ans = 0;
	while(!wait.empty()) {
		int u = wait.front();
		wait.pop();
		if(vis[u])	continue;
		vis[u] = true;
		
		int x = arr[u].x , y = arr[u].y;
		for(int delta_y_coe : {-1,1}) {
			int ny = y + delta_y_coe * len;
			for(int t : {-1,1}) {
				int type = x + t * ny;
				int l,r;
				if(delta_y_coe == -1) {
					if(t == -1)
						l = x + 1 , r = x + len;
					else
						l = x - len + 1 , r = x;
				}
				else {
					if(t == -1)
						l = x - len , r = x - 1;
					else
						l = x , r = x + len - 1;
				}
				
				// calculate
				auto L = ptrs[min(t+1,1)][type].lower_bound(node{l,-INF});
				auto R = ptrs[min(t+1,1)][type].upper_bound(node{r,INF});
				if(R != ptrs[min(t+1,1)][type].begin() && L != ptrs[min(t+1,1)][type].end()) {
					R--;
					int num = max(0,R->num - L->num + 1);
					ans += num;
				}
				// update
				auto it = idxs[min(t+1,1)][type].lower_bound(pii{l,-INF});
				while(it != idxs[min(t+1,1)][type].end() && it->first <= r) {
					int v = it->second;
					wait.push(v);
					idxs[min(t+1,1)][type].erase(*it);
					it = idxs[min(t+1,1)][type].lower_bound(pii{l,-INF});
				}
			}
		}
	}
	
	cout << ans/2 << endl;
	return 0;
}


Measured memory_bytes: 89216
a0,a1,a2=0,0,0
b0,b1,b2=0,0,0
matrix=[list(map(int,input().split())) for i in range(3)]
b0=matrix[0][0]-a0
b1=matrix[0][1]-a0
b2=matrix[0][2]-a0
a1=matrix[1][0]-b0
a2=matrix[2][0]-b0
flag=True
if matrix[1][1]==a1+b1 and matrix[1][2]==a1+b2 and matrix[2][1]==a2+b1 and matrix[2][2]==a2+b2:
    print('Yes')
else:
    print('No')

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

bool Solve(int pos);

int n, k;
vector< int > v;
bool dp[5005][5005];

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

    cin >> n >> k;
    for( int i = 0; i < n; ++i ) {
        int a;
        cin >> a;
        v.pb(a);

    }
    sort(all(v));

    int l, r;
    l = -1; r = n;
    while( r - l > 1 ) {
        int mid = (l + r) / 2;
        bool need = Solve(mid);

        if( need ) {
            r = mid;

        } else {
            l = mid;

        }
    }
    cout << l + 1 << endl;

    return 0;
}

bool Solve(int pos) {
    for( int i = 0; i < n; ++i ) {
        for( int j = 0; j <= k; ++j ) {
            dp[i][j] = false;

        }
    }

    for( int i = 0; i < n; ++i ) {
        dp[i][0] = true;
        if( i == 0 && i == pos ) continue;

        for( int j = 1; j < k; ++j ) {
            if( i == pos ) {
                dp[i][j] = dp[i - 1][j];
                continue;

            }

            if( i == 0 ) {
                if( v[i] == j ) {
                    dp[i][j] = true;

                }
            } else {
                if( v[i] <= j ) {
                    dp[i][j] |= dp[i - 1][j - v[i]];

                }
                dp[i][j] |= dp[i - 1][j];
            }
        }
    }

    for( int j = max(k - v[pos], 0); j < k; ++j ) {
        if( dp[n - 1][j] ) {
            return true;

        }
    }
    return false;
}



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

int a[10];
int dfs(string &s, string &t, int k) {
    int N = s.size();
    if(k >= N) return 0;
    
    int vl = (s[k] - '0' + a[k]) % 10;
    int vr = (t[k] - '0');
    if(vl == vr) return dfs(s, t, k+1);

    int x = (vr - vl + 10) % 10;
    int ans = 1010;
    for(int l=k; l<N; l++) {
        a[l] += x;
        ans = min(ans, dfs(s, t, k+1) + 1);
    }
    for(int l=k; l<N; l++) a[l] -= x;
    return ans;
}

int solve_testcase() {
    int N; cin >> N;
    if(N == 0) return 1;

    string s, t; cin >> s >> t;
    fill(a, a + 10, 0);
    cout << dfs(s, t, 0) << endl;
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;


int main(){
        int n,W;
        cin >>n >>W;
        vector<int> v(n);
        vector<int> w(n);
        rep(i,n) { cin >> v[i]; cin >>w[i]; }
        vector<vector<int>> dp(n+1,vector<int>(W+1,0));
        
        for(int i=1;i<=n;i++){
                rep(j,W+1){
                           if(j < w.at(i-1)) dp.at(i).at(j) = dp.at(i-1).at(j);
                        else dp.at(i).at(j) = max(dp.at(i-1).at(j) , dp.at(i-1).at(j-w.at(i-1)) + v.at(i-1));
                }
        }
        
        cout << dp.at(n).at(W) << endl;
        
           

        return 0;
}



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

#define ll long long
#define pb push_back
#define eb emplace_back

using namespace std;

const ll mod = 1e9 + 7;
const int e = 2*1e5 + 69;
const int base = 311;

ll n, m, k;
ll h[e];

int main()
{
    //freopen("KIENDT.inp","r",stdin);
    cin >> n;
    map<ll,ll>kt;
    map<ll,ll>kt1;
    for(int i=1; i<=n; i++)
    {
        cin >> h[i];
        kt[h[i] + i] ++;
        kt1[i - h[i]] ++;
    }
    ll ans = 0;
    for(int i=1; i<=n; i++)
    {
        ans += kt1[h[i] + i];
    }
    cout << ans;

}


Measured memory_bytes: 39376
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		char[] S = sc.next().toCharArray();

		int happy = 0;
		for (int i = 1; i < S.length; i++) {
			if (S[i-1] == S[i]) happy++;
		}
		int unhappy = S.length - 1 - happy;
		// System.out.println("unhappy = " + unhappy);
		int flip1 = Math.min(K, unhappy / 2) * 2;
		int flip2 = Math.min(K, (unhappy + 1) / 2) * 2 - 1;
		int flip = Math.max(flip1, flip2);

		System.out.println(happy + flip);
	}
}


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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	long long a, b, c;
	cin >> a >> b >> c;
	cout << b + min(c, a + b + 1) << '\n';
	return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

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

		// 整数の入力
		
		double a = sc.nextDouble();
		double v = sc.nextDouble();
		double b = sc.nextDouble();
		double w = sc.nextDouble();
		double t = sc.nextDouble();
		
		if (a > b) {
			if (b-w*t >= a-v*t) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		} else {
			if (b+w*t <= a+v*t) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}

        sc.close();
	}
}

Measured memory_bytes: 37348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

#pragma region mod
const int p = 1e9 + 7; //10^9 + 7
struct mint
{
    ll x;
    mint(ll x = 0) : x(x % p) {}
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= p)
            x -= p;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += p - a.x) >= p)
            x -= p;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= p;
        return *this;
    }

    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const
    {
        mint r = 1;
        mint a = *this;
        while (true)
        {
            if (t & 1)
            {
                r *= a;
            }
            t >>= 1;
            if (t == 0)
                break;
            a *= a;
        }

        return r;
    }

    mint inv() const
    {
        return pow(p - 2);
    }

    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
};

struct comb
{
    vector<mint> fact, invs;
    comb(int n) : fact(n + 1), invs(n + 1)
    {
        assert(n < p);

        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;

        invs[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            invs[i - 1] = invs[i] * i;
    }
    mint operator()(int n, int k)
    {
        if (k < 0 || k > n)
            return 0;
        return fact[n] * invs[n - k] * invs[k];
    }
};
#pragma endregion

int main()
{
    int n, m;
    cin >> n >> m;
    comb ncr(max(n, m));
    int ans = (ncr(n, 2) + ncr(m, 2)).x;

    cout << ans << endl;

    return 0;
}

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

int main() {
	char a[4] = { 'N','W','S','E' };
	bool flag[4] = { false };
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < 4; j++)if (s[i] == a[j])flag[j] = true;
	}
	if ((flag[0] || flag[2]) == true) {
		if ((flag[0] && flag[2]) == false) {
			cout << "No" << endl;
			return 0;
		}
	}
	if ((flag[1] || flag[3]) == true) {
		if ((flag[1] && flag[3]) == false) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys


def dep(u, p):
    D[u] = p
    for i in tree[u][3]:
        dep(i, p+1)


def print_ans():
    for i in range(n):
        print("node {}: parent = {}, depth = {}, {}, {}"
              .format(i, tree[i][0], D[i],
                      "root" if tree[i][0] == NIL else "leaf" if tree[i][1] == NIL else "internal node",
                      tree[i][3]))


if __name__ == "__main__":
    NIL = -1
    n = int(sys.stdin.readline())
    tree = [[NIL, NIL, NIL] for i in range(n)]
    D = [0 for i in range(n)]
    root = set(range(n))
    for a in sys.stdin.readlines():
        a = list(map(int, a.split()))
        tree[a[0]].append(a[2:])
        if a[1] > 0:
            tree[a[0]][1] = a[2]    # ???????????????
            for i in range(a[1]):
                tree[a[i+2]][0] = a[0] # ????????????
                if i != a[1] - 1:
                    tree[a[i+2]][2] = a[i+3] # ??????????????????
        root -= set(a[2:])
    dep(root.pop(), 0)
    print_ans()

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

int main(){
    using namespace std;
    size_t n;
    cin >> n;
    size_t p1, p2;
    cin >> p1 >> p2;
    unsigned long ans{0};
    for(size_t i = 2, p; i < n; ++i){
        cin >> p;
        ans += (p2 != min({p, p1, p2}) && p2 != max({p, p1, p2}));
        p1 = p2;
        p2 = p;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define oo 1e9
#define endl '\n'
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define vi vector<int>


using namespace std;

int n, k, c;
vi L, R;
string s;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> k >> c;
    cin >> s;
    L.pb(-oo);
    R.pb(oo);

    for(int i=0; i < n; ++i) {
        if(L.size() == k + 1) {
            break;
        }
        if(s[i] == 'x') continue;
        if(L.back() + c < i) {
            L.pb(i);
        }
    }

    for(int i=n - 1; i >= 0; --i) {
        if(R.size() == k + 1) {
            break;
        }
        if(s[i] == 'x') continue;
        if(R.back() - c > i) {
            R.pb(i);
        }
    }
    
    R.pb(-oo);
    L.pb(oo);

    reverse(R.begin(), R.end());

    for(int i=1; i < R.size() - 1; ++i) {
        //cout << R[i] << ' ' << L[i] << endl;
        if(R[i] == L[i]) {
            cout << R[i]+1 << endl;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3468
N = int(input())
A= list(map(int,input().split()))

ans = 0

while True:
        if max(A) == 0:
                break
        hoge = 0
        for i in range(N-1):
                if A[i] > 0 and A[i+1]  == 0:
                        ans += 1
        if A[N-1] > 0:
                        ans += 1

        for i in range(N):
                if A[i] != 0:
                        A[i] -= 1

print(ans)

Measured memory_bytes: 3064