akhauriyash/Code-Regression huggingface dataset:
def f_c():
    n = int(input())
    s = input()
    q = 10**9+7

    stack, c = 1, 1
    for si in s[1:]:
        if si=="B":
            if stack%2==0:
                stack += 1
            else:
                c *= stack
                stack -= 1
        else:
            if stack%2==0:
                c *= stack
                stack -= 1
            else:
                stack += 1
        c %= q
    if stack!=0 or c==0:
        print(0)
    else:
        for i in range(1, n+1):
            c *= i
            c %= q
        print(c)

if __name__ == "__main__":
    f_c()


Measured memory_bytes: 3516
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=505;
char s[5];int a[N],col[N],bs[N],cnt[2],n,las,now,ql,qr,l,r,mid,ans;
inline int ask(R int l,R int r){
	putchar('?'),putchar(' ');
	fp(i,l,r)printf("%d ",i);
	putchar('\n'),fflush(stdout);
	scanf("%s",s+1);return s[1]=='R';
}
inline int ask(R int l,R int r,R int x,R int d){
	putchar('?'),putchar(' ');
	fp(i,l,r)if(i!=x)printf("%d ",i);
	if(d)printf("%d ",x);
	putchar('\n'),fflush(stdout);
	scanf("%s",s+1);
	if(s[1]=='-')while(true);
	return s[1]=='R';
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	fp(i,1,n<<1)col[i]=-1;
	l=1,r=n+1,ans=0,bs[1]=ask(1,n),bs[n+1]=bs[1]^1;
	while(r-l>1){
		mid=(l+r)>>1,bs[mid]=ask(mid,mid+n-1);
		bs[mid]==bs[l]?l=mid:r=mid;
	}
//	printf("%d %d\n",l,r);
	col[l]=bs[l],col[r+n-1]=bs[r];
	ql=r,qr=r+n-2;
//	printf("%d %d\n",ql,qr);
	fp(i,ql,qr)col[i]=ask(ql-1,qr+1,i,0)^1;
	fp(i,1,ql-2)col[i]=ask(ql,qr,i,1);
	fp(i,qr+2,n<<1)col[i]=ask(ql,qr,i,1);
	putchar('!'),putchar(' ');
	fp(i,1,n<<1)putchar(col[i]?'R':'B');
	putchar('\n'),fflush(stdout);
	return 0;
}


Measured memory_bytes: 724
object Main extends App {
	import scala.math._
	val N = scala.io.StdIn.readInt
	val a = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val b = new Array[Int](N+1)
	val c = new Array[Int](N)
	
	b(0) = (0 - a(0)).abs
	for(i<-1 until N){
		b(i) = (a(i-1) - a(i)).abs
	}
	b(N) = (a(N-1) - 0).abs

/*
	b(i  ) = a(i-1) - a(i)
	b(i+1) = a(i  ) - a(i+1)
*/
	val bsum = b.sum

	c(0) = (0 - a(1)).abs + bsum - b(0) - b(1)

	for(i<-1 until N-1){
		c(i) = bsum - b(i) - b(i+1) + (a(i-1) - a(i+1)).abs
	}
	c(N-1) = bsum - b(N) - b(N-1) + (a(N-2) - 0).abs

	for(x <- c){
		println(x)
	}
}


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

