akhauriyash/Code-Regression huggingface dataset:
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad.ST                 (ST)
import           Control.Monad.State              (StateT (..), runStateT)
import           Data.Attoparsec.ByteString.Char8 (isSpace)
import           Data.Bits                        (shiftR)
import qualified Data.ByteString.Char8            as B
import qualified Data.ByteString.Unsafe           as B
import qualified Data.Vector.Unboxed              as V
import qualified Data.Vector.Unboxed.Mutable      as VM
import           Debug.Trace

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  abs <- V.unfoldrN n parseInt2 <$> B.getContents
  print $ solve n m abs

solve :: Int -> Int -> V.Vector (Int, Int) -> Int
solve _ m abs = go 0 0 abs'
  where
    abs' = sort' abs
    go n p abs
      | V.null abs = p
      | n + b >= m = p + (m - n) * a
      | otherwise = go (n + b) (p + b * a) (V.tail abs)
        where
          (a, b) = V.head abs

sort' :: (V.Unbox a, Ord a) => V.Vector a -> V.Vector a
sort' = V.modify (\v -> quicksort v 0 (VM.length v))

-- https://github.com/as-capabl/haskell-qsort-pfm/blob/master/src/UV.hs
quicksort :: (V.Unbox a, Ord a) => VM.STVector s a -> Int -> Int -> ST s ()
quicksort work iStart iEnd
    | iEnd - iStart <= 1 = return ()
    | otherwise = do
        pivot <- VM.unsafeRead work (((iEnd - iStart) `shiftR` 1) + iStart)
        med <- divide pivot iStart (iEnd - 1)
        quicksort work iStart med
        quicksort work med iEnd
  where
    divide pivot iS' iE'
        | iS' > iE' = return iS'
        | otherwise = do
            lower <- shrinkLower pivot iS' iE'
            higher <- shrinkHigher pivot lower iE'
            if lower >= higher
              then do
                return lower
              else do
                swapWork lower higher
                divide pivot (lower + 1) (higher - 1)

    shrinkLower pivot iS' iE'
        | iS' > iE' = return iS'
        | otherwise = do
            x <- VM.unsafeRead work iS'
            if x >= pivot
              then
                return iS'
              else
                shrinkLower pivot (iS' + 1) iE'

    shrinkHigher pivot iS' iE'
        | iS' > iE' = return iE'
        | otherwise = do
            x <- VM.unsafeRead work iE'
            if x <= pivot
              then
                return iE'
              else
                shrinkHigher pivot iS' (iE' - 1)

    swapWork i j = VM.unsafeSwap work i j

parseInt :: B.ByteString -> Maybe (Int, B.ByteString)
parseInt = B.readInt . B.dropWhile isSpace

parseInt2 :: B.ByteString -> Maybe ((Int, Int), B.ByteString)
parseInt2 = runStateT $
  (,) <$> StateT parseInt
  <*> StateT (B.readInt . B.unsafeTail)


Measured memory_bytes: 5756
N = int(input())
A = [int(i) for i in input().split()]
B = A.copy()
OK = True
count = 0
while OK:
    for c in range(N):
        if A[c] % 2 == 0:
            A[c] = A[c] // 2
            if A[-1] == (B[-1] / (2 ** (count+1))):
                count += 1
        else:
            OK = False
            break
print(count)

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//以上テンプレ
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

int main(){
    ll N,K;
    cin>>N>>K;
    vector<double> vec(N);
    rep(i,N) cin>>vec.at(i);
    rep(i,N) vec.at(i)=(vec.at(i)+1)/2;
    double sum=0;
    rep(i,K){
        sum+=vec.at(i);
    }
    double ans=sum;
    rep(i,N-K){
        sum-=vec.at(i);
        sum+=vec.at(i+K);
        chmax(ans,sum);
    }
    cout<<fixed<<setprecision(7)<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
#define all(vec) vec.begin(), vec.end()
namespace mp = boost::multiprecision;
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
};

class dijkstra {
  private:
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<>> que;

  public:
	dijkstra(int v, int s, vector<edge> G[]) {
		V = v;
		update(s, G);
	}

	void update(int s, vector<edge> G[]) {
		fill(d, d + V + 1, 100000000000ll);
		d[s] = 0;
		que.push(make_pair(0, s));
		while (!que.empty()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (d[v] < p.first)
				continue;
			rep(i, G[v].size()) {
				edge e = G[v][i];
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					que.push(make_pair(d[e.to], e.to));
				}
			}
		}
	}

	int find(int e) {
		return d[e];
	}
};

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

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

bool prime(int a) {
	if (a == 1)
		return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;
	}
	return true;
}

class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(int x, int y) {
		if (same(x, y))
			return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}

	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

	bool same(int x, int y) {
		return Find(x) == Find(y);
	}

	int get_Size(int a) {
		return s[a];
	}
};

