akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import Data.List

throwAwayKAndGetList :: IO [Int]
throwAwayKAndGetList = do
 _  <- getLine -- throw away K
 ak <- map read <$> words <$> getLine :: IO [Int]
 return ak

main = do
 [n,k] <- map read <$> words <$> getLine :: IO[Int]
 aijList <- concat <$> replicateM k throwAwayKAndGetList
 let a = nub $ sort aijList
 print $ (-) n (length a)

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

#include <vector>
int main(){
    int n,k; cin >> n >> k;
    vector<int> high(n),dp(n);
    for(int i=0; i<n; i++) cin >> high.at(i);
    for(int i=1; i<n; i++){
        dp.at(i) = dp.at(i-1)+abs(high.at(i)-high.at(i-1));
        for(int j = max(0,i-k); j < i-1; j++) {
            dp.at(i) = min(dp.at(i),dp.at(j)+abs(high.at(i)-high.at(j)));
        }
    }
    printf("%d\n",dp[n-1]);
}

Measured memory_bytes: 4064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

const ll INF=1e18;

int main(){
  int N;
  cin>>N;
  vector<ll> H(N),P(N);
  vector<pair<ll,int>> v;
  for(int i=0;i<N;i++){
      cin>>H[i]>>P[i];
      v.push_back(make_pair(H[i]+P[i],i));
  }

  sort(v.begin(),v.end());
  
  ll dp[N+1][N+1]={};
  for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) dp[i][j]=INF;
  dp[0][0]=0;
  for(int i=0;i<N;i++){
      int now=v[i].second;
      for(int j=0;j<N;j++){
          if(H[now]>=dp[i][j]){
              dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+P[now]);
          }
          dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
      }
  }

  int ans=0;
  for(int j=0;j<=N;j++){
      if(dp[N][j]!=INF) ans=j;
  }
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 196096
#include <stdio.h>

#define lli long long int

lli solve(lli a, lli b, lli c) {
	lli ret, left, right, up, low, len;
	low = a / c;
	up = b / c;
	if (low == up)
		return ((b - a + 1) * up);
	left = a;
	right = ((low + 1) * c) - 1;
	ret = (right - left + 1) * low;
	left = up * c;
	right = b;
	ret += ((right - left + 1) * up);
	left = low + 1;
	right = up - 1;
	len = right - left + 1;
	ret += (len * (left + right) / 2);
	return ret;
}

int main() {
	lli n, k, ans;
	scanf("%lld %lld", &n, &k);
	if (k < 1)
		ans = n * n;
	else {
		ans = (n - k) * (n - k + 1) / 2;
		for (lli i = 1; i <= (n - k); i++)
			ans += solve(i, n - k, n - i + 1);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<cmath>
int era[100000];
using namespace std;
int main(void)
{
	int p,q,i,j,kou,x,a,b,suu,flg;
	scanf("%d %d",&p,&q);
	a=q;	b=p;
	while(1)	{
		x=a%b;
		if(x==0)	break;
		a=b;
		b=x;
	}
	for(i=2;i<=100000;i++)	era[i]=1;
	for(i=2;i*i<=100000;i++)	{
		if(era[i]==1)	{
			for(j=2;j*i<=100000;j++)	{
				era[i*j]=0;
			}
		}
	}
	
	
	kou=b;
	x=q/kou;
	a=1;
	for(i=2;i<=100000;i++)	{
		if(era[i]==1 && x%i==0)	{
			a=a*i;
			while(x%i==0)	x/=i;
		}
		if(x==1)	break;
	}
	if(x!=1)	a=a*x;
	printf("%d\n",a);
	return 0;
}
	


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

int main() {
    int N, temp;
    std::vector<int> a;
    
    std::cin >> N;
    
    for (auto i=0; i<N; i++) {
        std::cin >> temp;
        a.push_back(temp);
    }
    
    std::sort(a.begin(), a.end());
    
    std::cout << a.back() - a.front() << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
 int a,b;
 scanf("%d %d",&a,&b);
 if(a < b)
 {
 	printf("a < b\n",a,b);
 }
 if(a > b)
 {
 	printf("a > b\n",a,b);
 }
 else
 if(a == b)
 {
 	printf("a == b\n",a,b);
 }
 return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
char noot(char c)
{
	if(c=='1')return '0';
	return '1';
}
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	int res = 0;
	for(int i=1;i<s.length();i++)
		if(s[i]==s[i-1])s[i]=noot(s[i-1]),++res;
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[200001];
signed main(){
	int n,cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[1]>0){
			cnt=-1;
		}
		if(a[i]-a[i-1]>1){
			cnt=-1;
		}
	}
	if(cnt==-1){
		cout<<"-1";
		return 0;
	}
	for(int i=2;i<=n;i++){
	cnt+=(a[i]==a[i-1]+1)?1:a[i];
	}
	cout<<cnt;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")

#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>         //可変長配列
#include <list>           //双方向連結リスト

using namespace std;

// aはソート済みとする
bool solve(const vector<int>& a, int i, int m){
    if(m == 0) return true;
    if(i >= a.size()) return false;
    bool res = solve(a, i + 1, m) || solve(a, i + 1, m - a[i]);
    return res;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int q;
	cin >> q;
    for(int i = 0, m; i < q; ++i){
        cin >> m;
        if(solve(a, 0, m)) cout << "yes\n";
        else cout << "no\n";
    }
	return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int k;
    cin >> k;
    if (k % 2 == 0)
    {
        cout << (k / 2) * (k / 2);
    }
    else
    {
        cout << (k - 1) / 2 * ((k - 1) / 2 + 1);
    }
}


Measured memory_bytes: 256
// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define output(x)   cout << (x ? "Yes" : "No")<<endl;
using namespace std;


// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	string s, t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();
	if(m == n+1){
		string ss = t.substr(0, n);
		if(s == ss){
			output(1);
		}
		else{
			output(0);
		}
	}
	else{
		output(0);
	}

	return 0;
}  


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    cout << (s < t ? "Yes" : "No") << endl;

    return 0;
}


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

