akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eb emplace_back
#define All(v) v.begin(), v.end()
long power(long a,long b){return b?power(a*a%inf,b/2)*(b%2?a:1)%inf:1;}

/*
 dead_rock term
 01, 10
 ...
 01, 12, 23, ..., 90
 とは限らない
 
 1.
 201 130
 a_nxt is 0
 b_nxt is 1
 a_have has 1
 b_have has 0
 
 2. not
 201u210u
 
 3つ以上でdead_rock起きるケース
 a  b  c
 01 12 20
 
 merge a, b -> d
 d_nxt is 2
 d_have has 0, 1
 
 */
bool self_deadlock(string S) {
    map<int, int> mp;
    rep(i, S.size()) {
        if (S[i] == 'u') {
            for (auto e : mp) mp[e.first] = 0;
        }
        if (mp[S[i] - '0'] == 1) {cout << "UNSAFE" << endl; return 1;}
        else mp[S[i] - '0'] = 1;
    }
    return 0;
}
bool comp(pii a, pii b) {
    return a.second < b.second;
}
void deadlock(string S) {
    vector<pii> s;
    int tmp = 0;
    rep(i, S.size()) {
        if (S[i] == 'u') {tmp = 0; continue;}
        int num = S[i] - '0';
        if (tmp != 0) s.eb(tmp, num);
        tmp += (1 << num);
    }
    //rep(i, s.size()) cout << bitset<8>(s[i].first) << " " << s[i].second << endl;
    sort(s.begin(), s.end(), comp);
    rrep(i, 1, s.size()) {
        if (s[i].first == s[i - 1].first && s[i].second == s[i - 1].second) {
            s.erase(s.begin() + i);
        }
    }
    //rep(i, s.size()) cout << bitset<8>(s[i].first) << " " << s[i].second << endl;
    rep(loop, 10) { //10周でいいのか
        //merge combination
        int flg = 0;
        rep(i, s.size()) {
            rrep(j, i + 1, s.size()) {
                if (s[i].first & s[j].first) continue;
                if (s[i].second == s[j].second) continue;
                //2つでdeadlock
                if ((s[i].first & (1 << s[j].second)) &&
                    (s[j].first & (1 << s[i].second))) {cout << "UNSAFE" << endl; return;}
                else if ((s[i].first & (1 << s[j].second))) {
                    s[i].first |= s[j].first;
                    s.erase(s.begin() + j);
                    flg = 1;
                } else if ((s[j].first & (1 << s[i].second))) {
                    s[j].first |= s[i].first;
                    s.erase(s.begin() + i);
                    i++;
                    flg = 1;
                }
            }
        }
        if (flg == 0) break;
    }
    cout << "SAFE" << endl;
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; string S;
    while (cin >> N && N) {
        cin >> S;
        if (self_deadlock(S)) continue;
        deadlock(S);
    }
}



Measured memory_bytes: 3304
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define freopen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#else
#define freopen //comment
#endif
#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define pb push_back
typedef tree<int, null_type,less<int>,  rb_tree_tag,tree_order_statistics_node_update>  ordered_set;
#define int long long int
#define endl "\n"
main()
{ 
// freopen
 io
 int n,x,t;
 cin>>n>>x>>t;
 int ans=(n/x)+(n%x!=0);
 cout<<ans*t<<endl;
}


Measured memory_bytes: 3596
N = int(input())
W = list(map(int, input().split()))
absvalue = 10000000

for i in range(N):
  after = 0
  before = 0
  for j in range(i):
    before += W[j]
  for j in range(N-i):
    after += W[-j-1]
  if abs(before - after) < absvalue:
    absvalue = abs(before - after)

print(absvalue)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define N 100009
using namespace std;
char s[N], ss[N];

int main()
{
    int a, b;
    scanf("%s%s", s, ss);
    a = strlen(s); b = strlen(ss);
    if(a < b || strcmp(s, ss) < 0) puts("LESS");
    else if(a > b || strcmp(s, ss) > 0) puts("GREATER");
    else puts("EQUAL");
    return 0;
}



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

