akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
using namespace std;
//
const int inf=1e9+7;//0x3f
//
int DP[101];
int main(){
	int N;
	cin>>N;
	DP[4]=1;DP[7]=1;
	for(int i=8;i<=N;i++){
		DP[i]=DP[i-4]+DP[i-7];
	}
	cout<<(DP[N]?"Yes":"No")<<endl;
	return 0;
}

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


def countMask(a):
    ret = 0
    for x in cand:
        if (x & a) == a:
            ret += 1
    return ret


cand = []
for i in range(N):
    sum = 0
    for j in range(i, N):
        sum += A[j]
        cand.append(sum)

ans = 0

for i in range(40, -1, -1):
    if (countMask(ans | (1 << i)) >= K):
        ans |= 1 << i

print(ans)


Measured memory_bytes: 28848
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

string a, b;
int main() {
  while (cin >> a >> b) {
	string res = "";
	for (int i = 0; i < a.size(); ++i) {
	  res += a[i];
	  if (i < b.size()) res += b[i];
	}
	cout << res << endl;
  }
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D;
cin >> A >> B >> C >>D;
if(A*B == C*D||A*B>C*D){
    cout<<A*B<<endl;
}
else{
    cout<<C*D<<endl;
    
}
return 0;
}

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

int N, K;
int main(){
    cin >> N >> K;
    
    vector<long long> x(N);
    for (int i = 0; i < N; i++) cin >> x[i];
    
    long long res = 1LL<<60;
    
    for (int i = 0; i +K -1 < N; i++){
        long long left = x[i];
        long long right = x[i+K-1];
        
        long long firstMove = min(abs(left),abs(right));
        
        res = min(res, firstMove + right - left);
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
j=true
n=gets.to_i
a=gets.split.map &:to_i
t1=0
t2=0
c1=0
c2=0
n.times do |i|
  t1+=a[i]
  t2+=a[i]
  if j
    if t1<=0
      c1+=1-t1
      t1=1
    end
    if t2>=0
      c2+=1+t2
      t2=-1
    end
  else
    if t2<=0
      c2+=1-t2
      t2=1
    end
    if t1>=0
      c1+=1+t1
      t1=-1
    end
  end
  j=!j
end
p [c1,c2].min

Measured memory_bytes: 8588
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;

int n,m,xx[100010],par[100010],p[100010];
pair<int,int> a[100010];
vector<pair<int,int> > v[100010],g[100010];
vector<int> res;
bool vis[100010];

inline void dfs(int x)
{
	vis[x]=1;
	for(int i=0;i<v[x].size();i++){
		int u=v[x][i].first;
		if(vis[u]) continue;
		g[x].push_back(make_pair(u,v[x][i].second));
		g[u].push_back(make_pair(x,v[x][i].second));
		dfs(u); 
	} 
}

inline void dfs2(int x,int pr)
{
	p[x]=pr;
	vis[x]=1;
	int num=0;
	for(int i=0;i<g[x].size();i++) if(!vis[g[x][i].first]){
		dfs2(g[x][i].first,x);
		num+=par[g[x][i].first];
	}
	num%=2;
	if(xx[x]==num) par[x]=0;
	else par[x]=1;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i].first>>a[i].second;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n+1;i++){
		xx[i]=(a[i-1].second!=a[i].second);
	}
	a[n+1]=make_pair(INF,INF);
	for(int i=1;i<=m;i++){
		int l,r;
		cin>>l>>r;
		int pos1=lower_bound(a+1,a+n+1,make_pair(l,0))-a;
		int pos2=upper_bound(a+1,a+n+1,make_pair(r,1))-a-1;
		if(pos1>pos2) continue;
		v[pos1].push_back(make_pair(pos2+1,i));
		v[pos2+1].push_back(make_pair(pos1,i));
	}
	for(int i=1;i<=n+1;i++) if(!vis[i]){
		dfs(i);
	}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n+1;i++) if(!vis[i]){
		dfs2(i,-1);
		if(par[i]==1){
			cout<<-1<<endl;
			return 0;
		}
	}
	for(int i=1;i<=n+1;i++){
		for(int j=0;j<g[i].size();j++){
			if(p[g[i][j].first]==i&&par[g[i][j].first]==1){
				res.push_back(g[i][j].second);
			}
		}
	}
	sort(res.begin(),res.end());
	cout<<res.size()<<endl;
	for(int i=0;i<res.size();i++){
		cout<<res[i]<<" ";
	} 
	cout<<endl;
	return 0;
}

Measured memory_bytes: 20096
w = input()
N = int(input())
for n in range(N):
    o = input().split()
    if o[0] == "print":
        print(w[int(o[1]):int(o[2])+1])
    if o[0] == "reverse":
        a = w[int(o[1]):int(o[2])+1]
        w = w[:int(o[1])] + a[::-1] + w[int(o[2])+1:]
    if o[0] == "replace":
        b = [x for x in w]
        i = [y for y in o[3]]
        for j in range(len(i)):
            b[int(o[1])+j] = i[j]
        w = "".join(map(str,b))
            