int main(){
  string S;
  cin>>S;
  int counta=0;
  int countb=0;
  for(int i=0;i<S.length();i++){
    if(S.at(i)=='0'){
      counta++;
    }
    else countb++;
  }
  cout<<S.length()-abs(counta-countb)<<endl;
  return 0;
}


  
  

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

using namespace std;

void dfs(vector<vector<int>>& graph, int& num, int node, vector<bool>& visited){
    visited[node] = true;
    num++;
    for(auto x : graph[node]){
        if(!visited[x]){
            dfs(graph, num, x, visited);
        }
    }
}
int biggest_comp(vector<vector<int>>& graph , int n){
    int maxi = 0;
    vector<bool> visited(n + 1, false);
    for(int i = 1; i <= n; i++){
        if(!visited[i]){
            int num = 0;
            dfs(graph, num, i, visited);
            if(num > maxi)
                maxi = num;
        }
    }
    return maxi;
}

int main(){
    // freopen("input.in", "r", stdin);
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n + 1);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    cout << biggest_comp(graph, n);
}


Measured memory_bytes: 26620
#include<cstdio>
long long a,b,x;
long long s,e;
int main(){
    scanf("%lld%lld%lld",&a,&b,&x);
    if(a%x==0)s=a/x;
    else s=a/x+1;
    e=b/x;
    printf("%lld",e-s+1);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
  int a,b[100],c,i,m,M;
  cin >> a;
  b[100] = {};
  m = 0;
  for(i=0;i<a;i++){
    cin >> b[i];
    if(b[i]<0) b[i] =b[i] * (-1);
  }
  m = b[0];
  M = b[0];
  for(i=0;i<a;i++){
    if(m > b[i])m=b[i];
  }
  for(i=0;i<a;i++){
    if(M < b[i])M=b[i];
  }
  c=M-m;
  cout << c << endl;
}
    
    

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

  
int main(){
 string n;
  cin >> n ;
  bool a=false;
  if(n.at(0)=='A') a=true;
  bool b=false;
  rep(i,n.size()-3){
	if(n.at(i+2)=='C') b=true;
  }
  int count=0;
  rep(i,n.size()){
    int x;
    x=n.at(i);
    if(x<=90) count++;
  }
  bool c=false;
  if(count==2) c=true;
  if(a && b && c) cout <<"AC" << endl;
  else cout << "WA" <<endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int n, s, sum, mn=1e9, a[105];
int main() {
	int i;
	cin>>n;
	for(i=1; i<=n; i++) {
		cin>>a[i];
		sum += a[i];
	}
	for(i=1; i<=n; i++) {
		s += a[i];
		mn = min(mn, (int)abs(sum-2*s));
	}
	cout<<mn;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>

using namespace std;

long long N, M;
vector<pair<long long, long long> > a;

int main()
{
    cin >> N >> M;
    for (int i = 0; i < N;i++)
    {
        long long A, B;
        cin >> A >> B;
        a.push_back(make_pair(A, B));
    }
    sort(a.begin(), a.end());
    long long nd = 0;
    long long nm = 0;
    for (int i = 0; i < a.size();i++)
    {
        long long r = M - nd;
        if(r <= a[i].second)
        {
            nd += r;
            nm += r * a[i].first;
        }
        else
        {
            nd += a[i].second;
            nm += a[i].first * a[i].second;
        }
    }
    cout << nm << endl;
    return 0;
}

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

#define MAX_N 100005
#define bit(mask, i) (mask & (1<<i))

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef double lf;


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

    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    int n; 
    ll x, sol = 0, aux = 0;
    cin>>n;
    
    for(int i = 0; i < n; ++i) {
        cin>>x;
        if(x) { aux += x; }
        else { sol += (aux>>1); aux = 0; }
    }
    sol += (aux>>1);

    cout<<sol<<"\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define N 210
#define ll long long
#define mod 998244353
using namespace std;
struct node{
	int x,y;
	node(int X=0,int Y=0):x(X),y(Y){}
	node operator -(const node a)const{return node(a.x-x,a.y-y);}
	int operator *(const node a)const{return x*a.y-y*a.x;}
}p[N];
ll _2[N];
int main()
{
	int n;
	scanf("%d",&n);
	_2[0]=1;
	for(int i=1;i<=n;i++) _2[i]=_2[i-1]*2%mod;
	for(int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y);
	ll res=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			int cnt=0;
			for(int k=1;k<i;k++)	
	 		if((p[j]-p[i])*(p[k]-p[i])==0) cnt++;
			(res+=_2[cnt]-1)%=mod;
		}
	printf("%lld\n",((_2[n]-n*(n-1)/2-n-1)%mod-res+2*mod)%mod);
	return 0;
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cerr << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

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

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 100010;
V<int> g[maxn], gg[maxn];
int dg[maxn];
bool w[maxn];

int dfs(int v, int p, int &maxi) {
	int res = 0;
	multiset<int> st;
	for (int to : g[v]) if (to != p) {
		st.insert(dfs(to, v, maxi));
		if (st.size() > 2) {
			st.erase(st.begin());
		}
	}
	int s = 0;
	while (st.size()) {
		int x = *st.begin();
		s += x;
		chmax(res, x);
		st.erase(st.begin());
	}
	chmax(maxi, s + w[v]);
	res += w[v];
	return res;
}

int main() {
	int N; cin >> N;
	V<int> deg(N), alive(N, 1);

	rep(i, N-1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].pb(b);
		g[b].pb(a);
		++deg[a];
		++deg[b];
	}

	string S; cin >> S;

	if (N == 1) {
		cout << (S[0] == 'W') << endl;
		return 0;
	}

	queue<int> que;
	rep(i, N) {
		w[i] = (S[i] == 'W');
		if (!w[i] && deg[i] == 1) {
			que.push(i);
		}
	}

	while (!que.empty()) {
		int v = que.front(); que.pop();
		alive[v] = 0;
		for (int to : g[v]) {
			if (alive[to] && --deg[to] == 1 && !w[to]) {
				que.push(to);
			}
		}
	}

	rep(i, N) deg[i] = 0;

	int r = -1;
	int cnt = 0;

	rep(i, N) if (alive[i]) {
		r = i;
		++cnt;
		for (int to : g[i]) if (alive[to]) {
			gg[i].pb(to);
			dg[to] ^= 1;
		}
	}

	if (cnt < 2) {
		cout << cnt << endl;
		return 0;
	}

	int ans = 2 * (cnt - 1);
	rep(i, N) if (alive[i]) {
		w[i] ^= dg[i];
		ans += w[i];
	}

	int maxi = 0;

	dfs(r, -1, maxi);
	cout << ans - maxi * 2 << endl;
	return 0;
}

Measured memory_bytes: 25856
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <forward_list>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() { return numeric_limits<long long>::min(); }
ll mal() { return numeric_limits<long long>::max(); }

#define R3(i, a, b) for (long long i = (a); i < (b); ++i)
#define R2(i, b) for (long long i = 0; i < (b); ++i)
#define R1(b) for (long long i = 0; i < (b); ++i)
#define RR(i, a, b) for (long long i = a; i > b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

// build: ctrl + f9

// run: shift + f10
// sanitize: shift + f11
// debug: shift + f9

int main()
{
    ll X;
    cin >> X;

    ll balance = 100;
    ll year = 0;

    while(balance < X) {
        ++year;
        balance *= 1.01;
    }

    cout << year << endl;
}

Measured memory_bytes: 3604
#include<iostream>

using namespace std;

int main(){
	int N, A[100000];
	int buff = 0, num = 1;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	for(int i = 1; i < N; i++){
		if(buff == 0){
			if(A[i - 1] > A[i]){
				buff = -1;
			}else if(A[i - 1] < A[i]){
				buff = 1;
			}
		}else if(buff == 1){
			if(A[i - 1] > A[i]){
				num++;
				buff = 0;
			}
		}else if(buff == -1){
			if(A[i - 1] < A[i]){
				num++;
				buff = 0;
			}
		}
	}
	cout << num;
}

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

int main()
{
	int n,m;
	cin>>n>>m;
	int a[n];
	int sum=0;

	for(int i=0;i<n;i++)
		{
			cin>>a[i];
			sum=sum+a[i];
		}

	sort(a,a+n,greater<int>());

	if(a[m-1]*4*m<sum)
		cout<<"No"<<endl;
	else cout<<"Yes"<<endl;

return 0;
}


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

void Main() {
    // input
    int N;
    int A, B;
    cin >> N >> A >> B;

    // translate
    u_int64_t ans = 0;
    for(int i = 1; i <= N; i++) {
        int num = 0;
        num += i % 10;  // 1の位 
        num += (i / 10) % 10; // 10の位
        num += (i /100) % 10; // 100の位
        num += (i /1000) % 10; // 1000の位
        num += (i /10000) % 10; // 10000の位
        if (A <= num && num <= B) {
            ans += i;
        }
    }


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 86400
#define inf 1e17
#define eps 1e-9
using namespace std;

int n;
int s[MAX];
double lim;

bool ok(double m){
  double c=lim;
  for(int i=0;i<MAX;i++){
    c-=s[i];
    c+=m;
    c=min(c,lim);
    if(c<0)return false;
  }
  double d=c;
  for(int i=0;i<MAX;i++){
    d-=s[i];
    d+=m;
    d=min(d,lim);
    if(d<0)return false;
  }
  return c-d<eps;
}

int main()
{
  while(1){
    cin>>n>>lim;
    if(n+lim==0)break;
    for(int i=0;i<MAX;i++)s[i]=0;
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>>a>>b>>c;
      for(int j=a;j<b;j++)s[j]=c;
    }

    double l=0,r=inf,m;
    for(int i=0;i<100;i++){
      m=(r+l)/2.0;
      if(ok(m))r=m;
      else l=m;
    }
    printf("%.10f",l);
    cout<<endl;
  }
  return 0;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2) ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
//#define MULTIPLE_TEST_CASE
void solution() {
  int n;
  cin >> n;
  int v[n];
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int k = 1000;
  for (int i = 1; i < n; i++) {
    if (v[i] > v[i - 1]) {
      int tot = k / v[i - 1];
      k -= tot * v[i - 1];
      k += tot * v[i];
    }
  }
  cout << k << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  int k = 0;
  rep(i, n) {
    if (p[i] != i+1) k++;
  }
  if(k <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
 }


Measured memory_bytes: 256
def solve():
    s_x, s_y, t_x, t_y = list(map(int, input().split(" ")))

    print("D", end="")

    for _ in range(t_x - s_x + 1):
        print("R", end="")
    for _ in range(t_y - s_y + 1):
        print("U", end="")

    print("L", end="")
    print("U", end="")

    for _ in range(t_x - s_x + 1):
        print("L", end="")
    for _ in range(t_y - s_y + 1):
        print("D", end="")

    print("R", end="")

    for _ in range(t_x - s_x):
        print("R", end="")
    for _ in range(t_y - s_y):
        print("U", end="")
    for _ in range(t_x - s_x):
        print("L", end="")
    for _ in range(t_y - s_y):
        print("D", end="")


solve()

Measured memory_bytes: 4468
import math
A, B, H, M = map(int, input().split())
 
X, Y = A*math.cos(math.pi*(60*H+M)/360), -A*math.sin(math.pi*(60*H+M)/360)
x, y = B*math.cos(math.pi*M/30), -B*math.sin(math.pi*M/30)
 
print(math.sqrt((X-x)**2+(Y-y)**2))

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

using namespace std;

int main() {
  string s,t;
  cin >> s >> t;

  int mi = 2000;
  for(int i = 0; i < s.size()-t.size()+1; i++) {
    int cnt = 0;
    int x = i;
    for(int j = 0; j < t.size(); j++) {
      if(s[i] != t[j]) cnt++;
      i++;
    }
    i = x;
    mi = min(mi, cnt);  
  }

  cout << mi << endl;
}


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

const string flick[10][5] = {
  {"wa", "", "nn", "", "wo"},
  {"a", "i", "u", "e", "o"},
  {"ka", "ki", "ku", "ke", "ko"},
  {"sa", "si", "su", "se", "so"},
  {"ta", "ti", "tu", "te", "to"},
  {"na", "ni", "nu", "ne", "no"},
  {"ha", "hi", "hu", "he", "ho"},
  {"ma", "mi", "mu", "me", "mo"},
  {"ya", "", "yu", "", "yo"},
  {"ra", "ri", "ru", "re", "ro"}
};

int main()
{
  string s;
  while (cin >> s) {
    for (unsigned int i = 0; i < s.size(); i += 2) {
      int dir = -1;
      if (s[i+1] == 'T')
        dir = 0;
      else if (s[i+1] == 'L')
        dir = 1;
      else if (s[i+1] == 'U')
        dir = 2;
      else if (s[i+1] == 'R')
        dir = 3;
      else
        dir = 4;

      cout << flick[s[i]-'0'][dir];
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
	vector<int> A(5);
	for(int i = 0; i < 5; i++){
		cin >> A.at(i);
	}
	int K;
	cin >> K;
	int ans = A.at(4) - A.at(0);
	if(ans > K) cout << ":(" << endl;
	else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int i,j,N,v,s;
	int A[1001];
	
	
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	for(s=0;s<N;s++){
		if(s == N-1){
			printf("%d\n",A[s]);
		}else{
		printf("%d ",A[s]);
		}
	}
	
	for(i=1;i<N;i++){
		
		
		
		v = A[i];
		j = i-1;
		while(j >= 0 && A[j]>v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		for(s=0;s<N;s++){
			if(s==N-1){
				printf("%d\n",A[s]);
			}else{
			printf("%d ",A[s]);
			}
		}
		
	}
}

Measured memory_bytes: 1032
a,b = list(map(int, input().split()))
ans = 0

if a==1:
  ans += 300000
elif a==2:
  ans += 200000
elif a==3:
  ans += 100000
  
if b==1:
  ans += 300000
elif b==2:
  ans += 200000
elif b==3:
  ans += 100000
  
if a==1 and b==1:
  ans+= 400000
  
print(ans)

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

int main(void){
	vector<string> vs(3);vector<int> cnt(3);
	cin >> vs[0] >> vs[1] >> vs[2];
	int t = 0;
	for(;;){
		t = vs[t][cnt[t]++] - 'a';
		if(vs[t].size() == cnt[t]){
			cout << (char)(t + 'A') << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int, int> P;
struct UnionFind
{
	vector<int> data;
	int __size;
	UnionFind(int sz)
	{
		data.assign(sz, -1);
		__size = sz;
	}

	bool unite(int x, int y)
	{
		x = find(x), y = find(y);
		if (x == y)
			return (false);
		if (data[x] > data[y])
			swap(x, y);
		__size--;
		data[x] += data[y];
		data[y] = x;
		return (true);
	}

	int find(int k)
	{
		if (data[k] < 0)
			return (k);
		return (data[k] = find(data[k]));
	}

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

	int size(int k)
	{
		return (-data[find(k)]);
	}

	int union_count()
	{
		return (__size);
	}
};

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

	UnionFind uf(n);
	vector<set<int>> bo(n);
	vector<set<int>> f(n);
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		f[a].insert(b);
		f[b].insert(a);
		uf.unite(a, b);
	}
	rep(i, k)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		bo[a].insert(b);
		if (!uf.same(a, b))
			bo[a].erase(b);
		bo[b].insert(a);
		if (!uf.same(a, b))
			bo[b].erase(a);
	}

	vector<int> res(n, 0);
	for (int i = 0; i < n; i++)
	{
		res[i] = uf.size(i) - 1 - f[i].size() - bo[i].size();
	}
	for (auto e : res)
		cout << e << " ";
	cout << endl;
	return 0;
}

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

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    int Max =max(a,b),Min =min(a,b);
    for(int i=0;i<Max;i++)
        printf("%d",Min);
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=3123;
int dp[MAXN][MAXN];
int main()
{
	string s1,s2;
	cin >> s1;cin >> s2;
	int t1=s1.size(),t2=s2.size();
	for(int i=1;i<=t1;i++)
	{
		for(int j=1;j<=t2;j++)
		{
			if(s1[i-1]==s2[j-1])dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	stack<char,vector<char> > rs;
	int x=t1,y=t2;
	while(x!=0 && y!=0)
	{
		int vizx=x-1,vizy=y-1;
		if(s1[vizx]==s2[vizy])
		{
			rs.push(s1[vizx]);
			x--;y--;
		}
		else
		{
			if(dp[x][y]==dp[vizx][y])
			{
				x--;
			}
			else y--;
		}
	}
	//if(s1[0]==s2[0])rs.push(s1[0]);
	while(!rs.empty())
	{
		printf("%c",rs.top());rs.pop();
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 37120
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define For(i, a, b)    for(int i = (a); (i) < (b) ; ++(i))
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };



/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    int c_AC = 0, c_WA = 0, c_TLE = 0, c_RE = 0;

    rep(i, n){
        string s; cin >> s;
        if(s == "AC") c_AC++;
        if(s == "WA") c_WA++;
        if(s == "TLE") c_TLE++;
        if(s == "RE") c_RE++;
    }

    cout << "AC x " << c_AC << endl;
    cout << "WA x " << c_WA << endl;
    cout << "TLE x " << c_TLE << endl;
    cout << "RE x " << c_RE << endl;

return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  rep(i, n) {
    int h;
    cin >> h;
    if (h >= k) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
# from typing import List
sys.setrecursionlimit(10 ** 7)


class UnionFind(object):
    """docstring for UnionFind"""

    def __init__(self, n):
        super(UnionFind, self).__init__()
        self.v = [-1 for _ in range(n)]

    def find_root(self, x):
        if self.v[x] < 0:
            return x
        else:
            self.v[x] = self.find_root(self.v[x])
            return self.v[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:
            x, y = y, x
        self.v[x] += self.v[y]
        self.v[y] = x

    def is_root(self, x):
        return self.v[x] < 0

    def has_same_root(self, x, y):
        return self.find_root(x) == self.find_root(y)


def solve(N: int, M: int, X: "List[int]", Y: "List[int]", Z: "List[int]"):
    uf = UnionFind(N)
    for x, y, z in zip(X, Y, Z):
        uf.unite(x - 1, y - 1)

    print(sum(1 for i in range(N) if uf.is_root(i)))

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [int()] * (M)  # type: "List[int]"
    Y = [int()] * (M)  # type: "List[int]"
    Z = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
        Z[i] = int(next(tokens))
    solve(N, M, X, Y, Z)


if __name__ == '__main__':
    main()


Measured memory_bytes: 67292
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std; 
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define mp make_pair
#define endl "\n"
#define N (ll)2e5+10 




int main(){
    
    ios::sync_with_stdio(0);
    
    int n ;
    cin >> n ;
    string s ; cin >> s ;
    int ans =1 , i ;
    for(i=1 ; i<n ; i++){
    	ans+= (s[i]!=s[i-1]) ;

    }

    cout << ans ;

    return 0 ;
 }

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

const int MAX_N = 1 << 17;

int n, dat[2*MAX_N-1];

void init(int n_){
    n = 1;
    while(n < n_) n *= 2;
    
    for(int i=0; i<(2*n-1); i++) dat[i] = INT_MAX;
}

// k 番目の値(0-indexed)を a に変更
void update(int k, int a){
    k += n-1;
    dat[k] = a;
    
    while(k > 0){
        k = (k-1)/2;
        dat[k] = min(dat[k*2+1], dat[k*2+2]);
    }
}

// [a,b)の最小値を求める. k:節点の番号. l,r:その節点が[l,r)に対応づいていることを表す.
int find(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return INT_MAX;
    
    if(a <= l && r <= b) return dat[k];
    else {
        int vl = find(a,b,k*2+1,l,(l+r)/2);
        int vr = find(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}

int main() {
    int q;
    cin >> n >> q;
    
    init(n);
    
    for(int i=0; i<q; i++){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0){
            update(x,y);
        }
        else if(com == 1){
            cout << find(x,y+1,0,0,n) << endl;
        }
    }
}



Measured memory_bytes: 4116
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,k,k1;
	scanf("%d%d%d",&a,&b,&k);
	int i;
	for(i=a,k1=k;k1>0&&i<=b;i++,k1--){
		printf("%d ",i);		
	}
	
	i=max(i,b-k+1);
	for(k1=k;k1>0&&i<=b;i++,k1--){
		printf("%d ",i);
	}
	
	return 0;
}

Measured memory_bytes: 256
// In The Name OF Allah
// Mehrkish Makuei
// Islamic Republic Of Iran

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define Mehrkish ios::sync_with_stdio(false),		cin.tie(0),		cout.tie(0)
#define pb push_back

const int maxx = 2e5 + 19;
int n, m, a[maxx], c[maxx], b[maxx], ans, jvb, sum, z, l, x, y, k, minn = 99999999;
string s[119], t, w;
bool flag = true;
vector <ll> v;

void Input(){
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		cin >> s[i];
		cin >> a[i];
	}
}

void Solve(){
	for ( int i = 0; i < n; i++ ){
		ans = 0;
		for ( int j = 0; j < n; j++ ){
			if ( s[i] > s[j] )
				ans++;
			if ( s[i] == s[j] and a[i] < a[j] )
				ans++;
		}
		ans++;
		b[ans] = i + 1;
	}
	for ( int i = 1; i <= n; i++ )
		cout << b[i] << endl;
}


int main(){
	Mehrkish;
	Input(),	Solve();
	return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>s;
      map<char,ll> mp;
      rep(i,Size(s)){
        mp[s[i]]++;
        if(mp[s[i]]>=2){
          Cout("no");
          return 0;
        }
      }
      Cout("yes");
     

       
return 0;
}


Measured memory_bytes: 764
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    string s, t;
    int q, ty, f;
    char c;
    cin >> s >> q;
    for(int i = 0; i < q; i++){
        cin >> ty;
        if(ty == 1) swap(s, t);
        else{
            cin >> f >> c;
            if(f == 1) t += c;
            else s += c;
        }
    }
    reverse(t.begin(), t.end());
    t += s;
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 1160
import java.io.IOException;
import java.util.*;

class Main {
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		Map<String, Integer> ans = new HashMap<>();
		create_ans(ans);
		while(in.hasNext()) {
			String[] map = in.nextLine().split(" ");
			System.out.println(ans.get(""+new Node(0, 0, map).getStrId()));
		}
	}

	public static void create_ans(Map<String, Integer> ans) {
		String[] map = {"0","1","2","3","4","5","6","7"};
		Set<Integer> s = new HashSet<>();
		Queue<Node> q = new PriorityQueue<>();
		int z_pos = 0;
		for(int i=0;i<8;i++) {
			if(map[i].equals("0")) {
				z_pos = i;break;
			}
		}
		q.offer(new Node(z_pos, 0, map));
		while(!q.isEmpty()) {
			Node node = q.poll();
			int id = node.getId();
			s.add(id);
			ans.put(node.getStrId(), node.num);

			// ??????????????????????????\??????????????????????????\????????????
			int di[] = {-4, +4, -1, +1};
			for(int i=0;i<4;i++) {
				int zero = node.zero_pos + di[i];
				// ???????????????
				if(zero < 0 || zero > 7) continue;
				if(node.zero_pos == 3 && i == 3) continue;
				if(node.zero_pos == 4 && i == 2) continue;

				// ??\????????????
				Node newNode = new Node(zero, node.num+1, node.map);
				swap(newNode.map, node.zero_pos, zero);
				if(s.contains(newNode.getId())) continue;
				newNode.addSteps(node.getSteps());
				newNode.addStep(newNode);

				q.offer(newNode);
				s.add(newNode.getId());
			}
		}
	}

	public static void swap(String[] map, int p1, int p2) {
		String buf = map[p1];
		map[p1] = map[p2];
		map[p2] = buf;
	}
}

class Node implements  Comparable<Node>{
	int zero_pos = 0;
	int num;
	String[] map;
	List<Node> steps = new ArrayList<>();
	Node(int zero_pos, int num, String[] map) {
		this.zero_pos = zero_pos;
		this.num = num;
		this.map = map.clone();
	}

	public void addStep(Node node) {
		this.steps.add(node);
	}

	public void addSteps(List<Node> steps) {
		this.steps = new ArrayList<Node>(steps);
	}

	public List<Node> getSteps() {
		return this.steps;
	}

	public int getId() {
		int id = 0;
		for(int i=0;i<map.length;i++) {
			id = id * 10 + Integer.parseInt(map[i]);
		}
		return id;
	}

	public String getStrId() {
		String id = "";
        for(int i=0;i<map.length;i++) {
			id = id + map[i];
		}
		return id;
	}

	@Override
	public int compareTo(Node o) {
		return this.num - o.num;
	}
}

Measured memory_bytes: 58432
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
char S[2020200];
int n,A[2020200],C[2020200],D[2020200];
void Work(){
	memset(C,0,sizeof(C));
	memset(D,0,sizeof(D));
	int k; scanf("%d",&k);
	int nC=0,nD=0;
	for (int i=n;i>=1;i--) if (A[i]==3)
		C[++nC]=i;
	LL Cur=0,ans=0;
	int ptc=nC+1,ptd=1;
	
	for (int i=1;i<=n;i++){
		if (!A[i]) continue;
		if (A[i]==1){
			D[++nD]=i; 
			while (ptc>1&&C[ptc-1]-i<k) ptc--;
			Cur+=(LL)(nC-ptc+1);
			continue;
		}
		if (A[i]==3){
			nC--;
			while (ptc>nC+1) ptc--;
			while (C[nC+1]-D[ptd]>=k&&ptd<=nD)
				ptd++; 
			Cur-=(LL)(nD-ptd+1);
			continue;
		} 
		ans+=(LL)Cur;
	}
	cout<<ans<<endl;
}
int main(){
	scanf("%d",&n);
	scanf("%s",S+1); getchar();
	for (int i=1;i<=n;i++){
		if (S[i]=='D') A[i]=1;
		if (S[i]=='M') A[i]=2;
		if (S[i]=='C') A[i]=3;
	}
	int T_num; cin>>T_num;
	while (T_num--) Work();
}

Measured memory_bytes: 22784
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<=(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const double Pi = acos(-1);
const ll mod=1e9+7;
 
int main(){
    ll n;
    cin >>n;
    n--;
    string ans="";
    vector<int> ts;
    while(true){
        ts.push_back((n+26)%26);
        n=n/26-1;
        if(n==-1) break;
    }
    reverse(ts.begin(),ts.end());
    rep(i,ts.size()){
        printf("%c",'a'+ts[i]);
    }
    cout <<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	vector<int>a(3);
	for (int i = 0; i < 3; i++)cin >> a[i];
	sort(a.begin(), a.end());
	cout << abs(a[2] - a[1]) + abs(a[1] - a[0]) << endl;
}

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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

const ll big = 1000000007ll;
const ll big2 = 1000000009ll;
ll n,m,k,q,w,h,T;



int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d;
    string s;
    cin >> s;
    n = s.length();
    for(ll c1 = 0; c1 < n-8; c1++)cout << s[c1];

    return 0;
}


Measured memory_bytes: 764
while 1:
    n = input(); ans = 0;
    if n==0: break
    s = [input() for i in range(n)]
    for i in range(n):
        for j in range(n-i-1):
            if s[j+1]<s[j]:
                s[j],s[j+1]=s[j+1],s[j]
                ans += 1
    print ans

Measured memory_bytes: 4224
d,n = [int(x) for x in input().split()]

if d == 0:
    if n == 100:
        print(101)
    else:
        print(n)
elif d == 1:
    if n == 100:
        print(101 * 100)
    else:
        print(n * 100)
else:
    if n == 100:
        print(101 * 10000)
    else:
        print(n * 10000)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
// cd test ; rm -R ./*; cd ..


int main(void) {

  string a, b, c;
  cin >> a >> b >> c;

  cout << 'A' << b[0] << 'C' << endl;
  

  return 0;
}

Measured memory_bytes: 764
from collections import Counter

N = int(input())
h = [int(x) for x in input().split(" ")]
 
L = [0] * N
R = [0] * N
cnt = 0
for i in range(0, N):
    L[i] = i + 1 + h[i]
    R[i] = i + 1- h[i]
LC = Counter(L)
RC = Counter(R)

cnt = 0
for key,values in LC.most_common():
    if key in RC:
        num = RC[key]
        cnt += values * num

print(cnt)

Measured memory_bytes: 152632
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int kaijou(int N) {
	if (N == 0) return 1;
	else return N * kaijou(N - 1);
}


int main() {

	int N;
	cin >> N;

	vector<P>xy;

	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		xy.push_back(make_pair(x, y));
	}

	SORT(xy);
	
	double all = 0;
	//int i = 0;
	do {

		/*for (int i = 0; i < N; i++) {
			cout << xy[i].first << "," << xy[i].second;
			if (i != N - 1) cout << " ";
		}
		cout << endl;*/

		double sum = 0;
		for (int i = 0; i < N - 1; i++) {
			sum += sqrt(pow(xy[i + 1].first - xy[i].first, 2.0) + pow(xy[i + 1].second - xy[i].second, 2.0));
		}

		all += sum;

		//REP(i,N-1) cout << sqrt(pow(xy[i + 1].first - xy[i].first, 2.0) + pow(xy[i + 1].second - xy[i].second, 2.0)) << endl;

		//cout << sum << endl;

	} while (next_permutation(xy.begin(), xy.end()));

	cout << setprecision(10) << all/kaijou(N) << endl;
	
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll n;

vector<ll> makePrimes(ll n) {
  vector<ll> res, pr(n + 1, 1);
  pr[0] = pr[1] = 0;
  rep(p, 2, sqrt(n) + 2) 
    if (pr[p]) 
    for (ll x = p * 2; x <= n; x += p) pr[x] = 0;
  rep(p, 2, n + 1) 
    if (pr[p]) 
      res.push_back(p);
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    auto p = makePrimes(n);
    vii cnt;
    rep(i, 0, p.size()) {
        int sum = 0;
        erep(j, 2, n) {
            int t = j;
            while (t % p[i] == 0) {
                sum++;
                t /= p[i];
            }
        }
        cnt.pb(sum);
    }
    ll ans = 1;
    rep(i, 0, cnt.size()) {
        ans *= (cnt[i] + 1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,c = map(int, input().split())

dl = [list(map(int, input().split())) for _ in range(c)]
nl = [list(map(int, input().split())) for _ in range(n)]

ax = [[0 for i in range(c)] for j in range(3)]

for i in range(n):
    for j in range(n):
        x = (i+j) % 3
        ax[x][nl[i][j]-1] += 1

l = list(range(0,c))
import itertools
ll = list(itertools.permutations(l, 3))
res = float('inf')

#axを変換していくコストを全列挙
for i in ll:
    temp= 0
    for j in range(c):
        temp += ax[0][j]*dl[j][i[0]]
        temp += ax[1][j]*dl[j][i[1]]
        temp += ax[2][j]*dl[j][i[2]]
    res= min(res,temp)
print(res)

Measured memory_bytes: 13516
#include <bits/stdc++.h>
#define FOR(i, l, r) for(int i = (int)l; i <= (int)r; ++i)
#define REP(i, r) for(int i = (int)0; i < (int)r; ++i)
#define FORD(i, l, r) for(int i = (int)l; i >= (int)r; --i)
#define REPD(i, r) for(int i = (int)r - 1; i >= 0; --i)
#define X first
#define Y second
#define debug(x) {cerr << #x << " = " << x << '\n';}
#define pr(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define pr0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int Nmax = 2e5 + 11;
const ll MOD = 1e9 + 7;

ll n, m, a, b, inv[Nmax], p[Nmax];

ll power(ll a, ll k) {
    if (k == 0) return 1;
    ll tmp = power(a, k / 2);
    if (k % 2 == 1) return tmp * tmp % MOD * a % MOD;
    else return tmp * tmp % MOD;
}

ll C(ll k, ll n) {
    if (k > n) return 0;
    return ((p[n] * inv[k]) % MOD * inv[n - k]) % MOD;
}

int main() {
//    freopen("D.inp", "r", stdin);
    cin >> n >> m >> a >> b;
    p[0] = 1;
    FOR(i, 1, Nmax - 1) p[i] = (p[i - 1] * i) % MOD;
    inv[Nmax - 1] = power(p[Nmax - 1], MOD - 2);
    FORD(i, Nmax - 1, 1) {
        inv[i - 1] = (inv[i] * i) % MOD;
    }
    ll ans = C(m - 1, n + m - 2);
    FOR(i, n - a, n - 1) {
        ans = (ans - C(b - 1, i + b - 1) * C(n - 1 - i, m + n - 2 - i - b) + MOD * MOD) % MOD;
    }
    cout << ans;
}


Measured memory_bytes: 3328
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<stack>
using namespace std;

int w,h;
char map[21][21];
int dfs(int si,int sj){
    int ans=1;
    if(si<=-1||si>=h)return 0;
    if(sj<=-1||sj>=w)return 0;
    if(map[si][sj]=='#') return 0;
    map[si][sj]='#';
    ans+=dfs(si+1,sj);
    ans+=dfs(si,sj+1);
    ans+=dfs(si-1,sj);
    ans+=dfs(si,sj-1);
    return ans;
}


int main(){
    while(1){
        scanf("%d %d",&w,&h);
        if(w==0 && h==0)break;
        int i,j,si=0,sj=0;
        for(i=0;i<=h-1;i++){
        scanf("%s",map[i]);
        }
        for(i=0;i<=h-1;i++){
            for(j=0;j<=w-1;j++){
                if(map[i][j]=='@'){
                    si=i;
                    sj=j;
                }
            }
        }
        printf("%d\n",dfs(si,sj));
        }
    return 0;
}

Measured memory_bytes: 3132
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;cin>>n;
  vector<int>V(n);
  rep(i,n){
    cin>>V[i];
  }
  sort(V.begin(),V.end());
  cout<<V.at(n-1)-V.at(0)<<endl;
  
}

Measured memory_bytes: 256