akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

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

  string res = "";
  for (int i = 0; i < n; i++) {
    if (s[i] != s[k]) {
      res += '*';
    } else {
      res += s[i];
    }
  }
  cout << res << endl;
  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    string ss,ss1;
    cin>>ss>>ss1;
    for(int i=0;i<n;i++)
    {
        cout<<ss[i]<<ss1[i];
    }



    return 0;
}


Measured memory_bytes: 256
/*
https://t.me/unstoppabIesoIvemachinechannel
*/
#pragma ARCENIY_KIRILLOV_POVELITEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;










ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}




signed main(){
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    map<ll,int> fl;
    for (ll j = 2; j * j <= g; j++){
        if (g % j == 0){
            g /= j;
            fl[j]++;
            j--;
        }
    }
    fl[g]++;
    fl[1]++;
    cout << fl.size();


}


Measured memory_bytes: 256
import itertools
def main():
    n,m,x = map(int, input().split())
    c = [list(map(int, input().split())) for _ in range(n)]
    # c = sorted(c, key=lambda x:sum(x[1:])/x[0], reverse=True)
    ans = 10**9
    possible = False

    for i in range(1, n+1):
        for j in itertools.combinations(c,i):
            rikaido = [0]*m
            kingaku = 0
            for k in j:
                kingaku += k[0]
                for num, val in enumerate(k[1:]):
                    rikaido[num] += val

            if min(rikaido) >= x:
                ans = min(ans, kingaku)
    print(-1) if ans == 10**9 else print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9248
/*Unlucky_Glass*/
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=2e3,inf=(1<<29);

int n;
int siz[N+3],mx[N+3],mn[N+3];
char gnu[N+3];
vector<int> lnk[N+3];

