akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define ll long long

vector<int> v[nn],c[nn];
int n;


#define pll pair<ll,ll>
#define mp make_pair

vector<pll> merge(vector<pll> a,vector<pll> b)
{
	vector<pll> tp;
	int i=0,j=0;
	while(i<a.size() or j<b.size())
	{
		if(i<a.size() and j<b.size() and a[i].first==b[j].first)
		{
			tp.push_back(min(a[i],b[j]));
			i++,j++;
		}
		else if(i<a.size() and (j>=b.size() or a[i].first<b[j].first) )
		{
			tp.push_back(a[i]);
			i++;
		}
		else
		{
			tp.push_back(b[j]);
			j++;
		}
	}

	if(tp.size()==0) return tp;
	vector<pll> cp;cp.push_back(tp[tp.size()-1]);
	for(int i=tp.size()-1;~i;i--)
	{
		if(tp[i].first==cp[cp.size()-1].first)
		{
			cp[cp.size()-1]=min(cp[cp.size()-1],tp[i]);
			continue;
		}
		if(tp[i].second<cp[cp.size()-1].second)
			cp.push_back(tp[i]);
		else if(tp[i].second==cp[cp.size()-1].second) cp[cp.size()-1]=max(cp[cp.size()-1],tp[i]);
	}
	reverse(cp.begin(),cp.end());
	return cp;
}
vector<pll> work(vector<pll> lc,vector<pll> rc,ll pr,ll pl,ll ce)
{
	vector<pll> tp;
	int i=lc.size()-1,j=rc.size()-1;
	ll es=1e15;ll ces=es;
	while( ~j)
	{
		ll x=rc[j].first-pr;
		
	//	if(ce) cout<<i<<" "<<j<<"\n";
		if(~i and rc[j].second+pl+pr<=lc[i].first)
		{
			es=min(es,lc[i].second+pl);
			i--;
		}
		else
		{
			if(es<1e15 ) tp.push_back(mp(x,es));// ensure complexity
			j--;ces=es;
		}
		
	}
	reverse(tp.begin(),tp.end());
//	sort(tp.begin(),tp.end());
	if(tp.size()==0) return tp;
	vector<pll> cp;cp.push_back(tp[tp.size()-1]);
	for(int i=tp.size()-1;~i;i--)
	{
		if(tp[i].first==cp[cp.size()-1].first)
		{
			cp[cp.size()-1]=min(cp[cp.size()-1],tp[i]);
			continue;
		}
		if(tp[i].second<cp[cp.size()-1].second)
			cp.push_back(tp[i]);
		else if(tp[i].second==cp[cp.size()-1].second) cp[cp.size()-1]=max(cp[cp.size()-1],tp[i]);
	}
	reverse(cp.begin(),cp.end());
	return cp;
}


ll lim;
vector<pll> dfs(int x)
{
	vector<pll>tp;//now i mean   howmuch can be up & mini out
	if(v[x].size()==0)
	{
		tp.push_back(mp(lim,0));
	}
	else
	{
		vector<pll> lc,rc;
		assert(v[x].size()==2);
		ll pl=c[x][0],pr=c[x][1];
		lc=dfs(v[x][0]),rc=dfs(v[x][1]);
		vector<pll> fl,fr;
		int ce=0;
		if(x==1) ce=1;//spjajjjjjjjjjjjj
		fl=work(lc,rc,pr,pl,ce);
		fr=work(rc,lc,pl,pr,ce);
	
		tp=merge(fl,fr);
	}
	
//	for(int i=1;i<tp.size();i++) assert(tp[i].first>tp[i-1].first),assert(tp[i].second>tp[i-1].second);
//	cout<<x<<":\n";
//	for(int i=0;i<tp.size();i++) cout<<tp[i].first<<"  "<<tp[i].second<<"\n";
//	system("pause");
	return tp;
}

int check(ll mid)
{
	lim=mid;
	vector<pll> tp=dfs(1);
	for(int i=0;i<tp.size();i++)
		return 1;
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		int p,w;scanf("%d%d",&p,&w);
		v[p].push_back(i);c[p].push_back(w);
	}
	ll l=0,r=1e12;ll ans=-1;
	while(l<=r)
	{
		ll mid=(l+r)/2;
		if(check(mid))
			r=mid-1,ans=mid;
		else l=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 49408
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define M 1000000007
typedef long long int ll;

int main()
{
    int n,i;
    cin>>n;
    ll h[n];
    for(i=0;i<n;i++)
    {
        cin>>h[i];
    }
    if(n==2)
    {
        cout<<h[1]-h[0];
    }
    else
    {
    ll dp[n+1];
    memset(dp,1e9+7,sizeof(dp));
    dp[1]=0;
    dp[2]=abs(h[1]-h[0]);
    dp[3]=abs(h[2]-h[0]);
    for(i=2;i<=n;i++)
    {
        if(i+1<=n)
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i-1]));
        if(i+2<=n)
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i-1]-h[i+1]));
    }

    cout<<dp[n];
    }

}