int main() {
	long long int h,w;
	cin>>h>>w;
	
	if(h==1 || w==1)
	cout<<"1";
	else if((h*w)%2==0)
	cout<<(long long int)(h*w)/2;
	else
	cout<<(long long int)(h*w)/2+1;
	// your code goes here
	return 0;
}

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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int dfs(vector<vector<int>> &A, vector<int> &seen, int i) {
    seen[i] = 1;
    int res = 1;
    rep(j,A[i].size()) {
        int to = A[i][j];
        if (seen[to]!=-1) continue;
        res += dfs(A,seen,to);
    }
    return res;
}

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> A(N,vector<int>(0));

    rep(i,M) {
        int a,b;
        cin >> a >> b;
        a--,b--;
        A[a].push_back(b);
        A[b].push_back(a);
    }
    
    vector<int> seen(N,-1);

    int ans = 0;
    rep(i,N) {
        if (seen[i]!=-1) {
            continue;
        }
        //cout << dfs(A,seen,i) << endl;
        ans = max(ans,dfs(A,seen,i));
        //cout << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 24340
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

void bfs(vector< vector<int> >& edges, vector<int>& state, int node){
    queue<int> Q;
    Q.push(node);
    state[node] = -1;
    int color;
    while(!Q.empty()){
        node = Q.front();
        Q.pop();
        color = 1;
        for(int e : edges[node]){
            if(state[e] == 0){
                if(color != state[node]){
                    state[e] = color++;
                }
                else{
                    state[e] = ++color;
                    ++color;
                }
                Q.push(e);
            }
        }
    }
}

void swap(int& a, int& b){
    int temp = a;
    a = b;
    b = temp;
}

int main()
{
    int N;
    cin >> N;
    vector< vector<int> > edges(N);
    vector<int> state(N), vec(N-1);
    int a, b;
    for(int i=0;i<N-1;++i){
        cin >> a >> b;
        if(a > b) swap(a, b);
        edges[--a].push_back(--b);
        edges[b].push_back(a);
        vec[i] = b;
    }

    bfs(edges, state, 0);
    int ans = -1;
    for(int i=1;i<N;++i){
        ans = max(ans, state[i]);
    }
    cout << ans << endl;
    for(int i=0;i<N-1;++i){
        cout << state[vec[i]] << endl;
    }
}


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

int main(){
    int dom[5][4][11] = {};
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        dom[b][f][r] += v;
    }
    
    
    for(int i = 1; i <= 4; i++){
        for(int j = 1; j <= 3; j++){
            for(int k = 1; k <= 10; k++) cout << " " << dom[i][j][k];
            cout << endl;
        }
        if(i != 4) cout << "####################" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>

using namespace std;

int main() {

	int K;
	cin >> K;

	string S;
	cin >> S;

	int N = S.length();
	
	if (K < N) {
		for (int i = 0; i < K; ++i) {
			cout << S[i] << flush;
		}
		cout << "..." << endl;
	}
	else {
		cout << S << endl;
	}
}

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

/*int main(){
  int R,G,B,N; cin >> R >> G >> B >> N;
  
  int ans = 0;
  for(int i = 0; i <= N/R; i++){
    for(int j = 0; j <= N/G; j++){
      for(int k = 0; k <= N/B; k++){
        if(R*i+G*j+B*k == N) ans++;
      }
    }
  }
  cout << ans << endl;
}*/

int main(){
  int N,K; cin >> N >> K;
  
  cout << N - (K - 1);
}

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


struct Node{
  int key;
 struct Node *right, *left, *parent;
};

struct Node *root, *NIL;

void insert(int k){
struct  Node *y=NIL;
struct  Node *x=root;
struct  Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!= NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }


  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}


void inorder(struct Node *u){
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}


void preorder(struct Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n,i,x;
  char *com;
  char *pri="print";
  char *ins="insert";

  com = (char *)malloc(7*sizeof(char));
   

   scanf("%d",&n);
  

  for(i=0;i<n;i++){
     scanf("%s",com);
     if(strncmp(com,ins,6)==0){
       scanf("%d",&x);
       insert(x);
     }
     else if(strncmp(com,pri,5)==0){
       inorder(root);
       printf("\n");
       preorder(root);
       printf("\n");
     }
  }

  return 0;
}





Measured memory_bytes: 25164
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000007
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

ll mod_pow(ll x, ll n){
    if(n==0) return 1;
    ll res = mod_pow(x*x % mod, n / 2);
    if(n & 1) res = res * x % mod;
    return res;
}

map<int, int> prime_factor(int n){
    map<int, int> res;
    for(int i=2; i*i <= n; i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        } 
    }
    if(n != 1) res[n]++;
    return res;
}

int main(){
    int N;
    cin >> N;
    vi a;
    map<int, int> D;
    rep(i, 0, N){
        int _a; cin >> _a;
        a.pb(_a);
    }
    for(int i=0; i<N; i++){
        map<int, int> d = prime_factor(a[i]);
        for(auto &item : d){
            D[item.first] = max(D[item.first], item.second);
        }
    }
    ll kobai = 1;
    for(auto &item : D){
        kobai = (kobai * mod_pow(item.first, item.second) % mod);
    }
    ll ans = 0;
    for(int i; i<N; i++){
        ans += kobai * mod_pow(a[i], mod-2);
        ans %= mod;
    }
    cout << ans << endl;


    return 0;
}




Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

void solve(){
    /*
    s[i]=='1'の部分のa[i]をそれ以降のs[i]=='0'のa[i]の組み合わせで表現できるか
    a[i]とa[j]を組み合わせたところで，結局a[i]を後ろので表現でき，a[j]を後ろので表現できれば
    a[i]^a[j]も表現できる
    mat ei ^ mat ej = a[i]^a[j]
    mat (ei^ej) = a[i]^a[j]
    */

    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    string s;cin>>s;
    reverse(ALL(a));reverse(ALL(s));
    vector<ll> b;// 基底の集合，iに対し1しか増えない
    rep(i,n){
        ll v=a[i];
        for(auto x:b) chmin(v,v^x);
        if(s[i]=='1'){
            // 今後s[i]='0'のa[i]を使っても0化できない
            // (基底ベクトルたちを使って0化できない)
            if(v){
                cout<<1<<endl;
                return ;
            }
        }else{
            b.push_back(v);
        }

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

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

    int q;cin>>q;while(q--) solve();
    return 0;    
}


Measured memory_bytes: 3616
const [nmk, _a, _b] = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/)
let [n, m, k] = nmk.split(/\s/).map(Number)
const a = _a.split(/\s/).map(Number).reduce((acc, curr, i) => {
  acc[i] = curr + (i && acc[i - 1])
  return acc
}, [])
const b = _b.split(/\s/).map(Number).reduce((acc, curr, i) => {
  acc[i] = curr + (i && acc[i - 1])
  return acc
}, [])

