akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    H, W, K = map(int, readline().split())
    grid = []
    for _ in range(H):
        grid.append(list(readline().rstrip().decode()))
    #gridの状態をシミュレーションしない
    ans = 0
    for i in range(1<<H):
        for j in range(1<<W):
            cnt = 0
            for k in range(H):
                if (i>>k) & 1:
                    continue
                for l in range(W):
                    if (j>>l) & 1:
                        continue
                    if grid[k][l] == '#':
                        cnt += 1
            if cnt == K:
                ans += 1
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 73828
///https://agc020.contest.atcoder.jp/tasks/agc020_c?lang=en
///http://petr-mitrichev.blogspot.com/2018/01/
#include<bits/stdc++.h>
#define i64 long long
#define inf 1000000000000000000
using namespace std;

int ara[2001];
bitset<2001*2001>bset;//[2];
int main()
{
    int n;
    scanf("%d",&n);

    int sum=0,mx=0;
    for(int i=1; i<=n; i++)
        scanf("%d",&ara[i]);


  //  sort(ara+1,ara+n+1);

    for(int i=1; i<=n; i++)
    {
        sum+=ara[i];
        mx=max(mx,ara[i]);
    }

    int avg=(sum+2-1)/2, last=mx*n;

    bset[0]=1;
    for(int i=1; i<=n; i++)
        bset= bset | (bset<<ara[i]);


    for(int i=avg; i<=last; i++)
    {
        if(bset[i]==1)
        {
            printf("%d\n",i);
            return 0;
        }
    }


    return 0;
}


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

int main()
{
  int r, g, b;
  cin >> r >> g >> b;
  
  int sum;
  sum = 100 * r + 10 * g + b;

  if (0 == sum % 4)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
    
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>


using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define fs first
#define sc second

vector<int> x[101000], y[101000];
bool x_list[101000];
bool xc[101000], yc[101000];

P dfs(int xx, int yy){
    if(xc[xx] && yc[yy]){
        return P(0, 0);
    }
    P res = P(0, 0);
    if(!xc[xx]){
        xc[xx] = true;
        for(auto y2: x[xx]){
            P ret = dfs(xx, y2);
            res.fs += ret.fs;
            res.sc += ret.sc;
        }
        res.fs += 1;
    }
    if(!yc[yy]){
        yc[yy] = true;
        for(auto x2: y[yy]){
            P ret = dfs(x2, yy);
            res.fs += ret.fs;
            res.sc += ret.sc;
        }
        res.sc += 1;
    }
    return res;
}


int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        x[a].push_back(b);
        y[b].push_back(a);
    }

    ll res = 0;
    fill(xc, xc+101000, false);
    fill(yc, yc+101000, false);
    fill(x_list, x_list+101000, false);
    for(int i = 0; i < 101000; i++){
        if(!x[i].empty() && !yc[x[i][0]]){
            P ret = dfs(i, x[i][0]);
            res += ret.fs * ret.sc;
        }
    }

    cout << max(res - N, 0LL) << endl;

    return 0;
}


Measured memory_bytes: 12288
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N,K;
		N =sc.nextLong();
		K =sc.nextLong();
		long a= N-N/K*K;
		if (a>Math.abs(a-K)) {
			System.out.println(Math.abs(a-K));
		} else {
			System.out.println(a);
		}
	}
}

Measured memory_bytes: 23636
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_LEN 10

using namespace std;

bool is_acgt(char ch) {
    return ch == 'A' || ch == 'T' || ch == 'C' || ch == 'G';
}