Measured memory_bytes: 1792
n = int(input())
p = list(map(int, input().split()))
ans = 0

for i in range(1, n-1):
  li = [p[i-1],p[i],p[i+1]]
  if (not p[i] == max(li)) and (not p[i] == min(li)):
    ans += 1
    
print(ans)

Measured memory_bytes: 38384
#include <stdio.h>
#include <string.h>
int main()
{
    char s[10],t[10],u[10];
    int a,b,i,j,k;
    scanf("%s %s",s,t);
    scanf("%d %d",&a,&b);
    scanf("%s",u);
    if(strcmp(s,u)==0)
        a=a-1;
    else if(strcmp(t,u)==0)
        b=b-1;
    printf("%d %d",a,b);
    return 0;
} 

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	long long N, M;
	cin >> N >> M;

	long long ans = pow((long long)2, min((long long)5, M)) * (100 * (N - M) + 1900 * M);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3980
#include<stdio.h>
#include<math.h>
int main(){

  int i,n,score[1001],sum;
  double ave,sig,v;

  
  while(1){

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

    sum = 0;
    
    for ( i = 0 ; i < n ; i++ ){
      sum = sum + score[i];
    }
    
    ave = 1.0 * sum / n;

    sig = 0;
    
    for ( i = 0 ; i < n ; i++ ){
      sig = sig + ( score[i] - ave ) * ( score[i] - ave );
    }

    v = sqrt( sig / n );

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

  }
  
  return 0;
    
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}



