akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

int n,l;
cin >> n >> l;
vs s(n);
rep(i,n) cin >> s[i];
Sort(s);
rep(i,n) cout << s[i];
cout << endl;

//////////////////////////////////////////////////////
return 0;}

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

namespace ABC160
{
    class D
    {
        static void Main(string[] args)
        {
            var nxy = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var n = nxy[0]; var x = nxy[1] - 1; var y = nxy[2] - 1;
            var dist1 = new long[n, n];
            for (int i = 0; i < n; i++)
            {
                for (int j = i; j < n; j++)
                {
                    if (i != j)
                    {
                        dist1[i, j] = Math.Min(Math.Abs(j - i), Math.Abs(x - i) + 1 + Math.Abs(j - y));
                        //dist1[i, j] = Math.Min(dist1[i, j], Math.Abs(y - i) + 1 + Math.Abs(j - x));
                    }
                }
            }

            /*
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.Write(dist1[i, j]);
                }
                Console.WriteLine();
            }
            */

            var res = new long[n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    res[dist1[i, j]]++;
                }
            }

            for (int i = 1; i < n; i++)
            {
                Console.WriteLine(res[i]);
            }
        }
    }
}


Measured memory_bytes: 42336
//絶望的に汚い
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const char* solve() {
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    int cnt = -1;
    for (auto& s : A) {
        cin >> s;
        cnt += count(s.cbegin(), s.cend(), '#');
    }
    int cw = 0, ch = 0, dw[] = {1, 0}, dh[] = {0, 1};
    while (cw != W - 1 || ch != H - 1) {
        bool f = false;
        for (int i = 0; i < 2; i++) {
            int tw = cw + dw[i], th = ch + dh[i];
            if (tw < 0 || tw >= W || th < 0 || th >= H) continue;
            if (A[th][tw] == '#') {
                f = true;
                cnt--;
                cw = tw;
                ch = th;
                break;
            }
        }
        if (!f) return "Impossible";
    }
    return cnt ? "Impossible" : "Possible";
}
int main() {
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int n;
std::string str;

int dist(char from, char to) {
    if(from <= to) {
        return to - from;
    }else {
        return 26 + to - from;
    }
}

int main() {
    std::cin >> str >> n;

    for(auto&& c : str) {
        int da = dist(c, 'a');
        if(da <= n) {
            n -= da;
            c = 'a';
        }
    }

    int a = str[str.size() - 1];
    a += n;

    while(a > 'z') {
        a -= 26;
    }
    str[str.size() - 1] = a;

    std::cout << str << std::endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define ar array
#define pb push_back
#define sz(X) ((int)(X).size())
#define pcnt __builtin_popcount
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define get_pos(c, x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define all(X) (X).begin(), (X).end()
#define ms(c,x)  memset(c,x,sizeof c)
#define  No cout<<"NO"<<endl;
#define  Yes cout<<"YES"<<endl;
#define  nl cout<<endl;
template<typename T>
using orderedSet=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T>
ostream &operator+(ostream &out, const vector<T> &vec) {
    for (const auto &x : vec) {
        out << x << " ";
    }
    out << "\n";
    return out;
}

template<typename T>
ostream &operator*(ostream &out, const vector<T> &vec) {
    for (const auto &x : vec) {
        out + x;
    }
    return out;
}

template<typename T>
istream &operator>>(istream &in, vector<T> &vec) {
    for (auto &x : vec) {
        in >> x;
    }
    return in;
}

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

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


const int mod = 1e9 + 7;
const int mod2 = 998244353;
const ll INF = 1e9 + 6;

ll add(ll a, ll b) {
    a += b;
    return a % mod;
}

ll mul(ll a, ll b) {
    a *= b;
    return a % mod;
}

inline ll power(ll x, ll y, ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

inline ll modInverse(ll x, ll p,int chance) {
    return power(x, p - 2, p);
}
const int MXN=3002;
ll cache[MXN][MXN];
ll a[MXN];

ll dp(int l,int r){
    if(l>r){
        return 0;
    }
    ll &ans=cache[l][r];
    if(ans!=-1){
        return ans;
    }
    return ans=max(a[l]-dp(l+1,r),a[r]-dp(l,r-1));

}
void solve() {
    int n;
    cin >>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<MXN;i++)for (int j = 0; j <MXN ; ++j)cache[i][j]=-1;

    cout<<dp(0,n-1)<<endl;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--)solve();
#ifndef ONLINE_JUDGE
    cerr << endl << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
#endif
    return 0;
}
//look if it requires ll

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

signed main(){
  string s;
  int k;
  cin>>s>>k;
  set<string> v;
  for(int i=0;i<s.size();i++){
    string t;
    t+=s[i];
    v.insert(t);
    for(int j=1;j<k&&j+i<s.size();j++){
      t+=s[i+j];
      v.insert(t);
    }
  }
  auto i=v.begin();
  k--;
  while(k--)i++;
  cout<<*i<<endl;
  return 0;
}


Measured memory_bytes: 1664
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#define INF 1<<28
#define F first
#define S second
using namespace std;
 
int sx, sy, gx, gy;
typedef pair < int, int > P;
vector < P > v[5];
int memo[5][5][1111];

int dist(P a, P b){
  return abs(a.F - b.F) + abs(a.S - b.S);
}


int solve(int cnt, int now, int p){
 
  if(cnt == 4) return dist(v[now][p], P(gx, gy));
  if(memo[cnt][now][p]) return memo[cnt][now][p];
 
  int ans = INF, next = (now+1)%5, cost;
  for(int i=0;i<v[next].size();i++){
    if(!cnt) cost = dist(P(sx, sy), v[next][i]);
    else cost = dist(v[now][p], v[next][i]);
    ans = min(ans, solve(cnt+1, next, i) + cost);
  }
 
  return memo[cnt][now][p] = ans;
}
 
int main(){
 
  int w, h;
  char c;
 
  while(scanf("%d %d", &w, &h), w){
    
    for(int i=0;i<5;i++) v[i].clear();
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	scanf(" %c", &c);
	if(c == '.') continue;
	else if(c == 'S') sx = j, sy = i;
	else if(c == 'G') gx = j, gy = i;
	else v[c-'1'].push_back( P(j,i) );
      }
    }
    
    int a, b = INF;
    for(int i=0;i<5;i++){
      memset(memo, 0, sizeof(memo));
      if(b > solve(0,i,0)) a = i+1, b = solve(0,i,0);
    }
 
    b == INF?puts("NA"):printf("%d %d\n", a, b);
 
  }
}