set<int> prime_num_factor(int n) {
	if (n < 2)
		return set<int>();
	set<int> prime;
	prime.insert(2);
	for (int i = 3; i <= n; i++) {
		for (int it : prime) {
			if (it * it > i) {
				prime.insert(i);
				break;
			}
			if (i % it == 0)
				break;
		}
	}
	return prime;
}
vector<int> primeFactorization(int n) {
	vector<int> re;
	int cnt = 2;
	while (n != 1) {
		if (n % cnt != 0) {
			cnt++;
			continue;
		}
		n /= cnt;
		re.push_back(cnt);
	}
	return re;
}
signed main() {
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max(0ll,c-(a-b))<<endl;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   int x,y;
    cin >> x >> y;
    
  for(int i=0;i<=x;i++)
  {
      int cr = i;
      int ot = x - i;
      
      if((cr*2) + (ot*4) == y)
      {
          cout <<"Yes";
          return;
      }
  }
    
    
  cout << "No";  
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
using namespace std;
const ll mod = 998244353;
const int N = 305;
int n;
string s, t;
ll dp[N][N][N];
bool p[N][N][N], ign[N][N][N];
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>s;
	n = s.size();
	if(n==1) {
		cout<<1;
		return 0;
	}
	t = s;
	reverse(t.begin(), t.end());
	for(int i=0; i<=n; ++i) {
		for(int j=n; j>=0; --j) {
			for(int k=n; k>=0; --k) {
				if(i==0) {
					if(j==0 && k==0) p[i][j][k]=1;
					continue;
				}
				if(i==1) continue;
				if((s[i-2] == '0' || s[i-1] == '0') && j != 0) {
					p[i][j][k] = p[i][j][k] | p[i-2][j-1][k];
				}
				if((s[i-2] == '1' || s[i-1] == '1') && k != 0) {
					p[i][j][k] = p[i][j][k] | p[i-2][j][k-1];
				}
				p[i][j][k] = p[i][j][k] | p[i-1][j][k];
				if((s[i-1] == '0') && j != 0) {
					p[i][j][k] = p[i][j][k] | p[i-1][j-1][k+1];
				}
				if((s[i-1] == '1') && k != 0){
					p[i][j][k] = p[i][j][k] | p[i-1][j+1][k-1];
				}
				p[i][j][k] = p[i][j][k] | p[i][j+1][k];
				p[i][j][k] = p[i][j][k] | p[i][j][k+1];
				
			}
		}
	}
	for(int i=0; i<=n; ++i) {
		for(int j=0; j<=n; ++j) {
			for(int k=0; k<=n; ++k) {
				if(i==0 && j==0 && k==0) {
					dp[i][j][k] = 1;
					continue;
				}
				if(i==0) {
					dp[i][j][k] = (((j==0)?0LL:dp[i][j-1][k]) + ((k==0)?0LL:dp[i][j][k-1])) % mod;	
					continue;
				}
				dp[i][j][k] = dp[i-1][j][k];
				if(t[i-1] == '0' && k != 0) dp[i][j][k] = (dp[i][j][k] + dp[i][j][k-1]) % mod;
				if(t[i-1] == '1' && j != 0) dp[i][j][k] = (dp[i][j][k] + dp[i][j-1][k]) % mod;
				if(t[i-1] == '0' && (p[n-(i-1)][j+1][k] || ign[i-1][j+1][k])) {
					ign[i][j][k]=1;
				}
				if(t[i-1]=='1' && (p[n-(i-1)][j][k+1] || ign[i-1][j][k+1])) {
					ign[i][j][k]=1;
				}
			}
		}
	}

	ll ans = 0;
	for(int i=0; i<=n; ++i) {
		for(int j=0; j<=n; ++j) {
			for(int k=0; k<=n; ++k) {
				if(!ign[i][j][k] && p[n-i][j][k]) ans = (ans + dp[i][j][k]) % mod;
				//if(p[n-i][j][k] && !ign[i][j][k]) {
				//	cout<<i<<' '<<j<<' '<<k<<": "<<dp[i][j][k]<<'\n';
				//}
			}
		}
	}
	cout<<(ans-1+mod)%mod;
}



Measured memory_bytes: 255656
import collections


def solve():
    n,a,b = map(int,input().split())
    x = list(map(int,input().split()))
    ans = int()
    for i in range(1,n):
        ans += min((x[i]-x[i-1])*a,b)
    print(ans)
    return

if __name__ == "__main__":
    solve()


Measured memory_bytes: 14636
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    int rr = (3000+r)/r;
    int gg = (3000+g)/g;
    int cnt = 0;
    rep(i,rr){
        if(i * r > n) break;
        rep(j,gg){
            if(i*r+j*g > n) break;
            if((n-i*r-j*g)%b == 0 )cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}
/*

*/

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   char a[3][3];

   for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
         cin >> a[i][j];
}
}
   
   cout << a[0][0] << a[1][1] <<a[2][2];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;