let bIndex = binarySearch(b)
let result = bIndex + 1
for (let i = 0; i < a.length; i++) {
  const remaining = k - a[i]
  if (remaining < 0) {
    break
  }
  for (; bIndex >= 0; bIndex--) {
    if (b[bIndex] <= remaining) {
      break;
    }
  }
  result = Math.max(result, i + bIndex + 2)
}
console.log(result)

function binarySearch(arr) {
  let s = 0, e = arr.length - 1
  while (s < e) {
    const m = (s + e) >> 1
    const ml = arr[m] <= k, mu = arr[m + 1] <= k
    if (ml === mu) {
      if (ml) {
        s = m + 1
      } else {
        e = m - 1
      }
    } else {
      return m;
    }
  }
  return arr[s] <= k ? s : s - 1
}

Measured memory_bytes: 80988
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#define SIZE 100005
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

struct UF
{
	int par[SIZE],rank[SIZE];
	
	void init(int n)
	{
		for(int i=0;i<n;i++)
		{
			par[i]=i;
			rank[i]=1;
		}
	}
	int find(int x)
	{
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y])
		{
			par[x]=y;
		}
		else
		{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
	bool same(int x,int y)
	{
		return find(x)==find(y);
	}
};
UF uf;
int A[SIZE],B[SIZE];
bool use[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	A[n]=0;
	for(int i=0;i<n;i++) A[n]^=A[i];
	for(int i=0;i<n;i++) scanf("%d",&B[i]);
	B[n]=0;
	for(int i=0;i<n;i++) B[n]^=B[i];
	n++;
	vector <int> va,vb;
	for(int i=0;i<n;i++)
	{
		va.push_back(A[i]);
		vb.push_back(B[i]);
	}
	sort(va.begin(),va.end());
	sort(vb.begin(),vb.end());
	for(int i=0;i<n;i++)
	{
		if(va[i]!=vb[i])
		{
			puts("-1");
			return 0;
		}
	}
	va.erase(unique(va.begin(),va.end()),va.end());
	uf.init(n+2);
	int ret=0;
	int nm=0;
	for(int i=0;i<n;i++)
	{
		A[i]=lower_bound(va.begin(),va.end(),A[i])-va.begin();
		B[i]=lower_bound(va.begin(),va.end(),B[i])-va.begin();
		if(A[i]!=B[i])
		{
			//printf("%d : %d %d\n",i,A[i],B[i]);
			uf.unite(A[i],B[i]);
			use[A[i]]=use[B[i]]=true;
			if(i!=n-1) ret++;
		}
	}
	int sz=0;
	for(int i=0;i<va.size();i++) if(use[i]&&uf.find(i)==i) ret++;
	if(use[A[n-1]]) ret--;
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 2932
def calc_distance(p1, p2):
    from math import sqrt
    x1, y1 = p1
    x2, y2 = p2
    return sqrt((x2 - x1)**2 + (y2 - y1)**2)


if __name__ == '__main__':
    # ??????????????\???
    data = [float(x) for x in input().split(' ')]

    # 2???????????¢????¨????
    result = calc_distance((data[0], data[1]), (data[2], data[3]))

    # ???????????????
    print('{0:.8f}'.format(result))

Measured memory_bytes: 7604
#!/usr/bin/perl

my ($n,$m,$q) = map {$_ - 0} split(/\s+/o,<STDIN>);

my @d = ();
my @d2 = ();
for(my $i=0;$i<$n;$i++){
  my @dm1 = ();
  $#dm1 = $n-1;
  push(@d,\@dm1);
  my @dm2 = ();
  $#dm2 = $n-1;
  push(@d2,\@dm2);
}

for(my $i=0;$i<$m;$i++){
  my ($l,$r) = map {$_ - 0} split(/\s+/o,<STDIN>);
  $d[$l-1]->[$r-1] += 1;
}

$d2[$n-1]->[$n-1] = $d[$n-1]->[$n-1];
if( $n>=2 ){
  for(my $i=$n-2;$i>=0;$i--){
    my $tot = 0;
    for(my $j=$i;$j<$n;$j++){
      $tot += ( $d[$i]->[$j] - 0 );
      $d2[$i]->[$j] = $tot + $d2[$i+1]->[$j];
    }
  }
}

for(my $i=0;$i<$q;$i++){
  my ($p,$qq) = map {$_ - 0} split(/\s+/o,<STDIN>);
  my $v = $d2[$p-1]->[$qq-1] - 0;
  print "$v\n";
}

exit(0);


Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
double a[200010];
int main(){
   int n,k;
   double m;
   cin>>n>>k;
   for(int i=0;i<n;i++){
   	cin>>m;
   	a[i]=(1.0+m)/2;
   }
   
   for(int i=1;i<n;i++){
   	a[i]=a[i]+a[i-1];
   }
     
   double max=a[k-1];
   for(int i=n-1;i>=k;i--){
   	a[i]=a[i]-a[i-k];
   	if(a[i]>max) max=a[i];
   }
      
   printf("%.12lf\n",max);
return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


#define INF 999999999
int n,m;
int cost[200][200];
int tim[200][200];

int main(){
    while(cin>>n>>m){
        rep(i,200)rep(j,200) {
            cost[i][j]=INF;
            tim[i][j]=INF;
        }
        if(n==0&&m==0)break;
        rep(i,n){
            int a,b,c,d;
            cin>>a>>b>>c>>d;
            a--,b--;
            cost[a][b] = cost[b][a] = c;
            tim[a][b] = tim[b][a] = d;
        }
        rep(l,m){
            rep(i,m){
                rep(j,m){
                    cost[i][j] = min(cost[i][j],cost[i][l]+cost[l][j]);
                    tim[i][j]  = min(tim[i][j] ,tim[i][l] +tim[l][j] );
                }
            }
        }
        int k;
        cin>>k;
        rep(i,k){
            int a,b,c;
            cin>>a>>b>>c;
            a--,b--;
            if(c==0){
                cout<<cost[a][b]<<endl;
            }
            else cout<<tim[a][b]<<endl;
        }
    }
}

Measured memory_bytes: 1472
def solve():
    mod = 10**9+7
    N, M = map(int, input().split())
    k = [0]*(N+1)
    if M==0:
        k[0]=1
        k[1]=1
        for i in range(2, N+1):
            k[i]=(k[i-1]+k[i-2])%mod
        print(k[N]%mod)
        return
    a = [int(input()) for _ in range(M)]
    k[0]=1
    cnt = 0
    if a[0]!=1:
        k[1]=1
    else:
        cnt+=1
    for i in range(2, N+1):
        if cnt<M and i ==a[cnt]:
            cnt+=1
            continue
        else:   
            k[i]=(k[i-1]+k[i-2])%mod
    print(k[N]%mod)
    return
solve()

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

int main() {
    int n,k;
    string s;
    cin >> n >> k >> s;
    vector<int> sum(0);
    if (s.at(0) == '0') sum.push_back(0);
    int c = 1;
    for(int i = 1; i < n; i++)
    {
        if (s.at(i) != s.at(i - 1)) {
            sum.push_back(c); 
            c = 1;
        }
        else c++;
    }
    sum.push_back(c);
    if (s.at(n - 1) == '0') sum.push_back(0);
    
    vector<int> c_sum((int)sum.size() + 1);
    c = 0;
    for(int i = 0; i < (int)sum.size(); i++)
    {
        c += sum.at(i);
        c_sum.at(i + 1) = c;
    }
    
    int ans = 0;
    for (int i = 0; i < (int)c_sum.size(); i += 2) {
        ans = max(ans, ((c_sum.at(min((i + (k * 2 + 1)), ((int)c_sum.size() - 1)))) - c_sum.at(i)));
    }

    cout << ans << endl;      
}

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

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> C(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> C.at(i).at(j);
    }
  }
  int ans = 0;
  for (int bit = 0; bit < 1 << H; bit++) {
    for (int bit2 = 0; bit2 < 1 << W; bit2++) {
      int cnt = 0;
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if (bit >> i & 1) continue;
          if (bit2 >> j & 1) continue;
          if (C.at(i).at(j) == '#') cnt++;
        }
      }
      if (cnt == K) ans++;
    }
  }
  cout << ans << "\n";
}

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

