akhauriyash/Code-Regression huggingface dataset:
#ifndef TEMPLATE
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define mp make_pair
#define sz(a) ((int)(a).size())
#define mem(x,v) memset((x),(v),sizeof((x)));
#define A(x) (x).begin(),(x).end()
#define re(i,n) for(int i=0;i<(int)n;i++)
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define erp(i,k,n) for(int i=n;i>=k;i--)
#define input(v,n) re(i,n)cin>>v[i]
using vi = vector<int>;
using vpi = vector<pair<int,int>>;
using vvi = vector<vi>;
using tp = tuple<int,int,int>;
using pi = pair<int,int>;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int> :: max() - (int)9e6;
#endif
// ===================== MANASH =================== //

int n;

void test() {

      cin >> n;
      vector<array<int,3>> vec(n),dp(n);
      re(i,n) cin >> vec[i][0] >> vec[i][1] >> vec[i][2];
      
      dp[0] = vec[0];

      for( int i = 1; i < n; i++) {
            for( int me : {0,1,2}) {
                  for( int pr : {0,1,2}) {
                        if ( me == pr ) continue;
                        dp[i][me] = max(dp[i][me],dp[i-1][pr]+vec[i][me]);
                  }
            }
      }
      cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

signed main() {

      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
      int T = 1;
      //cin >> T;
      for( int tt = 1; tt <= T; tt++) {
            //cout << "Case #" << tt << " ";
            test();
            cout << "\n";
      }
      return 0;

}

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

using namespace std;

const int N = 2000 + 5;
const int MAX = 1000 * 2000 + 5;

int n;
int a[N];

bitset<MAX> dp[N];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  for (int i = 0; i < n; ++i) {
    dp[i][a[i]] = 1;
    if (i != 0) {
      dp[i] |= dp[i - 1] | (dp[i - 1] << a[i]);
    }
  }
  dp[0] = 1;
  for (int i = sum / 2; i >= 0; --i) {
    if (dp[n - 1][i]) {
      cout << sum - i << endl;
      return 0;
    }
  }
  return 0;
}


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

import collections
import copy

N = int(input())
s = []
for i in range(N):
    s.append(str(input()))

s_count = collections.Counter(s).most_common()
max_count = s_count[0][1]
roop = True
index = 1
s_count_len = len(s_count)
while roop and index < s_count_len:
    if s_count[index][1] == max_count:
        index += 1
    else:
        roop = False

values, counts = zip(*s_count[0:index])

out_list = sorted(values)
print("\n".join(out_list))


Measured memory_bytes: 50308
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
using namespace std;
 
 
 