int main(){
	string O,E;
	int o,e;
	cin >> O;
	cin >> E;
	o = O.size();
	e = E.size();
	for(int i = 0;i < o; i++){
		if(i<o){
		cout << O[i];
		}
		if(i<e){
		cout << E[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
string s;
int n;
bool check(){
	for(int i=0;i< n>>1 ;i++)if(s[i]!=s[n-i-1])return 0;
	for(int i=0;i< n>>2 ;i++)if(s[i]!=s[ (n>>1)-i-1])return 0;
	for(int i= (n+3>>1)-1;i<n;i++)if(s[i]!=s[n + (n+3>>1)-2 -i ])return 0;
	return 1;
}
int main(){
	cin>>s;
	n=s.size();
	puts(check()?"Yes":"No");
}


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

int main(){
  int n; cin >> n;
  ll sum = 0;
  ll digit = 0;
  for(int i = 0; i < n; i++){
    ll a, b; cin >> a >> b;
    digit += b;
    sum += a * b;
  }
  cout << digit - 1 + (sum - 1) / 9 << endl;
}


Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    for (int i = 1; i <= 1250; i++) {
        if ((int) (i * 0.08) == A && (int) (i * 0.1) == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
set<string> ss;
string a[200048],s;
int tot=0,k;
int main(int argc, char *argv[]) {
	cin>>s>>k;
	int i,j,n=int(s.size());
	for (i=0; i<=n-1; i++)
		for (j=1; j<=5; j++) {
			if (i+j-1>=n) continue;
			ss.insert(s.substr(i,j));
		}
	for (i=1; i<=k-1; i++) ss.erase(ss.begin());
	cout<<(*(ss.begin()))<<endl;
	return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t
#include <math.h>

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int64_t *a1, int64_t *a2) {
  scanf("%lld %lld", a1, a2);
  return 0;
}

void swap(int64_t *a1, int64_t *a2) {
    int64_t tmp = *a1;
    *a1 = *a2;
    *a2 = tmp;
}

#define QUERY_MAX 100

// int main(void) {
//     int queries = get_int();
// 
//     int i;
//     static int64_t ans[QUERY_MAX];
//     int aidx = 0;
//     for(i = 0; i < queries; i++) {
//         int64_t a1, a2;
//         int64_t res;
//         get_int2(&a1, &a2);
//         if(a1 > a2) swap(&a1, &a2);
//         if(a1 == a2) {
//             res = (a1-1)*2; // exclude a1-a2
//         } else if (a1+1 == a2) {
//             res = (a1-1)*2; // exclude a1-a1 and a2-*
//         } else {
//             int64_t sum = a1*a2;
//             int64_t power_2 = (int64_t)sqrt(-0.5 + sum);
//             if(power_2*(power_2+1) >= sum) {
//                 res = (power_2-1)*2;
//             } else {
//                 res = power_2*2-1;
//             }
//         }
//         ans[aidx++] = res;
//     }
// 
//     for(i = 0; i < aidx; i++) {
//         printf("%lld\n", ans[i]);
//     }
//     return 0;
// }
int main(int argc, char const *argv[]){
  int64_t ans;
  int queries = get_int();
  int i;
  for(i = 0;i < queries;i++){
      int64_t a, b;
      get_int2(&a, &b);
      int64_t t=a*b;
      int64_t s=sqrt(t);
      if(a==b) {
          ans = 2*s-2;
      } else if(s*s==t) {
          ans=2*s-3;
      } else if(s*(s+1)>=t) {
          ans=2*s-2;
      } else { 
          ans=2*s-1;
      }
      printf("%lld\n",ans);
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
int a;
int b;
int c;
int d;
int e;
while(cin >>n){
c=0;
d=0;
e=0;
if(n!=0){while(e<n){
cin >>a;
cin >>b;
if(a>b){c=c+a+b;}
if(a==b){c=c+a; d=d+b;}
if(a<b){d=d+a+b;}
e=e+1;}
cout << c <<" "<<d<<endl;
}
}

}

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

/**
       return NO_PAIN ? NO_GAIN : GAIN;
*/

using namespace std;

#define all(v)   v.begin(), v.end()
#define sz(x)    (int) (x.size())
#define Unique(x) x.erase(unique(all(x)), x.end())
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define pow(n, m) (ll)powl(n, m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define clr(x, val)    memset(x, val, sizeof(x)) //be careful of value and TLE
#define MOD 1000000007
#define EPS 1e-7


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


int main()
{
    START
    //freopen("test cases\\in.txt", "r", stdin);
    //freopen("test cases\\in.txt", "w", stdout);
    int x, n; cin>>x>>n;
    int f[300] = {};
    for(int  i =0; i<n; i++){
        int a; cin>>a;
        f[a] = 1;
    }
    int mn = INT_MAX, y = 0;
    for(int i = 0; i<= 200; i++){
        if(!f[i] && abs(i - x) < mn)
            mn = abs(i - x), y = i;
    }
    cout<<y;
    return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
int solve(int a, int b) {
    int c = a+b;
    int i=0;

    if(c==0) {
        return 1;
    }
    else
    for(; c != 0; i++) {
        c = c/10;
    }
    return i;
}

int main() {
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF) {
        printf("%d\n",solve(a,b));
    }

}



Measured memory_bytes: 2052
#include<cstdio>
#include<algorithm>
using namespace std;
int a[200007],n;
int main()
{
    scanf("%d",&n);
    int minn=99999999,ans=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(minn>a[i])
        {
            ans++;
            minn=a[i];
        }
    }
    printf("%d",ans);

}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

int n;
char _s[6005];
string s;

void comb(string& r, string s){
	r=max(r,s+r);
}

string doit(string s){
	string r="";
	int n=SZ(s);
	if(s[0]=='a'){
		int a=0,b=0,l=-1;
		bool aa=true;
		fore(i,0,n){
			if(s[i]=='a'){
				if(aa)r.pb('a'),l=a,aa=false;
				a++;
			}
			else {
				if(b==l)r.pb('b'),aa=true;
				b++;
			}
		}
	}
	else {
		int a=0,b=0;
		fore(i,0,n){
			if(s[i]=='a'){
				a++;
			}
			else {
				string t="";
				int aa=a;
				fore(j,i,n){
					if(s[j]=='a'){
						if(aa>=b)t.pb('a');
						aa++;
					}
					else t.pb('b');
				}
				r=max(r,t);
				b++;
			}
		}
	}
	return r;
}

vector<string> v;

int main(){
	scanf("%d%s",&n,_s);n*=2;
	s=string(_s);
	int l=0,t=0;
	string r="";
	fore(i,0,n){
		if(s[i]=='a')t++;
		else t--;
		if(t==0)v.pb(doit(s.substr(l,i-l+1))),l=i+1;
	}
	for(int i=SZ(v)-1;i>=0;--i)comb(r,v[i]);
	puts(r.c_str());
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <queue>
#include <algorithm>

#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define INF 2000000000000LL
using namespace std;

typedef long long Weight;
typedef pair<Weight,pair<int,int> >Edge;

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool shortestPath(Graph &g, Matrix &dist, vector<vector<int> > &prev){
	int n = g.size()-1;
	Array h(n+1);
	h.assign(n,INF);
	for(int k=0;k<n+1;k++)for(int i=0;i<n+1;i++)FOR(e,g[i]){
		if (h[e->second.first]<INF && e->first<INF && h[e->second.second] > h[e->second.first] + e->first){
			h[e->second.second] = h[e->second.first] + e->first;
			if(k==n)return false; // negative cycle
		}
	}
	for(int i=0;i<n;i++)FOR(e,g[i])e->first+=h[i]-h[e->second.second];
	dist.assign(n, Array(n,INF));
	prev.assign(n, vector<int>(n,-2));
	for(int s=0;s<n;s++){
		priority_queue<Edge> Q;
		Q.push(make_pair(0,make_pair(s,s)));
		for(;!Q.empty();){
			Edge e = Q.top(); Q.pop();
			if(prev[s][e.second.second]!=-2)continue;
			prev[s][e.second.second] = e.second.first;
			FOR(f,g[e.second.second]){
				if(e.first<INF && f->first<INF && dist[s][f->second.second] > -e.first + f->first){
					dist[s][f->second.second] = -e.first + f->first;
					Q.push(make_pair(-(-e.first + f->first),make_pair(f->second.first, f->second.second)));
				}
			}
		}
		for(int u=0;u<n;u++){
			if(dist[s][u]<INF)dist[s][u] += h[u] - h[s];
		}
	}
	return true;
}

int main(){
	int r,T,V,E,s,t,e,i,j;
	scanf("%d%d",&V,&E);
	Graph g(V+1);
	Matrix dist;
	vector<vector<int> > prev;
	for(i=0;i<V;i++)g[i].push_back(make_pair(0,make_pair(i,i)));
	for(i=0;i<V;i++)g[V].push_back(make_pair(0,make_pair(V,i)));
	for(;E--;)scanf("%d%d%d",&s,&t,&e),g[s].push_back(make_pair(e,make_pair(s,t)));
	if(!shortestPath(g,dist,prev))puts("NEGATIVE CYCLE");
	else for(i=0;i<V;i++)for(j=0;j<V;j++){
		if(dist[i][j]>=INF)printf("INF");
		else printf("%lld",dist[i][j]);
		printf(j<V-1?" ":"\n");
	}
}

Measured memory_bytes: 1376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<vector<bool>> g(n,vector<bool>(n,false));
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--,b--;
    g[a][b]=true;
    g[b][a]=true;
  }
  vector<int> a;
  FOR(i,1,n) a.push_back(i);
  int ans=0;
  do{
    bool flag=true;
    int now=0;
    rep(i,a.size()){
      if(!g[now][a[i]]){
        flag=false;
        break;
      }
      now=a[i];
    }
    if(flag) ans++;
  }while(next_permutation(begin(a),end(a)));
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/* ?´??????°????§£ */
vector<ll> PrimeFact(ll n){
    vector<ll> res;
    while(n!=1){
        if(n == 2 || n == 3){
            res.emplace_back(n); n/=n;
            continue;
        }
        bool prime_flag = false;
        for(int i = 2;i*i <= n;i++){
            if(n%i==0){
                res.emplace_back(i); n/=i;
                prime_flag = true;
                break;
            }
        }
        if(!prime_flag){res.emplace_back(n); n/= n;}
    }
    return res;
}

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    auto primes = PrimeFact(n);
    cout << n<<":";
    for(auto x:primes){
        cout << " " <<x;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, n,m , M, K,a;

vector<int> v,w;
int main(){
    cin >> N;
    for(int i = 0; i < N; ++i) v.push_back(i+1);
    vector<int> p;
    vector<int> q;
    int s,t;
    for(int i = 0;  i < N; ++i){
        cin >> s;
        p.push_back(s);
    }
     for(int i = 0;  i < N; ++i){
        cin >> s;
        q.push_back(s);
    }
    int n = 1;
    do{
        if(v == p) s = n;
        if(v == q) t = n;
        n += 1;
    }while(next_permutation(v.begin(),v.end()));
    cout << abs(s-t);
    return 0;
}



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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N, a, b;
  cin >> N >> a >> b;

  // 解答
  cout << ((b - a) & 1 ? "Borys" : "Alice") << endl;

  return 0;
}


Measured memory_bytes: 256
# 2019/10/03

import sys

inpt=sys.stdin.readline
n=int(input())
a=[]
for i in range(n):
    a.append((int(input()),i+1))
a.sort()

cnt=0
for idx,aa in enumerate(a,1):
    if aa[1]%2==idx%2:continue
    cnt+=1
print(cnt//2)

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

#define int long long 

main()
{
  int r, g, b;
  cin >> r >> g >> b;
  if((r * 100 + g * 10 + b) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return (0);
}


Measured memory_bytes: 256
// 解き直し.
// https://img.atcoder.jp/agc011/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int t[101010];

int main(){
    
    // 1. 入力情報.
    int N, C, K;
    scanf("%d %d %d", &N, &C, &K);
    rep(i, N) scanf("%d", &t[i]);
    
    // 2. sort.
    sort(t, t + N);
    
    // 3. バスの台数を計算.
    int bus = 0, at = 0, idx = 0, top = t[0];
    while(idx < N){
        // 先頭と同じバスに乗る乗客を検索.
        at = upper_bound(t, t + N, top + K) - t;
        
        // 乗客を振り分ける.
        if(at - idx >= C) idx += C;
        else              idx = at;
        
        // 先頭を更新.
        top = t[idx];
      
        // バスの台数をカウントアップ
        bus++;
    }
    
    // 4. 出力.
    printf("%d\n", bus);
    return 0;
    
}

Measured memory_bytes: 4192
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
long long k,n,m,i,j,a[100005],d[100005],f[100005],g[100005],h[100005];
int main()
{
	scanf("%lld",&n);
	fz1(i,n){
		scanf("%lld",&a[i]);
	}
	fz1(i,n-1){
		d[i]=a[i+1]-a[i];
		f[i]=g[i]=i;
	}
	scanf("%lld%lld",&m,&k);
	fz1(i,m){
		int x;
		scanf("%lld",&x);
		swap(f[x-1],f[x]);
	}
	while(k)
	{
		if(k&1){
			fz1(i,n-1){
				g[i]=f[g[i]];
			}
		}
		fz1(i,n-1){
			h[i]=f[f[i]];
		}
		fz1(i,n-1){
			f[i]=h[i];
		}
		k/=2;
	}
	fz1(i,n){
		if(i!=1){
			a[i]=a[i-1]+d[g[i-1]];
		}
		printf("%lld.0\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 5376
N = int(input())
if N > 81:
  print("No")
elif N <= 9:
  print("Yes")
else:
  found = False
  for i in range(2, 10):
    if N % i == 0:
      X = N // i
      if X <= 9:
        print("Yes")
        found = True
        break
  if not found:
    print("No")
 


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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

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

const ll INF = 1e18;
const int mod = 1e9+7;
const int MAX = 1e6;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問の有無

int gcd(int a, int b) { // aとbの最大公約数（ユークリッドの互除法）
    if (b == 0) return a;
    return gcd(b, a % b);
}

bool is_prime[MAX+1];
int d[MAX+1];

void erat() { // エラトステネスのふるい
    memset(is_prime, true, sizeof(is_prime));
    for (int i = 2; i <= MAX; i++) {
        if (is_prime[i]) {
            for (int j = i + i; j <= MAX; j += i) {
                is_prime[j] = false;
                d[j] = i;
            }
        }
    }
}

void prime_fact(int x, set<int> &fact) { // 素因数分解
    if (x < 2) return;
    // for (int i = 2; i * i <= x; i++) {
    //     if (x % i == 0) {
    //         fact.insert(i);
    //         while (x % i == 0) x /= i;
    //     }
    // }
    // if (x != 1) fact.insert(x);
    while (not is_prime[x] && x % d[x] == 0) {
        fact.insert(d[x]);
        x /= d[x];
    }
    if (x != 1) {
        fact.insert(x);
    }
}

int n;
int a[MAX];
set<int> s;
bool flag = true;

int main() {
// input
    erat();
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
// solve
    rep(i, n) {
        if (a[i] == 1) continue;
        if (flag) {
            set<int> fact;
            prime_fact(a[i], fact);
            for (int x : fact) {
                if (not s.count(x)) {
                    s.insert(x);
                } else {
                    flag = false;
                    break;
                }
            }
        }
        if (i > 0) a[i] = gcd(a[i], a[i-1]);
    }
// output
    if (flag) cout << "pairwise coprime" << "\n";
    else {
        if (a[n-1] == 1) cout << "setwise coprime" << "\n";
        else cout << "not coprime" << "\n";
    }
}

Measured memory_bytes: 12472
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    int ans = 0;
    ans += min(max(0,n),9);
    ans += min(max(0,n-99),900);
    ans += min(max(0,n-9999),90000);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, K, h[100000], DP[100000];

int main() {
	cin >> N >> K;
	for (int i = 0; i != N; ++i)
		cin >> h[i];
	DP[0] = 0;
	for (int i = 1; i != N; ++i) {
		DP[i] = intmax;
		for (int j = max(0, i - K); j != i; ++j) {
			DP[i] = min(DP[i], DP[j] + abs(h[i] - h[j]));
		}
	}
	cout << DP[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import deque

INF = 10**5
# (sx, sy) から (gx, gy) への最短距離を求める
# 辿り着けないと INF
def bfs(maze, sx, sy):
    if maze[sx][sy] == "#":
        return [[-1]]
    # すべての点を INF で初期化
    d = [[-INF] * m for i in range(n)]

    # 移動4方向のベクトル
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    # for i in range(n):
    #     for j in range(m):
            # スタートとゴールの座標を探す
            # if maze[i][j] == "S":
            #     sx = i
            #     sy = j
            # if maze[i][j] == "G":
            #     gx = i
            #     gy = j

    # スタート地点をキューに入れ、その点の距離を0にする
    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    # キューが空になるまでループ
    while que:
        # キューの先頭を取り出す
        p = que.popleft()
        # 取り出してきた状態がゴールなら探索をやめる
        # if p[0] == gx and p[1] == gy:
        #     break
        # 移動4方向をループ
        for i in range(4):
            # 移動した後の点を (nx, ny) とする
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            # 移動が可能かの判定とすでに訪れたことがあるかの判定
            # d[nx][ny] != INF なら訪れたことがある
            if 0 <= nx < n and 0 <= ny < m and maze[nx][ny] != "#" and d[nx][ny] == -INF:
                # 移動できるならキューに入れ、その点の距離を p からの距離 +1 で確定する
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d


n, m = map(int, input().split())
ma = [list(input()) for i in range(n)]
maxm=0
for i in range(m):
    for j in range(n):
        a = bfs(ma, j, i)
        # print(a)
        for x in a:
            for y in x:
                maxm = maxm if maxm>y else y
print(maxm)

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

int main(){
  string s;cin >> s;
  if( s == "ABC" )
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
  return 0;
}

Measured memory_bytes: 3612
a = input()
num1 = a.count("1")
num9 = a.count("9")
num7 = a.count("7")
num4 = a.count("4")
if num1 == 1 and num9 == 1 and num7 == 1 and num4 == 1:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 2940
n, m, x = list(map(int, input().split()))
a = list(map(int, input().split()))

u = []
l = []

for i in range(m):
    if a[i] < x:
        l.append(a[i])
    elif a[i] > x:
        u.append(a[i])

print(min(len(u), len(l)))

Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))

typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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 qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
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;}
//#define int long long

int h[100005];
int mem[100005];
int dp(int n){
    if(mem[n]!= -1)
        return mem[n];
    if(n < 1)
        return INF;
    if(n==1)
        return 0;
    int a1 = dp(n-1) + abs(h[n]-h[n-1]);
    int a2 = dp(n-2) + abs(h[n]-h[n-2]);

    return mem[n] = min(a1,a2);
}

inline void solve(){

    int n;
    cin >> n;
    memset(mem,-1,sizeof(mem));
    
    for(int i = 1; i <= n; i++) {
        cin >> h[i];
    }

    cout << dp(n) << endl;

}

struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}



Measured memory_bytes: 4224
import java.util.*;

class Main
{
    static int MOD = 998244353;

    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        long K = sc.nextLong();
        long ans = 0;
        long[] comb = new long[n+1];
        comb[0] = 1;
        for(int i = 1; i < n+1; i++){
            comb[i] = comb[i-1] * (n - i + 1) % MOD * pow(i, MOD - 2) % MOD;
        }
 //       long yy = Math.max(K / n - B , 0);
 //       long xx = Math.min(n, K / A); 
        long q = K + A;
        for(int x = 0; x <= n; x++){
            q -= A;
            if(q % B == 0){
                long y = q / B;
                if(y > n ) continue;
                if(y < 0 ) break;
                ans = (ans + comb[x] * comb[(int)y] % MOD) % MOD;
            }
        }
        System.out.println(ans);
    }
    static long calc(int n, long a)
    {
        long MulSumN = 1;
        long MulSumA = 1;
        for(int i = 1; i <= a; i++){
            MulSumN *= n - i + 1;
            MulSumN %= MOD;
            MulSumA *= i;
            MulSumA %= MOD;
        }
        return MulSumN * pow(MulSumA, MOD - 2) % MOD;
    }
    public static long pow(long a, int b){
        if(b == 1) return a;
        if(b % 2 == 0){
            long d = pow(a, b / 2);
            return d * d % MOD;
        }
        return a * pow(a, b - 1) % MOD;
    }
 }


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

int main() {
    int N, K;
    cin>>N>>K;
    vector<long> H;
    long tmp;
    for(int i=0;i<N;++i){
        cin>>tmp;
        H.push_back(tmp);
    }
    sort(H.begin(), H.end(), greater<long>());
    long ans = 0;
    if(K>=N){
        ans = 0;
    }
    else {
        for(int i=K;i<N;++i){
            ans += H[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}


void solve_tle(long long N, std::string S){
    ll cnt=0;
    for (long long i = 0; i < N; i++) {
        for (long long j = i+1; j < N; j++) {
            if(S[i]==S[j] || 2*j-i<j+1) continue;
            for (long long k = j+1; k < N; k++) {
                // if(S[i]!=S[j]&&S[i]!=S[k]&&S[j]!=S[k]){
                if(S[i]!=S[k]&&S[j]!=S[k]){
                    if(j-i!=k-j){
                        cnt++;
                    }
                }
            }
        }
    }
    cout << cnt << endl;
}

void solve(long long N, std::string S){
    unordered_map<char, ll> m={{'R',0},{'B',0},{'G',0}};
    for (long long i = 0; i < N; i++) {
        m[S[i]]++;
    }
    ll sum=1;
    for (auto& e: m) {
        // debg(e.second);
        sum*=e.second;
    }
    if(sum==0){
        cout << 0 << endl;
        return;
    }
    // debg(sum);
    for (long long i = 0; i < N; i++) {
        for (long long j = 1; j < N; j++) {
            if(i+j>=N || i+j*2>=N) continue;
            if(S[i]!=S[i+j] && S[i]!=S[i+j*2] && S[i+j]!=S[i+j*2]) sum--;
        }
    }
    cout << sum << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void) {
    int N;
    double T, A;
    cin >> N >> T >> A;
    vector<double> temp;
    for(int i=0; i<N; i++) {
        double H;
        cin >> H;
        temp.push_back(abs(T - 0.006*H - A));
    }
    cout << distance(temp.begin(), min_element(temp.begin(), temp.end())) + 1 << endl;
    return 0;
}


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(10)





void solve() {

	int n;
	cin >> n;
	set<int> bag;
	int k = n;
	while(k--) {
		int x;
		cin >> x;
		bag.insert(x);
	}
	if(bag.size() == n) {
		cout << "YES\n";
	}
	else {
		cout << "NO\n";
	}
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	solve();

	return 0;
}

Measured memory_bytes: 12972
#include <iostream>
#include <algorithm>
using namespace std;
const int M = 1e9+7;

long long qpow(long long a, long long n) {
    long long ret = 1;
    a = (a % M + M) % M;
    for (; n; n >>= 1) {
        if (n & 1) ret = (ret * a) % M;
        a = (a * a) % M;
    }
    return ret;
}

int main()
{
    int a, b, c;
    int n, k;
    cin >> n >> k;
    long long ans[200005] = {0}, sum = 0;
    for (int i = k; i >= 1; --i) {
        ans[i] = qpow((int)k/i, n);
        for (int t = 2; t * i <= k; ++t) {
            ans[i] = (ans[i] + M - ans[t*i]) % M;
        }
        sum = (sum + (ans[i] * i) % M) % M;
    }
    cout << sum << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    if (K == 3) cout << "ACLACLACL" << endl;
    else {
        string ans = "";
        rep(i, K) ans += "ACL";
        cout << ans << endl;
    }
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>

#include <iomanip>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
// queue: first in first out
// stack: first in last out
typedef long long ll;

const long long int MOD = 1e9+7;
const ll INF = 1e17;
const ll NUM = 1e5+1;
// ll dp[100005][13];
ll dp[10005];

ll Query[NUM];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

signed main(void) {
  string S;
  cin >> S;
  if (S[2] == S[3] && S[4] == S[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> k(m), p(m);
  vector<vector<int>> s(m);
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      int tmp;
      cin >> tmp;
      tmp--;
      s[i].push_back(tmp);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }

  int ans = 0;
  for (int z = 1; z <= (1 << n); z++) {
    bool res = true;
    for (int i = 0; i < m; i++) {
      int cnt = 0;
      for (int j = 0; j < k[i]; j++) {
        int tmp = 1 << s[i][j];
        if (z & (1 << s[i][j])) { cnt++; }
      }
      if (cnt % 2 != p[i]) { res = false; }
    }
    if (res) { ans++; }
  }
  cout << ans << endl;
}

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

int main(void) {
	std::vector<int> vec;

	for (int i = 0; i < 3; i++) {
		int v;
		std::cin >> v;
		vec.push_back(v);
	}

	std::sort(vec.begin(), vec.end());

	int c1 = vec[1] - vec[0];
	int c2 = vec[2] - vec[1];
	std::cout << c1 + c2 << std::endl;

	return 0;
}




Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int

require 'prime'

primes = Prime.each(55555).to_a

primes_more = Prime.each(55555*5).to_a.to_set

# result = []
# skip = false
# count = 0
#
# primes.each do |p|
#   next if p == 2
#   next if result.length > 0 && p <= result.last
#   break if result.length >= 55
#
#   if result.length < 4
#     result << p
#   else
#     [p, *result].combination(5) do |array|
#       if primes_more.include?(array.sum)
#         result = [*result[0..count], array.sum]
#         count += 1
#         break
#       end
#     end
#   end
# end

result = primes.filter { |p| p.to_s.split('').last == '1' }[0..(N-1)]

puts result.join(' ')


Measured memory_bytes: 16808
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long n;cin>>n;
    vector<long long> arr(n);
    for(int i=1;i<n;i++){
        int no;cin>>no;
        arr[no-1]++;
    }
    for(int i=0;i<n;i++) cout<<arr[i]<<endl;
}

Measured memory_bytes: 4756
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: i64 = iterator.next().unwrap().parse().unwrap();
    let m: i64 = iterator.next().unwrap().parse().unwrap();

    if n == 1 && m == 1 {
        return "1".to_string();
    }
    if n == 1 || m == 1 {
        return format!("{}", n * m - 2);
    }

    return format!("{}", (n - 2) * (m - 2));
}


Measured memory_bytes: 4352
from operator import itemgetter
N = int(input())
A = [(i+1, int(x)) for i, x in enumerate(input().split())]
A_ = sorted(A, key=itemgetter(1))
A__ = [a[0] for a in A_]
for i in A__[:-1]:
    print(i, end=' ')
print(A__[-1])

Measured memory_bytes: 23412
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
	#ifdef LOCAL_DEFINE
		freopen("../a.in","r",stdin);
		freopen("../a.out", "w",stdout);
	#endif
	
	int n;
	cin >> n;
	float conv = 380000.0;
	float ans = 0.0;
	for(int i=0;i<n;i++){
		float x;
		string u;
		cin >> x >> u;
		if(u=="BTC"){
			x = x*conv;
			ans += x;
		} else {
			ans += x;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[200009];
long long ans,mx[200009];
pair<int,int>h[200009];
void update(int x,long long y) {
	for(int i=x;i<=n;i+=i&-i) mx[i]=max(mx[i],y);
}
long long query(int x) {
	long long maxn=0;
	for(int i=x;i;i-=i&-i) maxn=max(maxn,mx[i]);
	return maxn;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%d",&h[i].first);
		h[i].second=i;
	}
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	sort(h+1,h+n+1);
	for(int i=1;i<=n;i++) {
		long long now=query(h[i].second)+a[h[i].second];
		update(h[i].second,now);
		ans=max(ans,now);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4096
import java.util.*;
import java.io.*;

/**
 * Made by egor https://github.com/chermehdi/egor.
 * 
 * @author Azuz
 * 
 */
public class Main {

    void solve(Scanner in, PrintWriter out) {
      char[] s = in.next().toCharArray();
      char[] t = in.next().toCharArray();
      
      int ans = Integer.MAX_VALUE;
      for (int i = 0; i + t.length <= s.length; ++i) {
        int cnt = 0;
        for (int j = 0; j < t.length; ++j) {
          if (s[i + j] != t[j]) {
            ++cnt;
          } 
        }
        ans = Math.min(ans, cnt);
      }

      out.println(ans);
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


Measured memory_bytes: 35712
from bisect import *
input()
L = [int(x) for x in input().split()]
n = int(input())
for _ in range(n):
    x = int(input())
    i = bisect_left(L,x)
    if i >= len(L):
        print(0)
        continue
    if L[i] == x:
        print(1)
    else:
        print(0)



Measured memory_bytes: 17204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (register int i = a; i <= b; i++)

ll n, k, a[200010];
inline void solve(int T) {

    cin >> n >> k;
    rep(i, 1, n) cin >> a[i];
    ll l = 1, r = 1e9;
    while(l < r) {
        ll mid = (l + r) / 2, tmp = 0;
        rep(i, 1, n) if(a[i] > mid) {
            ll f = ceil(1.0 * a[i] / mid);
            tmp += f - 1;
        }
        if(tmp > k) l = mid + 1;
        else r = mid;
    }
    cout << l << endl;
}   
int main()
{
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
 
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
 
    int T = 1;
    // cin >> T;
    rep(i, 1, T) solve(i);
    // system("pause");
}

Measured memory_bytes: 5148
function Main(input) {
  args = input.split('\n')
  const square = []
  for(var i = 0; i < 3; i++){
    square[i] = args[i].split(' ')
  }
  
  const count = args[3]
  const nums = []
  for(var i = 0; i < count; i++){
    nums.push(args[i + 4])
  }
  
  // Ai,jとbnを比較
  const results = []
  for(var i = 0; i < 3; i++){
    results.push([0, 0, 0])
  }
  for(var i = 0; i < 3; i++){
    for(var j = 0; j < 3; j++){
      for(var k = 0; k < nums.length; k++){
        if(square[i][j] === nums[k]) {
          results[i][j] = 1
        }
      }
    }
  }
  
  // ビンゴかどうかをチェック - タテヨコ
  var bingoCount = 0
  var checkedCountAngleRight = 0
  var checkedCountAngleLeft = 0
  for(var i = 0; i < 3; i++) {
    var checkedCountHorizontal = 0
    var checkedCountVertical = 0
    for(var j = 0; j < 3; j++) {
      // ヨコ
      if(results[i][j]) checkedCountHorizontal++
      // タテ
      if(results[j][i]) checkedCountVertical++
    }
    // 右ナナメ
    if(results[i][i]) {
      checkedCountAngleRight++
    }
    // 左ナナメ
    if(results[i][2-i]) {
      checkedCountAngleLeft++
    }
    
    if(checkedCountHorizontal === 3) {
      bingoCount++
    }
    if(checkedCountVertical === 3) {
      bingoCount++
    }
  }
  if(checkedCountAngleRight === 3) {
    bingoCount++
  }
  if(checkedCountAngleLeft === 3) {
    bingoCount++
  }
  if(bingoCount) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>

int n, dp[100055][3], a[100055][3];

int main() {
	
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
	}
	
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j == k) {
					continue;
				}
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
			}
		}
	}
	
	printf("%d\n", max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])));
	
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;

int main() {
    // input
    ll N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    // process
    vector<char> predict[K];
    for (ll i = 0; i < N; i++) {
        predict[i % K].emplace_back(T[i]);
    }

    ll ans = 0;
    for (ll i = 0; i < K; i++) {
        char previous_hand = 'a';
        for (ll j = 0; j < predict[i].size(); j++) {
            if (predict[i][j] == 'r') {
                if (previous_hand == 'p') {
                    previous_hand = 'a';
                    continue;
                }
            } else if (predict[i][j] == 's') {
                if (previous_hand == 'r') {
                    previous_hand = 'a';
                    continue;
                }
            } else if (predict[i][j] == 'p') {
                if (previous_hand == 's') {
                    previous_hand = 'a';
                    continue;
                }
            }

            if (predict[i][j] == 'r') {
                previous_hand = 'p';
                ans += P;
            } else if (predict[i][j] == 's') {
                previous_hand = 'r';
                ans += R;
            } else if (predict[i][j] == 'p') {
                previous_hand = 's';
                ans += S;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define int long long

struct UF{
  vector<int> par; //親
  vector<int> size; //集合の大きさ

  void init(int n){
    par.resize(n);
    size.resize(n);
    for(int i = 0; i < n; i++){
      par[i] = i;
      size[i] = 1;
    }
  }

  //木の根を求める
  int root(int x){
    if(par[x] == x){
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }

  //xとyの属する集合を併合
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x == y) return;

    if(size[x] < size[y]) swap(x,y);
    par[y] = x;
    size[x] += size[y];
  }

}uf;

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

  int n,m; cin >> n >> m;
  vector< pair<int,int> > v(m);
  for(int i = 0; i < m; i++){
    cin >> v[i].first >> v[i].second;
  }
  uf.init(n+1);

  vector<int> ans(m);
  ans[m-1] = n*(n-1)/2;
  for(int i = m-1; i > 0; i--){
    int a = v[i].first;
    int b = v[i].second;
    if(uf.root(a) == uf.root(b)){
      ans[i-1] = ans[i];
    }
    else {
      ans[i-1] = ans[i] - uf.size[uf.root(a)]*uf.size[uf.root(b)];
      uf.unite(a,b);
    }
  }

  for(int i : ans){
    cout << i << endl;
  }

  return 0;
}


Measured memory_bytes: 5248
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main(void){
    int N;
    
    cin >> N;

    int A[N];
    int odd=0;
    int divi=0;
    int ans=0;

    for(int i=0;i<N;i++){
        A[i] =0;
    }
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        if(A[i] % 2 == 1){
            odd++;  
        }
        else{   
            divi++;
        }
    }
    ans = pow(3, N) - pow(2, divi);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
al = list(map(int, input().split()))

x = al[-1]
for i in range(n-1):
    x += (-1)**(i+1) * al[i]
x //= 2
xl = [x]

for i in range(n-1):
    xl.append(al[n-i-2] - xl[i])

print(*reversed(list(map(lambda a:a*2, xl))))

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

int main(){
	int H,W;

	while(1){
		cin >>H>>W;
		if (W==0 && H==0) break;
		for (int i=1; i<=H; i++){
			
			for (int k=1; k<=W; k++){
				if (i==1 || i==H || k==1 || k==W) cout <<"#";
				else cout << ".";
			}
			cout <<"\n";
		}
		cout << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 1120