akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;

class BCommonRaccoonVsMonster {
public:
	void solve(std::istream& cin, std::ostream& cout) {
		int h,n;cin >> h >> n;//scanf("%lld",&a[i]);
		vector<ll> a(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> a[i];
			h -= a[i];
		}
		if(h <= 0){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
};


int main() {
	BCommonRaccoonVsMonster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll h[100010],c[100010];
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<=n;i++){
		cin>>h[i];
	}
	for(ll i=0;i<n;i++){
		cin>>c[i];
	}
	ll ans=0;
	for(ll i=0;i<n;i++){
		ll now=min(h[i],c[i]);
		ans+=now;
		h[i]-=now;c[i]-=now;
		now=min(h[i+1],c[i]);
		ans+=now;
		h[i+1]-=now;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	for(int i = n - 1; i > 0; i--){
		if(a.at(i) < a.at(i - 1)) a.at(i - 1)--;
	}
	bool ok = true;
	rep(i,n - 1){
		if(a.at(i) > a.at(i + 1)) ok = false;
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll tree[2000000];
void updatetree(ll ind,ll l,ll h,ll i,ll val)
{
    if(i<l || i>h || l>h)return;
    if(l==h)
    {
        tree[ind]=val;
        return;
    }
    ll md=l+(h-l)/2;
    updatetree(2*ind+1,l,md,i,val);
    updatetree(2*ind+2,md+1,h,i,val);
    tree[ind]=max(tree[2*ind+1],tree[2*ind+2]);
}
ll query(ll ind,ll l,ll r,ll i,ll j)
{
    if(l>r || l>j || r<i)return 0;
    if(i<=l && j>=r)
    {
        return tree[ind];
    }
    ll md=l+(r-l)/2;
    ll l1=query(2*ind+1,l,md,i,j);
    ll r1=query(2*ind+2,md+1,r,i,j);
    return max(l1,r1);
}
int main() 
{
	ll n,k;
	cin>>n>>k;
	vector<ll> v(n);
	for(ll i=0;i<n;i++)cin>>v[i];
	ll dp[n][2];
	updatetree(0,0,1000000,v[0],1);
	dp[0][0]=1;
	dp[0][1]=1;
	ll ans=1;
	for(ll i=1;i<n;i++)
	{
		ll x=query(0,0,1000000,v[i]-k,v[i]);
		dp[i][0]=x+1;
		ll y=query(0,0,1000000,v[i],v[i]+k);
		dp[i][1]=y+1;
		
		ans=max(ans,max(dp[i][0],dp[i][1]));
		updatetree(0,0,1000000,v[i],max(dp[i][0],dp[i][1]));
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 15144
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int n, m;
vector<int> v = {0};
vector<vector<int>> u;

void f(int a, int i){
	if(i == n){
		u.PB(v);
		return;
	}
	FOR(b, a, m+1){
		v.PB(b);
		f(b, i+1);
		v.pop_back();
	}
}
int a[50], b[50], c[50], d[50];

int main(){
	int q; scanf("%d%d%d", &n, &m, &q);
	REP(i, q) scanf("%d%d%d%d", a+i, b+i, c+i, d+i);
	f(1, 0);
	int z = -1;
	for(auto &v : u){
		for(auto &i : v) DEBUG("%d ", i);
		DEBUG("\n");
		int s = 0;
		REP(i, q) if(v[b[i]] - v[a[i]] == c[i]) s += d[i];
		LAR(z, s);
	}
	printf("%d\n", z);
}





Measured memory_bytes: 11072
C = [list(map(int, input().split())) for _ in range(3)]
a = [0] * 3
b = [0] * 3
flg = True
for j in range(3):
    b[j] = C[0][j] - a[0]

for j in range(1, 3):
    a[j] = C[j][0] - b[0]
for j in range(3):
    for k in range(3):
        if C[j][k] != a[j] + b[k]:
            flg = False
            break
if flg:
    print('Yes')
    quit()
print('No')

Measured memory_bytes: 3064
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
def worstdata():
    a=0
    return a
#solution:
def comp(p):#期待値
    return ((p+1)/2)



#input
n,=(pin())
S=sorted(list(pin()))
cond=1
for i in range(1,n):
    if S[i]-S[i-1]==0:
        cond=0
        break

print(["NO","YES"][cond])

Measured memory_bytes: 87892
#include "bits/stdc++.h"
using namespace std;

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

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

    int res = 0;
    if (N % 2 == 0) {
        for (int i = N - 1; i > 0; i -= 2) {
            res++;
            cout << A[i] << " ";
        }
        for (int i = 0; i < N; i += 2) {
            res++;
            if (res < N) {
                cout << A[i] << " ";
            }
            else {
                cout << A[i] << endl;
            }
        }
    }
    else {
        for (int i = N - 1; i >= 0; i -= 2) {
            res++;
            cout << A[i] << " ";
        }
        for (int i = 1; i < N; i += 2) {
            res++;
            if (res < N) {
                cout << A[i] << " ";
            }
            else {
                cout << A[i] << endl;
            }
        }
    }
}

Measured memory_bytes: 2944
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
typedef long long ll;
 
using namespace std;
 
int dp[2001][2001][2]={0};
int m,n,ans=0;
char t[2001],s[2001];
 
int main(){
    
    scanf("%d%d%s%s",&m,&n,t,s);
    
    for(int i=0;i<m+n;i++){
        
        for(int k=0;k<=i;k++){
            if(k<m && i-k<=n){
                if(t[k]=='I'){
                    dp[k+1][i-k][1]=max(dp[k+1][i-k][1],dp[k][i-k][0]+1);
                }else{
                    if(dp[k][i-k][1])
                        dp[k+1][i-k][0]=max(dp[k+1][i-k][0],dp[k][i-k][1]+1);
                }
                ans=max(ans,dp[k+1][i-k][1]);
            }
            if(k<=m && i-k<n){
                if(s[i-k]=='I'){
                    dp[k][i-k+1][1]=max(dp[k][i-k+1][1],dp[k][i-k][0]+1);
                }else{
                    if(dp[k][i-k][1])
                        dp[k][i-k+1][0]=max(dp[k][i-k+1][0],dp[k][i-k][1]+1);
                }
                ans=max(ans,dp[k][i-k+1][1]);
            }
        }
    }
    
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 34448
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

struct edge{
  ll to;
  ll cost;
};

int solve() {
  ll n,q,k;
  cin >> n;
  vector<vector<edge> > tree(n);
  for(ll i = 0;i < n - 1; i++){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    edge tmp;
    tmp.to = b;
    tmp.cost = c;
    tree[a].push_back(tmp);
    tmp.to = a;
    tmp.cost = c;
    tree[b].push_back(tmp);
  }
  cin >> q >> k;
  k--;
  // dfs
  vector<ll> d(n);
  vector<ll> res(q);
  stack<ll> stk;
  stk.push(-1);
  stk.push(k);
  while(stk.top() != -1){
    ll now = stk.top();
    stk.pop();
    for(ll i = 0;i < tree[now].size(); i++){
      if(d[tree[now][i].to] == 0){
        stk.push(tree[now][i].to);
        d[tree[now][i].to] = d[now] + tree[now][i].cost;
      }
    }
  }
  for(ll i = 0; i < q; i++){
    ll x,y;
    cin >> x >> y;
    x--; y--;
    cout << d[x] + d[y] << endl;
  }
  return 0;
}


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


Measured memory_bytes: 10752
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int N=26;

int main(){
  int D;
  cin>>D;
  int c[N];
  REP(i,N)cin>>c[i];
  int s[D][N];
  REP(d,D)REP(n,N)cin>>s[d][n];
  REP(i,D)cout<<i%26+1<<endl;
  return 0;
}


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


int main()
{
    vector<int> v;
    int n;
	do
	{
	    cin >> n;
	    v.push_back(n);
	} while (n != 0);
	
	for (int i = 0; i < v.size() - 1; i++)
	    cout << "Case " << i+1 << ": " << v[i] << endl;
	
	return 0;
}



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

int main() {
  long long N, M; cin >> N >> M;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  vector<pair<long long, long long>> BC(M);
  for (int i = 0; i < M; i++) {
    long long b, c; cin >> b >> c;
    BC.at(i).first = c;
    BC.at(i).second = b;
  }
  sort(BC.begin(), BC.end(), greater<pair<long long, long long>>());
  vector<long long> D;
  long long cnt = N;
  for (auto p : BC) {
    bool flag = false;
    for (int i = 0; i < p.second; i++) {
      D.push_back(p.first);
      cnt--;
      if (cnt == 0) {
        flag = true;
        break;
      }
    }
    if (flag) break;
  }
  long long sum = 0;
  long long sizeofD = D.size();
  long long index = min(N, sizeofD);
  for (int i = 0; i < index; i++) {
    sum += max(A.at(i), D.at(i));
  }
  for (long long i = index; i < N; i++) sum += A.at(i);
  cout << sum << endl;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

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

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

int main()
{
    int n,a,even = 0;
    cin >> n;
    rep(i, n){
        cin >> a;
        if (a % 2 == 0) {
            ++even;
        }
    }
    cout << pow(3, n) - pow(2, even) << endl;
    return 0;
}


Measured memory_bytes: 256
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);
    x-=z;
    printf("%d\n",x/(y+z));
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;

    
signed main(){
    
	string a;
	int n;
	int r=0,b=0;
	cin>>n;
	rep(i,n){
	    cin>>a[i];
	    if(a[i]=='R')r++;
	    else b++;
	}
	if(r>b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
}

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

int main(){
  int A,B;
  cin>>A>>B;
  if(A>B){
    cout<<2*A-1<<endl;
  }
  else if(A<B){
    cout<<2*B-1<<endl;
  }
  else if(A=B){
    cout<<A+B<<endl;
  }
}
  


Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
	int b,f,r,v;
	int n,i,j,k;
	int dome[4][3][10] = {0};
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d %d",&b,&f,&r,&v);
		dome[b-1][f-1][r-1] += v;
	}
	
	for(i=0;i<4;i++)
	{
		for(j=0;j<3;j++)
		{
			for(k=0;k<10;k++)
			{
				printf(" %d",dome[i][j][k]);
			}
			printf("\n");
		}
		if((i+1)<4)
			printf("####################\n");
	}
	
	
	return 0;
}

Measured memory_bytes: 612
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

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

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

struct state {
	int x, y, level;
	state(int x, int y, int level):x(x), y(y), level(level){}
	bool operator>(const state& s) const {
		return level > s.level;
	}
};

map<int, int> nextOffice() {
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	--x;
	--y;

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

	vector<vector<bool> > visited(h, vector<bool>(w, false));
	priority_queue<state, vector<state>, greater<state> > que;
	que.push(state(x, y, field[y][x]));

	while(!que.empty()) {
		state s = que.top();
		que.pop();

		visited[s.y][s.x] = true;

		for(int i = 0; i < 4; ++i) {
			int nx = s.x + dx[i], ny = s.y + dy[i];
			if(nx < 0 || ny < 0 || nx >= w || ny >= h || visited[ny][nx])
				continue;

			chmax(field[ny][nx], field[s.y][s.x]);
			que.push(state(nx, ny, field[ny][nx]));
		}
	}

	map<int, int> res;
	res.insert(make_pair(0, 0));
	for(int i = 0; i < h; ++i)
		for(int j = 0; j < w; ++j)
			res[field[i][j]] += 1;

	for(map<int, int>::iterator it = res.begin(); it != res.end(); ++it) {
		map<int, int>::iterator next = it;
		++next;

		if(next != res.end())
			next->second += it->second;
	}

	return res;
}

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

	for(int r; cin >> r, r;) {
		map<int, int> office1 = nextOffice();
		map<int, int> office2 = nextOffice();

		int ans = MAX * 2;
		map<int, int>::iterator it = office1.begin();
		map<int, int>::reverse_iterator it2 = office2.rbegin();
		for(; it != office1.end(); ++it) {
			while(it2 != office2.rend() && it->second + it2->second >= r) {
				chmin(ans, it->first + it2->first);
				++it2;
			}

			if(it2 == office2.rend())
				goto finish;
		}

	finish:;
		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 15116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  string S;
  cin >> N >> S;
  int left = 0;
  int right = 1;
  int ans = 0;
  while(1){
    if(N-left<ans+2) break;
    string a = S.substr(left, right-left);
    string b = S.substr(right);
    //cout << a << " " << b << " " << left << " " << right << endl;
    if(b.find(a) != string::npos){
      ans = max(ans, (int)a.size());
      right=min(right+1, N-1);
      if(left==N-1) break;
    }
    else{
      left++;
      if(right==left) right=min(right+1, N-1);
      if(left==N-1) break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
from collections import Counter
N=int(input())
S=Counter(list(input()))

for i in range(1,N):
  S_=Counter(list(input()))
  for s in S:
    if S_[s]<S[s]:
      S[s]=S_[s]

ans=[]
for s in S:
  for _ in range(S[s]):
    ans.append(s)
print("".join(sorted(ans)))

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  string s;
  cin>>s;

  vll r,g,b;
  REP(i,n){
    if(s[i]=='R')
      r.push_back(i);
    if(s[i]=='G')
      g.push_back(i);
    if(s[i]=='B')
      b.push_back(i);
  }


  auto f=[](ll i, vll a, vll b){
    ll sum=0;
    auto it=lower_bound(ALL(a),i);

    for(ll j=it-a.begin(); j<a.size(); j++){
      ll dif=a[j]-i;

      auto it2=lower_bound(ALL(b), a[j]);
      if(it2==b.end())
        continue;
      ll cnt=(b.size()-(it2-b.begin()));

      auto find=lower_bound(ALL(b), a[j]+dif);
      if(find!=b.end() && *find==a[j]+dif)
        cnt--;
       // cout<<"find"<<endl;

      sum+=cnt;
    }

    return sum;
  };



  ll sum=0;
  REP(i,n){
    if(s[i]=='R'){
      sum +=f(i,g,b);
      sum +=f(i,b,g);
    }
    else if(s[i]=='G'){
      sum +=f(i,r,b);
      sum +=f(i,b,r);
    }

    else if(s[i]=='B'){
      sum +=f(i,g,r);
      sum +=f(i,r,g);
    }
  }

  cout<<sum<<endl;
}



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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int M, K, ans[int(2e5+5)];

int main(){
  cin >> M >> K;

  if (M == 0){
    if (K > 0) cout << -1 << endl;
    else cout << "0 0" << endl;
    return 0;
  }

  if (M == 1){
    if (K > 0) cout << -1 << endl;
    else cout << "0 0 1 1" << endl;
    return 0;
  }

  int all = 1;
  for (int i = 0; i < M; i++){
    all = all << 1;
  }

  if (K >= all){
    cout << -1 << endl;
    return 0;
  }

  if (K == 0){
    cout << 0;
    for (int i = 1; i < all; i++) cout << " " << i;
    for (int i = all-1; i >= 0; i--) cout << " " << i;
    cout << endl;
    return 0;
  }

  cout << 0 << " " << K << " " << 0;
  for (int i = 1; i < all; i++){
    if (i == K) continue;
    cout << " " << i;
  }
  cout << " " << K;
  for (int i = all - 1; i >= 1; i--){
    if (i == K) continue;
    cout << " " << i;
  }
  cout << endl;


  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

pair<int,int> a[1001];
pair<int,int> ans;
int b[1001], c[1001];
bool comp(pair<int,int> x, pair<int,int> y){
	return x.fi > y.fi;
}

int main(){
	int n, m, t;
	ans.se = 0;
	scanf("%d%d", &n, &m);
	rrep(i,n){
		scanf("%d", &t);
		a[i].fi = t;
		a[i].se = i;
	}
	rrep(i,m)scanf("%d", &b[i]);
	//sort(a+1, a+n+1);
	for(int i = 1;i <= m;i++){
		t = INF;
		rrep(j,n)if(a[j].fi <= b[i])t = min(t, a[j].se);
		c[t]++;
		if(c[t] > ans.se){
			ans.fi = t;
			ans.se = c[t];
		}
	}
	printf("%d\n", ans.fi);
	return 0;
}

Measured memory_bytes: 3232
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = map(int, input().split())
    A = sorted([a - i - 1 for i, a in enumerate(A)])

    b = A[N//2]
    print(sum([abs(a - b) for a in A]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 25196
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n = int(input())
#n = 2

prev = [0,0,0]
for i in range(n):
    txy = list(map(int, input().split()))
    #txy = list(map(int, ["3 1 2", "6 1 1"][i].split()))
    t = txy[0] - prev[0]
    x = abs(txy[1] - prev[1])
    y = abs(txy[2] - prev[2])
    d = x + y
    if not(d <= t and (d - t) % 2 == 0):
        print('No')
        exit()
    prev = txy
print('Yes')


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	int N, a[100], i, b[101]={0};
    int c=0;
  
    scanf("%d", &N);
    for(i=0; i<N; i++){
     scanf("%d", &a[i]);
    }
    
    for(i=0; i<N; i++){
      b[a[i]]++;
    }

  	for(i=1; i<=100; i++){
      if(b[i]) c++;
    }
  
  	printf("%d", c);
return 0;
}

Measured memory_bytes: 128
ABCD= str(input())

sign_list = ["+","-"]
ans_str = ""
for i in range(2):
  new_sign_list = []
  for sign in sign_list:
    new_sign_list.append(sign+"+")
    new_sign_list.append(sign+"-")
  sign_list = new_sign_list

for signs in sign_list:
  tmp_num = int(ABCD[0])
  for i in range(len(signs)):
    if signs[i] == "+":
      tmp_num += int(ABCD[i+1])
    elif signs[i] == "-":
      tmp_num -= int(ABCD[i+1])

  if tmp_num == 7:
    ans_str = signs
    break

ans = ABCD[0]
for i in range(len(ans_str)):
  ans += ans_str[i]
  ans += ABCD[i+1]

ans += "=7"

print(ans)




Measured memory_bytes: 3064
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int n = rint, k = rint;
	long s = rlong;

	long[] ans;
	if(s < 1_000_000_000){
		foreach(i; 0 .. k) ans ~= s;
		foreach(i; k .. n) ans ~= 1_000_000_000;
	}
	else{
		foreach(i; 0 .. k) ans ~= s;
		foreach(i; k .. n) ans ~= 1;
	}

	ans.map!(to!string).join(" ").writeln;
}

Measured memory_bytes: 6140
#include <stdio.h>
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)

int main(){
	int H,W; scanf("%d %d",&H,&W);
	char s[100];
	int map[H][W];
	rep(i,0,H){
		scanf("%s",s);
		rep(j,0,W){
			if( s[j]=='#' ) map[i][j]=0; // 黒
			else map[i][j]=1; //白
		}
	}
	int dp[H+1][W+1][2];
	// dp[i][j][0] -- (i,j)マス自身がそれまでの操作でひっくり返されている
	// dp[i][j][1] -- (i,j)マスはそれまでの操作でひっくり返されていない
	rep(i,0,H+1){ rep(j,0,W+1){
		dp[i][j][0]=100000;
		dp[i][j][1]=100000;
	}}
	dp[1][0][1]=0; dp[0][1][1]=0;
	rep(i,2,H+W+1){
		rep(j,1,H+1){
			if( i-j>W+1 ) continue;
			if( i-j<=0 ) break;
			int a=j,b=i-j;
			if( map[a-1][b-1]==0 ){
				dp[a][b][0] = min( dp[a-1][b][0],dp[a][b-1][0] );
				dp[a][b][0] = min( dp[a][b][0],dp[a-1][b][1]+1 );
				dp[a][b][0] = min( dp[a][b][0],dp[a][b-1][1]+1 );
			}else{
				dp[a][b][1] = min( dp[a-1][b][1],dp[a][b-1][1] );
				dp[a][b][1] = min( dp[a][b][1],dp[a-1][b][0] );
				dp[a][b][1] = min( dp[a][b][1],dp[a][b-1][0] );
			}
		}
	}
	printf("%d",min(dp[H][W][0],dp[H][W][1]));
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int count = 0;
			for(int i = 9;i >= 0;i--){
				if((n-i) > 27){
					break;
				}
				for(int j = 9;j >= 0;j--){
					if((n-i-j) > 18){
						break;
					}
					for(int k = 9;k >= 0;k--){
						if((n-i-j-k) > 9){
							break;
						}
						for(int l=9;l >= 0;l--){
							if(n-i-j-k == l){
								count++;
							}
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 11000
// ダイクストラ法 TLE解法 ==> ワーシャルフロイドで前点間最短距離を求めた方が早い.

#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define dump1d_arr(array)  REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array,i,j) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define dump_pair(pair) cerr << #pair << " ==> (" << pair.first << "," << pair.second << ")" << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define loINF (long)10000000000
#define shINF (short)30000
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;

typedef pair<long,long> pr;

struct Order {
	bool operator() (pr const& a,pr const& b) const {
		return a.first > b.first || ((a.first == b.first) && (a.second > b.second));
	}
};

typedef priority_queue<pr,vector<pr>,Order> pq;
typedef vector<char> VC;
typedef vector<long> VL;
typedef vector<pr> VP;
typedef vector<VP> VVP;


// global
long V;
VVP cost;
long start;
VL ans;

//入力 
void input_gragh(void){
	long E; 
	long ver1,ver2;
	short dis;

	cin >> V >> E >> start;		//V:頂点数 , E:辺数
	cost = VVP(V+1,VP(0)); // 辺の情報。cost[i] := (辺の先の頂点j,頂点iと頂点jの距離)

	REP(i,E){ //辺の情報を格納する。
		cin >> ver1 >> ver2 >> dis;
		cost[ver1].push_back(make_pair(ver2,dis));
	}

	ans = VL(V+1,loINF);
}

void dijekstra(long start){
	pq distance;
	pr minver;
	long now_ver,next_ver,next_dis;
	VC used(V+1,0);

	distance.push(make_pair(0,start));

	while (!distance.empty()) {
		minver = distance.top();
		distance.pop();
		now_ver = minver.second;
		if (used[now_ver]) continue;
		else {
			used[now_ver] = 1;
			ans[now_ver] = minver.first;
		}
			
		REP(i,cost[now_ver].size()) {
			next_ver = cost[now_ver][i].first;
			next_dis = cost[now_ver][i].second;
			if (used[next_ver]) continue;
			distance.push(make_pair(minver.first+next_dis,next_ver));
		}
	}
}

int main (void){
	input_gragh();
	dijekstra(start); 
	REP(i,V){
		if (ans[i] == loINF) cout << "INF" << endl;
		else  cout << ans[i] << endl;
	}
 	return 0;
}



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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define BIT(bit,a,n) for (int bit = a;bit < (1<<n);bit++) // {0, 1, ..., n-1} の部分集合の全探索 // n番目のフラグが立っている状態は (1<<n)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20

typedef long long ll;
using namespace std;

int n;
int p=0,w=0,g=0,y=0;
int main() {
    scanf("%d",&n);
    vector<char> s(n);
    rep(i, 0, n) cin >> s[i];
    rep(i,0,n){
        if(s[i] == 'P') p++;
        else if(s[i] == 'W') w++;
        else if(s[i] == 'G') g++;
        else if(s[i] == 'Y') y++;
    }
    if(p>0 && w>0 && g>0 && y>0) printf("Four\n");
    else printf("Three\n");
    return 0;    
}


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

int HammingNumber(int n){
	int p=n;
	while(p%2 == 0)p/=2;
	while(p%3 == 0)p/=3;
	while(p%5 == 0)p/=5;
	return p==1;
}

int main() {
	
	int m,n;
	int count;
	
	while(count=0,cin>>m>>n,m){
		for(int i=m;i<=n;++i)if(HammingNumber(i))++count;
		cout << count << endl;
	}
	return 0;	
}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val costs = (0..9).map {
        readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    }.toTypedArray()
    val wall = (0 until h).map {
        readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    }.toTypedArray()

    for (k in 0..9) {
        for (i in 0..9) {
            for (j in 0..9) {
                costs[i][j] = Math.min(costs[i][j], costs[i][k] + costs[k][j])
            }
        }
    }

    var ans = 0

    for (i in 0 until h) {
        for (j in 0 until w) {
            if (wall[i][j] != -1) {
                ans += costs[wall[i][j]][1]
            }
        }
    }

    println(ans)
}


Measured memory_bytes: 40500
n = int(input())
b = list(map(int,input().split()))

ans = 0
for i in range(n):
    if i == 0:
        ans += b[i]
    elif i == n-1:
        ans += b[i-1]
    else:
        ans += min(b[i-1],b[i])

print(ans)



Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var NXY = IO.RSInt;
            var N = NXY[0];
            var X = NXY[1];
            var Y = NXY[2];

            // 1-indexedとする
            var ans = new int[N];

            //[i,j]間の距離を調べる
            for (int i = 1; i <= N; i++)
            {
                for (int j = i + 1; j <= N; j++)
                {
                    int straight = j - i;

                    int dis_X = Abs(X - i);
                    int dis_Y = Abs(Y - j);
                    int warp = dis_X + dis_Y + 1;

                    int dis = Min(straight, warp);
                    ans[dis]++;
                }
            }
            for (int i = 1; i < N; i++)
            {
                WriteLine(ans[i]);
            }
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 19172
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < b; ++i)

int main()
{
    int H, W;
    scanf("%d %d", &H, &W);

    char mp[H][W + 2];
    REP(i, 0, H) scanf("%s", mp[i]);
    REP(i, 0, 2*H) printf("%s\n", mp[i/2]);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

int main() {
  cout << fixed << setprecision(15);

  ll H, W;
  cin >> H >> W;

  ll N;
  cin >> N;

  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<vector<ll>> coloring(H, vector<ll>(W, 0));
  ll index = 0;
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      coloring[i][j] = index + 1;
      A[index]--;
      if (A[index] == 0) {
        index++;
      }
    }
  }

  for (ll i = 0; i < H; i++) {
    vector<ll> row = coloring[i];
    if (i % 2 != 0) {
      reverse(row.begin(), row.end());
    }

    for (ll j = 0; j < W; j++) {
      cout << row[j] << " ";
    }

    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 512
//Jai Shree Ram
//#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define loopi(stop) for(int i=0; i<stop; i++)
#define loopj(stop2) for(int j=0; j<stop2; j++)
#define loopk(stop3) for(int k=0; k<stop3; k++)
#define loopi1(stop) for(int i=1; i<=stop; i++)
#define loopj1(stop2) for(int j=1; j<=stop2; j++)
#define loopk1(stop3) for(int k=1; k<=stop3; k++)
#define loopse(kt,sstart, eend) for(int kt = sstart; kt<eend; kt++)
#define faster_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define file_io_cf freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define p_b push_back
#define pii pair<int,int>
#define fi first
#define se second
#define prec_10 << fixed << setprecision(10)
#define DEB cout<<"DEBUG"<<'\n';
#define SRAND srand(time(0));

using namespace std;

int mod = 1000000007;

template <typename T>
void O(T x) {
	cout << x << '\n';
}

///////////////////////////////////CODE STARTS HERE///////////////////////////////////////////

int32_t main() {

	faster_io
	// file_io_cf

	string s, t;
	cin >> s >> t;

	int ans = INT_MAX;



	loopi(s.length() - t.length() + 1) {

		int score = 0;

		for(int j = 0; j<t.length(); j++ ){
			if(t[j] != s[i+j]){
				score++;
			}
		}

		ans = min(ans, score);

	}

	O(ans);
	
	return 0;
}

Measured memory_bytes: 3652
import 'dart:io';

main(List<String> args) {
  List NK = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  int N = NK[0];
  int K = NK[1];
  int ans = 1;
  int tmp = 1;
  int mod = 1000000007;
  for (var i = 1; i < N + 1; i++) {
    tmp = tmp - (i - 1) + N - (i - 1);
    if (i >= K) {
      ans += tmp;
      ans %= mod;
    }
  }
  print(ans);
}


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

int main() {
	//a + b + c + d = n
	// 0~9
	int n, cnt;
	while (cin >> n){
		cnt = 0;
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				for (int k = 0; k < 10; k++){
					for (int l = 0; l < 10; l++){
						if (i+j+k+l == n)	cnt++;
					}
				}				
			}	
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,w,d,mod;
vector<pair<int,int> >a;
main()
{
	cin>>n>>w>>d;
	mod=2*(w+d);
	for(int i=0;i<n;i++)
	{
		int x,y;char f;cin>>x>>y>>f;
		a.push_back(make_pair(
			(f=='E'?d+x+y:f=='W'?mod-x+d-y:f=='S'?d+x-y:mod-x-d+y)%mod,
			(f=='E'?mod-x-d+y:f=='W'?d+x-y:f=='S'?d+x+y:mod-x+d-y)%mod));
	}
	int ans=1e9;
	for(int i=0;i<n;i++)
	{
		int now=1,id=a[i].second;
		vector<pair<int,int> >m;
		for(int j=0;j<n;j++)
		{
			if(a[j].first<=id&&id<=a[j].second||a[j].second<a[j].first&&(id<=a[j].second||a[j].first<=id))continue;
			m.push_back(make_pair((a[j].second-id+mod)%mod,(a[j].first-id+mod)%mod));
		}
		sort(m.begin(),m.end());
		int p=-1;
		for(int j=0;j<m.size();j++)
		{
			if(p<m[j].second)
			{
				p=m[j].first;
				now++;
			}
		}
		ans=min(ans,now);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <cmath>
using namespace std;
int main() {
  int n, s = 0;
  cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; i++) {
    cin >> a[i];
    s += a[i];
  }
  cout << s-n << endl;

}

Measured memory_bytes: 3216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String base;
		String comparison;
		
		try {
			base = br.readLine();
			comparison = br.readLine();
			
			Inversions(base, comparison, br);
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}

	public static void Inversions(String base, String comparison,  BufferedReader br){ 
		StringBuilder sb = new StringBuilder();
		int length = base.length() - comparison.length();
		String 	container;
		int ans_num = 0;
		int[] ans = new int[1000000];
		
		for(int i = 0; i <= length ; i ++ ) {
			container = base.substring( i, i + comparison.length() );
			if( container.equals(comparison) ) {
				ans[ans_num] = i;
				ans_num ++;
			}
		}
		
		for(int i = 0; i <ans_num; i++){;
			sb.append(ans[i] + "\n");
		}
		 
		System.out.print(sb);
	}
}


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

int n, m;
bool edge[55][55];
bool visited[55];

void dfs(int s) {
	visited[s] = true;
	for (int i = 1; i <= n; i++) {
		if (i != s && visited[i] == false && edge[s][i] == true) {
			dfs(i);
		}
	}
}

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

	int a, b;
	vector<pair<int,int>> P(m);
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		edge[a][b] = true;
		edge[b][a] = true;
		P[i].first = a;
		P[i].second = b;
	}
	int cnt = 0;
	for (int i = 0; i < m; i++) {
		a = P[i].first;
		b = P[i].second;
		edge[a][b] = false;
		edge[b][a] = false;
		dfs(1);
		bool flag = false;
		for (int j = 1; j <= n; j++) {
			if (visited[j]==false)
				flag = true;
		}
		if (flag) cnt++;
		edge[a][b] = true;
		edge[b][a] = true;
		for (int j = 1; j <= n; j++) {
			visited[j] = false;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b= int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());
            int bus = Math.Min(a, b);
            int densha = Math.Min(c, d);

            Console.WriteLine(bus + densha);
            ;
        }
    }
}


Measured memory_bytes: 13140
import sys

def main(inp):
    n,m=map(int,next(inp).split())
    
    count=[0 for _ in range(m)]
    
    for i in range(n):
        result=list(map(int,next(inp).split()))
        for j in range(1,len(result)):
            count[result[j]-1]+=1

    ans=0
    for i in range(m):
        if(count[i]==n):
            ans+=1
    
    return ans
    
print(main(sys.stdin))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    CIN(A);CIN(B);CIN(C);
    I v;
    v.push_back(A);
    v.push_back(B);
    v.push_back(C);
    if(count(ALL(v),5) == 2 && count(ALL(v),7) == 1){
        COUT("YES");
    }else{
        COUT("NO");
    }
    return 0;
}




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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << (b)/c-(a-1)/c << endl;
}

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

using namespace std;

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

template<class T>
map<T,int> prime_factor(T n){
  map<T,int> ret;
  for(T i=2; i*i<=n; ++i){
    while(n%i == 0){
      n /= i;
      ++ret[i];
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
  int N;
  cin >> N;
  cout << N << ":";
  for(auto p : prime_factor<int>(N)) {
    while(p.second--) cout << " " << p.first;
  }
  cout << endl;
}


Measured memory_bytes: 3076
using System;

namespace AOJ.ALDS
{
    public class SelectionSort
    {
        public static void Main()
        {
            int count = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Trim().Split(' ');

            int[] ar = new int[count];
            for (int i = 0; i < count; i++) { ar[i] = int.Parse(input[i]); }

            // ソート処理
            int change = 0;
            for (int i = 0; i < count - 1; i++)
            {
                // 最小値候補の初期化
                int minj = i;
                // 位置[i + 1]から位置[count -1]の中で最小の値を探す
                for (int j = i + 1; j < count; j++)
                {
                    if (ar[j] < ar[minj]) { minj = j; }
                }
                // 最小値候補が変更されていたら値を交換
                if (i != minj)
                {
                    int tmp = ar[i];
                    ar[i] = ar[minj];
                    ar[minj] = tmp;

                    change++;
                }
            }

            // 出力
            string output = "";
            foreach (var i in ar) { output += i.ToString() + " "; }
            output = output.Trim();
            Console.WriteLine(output);
            Console.WriteLine(change);
        }
    }
}

Measured memory_bytes: 5652
import std.stdio;
import std.string;
import std.conv;

void main()
{
	auto input = split( readln() );
	int sup = to!int(input[1]), inf = to!int(input[0]);
	
	int i = inf;
	int cnt = 0;
	while (i <= sup) {
		int n1 = i % 10;
		int n2 = (i % 100 - n1) / 10;
		int n3 = (i % 1000 - 10 * n2 - n1) / 100;
		int n4 = (i % 10000 - 100 * n3 - 10 * n2 - n1) / 1000;
		int n5 = (i - 1000 * n4 - 100 * n3 - 10 * n2 - n1) / 10000;
		if (n1 == n5 && n2 == n4) { cnt += 1; }
		i+=1;
	}
	writeln(cnt);
	
}

Measured memory_bytes: 380