akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

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

    ll N,H;
    cin>>N>>H;
    priority_queue<LP> ab;
    ll a,b;
    FOR(i,0,N){
        cin>>a;
        ab.push({a,0});
        cin>>b;
        ab.push({b,1});
    }

    ll ans=0;

    while(H>0){
        ans++;
        H-=ab.top().first;
        if(ab.top().second) ab.pop();
    }

    cout<<ans<<endl;
    
}

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

int main()
{
    int n;
    cin >> n;
    unordered_set<string> ans;
    for(int i = 0; i < n; ++i)
    {
        string temp;
        cin >> temp;
        ans.insert(temp);
    }

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


Measured memory_bytes: 17652
package main

import (
	"fmt"
)

var array []int
var n int

func main() {
	array = append(array, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)
	fmt.Scanf("%d", &n)
	n--
	fmt.Println(array[n])
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	for (int& x : A) cin >> x;
	vector<int> odd, even;
	for (int x : A) {
		if (x % 2) odd.push_back(x); else even.push_back(x);
	}
	if (odd.size() > 2) {
		cout << "Impossible" << endl;
		return 0;
	}
	vector<int> a;
	if (odd.size() >= 1) a.push_back(odd[0]);
	a.insert(a.end(), even.begin(), even.end());
	if (odd.size() >= 2) a.push_back(odd[1]);

	vector<int> b;
	if (a.size() == 1) {
		b = {a[0]-1, 1};
	} else {
		b = a;
		-- b[0];
		++ b.back();
	}
	if (b[0] == 0) b.erase(b.begin());

	for (int i = 0; i < M; ++ i) {
		if (i) cout << " ";
		cout << a[i];
	}
	cout << endl;
	cout << b.size() << endl;
	for (int i = 0; i < b.size(); ++ i) {
		if (i) cout << " ";
		cout << b[i];
	}
	cout << endl;
}


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

int main() {
  	long long int N;
  	cin >> N;
  	long long int count = 0;
  	for (int i = 0; i < N; i++){
      	count += (i + 1) * (N - i);
    }
  	for (int i = 0; i < N - 1; i++){
      	long long int u, v;
      	cin >> u >> v;
      	if (u < v) count -= u * (N - v + 1);
      	if (v < u) count -= v * (N - u + 1);
    }
  	cout << count << endl;
}


Measured memory_bytes: 3604
#include <cstdio>
#include <map>
using namespace std;
map<long long, long long> ma;
map<long long, long long> ::iterator it;
int main(){
    int n;
    scanf("%d", &n);
    long long sum = 0;
    for(int i = 1; i <= n; i++){
        long long x;
        scanf("%lld", &x);
        sum += x;
        ma[sum]++;
    }
    long long ans = 0;
    for(it = ma.begin(); it != ma.end(); it++){
        long long now = it -> second;
        if(it -> first == 0) ans = ans + (now + 1) * now / 2;
        else ans = ans + (now - 1) * now / 2;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 12672
read;tr \  \\n|nl|awk 1,\$1%=2|sort|uniq -c|sort -nr|awk '{$2?K[++i]=$3:M[++j]=$3;s+=$2?L[i]=$1:N[j]=$1}END{print s-(K[1]!=M[1]?L[1]+N[1]:(a=L[1]+N[2])<(b=L[2]+N[1])?b:a)}'

Measured memory_bytes: 32152
import sys

def ans(anl,n):
    an = 0
    for i in range(n):
        an += 10**(n-i-1)*anl[i]
    return(an)

n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

sc.sort(key=lambda x:x[0])
sc.sort()
anl =[0 for i in range(n)]
anl[0] = 1

if m == 0:
    if n == 1:
        print(0)
        sys.exit()
    else:
        print(10**(n-1))
        sys.exit()
if m == 1:
    if sc[0][1] == 0 and n == 1:
        print(0)
        sys.exit()
    anl[sc[0][0]-1] = sc[0][1]
    if anl[0] == 0:
        print('-1')
        sys.exit()
    print(ans(anl,n))
    sys.exit()

for i in range(m):
    for j in range(1,m):
        if sc[i][0] == sc[j][0] and sc[i][1]!=sc[j][1]:
            print('-1')
            sys.exit()
        else:
            anl[sc[i][0]-1] = sc[i][1]

if anl[0] == 0:
    print('-1')
    sys.exit()

print(ans(anl,n))

Measured memory_bytes: 3192
using System;

namespace ITP1_6_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var Length = int.Parse(Console.ReadLine());
            var inputs = Console.ReadLine().Split(' ');
            int[] numbers = new int[Length];
            for(int i=0 ; i<Length ; i++)
            {
                numbers[i] = int.Parse(inputs[i]);
            }

            for(int i=0 ; i<Length ; i++)
            {
                Console.Write("{0}",numbers[Length-i-1]);
                if(i!=Length-1) Console.Write(" ");
            }
            Console.WriteLine("");
        }
    }
}

