akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>


int main()
{
    int n;
    std::cin >> n;
    std::vector<int> a(n),p(n),q(n);
    for(int i = 1; i <= n; i++)a[i - 1] = i;
    for(int i = 0; i < n; i++)std::cin >> p[i];
    for(int i = 0; i < n; i++)std::cin >> q[i];
    int x,y;
    int cnt = 1;
    do{
        if(a == p)x = cnt;
        if(a == q)y = cnt;
        cnt++;
    }while(std::next_permutation(a.begin(), a.end()));
    std::cout << std::abs(x - y) << std::endl;
}

Measured memory_bytes: 256
import heapq
n, k = map(int, input().split())
r = min(n, k)
v = list(map(int, input().split()))
ans = 0
for i in range(1, r+1):
  for j in range(i+1):
    a = j
    b = i-j
    v_temp = v[:a]
    v_temp.extend(v[n-b:])
    heapq.heapify(v_temp)
    for l in range(k-i):
      get = heapq.heappop(v_temp)
      if get>=0:
        heapq.heappush(v_temp, get)
        break
      if not v_temp:
        break
    v_temp.append(0)
    ans = max(ans, sum(v_temp))
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9
#define vint vector<int>

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint count(n, 0);
    int a;
    REP(i, 0, n - 1){
        cin >> a;
        count[a-1] += 1;
    }

    REP(i, 0, n){
        p(count[i]);
    }

}

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

int main() {

long double l;
cin >> l;
long double hen=l/3;

long double ans =hen*hen*hen;

printf("%.100Lf\n", ans);
return 0;

}


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

using namespace std;

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

    vector<long long> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    vector<long long> c(m), d(m);
    for (int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }

    for (int i = 0; i < n; i++) {
        long long p = 0, r = 1LL << 61;
        for (int j = 0; j < m; j++) {
            if (r > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
                p = j;
                r = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            }
        }

        cout << p + 1 << endl;
    }
}


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

#define int long long
#define mod 1000000007

using namespace std;

