akhauriyash/Code-Regression huggingface dataset:
N,D = map(int,input().split())
XY = [tuple(map(int,input().split())) for i in range(N)]

import sys
sys.setrecursionlimit(10**8)
class Scc:
    def __init__(self,n):
        self.n = n
        self.edges = []

    def add_edge(self,fr,to):
        assert 0 <= fr < self.n
        assert 0 <= to < self.n
        self.edges.append((fr, to))

    def scc(self):
        csr_start = [0] * (self.n + 1)
        csr_elist = [0] * len(self.edges)
        for fr,to in self.edges:
            csr_start[fr + 1] += 1
        for i in range(1,self.n+1):
            csr_start[i] += csr_start[i-1]
        counter = csr_start[:]
        for fr,to in self.edges:
            csr_elist[counter[fr]] = to
            counter[fr] += 1

        self.now_ord = self.group_num = 0
        self.visited = []
        self.low = [0] * self.n
        self.ord = [-1] * self.n
        self.ids = [0] * self.n
        def _dfs(v):
            self.low[v] = self.ord[v] = self.now_ord
            self.now_ord += 1
            self.visited.append(v)
            for i in range(csr_start[v], csr_start[v+1]):
                to = csr_elist[i]
                if self.ord[to] == -1:
                    _dfs(to)
                    self.low[v] = min(self.low[v], self.low[to])
                else:
                    self.low[v] = min(self.low[v], self.ord[to])
            if self.low[v] == self.ord[v]:
                while 1:
                    u = self.visited.pop()
                    self.ord[u] = self.n
                    self.ids[u] = self.group_num
                    if u==v: break
                self.group_num += 1
        for i in range(self.n):
            if self.ord[i] == -1: _dfs(i)
        for i in range(self.n):
            self.ids[i] = self.group_num - 1 - self.ids[i]

        groups = [[] for _ in range(self.group_num)]
        for i in range(self.n):
            groups[self.ids[i]].append(i)
        return groups

class TwoSat:
    def __init__(self,n=0):
        self.n = n
        self.answer = []
        self.scc = Scc(2*n)

    def add_clause(self, i:int, f:bool, j:int, g:bool):
        assert 0 <= i < self.n
        assert 0 <= j < self.n
        self.scc.add_edge(2*i + (not f), 2*j + g)
        self.scc.add_edge(2*j + (not g), 2*i + f)

    def satisfiable(self):
        g = self.scc.scc()
        for i in range(self.n):
            if self.scc.ids[2*i] == self.scc.ids[2*i+1]: return False
            self.answer.append(self.scc.ids[2*i] < self.scc.ids[2*i+1])
        return True

    def get_answer(self):
        return self.answer

ts = TwoSat(N)
for i in range(N-1):
    xi,yi = XY[i]
    for j in range(i+1,N):
        xj,yj = XY[j]
        if abs(xi - xj) < D:
            ts.add_clause(i, False, j, False)
        if abs(xi - yj) < D:
            ts.add_clause(i, False, j, True)
        if abs(yi - xj) < D:
            ts.add_clause(i, True, j, False)
        if abs(yi - yj) < D:
            ts.add_clause(i, True, j, True)
if not ts.satisfiable():
    print('No')
    exit()
print('Yes')
ans = []
for b,(x,y) in zip(ts.get_answer(), XY):
    if b:
        ans.append(x)
    else:
        ans.append(y)
print(*ans, sep='\n')

Measured memory_bytes: 10080
#include<iostream>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 100010;
const int inf = (1<<20);
int m[N];
int cost[N];

int solve(int n){
  rep(i,N)cost[i] = inf;
  deque<int> Q;
  Q.push_back(0);
  cost[0] = 0;
  while(!Q.empty()){
    int now = Q.front();Q.pop_front();
    if (now >= n-1)return cost[now];//ÂÃªÂÂÂANÂÃÂlÂÃÂAÂSÂ[ÂÂ+6ÂÃ¦ÂÃ¨ÂÃ¥ÂÂ«ÂÂ¢ÂÃÂÃÂZÂOÂÃ©ÂÂ±ÂÃÂÃÂÃÂÂ¢ÂÃÂvÂÂ¤ÂB
    if (m[now] != 0){
      int next = now + m[now];
      int nec  = cost[now];
      if (cost[next] > nec){
	cost[next] = nec;
	Q.push_front(next);
      }
    }else if (m[now] == 0){
      REP(i,1,7){
	int next = now + i;
	int nec  = cost[now] + 1;
	if (cost[next] > nec){
	  cost[next] = nec;
	  Q.push_back(next);
	}
      }
    }
  }
  return 0;
}