Measured memory_bytes: 5652
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main() {
    ll a,b;
    cin>>a>>b;
    cout<< a*b<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,a,sum=0;
cin>>n>>m;
for(int i=0; i<m; i++){
   cin>>a;
   sum=sum+a;

}
if(sum>n) cout<<"-1"<<endl;
 else cout<<(n-sum)<<endl;






return 0;

}


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


int main () {

  double  W, H, x, y;
  
  cin >> W >> H >> x >> y;
 double maxArea = (double)(W*H*(double)(0.5000000));
 int count = (x == W/2 && y == H/2) ? 1 :0;

 std::cout << std::fixed << std::setprecision(6) << maxArea  << " " << count << std::endl;
  return 0;
}


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

using namespace std;

typedef pair<long, long> P;

long sum(long n){
    long tmp = 1;
    long ans = 0;
    while(tmp <= n){
        ans += (n%(tmp*10)-ans)/tmp;
        tmp *= 10;
    }
    return ans;
}

int main(){
    int K;
    
    vector<P> v;
    cin >> K;
    long pow[16];
    pow[0] = 1;
    for(int i = 1; i <= 15; i++) pow[i] = pow[i-1]*10;

    for(int i = 1; i <= 15; i++){
        if(i == 1){
            for(int j = 1; j <= 9; j++){
                v.push_back(P(j, sum(j)));
            }
        }
        if(i == 2){
            for(int j = 10; j <= 99; j++){
                v.push_back(P(j, sum(j)));
            }
        }
        if(i == 3){
            for(int j = 100; j <= 999; j++){
                v.push_back(P(j, sum(j)));
            }
        }
        if(i >= 4){
            for(int j = 1000; j <= 9999; j++){
                v.push_back(P(j*pow[i-4]+pow[i-4]-1, sum(j*pow[i-4]+pow[i-4]-1)));
            }
        }
    }
    double tmp_min = 10e+16;
    vector<long> ans;
    for(int i = v.size()-1; i >= 0; i--){
        if(tmp_min >= (double)v[i].first/(double)v[i].second) {
            ans.push_back(v[i].first);
            tmp_min = (double)v[i].first/(double)v[i].second;
        }
    }
    
    for(int i = 1; i <= K; i++){
        cout << ans[ans.size()-i];
        if(i != K) cout << ' ';
        else cout << endl;
    }
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N;
  cin >> N;
  vector<i64> A(3 * N);
  for (auto& x : A) cin >> x;

  priority_queue<i64> q;
  vector<i64> lcum(N + 1);
  REP(i, N) {
    q.push(-A[i]);
    lcum[0] += A[i];
  }
  for (int i = 1; i <= N; ++i) {
    lcum[i] = lcum[i - 1] + A[N + i - 1];
    q.push(-A[N + i - 1]);
    i64 v = -q.top();
    lcum[i] -= v;
    q.pop();
  }

  priority_queue<i64> q2;
  vector<i64> rcum(N + 1);
  REP(i, N) {
    int j = 3 * N - 1 - i;
    q2.push(A[j]);
    rcum[N] += A[j];
  }
  for (int i = N - 1; i >= 0; --i) {
    rcum[i] = rcum[i + 1] + A[N + i];
    q2.push(A[N + i]);
    rcum[i] -= q2.top();
    q2.pop();
  }

  i64 ans = lcum[0] - rcum[0];
  REP(i, N + 1) { ans = max(ans, lcum[i] - rcum[i]); }
  cout << ans << endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Slimes
            int N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            for(char c = 'a'; c <= 'z'; c++)
            {
                var before = new string(c, 2);
                var after = new string(c, 1);
                
                while (true)
                {
                    var s = S.Replace(before, after);

                    if (s.Length == S.Length)
                    {
                        break;
                    }
                    else
                    {
                        S = s;
                    }
                }
            }

            Console.WriteLine(S.Length);
        }
    }
}

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

int main()
{
	int n;
	char s[9];

	cin >> n;

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

		int a[8];

		for (int i = 0; i < 8; i++)
			a[i] = s[i] - '0';

		sort(a, a + 8);

		int m = 0;

		for (int i = 0; i < 8; i++) {
			m += a[7 - i] - a[i];
			m *= 10;
		}

		cout << m / 10 << endl;
	}

	return 0;
}


Measured memory_bytes: 3004
#include<stdio.h>
int main(void)
{
	int n,h[10],s[10],k[10],i,j,temp,flg,cnt;
	while(1){
		flg=0;
		cnt=0;
		scanf("%d",&n);
		if(n==0000)break;
		while(1){
			if(n==6174)break;
			if(n<1000){
				h[0]=0;
			}
			else{
				h[0]=n/1000;
			}
			if(n<100){
				h[1]=0;
			}
			else{
				h[1]=(n%1000)/100;
			}
			if(n<10){
				h[2]=0;
			}
			else{
				h[2]=((n%1000)%100)/10;
			}
			h[3]=(((n%1000)%100)%10)/1;
			if(h[0]==h[1]&&h[0]==h[2]&&h[0]==h[3]){
			flg=1;
			printf("NA\n");
			break;
			}
			cnt++;
//			printf("%d\n",cnt);
			for(i=0;i<4;i++){
				s[i]=h[i];
				k[i]=h[i];
			}
			for(i=0;i<3;i++){
				for(j=i+1;j<4;j++){
					if(s[i]>s[j]){
						temp=s[i];
						s[i]=s[j];
						s[j]=temp;
					}
				}
			}
			for(i=0;i<3;i++){
				for(j=i+1;j<4;j++){
					if(k[i]<k[j]){
						temp=k[i];
						k[i]=k[j];
						k[j]=temp;
					}
				}
			}
			n=(k[0]*1000+k[1]*100+k[2]*10+k[3])-(s[0]*1000+s[1]*100+s[2]*10+s[3]);
		}
		if(flg!=1){
			printf("%d\n",cnt);
		}
	}
	return 0;
}

