akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<climits>

using namespace std;

class MatrixMultipluCost{
private:
 vector<unsigned long> p;
 vector< vector<unsigned long> > cost;

public:
 MatrixMultipluCost(unsigned long num)
  : p(num+1, 0), cost(num+1, vector<unsigned long>(num+1, 0)){

  for(unsigned long mat_i = 0; mat_i < num; ++mat_i){
   unsigned long tmp_row = 0; cin >> tmp_row;
   if(mat_i == 0) p[mat_i] = tmp_row;
   unsigned long tmp_col = 0; cin >> tmp_col; p[mat_i+1] = tmp_col;
  }

 };

 unsigned long colculateCost(void){
 unsigned long matrixNum = p.size()-1;

  for(unsigned long distance = 1; distance < matrixNum; ++distance){
   for(unsigned long front_i = 1; front_i+distance <= matrixNum; ++front_i){
    for(unsigned long rear_i = front_i; rear_i < front_i+distance; ++rear_i){
     unsigned long tmp_cost = cost[front_i][rear_i] + cost[rear_i+1][front_i+distance] + p[front_i-1] * p[rear_i] * p[front_i+distance];
     if(cost[front_i][front_i+distance] == 0 || cost[front_i][front_i+distance] > tmp_cost) cost[front_i][front_i+distance] = tmp_cost;
    }
   }
  }

  return cost[1][matrixNum];
 };

 void display(){
  for(unsigned long i = 0, max = p.size(); i < max; ++i)
   cout << p[i] << " ";
  cout << endl;

  for(unsigned long i = 0, max = cost.size(); i < max; ++i){
   for(unsigned long j = 0; j < max; ++j){
    cout << cost[i][j] << " ";
   }
   cout << endl;
  }
 };

};

int main(){
 unsigned long num = 0; cin >> num;

 MatrixMultipluCost MMC(num);
 cout << MMC.colculateCost() << endl;


 return 0;
};

Measured memory_bytes: 1292
#include<iostream>
using namespace std;
#include<stdio.h>

int *P;

int root(int a)
{
    if(P[a] == a) return a;
    P[a] = root(P[a]);
    return P[a]; 
}

void join(int a, int b){ int x = root(a), y = root(b); P[x] = y; }

bool same(int a, int b){ return (root(a) == root(b) ? true : false); }

int main()
{
    int i, n, m, a, b, q;
    scanf("%d %d", &n, &m);
    P = new int [n];
    for(i = 0; i < n; i++) P[i] = i;

    for(i = 0; i < m; i++){ scanf("%d %d", &a, &b); join(a, b); }

    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d %d", &a, &b);
        if(same(a, b)){ printf("yes\n"); }else{ printf("no\n"); }
    }
    delete [] P;
    return 0; 
}

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

using namespace std;

const int maxn = 1001, mod = 1000000007;
int dp[maxn][maxn], n, m;

char arr[maxn][maxn];

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

    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> arr[i][j];
    dp[1][1] = 1;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++){
            if(i==1 && j == 1) continue;
            if(arr[i][j]=='#') continue;
            dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
        }
    cout << dp[n][m];


    return 0;
}


Measured memory_bytes: 5120
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std;
#define N 2050
#define mod 1000000007
typedef long long ll;
int n,m,K;
ll f[N<<1][N][2],s[N],ans;
void upd(ll &x,ll y) {
	x=x+y; if(x>=mod) x-=mod;
	if(x<0) x+=mod;
}
int main() {
	scanf("%d%d%d",&n,&m,&K);
	int t1=n%(K-1),t2=m%(K-1);
	f[0][0][0]=1;
	int i,j,lim=max(n,m)<<1;
	for(i=1;i<=lim;i++) {
		int num=i*(K-1);
		s[0]=(f[i-1][0][0]+f[i-1][0][1])%mod;
		for(j=1;j<=n;j++) {
			s[j]=(s[j-1]+f[i-1][j][0]+f[i-1][j][1])%mod;
		}
		for(j=0;j<=n;j++) {
			f[i][j][0]=(f[i-1][j][0]+f[i-1][j][1])%mod;
			if(j) f[i][j][1]=(s[j-1]-(j-K>=0?s[j-K]:0))%mod;
		}
		for(j=0;j<=n;j++) {
			if(j%(K-1)==t1 && (num-j+1)%(K-1)==t2 && num-j+1<=m) upd(ans,f[i][j][1]);
		}
	}
	printf("%lld\n",(ans+mod)%mod);
}


Measured memory_bytes: 129152
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Blue ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,n) for(int i=a;i<n;++i)
typedef vector<int> vi;
typedef long long ll;
const int mod=1e9+7;
 
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
const int N=105; 