ll find(vector<ll> &root,ll x){
    if (root[x]>=0){
        root[x] = find(root, root[x]);
        return root[x];
    }
    return x;
}
void unit(vector<ll> &root,ll a,ll b){
    ll ra, rb;
    ra = find(root, a);
    rb = find(root, b);
    if (ra==rb){
        return;
    }
    else if (root[ra]<=root[rb]){
        root[ra] += root[rb];
        root[rb] = ra;
    }
    else {
        root[rb] += root[ra];
        root[ra] = rb;
    }
    return;
}
void UnionFind(vector<ll> &root,ll m){
    rep(i,m){
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        unit(root, a, b);
    }
    return;
}

int main(){
    ll N, K, L;
    cin >> N >> K >> L;
    vector<ll> road(N);
    vector<ll> metro(N);
    rep(i,N){
        road[i] = -1;
        metro[i] = -1;
    }
    UnionFind(road, K);
    UnionFind(metro, L);
    vector<pll> idx(N);
    map<pll, int> cnt;
    rep(i,N){
        idx[i] = mp(find(road, i), find(metro, i));
        cnt[idx[i]]++;
    }
    cout << cnt[idx[0]];
    repf(i,1,N){
        cout << " " << cnt[idx[i]];
    }
    cout << endl;
}


Measured memory_bytes: 18048
#include <iostream>
using namespace std;
int main(){
    int x, y;
    int i = 1;
    while(i <= 3000){
        cin >> x >> y;
        if(x == 0 && y == 0){
            break;
        } else if(x < y){
            cout << x << " " << y << endl;
        } else {
            cout << y << " " << x << endl;
        }
        
        i++;
    }
    
    return 0;
}


Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		int x;
		int i = 0;

		while ( 0 !=  ( x = sc.nextInt() ) ) {
			i++;
			sb.append("Case ").append(i).append(": ").append(x).append("\n");
		}

		System.out.print(sb);
	}

}

Measured memory_bytes: 42204
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long int
#define MOD 1000000007

int main() {
    long int n,a[100002],b[100002]={0};
    cin>>n;
    for(long int i=1;i<=n;i++){
        cin>>a[i];
    }
    ll count=0;
    for(long int i=1;i<=n;i++){
        if(b[i]==0){
            if(a[a[i]]==i){
                count++;
                b[i]=1;
                b[a[i]]=1;
            }
        }
    }
    cout<<count<<endl;
	// your code goes here
	return 0;
}


Measured memory_bytes: 1792
while True:
    n,x=map(int,input().split())
    if n == 0 and x == 0:
        break
    count=0
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if i+j+k+3 == x:
                    if i < j and j < k:
                        count += 1
    print("%d"%(count))



Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>

using namespace std;

int main(){
    int n; cin>>n;
    vector<char> s(n);
    int firstw = 1e9;
    int wcnt = 0;
    for(int i = 0; i < n; i++){
        cin>>s[i];
        if(s[i] == 'W'){
            wcnt++;
            if(firstw == 1e9)
                firstw = i;
        }
    }
    if(firstw == 1e9){
        cout<<0<<endl;
        return 0;
    }
    int pos = 0;
    for(int i = 0; i < wcnt; i++){
        if(s[n - i - 1] == 'R') pos++;
    }
    cout<<min({n - firstw - wcnt, wcnt, pos});
}