Measured memory_bytes: 1036
sx, sy, tx, ty = map(int,input().split())
x = tx-sx
y = ty-sy
print('U'*y + 'R'*x + 'D'*y + 'L'*x + 'D' + 'R'*(x+1) + 'U'*(y+1) + 'L' + 'U' + 'L'*(x+1) + 'D'*(y+1) + 'R')

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
struct Data
{
    char name;
    int win;
    int lose;
    bool operator<(const Data& d)const{
        if(win != d.win){
            return win > d.win;
        }
        else{
            return lose < d.lose;
        }
    }
};
int main(){
    int n;
    while(scanf("%d",&n),n){
        Data d[32];
        rep(i,n){
            char team;
            scanf(" %c",&team);
            int w = 0,l = 0;
            rep(j,n-1){
                int x;
                scanf("%d",&x);
                (x == 0) ? ++w : (x == 1) ? ++l :  l+=0;
            }
            d[i].name = team;
            d[i].win = w;
            d[i].lose  = l;
        }
        sort(d,d+n);
        rep(i,n){
            printf("%c\n",d[i].name);
        }
    }
    return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  bool value[100], prev[100];
  int ret = 0;
  cin >> M >> N;
  for(int i = 0; i < M; i++){
    for(int j = 0; j < N; j++){
      cin >> prev[j];
      if(i != 0){
        prev[j] ^= 1;
      }
    }

    int rem = 0;
    for(int j = 0; j < N; j++){ //最後に食べるちょこ
      memcpy( value, prev, sizeof(prev));
      int res = 0;
      
      for(int k = 0; k < j; k++){
        res += value[k] == 1;
        value[k + 1] ^= 1;
      }
      for(int k = N - 1; k >= j; k--){
        res += value[k] == 1;
        value[k - 1] ^= 1;
      }
      rem = max( rem, res);
    }
    ret += rem;
  }
  cout << ret << endl;
}

Measured memory_bytes: 1164
// Knapsack 1
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define times(t) int t; cin >> t; while(t--)
#define mod 1000000007

const int mxW = 1e5+5;
ll dp[mxW];
int N, W;

void solve() {
	cin >> N >> W;
	for(int i=0; i<N; i++) {
		int w, v; cin >> w >> v;
		for(int j = W; j>=w; j--)
			dp[j] = max(dp[j-w] + v, dp[j]);
	}
	// for(int i=0; i<=W; i++) cout << dp[i] << ' ';
	// cout << endl;
	ll ans = 0;
	for(int i=0; i<=W; i++) ans = max(ans, dp[i]);
	cout << ans << endl;
	return;
}

int main() {
	IOS;
	// #ifndef ONLINE_JUDGE
	// freopen("C:/Gen code/CompProg/input.txt", "r", stdin);
	// freopen("C:/Gen code/CompProg/output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}

Measured memory_bytes: 4432
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "queue"

using namespace std;
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  ll a[200100];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    a[i] -= i;
  }
  sort(a, a + n);
  ll b = a[n / 2];
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    ans += abs(a[i] - b);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1920
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	for i := 0; i < len(s); i++ {
		if i + 2 <= len(s) {
			if isXx(s[i:i+2]) {
				fmt.Println(i + 1, i+2)
				return
			}
		}
		if i + 3 <= len(s) {
			if isXyx(s[i:i+3]) {
				fmt.Println(i + 1, i+3)
				return
			}
		}
	}
	fmt.Println("-1 -1")
}

func isXx(s string) bool {
	if len(s) != 2 {
		return false
	}

	return s[0] == s[1]
}

func isXyx(s string) bool {
	if len(s) != 3 {
		return false
	}

	return s[0] == s[2] && s[0] != s[1]
}

Measured memory_bytes: 1280
import math


def solve(depth, p1, p2):
    if depth == 0:
        return
    else:
        px = (p2[0] - p1[0]) / 3
        py = (p2[1] - p1[1]) / 3
        s = [p1[0] + px, p1[1] + py]
        t = [p1[0] + 2 * px, p1[1] + 2 * py]
        u = [(t[0] - s[0]) * math.cos(math.pi/3) -
             (t[1] - s[1]) * math.sin(math.pi/3) + s[0],
             (t[0] - s[0]) * math.sin(math.pi/3) +
             (t[1] - s[1]) * math.cos(math.pi/3) + s[1]]
        solve(depth-1, p1, s)
        print(*s)
        solve(depth-1, s, u)
        print(*u)
        solve(depth-1, u, t)
        print(*t)
        solve(depth-1, t, p2)