main(){
  int n;
  while(cin>>n && n){
    rep(i,n)cin>>m[i];
    cout << solve(n) << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld double
#define mp make_pair
#define vl vector<ll> 
#define ll long long int
#define pl pair<ll, ll>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
ll fact[(ll)(1e6+100)];
ll a, b, n;
ll power(ll a, ll b)
{
    if(b==0)
    return 1%MOD;
    if(b%2==1)
    return a*(power(a, b-1))%MOD;
    ll pow2=power(a, b/2);
    return pow2*pow2%MOD;
}
void solve()
{
    ll n, k;
    cin>>n>>k;
    vl cost(n, INT_MAX);
    forr(i, n)
    cin>>cost[i];
    if(n==0||n==1)
    {
        cout<<0;
        return;
    }
    vl dp(n, INT_MAX);
    dp[0]=0;
    dp[1]=abs(cost[1]-cost[0]);
    for(ll i=2; i<n; i++)
    {
        for(ll j=1; j<=k; j++)
        {
            if(i-j>=0)
            {
                dp[i]=min(dp[i], dp[i-j]+abs(cost[i]-cost[i-j]));
            }
            else break;
        }
    }
    cout<<dp[n-1];
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

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

int main(){
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for(int i=0;i<3;i++){
        if(s.at(i)==t.at(i))ans++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3584
n = int(input())
P = input().split()
P = [int(n) for n in P]
A = 0
for i in range(1,n-1):
    if (P[i-1]<P[i] and P[i]<P[i+1])or(P[i-1]>P[i] and P[i]>P[i+1]):
        A += 1
print(A)

Measured memory_bytes: 3060
import java.util.Scanner;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		try {
		    Scanner sc = new Scanner(System.in);
		    String s,t;
		    int c,m,i,j;
		    s=sc.nextLine();
		    t=sc.nextLine();
		    m=2147483647;
		    c=0;
		    for(i=0;i<=(s.length()-t.length());i++)
		    {
		        c=0;
		      for(j=i;j<(i+t.length());j++)
		        {
		        if(s.charAt(j)!=t.charAt(j-i))
		          c++;
		        }
		       
		       if(c<m)
		        m=c;
		    }
		    System.out.println(m);
		    
		} catch(Exception e) {
		}
	}
}


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

int main(){
    priority_queue<int> pq;
    string s;
    cin>>s;

    while(s!="end"){
        
        if(s=="insert"){
            int a;
            cin>>a;
            pq.push(a);
        }
        else if(s=="extract"){
            cout<<pq.top()<<endl;
            pq.pop();
        }
        cin>>s;
    }
    return 0;
}


Measured memory_bytes: 6940
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vi g[100010];

void bfs(int s, vi& dist){
    queue<int> Q;
    Q.push(s);
    dist[s] = 0;
    while(!Q.empty()){
        int v = Q.front();
        Q.pop();
        for(auto u: g[v]){
            if(dist[u] != -1) continue;
            dist[u] = dist[v] + 1;
            Q.push(u);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    int N, U, V;
    cin >> N >> U >> V;
    rep(i,N){
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vi distu(N+1, -1);
    vi distv(N+1, -1);
    bfs(U, distu);
    bfs(V, distv);

    int ans = -1;
    rep(i,N+1){
        if(distu[i] < distv[i]) ans = max(ans, distv[i]);
    }

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


Measured memory_bytes: 6656
//#include<iostream>
//#include<vector>
//#include<cmath>
//#include<algorithm>
//#define N 300100
//using namespace std;
//
//int used[N];
//int cmp(int a, int b)
//{
//    return a > b;
//}
//int main()
//{
//    int n, i, j, k;
//    cin>>n;
//    vector<int>v[N];
//    for(i = 1; i <= n; i++)
//    {
//        for(j = 1; j <= sqrt(i); j++)
//        {
//            if(i % j == 0)
//            {
//                v[i].push_back(j);
//                if(sqrt(i) != (int)sqrt(i))
//                    v[i].push_back(i/j);
//            }
//        }
//        sort(v[i].begin(), v[i].end(), cmp);
//    }
//    int ans = 0;
//    int by;
//    for(i = 1; i < n; i++)
//    {
//        for(j = 1; j * i < n; j++)
//        {
//            by = n - i*j;
//            int s = v[by].size()
//            for(k = 0; k < s; k++)
//            {
//                if(v[by][k] <= i)
//                    break;
//                if(used[v[by][k]] != i)
//                {
//                    used[v[by][k]] = i;
//                    ans++;
//                }
//            }
//        }
//    }
//    cout<<ans<<endl;
//    return 0;
//
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

int main()
{
    string s;
    cin>>s;
    int l = s.size();
    if (s[l-1] == s[0])
    {
        if (l % 2 == 0)
            cout<<"First"<<endl;
        else
            cout<<"Second"<<endl;
    }
    else
    {
        if (l % 2 == 0)
            cout<<"Second"<<endl;
        else
            cout<<"First"<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
import itertools

n = int(input())
s = [input() for _ in range(n)]
m = a = r = c = h = 0
ans = 0

for name in s:
    if name[0] == 'M':
        m += 1

    elif name[0] == 'A':
        a += 1

    elif name[0] == 'R':
        r += 1

    elif name[0] == 'C':
        c += 1

    elif name[0] == 'H':
        h += 1

march = [m, a, r, c, h]

for v in itertools.combinations(march, 3):
    ans += v[0] * v[1] * v[2]

print(ans)


Measured memory_bytes: 9776
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	string str1,str2;
	cin>>str1>>str2;
	ll len1,len2;
	len1=str1.length();
	len2=str2.length();
	stack<char> s;
	ll arr[len1+1][len2+1],i,j;
	for(i=0;i<=len1;i++)
	{
		for(j=0;j<=len2;j++)
		{
			if(i==0 || j==0)
				arr[i][j]=0;
			else
			{
				if(str1[i-1]==str2[j-1])
					arr[i][j]=1+arr[i-1][j-1];
				else
					arr[i][j]=max(arr[i-1][j],arr[i][j-1]);
			}
		}
	}
	//cout<<arr[len1][len2]<<endl;
	i=len1;
	j=len2;
	/*for(i=1;i<=len1;i++)
	{
		for(j=1;j<=len2;j++)
			cout<<arr[i][j]<<" ";
		cout<<endl;
	}*/
	while(arr[i][j])
	{
		if(str1[i-1]==str2[j-1])
		{
			s.push(str1[i-1]);
			i--;
			j--;
		}
		else
		{
			if(arr[i-1][j]>=arr[i][j-1])
				i--;
			else
				j--;
		}
		//cout<<i<<" "<<j<<endl;
	}
	while(!s.empty())
	{
		cout<<s.top();
		s.pop();
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 70656
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a*b % 2 != 0){
            System.out.println("Odd");
        }else{
            System.out.println("Even");
        }

    }
}

Measured memory_bytes: 22740
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    int n, m, x;
    cin >> n >> m >> x;
    int* a = new int[n];

    for (int i = 0; i < m; ++i) cin >> a[i];

    int b = 0, s = 0;
    for (int i = 0; i < m; ++i) {
        if (a[i] > x) b++;
        else s++;
    }

    cout << (b > s ? s : b);
    return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

# input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    A = list(map(int, input().split()))

    a = 0.0
    for i in range(N):
        a += 1 / float(A[i])
    print(1.0/a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = (1'000'000'000 + 7);

int main()
{
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int mod=1000000007;

int binpow(int a, int b)
{
	int res=1;
	b%=(mod-1);
	while(b)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		b>>=1;
		a=(a*a)%mod;
	}
	return res;
}

int h, w, t;

signed main()
{
	cin>>h>>w>>t;
	int vl=__gcd(h, t);
	int vl1=__gcd(w, t);
	int vl2=__gcd(h/vl, w/vl1);
	int ssm=binpow(2, h/vl)+binpow(2, w/vl1)+binpow(2, vl2)-3;
	cout<<binpow(ssm, vl*vl1);
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    UnionFind(int N) : par(N),siz(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
             par[i] = i;
             siz[i] = 1;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        // merge technique（小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

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

signed main(){
    gearup;
    ll n,m,k; cin >> n >> m >> k;
    vl a(m),b(m),c(k),d(k);
    vector<set<ll> > s(n);
    //UnionFindのサイズから友達の数と、ブロックリストの数を引けば良い
    UnionFind uf(n);
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        uf.unite(a[i],b[i]);
        s[a[i]].insert(b[i]);
        s[b[i]].insert(a[i]);
    }

    rep(i,k){
        cin>>c[i]>>d[i];
        c[i]--;d[i]--;
        if(uf.same(c[i],d[i]) == false)continue;//元々同じ木に属さないものは無視
        s[c[i]].insert(d[i]);
        s[d[i]].insert(c[i]);
    }

    rep(i,n){
        if(i) cout << " ";
        cout << uf.size(i) - s[i].size() - 1; //自分を引くため 1
    }
    cout << endl;
}



Measured memory_bytes: 28544
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
class modBinomial{
	long inv(long x){// p is a prime
		if(x==0) return 0;
		int i=0;long res=1;
		while((p-2)>=(1<<i)){
			if((p-2)&(1<<i)) (res*=x)%=p;
			i++; x=x*x%p;
		}return res;
	}
public:
	const long p=mod;
    long modfact(long n){//n! mod p
	    if(n>=p) return 0;
        long res=1;
	    rep(i,1,n+1) (res*=i)%=p;
	    return res;
    }
    long modperm(long n,long r){//nPr mod p
	    if(n-r>=p||r%p>n%p) return 0;
	    long res=1;
	    rep(i,n-r+1,n+1) (res*=i)%=p;
	    return res;
    }
    long modcomb(long n,long r){//nCr mod p
	    return (modperm(n,r)*inv(modfact(r)))%p;
    }
};
int main(){
	int X,Y;cin>>X>>Y;
	if((2*Y-X)%3!=0||2*X<Y||2*Y<X){ cout<<0<<endl; return 0; }
	int a=(-X+2*Y)/3;int b=(2*X-Y)/3;
	modBinomial mb;
	cout<<mb.modcomb(a+b,b)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	string s, t;
	cin >> s >> t;
	ll n = s.size(), m = t.size();
	ll ans = n;
	for (ll i = 0; i < n - m + 1; i++) {
		ll subans = 0;
		for (ll j = 0; j < m; j++) {
			if (s[i + j] != t[j]) subans++;
		}
		ans = min(ans, subans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

template <typename T>
struct Graph {
    int V, E;
    struct Edge {
        int from, to;
        T cost;
    };
    vector<vector<Edge>> edge;
    vector<vector<T>> dist;
    vector<Edge> es;

    Graph(int V, int E) : V(V), E(E) {
        edge.assign(V, vector<Edge>(0));
        dist.assign(V, vector<T>(0));
    }

    void input(bool is_direct, bool inputc, bool index0 = false) {
        int a, b;
        T c = 0;
        for (int i = 0; i < E; i++) {
            cin >> a >> b;
            if (inputc) cin >> c;
            if (!index0) a--, b--;
            edge[a].push_back((Edge){a, b, c});
            es.push_back((Edge){a, b, c});
            if (!is_direct) {
                edge[b].push_back((Edge){b, a, c});
                es.push_back((Edge){b, a, c});
            }
        }
        if (!is_direct) E *= 2;
    }

    void add_edge(int from, int to, T cost, bool is_direct) {
        edge[from].push_back({from, to, cost});
        es.push_back({from, to, cost});
        if (!is_direct) {
            edge[to].push_back({to, from, cost});
            es.push_back({to, from, cost});
            E++;
        }
        E++;
    }

    vector<bool> visited;
    vector<int> nodes;
    vector<vector<int>> ans;

    bool build_loop(int v, int r = -1) {
        if (v == r) return true;
        if (visited[v]) return false;
        if (r == -1) r = v;
        visited[v] = true;

        for (const auto& e : edge[v]) {
            int to = e.to;
            if (build_loop(to, r)) {
                nodes.push_back(v);
                return true;
            }
        }
        return false;
    }

    bool detect_loop(int r) {
        nodes.resize(0);
        visited.assign(V, false);
        return build_loop(r);
    }

    void minloop() {
        unordered_map<int, int> mp;
        reverse(nodes.begin(), nodes.end());
        for (int i = 0; i < nodes.size(); i++) mp[nodes[i]] = i;
        vector<int> pre(1, nodes[0]);
        for (int i = 0; i < nodes.size() - 1;) {
            int v = nodes[i];
            for (const auto& e : edge[v]) {
                int to = e.to;
                if (mp.find(to) == mp.end()) continue;
                i = max(i, mp[to]);
            }
            pre.push_back(nodes[i]);
        }
        ans.push_back(pre);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    Graph<int> g(N, M);
    g.input(true, false);
    for (int i = 0; i < N; i++)
        if (g.detect_loop(i)) g.minloop();

    if (g.ans.size() == 0)
        cout << -1 << endl;
    else {
        int min_index = -1, min_size = N + 1;
        for (int i = 0; i < g.ans.size(); i++)
            if (g.ans[i].size() < min_size) {
                min_index = i;
                min_size = g.ans[i].size();
            }
        cout << min_size << endl;
        for (int j = 0; j < min_size; j++) cout << g.ans[min_index][j] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 4352
#-*-coding:utf-8-*-

def main():
    a, b = list(map(int, input().split()))

    east_tree_hight = 0
    for i in range(1, b-a+1):
        east_tree_hight += i

    snow_hight = east_tree_hight - b
    print(snow_hight)


if __name__ == '__main__':
    main()

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

int main() {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        if ((a+b) > (c+d)){
                cout << "Left" << endl;
        } else if ((a+b) == (c+d)){
                cout << "Balanced" << endl;
        } else {
                cout << "Right" << endl;
        }
        return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int w = sc.nextInt();
			int d = sc.nextInt();
			if(w == 0 && d == 0)break;
			else calc(w, d);
			
		}
	}
	public void calc(int w, int d){
		int[] frontH = new int[w];
		int[] sideH = new int[d];
		
		for(int i = 0; i < w; i++){
			int f = sc.nextInt();
			frontH[i] = f;
		}
		for(int i = 0; i < d; i++){
			int s = sc.nextInt();
			sideH[i] = s;
		}
		
		//calc
		for(int i = 0; i < d; i++){
			for(int j = 0; j < w; j++){
				if(sideH[i] == frontH[j]) {
					frontH[j] = 0;
					break;
				}
			}
		}
		
		int sum = 0;
		for(int i = 0; i < w; i++){
			sum = sum + frontH[i];
		}
		for(int i = 0; i < d; i++){
			sum = sum + sideH[i];
		}
		System.out.println(sum);
	}

	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;

int main(){
    int a,b,c,d;
    std::cin >> a>>b>>c>>d;
    for(;;){
        c-=b;
        if(c<=0){
            std::cout << Yes << std::endl;
            break;
        }
        a-=d;
        if(a<=0){
            std::cout << No << std::endl;
            break;
        }
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define R(x) (x)=read()
const int N = 100005;
char c[N];
int a[N],b[N];
int n,m,T;
using namespace std;
int gcd(int x,int y) {
	if(x%y==0) return y;
	else return gcd(y,x%y);
}
int read() {
	int x=0;char c=getchar();
	while((c<48||c>57)&&c!='-') c=getchar();
	if(c=='-') {c=getchar();while(c>=48&&c<=57) x=x*10-c+48,c=getchar();}
	while(c>=48&&c<=57) x=x*10+c-48,c=getchar();
	return x;
}
void init() {
	
}
int sum,l,r;
void solve() {
	R(n);
	for(int i=1;i<=n;i++) {
		R(l),R(r);
		sum+=r-l+1;
		
	}
	cout<<sum;
	
	
	
}
int main() {
	init();
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const int N = 100005;
#define ll long long
int cmp(int a,int b){
	return a>b;
}	
int gcd(int x, int y)
{
    while(y^=x^=y^=x%=y);
    return x;
}
int main(){	
	string s,t;
	cin >> s >> t;
	int f=0;
	for(int i=0;i<s.size();i++){
		if(s[i] != t[i]) f++;
	}
	cout <<f <<endl;
	return 0;
}




Measured memory_bytes: 3832
import sys
input = sys.stdin.readline
import random
import copy
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(d)]
ans = []
now = [0]*26
for i in range(d):
    no = -1
    score = -10**10
    for j in range(26):
        count = s[i][j]
        for k in range(26):
            if j == k:
                continue
            count -= (i+1-now[k])*c[k]
        if count > score:
            no = j
            score = count
    ans.append(no+1)
    now[no] = i+1
score = [0]*26
for i in range(d):
    
    now[ans[i]-1] = i+1
    ind = ans[i]-1
    for j in range(26):
        if j == ind:
            score[j] += s[i][ind]
        else:
            x = (i+1-now[j])*c[j]
            score[j]-= x
SUM = sum(score)
roop = 0
while roop < 1000:
    x = random.randint(1,d)
    y = random.randint(1,26)
    if ans[x-1] == y:
        continue
    be = ans[x-1]
    be -= 1
    now1 =  0
    now2 = 0
    nex = copy.deepcopy(ans)
    nex[x-1] = y
    y -= 1
    count1 = 0
    count2 = 0
    for j in range(d):
        if be == nex[j]-1:
            now1 = j+1
            count1 +=s[j][be]
        else:
            count1 -= (j+1-now1)*c[be]
        if y == nex[j]-1:
            now2 = j+1
            count2 +=s[j][y]
        else:
            count2 -= (j+1-now2)*c[y]
 
    count = SUM + count1+count2-score[be]-score[y]
    
    if count > SUM:
        score[be] = count1
        score[y] = count2
        ans = nex
        SUM = count
    roop += 1
for i in ans:
    print(i)


Measured memory_bytes: 81352
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;

template<int N, typename T, T M>
struct ModFact {
    T fact[N + 1];
    T ifact[N + 1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i = 0; i < N; ++i)
            fact[i + 1] = (fact[i] * (i + 1)) % M;
        ifact[N] = power(fact[N], M - 2);
        for (int i = N - 1; i >= 0; --i)
            ifact[i] = (ifact[i + 1] * (i + 1)) % M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b > 0) {
            if (b & 1) r = (r * a) % M;
            a = (a * a) % M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        return (((fact[n] * ifact[r]) % M) * ifact[n - r]) % M;
    }
};
 
ModFact<200000, ll, MOD> fact;

int main() {
    ll H, W, A, B, ans = 0;
    ios::sync_with_stdio(false);
    cin.tie(0);
	cin >> H >> W >> A >> B;
	const ll c1 = H-1-A+B;
	const ll c2 = W-1-B+A;
	while (A < H && B < W)
      ans=(ans+((fact.comb(c1,B++)*fact.comb(c2,A++))%MOD))%MOD;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    s = input()
    K = int(input())

    s_l = sorted(set(s))
    ans = set()
    cnt = 0
    for i in s_l:
        ans.add(i)
        cnt += 1
        if cnt >= K:
            break
        cur = set()
        for j in range(len(s)):
            if not s[j] in cur or s[j] == i:
                cur.add(s[j:min(j+5,len(s))])
        for c in cur:
            cnt += 1
        for c in cur:
            for k in range(5):
                ans.add(c[:min(k+1,len(c))])
        if cnt >= K:
            break
        print(ans)
    print(sorted(ans)[K-1])
if __name__ == "__main__":
    main()

Measured memory_bytes: 41328
/*
Author: yww
Language: C++
Mail: weeerrr720@qq.com
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<functional>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<assert.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
template <class T>
int upmin(T &a, const T &b){return (b<a?a=b,1:0);}
template <class T>
int upmax(T &a, const T &b){return (b>a?a=b,1:0);}
namespace io
{
	const int SIZE=(1<<20)+1;
	char ibuf[SIZE],*iS,*iT;
	char obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1;
	int getc()
	{
		(iS==iT?iS=ibuf,iT=ibuf+fread(ibuf,1,SIZE,stdin):0);
		return iS==iT?EOF:*(iS++);
	}
	int f;
	char c;
	template <class T>
	void get(T &x)
	{
		f=1;
		for(c=getc();(c<'0'||c>'9')&&c!='-';c=getc());
		(c=='-'?f=-1,c=getc():0);
		x=0;
		for(;c>='0'&&c<='9';c=getc())
			x=x*10+c-'0';
		x*=f;
	}
	void flush()
	{
		fwrite(obuf,1,oS-obuf,stdout);
		oS=obuf;
	}
	void putc(char x)
	{
		*(oS++)=x;
		if(oS==oT)
			flush();
	}
	int a[55],t;
	template <class T>
	void put(T x)
	{
		if(!x)
			putc('0');
		x<0?putc('-'),x=-x:0;
		while(x)
		{
			a[++t]=x%10;
			x/=10;
		}
		while(t)
			putc(a[t--]+'0');
	}
	void space()
	{
		putc(' ');
	}
	void enter()
	{
		putc('\n');
	}
	struct flusher
	{
		~flusher()
		{
			flush();
		}
	}
	io_flusher;
}
ll query(ll x,ll y,ll z)
{
	return min(abs(x-y)+abs(y-z),abs(x-z)+abs(y-z));
}
const int N=100010;
ll a[N],b[N];
int n,m,q;
ll x;
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=m;i++)
		scanf("%lld",&b[i]);
	for(int i=1;i<=q;i++)
	{
		scanf("%lld",&x);
		int t1=lower_bound(a+1,a+n+1,x)-a;
		int t2=lower_bound(b+1,b+m+1,x)-b;
		ll ans=0x7fffffffffffffffll;
		if(t1<=n)
		{
			if(t2<=m)
				ans=min(ans,query(x,a[t1],b[t2]));
			if(t2>1)
				ans=min(ans,query(x,a[t1],b[t2-1]));
		}
		if(t1>1)
		{
			if(t2<=m)
				ans=min(ans,query(x,a[t1-1],b[t2]));
			if(t2>1)
				ans=min(ans,query(x,a[t1-1],b[t2-1]));
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int a,b,c;
    cin>>a>>b>>c;
    if (a==1&&b==0&&c==0) {
        cout<<"Close"<<endl;
    } else if (a==0&&b==1&&c==0) {
        cout<<"Close"<<endl;
    } else if (a==1&&b==1&&c==0) {
        cout<<"Open"<<endl;
    } else if (a==0&&b==0&&c==1) {
        cout<<"Open"<<endl;
    } else if (a==0&&b==0&&c==0) {
        cout<<"Close"<<endl;
    }
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

class UnionFind{
  vi p,r;
public:
  UnionFind(int n):p(n,-1),r(n,0){ }
  int find(int x){ return (p[x]<0)?x:(p[x] = find(p[x])); }
  bool same(int x,int y){return find(x)==find(y);}
  void unite(int x,int y){
    x = find(x); y = find(y);
    if(x==y)return;

    if(r[x] < r[y])p[x] = y;
    else p[y] = x;
    if(r[x] == r[y])r[x]++;
  }
};

inline void updateIds(int x,  unordered_map<int, int>& id,
	       unordered_map<int, int>& inv_id) {
  if (id.count(x) == 0) {
    int new_id = id.size();
    id[x] = new_id;
    inv_id[new_id] = x;
  }
}

vector<vi> getConnectedComponents(const vector<pii>& edges) {
  unordered_map<int, int> id, inv_id;
  for (pii edge : edges) {
    updateIds(edge.first, id, inv_id);
    updateIds(edge.second, id, inv_id);
  }

  UnionFind uf(id.size());
  for (pii edge : edges) {
    uf.unite(id[edge.first], id[edge.second]);
  }

  unordered_map<int, vi> components;
  rep(i, id.size()) {
    components[uf.find(i)].eb(inv_id[i]);
  }

  vector<vi> res;
  for (auto component : components) {
    res.eb(component.second);
  }
  return res;
}

int solve(int s, int t, const vector< vector<pii> >& graph) {
  vi dist(graph.size(), INF);
  deque<int> q;
  dist[s] = 0;
  q.push_back(s);

  while(not q.empty()) {
    int v = q.front(); q.pop_front();
    for (pii e : graph[v]) {
      int u = e.first, c = e.second;
      if (dist[u] < INF) continue;
      if (c == 0) {
	dist[u] = dist[v];
	q.push_front(u);
      } else {
	dist[u] = dist[v] + c;
	q.push_back(u);
      }
    }
  }

  return dist[t] < INF ? dist[t] : -1;
}

int main(){
  int n, m;
  cin >> n >> m;
  vector< vector<pii> > g(n);
  unordered_map<int, vector<pii>> colored_edges;
  rep(i, m) {
    int p, q, c;
    cin >> p >> q >> c;
    p--; q--;
    colored_edges[c].eb(p, q);
  }

  int id = n;
  for (const auto& entry : colored_edges) {
    const vector<pii>& edges = entry.second;
    vector<vi> components = getConnectedComponents(edges);
    for (const auto& component : components) {
      g.push_back(vector<pii>());
      for (int u : component) {
	g[u].eb(id, 1);
	g[id].eb(u, 0);
      }
      id++;
    }
  }
  
  cout << solve(0, n-1, g) << endl;
}


Measured memory_bytes: 38096
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=[I() for _ in range(n)]

  if l[0]!=0:
    return -1

  ans=0
  st=l[0]
  for x in l[1:]:
    if st+1<x:
      return -1

    if x==st:
      ans+=x

    elif st<x:
      ans+=1

    elif st>x:
      ans+=x

    st=x

  return ans

# main()
print(main())


Measured memory_bytes: 19916
/**
 *    author:  tourist
 *    created: 03.11.2019 18:31:20       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int) s.size();
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    if (s[i] == '<') {
      a[i + 1] = max(a[i + 1], a[i] + 1);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '>') {
      a[i] = max(a[i], a[i + 1] + 1);
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 2844
#include <cstdio>

int main(){
    char str_in[4];
    int A, B, C, D;
    scanf("%s", str_in);

    int in1 = str_in[0] - '0';
    int in2 = str_in[1] - '0';
    int in3 = str_in[2] - '0';
    int in4 = str_in[3] - '0';

    int in = in1 * 1000 + in2 * 100 + in3 * 10 + in4;

    A = in / 1000;
    B = (in % 1000) / 100;
    C = (in % 100) / 10;
    D = in % 10;

    int sum;
    sum = A + B + C + D;

    int a[7];
    a[0] = B*2;
    a[1] = C*2;
    a[2] = D*2;
    a[3] = (B + C)*2;
    a[4] = (B + D)*2;
    a[5] = (C + D)*2;
    a[6] = (B + C + D)*2;

    int i;
    int ans = 100;
    int diff = sum - 7;
    for(i=0; i<7; i++){
        if(diff == a[i])
            ans = i;
    }


    if(ans == 0){
        printf("%d-%d+%d+%d=7\n", A, B, C, D);
    }else if(ans == 1){
        printf("%d+%d-%d+%d=7\n", A, B, C, D);
    }else if(ans == 2){
        printf("%d+%d+%d-%d=7\n", A, B, C, D);
    }else if(ans == 3){
        printf("%d-%d-%d+%d=7\n", A, B, C, D);
    }else if(ans == 4){
        printf("%d-%d+%d-%d=7\n", A, B, C, D);
    }else if(ans == 5){
        printf("%d+%d-%d-%d=7\n", A, B, C, D);
    }else if(ans == 6){
        printf("%d-%d-%d-%d=7\n", A, B, C, D);
    }else{
        printf("%d+%d+%d+%d=7\n", A, B, C, D);
    }

    return 0;
}


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

int main() {
  int K;
  cin >> K;
  string S;
  cin >> S;
  
  int len = S.size();
  
  if(len <= K) cout << S << endl;
  else{
    for(int i=0; i<K; i++) cout << S[i];
    cout << "..." << endl;
  }
}

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

#define REP(i,n,m) for(int i=n;i<m;i++)
#define REPR(i,n,m) for(int i=n;i>m;i--)
#define ALL(v) v.begin(),v.end()
#define elif else if
using ll=long long;

ll gcd(ll x,ll y){
    ll a;
    while(y!=0){
        a=x%y;
        x=y;
        y=a;
    }
    return x;
}

//lcm a*b/gcd(a,b)

/*----------template----------*/

int main(){
    ll h, cnt = 1, ans = 0;
    cin >> h;

    while(h > 0){
        h /= 2;
        ans += cnt;
        cnt *= 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
y = int(input())
 #this is a comment
ans = 0
 
for ai in range(a+1):
    for bi in range(b+1):
        for ci in range(c+1):
            amount = 500 * ai + 100 * bi + 50 * ci
            if amount == y:
                ans += 1
 
print(ans)

Measured memory_bytes: 3060
import java.util.*;    
    public class Main{
          public static void main(String []args){
            Scanner sc = new Scanner(System.in);
           int n =sc.nextInt();
            int a[] = new int[n];
            int k = sc.nextInt();
            for (int i=0; i<n; i++){
              a[i]=sc.nextInt();
            }
            Arrays.sort(a);
            int ans=0;
            for(int i=0; i<k; i++){
              ans+=a[i];
            }
            System.out.println(ans);
          }
         }

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

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

Measured memory_bytes: 3628
import math
import collections
import sys

#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

T,X=MI()
print(T/X)

Measured memory_bytes: 3316
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<string>
#define dint __int128
using namespace std;
#define kk putchar(32)
#define gc getchar()
#define fup(i,a,b) for(int i=a,i##e=b;i<=i##e;++i)
#define fdn(i,a,b) for(int i=a,i##e=b;i>=i##e;--i)
#define mem(a,b) memset(a,b,sizeof(a))
#define hh putchar(10)
#define ll long long
inline ll rrr(){ll x,f=1;char a;while((a=gc)<48||a>57)if(a==45)f=-1;
for(x=a^48;(a=gc)>47&&a<58;x=(x<<3)+(x<<1)+(a^48));return f*x;}
struct nnn{int x,y,z;};
void Main();

int main()
{
    Main();
    return 0;
}
int b[200004],a[200004];
void Main()
{
    int n,k;
    cin>>n>>k;
    fup(i,0,n-1)b[i]=rrr();
    sort(b,b+n);
//    fup(i,0,n-1)cout<<b[i]<<' ';hh;
    int p=0;
    fup(i,0,n-1){
        ++a[p];
        while(b[i]==b[i+1]){
            ++i;++a[p];
        }
        ++p;
    }
    sort(a,a+p);
//    fup(i,0,p-1)cout<<a[i]<<' ';hh;
    int ans=0;
    fup(i,0,p-k-1)ans+=a[i];
    cout<<ans;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a[3],b[3];
  cin>>a[0]>>a[1]>>a[2];
  cin>>b[0]>>b[1]>>b[2];
  if((a[0]==b[2])&&(a[1]==b[1])&&(a[2]==b[0])){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=100005;
int n,m,cnt;
vector<pii>edge[maxn*10],col[maxn*10];
int dist[maxn*10],f[maxn],in[maxn],id[maxn];

int Find(int x){
	return f[x]==x?x:f[x]=Find(f[x]);
}

void Union(int x,int y){
	x=Find(x);y=Find(y);
	if(x!=y)f[x]=y;
}

void Dij(){
	REP(i,cnt)dist[i]=INF;
	dist[1]=0;
	priority_queue<pii,vector<pii>,greater<pii> >q;
	q.push(mk(0,1));
	while(!q.empty()){
		pii x=q.top();
		q.pop();
		if(dist[x.se]<x.fi)continue;
		rep(i,edge[x.se].size()){
			pii y=edge[x.se][i];
			if(dist[x.se]+y.se<dist[y.fi]){
				dist[y.fi]=dist[x.se]+y.se;
				q.push(mk(dist[y.fi],y.fi));
			}
		}
	}
}

int main(){
	rep(i,maxn)f[i]=i;
	scanf("%d%d",&n,&m);
	rep(i,m){
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		col[c].push_back(mk(u,v));
		edge[u].push_back(mk(v,2));
		edge[v].push_back(mk(u,2));
	}
	cnt=n;
	REP(i,1000000){
		if(col[i].empty())continue;
		vector<int>occ;
		rep(j,col[i].size()){
			pii e=col[i][j];
			Union(e.fi,e.se);
			occ.push_back(e.fi);
			occ.push_back(e.se);
		}
		sort(occ.begin(),occ.end());
		occ.resize(unique(occ.begin(),occ.end())-occ.begin());
		rep(i,occ.size()){
			int x=occ[i];
			if(Find(x)==x)in[x]=++cnt;
		}
		rep(i,occ.size()){
			int x=occ[i];
			edge[in[Find(x)]].push_back(mk(x,1));
			edge[x].push_back(mk(in[Find(x)],1));
		}
		rep(i,occ.size())f[occ[i]]=occ[i];
	}
	Dij();
	if(dist[n]==INF)printf("-1");
	else printf("%d",dist[n]/2);
	return 0;
}

Measured memory_bytes: 75632
def b_buildings_are_colorful(N, K, A):
    import itertools
    combination = itertools.combinations(range(1, N), K - 1)
    ans = float('inf')
    for comb in combination:
        tmp = A[:]
        max_height = A[0]
        for k in range(1, N):
            if k in comb:
                if tmp[k] <= max_height:
                    tmp[k] = max_height + 1
            max_height = max(max_height, tmp[k])

        delta = 0
        for k in range(N):
            delta += tmp[k] - A[k]
        ans = min(ans, delta)
    return ans

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(b_buildings_are_colorful(N, K, A))

Measured memory_bytes: 3064