void DFS(int u,int fa){
	siz[u]=mx[u]=mn[u]=0;
	for(auto v : lnk[u]){
		if(v==fa) continue;
		DFS(v,u);
		mx[v]+=siz[v];mn[v]+=siz[v];
		siz[u]+=siz[v];
		if(max(mn[u],mn[v])<=min(mx[u],mx[v])) mn[u]=((mn[u]&1)^(mn[v]&1));
		else mn[u]=max(mn[u],mn[v])-min(mx[u],mx[v]);
		mx[u]+=mx[v];
	}
	if(gnu[u]=='1') siz[u]++;
}
int main(){
	scanf("%d%s",&n,gnu+1);
	for(int i=1;i<n;i++){
		int u,v;scanf("%d%d",&u,&v);
		lnk[u].push_back(v);
		lnk[v].push_back(u);
	}
	int ans=inf;
	for(int i=1;i<=n;i++){
		DFS(i,0);
		if(!mn[i]) ans=min(ans,mx[i]/2);
	}
	if(ans==inf) printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    //後ろから解くかわりに全ての文字列を反転する
    reverse(S.begin(), S.end());
    for(int i = 0; i < 4; i++) {
        reverse(divide[i].begin(), divide[i].end());
    }

    //端から切っていく
    bool can = true;
    for(int i = 0; i < S.size();) {
        bool can2 = false;
        for(int j = 0; j < 4; j++) {
            string d = divide[j];
            if(S.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }
        if(!can2) {
            can = false;
            break;
        }
    }

    if(can) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#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 srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(kbrni,n)cout<<" "<<a[kbrni];cout<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define svecp(v) cout<<#v<<":";each(kbrni,v)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

map<ll,ll> mp2[15][130][3];

void solve(int& sm,ll& mul,string& s)
{
    sm = 0,mul = 1;
    rep(i,len(s)){
        sm += (s[i]-'0');
        mul *= (s[i]-'0')+1;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int keta = len(s);
    int sm;
    ll mul;
    solve(sm,mul,s);
    mp2[0][0][0][1] = 1;
    rep(i,keta){
        rep(j,sm+1){
            each(it,mp2[i][j][0]){
                rep(k,min(sm+1-j,10)){
                    if(k < s[i]-'0'){
                        mp2[i+1][j+k][1][it.fi*(k+1)] += it.se;
                    }else if(k == s[i]-'0'){
                        mp2[i+1][j+k][0][it.fi*(k+1)] += it.se;
                    }else{
                        mp2[i+1][j+k][2][it.fi*(k+1)] += it.se;
                    }
                }
            }
            srep(k,1,3){
                each(it,mp2[i][j][k]){
                    rep(l,min(sm+1-j,10)){
                        mp2[i+1][j+l][k][it.fi*(l+1)] += it.se;
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(i,sm){
        rep(j,3){
            each(it,mp2[keta][i][j]){
                ans += it.se;
            }
        }
    }
    rep(i,3){
        each(it,mp2[keta][sm][i]){
            if(it.fi >= mul){
                break;
            }
            ans += it.se;
        }
    }
    ans += mp2[keta][sm][1][mul];
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 55576
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
const int mod=1e9+9;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define si(a) a.size()
#define pii pair<int,int>
using namespace std;
//#if !defined(ONLINE_JUDGE)
//#include "debugging.h"
//#endif
void fail(){cout<<"IMPOSSIBLE\n";exit(0);}

int32_t main() {
   std::ios::sync_with_stdio(false);cin.tie(NULL);
   int n,cnt=0;
   cin>>n;
   int a[n+1];
   for(int i=1;i<=n;i++)
   {
    cin>>a[i];
    cnt+=(a[i]!=i);
   }
   if(cnt>2)cout<<"NO";
   else cout<<"YES";
   return 0;
}


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

typedef long long ll;
using namespace std;

int main() {
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();

    int front = 0;
    while (front < n && s[front] == s[n - 1])front++;
    int back = 0;
    while (n - 1 - back >= 0 && s[0] == s[n - 1 - back])back++;
    ll len = front + back;

    if (len == n * 2) {
        k *= n;
        cout << k / 2 << endl;
    } else {
        int now = 1;
        ll inside = 0;
        for (int i = front + 1; i < n - back; i++) {
            if (s[i] == s[i - 1])now++;
            else {
                inside += now / 2;
                now = 1;
            }
        }
        inside += now / 2;

        cout << inside * k + front / 2 + back / 2 + len / 2 * (k - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
A1, A2, A3 = map(int, input().split())

costs = []
costs.append(abs(A1-A2) + abs(A2-A3))
costs.append(abs(A1-A3) + abs(A3-A2))
costs.append(abs(A2-A1) + abs(A1-A3))
costs.append(abs(A2-A3) + abs(A3-A1))
costs.append(abs(A3-A1) + abs(A1-A2))
costs.append(abs(A3-A2) + abs(A2-A1))

print(min(costs))

Measured memory_bytes: 3064
using System;
using System.Linq;
public class c
{
  public static void Main()
  {
    int[] NMC=Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); 
    int[] B=Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); 
    int ans=0;
    int sum=0;
    for(int i=0;i<NMC[0];i++)
    {
      int[] A=Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      for(int j=0;j<NMC[1];j++)
      {
        sum+=A[j]*B[j];
      }
      sum+=NMC[2];
      if(sum>0)ans++;
      sum=0;
    }
    Console.WriteLine(ans);
  }
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N),F(N);
  for(ll i = 0; i < N; i++) cin>>A[i];
  for(ll i = 0; i < N; i++) cin>>F[i];
  sort(A.begin(),A.end());
  sort(F.begin(),F.end());
  reverse(F.begin(),F.end());
  ll M=0,m=-1;
  vector<ll> T(N);
  for(ll i = 0; i < N; i++){
    ll t = A[i]*F[i];
    T[i]=t;
    chmax(M,t);
  }
  while(M-m>1){
    ll mid = (M+m)/2;
    ll cnt = 0;
    for(ll i = 0; i < N; i++){
      if(mid<T[i]){
        cnt+=(T[i]-mid-1)/F[i]+1;
      }
    }
    if(cnt>K)m=mid;
    if(cnt<=K)M=mid;
  }
  cout<<M<<endl;
}

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

int swapCount;

// N 個の要素を含む 0-オリジンの配列 A
void bubbleSort(int a[], int n){
    bool flag = true;  // 逆の隣接要素が存在する
    while(flag){
        flag = false;
        for(int j=n-1; j>0; j--){
            if(a[j] < a[j-1]){
                swap(a[j], a[j-1]);
                swapCount++;
                flag = true;
            }
        }
    }
}

void print(int a[], int n){
    for(int i=0; i<n-1; i++){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
}

int main(void){
    int n;
    cin >> n;
    int a[110];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    swapCount = 0;
    bubbleSort(a, n);

    print(a, n);

    cout << swapCount << endl;
    return 0;
}


Measured memory_bytes: 3112
n=int(input())
a=list(map(int,input().split()))
MOD=10**9+7
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
from collections import defaultdict
d=defaultdict(int)
for i in a:
    s=factorization(i)
    for x,y in s:
        if d[x]<y:
            d[x]=y
lcm=1
for val in d:
    #print(d[val],val,d[val]*val)
    lcm=lcm*pow(val,d[val],MOD)
    lcm%=MOD
#print(lcm)
#print(d)
count=0
for val in a:
    y=modinv(val,MOD)
    x=lcm*y
    #print((y*val)%MOD)
    x%=MOD
    #print(x,count)
    count+=x
    count%=MOD
print(count)


Measured memory_bytes: 46940
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b,i,j;
    cin>>a;
    int jump[a];
    for(i=0;i<a;i++){
        cin>>b;
        jump[i]=b/10;
    }
    int c=0;
    for(i=0;i<a;i++){
        c++;
        if(jump[i]<c)
        continue;
        else
        c=0;
    }
    if(c==0){
        for(i=a-1;0<=i;i--){
            c++;
        if(jump[i]<c)
        continue;
        else
        c=0;
    }
    }
    if(c)
    cout<<"no"<<endl;
    else
    cout<<"yes"<<endl;
    
}



Measured memory_bytes: 4276
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL L, N;
std::vector<std::pair<std::pair<LL, LL>, LL>>paths;

int main()
{
	in >> L;
	LL temp = L;
	while (temp > 0)
	{
		temp /= 2;
		++N;
	}
	rep(i, N - 1)
	{
		paths.push_back(std::make_pair(std::make_pair(i + 1, i + 2), 0));
		paths.push_back(std::make_pair(std::make_pair(i + 1, i + 2), (1LL << i)));
	}
	for (LL r = N - 1; r >= 1; --r)
	{
		if ((1LL << (N - 1)) + (1LL << (r - 1)) <= L)
		{
			paths.push_back(std::make_pair(std::make_pair(r, N), L - (1LL << (r - 1))));
			L -= (1LL << (r - 1));
		}
	}
	out << N << " " << paths.size() << std::endl;
	for (auto path : paths) out << path.first.first << " " << path.first.second << " " << path.second << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl
#define all(x) x.begin(), x.end()
#define endl "\n"

const int M = 998244353, N = 2e5 + 3;
vll fact(N), inv_fact(N);

ll bpow(int base, int exp)
{
    if (exp == 0)
        return 1ll;
    ll ans = bpow(base, exp / 2);
    ans = (ans * ans) % M;
    if (exp % 2)
        ans = (ans * base) % M;
    return ans;
}
void pre()
{
    fact[0] = 1;
    for (int i = 1; i < N; i++)
        fact[i] = (fact[i - 1] * i) % M;
    inv_fact[N-1] = bpow(fact[N-1],M-2);
    for(int i=N-2;i>=0;i--)
    {
        inv_fact[i] = ((i+1)*inv_fact[i+1])%M;
    }
}
inline ll ncr(int n, int r)
{
    return (((inv_fact[r]*inv_fact[n-r])%M)*fact[n])%M;
}
void print(vll v,int n)
{
    cout<<"DEBUG\n";
    for(int i=0;i<n;i++)
        cout<<v[i]<<" ";
    cout<<endl;
}

void solve()
{
    pre();
    int n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    for(int i=0;i<=k;i++)
    {
        ll a = ncr(n-1,i);
        ll b = bpow(m-1,n-1-i);
        ll t = (a*b)%M;
        //vll temp = {a,b,t};
        //print(temp,temp.size());
        ans = (ans + (m*t)%M)%M;
    }
    cout<<ans<<endl;
}

int main()
{
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 6204
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define all(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x,y)* mod_pow(kai(y,y), mod - 2, mod) % mod;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(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)];
	}
};
signed main(){
	int n;
	string s;
	cin >> n;
	cin >> s;
	int ans = 0;
	for (int i = 2; i < s.size(); ++i) {
		if (s[i - 2] == 'A' && s[i - 1] == 'B' && s[i] == 'C')ans++;
	}
	cout << ans << endl;
}


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

int main() {
  string str1, str2;
  cin >> str1;
  if (str1.at(str1.size()-1) == 's') {
    str2 = "es";
  }
  else {
    str2 = "s";
  }

  cout << str1 << str2 << endl;
}


Measured memory_bytes: 3628
module Main where
    import Debug.Trace
    import Data.List
    import qualified Data.Sequence as S
    import qualified Data.ByteString.Char8 as B
    import Data.Int
    import Data.Char
    import Data.Array
    import Data.Maybe
    import qualified Data.Map as M
    import Data.Ord
    import Data.Functor
    import Control.Applicative
    import Control.Monad
    
    solve :: Int -> Int -> [Int] -> Int
    solve n k wl = iter 0 (div (n * maximum wl) k +1) where
        iter failed successful
            | failed +1 == successful = successful
            | loadable p k wl = iter failed p
            | otherwise       = iter p successful where
                p = div (failed+successful) 2 

    loadable :: Int -> Int -> [Int] -> Bool
    loadable p k = iter 1 0 where -- 1st arg : number of tracks, 2nd arg : loaded weight 
        iter t _ [] = t <= k
        iter t l (w:ws)
            | t > k = False
            | w > p = False
            | lw <= p = iter t lw ws
            | otherwise = iter (t+1) w ws where
                lw = l+w

    readIntLn:: IO Int
    readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

    readIntList:: IO [Int]
    readIntList = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
       
    readLines :: Int -> IO [Int]
    readLines n = replicateM n readIntLn
                
    main :: IO() 
    main = do
        [n, k] <- readIntList :: IO [Int]
        wl <- readLines n
        print $ solve n k wl

    


Measured memory_bytes: 42500
#include <iostream>
#include <unordered_set>
using namespace std;
int main() {
    string text;
    cin>>text;
    unordered_set<char> us;
    for(int i=0; i<text.size(); i++){
        us.insert(text[i]);
    }
    cout << ((us.size()==2) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define F first
#define S second
int n,ans;
ll s;
map<ll,int> m;
int main(void){
    scanf("%d",&n);
    m.insert(P(ll(0),0));
    for(int i=1;i<=n;i++){
        ll a;
        scanf("%lld",&a);
        s+=a;
        if(m.find(s)==m.end())m.insert(P(s,i));
        else ans=max(ans,i-m[s]);
        
    }
    printf("%d\n",ans);
}



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

using namespace std;

typedef long long LL;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define fin "\n"


#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

template <typename T>
inline void chmin(T &l,T r){l=min(l,r);}

template <typename T>
inline void chmax(T &l,T r){l=max(l,r);}

template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

int main(){
    int N;
    cin>>N;
    map<int,int> cnt;
    REP(i,N){
        int a;cin>>a;cnt[a]++;
    }
    int del=0;
    for(auto &it:cnt){
        del+=it.second-1;
    }
    int res;
    if(del%2==0)res=N-del;
    else res=N-del-1;
    cout<<res<<endl;
}


Measured memory_bytes: 4992
S = input()
a, b = int(S[:2]), int(S[2:])

if 1 <= a <= 12 and 1 <= b <= 12:
    print("AMBIGUOUS")
elif 1 <= a <= 12:
    print("MMYY")
elif 1 <= b <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
// ABC121_C
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, M;
    cin >> N >> M;
    vector<ll> yen(N), maxdri(N);
    vector<pll> p(N);
    REP(i, N) {
        cin >> yen[i] >> maxdri[i];
        p[i] = make_pair(yen[i], maxdri[i]);
    }
    
    // calculation
    sort(p.begin(), p.end());
    
    ll res = 0, now = 0;  // now 本数
    REP(i, N) {
        if (now < M) {
            if ((M-now) <= p[i].S) {
                // 本数より小さい時
                res += (M-now)*p[i].F;
                break;
            } else {
                res += p[i].S * p[i].F;
                now += p[i].S;
            }
        } else {
            break;
        }
    }
    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 3328
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N;
ll K;
ll dp[3005][3005]={0};
vpii datas;
vector<ll> hoge;

map<ll,int> cnt;
ll score[214514];
int main(){
	cin>>N>>K;
	ll sum=0;
	ll ans=0;
	score[0]=0;
	cnt[(ll)0]++;
	rep(i,N){
		ll x;
		cin>>x;
		sum+=x;
		sum=(sum-1+K)%K;
		score[i+1]=sum;
		
		if((ll)i+1>=K)cnt[score[i+1-K]]--;
		cnt[sum]++;
		ll num=cnt[sum];
		ans+=num-1;

		//cout<<ans<<" ";
	}
	//cout<<endl;
	cout<<ans<<endl;
}



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

int main(){
    int N, K;
    cin >> N >> K;
    vector<ll> p(N);
    for(int i=0; i<N;i++){
        cin >> p[i];
    }

    double pex[N];
    for(int i=0; i<N; i++){
        pex[i] = (p[i]+1.0)/2;
    }

    double ans = 0;
    for(int i=0; i<K; i++){
        ans += pex[i];
    }

    double sum = ans;
    for(int i=1; i+K-1<N; i++){
        sum = sum-pex[i-1]+pex[i+K-1];
        ans = max(ans, sum);
    }

    printf("%.8lf\n", ans);

    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
typedef int LL;
const LL maxn=3e3+9,mod=998244353;
LL a,b,c,d;
LL f[maxn][maxn];
LL add(LL x,LL y){ return x+=y,x>=mod?x-mod:x; }
LL mul(LL x,LL y){ return 1ll*x*y%mod; }
LL dec(LL x,LL y){ return x-=y,x<0?x+mod:x; }
int main(){
	scanf("%d%d%d%d",&a,&b,&c,&d);
	f[a][b]=1;
	for(LL i=a;i<=c;++i){
		for(LL j=b;j<=d;++j){
			if(i==a && j==b) continue;
			if(i==a){
				f[i][j]=mul(f[i][j-1],i);
			}else if(j==b){
				f[i][j]=mul(f[i-1][j],j);
			}else{
				f[i][j]=add(mul(f[i-1][j],j),mul(f[i][j-1],i));
				f[i][j]=dec(f[i][j],mul(f[i-1][j-1],1ll*(i-1)*(j-1)%mod));
			}
		}
	}
	printf("%d\n",f[c][d]);
	return 0;
}

Measured memory_bytes: 39072
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)

int main(){
	int flg = 0;
	for(int i = 0; i < 28; i++){
		int tmp;
		scanf("%d",&tmp);
		flg = flg | 1<<tmp;
	}
	for(int i = 1; i < 31; i++){
		if(!(flg>>i & 1))printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define ll long long
#define one_peace ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int main()
{
    one_peace;
int a,b,i=1,sum=0,h;
cin>>a;
h=a;
while(a--){
cin>>b;
if(b!=i){sum++;}
else{i++;}
}
if(sum==h){cout<<-1;}
else{cout<<sum;}
    return 0;
}


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

using namespace std;

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

void solve() {
	
}

int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int arr[] = {a, b, c, d, e};
	for (int i = 0; i < 5; i++) {
		if (arr[i] == 0) cout << i + 1;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int N,Q;
int64 A[MAXN],sum[MAXN],b[MAXN];
pii Calc(int64 l,int64 r) {
	int a = lower_bound(A + 1,A + N + 1,l) - A;
	int b = upper_bound(A + 1,A + N + 1,r) - A - 1;
	return mp(a,b);
}
int64 Process(int64 x) {
	if(x >= A[N]) return sum[N];
	int64 L = 0,R = A[N];
	int p = lower_bound(A + 1,A + N + 1,x) - A;
	while(L < R) {
		int64 mid = (L + R + 1) >> 1;
		pii t = Calc(x - mid,x + mid);
		int rem = N - p + 1 - (t.se - p + 1);
		if(rem >= t.se - t.fi + 1) L = mid;
		else R = mid - 1;
	}
	pii t = Calc(x - L,x + L);
	int len = t.se - t.fi + 1;
	int64 res = b[N] - b[N - len];
	int q = N - len,h0 = t.fi - 1,h1 = t.se + 1;
	while(q >= h1) {
		res += A[q];--q;
		if(h1 > q && h0 < 1) break;
		int now;
		if(h1 > q) now = h0;
		else if(h0 < 1) now = h1;
		else {
			if(x - A[h0] <= A[h1] - x) now = h0;
			else now = h1;
		}
		if(now == h1) ++h1;
		if(now == h0) --h0;
	}
	res += sum[h0];
	return res;
}
void Solve() {
	read(N);read(Q);
	for(int i = 1 ; i <= N ; ++i) read(A[i]);
	for(int i = 1 ; i <= N ; ++i) {
		sum[i] = A[i];
		if(i >= 2) sum[i] += sum[i - 2];
		b[i] = A[i] + b[i - 1];
	}
	int64 x;
	for(int i = 1 ; i <= Q ; ++i) {
		read(x);
		out(Process(x));enter;
	}
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


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

const int nmax = 8;
vector<vector<bool>> graph(nmax, vector<bool>(nmax));

int dfs(int v, int n, vector<bool>visited) {

  bool all_visited = true;

  rep(i, n) {
    if (visited[i] == false) {
      all_visited = false;
    }
  }

  if (all_visited) {
    return 1;
  }

  int ret = 0;
  rep(i, n) {
    if(graph[v][i] == false) continue;
    if(visited[i]) continue;

    visited[i] = true;
    ret += dfs(i, n, visited);
    visited[i] = false;
  }

  return ret;
}

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

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    graph[a-1][b-1] = graph[b-1][a-1] = true;
  }

  vector<bool> visited(nmax, false);

  visited[0] = true;
  cout << dfs(0, n, visited) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n;
	cin >> n;
	int sum = 0;
	vector<int>h(n);
	repp(i, 0, n) {
		cin >> h[i];
		if (i) {
			if (h[i - 1] > h[i]) {
				sum += h[i - 1] - h[i];
			}
		}
	}
	sum += h[n - 1];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import sys;sys.setrecursionlimit(int(1e7))
from sys import stdin
from collections import deque
 
input = stdin.readline
N = int(input())
tree = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int,input().split())
    tree[a].append((b,c))
    tree[b].append((a,c))
 
Qn,K = map(int,input().split())
XY = [tuple(map(int,input().split())) for _ in range(Qn)]
 
depth = [None]*(N+1)
def DFS(v,p,d):
    depth[v] = d
    for e in tree[v]:
        if e[0] != p:
            DFS(e[0], v, d + e[1])
DFS(K,0,0)
 
for i in range(Qn):
    print(depth[XY[i][0]] + depth[XY[i][1]])

Measured memory_bytes: 145548
#include <iostream>
#include <vector>
#include <functional>
using namespace std;


// セグメントツリー
template<class Monoid> struct SegTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int SIZE_R;
    vector<Monoid> dat;
    
    SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, UNITY);
    }
    
    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k)
            dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* update a, a is 0-indexed */
    void update(int a, const Monoid &v) {
        int k = a + SIZE_R;
        dat[k] = v;
        while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* get [a, b), a and b are 0-indexed */
    Monoid get(int a, int b) {
        Monoid vleft = UNITY, vright = UNITY;
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = F(vleft, dat[left++]);
            if (right & 1) vright = F(dat[--right], vright);
        }                                                                                                              
        return F(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }
    
    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            cout << (*this)[i];
            if (i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};


long long GCD(long long a, long long b) {
    return b ? GCD(b, a%b) : a;
}


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

    // セグツリーの構築
    SegTree<long long> seg(N, [](long long a, long long b) {
            return GCD(a, b);
        },
        0);
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        seg.set(i, A[i]);
    }
    seg.build();

    // 求める
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        long long left = seg.get(0, i);
        long long right = seg.get(i+1, N);
        res = max(res, GCD(left, right));
    }
    cout << res << endl;
}


Measured memory_bytes: 3072
#include <stdio.h>
int main()
{
     int a,b;
     char op;
     while(1){
           scanf("%d %c %d",&a,&op,&b);
           if(op=='+'){
                  printf("%d\n",a+b);
           }else if(op=='-'){
                  printf("%d\n",a-b);
           }else if(op=='*'){
                  printf("%d\n",a*b);
           }else if(op=='/'){
                  printf("%d\n",a/b);
           }else if(op=='?'){
                  break;
           }
      }
      return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

ll cost(int i, int s, vector<ll> &A) {
    if (s == 0) return A[i];
    else if (s == 4) return A[i];
    else if (s == 1 || s == 3) {
        if (A[i] % 2 == 0 && A[i] > 0) return 0;
        else if (A[i] > 0) return 1;
        else return 2;
    } else {
        if (A[i] % 2 == 0) return 1;
        else return 0;
    }
}


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

    vector<ll> a(l);
    rep(i, l) cin >> a[i];
    vector<vector<ll>> dp(l + 1, vector<ll>(5, INF));
    dp[0][0] = 0;

    rep(i, l) {
        rep(j, 5) {
            for (int k = j; k < 5; k++) {
                cmin(dp[i + 1][k], dp[i][j] + cost(i, k, a));
            }
        }
    }

    ll ans = *min_element(dp[l].begin(), dp[l].end());
    cout << ans << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll cost[305][305], base[305][305];
int n;

void warshall_floyd(ll a[305][305]){
    rep(k, n){
        rep(i, n){
            rep(j, n) a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
        }
    }
}

ll count(ll a[305][305]){
    ll ret = 0;
    rep(i, n){
        rep(j, n){
            bool flag = 1;
            rep(k, n){
                if (i == j || k == i || k == j) continue;
                if (a[i][j] >= a[i][k] + a[k][j]) flag = 0;
            }
            if (flag) ret += a[i][j];
        }
    }
    return ret / 2;
}

int main(){
    cin >> n;
    rep(i, n) rep(j, n) cin >> cost[i][j], base[i][j] = cost[i][j];
    warshall_floyd(base);

    bool f = 0;
    rep(i, n) rep(j, n) if (cost[i][j] != base[i][j]) f = 1;

    if(f) {
        cout << -1 << endl;
        return 0;
    }

    cout << count(cost) << endl;

    return 0;
}


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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int N = max(B, D);
    bool alice = false, bob = false;
    int count = 0;

    for (int i = 0; i <= N; i++) {
        if (i == A) alice = true;
        if (i == C) bob = true;
        if (i == B) alice = false;
        if (i == D) bob = false;
        if (alice && bob) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;

int cnt_digits(ll N){
    int digits=0;

    while(N>0){
        N /= 10;
        digits++;
    }
    return digits;
}

int main(){
    ll c=0,d=0,k=0,n,m,h,w,p,q,ans=0;
    string s,s1,s2;
    cin >> n;
    ans = cnt_digits(n);

    for(ll a= (long long)1; a*a<=n; a++){
        if(n%a!=0) continue;
        const ll b = n/a;
        const int cur = max(cnt_digits(a), cnt_digits(b));
        if(ans > cur){
            ans=cur;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 100000000000;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif          // -D_DEBUG をつけて実行 cf)可変引数
 
// rep(i, 0, sz(v)) cout << v[i] << " \n"[i==sz(v)-1];
 
////////////////////////////////////////////////////////


int main() {
	string s, t; cin >> s >> t;
	ll fa = 100100100;
	rep(i, 0, sz(s)-sz(t)+1){
		ll ans = 0; 
		rep(j, 0, sz(t)){
			if(s[i+j] != t[j]) ans++;
		}
		chmin(fa, ans);
	}
	co(fa);

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

bool ok=true;
ll a[3];

void init(){
	rep(i,3)cin>>a[i];
	sort(a,a+3);
}

int main(void){
	init();
	if(a[0]==a[1] && a[1]!=a[2])ok=false;
	if(a[0]!=a[1] && a[1]==a[2])ok=false;
	cout<<(ok?"No":"Yes")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 1000000007
typedef long long ll;
#define all(v) (v).begin(),(v).end()
#define sz(x) int(x.size())
int main(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int ma=n-1;
	ll sum=0;
	rep(i,n-1){
		if(s[i]==s[i+1]){
			sum++;
		}
	}
	if((ma-sum)==1){
		sum++;
	}else{
		if(k*2>=(ma-sum)){
			sum=ma;
		}else{
			sum+=2*k;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str0;
    string str1;
    string p,alt,abb;
    cin>>str0;
    int q,a,b;
    cin>>q;
    for(int i=1;i<=q;i++){
        cin>>str1;
        if(str1=="print"){
            cin>>a>>b;
            cout<<str0.substr(a,b-a+1)<<endl;
        }
        else if(str1=="reverse"){
            cin>>a>>b;
            string rev;
            abb = str0.substr(0, a);
            alt = str0.substr(b + 1, str0.size() - 1);
             
            for(int i = b; i >= a; i--){
                rev += str0[i];
            }
            str0 = abb + rev + alt;
           
        }        
        else{
            cin>>a>>b;
            cin>>p;
            str0.replace(a,b-a+1,p);
            
        }
    }
    
    return 0;
}


Measured memory_bytes: 3196
// Nurbakyt Madibek
// Look at my code! IT'S AWESOME

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;

const int mod = (int)1e9 + 7;
const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-10;

const int MAX_N = (int)3e5 + 123;

int good[MAX_N];

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        good[a] ^= 1, good[b] ^= 1;
    }
    for (int i = 1; i <= n; i++) {
        if (good[i]) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


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

int main () {
  int H1,M1,H2,M2,K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int st, en;
  st = H1*60 + M1;
  en = H2*60 + M2;
  int d = en - st;
  cout << d-K << endl;
}

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

int main()
{
    vector<int> a(5);
    rep(i, 0, 5) cin >> a[i];
    int mn = 10;
    rep(i, 0, 5){
        if(a[i]%10 == 0) continue;
        mn = min(mn, a[i]%10);
    }
    int ans = 0;
    rep(i, 0, 5){
        if(a[i]%10 == 0) ans += a[i];
        else ans += 10*(a[i]/10 + 1);
    }
    cout << ans - 10 + mn << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 205050

ll n;
ll p;
ll a[N];
ll c[4]={1,9,7,4};
main(){
    rep(i,4)a[i]=in();
    bool flag=true;
    rep(i,4){
        bool f=false;
        rep(j,4){
            if(c[i]==a[j]){
                f=true;
            }
        }
        if(!f)flag=false;
    }
    cout<<(flag?"YES":"NO");
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

typedef long long llong;

constexpr int kMod = 1e9 + 7;

std::ostream &Log() {
  std::cout << "I ";
  return std::cout;
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);

  std::vector<int> a(n);
  std::vector<int> b(m);
  std::set<int> sa, sb;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    sa.insert(a[i]);
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d", &b[i]);
    sb.insert(b[i]);
  }

  std::sort(a.begin(), a.end(), std::greater<int>{});
  std::sort(b.begin(), b.end(), std::greater<int>{});

  llong total = 1;

  if (a.size() != sa.size() || b.size() != sb.size()) {
    total = 0;
  } else {
    int ai = 0;
    int bi = 0;
    int nm = n * m;
    for (int x = nm; x >= 1; --x) {
      bool ina = sa.find(x) != sa.end();
      bool inb = sb.find(x) != sb.end();

      while (ai < n && a[ai] >= x) {
        ++ai;
      }
      while (bi < m && b[bi] >= x) {
        ++bi;
      }

      llong p;
      if (ina && inb) {
        p = 1;
      } else if (ina) {
        p = bi;
      } else if (inb) {
        p = ai;
      } else {
        p = llong(ai) * llong(bi) - (nm - x);
      }

      // Log() << x << " " << p << std::endl;
      total = (total * p % kMod) % kMod;
    }
  }

  std::cout << total << std::endl;
  return 0;
}

Measured memory_bytes: 760
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
    int N, ans = 0;
    cin >> N;
    int A[N], B[N], C[N];
    rep(i, N) cin >> A[i], A[i]--;
    rep(i, N) cin >> B[i];
    rep(i, N-1) cin >> C[i];
    rep(i, N) {
        ans += B[i];
        if (i != N - 1 && A[i] + 1 == A[i+1]) ans += C[A[i]];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256