def main():
    n = int(input())
    print("%f %f" % (0, 0))
    solve(n, [0, 0], [100, 0])
    print("%f %f" % (100, 0))


if __name__ == '__main__':
    main()



Measured memory_bytes: 5784
program sum_of_large_numbers
  implicit none
  integer(8), parameter :: m = 1000000007_8, h = (m+1)/2, s = (m+1)/6
  integer(8) :: n, k, i
  read(*,*) n, k
  write(*,'(i0)') modulo(x(n+1)-x(k-1),m)
contains
  integer(8) function f(i)
    integer(8), intent(in) :: i
    f = mod(mod(h*i,m)*(i+1),m)
  end
  integer(8) function g(i)
    integer(8), intent(in) :: i
    g = mod(mod(s*i,m)*mod((i+1)*(i*2+1),m),m)
  end
  integer(8) function x(i)
    integer(8), intent(in) :: i
    x = mod((n+1)*f(i)-g(i)+i,m)
  end
end program sum_of_large_numbers

Measured memory_bytes: 2916
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  int r,g,b;
  cin >> r >> g >> b;
  if((10*g+b)%4==0)cout << "YES" << endl;
  else cout << "NO" <<endl;
    
  return 0;     
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main()
{
	int n,k;
	cin>>n>>k;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	int ans=0;
	for (int i = 0; i < k; ++i)
	{
		ans += a[i];
	}
	cout<<ans<<endl;

	
	return 0;
}

Measured memory_bytes: 3632
a, b, c = (int(i) for i in input().split())

if ((a == 7) and (b == 5) and (c == 5)) or ((a == 5) and (b == 7) and (c == 5)) or ((a == 5) and (b == 5) and (c == 7)):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
# coding: utf-8


def solve(*args: str) -> str:
    n, a, b = map(int, args[0].split())

    if (b-a) % 2:
        ret = min(a-1, n-b) + 1 + (b-a-1)//2
    else:
        ret = (b-a)//2

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 2940
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

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

const int INF = 1 << 30;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool leap(int y)
{
	return ((y%4==0&&y%100!=0)||y%400==0);
}

#define debug(a, b, c) for(int i = 0; i < b; i++){for(int j = 0; j < c; j++){printf("%3d", a[i][j]);}puts("");}puts("-----------------------------------------");