Measured memory_bytes: 5640
import collections
import itertools

N, M=map(int, input().split())
a = []
for i in range(N):
  b = []
  b = list(map(int, input().split()))
  del b[0]
  a.extend(b)

counter = collections.Counter(a)

ret = [letter for letter,count in counter.most_common() if count == counter.most_common()[0][1]]
if N == counter.most_common()[0][1]:
	print(len(ret))
else:
  print(0)
 

Measured memory_bytes: 3316
# 貪欲の評価関数を選ぶ
d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]


def calc_score(T):
    L = [-1 for j in range(26)]
    X = [0 for j in range(26)]
    score = 0
    for i in range(d):
        score += S[i][T[i]]
        X[T[i]] += (d - i) * (i - L[T[i]])
        L[T[i]] = i
    for j in range(26):
        score -= C[j] * (dd - X[j])
    return score


max_score = -10**8
best_T = [0 for i in range(26)]
for next_day in range(26):
    T = []
    L = [-1 for j in range(26)]
    for i in range(d):
        max_diff = -10**7
        best_j = 0
        for j in range(26):
            memo = L[j]
            L[j] = i
            diff = S[i][j] - sum([C[k] * (min(i + next_day, d) - L[k])
                                  for k in range(26)])
            if diff > max_diff:
                max_diff = diff
                best_j = j
            L[j] = memo
        T.append(best_j)
        L[best_j] = i
    score = calc_score(T)
    if score > max_score:
        max_score = score
        best_T = T
for t in best_T:
    print(t + 1)


Measured memory_bytes: 74908
#include<stdio.h>

int main(void)
{
  int W,H,x,y,r;

  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

  if(r<=x&&x<=W-r&&r<=y&&y<=H-r)
    printf("Yes\n");
  else
    printf("No\n");


  return 0;
}

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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << "\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int N = 3e3+5;
LL arr[N];

LL dp[N][N][2];

LL dfs(int l, int r, bool Taro){
    if(l > r) return 0;
    if(dp[l][r][Taro] != -1) return dp[l][r][Taro];
    LL res = 0;
    if(Taro){
        res = max(arr[l] + dfs(l+1, r, false), arr[r] + dfs(l, r-1, false));
    }
    else{
        res = min(-arr[l] + dfs(l+1, r, true), -arr[r] + dfs(l, r-1, true));
    }
    return dp[l][r][Taro] = res;
}

void solve(){
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> arr[i];

    memset(dp, -1, sizeof dp);
    cout << dfs(0, n-1, true) << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}


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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;

  int l=a+b;
  int r=c+d;

  if(l>r) cout<<"Left"<<endl;
  else if (l==r) cout<<"Balanced"<<endl;
  else cout<<"Right"<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int h,m,s = 0 ;
    int a = 0;
    cin >> a ;
    h = a / 3600 ;
    m = (a-(3600 * h)) / 60;
    s = (a-(3600 * h) - (60 * m));
    cout << h << ":" << m << ":" << s << endl ;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    string s;
    cin>>s;
    int n = sz(s);
    int k;
    cin>>k;
    
    rep(i, n) {
        if (i == n - 1) {
            s[i] = (s[i] - 'a' + k) % 26 + 'a';
            continue;
        }
        if (s[i] == 'a') continue;
        if ('z' - s[i] + 1 > k) continue;
        k -= 'z' - s[i] + 1;
        s[i] = 'a';
    }
    cout<<s<<endl;
}

Measured memory_bytes: 592
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

int main(){fastio
    string s,t;cin>>s>>t;
    ll a,b;cin>>a>>b;
    string u;cin>>u;
    if(s==u)a--;
    else b--;
    cout<<a<<" "<<b<<endl;
    
    return 0;
}


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

int main(){
  int64_t ret = 0;
  int64_t l_2, l_1;
  l_1 = 1; l_2 = 2;
  int i, N;
  cin >> N;
  if (N == 0){
    cout << l_2 << endl;
    return 0;
  }
  else if (N == 1){
    cout << l_1<< endl;
    return 0;
  }
  else{
    rep(i, 2, N+1){
      ret = l_1 + l_2;
      l_2 = l_1; l_1 = ret;
    }
    cout << ret << endl;
  }
}

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

