akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if(S == U) --A;
  if(T == U) --B;
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include <iostream>

#include <map>
#include <string>

#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cinttypes>


using namespace std;

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

	if (n < 10)
	{
		r = r + (100 * (10 - n));
	}

	cout << r << endl;

	return 0;
}


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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int point;
	bool isRunner[3];
	int out;
	int n;
	char event[8];

	n = in();
	loop(i, 0, n)
	{
		point = 0;
		out = 0;
		isRunner[0] = isRunner[1] = isRunner[2] = false;

		while( out < 3 )
		{
			scanf("%s", event);
			switch( event[1] )
			{
				case 'I':
					if( isRunner[2] )
					{
						point++;
					}
					isRunner[2] = isRunner[1];
					isRunner[1] = isRunner[0];
					isRunner[0] = true;
					break;
				case 'O':
					point++;
					if( isRunner[0] )
					{
						point++;
					}
					isRunner[0] = false;
					if( isRunner[1] )
					{
						point++;
					}
					isRunner[1] = false;
					if( isRunner[2] )
					{
						point++;
					}
					isRunner[2] = false;
					break;
				case 'U':
					out++;
					break;
			}
		}
		printf("%d\n", point);
	}

	return (0);
}

Measured memory_bytes: 1192
#include<stdio.h>

 int main(){

   int i, j, A[100], n, len, minj, c=0;
   scanf("%d", &len);
   for(i=0; i<len; i++){
     scanf("%d", &A[i]);
   }

   for(i=0; i<len; i++){
     minj = i;

     for(j=i; j<len; j++){

 if(A[j] < A[minj]){
 minj =  j;
 }
     }

     if(minj != i){
       n = A[i];
       A[i] = A[minj];
       A[minj] = n;

       c++;
     }
   }
   for(j=0; j < len; j++){

     printf("%d",A[j]);
     if(j != len-1)
     printf(" ");
   }
   printf("\n");
   printf("%d\n",c);

   return 0;
 }



Measured memory_bytes: 2128
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint()
{
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//
const int maxn=2e6;
int par[maxn],flag[maxn],dis[maxn];
vector<pii >e[maxn];
vector<int>G[maxn];
//
void init(int x)
{
	flag[x]=-1;
	par[x]=x;
}
int fF(int x)
{
	if(par[x]==x)return x;
	return par[x]=fF(par[x]);
}
void fU(int x,int y)
{
	x=fF(x);y=fF(y);
	if(x==y)return;
	par[x]=y;
}
vector<int>v;
int n,m,cnt;
int main()
{
	n=getint();m=getint();
	rep(i,m)
	{
		int x=getint()-1,y=getint()-1,z=getint();
		e[z].push_back(mp(x,y));
	}
	cnt=n;
	rep(i,maxn)if(!e[i].empty())
	{
		v.clear();
		rep(j,e[i].size())
		{
			int x=e[i][j].first,y=e[i][j].second;
			init(x);init(y);
			v.push_back(x);
			v.push_back(y);
		}
		rep(j,e[i].size())
		{
			int x=e[i][j].first,y=e[i][j].second;
			fU(x,y);
		}
		rep(j,v.size())
		{
			int x=v[j],y=fF(x);
			if(flag[y]<0)flag[y]=cnt++;
			G[x].push_back(flag[y]);
			G[flag[y]].push_back(x);
		}
	}
	queue<int>qu;
	rep(i,maxn)dis[i]=-2;
	dis[0]=0;qu.push(0);
	while(!qu.empty())
	{
		int u=qu.front();
		qu.pop();
		rep(i,G[u].size())
		{
			int y=G[u][i];
			if(dis[y]==-2)
			{
				dis[y]=dis[u]+1;
				qu.push(y);
			}
		}
	}
	printf("%d\n",dis[n-1]/2);
	return 0;
}

Measured memory_bytes: 120704
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var a int

	fmt.Fscan(r, &a)

	x := a / 2
	y := a % 2
	fmt.Println(x + y)
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int M =sc.nextInt();
		int D =sc.nextInt();
		int count=0;
		for(int i=1;i<=M;i++) {
			
			for(int j=22;j<=D;j++) {
				int s1=j%10;
				int s2 =j/10;
				if(s1>=2 && s2>=2 && s1*s2 == i) {
					count++;
					
				}
				
			}
		}
		System.out.println(count);
		  
	}
}

