akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int p[10000];
int main()
{
	MaRiaMa;
	int n, m,k=0;
	cin >> n >> m;
	vector<pair<int, int>>l(n);
	vector<pair<int, int>>h(m);
	for (int i = 0; i < n; i++)
	{
		cin >> l[i].first >> l[i].second;
	}
	for (int j = 0; j < m; j++)
	{
		cin >> h[j].first >> h[j].second;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
		    p[k] = abs(l[i].first - h[j].first) + abs(l[i].second - h[j].second);
			k++;
		}
		for (int m = 0; m < k; m++)
		{
			if (p[m] == *min_element(p, p+k))
			{
				cout << m + 1<<e;
				break;
			}
		}
		k = 0;
	}
}

Measured memory_bytes: 3500
X = int(input())

if 400 <= X <= 599:
    print(8)
elif 600 <= X <= 799:
    print(7)
elif 800 <= X <= 999:
    print(6)
elif 1000 <= X <= 1199:
    print(5)
elif 1200 <= X <= 1399:
    print(4)
elif 1400 <= X <= 1599:
    print(3)
elif 1600 <= X <= 1799:
    print(2)
elif 1700 <= X <= 1999:
    print(1)

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

const int INF = 1000000000;

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

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

		int C[100][100];
		int T[100][100];
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				if(i==j){
					C[i][j] = T[i][j] = 0;
				}
				else{
					C[i][j] = T[i][j] = INF;
				}
			}
		}

		for(int i=0; i<n; i++){
			int a, b, c, t;
			cin >> a >> b >> c >> t;

			C[a-1][b-1] = C[b-1][a-1] = c;
			T[a-1][b-1] = T[b-1][a-1] = t;
		}

		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(C[i][j]>C[i][k]+C[k][j]){
						C[i][j]=C[i][k]+C[k][j];
					}
				}
			}
		}

		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
					}
				}
			}
		}
		
		int k;
		cin>>k;
		int p,q,r;

		for(int i=0;i<k;i++){
			cin>>p>>q>>r;
			if(r==0){
				cout<<C[p-1][q-1]<<endl;
			}
			if(r==1){
				cout<<T[p-1][q-1]<<endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3132
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;

ll LayerOfBurger(int N){
  ll answer;
  if(N==0) return 1;
  else{
    answer=3+2*LayerOfBurger(N-1);
    return answer;
  }
}

ll NumberOfPatti(int N, ll X){
  if(N==0) return 1;
  if(X==1) return 0;
  else if(1<X && X<LayerOfBurger(N)/2+1){
    return NumberOfPatti(N-1,X-1);
  }
  else if(X==LayerOfBurger(N)/2+1){
    return NumberOfPatti(N-1,LayerOfBurger(N-1))+1;
  }
  else if(LayerOfBurger(N)/2+1<X && X<LayerOfBurger(N)){
    return NumberOfPatti(N-1,LayerOfBurger(N-1))+1+NumberOfPatti(N-1,X-2-LayerOfBurger(N-1));
  }
  else if(X==LayerOfBurger(N)){
    return 1+2*NumberOfPatti(N-1,LayerOfBurger(N-1));
  }
}

int main(){
  int N;
  ll X;

  scanf("%d%lld",&N,&X);
  printf("%lld\n",NumberOfPatti(N,X));

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0 ; i<(n) ; ++i)
typedef long long ll;
using namespace std;
//const ll MAX = 2500LL;
typedef pair <ll, ll> P;
const ll MX = 1e18;

int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main(){
  int n;
  cin >> n;
  ll ans=1;
  vector<ll> a_hai;
  bool flag=false;
  rep(i,n){
    ll a;
    cin >> a;
    if(a==0){
      cout << 0 << endl;
      return 0;
    }
    //a_hai.push_back(a);
    if(flag || MX/a < ans || a*ans > MX){
      flag=true;
      //cout << -1 << endl;
      //return 0;
    }
    ans *= a;
  }
  if(flag) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    int n;
    cin >> n;
    vi h(n);
    vi cost(n);
    rep(i,n) cin >> h[i];
    rep(i,n){
        if(i==0) cost[i]=0;
        else if(i==1) cost[i]=abs(h[i]-h[i-1]);
        else{
            cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]));
        }
    }
    cout << cost[n-1] <<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{

string s;

cin>>s;

if(s=="SUN")
    cout<<"7";
    else if (s=="MON")
    cout<<"6";
        else if (s=="TUE")
    cout<<"5";
      else if (s=="WED")
    cout<<"4";
      else if (s=="THU")
    cout<<"3";
      else if (s=="FRI")
    cout<<"2";
      else if (s=="SAT")
    cout<<"1";

return 0;
}