int main()
{
	vector< pair<char, int> > sent;
	char nchar; int nnum = 0;
	string Bsent;

	cin >> Bsent;

	for(int i = 0; i < Bsent.size(); i++)
	{
		if(!nnum)
		{
			nchar = Bsent[i];
		}
		nnum++;

		if(nchar == Bsent[i+1])
		{
			continue;
		}
		else
		{
			sent.push_back(make_pair(nchar, nnum));
			nnum = 0;
		}
	}

	int ans = 0;

	for(int i = 1; i < sent.size()-1; i++)
	{
		if(sent[i].first == 'O')
		{
			nnum = sent[i].second;
			if( sent[i-1].first == 'J' && nnum <= sent[i-1].second && nnum <= sent[i+1].second && sent[i+1].first =='I')
			{
				int nans = min(sent[i-1].second, min(sent[i+1].second, nnum));
				if(nans > ans)
					ans = nans;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 11864
use io::*;
use std::collections::BinaryHeap;

fn main() {
	let con = read_string();
	let mut sc = Scanner::new(&con);

	let n: usize = sc.next();
	let m: usize = sc.next();

	let inf: i32 = std::i32::MAX / 2;

	let mut g: Vec<Vec<usize>> = vec![Vec::new(); n];

	for _ in 0..m {
		let mut a: usize = sc.next();
		let mut b: usize = sc.next();
		a -= 1;
		b -= 1;

		g[a].push(b);
	}

	let mut s: usize = sc.next();
	let mut t: usize = sc.next();
	s -= 1;
	t -= 1;

	let mut dist: Vec<Vec<i32>> = vec![vec![inf; n]; 3];

	let mut pq = BinaryHeap::new();

	dist[0][s] = 0;
	pq.push((-dist[0][s], (0, s)));

	while let Some((d, (i, v))) = pq.pop() {
		let d = -d;

		if dist[i][v] < d {
			continue;
		}

		for u in &g[v] {
			let j: usize = (i + 1) % 3;
			let u: usize = *u;

			if dist[i][v] + 1 < dist[j][u] {
				dist[j][u] = dist[i][v] + 1;
				pq.push((-dist[j][u], (j, u)));
			}
		}
	}

	if dist[0][t] == inf {
		println!("-1");
		std::process::exit(0);
	}

	println!("{}", dist[0][t] / 3);
}

pub mod io {
	use std;
	use std::str::FromStr;

	pub struct Scanner<'a> {
		iter: std::str::SplitWhitespace<'a>,
	}

	impl<'a> Scanner<'a> {
		pub fn new(s: &'a str) -> Scanner<'a> {
			Scanner {
				iter: s.split_whitespace(),
			}
		}

		pub fn next<T: FromStr>(&mut self) -> T {
			let s = self.iter.next().unwrap();
			if let Ok(v) = s.parse::<T>() {
				v
			} else {
				panic!("Parse error")
			}
		}

		pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
			let n: usize = self.next();
			self.next_vec(n)
		}

		pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
			(0..n).map(|_| self.next()).collect()
		}
	}

	pub fn read_string() -> String {
		use std::io::Read;

		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	}

	pub fn read_line() -> String {
		let mut s = String::new();
		std::io::stdin().read_line(&mut s).unwrap();
		s.trim_right().to_owned()
	}
}

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

int main(){
  int l[26] = {0}, r[26] = {0};
  int n, ret=0;
  string str;
  cin >> n >> str;
  for(int i=0; i<n; i++){
    r[str[i]-'a']++;
  }
  for(int i=0; i<n; i++){
    l[str[i]-'a']++;
    r[str[i]-'a']--;
    int c=0;
    for(int j=0; j<26; j++){
      if(l[j]*r[j]>0)c++;
    }
    ret = (ret<c) ? c : ret;
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pii pair<int,int>
#define two(x) (x<<1)
#define towd(x) (x>>1)
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define x first
#define y second
 
ll a[200001];
 
int main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
	ll n,k;
	cin>>n>>k;
	for (int i=0;i<n;i++) cin>>a[i];
	
	ll L=-2e18,R=2e18;
	sort(a,a+n);
	while (L+1!=R){
		ll m=towd(L+R);
		ll cnt=0;
		for (int i=0; i<n; i++){
			if (a[i]<0){
				ll l=i,r=n;
				while (l+1!=r){
					int mid=towd(l+r);
					if (a[mid]*a[i]<=m) r=mid;
					else l=mid;
				}
				cnt+=n-r;
			}
			else{
				ll l=i,r=n;
				while (l+1!=r){
					int mid=towd(l+r);
					if (a[mid]*a[i]<=m) l=mid;
					else r=mid;
				}
				cnt+=l-i;
			}
		}
		if (cnt<k) L=m;
		else R=m;
	}
	cout<<R<<endl;
	return 0;
}

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

using namespace std;

int main(){
	/*freopen("in.txt.txt","r",stdin);
	freopen("out.txt.txt","w",stdout);*/
	int n;
	cin>>n;
	int ans=0;
	for(int  i=1;i<=n;i+=2){
		int divisor=0;
		for(int j=1;j<=i;j++){
			if(i%j==0)	divisor++;
		}
		if(divisor==8)	ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a;
  cin >> a;
  if (a==25) cout << "Christmas" << endl;
  if (a==24) cout << "Christmas Eve" << endl;
  if (a==23) cout << "Christmas Eve Eve" << endl;
  if (a==22) cout << "Christmas Eve Eve Eve" << endl;
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if (a * n < b) {
    cout << a * n << endl;
  }
  else if (a * n == b) {
    cout << b << endl;
  }
  else {
    cout << b << endl;
  }
}


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

int main()
{
    int n,a[110],b[10],sum,ma;
    while (scanf("%d",&n)!=EOF)
    {
        sum = 0;
        ma = 0;
        memset(b,0,sizeof b);
        for (int i = 0;i<n;i++)
        {
            scanf("%d",&a[i]);
            if (a[i]>=1&&a[i]<=399)
            {
                if (b[0]==0)
                    sum++;
                b[0]=1;
            }
            else if (a[i]>=400&&a[i]<=799)
            {
                if (b[1]==0)
                    sum++;
                b[1] = 1;
            }
            else if (a[i]>=800&&a[i]<=1199)
            {
                if (b[2]==0)
                    sum++;
                b[2] = 1;
            }
            else if (a[i]>=1200&&a[i]<=1599)
            {
                if (b[3]==0)
                    sum++;
                b[3] = 1;
            }
            else if (a[i]>=1600&&a[i]<=1999)
            {
                if (b[4]==0)
                    sum++;
                b[4] = 1;
            }
            else if (a[i]>=2000&&a[i]<=2399)
            {
                if (b[5]==0)
                    sum++;
                b[5] = 1;
            }
            else if (a[i]>=2400&&a[i]<=2799)
            {
                if (b[6]==0)
                    sum++;
                b[6] = 1;
            }
            else if (a[i]>=2800&&a[i]<=3199)
            {
                if (b[7]==0)
                    sum++;
                b[7] = 1;
            }
            else
            {
                ma++;
            }

        }
        if (sum==0)
            printf("1 %d\n",ma);
        else
            printf("%d %d\n",sum,sum+ma);
    }
    return 0;
}


Measured memory_bytes: 256
use proconio::*;

fn main() {
    input! {
        n: usize,
        m: usize,
    }
    let mut uf = UnionFind::new(n);
    let mut ans = 0;
    for _ in 0..m {
        input! {
            a: usize,
            b: usize,
        }
        uf.unite(a-1, b-1)
    }
    for r in uf.roots(n).iter() {
        if uf.size(*r) > ans {
            ans = uf.size(*r);
        }
    }
    println!("{}", ans)
}

struct UnionFind {
    root: Vec<usize>,
    rank: Vec<usize>,
    sizes: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut vec = vec![0;n];
        for i in 0..n {
            vec[i] = i;
        }
        UnionFind {
            root: vec,
            rank: vec![0;n],
            sizes: vec![1;n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if self.root[x] == x { return x }
        self.root[x] = self.find(self.root[x]);
        self.root[x]
    }

    fn unite(&mut self, x: usize, y: usize) -> () {
        let x = self.find(x);
        let y = self.find(y);
        if x == y { return }
        if self.rank[x] < self.rank[y] {
            self.root[x] = y;
            self.sizes[y] += self.sizes[x];
        } else {
            self.root[y] = x;
            self.sizes[x] += self.sizes[y];
            if self.rank[x] == self.rank[y] {
                self.rank[x] += 1;
            }
        }
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn size(&mut self, x: usize) -> usize{
        let f = self.find(x);
        self.sizes[f]
    }

    fn roots(&mut self, n: usize) -> Vec<usize> {
        let mut vec = vec![];
        for i in 0..n {
            if self.root[i] == i {
                vec.push(self.root[i]);
            }
        }
        vec
    }
}

Measured memory_bytes: 9264
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

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

		StringBuilder buf = new StringBuilder();

		String S = scan.next();

		Pattern p = Pattern.compile("hi");
		Matcher m = p.matcher(S);

		while(m.find()) {
			buf.append(m.group());
		}

		if(S.equals(buf.toString())) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		scan.close();
	}
}

Measured memory_bytes: 23636
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k; cin >> n >> k;
	int ans = 0;
	while (n > 0) {
		n /= k;
		ans++;
	}
	cout << ans << endl;
}

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

int main(){
    int W,H,N;
    cin>>W>>H>>N;

    vector<vector<int>> v(H,vector<int>(W,1));

    vector<int> x(N);
    vector<int> y(N);
    vector<int> a(N);

    for(int i=0;i<N;i++){cin>>x.at(i)>>y.at(i)>>a.at(i);}

    for(int i=0;i<N;i++){
        if(a.at(i)==1){
            for(int j=0;j<H;j++){  
                for(int k=0;k<x.at(i);k++){
                    v.at(j).at(k) = 0;
                }
            }
        }
        if(a.at(i)==2){
            for(int j=0;j<H;j++){  
                for(int k=x.at(i);k<W;k++){
                    v.at(j).at(k) = 0;
                }
            }
        }

        if(a.at(i)==3){
              for(int k=0;k<y.at(i);k++){
                    for(auto& e:v.at(k)){
                        e = 0;
                    }
                }
            
        }
        if(a.at(i)==4){
            for(int k=y.at(i);k<H;k++){
                    for(auto& e:v.at(k)){
                        e = 0;
                    }
                }
            
        }
    }

    vector<int> w(H);
  
    for(int i=0;i<H;i++){
        w.at(i)= accumulate(v.at(i).begin(), v.at(i).end(), 0); 
    }

    int sum = accumulate(w.begin(), w.end(),0);
    cout << sum << endl; 
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 100010;
int a[N], f[N], n;

int main() {
  scanf("%d", &n);
  memset(f, 0, sizeof f);
  ll res = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    res += x;
    f[x]++;
  }

  int q, b, c;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &b, &c);
    res += (ll)f[b] * (c - b);
    f[c] += f[b];
    f[b] = 0;
    printf("%lld\n", res);
  }
}



Measured memory_bytes: 4152
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main() 
{
    int a, b, c;

    while (cin >> a >> b >> c) {
        if (a < b && b < c) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}



Measured memory_bytes: 3056
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int N,M;


int main (){
      cin>>N>>M;
      int ans=0;
      for(int i=1;i*i<=M;i++){
            if(M%i==0&&M/i>=N){
                  ans=max(ans,i);
            }
            if(M%i==0&&i>=N){
                  ans=max(ans,(M/i));
            }
      }
      cout<<ans<<endl;
      
      return 0;
}


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

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int> vec;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    if(tmp==0) k--;
    else vec.push_back(tmp);
  }
  n=vec.size();
  if(k==0){
    cout<<0;
    return 0;
  }
  vector<int> ans;
  vector<int> tmp(k);
  for(int j=0;j<k;j++){
    tmp[j]=vec[j];
  }
  for(int i=k;i<=n;i++){   
    if(tmp[k-1]<0){
      ans.push_back(abs(tmp[0]));
    }
    else if(tmp[0]>0){
      ans.push_back(abs(tmp[k-1]));
    }
    else{
      if(abs(tmp[0])>tmp[k-1]){
        ans.push_back(abs(tmp[0])+2*tmp[k-1]);
      }
      else{
        ans.push_back(2*abs(tmp[0])+tmp[k-1]);
      }
    }
    tmp.erase(tmp.begin());
    tmp.push_back(vec[i]);
  }
  cout<<*min_element(ans.begin(),ans.end());
}