int main(){
    int N;  cin >> N;
    vector<int> H(N);
    for(int i=0; i<N; i++){
        cin >> H[i];
    }
    H[0]--;
    for(int i=1; i<N; i++){
        if(H[i] > H[i-1]){
            H[i]--;
        }
        if(H[i] < H[i-1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
if n >= m:
  print(0)
  exit()
s = set(map(int,input().split()))
l = list(s)
l.sort()
gap = []
for i in range(len(l)-1):
  gap.append(l[i+1]-l[i])
gap.sort()
print(sum(gap[:1-n]) if n!= 1 else sum(gap))

Measured memory_bytes: 63060
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

int main()
{
    fast;
    double r,pi=3.141592653;
    cin>>r;
    cout<<2*pi*r<<endl;
    return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  int N, tmp;
  cin >> N;
  vector<int> B;
  for (int i=0; i<N - 1; i++){
    cin >> tmp;
    B.push_back(tmp);
  }
  int ans = B[0];
  for (int i=1; i<N - 1; i++){
    ans += min(B[i - 1], B[i]);
  }
  ans += B.back();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
MOD = 10 ** 9 + 7
a = [0] * (n+2)
dp = [0] * (n+2)
for i in range(m):
	k = int(input())
	a[k] = 1

dp[0] = 1
for i in range(n):
	if a[i]: dp[i] = 0
	if i+1 <= n: dp[i + 1] += dp[i]
	if i+2 <= n: dp[i + 2] += dp[i]
	dp[n] %= MOD
print(dp[n])

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

int main() {
	char a,b,c,d;
	cin >> a >> b >> c >> d;
	int A = a - '0';
	int B = b - '0';
	int C = c - '0';
	int D = d - '0';
	for(int i=0; i<8; ++i) {
		int res = A;
		if(i & 1) res += B;
		else res -= B;
		if((i >> 1) & 1) res += C;
		else res -= C;
		if((i >> 2) & 1) res += D;
		else res -= D;
		if(res == 7) {
			cout << A;
			if(i & 1) cout << '+';
			else cout << '-';
			cout << B;
			if((i >> 1) & 1) cout << '+';
			else cout << '-';
			cout << C;
			if((i >> 2) & 1) cout << '+';
			else cout << '-';
			cout << D << "=7" << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;
 
int main() {
    static const double pi = 3.141592653589793;
 
    double A,B;
    double H,M;
    cin >> A >> B >> H >> M;
    double S = H*30.0+M*30/60;
    double L = M*6;
    double diff = abs(S-L);
 
    if(diff>180) diff=360-diff;
    double p = (double)diff/180;
 
    double ans = A*A+B*B-2*A*B*cos(p*pi);
 
    cout << fixed << setprecision(15);
    cout << sqrt(ans) << endl;
}

Measured memory_bytes: 4200
#include <bits/stdc++.h>  // ios_base::sync_with_stdio(false);
#define MAXN 500005          // cin.tie(NULL);
#define di pair<int, int>
#define tri pair<int, di>
#define bi pair<bool, int>
using namespace std;
void swap(int ar[],int  i,int j)
    {int aux = ar[j]; ar[j] = ar[i]; ar[i] = ar[j];}

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    long long  ar[11];

    ar[0] = C;
    
    for(int k = 1; k < 11; k++){
        ar[k] = ar[k-1]*A - B;
        cout << ar[k] << endl;
    }   
}


Measured memory_bytes: 256
import math
PrimeList = [2]

def calc_prime(N):
    for i in range(3,N+1,2):
        x = int(math.sqrt(i))+1
        j = 0
        prime = True
        while j < len(PrimeList) and PrimeList[j] <= x:
            if i % PrimeList[j] == 0:
                prime = False
                break
            j += 1
        if prime:
            PrimeList.append(i)

calc_prime(55555)
AnsList = []
for p in PrimeList:
    if p % 5 == 1:
        AnsList.append(p)

N = int(input())
for i in range(N):
    print(AnsList[i],end=' ')
print('')


Measured memory_bytes: 3188
N = int(input())
A = sorted([int(a) for a in input().split()])
X = [0] * 1001
for a in A:
    X[a] += 1
for i in range(1, 1001):
    X[i] += X[i-1]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += X[min(A[i]+A[j]-1, 1000)] - (j+1)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const int INF=1000000;
ll p[55][55];
int main() {
	ll a,b;
	cin>>a>>b;
	if(abs(a-b)<=1)cout<<"Brown"<<endl;
	else cout<<"Alice"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream> 

using namespace std;

int main() {
		int N;
		cin >> N;
		int a[N];
		for (int i = 0; i < N; i++) cin >> a[i];

		int bit = 0, cnt = 0;
		for (int i = 0; i < N; i++) {
				if (a[i] < 400) {
						bit |= (1<<0);
				} else if (a[i] < 800) {
						bit |= (1<<1);
				} else if (a[i] < 1200) {
						bit |= (1<<2);
				} else if (a[i] < 1600) {
						bit |= (1<<3);
				} else if (a[i] < 2000) {
						bit |= (1<<4);
				} else if (a[i] < 2400) {
						bit |= (1<<5);
				} else if (a[i] < 2800) {
						bit |= (1<<6);
				} else if (a[i] < 3200) {
						bit |= (1<<7);
				} else {
						cnt++;
				}
		}

		int flg = __builtin_popcount(bit);

		int max_ans, min_ans;
		max_ans = flg + cnt;
		if (cnt) min_ans = max(flg, 1);
		else min_ans = flg;

		cout << min_ans << " " << max_ans << endl;
		return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;


int main(){
    int h,w;cin >>h>>w;
    vector<string>s(h);
    int ans=0;
    for (int i = 0; i < h; ++i)cin >>s[i];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            vector<vector<int>>d(h,vector<int>(w,INF));
            if(s[i][j]=='#')continue;
            d[i][j]=0;
            queue<P>que;
            que.push({i,j});
            auto add=[&](int x,int y,int k){
                if(x<0||x>=h)return;
                if(y<0||y>=w)return;
                if(s[x][y]=='#')return;
                if(k<d[x][y]){
                    d[x][y]=k;
                    que.push({x,y});
                    ans=max(ans,k);
                }
            };
            while(!que.empty()){
                P p=que.front();
                que.pop();
                int x=p.first;
                int y=p.second;
                int k=d[x][y];
                k++;
                add(x+1,y,k);
                add(x-1,y,k);
                add(x,y+1,k);
                add(x,y-1,k);
            }
        }
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main(void){
	int h,w,i;



	while(1){
		scanf("%d %d",&h,&w);

		if(h==0 && w == 0){
			return 0;
		}

		while(h>0){
			i=w;
			while(i>0){
				printf("#");
				i--;
			}
			printf("\n");
			h--;
		}
		printf("\n");
	}
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	int h, w,num;
	cin >> h >> w >> num;
	int ans = 0;
	char tmp;
	vector<vector<int>> vec(h, vector<int>(w, 0));
	rep(i, h) {
		rep(j, w) {
			cin >> tmp;
			if (tmp == '.') vec[i][j] = 0;
			else vec[i][j] = 1;
		}
	}
	vector<vector<int>> change;
	rep(i, 1 << h) {
		change = vec;
		rep(j, h) {
			if (i >> j & 1) {
				rep(k, w) change[j][k] = 0;
			}
		}
		rep(j, 1 << w) {
			vector<vector<int>> change2 = change;
			rep(k, w) {
				if (j >> k & 1) {
					rep(l, h) change2[l][k] = 0;
				}
			}
			// Count
			int c = 0;
			rep(y, h) {
				rep(x, w) {
					c += change2[y][x];
				}
			}
			if (c == num) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int power(int n){
  int res=1;
  rep(i,0,n) res*=2;
  return res;
}

int main(){
  int l;
  cin>>l;
  vector<bool> v;
  int a=l;
  while(a>0){
    v.push_back(a%2);
    a/=2;
  }
  int n=v.size();
  reverse(v.begin(),v.end());
  //cout<<n<<endl;
  vector<int> b,c,d;
  rep(i,0,n-1){
    b.push_back(i);
    c.push_back(i+1);
    d.push_back(0);
  }
  int cur=1;
  rep(i,0,n-1){
    b.push_back(i);
    c.push_back(i+1);
    d.push_back(cur);
    cur*=2;
  }
  rep(i,1,n){
    if(v[i]){
      b.push_back(n-1-i);
      c.push_back(n-1);
      d.push_back(cur);
      cur+=power(n-1-i);
    }
  }
  int e=b.size();
  cout<<n<<' '<<e<<endl;
  rep(i,0,e){
    cout<<b[i]+1<<' '<<c[i]+1<<' '<<d[i]<<endl;
  }
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if((a+b)==(c+d)){
    cout << "Balanced" << endl;
  }
  else if((a+b)>(c+d)){
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
    #define rep(i,n) for(int i=0;i<(n);i++)
    #define rep2(i,n) for(int i=1;i<=(n);i++)
    #define pb push_back
    #define mod 1000000007
    #define INF 2000000000
    typedef long long ll;
    bool compare_by_b(pair<int, int> a, pair<int, int> b) {
        if(a.first != b.first){
            return a.first < b.first;
            
        }else{
            return a.second < b.second;
        }
    }
    int main(){
        int N ,Q;
     
        int ans[200001]={};
        cin >>N>>Q;
     
        vector<pair<int, int> > ab(N);
        vector<pair<int, int> > px(Q);
     
        rep(i,N-1){
            int a, b;
            cin >> a >> b;
            ab[i] = make_pair(a,b);
            //cout << pairs[i].first << ' ' << pairs[i].second<< endl;
        }
        rep(i,Q){
            int a, b;
            cin >> a >> b;
            px[i] = make_pair(a,b);
            //cout << pairs[i].first << ' ' << pairs[i].second<< endl;
        }
         sort(ab.begin(),ab.end(), compare_by_b);
        rep(i,Q){
            ans[px[i].first-1] += px[i].second;
        }
        rep(i,N){
            ans[ab[i].second-1] += ans[ab[i].first-1];
        }
     
        rep(i,N){
            cout << ans[i] << ' ';
        }
        cout << endl;
        
        
        return 0;
        
     
    }

Measured memory_bytes: 6272
l, r = map(int, input().split())
m = []
if r-l >= 2018:
  print(0)
else:
  L = l%2019
  R = r%2019
  if L == 0 or R == 0:
    print(0)
  elif L>R:
    print(0)
  else:
    for i in range(L, R+1):
      for j in range(i+1, R+1):
        m.append(i*j%2019)
    print(min(m))

Measured memory_bytes: 75412
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main(){
    int n,m;cin>>n>>m;
    vector<vector<int>> d(n);
    vector<int> list(n);
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        d[a].push_back(b);
        d[b].push_back(a);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        //if(list[i]==1)continue;
        queue<int> q;
        q.push(i);
        list[i]=1;
        int sum=1;
        while(!q.empty()){
            int p=q.front();
            q.pop();
            for(auto np:d[p]){
                if(list[np]==1)continue;
                list[np]=1;
                q.push(np);
                sum+=1;
            }
        }
        ans=max(ans,sum);
    }
    cout <<ans;
}

Measured memory_bytes: 15620
#include<iostream>
#include<math.h>
#include <stdio.h>
using namespace std;

int main(){
    char s[1000];
    scanf("%s", s);
    for(int i=0; i<1000; i++){
        if(s[i] == ' ')
            continue;
        if(s[i] == '\0')
           break;
        else if('A'==s[i])
            s[i] = 'X';
        else if('B'==s[i])
            s[i] = 'Y';
        else if('C'==s[i])
            s[i] = 'Z';
        else
            s[i] -= 3;
    }
    printf("%s\n", s);

    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	ll n, ans = 1, inf = 1e18;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) {
		cin >> a[i];
		if(a[i] == 0) ans = 0;
	}
	if(ans != 0) {
		rep(i,n) {
			ll x = inf;
			x /= ans;
			x /= a[i];
			if(x >= 1) ans *= a[i];
			else {
				ans = -1;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4012
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    vector<int> arr;
    vector<int> label;
    char pre = '1';
    int cnt = 0, feet_cnt = 0;
    for(char c: s) {
        if (c != pre) {
            arr.push_back(cnt);
            label.push_back((c=='0')?1:0);
            cnt = 1;
            if (c == '0')
                feet_cnt += 1;
        } else {
            cnt += 1;
        }
        pre = c;
    }
    arr.push_back(cnt);
    label.push_back((pre=='0')?0:1);
    // arr.push_back(0);
    if (feet_cnt <= k) {
        cout << s.size() << endl;
    } else {
        for(int i = 0; i < arr.size(); i++) { // prefix sum
            // cout << arr[i] << endl;
            if (i > 0)
                arr[i] += arr[i-1];
        }
        // 11101010110011
        // 0311111222
        int ans = 0;
        for(int i = 1; i < arr.size(); i++) {
            if (label[i] == 0) {
                ans = max(ans, arr[i] - arr[max(0, i-(k*2))]);
            } else {
                ans = max(ans, arr[i] - arr[max(0, i-(k*2+1))]);
            }
        }cout << ans << endl;
        // 00010
        // 0311

    }

    return 0;
}




Measured memory_bytes: 1372
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

static inline void p(int x) { printf("%d\n", x); }

int main()
{

	int n, cnt = 0;
	scanf("%d", &n);

	vector<int> A(n), G;
	for (int &x: A)
		scanf("%d", &x);

	for (int i = 1, x = 1; x <= n; x = (pow(4, ++i) - 1) / 2)
		G.push_back(x);
	reverse(G.begin(), G.end());

	for (int g: G)
		for (auto i = A.begin() + g; i != A.end(); i++) {
			int v = *i;
			auto j = i - g;
			for(; j >= A.begin() && *j > v; j -= g)
				*(j + g) = *j, cnt++;
			*(j + g) = v;
		}

	p(G.size());
	for (int &x: G)
		printf("%s%d", (&x == &G[0] ? "" : " "), x);
	puts("");
	p(cnt);
	for (int x: A)
		p(x);
}


Measured memory_bytes: 6248
S = input()
line = 0
Acount = 0
ans = 0
leng = len(S)
while line<leng-1:
    if S[line] == "A":
        Acount += 1
        line += 1
    elif S[line]== "B" and S[line+1]=="C":
        ans += Acount
        line += 2
    else:
        Acount = 0
        line += 1
print(ans)

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

int main(void){
	int D;
	cin >> D;
	int c[26];
	int s[D][26];
	rep(i,26) cin >> c[i];
	rep(i,D) rep(j,26) cin >> s[i][j];

	int t[D];
	rep(i,D){
		int max_s = s[i][0];
		int jmax = 0;
		rep(j,26){
			if (s[i][j]>=max_s){
				max_s = s[i][j];
				jmax =j;
			}
		}
		t[i] = jmax+1;
	}
	rep(i,D) cout << t[i] << endl;
	


return 0;
}


Measured memory_bytes: 3664
#include<stdio.h>
#include<queue>
#include<algorithm>

#define MAX 100

int G[MAX+1][MAX+1], d[MAX+1];
int n;
std::queue<int> Q;

void bfs() {
    d[1] = 0;

    Q.push(1);
    while(!Q.empty()) {
        int cur = Q.front();Q.pop();
        for (int i = 1; i <= n; ++i) {
            if (G[cur][i] == 0) continue;
            if (d[i] != -1) continue;

            Q.push(i);
            d[i] = d[cur] + 1;
        }
    }

}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        d[i] = -1;
        for (int j = 1; j <= n; ++j) {
            G[i][j] = 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        int u,k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            int t;
            scanf("%d", &t);
            G[u][t] = 1;
        }
    }

    bfs();
    for (int i = 1; i <= n; ++i) {
        printf("%d %d\n", i, d[i]);
    }

}

Measured memory_bytes: 2796
from math import factorial
N, M, K = map(int, input().split())

MOD = 10**9+7

fact = [1] * (N*M+1)
for i in range(2, N*M+1):
    fact[i] = fact[i-1] * i % MOD

def comb(n, r):
    r = n-r if n-r < r else r
    return fact[n] * pow(fact[r], MOD-2, MOD) * pow(fact[n-r], MOD-2, MOD) % MOD

p = comb(N*M-2, K-2)
ans = 0
for i in range(N):
    for j in range(M):
        if i == 0 and j == 0:
            continue
        d = i+j
        cnt = (N-i) * (M-j)
        if i != 0 and j != 0:
            cnt *= 2
        ans += d * cnt % MOD
ans = ans * p % MOD

print(ans)


Measured memory_bytes: 10868
/* Arpit Pandey*/ 

#include <bits/stdc++.h>
#include <stdlib.h>
#include <stdint.h>
using namespace std;
 
#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define test(x) int x;cin>>x; while(x-->0)
#define memset(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;
 
void fast_io()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
#endif
}

void sol()
{
	int n;cin>>n;
	int arr[n];
	for(int &a:arr)
		cin>>a;
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		if(arr[i]>arr[i+1])
		{
			ans+=arr[i]-arr[i+1];
			arr[i+1]=arr[i];
		}
	}
	cout<<ans;

}

int32_t main()
{
	fast_io();
	//test(t)
	sol();
	//cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	//cerr << sizeof(dp)*(1e-6) << " megabytes\n";
	return 0;
}


Measured memory_bytes: 5176
import itertools, operator
N = int(input())
S = [ord(s) - 97 for s in input()]
Q = int(input())
Query = [input().split() for _ in range(Q)]
cntraw = [[0] * (N + 1) for _ in range(26)]
for i, v in enumerate(S):
    cntraw[v][i + 1] = 1


class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        res = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                res = f(res, dat[l])
                l += 1
            if r & 1:
                r -= 1
                res = f(dat[r], res)
            l >>= 1
            r >>= 1
        return res


sts = [SegmentTree(cntraw[i], f=operator.add, ti=0) for i in range(26)]
for query in Query:
    if query[0] == '1':
        i, c = query[1:]
        i = int(i)
        for st in sts:
            st.update(i, 0)
        sts[ord(c) - 97].update(i, 1)
    else:
        l, r = [int(_) for _ in query[1:]]
        r += 1
        print(sum(st.query(l, r) > 0 for st in sts))


Measured memory_bytes: 541160
#include <bits/stdc++.h>
using namespace std;
const int N = 103;
int m,n;
int cnt[N];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		int k;
		scanf("%d",&k);
		for(int i=1;i<=k;i++)
		{
			int x;
			scanf("%d",&x);
			cnt[x]++;
		}
	}
	
	int dem = 0;
	for(int i=1;i<=m;i++)
	{
		if(cnt[i] == n) dem++;
	}
	cout<<dem;
}

Measured memory_bytes: 256
def main():
    n, s = int(input()), input()
    r, g, b = s.count('R'), s.count('G'), s.count('B')
    ans = r * g * b
    v = {'R', 'G', 'B'}
    for i in range(n - 2):
        for j in range(n // 2 + 1):
            if i + j + j < n:
                if v == {s[i], s[i + j], s[i + j + j]}:
                    ans -= 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
#include<bits/stdc++.h>
#define Maxn 500010
using namespace std;
int a[Maxn], H;
void maxHeapify(int x);
int main()
{
	scanf("%d", &H);
	for(int i = 1; i <= H; i++) scanf("%d", &a[i]);
	
	for(int i = H / 2; i >= 1; i--) maxHeapify(i);
	
	for(int i = 1; i <= H; i++) printf(" %d", a[i]);
	printf("\n");
	return 0;
}
void maxHeapify(int x){
	int l = x * 2, r = x * 2 + 1, largest = x;
	if(l <= H && a[l] > a[largest]) largest = l;
	if(r <= H && a[r] > a[largest]) largest = r;
	
	if(largest != x){
		swap(a[largest], a[x]);
		maxHeapify(largest);
	}
}


Measured memory_bytes: 5040
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

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

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;

	char buf[L], *S , *T, c;

	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}

	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}

	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	char B[45], *outs=B+40, *outr=B+40;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;

		if(!a)*--outs = '0';
		else
			while(a)
				*--outs = (a % 10) + 48, a /= 10;

		if(x)
			*--outs = x;

		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

const int MOD = 1000000007;
const int INF = 1000000000;

typedef long long ll;

const int MAXN = 200010;

int main()
{
	
	int n;
	cin >> n;
	cout << (n-2)*180 << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
signed main(){
    int A,B,K;
    cin>>A>>B>>K;
    map<int,int>memo;
    REP(i,K){
        if(A+i<=B)memo[A+i]++;
        if(B+i-K+1>=A)memo[B+i-K+1]++;
    }
    for(auto it=memo.begin();it!=memo.end();it++){
        if(it->second!=0){
            cout<<it->first<<endl;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int n,t;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	ll x,k,d;
	ll ans=0;
	cin>>x>>k>>d;
	x=abs(x);
	ll val=abs(x/d);
	if(val<=k){
		k-=val;
		x=x-val*d;
		if(k&1){
			ans=min(abs(x+d),abs(x-d));
		}
		else if(k>0){
			ans=min(abs(x),abs(abs(x)-abs(2*d)));
		} 
		else ans=x;
	}
	else{
		x=x-k*d;
		ans=x;
	}
	cout<<ans;
 
 
 
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>

int LinearSearch(int A[],int n,int key){
	int i;
	for(i=0;i<n;i++){
		if(A[i]==key){
			return i;
		}
	}
	return -1;
}

int main(void){
	int i,n,q,key,sum=0;
	int A[100000];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&key);
		if(LinearSearch(A,n,key)!=-1){
			sum=sum+1;
		}
	}
	
	printf("%d\n",sum);

	return 0;
}


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

int main(){
  int n,k;
  cin >> n >> k;
  if((n+1)/2 >= k) puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	cout<<"case #" << x << ": " << endl
#define DEBUG 0
const ll inf = (ll)1e9;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };

int main() {
	ll x, y;	cin >> x >> y;
	ll cur = x;
	int cnt = 1;
	while (2*cur <= y) {
		cur *= 2;
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256