akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll

int32_t main()
{
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	#endif
	
	int k,n;
	cin>>k>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	vector<int> d;
	d.push_back(a[0]+k-a[n-1]);
	for(int i=0;i<n-1;i++)d.push_back(a[i+1]-a[i]);
	
	int s=accumulate(d.begin(),d.end(),0LL);
	int mx=*max_element(d.begin(),d.end());
	cout<<s-mx;
	
}

Measured memory_bytes: 6860
#include<iostream>
#include<map>
#include<vector>

using namespace std;
typedef long long ll;

int main(){
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    map<char, ll> data;
    data['A'] = a;
    data['B'] = b;
    data['C'] = c;
    vector<char> move;
    string choices[n];
    for(int i = 0;i < n;i++){
        cin >> choices[i];
    }
    for(int i = 0;i <= n - 1;i++){
        char ch_1 = choices[i][0];
        char ch_2 = choices[i][1];
        if(data[ch_1] > data[ch_2]){
            data[ch_1] -= 1;
            data[ch_2] += 1;
            move.push_back(ch_2);
        }
        else if(data[ch_1] < data[ch_2]){
            data[ch_2] -= 1;
            data[ch_1] += 1;
            move.push_back(ch_1);
        }
        else{
            if((i < n - 1) && (ch_1 == choices[i + 1][0] || ch_1 == choices[i + 1][1])){
                data[ch_1] += 1;
                data[ch_2] -= 1;
                move.push_back(ch_1);
            }
            else{
                data[ch_1] -= 1;
                data[ch_2] += 1;
                move.push_back(ch_2);
            }
        }
        if(data['A'] < 0 || data['B'] < 0 || data['C'] < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    if(data['A'] < 0 || data['B'] < 0 || data['C'] < 0){
        cout << "No" << endl;
        return 0;
    }
    cout<< "Yes" << endl;
    for(auto x: move){
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 6896
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
  int N,M;cin>>N>>M;
  vector<int>V(N);
  UnionFind UF(N);
  for(int X=0;X<N;X++){
    cin>>V[X];V[X]--;
  }
  for(int X=0;X<M;X++){
    int A,B;cin>>A>>B;A--;B--;
    UF.merge(A,B);
  }
  int H=0;
  for(int X=0;X<N;X++){
    if(UF.issame(X,V[X]))H++;
  }
  cout<<H<<endl;
}


Measured memory_bytes: 3956
#include<stdio.h>

int main(void){
  int n, x[100] = {0}; 
  int p, sum = 0;
  int i;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &x[i]);
    sum += x[i];
  }
  
  p = (double)sum / n + 0.5;
  int min = 0;
  
  for(i = 0; i < n; i++)  min += (x[i] - p) * (x[i] - p);
  
  printf("%d\n", min);
  
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define dbg(x)
#endif

#define X first
#define Y second
const int MOD = int(1e9 + 7);
void add(int &a, int b){
    a += b;
    if (a >= MOD) a -= MOD;
}

int N, C;
int arr[512], brr[512];
int memo[512][512];
int table[512][512];
int exp(int a, int b){
    if (b == 0) return 1;
    if (b & 1){
        return (ll)a * exp(a, b-1) % MOD;
    }
    int tmp = exp(a, b/2);
    return (ll)tmp * tmp % MOD;
}

void pre(){
    memset(table, 0, sizeof table);
    for (int c = 0; c < 512; c++){
        for (int x = 1; x < 512; x++){
            add(table[c][x], exp(x, c));
            add(table[c][x], table[c][x - 1]);
        }
    }
}


int dp(int id, int c){
    int &res = memo[id][c];
    if (res != -1) return res;
    if (id == N){
        if (c == 0) return res = 1;
        return res = 0;
    }
    res = 0;
    for (int i = 0; i <= c; i++){
        int mul = (table[i][brr[id]] - table[i][arr[id] - 1] + MOD) % MOD;
        add(res, (ll)mul * dp(id + 1, c - i) % MOD);
    }
    return res;
}
int main(){
    pre();
    std::ios_base::sync_with_stdio(false);
    cin >> N >> C;
    for (int i = 0; i < N; i++) cin >> arr[i];
    for (int i = 0; i < N; i++) cin >> brr[i];
    memset(memo, -1, sizeof memo);
    cout << dp(0, C) << endl;


    return 0;
}


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

template<class T>
T lcm(T a,T b){
    return a/__gcd(a,b)*b;
}

int main(){
    int a,b,c;cin >> a >> b >> c;
    cout << min(b/a,c);
    return 0;
}

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

int main() {
  int a;
  cin >> a;
  int kaunto = 0;
  for (int i = 1; i <= 9; i++) {
    if (a / i <= 9 && a % i == 0) {
      kaunto++;
      cout << "Yes" << endl;
    }
    if (kaunto > 0) {
      break;
    }
  }
  if (kaunto == 0) {
    cout << "No" << endl;
  }
}

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

latest = [None]*K
i = len(S)+C
for j in range(K-1, -1, -1):
  i = S.rindex("o", 0, i-C)
  latest[j] = i

if i<=C or "o" not in S[:i-C]:
  i = -C-1
  for j in latest:
    i = S.index("o", i+C+1)
    if i == j:
      print(i+1)


Measured memory_bytes: 12688
N, K= map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(30):
    res = 0
    k = K>>i
    if k & 1:
        for a, b in zip(A, B):
            if not (a>>i) & 1 and ((a>>i)| k)<=k:
                res+=b
    ans = max(res, ans)
res = 0
for a, b in zip(A, B):
    if a | K <= K:
        res+=b
ans = max(ans, res)
print(ans)

Measured memory_bytes: 11060
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S = gets.chomp

ss = S.split('')[0...(S.length/2)]
sr = S.reverse.split('')[0...(S.length/2)]

num = 0
ss.each.with_index do |c, index|
  num += 1 if c != sr[index]
end

puts num


Measured memory_bytes: 14464
def main():
    MOD = 10 ** 9 + 7

    N, K = map(int, input().split())

    ctr = [0] * (K + 1)
    for g in range(K, 0, -1):
        cnt = pow(K // g, N, MOD)

        c = 2
        while c * g <= K:
            cnt = (cnt - ctr[c * g]) % MOD
            c += 1
        ctr[g] += cnt

    ans = 0
    for g, cnt in enumerate(ctr, 0):
        ans = (ans + g * cnt) % MOD

    print(ans)


if __name__ == '__main__':
    main()


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

G =[]
for idx,a in enumerate(A):
    if idx == 0:
        G.append(A[idx]+K-A[N-1])
    else:
        G.append(A[idx]-A[idx-1])

G.append(K-A[N-1])

print(K-max(G))

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

int main(){
    int N,M;
    cin >> N >> M;
    int V = 0;
    int A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
        V = V + A[i];
    }

    int tmp;

    for(int i=N; i>0; i--){
        for(int j=1; j<i; j++){
            if(A[j] > A[j-1]){
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
            }
        }
    }

    if(A[M-1]*4*M >= V){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<long long> a(n);
    int x;
    for (int i = 0; i < n; i++) {
        cin >> x;
        x -= i + 1;
        a[i] = x;
    }
    sort(a.begin(), a.end());
    int c;
    if (n % 2 == 0) {
        c = (a[n / 2 - 1] + a[n / 2]) / 2;
    } else {
        c = a[n / 2];
    }
    c--;
    long long ans = __LONG_LONG_MAX__;
    long long tmpans;
    for (int i = 0; i < 3; i++) {
        tmpans = 0;
        for (int j = 0; j < n; j++) { tmpans += abs(a[j] - c); }
        ans = min(ans, tmpans);
        c++;
    }
    cout << ans << endl;
}

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

int main()
{
    int n;
    cin >> n;
    
    map<int, int>a;
    for(int i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        a[b]++;
    }
    
    long long int cnt = 0;
    for(auto it = a.begin(); it != a.end(); it++)
    {
        int a = (*it).second;
        int val = (*it).first;
        if(val > a)
        {
            cnt += a;
        }
        else
        {
            cnt += (a - val);
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4736
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

class UF
{
private:
    int         num;
    vector<int> par;
    vector<int> siz;
public:
    vector<int> val0;
    vector<int> val1;
public:
    UF(int n): num(n) {
        par.resize(n);
        siz.resize(n);
        val0.resize(n);
        val1.resize(n);
        int i;
        for(i=0; i<n; i++) {
            par[i]=i; siz[i]=1;
            val0[i]=val1[i]=0;
        }
    }
	
    int find(int x) {
        if(x==par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(siz[x]<siz[y]) {
            par[x]=y;
            siz[y]=siz[x]+siz[y];
            val0[y]=val0[x]+val0[y];
            val1[y]=val1[x]+val1[y];
        }
        else {
            par[y]=x;
            siz[x]=siz[x]+siz[y];
            val0[x]=val0[x]+val0[y];
            val1[x]=val1[x]+val1[y];
        }
    }

    bool same(int x, int y) {
        return find(x)==find(y);
    }

    int size(int x) {
        return siz[find(x)];
    }

    int ngroup( ll& ans ) {
        int count=0;
        int i;
        for(i=0; i<num; i++) {
            if(par[i]==i) {
                count++;
                ans += ((ll)val0[i]*val1[i]);
            }
        }
        return count;
    }
};

char str[401][401];

int main(int argc, char* argv[])
{
    int h,w;
    scanf("%d%d", &h, &w);

    int i,j;
    for(i=0; i<h; i++) {
        scanf("%s", str[i]);
    }

#define INDEX(i,j) ((i)*w+(j))
    UF uf(h*w);
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            if(str[i][j]=='#') uf.val0[INDEX(i,j)]++;
            else               uf.val1[INDEX(i,j)]++;
        }
    }

    for(i=0; i<h; i++) {
        for(j=0; j<w-1; j++) {
            if(str[i][j]!=str[i][j+1]) {
                uf.unite(INDEX(i,j),INDEX(i,j+1));
            }
        }
    }
    for(j=0; j<w; j++) {
        for(i=0; i<h-1; i++) {
            if(str[i][j]!=str[i+1][j]) {
                uf.unite(INDEX(i,j),INDEX(i+1,j));
            }
        }
    }

    ll ans=0;
    int nn = uf.ngroup(ans);
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 2944
A, B, K = map(int, input().split())
for i in range(K) :
    if i % 2 == 0 :
        if A % 2 == 1:
            A -= 1
        B += int(A / 2)
        A = int(A / 2)
    else : 
        if B % 2 == 1 :
            B -= 1
        A += int(B / 2)
        B = int(B / 2)
print(A, B)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int a,b,ans,now=1;
int main()
{
	//freopen(".in","r",stdin);freopen(".out","w",stdout);
	cin>>a>>b;
	ans=0;
	while(now<b){
		ans++;
		now=now-1+a;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
using System;
namespace ForATCODER
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int N = s2i(Console.ReadLine());
            if(N.ToString().IndexOf('7') !=-1)
            {
                Console.WriteLine("Yes");
            }
            else Console.WriteLine("No");

        }
        static int s2i(String s)
        {
            return Convert.ToInt32(s);
        }
        static void RESULT(int res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(String res)
        {
            Console.WriteLine(res);
        }
        static String[] ReadLineAll(int count)
        {
            String[] res = new String[count];
            for (int i = 0; i < count; i++)
            {
                res[i] = Console.ReadLine(); 
            }
            return res;
        }

        static int[] S2Iarray(String[] src)
        {
            int len = src.Length;
            int[] res = new int[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt32(src[i]);
            }
            return res;
        }
    }
}


Measured memory_bytes: 27512
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) ;
#define cerr if(0)cout
#endif

int main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    vector<pair<ll, ll> >prc(4);
    rep(i, 0, 4){
        cin >> prc[i].sd;
        prc[i].ft = (1 << i);
    }
    ll tgt, res = INF; cin >> tgt; tgt *= 4;
    do{
        ll cand = 0, to_buy = tgt;
        for(auto& p : prc){
            cand += (to_buy / p.ft) * p.sd;
            to_buy %= p.ft;
        }
        res = min(res, cand);
    } while(next_permutation(all(prc)));
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,a,b,c,d,e
    integer(8),allocatable :: x(:)
  
    read(*,*) a,b,c,n
    
    m=0
    do i=0,n/a
        d=n-a*i
        do j=0,d/b
            e=d-b*j
            if(mod(e,c)==0)then
            	m=m+1
            endif
        end do
    end do

    write(*,*) m
  
    stop
end program sample
  



Measured memory_bytes: 2788
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetNumber();
            var line = GetStrings(N).Reverse().ToArray();
            Console.WriteLine(string.Join(" ", line));
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static int[] GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static long[] GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();
        }

        static double[] GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray();
        }

        static string[] GetStrings(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        }
    }
}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)82;
int N, ab[MAXN][MAXN][2], dp[MAXN][MAXN][80*80*4+1], ans = (int)1e9;


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int H, W;
    cin >> H >> W;
    for(int i=0; i<2; i++)
    {
        for(int j=0; j<H; j++)
        {
            for(int k=0; k<W; k++)
            {
                cin >> ab[j][k][i];
            }
        }
    }
    dp[0][0][ab[0][0][0]-ab[0][0][1] + 80*80*2] = true, dp[0][0][ab[0][0][1]-ab[0][0][0] + 80*80*2] = true;
    for(int i=0; i<H; i++)
    {
        for(int j=0; j<W; j++)
        {
            for(int k=0; k<=80*80*4; k++)
            {
                if(!dp[i][j][k])
                    continue;
                if(i < H-1)
                {
                    int x = ab[i+1][j][0] - ab[i+1][j][1];
                    dp[i+1][j][k+x] = true;
                    dp[i+1][j][k-x] = true;
                }

                if(j < W-1)
                {
                    int x = ab[i][j+1][0] - ab[i][j+1][1];
                    dp[i][j+1][k+x] = true;
                    dp[i][j+1][k-x] = true;
                }

            }
        }
    }
    for(int i=0; i<=80*80*4; i++)
    {
        if(dp[H-1][W-1][i])
        {
            ans = min(ans, abs(80*80*2-i));
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 655872
#include<stdio.h>

int main(void)
{
  int sum;
  int n[5000];
  int a=0,i,j,x=0,k;

  while(scanf("%d",&k) != EOF){
    if(k==0)
      break;

    for(i=0; i<k; i++){
      scanf("%d",&n[i]);
    }

    x=-10000000;
    for(i=0; i<k; i++){
      sum =0; 
      for(j=i; j<k; j++){
	sum=sum+n[j];
	if(x<sum)
	  x=sum;
      }
    }
    printf("%d\n",x);
  }

  return 0;
}

Measured memory_bytes: 1048
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def main():
    s = read()
    ans = 0
    cnt_a = 0
    last_ch = 'C'
    for ch in s:
        if ch == 'A':
            if last_ch != 'A':
                cnt_a = 0
            cnt_a += 1
            last_ch = ch
        elif ch == 'B':
            if last_ch != 'A':
                cnt_a = 0
            last_ch = ch
        elif ch == 'C':
            if last_ch == 'B':
                ans += cnt_a
                cnt_a = cnt_a
                last_ch = 'A'
            else:
                cnt_a = 0
                last_ch = ch
    print(ans)


def slow(s):
    ans = 0
    while True:
        x = s.count('ABC')
        if x:
            ans += x
            s = s.replace('ABC', 'BCA')
        else:
            break
    return ans

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")


def read():
    return input()


def read_array(sep=None, maxsplit=-1):
    return read().split(sep, maxsplit)


def read_int():
    return int(read())


def read_int_array(sep=None, maxsplit=-1):
    return [int(a) for a in read_array(sep, maxsplit)]

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 34076
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db double
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
const int mxn=52,du=1e9+7;
int n,k;
vector<vector<int> > mul(vector<vector<int> > a,vector<vector<int> > b)
{
    vector<vector<int> > pro(a.size(),vector<int>(b[0].size()));
    for (int i=0;i<a.size();i++) 
    for (int j=0;j<b.size();j++)
    for (int k=0;k<b[0].size();k++)
    {
        pro[i][j]+=a[i][k]*b[k][j];
        pro[i][j]%=du;
    }
    return(pro);
}
vector<vector<int> > bin(vector<vector<int> > a,int k)
{
    vector<vector<int> > res=a;
    while(k)
    {
        if (k&1) res=mul(res,a);
        a=mul(a,a);
        k/=2;
    }
    return(res);
}
vector<vector<int> > a;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    k--;
    a=vector<vector<int> >(n+1,vector<int>(n+1));
    for (int i=1;i<=n;i++)
    for (int j=1;j<=n;j++)
    {
        cin>>a[i][j];
    }
    vector<vector<int> > ans=bin(a,k);
    int sum=0;
    for (int i=1;i<=n;i++)
    for (int j=1;j<=n;j++)
    {
        sum+=ans[i][j];
        sum%=du;
    }
    cout<<sum;
    return 0;
}

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

int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int>c(n),sum(m);
    vector<vector<int>>a(n,vector<int>(m));
    rep(i,n){
        cin>>c[i];
        rep(j,m){
            cin>>a[i][j];
            sum[j]+=a[i][j];
        }
    }
    rep(i,m)if(sum[i]<x){cout<<-1<<endl; return 0;}
    int ans=1e9;
    rep(i,1<<n){
        int cnt=0;
        rep(j,m)sum[j]=0;
        rep(j,n){
            if(i&(1<<j)){
                cnt+=c[j];
                rep(k,m)sum[k]+=a[j][k];
            }
        }
        bool ok=true;
        rep(j,m)if(sum[j]<x)ok=false;
        if(ok)ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main( ) {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,a,b,c;
	t = 1;
	while(t--) {
	 cin >> a >> b >> c;
	 if(a + b == c || b + c == a || c + a == b)
	  cout << "Yes" << endl;
	 else
	  cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;
	char c;
	cin>>c;
	cout << (char)(c+1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
template <typename T> 
using lim = numeric_limits<T>;
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N= 5e5;
int n, q;
int c[N];

struct query{
    int l, r, idx;

    bool operator<(const query& other){
        return r < other.r;
    }
};

int last[N];
int bits[N+1];
query queries[N];

int ans[N];

void update(int idx, int val){
    for (; idx <= N; idx+=idx&-idx)
        bits[idx] += val;
}

int solve(int idx){
    int sum = 0;
    for (; idx >0; idx-=idx&-idx)
        sum += bits[idx];
    return sum;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> q;
    memset(last, -1, sizeof last);
    memset(bits, 0, sizeof bits);

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

    for (int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        l--; r--;
        queries[i] = {l, r, i};
    }
    sort(queries, queries+q);

    int counter = 0;
    for (int i = 0; i < n; i++){
        if (last[c[i]] != -1){
            update(last[c[i]]+1,-1);
        }

        last[c[i]] = i;
        update(i+1, 1);

        while(counter < q && queries[counter].r == i){
            ans[queries[counter].idx] = solve(queries[counter].r+1)-solve(queries[counter].l);
            counter++;
        }
    }

    for (int i = 0; i < q; i++){
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 17428
object Main extends App{
    var n = scala.io.StdIn.readInt
    n.toString.last match{
      case '2'|'4'|'5'|'7'|'9' => printf("hon")
      case '0'|'1'|'6'|'8' =>printf("pon")
      case '3'=>printf("bon")
    }
  }


Measured memory_bytes: 54500
/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
lint gcd(lint a, lint b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
lint lcm(lint a, lint b) { return a * b / my::gcd(a, b); }
}  // namespace my
/*                    */

int main() {
  string s;
  cin >> s;
  if (s == "ABC")
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
}

Measured memory_bytes: 3628
/*
                            Author: Ankit Kaul
*******Code Belongs to Respective Author Only*************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
/*freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
        {   if(n % 2 ==1)
            result=(result * x)%M;
            x=(x*x)%M;
            n=n/2;
        }
    return result%M;
}
bool isPrime(int n)
    {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
    }
int inv(int a,int m)
{   return power(a,m-2);
}   
int lcm(int a,int b)
{   return a*b/(gcd(a,b));
}
signed main()
{   jaldi
    string str;
    cin>>str;
    if(str[0]=='R' && str[1]=='R' && str[2]=='R')
    cout<<3<<endl;
    else if(str[0]=='R' && str[1]=='R')
    cout<<2<<endl;
    else if(str[1]=='R' && str[2]=='R')
    cout<<2<<endl;
    else if(str[0]=='R' || str[2]=='R' || str[1]=='R')
    cout<<1<<endl;
    else
    cout<<0<<endl;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size())cout << a[i] << " ";cout << "\n"
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; 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 nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M;
    cin >> N >> M;
    cout << (N == M ? "Yes":"No") << endl;
}

Measured memory_bytes: 3700
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long a, b, c, d, e, f, g, h, i;
    scan(a, b, c);
    scan(d, e, f);
    scan(g, h, i);
    bool x = a - b == d - e;
    x = x && d - e == g - h;
    x = x && b - c == e - f;
    x = x && e - f == h - i;
    x = x && a - d == b - e;
    x = x && b - e == c - f;
    x = x && d - g == e - h;
    x = x && e - h == f - i;
    writeln(x ? "Yes" : "No");
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0,f=1;char c;
	while((c=tc())<'0'||c>'9')c=='-'?f=-1:0;
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a*f;
}
int n,a[1003],pos1[1003],pos2[1003],tot1,tot2,mx=-1e9,p,m;
long long sum1,sum2;
int main(void){
	register int i,times;
	n=read();
	for(i=1;i<=n;++i){
		a[i]=read();if(a[i]>mx)mx=a[i],p=i;
		if(a[i]>0){
			if(i&1)pos1[++tot1]=i,sum1+=a[i];
			else pos2[++tot2]=i,sum2+=a[i];
		}
	}
	if(sum1==0&&sum2==0){
		printf("%d\n",mx);
		printf("%d\n",n-1);
		for(i=1;i<p;++i)printf("%d\n",1);
		for(i=p+1;i<=n;++i)printf("%d\n",n-i+2);
		return 0;
	}
	if(sum1>sum2){
		printf("%lld\n",sum1);
		for(i=1;i<=n-(pos1[tot1]);++i)++m;
		for(i=1;i<pos1[1];++i)++m;
		m+=(n-m)/2;
		printf("%d\n",m);
		for(i=1;i<=n-(pos1[tot1]);++i)printf("%d\n",n-i+1);
		for(i=1;i<pos1[1];++i)printf("%d\n",1);
		for(i=tot1;i;--i)pos1[i]-=pos1[1]-1;
		for(i=2;i<=tot1;++i){
			times=(pos1[i]-pos1[i-1]>>1)-1;
			while(times)printf("%d\n",3),--times;
			printf("%d\n",2);
		}
	}else{
		printf("%lld\n",sum2);
		for(i=1;i<=n-(pos2[tot2]);++i)++m;
		for(i=1;i<pos2[1];++i)++m;
		m+=(n-m)/2;
		printf("%d\n",m);
		for(i=1;i<=n-(pos2[tot2]);++i)printf("%d\n",n-i+1);
		for(i=1;i<pos2[1];++i)printf("%d\n",1);
		for(i=tot2;i;--i)pos2[i]-=pos2[1]-1;
		for(i=2;i<=tot2;++i){
			times=(pos2[i]-pos2[i-1]>>1)-1;
			while(times)printf("%d\n",3),--times;
			printf("%d\n",2);
		}
	}
	return 0;
}

Measured memory_bytes: 128
import sys


def main():
    [n, s] = [x for x in sys.stdin]
    n = int(n)
    if n % 2 != 0:
        print("No")
        return

    half = int(n / 2)

    if s[0:half] == s[half:n]:
        print("Yes")
        return

    print("No")


main()


Measured memory_bytes: 2940
n = int(input())
l = list(input().split())
s = sum(int(i) for i in l)
m0 = 0
m1 = 0
c = 0
for i in l:
    m1 = m0
    m0 += int(i)
    if m0 * 2 == s:
        break
    elif m0 * 2 > s:
        c = min(m0 *2 -s, s - m1 * 2)
        break
        
print(c)

Measured memory_bytes: 20504
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]

c=sorted(c,key=lambda x:x[0])
ans=0
for i in range(a):
    if b==0:
        break
    elif b>=c[i][1]:
        b-=c[i][1]
        ans+=c[i][1]*c[i][0]
    else:
        ans+=b*c[i][0]
        break
print(ans)

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

template <typename T>
struct Matrix {
  vector<vector<T>> v;
  int r, c;
  Matrix(int r, int c, T d) : r(r), c(c) {
    v = vector<vector<T>>(r, vector<T>(c, d));
  }
  vector<T>& operator[](int x) {
    return v[x];
  }
};

template <typename T>
void warshall_floyd(Matrix<T> &m, T INF) {
  int n = m.r;
  rep(k, n) rep(i, n) rep(j, n) {
    if (m[i][k] == INF || m[k][j] == INF) continue;
    amin(m[i][j], m[i][k] + m[k][j]);
  }
}

void solve() {
  int V, E; cin >> V >> E;
  auto m = Matrix<i64>(V, V, 1e18);
  rep(i, V) m[i][i] = 0;
  rep(i, E) {
    int s, t, d; cin >> s >> t >> d;
    m[s][t] = d;
  }
  warshall_floyd(m, (i64) 1e18);
  rep(i, V) if (m[i][i] < 0) {
    cout << "NEGATIVE CYCLE" << '\n';
    return;
  }
  rep(i, V) {
    rep(j, V) {
      if (j) cout << " ";
      if (m[i][j] == 1e18) cout << "INF";
      else cout << m[i][j];
    }
    cout << '\n';
  }
}



Measured memory_bytes: 3304
<?php
  fscanf(STDIN,"%d %d", $N, $X);
  $array = explode(" ",trim(fgets(STDIN)));
  $D = 0;

 for($i = 0; $i < $N; $i++){
   $array[$i] = abs($array[$i] - $X);
 }
 
 for($i = 0; $i < $N-1; $i++){
   $array[0] = gcd($array[0], $array[$i+1]);
}

  echo $array[0];

function gcd($a, $b){
  if($b === 0) return $a;

  return gcd($b, $a%$b);
}
 ?>


Measured memory_bytes: 12792
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int ans = INF;

int main(void) {
    string S, T;
    cin >> S >> T;

    rep(i, 0, sz(S)-sz(T)+1) {
        int cnt = 0;
        rep(j, 0, sz(T)) {
            if (S[i+j]!=T[j]) cnt++;
        }
        ans = min(ans, cnt);
    }

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





Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PAIR pair<double, double>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
#define PI acos(-1)
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int N;
	cin >> N;
	vector<int> line(N+1);
	vector<int> pop(N+1);
	REPA(i, N+1){
		cin >> line[i];
		pop[line[i]] = i;
	}
	set<int> m;
	m.insert(-1);
	m.insert(-1);
	m.insert(N+1);
	m.insert(N+2);
	LL ans = 0;
	for(int i=N;i;--i){
		auto p = m.lower_bound(pop[i]);
		LL a = *p;
		++p;
		LL b = *p;
		--p;
		--p;
		LL c = *p;
		--p;
		LL d = *p;
		if(a<=N){
			LL e = N - a + 1;;
			if(b<=N){
				e = b - a;
			}
			if(c>=1){
				ans += i * e * (pop[i] - c);
			}else{
				ans += i * e * pop[i];
			}
		}
		if(c>=1){
			LL e = c;
			if(d>=1){
				e = c - d;
			}
			if(a<=N){
				ans += i * e * (a - pop[i]);
			}else{
				ans += i * e * (N - pop[i] + 1);
			}
		}
		m.insert(pop[i]);
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 5760
from collections import deque,defaultdict
H,W = map(int,input().split())
s = [["#"]*(W+2)] + [list("#"+input()+"#") for _ in range(H)] + [["#"]*(W+2)]
Q = deque([(1,1,1)])
cnt = 0
for S in s[1:-1]:
    cnt += S.count(".")

while Q:
    x,y,d = Q.popleft()
    s[x][y] = "#"
    if x == H and y == W:
        route = d
        break
    for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
        if s[x+dx][y+dy] == ".":
            Q.append((x+dx,y+dy,d+1))
            s[x+dx][y+dy] = "#"
else:
    print(-1)
    exit()

print(cnt-route)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 1000000007 
#define mx 300000

long long mini[2][mx * 4], n, q, a[mx], lazy[2][mx * 4];

void build(int t, int idx, int l, int r){
	mini[t][idx] = 1e18;
	if(l == r)
		return;
	int mid = (l + r) >> 1;
	build(t, 2 * idx, l, mid);
	build(t, 2 * idx + 1, mid + 1, r);
	mini[t][idx] = min(mini[t][idx * 2], mini[t][idx * 2 + 1]);
}

long long cari(int t, int idx, int l, int r, int fl, int fr){
	if(fl > r || fr < l)
		return 1e18;
	if(fl <= l && r <= fr)
		return mini[t][idx];
	int mid = (l + r) >> 1;
	if(lazy[t][idx] != 0){
		mini[t][idx * 2] += lazy[t][idx];
		mini[t][idx * 2 + 1] += lazy[t][idx];
		lazy[t][idx * 2] += lazy[t][idx];
		lazy[t][idx * 2 + 1] += lazy[t][idx];
		lazy[t][idx] = 0;
	}
	return min(cari(t, idx * 2, l, mid, fl, fr), cari(t, idx * 2 + 1, mid + 1, r, fl, fr));
}

void upd(int t, int idx, int l, int r, int in, long long val){
	if(in > r || in < l)
		return;
	if(l == r){
		mini[t][idx] = val;
		return;
	}
	int mid = (l + r) >> 1;
	if(lazy[t][idx] != 0){
		mini[t][idx * 2] += lazy[t][idx];
		mini[t][idx * 2 + 1] += lazy[t][idx];
		lazy[t][idx * 2] += lazy[t][idx];
		lazy[t][idx * 2 + 1] += lazy[t][idx];
		lazy[t][idx] = 0;
	}
	upd(t, 2 * idx, l, mid, in, val);
	upd(t, 2 * idx + 1, mid + 1, r, in, val);
	mini[t][idx] = min(mini[t][idx * 2], mini[t][idx * 2 + 1]);
}

vector<pair<int, int>> ve;

void update(int idx, long long val){
	int in = lower_bound(ALL(ve), make_pair((int)a[idx], (int)idx)) - ve.begin() + 1;
	upd(0, 1, 1, n, in, val - a[idx]);
	upd(1, 1, 1, n, in, val + a[idx]);
}

int main(){
	cin >> n >> n >> a[1] >> a[2];
	build(0, 1, 1, n + 2);
	build(1, 1, 1, n + 2);
	for(int i = 1; i <= n; i++)
		cin >> a[i + 2];
	for(int i = 1; i <= n + 2; i++)
		ve.pb({a[i], i});
	n += 2;
	sort(ALL(ve));
	int satu = abs(a[2] - a[3]);
	int dua = abs(a[1] - a[3]);
	update(1, satu);
	update(2, dua);
	// debug(n);
	for(int i = 4; i <= n; i++){
		int in = lower_bound(ALL(ve), make_pair((int)a[i], (int)i)) - ve.begin() + 1;
		long long sa = cari(0, 1, 1, n, 1, in) + a[i];
		long long du = cari(1, 1, 1, n, in, n) - a[i];
		long long tambah = abs(a[i] - a[i - 1]);
		lazy[0][1] += tambah;
		mini[0][1] += tambah;
		lazy[1][1] += tambah;
		mini[1][1] += tambah;
		update(i - 1, min(sa, du));
	}
	long long jaw = 1e18;
	for(int i = 1; i < n; i++){
		int in = lower_bound(ALL(ve), make_pair((int)a[i], (int)i)) - ve.begin() + 1;
		jaw = min(jaw, cari(0, 1, 1, n, in, in) + a[i]);
		jaw = min(jaw, cari(1, 1, 1, n, in, in) - a[i]);
	}
	cout << jaw << endl;
}

Measured memory_bytes: 28528
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    string s;
    cin>>s;
    n = sz(s);

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

        ans += s[i] - '0';
    }  

    cout<<(ans%9 == 0 ? "Yes" : "No");
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


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

#define ll long long

string s;
int n;
int main()
{
	cin>>s;
	n=s.length();
	cout<<2018;
	for(int i=4;i<n;i++) cout<<s[i];
	cout<<endl;
	return 0;	
}

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

int main(int argc, char** argv)
{
  int a, b;

  while (1) {
    if (fscanf(stdin, "%d %d", &a, &b) != 2)
      break;

    fprintf(stdout, "%d\n", int(log10(a + b)) + 1);
  }
}

Measured memory_bytes: 0