Measured memory_bytes: 1272
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <list>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#define M 500005
#define INF (1 << 30)
typedef long long ll;
using namespace std;

int arr[M], cnt;
int R[M / 2 + 2], L[M / 2 + 2];
void merge(int left, int mid,  int right)	//????????????
{
	if (right - left <= 1)
		return;
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; ++i)
		L[i] = arr[left + i];
	for (int i = 0; i < n2; ++i)
		R[i] = arr[mid + i];
	L[n1] = R[n2] = INF;
	int i = 0, j = 0;
	for (int k = left; k < right; ++k)
	{
		++cnt;
		if (L[i] <= R[j])
		{
			arr[k] = L[i++];
		}
		else
		{
			arr[k] = R[j++];
		}
	}
}

void mergesort(int l, int r)
{
	if (r - l <= 1)
		return;
	int mid = (l + r) / 2;
	mergesort(l, mid);
	mergesort(mid, r);
	merge(l, mid, r);
}


int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		scanf("%d", &arr[i]);
	cnt = 0;
	mergesort(0, n);
	
	for (int i = 0; i < n - 1; ++i)
		printf("%d ", arr[i]);
	printf("%d\n", arr[n - 1]);
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 7108
open Batteries
open BatPrintf

let scan fmt f =
  Scanf.sscanf (read_line ()) fmt f