void solve(){
	int n=3;
	int a[n][n];
	rep(i,0,n){
		rep(j,0,n){
			cin>>a[i][j];
		}
	}
	int x;
	cin>>x;
	while(x--){
		int m;
		cin>>m;
		rep(i,0,n){
			rep(j,0,n){
				if(a[i][j]==m)a[i][j]=0;
			}
		}
	}
	int d1=0,d2=0;
	for(int i=0;i<n;i++){
		int row=0;
		for(int j=0;j<n;j++){
			if(a[i][j])continue;
			row++;
			d1+=i==j;
			d2+=(i+j==n-1);
		}
		if(row==n || d1==n||d2==n){
			cout<<"Yes";
			return;
		}
	}
	rep(j,0,n){
		int col=0;
		rep(i,0,n){
			if(a[i][j])continue;
			col++;
		}
		if(col==n){
			cout<<"Yes";
			return;
		}
	}
	cout<<"No";
 
}
 
 
int main(){
	Blue;
	int test=1;
	//cin>>test;
	while(test--)
		solve();
	return 0;
}

Measured memory_bytes: 3644
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    s.sort()
    if s == ["a", "b", "c"]:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    a, b, k = LI()
    ans = []
    for i in range(a, min(a + k, b + 1)):
        ans.append(i)
    for i in range(max(b - k + 1, a + k), b + 1):
        ans.append(i)
    for i in ans:
        print(i)
    return