int main() {
  int n;cin>>n;
  string s;cin>>s;
  vector<int> an;
  rep(i,n-1) {
    if (s[i]==s[i+1]) {an.push_back(2);i++;}
    else an.push_back(1);
  }
  if (n==1) an.push_back(1);
  else if (s[n-1]!=s[n-2]) an.push_back(1);
  
  //rep(i,an.size()) cout << an[i]<<" ";cout<<endl;
  
  long cnt; if (an[0]==1) cnt=3; else cnt=6;
  rep(i,an.size()-1) {
    if (an[i+1]==1) {
      if (an[i]==1) {
        cnt = (cnt * 2) % MOD;
        //cout<<"#11"<<endl;
      } 
      //else cout<<"#21"<<endl;
    } else {
      if (an[i]==1) {
        cnt = (cnt * 2) % MOD;
        //cout<<"#12"<<endl;
      } else {
        cnt = (cnt * 3) % MOD;
        //cout<<"#22"<<endl;
      }
    }
  }
  cout << cnt;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
using namespace std;

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

const double def = 60.0 * 2* M_PI / 360.0;


int kohho( int n, pair<double, double> start, pair<double, double> end ){

  pair<double, double>  s, u, t;

  if( n == 0  ) return 0;

  double diffx = end.first - start.first;
  double diffy = end.second - start.second;

  s.first = ( diffx / 3.0) +  start.first;
  s.second = ( diffy / 3.0) +  start.second;
  t.first = ( diffx * 2.0 / 3.0) +  start.first;
  t.second = ( diffy * 2.0 / 3.0) +  start.second;
  u.first = cos(def) * ( diffx / 3.0) - sin(def) * ( diffy / 3.0) + s.first;
  u.second = sin(def) * ( diffx / 3.0) + cos(def) * ( diffy / 3.0) + s.second;

  kohho( n-1, start, s );

  printf("%.8f %.8f\n", s.first, s.second );

  kohho( n-1, s, u );

  printf("%.8f %.8f\n", u.first, u.second );

  kohho( n-1, u, t );

  printf("%.8f %.8f\n", t.first, t.second );

  kohho( n-1, t, end );

  return 0;
}

int main(){

  int n;
  pair<double, double> start, end;

  start.first = 0.0;
  start.second = 0.0;
  end.first = 100.0;
  end.second = 0.0;

  cin >> n;

  printf("%.8f %.8f\n", start.first, start.second );

  kohho( n, start, end );

  printf("%.8f %.8f\n", end.first, end.second );

  return 0;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 3220
#include <iostream>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <numeric>
    #include <cmath>
        
    using namespace std;    
    typedef unsigned long long ll;
    #define all(x) (x).begin(),(x).end()
    #define rall(x) (x).rbegin(),(x).rend()
     
     
    int main(){
     
        ll N;
        cin >> N;
     
        ll ans = 0;
        ll i_max = sqrt(N)+1;
        for(ll i = 1; i <= i_max; i++){
            if(N % i == 0){
                if(N / i - (ll)1 > i) ans += N / i - (ll)1;
                //cout << N/i-1 << " " << i <<  endl;
            }
        }
        cout << ans << endl;
        /*
        vector<ll> v;
     
        ll cnt = 0;
        while(N > 0){
            if(N % 2 == 0){
                cnt ++;
                N = N / 2;
            }
            else{
                v.push_back(cnt + 1);
                cnt = 0;
                break;
            }
        }
     
        ll mod = 3;
        while(N > mod){
            if(N % mod == 0){
                cnt ++;
                N = N / mod;
            }
            else{
                v.push_back(cnt + 1);
                cnt = 0;
                mod += 2;
            }
        }
     
        ll ans = 1;
        for(ll i = 0; i < v.size(); i++){
            ans = ans * v[i];
        }
        cout << ans << endl;
        */
     
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX=1e6+5;

ll a[MAX];
int main()
{
    int t;
    while(cin>>t)
    {
        for(int i=0;i<t;i++)scanf("%lld",&a[i]);
        sort(a,a+t);
        ll tot=a[t-1]/2;
        for(int i=0;i<t-1;i++)tot+=a[i];
        cout<<tot<<endl;
    }
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  [n, k] <- readIntList
  print $ foldl' (\acc i -> acc * (k - 1)) k [1..(n - 1)]



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

long long A, B, C, N, S;

int main() {
	cin >> A >> B >> C >> N;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			int Z = N - i * A - j * B;
			if (0 <= Z && Z % C == 0) S++;
		}
	}
	cout << S << endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    map<int,int>Dcounter;
    map<int,int>Mcounter;
    
    for (int i=0; i<N; i++){
        int di;
        cin >> di;
        Dcounter[di]++;
    }
    int M;
    cin >> M;
    vector<int>Ts(M);
    for (int i=0; i<M; i++){
        int mi;
        cin >> mi;
        Mcounter[mi]++;
        Ts[i] = mi;
    }

    for (int i=0; i<M; i++){
        int Ti = Ts[i];
        if (Dcounter[Ti] > 0)Dcounter[Ti]--;
        else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 19840
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  300005
ll lt[N],rt[N];
int main()
{
	ios
	ll n,i,j,ans=0;
	cin>>n;
	ll a[n+1];
	for(i=1;i<=n;i++)
		cin>>a[i];
	stack<ll>st;
	st.push(1);
	for(i=2;i<=n;i++){
		while(!st.empty()){
			if(a[st.top()]>a[i]){
				rt[st.top()]=i;
				st.pop();
			}else break;
		}
		st.push(i);
	}
	while(!st.empty())st.pop();
	st.push(n);
	for(i=n-1;i>=1;i--){
		while(!st.empty()){
			if(a[st.top()]>a[i]){
				lt[st.top()]=i;
				st.pop();
			}else break;
		}
		st.push(i);
	}
	//for(i=1;i<=n;i++)cout<<lt[i]<<" "<<rt[i]<<"\n";
	for(i=1;i<=n;i++){
		ll aa,b;
		if(lt[i]==0)aa=i;else aa=i-lt[i];
		if(rt[i]==0)b=n+1-i;else b=rt[i]-i;
		ans+=aa*b*a[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6296
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

ll a[200002];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }

    ll sol = 1e15;
    for (int i = 1; i < n; ++i)
        sol = min(sol, abs(a[n] - a[i] - a[i]));

    cout << sol;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>

#define PI 3.1415926

int main(){
  double a, b, c;
  double rad;
  double l; //third line length
  double S, L, h;

  scanf("%lf %lf %lf", &a, &b, &c);

  rad=c*PI/180.0;
  S=a*b*(sin(rad))/2;
  l=sqrt(a*a+b*b-2*a*b*cos(rad));
  L=a+b+l;
  h=S*2/a;

  printf("%.6f\n", S);
  printf("%.6f\n", L);
  printf("%.6f\n", h);

  return 0;
}

Measured memory_bytes: 2984
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int inf = 1e9 + 10;

int N, M;
int a[1010];
int mask[1010];
int dp[1 << 12 + 5];

signed main()
{
	cin >> N >> M;

	rep(i, M) {
		int b;
		cin >> a[i] >> b;
		rep(j, b) {
			mask[i] |= 1 << (read() - 1);
		}
	}

	rep(i, (1 << N) + 5) dp[i] = inf;
	dp[0] = 0;

	rep(i, M) {
		rep(S, 1 << N) {
			chmin(dp[S | mask[i]], dp[S] + a[i]);
		}
	}

	if (dp[(1 << N) - 1] == inf) {
		cout << -1 << endl;
		return 0;
	}
	cout << dp[(1 << N) - 1] << endl;
}



Measured memory_bytes: 256
def fib_memo(n):
    memo=["Empty"]*(n+1)
    def _fib(n):
        if n==0:
            return 2
        elif n==1:
            return 1
        elif memo[n] != "Empty":
            return memo[n]
        else:
            memo[n]=_fib(n-1)+_fib(n-2)
            return memo[n]
    return _fib(n)

n=int(input())
result=fib_memo(n)
print(str(result))

Measured memory_bytes: 3064
N, M = map(int, input().split())
*A, = map(int, input().split())

d = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
c = [(i, d[i]) for i in A]
minpos = min(c, key=lambda x:x[1])[1]

dp = [0] * (N+1)
digit = [0] * (N+1)

for i in range(minpos, N+1):
    for n, cost in c:
        if i-cost<0 or 0<i-cost<minpos: continue
        a = dp[i]
        b = dp[i-cost] + n * (10**(digit[i-cost]))
        if a<b:
            dp[i] = b
            digit[i] = digit[i-cost] + 1

print(dp[N])

Measured memory_bytes: 52188
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int N,M,X;

int c[12];
int a[12][12];

int data[12][12];

int calcSum(int num)
{
    int sum = 0;
    vector<int> skill(M);
    for(int i=0;i<M;i++) skill[i] = 0;
    for(int i=0;i<N;i++)
    {
        if(num % 2 == 1)
        {
            sum += c[i];
            for(int j=0;j<M;j++) skill[j] += a[i][j];
        }
        num /= 2;
    }

    int minSkill = MIN(skill);
    if(minSkill < X) return 100000*12+1;
    return sum;

}



signed main(){
    cin >> N >> M >> X;

    for(int i=0;i<N;i++)
    {
        cin >> c[i];
        for(int j=0;j<M;j++)
        {
            cin >> a[i][j];
        }
    }

    vector<int> costs(pow(2, N));
    for(int i=0;i<pow(2, N);i++) costs[i] = calcSum(i);

    int minCost = MIN(costs);
    if(minCost > 100000*12){
        cout << -1 << endl;
    }else{
        cout << minCost << endl;
    }


}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9 + 7;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll ans = 1;
    cin >> n;
    map<int, int> mp;
    rep (i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    
    if (n % 2) {
        if (mp[0] != 1) {
            ans = 0;
        } else {
            for (auto const& entry: mp) {
                if(entry.first == 0) continue;
                if (entry.second != 2) {
                    ans = 0;
                    break;
                }
                ans *= 2;
                ans = ans % Inf;
            }
        }
    } else {
        for (auto const& entry: mp) {
            if (entry.second != 2) {
                ans = 0;
                break;
            }
            ans *= 2;
            ans = ans % Inf;
        }
    }
    cout << ans % Inf << endl;
    
    return 0;
}



Measured memory_bytes: 3200
#include<stdio.h>
#include<limits.h>
int main() {
 
    int size; 
    scanf("%d", &size);
    int count = 0;
    int matrix[size+1][size+1];
    int color[size+1], d[size+1], p[size+1];
    int mincost;
 
    for (int i = 0; i < size; i++)
    {
        for (int j = 0; j < size; j++) {
            scanf("%d", &matrix[i][j]);
        }
    }
    for (int i = 0; i < size; i++) 
    {
        color[i] = 0;
        p[i] = -1;
        d[i] = INT_MAX;
    }
    d[0] = 0;
    
    int u;
    while (1) {
        mincost = INT_MAX;
        for (int i = 0; i < size; i++) {
            if (color[i] != 2 && d[i] < mincost) {
                mincost = d[i];
                u = i;
            }
        }
         
        if (mincost == INT_MAX)
            break;
        color[u] = 2;
        for (int v = 0; v < size; v++)
        {
            if (color[v] != 2 && matrix[u][v] < d[v]&& matrix[u][v] != -1)
            {
                p[v] = u;
                d[v] =  matrix[u][v];
                color[v] = 1;
            }
        }
    }
    for (int i = 0; i < size; i++) {
        if (p[i] != -1)
            count += matrix[i][p[i]];
    }
    printf("%d\n", count);
    return 0;
}



Measured memory_bytes: 2112
n, m = gets.strip.split.map(&:to_i)

a=Array.new(n,0)
m.times do |i|
  an,bn = gets.strip.split.map(&:to_i)
  a[an-1] += 1
  a[bn-1] += 1
end
n.times do |i|
puts a[i]
end


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
using namespace std;
int N;
int A[2<<17];
vector<int>G[2<<17];
int dp[2<<17];
int ans[2<<17];
void dfs(int u,int p,int R)
{
	int l=0,r=R;
	while(r-l>1)
	{
		int m=l+r>>1;
		if(dp[m]<A[u])l=m;
		else r=m;
	}
	int pre=dp[r];
	dp[r]=A[u];
	ans[u]=R==r?R++:R-1;
	for(int v:G[u])if(v!=p)dfs(v,u,R);
	dp[r]=pre;
}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=1;i<N;i++)
	{
		int u,v;cin>>u>>v;u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=N;i++)dp[i]=2e9;
	dfs(0,-1,1);
	for(int i=0;i<N;i++)cout<<ans[i]<<endl;
}


Measured memory_bytes: 32712
#include<cstdio>
#include<iostream>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL mod=1e9+7;
LL n,s,p,ans;
char s1[55],s2[55];
int main()
{
	scanf("%lld",&n);getchar();
	scanf("%s%s",s1+1,s2+1);
	if(n==1) return puts("3"),0;
	if(s1[1]==s2[1]) p=2,ans=3,s=1;
	else p=3,ans=6,s=2;
	while(p<=n)
	{
		LL t;
		if(s1[p]==s2[p]) p++,t=1;
		else p+=2,t=2;
		if(s==1) (ans*=2)%=mod;
		else if(t!=1) (ans*=3)%=mod;
		s=t;
	}
	printf("%lld",ans);
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int digit(ll n){
  int res = 0;
  while(n){
    res++;
    n /= 10;
  }
  
  return res;
}

int main(){
  ll n;
  cin >> n;
  int f = INF;
  rep(i, sqrt(n)+1){
    if(n % i == 0){
      f = min(f, digit(n/i));
    }
  }
  cout << f <<endl;
}

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

int main(){
  int n,x;
  int i,j,k;
  int cnt = 0;
  int cntd;

  scanf("%d", &n);

  for(i = 1;i <= n;i += 2){
    cntd = 0;
    for(j = 1;j <= i;j++){
      if(i % j == 0) cntd++;
    }

    if(cntd == 8) cnt++;
  }

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

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    set<string> st;
    rep(i,n) {
        string s; cin>>s;
        st.insert(s);
    }

    cout << st.size() << '\n';
    return 0;
}

Measured memory_bytes: 19148
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#define FUP(i,x,y) for(int i=(x);i<=(y);i++)
#define FDW(i,x,y) for(int i=(x);i>=(y);i--)
#define MAXN 40
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define ll long long
#define db double
using namespace std;
int read(){
    int w=0,flg=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')flg=-1;ch=getchar();}
    while(ch<='9'&&ch>='0'){w=w*10-'0'+ch,ch=getchar();}
    return w*flg;
}
int n,m1,m2,a[MAXN],b[MAXN],c[MAXN],ans=INF,cnt=1,suma,sumb;
int f[410][410];
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int main(){
	
	memset(f,0x3f,sizeof(f));
	f[0][0]=0;
	n=read(),m1=read(),m2=read();
	FUP(i,1,n)
	{
		a[i]=read(),b[i]=read(),c[i]=read();
		suma+=a[i],sumb+=b[i];
		FDW(j,suma,a[i])
		{
			FDW(k,sumb,b[i])
			{
				f[j][k]=min(f[j][k],f[j-a[i]][k-b[i]]+c[i]);
				if(j*1.0/m1==k*1.0/m2)
				{
					ans=min(ans,f[j][k]);
					//printf("%d,%d\n",j,k);
				}
			}
		}
		//printf("%d\n",f[2][2]);
	}
	printf("%d\n",ans==INF?-1:ans);
    return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		int a;
		int b;
		int sumA, sumB;
		
		while (num != 0) {
			sumA = 0;
			sumB = 0;
			for (int i = 0; i < num; i++) {
				a = scanner.nextInt();
				b = scanner.nextInt();
				if (a < b) {
					sumB += (a + b);
				} else if (a > b) {
					sumA += (a + b);
				} else {
					sumA += a;
					sumB += b;
				}
			}
			System.out.println(sumA + " " + sumB);
			num = scanner.nextInt();
		}

	}
}

Measured memory_bytes: 12000
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            Console.WriteLine((A - 1) * (B - 1));
        }
    }
}

Measured memory_bytes: 11092
#include<stdio.h>

int main(){
  long long N, p = 1;
  scanf("%lld", &N);
  
  for (int i = 1; i <= N; i++){
    p *= i;
    p = p%1000000007;
  }
  
  printf("%lld\n", p);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//--<for debugging>
#define whatis(x) cout << #x << " is " << x<<" ";
#define whatisl(x) cout << #x << " is " << x<<"\n";
#define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
#define lline cout<<"\n";
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"___";}
    
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a <<" , ";
    err(++it, args...);
}
//--</for debugging> 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define testcase ll tt; cin >> tt; while(tt--)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define vars ll h,i,j,k,d,l,p,q,r,x,y,a,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
#define vll vector<ll>
#define pll pair<ll,ll>
#define sll set<ll>
#define pint pair<int,int>
const ll INF=1e9+7;
const ll MOD=1e9+7;
int main()
{
    boost vars
    cin>>n>>k>>x>>y;
    v=min(k,n);
    ans=v*x;
    v=max(0ll,n-k);
    ans+=v*y;
    cout<<ans;
}

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