let scan_list cnv =
  read_line ()
  |> String.split_on_char ' '
  |> List.map cnv

let scan_listn n cnv =
  (0 --^ n) |> Enum.map (fun _ -> (cnv % read_line) ())

let bsearch_ge arr a =
  let l = Array.length arr in
  match Array.bsearch Int.ord arr a with
  | `All_lower -> l
  | `All_bigger -> 0
  | `Just_after n -> l - n -1
  | `At n -> l - n
  | `Empty -> 0

let rec zip xs ys =
  match xs, ys with
  | [], _ -> []
  | _, [] -> []
  | x::xs, y::ys ->
    (x, y) :: zip xs ys

let square x = x * x

let dbg n = Printf.eprintf "%s\n" @@ dump n; n

let n = scan "%d" identity

let () =
  succ n / 2
  |> printf "%d"


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

int main(){
    string S;
    cin >>S;
    int ans=0;
    for(int i=0;i<4;i++){
      if(S.at(i)=='+')ans++;
      else ans--;
    }
    cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,size;
  string s,a,b;
  for(cin>>n,getline(cin,s,'\n');n>0;n--){
    getline(cin,s,'\n');
    //cin>>s;
    size = s.size();
    if(size<6||size%2){cout<<"NA"<<endl;continue;}
    a=">'"; b=">^";
    for(int i=0;i<size/2-2;i++){a=a+"=";b=b+"Q=";}
    a+="#";
    for(int i=0;i<size/2-2;i++){a=a+"=";}
    a+="~"; b+="~~";
    if (s==a)cout<<"A"<<endl;
    else if (s==b)cout<<"B"<<endl;
    else cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
def partition(a,p,r)
  x = a[r]
  i = p-1
  (p..r-1).each do |j|
    if a[j] <= x
      i = i+1
      a[i],a[j] = a[j],a[i]
    end
  end 
  a[i+1],a[r] = a[r],a[i+1]
  return i+1
end
ab = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ind =  partition(a,0,ab-1)
a.size.times do |d|
  if(d == (ab-1))
    break
  elsif d != ind
    print("#{a[d]} ")
  else
    print("[#{a[d]}] ")
  end
end
if ab != ind
  puts("#{a[ab-1]}")
else
  puts("[#{a[ab-1]}]")
end

Measured memory_bytes: 17148
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto s = readln.chomp;
  int m;
  foreach (i; 1..n-1) {
    auto a = s[0..i];
    auto b = s[i..$];
    int[int] cnt1;
    int[int] cnt2;
    foreach (e; a) {
      cnt1[e]++;
    }
    foreach (e; b) {
      cnt2[e]++;
    }
    int lm;
    foreach (k; cnt1.keys) {
      if (cnt2.get(k, 0)) {
        lm++;
      }
    }

    m = max(m, lm);
  }

  m.writeln;
}


Measured memory_bytes: 636
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	cc = collections.Counter(al)
	if n % 2 == 1:
		if cc[0] != 1:
			return 0
		for c in range(2, n, 2):
			if cc[c] != 2:
				return 0
		else:
			return pow(2, n//2, mod)
	else:
		for c in range(1, n, 2):
			if cc[c] != 2:
				return 0
		else:
			return pow(2, n//2, mod)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 93252
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n;

	cin >> n;
	vector<int> a(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		long long b = min(a[i-1], a[i]);
		ans += b;
		a[i-1] -= b;
		a[i] -= b;

		long long c = a[i] / 2;
		ans += c;
		a[i] -= 2 * c;
	}

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


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.HashSet;

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

if(Ss[Ss.length-1].equals("s")){
  System.out.println(S+"es");

}else{
  System.out.println(S+"s");
}

}
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s, t; cin >> s >> t;
    int n = t.size();
    ll res = INF;
    rep(i, (int)s.size()-n+1){
        ll cnt = 0;
        rep(j, n){
            if(s[i+j] != t[j]) cnt++;
        }
        res = min(res, cnt);
    }
    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7716
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll par[55], ran[55];
ll n, m;
ll root(ll x) {
	return par[x] == x ? x : par[x] = root(par[x]);
}
void unite(ll x, ll y) {
	x = root(x);
	y = root(y);
	if (x == y)return;
	if (ran[x] < ran[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (ran[x] == ran[y])ran[x]++;
	}
}
int main() {
	cin >> n >> m;
	P p[55];
	ll ans = 0;
	for (int i = 0; i < m; i++) {
		cin >> p[i].first >> p[i].second;
	}
	for (int i = 0; i < m; i++) {
		for (int o = 1; o <= n; o++) {
			par[o] = o;
			ran[o] = 0;
		}
		ll p1 = p[i].first, p2 = p[i].second;
		for (int j = 0; j < m; j++) {
			if (i == j)continue;
			unite(p[j].first, p[j].second);
		}
		ll num;
		for (int k = 1; k <= 3; k++) {
			if (k == p1 || k == p2)continue;
			num = k;
			break;
		}
		if (root(p1) != root(p2) || root(p1) != root(num) || root(p2) != root(num))ans++;
	}
	cout << ans << endl;
	return 0;
}


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

int main () {
  int N;
  cin >> N;
  vector <int> boss(N-1);
  for (int i = 0; i < N-1; i++) cin >> boss.at(i);
  vector <int> count(N);
  for (int i = 0; i < N-1; i++){
    int a;
    a = boss.at(i)-1;
    count.at(a)++;
  }
  for (int i = 0; i < N; i++) cout << count.at(i) << endl;
}


Measured memory_bytes: 4828
N, K = map(int, input().split())
S = input()

c_1 = [0]
c_0 = [0]
count = 0
before = '1'
answer = 0



for i in S:
    if i == before:
        count += 1
    else:
        if before == '1':
            c_1.append(c_1[-1] + count)
        else:
            c_0.append(c_0[-1] + count)
        if i == '0':
            if K+1 < len(c_1):
                answer = max(answer, c_1[-1] - c_1[-(K+2)] + c_0[-1] - c_0[-(K+1)])
            else:
                answer = max(answer, c_1[-1] + c_0[-1])
        count = 1
        before = i

if i == '1':
    c_1.append(c_1[-1] + count)
    if K + 1 < len(c_1):
        answer = max(answer, c_1[-1] - c_1[-(K + 2)] + c_0[-1] - c_0[-(K + 1)])
    else:
        answer = max(answer, c_1[-1] + c_0[-1])

else:
    c_0.append(c_0[-1] + count)

    if K + 1 < len(c_1):
        answer = max(answer, c_1[-1] - c_1[-(K + 1)] + c_0[-1] - c_0[-(K + 1)])
    else:
        answer = max(answer, c_1[-1] + c_0[-1])


print(answer)

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

using namespace std;

#define int long long
#define MKP make_pair
typedef pair<int, int> pii;

constexpr int MAX_N = 305;
constexpr int INF = 1LL << 60;

int n, mem[MAX_N][MAX_N], w[MAX_N];

int solve(int l, int r) {
    if (r - l <= 1) {
        return 0;
    }
    if (mem[l][r] != -1) {
        return mem[l][r];
    }

    int res = 0;
    for (int i = l + 1; i < r; ++i) {
        res = max(res, solve(l, i) + solve(i, r));
    }
    for (int i = r - 1; l + 1 <= i; --i) {
        res = max(res, solve(l, i) + solve(i, r));
    }

    if (abs(w[l] - w[l + 1]) <= 1) {
        res = max(res, solve(l + 2, r) + 2);
    }
    if (abs(w[r - 1] - w[r - 2]) <= 1) {
        res = max(res, solve(l, r - 2) + 2);
    }
    if (abs(w[l] - w[r - 1]) <= 1) {
        int tmp = solve(l + 1, r - 1);
        if (tmp == r - l - 2) {
            res = max(res, tmp + 2);
        }
    }

    return mem[l][r] = res;
}

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

    while(1) {
        cin >> n;
        if (n == 0) {
            return 0;
        }
        memset(mem[0], -1, sizeof(mem));

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

        cout << solve(0, n) << endl;
    }
}



Measured memory_bytes: 3860
import java.util.*;
import java.util.Scanner;
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
 
public class Main
{
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main (String[] args) 
	{
        //code by sushant kumar
        FastReader in=new FastReader();
        char ch=(in.nextLine()).charAt(0);
        if(ch>=65&&ch<=90)
            System.out.println('A');
        else 
            System.out.println('a');
    }
}

Measured memory_bytes: 25288
N = int(input())
ac = 0
wa = 0
re = 0
tle = 0
for i in range(N):
    s = input()
    if s=="AC":
        ac += 1
    elif s=="WA":
        wa += 1
    elif s=="RE":
        re += 1
    elif s=="TLE":
        tle += 1

print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

Measured memory_bytes: 9136