akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

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

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

int main(){
    char s[100001];

    scanf("%s", s);

    int flag = 0;
    char ans = 0;
    for(int i = 0; i < 26; ++i){
        for(int j = 0; j < strlen(s); ++j){
            if(s[j] == 'a' + i){
                flag = 0;
                break;
            }else{
                flag = 1;
            }
        }
        if(flag == 1){
            ans = 'a' + i;
            break;
        }
    }

    if(ans == 0) puts("None");
    else printf("%c\n", ans);

    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int n,m,q;
int state[100010];

int last[100010];

int number[100010];

int a[100010];

int main(void){
	cin >> n >> m >> q;
	rep(i,q) cin >> a[i],a[i]--;
	
	rep(i,m) last[i]=-i-1;
	rep(i,q) last[a[i]]=i;

	using type=tuple<int,int>;
	vector<type> ary;
	rep(i,m) ary.push_back(type(last[i],i));
	
	sort(_all(ary));
	
	int offset=1;
	while(offset<m and get<1>(ary[offset-1]) > get<1>(ary[offset])) offset++;

	fill(number,number+m,-1);
	const int len=m-offset;
	rep(i,len) number[get<1>(ary[i+offset])]=i;



	state[0]=n;

	rep(i,q){
		int idx=number[a[i]];
		if(idx==-1) continue;
		if(state[idx]>0){
			state[idx]--;
			state[idx+1]++;
		}
	}

	if(state[len]==n)
		puts("Yes");
	else
		puts("No");
	return 0;
}

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

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

    if (a > b) {
        for (int i = 0; i < a; i++) {
            cout << b;
        }
        cout << endl;
    } else {
        for (int i = 0; i < b; i++) {
            cout << a;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int N;
  	cin >> N;
    int array[N];
    for(int i = 0; i < N; i++){ 
      	cin >> array[i];
        }
  	int height = array[0];
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(height <= array[i]){
            height = array[i];
            ans++;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
S =int(input())
a = S // 100
b = S % 100
if 0 < a < 13 :
  if 0 < b < 13:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 0 < b < 13:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define input for(int i = 0; i < n; ++i) cin >> a[i]
#define output for(int i = 0; i < n; ++i) cout << a[i] << " "
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pll pair<long long ,long long >
#define ppll pair < pll , pll >
int main(){
    SPEED;
    int n, k;
    cin >> n >> k;
    int a[n];
    input;
    int dp[n];         //    40 10 20 70 80 10 20 70 80 60     // Ans : 
    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);       //   10 30 40 50 20  6 3
    for(int i = 2; i < n; i++){
        dp[i] = INT_MAX;
    }
    for(int i = 2; i < n; ++i){
        int temp = INT_MAX;
        int range = 0;
        if(i + 1 <= k) range = 0;
        else range = i + 1 - k - 1;
        for(int j = i - 1; j >= range; --j){
            temp = min(temp, dp[j] + abs(a[i] - a[j]));
        }
        dp[i] = temp;
    }
    // for(int i = 0; i < n; ++i){
    //     cout << dp[i] << " ";
    // }
    cout << dp[n - 1] ;
}

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

int main(){

int n,l;
cin >> n >> l;
vector<string>s(n);
for (int i = 0; i < n; i++){
  cin >> s[i];
}
sort(s.begin(),s.end());
for (int i = 0; i < n; i++){
  cout << s[i];
}
cout << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repeq(i,a,b) for(int i=a;i<=(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    debug(n);
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    reverse(all(a));
    ll lo=2, hi=2;
    bool bad=false;
    rep(i,0,n) {
        ll hh = (hi/a[i])*a[i];
        if(hh<lo) {
            bad=true;
            break;
        }
        hi = hh+a[i]-1;
        lo = ((lo-1)/a[i]+1)*a[i];
    }
    if(bad) cout<<-1<<endl;
    else cout<<lo<<" "<<hi<<endl;
    
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX_N 100000
#define MAX_M 100000
 
typedef struct EDGE {
    int to;
    struct EDGE *next;
} edge;
 
int buff_size;
edge buff[MAX_M + MAX_M];
edge *adj[MAX_N];
 
void init(int n, int m) {
    int i;
    for(i = 0; i < n; ++i) {
        adj[i] = NULL;
    }
    for(i = 0; i < m; ++i) {
        buff[i].next = NULL;
    }
    buff_size = 0;
}
 
edge *new_edge() {
    return buff + buff_size++;
}
 
void add_edge(int u, int v) {
    edge *e = new_edge();
    e->to = v;
    e->next = adj[u];
    adj[u] = e;
}
 
int head, tail;
int queue[MAX_N];
 
void enqueue(int data) {
    queue[tail++] = data;
}
 
int dequeue() {
    return queue[head++];
}
 
int empty() {
    return head == tail;
}
 
void clear() {
    head = tail = 0;
}
 
int next_label;
int label[MAX_N];
 
void bfs(int v) {
    edge *e;
 
    clear();
    enqueue(v);
 
    label[v] = next_label;
    while(!empty()) {
        const int v = dequeue();
        for(e = adj[v]; e != NULL; e = e->next) {
            if(label[e->to] == -1) {
                label[e->to] = next_label;
                enqueue(e->to);
            }
        }
    }
    ++next_label;
}
 
int main() {
    int n, m, q;
    int u, v;
    int s, t;
    int i;
 
    scanf("%d %d", &n, &m);
    init(n, m);
 
    for(i = 0; i < m; ++i) {
        scanf("%d %d", &u, &v);
        add_edge(u, v);
        add_edge(v, u);
    }
 
    memset(label, -1, sizeof(label));
    for(i = 0; i < n; ++i) {
        if(label[i] == -1) bfs(i);
    }
 
    scanf("%d", &q);
    while(q--) {
        scanf("%d %d", &s, &t);
        puts(label[s] == label[t] ? "yes" : "no");
    }
 
    return EXIT_SUCCESS;
}

Measured memory_bytes: 5280
fun main(args: Array<String>) {
    val (n, m, x) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }
    var arr = IntArray(n + 1) { 0 }
    for (value in a) {
        arr[value] = 1
    }

    var right = 0
    for (i in x+1 until n) {
        if (arr[i] == 1) right++
    }

    var left = 0
    for (j in x-1 downTo 1) {
        if (arr[j] == 1) left++
    }

    println(if (right > left) left else right)
}

Measured memory_bytes: 36028
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e3;
const int INF=1e9;
int main(){
	int H,W,N;cin>>H>>W>>N;
	int A[N];int c[H*W];int d=0;
	rep(i,0,N){
		cin>>A[i];
		rep(j,0,A[i]) c[d+j]=i+1;
		d+=A[i];
	}
	for(int i=1;i<H;i+=2){
		reverse(c+W*i,c+W*(i+1));
	}
	rep(i,0,H){
		rep(j,0,W){
			cout<<(j ? " ":"")<<c[W*i+j];
		}cout<<endl;
	}
}

Measured memory_bytes: 384
#include<map>
#include<cstdio>
#include<algorithm>
#define N 100005
inline int read(){
    int x=0;char ch=getchar();
    for(;ch<48||ch>57;ch=getchar());
    for(;ch>47&&ch<58;ch=getchar())
    x=(x<<1)+(x<<3)+(ch^48);return x;
}
using namespace std;
int s[N],t[N],f[N];
map<int,int>vis,num;
int Fin(int x){return f[x]==x?x:f[x]=Fin(f[x]);}
void merge(int x,int y){
    x=Fin(x),y=Fin(y);
    if(x^y)f[x]=y;
}
int main(){
    int n=read(),sum=0,ans=0,tot=0;
    for(int i=1;i<=n;++i)++vis[s[i]=read()];
    for(int i=1;i<=n;++i)--vis[t[i]=read()];
    for(int i=1;i<=n;++i)sum^=s[i];++vis[sum];
    for(auto v:vis)if(v.second<0)return puts("-1"),0;
    s[n+1]=sum;sum=0;
    for(int i=1;i<=n;++i)sum^=t[i];t[++n]=sum;
    for(int i=1;i<n;++i)
        if(s[i]^t[i]){
            ++ans;
            if(!num[s[i]])num[s[i]]=++tot;
            if(!num[t[i]])num[t[i]]=++tot;
        }
    if(!num[s[n]])num[s[n]]=++tot;
    if(!num[t[n]])num[t[n]]=++tot;
    if(!ans)return puts("0"),0;
    for(int i=1;i<=tot;++i)f[i]=i;
    for(int i=1;i<=n;++i)
        if(s[i]^t[i])
            merge(num[s[i]],num[t[i]]);
    for(int i=1;i<=tot;++i)
        if(f[i]==i)++ans;
    printf("%d\n",ans-1);
    return 0;
}

Measured memory_bytes: 12288
#include <iostream>
using namespace std;
int main(){
    // Your code here!
    int D = 0;
    cin>>D;
    
    switch(D){
        case 25:
        cout<<"Christmas";
        break;
        
        case 24:
        cout<<"Christmas Eve";
        break;
        
        case 23:
        cout<<"Christmas Eve Eve";
        break;
        
        case 22:
        cout<<"Christmas Eve Eve Eve";
        break;
        
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
using namespace std;
const constexpr int INF = 1e9;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
const int BITSIZE = 100010;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.second < y.second;
	}
};
struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};
//1-indexed
int bit[100010];

int bit_query(int i) {
	int res = 0;
	for (; i >= 1; i -= i & -i) res = max(res, bit[i]);
	return res;
}

void bit_set(int x, int v) {
	for (; x <= BITSIZE; x += x & -x) {
		bit[x] = max(bit[x], v);
	}
}
ll combination(ll n, ll r)
{
    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (combination(n - 1, r - 1)%MOD + combination(n - 1, r)%MOD);
}
ll pow_mod(ll a, ll b){
    ll sum =1;
    while(b>0){
        if(b&1){
            sum *= a%MOD;
        }
        a = a* a%MOD;
        b >>= 1;
    }
    return sum;
}
int a[110];
int b[110];
int main() {
    int N; cin >> N;
    REP(i, N) cin >> a[i];
    REP(i, N) cin >> b[i];
    reverse(b, b+N);
    
    //1-indexed
    int aa[110]={0};
    aa[0] = a[0];
    int bb[110]={0};
    bb[0] = b[0];
    for(int i=1; i<N; ++i){
        aa[i] =a[i]+aa[i-1];
    }
    for(int i=1; i<N; ++i){
        bb[i] =b[i]+bb[i-1];
    }
    reverse(bb, bb+N);
    
    
    int ans=0;
    for(int i=0; i<N; ++i){
        ans = max(ans, aa[i]+bb[i]);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

struct ID{
    ll no;
    ll pref;
    ll year;
    string id;
};

bool compare(ID a, ID b){
    if(a.pref == b.pref)return a.year < b.year;
    return a.pref < b.pref;
}
bool compByno(ID a, ID b){
    return a.no < b.no;
}


int main(){
    ll n, m;
    cin >> n >> m;
    vector<ID> vec(m);
    rep(i, m){
        ll p, y;
        cin >> p >> y;
        vec[i].no = i;
        vec[i].pref = p;
        vec[i].year = y;
    }

    sort(ALL(vec), compare);
    ll count;
    rep(i, m){
        string strp = to_string(vec[i].pref);
        while(strp.size() != 6){
            strp = "0" + strp;
        }
        if(i == 0 || vec[i].pref != vec[i-1].pref)count = 1;
        else count++;
        string stry = to_string(count);
        while(stry.size() != 6){
            stry = "0" + stry;
        }
        vec[i].id = strp + stry;
    }
    sort(ALL(vec), compByno);
    rep(i, m)cout << vec[i].id << endl;
    //rep(i, m)cout << "pref" << vec[i].pref << "year" << vec[i].year << endl;


}

Measured memory_bytes: 9344
array = gets.chomp.split('')
hash = array.group_by(&:itself).map{ |key, value| [key, value.count] }.to_h

a = hash['a'] || 0
b = hash['b'] || 0
c = hash['c'] || 0

def s(x, y)
  return true if (x-y).abs <= 1
  false
end

if s(a,b) && s(b,c) && s(c,a)
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 8000
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int32_t main(){
    int n,i;
    cin>>n;
    if(n<=12){
        cout<<n;
        return 0;
    }
    priority_queue<int,vector<int>,greater<int>> p;
    for(i=1;i<=9;i++){
        p.push(i);
    }
    int count=0;
    int ans;
    while(true){
        int num=p.top();
        p.pop();
        count++;
        if(count==n){
            ans=num;
            break;
        }
        int d=num%10;
        p.push((num*10)+d);
        if(d!=0){
            p.push((num*10)+d-1);
        }
        if(d!=9){
            p.push((num*10)+d+1);
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2420
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int v[] = {0,2,5,5,4,5,6,3,7,6};
    int n,m;
    cin >> n >> m;
    vi a(m);
    rep(i,m)cin >> a[i];
    vi dp(n+10,-1);//dp[i]:=i本使ったときの最大桁数
    dp[0] = 0;
    rep(i,n)rep(j,m){
        dp[i + v[a[j]]] = max(dp[i + v[a[j]]], dp[i] + 1);
    }
    sort(all(a));
    //rep(i,n+1)cout << " " << dp[i];cout << endl;
    while(n){
        for(int i = m-1; i >= 0; i--){
            if(n >= v[a[i]] && dp[n - v[a[i]]] == dp[n] - 1){
                cout << a[i];
                n -= v[a[i]];
                break;
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 384
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        long sum = 0l;
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
            sum += as[i];
        }

        long ans = Long.MAX_VALUE;
        long x = 0;
        for (int i = 0; i < n - 1; i++) {
            x += as[i];
            ans = Math.min(ans, Math.abs(x - (sum - x)));
        }
        System.out.println(ans);
    }
}


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<ll>dp(1<<n,INF);
  dp[0]=0;
  rep(i,0,m){
    ll a,b;cin>>a>>b;
    bitset<30>x=0;
    rep(j,0,b){
      ll y;cin>>y;
      x[y-1]=1;
    }
    ll tmp=x.to_ullong();
    for(ll j=tmp;j>0;j=(j-1)&tmp)chmin(dp[j],a);
  }
  //debug(dp,1<<n);
  rep(i,1,1<<n){
    bitset<30>x=i;
    vector<ll>idx;
    rep(j,0,n){
      if(x[j])idx.PB(j);
    }
    ll k=idx.size();
    ll minbuf=INF;
    rep(j,0,(1<<k)){
      bitset<30>y=j,z=0;
      rep(o,0,k)if(y[o])z[idx[o]]=1;
      ll tmp=z.to_ullong();
      //cout<<i spa tmp spa i-tmp<<endl;
      chmin(minbuf,dp[tmp]+dp[i-tmp]);
    }
    chmin(dp[i],minbuf);
  }
  //debug(dp,1<<n);
  ans(dp[(1<<n)-1]==INF,-1,dp[(1<<n)-1]);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        bool ok = true;

        if (s.Substring(0, 1) != "A")
        {
            ok = false;
        }

        if (!s.Substring(2, s.Length - 3).Contains("C"))
        {
            ok = false;
        }

        int countA = 0;
        int countC = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'A')
            {
                countA++;
                continue;
            }
            if (s[i] == 'C')
            {
                countC++;
                continue;
            }
            if (s[i] < 'a')
            {
                ok = false;
            }
        }
        if (!(countA == 1 && countC == 1))
        {
            ok = false;
        }

        string answer = ok ? "AC" : "WA";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
/*
AizuOnline A2026
Title Divisor is the Conqueror
13/02/14 TE
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
#include <setjmp.h>
int N;
int card[52];
int flag[52];
jmp_buf env;
//
int calc_ba()
{
  int sum,i;
  sum=0;
  for(i=0;i<N;i++)
    sum += (flag[i]?0:card[i]); 
  return(sum);
}

void try(int n)
{
  int sum,i,prev;
  if(n==0)
    longjmp(env,1);
  sum=calc_ba();
  prev=0;
  for(i=0;i<N;i++)
    {
      if(flag[i]==0 && ((sum-card[i]) % card[i] ==0))
	{ if(prev == card[i])
	    continue;
	  flag[i] = n;
	  try(n-1);
	  flag[i]=0;
	  prev = card[i];
	}
    }
}
print()
{
  
  int i,j;
  //printf("print\n");
  for(i=0;i<=N;i++)
    for(j=0;j<N;j++)
      {
	if(flag[j]==i)
	  printf("%d",card[j]);
	if(flag[j]==i && i)
	  printf(" ");
      }
  printf("\n");
}
int comp(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

main()
{
  int i;

  while(EOF!=scanf("%d",&N) && N)
    {
      for(i=0;i<N;i++)
	{
	  scanf("%d ",&(card[i]));
	  flag[i]=0;
	}
      qsort(card,N,sizeof(int),comp);
      if(setjmp(env)==0)
	{
	  try(N);
	}
      else
	{
	  print();
	  continue;
	}
      printf("No\n");    
   }

return(0);
}

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

using namespace std;

typedef long long ll;

void solve() {
    ll n;
    cin >> n;

    vector<ll> a(n);
    for(auto &i : a)
        cin >> i;

    vector<ll> b(n);
    for (int i = 1; i <= n; i++) {
        b[i - 1] = a[i - 1] - i;
    }
    sort(b.begin(), b.end());
    ll med = b[n / 2];

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += abs(b[i] - med);
    }
    cout << ans;
}

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

Measured memory_bytes: 3328
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a), i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main()
{
	ll N, K;
	cin >> N >> K;
	if(N<=K){
		cout << 0 << endl;
		return 0;
	}
	vector<ll> H;
	REP(i, N){
		ll h;
		cin >> h;
		H.PB(h);
	}
	sort(ALL(H));
	cout << (ll){accumulate(H.begin(), H.end()-K, 0LL)} << endl;
}


Measured memory_bytes: 2928
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<utility>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>k(n,0);
	vector<int>vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
		while (vec.at(i) % 2 == 0) {
			vec.at(i) /= 2;
			k.at(i)++;
		}
	}
	sort(k.begin(), k.end());
	cout << k.at(0) << endl;
	

}

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            int xor = 1^2^3^4^5;
            st = new StringTokenizer(br.readLine());
            xor ^= Integer.parseInt(st.nextToken());
            xor ^= Integer.parseInt(st.nextToken());
            xor ^= Integer.parseInt(st.nextToken());
            xor ^= Integer.parseInt(st.nextToken());
            xor ^= Integer.parseInt(st.nextToken());
            pw.print(xor);

        }
        finally {
            pw.flush();
            pw.close();
        }
    }
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

template< class T >
struct BinaryIndexedTree
{
  vector< T > data;

  BinaryIndexedTree(int sz)
  {
    data.assign(++sz, 0);
  }

  T sum(int k)
  {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x)
  {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};



struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    i64 n, q;
    string s;
    cin >> n >> s >> q;
    vector<BinaryIndexedTree<i64>> bits(26, n);
    rep(i, n) bits[s[i] - 'a'].add(i, 1);
    rep(xxx, q){
        i64 ty;
        cin >> ty;
        if(ty == 1){
            i64 iq;
            char cq;
            cin >> iq >> cq;
            --iq;
            if(s[iq] != cq){
                bits[s[iq] - 'a'].add(iq, -1);
                bits[cq - 'a'].add(iq, 1);
                s[iq] = cq;
            }
        }else{
            i64 l, r;
            cin >> l >> r;
            i64 cnt = 0;
            if(l == 1) rep(i, 26) cnt += bits[i].sum(r - 1) > 0;
            else rep(i, 26) cnt += bits[i].sum(r - 1) - bits[i].sum(l - 2) > 0;
            cout << cnt << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 106396
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  L=LI()

  ans=0
  for i in range(N):
    for j in range(i+1,N):
      for k in range(j+1,N):
        a,b,c=sorted([L[i],L[j],L[k]])
        if a!=b and a!=c and b!=c and a+b>c:
          ans+=1

  return ans

# main()
print(main())


Measured memory_bytes: 10728
#include <iostream>
#include <string>
using namespace std;
int N;
int x = 0;
int max_ = 0;
string S;

void solve()
{

    for(int i=0;i<N;i++)
    {
        if(S[i]=='I')
        {
            x++;
        }
        if(S[i]=='D')
        {
            x--;
        }
        if(max_<x)
        {
            max_ = x;
        }
    }
    cout << max_ << endl;
}
int main()
{
    cin >> N;
    cin >> S;
    solve();
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i

s = gets.split('')

e_sum = []
num = 0
n.times do |i|
  num += 1 if s[i] == 'E'
  e_sum << num
end

counts = []
n.times do |i|
  if i == 0
    counts << e_sum[n-1] - e_sum[i]
  elsif i == n-1
    counts << (n-1-(e_sum[n-2]))
  else
    counts << (i-e_sum[i-1] + (e_sum[n-1] - e_sum[i]))
  end
end
puts counts.min



Measured memory_bytes: 33500
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>


using namespace std;
int main() {
    long long N;
    cin >> N;
    vector<pair<long long, long long>> val(N);
    for(int i = 0; i < N; i++){
        long long A,B;
        cin >> A >> B;
        val[i].first = A + B;
        val[i].second = B;
    }
    sort(val.begin(),val.end());
    int count = 0;
    if(N % 2 == 0){
        count = N / 2;
    }else{
        count = (N - 1)/2 + 1;
    }
    long long result = 0;
    for(int i = 0; i <N; i++){
        if(i % 2 == 0){
            result += val[N - i - 1].first;
        }else{

        }
    }
    for(int i =0; i < N; i++){
        result -= val[i].second;
    }
    cout << result << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int v[100000];
int A[100000];
int B[100000];

int main(){
  int n;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> v[i];
    if(i % 2 == 0)
      A[v[i]-1]++;
    else
      B[v[i]-1]++;
  }
  int M_odd = 0;  int m_odd = 0;
  int i_odd = -1;
  int M_even = 0;  int m_even = 0;
  int i_even = -1;
  for(int i=0; i<100000; i++) {
    if(A[i] > M_even) {
      m_even = M_even;
      M_even = A[i];
      i_even = i;
    } else if(A[i] > m_even) {
      m_even = A[i];
    }
    if(B[i] > M_odd) {
      m_odd = M_odd;
      M_odd = B[i];
      i_odd = i;
    } else if(B[i] > m_odd) {
      m_odd = B[i];
    }
  }
  if(i_even == i_odd)
    cout << min(n - M_even - m_odd, n - M_odd - m_even) << endl;
  else
    cout << n - M_even - M_odd << endl;
  return 0;
}


Measured memory_bytes: 1408
s = input()

while(len(s)>0):
    flag = False
    if s.endswith("dream"):
        s = s[:-5]
        flag = True
    if s.endswith("dreamer"):
        s = s[:-7]
        flag = True
    if s.endswith("erase"):
        s = s[:-5]
        flag = True
    if s.endswith("eraser"):
        s = s[:-6]    
        flag = True
    if not(flag):
        break

if flag:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
import sys
import numpy as np

inf = float('inf')

h, n, *ab = map(int, sys.stdin.read().split())
a, b = np.array(ab, dtype=np.int64).reshape(n, 2).T

def main():
    dp = np.zeros(h+1, dtype=np.int64)
    for i in range(1, h+1):
        dp[i] = np.amin(dp[np.maximum(i-a, 0)] + b)
        
    return dp[h]

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 12496
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Sumo
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  char s[32];
  scanf("%s", s);

  int c = 0, k = 0;
  for (; s[k]; k++)
    if (s[k] == 'o') c++;

  if (15 - k + c >= 8) puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 256
w,h=map(int,input().split())
while w!=0 or h!=0:
    maps=[]
    flag=False
    ans=0
    for i in range(h):
        k=list(input())
        maps.append(k)
    for i in range(h):
        if flag:
            break
        for j in range(w):
            if maps[i][j]=='@':
                maps[i][j]='#'
                pos_x=i
                pos_y=j
                flag=True
                break
    def check(x,y):
        global maps
        if 0<=x<h and 0<=y<w:
            pass
        else:
            return False
        if maps[x][y]=='#':
            return False
        else:
            return True
    def bfs(x,y):
        global ans
        global maps
        for i in [[0,1],[0,-1],[1,0],[-1,0]]:
            p=i[0]
            q=i[1]
            if check(x+p,y+q):
                ans+=1
                maps[x+p][y+q]='#'
                bfs(x+p,y+q)
    bfs(pos_x,pos_y)
    print(ans+1)
    w,h=map(int,input().split())



Measured memory_bytes: 5720
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(std::string C){
  std::cout << (char)(C[0]+1) << std::endl;
}

int main(){
  std::string C;
  std::cin >> C;
  solve(C);
  return 0;
}



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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s;cin >> s;
    int m = stoi(s.substr(5, 2));
    int d = stoi(s.substr(8, 2));
    string ans = "TBD";
    if(m < 4 || (m == 4 && d <= 30)) ans = "Heisei";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <stdlib.h>
#define N 8
#define SET 1
#define FREE 1
#define NOTFREE -1
void setQueen(int);
void printField();
int n;
int field[N][N];
int row[N], col[N], dpos[2 * N - 1], dneg[2 * N -1];
int main(){
  int i,j;
  int r,c;
  scanf("%d",&n);
 
 
  
  for(i=0;i<N;i++){
   row[i] = FREE;
   col[i] = FREE;
  }
  for(i=0; i < 2 * N - 1; i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
  
  for(i=0;i<n;i++){
    scanf("%d %d",&r,&c);
    field[r][c] = SET;
  }

  setQueen(0);
    
  
  return 0;
}

void setQueen(int i){
  int j;
  if(i == N){
    printField();
    return;
  }

  
  for(j=0;j<N;j++){
    if( col[j] == NOTFREE || dpos[i+j] == NOTFREE || dneg[i - j + N - 1] == NOTFREE){
      continue;
    }
    row[i] = j;
    col[j] = NOTFREE;
    dpos[i+j] = NOTFREE;
    dneg[i - j + N -1] = NOTFREE;

    setQueen(i+1);
    row[i] = FREE;
    col[j] = FREE;
    dpos[i+j] = FREE;
    dneg[i - j + N -1] = FREE;
  } 
}

void printField(){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(field[i][j] == 1){
	if(row[i] != j) return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
     if(row[i] == j ) printf("Q");
     else printf(".");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2112
/** Author: Dwai
 *  Omae wa mou shindeiru!
**/

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define fr(i,a,b) for (i = a; i <= b; i++)
#define frr(i,a,b) for (i = a; i >= b; i--)
#define rep(i,n) for (i = 0 ; i < n; i++)
#define repr(i,n) for (i = n - 1; i >= 0; i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define flushinput   cin.ignore(numeric_limits<streamsize>::max(),'\n');

void debug_out() { cerr << endl; }

void clock_out(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}

void fileio(){
  freopen("/home/dwai/Desktop/cp/input.txt","r", stdin);
  freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
  freopen("/home/dwai/Desktop/cp/debug.txt", "w", stderr);
}

void ofileio(){
  freopen("input.txt","r", stdin);
  freopen("output.txt", "w", stdout); 
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define fio() fileio()
#define ofio() fileio()
#define clock() clock_out()
#else
#define debug(...) 42
#define fio() 42
#define ofio() ofileio()
#define clock() 42
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef map<ll,ll> mll;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;



void solve()
{
	ll n,m;
	cin>>n>>m;
	ll a[n],i;
	ll lcm=1;
	rep(i,n)
	{
		cin>>a[i];
		a[i]/=2;
		if(i==0)
			lcm=a[i];
		else
			lcm=(a[i]*lcm)/__gcd(a[i],lcm);
	}

	rep(i,n)
	{
		if((lcm/a[i])%2==0)
		{
			cout<<0;
			return;
		}
	}
	ll x=m/lcm;
	if(x&1)
		cout<<(x+1)/2;
	else cout<<x/2;
}

int main()
{
//	fio();
	fast
	ll t=1;
	//cin>>t;

	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 1024
type BIT
	n::Int
	bit::Array{Int}
	BIT(n)=new(n,zeros(Int,n))
end
function sum(bit::BIT,i::Int)
	ans=0
	while i>0
		ans+=bit.bit[i]
		i-=i&-i
	end
	ans
end
function add(bit::BIT,i::Int,a::Int)
	while i<=bit.n
		bit.bit[i]+=a
		i+=i&-i
	end
end
function main()
	N=parse(Int,readline())
	S=Char[]
	for c=chomp(readline())
		push!(S,c)
	end
	bits=[BIT(N) for _=1:26]
	for i=1:N
		x=Int(S[i])-96
		add(bits[x],i,1)
	end
	Q=parse(Int,readline())
	for _=1:Q
		qi,a,b=split(readline())
		if qi=="1"
			a=parse(Int,a)
			x=Int(S[a])-96
			add(bits[x],a,-1)
			S[a]=b[1]
			x=Int(S[a])-96
			add(bits[x],a,1)
		else
			a=parse(Int,a)
			b=parse(Int,b)
			cnt=0
			for i=1:26
				if sum(bits[i],b)>sum(bits[i],a-1)
					cnt+=1
				end
			end
			println(cnt)
		end
	end
end
main()


Measured memory_bytes: 230792
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
    using namespace std;
    int main(){
      string S;
     cin >> S;
      
      vector<int> A(S.size()+1);
      vector<int> B(S.size()+1);
      for(int i=0;i< S.size();i++){
        A[i]=S[S.size()-i -1]-'0';
      }
      int count=0;
      for(int i=0;i< S.size();i++){
        if(A[i] < 5 || ((A[i] == 5) && (A[i+1] < 5)) ){
          count+=A[i];
        }else{
          count+=10-A[i];
          B[i]=10-A[i];
          A[i] = 0;
          A[i+1]+=1;
        }
      }
      if(A[S.size()]==1)
        count++;
      
      /*cout << 0 << S << endl;
      for(int i=0;i< S.size()+1;i++){
        cout << A[S.size()-i];
      }
      cout <<endl;
      for(int i=0;i< S.size()+1;i++){
        cout << B[S.size()-i];
      }*/
      cout << count;
      return 0;
    }

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

using namespace std;

typedef long long ll;

//#include<ext/pb_ds/assoc_container.hpp>
//#nclude<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define pii pair<int,ll>
#define pi pair<int,int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define eps 10E-10
#define mod 1000000007
#define pai acos(-1)
#define mx 1000000000
#define N 2005

int ar[N];

int main ()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    int t,l,sum=0,r,n,m,id=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>ar[i],sum+=ar[i];
    sort(ar+1,ar+1+n);
    l=(sum-1)/(4*m)+1;
    for(int i=n;i>0;i--){
        if(ar[i]>=l) id++;
    }
    if(id>=m) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std ;

int x , y ;

void input ( ) {
    cin >> x >> y ;
}

void solve ( ) {
    int ans = 0 ;
    int z = 1 ;
    while ( z < y ) {
        z += ( x - 1 ) , ++ ans ;
    }
    cout << ans << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,r,i,j,k,l,x;
	while(scanf("%d",&n),n)
	{
		for(r=i=0;4*i*i<=n;++i)for(j=i;i*i+3*j*j<=n;++j)for(k=j;i*i+j*j+2*k*k<=n;++k)for(l=k;x=i*i+j*j+k*k+l*l,x<=n;++l)if(x==n)++r;
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 760
#include<stdio.h>

int main(){
    int N;
    scanf("%d",&N);
    
    int A[N];
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    
    int turn[N];
    int i=0;
    
    for(int i=0;i<N;i++){
        turn[A[i]-1] = i+1;
    }
    
    
    for(int i=0;i<N;i++){
        printf("%d ",turn[i]);
    }
    
    printf("\n");
    
    return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;


int main(){
  string L; cin >> L; int N = L.size();
  
  vector<ll> dp0(N); vector<ll> dp1(N);
  dp0[0] = 2; dp1[0] = 1; 
  
  for(int i = 1; i < N; i++){
    if( L[i] =='0'){
      dp0[i] = dp0[i-1]; dp1[i] = dp1[i-1] * 3;}
    else{
      dp0[i] = dp0[i-1] * 2 ; dp1[i] = dp1[i-1] * 3 + dp0[i-1];}
     dp0[i] %= MOD; dp1[i] %= MOD;}
  
  cout << (dp0[N-1] + dp1[N-1]) % MOD << endl; return 0;}
       

Measured memory_bytes: 2048
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int a;cin>>a;
	if(a==3 || a==5 || a==7) cout<<"YES"<<endl;else cout<<"NO"<<endl;
}


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

using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;

int main() {
	int h,w;
	char a[101][101];
	cin>>h>>w;
	for(int i=0;i<w+2;++i)cout<<"#";
	cout<<endl;
	for(int i=0;i<h;++i){
		cout<<"#";
		for(int j=0;j<w;++j){
			cin>>a[i][j];
			cout<<a[i][j];
		}
		cout<<"#"<<endl;
	}
	for(int i=0;i<w+2;++i)cout<<"#";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cmath>
using namespace std;
int main(void)
{
	int v,r,x[101],y[101],s[1000],t[1000];
	int mx,mn,mflg[101],len[101],par[101],mni,ii;
	int x0,y0,x1,y1,x2,y2,mi,i,j,k,p1,p2,cnt;
	double yog,myog,sum,dis[1000];
	scanf("%d %d",&v,&r);
	for(i=1;i<=v;i++)	{
		scanf("%d %d",&x[i],&y[i]);	mflg[i]=0;	len[i]=1;	par[i]=i;
	}
	for(i=0;i<r;i++)	scanf("%d %d",&s[i],&t[i]);
	mn=2000;
	for(i=1;i<=v;i++)	{
		if(mn>x[i])	{
			mn=x[i];
			mni=i;
		}
	}
	mflg[mni]=1;
//	printf("m=%d\n",mni);
	x0=x[mni];	y0=y[mni]+1;
	x1=x[mni];	y1=y[mni];	ii=mni;
	sum=0.0;	cnt=1;
	len[ii]=2;
	while(1)	{
		myog=2.0;
		for(i=1;i<=v;i++)	{
			if(i!=ii)	{
				x2=x[i];	y2=y[i];
				yog=((double)(x0-x1)*(x2-x1)+(double)(y0-y1)*(y2-y1))/
				(sqrt((double)(x0-x1)*(x0-x1)+(double)(y0-y1)*(y0-y1))*
				 sqrt((double)(x2-x1)*(x2-x1)+(double)(y2-y1)*(y2-y1)));
//				 printf("   %lf %d \n",yog,i);
				if(myog>yog)	{
					myog=yog;
					mi=i;
				}
			}
		}
		if(mi==mni)	break;
		mflg[mi]=1;	par[mi]=mni;		
//		printf("m=%d\n",mi);
		p1=ii;	p2=mi;
		while(p1!=par[p1])	p1=par[p1];
		while(p2!=par[p2])	p2=par[p2];
		if(p1!=p2)	{
			if(len[p1]>len[p2])	par[p2]=p1;
			else if(len[p1]<len[p2])	par[p1]=p2;
			else {
				par[p2]=p1;	len[p1]++;
			}
		}
		x0=x1;	y0=y1;	x1=x[mi];	y1=y[mi];
		ii=mi;
		sum+=sqrt((double)(x0-x1)*(x0-x1)+(double)(y0-y1)*(y0-y1));
//		printf("  %lf\n",sum);
		cnt++;
	}	
//	printf("cnt=%d\n",cnt);
	sum+=sqrt((double)(x[mi]-x1)*(x[mi]-x1)+(double)(y[mi]-y1)*(y[mi]-y1));	
//	printf(" %lf\n",sum);
	for(i=0;i<r;i++)	{
		dis[i]=sqrt((double)(x[s[i]]-x[t[i]])*(x[s[i]]-x[t[i]])+(y[s[i]]-y[t[i]])*(y[s[i]]-y[t[i]]));
//		printf("  %lf\n",dis[i]);
	}
	for(i=0;i<r-1;i++)	{
		for(j=i+1;j<r;j++)	{
			if(dis[i]>dis[j])	{
				swap(dis[i],dis[j]);
				swap(s[i],s[j]);
				swap(t[i],t[j]);
			}
		}
	}
	for(i=0;i<r;i++)	{
		if(cnt==v)	break;
		p1=s[i];	p2=t[i];
		while(p1!=par[p1])	p1=par[p1];
		while(p2!=par[p2])	p2=par[p2];
		if(p1!=p2)	{
			if(len[p1]>len[p2])	par[p2]=p1;
			else if(len[p1]<len[p2])	par[p1]=p2;
			else {
				par[p2]=p1;	len[p1]++;
			}
			sum+=dis[i];
			cnt++;
		}	
	}
	printf("%lf\n",sum);
	return 0;
}
	


Measured memory_bytes: 2712