Measured memory_bytes: 21844
S = input()
l = len(S)
i = 0
if l%2:
    c = S[l//2]
    for i in range(1,l//2+1):
        if S[l//2-i] != c or S[l//2 + i] != c:
            break
    else:
        i += 1
    print(l//2+i)
else:
    c = S[l//2]
    for i in range(l//2):
        if S[l//2-1-i] != c or S[l//2 + i] != c:
            break
    else:
        i += 1
        pass
    print(l//2 + i)

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	ll n ;
	cin >> n ;
	//n = a * bで表される時、小さい方をbとすると、bは√ｎ　以下である。
	ll ans = to_string(n).size();
	for(ll i = 1 ; i * i <= n ; i++){
		if(n % i == 0){
			ans = to_string(n/i).size() ;
		}
	}
	cout <<ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    int h[100010];
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    int mem[100010]={};
    int cost[100010]={};
    cost[1]=0;
    cost[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++){
        cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<cost[n]<<"\n";
    return(0);
}

Measured memory_bytes: 4388
#include <math.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

template <typename T>
void in(T& x) {
    std::cin >> x;
}

template <typename T>
void out(const T H) {
    std::cout << H;
}

template <typename T1, typename... T2>
void out(const T1 H, const T2... T) {
    std::cout << H << " "; out(T...);
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) {
    return os << "(" << v.first << " " << v.second << ")";
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    os << "[ "; for (auto &i: v) os << i << " "; return os << "]";
}

template <typename T>
void eout(const char *s, const T H) {
    std::cerr << s << "=" << H << "\n";
}

template <typename T1, typename... T2>
void eout(const char *s, const T1 H, const T2... T) {
    while (*s != ',') std::cerr << *s++;
    std::cerr << "=" << H << " | "; eout(++s, T...);
}

#define nl                std::cout << "\n"
#define err(args...)      eout(#args, args)

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define sz(v)             ((int) v.size())
#define all(v)            (v).begin(), (v).end()
#define lla(v)            (v).rbegin(), (v).rend()

#define no                std::cout << "NO\n"
#define yes               std::cout << "YES\n"

const int INF           = 2147483647;
const long long int LNF = 9223372036854775807LL;

using ll  = long long int;
using vi  = std::vector<int>;
using vb  = std::vector<bool>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N  = 505050;
const int MD = 1000*1000*1000 + 7;

int solve();
int main() {
    std::ios_base::sync_with_stdio(0); std::cin.tie(0);
    //std::cout.tie(0);

    //inn(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}

inline int mul(int a, int b, int p = MD) {
    return (int) ((long long) a*b%p);
}

int solve() {
    std::string s; in(s);
    std::reverse(all(s));

    int n = sz(s);

    vi p10(n); p10[0] = 1;
    repr(i, 1, n) p10[i] = mul(p10[i - 1], 10, 13);

    int b = 0;
    vi a; a.reserve(n);
    rep(i, n) {
        if (s[i] == '?') a.push_back(p10[i]);
        else b += mul(p10[i], s[i] - '0', 13);
    }
    b = ((5 - b)%13 + 13)%13;

    int m = sz(a);
    int dp[m + 1][13] = {{0}}; dp[0][0] = 1;
    rep(i, m) {
        rep(j, 10) {
            int x = mul(a[i], j, 13);
            rep(k, 13) {
                (dp[i + 1][(x + k)%13] += dp[i][k]) %= MD;
            }
        }
    }

    out(dp[m][b]);
    return 0;
}


Measured memory_bytes: 6352
n = int(input())
p = list(map(int, input().split()))

num = int(n/2)
p.sort()
med = p[num]
#print(med)

ans1 = list(filter(lambda x:x>=med,p))
ans2 = list(filter(lambda x:x<med,p))
#print(ans1)
#print(ans2)
cnt = 0
if len(ans1) != len(ans2):
    print(0)
else:
    for i in range(max(ans2)+1,min(ans1)+1):
        #print(i)
        cnt+=1
    print(cnt)


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

using namespace std;

typedef long long ll;

int main() {
  ll L, R;
  
  cin >> L >> R;
  
  int s, c;
  
  s = L % 2019;
  c = R - L >= 2018 ? 2019 : R - L + 1;
  
  int ans = 2018;
  
  for (int i = 0; i < c - 1; i++) {
    for (int j = i + 1; j < c; j++) {
      int a = s + i;
      int b = s + j;
      
      ans = min(ans, (a * b) % 2019);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int a[100]={};
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        cout<<a[i]<<(i==n-1?'\n':' ');
    }
    for(int i=1; i<n; i++){
        int key = a[i];
        int j=i-1;
        while(j>=0&&a[j]>key){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=key;
        for(int k=0; k<n; k++){
            cout<<a[k]<<(k==n-1?'\n':' ');
        }
        
    }
    return 0;
}


Measured memory_bytes: 3112
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void raushan_kumar(){
	int n;cin>>n;
	if(n%2){
		int q=ceil(n*1.0/2);
		double t=q*1.0/n;
		// cout<<q<<endl;
		printf("%.12f",t);
	}
	else{
		printf("%.12f",0.5);
	}
}

int32_t main()
{
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

Measured memory_bytes: 256
#-------------------------------------------------------------------
import sys
def p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())

ans = "NO"

x = v-w
y = abs(a-b)

p(x,y)
if y <= x*t:
  ans = "YES"

print(ans)


Measured memory_bytes: 9128
#include <bits/stdc++.h>
     
    using namespace std;
     
    int table[8] {1, 2, 3, 4, 5, 6, 7, 8};
    int ar[8];
    int visit[8];
     
    int d = 0;
    int p = 0;
    int s = 0;
     
    void fn(vector<int> &t, int idx, int &input)
    {
        if (idx == t.size())
        {
            ++d;
            bool pass = true;
            for (int x = 0; x < t.size(); ++x)
                if (ar[x] != t[x])
                {
                    pass = false;
                    break;
                }
            
            if (pass)
                input = d;
            
        }
        else
        {
            for (int i = 0; i < t.size(); ++i)
            {
                if (!visit[table[i] - 1])
                {
                    visit[table[i] - 1] = 1;
                    ar[idx] = table[i];
                    fn(t, idx + 1, input);
                }
            }
        }
     
        visit[ar[idx - 1] - 1] = 0;
        ar[idx - 1] = 0;
    }
     
    int main() 
    {
        cin.tie(0); cout.tie(0);
        ios_base::sync_with_stdio(false);
        
        int n; cin >> n;
        vector<int> a(n), b(n);
     
        for (int i = 0; i < n; ++i)
            cin >> a[i];
        for (int j = 0; j < n; ++j)
            cin >> b[j];
        
        vector<vector<int>> ent;
        ent.push_back(a);
        ent.push_back(b);
        sort(ent.begin(), ent.end());
        
        fn(a, 0, p);
        d = 0;
        fn(b, 0, s);    
        
        cout << abs(s - p);
    }

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#define N 5044
using namespace std;
int head[N];
int cnt[N];
int tot;
struct cmp//定义优先队列排序 
{
	template<typename T>
	bool operator()(T const& left, T const& right)
	{
		//second较大的在后 
		if (left.second > right.second) return true;
		else return false;
	}
};
struct E
{
	int to;
	int Next;
	int w;
}edge[N];
void add_edge(int from, int to, int w)
{
	tot++;
	edge[tot].to = to;
	edge[tot].w = w;
	edge[tot].Next = head[from];
	head[from] = tot;
}
int t, n;
bool vis[N];
int dis[N];
void dijkstra(int x)
{
	int i, j;
	memset(dis, 0x3f, sizeof(dis));
	memset(vis, 0, sizeof(vis));
	int res, pos;
	dis[x] = 0;
	priority_queue<pair<int, int>, vector<pair<int, int> >, cmp>q;
	q.push(make_pair(x, 0));//代表顶点1，距离0。
	while (!q.empty())
	{
		pair<int, int>res;
		//弹出dis[i]最小的点 
		res = q.top();
		//该点被访问，删去 
		q.pop();
		int from = res.first;
		vis[from] = 1;//标记 
		//松弛操作 
		for (j = head[from]; j != -1; j = edge[j].Next)
		{
			int to = edge[j].to;
			if (!vis[to] && dis[to] > dis[from] + edge[j].w)
			{
				dis[to] = dis[from] + edge[j].w;
				//更新，压入优先队列 
				q.push(make_pair(to, dis[to]));
			}
		}
	}
}
void solve()
{
	memset(head, -1, sizeof(head));
	int n,x,y;
	cin >> n>>x>>y;
	int i;
	for (i = 2; i <= n; i++)
	{
		add_edge(i, i - 1,1);
		add_edge(i-1,i,1);
	}
	add_edge(x, y, 1);
	add_edge(y, x, 1);
	int j;

	for (i = 1; i <= n; i++)
	{
		dijkstra(i);
		for (j = 1; j <= n; j++)
		{
			if (i == j) continue;
			else cnt[dis[j]]++;
		}
	}
	for (i = 1; i <= n - 1; i++) cout << cnt[i]/2 << endl;
}
int main()
{
	solve();
	return 0;
}


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

int main(){
  long N;
  cin >> N;
  vector<long> A(N);
  vector<long> numC(N, 0);
  vector<long> com;
  bool enable = true;
  int num = 0;
  for(long i = 0; i < N; i++){
    cin >> A[i];
    // cout << "i " << i << endl;
    if(A[i] > i){
      enable = false;
      break;
    }
    if(A[i] == 0){
      numC[1]++;
      if(3-num != 1) com.push_back(3-num);
      num++;
    }
    else{
      if(numC[A[i]] == 0){
        enable = false;
        break;
      }
      else{
        if(numC[A[i]] != 1) com.push_back(numC[A[i]]);
        numC[A[i]]--;
        numC[A[i]+1]++;
      }
    }
    if(num > 3){
      enable = false;
      break;
    }
  }
  long long ans = 1;
  if(!enable) cout << 0 << endl;
  else{
    for(long i = 0; i < com.size(); i++){
      // cout << "i = " << i << ", com = " << com[i] << endl;
      ans *= com[i];
      ans %= 1000000007;
    }
    cout << ans << endl;
  }
}


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


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

    int a,b;
    cin >> a >> b;
    if (a * b % 2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  ll X, Y;
  cin >> X >> Y;
  if (abs(X - Y) <= 1) {
    cout << "Brown" << endl;
  } else {
    cout << "Alice" << endl;
  }
  return 0;
}
int naive(int x, int y) {
  int res = 0;
  for (int i = 1; i*2 <= x; i++) {
    if (naive(x - i*2, y+i) == 0) {
      return 1;
    }
  }
  for (int i = 1; i*2 <= y; i++) {
    if (naive(x+i, y-2*i) == 0) {
      return 1;
    }
  }
  return res;
}
int main() {

  // REP(x, 10) {
    // REP(y, 10) {
      // cout << naive(x, y) << " ";
    // }
    // cout << endl;
  // }
  // return 0;

  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(a < b && b < c){
			System.out.printf("Yes\n");
		}else{
			System.out.printf("No\n");
		}
	}
}


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

int main()
{
int n;
while(cin>>n)
{
int combo = 0;
for(int a=0;a<=9;++a)
{
for(int b=0;b<=9;++b)
{
for(int c=0;c<=9;++c)
{
for(int d=0;d<=9;++d)
{
if(a+b+c+d==n)
++combo;
}
}
}
}
cout<<combo<<endl;
}
return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    map<string, ll> mp;
    rep(i, n){
        string s; cin >> s;
        sort(all(s));
        mp[s]++;
    }
    ll res = 0;
    for(auto a: mp){
        ll num = a.second;
        res += (num * (num - 1))/2;
    }
    cout << res << ln;
}
    


Measured memory_bytes: 11352
q = int(input())
n = 10**5+1
p = [0]*n
p[2] = 1
for i in range(3,10**5+1):
  prime = 1
  for j in range(2, int(i**0.5)+1):
    if i%j==0:
      prime = 0
      break
  if prime:
    p[i] = 1

like2017 = [1 if p[i] and p[(i+1)//2] else 0 for i in range(n)]
cnter = [0]*n
for i in range(1,n):
  cnter[i] = cnter[i-1]+ like2017[i]

for _ in range(q):
  ans = 0
  l, r = map(int, input().split())
  ans = cnter[r]-cnter[l-1]
  print(ans)

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

using vi = std::vector<int64_t>;
using vvi = std::vector<vi>;
using vvvi = std::vector<vvi>;

int K;
std::vector<int> N;
vvvi dp;

int64_t rc(int, int, bool);

int main()
{
	std::string n_str;
	std::cin >> n_str >> K;
	N.resize(n_str.size());
	for (int i{}; i < (int)n_str.size(); i++)
		N[i] = n_str[i] - '0';
	dp.resize(K, vvi(N.size(), vi(2, -1)));
	printf("%lld\n", rc(0, 0, false));

	return 0;
}

int64_t rc(int num_i, int N_i, bool free)
{
	if (num_i == K) return 1;
	if (N_i == N.size()) return 0;
	auto& ret{dp[num_i][N_i][free]};
	if (ret >= 0) return ret;
	ret = 0;
	for (int i{N_i}; i < N.size(); i++)
	{
		if (free)
			ret += 9 * rc(num_i + 1, i + 1, true);
		else
		{
			ret += std::max(0, N[i] - 1) * rc(num_i + 1, i + 1, true);
			if (N[i] != 0) ret += rc(num_i + 1, i + 1, false);
		}
		if (N[i] != 0) free = true;
	}
	
	return ret;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
using namespace std;
bool dp[1000001] = {};
int sosuu() {
	dp[1] = true;
	for (int i = 2;i <= 1000;++i) {
		if (dp[i] == false) {
			for (int q = 2;q <= 1000000 / i + 1;++q) {
				dp[i*q] = true;
			}
		}
	}
	return 0;
}
int main() {
	sosuu();
	int n = 0;
	while (cin >> n) {
		int count = 0;
		for (int i = 1;i <= n;++i) {
			if (dp[i] == false) count++;
		}
		printf("%d\n", count);
	}
}


Measured memory_bytes: 2120
#include<stdio.h>
#include<string.h>
int main()
{
	int m,n;
	char a[1000],b[1000];
	scanf("%s %s",a,b);
	m=strlen(a);
	n=strlen(b);
	if(m>n)
	{
		printf("GREATER\n");
	}
	else if(m<n)
	{
		printf("LESS\n");
	}
	else if(m==n)
	{
		if(strcmp(a,b)>0)
			printf("GREATER\n");
		else if(strcmp(a,b)<0)
			printf("LESS\n");
		else if(strcmp(a,b)==0)
			printf("EQUAL\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.List;
import java.util.ArrayList;

import java.util.Scanner;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        while (sc.hasNext()) {
            String s = sc.next();
            if (isOperand(s)) {
                int a = stack.pop();
                int b = stack.pop();
                switch(s) {
                    case "+":
                        stack.push(a+b);
                        break;
                    case "-":
                        stack.push(b-a);
                        break;
                    case "*":
                        stack.push(a*b);
                        break;
                }
            } else {
                stack.push(Integer.parseInt(s));
            }
        }
        
        System.out.println(stack.pop());
    }
    
    static boolean isNumber(String s) {
        try {
            Integer.parseInt(s);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
    
    static boolean isOperand(String s) {
        return s.equals("+") || s.equals("-") || s.equals("*");
    }
}

class Stack<T> {
    private List<T> list;
    
    public Stack() {
        list = new ArrayList<>();
    }
    
    public void push(T t) {
        list.add(t);
    }
    
    public T pop() {
        T t = list.get(list.size()-1);
        list.remove(list.size()-1);
        return t;
    }
    
    public boolean isEmpty() {
        return list.isEmpty();
    }
}

Measured memory_bytes: 26180
#include<bits/stdc++.h>
using namespace std;
struct node{int l,r;}c[15],d[15];
bool cmp(node x,node y){return x.l<y.l;}
int const p=998244353;
int f[200005],s[200005];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++)scanf("%d%d",&c[i].l,&c[i].r);
    sort(c+1,c+k+1,cmp);
    int nowl=c[1].l,nowr=c[1].r,sum=0;
    for(int i=2;i<=k;i++)
        if(c[i].l<=nowr)nowr=max(nowr,c[i].r);
        else d[++sum]=node{nowl,nowr},nowl=c[i].l,nowr=c[i].r;
    d[++sum]=node{nowl,nowr};
    f[1]=s[1]=1;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=sum;j++)
        {
            int l=max(1,i-d[j].r),r=i-d[j].l;
            if(l<=r)f[i]=(1ll*f[i]+s[r]-s[l-1]+p)%p;
        }
        s[i]=(s[i-1]+f[i])%p;
    }
    cout<<f[n];
    return 0;
}

Measured memory_bytes: 5216
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;
long long ab(long long a)
{
	if (a<0)	return -a;
	return a;
}
int main()
{
	int n;
	long long num1=0,num2=0;
	int t;
	cin >> n;
	vector<long long> ai;
	for(t=0;t<n;t++)
	{
		int a;
		cin >> a;
		ai.push_back(a);
		num2 += ai[t];
	}
	long long min;
	for(t=0;t<n-1;t++)
	{
		num1 += ai[t];
		num2 -= ai[t];
		if(t==0)	min = ab(num2-num1);
		if(ab(num2-num1) < min)	min = ab(num2-num1);
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int INF = 100050;
const int MAX_N = 100050;
int n, u, v;
vi adj[MAX_N];

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n >> u >> v;
	rep(i,0,n-1) {
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}

	queue<int> q;

	vi c(n+1, -1);
	c[u] = 0;
	q.push(u);
	while(!q.empty()) {
		int here = q.front();
		q.pop();
		for(auto there:adj[here]) {
			if(c[there] == -1) {
				c[there] = c[here] + 1;
				q.push(there);
			}
		}
	}

	vi d(n+1, -1);
	d[v] = 0;
	q.push(v);
	while(!q.empty()) {
		int here = q.front();
		q.pop();
		for(auto there:adj[here]) {
			if(d[there] == -1) {
				d[there] = d[here] + 1;
				q.push(there);
			}
		}
	}

	int mx = 0;
	rep(i,1,n+1) {
		if(adj[i].size() > 1) continue;
		if(c[i] >= d[i]) continue;
		int x = c[i];
		int y = d[i];
		int ret = x;
		y = y - x;
		ret += y-1;
		mx = max(mx, ret);
	}
	cout << mx << '\n';
	return 0;
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
Int flg=0;
Int expr(string &s,Int &p,Int pos);
Int factor(string &s,Int &p,Int pos);
Int number(string &s,Int &p);

const Int LIM = 1e8;
Int expr(string &s,Int &p,Int pos){
  Int res=factor(s,p,pos);
  if(flg) return -1;
  pos-=res;

  while(p<(Int)s.size()&&s[p]!=')'){
    Int len=factor(s,p,pos);
    if(flg) return -1;
    res+=len;
    pos-=len;
  }
  return max(min(res,LIM),-LIM);
}

Int factor(string &s,Int &p,Int pos){
  if(isupper(s[p])){
    if(0<=pos&&pos<1){
      cout<<s[p]<<endl;
      flg=1;
      return -1;
    }
    p++;
    return 1;
  }
  assert(isdigit(s[p]));

  Int num=number(s,p);

  if(isalpha(s[p])){
    if(0<=pos&&pos<num){
      cout<<s[p]<<endl;
      flg=1;
      return -1;
    }
    p++;
    return num;
  }
  //cout<<s<<" "<<p<<" "<<pos<<":"<<s[p]<<endl;

  assert(s[p]=='(');
  p++;

  Int b=p;
  Int res=expr(s,p,-1);
  assert(!flg);

  assert(s[p]==')');
  p++;

  if(0<=pos&&pos<num*res){
    expr(s,b,pos%res);
    assert(flg);
    return -1;
  }

  return max(min(num*res,LIM),-LIM);
}

Int number(string &s,Int &p){
  Int res=0;
  while(isdigit(s[p])){
    res=res*10+(s[p]-'0');
    p++;
  }
  return res;
}

signed main(){
  string s;
  Int pos;
  while(cin>>s>>pos,s!="0"){
    flg=0;
    Int p=0;
    expr(s,p,pos);
    if(!flg) cout<<0<<endl;
  }
  return 0;
}



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

int main() {

  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vector<int> p(A);
  vector<int> q(B);
  vector<int> r(C);

  for(auto &pp : p){
    cin >> pp;
  }
  for(auto &qq : q){
    cin >> qq;
  }
  for(auto &rr : r){
    cin >> rr;
  }

  sort(p.begin(), p.end(), greater<int>());
  sort(q.begin(), q.end(), greater<int>());
  sort(r.begin(), r.end(), greater<int>());

  vector<int> eat(X + Y);
  for(int i = 0; i < X; i++){
    eat[i] = p[i];
  }
  for(int i = 0; i < Y; i++){
    eat[X + i] = q[i];
  }

  sort(eat.begin(), eat.end(), greater<int>());
  for(int i = 0; i < C; i++){
    if(eat[X + Y - 1 - i] < r[i]){
      eat[X + Y - 1 - i] = r[i];
    }else{
      break;
    }
  }
  long long sum = 0;
  for(int i = 0; i < X + Y; i++){
    sum += eat[i];
  }

  cout << sum << endl;
}

Measured memory_bytes: 2176
bord = []

h, w = gets.chomp.split.map(&:to_i)
h.times do
  bord << gets.chomp.split('')
end

flag = true
h.times do |i|
  w.times do |j|
    if bord[i][j] == '#'
      f = false
      f = true if i - 1 >= 0 && bord[i-1][j] == '#'
      f = true if j + 1 < w && bord[i][j+1] == '#'
      f = true if i + 1 < h && bord[i+1][j] == '#'
      f = true if j - 1 >= 0 && bord[i][j-1] == '#'
      flag = flag && f
    end
  end
end

puts flag ? 'Yes' : 'No'

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

using namespace std;

const int MAXN = 105;
char matrix[MAXN][MAXN];
bool removablesV[MAXN];
bool removablesH[MAXN];

int main() {
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++){
        removablesH[i] = false;
        cin >> matrix[i];
    }
    for (int j = 0; j < w; j++){
        removablesV[j] = false;
    }
    bool changed = true;
    while (changed) {
        changed = false;
        for (int i = 0; i < h; i++) {
            if (removablesH[i])
                continue;
            bool removable = true;
            for (int j = 0; j < w; j++) {
                if (matrix[i][j] == '#') {
                    removable = false;
                    break;
                }
            }
            removablesH[i] = removable;
            changed = removable || changed;
        }
        for (int i = 0; i < w; i++) {
            if (removablesV[i])
                continue;
            bool removable = true;
            for (int j = 0; j < h; j++) {
                if (matrix[j][i] == '#') {
                    removable = false;
                    break;
                }
            }
            removablesV[i] = removable;
            changed = removable || changed;
        }
    }
    for (int i = 0; i < h; i++){
        if (removablesH[i])
            continue;
        for (int j = 0; j < w; j++){
            if (!removablesV[j])
                cout << matrix[i][j];
        }
        cout << endl;
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1e9 + 10;//10^9
ll MOD  = 1000000007;
int dy[] = {0,0,1,-1};
int dx[] = {1,-1,0,0};

int main(void){
    int N, Q;
    cin >> N >> Q;
    vector<tuple<int, int, int>> a(N);
    for(int i = 0; i < N; i++){
        int x, l, r;
        cin  >> l >> r >> x;
        get<0>(a[i]) = x;
        get<1>(a[i]) = l - x;
        get<2>(a[i]) = r - x;
    }
    sort(a.begin(), a.end());
    
    vector<ll> d(Q);
    for(int i = 0; i < Q; i++) cin >> d[i];
    
    set<P> Set;
    for(int i = 0; i < Q; i++){
        Set.insert({d[i], i});
    }
    
    vector<ll> ans(Q, -1);
    for(int i = 0; i < N; i++){
        int x, l, r;
        tie(x, l, r) = a[i];
        auto it = Set.lower_bound(P(l, -1));
        while(it != Set.end()){
            if(it -> first >= r) break;
            ans[it -> second] = x;
            Set.erase(it++);
        }
    }
    for(int i = 0; i < Q; i++){
        cout << ans[i] << endl;
    }
    
}



Measured memory_bytes: 16768
// D.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <map>

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	int gc = 0, pc = 0, score = 0;
	for (char c : s) {
		if (c == 'g') {
			if (gc > pc) {
				++pc;
				++score;
			} else {
				++gc;
			}
		} else {
			if (gc > pc) {
				++pc;
			} else {
				++gc;
				--score;
			}
		}
	}
	cout << score << endl;
	return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vi x(m), y(m-1);
  rep(i,m) cin >> x.at(i);
  sort(x.begin(),x.end());
  rep(i,m-1) y.at(i) = abs(x.at(i+1) - x.at(i));
  sort(y.begin(),y.end());
  int ans = 0;
  rep(i,m-n) ans += y.at(i);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3972
#include <iostream>
using namespace std;
const long long int mN = 1 << 20;
long long int Atree[2*mN];
bool zero[2*mN];

void init(){
  for(int i = 0; i < mN*2;i++){
    Atree[i] = 0;
    zero[i] = true;
  }
}
void input(long long int n,long long int k){
  for(int i = 0; i < n; i++){
    cin >> Atree[mN-1+i];
    if(Atree[mN-1+i] == 0){
      zero[mN-1+i] = false;
    }
    Atree[mN-1+i]%=k;
  }
  for(int i = mN - 2; i >= 0; i--){
    if(zero[i*2+1] && zero[i*2+2]){
      Atree[i] = Atree[i*2+1]+Atree[i*2+2];
      Atree[i] %= k;
      zero[i] = true;
    }else
      if(!zero[i*2+1] && zero[i*2+2]){
	Atree[i] =Atree[i*2+1] - Atree[i*2+2];
	Atree[i] %= k;
	zero[i] = false;
      }else
	if(zero[i*2+1] && !zero[i*2+2]){
	  Atree[i] = Atree[i*2+1] + Atree[i*2+2];
	  Atree[i] %= k;
	  zero[i] = false;
	}else{
	  Atree[i] =Atree[i*2+1] - Atree[i*2+2];
	  Atree[i] %= k;
	  zero[i] = true;
	}
  }
}

void change(int i, long long int aa,bool zz,long long int k){
 
  i+=mN-1;
  Atree[i] = aa;
  zero[i] = zz;
  while(i>0){
    i = (i-1)/2;
      if(zero[i*2+1] && zero[i*2+2]){
	Atree[i] = Atree[i*2+1]+Atree[i*2+2];
	Atree[i] %= k;
	zero[i] = true;
      }else
	if(!zero[i*2+1] && zero[i*2+2]){
	  Atree[i] =Atree[i*2+1] - Atree[i*2+2];
	  Atree[i] %= k;
	  zero[i] = false;
	}else
	  if(zero[i*2+1] && !zero[i*2+2]){
	    Atree[i] = Atree[i*2+1] + Atree[i*2+2];
	    Atree[i] %= k;
	    zero[i] = false;
	  }else{
	    Atree[i] =Atree[i*2+1] - Atree[i*2+2];
	    Atree[i] %= k;
	    zero[i] = true;
	  }
  }
}
int main(){
  long long int n,k,q;
  long long int al,ar;
  bool zl,zr;
  cin >> k >> n >> q;
  init();
  input(n,k);

  for(int i = 0; i < q; i++){
    int l,r;
    cin >> l >> r;
    l--;
    r--;
    al = Atree[mN-1+l];
    ar = Atree[mN-1+r];
    zl = zero[mN-1+l];
    zr = zero[mN-1+r];
    change(l,ar,zr,k);
    change(r,al,zl,k);
    int ans;
    int move = 0;
 
    if(zero[0]){
      ans = 1;
      Atree[0] %= k;
      move = k - Atree[0];
      move %= k;
      ans += move;
    }else{
      ans = -1;
      Atree[0] %= k;
      move = k-Atree[0];
      move %= k;
      ans -= move;
    }
    cout << ans << endl;
  } 
}



Measured memory_bytes: 21552
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int mi=10000000,k=0,sums=0,sum=0,co=0;
  vector<int> a(5);
  for(int i=0;i<5;++i){
    cin>>a[i];
    sums+=a[i];
    if(a[i]%10==0){
      a[i]-=10;
      ++co;
    }
    if(mi>a[i]%10&&a[i]%10!=0){
      mi=a[i]%10;
      k=i;
    }
  }
  if(co==5){
    cout<<sums<<endl;
    return 0;
  }
  for(int i=0;i<5;++i){
    if(i!=k){
      sum+=(a[i]+(10-a[i]%10));
    }
  }
  cout<<sum+a[k]<<endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

string s, t;
int len;

void input() {
	cin >> s >> t;
	len = s.length();
}

string solve() {
	char baseChar;
	for (char c = 'a'; c <= 'z'; c++) {
		baseChar = '-';
		for (int i = 0; i < len; i++) {
			if (s.at(i) == c) {
				if (baseChar == '-') baseChar = t.at(i);
				if (t.at(i) != baseChar) return "No";
			}
		}
		baseChar = '-';
		for (int i = 0; i < len; i++) {
			if (t.at(i) == c) {
				if (baseChar == '-') baseChar = s.at(i);
				if (s.at(i) != baseChar) return "No";
			}
		}
	}
	return "Yes";
}

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

	input();
	cout << solve() << "\n";

	return 0;
}

Measured memory_bytes: 916
#include<stdio.h>
int main(){
	int A,B,K,i,C;
	scanf("%d %d %d",&A,&B,&K);
	for(i=0;i<K;i++){
		if(A%2!=0){
		A=A-1;
	}
		B=B+A/2;
		A=A/2;
		C=A;
		A=B;
		B=C;
	}
	if(K%2==0){
		printf("%d %d",A,B);
	}
	else{
		printf("%d %d",B,A);
	}
	return 0;
} 

Measured memory_bytes: 128
package main
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
    sc.Scan()
    i, err := strconv.Atoi(sc.Text())
    if err != nil {
        panic(err)
    }
    return i
}

func main(){
    sc.Split(bufio.ScanWords)
    n := nextInt()
    k := nextInt()
    q := nextInt()
    
    m := map[int]int{}
    for i := 0; i < q; i++ {
        m[nextInt()]++
    }
    for i := 0; i < n; i++ {
        if m[i+1] > (q - k) {
            fmt.Println("Yes")
        } else {
            fmt.Println("No")
        }
    }
}


Measured memory_bytes: 7296
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005

int main()
{
    fastread;
    int n,m;
    cin>>n>>m;
    if(n == m)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;
    
    string ans = "";
    rep(i, S.size()) {
        if (i % 2 == 0) ans.push_back(S[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}


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

	string s;
	cin >> s;

	vector<set<int>> is(26);
	rep(i, n) is[s[i] - 'a'].insert(i);
	int q;
	cin >> q;
	rep(_, q)
	{
		int query;
		cin >> query;
		if (query == 1){
			int i;
			char c;
			cin >> i >> c;
			i--;
			is[s[i] - 'a'].erase(i);
			s[i] = c;
			is[s[i] - 'a'].insert(i);
		} else {
			int l, r;
			cin >> l >> r;
			l--;
			r--;
			int ans = 0;
			rep(j,26){
				auto it = is[j].lower_bound(l);
				if (it != is[j].end() && *it <= r)
					ans++;
			
			}
			cout << ans << endl;
		}
		
	}

	return 0;
}



Measured memory_bytes: 24196
import heapq
H,W = map(int, input().split())
C = []
for i in range(10):
    C.append(list(map(int, input().split())))
INF = float("inf")

def dfs(x):
    memo = [INF]*10
    memo[x] = 0
    hq = [(0,x)]
    heapq.heapify(hq)
    while hq:
        cost,step = heapq.heappop(hq)
        if cost > memo[step]:
            continue
        for j,c in enumerate(C[step]):
            if memo[j] > memo[step] + c:
                memo[j] = memo[step] + c
                heapq.heappush(hq,(memo[j],j))
    return memo[1]

A = [0]*10
for h in range(H):
    for w in map(int, input().split()):
        if w == -1:
            continue
        else:
            A[w] += 1
ans = 0
for number, a in enumerate(A):
    ans += a*dfs(number)
print(ans)

Measured memory_bytes: 9108
import math
M = 256

def entropy_if_smallest(ctr,bound):
    ret = 0
    for v in ctr:
        if v == 0: continue
        ret -= (v / N) * math.log2(v / N)
        if ret >= bound:
            return None
    return ret

def solve(src):
    ans_h = float('inf')
    ans = None
    for s in range(16):
        for a in range(16):
            for c in range(16):
                ctr = [0] * M
                r = s
                for i in src:
                    r = (a*r + c) % M
                    o = (i + r) % M
                    ctr[o] += 1
                h = entropy_if_smallest(ctr,ans_h)
                if h is not None:
                    ans = (s,a,c)
                    ans_h = h
                    if ans_h == 0:
                        return ans
    return ans

while True:
    N = int(input())
    if N == 0: break
    src = list(map(int,input().split()))
    print(' '.join(map(str,solve(src))))

Measured memory_bytes: 5704
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{
	auto tokens = my_readln().split();
	auto N = tokens[0].to!uint;
	long[] a;
	foreach (token; my_readln.split)
	{
		a ~= token.to!long;
	}

	auto dp = new long[][](3005, 3005);

	foreach_reverse (i; 0..N)
	{
		foreach (j; i+1..N+1)
		{
			long turn = (N - (j - i)) % 2 == 0 ? 1 : -1; 
			auto r1   = dp[i][j-1] + a[j-1] * turn;
			auto r2   = dp[i+1][j] + a[i] * turn;
			auto r    = turn == 1 ? max(r1, r2) : min(r1, r2);
			dp[i][j]  = r;
		}
	}

	writeln(dp[0][N]);
	stdout.flush();
}

Measured memory_bytes: 74492
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n;
	cin >> n;
	if (n >= 30)print("Yes");
	else print("No");
}

Measured memory_bytes: 3632
import math
n, m = map(int, input().split())

if n - 2 < 0:
    a = 0
else:
    a = math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
if m - 2 < 0:
    b = 0
else:
    b = math.factorial(m) // (math.factorial(m - 2) * math.factorial(2))
print(a + b)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int arr[] = new int[a];
        long t = 0;
        for (int i = 0;i < a;++i){
            arr[i] = scanner.nextInt() - i;
            t += arr[i];
        }
        Arrays.sort(arr);
        int k = arr[(a - 1) / 2];
        long f = 0;
        for (int i = 0;i < a;++i){
            f += Math.abs(arr[i] - k);
        }
        System.out.println(f);
    }
}


Measured memory_bytes: 89456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,p;cin>>a>>p;
  print((a*3+p)/2);
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    vector<ll> z(n);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> z[i];
        ans += z[i]-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604