Measured memory_bytes: 1192
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=1<<30;
int main() {
	int n,m;cin>>n>>m;
	int c[20],t[50001];
	for(int i=0;i<m;i++)cin>>c[i];
	for(int i=1;i<=n;i++)t[i]=INF;
	t[0]=0;
	for(int i=0;i<m;i++)
	{
		for(int j=c[i];j<=n;j++)
		{
			t[j]=min(t[j],t[j-c[i]]+1);
		}
	}
	cout<<t[n]<<endl;
	return 0;
}

Measured memory_bytes: 3220
program ABC145_B
integer N
character(200)S
logical check
read*,N
read*,S

check=.true.
if(mod(N,2)==1)check=.false.
if(S(1:N/2)/=S(N/2+1:N))check=.false.

if(check)then
  print"(A)","Yes"
else
  print"(A)","No"
endif
end program

Measured memory_bytes: 640
# -*- coding utf-8 -*-

a,b,c,d=map(int,input().split())

if a<=c<b or a<=d<b:
    x=max(a,c)
    y=min(b,d)
    print(abs(y-x))
elif c<=a<d or c<=b<d:
    x=max(a,c)
    y=min(b,d)
    print(abs(y-x))


else:
    print("0")


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace Official_House
{
    class Program
    {
        static void Main(string[] args)
        {
            int[, ,] house = new int[4,3,10]; //?£????????????¨?±?

            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; ++i)
            {
                var input = Console.ReadLine().Split(' ');
                house[int.Parse(input[0]) - 1, int.Parse(input[1]) - 1, int.Parse(input[2]) - 1] += int.Parse(input[3]);

            }

            for (int i = 0; i < 4; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    for (int k = 0; k < 10; ++k)
                    {
                        Console.Write(" " + house[i, j, k]);
                    }
                    if (j < 2) Console.WriteLine();
                }
                if (i < 3) Console.WriteLine("\n####################");
            }
            Console.WriteLine();
        }
    }
}


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