int main(){
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> x;
    x.pb(a);x.pb(b);x.pb(c);
    sort(x);
    int p,q;
    int ans=0;
    p=(x[2]-x[0])%2;
    q=(x[2]-x[1])%2;
    if(p==1&&q==1){
        ans++;
        x[0]++;
        x[1]++;
    }else if(p==0&&q==1){
        ans++;
        x[0]++;
        x[2]++;
    }else if(p==1&&q==0){
        ans++;
        x[1]++;
        x[2]++;
    }
    sort(x);
    ans+=(x[2]-x[0]+x[2]-x[1])/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

const int INF = 1000000000;
int main() {
    int n,k;
    cin >> n >> k;
    vector<int>h(n);
    rep(i,n) {
        cin >> h[i];
    }
    vector<int>dp(n,INF);
    dp[0] = 0;
    rep(i,n) {
        for(int j = 1;j<=k;j++) {
            if(i+j>n-1) continue;
            chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout << dp[n-1] << endl;
}    

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll now = 0;
    ll res = 0;
    rep(i, N) {
        if (now >= A[i]) {
            res += now - A[i];
        } else {
            now = A[i];
        }
        // cout << now << " ";
    }
    // cout << endl;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 4752
#include <stdio.h>
 
int main() {
 
  int m, f, r;
  int x;
  while(1) {
 
    scanf("%d %d %d", &m , &f , &r);
    x = m + f;
    if(m == -1 && f ==-1 && r == -1) {
      break;
    }
 
    if(m == -1 || f == -1) {
      printf("F\n");
    } else if(x >= 80) {
      printf("A\n");
    } else if (x >= 65) {
      printf("B\n");
    } else if(x >= 50) {
      printf("C\n");
    } else if ( x >=30) {
      if(r >= 50) {
    printf("C\n");
      } else {
    printf("D\n");
      }
    } else if (x < 30) {
      printf("F\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2052
n, m = map(int, input().split())
cards = [[1, int(i)] for i in input().split()]
bc = [list(map(int, input().split())) for _ in range(m)]
cards += bc
cards.sort(key = lambda x: x[1], reverse = True)

l = []
flag = 0
for i in cards:
    for j in range(i[0]):
        l.append(i[1])
        if len(l) == n:
            flag = 1
            break
    if flag:
        break

print(sum(l))

Measured memory_bytes: 45432
r, c = map(int, input().split())
a = [[0 for i in range(c+1)] for j in range(r+1)]

###### 入力データの代入 ######
for i in range(r):
    for j, x in enumerate(input().split()):
        a[i][j] = int(x)

###### 各行の合計を求める ######
for i, line in enumerate(a):
    a[i][c] = sum(line)

###### 行と列を入れ替える ######
a = list(zip(*a))

###### 各列の合計を求める ######
for i, line in enumerate(a):
    a[i] = list(line)
    a[i][r] = sum(a[i])

###### 行と列を入れ替える ######
a = list(zip(*a))

for line in a:
    for i, x in enumerate(line):
        if i == c:
            print(x)
        else:
            print(x, end=" ")



Measured memory_bytes: 6216
def foo(xs):
    d = {}
    for x in xs:
        d[x] = d.get(x, 0) + 1
    
    count = 0
    for k, v in d.items():
        if k > v:
            count += v
        elif k < v:
            count += (v - k)
        elif k == v:
            pass
        else:
            pass
    return count



if __name__ == "__main__":
    n = input()
    xs = map(int, input().split())
    print(foo(xs))


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

#define int long long

#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))
#define upp(a,b) upper_bound(all(a),(b))
#define fill(i,n) memset(i,n,sizeof(i)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N,ans=INF;
int solve(int a){
    int res=0;
    while(a){
        res+=a%10;
        a/=10;
    }
    return res;
}

signed main() {
    IOS();
    /*シフト演算は(1ll<<x)*/
    
    cin>>N;
    rep(i,1,N){
        int a=i;
        int b=N-i;
        chmin(ans,solve(a)+solve(b));
    }
    
cout<<ans<<endl;    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
S = input()
N = int(input())
rev_flg=False
head = []
tail = []
for i in range(N):
	Q = input().split()
	if Q[0] == "1":
		if not rev_flg:
			rev_flg = True
		else:
			rev_flg = False
	elif Q[0] == "2":
		if Q[1] == "1":
			if not rev_flg:
				head.append(Q[2])
			else:
				tail.append(Q[2])
		if Q[1] == "2":
			if not rev_flg:
				tail.append(Q[2])
			else:
				head.append(Q[2])
S = "".join(head[::-1])+S+"".join(tail)
#print(head,tail)
#print(S)
if rev_flg:
	S =S[::-1]
print(S)

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

using namespace std;

int main(){

    string S;
    cin >> S;

    if(S == "Sunny") cout << "Cloudy" << endl;
    else if(S == "Cloudy") cout << "Rainy" << endl;
    else if(S == "Rainy") cout << "Sunny" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
using namespace std;
 
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
 
#define csh(a,n) memset(a,n,sizeof(a));
string arr[]={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main(){
	int n,m,t,a,b;
	string p;
	cin>>p;
	for(int i=0;i<7;i++){
		if(arr[i]==p){
			cout<<7-i;
			return 0;
		}
	}
	
}

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

int main(){
  int n,k,a[8888],dp[8888];

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

  int ans = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<=a[i]-i+1;j++)dp[j] = 1e8;
    for(int j=i;j<a[i];j++){
      if(a[i]<a[j])*lower_bound(dp,dp+a[i]-i+1,a[j]) = a[j];
    }
    int arg = lower_bound(dp,dp+a[i]-i+1,1e8) - dp;
    if(ans < arg){
      ans = arg;
      if(ans+1+k>=n/2){ printf("%d\n",n/2); return 0; }
    }
  }
  printf("%d\n",ans+1+k);
}

Measured memory_bytes: 1256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

string s, t;
int dp[3300][3300];
int main(){
    cin >> s >> t;
    int n = s.size(), m = t.size();

    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= m;j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i-1] == t[j-1]){
                dp[i][j] = max(dp[i-1][j-1] + 1, dp[i][j]);
            }
        }
    }

    string rewsna = "";

    while(n > 0 && m > 0){
        if(dp[n][m] == dp[n-1][m])n--;
        else if(dp[n][m] == dp[n][m-1])m--;
        else {
            rewsna += s[n-1];
            n--;
            m--;
        }
    }
    int l = rewsna.size();
    for(int i = 0;i < l;i++){
        cout << rewsna[l-i-1];
    }cout << endl;
    
    return 0;
}


Measured memory_bytes: 42328
#include<stdio.h>
int main(){
  int a,b,c,sum=0,day=0;
  scanf("%d%d%d",&a,&b,&c);
  while(sum<c){
    day++;
    if(day%7==0){
      sum+=b;
    }
    sum+=a;
  }
  printf("%d\n",day);
  return 0;
}


Measured memory_bytes: 2100
#include <stdio.h>

int main(void){
  int n, s[100000], q, t[50000], c;
  int left, right, mid, key;
  int i;

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

  c = 0;

  for (i = 0; i < q; i++) {
    key = t[i];
    left = 0;
    right = n;
    while (left < right) {
      mid = (left + right) / 2;
      if (s[mid] == key) {
        c++;
        break;
      }
      else if (key < s[mid]) {
        right = mid;
      }
      else {
        left = mid + 1;
      }
    }
  }

  printf("%d\n", c);

  return 0;
}


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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}


int main(){
ll H;
cin >> H;
ll ans = 1;
ll cnt = 1;
while(H > 0){
  if(H == 1)break;
  H /= 2;
  ans += cnt * 2;
  cnt *= 2;
}
print(ans);
}




Measured memory_bytes: 256
I=input
def f(x,y,r):
    if not(0<=x<len(r[0])and(0<=y<len(r)))or r[y][x]=='#':return 0
    r[y][x]='#'
    return 1+sum(f(x+dx,y+dy,r)for dx,dy in[[-1,0],[1,0],[0,-1],[0,1]])
while 1:
    w,h=map(int,I().split())
    if w==0:break
    r=[list(input()) for _ in[0]*h]
    for a,b in enumerate(r):
        if '@'in b:y=a;x=b.index('@');break
    print(f(x,y,r))

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

int main()
{
    long long N,A,B;
    while(cin>>N>>A>>B){
        if((N==1 && A!=B) || (A>B)){
            cout<<0<<endl;
        }
        else{
            long long Min=A*(N-1)+B;
            long long Max=A+B*(N-1);
            long long answer=Max-Min+1;
            cout<<answer<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,m,ans=0;
string s;
int main(){
  cin >> s >> m;
  for(int i=0;i<s.size();i++){
    if(m==i+1){
      cout << s[i] << endl;
      return 0;
    }
    if(s[i]!='1'){
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}  

Measured memory_bytes: 256
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int N = 1003;
const int MX = 5003;

vector<int> children[N];
int parent[N];

int X[N];

int findPrevious(const bitset<MX>& bs, int ind) {
  int res = -1;
  for (int i = 0 ; i <= ind; ++i) {
    if (bs[i]) {
      res = i;
    }
  }
  return res;
}

int getMin(const vector<pair<int, int>>& v, int x) {
  bitset<MX> bs;
  bs[0] = true;
  int sum = 0;
  for (auto& p : v) {
    bs = (bs << p.first) | (bs << p.second);
    sum += p.first + p.second;
  }
  int res = findPrevious(bs, x);
  if (res == -1) return res;

  return sum - res;
}

int getMin(int node) {
  vector<pair<int, int>> v;
  for (auto& child : children[node]) {
    v.emplace_back(X[child], getMin(child));
    if (v.back().second == -1) return -1;
  }
  int res = getMin(v , X[node]);
  return res;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n;
  cin >> n;

  for (int i = 2; i <= n; ++i) {
    cin >> parent[i];
    children[parent[i]].push_back(i);
  }

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

  int res = getMin(1);
  if (res != -1) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d;
    cin>>a>>b>>c>>d;

    long long aa=a*c;
    long long aaa=a*d;
    long long bb=b*c;
    long long bbb=b*d;
    long long maxx=max(aa,max(aaa,max(bb,bbb)));
    cout<<maxx<<endl;






    return 0;
}


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

int main(void) {
    int w, h, n;
    cin >> w >> h >> n;
    int x[n], y[n], a[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> a[i];
    }

    int board[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            board[i][j] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        switch (a[i]) {
            case 1:
                for (int j = 0; j < h; j++) {
                    for (int k = 0; k < x[i]; k++) {
                        board[j][k] = 0;
                    }
                }
                break;
            case 2:
                for (int j = 0; j < h; j++) {
                    for (int k = x[i]; k < w; k++) {
                        board[j][k] = 0;
                    }
                }
                break;
            case 3:
                for (int j = 0; j < y[i]; j++) {
                    for (int k = 0; k < w; k++) {
                        board[j][k] = 0;
                    }
                }
                break;
            case 4:
                for (int j = y[i]; j < h; j++) {
                    for (int k = 0; k < w; k++) {
                        board[j][k] = 0;
                    }
                }
                break;
        }
    }
    
    int area = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            area += board[i][j];
        }
    }

    cout << area << endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = min(a, k);
  if (a + b < k) ans -= k - (a + b);
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
using namespace std;

ostream& operator << (ostream &out, vector<int> &v) { for(auto a:v) out << a<<" "; out<<endl; }

int main()
{
    fast_cin
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1]=tolower(s[k-1]);
    cout << s << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define MAX(a,b) ((a) > (b) ? (a) : (b))

void run (void) {
  i32 a[5];
  const i32 n = 5;
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  i32 ans = 0;
  i32 sub = 0;
  for (i32 i = 0; i < n; ++i) {
    if (a[i] % 10 == 0) {
      ans += a[i];
    } else {
      ans += (a[i] + 9) / 10 * 10;
      sub = MAX(sub, 10 - a[i] % 10);
    }
  }
  printf ("%" PRIi32 "\n", ans - sub);
}

int main (void) {
  run ();
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

vll fac(2,1),inv(2,1),finv(2,1) ;

void nCr_set(int n){
	for(int i=2;i<=n;i++){
		fac.push_back(fac.at(i-1)*i%mod) ;
		inv.push_back(mod-inv.at(mod%i)*(mod/i)%mod) ;
		finv.push_back(finv.at(i-1)*inv.at(i)%mod) ;
	}
}

ll nCr(ll n,ll r){
	if(n<0||r<0||n<r) return 0 ;
	if(n==r||r==0) return 1 ;
	return fac.at(n)*finv.at(n-r)%mod*finv.at(r)%mod ;
}

ll nPr(ll n,ll r){
	return fac.at(n)*finv.at(n-r)%mod ;
}

ll nHr(ll n,ll r){
	return nCr(n+r-1,n-1) ;
}

int main(){
	nCr_set(2*1e6) ;
	ll n,m ;
	cin >> n >> m ;
	ll ans = 0 ;
	for(int i=0;i<=n;i++){
		ll add = nCr(n,i)*nPr(m,i)%mod*nPr(m-i,n-i)%mod*nPr(m-i,n-i)%mod ;
		if(i&1) add = mod-add ;
		ans = (ans+add)%mod ;
	}
	cout << ans << endl ;
}

Measured memory_bytes: 50076
#include <stdio.h>

int main()
{
    int N, K;
    char S[100];

    scanf("%d%d", &N, &K);
    scanf("%s", S);

    char tmp, tmp_a;
    tmp = S[K-1];


    if(tmp == 'A') {
        tmp_a = 'a';
    }
    else if (tmp == 'B')
    {
        tmp_a = 'b';
    }
    else if (tmp == 'C')
    {
        tmp_a = 'c';
    }

    S[K - 1] = tmp_a;

    printf("%s", S);
    return 0;
}

Measured memory_bytes: 128
Rect = []
cnt = 0
while True:
    H, W = map(int, input().split())
    if (H, W) == (0, 0):
        break
    Rect.append((H, W))
    cnt += 1

# print(Rect)
# print(Rect[1][1])
for i in range(cnt):
    for _ in range(Rect[i][0]):
        print("#"*Rect[i][1])
    print()


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define foru(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
typedef pair<int, int> ii;
int n, k;
int m[26],id[26];
bool cmp(int i, int j){
   return m[i] > m[j];
}
char s[11];
int main() {
//   freopen("input.txt","r",stdin);
   scanf("%d%d", &n, &k);
   foru(u, 1, n){
      scanf("%s", s);
      m[s[0]-'A']++;
   }
   for(int i=0; i<26; ++i)
      id[i] = i;
   int ans=0;
   while(1){
      sort(id, id + 26, cmp);
      for(int i=0; i<k; ++i)
         if(m[id[i]] == 0){
            printf("%d\n", ans);
            return 0;
         }
         else --m[id[i]];
      ++ans;
   }
   return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#define MAX 100000
using namespace std;

int n, A[MAX + 1], L[MAX];

int lis(){
  L[0] = A[0];
  int length = 1;

  for(int i = 1; i < n; i++){
    if(L[length-1] < A[i]){
      L[length++] = A[i];
    } else {
      *lower_bound(L, L + length, A[i]) = A[i];
    }
  }

  return length;
}

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

  cout << lis() << endl;
}

Measured memory_bytes: 1940
#include<iostream>
using namespace std; //or std::cin et al.

int main() {
	int w,h;
	
	while (1) {
	    cin >> h >> w;
		if ( w == 0 && h == 0 ) {
			break;
		}
		for ( int i = 0; i < h; i++ ) {
	            for ( int j = 0; j < w; j++ ) {
	    	        cout << "#";
	            }
	            cout << "\n";
                }
            cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define fo(i,n) for(int i=0;i<n;++i)
#define Fo(i,k,n) for(int i=k;i<n;++i)
typedef long long int lli;
int main(){
    FIO
    int N; cin>>N;
    int a[N];
    int i,j,k,ans=0;
    fo(i,N){
    cin>>a[i];
    }
    fo(i,N){
        Fo(j,i+1,N){
            Fo(k,j+1,N){
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]){
                   if(a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[i]+a[k]>a[j]){
                      ans++;
                   }
                }
            }
        }
    }
    cout<<ans<<endl;
}


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

int main() {
  const int l_bound = -1000000;
  const int u_bound =  1000000;
  int k, x;
  cin >> k >> x;
  
  int s = max(x - (k - 1), l_bound);
  int t = min(x + (k - 1), u_bound);
  
  for (int i = s; i < t; i++) {
    cout << i << " ";
  }
  cout << t << endl;
}

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

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

  int ming=1000;
  int m,sum=0;
  for(int i=0;i<N;i++) {
    cin >> m;
    ming=min(m,ming);
    sum+=m;
  }
  cout << N+(X-sum)/ming << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;



int main() {
	
	int n; cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++)cin >> p[i];

	int ans = 0, pos = 0;

	while (pos < n) {
		if (p[pos] == pos + 1) {
			if (p[pos + 1]==pos+2) {
				ans++;
				pos += 2;
			}
			else {
				ans++;
				pos++;
			}
		}
		else pos++;
	}

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

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

int main() {
  int n;
  cin>>n;
  vector<int> vec(n);
  for (int i=0;i<n;i++) {
    int a;
    cin>>a;
    vec.at(i)=a;
  }
  int ans=0;
  for (int i=0;i<n-1;i++) {
    for (int j=i+1;j<n;j++) {
      ans+=vec.at(i)*vec.at(j);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
d = {}
P = {}
for i in range(1,N+1):
    d[i] = 0
    P[i] = 0
for i in range(M):
    p,s = map(str,input().split())
    q = int(p)
    if d[q] == 1:
        continue
    else:
        if s == 'AC':
            d[q] = 1
        else:
            P[q] += 1
ans1 = 0
ans2 = 0
for i in range(1,N+1):
    if d[i] == 1:
        ans1 += 1
        ans2 += P[i]
print(ans1,ans2)

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

int main()
{
	string S;
	cin >> S;
	
	if ( S[0] == S[1] && S[1] == S[2] )
	{
		cout << "No";
	}
	else
	 cout << "Yes";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
int main()
{
	int n; cin>>n;
	map<P, P> mp;
	ll ans=0;
	for(int i=0; i<n; i++){
		ll a, b; cin>>a>>b;
		if(a==0 && b==0){
			ans++;
			continue;
		}
		ll g=gcd(a, b);
		a/=g, b/=g;
		if(b<0) a=-a, b=-b;
		if(b==0 && a<0) a=-a;
		if(a>0) mp[{a, b}].first++;
		else mp[{b, -a}].second++;
	}
	ll ans1=1;
	for(auto p:mp){
		ll x=p.second.first, y=p.second.second;
		(ans1*=(powmod(2, x)+powmod(2, y)-1))%=MOD;
	}
	cout<<(ans+ans1+MOD-1)%MOD<<endl;
	return 0;
}


Measured memory_bytes: 19152
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int count = 0;
        for(int i=0;i<3;i++){
            if(s.charAt(i)=='R'){
                count++;
            }
        }
        if(s.charAt(1)=='S'&&count==2){
            count = 1;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35588
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b){ //最大公約数
  if(a % b == 0) return b;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b){ //最小公倍数
  return a / gcd(a, b) * b;
}
int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  a--;
  ll g = lcm(c, d);
  ll cnt = b / c + b / d;
  cnt -= a / c + a / d;
  cnt -= b / g - a / g;
  cout << b - a - cnt << endl;
}

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

using namespace std;

#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 FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<string,int>Psi;

int main(){
  ll n;
  cin>>n;
  ll a[5];
  REP(i,5){
    cin>>a[i];
  }
  sort(a,a+5);
  ll min=a[0];
  ll count;
  if(n%min==0){
    count=n/min+4;
  }else{
    count=n/min+5;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0014
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            while ((str = Console.ReadLine()) != null)
            {
                int d = int.Parse(str);
                int s = 0;
                for (int i = 0; i < (600 / d); i++)
                {
                    int h = (int)Math.Pow(i * d, 2);
                    s += d * h;
                }
                Console.WriteLine(s);
            }
        }
    }
}



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

int main(){
    int i,n,c_buff;
    int S[13],H[13],C[13],D[13];
    char m_buff;
    std::vector<char> mark;
    std::vector<int> card;

    for(i=0;i<13;i++){
        S[i]=0;
        H[i]=0;
        C[i]=0;
        D[i]=0;
    }

    std::cin>>n;

    for(i=0;i<n;i++){
        std::cin>>m_buff>>c_buff;

        if(m_buff=='S'){
            S[c_buff-1]=c_buff;
        }else if(m_buff=='H'){
            H[c_buff-1]=c_buff;
        }else if(m_buff=='C'){
            C[c_buff-1]=c_buff;
        }else if(m_buff=='D'){
            D[c_buff-1]=c_buff;
        }
    }

    for(i=0;i<13;i++){
        if(S[i]==0){
            std::cout<<"S"<<" "<<i+1<<std::endl;
        }
    }

    for(i=0;i<13;i++){
        if(H[i]==0){
            std::cout<<"H"<<" "<<i+1<<std::endl;
        }
    }

    for(i=0;i<13;i++){
        if(C[i]==0){
            std::cout<<"C"<<" "<<i+1<<std::endl;
        }
    }

    for(i=0;i<13;i++){
        if(D[i]==0){
            std::cout<<"D"<<" "<<i+1<<std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3084
import java.util.*

fun main(args: Array<String>) {
	val cin = Scanner(System.`in`)
	val ans = mutableListOf<String>()

	while (true) {
		val H = cin.nextInt()
		val W = cin.nextInt()
		if (H + W == 0) break

		for (h in 0 until H) {
			ans.add("#".repeat(W))
		}
		ans.add("")
	}
	println(ans.joinToString("\n"))
}



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

typedef long long ll;

const int MAXN = 2e5 + 5;

int N;
ll a[MAXN];
map <ll, int> cnt;
ll sol;

int main() {
	scanf("%d", &N);
	cnt[0]++;
	for (int i = 1; i <= N; i++) {
		scanf("%lld", a + i);
		a[i] += a[i - 1];
		sol += cnt[a[i]]++;
	}
	
	printf("%lld\n", sol);
	
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


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

    int ans = 10000;
    for (int i = 0; i <= s.size() - t.size(); i++)
    {
        //i : shift
        int cnt = 0;
        for (int j = 0; j < t.size(); j++)
        {
            if (t[j] != s[j+i]) cnt++;
        }
        ans = min(ans, cnt);   
        //cout << cnt << endl;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  if(a.size()>b.size())
    cout<<"GREATER"<<endl;
  else if(a.size()<b.size())
    cout<<"LESS"<<endl;
  else if(a==b)
    cout<<"EQUAL"<<endl;
  else{
    for(int i=0;i<a.size();i++){
      if(a.at(i)>b.at(i)){
        cout<<"GREATER"<<endl;
        break;
      }
      else if(a.at(i)<b.at(i)){
        cout<<"LESS"<<endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define MAX_N 1010
#define MAX_M 100010
const long long mod = pow(10, 9) + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 10010
#define PI 3.141592653589793
#define vecP vector<P>
//cout << setprecision(15) << std::fixed;


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

ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

int main(){
    int n;
    ll x,y;
    cin>>n>>x;
    for(int i;i<n-1;i++){
        cin>>y;
        x=lcm(x,y);
    }
    print(x);

    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans=0,n,d;
    cin >>n>>d;
    ll pos[n][d];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>pos[i][j];
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>pos[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ll sum=0;
            for(int k=0;k<d;k++){
                sum+=(pos[i][k]-pos[j][k])*(pos[i][k]-pos[j][k]);
            }
            if((int)sqrt(sum)*sqrt(sum)==sum)ans++;
        }
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
int a;
cin >> a;
int e = (a/100);
int f =((a%100)/10);
int g = (((a%100)%10)/1);
int h = (g*100)+(f*10)+(e*1);
if(a==h){
    cout << "Yes" << endl;
}else{
    cout << "No" << endl;
}
return 0;
}

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

int main(){
    int N,M,X,K,l=0,r=0;
    cin >> N >> M >> X;
    for(int i=0;i<M;i++){
        cin >> K;
        if(K<X)
        l++;
        else
        r++;
    }
    cout << min(l,r) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int data[1000000];

int insert_sort(int *a, int n, int g)
{
	int swap_count = 0;
	for(int i = g; i < n; ++i)
	{
		int v = a[i];
		int j = i - g;
		while((0 <= j) && (v < a[j]))
		{
			a[j+g] = a[j];
			j -= g;
			++swap_count;
		}
		a[j+g] = v;
	}
	return swap_count;
}

int main()
{
	int n, m, g;
	int swap_count = 0;
	
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%d", &data[i]);
	}
	
	for(m = 0, g = 1; g <= n; ++m)
	{
		g = 3 * g + 1;
	}
	
	printf("%d\n", m);
	while(1)
	{
		g = (g - 1) / 3;
		printf("%d", g);
		swap_count += insert_sort(data, n, g);
		
		if(g == 1)
		{
			break;
		}
		printf(" ");
	}
	printf("\n%d\n", swap_count);
	
	for(int i = 0; i < n; ++i)
	{
		printf("%d\n", data[i]);
	}
}



Measured memory_bytes: 5628
import itertools
S = input()
l = len(S)

if l == 2:
    if S[0] == S[1]:
        print(1,2)
    else:
        print(-1, -1)
    exit()


else:
    for i in range(l-2):
        a,b,c = S[i],S[i+1],S[i+2]
        if a == b or b == c or a == c:
            print(i + 1,i+3)
            exit()

print(-1,-1)

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

int main() {
  int n, k;
  cin >> n >> k;
  double csum[n+1];
  csum[0] = 0;
  for ( int i = 1; i < n+1; i++ ) {
    double p;
    cin >> p;
    csum[i] = ((1.0+p)/2.0) + csum[i-1];
  }

  double ans = 0;
  for ( int i = k; i <= n; i++ ) {
    double now_sum = csum[i] - csum[i-k];
    ans = ( now_sum > ans ) ? now_sum : ans;
  }

  printf("%.12f\n", ans);
  return 0;
}


Measured memory_bytes: 5352
//Graph
#include<stdio.h>

#define MAX 110

int main(){
  int i,j,k,n,u,v;
  int count[MAX][MAX];
  
  
  scanf("%d",&n);
  
  for(i=1; i<=n; i++){
    scanf("%d%d",&u,&k);
    for(j=1; j<=k; j++){
      scanf("%d",&v);
      count[i][v] = 1;
    }
  }

  for(i=1; i<=n; i++){
    for(j=1; j<=n; j++){
      printf("%d",count[i][j]);
      if(j==n) continue;
      printf(" ");
    }
    printf("\n");
   }
  return 0;
}



Measured memory_bytes: 2044
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,W = map(int,readline().split())
WV = [list(map(int,readline().split())) for _ in range(N)]

dp = np.zeros(W+1,np.int64)
for w,v in WV:
  np.maximum(dp[w:],dp[:-w].copy() +v,out=dp[w:])
print(dp.max())

Measured memory_bytes: 15480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int n, ans = 0;
    cin >> n;
    int a[n];
    rep(i, n)
    {
        cin >> a[i];
        ans ^= a[i];
    }
    if (ans == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//ここまでの覚悟が必要なのか

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

pair<int, int> E[100001];
int H[100001], n[100001], kari[100001];
int sagasu(int A) {
	if (n[A] - n[A - 1] == 0) return 0;
	int k = n[A - 1];
	for (int i = H[A]; i; i = E[i].second) {
		kari[k++] = sagasu(E[i].first);
	}
	sort(kari + n[A - 1], kari + n[A], greater<int>());
	int ret = 0;
	rep(i, n[A] - n[A - 1]) ret = max(ret, i + *(kari + n[A - 1] + i) + 1);
	return ret;
}

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


	int N = getint();

	for (int i = 2; i <= N; i++) {
		int a = getint();
		n[a]++;
		E[i] = mp(i, H[a]);
		H[a] = i;
	}
	rep1(i, N) n[i] = n[i - 1] + n[i];

	co(sagasu(1));

	Would you please return 0;
}

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

int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    ll ans = 0;
    map<ll,ll> mp;
    rep(i,n){
        ll b = i+a[i];
        ll c = i-a[i];
        if(mp.count(c)){
        ans+=mp.at(c);
        }
        
        if(mp.count(b)){
            mp[b]++;
        }
        else{
            mp[b] = 1;
        }
    }
    //cout << mp.at(0) << endl;
    cout << ans << endl;
}

Measured memory_bytes: 17592