int main(){
    int a,b;
    cin>>a>>b;
    if(a==b) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 5*(int)1e5 + 10;
// make sure N size is correctttt!!!!!!!!!


int n, a[N], m;
vector<P> take;

int32_t main(){_

   cin>>n>>m;

   set<int> s;

   for (int i = 0; i < m; ++i)
   {
      cin>>a[i];
      s.insert(a[i]);
   }

   if(n >= m){
      cout<<0;
      return 0;
   }

   sort(a, a+m);

   for (int i = 1; i < m; ++i)
   {
      take.pb({-(a[i]-a[i-1]), a[i]});
   }

   sort(take.begin(), take.end());

   vector<int> choose;
   choose.pb(a[0]);

   int ans = 0;
   for (int i = 0; i < n-1; ++i)
   {
      auto it = s.lower_bound(take[i].S);
      --it;
      ans += *it - choose.back();
      choose.pb(take[i].S);
   }

   ans += a[m-1] - choose.back();
   cout<<ans;
   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int X, t;
  cin >> X >> t;
  if (t >= X) {
    cout << 0 << endl;
  } else {
    cout << X - t << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string str;
int main()
{
    int n,t1=0,t2=0,t3=0,t4=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        cin>>str;
        if(str=="AC")t1++;
        else if(str=="WA")t2++;
        else if(str=="TLE")t3++;
        else t4++;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",t1,t2,t3,t4);
    return 0;
}

Measured memory_bytes: 3788
#include<iostream>
#include<string>
using namespace std;
int main(){
    int i,b,c,cut=0;
    string str1,str,mozi;
    cin>>str>>str1;
    mozi=str+str;
    int a=mozi.find(str1);
    if(a!=-1){
        cut=1;
    }
    if(cut==1){
        cout<<"Yes"<<"\n";
    }else
        cout<<"No"<<"\n";
return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <functional>
#include <string>


using namespace std;
int main()
{
	long long i, j, k, a, b, c, d, X, N, M;
	long long A[200001];
	long long B[200001];
	
	cin >> N;

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

	sort(A, A + N);

	a = A[N / 2 - 1];
	b = A[N / 2];

	for (i = 0; i < N; i++) {
		if (B[i] <= A[N/2-1]) {
			cout << b << endl;
		}
		else {
			cout << a << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 5376
s = raw_input()
cur = 0
def parse():
    global cur
    if s[cur] != "m": return 0
    cur += 1
    if s[cur] == "m" and not parse(): return 0
    if s[cur] != "e": return 0
    cur += 1
    if s[cur] == "m" and not parse(): return 0
    if s[cur] != "w": return 0
    cur += 1
    return 1
print "Cat"*(parse() and cur == len(s)) or "Rabbit"

Measured memory_bytes: 6496
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    int X, Y;
    cin >> X >> Y;
    bool possible = false;
    for (int i = 0; i < X + 1; i++) {
        int c = i;
        int t = X - i;
        if (c * 2 + t * 4 == Y) {
            possible = true;
            break;
        }
    }
    string ans = (possible == true)?"Yes":"No";
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
    int N,M;
    int A[200000]={0},W[200000]={0};

    cin>>N>>M;
    for(int i=0;i<M;i++){
        string s;
        int m;
        cin>>m>>s;
        if(s=="AC"){
            A[m]++;
        }
        else{
            if(A[m]==0) W[m]++;
        }
    }

    int ACsum=0,WAsum=0;
    for(int i=0;i<200000;i++){
        if(A[i]>0){
            ACsum++;
            WAsum+=W[i];
        }
    }
    cout<<ACsum<<" "<<WAsum<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

int pascal[51][51]={};
int pas_init(int N){
    REP(i,N+1){
        pascal[0][i]=1;
        pascal[i][0]=1;
    }
    OREP(i,N){
        OREP(j,N){
            pascal[i][j]=pascal[i-1][j]+pascal[i][j-1];
        }
    }
    return 0;
}

int comb(int n,int r){
    if(n<r)return 0;
    return pascal[n-r][r];
}

signed main(){
    int N,A,B;
    int v[50];
    cin >> N >> A >> B;
    pas_init(50);
    REP(i,N){
        cin >> v[i];
    }
    sort(v,v+N,greater<>());
    if(v[0]==v[A-1]){
        printf("%.8f\n",(double)v[0]);
        int t=0;
        int Ans=0;
        REP(i,N){
            if(v[0]==v[i])t++;
        }
        for(int i=A;i<=B;i++){
            Ans+=comb(t,i);
        }
        cout << Ans << Endl;
        return 0;
    }
    
    int e=v[A-1];
    double ave=0;
    REP(i,A){
        ave+=v[i];
    }
    printf("%.8f\n",ave/A);
    int r=0;
    REP(i,A){
        if(v[i]==e)r++;
    }
    int n=0;
    REP(i,N){
        if(v[i]==e)n++;
    }
    //cout << n << " " << r << " " << e << endl;
    cout << comb(n,r) << endl;
    return 0;
}   


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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

int N;
constexpr int pow_max = 35;
ll pow2[pow_max + 1];
map<ll, ll> mp;

int main()
{
  pow2[0] = 1LL;
  REP(i, pow_max) pow2[i + 1] = 2LL*pow2[i];
  cin >> N;
  REP(i, N) {
    ll A; cin >> A;
    mp[-A]++;
  }

  ll ans = 0;
  while (!mp.empty()) {
    auto itr = mp.begin();
    ll x = -itr->FI;
    itr->SE--;
    if (itr->SE == 0) mp.erase(itr->FI);
    for (int i = 1; i < pow_max; i++) {
      ll y = pow2[i] - x;
      auto itr2 = mp.find(-y);
      if (itr2 != mp.end()) {
        ans++;
        itr2->SE--;
        if (itr2->SE == 0) mp.erase(itr2->FI);
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12800
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const ll MOD = 1e9+7;

struct Node {
    int left,right;
    ll val;
};

const int SZ = 5e7;
int sz = 0;
Node nodes[SZ];

int newNode(){
    nodes[sz] = Node{-1,-1,0};
    return sz++;
}

int idOf(int i){
    if(i==-1){
        return newNode();
    }
    else{
        return i;
    }
}

Node& ithNode(int i){
    assert(i>=1);
    return nodes[i];
}

int h;

ll addImpl(Node& node,int id,ll w,int v,int l,int r){
    if(r-l==1){
        node.val=(node.val+w*v)%MOD;
        return w*v%MOD;
    }
    else{
        int mid = (l+r)/2;
        int i,piyo;
        if(id<mid) i = node.left = idOf(node.left),r=mid,piyo=0;
        else i = node.right = idOf(node.right),l=mid,piyo=1;
        Node& chi = ithNode(i);
        ll ret = addImpl(chi,id,w,v*2+piyo,l,r);
        node.val=(node.val+ret*v)%MOD;
        return ret*v%MOD;
    }
}
void add(Node& node,int id,ll w){
    addImpl(node,id,w,1,0,1<<(h-1));
}

ll calcImpl(Node& node,int i,int dep,int l,int r,const vector<ll>& wei){
    if(i<l){
        return node.val*wei[dep]%MOD;
    }
    else if(r<=i+1){
        return 0;
    }
    else{
        int mid = (l+r)/2;
        ll ansl = node.left>0 ? calcImpl(ithNode(node.left),i,dep+1,l,mid,wei) : 0LL;
        ll ansr = node.right>0 ? calcImpl(ithNode(node.right),i,dep+1,mid,r,wei) : 0LL;
        return (ansl+ansr)%MOD;
    }
    
}
ll calc(Node& node,int i,const vector<ll>& wei){
    return calcImpl(node,i,0,0,1<<(h-1),wei);
}

int main(){
    cin>>h;
    int l = 1<<(h-1);
    vector<int> p(l);
    for(int i=0;i<l;i++) cin>>p[i];
    
    
    // build
    for(int i=0;i<(1<<h);i++) newNode();

    for(int i=0;i<l;i++){
        int x = i+l;
        int y = l+p[i]-1;
        int z = y;

        ll w = 1;
        while(z>1){
            w=w*z%MOD;
            Node& node = ithNode(z);
            add(node,i,w);
            z/=2;
        }
    }

    // answer
    ll ans = 0;
    for(int i=0;i<l;i++){
        int x = i+l;
        int y = l+p[i]-1;
        int z = y;
        ll w = z;
        vector<ll> ws(h+1);
        ws[h] = x;
        int tmp = x/2;
        for(int i=h-1;i>=0;i--) ws[i] = ws[i+1]*tmp%MOD,tmp/=2;

        while(z>1){
            w= (w*(z/2))%MOD;
            ll sc = calc(ithNode(z^1),i,ws);

            ans = (ans+w*sc)%MOD;
            z/=2;
        }        
    }

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

Measured memory_bytes: 358240
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

int main() {
	ll a, b, c, d, e;
	int n;
	scanf("%lld%lld%lld%lld%d", &a, &b, &c, &d, &n);
	ll tl = min(min(a*8, b*4), min(c*2, d));
	ll sol = tl * (n/2);
	if (n%2) sol += min(min(a*4, b*2), c);
	printf("%lld\n", sol);
	return 0;
}

Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    X, N = map(int, input().split())
    P = set(map(int, input().split()))

    val = 1000
    ans = -1
    for x in range(0, 102):
        if x in P:
            continue
        if abs(X - x) < val:
            ans = x
            val = abs(X - x)
    print(ans)


if __name__ == '__main__':
    main()


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

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

    int prime_m=100003;

    vector<int> prime;

    prime.push_back(2);

    int ans = 2;
    if(x==2){
        cout << ans << endl;
        return 0;
    }

    for (int i = 3; i <= prime_m; i+=2){
        bool is_prime = true;

        for (int j = 0; j < prime.size(); j++) {
            if(i%prime[j]==0){
                is_prime = false;
                break;
            }
        }

        if(is_prime){
            prime.push_back(i);

            if(i>=x){
                ans = i;
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
n = int(input())
num = list(map(int,input().strip().split()))
s = sum(num)
num_dict = {}
for i in num:
  if i in num_dict:
    num_dict[i] += 1
  else:
    num_dict[i] = 1
q = int(input())
for i in range(q):
  b,c = map(int,input().strip().split())
  if c in num_dict:
    if b in num_dict:
      k = num_dict[b]
      num_dict[c] += num_dict[b]
      del num_dict[b]
      if b > c:
        s = s - (b-c)*k
        print(s)
      else:
        s = s + (c-b)*k
        print(s)
    else:
      print(s)
  else:
    if b in num_dict:
      k = num_dict[b]
      num_dict[c] = num_dict[b]
      del num_dict[b]
      if b > c:
        s = s - (b-c)*k
        print(s)
      else:
        s = s + (c-b)*k
        print(s)
    else:
      print(s)
  
  

Measured memory_bytes: 20888
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}
const int N = 2e5 + 10;
int nxt[N], depth[N];
int go(int node, ll k, int dis = 1) {
	if (k == 0)
		return node;
	if (depth[node]) {
		int cycle = dis - depth[node];
		depth[node] = 0;
		return go(node, k % cycle, dis);
	}
	depth[node] = dis;
	return go(nxt[node], k - 1, dis + 1);
}
int main() {
	run();
	int n;
	ll k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> nxt[i];
	cout << go(1, k) << endl;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    int a, b, c; cin>>a>>b>>c;
    int k; cin>>k;
    int cnt = 0;
    while(b <= a) b *= 2, cnt++;
    while(c <= b) c *= 2, cnt++;
    if(cnt <= k) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    long long tmp, tmp2;
    tmp =(N/(A+B)) * A;
    tmp2 =(N%(A+B));

    if(tmp2<=A)
	tmp+=tmp2;
    else
	tmp+=A;
    cout << tmp << endl;
} 




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

using namespace std;

#define MOD 1000000007

int n, q, l, r, hv = 1, par[105], id[105], at[105], x[105], fm, im;
vector<int> gp;
pair<int, int> p[105];
int u;
long long inv9, ans, mul[105], mu, smu, dp[10][1 << 16], sum;

int find(int a) {
	return par[a] == a ? a : par[a] = find(par[a]);
}

long long po(long long b, int pp) {
	long long re = 1;
	while (pp) {
		if (pp & 1)
			re = re * b % MOD;
		b = b * b % MOD;
		pp >>= 1;
	}
	return re;
}

int main() {
	inv9 = po(9, MOD - 2);
	scanf("%d%d", &n, &q);
	for (int i = 0; i < q; i++) {
		scanf("%d%d", &l, &r);
		p[i * 2] = {l - 1, i * 2};
		p[i * 2 + 1] = {r, i * 2 + 1};
	}
	sort(p, p + q * 2 + 1);
	for (int i = 1; i <= q * 2; i++) {
		if (p[i].first != p[i - 1].first) {
			x[hv] = p[i].first;
			par[hv] = hv;
			hv++;
		}
		at[p[i].second] = hv - 1;
	}
	for (int i = 0; i < q; i++)
		if (find(at[i * 2]) != find(at[i * 2 + 1]))
			par[par[at[i * 2]]] = par[at[i * 2 + 1]];
	memset(id, -1, sizeof(id[0]) * hv);
	gp.reserve(hv);
	for (int i = 0; i < hv; i++) {
		if (id[find(i)] == -1) {
			id[par[i]] = gp.size();
			gp.push_back(0);
		}
		gp[id[par[i]]] |= 1 << i;
	}
	ans = po(10, n - x[hv - 1]);
	for (int i = 1; i < hv; i++) {
		mul[i] = (po(10, x[i] - x[i - 1]) + MOD - 1) * inv9 % MOD;
		ans = ans * mul[i] % MOD;
		mul[i] = (mul[i] + 1) * po(mul[i], MOD - 2) % MOD;
	}
	dp[9][0] = 1;
	fm = (1 << gp.size()) - 1;
	for (int i = 1; i <= fm; i++) {
		mu = 1;
		u = 0;
		for (int j = 0; j < gp.size(); j++)
			if (i & (1 << j))
				u |= gp[j];
		for (int j = 1, bm = 3; j < hv; j++, bm <<= 1)
			if ((u & bm) == bm)
				mu = mu * mul[j] % MOD;
		im = i ^ fm;
		for (int j = 1; j <= 9; j++) {
			smu = mu * (j == 9 ? 1 : j) % MOD;
			if (dp[j][0])
				dp[j - 1][i] = (dp[j - 1][i] + dp[j][0] * smu) % MOD;
			for (int k = im; k; k = (k - 1) & im)
				if (dp[j][k])
					dp[j - 1][i | k] = (dp[j - 1][i | k] + dp[j][k] * smu) % MOD;
		}
	}
	for (int i = 0; i < 9; i++)
		sum += dp[i][fm];
	printf("%lld\n", ans * sum % MOD);
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	int n;
	cin >> n;
	vector<int> w(n);
	int g1 = 0;
	int g2 = 0;
	for(int i = 0; i < n; ++i)
	{
		cin >> w[i];
		g2 += w[i];
	}

	int ans = 10000;
	for(int i = 0; i < n; ++i)
	{
		g1 += w[i];
		g2 -= w[i];
		ans = min(ans, abs(g2 - g1));
	}
	cout << ans;

}

int main()
{
	fastio;
	solve();

	return 0;
}

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

int main(){
  int a,sum;
  string s1,s2,s11,s22;
  cin>>a;
  cin>>s1>>s2;
  sum=a*2;
  for(int i=0;i<a;i++){
    s11=s1.substr(i , a);
    s22=s2.substr(0 , a-i);
    if(s11==s22){
      sum=sum-(a-i);
      break;
    }
  }
  cout<<sum<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define MAX_R 100
#define MAX_C 100

using namespace std;

int r, c, arr[MAX_R+1][MAX_C+1];

void solve() {
    for(int i= 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            arr[i][c] += arr[i][j];
        }
    }
    for(int i= 0; i <= c; i++) {
        for(int j = 0; j < r; j++) {
            arr[r][i] += arr[j][i];
        }
    }
    for(int i= 0; i <= r; i++) {
        for(int j = 0; j < c; j++) {
            cout << arr[i][j] << " ";
        }
        cout << arr[i][c] << endl;
    }
    
}

int main() {
    cin >> r >> c;
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            cin >> arr[i][j];
        }
    }
    solve();
}





Measured memory_bytes: 3084
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

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

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, M;
    cin >> N >> M;
    VEC(int) A(N);
    READVEC(A);

    int lcm = 1, ret = 0;
    for (int& a : A)
        if (a % 2 == 1) {
            goto done;
        } else
            a /= 2;

    FOR(i, 1, N)
        if (A[i] % 2 != A[i - 1] % 2) {
            goto done;
        }

    for (int a : A) {
        int g = gcd(lcm, a);
        // a / g * lcm
        if (a / g > M / lcm) {
            goto done;
        }

        lcm = lcm / g * a;
    }

    for (int a : A)
        if (lcm / a % 2 == 0) {
            goto done;
        }
    // lcm * some odd number <= M.
    ret = (M / lcm + 1) / 2;
done:
    cout << ret << endl;
    return 0;
};


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

using namespace std;

int n, q, s, t, x, d;

enum Kind { BlockStart = 0, BlockEnd = 1 };

struct Event {
  Kind kind;
  int time;
  int distance;

  Event(Kind _kind, int _time, int _distance)
      : kind(_kind), time(_time), distance(_distance) {}

  bool operator<(const Event &other) {
    if (time == other.time) {
      return kind > other.kind;
    }
    return time < other.time;
  }
};

vector<Event> events;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> s >> t >> x;
    events.push_back(Event(BlockStart, s - x, x));
    events.push_back(Event(BlockEnd, t - x, x));
  }
  sort(events.begin(), events.end());
  // for (int i = 0; i < events.size(); i++) {
  //   printf("%d %d %d\n", events[i].kind, events[i].time, events[i].distance);
  // }
  int it = 0;
  set<int> blocks;
  for (int i = 0; i < q; i++) {
    cin >> d;
    while (events[it].time <= d && it < events.size()) {
      if (events[it].kind == BlockStart) {
        blocks.insert(events[it].distance);
      } else {
        assert(blocks.find(events[it].distance) != blocks.end());
        blocks.erase(events[it].distance);
      }
      it += 1;
    }
    if (blocks.size() > 0) {
      cout << *blocks.begin() << '\n';
    } else {
      cout << -1 << '\n';
    }
  }
}

Measured memory_bytes: 15724
count = int(input())
people=input().split(" ")
people1=[]
 
for i in range(count):
    people1.append(int(people[i]))
 
people1.sort(reverse=True)
#print(people1)

ans=0
k=1
for i in range(count-1):
    if i == 0:
        ans = people1[0]
    elif i % 2 != 0:
        ans = ans+people1[k]
    else:
        ans = ans + people1[k]
        k=k+1
    i=i+1
print(ans)
    

Measured memory_bytes: 31620
#include <stdio.h>
#define N 200002
typedef long long LL;

int a[N];
LL s[N][2];

int read()
{
	char c, f = 0;
	while((c = getchar()) < 48 || c > 57){
		if(c == '-') f = 1;
	}
	int x;
	if(!f){
		x = c - 48;
		while((c = getchar()) > 47 && c < 58) x = x * 10 + (c - 48);
	}
	else{
		x = 48 - c;
		while((c = getchar()) > 47 && c < 58) x = x * 10 - (c - 48);
	}
	return x;
}

int main()
{		
	int n, i;
	LL s1 = 0, s2 = 0, t, x;
	
	scanf("%d", &n);
	for(i = 1; i <= n; i++){
		a[i] = read();
	}
	if(n % 2 == 0){
		s[1][0] = (LL)a[1], s[2][0] = (LL)a[2];
		for(i = 3; i <= n; i++){
			if(i & 1){
				s[i][0] = s[i - 2][0] + (LL)a[i];
			}
			else{
				t = s[i - 2][0];
				if((x = s[i - 3][0]) > t) t = x;
				s[i][0] = t + (LL)a[i];
			}
		}
		t = s[n][0];
		if((x = s[n - 1][0]) > t) t = x;
		printf("%lld\n", t);
		return 0;
	}
	
	s[1][0] = (LL)a[1], s[2][0] = (LL)a[2];
	s[3][1] = (LL)a[3], s[3][0] = (LL)(a[1] + a[3]);
	for(i = 4; i <= n; i++){
		if(i & 1){
			s[i][0] = s[i - 2][0] + (LL)a[i];
			t = s[i - 2][1];
			if((x = s[i - 3][0]) > t) t = x;
			if((x = s[i - 4][0]) > t) t = x;
			s[i][1] = t + (LL)a[i];
		}
		else{
			t = s[i - 2][0];
			if((x = s[i - 3][0]) > t) t = x;
			s[i][0] = t + (LL)a[i];
		}
	}
	t = s[n][1];
	if((x = s[n - 1][0]) > t) t = x;
	if((x = s[n - 2][0]) > t) t = x;
	printf("%lld\n", t);
			
	return 0;
}

Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 5100000
#define MOD 1000000007
#define INF 100000000000000

int main(){
  int X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  vector<ll> p(A),q(B),r(C);
  for(int i=0;i<A;i++){
    cin>>p.at(i);
  }
  for(int i=0;i<B;i++){
    cin>>q.at(i);
  }
  for(int i=0;i<C;i++){
    cin>>r.at(i);
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  p.push_back(0);
  sort(q.begin(),q.end());
  reverse(q.begin(),q.end());
  q.push_back(0);
  sort(r.begin(),r.end());
  reverse(r.begin(),r.end());
  r.push_back(0);
  int red=0;
  int green=0;
  int i=0;
  ll ans=0;
  int count=0;
  while(X>0||Y>0){
    ll a=(ll)p.at(red);
    ll b=(ll)q.at(green);
    ll c=(ll)r.at(i);
    if(X==0){
      if(b>=c){
        ans+=b;
        green++;
        Y--;
        continue;
      }else{
        ans+=c;
        Y--;
        i++;
        continue;
      }
    }
    if(Y==0){
      if(a>=c){
        ans+=a;
        red++;
        X--;
      }else{
        ans+=c;
        X--;
        i++;
      }
      continue;
    }
    if(a>=b&&a>=c){
      ans+=a;
      X--;
      red++;
      continue;
    }
    if(b>=a&&b>=c){
      ans+=b;
      Y--;
      green++;
      continue;
    }
    ans+=c;
    count++;
    X--;
    Y--;
    i++;
  }
  for(int j=0;j<count;j++){
    ll a=p.at(red);
    ll b=q.at(green);
    ll c=r.at(i);
    if(a>=b&&a>=c){
      ans+=a;
      red++;
      continue;
    }
    if(b>=a&&b>=c){
      ans+=b;
      green++;
      continue;
    }
    ans+=c;
    i++;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 3424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
typedef pair<double,double> Pd;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e18;

struct edge{
	ll to,id;
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll x,d;
	cin>>n>>x>>d;
	if(d==0){
		if(x==0){
			cout<<1<<endl;
		}else{
			cout<<n+1<<endl;
		}
		return 0;
	}
	if(d<0){
		d*=-1;
		x*=-1;
	}
	map<int,vector<P>> mp;
	rep(k,n+1){//高橋君が取る数の個数を決め打ち
		ll l=k*(k-1)/2;
		ll r=k*(2*n-k-1)/2;
		ll c=k*x+l*d;
		r-=l;
		mp[(c%d+d)%d].emplace_back(c,r);
	}
	ll ans=0;
	for(auto itr:mp){
		vector<P> now=itr.se;
		int m=now.size();
		rep(i,m){
			now[i].fi=(now[i].fi-itr.fi)/d;
		}
		vector<P> ev;
		rep(i,m){
			ev.emplace_back(now[i].fi,1);
			ev.emplace_back(now[i].fi+now[i].se+1,-1);
		}
		sort(begin(ev),end(ev));
		ll cnt=0,pre=-inf;
		rep(i,2*m){
			ll len=ev[i].fi-pre;
			if(cnt) ans+=len;
			cnt+=ev[i].se;
			pre=ev[i].fi;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 22144
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local A = {}
for i=1,26 do
    A[i] = string.char(0x60 + i)
end
local N = read.n()

local ans = {}
local build = {}
local function dfs_cps(i, mx, cont)
    if i == N then
        table.insert(ans, table.concat(build))
        return cont()
    else
        local function make_cont(j, lim)
            return function()
                if j <= lim then
                    build[i+1] = A[j]
                    return dfs_cps(i+1, math.max(j,mx), make_cont(j+1,lim))
                else
                    return cont()
                end
            end
        end
        return make_cont(1, mx+1)()
    end
end
dfs_cps(0, 0, function()
    for i=1,#ans do
        print(ans[i])
    end
    --print(#ans)
end)

Measured memory_bytes: 21880
#include<bits/stdc++.h>
                #define vll vector<ll>
                #define vi vector<int>
                #define vvi vector<vector<int>>
                #define vpll vector<pair<ll,ll>>
                #define pii pair<int,int>
                #define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
                #define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
                #define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
                #define MOD 1000000007
                #define INF 0x7FFFFFFF
                #define ALL(v) v.begin(), v.end()  
                #define m0(x) memset(x,0,sizeof(x))
                typedef long long ll;
                 
                using namespace std;
                 
                int main(){
                    int N;
                    cin >> N;
                    vector<int> A(N), B(N), C(N-1);
                    REP(i,N) cin >> A[i];
                    REP(i,N) cin >> B[i];
                    REP(i,N-1) cin >> C[i];
                    int ans = B[A[0]-1];
                    REP2(i,1,N){
                      ans += B[A[i]-1];
                      if(A[i] - A[i-1] == 1) ans += C[A[i-1]-1];
                    }
                    cout << ans << endl;
                    return 0;
                }

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e7+50;
const int mod=1e9+7;
using namespace std;
string n;
int main(){
	cin>>n;
	for (int k=0; k<3; k++){
		if (n[k]=='9'){
			n[k]='1';
		}
		else{
			n[k]='9';
		}
	}
	cout<<n;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
int main(){
  int kazu = 0;
  cin >> kazu;
  vector<int> a(100000);
  vector<int> b(100000);
  for(int i = 0;i < 100000;i++)a[i] = 0,b[0] = 0;
  for(int i = 0;i < kazu;i++){
    int n = 0;
    cin >> n;
    n--;
    if(i % 2 == 0)a[n]++;
    else b[n]++;
  }
  int res = 0;
  int afirst,asecond,bfirst,bsecond;
  afirst = *max_element(a.begin(),a.end());
  bfirst = *max_element(b.begin(),b.end());
  int ai,bi;
  for(int i = 0;i < a.size();i++){
    if(a[i] == afirst){
      a[i] = 0;
      ai = i;
      break;
    }
  }
  for(int i = 0;i < b.size();i++){
    if(b[i] == bfirst){
      b[i] = 0;
      bi = i;
      break;
    }
  }
  if(ai != bi)res = kazu - afirst - bfirst;
  else{
    asecond = *max_element(a.begin(),a.end());
    bsecond = *max_element(b.begin(),b.end());
    res = min(kazu - afirst - bsecond,kazu - asecond - bfirst);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <cassert>
#include <random>
#ifdef DEBUG
#include "./Lib/debug.hpp"
#include "./Lib/Timer.h"
#else
#define dump(...)
template<class T>inline auto d_val(T a, T b) { return a; }
#endif

/* (=＾o＾=) */
#define int ll

/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
#define SORT(x) do{sort(ALL(x));}while(false)
#define RSORT(x) do{sort((x).rbegin(),(x).rend());}while(false)
#define UNIQUE(v) do{v.erase( unique(v.begin(), v.end()), v.end() );}while(false)
#define MAX(x,y) do{x = std::max(x,y);}while(false)
#define MIN(x,y) do{x = std::min(x,y);}while(false)
#define BR do{cout<<"\n";}while(false)

/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;
template<class T>
using V = std::vector<T>;

/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;

/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;

/* Initial processing  */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;

/* Remove the source of the bug */
signed pow(signed, signed) { assert(false); return -1; }

/* define hash */
namespace std { template <>	class hash<std::pair<ll, ll>> { public:	size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; }

/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

//=============================================================================================

signed main() {
	ll n;
	cin >> n;
	FOR(i, 1, 10) FOR(j, 1, 10) {
		if (i * j == n) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
s = input()
t = input()

s_len = len(s)
t_len = len(t)
count = 0
c_min = 1000

for i in range(s_len - t_len + 1):
    count = 0
    for j in range(t_len):
        if s[i + j] == t[j]:
            continue
        count += 1
    if c_min > count:
        c_min = count

print(c_min)


Measured memory_bytes: 9064
import math

N = int(input())

def gcd(a, b):
    while b: a, b = b, a % b
    return a

def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1

def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)

def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret

pfacts = primeFactor(N)
ans = 0
for p, e in pfacts.items():
    i = math.floor((-1 + math.sqrt(1 + 8 * e)) / 2)
    ans += i
print(ans)

Measured memory_bytes: 9352
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;
// int64_t INF = 9223372036854775807;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,k;
    cin >> n >> k;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    // kが非常に大きい
    // どこかで循環しているから、それを見つける
    // 次の街
    vi memo(n,0);
    memo.at(0) = 1;
    int64_t next = 0;
    rep(i,INF){
        next = a.at(next)-1;
        if(memo.at(next) != 2){
            memo.at(next)++;
        }else{
            break;
        }
    }
    int64_t init = 0;
    int64_t circle = 0;
    rep(i,n){
        if(memo.at(i)==1) init++;
    }
    rep(i,n){
        if(memo.at(i)==2) circle++;
    }
    int64_t realk = k;
    if(k>=init){
        realk = init + (k-init)%circle;
    }
    // cout << "init:" << init << endl;
    // cout << "circle:" << circle << endl;
    // cout << "realk:" << realk << endl;
    // rep(i,n) cout << "memo:" << memo.at(i) << endl;
    next = 0;
    rep(i,realk){
        next = a.at(next)-1;
    }
    cout << next+1 << endl;
}

Measured memory_bytes: 6348
import sys
input = sys.stdin.readline
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[y] - self.weight[x]


N,M=map(int,input().split())
uf=WeightedUnionFind(N)

for i in range(M):
    #print(a)
    #print(uf.weight)
    L,R,D=map(int,input().split())
    L-=1
    R-=1

    if uf.same(L,R):
        if uf.diff(L,R)!=D:
            print("No")
            exit()
    else:
        uf.union(L,R,-D)
        #a[R]=a[L]+D
#print(a)
print("Yes")


Measured memory_bytes: 10028
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int h, w; cin >> h >> w;
    vector<string> grid(h+2);
    rept(i, 1, h+1){
        string s; cin >> s;
        grid[i] = s;
        grid[i] = "*" + s + "*";
    }
    grid[0] = "";
    grid[h+1] = "";
    rep(i, w+10){
        grid[0] += "*";
        grid[h+1] += "*";
    }
    /*
    rep(i, h+2){
        rep(j, w+2){
            cout << grid[i][j];
        }cout << ln;
    }
    */
    const int dx[4] = {0,0,-1,1};
    const int dy[4] = {1,-1,0,0};
    vector<vector<int>> costs(h+2, vector<int>(w+2, INF));
    queue<pii> que;
    rept(i, 1, h+1){
        rept(j, 1, w+1){
            if(grid[i][j]=='#'){
                que.push({i, j});
                costs[i][j] = 0;
            }
        }
    }
    while(!que.empty()){
        auto p = que.front(); que.pop();
        int y = p.first, x = p.second;
        rep(k, 4){
            int nx = x + dx[k], ny = y + dy[k];
            if(grid[ny][nx] == '.'){
                grid[ny][nx] = '#';
                costs[ny][nx] = costs[y][x] + 1;
                que.push({ny, nx});
            }
        }
    }
    int res = -INF;
    rept(i, 1, h+1){
        rept(j, 1, w+1){
            if(costs[i][j]!=INF){
                chmax(res, costs[i][j]);
            }
        }
    }
    cout << res << ln;
}
    


Measured memory_bytes: 17148
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int main() {
	int n, a, x = 0, y = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 4 == 0) x++;
		else if (a % 2 != 0) y++;
	}
	if (y == x + 1 && x + y == n || x >= y) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n,a,b,c,d,e,f;

int main(void){

  while( cin >> n , n ){

    n = 1000 - n;
    a = b = c = d = e = f = 0;

    while( n >= 500 ){
      a++;
      n -= 500;
    }
    while( n >= 100 ){
      b++;
      n -= 100;
    }
    while( n >= 50 ){
      c++;
      n -= 50;
    }
    while( n >= 10 ){
      d++;
      n -= 10;
    }
    while( n >= 5 ){
      e++;
      n -= 5;
    }
    while(n){
      f++;
      n--;
    }
    cout << a + b + c + d + e + f << endl;
  }
  return 0;
}

Measured memory_bytes: 1160