using namespace std;
using ll = long long;

int main() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if(A == B) {
        cout << 0 << endl;
    } else {
        cout << (A - B)*(1 - 2*(K%2)) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3604
N,M=map(int,input().split())
s=[];c=[]
num=[0]*N


for i in range(M):
  array=list(map(int,input().split()))
  s.append(array[0])
  c.append(array[1])

for i in range(1000):
  num=str(i)
  if N != len(num):
    continue
  
  for m in range(M):
    if num[s[m]-1] != str(c[m]):
      break
  #for文のあとにelseブロックを使用
  else:
    print(num)
    exit()
    
print(-1)
  
  

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

int n, A[30];

bool solve(int i, int m);

int main(){
    cin >> n;
    for(int i = 0; i < n; i++) cin >> A[i];
    int q; cin >> q;
    int m;
    for(int i = 0; i < q; i++){
        cin >> m;
        if(solve(0,m)) cout << "yes" << endl;
        else cout << "no" << endl;
    }


}

bool solve(int i, int m){
    // i番目を選んでmから引いていく

    if(m == 0) return true;
    if(i >= n) return false;
    return solve(i+1, m) || solve(i+1, m-A[i]);
    // i番目を選ばなかった時　|| i番目を選んだ時
    // どっちか片方がtrueならできる
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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; }
 
ll MOD = 1000000007;
ll INF =1<<30;



int main(){
    int n;
    cin >>n;
    vector<int>h(n);
    rep(i,n)cin >> h[i];
    reverse(h.begin(),h.end());
    rep(i,n-1){
        if(h[i+1]-h[i]>=2){
            cout << "No" <<endl;
            return 0;
        }
        if(h[i+1]-h[i]==1){
            h[i+1]--;
        }
    }
    cout << "Yes" <<endl;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	string s, t;
	cin >> s >> t;
	int x = s.size(), y = t.size();
	VV pos(26);
	rep(i, x) {
		int c = s[i] - 'a';
		pos[c].push_back(i + 1);
	}
	rep(i, 26) {
		int z = pos[i].size();
		rep(j, z) {
			pos[i].push_back(pos[i][j] + x);
		}
	}
	rep(i, y) {
		if (pos[t[i] - 'a'].size() == 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	ll ans = 0;
	ll posnow = 0;
	rep(i, y) {
		int c = t[i] - 'a';
		auto itr = upper_bound(all(pos[c]), posnow);
		ans += *itr - posnow;
		posnow = *itr;
		if (posnow > x) posnow -= x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1724
#include <stdio.h>
#include <math.h>

int divid[201];

void cal(){
    int i=0, j, half, c, root;
    double rcheck;
    divid[105]=1;
    for(i=107; i<201; i+=2){
        root=sqrt(i); rcheck=sqrt(i);
        if(root==rcheck) continue;
        half=i/2; c=0;
        for(j=2; j<=root; j++){
            if(i%j==0) c+=2;
        }
        if(c==6) divid[i]=1;
    }
}

int main(){
    cal();
    int n, i, total=0;
    scanf("%d", &n);
    for(i=1; i<=n; i++) total+=divid[i];
    printf("%d\n", total);
    return 0;
}


Measured memory_bytes: 128
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


s = str_inp()
t = str_inp()
ans = 0
for i in range(len(s)):
    if s[i] != t[i]:
        ans += 1
print(ans)


Measured memory_bytes: 82808
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  map<string,int>mp;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if(mp.count(s))mp[s]++;
    else mp[s]=1;
  }
  long long kotae=0;
  long long kazu=0;
  auto begin=mp.begin(),end=mp.end();
  for(auto iter=begin;iter!=end;iter++){
    kazu=iter->second;
    if(kazu>1){
      kotae+=kazu*(kazu-1)/2;
    }
  }
  cout<<kotae<<endl; 
  return 0;
}
  


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

using namespace std;


vector<string> vs;
bool used[1010][100];

int search(int x,int y){
  // 0->ツ右,1->ツ可コ,2->ツ債カ,3->ツ湘」
  int sit=0;
  int cx=x;
  int cy=y;
  int over=1;
  int under=1;
  int high=0;
  int dx=1;
  int dy=0;
  int miny=10000000;
  int maxy=-1000000;
  while(1){
    used[cy][cx]=true;
    int nx=cx+dx;
    int ny=cy+dy;
    if(nx>=0&&ny>=0&&ny<vs.size()&&nx<vs[ny].size()
       &&vs[ny][nx]=='*'){
      cx=nx;
      cy=ny;
      miny=min(miny,ny);
      maxy=max(maxy,ny);
      if(sit==0)
	over++;
      else if(sit==2)
	under++;
      if(sit==3&&ny==y&&nx==x)
	break;
    }
    // ツ暗堋督ョツ陛サツ古シツづ個陛渉更
    else{
      if(sit==0){
	for(int i = -1; i <=1; i++){
	  int nnx=cx+i;
	  int nny=cy+1;
	  int nnnx=nnx+i;
	  int nnny=nny+1;
	  if(nnx>=0&&nny<vs.size()&&nny>=0&&nnx<vs[nny].size()
	     &&vs[nny][nnx]=='*'
	     &&nnnx>=0&&nnny<vs.size()&&nnny>=0&&nnnx<vs[nnny].size()
	     &&vs[nnny][nnnx]=='*'
	     ){
	    dy=1;
	    dx=i;
	    break;
	  }
	}
	sit=1;
      }
      else if(sit==1){
	// ツ債カツづ鳴暗堋督ョ
	dx=-1;
	dy=0;
	sit=2;
      }
      else if(sit==2){
	// ツ湘」ツづ鳴暗堋督ョ
	for(int i = -1; i <=1; i++){
	  int nnx=cx+i;
	  int nny=cy-1;
	  int nnnx=nnx+i;
	  int nnny=nny-1;
	  if(nnx>=0&&nny<vs.size()&&nny>=0&&nnx<vs[nny].size()
	     &&vs[nny][nnx]=='*'
	     &&nnnx>=0&&nnny<vs.size()&&nnny>=0&&nnnx<vs[nnny].size()
	     &&vs[nnny][nnnx]=='*'
	     ){
	    dy=-1;
	    dx=i;
	    break;
	  }
	}
	sit=3;
      }
    }
  }
  int res=(over+under)*(abs(miny-maxy)+1)/2;
  return res;
}

int main(){

  int n;
  bool b=false;
  while(cin>>n&&n!=0){
    if(b){
      cout<<"----------"<<endl;
    }
    b=true;
    memset(used,0,sizeof(used));
    int maxLength=0;
    string str;
    getline(cin,str);
    for(int i = 0; i < n; i++){
      getline(cin,str);
      vs.push_back(str);
      maxLength=max(maxLength,(int)str.size());
    }
    for(int i = 0; i < n; i++){
      int diff=maxLength-vs[i].size();
      for(int j = 0; j < diff; j++){
	vs[i]+=' ';
      }
    }
    map<int,int> mii;
    int res=0;
    for(int i = 0; i < vs.size(); i++)
      for(int j= 0;j<vs[i].size();j++)
	if(vs[i][j]=='*'&&!used[i][j])
	  mii[search(j,i)]++;
    for(map<int,int>::iterator it=mii.begin();it!=mii.end();it++)
      cout<<it->first<<" "<<it->second<<endl;
    vs.clear();
  }
  return 0;
}

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

using namespace std;

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

typedef long long ll;
const int MAX_N=400;


struct TILE{
	int c[4];
	int index;
	TILE(int a=0,int b=0,int f=0, int d=0,int ind=0){
		c[0]=a;
		c[1]=b;
		c[2]=f;
		c[3]=d;
		index=ind;
	}
	bool operator < (const TILE &t)const{
		REP(i,4){
			if (c[i]!=t.c[i]){
				return c[i]<t.c[i];
			}
		}
		return false;
	}
	bool operator == (const TILE &t)const{
		REP(i,4){
			if (c[i]!=t.c[i]){
				return false;
			}
		}
		return true;
	}
};

TILE rotate(const TILE &t,int x){
	TILE res=t;
	REP(i,x){
			TILE temp=res;
			REP(j,4){
				res.c[j]=temp.c[(j+3)%4];
			}
	}
	return res;
}

int N;
TILE T[MAX_N*4];
int pa[4]={1,0,3,2};
map<TILE,int> mp;

int main(){
	scanf("%d",&N);
	REP(i,N){
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);
		T[i*4]=TILE(a,b,c,d,i);
		FOR(j,1,4){
			T[i*4+j]=rotate(T[i*4],j);
		}
	}
//	sort(T,T+N*4);
	REP(i,N*4){
		mp[T[i]]++;
	}
	ll ans=0;
	TILE TI[6];
	int cnt[4];
	int cnt2[4][4];
	REP(i,N*4){
		TI[0]=T[i];
		FOR(j,i+1,N*4){
			if (TI[0].index==T[j].index) continue;
			TI[1]=T[j];
			memset(cnt,0,sizeof(cnt));
			REP(k,4){
				TI[k+2]=TILE(TI[0].c[(k+1)%4],TI[0].c[k],TI[1].c[pa[k]],TI[1].c[pa[(k+1)%4]],0);
			}
			REP(k,4){
//				cnt[k]=upper_bound(T,T+N*4,TI[k+2])-lower_bound(T,T+N*4,TI[k+2]);
				cnt[k]=mp[TI[k+2]];
				REP(a,2){
					REP(b,4){
						if (TI[k+2]==rotate(TI[a],b)){
							cnt[k]--;
						}
					}
				}
			}
			REP(k,4){
				FOR(a,k+1,4){
					cnt2[k][a]=0;
					REP(b,4){
						if (TI[k+2]==rotate(TI[a+2],b)){
							cnt2[k][a]++;
						}
					}
				}
			}
			bool f=false;
			ll temp=1;
			REP(k,4){
				REP(a,k){
					cnt[k]-=cnt2[a][k];
				}
				if (cnt[k]<0){
					f=true;
				}else{
					temp*=cnt[k];
				}
			}
			if (!f){
				ans+=temp;
			}
		}
	}
	ans/=12;
	printf("%lld\n",ans);
	return 0;
}


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

int main() {
  int n,d,count=0; cin>>n>>d;
  vector<vector<int>> v(n,vector<int>(d));
  rep(i,n){
    rep(j,d){      
      cin>>v.at(i).at(j);
    }
  }
  for(int i=1;i<n; i++){
    for(int j=0; j<i;j++){
      vector<int> vec(d,0);
      int x=0;
      rep(k,d){
        vec.at(k)=v.at(i).at(k)-v.at(j).at(k);
        x+=pow(vec.at(k),2);
      }
      int intx=pow(x,0.5);
      double  dblx=pow(x,0.5);
     // cout<<intx<<" "<<dblx<<endl;
      if(intx==dblx)count++;
    }
  }
  cout<<count;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

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


int main() {
    ll n,q;
    cin >> n>>q;
    UnionFind tree(n+1);
    rep(i,q){
        ll com,x,y;
        cin>>com>>x>>y;

        if(com==0){
            tree.unite(x,y);
        }else{
            cout<<tree.same(x,y)<<endl;;
        }
    }

    
    return 0;
    

}



Measured memory_bytes: 3264