int a[200010];

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

    multiset <int> s;

    for(int i=0;i<n;i++)
        cin >> a[i], s.insert(a[i]);

    int count = 0;

    while(!s.empty())
    {
        int temp = *(--s.end());

        int cnt = 1;

        while(cnt <= temp)
            cnt *= 2;

        s.erase(--s.end());

        if(cnt != temp)
        {
            cnt -= temp;

            if(s.find(cnt) != s.end())
            {
                count++;
                s.erase(s.find(cnt));
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 1000000007;


int main() {
    ll si = 2001;
    vector<vector<ll>> a(si,vector<ll>(si,0));
    for(ll i = 0;i < si;++i){
        a[1][i] = 1;
    }
    for(ll k = 2;k < si;++k){
        a[k][0] = 1;
        for(ll i = 1;i < si;++i){
            a[k][i] = a[k][i - 1] +  a[k - 1][i];
            a[k][i] %= BIG;
        }
    }

    /*
    for(ll k = 2;k < 5;++k){
        for(ll i = 1;i < 10;++i){
            cout << "k = " << k << ",i = " << i << ",a = " << a[k][i] << endl;
        }
    }
     */


    ll s;
    cin >> s;
    ll ans = 0;
    for(ll k = 1;k < si;++k){
        if(s - k * 3 < 0)break;
        ans += a[k][s - k * 3];
        //cout << "k = " << k << ",sum = " << (s - k * 3) << "," << a[k][s -  k * 3] << endl;
        ans %= BIG;
    }
    cout << ans << endl;
}




Measured memory_bytes: 34360
h,w = map(int,input().split())
a = []
count = 0

for i in range(h):
    a.append(list(map(str,input().split())))

for j in range(h):
    c = str(a[j])
#    print(c)
    count += c.count("#")
#    print(count)

if count == h + w -1:
    print("Possible")
else:
    print("Impossible")


Measured memory_bytes: 2940
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

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

typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const LL LINF=4557430888798830399;
const ld eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define rep1(i,n) for(int i=1;i<=((int)(n));i++)
#define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

inline int Read()
{
	int x=0,w=0;char ch=0;while(!isdigit(ch)){w|=ch=='-';ch=getchar();}while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
inline void Write(int x){if(x<0)putchar('-'),x=-x;if(x>9)Write(x/10);putchar(x%10+'0');}
inline LL powmod(LL a,LL b){LL res=1;a%=MOD;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res%MOD;}
inline LL gcdll(LL a,LL b){return b?gcdll(b,a%b):a;}

const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={1,0,-1,0,-1,-1,1,1};
/************************************************************BEGIN************************************************************/
const int maxn=INF;

int a;

int main()
{
	cin>>a;
	cout<<a+a*a+a*a*a;

	return 0;
}
/*************************************************************END**************************************************************/

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

ll sx, sy, tx, ty;
string ans = "";

void solve() {
	for (int i = 0; i < ty - sy; i++) {
		ans += "U";
	}
	for (int i = 0; i < tx - sx; i++) {
		ans += "R";
	}
	for (int i = 0; i < ty - sy; i++) {
		ans += "D";
	}
	for (int i = 0; i < tx - sx; i++) {
		ans += "L";
	}
	ans += "L";
	for (int i = 0; i < ty - sy + 1; i++) {
		ans += "U";
	}
	for (int i = 0; i < tx - sx + 1; i++) {
		ans += "R";
	}
	ans += "D";
	ans += "R";
	for (int i = 0; i < ty - sy + 1; i++) {
		ans += "D";
	}
	for (int i = 0; i < tx - sx + 1; i++) {
		ans += "L";
	}
	ans += "U";
	cout << ans << endl;
}

int main() {
	cin >> sx >> sy >> tx >> ty;
	solve();
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

struct edge{
    int to;
    ll cost;
};

vector<edge>g[100010];
set<P>dist[100010];

bool visited[100010];
bool decided[100010];

int main(void){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        ll d;
        cin>>a>>b>>d;
        a--;
        b--;
        g[a].push_back({b,d});
        dist[a].insert(P(b,d));
        g[b].push_back({a,-1*d});
        dist[b].insert(P(a,-1*d));
    }
    for(int i=0;i<n;i++){
        queue<P>que;
        que.push(P(i,0));
        dist[i].insert(P(i,0));
      	//cout<<"kj"<<i+1<<endl;
        while(!que.empty()){
            P p = que.front();
            que.pop();
            int now = p.first;
            ll di = p.second;
            if(visited[now])continue;
            visited[now]=true;
            for(int j=0;j<g[now].size();j++){
                int next = g[now][j].to;
                ll c =g[now][j].cost;
              	//cout<<next<<" "<<c<<endl;
                if(!decided[next]){
                    decided[next]=true;
                    que.push(P(next,di+c));
                    dist[i].insert(P(next,di+c));
                }
                else{
                    if(dist[i].count(P(next,di+c))==0){
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"Yes"<<endl;
	return 0; 
}

Measured memory_bytes: 46080
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]";
	err(++it, args...);
}

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll ans = 0;
	ll a;
	double b, f;
	cin >> a >> b;
	ll w = b*100 + 0.01;

	ans = (a*w) / 100;

	cout << fixed << ans << endl;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

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

using namespace std;

#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define LL long long
#define ULL unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<LL,int>
#define PLL pair<LL,LL>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<LL,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




const int N=2e5+2;
const LL mod=998244353;
LL tree[4*N+5],lazy[4*N+5],Base[N];

void PreCal(const int& n)
{
    Base[n]=1;
    for(LL i=n-1;i>0;i--)Base[i]=(Base[i+1]*10)%mod;
}

void Build(int treeNum,int l,int r)
{
    if(l == r)
    {
        tree[treeNum]=Base[l]%mod;
        return;
    }
    int mid=(l+r) >> 1;
    Build(2*treeNum,l,mid);
    Build(2*treeNum+1,mid+1,r);
    tree[treeNum]=(tree[2*treeNum] + tree[2*treeNum+1]) % mod;
}

void Update(int tree_num,int start,int end,int l,int r,long long int value)
{
    if(lazy[tree_num] != 0)
    {
        tree[tree_num]=(Base[start]-Base[end+1])%mod;
        if(tree[tree_num] < 0)tree[tree_num]+=mod;
        tree[tree_num]*=lazy[tree_num];
        tree[tree_num]%=mod;
        if(start != end)
        {
            lazy[tree_num*2]=lazy[tree_num];
            lazy[tree_num*2 + 1]=lazy[tree_num];
        }
        lazy[tree_num]=0;
    }
    if(start > end  ||  start > r  ||  end < l)return ;
    if(start >= l  &&  end <= r)
    {
        tree[tree_num]=(Base[start]-Base[end+1])%mod;
        if(tree[tree_num] < 0)tree[tree_num]+=mod;
        tree[tree_num]*=value;
        tree[tree_num]%=mod;
        if(start != end)
        {
            lazy[tree_num*2]=value;
            lazy[tree_num*2 + 1]=value;
        }
        return ;
    }

    int mid=(start+end)/2;
    Update(tree_num*2,start,mid,l,r,value);
    Update(tree_num*2 + 1,mid+1,end,l,r,value);

    tree[tree_num]=(tree[tree_num*2] + tree[tree_num*2 + 1])%mod;
}

int main()
{
    FAST();
    int i,l,n,q,r,x;
    cin >> n >> q;
    PreCal(n);
    Build(1,1,n);
    for(i=n;i > 0;i--)Base[i]=(Base[i]+Base[i+1])%mod;
    while(q--)
    {
        cin >> l >> r >> x;
        Update(1,1,n,l,r,x);
        cout << tree[1] << '\n';
    }
    return 0;
}


Measured memory_bytes: 13388
#include<bits/stdc++.h>
using namespace std;
int f[109][109];
 
main()
{
   int a,b;
   string s;
   cin>>a>>b;
   cin>>s;
   int fl=1;
   for(int i=0; i<s.size(); i++)
   {
       if(i==a && s[i]!='-' || i!=a && s[i]=='-') {fl=0;}
   }
   if(fl) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
 
}

Measured memory_bytes: 256
N, L = gets.split.map(&:to_i)
list = (1..N).map { |i| L + i - 1 }
list2 = list.map(&:abs)
sum = list.reduce(&:+)
list3 = list2.map.with_index { |a, i| [a, i] }.sort
i = list3[0][1]
ans = sum - list[i]
puts ans


Measured memory_bytes: 1788
#include<stdio.h>
void quicksort(long int a[],int s,int t){
  if(s<t){
    int i=s,j=t,p=a[(s+t)/2];
    while(1){
      while(a[i]<p)i++;
      while(p<a[j])j--;
      if(i>=j)break;
      a[i]^=a[j]^=a[i]^=a[j];
      i++;j--;
    }
    quicksort(a,s,i-1);quicksort(a,j+1,t);
  }
}
int main(){
  long int p[50][2],n,k,z=1L<<62L,i,j,l,m,o,x[50],y[50],a;
  scanf("%ld%ld",&n,&k);
  for(i=0;i<n;i++){scanf("%ld%ld",&p[i][0],&p[i][1]);x[i]=p[i][0];y[i]=p[i][1];}
  quicksort(x,0,n-1);quicksort(y,0,n-1);
  for(i=0;i<n;i++)for(j=i;j<n;j++)for(l=0;l<n;l++)for(m=l;m<n;m++){
    a=0;for(o=0;o<n;o++)if(p[o][0]>=x[i]&&p[o][0]<=x[j]&&p[o][1]>=y[l]&&p[o][1]<=y[m])a++;
    if(a>=k&&(long long int)(x[j]-x[i])*(y[m]-y[l])<z)z=(long long int)(x[j]-x[i])*(y[m]-y[l]);
  }
  printf("%ld",z);
}


Measured memory_bytes: 1736
#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
const int maxn = 8080 * 2;
bitset<maxn> mp;
int main(){
    string s;
    cin >> s;
    vector<int> t[2];
    int p = 0, curx = maxn/2, cury = maxn/2;
    while(p < s.size() && s[p] == 'F') curx++, p++;
    int tot = 0, m = 1;
    for(int e = p; e < s.size(); e++){
        if(s[e] == 'T'){
            t[m].push_back(tot);
            // cout << m << " " << tot << endl;
            tot = 0;
            m ^= 1;
        } else {
            tot++;
        }
    }
    // cout << m << " " << tot << endl;
    t[m].push_back(tot);
    mp.reset();
    mp.set(curx);
    for(int v : t[1]){
        mp = (mp<<v)|(mp>>v);
    }
    int xx, yy;
    cin >> xx >> yy;
    xx += maxn / 2;
    yy += maxn / 2;
    if(mp.test(xx));
    else return ! printf("No\n");
    mp.reset();
    mp.set(cury);
    for(int v : t[0]){
        mp = (mp<<v)|(mp>>v);
    }
    if(mp.test(yy));
    else return ! printf("No\n");
    printf("Yes\n");
    return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;
using PP = pair<P,llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

PP operator+(const PP &l, const PP &r){
	return PP(P(l.first.first+r.first.first,l.first.second+r.first.second), l.second+r.second);
}
P operator-(const P &l, const P &r){
	return P(l.first-r.first, l.second-r.second);
}

int main(){
	llong N, Ma, Mb;
	vector<PP> v;

	cin >> N >> Ma >> Mb;
	v.resize(N);
	for(int i = 0; i < N; i++)
		cin >> v[i].first.first >> v[i].first.second >> v[i].second;

	vector<PP> f,b;
	for(int i = 0; i < 1<<(N/2); i++){
		bitset<40> bs(i);
		PP sum = PP(P(0,0),0);
		for(int j = 0; j < N/2; j++)
			if(bs.test(j))
				sum = sum + v[j];
		f.push_back(sum);
	}
	for(int i = 0; i < 1<<(N-N/2); i++){
		bitset<40> bs(i);
		PP sum = PP(P(0,0),0);
		for(int j = 0; j < N-N/2; j++)
			if(bs.test(j))
				sum = sum + v[j+N/2];
		b.push_back(sum);
	}
	sort(BE(f)), sort(BE(b));

	llong ans = inf;
	for(int i = 0; i < f.size(); i++){
		PP now = f[i];
		// cerr << now.first.first << " " << now.first.second << endl;
		int tmA = now.first.first/Ma + (now.first.first%Ma > 0 ? 1 : 0);
		int tmB = now.first.second/Mb + (now.first.second%Mb > 0 ? 1 : 0);
		if(now.first.first == 0)
			tmA = 1;
		if(now.first.second == 0)
			tmB = 1;
		int tgA = Ma*max(tmA,tmB), tgB = Mb*max(tmA,tmB);

		// cerr << tgA << " " << tgB << endl << endl;
		for(int i = 0; i < 10; i++){
			int cA = tgA + Ma*i, cB = tgB + Mb*i;
			// cerr << cA << " " << cB << endl;
			auto it = lower_bound(BE(b), PP(P(cA, cB) - now.first, 0));
			if(it->first == P(cA,cB) - now.first)
				ans = min(ans, it->second + now.second);
		}
	}

	if(ans == inf)
		ans = -1;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 63716
K = int(input())
AT = list(map(int,input().split()))

A=reversed(AT)
s = 2;b = 1;lis=[]
for i in A:
    ns = i
    if s > ns:
        ns +=(((s-ns)//i)*i)
        if s > ns:
            ns+=i
    s = ns
sn = s
for i in AT:
    sn = sn-sn%i

if sn!=2:
    print(-1)
    exit()
b = 1
AT.reverse()
for i in AT:
    b=b-b%i
    nb = i
    if b > nb:
        nb +=(((b-nb)//i)*i)
        if b > nb:
            nb+=i
    b= (nb+i-1)
print(s,b)


Measured memory_bytes: 63856
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ii = pair<int, int>;
 
void solve();
 
clock_t start_time;
double get_current_time() {
	return (double)(clock() - start_time) / CLOCKS_PER_SEC;
}
 
int main() {
	// freopen("substring.in", "r", stdin);
	// freopen("substring.out", "w", stdout);
 
	ios_base::sync_with_stdio(false);
	solve();
}
 
/* ========== actual code starts here ========== */
 
#define fi first
#define re return
#define se second
#define in insert
#define pb push_back
#define eb emplace_back
#define y1 y123123123123
#define all(x) x.begin(), x.end()
#define hash hash123s
#define index ind123
 
#define repx(i, x, n) for (int i = x; i < (n); i++)
#define repd(i, n, d) for (int i = 0; i < (n); i += d)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepd(i, n, d) for (int i = (n) - 1; i >= 0; i -= d)
#define rep(i, n) for (int i = 0; i < (n); i++)
 
template<class t>
void print(t x, int end = 1) {
	cout << x << (end == 1 ? "\n" : " ");
}
 
template<class T>
void print(const vector<T> &v, int end = 1) {
	rep(i, (int) v.size()) {
		print(v[ i ], 0);
	}
	cout << endl;
}

template<class T>
void print(const int *a, int sz, int end = 1) {
	rep(i, sz) {
		print(a[ i ], 0);
	}
	cout << endl;
}
 
template<class T>
void print(const set<T> &v, int end = 1) {
	for(auto to = v.begin(); to != v.end(); to++) {
		print(*to);
	}
	cout << endl;
}
 
template<class T>
void print(const map<T, T> &v, int end = 1) {
	for(auto to : v) {
		print(to.fi, 0);
		cout << ": ";
		print(to.se);
	}
}
 
template<class t>
void errprint(t x, int end = 1) {
	cerr << x << (end == 1 ? "\n" : " ");
}
 
#ifdef artem
	#define debug(x) x
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(x)
#endif
 
const int limit = (int)1e5 + 123;
const int k = 18;
int n, t;
int sparse[ limit ][ k ], a[ limit ];

int get_min(int l, int r) {
	--l, --r;
	int log = log2(r - l + 1);
	re min(sparse[ l ][ log ], sparse[ r - (1 << log) + 1 ][ log ]);
}

bool cmp(int x, int y) {
	re a[ x ] < a[ y ];
}

void solve() {
	cin >> n >> t;
	rep(i, n) cin >> a[ i ];
	rep(i, n) sparse[ i ][ 0 ] = a[ i ];

	repx(j, 1, k) {
		rep(i, n - (1 << j) + 1) {
			sparse[ i ][ j ] = min(sparse[ i ][ j - 1 ], sparse[ i + (1 << (j - 1)) ][ j - 1 ]);
		}
	}

	map<int, int> answer;
	repx(i, 1, n) {
		int x = a[ i ];
		int y = get_min(1, i);
		answer[ x - y ]++;
	}
	cout << answer.rbegin()->se;
}

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

int main(){
  vector<int>Food(5);
  vector<int>rest(5);
  int sum = 0;
  repeat(i,5){
    cin >> Food[i];
    rest[i] = (Food[i]%10);
    if(rest[i]!=0)Food[i] = (Food[i]/10+1)*10;
    else rest[i] = 10;
    sum += Food[i];
  }
  
  int ans;
  int diff = *min_element(rest.begin(),rest.end());
  ans = sum - (10-diff);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int A[MAX];
int partition(int[],int,int);

int main(void){
  int n,i,p,r,x;
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  
  p=1;
  r=n;
  x=partition(A,p,r);
  
  for(i=1;i<n;i++){
    if(i == x) printf("[%d] ",A[i]);
    else printf("%d ",A[i]);
  }
  printf("%d",A[n]);
  printf("\n");

  return 0;
}

int partition(int A[],int p,int r){
  int x,i,j,b;

  x = A[r];
  i = p-1;
  for(j=p;j<=r-1;j++){
    if(A[j] <= x){
      i++;
      b = A[i];
      A[i] = A[j];
      A[j] = b;
    }
  }
  b = A[i+1];
  A[i+1] = A[r];
  A[r] = b;

  return i+1;
}

Measured memory_bytes: 988
H, W, K = gets.split.map(&:to_i)

cake = H.times.map { gets.chomp.chars }
AREA = Array.new(H) { Array.new(W, -1) }

cnt = 0

H.times do |y|
  W.times do |x|
    c = cake[y][x]

    next if c != '#'
    cnt += 1

    AREA[y][x] = cnt
  end
end

require 'pp'
# pp AREA

def check_right
  H.times do |y|
    id = -1

    W.times do |x|
      if AREA[y][x] != -1
        id = AREA[y][x]
      end

      AREA[y][x] = id
    end
  end
end

def check_left
  (H - 1).downto(0) do |y|
    id = -1

    (W - 1).downto(0) do |x|
      if AREA[y][x] != -1
        id = AREA[y][x]
      end

      AREA[y][x] = id
    end
  end
end

def check_down
  H.times do |y|
    visited = Hash.new(false)

    W.times do |x|
      id = AREA[y][x]

      next if id == -1
      next if visited[id]

      visited[id] = true
      from = to = x

      (x + 1).upto(W - 1) do |nx|
        break if id != AREA[y][nx]

        to = nx
      end

      (y + 1).upto(H - 1) do |ny|
        break unless all_empty?(ny, from, to)

        update_area(ny, from, to, id)
      end
    end
  end
end

def check_up
  (H - 1).downto(0) do |y|
    visited = Hash.new(false)

    0.upto(W - 1) do |x|
      id = AREA[y][x]

      next if id == -1
      next if visited[id]

      visited[id] = true
      from = to = x

      (x + 1).upto(W - 1) do |nx|
        break if id != AREA[y][nx]

        to = nx
      end

      (y - 1).downto(0) do |ny|
        break unless all_empty?(ny, from, to)

        update_area(ny, from, to, id)
      end
    end
  end
end

def all_empty?(y, from, to)
  AREA[y][from..to].all? { |x| x == -1 }
end

def update_area(y, from, to, id)
  from.upto(to) do |x|
    raise if AREA[y][x] != -1
    AREA[y][x] = id
  end
end

require 'pp'

check_right
check_left
check_down
check_up

puts AREA.map { |row| row.join(' ') }


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

int main(void){
    int A,B,i=0;
    cin >> A >>B;
    while(1){
        if(A*i-i+1>=B)break;
        i++;
    }
    cout << i  <<endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
if s.find("1") != -1:
    print("NO")
elif s.find("2") != -1:
    print("NO")
else:
    a = s.replace("dream", "11111").replace("erase", "22222").replace("11111er", "1111111").replace("22222r", "111111").replace("22222", "11111")
    if a.count("1") == len(a):
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 3316
import java.util.Scanner;

class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int tmp = 0;

			if(n == 0 && x == 0)
				break;

			for(int i=1; i<n; i++){
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			}
			System.out.println(tmp);

		}

	}

}

Measured memory_bytes: 19612
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int a, b;
    cin >> a >> b;
    cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 3612
class Graph:
    def __init__(self):
        self.edges = {}

    def addVertex(self, v):
        if v not in self.edges:
            self.edges[v] = []

    def addEdge(self, from_v, to_v):
        if from_v not in self.edges:
            self.edges[from_v] = []
        if to_v not in self.edges[from_v]:
            self.edges[from_v].append(to_v)

    def isEdge(self, from_v, to_v):
        if to_v not in self.edges:
            return False
        return to_v in self.edges[from_v]

g = Graph()
n = int(input())
for i in range(n):
    u, k, *v = map(int, input().split())
    g.addVertex(u)
    for j in v:
        g.addEdge(u, j)

adj = []
for i in range(1, n+1):
    e = []
    for j in range(1, n+1):
        if g.isEdge(i, j):
            e.append(1)
        else:
            e.append(0)
    adj.append(e)

for a in adj:
    print(" ".join(map(str, a)))

Measured memory_bytes: 6764
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll lg=14;
const ll N=3e3+1;
const ll INF=1e9;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%lld",&n)
#define longp(n) printf("%lld\n",n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

ll n;
ld h[N],dp[N][N];

ld F(ll idx,ll head)
{
  ld res=0;
  if(idx==n+1)
  {
    if(head<=n/2){return 0;}
    return 1;
  }
  if(dp[idx][head]!=-1){return dp[idx][head];}
  res+=h[idx]*F(idx+1,head+1);
  res+=(1-h[idx])*F(idx+1,head);
  return dp[idx][head]=res;
}

int main()
{
  cin>>n;
  for(ll i=0;i<=n;i++)
  {
    for(ll j=0;j<=n;j++){dp[i][j]=-1;}
  }
  for(ll i=1;i<=n;i++){cin>>h[i];}
  ld val=F(1,0);
  cout<<fixed<<setprecision(10)<<val<<endl;
}


Measured memory_bytes: 141184
M=int(input())
N=list(input().split())
check=[0]*M
for i in range(M):
    check[int(N[i])-1]+=1
num=0
for i in range(M):
    num+=check[i]*(check[i]-1)//2
for i in range(M):
    if check[int(N[i])-1]!=2:
        print(num-(check[int(N[i])-1]-1))
    else:
        print(num-1)

Measured memory_bytes: 20576
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;

pss split(string s) {
  ll k;
  REP(i, 0, s.size()) if(s[i] == '-') k = i;
  string fi = s.substr(0, k);
  string se = s.substr(k + 1, s.size() - k - 1);
  return pss(fi, se);
}

void dfs(ll v, vector<vector<ll>> &E, vector<bool> &used, vector<ll> &color, ll c) {
  if(used[v]) return;
  used[v] = true;

  color[v] = c;
  for(ll u : E[v]) dfs(u, E, used, color, -c);
}

bool dfs2(ll v, ll g, vector<vector<ll>> &E, vector<bool> &used) {
  if(v == g) return true;

  if(used[v]) return false;
  used[v] = true;

  bool ret = false;
  for(ll u : E[v]) ret = ret || dfs2(u, g, E, used);
  return ret;
}

int main(void) {
  ll N, M;
  while(cin >> N, N) {
    vector<string> uniq;
    vector<pss> C(N);
    REP(i, 0, N) {
      string s;
      cin >> s;
      C[i] = split(s);
      uniq.push_back(C[i].first);
      uniq.push_back(C[i].second);
    }
    cin >> M;
    vector<pss> Q(M);
    REP(i, 0, M) {
      string s;
      cin >> s;
      Q[i] = split(s);
      uniq.push_back(Q[i].first);
      uniq.push_back(Q[i].second);
    }
    sort(uniq.begin(), uniq.end());
    uniq.erase(unique(uniq.begin(), uniq.end()), uniq.end());

    vector<pll> cross(N), query(M);
    REP(i, 0, N) {
      cross[i].first = lower_bound(uniq.begin(), uniq.end(), C[i].first) - uniq.begin();
      cross[i].second = lower_bound(uniq.begin(), uniq.end(), C[i].second) - uniq.begin();
    }
    REP(i, 0, M) {
      query[i].first = lower_bound(uniq.begin(), uniq.end(), Q[i].first) - uniq.begin();
      query[i].second = lower_bound(uniq.begin(), uniq.end(), Q[i].second) - uniq.begin();
    }

    ll n = uniq.size();
    vector<vector<ll>> E(n), R(n), A(n), X(n);
    REP(i, 0, N) {
      E[cross[i].first].push_back(cross[i].second);
      R[cross[i].second].push_back(cross[i].first);
      A[cross[i].first].push_back(cross[i].second);
      A[cross[i].second].push_back(cross[i].first);
      X[cross[i].first].push_back(cross[i].second);
    }

    vector<bool> used(n, false);
    vector<ll> color(n);
    ll c = 1;
    REP(i, 0, n) if(!used[i]) dfs(i, A, used, color, c++);

    vector<vector<bool>> e(n, vector<bool>(n, false));
    REP(i, 0, N) e[cross[i].first][cross[i].second] = true;
    REP(i, 0, n) REP(j, 0, n) {
      bool c1 = false, c2 = true;
      REP(k, 0, n) {
        c1 = c1 || (e[i][k] && e[j][k]) || (e[k][i] && e[k][j]);
        c2 = c2 && !(e[i][k] && e[k][j]) && !(e[j][k] && e[k][i]);
      }
      if(c1 && c2) {
        X[i].push_back(j);
        X[j].push_back(i);
      }
    }

    set<ll> st;
    REP(i, 0, N) {
      st.insert(cross[i].first);
      st.insert(cross[i].second);
    }

    cout << st.size() << endl;
    REP(i, 0, M) {
      ll s = query[i].first, t = query[i].second;
      vector<bool> used2(n, false);
      bool ok = color[s] == -color[t] && dfs2(s, t, X, used2);
      cout << (ok ? "YES" : "NO") << endl;
    }
  }
}



Measured memory_bytes: 3612
#include <stdio.h>
int main(){
  int n;
  
  scanf("%d",&n);
  
  switch(n%10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      printf("hon");
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      printf("pon");
      break;
    case 3:
      printf("bon");
  }
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  vector<bool> ch(b, false);
  if(a >= b) a %= b;
  int now = a;
  while(1){
    if(ch.at(now) == false){
      // cerr << now << endl;
      ch.at(now) = true;
    }else{
      break;
    }
    now = (now + a) % b;
  }
  if(ch.at(c) == true) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
	int n;
	int m=0,ans=0;
	char s;
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
	{
		cin >>s;
		if (s=='I') ans++;
		   else ans--;
		m=max(m,ans);
	}
	if (m==-1) m=0;
	printf("%d",m);
	return 0;
}

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

int m,s,t;

#define MAX_V 100010
#define INF 11111111111111111
struct edge{int to,cost;};
typedef pair<int ,int> P; //firstは最短距離、secondは頂点の番号

int V; //頂点数
vector<edge> G[MAX_V]; //添字がfrom
vector<edge> GG[MAX_V]; //添字がfrom
int d1[MAX_V]; //最短コスト(経路が無い場合はINF)
int d2[MAX_V];

void dijkstra1(int s){
  priority_queue<P,vector<P>,greater<P> > que;
  fill(d1,d1+MAX_V,INF);
  d1[s]=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    int v=p.second;
    if(d1[v]<p.first)continue;
    for(int i=0;i<G[v].size();i++){
      edge e=G[v][i];
      if(d1[e.to]>d1[v]+e.cost){
	d1[e.to]=d1[v]+e.cost;
	que.push(P(d1[e.to],e.to));
      }
    }
  }
}

void dijkstra2(int s){
  priority_queue<P,vector<P>,greater<P> > que;
  fill(d2,d2+MAX_V,INF);
  d2[s]=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    int v=p.second;
    if(d2[v]<p.first)continue;
    for(int i=0;i<GG[v].size();i++){
      edge e=GG[v][i];
      if(d2[e.to]>d2[v]+e.cost){
	d2[e.to]=d2[v]+e.cost;
	que.push(P(d2[e.to],e.to));
      }
    }
  }
}

signed main(){
  cin>>V>>m>>s>>t;
  for(int i=0;i<m;i++){
    int u,v,a,b;
    cin>>u>>v>>a>>b;
    u--,v--;
    G[u].push_back((edge){v,a});
    G[v].push_back((edge){u,a});
    GG[u].push_back((edge){v,b});
    GG[v].push_back((edge){u,b});
  }
  dijkstra1(--s);
  dijkstra2(--t);
  int tmp=1000000000000000;
  int ans[MAX_V];
  for(int i=V-1;i>=0;i--){
    ans[i]=d1[i]+d2[i];
    if(i!=V-1)ans[i]=min(ans[i],ans[i+1]);
  }
  for(int i=0;i<V;i++){
    cout<<tmp-ans[i]<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 20828
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int MAX = 1e6 + 20 ;
int n , ans ;

void solve (int n , int m) {
	if (!m) return ;

	int k = n / m ;
	int l = n / (k + 1) + 1 , r = m ;

	if ((n - k) % k == 0) {
		int val = (n - k) / k ;

		ans += (l <= val && val <= r) * val ;
	}

	solve(n , l - 1) ;
}

int32_t main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;

	cin >> n ;
	solve(n , n) ;

	cout << ans << '\n' ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N,tmp,ans = 0;

	scanf("%d",&N);

	for(int loop = 0; loop < N; loop++){

		scanf("%d",&tmp);
		if(tmp%2 == 0){
			ans++;
		}
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 3232
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>

using namespace std;

long long int A, a, n, m, y, s;
string str_1, str_2, str_3;
long long int x[2][30000];


long long int gcd(int m, int n){
	while (true) {
		if (m%n == 0)return n;
		m %= n;
		if (n%m == 0)return m;
		n %= m;
	}
}



int main() {
	cin >> n >> m;
	cin >> str_1 >> str_2;

	y = gcd(n, m);

	for (int i = 0; i < y; i++) {
		if (str_1[i*n / y] != str_2[i*m / y]) {
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << n * m / y << '\n';
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int c[4][4];
	for(register int i=1;i<=3;i++)
		for(register int j=1;j<=3;j++){
			cin>>c[i][j];
			//cout<<c[i][j];
		}  
	
	int f=1;
	if((c[1][1]+c[2][2])!=(c[1][2]+c[2][1]))  f=0;//c11,c22
	//cout<<f<<' ';
	if((c[1][1]+c[3][2])!=(c[1][2]+c[3][1]))  f=0;//c11,c32
	//cout<<f<<' ';
	if((c[1][1]+c[2][3])!=(c[1][3]+c[2][1]))  f=0;//c11,c23
	//cout<<f<<' ';
	if((c[1][1]+c[3][3])!=(c[1][3]+c[3][1]))  f=0;//c11,c33
	//cout<<f<<' ';
	if((c[2][1]+c[3][2])!=(c[2][2]+c[3][1]))  f=0;//c21,c32
	//cout<<f<<' ';
	if((c[2][1]+c[3][3])!=(c[2][3]+c[3][1]))  f=0;//c21,c33
	//cout<<f<<' ';
	if((c[1][2]+c[2][3])!=(c[1][3]+c[2][2]))  f=0;//c12,c23
	//cout<<f<<' ';
	if((c[1][2]+c[3][3])!=(c[1][3]+c[3][2]))  f=0;//c12,c33
	//cout<<f<<' ';
	if((c[2][2]+c[3][3])!=(c[2][3]+c[3][2]))  f=0;//c22,c33
	//cout<<f<<' ';
	//cout<<endl;
	
	if(f==0)  cout<<"No";
	else  cout<<"Yes";
	return 0;
}

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

template<class T>
class BIT {
private:
    vector<T> dat;
    int n;
public:
    BIT(int _n) : dat(_n + 1), n(_n) {}
    // [1, i] の総和
    T sum(int i) {
        int s = 0;
        while(i > 0) {
            s += dat[i];
            i -= i & -i;
        }
        return s;
    }
    // [l, r] の総和
    T sum(int l, int r) {
        if(l > r) return 0;
        return sum(r) - sum(l - 1);
    }
    void add(int i, T x) {
        while(i <= n) {
            dat[i] += x;
            i += i & -i;
        }
    }
};

BIT<int> bit[30](505050);

int main() {
    int N;
    string S;
    int Q;
    cin >> N >> S >> Q;
    for(int i = 0; i < N; ++i) {
        int n = S[i] - 'a';
        bit[n].add(i + 1, 1);
    }
    while(Q--) {
        int q; cin >> q;
        if(q == 1) {
            int i;
            char c;
            cin >> i >> c;
            int n = S[i-1] - 'a';
            int m = c - 'a';
            bit[n].add(i, -1);
            S[i-1] = c;
            bit[m].add(i, 1);
        } else {
            int l, r;
            cin >> l >> r;
            int cnt = 0;
            for(int i = 0; i < 26; ++i) {
                if(bit[i].sum(l, r)) cnt++;
            }
            cout << cnt << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 60164
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,m,k;
    while(cin>>n>>m>>k){
        for(int i=n;i<=m;i++){
            if(i>=(m-k+1) || i<=(n+k-1))
                cout<<i<<endl;
        }
    }
}


Measured memory_bytes: 256
N, X = map(int,input().split())
S = list(map(int,input().split()))
S.sort(reverse=True)
S = [0] + S # 1-indexed 
MOD = 10**9+7
dp = [[0]*(10**5+1) for i in range(N+1)]
dp[0][X] = 1
for i in range(N):
    for x in range(10**5+1):
        dp[i+1][x%S[i+1]] += dp[i][x]
        dp[i+1][x] += dp[i][x]*(N-(i+1))
        dp[i+1][x%S[i+1]] %= MOD
        dp[i+1][x] %= MOD
ans = 0
for x in range(10**5+1):
    ans += (x*dp[N][x])%MOD
print(ans%MOD)

Measured memory_bytes: 193672
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		out: while (true) {
			int[] x;
			x = new int[5];
			for (int i = 0; i < 5; i++) {
				x[i] = s.nextInt();
				if (x[0] == 0)
					break out;
			}

			boolean[] j = { false, false, false };

			for (int i = 0; i < 5; i++) {
				j[x[i] - 1] = true;
			}

			if (j[0] && j[1] && j[2])
				for (int i = 0; i < 5; i++) {
					System.out.println("3");
				}

			if (j[0] && !j[1] && !j[2])
				for (int i = 0; i < 5; i++) {
					System.out.println("3");
				}

			if (!j[0] && !j[1] && j[2])
				for (int i = 0; i < 5; i++) {
					System.out.println("3");
				}

			if (!j[0] && j[1] && !j[2])
				for (int i = 0; i < 5; i++) {
					System.out.println("3");
				}

			if (!j[0] && j[1] && j[2])
				for (int i = 0; i < 5; i++) {
					if (x[i] == 2)
						System.out.println("1");
					else
						System.out.println("2");
				}

			if (j[0] && !j[1] && j[2])
				for (int i = 0; i < 5; i++) {
					if (x[i] == 3)
						System.out.println("1");
					else
						System.out.println("2");
				}

			if (j[0] && j[1] && !j[2])
				for (int i = 0; i < 5; i++) {
					if (x[i] == 1)
						System.out.println("1");
					else
						System.out.println("2");
				}

		}
	}
}

Measured memory_bytes: 20768
import std.stdio, std.string, std.array, std.conv, std.algorithm;

char[10^^5] SS;

char conv(char who, char what, char whom)
{
    switch (who) {
        case 'S':
            switch (what) {
                case 'o':
                    switch (whom) {
                        case 'S':
                            return 'S';
                        case 'W':
                            return 'W';
                        default:
                    }
                    break;
                case 'x':
                    switch (whom) {
                        case 'S':
                            return 'W';
                        case 'W':
                            return 'S';
                        default:
                    }
                    break;
                default:
            }
            break;
        case 'W':
            switch (what) {
                case 'o':
                    switch (whom) {
                        case 'S':
                            return 'W';
                        case 'W':
                            return 'S';
                        default:
                    }
                    break;
                case 'x':
                    switch (whom) {
                        case 'S':
                            return 'S';
                        case 'W':
                            return 'W';
                        default:
                    }
                    break;
                default:
            }
            break;
        default:
    }
    throw new Exception("Invalid charactor. [" ~ who ~ ", " ~ what ~ ", " ~ whom ~ "]");
}

char[] solve(long n, char[] zoo)
{
    zoo.length = n+1;
    for (size_t i = 2; i <= n; ++i)
        zoo[i] = conv(zoo[i-1], SS[i-1], zoo[i-2]);
    if (zoo[0] == zoo[n] && zoo[n-1] == conv(zoo[0], SS[0], zoo[1]))
        return zoo[0..n];
    return null;
}

void main()
{
    auto n = readln.chomp.to!long;
    foreach (i, s; readln.chomp) SS[i] = s;
    
    auto ret = solve(n, ['S', 'S']);
    if (!ret) ret = solve(n, ['S', 'W']);
    if (!ret) ret = solve(n, ['W', 'S']);
    if (!ret) ret = solve(n, ['W', 'W']);
    
    if (ret)
        writeln(ret);
    else
        writeln("-1");
}

Measured memory_bytes: 1020
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;

int main(){    
 int a,b,c;
 scanf("%d%d%d",&a,&b,&c);
 
 if(a <b&& b<c){

   printf("Yes\n");
 }
 else {
     printf("No\n");
 }


    return 0;
    }



Measured memory_bytes: 2608
#include <stdio.h>

int main(){
  int i,N,j,A[100],v,k;
  scanf("%d",&N);
  if(1<= N && N<=100)
  for(i=0;i<=N-1;i++){
    scanf("%d",&A[i]);
    if(A[i]>1000) break;
  }

  for(i=0;i<=N-1;i++){
    if(i!= N-1) printf("%d ",A[i]);
    else printf("%d",A[i]);
    }
printf("\n");

  for(i=1;i<=N-1;i++){
    v=A[i];
    j=i-1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1]=v;
    }
    for(k=0;k<=N-1;k++){
      if(k!= N-1) printf("%d ",A[k]);
     else printf("%d",A[k]);
    }
    printf("\n");
  }
  return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

void IsPrimeNum(ll n, v_bool &is_prime)
{
    is_prime[0] = is_prime[1] = false;
    for(ll i = 2; i <= n; i++) {
        for(ll j = i*i; j <= n; j += i) {
            is_prime[j] = false;
        }
    }
}

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

    v_bool is_prime(100000+1, true);    
    IsPrimeNum(100000, is_prime);

    v_int prime_cnt(100000+1, 0);

    int cnt = 0;
    for(int i = 1; i <= 100000; i += 2) {
        if(is_prime[i] && is_prime[(i+1)/2]) {
            cnt++; 
        }
        prime_cnt[i] =  cnt;
        prime_cnt[i+1] =  cnt;
    }
    
    v_int ans(q);
    v_int ans_l(q);
    v_int ans_r(q);
    irep(i, q) {
        int l, r;
        cin >> l >> r;
        ans[i] = prime_cnt[r] - prime_cnt[l-1];
    }

    irep(i, q) {
        cout << ans[i] << endl;
    }
    return 0;
}
/** atcoder **/


Measured memory_bytes: 2176
#include<stdio.h>
#include<string.h>

int main(void){
  int i,j,k,l;
  char str[100001];
  scanf("%s",str);
  l=strlen(str);

  if(l==2){
    puts(str[0]==str[1]?"1 2":"-1 -1");
    return 0;
  }

  for(i=0;i<l-2;i++){
    if(str[i]==str[i+1] || str[i]==str[i+2] || str[i+1]==str[i+2]){
      printf("%d %d\n",i+1,i+3);
      return 0;
    }
  }
  puts("-1 -1");
  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int a;
  int ans = 1;
  int d[100001] = {};
  bool flag = true;
  
  cin >> n;

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

  for(int j = n - 1;j > 0 && flag;j -= 2){
    if(d[j] != 2){
      flag = false;
    }
    ans = (ans * 2) % 1000000007;
  }

  if(d[0] == 1 && n % 2 != 0){
    flag = true;
  }

  if(flag){
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    ll sum = 60 * h2 + m2 - 60 * h1 - m1;
    cout << sum - k << endl;
    return 0;
}

Measured memory_bytes: 3624