int main() {
  int K, S;
  cin >> K >> S;
  int count = 0;

  for (int i=0; i <= K; ++i) {
    for (int j=0; j <= K; ++j) {
      int l = S - (i + j);
      if (l >= 0 && l <= K) ++count;
    }
  }
  cout << count << endl;
}


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

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

	int m = 1;
	while (1){
		if (s == 1 || s == 2 || s == 4){
			break;
		}

		if (s % 2 == 1){
			s = (s * 3) + 1;
		}
		else {
			s /= 2;
		}
		
		m++;
	}

	cout << m + 3 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int sosu(int a){
    if(a==2){
        return 1;
    }
    for(int i=2;i<sqrt(a)+1;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
vector<int> v;
int n,m,cnt=0,ans=0,aa[110],ab[110];
pair<int,char> pp[220000];
string s,sa[220000];
char ch[110][110];
queue<int> que;
signed main(){
    cin>>n>>m;
    rep(i,n){
        cin>>s;
        rep(j,m){
            ch[i][j]=s[j];
            if(ch[i][j]=='#'){
                aa[i]++;
                ab[j]++;
            }
        }
    }
    rep(i,n){
        if(aa[i]==0){
            continue;
        }
        rep(j,m){
            if(ab[j]!=0){
                cout<<ch[i][j];
            }
        }
        cout<<endl;
    }
}

Measured memory_bytes: 10492
#include<stdio.h>

int main(void){

char str[1010];

int i,sum;

scanf("%s",str);

while(str[0]!='0'){

i=0;

sum=0;

while(str[i]){

sum+=str[i]-'0';

i++;

}

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

scanf("%s",str);

}

return 0;

}

Measured memory_bytes: 540
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN

using namespace std;
using ll = long long;

void testcase() {
    int n ; cin >> n;
    bool found = false;
    for (int x = 1; x <= n; x++) {
    	if (floor(x*1.08) == n) {
    		cout << x << endl;
    		found = true;
    		break;
    	}
    }

    if (!found) cout << ":(" << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
int a,b,c,k;
cin>>a>>b>>c>>k;
if(k<=a)
cout<<k;
else
{
	int sum=a;
	k-=a;
	if(k<=b)
	{
		cout<<sum;
	}
	else
	{
		k-=b;
		cout<<sum-k;
	}
}
}
int main()
{
//code

fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


Measured memory_bytes: 3656
#include <stdio.h>
int main(void){
  int n;
  int s;
  scanf("%d", &n);
  if (n%1000==0){
    s=0;
    printf("%d", s);
  }
  else{
s=(n/1000+1)*1000-n;
    printf("%d", s);
  }
  return 0;
}

Measured memory_bytes: 1736
// 2011/01/07 Tazoe

#include <iostream>
using namespace std;

bool DFS(int X, int Y, int n, int bk[15][2], int s[10][10], int& cnt, int ans[10][10])
{
	if(n==0){
		for(int y=0; y<Y; y++)
			for(int x=0; x<X; x++)
				if(s[y][x]==0)
					return false;

		cnt++;
		for(int y=0; y<Y; y++)
			for(int x=0; x<X; x++)
				ans[y][x] = s[y][x];
		return true;
	}

	int bx;
	int by;
	bool flg = false;
	for(by=0; by<Y; by++){
		for(bx=0; bx<X; bx++){
			if(s[by][bx]==bk[n-1][0])
				flg = true;
			if(flg)
				break;
		}
		if(flg)
			break;
	}

	for(int kY=1; kY<=bk[n-1][1]; kY++){
		if(bk[n-1][1]%kY!=0)
			continue;

		int kX = bk[n-1][1]/kY;

		for(int i=0; i<kY; i++)
			for(int j=0; j<kX; j++){
				int tmp[10][10];
				for(int y=0; y<Y; y++)
					for(int x=0; x<X; x++)
						tmp[y][x] = s[y][x];

				bool flg2 = true;
				int my = by-i;
				for(int mm=0; mm<kY; mm++){
					int nx = bx-j;
					for(int nn=0; nn<kX; nn++){
						if((my>=0&&my<Y)
						 &&(nx>=0&&nx<X)
						 &&(s[my][nx]==0||s[my][nx]==bk[n-1][0]))
							tmp[my][nx] = bk[n-1][0];
						else
							flg2 = false;
						if(!flg2)
							break;
						nx++;
					}
					if(!flg2)
						break;
					my++;
				}

				if(flg2)
					DFS(X, Y, n-1, bk, tmp, cnt, ans);
			}
	}

	return false;
}

int main()
{
	while(true){
		int X, Y, n;
		cin >> X >> Y >> n;
		if(X==0&&Y==0&&n==0)
			break;

		int bk[15][2];
		for(int i=0; i<n; i++)
			cin >> bk[i][0] >> bk[i][1];

		int s[10][10];
		for(int y=0; y<Y; y++)
			for(int x=0; x<X; x++)
				cin >> s[y][x];

		int cnt = 0;
		int ans[10][10];
		for(int y=0; y<Y; y++)
			for(int x=0; x<X; x++)
				ans[y][x] = -1;

		DFS(X, Y, n, bk, s, cnt, ans);

		if(cnt==1)
			for(int y=0; y<Y; y++)
				for(int x=0; x<X; x++){
					cout << ans[y][x];
					if(x!=X-1)
						cout << ' ';
					else
						cout << endl;
				}
		else
			cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll mod=1e9+7;
  ll n,k;
  cin >> n >> k;
  ll a[n];
  rep(i,n) cin >> a[i];
  ll ans=0;
  ll ttt=0;
  rep(i,n){
    for(int j=i+1;j<n;j++){    
      if(i<j && a[i]>a[j]){
	ans++;
      }
    }
    rep(j,n){
      if(a[i]<a[j]){
	ttt++;
      }
    }
  }
  set<ll> ss;
  multiset<ll> set;
  //  ans = (ans*k)%mod;
  ll tt=((k*(k-1))/2LL)%mod;
  //  cout << ans << " " << ttt << endl;
  //  cout << (ans *k + ttt*tt)%mod << endl;


  rep(i,n){
    set.insert(a[i]);
    ss.insert(a[i]);
  }
  //  cout << ans << endl;
  ll t=0;
  for(auto i: ss){
    //    ll tt=(((k%mod)*(k-1)%mod)/2LL)%mod;
    t +=((n-set.count(i))*set.count(i))%mod;
    t %=mod;
    //    cout << t << endl;
  }
  //  assert(t!=0);
  t = (t*tt/2LL)%mod;
  ans = (ans*k+t)%mod;
  cout << ans << endl;
  
  return 0;
    

}


Measured memory_bytes: 384
import math

def makePrimes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

m = 10**5
primes = set(makePrimes(m))
cumulative_sum = [0]*(10**5+1)
for N in range(2,10**5+1):
    cumulative_sum[N] = cumulative_sum[N-1]+1 if N in primes and (N+1)//2 in primes else cumulative_sum[N-1]

Q = int(input())
for i in range(Q):
    l,r = list(map(int,input().split()))
    print(cumulative_sum[r]-cumulative_sum[l-1])


Measured memory_bytes: 8072
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N;
}

char maxX(string S){
    char ret='a';
    for(auto x:S) ret=max(ret,x);
    return ret; 
}

vector<string> dfs(vector<string> X){
    if(X[0].size()==N) return X;
    vector<string> ret;
    string y;
    for(auto x:X){
        for(char c='a';c<=(maxX(x)+1);c++){
            y=x+c;
            ret.push_back(y);
        }
    }
    return dfs(ret);
}

int solve(){
    vector<string> x;
    x.push_back("a");
    vector<string> ret=dfs(x);
    sort(ret.begin(),ret.end());
    for(auto a:ret) cout << a << "\n";
    return 0;
}   

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


Measured memory_bytes: 9496
// ref. https://atcoder.jp/contests/arc094/submissions/2315168

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = (ll)1e10;
const ll MOD = 1000000007;  // 1e9 + 7

// return true when maxim number is equal or smaller than x.
bool check(ll a, ll b, ll x) {
  // Try 100 elements in [x/2-50, x/2+50]
  ll tmp = 0;
  for (ll i = max(x/2 - 50, 1ll); i <= min(x/2 + 50, x); ++i) {
    // pair i-th smallest(from a) and i-th greatest(from b)
    ll L = i;
    if (L >= a) { ++L; } // [1,...,a-1,a+1..i+1]
    ll R = x-i+1;
    if (i <= x-b+1) { ++R; } // [x-i,...,b-1, b+1, ..., x]
    tmp = max(tmp, L*R);
  }

  return tmp < a * b;
}

void solve() {
  ll a, b;
  cin >> a >> b;

  ll l = 0;
  ll r = INF;
  // find the boundary of [t, t, ..., t, f, ..., f]
  while (r-l > 1) {
    ll m = (r+l)>>1;
    if (check(a, b, m)) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << l << endl;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll q;
  cin >> q;
  rep(iter, q) {
    solve();
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;

  bool isRight = false;

  for (int i = 0; i <= x; i++) {
    int num_of_leg = 2 * i + (x - i) * 4;
    
    if (num_of_leg == y) {
      isRight = true;
    }
  }

  if (isRight) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
require 'pp'

def gets; ARGF.gets; end

class Solver

  def main
    o = gets.chomp
    e = gets.chomp

    1.upto(o.length + e.length) do |i|
      if i.odd?
        print o[i / 2]
      else
        print e[(i - 1) / 2]
      end
    end
    puts
  end
end

if __FILE__ == $0
  Solver.new.main
end


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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

string s;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s;
    cout << (s == "ABC" ? "ARC" : "ABC") << '\n';
    return 0;
}

Measured memory_bytes: 3520
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
using namespace std;
using ll = long long;
const ll mod =  1000000007;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (int i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

ll dp[500010] = {};

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }

  int root(int x) {
    if (par[x] < 0)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { return -par[root(x)]; }
};


signed main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  UnionFind tree(n);
  REP(i, m) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    tree.unite(x, y);
  }
  ll ans = 0;
  REP(i, n) {
    if(tree.root(i) == i) {
      ans++;
    }
  }

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


Measured memory_bytes: 640
fun main(args: Array<String>) {
    val (h,w,n) = readLine()!!.split(" ").map { it.toInt() }
    val (y,x)= readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!
    val t = readLine()!!

    var py = y
    for (i in 0..n-1){
        if(s[i]=='U') py--
        if(py==0){ println("NO"); return }
        if(t[i]=='D' && py<h) py++
    }

    py = y
    for (i in 0..n-1){
        if(s[i]=='D') py++
        if(py==h+1){ println("NO"); return }
        if(t[i]=='U' && py>1) py--
    }

    var px = x
    for (i in 0..n-1){
        if(s[i]=='R') px++
        if(px==w+1){ println("NO"); return }
        if(t[i]=='L' && px>1) px--
    }

    px = x
    for (i in 0..n-1){
        if(s[i]=='L') px--
        if(px==0){ println("NO"); return }
        if(t[i]=='R' && px<w) px++
    }

    println("YES")

}

Measured memory_bytes: 41380
import sys
input = sys.stdin.readline
 
N, K = [int(x) for x in input().split()]

if K == 0:
    print(N ** 2)
    sys.exit()

cnt = 0

for i in range(1, N + 1):
    if i <= K:
        continue
    a = i - K # 1周期でのK以下の個数
    b = N // i # 何周期あるか
    c = N % i # 周期の余り(1~c)

    cnt += a * b
    if c >= K:
        cnt += c - K + 1

print(cnt)

        

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

void printv(vi v){
	for(int i = 0; i < v.size(); i++){
		cout << v[i] << " ";
		}cout << endl;
		return ;
		}

int main() {
	while(1){
	
	int n,s; cin >> n >> s;
	if (n + s == 0) break;
	int ans = 0;
	vi loop(10,1);
	for (int i = 0; i < 10; i++){
		if (10 - i > n){
			loop[9-i] = 0;
		}
		
	}

	
	
	vi aold_used(10,0);
	vi bold_used(10,0);
	vi cold_used(10,0);
	vi dold_used(10,0);
	vi eold_used(10,0);
	vi fold_used(10,0);
	vi gold_used(10,0);
	vi hold_used(10,0);
	vi iold_used(10,0);
	vi jold_used(10,0);
	for (int a = 0; a <= 9*loop[0]; a++){
		vi used(10,0);
		aold_used = used;
		used[a] = 1;
		for (int b = a*loop[1]; b <= 9*loop[1]; b++){
			bold_used = used;
			if (used[b] == 1 and loop[1] != 0) continue;
			else if(loop[1] != 0) used[b] = 1;
			for (int c = b*loop[2]; c <= 9*loop[2]; c++){
				cold_used = used;
				if (used[c] == 1 and loop[2] != 0) continue;
				else if(loop[2] != 0) used[c] = 1;
				for (int d = c*loop[3]; d <= 9*loop[3]; d++){
					dold_used = used;
					if (used[d] == 1 and loop[3] != 0) continue;
					else if(loop[3] != 0) used[d] = 1;
					for (int e = d*loop[4]; e <= 9*loop[4]; e++){
						eold_used = used;
						if (used[e] == 1 and loop[4] != 0) continue;
						else if(loop[4] != 0) used[e] = 1;
						for (int f = e*loop[5]; f <= 9*loop[5]; f++){
							fold_used = used;
							if (used[f] == 1 and loop[5] != 0) continue;
							else if(loop[5] != 0) used[f] = 1;
							for (int g = f*loop[6]; g <= 9*loop[6]; g++){
								gold_used = used;
								if (used[g] == 1 and loop[6] != 0) continue;
								else if(loop[6] != 0) used[g] = 1;
								for (int h = g*loop[7]; h <= 9*loop[7]; h++){
									hold_used = used;
									if (used[h] == 1 and loop[7] != 0) continue;
									else if(loop[7] != 0) used[h] = 1;
									for (int i = h*loop[8]; i <= 9*loop[8]; i++){
										iold_used = used;
										if (used[i] == 1 and loop[8] != 0) continue;
										else if(loop[8] != 0) used[i] = 1;
										for (int j = i*loop[9]; j <= 9*loop[9]; j++){
											jold_used = used;
											if (used[j] == 1 and loop[9] != 0) continue;
											else if(loop[9] != 0) used[j] = 1;
											if (a + b + c + d + e + f + g + h + i + j == s){
												//cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << " " << g << " " << h << " " << i << " " << j << endl;
												ans++;
											}
											used = jold_used;
										}	
										used = iold_used;
									}
									used = hold_used;
								}
								used = gold_used;
							}
							used = fold_used;
						}
						used = eold_used;
					}
					used = dold_used;
				}
				used = cold_used;
			}
			used = bold_used;
		}
		used = aold_used;
	}

	cout << ans << endl;
	}
}

Measured memory_bytes: 3120
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-
import numpy as np


def main():
    N, K, Q = map(int, input().split())
    result = np.array([K - Q] * N)
    for _ in range(Q):
        a = int(input())
        result[a - 1] += 1

    for r in result:
        print('Yes'if r > 0 else 'No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 14024
import java.util.*;
import java.io.*;
 
class Main{
public static void main(String[] args) throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  	String[] str = br.readLine().split(" ");
  	int n = Integer.parseInt(str[0]);
  	int k = Integer.parseInt(str[1]);
  	int[] h = new int[n];
  	String[] s = br.readLine().split(" ");
  	for(int i=0;i<n;i++)
      h[i] = Integer.parseInt(s[i]);
  	int[] dp = new int[n];
    Arrays.fill(dp,Integer.MAX_VALUE);
    dp[0] = 0;
  	//dp[1] = Math.abs(h[1]-h[0]);
  	for(int i=1;i<n;i++){
      for(int j=i-1;j>=0 && i-j<=k;j--)
      dp[i] = Math.min(dp[i],dp[j] + Math.abs(h[i]-h[j]));
    }
      System.out.println(dp[n-1]);
    }
}


Measured memory_bytes: 45196
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <set>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e10
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<lli>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using lli = long long int;
template<typename T> bool chmax(T &a, T &b){ if(a<b) { a=b; return 1; }}
template<typename T> bool chmin(T &a, T &b){ if(b<a) { a=b; return 1; }}
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T arrdebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    lli a, b;
  	cin >> a >> b;
  	
  	lli suma, sumb;
  	lli buf;
  	if(a%2 == 0){
    	suma = (a/2)%2;
  	}else{
    	buf = ((a-1)/2)%2;
    	suma = ((buf | (a-1)) & (~buf | ~(a-1)));
  	}
  	
  	if((b+1)%2 == 0){
  		sumb = ((b+1)/2)%2;
  	}else{
  		buf = (b/2)%2;
  		sumb = ((buf | b) & (~buf | ~b));
  	}
  	
  	cout << ((suma | sumb) & (~suma | ~sumb)) << endl;
  	return 0;
}

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

const int N = 1e5 + 5, inf = INT_MAX, mod = 1e9 + 7;

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    int n, profit[102][12];
    bool days[102][12];
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 10; j++)
            cin >> days[i][j];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 11; j++)
            cin >> profit[i][j];
    int mask = 0, ans = INT_MIN;
    while (mask < (1 << 10) - 1)
    {
        mask++;
        int cnt[102] = {};
        for (int i = 0; i < n; i++)
            for (int j = 0; j < 10; j++)
                if ((mask & (1 << j)) != 0 && days[i][j])
                    cnt[i]++;
        int sum = 0;
        for (int i = 0; i < n; i++)
            sum += profit[i][cnt[i]];
        ans = max(ans, sum);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3524
def main():
    H, W, K = map(int, input().split())
    S = []
    for i in range(H):
        S.append(input())
    counter = 1
    T = []
    for i in range(H):
        if '#' in S[i]:
            t = []
            cc = 0
            for j in range(W):
                if S[i][j] == '#':
                    cc += 1
            for j in range(W):
                t.append(counter)
                if S[i][j] == '#' and cc > 1:
                    counter += 1
                    cc -= 1
            tt = ' '.join([str(k) for k in t])
            T.append(tt)
            counter += 1
        else:
            if i != 0:
                T.append(T[-1])
            else:
                T.append("None")
    
    for i in range(H-1, -1, -1):
        if T[i] == "None":
            T[i] = T[i+1]

    print('\n'.join(T))
            

if __name__ == '__main__':
    main()

Measured memory_bytes: 49756
import java.util.*;
import java.util.concurrent.ConcurrentSkipListSet;

public class Main {

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

        String s = scanner.next();
        char c = s.charAt(0);

        if (c >= 0x41 && c <= 0x5a) {
            System.out.println("A");
        } else if (c >= 0x61 && c <= 0x7a) {
            System.out.println("a");
        }
    }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }

deque<bool> enum_prime(ll N){
	deque<bool> is_prime(N+1,true);
	is_prime[0]=is_prime[1]=false;
	for(ll i=2;i<=N;i++){
		if(is_prime[i]){
			for(ll j=i*i;j<=N;j+=i){
				is_prime[j] = false;
			}
		}
	}
	return is_prime;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto P = enum_prime(1000000);

	while(true){
		int N=in(),X=in();
		if(!N && !X) break;
		auto V=vecin(N);
		vector<int> dp(X+1,0);
		dp[0]=1;
		int ans=-1;
		REP(j,X+1){
			REP(i,N){
				if(j+V[i]<=X){
					chmax(dp[j+V[i]],dp[j]);
				}
			}
			if(dp[j] && P[j]){
				ans = j;
			}
		}
		
		if(ans<0) out("NA");
		else out(ans);
	}

	return 0;
}



Measured memory_bytes: 10780
n=int(input())
L=list(map(int,input().split()))

def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)