Measured memory_bytes: 3592
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  ll n;
  cin >> n;
  ll m;
  cin >> m;
  ll a[m];
  set<ll> set;
  rep(i,m){
    cin >> a[i];
    set.insert(a[i]);
  }

  ll dp[n+1] = {0};
  dp[0] = 1;
  if(a[0] == 1) dp[1] = 0;
  else dp[1] = 1;

  for(int i = 2; i <= n; i++){
    if(set.count(i) == 0){
      dp[i] += dp[i-1];
      dp[i] %= mod;
      dp[i] += dp[i-2];
      dp[i] %= mod;
    }
  }
  printf("%lld\n", dp[n]);
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int X;
	cin >> X;
	int ans = 1;
	for (int i = 2; i <= 10; i++)
	{
		for (int n = 1; pow(n,i) <= X; n++)
		{
			ans = max(ans, (int)pow(n, i));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

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

int main() {
  vector<string> vs;

  int n, l;
  cin >> n >> l;
  while (n--) {
    string s;
    cin >> s;
    vs.pb(s);
  }

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

  for (string s : vs) {
    cout << s;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    
    int x = 1;
    int k = 0;
    int ans = 0;
    while (x * 10 <= n) {
        if (k % 2 == 0) {
            ans += x * 9;
        }
        x *= 10;
        k += 1;
    }
    if (k % 2 == 0) ans += n - x + 1;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
K = int(input())

l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[K-1])



Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stack>
#include<queue>
using namespace std;

typedef long long ll;

int main(){
	string s,t="CODEFESTIVAL2016";
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
  AOJ 2100
  Title:Saizo
  @kankichi573
*/
#include <stdio.h>
#define max(x,y) (((x)>(y))?(x):(y))
int d,N;


main()
{
  int i,j,ret,prev,now,max_up,max_down,diff;
  scanf("%d",&d);
  for(i=0;i<d;i++)
    {
      scanf("%d",&N);
      scanf("%d",&prev);
      max_up=max_down=0;
      for(j=1;j<N;j++)
	{
	  scanf("%d",&now);
	  diff=now-prev;
	  if(diff>0)
	    max_up=max(max_up,diff);
	  else
	    max_down=max(max_down,-diff);
	  prev=now;
	}
      printf("%d %d\n",max_up,max_down);
    }
  return(0);
}

Measured memory_bytes: 596
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
#include<algorithm>
int main()
{
	int a,b,t;
	scanf("%d%d%d",&a,&b,&t);
	double m=t+0.5;
	int i=0;
	int n=a;
	int k=b;
	if(m<a)
	printf("0\n");
	if(m>=a)
	{
			for(;i<t/a;)
	{	i++;
		n=a*i;
			k=b*i;
			
	}
	printf("%d\n",k);
	}

	return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;

fn mypow(a: u64, b: u64, md: u64) -> u64 {
    if b == 0 {
        1
    } else {
        let tmp = mypow(a, b / 2, md);
        if b % 2 == 1 {
            (((tmp * tmp) % md) * a) % md
        } else {
            (tmp * tmp) % md
        }
    }
}

fn main() {
    input! {
        k: usize,
        s: Chars,
    }
    let n = k + s.len();
    let md = 1000000007;
    let max_n = 2000010;
    let mut fact = vec![1 as u64; max_n];
    let mut inv = vec![1 as u64; max_n];
    fact[0] = 1;
    for i in 2..max_n {
        fact[i] = fact[i - 1] * i as u64 % md;
        inv[i] = mypow(fact[i], md - 2, md);
    }
    let mut ans: u64 = 1;
    for _ in 0..n {
        ans *= 26;
        ans %= md;
    }
    let mut sum: u64 = 0;
    for i in 0..s.len() {
        let mut comb = fact[n] * inv[i] % md;
        comb = comb * inv[n-i] % md;
        //println!("i: {}, comb: {}", i, comb);
        sum += mypow(25 as u64, (n - i) as u64, md) * comb % md;
        sum %= md;
    }
    println!("{}", (ans + md - sum) % md);
}


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

int main() {
  long long a=0,b=0,c=0,d=0,m=0,n=0,p=0,q=0;
  
 cin >> n;

vector<char> x(n,false);
for(int i=0;i<n;i++)
{
cin >> x.at(i);
if(x.at(i)=='R')
{
a++;
}
}

for(int i=0;i<a;i++)
{
if(x.at(i)=='R')
{
b++;
}
}	  
 
cout << a-b; 
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  int K, X;
  cin >> K >> X;
  if(500 * K >= X) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int i = 0; i< N; i++)
typedef long long ll;
 
int main() {
    ll a,b,n; cin >> a >> b >> n;
    ll x;
    if(n >= b-1) x = b-1;
    else x = n;
    ll ans = floor(a*x/b) - a*floor(x/b);
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define endl "\n" 
#define pi acos(-1)
#define ll long long 
using namespace std;
void att(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}
void sirra(){
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
}
void solve();
int main(){
	att();sirra();
	int q=1;//cin>>q;
	while(q--){
		solve();
	}
}
void solve(){
	int l,r,n,k(0);cin>>l>>r>>n;
	for(int i=l;i<=r;i++){
		if(i%n==0)
			k++;
	}
	cout<<k;
}

Measured memory_bytes: 3636
#include <stdio.h>

char ans[100010];
char res[100010];
char exp[4][3] = {"SS", "SW", "WS", "WW"};

char flip(char c)
{
	if (c == 'W') {
		return 'S';
	}
	else {
		return 'W';
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	scanf(" %s", ans);
	ans[n] = ans[0];
	ans[n + 1] = ans[1];
	ans[n + 2] = '\0';
	for (int i = 0; i < 4; i++) {
		res[0] = exp[i][0];
		res[1] = exp[i][1];
		for (int j = 1; j <= n + 1; j++) {
			char next = res[j-1];
			if (res[j] == 'W') {
				next = flip(next);
			}
			if (ans[j] == 'x') {
				next = flip(next);
			}
			res[j + 1] = next;
		}
		if (res[0] == res[n] && res[1] == res[n+1]) {
			res[n] = '\0';
			printf("%s\n", res);
			return 0;
		}
	}
	printf("%d\n", -1);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sq(x) ((x)*(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<"\n"
#define fi first
#define se second
const double pi = 3.14159265358979323846;
#define uni(c) (c).resize(unique(all(c))-(c).begin())
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};   // for matrix movement:
void cp()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
void solve()
{
	ll n; cin >> n;
	if (n >= 30)
		cout << "Yes";
	else
		cout << "No";

}
int main()
{
	fast;
	//cp();
	ll t = 1;
	//cin >> t;
	while (t--)
		solve();


	return 0;
}

Measured memory_bytes: 3644
def inpl(): return [int(i) for i in input().split()]
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def suma(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

N, K = inpl()
a = [0]
for _ in range(N):
    a.append(a[-1] + int(input()) -K)
c = dict([])
for i, v in enumerate(sorted(set(a))):
    c[v] = i+1
Tr = BIT(N+1)
ans = 0
for v in a:
    ans += Tr.suma(c[v])
    Tr.add(c[v], 1)
print(ans)

Measured memory_bytes: 45032
#include <cstring>
#include <iostream>
#define MOD 1000000007
using namespace std;
int a[10005];
int f[1000005],lf[1000005];
long long lcm=1;
long long fpow(long long x,long long y)
{
 long long ans=1;
 while(y)
 {
  if(y&1)ans=ans*x%MOD;
  x=x*x%MOD;
  y>>=1;
 }
 return ans;
}
void calc(int x)
{
 memset(f,0,sizeof(f));
 int x1=x;
 for(int i=2;x!=1&&i*i<=x1;i++)
 {
  while(x%i==0)
   x/=i,f[i]++;
  lf[i]=max(lf[i],f[i]);
 }
 if(x!=1)
 {
  f[x]++;
  lf[x]=max(lf[x],f[x]);
 }
}
int main()
{
 int n;
 cin>>n;
 for(int i=1;i<=n;i++)
 {
  cin>>a[i];
  calc(a[i]);
 }
 long long ans=0;
 for(int i=2;i<=1e6;i++)
  lcm=lcm*fpow(i,lf[i])%MOD;
 for(int i=1;i<=n;i++)
  ans=(ans+lcm*fpow(a[i],MOD-2))%MOD;
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 7808
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] elm = br.readLine().split(" ");
		int n = Integer.parseInt(elm[0]);
		int m = Integer.parseInt(elm[1]);
		int l = Integer.parseInt(elm[2]);
		int[][] mata = new int[n][m];
		int[][] matb = new int[m][l];
		long[][] ans = new long[n][l];
		for(int i = 0; i < n ; i++){
			String[] line = br.readLine().split(" ");
			for(int j = 0; j < m ; j++){
				mata[i][j] = Integer.parseInt(line[j]);
			}
		}
		for(int i = 0; i < m ; i++){
			String[] line = br.readLine().split(" ");
			for(int j = 0; j < l ; j++){
				matb[i][j] = Integer.parseInt(line[j]);
			}
		}
		for(int i = 0; i < n ; i++){
			for(int j = 0; j < l ; j++){
				for(int k = 0; k < m; k++){
					ans[i][j] += mata[i][k] * matb[k][j];
				}
				sb.append(ans[i][j]);
				if( j != l-1) sb.append(" ");
				//System.out.print(ans[i][j]+" ");
			}
			sb.append("\n");
			//System.out.println();
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 32152
#include<bits/stdc++.h>
#define long long long
#define N 100005
using namespace std;
long n,un,ans;
string s1,s2;
int main()
{
    ///ofstream cout("out.txt");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    cin>>n;
    cin>>s1>>s2;
    ans=1;
    for(long i=0; i<n; i++)
    {
        if(i==0)
        {
            if(s1[i]==s2[i])
            {
                ans=(ans*3)%1000000007;
            }
            else
            {
                ans=(ans*6)%1000000007;
                i++;
            }
        }
        else
        {
            if(s1[i]==s2[i])
            {
                if(s1[i-1]==s2[i-1])
                {
                    ans=(ans*2)%1000000007;
                }
            }
            else
            {
                if(s1[i-1]==s2[i-1])
                {
                    ans=(ans*2)%1000000007;
                    i++;
                }
                else
                {
                    ans=(ans*3)%1000000007;
                    i++;
                }
            }
        }
        ///cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
using namespace std;
long long n, k, a[100010];

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

    long long ans;
    ans = (n-1) / (k-1);
    if ((n-1) % (k-1) != 0) ans++;

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
while True:
    x=int(input())
    if x==0:
        break
    oturi=int(1000-x)
    
    a=oturi//500
    oturi=oturi%500
    b=oturi//100
    oturi=oturi%100
    c=oturi//50
    oturi=oturi%50
    d=oturi//10
    oturi=oturi%10
    e=oturi//5
    oturi=oturi%5
    f=oturi//1
    
    print(a+b+c+d+e+f)


Measured memory_bytes: 5588
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  
  int n; 
  cin>>n ;
  int a[n] ;

  for (int i = 0; i < n; i++)
  {
      cin >> a[i] ;
  }
    sort(a,a+n) ;
  
  cout << a[n-1]-a[0] << endl ;

return 0 ;

}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    map<char, int> t;
    int n;
    char m[26];
    string suuti;
    getline(cin, suuti);
    n = stoi(suuti);
    rep(i, 26)
    {
        m[i] = char('a' + i);
        t[m[i]] = i;
    }

    rep(i, n)
    {
        string s, s_trans;
        bool flag = 0;
        getline(cin, s);
        s_trans = s;
        rep(a, 26)
        {
            rep(b, 26)
            {
                rep(k, s.size())
                {
                    if (s[k] == ' ')
                        s_trans[k] = ' ';
                    else
                        s_trans[k] = m[a * (t[s[k]] - b + 26) % 26];
                }
                if (s_trans.find("this") != string::npos || s_trans.find("that") != string::npos)
                {
                    flag = 1;
                    break;
                }
            }
            if (flag == 1)
                break;
        }
        OP(s_trans)
    }

    return 0;
}


Measured memory_bytes: 3188
n, w = map(int, input().split())
items = []
for i in range(n):
    array = list(map(int, input().split()))
    items.append(array)

dp = [0] * (w+1)

for i in range(w+1):
    for value, weight in items:
        x = i + weight
        if x > w:
            continue
        dp[x] = max(dp[i] + value, dp[x])

print(dp[w])


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

using namespace std;

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


Measured memory_bytes: 256
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)

int main(){
    int N, X;
    cin >> N>>X;
    int L[N+1];
    rep2(i,N){
        cin >> L[i];
    }
    int D[N+1];
    D[1]=0;
    int k=1;
    for(int i=2;i<=N+1;i++){
        D[i]=D[i-1]+L[i-1];
        if(D[i]>X){
            break;
        }
        k=k+1;
    }
    cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, M = map(int, input().split())
res = []

def solve(l, r):
  global res
  if r <= l: return
  res.append((l, r))
  solve(l + 1, r - 1)


solve(1, M + 1)
solve(M + 2, M * 2 + 1)
for r in res: print(*r)

Measured memory_bytes: 105272
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
 
#define ll long long
 
int main()
{
  ll x,y,a,b,c,i,num,result=0;
  cin>>x>>y>>a>>b>>c;
  vector<ll> red;
  vector<ll> green;
  vector<ll> colourless;
 
  for(i=0;i<a;i++)
  {
    cin>>num;
    red.push_back(num);
  }

  for(i=0;i<b;i++)
  {
    cin>>num;
    green.push_back(num);
  }
 
  for(i=0;i<c;i++)
  {
    cin>>num;
    colourless.push_back(num);
  }

  sort(red.rbegin(),red.rend());
  sort(green.rbegin(),green.rend());

  vector<ll> ans;

  for(i=0;i<x;i++)
  {
    ans.push_back(red[i]);
  }

  for(i=0;i<y;i++)
  {
    ans.push_back(green[i]);
  }

  for(i=0;i<c;i++)
  {
    ans.push_back(colourless[i]);
  }

  sort(ans.rbegin(),ans.rend());

  for(i=0;i<x+y;i++)
  {
    result+=ans[i];
  }

  cout<<result<<endl;
 
}

Measured memory_bytes: 8304
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main(){
    int n; cin >> n;
    vector<int> p(n), q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> pp(n);
    rep(i,n) pp[i] = i+1;
    int cnt = 1;
    int ans1, ans2;
    do {
        if (p == pp) ans1 = cnt;
        if (q == pp) ans2 = cnt;
        cnt++;
    } while (next_permutation(pp.begin(), pp.end()));
    cout << abs(ans1 - ans2) << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader tec=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out=new PrintWriter(System.out);
		for(String line;(line=tec.readLine())!=null;){
			int n=Integer.parseInt(line.trim());
			int[]arr=new int[n];
			for (int i = 0; i < arr.length; i++) 
				arr[i]=Integer.parseInt(tec.readLine().trim());
			if(n==1){
				out.println(arr[0]/2);
				continue;
			}
			long x=arr[0],cont=0;
			
			for (int i = 1; i < arr.length; i++) {				
				x+=arr[i];
				cont+=x/2;
				if((x&1)==1&&arr[i]!=0){
					x=1;
				}else{
					x=0;
				}				
			}
			out.println(cont);
		}
		out.close();		
	}
}

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

using namespace std;
using ll = long long;
using ld = long double;
const int MX = 1e5;

vector<int> g[MX];
bool vis[MX];

void dfs (int v) {
	vis[v] = true;
	for (auto x: g[v]) {
		if (vis[x]) continue;
		dfs(x);
	}
}

int main () {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int cc = 0;
	for (int i = 0; i < n; i++) {
		if (vis[i]) continue;
		dfs(i);
		cc++;
	}

	cout << cc - 1 << '\n';
}


Measured memory_bytes: 9696
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
using namespace std;

int getint(){
    int x = 0, c = getchar();
    while(c > 47 && c < 58){
        x = x * 10 + c - 48;
        c = getchar();
    }
    return x;
}

int rows[300001];
int cols[300001];
int hs[300001], ws[300001];

int main(){
    int H = getint();
    int W = getint();
    int M = getint();
    int h, w, ans;
    int mxr = 0;
    int mxc = 0;
    int ctrow = 0;
    int ctcol = 0;
    for(int i = 0; i < M; ++i){
        h = getint(), w = getint();
        hs[i] = h, ws[i] = w;
        ++rows[h], ++cols[w];

        if(rows[h] == mxr) ++ctrow;
        if(rows[h] > mxr){
            mxr = rows[h];
            ctrow = 1;
        }

        if(cols[w] == mxc) ++ctcol;
        if(cols[w] > mxc){
            mxc = cols[w];
            ctcol = 1;
        }
    }

    long ct = ctrow;
    ct *= ctcol;
    ans = mxr + mxc;

    for(int i = 0; i < M; ++i) if(rows[hs[i]] == mxr && cols[ws[i]] == mxc) --ct;

    if(ct <= 0) --ans;
    printf("%d\n", ans);
}

Measured memory_bytes: 6292
N = int(input())
count=0
P=[]
for i in range(N):
	P.append(int(input()))
P_2=sorted(P)
for i in range(N):
	if i == N-1:
		count+=(P_2[i]//2)
	else:
		count+=P_2[i]

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, K, A[205000];
ll ans;
map<ll, ll> mp;
ll sum[205000];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        A[i]--;
        A[i] %= K;
        sum[i] = (sum[i-1] + A[i]) % K;
    }
    for(int i = 0; i <= N; i++) {
        ans += mp[sum[i]];
        mp[sum[i]]++;
        if(i >= K - 1) {
            mp[sum[i-K+1]]--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
	
#define int long long
#define double long double 
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
// Use for file I/O;
#define FIN string _fname = "paintbarn"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

using namespace std;
	
int gcd(int a, int b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

const int INF = 4e18 + 10;
const int INF2 = 2e18 + 10;
const int INF3 = 2e10;
const int MAXN = 100000;
const int LOGN = 19;
const int MOD = 1e9 + 7;
const int EPS = 1e-9;
const int MULT = 2e5;
const int MCNST = MOD * MOD * 8;

int32_t main() {
	FAST;

	int n;
	cin >> n;
	int a = 0, b = 0, c = 0, d= 0;

	while (n--) {
		string s;
		cin >> s;
		if (s == "AC") a++;
		else if (s == "WA") b++;
		else if (s == "TLE") c++;
		else d++;
	}

	cout << "AC x " << a << '\n';
	cout << "WA x " << b << '\n';
	cout << "TLE x " << c << '\n';
	cout << "RE x " << d;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
struct RH {
  vector<unsigned long long> p,hash;
  void init(const string s) {
    unsigned long long m=1000000007,q=1,n=s.size();
    p.resize(n+1);hash.resize(n+1);p[0]=q;hash[0]=0;
    rep(i,n){p[i+1]=p[i]*m;hash[i+1]=s[i]+hash[i]*m;}
  }
  unsigned long long h(int i)const{return hash[i];}
  unsigned long long h(int i,int j)const{return h(j)-h(i)*p[j-i];}
};
int n,m;
string s[12];
bool u[1<<12];
RH r[12],e;

ll dfs(ll t,ll k) {
  if(t==(1<<n)-1) return 1;
  if(u[t]) return 0;
  u[t]=1;
  rep(i,n) {
    if(t&(1<<i)) continue;
    if(r[i].h(s[i].size())==e.h(k,k+s[i].size())&&dfs(t|(1<<i),k+s[i].size())) return 1;
  }
  return 0;
}

void Main() {
  while(cin >> n >> m && n) {
    ll c=0;
    rep(i,n) {
      R s[i];
      r[i].init(s[i]);
      c+=s[i].size();
    }
    ll ans=0;
    string t="";
    rep(i,m) {
      string z;
      R z;
      t+=z;
    }
    e.init(t);
    rep(i,t.size()-c+1) {
      mem(u);
      ans+=dfs(0,i);
    }
    pr(ans);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3164
//============================================================================
// Name        : template.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

int main() {
	ios::sync_with_stdio(false);
 cin.tie(0);
 string c; cin >> c;
 if(c == "ABC") cout << "ARC" << endl;
 else cout << "ABC" << endl;
return 0;
}


Measured memory_bytes: 3588
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 2e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int st[MAXN];
int top;

void work(){
    char s[100];
    while(~scanf("%s",s)){
        if('0'<=s[0]&&s[0]<='9'){
            int num=0;
            for(int i=0;s[i]!='\0';i++) num=num*10+s[i]-'0';
            st[top++]=num;
        }
        else{
            int y=st[--top];
            int x=st[--top];
//            printf("%d %c %d\n",x,s[0],y);
            if(s[0]=='+') st[top++]=x+y;
            if(s[0]=='-') st[top++]=x-y;
            if(s[0]=='*') st[top++]=x*y;
        }
    }
    printf("%d\n",st[top-1]);
}

int main(){
    work();
    return 0;
}









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

using namespace std;
using ll=long long;
const int N = 512; 
int a[N][N];
ll pos[N][N], neg[N][N];
ll dp[N][N];

void solve() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i!=j) cin >> a[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = i; j >= 0; j--) {
            pos[i][j] += pos[i][j+1] + a[i][j];
            neg[i][j] += neg[i][j+1] + a[j][i];
        }
    }
    memset(dp, 0x3f, sizeof dp);
    dp[0][0] = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            ll sum = 0;
            for (int x = i+1; x <= n; x++) {
                //sum += pos[x][j] - pos[x][i];
                sum += -pos[x-1][j];
                sum += neg[x-1][i];
                dp[x][i] = min(dp[x][i], dp[i][j] + sum);
            }
        }
    }
    ll res = 1ll<<60;
    for (int j = 0; j <= n; j++) {
        res = min(res, dp[n][j]);
    }
    for (int i = 0; i < n; i++) {
        res += pos[i][0];
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 7424
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

char s[15];

int main()
{
	scanf ("%s", s);
	int len = strlen(s);
	if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I')	printf ("Yes\n");
	else printf ("No\n");

}

Measured memory_bytes: 128
#c
N=int(input())
CSF = [None]*(N-1)
for i in range(N-1):
    CSF[i] = list(map(int, input().split()) )

for I in range(N):
    now = 0
    for csf in CSF[I:]:
        now = max( -(-now//csf[2])*csf[2] , csf[1]) + csf[0]
    print(now)

Measured memory_bytes: 68316
A,B = map(int, input().split())

#解法の大まかな流れ
#　AとBの素因数をそれぞれ計算し、And集合の長さを出す

#　数Nの素因数の算出方法
#  基本的には、Nを小さい数から順に割れるだけ割っていく（除算法）
#    割る数は素数だけでいい
# 課題：1～Aまでそれぞれ割って判定では計算量が足りない　A <= 10^12なので
# アイディア①：素数一覧表を作成して、一覧表に入っている数字だけで、割れるか判定
#  ⇒ 素数一覧表の作成の方が高コストになる可能性高い
# アイディア②： eratosthenesの篩の応用


def Soinsu(N):
    soinsu = set([1]) 
    if N > 1:
        # 偶数チェック（ここで引っ掛けられると割る数のカウントアップを倍にできるので)
        div2_flg = 1
        while div2_flg:
            if N % 2 == 0:
                soinsu.add(2)
                N = N/2
            else:
                div2_flg = 0
#         print("after 2: ",N)
        for i in range(3,int(N)+1,2):
#             print("i: ",i, " N: ",N)
        
            div_flg = 1
            while div_flg:
#                 print("   N: ",N)
                if N % i == 0:
                    soinsu.add(i)
                    N = N/i
                else:
                    div_flg = 0
            # 割る数の上限はN**(1/2)であることを適用
            if i**2 > N:
                break
        # 自分自身も入れる：これを入れないと片方がもう一方の素因数である場合を逃す
        soinsu.add(N)
        
    return(soinsu)
            
soi_A = Soinsu(A)
soi_B = Soinsu(B)
# print(soi_A)
# print(soi_B)
print(len(soi_A & soi_B))

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

using namespace std;

int n, score;
string city;
vector<pair<string,int>> v;
vector<pair<string,int>> c;



int main() {
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> city >> score;
        score = 100 - score;
        v.push_back(make_pair(city,score)); 
    }
    c = v;
    sort(c.begin(), c.end());
    for(int j = 0; j < v.size(); j++){
        for(int k = 0; k < v.size(); k++){
            if(c[j]==v[k]){
                cout << k + 1 << endl;
            }
        }
    } 
}

Measured memory_bytes: 256