#C
def C():
    abc= LI()
    abc.sort()
    a,b,c = abc
    a1 = (c - a) % 2
    b1 = (c - b) % 2
    if a1 and b1:
        print((c - a) // 2 + (c - b) // 2 + 1)
        return
    if a1 or b1:
        print((c - a) // 2 + (c - b) // 2 + 2)
        return
    print((c - a) // 2 + (c - b) // 2 )

    return

# D
# 解説AC

# a <= b として一般性を失わない
# 1: a = b のとき
# (a-k)*(a+k) = a*a - k*k < a*a
# であることを考えると0<k<aのすべてをとれて、
# 1回目にa-k,2回目にa+kもしくは2回目にa-k,1回目にa+kをとっている場合
# 満たすことがわかるこれは2*a-2人である
# ここでa*a > n*k を考えるとn,kどちらかはa-1以下である
# また、a+1以上である場合、もう一方がa-1以下であることが確定するため
# 片方がa+1以上である場合の個数はもう一方がa-1以下である場合に数えている 
# よって個数の上限が2*a-2人であるためこれが解であることがわかる
# 
# 2: c*c < a*b かつ c*(c+1) >= a*b を満たすcを考えるとき
# 1回目,2回目どちらかはc以下をとる必要があるゆえに上と同様に考えれば
# (c-k)*(c+k)を考えると0<=k<=c-1を考えればよくk=0で同じ組になることから
# 2*c-1人に見えるがc-k = aとなるときは除去しなければならないため
# 2*c-2人が解になる
# 
# 3: c*c < a*b かつ c*(c+1) < a*b を満たす最大のcを考えるとき
# 2と同様に(c-k)*(c+k)を考えるのではなく(c-k)*(c+1+k)の組として
# 考えればよく0<=k<c-1を考えてよく2*c人に見えるが、c-k=aのときだけ
# 除外する必要があるので2*c-1人が解になる 
def D():
    for _ in range(II()):
        a, b = LI()
        c = math.ceil(math.sqrt(a * b)) - 1
        print(2 * a - 2 if a == b else 2 * c - 1 - (c * (c + 1) >= a * b))
    return

#Solve
if __name__ == '__main__':
    D()


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

class DisjointSet{
public:
    vector<int> rank,p;
    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size,0);
        p.resize(size,0);
        for(int i=0; i<size; i++) makeSet(i);
    }
    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }
    
    bool same(int x,int y){
        return findSet(x) == findSet(y);
    }
    
    void unite(int x,int y){
        link(findSet(x), findSet(y));
    }
    
    void link(int x,int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        }else{
            p[x] = y;
            if(rank[x] == rank[y]){
                rank[y]++;
            }
        }
    }
    
    int findSet(int x){
        if(x != p[x]){
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
    int n,a,b,q;
    int t;
    
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);
    
    for(int i=0; i<q; i++){
        cin >> t >> a >> b;
        if(t==0) ds.unite(a,b);
        else if(t==1){
            if(ds.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    
    return 0;
}

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

#define ll long long int

int main() {
    int n;
    cin>>n;
    ll a[n+1];
    a[0] = 0;
    for(int i=1; i<=n; i++) {
        cin>>a[i];
        a[i] += a[i-1];
    }
    ll dp[n][n+1];
    for(int i=0; i<n; i++) dp[i][1] = 0;
    for(int l=2; l<=n; l++) {
        for(int i=0; i+l<=n; i++) {
            dp[i][l] = LLONG_MAX;
            for(int k=1; k<l; k++)
                dp[i][l] = min(dp[i][k] + dp[i+k][l-k], dp[i][l]);
            dp[i][l] += a[i+l] - a[i];
        }
    }
    cout<< dp[0][n] <<endl;
    return 0;
}


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

def dsMakeSet(ds, x):
    ds[x] = x


def dsFind(ds, x):
    if ds[x] == x:
        return x

    x0 = x
    while ds[x] != x:
        x = ds[x]

    ds[x0] = x
    return x


def dsUnion(ds, x, y):
    xRoot = dsFind(ds, x)
    yRoot = dsFind(ds, y)
    
    if xRoot != yRoot:
        ds[yRoot] = xRoot
        return True

    return False



N = int(input())
Q = {}

for _ in range(N):
    x, y = map(int, input().split())

    X = ('x', x)
    Y = ('y', y)

    if not (X in Q):
        dsMakeSet(Q, X)

    if not (Y in Q):
        dsMakeSet(Q, ('y', y))
    
    dsUnion(Q, X, Y)

R = {}

for q in Q:
    root = dsFind(Q, q)
    
    if not(root in R):
        R[root] = [0, 0]

    r = R[root]
    if q[0] == 'x':
        r[0] += 1
    else:
        r[1] += 1

s = 0
for r in R.values():
    s += r[0]*r[1]

print(s - N)

    



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

int main(){
  long a, b;
  int c=1;
  cin >> a >> b;
  for(long i=a; i<=b; i++){
    if(i>0) c*=1;
    if(i<0) c*=-1;
    if(i==0){
      c*=0;
      break;
    }
  }
  if(c>0){
    cout << "Positive" << endl;
    return 0;
  }
  if(c<0){
    cout << "Negative" << endl;
    return 0;
  }
  cout << "Zero" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <limits>
#include <map>
#include <bitset>

#define rep(i,n) for(int (i) = 0;(i)<(n);(i)++)

using namespace std;
using p = pair<int, int>;
using ll = long long;

vector< vector<int> > memo;

int gcd(int a, int b, int c) {
	int min_num = (a > b) ? b : a;
	if (min_num > c) min_num = c;
	while (min_num != 1) {
		if (a % min_num == 0 && b % min_num == 0 && c % min_num == 0) break;
		min_num--;
	}
	return min_num;
}

int gcd(int a, int b) {
	int m = (a < b) ? a : b;
	while (m != 1) {
		if (a % m == 0 && b % m == 0)break;
		m--;
	}
	return m;
}



int main() {
	float a, b, c, d;
	cin >> a >> b >> c >> d;
	int t_turn = ceil(c / b);
	int a_turn = ceil(a / d);
	
	if (t_turn <= a_turn) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 3720
#include<stdio.h>
int main(){
	int a,b,c,d,e,f,g,h,i,j,k,l,m,n;
	char z;
	scanf("%d %d %d %d %d %d\n",&a,&b,&c,&d,&e,&f);
	while(1){
		scanf("%c",&z);
		if(z=='N'){
		g=a;
		a=b;
		b=f;
		f=e;
		e=g;
		}
		if(z=='S'){
		g=e;
		e=f;
		f=b;
		b=a;
		a=g;
		}
		if(z=='E'){
		g=c;
		c=a;
		a=d;
		d=f;
		f=g;
		}
		if(z=='W'){
		g=d;
		d=a;
		a=c;
		c=f;
		f=g;
		}
if(z=='\n')
break;
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 596
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

bool dp1[30005][10], dp2[30005][100], dp3[30005][1000];

signed main() {
	int n;
	cin >> n;
	int a[30005];
	rep(i, n) {
		char c;
		cin >> c;
		a[i] = c - '0';
	}
	for (int i = 1; i <= n; i++) {
		rep(j, 10) {
			if (dp1[i - 1][j] || a[i - 1] == j) dp1[i][j] = true;
		}
	}
	for (int i = 2; i <= n; i++) {
		rep(j, 100) {
			if (dp2[i - 1][j]) dp2[i][j] = true;
			else if (dp1[i - 1][j / 10] && a[i - 1] == j % 10) dp2[i][j] = true;
		}
	}
	for (int i = 3; i <= n; i++) {
		rep(j, 1000) {
			if (dp3[i - 1][j]) dp3[i][j] = true;
			else if (dp2[i - 1][j / 10] && a[i - 1] == j % 10) dp3[i][j] = true;
		}
	}
	int ans = 0;
	rep(i, 1000) {
		if (dp3[n][i]) ans++;
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;



int main() {
    double N,K;
    cin>>N>>K;
    
    double sum = 0;
    for(int i = 1;i < N+1; i++){
    int j = 0;
    while( i*pow(2,j) < K){
            j++;
    }
    sum  +=  1.0/(N*pow(2.0,j));
    }
    printf("%.10lf\n", sum);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long int ll;
int main() {
	ll k;
	cin>>k;
	//ll arr[7]={7,77,777,7777,77777,777777,7777777};
	ll sum=7;
	for(ll i=1;i<1e7;i++){
		if(sum%k==0){
			cout<<i<<endl;
			return 0;
		}
		sum=sum*10 +7;
		sum%=k;
	}
	cout<<"-1\n";
	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<math.h>
using namespace std;

int main()
{	
  unsigned long long X;
  cin >> X; 
  
  unsigned long long money = 100;
  int i=0;
  if(X<100)
  {
    cout << 0;
    return 0;    
  }
  
  while(1)
  {
    double tmp = 1.0*money*1.01;
    money  = floor(tmp);
    i++;
//    cout << money << endl;
    
    if(money >= X){break;}
  }
  cout << i;
  return 0;
  
}


Measured memory_bytes: 3636
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val prime = eratos(55555)

    val ans = prime.filter { it%5==1 }.take(n)
    println(ans.joinToString(" "))
}

fun eratos(n:Int):List<Int>{
    val rtn = Math.sqrt(n.toDouble()).toInt()
    val prime = IntArray(n+1){ it }
    prime[0] = 0
    prime[1] = 0
    for(i in 2..rtn){
        if(prime[i]!=0){
            for(j in 2*i..n step i){
                prime[j]=0
            }
        }
    }
    return prime.filter { it!=0 }
}

Measured memory_bytes: 33852
#include<stdio.h>

long long min(long long a, long long b);

int main() {
	long long n, a[5], i, min_capa;

	scanf("%lld", &n);
	for (i = 0; i < 5; i++) {
		scanf("%lld", &a[i]);
	}

	min_capa = a[0];
	for (i = 1; i < 5; i++) {
		min_capa = min(min_capa, a[i]);
	}

	printf("%lld\n", (n / min_capa) + (n % min_capa == 0 ? 0 : 1) + 4);
	return 0;
}

long long min(long long a, long long b) {
	return (a < b) ? a : b;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();


		if (b <= c || d <= a) {
			System.out.println(0);
		} else if (a >= c) {
			if (b <= d) {
				System.out.println(b - a);
			} else {
				System.out.println(d - a);
			}
		} else {
			if (b <= d) {
				System.out.println(b - c);
			} else {
				System.out.println(d - c);
			}
		}

		sc.close();
	}
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int  (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int h; int w; int a; int b;
    cin >> h >> w >> a >> b;
    vector <int> first_arr;
    vector <int> second_arr;
    REP(j, a){
        first_arr.push_back(0);
        second_arr.push_back(1);
    }
    REP(j, w-a){
        first_arr.push_back(1);
        second_arr.push_back(0);
    }
    REP(i, b){
        REP(j, w-1){
            cout << first_arr[j];
        }
        cout << first_arr[w-1] << endl;
    }
    REP(i, h-b){
        REP(j, w-1){
            cout << second_arr[j];
        }
        cout << second_arr[w-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define SANKOU(n, a, b) cout << ((n) ? (#a) : (#b)) << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>

int H, W;
int A[1010][1010];
int dx[5] = {1, 0, -1, 0}, dy[5] = {0, 1, 0, -1};
queue<P> que;

void solve()
{
    int ans = 0;
    while (que.size()) {
        P p = que.front();
        que.pop();
        int a = A[p.first][p.second] + 1;
        FOR(i, 0, 4)
        {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (1 <= nx && nx <= H && 1 <= ny && ny <= W && A[nx][ny] > a) {
                A[nx][ny] = a;
                que.push(P(nx, ny));
                ans = max(ans, a);
            }
        }
    }
    cout << ans << endl;
}

signed main()
{
    cin >> H >> W;
    FOR(i, 1, H + 1)
    FOR(j, 1, W + 1)
    {
        char c;
        cin >> c;
        if (c == '.')
            A[i][j] = INF;
        else
            que.push(P(i, j));
    }
    solve();
    return 0;
}


Measured memory_bytes: 18064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <cstring>
#include <stack>
#include <cstdio>
#include <complex>
#include <iomanip>
#include <cstring>
#include <cctype>
#include <cassert>
#define rep(i,n) for(int i=0;i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define show(x) cout << #x << " = " << x << endl;
int main(){
    ll n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    if(a>b)swap(a,b);
    b-=a;
    bool ok = false;
    rep(k,n){
        if(b>=-d*k+c*(n-1-k) && b<=-c*k+d*(n-1-k)) ok = true;
    }
    if(ok) puts("YES");
    else puts("NO");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
using namespace std;
string s;
bool judge(int a,int b)
{
    for(int i=0;i<=b-a;i++)
    {
        if(s[a+i]!=s[b-a-i]) return false;
    }
    return true;
}
int main()
{
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin>>s;
    int n=s.size();
    if(judge(0,n-1)&&judge(0,(n-1)/2-1)&&judge((n+3)/2-1,n-1))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) {
        swap (a,b);
    }
    if (a > c) {
        swap (a,c);
    }
    if (b > c) {
        swap (b,c);
    }
    cout << a + b << endl;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()

score=0
scorei=0
myans=[]
myansi=""
for i in range(n):
    if(t[i]=="r"):
        myansi="p"
        scorei=p
    elif(t[i]=="s"):
        myansi="r"
        scorei=r
    else:
        myansi="s"
        scorei=s

    if(i>=k and myansi==myans[i-k]):
        myansi="*"
        scorei=0

    myans.append(myansi)
    score+=scorei
print(score)

Measured memory_bytes: 4212
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return a % 1000000007;
}

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


int main(){
  ll sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
  ll dx = tx - sx; ll dy = ty - sy;
  
  cout << string(dy,'U') << string(dx,'R') << string(dy,'D') << 
    string(dx+1,'L') << string(dy+1,'U') << string(dx+1,'R') <<
    "DR" << string(dy+1,'D') << string(dx+1,'L') << 'U' << endl;
  
}

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

int main()
{
    string s,t;
    cin >> s >> t;
    vector<int> transS(26,-1);
    vector<int> transT(26,-1);

    bool result = true;
    for(int i = 0; i < (int)s.size(); ++i)
    {
        int a = s[i]-'a';
        int b = t[i]-'a';
        if((transS[a] != -1 || transT[b] != -1)
        && (transS[a] != b || transT[b] != a))
        {
            result = false;
            break;
        }
        transS[a] = b;
        transT[b] = a;
    }

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

Measured memory_bytes: 776
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> monster(n);
  rep(i,n) cin >> monster[i];
  sort(monster.begin(), monster.end());
  int64_t res = 0;
  rep(i,n-k) res += monster[i];
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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;}

ll gcd(ll a, ll b){
  return b ? gcd(b, a%b) : a;
}

ll ngcd(vector<ll> a){
    int res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x; cin>>n>>x;
    vector<ll> vv(n);
    rep(i,n){
        ll v;cin>>v;
        vv[i] = abs(x-v);
    }
    ll ans = ngcd(vv);
    cout<<ans<<endl;
}

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

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

    vector<long long> A(N);
    for (long long &a : A)
    {
        cin >> a;
    }

    priority_queue<pair<long long, size_t>> q;
    for (size_t i = 0; i < N; i++)
    {
        q.push(make_pair(A[i], i));
    }

    vector<vector<long long>> dp(N + 1, vector<long long>(N + 1, 0));
    for (size_t i = 0; !q.empty(); i++)
    {
        for (size_t j = 0; j <= i; j++)
        {
            dp[j + 1][i - j] = max(dp[j + 1][i - j], dp[j][i - j] + q.top().first * abs((long long)(q.top().second - j)));
            dp[j][i - j + 1] = max(dp[j][i - j + 1], dp[j][i - j] + q.top().first * abs((long long)(N - 1 - (i - j) - q.top().second)));
        }
        q.pop();
    }

    long long ans = 0;
    for (size_t i = 0; i <= N; i++)
    {
        ans = max(ans, dp[i][N - i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 34652
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll n;
V<V<V<double> > > dp(301, V<V<double> >(301, V<double>(301, 0.0)));
V<V<V<bool> > > flag(301, V<V<bool> >(301, V<bool>(301, false)));

double f(ll c1, ll c2, ll c3) {
    if (flag[c1][c2][c3]) return dp[c1][c2][c3];
    flag[c1][c2][c3] = true;
    double fans = 1/(1-(double)(n-c1-c2-c3)/n);
    if (c1>0) fans += f(c1-1, c2, c3)*c1/n/(1-(double)(n-c1-c2-c3)/n);
    if (c2>0) fans += f(c1+1, c2-1, c3)*c2/n/(1-(double)(n-c1-c2-c3)/n);
    if (c3>0) fans += f(c1, c2+1, c3-1)*c3/n/(1-(double)(n-c1-c2-c3)/n);
    return dp[c1][c2][c3] = fans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vll a(n); REP(i, n) cin >> a[i];
    vll c(3); REP(i, n) c[a[i]-1]++;
    flag[0][0][0] = true;
    double ans = f(c[0], c[1], c[2]);
    cout << fixed << setprecision(12) << ans << '\n';
    return 0;
}


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

using i64 = int64_t;

using Graph = vector<vector<int>>;

int main(){
    int n;
    cin >> n;
    Graph graph(n+1, vector<int>());
    for(int i=0;i<n;++i){
        int u, k;
        cin >> u >> k;
        for(int j=0;j<k;++j){
            int v;
            cin >> v;
            graph[u].push_back(v);

        }
    }

    vector<int> mini(n+1, 200);
    queue<pair<int, int>> que;
    mini[1] = 0;
    que.push({1, 0});
    while(!que.empty()){
        auto cur = que.front(); que.pop();
        for(auto to: graph[cur.first]){
            int cost = cur.second + 1;
            if(mini[to] <= cost)continue;
            mini[to] = cost;
            que.push({to, cost});
        }
    }

    for(int i=1;i<=n;++i){
        cout << i << " " << (mini[i] < 200 ? mini[i] : -1) << endl;
    }

    return 0;
}



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

int main()
{
    int a,b,c,d=0;
    cin >>a>>b>>c>>d;
    
    if((abs(a-b)<=d &&abs(b-c)<=d)||abs(a-c)<=d)
    {
        cout <<"Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }
    
}

Measured memory_bytes: 888
#include <stdio.h>

#define R (0)
#define L (1)

int check_p(float eye)
{
	if (eye >= 1.1) return (0);
	else if (eye >= 0.6) return (1);
	else if (eye >= 0.2) return (2);
	else return (3);
}

int main(void)
{
	float in_tmp[2];
	int data[4][2] = { 0 };
	int i;
	
	while (scanf("%f %f", &in_tmp[L], &in_tmp[R]) != EOF){
		data[check_p(in_tmp[R])][R]++;
		data[check_p(in_tmp[L])][L]++;
	}
	
	for (i = 0; i < 4; i++) printf("%d %d\n", data[i][L], data[i][R]);
	
	return (0);
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;

int main() {
	int a = 0, b = 0;
	char s[5];
	cin >> s;
	sort(s, s + 4);
	if (s[0] == s[1] && s[1]!=s[2] && s[2] == s[3]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#define N 100;
using namespace std;

int main(){
    int n=N;
    int a[n];
    double b[n];
    double c=0;
    double d;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=1/(double)a[i];
        c+=b[i];
    }
    d=1/(double)c;
    cout<<setprecision(10)<<d<<endl;
}

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

using namespace std;
int main()
{
	int a,b,n;
	scanf("%d%d%d",&n,&a,&b);
	int x=max(a,b);
	int y=min(a,b);
	if((x-y)%2==0){
		printf("Alice\n");
	}else
	  puts("Borys");
	return 0;
}

Measured memory_bytes: 256
def myfind(S):
	if (len(S) % 2 == 0):
		dv = len(S)//2
		f,e = S[:dv],S[dv:]
		if f == e: return True
	return False

if __name__ == '__main__':
	S = input()
	S = S[:-1]
	while not(myfind(S)): 
		S= S[:-1]
	print(len(S))

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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	LL a, b, c, d;
	cin>>a>>b>>c>>d;
	LL w = max(b*d, a*c);
	w = max(w, max(b*c, a*d));
	cout<<w;
}


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

int main() {
    int A[3], ans = 0;
    for (int i = 0; i < 3; ++i) cin >> A[i];
    sort(A, A + 3);
    ans += A[1] - A[0];
    ans += A[2] - A[1];

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
vector<int> a(n+1);
a.at(0)=1;
int i;
for(i=1;i<=n;i++){
    a.at(i)=2*a.at(i-1);
    if(a.at(i)-a.at(i-1)>k)break;
}
  cout<<a.at(i-1)+(n-i+1)*k<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846
#ifdef LOCAL
#include <sys/types.h>
#include <sys/timeb.h>
#include <intrin.h> 
#include <thread>
#else
#include <sys/time.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c <= b)cout << b + c << endl;
	else {
		c -= b;
		if (c > a)cout << b + b + a + 1 << endl;
		else cout << b + b + c << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> H >> W;
  
  ans = H*W;
  ll h, w;
  cin >> h >> w;
  ans -= (h*W);
  ans -= (w*(H-h));
  cout << ans << endl;
  
  

  
  //cout << ans << endl;
  

}


Measured memory_bytes: 256
A,B=map(int, input().split())
s=input()

ng = 0
if not (s[0:A].isdecimal()):
  ng = 1
if s[A] != "-": ng = 1
if not (s[A+1:A+B+1].isdecimal()):
  ng = 1
if ng == 1:
  print("No")
else:
  print("Yes")
  


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

int IsPrime(int n){
    int i;
 
    if(n < 2)
        return 0;
    else if(n == 2)
        return 1;
 
    if(n % 2 == 0)
        return 0;
 
    for(i = 3; i * i <= n; i += 2)
         if(n % i == 0)
            return 0;
    return 1;
}

int main()
{
	int n,count = 0;
	vector<int> N;
	
	cin >> n;

	for(int i=0;i<n;++i){
		int j;
		cin >> j;

		bool flag = true;
		for(int k=0;k<N.size();++k){
			if(j == N[k]){
				flag = false;
				break;
			}
		}
		
		if(flag)
			N.push_back(j); 
	}
	
	for(int i=0;i<n;++i){
		if(IsPrime(N[i]))
			++count;
	}
	
	cout << count << endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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



int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    string s;
    cin>>n;
    cin>>s;
    set<int> v[26];

    REP(i,n){
        v[s[i]-'a'].insert(i+1);
    }

    int q;
    cin>>q;
    REP(lp,q){
        int com, l,r;
        char a;
        cin>>com;
        if(com==1){
            //変更
            cin>>l>>a;

            v[s[l-1]-'a'].erase(l);
            s[l-1] = a;
            v[s[l-1]-'a'].insert(l);
        }else{
            //出力
            cin>>l>>r;
            int ans=0;

            REP(i,26){
                auto it = v[i].lower_bound(l);
 
                if(it!=v[i].end() && *it <= r){
                    ans++;
                }
            }

            cout<<ans<<endl;
            //printf("%d\n", ans);
        }
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll n, k;
  cin >> n >> k;

  long double ans = 0;
  for (ll i = 1; i <= n; ++i) {
    if (i >= k) {
      ans += 1.0 / double(n);
    } else {
      ll x = 1;
      for (; ; ++x) {
        if ((i<<x) >= k) break;
      }
      //cout << "1.0/" << double(n) << " + " << "1.0/" << (2<<(x-1)) << " : i=" << i << " x=" << x <<  endl;
      ans += 1.0 / double(n) * 1.0/(2<<(x-1));
    }
  }

  cout << fixed << setprecision(12);
  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main()
{
   long long n;
   cin>>n;
   long long i,temp,count=0;
   for(i=0;i<n;i++){
    cin>>temp;
    if((temp%2)!=0)
        count++;
   }
   if(count%2==0)
    cout<<"YES"<<endl;
   else
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long

using namespace std;

signed main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;
    map<int, int> m;
    for(auto i = 0LL; i < N; i++) {
        for(auto j = i+1; j < N; j++){
            int t = min({j - i, abs(X - i) + 1 + abs(Y - j)});
            m[t]++;
        }
    }
    for(auto i = 1LL; i < N; i++){
        cout << m[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#define N 1000

int main() {
	int i, j, len, flag;
	char T[N], P[N];

	scanf("%s", T);
	scanf("%s", P);

	for (i = 0; i < strlen(T); i++) {
		flag = 0;
		if (T[i] == P[0]) {
			flag = 1;
			for (j = 0; j < strlen(P); j++) {
				if (T[i+j] != P[j]) {
					flag = 0;
					break;
				}
			}
		}
		if (flag == 1) printf("%d\n", i);
	}

	return 0;
}

Measured memory_bytes: 540
a = 3.times.map { gets.split.map(&:to_i) }.sort.transpose.sort.transpose
yes = 2.times.all? do
  a = a.transpose
  2.times.all? do |i|
    a[i][1] - a[i][0] == a[i+1][1] - a[i+1][0] && a[i][2] - a[i][1] == a[i+1][2] - a[i+1][1]
  end
end
puts yes ? "Yes" : "No"


Measured memory_bytes: 1788
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len = 0;
		int k = 0,j = 0;
		int[] a = new int[200000];
		int[] z = new int[200000];
		for(int i = 0;i < s.length();i ++) {
			char c = s.charAt(i);
			if(c == 'A') {
				a[k] = i;
				k ++;
			}
			if(c == 'Z') {
				z[j] = i;
				j ++;
			}
		}
		len = z[j - 1] - a[0] + 1;
		System.out.println(len);
	}
}

Measured memory_bytes: 28752
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL fact[6000];
LL invfact[6000];

LL gcd(LL a, LL b){
	if(b == 0) return a;
	return gcd(b,a%b);
}
LL powmod(LL a, LL n){
	if(n == 0) return 1;
	if(n % 2) return (a*powmod(a,n-1)) % MOD;
	LL c = powmod(a,n/2);
	return (c*c) % MOD;
}
LL inv(LL a){
	return powmod(a,MOD-2) % MOD;
}

int main(){
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	/*for(int i = 0; i < 6000; i++){
		for(int j = 0; j < 6000; j++){
			if(j > i){
				ncr[i][j] = 0;
				continue;
			}
			if(i == 0 || j == i){
				ncr[i][j] = 1;
				continue;
			}
			ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];
			ncr[i][j] %= MOD;
		}
	}*/
	fact[0] = 1;
	invfact[0] = inv(fact[0]);
	for(int i = 1; i < 6000; i++){
		fact[i] = fact[i-1]*i;
		fact[i] %= MOD;
		invfact[i] = inv(fact[i]);
	}
	if(b % 2 == 1){
		cout << 0 << endl;
		return 0;
	}
	int p2 = b/2;
	LL ans = 0;
	for(int i = 0; i <= 5000; i++){ // #13's
		for(int j = 0; j <= 5000; j++){ // #333's
			int n1 = a - i;
			int n3 = c - i - 3*j;
			if(n1 < 0 || n3 < 0) continue;
			if(p2 == 0 && n3 != 0) continue;
			int z = n1+j+i+p2;
			LL cur = 1;
			cur = (cur*fact[z]) % MOD;
			cur = (cur*invfact[n1]) % MOD;
			cur = (cur*invfact[j]) % MOD;
			cur = (cur*invfact[i]) % MOD;
			cur = (cur*invfact[p2]) % MOD;
			if(p2){
				cur = (cur*fact[p2-1+n3]) % MOD;
				cur = (cur*invfact[p2-1]) % MOD;
				cur = (cur*invfact[n3]) % MOD;
			}
			ans += cur;
			ans %= MOD;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {
	map<string, int> letters;
	string in;
	while(cin>>in){
		if(letters.count(in) == 0) letters.insert(make_pair(in, 0));
		else letters.find(in)->second++;
	}

	int maxChar = 0;
	int maxLength = 0;
	map<string, int>::iterator it, foo, bar;
	for(it=letters.begin(); it!=letters.end(); it++){
		maxChar = max(maxChar, it->second);
		if(maxChar == it->second) foo = it;
	}
	for(it=letters.begin(); it!=letters.end(); it++){
		maxLength = max(maxLength, (int)it->first.size());
		if(maxLength == it->first.size()) bar = it;
	}

	cout<<foo->first<<" "<<bar->first<<endl;
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
ll calc(P p1, P p2){
	ll ans = abs(p1.first -p2.first) + abs(p1.second - p2.second);
	return ans;
}
int main() {
	ll n, m;
	cin >> n >> m;
	vector<P> x(n);
	vector<P> y(m);
	rep(i,n) cin >> x[i].first >> x[i].second;
	rep(i,m) cin >> y[i].first >> y[i].second;
	for(auto k : x){
		ll min = INF, ans;
		rep(i,m){
			ll dist = calc(k, y[i]);
			if(dist < min){
				min = dist;
				ans = i+1;
			}
		}
		cout << ans << endl;
	}
 	return 0;
}

Measured memory_bytes: 3604
total_cnt, select_cnt = map(int, input().split())

tree_list = []

for i in range(total_cnt):
    tree_high = int(input())
    tree_list.append(tree_high)

tree_sorted_list = sorted(tree_list)

diff_list = []

for j in range(total_cnt-select_cnt+1):
    diff = tree_sorted_list[j+select_cnt-1] - tree_sorted_list[j]
    diff_list.append(diff)
    
print(min(diff_list))

Measured memory_bytes: 12060
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int dx[4] = {+1,-1,+0,-0};
const int dy[4] = {+0,-0,+1,-1};
const int maxn = 55;
vector<string>s(maxn);
int n,m;
bool valid(int x,int y){
	return x >=0 && x < n && y >=0 && y < m;
}
int spfa(int source){
	//return 0;
	vector<int>dis(n*m,1e8),inq(n*m);
	queue<int>q;
	dis[source]=0;
	q.push(source);
	inq[source]=1;
	while( q.size() ){
		int u = q.front(); q.pop(); inq[u] = 0;
		for(int k=0;k<4;k++){
			int x = u/m + dx[k];
			int y = u%m + dy[k];
			if( valid(x,y) && s[x][y] != '#' && dis[x*m+y] > dis[u] + 1){
				dis[x*m+y] = dis[u] + 1;
				if( !inq[x*m+y] ){
					q.push(x*m+y);
					inq[x*m+y]=1;
				}
			}
		}
	}
	//bugn(dis,n*m);
	return dis[ n*m -1 ];
}
int32_t main(){
	IOS
	cin>>n>>m;
	int cnt=0;
	for(int i=0;i<n;i++){
		cin>>s[i];
		for(int j=0;j<m;j++){
			cnt += s[i][j] =='.';
		}
	}
	bug2(cnt,spfa(0));
	int ans = cnt - spfa(0) -1;
	cout << (ans < 0 ? -1 : ans );
	
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

const int MAX_N = 1000001;
const int INF = 1e+8;
 
int f(int n){
	return (n * (n + 1) * (n + 2)) / 6;
}

int main(){
	vector<int> v, w;
	for(int i=1 ; f(i) < MAX_N ; i++ ){
		v.push_back( f(i) );
		if( f(i) % 2 == 1 ){
			w.push_back( f(i) );
		}
	}
	
	// dp[i] := 整数 i を正四面体数の和で表すときの個数の最小値
	int dp[MAX_N];
	int dp2[MAX_N];
	for(int i=0 ; i < MAX_N ; i++ ){
		dp[i] = dp2[i] = INF;
	}
	for(int i=0 ; i < v.size() ; i++ ){
		dp[ v[i] ] = 1;
	}
	for(int i=0 ; i < w.size() ; i++ ){
		dp2[ w[i] ] = 1;
	}
	for(int i=1 ; i < MAX_N ; i++ ){
		if( dp[i] != INF ){
			for(int j=0 ; j < v.size() && i + v[j] < MAX_N ; j++ ){
				dp[ i + v[j] ] = min( dp[i+v[j]] , dp[i] + 1 );
			}
		}
		if( dp2[i] != INF ){
			for(int j=0 ; j < w.size() && i + w[j] < MAX_N ; j++ ){
				dp2[ i + w[j] ] = min( dp2[i+w[j]] , dp2[i] + 1 );
			}
		}
	}
	
	int n;
	while( cin >> n , n ){
		cout << dp[n] << " " << dp2[n] << endl;
	}
}

Measured memory_bytes: 8604