int main(int argc, char **argv) {
    char str[MAX_LEN + 1];
    scanf("%s", str);

    int res = 0, cur = 0;
    bool sw = false;
    for(int i = 0; i < strlen(str); ++i) {
        if(is_acgt(str[i])) {
            if(sw) {
                cur++;
            } else {
                cur = 1;
                sw = true;
            }
            res = max(res, cur);
        } else {
            sw = false;
        }
    }
    printf("%d\n", res);
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

using mint = modint998244353;

int main(void){
    int n;
    cin >> n;
    n *= 2;
    map<int, int> mp;
    REP(i,n){
        mp[in()]++;
    }
    VI cnt;
    for (auto tmp : mp){
        cnt.push_back(tmp.second);
    }
    sort(ALL(cnt));
    priority_queue<P, vector<P>, greater<P> > que;
    vector<vector<mint>> polys;
    for (ll x : cnt){
        mint d = 1;
        vector<mint> p(1, 1);
        REP(i,x/2){
            ll t = (x - 2 * i) * (x - 2 * i - 1) / 2;
            d *= t;
            d /= (i + 1);
            p.push_back(d);
        }
        // a = convolution(a, p);
        que.push(make_pair(p.size(), polys.size()));
        polys.push_back(p);
    }
    while (que.size() > 1){
        int i, j;
        i = que.top().second;
        que.pop();
        j = que.top().second;
        que.pop();
        vector<mint> c = convolution(polys[i], polys[j]);
        polys[i].clear();
        polys[j].clear();
        que.push(make_pair(c.size(), polys.size()));
        polys.push_back(c);
    }
    vector<mint> a = polys.back();
    vector<mint> fact(n + 1, 1), invf(n + 1, 1), two(n + 1, 1);
    REP(i,n){
        two[i + 1] = 2 * two[i];
        fact[i + 1] = (i + 1) * fact[i];
    }
    invf[n] = fact[n].inv();
    FORR(i,n-1,0) invf[i] = invf[i + 1] * (i + 1);
    mint ans = 0;
    REP(i,a.size()){
        mint x = fact[n - 2 * i] * invf[n / 2 - i] / two[n / 2 - i];
        // cout << fact[n - 2 * i].val() << " " << invf[n / 2 - i].inv().val() << " " << two[n / 2 - i].val() << endl;
        // cout << x.val() << endl;
        x *= a[i];
        if (i % 2) x *= -1;
        ans += x;
    }
    cout << ans.val() << endl;

    return 0;
}


Measured memory_bytes: 21184
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long int ld;
typedef unsigned long long int lu;
typedef vector< int > vi;
typedef vector < ld > vd;
typedef set <ld> sd;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef pair< int,int > ii;
typedef pair< ld,ld > id;
#define sz(a) ld((a).size())
#define test(t) ll t;cin>>t;while(t--)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define Vi vector
#define pr pair
#define mpr make_pair
#define fi first
#define se second
#define isnum(a) (a>=48 && a<=57)
#define isS(a) (a>='a' && a<='z')
#define isU(a) (a>='A' && a<='Z')
#define toS(a) (isU(a)?a+32:a)
#define toU(a) (isS(a)?a-32:a)
#define toC(a) a&15

set <ld> s[100005];
ld d[100005];

vector<char> prime (100000+1, true);
void sieve(ld n)
{	
	//O(nloglogn) time
	prime[0] = prime[1] = false;
	for (ld i=2; i<=n; ++i)
	{
		if (prime[i])
		{
			s[i].insert(i);			
			for (ld j=2*i; j<=n; j+=i)
			{
				prime[j] = false;
				s[j].insert(i);
			}
		}
	}
}
#define forn(i,e) for(int i = 0; i < e; i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define reprev(i,a,b) for(i=a;i>=b;i--)

#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
ld gcd(ld a, ld b) { if(b == 0) return a; return gcd(b, a % b); }
ld fastpowMOD(ld a, ld p,ld MOD){ if(p==0) return 1; ld z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
ld fastpow(ld a, ld p){ if(p==0) return 1; ld z = fastpow(a,p/2); z = (z*z); if(p%2) z = (z*a); return z; }
ld a,b;

ld search1(ld a[], ld f,ld n)
{
	ld left=1;
	ld right=n+1;
	while(right-left>1)
	{
		ld mid = left + (right-left)/2;
		if(a[mid]<f)
		{
			left=mid;
		}
		else right=mid;
	}
	return a[left];
}

ld dp[3001][3001];
ld ar[3001];
ld getx(ld l,ld r,ld n)
{
	if(dp[l][r]!=-1)return dp[l][r];
	if(r-l==1)
	{
		return (dp[l][r] = max(ar[r]-ar[l],ar[l]-ar[r]));	
	}
	else 
	{
		dp[l][r] = ar[l]-getx(l+1,r,n);
		dp[l][r] = max(dp[l][r],ar[r]-getx(l,r-1,n));
		return dp[l][r]; 
	}
}

int main(){
	ld n,i,j;
	cin >> n;
	memset(dp,-1,sizeof(dp));
	memset(ar,0,sizeof(ar));
	REP(i,1,n)
	{
		cin >> ar[i];
	}
	ld maxs;
	if(n==1)maxs = ar[1];
	else maxs = getx(1,n,n);
	cout << maxs << endl;
	return 0;
}

Measured memory_bytes: 76288
#include <bits/stdc++.h>
using namespace std;
int fa[100005];
long long sum[100005];
int Find(int n){
	if(fa[n]==n) return n;
	else{
		fa[n]=Find(fa[n]);
		return fa[n];
	}
}
void Union(int a,int b){
	int aa=Find(a),bb=Find(b);
	fa[aa]=bb;
	sum[bb]+=sum[aa];
}
int main()
{
	long long n,m,a[100005],b[100005];
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		fa[i]=i;
		sum[i]=1;
	}
	for(int i=0;i<m;i++){
		scanf("%lld%lld",&a[i],&b[i]);
	}
	long long x=n*(n-1)/2,ans[100005];
	for(int i=m-1;i>=0;i--){
		ans[i]=x;
		if(Find(a[i])!=Find(b[i])){
			int aa=Find(a[i]),bb=Find(b[i]);
			x-=sum[aa]*sum[bb];
			Union(aa,bb);
		}
	}
	for(int i=0;i<m;i++){
		printf("%lld\n",ans[i]);
	}
	return 0;
} 

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#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)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const int INF = (1<<30)-1;
const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

int main () {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll ans = INF;
  for (int i = 0; i <= 100000; ++i) {
    ll cost = 0;
    int na = 0, nb = 0;
    na += i, nb += i;
    cost += (2*c)*i;
    cost += a*max(0,x-na) + b*max(0,y-nb);
    chmin(ans, cost);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    string s;
    string t;
    int count=0;
    cin>>s>>t;
    
    int m= s.length();
    int n= t.length();
    
    int i=0;
    int j=0;
    
    while(i<m && j<n){
        if(s[i]!=t[j] && i==j)
        {
            count++;
        }
        i++;
        j++;
        
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3824
import sys

c = [input().split() for i in range(3)]
num = [int(c[i][j]) for i in range(3) for j in range(3)]

if num[0] + num[4] != num[1] + num[3]:
    print('No')
    sys.exit()
elif num[4] + num[8] != num[5] + num[7]:
    print('No')
    sys.exit()
elif num[0] + num[8] != num[2] + num[6]:
    print('No')
    sys.exit()

print('Yes')

Measured memory_bytes: 3064
import sys
n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    _s, _c = map(int, input().split())
    s.append(_s)
    c.append(_c)

for i in range(1000):
    flag = True
    if len(str(i)) != n:
        continue
    for j in range(m):
        p = s[j]
        if str(c[j]) != str(i)[p-1]:
            flag = False
    if flag:
        print(i)
        sys.exit(0)

print(-1)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template<class S,class T>
string to_string(pair<S,T> p){
	return "{"+to_string(p.first)+","+to_string(p.second)+"}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
	ll N;
	cin>>N;
	print(N*(N-1)/2);
  return 0;
}


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

#define ll long long
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x << endl
#define N 200005

#define newLine	printf("\n");

#define sll(X) scanf("%lld", &X);
#define pll(X) printf("%lld", X);
#define printAll(X, n)	for(int i=0;i<n;i++)	printf("%lld ", X[i]); newLine;
#define scanAll(X, n)	for(int i=0;i<n;i++)	scanf("%lld", &X[i]);

int main() {
	ll n, x;
	sll(n); sll(x);
	if(n == 1) {
		cout<<"Yes\n";
		cout<<1<<"\n";
		return 0;
	}
	if(n == 2) {
		if(x == 1 || x == 2*n-1) {
			cout<<"No\n";
		} else {
			cout<<"Yes\n";
			cout<<"1\n2\n3\n";
		}
		return 0;
	}
	if(x == 1 || x == 2*n-1) {
		cout<<"No\n";
	} else {
		cout<<"Yes\n";
		ll rightHalf = n-1;
		ll curr = 2*n -1- x;
		if(curr > rightHalf) {
			ll rem = curr - rightHalf;
			for(int i=2*n-1;i>2*n -1 - rem;i--) {
				cout<<i<<"\n";
			}
			for(int i=1;i<=2*n-1-rem;i++) {
				cout<<i<<"\n";
			}

		} else {
			ll s = 1 + rightHalf - curr;
			for(int i=s;i<2*n;i++) {
				cout<<i<<"\n";
			}
			for(int i=1;i<s;i++) {
				cout<<i<<"\n";
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>

int A, B, C;
int A2, B2, C2;

void solve()
{
	int i;
	for(i=0; i<100000000; i++){
		if(A%2==1 || B%2==1 || C%2==1)
			break;
		A2 = (B+C)/2;
		B2 = (A+C)/2;
		C2 = (A+B)/2;
		A = A2;
		B = B2;
		C = C2;
	}
	if(i == 100000000)
		printf("-1\n");
	else
		printf("%d\n", i);
}

int main()
{
	scanf("%d%d%d", &A, &B, &C);
	solve();
	return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	ans := 0
	for i := 0; i < 2; i++ {
		ans += max(a, b)
		if a < b {
			b--
		} else {
			a--
		}
	}
	fmt.Println(ans)
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 512
i = list(map(int, input().split()))
j = list(map(int, input().split()))
max = 0


for k in range(i[1]-1):
  buf1 = j[k+1]
  buf2 = j[k]
  if max < buf1 - buf2:
    max =  buf1 - buf2
if max < i[0] + j[0] - j[i[1]-1]:
  max =  i[0] + j[0] - j[i[1]-1]
max = i[0] - max
print(max)

Measured memory_bytes: 25452
using System.Collections.Generic;
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray()[0];
            var Alist = new List<int>();
            for(var i = 0;i<N;i++)
            {
                Alist.Add(int.Parse(Console.ReadLine()));
            }
            var sorted = Alist.OrderByDescending(i => i).ToArray();
            var max = sorted[0];
            var second = sorted[1];
            foreach(var item in Alist)
            {
                if(item!=max)
                {
                    Console.WriteLine(max);
                }
                else
                {
                    Console.WriteLine(second);
                }
            }

        }
    }
}


Measured memory_bytes: 25556
def check(i, j, c):
    if grid[i - 1][j - 1] != c and grid[i][j - 1] != c and grid[i + 1][j - 1] != c and grid[i - 1][j] != c and grid[i + 1][j] != c and grid[i - 1][j + 1] != c and grid[i][j + 1] != c and grid[i + 1][j + 1] != c:
        return True
    else:
        return False

def change(N, c):
    k = 0
    if c == "#":
        k = 50
    for i in range(1 + k, 49 + k):
        for j in range(1, 99):
            if check(i, j, c):
                grid[i][j] = c
                N -= 1
            if N == 1:
                break
        if N == 1:
            break

A, B = map(int, input().split())
grid = [["#" for i in range(100)] for i in range(50)] + [["." for i in range(100)] for i in range(50)]
print(100, 100)
if A > 1:
    change(A, ".")
if B > 1:
    change(B, "#")
for g in grid:
    print("".join(g))

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void) {
  int n;
  cin >> n;
  REP(i, n) {
    string s, t;
    cin >> s >> t;

    int ss = 0, tt = 0, num = 1;
    REP(j, s.size()) {
      if(s[j] - '0' >= 2 && s[j] - '0' <= 9) {
        num = s[j] - '0';
      } else {
        if(s[j] == 'm') ss += num*1000;
        else if(s[j] == 'c') ss += num*100;
        else if(s[j] == 'x') ss += num*10;
        else if(s[j] == 'i') ss += num*1;
        num = 1;
      }
    }
    REP(j, t.size()) {
      if(t[j] - '0' >= 2 && t[j] - '0' <= 9) {
        num = t[j] - '0';
      } else {
        if(t[j] == 'm') tt += num*1000;
        else if(t[j] == 'c') tt += num*100;
        else if(t[j] == 'x') tt += num*10;
        else if(t[j] == 'i') tt += num*1;
        num = 1;
      }
    }

    int st = ss + tt;
    //cout << "ss:" << ss << " tt:" << tt << " st:" << st << endl;
    string ans, sts = to_string(st);
    REP(j, sts.size()) {
      if(sts[j] - '0' >= 2) ans += sts[j];
      if(sts[j] - '0' >= 1) {
        if(sts.size()-j == 4) ans += 'm';
        else if(sts.size()-j == 3) ans += 'c';
        else if(sts.size()-j == 2) ans += 'x';
        else if(sts.size()-j == 1) ans += 'i';
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3120
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    vector<vector<ll>> ADJE;
    READV(N);
    ADJE.resize(N+1);
    FORI(i,1,N)
    {
        READV(u);
        READV(v);
        ADJE[u].pb(i);
        ADJE[v].pb(i);
    }
    ll K=0;
    FORI(i,1,N+1)
    {
        K=max(K,(ll)ADJE[i].size());
    }
    vector<ll> colE(N,0);
    FORI(i,1,N+1)
    {
        set<ll> F;
        FORI(j,0,sz(ADJE[i]))
        {
            if (colE[ADJE[i][j]]!=0)
            {
                F.insert(colE[ADJE[i][j]]);
            }
        }
        ll col=1;
        FORI(j,0,sz(ADJE[i]))
        {
            if(colE[ADJE[i][j]]==0)
            {
            while (F.find(col)!=F.end())
            {
                col++;
            }
            colE[ADJE[i][j]]=col;
            F.insert(col);
            col++;           
            }
        }
    }
    cout<<K<<endl;
    FORI(i,1,N)
    {
        cout<<colE[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 7296
n, k = map(int, input().split())
a = list(map(int, input().split()))
one = [sum([(a[j]>>i)&1 for j in range(n)]) for i in range(40)]
zero = [n - one[i] for i in range(40)]
dp = [[-float("inf") for _ in range(2)] for _ in range(41)]
dp[40][0] = 0
for i in range(39, -1, -1):
	if (k>>i)&1 == 0:
		dp[i][0] = dp[i+1][0] + (2**i) * one[i]
		dp[i][1] = dp[i+1][1] + (2**i) * max(one[i], zero[i])
	else:
		dp[i][0] = dp[i+1][0] + (2**i) * zero[i]
		dp[i][1] = max(dp[i+1][0] + (2**i) * one[i], dp[i+1][1] + (2**i) * max(one[i], zero[i]))

print(max(dp[0]))

Measured memory_bytes: 14712
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a) memset(a,0,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int res=0;
    if(k>0)
    {
        res+=min(a,k);
        k-=a;
    }
    if(k>0)
    {
        k-=b;
    }
    if(k>0)
    {
        res-=min(c,k);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second

int n;
pii p[5555];
bool cmp(pii p1,pii p2){
	return p1.fi+p1.se < p2.fi+p2.se;
}

ll f[5050];

int main(){
	cin>>n;
	for (int i=1;i<=n;++i) cin>>p[i].fi>>p[i].se;
	sort(p+1,p+n+1,cmp);
	memset(f,33,sizeof f); f[0]=0;
	for (int i=1;i<=n;++i){
		for (int j=n;j;--j) if (f[j-1]<=p[i].fi)
			f[j]=min(f[j],f[j-1]+p[i].se);
	}
	for (int i=n;;--i) if (f[i]<(1e15)) return !(cout<<i);
}

Measured memory_bytes: 384
N,M = map(int,input().split())
#隣接リスト
g = [[] for i in range(N)]
for i in range(M):
  a,b = map(int,input().split())
  g[a-1].append(b)
  g[b-1].append(a)
ls = g[0]
flag = 0
for i in range(len(g[0])):
  ls2 = g[ls[i]-1]
  for j in range(len(ls2)):
    if ls2[j] == N:
      flag += 1
      print("POSSIBLE")
      break
if flag == 0:
  print("IMPOSSIBLE")


Measured memory_bytes: 108928
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, M, X, C[12], A[12][12];
    intmax_t ans = INTMAX_MAX;

    scanf("%jd%jd%jd", &N, &M, &X);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &C[i]);
        for (size_t j = 0; j < M; j++) {
            scanf("%jd", &A[i][j]);
        }
    }

    for (uint16_t a = 1; a <= ((1 << N) - 1); a++) {
        intmax_t level[12] = {}, cost = 0;
        bool achieve = true;
        for (size_t i = 0; i < N; i++) {
            if (a & (1 << i)) {
                cost += C[i];
                for (size_t j = 0; j < M; j++) {
                    level[j] += A[i][j];
                }
            }
        }
        for (size_t j = 0; j < M; j++) {
            if (level[j] < X) {
                achieve = false;
            }
        }
        if (achieve) {
            if (cost < ans) {
                ans = cost;
            }
        }
    }

    if (ans == INTMAX_MAX) {
        ans = -1;
    }

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 2152
import scala.collection.mutable.ListBuffer
import scala.io.StdIn

object Main extends App {

  val result = ListBuffer.empty[String]
  var Array(m, f, r) = Array(0, 0, 0)
  while(m != -1 || f != -1 || r != -1){
    val Array(inm, inf, inr) = StdIn.readLine().split(' ').map(_.toInt)
    m = inm
    f = inf
    r = inr
    val rank = (m, f, r) match {
      case (-1, -1, -1) =>  ""
      case (-1,  y, z) =>  "F"
      case ( x, -1, z) =>  "F"
      case ( x,  y, z) if x + y >= 80 =>  "A"
      case ( x,  y, z) if (65 <= x + y ) && (x + y < 80)  =>  "B"
      case ( x,  y, z) if (50 <= x + y ) && (x + y < 65)  =>  "C"
      case ( x,  y, z) if (30 <= x + y ) && (x + y < 50)  =>  {
        if (50 <= z) "C" else "D"
      }
      case ( x,  y, z) if x + y < 30  =>  "F"
      case _ => ""
    }
    result += rank
    
  }
    
  print(result.mkString(f"%n"))
  //result.foreach(println)
  
}


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

int main(){
    
    int x;
    
    cin >> x;
    
    if(65<=x && x<=90){
        cout << 1 << endl;
    }
    else if(97<=x && x<=122){
        cout << 2 << endl;        
    }
    else{
        cout << 0 << endl;
    }
}


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

#define o(output) cout << output << endl

using namespace std;

string s,t,u;
int a,b,c,d;
int l[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
char A,B,C;
priority_queue<int,vector<int>,greater<int> >small;

int main(){
  cin >>A>>B;
  if(A-B==0)o("H");
  else o("D");
}
  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while (s.hasNext()) {
			char[] chars = s.next().toCharArray();
			if (chars[0] == '0') return;
			int sum = 0;
			for (int i = 0; i < chars.length; ++i) {
				sum += Character.getNumericValue(chars[i]);
			}
			System.out.println(sum);
		}
	}
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

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

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) (x).erase(unique(all(x)), (x).end())
#define int long long

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int h, w;
    cin >> h >> w;
    rep(i, h)
    {
        string s;
        cin >> s;
        rep(i, 2)
        {
            cout << s << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
N=input()
n=list(N)
N_int =[int(i) for i in n]

Multi=0
i=0
l=len(N)

for i in range(l):
	Multi=Multi+N_int[i]
	i=i+1

mod = Multi % 9

if mod == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 12424
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
#define max 100000
using namespace std;
ll l = 1000000007;

int main()
{
	int n;
	cin >> n;
	if (n == 25) {
		cout << "Christmas" << endl;
	}else if (n == 24) {
		cout << "Christmas Eve" << endl;
	}else if (n == 23) {
		cout << "Christmas Eve Eve" << endl;
	}else if (n == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}

	
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
    int n, R[200000];
    int max, min;
    int i, j;

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

    max = R[1] - R[0];
    min = R[0];

    for(i = 1; i < n; i++) {
        if(max < R[i] - min) {
            max = R[i] - min;
            // printf("MAX: %d\n", max);
        }
        if(min > R[i]) {
            min = R[i];
            // printf("MIN: %d\n", min);
        }
    }

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

    return 0;
}


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

int gcd(int x, int y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {
    int x, y;
    cin >> x >> y;
    
    if (x >= y) cout << gcd(x, y) << endl;
    else cout << gcd(y, x) << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define pi acos(-1.)
#define ll long long
#define N 109
using namespace std;  
  
struct point{ int x,y,id; }a[N],q[N];
int n,tp;   double ans[N];
point operator -(point u,point v){  
    point t; t.x=u.x-v.x; t.y=u.y-v.y; return t;  
}  
ll crs(point u,point v){ return (ll)u.x*v.y-(ll)u.y*v.x; }  
double dot(point u,point v){ return 1.*u.x*v.x+1.*u.y*v.y; }
double dist(point u,point v){  
    return sqrt(1.*(u.x-v.x)*(u.x-v.x)+1.*(u.y-v.y)*(u.y-v.y));  
}  
bool cmp(point u,point v){  
    ll t=crs(u-a[1],v-a[1]);  
    return t>0 || t==0 && dist(u,a[1])<dist(v,a[1]);  
} 
double calc(point u,point v){
	return dot(u,v)/dist((point){0,0},u)/dist((point){0,0},v);
}
int main(){  
    scanf("%d",&n);
	int i,j;  
    for (i=1; i<=n; i++){
		scanf("%d%d",&a[i].x,&a[i].y); a[i].id=i;
	}
    for (i=2; i<=n; i++)  
        if (a[i].y<a[1].y || a[i].y==a[1].y && a[i].x<a[1].x) swap(a[1],a[i]);  
    sort(a+2,a+n+1,cmp);  
    q[1]=a[1]; q[2]=a[2]; int tp=2;  
    for (i=3; i<=n; i++){  
        while (tp>1 && crs(a[i]-q[tp-1],q[tp]-q[tp-1])>=0) tp--;  
        q[++tp]=a[i];  
    }
    q[tp+1]=q[1]; q[0]=q[tp];
    if (tp==2){
    	ans[q[1].id]=ans[q[2].id]=.5;
    } else{
    	for (i=1; i<=tp; i++){
    		ans[q[i].id]=acos(calc(q[i]-q[i+1],q[i-1]-q[i]))/2/pi;
    	}
    }
    for (i=1; i<=n; i++) printf("%.10f\n",ans[i]);
}

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


const int MAXN = 200007;


inline int read() {
	int x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x;
}


int A[MAXN];


long long sum[MAXN], xorSum[MAXN];


int main() {	
	int n = read();
	for (int i = 1; i <= n; ++i) {
		A[i] = read();
	}
	for (int i = 1; i <= n; ++i) {
		sum[i] = sum[i - 1] + A[i];
		xorSum[i] = (long long)((int)xorSum[i - 1] ^ A[i]);
	}
	long long ans = 0;
	for (int l = 1, r = 0; l <= n; ) {
		while (sum[r + 1] - sum[l - 1] == (xorSum[r + 1] ^ xorSum[l - 1]) && r < n) {
			++r;
			ans += r - l + 1;
		}
		if (r == n) break;
		++l;
	}
	std::cout << ans;
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int n;
    int k;
    cin >> n >> k;
    char d[k];
    for(int i=0;i<k;i++){
        cin >> d[i];
    }
    int tmp = n;
    while(1){
        string s = to_string(tmp);
        bool sw = true;
        for(int i = 0;i < s.size();i++){
            for(int j=0;j<k;j++){
                if(s[i] == d[j]){
                    sw = false;
                }
            }
        }
        if(sw){
            cout << tmp << endl;
            return 0;
        }
        else{
            tmp ++;
        }
    }
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  CIN(string, S, T);
  CIN(int, A, B);
  CIN(string, U);
  (U == S ? A : B)--;
  cout << A << " " << B << endl;
}


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

int isBase(char a);

int main() {
	char s[11];
	int flg_A, flg_C, flg_s, i, cnt;
	scanf("%s", s);
	
	flg_A = 0;
	if (s[0] == 'A') flg_A = 1;

	flg_C = 0;
	cnt = 0;
	for (i = 2; i < strlen(s) - 1; i++) {
		if (s[i] == 'C') {
			cnt++;
			s[i] = 'a';
		}
	}
	if (cnt == 1) flg_C = 1;

	flg_s = 1;
	for (i = 1; i < strlen(s); i++) {
		if (s[i] < 'a' || 'z' < s[i]) {
			flg_s = 0;
			break;
		}
	}

	printf(flg_A && flg_C && flg_s ? "AC" : "WA");
	return 0;
}

Measured memory_bytes: 128
from math import factorial

n, k = map(int, input().split())
r = n - k

def c(a, b):
    if a < b: return 0
    return factorial(a) // (factorial(a-b) * factorial(b))

for i in range(1, k+1):
    print((c(k-1, i-1) * c(r+1, i)) % (10**9 + 7))



Measured memory_bytes: 3316
def gcd(x,y):
    if x<y:
        x,y = y,x
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
A = list(map(int,input().split()))
x = A[0]
for i in range(1,N):
    y = A[i]
    x = gcd(x,y)
print(x)

Measured memory_bytes: 14252
from sys import stdin

def main():
    plus, minus = [], []
    readline = stdin.readline
    n = int(readline())
    for _ in range(n):
        s = readline().rstrip()
        if 2 * s.count('(') - len(s) > 0:
            plus.append(s)
        else:
            minus.append(s)
    plus.sort(key = lambda x: x.count(')'))
    minus.sort(key = lambda x: x.count('('), reverse = True)

    sum = 0
    for v in ''.join(plus + minus):
        sum = sum + (1 if v == '(' else -1)
        if sum < 0 : return print('No')
    if sum != 0:
        return print('No')

    return print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 44464
n=int(input())
l=list(map(int,input().split()))
m=1
maxx=10**18
flag=0
for i in range(n):
   if l[i]==0:
       print(0)
       flag=1
       break
if flag!=1:
    flag=0
    for i in range(n):
        m*=l[i]
        if m>maxx:
            print(-1)
            flag=1
            break

    if flag!=1:
        print(m)
    

Measured memory_bytes: 84916
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    ll n,a = 0,b = 0;
    cin >> n;
    rep0(i, n){
        ll x;
        cin >> x;
        if(x % 4 == 0)++a;
        else if(x % 2 == 0)++b;
    }
    if(n / 2 <= a + b/2)pf("Yes");
    else pf("No");
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val s = sc.nextLine()
    val t = sc.nextLine()
    val n = s.length
    val m = t.length
    var min = Int.MAX_VALUE
    for (i in 0 until n - m + 1) {
        var count = 0
        for (j in 0 until m) {
            if (s[i + j] != t[j]) count++
        }
        min = minOf(min, count)
    }
    println(min)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 34384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            solve(in);
        }
    }

    private static void solve(BufferedReader in) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        int N = Integer.parseInt(st.nextToken()), M = Integer.parseInt(st.nextToken());

        @SuppressWarnings("unchecked")
        List<LR>[] nByLen = new List[M + 1];

        for (int n = 1; n < N + 1; n++) {
            st = new StringTokenizer(in.readLine());
            int l = Integer.parseInt(st.nextToken());// 1 <= l <= r <= M
            int r = Integer.parseInt(st.nextToken());
            LR lr = new LR(l, r);
            if (nByLen[lr.len] == null) {
                nByLen[lr.len] = new ArrayList<>();
            }
            nByLen[lr.len].add(lr);
        }

        int accum = N;

        fenwick = new int[M + 1];
        for (int d = 1; d < M + 1; d++) {
            int sum = accum;
            for (int e = d; e < M + 1; e += d) {
                sum += faccum(e);
            }
            System.out.println(sum);
            if (nByLen[d] != null) {
                accum -= nByLen[d].size();
                for (LR lr : nByLen[d]) {
                    fadd(lr.l, 1);
                    fadd(lr.r + 1, -1);
                }
            }
        }
    }

    private static class LR {
        final int l, r, len;

        LR(int l, int r) {
            this.l = l;
            this.r = r;
            this.len = r - l + 1;
        }
    }

    private static int[] fenwick;

    private static int faccum(int i) {
        int sum = 0;
        for (; i > 0; i -= i & -i) {
            sum += fenwick[i];
        }
        return sum;
    }

    private static void fadd(int i, int a) {
        for (; i < fenwick.length; i += i & -i) {
            fenwick[i] += a;
        }
    }
}

Measured memory_bytes: 58020
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 998244353
#define INF 1000000000

vector<int> parent;

int find(int x){
  int y=parent.at(x);
  if(y!=parent.at(y)){
    y=find(y);
  }
  return parent.at(x)=y;
}

void unite(int a,int b){
  int x=find(a);
  int y=find(b);
  if(x!=y){
    parent.at(x)=y;
  }
}

int main(){
  int N,M;
  cin>>N>>M;
  parent.resize(N+M);
  for(int i=0;i<N+M;i++){
    parent.at(i)=i;
  }
  for(int i=0;i<N;i++){
    int K;
    cin>>K;
    for(int j=0;j<K;j++){
      int L;
      cin>>L;
      L--;
      unite(i,N+L);
    }
  }

  bool flag=true;
  for(int i=0;i<N-1;i++){
    if(find(i)!=find(i+1)){
      flag=false;
    }
  }

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


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

p = list(range(N))
p.sort(key=lambda i: A[i], reverse=True)

dp = [[0]*(N + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(i + 1):
        pi = p[i]
        dp[i+1][j] = max(dp[i+1][j], dp[i][j] + A[pi]*(N - i + j - 1 - pi))
        dp[i+1][j+1] = dp[i][j] + A[pi]*(pi - j)
print(max(dp[N]))


Measured memory_bytes: 124256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	string s, t;
	int n;
	bool ans = true;
	cin >> s;
	t = s;
	reverse(s.begin(), s.end());
	if (t != s) {
		ans = false;
	}
	n = s.size();
	for (int i = 0; i < (n - 1) / 2; i++) {
		if (t[i] != s[((n+1)/2)+i]) {
			ans = false;
		}
	}
	for (int i = (n+1)/2; i < n; i++) {
		if (t[i] != s[i - ((n + 1) / 2)]) {
			ans = false;
		}
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const ll MOD=(ll)1e9+7;
const int MAX = 5e5+1;

ll fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

ll COMcalc(int n,int k){
  if(n<k)return 0;
  if(n<0 || k<0)return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll Pcalc(int n,int k){
  if(n<k)return 0;
  if(n<0 || k<0)return 0;
  return fac[n]*(finv[n-k]%MOD)%MOD;
}

int main(){
  COMinit();
  int n,m;
  ll ans=0,tmp;
  cin>>n>>m;
  for(int i=0;i<=n;i++){
    tmp=COMcalc(n,i);
    tmp*=Pcalc(m,i);tmp%=MOD;
    tmp*=Pcalc(m-i,n-i);tmp%=MOD;
    tmp*=Pcalc(m-i,n-i);tmp%=MOD;
    ans+=(i%2==0 ? 1 : -1)*tmp;ans+=MOD;ans%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 15348
#include<stdio.h>

int main(void)
{
	int jougen=0;
	int count= 0;
	int out = 0;
	//printf("入力する文字を決める\n");
	scanf("%d", &jougen);
	int kazu[200];
	for (int i = 0; i < jougen; i++)
	{
		scanf("%d", &kazu[i]);
	}

	//以下判定をする
	while (1)
	{
		for (int i = 0; i < jougen; i++)
		{
			if (kazu[i] % 2 == 1)
			{
				out = 1;
				break;
			}
			kazu[i] = kazu[i] / 2;
			
		}
		if (out == 1)
		{
			break;
		}
		count++;
	}
	//printf("よってすべてを２で割れる数回数は\n");
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int hakox,hakoy,enx,eny,hankei;
    cin>>hakox>>hakoy>>enx>>eny>>hankei;
    int sum =enx+hankei;
    int sum2 = eny+hankei;
    int sum3 =enx-hankei;
    int sum4 =eny-hankei;

    if(sum>hakox||sum3<0){
        cout<<"No"<<endl;
    }else if(sum2>hakoy||sum4<0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>

using namespace std;

bool comp(const string& key1, const string& key2)
{
  if(key1.size() == key2.size()) {
    return key1 < key2;
  }
  return key1.size() < key2.size();
}

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

  string key;
  int value;
  map<string, int> products;
  vector<string> keys;

  for(int i = 0; i < n; i+= 1){
    cin >> key >> value;

    if(products.find(key) == products.end()) {
      products[key] = value;
      keys.push_back(key);
    } else {
      products[key] += value;
    }
  }

  sort(keys.begin(), keys.end(), comp);

  for(int i = 0; i < keys.size(); i += 1){
    cout << keys[i] << " " << products[keys[i]] << endl;
  }

  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm> 
#include <string>

using namespace std;

struct edge {
	int to;
	int cost;
};

typedef pair<int, int> P;

#define INF 1000000

int V;
vector<edge> G[2500];
int d[2500];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d+V, INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) {
			continue;
		}
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	int h, w;
	cin >> h >> w;
	V = h*w;
	vector< vector<int> > data2(h, vector<int>(w));
	string a;
	for (int i = 0; i < h; i++) {
		cin >> a;
		for (int j = 0; j < w; j++) {
			data2[i][j] = a[j]-'0';
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			edge e;
			if (i != 0) {
				e.to = i*w+j;
				e.cost = data2[i][j];
				G[(i-1)*w+j].push_back(e);
			} 
			if (j != 0) {
				e.to = i*w+j;
				e.cost = data2[i][j];
				G[i*w+(j-1)].push_back(e);
			}
		}
	}
	dijkstra(0);
	cout << d[V-1] << endl;
	return 0;
}

Measured memory_bytes: 1384