Measured memory_bytes: 256
def f(A,B,K):
    a=A-min(A,K)
    b=B-(K-min(A,K))
    if b<0: 
        b=0
    return a,b
A,B,K= map(int,input().split())
a=f(A,B,K)
print(a[0],a[1])

Measured memory_bytes: 3060
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;
int32_t K;
int32_t X[200];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>K;
	int64_t res = 0;
	for (int32_t i = 0; i < N; i++)
	{
		int a;
		in >> a;
		res += std::min(K - a, a);
	}
	out << res*2 << endl;
	return 0;
}
#endif


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

int main()
{
    string s,ans="No";
    cin >> s;
    vector<bool> f(3,false);
    REP(i,3){
        f.at(s.at(i) - 'a') = !f.at(s.at(i) - 'a');
    }
    if(f.at(0)&&f.at(1)&&f.at(2))
        ans = "Yes";
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <set>
#include <iomanip>
using namespace std;

 
int main(){
  long A, B, C, K;
  cin >> A >> B >> C >> K;
  if (A >= K){
    cout << K;
  }else if(A + B >= K){
    cout << A;
  }else{
    cout << A - (K - A - B);
  }
  return 0;
}

Measured memory_bytes: 3632
N = int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(N-2):
    p = P[i:i+3]
    if (p[0] < p[1] < p[2]) or (p[0]>p[1]>p[2]):
        ans += 1
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
typedef vector<int>		vi;
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=1000000007;

int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
   
    lli x;
	cin>>x;
	lli n=log2(x);
	lli ani=(lli)(pow(2,n+1)-1);
	cout<<ani;
	
}

Measured memory_bytes: 512
import itertools
n=int(input())
a=list(map(int,input().split()))

sumx=[0]+list(itertools.accumulate(a))

dp=[[0]*(n+1) for i in range(n+1)]

for distance in range(2,n+1):
  for i in range(n-distance+1):
    j=i+distance
    dp[i][j]=sumx[j]-sumx[i]+min(dp[i][k]+dp[k][j] for k in range(i+1,j))

print(dp[0][-1])


Measured memory_bytes: 75388
from itertools import groupby, accumulate
S = input()

s = [len(list(j)) for i, j in groupby(S)]

ans = ["0"] * len(S)
ss = list(accumulate(s))