L.sort()
ans=L[0]
for i in range(n-1):
  ans=gcd(ans,L[i+1])
    

print(ans)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return vec<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec


using namespace std;

// 0-indexed
// [l, r)
template <typename T>
struct BIT {
    vec<T> data;
    T id_ele;

    BIT(ll size, T id_ele) : id_ele(id_ele) {
        ll bsize = 1;
        while (bsize < size) bsize *= 2;
        data = vec<T>(bsize + 1, id_ele);
    }

    T sum(ll pos) {
        T ret = id_ele;
        for (; 0 < pos; pos -= pos & -pos) ret += data[pos];
        return ret;
    }

    T sum(ll l, ll r) { return sum(r) - sum(l); }

    void add(ll pos, T delta) {
        for (++pos; pos < data.size(); pos += pos & -pos) data[pos] += delta;
    }
};

const size_t SIZE = 5e5 + 10;
vec<BIT<ll>> bitv(26, BIT<ll>(SIZE, 0));

int main() {
    ll n;
    string s;
    cin >> n >> s;
    for (ll i = 0; i < n; i++) {
        ll idx = s[i] - 'a';
        bitv[idx].add(i, 1);
    }
    ll q;
    cin >> q;
    while (q--) {
        ll t;
        cin >> t;
        if (t == 1) {
            ll i;
            char c;
            cin >> i >> c;
            i--;
            char pc = s[i];
            char nc = c;
            bitv[pc - 'a'].add(i, -1);
            bitv[nc - 'a'].add(i, 1);
            s[i] = nc;
        } else {
            ll l, r;
            cin >> l >> r;
            l--;
            ll ans = 0;
            for (ll i = 0; i < 26; i++) ans += !!bitv[i].sum(l, r);
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 110976
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max()

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for(int i=0; i<n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	vector<int> oa(n), ob(n), oc(n);
	oa[0] = a[0];
	ob[0] = b[0];
	oc[0] = c[0];
	for(int i=1; i<n; i++) {
		oa[i] = max(ob[i-1], oc[i-1]) + a[i]; 
		ob[i] = max(oa[i-1], oc[i-1]) + b[i]; 
		oc[i] = max(oa[i-1], ob[i-1]) + c[i]; 
	}
	
	int ans = max(oa[n-1], max(ob[n-1], oc[n-1]));
	cout << ans << endl;
}










Measured memory_bytes: 2560
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    //optimize
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //---------
    string N;
    cin >> N;
    if ((N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3])) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
// vim: set fileencoding=utf-8


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int a,b;
  cin >> a >> b;
  if(a%3==0 || b%3==0 || (a+b)%3==0)cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int num1 = 0;
    int num2 = 0;
    int mul = 0;

    scanf("%d",&num1);
    scanf("%d", &num2);

    if((num1 <=9 && num1 > 0) && (num2 <=9 && num2 > 0)){
        mul = num1*num2;
        printf("%d", mul);
    }else{ printf("%d",-1);}



    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

const int N   = 2e5+7;
const int MOD = 1e9+7;
const double eps = 1e-6;
#define rep(aa,bb,cc) for(int aa=(bb),ee=(cc);aa<ee;aa++)
/***********************************************/
int n, m, a[N];
LL p[N];

int main() {
    LL all = 0;
    scanf("%d%d", &n, &m);
    for(int i=0; i<n; ++i) scanf("%d", a+i);
    for(int i=1; i<n; ++i) {
        int l = a[i-1], r = a[i];
        if(l>r) r += m;
        all += r-l;
        if(r-l>1) {
            p[l+2] += 1;
            p[r+1] -= (r-(l+2)+1) + 1;
            p[r+2] += (r-(l+2)+1);
        }
    }
    for(int i=1; i<=2*m; ++i) p[i] += p[i-1];
    for(int i=1; i<=2*m; ++i) p[i] += p[i-1];

    LL ans = -1;
    for(int i=1; i<=m; ++i) ans = max(ans, p[i]+p[i+m]);
    cout << all - ans << endl;

    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N) cin >> A.at(i);
  sort(A.begin(),A.end());
  rep(i,N-1){
    if(A.at(i) == A.at(i+1)){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

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

struct node{
  int key;
  struct node *next;
  struct node *prev;
};

typedef struct node *NodePointer;
NodePointer nil;

NodePointer listSearch(int key){
  NodePointer c;
  c=nil->next;
  while(c!=nil && c->key!=key){
    c=c->next;
  }
  return c;
}

void init(){
  nil=(NodePointer )malloc(sizeof(struct node));
  nil->next=nil;
  nil->prev=nil;
}

void printList(){
  NodePointer c;
  c=nil->next;
  int isf=0;
  while(1){
    if(c==nil) break;
    if(isf++ >0)printf(" ");
    printf("%d",c->key);
    c=c->next;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  NodePointer x;
  x=(NodePointer )malloc(sizeof(struct node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key,n,i,size=0,np=0,nd=0;
  char com[20];

  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0]=='i'){
      insert(key);
      np++;
      size++;
    }
    else if(com[0]=='d'){
      if(strlen(com)>6){
        if(com[6]=='F')deleteFirst();
        else if (com[6]=='L')deleteLast();
      }
      else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
  
}



Measured memory_bytes: 33000
#include <iostream>

using namespace std;

int main() {
	int L;
	do {
		cin>>L;
	} while (L < 1 || L > 1000);
	double L_double = static_cast<double>(L);
	double max_x, max_y, max_z;
	max_x = L_double / 3;
	max_y = max_x;
	max_z = max_x;

	double volumen{max_x*max_y*max_z};
	cout <<fixed<< volumen;
	return 0;
}

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

int main() {
	int x;
	cin >> x;
	cout << !x << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int N,T,A;
	cin>>N>>T>>A;
	T*=1000;
	A*=1000;
	
	int H[1000],dif[1000];
	rep(i,N){
		cin>>H[i];
		dif[i]=abs(T-6*H[i]-A);
	}
	
	
	int pal=0;
	rep(i,N){
		if(dif[i]<=dif[pal])pal=i;
	}
	cout<<pal+1;
}


Measured memory_bytes: 256
H, W = map(int, input().split())

A = []
for _ in range(H):
    a = list(input())
    A.append(a)

r = 0
for i in range(H):
    for j in range(r):
        if A[i][j] == '#':
            print('Impossible')
            exit(0)

    flag = False
    for j in range(r+1, W):
        if not(flag):
            if A[i][j] == '#':
                r += 1
            else:
                flag = True
                r = j-1
        else:
            if A[i][j] == '#':
                print('Impossible')
                exit(0)

print('Possible')


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main()
{ long long a,b,c,t;
cin>>a>>b>>c>>t;
long long p=t-a,q=p-b;
if(t<=a)
cout<<t;
else
{
    if(p<=b)
    cout<<a;
    else
    {
        cout<<a-q;
    }
}
}

Measured memory_bytes: 3580