for i in range(len(s))[::2]:
    ans[ss[i]-1] = str(((s[i] // 2) + (s[i] % 2)) + (s[i+1] // 2))
    ans[ss[i]] = str(((s[i+1] // 2) + (s[i+1] % 2)) + (s[i] // 2))

ans = " ".join(ans)
print(ans)

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

//#define int long long
typedef long long ll;
const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> six(7);
    vector<int> nine(6);
    six[0] = 1;
    for (int i=1;i<7;i++){
        six[i] = six[i-1]*6;
    }
    nine[0] = 1;
    for (int i=1;i<6;i++){
        nine[i] = nine[i-1]*9;
    }
    vector<int> dp(N+1,INF);//i円以上になるときの回数の最小値
    dp[0] = 0;
    for (int i=0;i<N;i++){
        dp[i+1] = min(dp[i+1],dp[i]+1);
        for (int j=0;j<7;j++){
            if (i+six[j] <=N){
                dp[i+six[j]] = min(dp[i+six[j]], dp[i] + 1);
            }
        }
        for (int j=0;j<6;j++){
            if (i+nine[j]<=N){
                dp[i+nine[j]] = min(dp[i+nine[j]], dp[i] + 1);
            }
        }
    }
    int ans = INF;
    for (int i=0;i<=N;i++){
        ans = min(ans, dp[i] + N - i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n)
	{
		bitset<10> o = n;

		rep(i, 10)
			if(o[i])
				cout << pow(2.0, i) << (pow(2.0, i+1) < n ? " " : "");

		cout << endl;
	}
}

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

int main()
{
	int n;
	cin >> n;
	double p[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> p[i];
	}

	double dp[n+1][n+1], result = 0;
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		dp[0][i] = 0;
		dp[i][0] = dp[i-1][0] * (1-p[i-1]);
	}


	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= i; ++j)
		{
			dp[i][j] = dp[i-1][j-1] * (p[i-1]) + dp[i-1][j] * (1-p[i-1]);
		}
	}

	for (int i = ceil(n/2.0); i <= n; ++i)
	{
		result += dp[n][i];
	}

	cout << setprecision(12)<< result;
	return 0;
}

Measured memory_bytes: 70144
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin >> n;
  
  ll res = 0;
  if(n%2==1){
    cout << 0 << "\n";
    return 0;
  }
  ll a = 10;
  for(ll i=0;i<26;++i){
    res += n/a;
    a *= 5;
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    String S=gs()+gs()+gs()+gs();

	    //System.out.print((int)Math.pow(4, n));
	    if (S.contains("1") && S.contains("7") && S.contains("9") && S.contains("4")) {
	    	System.out.print("YES");
	    }else {
	    	System.out.print("NO");
	    }



	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main(){ 
  int N, M;
  cin >> N >> M;
  vector<int> P(100010), Y(100010);
  vector<vector<int>> yd(100010, vector<int>(0));
  
  rep(i, M){
    cin >> P.at(i) >> Y.at(i);
    yd.at(P.at(i)).push_back(Y.at(i));
  }
  rep(i, N) sort(yd.at(i+1).begin(), yd.at(i+1).end());
  rep(i, M){
    
    int ans1 = 1000000 + P.at(i);
    string ans11 = to_string(ans1);
    cout << ans11.substr(1);
    ans1 = 1000000 + lower_bound(yd.at(P.at(i)).begin(), yd.at(P.at(i)).end(), Y.at(i)) - yd.at(P.at(i)).begin() + 1;
    ans11 = to_string(ans1);
    cout << ans11.substr(1) << endl;
    
  }
}

Measured memory_bytes: 7808
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

ll read_long() {
    ll ans = 0;
    char c;
    bool started = false;
    bool is_negative = false;
    while (true) {
        c = getchar();
        if ((c < '0' || c > '9') && c != '-' && !started) continue;
        if ((c < '0' || c > '9') && c != '-' && started) break;
        if (started) {
            ans = ans * 10;
        }
        started = true;
        if (c == '-') is_negative = true;
        else ans += c - '0';
    }
    if (is_negative) ans *= -1;
    return ans;
}

int n, a, b;

void print(string s) {
    cout << s << endl;
    exit(0);
}

int main(){

    cin >> n >> a >> b;

    while (true) {
        if (a + 1 < b) a++;
        else if (a > 1) a--;
        else print("Borys");

        if (b - 1 > a) b--;
        else if (b + 1 < n) b++;
        else print("Alice");
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void trace(int A[], int N){
	int i;
	for(i=0; i<N; i++){
		if(i>0)
			printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void insertionSort(int A[], int N){
	int j, i, v;
	for(i=1; i<N; i++){
		v = A[i];
		j = i - 1;
		while(j>=0 && A[j]>v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		trace(A, N);
	}
}

int main(){
	int N, i, j;
	int A[100];
	
	scanf("%d", &N);
	for(i=0; i<N; i++)
		scanf("%d", &A[i]);
	trace(A, N);
	insertionSort(A, N);
	
	return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

constexpr ll MOD = 1e9+7;

namespace math { namespace integer {

ll mod_pow(ll x, ll n, ll mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(x * x % mod, n / 2, mod); } else { return x * mod_pow(x, n - 1, mod) % mod; } }
template<class T> T extgcd(T a, T b, T& x, T& y) { T d = a % MOD; if(b != 0) { d = extgcd(b % MOD, a % MOD % b % MOD, y, x); y -= (a / b) * x;} else { x = 1, y = 0; } return d; }
template<class T> T mod_inverse(T x, T mod) { return mod_pow(x, T(mod - 2), mod); /* use fermat */ }
template<class T> T mod_inverse_composite_num_mod(T a, ll mod) { T x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; }

}}
using namespace math::integer;

auto prime_factor = [](ll x){map<ll, int> xfact;for(int i=2; (ll)i*i<=x; i++) {while(x % i == 0) {xfact[i]++;x /= i;}}if(x > 1) xfact[x]++;return xfact;};

int main() {
  int N; cin >> N;
  vector<ll> A(N); cin >> A;
  ll x, y;
  map<ll, int> m;
  rep(i, N) {
    auto pf = prime_factor(A[i]);
    for (auto e: pf) {
      m[e.first] = max(m[e.first], e.second);
    }
  }
  ll lcm = 1;
  for (auto e: m) {
    rep(i, e.second) {
      (lcm *= e.first) %= MOD;
    }
  }
  ll ans = 0;
  rep(i, N) {
    ll b = lcm * mod_inverse(A[i], MOD) % MOD;
    (ans += b) %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  string s;
  cin >> s;
  int n = sz(s);
  int ans = INF;
  for (int i = 0; i <= n-3; ++i) {
    string ss = s.substr(i,3);
    chmin(ans, abs(stoi(ss)-753));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		System.out.println((int)Math.ceil((double)n/(d*2+1)));
	}
}

Measured memory_bytes: 21716
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	foreach (line; stdin.byLine) {
		auto w = line.chomp.to!double;
		string str;
		if (w <= 48) str = "light fly";
		else if (w <= 51) str = "fly";
		else if (w <= 54) str = "bantam";
		else if (w <= 57) str = "feather";
		else if (w <= 60) str = "light";
		else if (w <= 64) str = "light welter";
		else if (w <= 69) str = "welter";
		else if (w <= 75) str = "light middle";
		else if (w <= 81) str = "middle";
		else if (w <= 91) str = "light heavy";
		else str = "heavy";
		str.writeln;
	}
}

Measured memory_bytes: 1084
from collections import deque

int1 = lambda x: int(x) - 1

H, W = map(int, input().split())
Ch, Cw = map(int1, input().split())
Dh, Dw = map(int1, input().split())
S = [[0 if s == '.' else -1 for s in input()] for _ in range(H)]

d = deque([(Ch, Cw)])
cur = 1
while True:
    visited = set()
    while d:
        h, w = d.pop()
        visited.add((h, w))
        S[h][w] = cur
        if (h, w) == (Dh, Dw):
            print(cur - 1)
            exit()
        for dh, dw in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            if 0 <= h + dh < H and 0 <= w + dw < W and S[h + dh][w + dw] == 0:
                d.append((h + dh, w + dw))

    for h, w in visited:
        for dh in range(-2, 3):
            for dw in range(-2, 3):
                if 0 <= h + dh < H and 0 <= w + dw < W and S[h + dh][w + dw] == 0:
                    d.append((h + dh, w + dw))
    if not d:
        print(-1)
        exit()
    cur += 1


Measured memory_bytes: 92668
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
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(){
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3544
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 998244353
//priority_queue<int,vector<int>, greater<int> > q2;


ll comb(ll N_, ll C_) {
	const int NUM_ = 400001;
	static ll fact[400002], factr[400002], inv[400002];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mod, factr[i] = factr[i - 1] * inv[i] % mod;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mod*factr[N_ - C_] % mod;
}
ll modpow(ll a, ll n = mod - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mod, a = a * a%mod, n >>= 1;
	return r;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, A, B, K;
	cin >> N >> A >> B >> K;

	int ans = 0;

	eREP(i, N) {
		if ((K - A * i) % B == 0) {
			int x = i, y = (K - A * i) / B;
			ans += comb(N, i)*comb(N, y);
			ans %= mod;
		}
	}



	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 9600
require 'set'

### main

while true
  n, m = gets.strip.split(' ').map{|s| s.to_i}
  break if n == 0 && m == 0

  edges = []

  m.times.each do
    edge = gets.strip.split(' ').map{|s| s.to_i}
    edges << edge
  end

  edges.sort! do |a, b|
    (cmp2 = a[2] <=> b[2]) != 0 ? cmp2 :
      (cmp0 = a[0] <=> b[0]) != 0 ? cmp0 : a[1] <=> b[1]
  end

  nd0, nd1, c = edges.shift

  con = Set.new([nd0, nd1])
  cost = c

  while con.length < n && ! edges.empty?
    for e in edges
      nd0, nd1, c = e

      inc0 = con.include? nd0
      inc1 = con.include? nd1

      if inc0 || inc1
        if ! inc0
          con << nd0
          cost += c
        elsif ! inc1
          con << nd1
          cost += c
        end
        edges.delete e
        break
      end
    end
  end

  puts cost
end

Measured memory_bytes: 6212
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

using namespace std;
typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

struct edge{
  long long int to, cost;
  edge(long long int to_, long long int cost_){
    to = to_;
    cost = cost_;
  }
};

vector<edge> E[110000];
int ans[110000];

void func(int pos, int pre, long long int cost){
  ans[pos] = cost % 2;
  for(edge e : E[pos]){
    if(e.to != pre){
      func(e.to, pos, cost + e.cost);
    }
  }
}

int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N - 1; i++){
    long long int u, v, c;
    cin >> u >> v >> c;
    E[u].push_back(edge(v, c));
    E[v].push_back(edge(u, c));
  }
  func(1, -1, 0);
  for(int i = 1; i <= N; i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 10112
N,K = list(map(int, input().split(" ")))
p = input()
cnt = 0
for i in range(N):
  if p[i]=="L" and i!=0:
    if p[i]==p[i-1]:
      cnt += 1
  elif p[i]=="R" and i!=N-1:
    if p[i]==p[i+1]:
      cnt += 1
cnt += 2*K
if cnt>=N:
  cnt = N-1
print(cnt)

Measured memory_bytes: 3316
package main

import (
	"fmt"
)

func main() {
	var N, Q int
	var S string
	fmt.Scan(&N, &Q)
	fmt.Scan(&S)

	current := 0
	cnt := make([]int, N)
	for i := 1; i < N; i++ {
		if S[i-1:i+1] == "AC" {
			current++
		}
		cnt[i] = current
	}

	var l, r int
	for i := 0; i < Q; i++ {
		fmt.Scan(&l, &r)
		fmt.Println(cnt[r - 1] - cnt[l - 1])
	}
}


Measured memory_bytes: 6144
n,c,k = map(int,input().split())
t = [int(input()) for i in range(n)]
t.sort()
ans = 0
ct = t[0]
cc = 0
for i in range(n):
  if cc == c or ct + k < t[i]:
    ans += 1
    ct = t[i]
    cc = 1
  else:
    cc += 1
print(ans + 1)

Measured memory_bytes: 7384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long tnum;

#define loop(i, num) for(int i = 0; i < num; i++)

tnum* tnumAlloc(int num);
tnum getNumStdin();
tnum* getNumsStdin(int);
char* getCharsStdin(int maxlength);
string getStringStdin();
void printlnNums(int count, tnum* nums);
void printlnNum(tnum num);
void printString(string str);

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

/*void sort(T* start, T* end) (in <algorithm>)
example:
	int a[5] = {2, 1, 3, 5, 4};
	sort(a, a + 5);
	-> a: {1, 2, 3, 4, 5}
*/

int main() {
    tnum d, t, s;

    d = getNumStdin();
    t = getNumStdin();
    s = getNumStdin();

    if(d <= t * s){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}



//have to be free()
tnum* tnumAlloc(int num) {
	return (tnum*)calloc(num,sizeof(tnum));
}

tnum getNumStdin() {
	tnum ret;
	scanf("%lld", &ret);

	return ret;
}

Measured memory_bytes: 3824
def b_sort(n, l):
    cn = 0
    for i in range(n):
        for j in range(n-1, i, -1):
            if l[j] < l[j-1]:
                l[j], l[j-1] = l[j-1], l[j]
                cn += 1

    print(' '.join(map(str, l)))
    print(cn)


if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))
    b_sort(N, L)



Measured memory_bytes: 5600
#include <iostream>

#define SIZE 100000

typedef long long ll;

int N;
ll  A, B;
ll  X[SIZE];

ll solve() {
    ll ans = 0;
    for (int i=1; i<N; ++i) {
        ll dist = A * ( X[i] - X[i-1] );
        ans += std::min( dist, B );
    }
    return ans;
}

int main() {
    std::cin >> N >> A >> B;
    for (int i=0; i<N; ++i) std::cin >> X[i];
    std::cout << solve() << std::endl;
    return 0;
}

Measured memory_bytes: 1024
<?php
fscanf(STDIN, "%d %d %d %d", $a, $b, $c, $d);

$lcm = lcm($c, $d);

$a_lcm = intdiv($a-1, $lcm);
$b_lcm = intdiv($b, $lcm);
$x = $b_lcm - $a_lcm;

$a_c = intdiv($a-1, $c);
$b_c = intdiv($b, $c);
$y = $b_c - $a_c;    

$a_d = intdiv($a-1, $d);
$b_d = intdiv($b, $d);
$z = $b_d - $a_d; 

echo ($b - $a +1) - ($y + $z - $x);

function gcd($a, $b) {
     if ($b === 0){
        return $a; 
     }
    return gcd($b, $a % $b);
}

function lcm($a, $b) {
    return $a * $b / gcd($a, $b);
}

?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	string ans="";
	while(n>0){
		int r = (n-1)%26;
		ans+= r+'a';
		n = (n - r)/26;
	}
	reverse(begin(ans), end(ans));
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3608
n,m = gets.split.map(&:to_i)
ar = gets.split.map(&:to_i).sort
sets = []
m.times do
  sets << gets.split.map(&:to_i)
end

count = 0
sets.sort_by!{|a,b| -b}

sets.each do |a,b|
  break if count > n
  a.times do
    if ar[0] < b
      ar.shift
      ar << b
      count += 1
    else
      break
    end
  end
end

puts ar.inject(&:+)

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

using namespace std;

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

int main() {
	ll x;
	scanf("%lld", &x);
	ll ans = 0;
	
	ans = (x / 11);
	ans *= 2;
	if (0 < x % 11 && x % 11 <= 6) {
		ans++;
	} else if (6 < x % 11 && x % 11 < 11) {
		ans += 2;
	}
	cout << ans << endl;
	
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

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

    map<int, int> A;
    for (int i = 1; i <= 1e5; i++)
    {
        A[i] = 0;
    }

    ll all = 0;
    for (int i = 0; i < N; i++)
    {
        int num;
        cin >> num;

        A[num]++;
        all += num;
    }

    int Q;
    cin >> Q;

    int before, after;
    ll result = all;
    for (int i = 0; i < Q; i++)
    {
        cin >> before >> after;

        if (A.count(before))
        {
            A[after] += A[before];
            // result = result - (before * A[before]) + (after * A[before]);
            result += (after - before) * A[before];
            A[before] = 0;
        }
        printf("%lld\n", result);

        // debug
        // for (auto itr = A.begin(); itr != A.end(); itr++)
        // {
        //     cout << itr->first << " : " << itr->second << endl;
        // }
        // printf("\n");
    }
    return (0);
}

Measured memory_bytes: 8420
#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())

using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
template<typename T>T lcm(T a, T b){return a * b / gcd(a, b);}
static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=pow(10,9)+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位


class unionfind{
public:
	vector<int> table;
	void init(int size){
		table.resize(size);
		rep(i,size)table[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
};


int main(){
	cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(19);
	lint ans=inf;
	int n;
	in(n);
	vint x(n);
	in(x);
	rep(place,200){
		lint cost=0;
		rep(i,n){
			cost+=(x[i]-place)*(x[i]-place);
		}
		chmin(ans,cost);
	}
	out(ans);
	return 0;
}


Measured memory_bytes: 3588
#!/usr/bin/env python3
import heapq

N, M = list(map(int, input().split()))
a_list = list(map(int, input().split()))

# Pythonのheapqは最小値しかとれないので、負の値に変換して扱う
a_list = list(map(lambda x: x * (-1), a_list))
heapq.heapify(a_list)

for _ in range(M):
    max_value = -heapq.heappop(a_list)
    heapq.heappush(a_list, -(max_value // 2))

ans = -sum(a_list)
print(ans)


Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 100000000002
#define N 200004

char v[301][301];

int ans[301][301];

int32_t main()
{
    IOS;

   
        int n,m,k;
        cin >> n >> m >> k;
        int cnt = 0;
        vector<int> r(n,0);
        for(int i = 0;i < n;i++)
        {
            cnt = 0;
            for(int j = 0;j < m;j++)
            {
                cin >> v[i][j];
                if(v[i][j] == '#')
                    cnt++;
            }
            r[i] = cnt;
        }
        int cur = 1;
        for(int i = 0;i < n;i++)
        {
            if(r[i])
            {
                int seen = 1;
                for(int j = 0;j < m;j++)
                {
                    ans[i][j] = cur;
                    if(v[i][j] == '#')
                    {
                        if(seen)
                            seen = 0;
                        else
                           {
                                cur++;
                                ans[i][j] = cur;
                           }
                    }
                }
                cur++;
            }
            
        }
        for(int i = 1;i < n;i++)
        {
            for(int j = 0;j < m;j++)
            {
                if(ans[i][j] == 0)
                {
                    ans[i][j] = ans[i - 1][j];
                }
            }
        }
        for(int i = n - 2;i >= 0;i--)
        {
            for(int j = 0;j < m;j++)
            {
                if(ans[i][j] == 0)
                {
                    ans[i][j] = ans[i + 1][j];
                }
            }
        }
        for(int i = 0;i < n;i++)
        {
            for(int j = 0;j < m;j++)
            {
                cout << ans[i][j] << " ";
            }
            cout << endl;
        }

    return 0;

}
 
 

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n;
  string s,ss,sss;
  cin>>n;
  cin>>s>>ss;
  for(int i=0;i<n;i++){
    cout<<s[i]<<ss[i];
  }
  cout<<endl;
  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 n = sc.nextInt();

        int[] dp = new int[n+10];
        dp[0] = 0;
        for (int i = 1; i < dp.length; i++) {
            dp[i] = Integer.MAX_VALUE;

            int tmp = 1;
            while (tmp <= i) {
                dp[i] = Math.min(dp[i], dp[i - tmp] + 1);
                tmp *= 6;
            }

            tmp = 1;
            while (tmp <= i) {
                dp[i] = Math.min(dp[i], dp[i - tmp] + 1);
                tmp *= 9;
            }
        }

        System.out.println(dp[n]);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define N 500005
using namespace std;
int a[27][N],n;
void upd(int i, int j, int c){
    while(i<=n){
        a[j][i]+=c;
        i+=i&(-i);
    }
}
int ans(int i, int j){
    int s=0;
    while(i){
        s+=a[j][i];
        i-=i&(-i);
    }
    return s;
}
int main(){
    int q,x,y,sum=0;
    char anduegay;
    string s;
    cin>>n>>s>>q;
    for(int i=0; i<n; ++i){
        upd(i+1,s[i]-'a',1);
    }
    while(q--){
        cin>>x>>y;
        if(x==1){
            cin>>anduegay;
            upd(y,s[y-1]-'a',-1);
            upd(y,anduegay-'a',1);
            s[y-1]=anduegay;
        }
        else{
            cin>>x;
            sum=0;
            for(int j=0; j<26; ++j){
                sum+=bool(ans(x, j)-ans(y-1, j));
            }
            cout<<sum<<"\n";
        }
    }
    return 0;
}

Measured memory_bytes: 52100
#include <iostream>

using namespace std;

int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int ans = 0;
  for (int i = 0; i < A+1; i++){
    for (int j = 0; j < B+1; j++){
      for (int k = 0; k < C+1; k++){
        if (X == i * 500 + j * 100 + k * 50) ans++;
      }
    }
  }
  
  printf("%d\n",ans);
  
}


Measured memory_bytes: 3752
#import <stdio.h>

int c(double num) {
    long inum = (long)num;
    return (int)(inum + (((num != inum) && (num > 0)) ? 1 : 0));
}


int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d", c((double)(a+b)/2.0));
}


Measured memory_bytes: 7000
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

ll n, s;

ll f(ll b, ll n) {
	ll ret;
	if (n < b)
		return n;
	ret = f(b, n / b) + n % b;
	return ret;
}

ll solve() {
	ll ans=INF;
	if (n == s)
		return n + 1;
	if (s > n)
		return -1;
	for (ll b = 2; b*b <= n; b++) {
		if (s == f(b, n)) {
			return b;
		}
	}
	for (ll p = 1; p*p <= (n - s); p++) {
		if ((n - s) % p != 0)
			continue;
		ll b = 1 + (n - s) / p;
		if (s == f(b, n)) {
			ans = min(b, ans);
				

		}
	}
	if (ans == INF)
		ans = -1LL;
	return ans;
}

int main(){
	cin >> n >> s;
	
	cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int map[10][10];
int line[10] = {0};
vector<int> cx;		//x座標
vector<int> cy;		//y座標
vector<int> cz;		//大きさ
int dx[13] = { 0,-1, 0, 1, 0,-1,-1, 1, 1, 0,-2, 2, 0};
int dy[13] = {-1, 0, 0, 0, 1,-1, 1,-1, 1,-2, 0, 0, 2};
int ds[4] = { 0, 5, 9,13};

int saiki( int nokori[3], int x, int y, int size ) {
	if ( nokori[0] + nokori[1] + nokori[2] == 0 ) {
		for ( int i = 0; i < 10; i++ ) {
			for ( int j = 0; j < 10; j++ ) {
				if ( map[j][i] != 0 ) return 0;
			}
		}
		return 1;
	}
	for ( int i = y; i < 9; i++ ) {
		if ( i >= 3 ) {
			if ( line[ i-3 ] > 0 ) return 0;
		}
		for ( int j = x; j < 9; j++ ) {
			cx.push_back(j);
			cy.push_back(i);
			for ( int k = size; k < 3; k++ ) {
				bool f = true;
				for ( int l = 0 ; l < ds[k+1] ; l++ ) {
					if ( map[ j+dx[l] ][ i+dy[l] ] <= 0 ) f = false;
					map[ j+dx[l] ][ i+dy[l] ]--;
					line[ i+dy[l] ]--;
				}
				if ( f ) {
					cz.push_back( k+1 );
					nokori[k]--;
					if ( saiki( nokori, j, i, k ) ) return 1;
					nokori[k]++;
					cz.pop_back();
				}
				for ( int l = 0 ; l < ds[k+1] ; l++ ) {
					map[ j+dx[l] ][ i+dy[l] ]++;
					line[ i+dy[l] ]++;
				}
				if ( f == false ) break;
			}
			cx.pop_back();
			cy.pop_back();
			size = 0;
		}
		x = 1;
	}
	return 0;
}

int main(){
	int n;
	cin >> n;
	int sum = 0;
	for ( int i = 0; i < 10; i++ ) {
		for ( int j = 0; j < 10; j++ ) {
			cin >> map[j][i];
			line[i] += map[j][i];
			sum += map[j][i];
		}
	}
	int nokori[3] = {0};
	nokori[1] = n;
	if ( sum > n * 9 ) {
		nokori[2] = ( sum - n * 9 ) / 4;
		nokori[1] -= nokori[2];
	}else if ( sum < n * 9 ) {
		nokori[0] = ( n * 9 - sum ) / 4;
		nokori[1] -= nokori[0];
	}
	for ( int i = 0; i <= nokori[1] / 2; i++ ) {
		if ( saiki( nokori, 1, 1, 0 ) ) break;
		nokori[0]++;
		nokori[1]-=2;
		nokori[2]++;
	}
	for ( int i = 0; i < n; i++ ) {
		cout << cx[i] << " " << cy[i] << " " << cz[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		int n,m; cin >> n >> m;
		if(n==0&&m==0)break;
		vector<vector<int>> login(m,vector<int>(1300,0));
		int r; cin >> r;
		while(r--){
			int a,b,c,d; cin >> a >> b >> c >> d;
			c--;
			if(d==1){
				login[c][a+1]++;
			}else{
				login[c][a+1]--;
			}
		}
		for(int i=0;i<m;i++){
			for(int j=1;j<1300;j++){
				login[i][j]+=login[i][j-1];
			}
		}
		int query; cin >> query;
		while(query--){
			int a,b,c; cin >> a >> b >> c;
			c--;
			int res=0;
			for(int i=a+1;i<=b;i++){
				if(login[c][i])res++;
			}
			printf("%d\n",res );
		}
	}
}


Measured memory_bytes: 52408
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int n;
  cin>>n;
  int a[n];
  int ans=0;
  REP(i,n){
    cin>>a[i];
    ans += a[i];
  }
  ans -= n;
  cout<<ans<<endl;
  return 0;
}


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

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    char s;
    cin >>s;
    cout << (char)(s+1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
    int K,S,X,Y,Z,cnt;
    cin>>K>>S;
    for(X=0;X<=K;X++){
        for(Y=0;Y<=K;Y++){    
            int Z=S-Y-X;
            if(0<=Z&&Z<=K)
            cnt+=1;            
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
typedef long long int LL;
int main(){
	int n;
	int s=0;
	cin>>n;
	for(;n>0;n/=10){
		s+=n%10;
	}
	if(s==1)s=10;
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256