akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

typedef long long lint;

const double EPS = 1e-10;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, -1, 0};
const int INF = 1001001001;
const lint INFLL = 1001001001001001001ll;

#define zclear(a) memset((a), 0, sizeof(a))
#define mclear(a) memset((a), -1, sizeof(a))

#define show(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

struct VLA {
	public:
	char c;
	vector<int> perm;
};

map<char, VLA> conv;

int pos;
char s[1024];
vector<int> factor();

vector<int> doIt(vector<int> x, vector<int> y)
{
	vector<int> ret(x.size());
	
	for (int i = 0; i < ret.size(); i++){
		ret[i] = x[y[i]];
	}
	
	return (ret);
}

vector<int> doIt2(vector<int> v, int rep)
{
	vector<int> ret(v.size()), next(v.size());
	
	for (int i = 0; i < ret.size(); i++){
		ret[i] = i;
	}
	for (int i = 0; i < rep; i++){
		for (int j = 0; j < ret.size(); j++){
			next[j] = ret[v[j]];
		}
		ret = next;
	}
	return (ret);
}

int lcm(int a, int b)
{
	return (a / __gcd(a, b) * b);
}

int getSize(vector<int> v)
{
	int ret = 1;
	bool vis[128] = {0};
	
	for (int i = 0; i < v.size(); i++){
		int ct = 0;
		int p = v[i];
		while (vis[p] == false){
			vis[p] = true;
			ct++;
			p = v[p];
		}
		if (ct) ret = lcm(ret, ct);
	}
	return (ret);
}

vector<int> equation()
{
	vector<int> res = factor();
	while (s[pos] == '+'){
		pos++;
		vector<int> next = factor();
		res = doIt(res, next);
	}
	return (res);
}

vector<int> factor()
{
	if (isalpha(s[pos])){
		char c = s[pos];
		pos++;
		return (conv[c].perm);
	}
	else {
		int rep = 0;
		while (isdigit(s[pos])) rep = rep * 10 + s[pos++] - '0';
		
		int dx = (s[pos] == '(');
		pos += dx;
		vector<int> x = (dx ? equation() : factor());
		pos += dx;
		rep %= getSize(x);
		x = doIt2(x, rep);
		return (x);
	}
}

int main()
{
	int N, K;
	
	scanf("%d %d", &N, &K);
	
	for (int i = 0; i < K; i++){
		VLA x;
		char buf[128];
		int a;
		vector<int> perm(N);
		
		scanf("%s %d", buf, &a);
		x.c = buf[0];
		
		for (int j = 0; j < N; j++){
			perm[j] = j;
		}
		for (int j = 0; j < a - 1; j++){
			for (int k = 0; k < N - 1; k++){
				int sw;
				scanf("%d", &sw);
				if (sw == 1) swap(perm[k], perm[k + 1]);
			}
		}
		
		x.perm = perm;
		conv[x.c] = x;
	}
	int E;
	scanf("%d", &E);
	for (int i = 0; i < E; i++){
		scanf("%s", s);
		
		pos = 0;
		vector<int> ret = equation();
		
		for (int j = 0; j < N; j++){
			printf("%d%c", ret[j] + 1, j == N - 1 ? '\n' : ' ');
		}
	}
	
	return (0);
}

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

using namespace std;

int main(){
    int i, n, counter=0;
    cin >> n;
    
    //n個の整数を格納
    int a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
    }

    int result=1;
    while(1){
        for(i=0; i<n; i++){
            if(a[i]%2 == 0){
                a[i] = a[i]/2;
            } else {
                result = 0;
                break;
            }
        }
        if(result){
            counter++;
        } else {
            break;
        }
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
 
X, Y = map(int, input().split())
 
def getComb(n, k, MOD):
    if n < k:
        return 0
    if n-k < k:
        k = n-k
    comb = 1
    for x in range(n-k+1, n+1):
        comb = (comb * x) % MOD
    d = 1
    for x in range(1, k+1):
        d = (d * x) % MOD
    comb *= pow(d, MOD-2, MOD)
    return comb % MOD
 
if (X+Y)%3:
    ans = 0
else:
    K = (X+Y)//3
    if X < K or Y < K:
        ans = 0
    else:
        ans = getComb(K, X-K, MOD)
 
print(ans)

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc114/tasks/abc114_c

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, f, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][f][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 1e9;
const int S_MAX = 10;
const int DIGITS[4] = {0, 3, 5, 7};

int L;
char S[S_MAX + 1];

int dp[S_MAX + 1][2][16];

void solve() {
  L = strlen(S);
  dp[0][0][0] = 1;
  REP(i, L) {
    int d = S[i] - '0';
    // printf("i:%d d:%d\n", i, d);
    REP(smaller, 2) REP(j, 16) REP(k, 4) {
      int x = DIGITS[k];
      // printf("  smaller:%d j:%d x:%d\n", smaller, j, x);
      if ((j & 0x0e) > 0 && x == 0) continue;
      if (!smaller && x > d) continue;
      dp[i + 1][smaller || x < d][j | (1 << k)] += dp[i][smaller][j];
    }
  }

  // DUMP2D(dp, 0, L + 1, 16);
  // DUMP2D(dp, 1, L + 1, 16);

  int ans = dp[L][0][0x0e] + dp[L][0][0x0f] + dp[L][1][0x0e] + dp[L][1][0x0f];
  printf("%d\n", ans);
}

void input() {
  scanf("%s", S);
}

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


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

int main() {
  int a, b;
  string str;
  cin >> a >> b;
  for (int i = 0; i < b + 2; i++) {
    cout << "#" ;
  }
  cout << endl;
  for (int k = 0; k < a; k++) {
    cin >> str;
    cout << "#" << str << "#" << endl;
  }
  
  for (int o = 0; o < b + 2; o++) {
    cout << "#" ;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(){
	int m,n;
	int i,j,k,l;
	int flag = 0;
	char** a;
	char** b;
	char* str;

	scanf("%d %d",&n,&m);
	a = (char**)calloc(n,sizeof(char*));
	for(i=0; i<n; i++){
		a[i] = (char*)calloc(n,sizeof(char));
	}
	b = (char**)calloc(m,sizeof(char*));
	for(i=0; i<m; i++){
		b[i] = (char*)calloc(m,sizeof(char));
	}

	str = (char*)calloc(n+1,sizeof(char));
	for(i=0; i<n; i++){
		scanf("%s",str);
		for(j=0; j<n; j++){
			a[i][j] = str[j];
		}
	}


	str = (char*)calloc(m+1,sizeof(char));
	for(i=0; i<m; i++){
		scanf("%s",str);
		for(j=0; j<m; j++){
			b[i][j] = str[j];
		}
	}

	i = 0;
	while( i <= n - m && flag == 0 ){
		j = 0;
		while( j <= n - m && flag == 0 ){
			flag = 1;
			k = 0;
			while( k < m && flag == 1 ){
				l = 0;
				while( l < m && a[i+k][j+l] == b[k][l] ){
					l++;
				}

				if( l == m ){
					flag = 1;
				}else{
					flag = 0;
				}

				k++;
			}
			j++;
		}
		i++;
	}

	if( flag == 1 ){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}

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

int main(){
    int N;
    long long int W;
    cin >> N >> W;
    vector<long long int>weight(110);
    vector<long long int>value(110);
    for(int i=0; i<N;i++){
        cin >> weight.at(i) >> value.at(i);
    }
    vector<vector<long long int>>dp(110,vector<long long int>(100100,0));
    
    //ちょうどWのときの最大の価値を計算
    for(int i=0; i<N; i++){
        for(int j=0; j<=W; j++){
            if(j-weight.at(i)>=0){
            dp.at(i+1).at(j) = max(dp.at(i).at(j-weight.at(i))+value.at(i),dp.at(i+1).at(j));
            }
            dp.at(i+1).at(j) = max(dp.at(i+1).at(j),dp.at(i).at(j));
            
        }
    }
    cout << dp.at(N).at(W) << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

char c;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
      cout << "vowel" << endl;
    }
    else {
      cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
N, *A = map(int, open(0).read().split())

d = [0] * (N + 1)
for i in range(N):
    d[i + 1] = d[i] + A[i]

ans = 10 ** 9 + 7
l = 0
r = 2
for m in range(1, N):
    # Left
    while l < m:
        s1 = abs((d[m] - d[l]) - d[l])
        s2 = abs((d[m] - d[l + 1]) - d[l + 1])
        if s1 > s2:
            l += 1
        else:
            break

    # Right
    while m <= r < N:
        s1 = abs((d[N] - d[r]) - (d[r] - d[m]))
        s2 = abs((d[N] - d[r + 1]) - (d[r + 1] - d[m]))
        if s1 > s2 or m == r:
            r += 1
        else:
            break

    m1 = min(d[l], d[m] - d[l], d[r] - d[m], d[N] - d[r])
    m2 = max(d[l], d[m] - d[l], d[r] - d[m], d[N] - d[r])
    ans = min(ans, m2 - m1)

print(ans)


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

#define IOS std::cin.tie(0);std::ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>;

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 55;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(N);
    vi H(N);VCIN(H);

    vi dp(N+10,0);
    dp[0]=0;dp[1]=abs(H[1]-H[0]);
    Rep(i,2,N){
        dp[i]=min(dp[i-2]+abs(H[i-2]-H[i]),dp[i-1]+abs(H[i-1]-H[i]));
    }
    COUT(dp[N-1]);

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd( T m, T n ){
    if ( ( 0 == m ) || ( 0 == n ) ) return 0;

    while( m != n ){
        if ( m > n ) m %= n;
        else         n %= m;

        if(m == 0) return n;
        if(n == 0) return m;
    }
    return m;
}


int main()
{
    ll N;
    cin >> N;
    set<ll> onePassed;
    ll Ai;
    cin >> Ai;
    ll aGCD = Ai;
    onePassed.insert(Ai);
    cin >> Ai;
    onePassed.insert(Ai);
    aGCD = gcd(aGCD, Ai);
    for(int i=2;i<N;i++){
        cin >> Ai;
        set<ll> tmp;
        for(auto v : onePassed){
            tmp.insert(gcd(Ai, v));
        }
        tmp.insert(aGCD);
        onePassed = tmp;
        aGCD = gcd(aGCD, Ai);
    }
    cout<<*onePassed.rbegin()<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 510000;
const int MOD = 1000000007;



ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}
 
ll mfact(ll n){
  ll ans = 1;
  for(ll i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}
 
ll mcomb(ll n, ll m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    ll ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}


int main(){
  ll x,y;
  cin>>x>>y;
  ll turn=(x+y)/3;

  if((x+y)%3!=0 || (abs(x-turn)+abs(y-turn))!=turn){
    cout<<0<<endl;
  }else{
    cout<<mcomb(abs(x-turn)+abs(y-turn),abs(x-turn))<<endl;
  }
}

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

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

    int w;
    cin >> w;

    string ans;
    for (int i = 0; i < s.size(); i += w)
    {
        ans += s[i];
    }

    cout << ans << endl;

    return 0;
}

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

struct Node
{
  // Given
  int num_of_child;
  std::vector<int> child;
  // Not given
  int parent;
  int depth;
  std::string type;
};

void init(Node tree[], int id, int parent, int parent_depth)
{
  tree[id].parent = parent;
  tree[id].depth = parent_depth + 1;

  if (tree[id].parent == -1)
  {
    tree[id].type = "root";
  }
  else if (tree[id].child.empty())
  {
    tree[id].type = "leaf";
  }
  else
  {
    tree[id].type = "internal node";
  }

  // Recursive call
  for (int i = 0; i < tree[id].num_of_child; ++i)
  {
    init(tree, tree[id].child[i], id, tree[id].depth);
  }
}

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

  Node tree[n];
  int children[n] = { 0 };
  for (int i = 0; i < n; ++i)
  {
    int id;
    std::cin >> id;
    std::cin >> tree[id].num_of_child;

    for (int j = 0; j < tree[id].num_of_child; ++j)
    {
      int c;
      std::cin >> c;
      tree[id].child.push_back(c);
      children[c] = 1;
    }
  }

  int root_id = 0;
  while(children[root_id] == 1)
  {
    ++root_id;
  }

  init(tree, root_id, -1, -1);

  for (int i = 0; i < n; ++i)
  {
    std::cout << "node " << i
              << ": parent = " << tree[i].parent
              << ", depth = " << tree[i].depth
              << ", " << tree[i].type
              << ", [";
    for (int j = 0; j < tree[i].num_of_child; ++j)
    {
      if (j != 0) std::cout << ", ";
      std::cout << tree[i].child[j];
    }
    std::cout << ']' << std::endl;
  }

  return 0;
}



Measured memory_bytes: 13704
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    N, X, M = iim()

    if X == 0:
        print(0)
        return
    A = [X]

    i = 0
    vis = {X: 0}
    while i < N-1:
        a = A[i]**2 % M
        if a in vis:
            break
        elif a == 0:
            print(sum(A))
            return
        A.append(a)
        i += 1
        vis[a] = i
    else:
        a = X

    i = vis[a]
    n = len(A) - i
    a, b = divmod(N-i, n)
    ans = sum(A[i:]) * a
    for j in range(i):
        ans += A[j]
    for j in range(i, i+b):
        ans += A[j]
    print(ans)



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 77528
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int dp[105][30];
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    memset(dp,0,sizeof(dp));
    int len=s.size();
    dp[0][s[0]-'a']++;
    for(int i=1;i<len;i++){
        for(int j=0;j<26;j++){
            dp[i][j]=dp[i-1][j];
        }
        dp[i][s[i]-'a']++;
    }
    int ans=0;
    int sum=0;
//    for(int i=0;i<len;i++){
//        for(int j=0;j<26;j++){
//            cout<<dp[i][j]<<" ";
//        }
//        cout<<endl;
//    }
    for(int i=0;i<len-1;i++){
        sum=0;
        for(int j=0;j<26;j++){
            if(dp[i][j]!=dp[len-1][j]&&dp[i][j]){
                sum++;
            }
        }
        //cout<<i<<" "<<sum<<endl;
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
return 0;}


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

#define endl "\n"
#define pb push_back
#define MOD 1000000007LL
#define PI 3.1415926

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	string s;cin >> s;
	if(s[5]=='1' or s[6]>='5') cout << "TBD" << endl;
	else cout << "Heisei" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
	char n[4];
	gets(n);
	int p= 0;
	for (int i = 0; i < 3; i++)
		if (n[i] == '7')
			p= 1;
	if (p)
		printf("Yes\n");
	else
		printf("No\n");
	
}

Measured memory_bytes: 1488
hq_left = []
hq_right = []

#スペースなどで区切られた入力が複数行に続くとき
listA=[] #appendのために宣言が必要
N,M= map(int,input().split())

for i in range(M):
    listA.append(list(map(int,input().split())))


candidate_list = [i for i in range(1,N+1)]

for i in range(M):
    hq_left.append(listA[i][0])
    hq_right.append(listA[i][1])

if min(hq_right)-max(hq_left) <0:
    print(0)
else:
    print(len(candidate_list[max(hq_left):min(hq_right)])+1)

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

#define ll long long
#define ull unsigned long long
#define lld long double
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define vt vector
#define vll vt<ll>
#define pll pair<ll,ll>
#define vpll vt<pll>
#define vvll vt<vll>
#define all(v) v.begin(),v.end()
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl '\n'
template <typename T> using mxpq = priority_queue<T>;
template <typename T> using mnpq = priority_queue<T, vt<T>, greater<T>>;
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define mmss(arr,v) memset(arr,v,sizeof(arr))
#define go_t int testcases; cin>>testcases; ffo(caseno,1,testcases)

#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define ptime auto z1z = duration_cast<microseconds>(stop-start); cout<<"Time elapsed : "<<z1z.count()<<" microseconds\n"

const ll mod = 1e9 + 7;
const ll N = 6e4 + 6;
const ll maxN = 1e5 + 15;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

int dx[4] = { -1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
// up, right, down, left
//int dx [] = {+1,-1,+0,+0,-1,-1,+1,+1};///Eight Directions
//int dy [] = {+0,+0,+1,-1,+1,-1,-1,+1};///Eight Directions
//int dx[]={-2,-2,-1,1,-1,1,2,2};///Knight moves
//int dy[]={1,-1,-2,-2,2,2,-1,1};///Knight moves

ll powerM(ll x, ll y, ll M = mod) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in4.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	FIO
	string s;
	cin >> s;
	cout << s;
	if (s[s.length() - 1] != 's') cout << "s";
	else cout << "es";
	return 0;
}


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

int main(){
 	int N,T,c,t,ans(1001);
  	cin >> N >> T;
  	for(int i = 0 ; i < N ; i ++){
    	cin >> c >> t;
      	if(t <= T && c < ans) ans = c;
    }
  	if(ans == 1001) cout << "TLE" << endl; else cout << ans << endl;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int s;
    Scd(s);
    bool hit[1000001] = {};

    int i = 1;
    while( !hit[s] ){
        hit[s] = true;
        if( s%2 ){
            s = s*3+1;
        }else{
            s /= 2;
        }
        i++;
    }

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

    return 0;
}



Measured memory_bytes: 1280
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
#define LL long long
#define LD long double
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pii pair<int,int>
#define pli pair<LL,int>
#define pil pair<int,LL>
#define pll pair<LL,LL>
#define ff first
#define ss second
#define pb push_back
#define BTW(x,a,b) ((a) <= (x) && (x) <= (b))
#define _eq(a,b) (fabs((a)-(b)) < EPS)
#define _lt(a,b) (fabs((a)-(b)) > EPS && a < b)
#define _gt(a,b) (fabs((a)-(b)) > EPS && a > b)
#define _lte(a,b) !_gt(a,b)
#define _gte(a,b) !_lt(a,b)
const vector<pii> XY = {pii(0,-1),pii(0,1),pii(-1,0),pii(1,0)};
const LD EPS = 1e-8;
const LD PI = acos(-1.0L);
const LL INFLL =  4e18;
const int INF  =  2e9;
const int MOD  =  1e9 + 7;
//#define int long long

// read / write
template<typename T> void read(T& t) { cin >> t; }
template<typename T, typename ... U> void read(T& t, U& ... u) { read(t); read(u ...); }
template<typename T> void write(T t) { cout << t; }
template<typename T, typename ... U> void write(T t, U ... u) { write(t); write(u ...); }



// ------------------------------------------------- Vs
const int LOGN    =  16              + 1;
const int MAXN1   =  3e5            + 3;
const int MAXN2   =  8            + 3;
// ------------------------------------------------- Fs
int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); write(fixed, setprecision(12));
    LL n; read(n);
    set<LL> st;
    for(int i = 1; i <= 1e6; ++i) if(n%i == 0){
        for(LL d: {(LL)i, n/i}){
            LL tmp = d - 1;
            if((tmp+-1) >= n/(tmp+1) && n/tmp == n%tmp)
                st.insert(tmp);
        }
    }
    LL ans = 0; for(LL x: st) ans+=x;
    write(ans, "\n");
    return 0;
}

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

while True:
    x = int(X ** 0.5)
    b = True #Xが素数
    for i in range(3, x, 2):
        if X % 2 == 0 or X % i == 0:
            b = False
            break
    if b == False:
        X += 1
    else:
        break
print(X)

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[50000][20]; // 集合sまで巡回済みで、最後にjを訪れた時の最小コスト
ll G[20][20];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  
  rep(i,n) rep(j,n) G[i][j]=INF;
  rep(i,m){
    ll a,b,c; cin>>a>>b>>c;
    G[a][b]=c;
  }
  
  rep(i,50000) rep(j,n) dp[i][j]=INF;
  dp[0][0]=0;
  
  // (2^n)*(n^2) ... n=15なら10^8程度
  rep(s,1<<n){
    // i => j への移動を考える
    rep(i,n) rep(j,n){
      if((s>>j&1)==0 && G[i][j]!=INF) chmin(dp[s|(1<<j)][j],dp[s][i]+G[i][j]);
    }
  }
  
  ll ans=dp[(1<<n)-1][0];
  if(ans!=INF) cout<<ans<<endl;
  else cout<<-1<<endl;
  
}


Measured memory_bytes: 11032
#include <iostream>
#include <cstring>

using namespace std;

constexpr int mod = 1000000007;

int pow(int base,int power) {
	int res = 1;
	for(int i = 0;i < power;i++) {
		res = res * base % mod;
	}
	return res;
}

int main(void) {
	int n,a,s[200000];
	memset(s,0,sizeof(int[200000]));
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a;
		s[a]++;
	}
	for(int i = 1+(n%2);i < n;i+=2) {
		if(s[i] != 2) {
			cout << 0 << endl;
			return 0;
		}	       
	}
	if(n%2 && s[0]!=1) {
		cout << 0 << endl;
		return 0;
	}
	cout << pow(2,n/2) << endl;
}


Measured memory_bytes: 1024
char n[][7]={"Sun","Mon","Tues","Wednes","Thurs","Fri","Satur"};m;main(d){for(;scanf("%d%d",&m,&d)*m;printf("%sday\n",n[(2488+(m<3?0:2)+((m+9)%12*13+47)/5+d)%7]));}

Measured memory_bytes: 596
from typing import List


class RollingHash:
    """Rolling Hash"""

    __slots__ = ["_base", "_mod", "_hash", "_power"]

    def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):
        self._base = base
        self._mod = mod
        self._hash = self._build_hash_from_zero(source)
        self._power = self._build_base_power(len(source))

    def _build_hash_from_zero(self, source: str) -> List[int]:
        """Compute hash of interval [0, right)."""
        res = [0] * (len(source) + 1)
        for i, c in enumerate(source, 1):
            res[i] = (res[i - 1] * self._base + ord(c)) % self._mod
        return res

    def _build_base_power(self, length: int) -> List[int]:
        """Compute mod of power of base."""
        res = [1] * (length + 1)
        for i in range(1, length + 1):
            res[i] = res[i - 1] * self._base % self._mod
        return res

    def get_hash(self, left: int, right: int):
        """Return hash of interval [left, right)."""
        return (
            self._hash[right] - self._hash[left] * self._power[right - left]
        ) % self._mod


def abc141_e():
    # https://atcoder.jp/contests/abc141/tasks/abc141_e
    N = int(input())
    S = input().rstrip()

    rh = RollingHash(S)
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg = False
        memo = set()
        for i in range(N - 2 * mid + 1):
            memo.add(rh.get_hash(i, i + mid))
            if rh.get_hash(i + mid, i + 2 * mid) in memo:
                flg = True
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter

    print(ok)  # max length of substrings appeared twice or more


if __name__ == "__main__":
    abc141_e()


Measured memory_bytes: 11252
// 入力処理
const lines = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

reader.on('line', function (line) {
    lines.push(line);
});

reader.on('close', function () {
    // 入力値
    const input = (lines[0] as string).split(" ");

    // 窓の幅とカーテンの幅
    const a = +input[0];
    const b = +input[1];

    // カーテンで隠されていない部分の幅
    const res = a - (b * 2);

    if (res > 0) {
        console.log(res);
    } else {
        console.log(0);
    }
})

Measured memory_bytes: 11596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,v[55]; 
ll solve(ll l,ll r)
{
	vector<ll> t;
	for(int i=0;i<=l;i++)
		t.push_back(v[i]);
	for(int i=r;i<n;i++)
		t.push_back(v[i]);
	sort(t.begin(),t.end());
	ll lim=k-t.size();
	if(lim<0)
		return 0;
	ll sum=0;
	for(int i=0;i<t.size();i++)
	{
		if(t[i]<0&&lim>0)
			lim--;
		else
			sum+=t[i];
	}
	return sum;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>v[i];
	ll ans=0;
	for(int i=-1;i<n;i++)
		for(int j=i+1;j<=n;j++)
			ans=max(ans,solve(i,j));
	cout<<ans;
	return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}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)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	auto A=vecin(N);

	int Q=in();
	REP(i,Q){
		auto res = equal_range(ALL(A),in());
		out(distance(A.begin(),res.first),distance(A.begin(),res.second));
	}
	return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#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 mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll A,B,C;
    cin >> A >> B >> C;
    Yes(A == B && B == C);
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 300005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,ans[N]; vector< pair<ll,ll> > vc[N];
void dijs(ll src){
	priority_queue< pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
	vector<ll> dt(n+1,1e15);
	dt[src]=0;
	pq.push({0,src});
	while(pq.size()>0){
		ll u=pq.top().sc;
		pq.pop();
		for(auto it:vc[u]){
			ll v=it.fs;
			ll d=it.sc;
			if(dt[v]>dt[u]+d){
				dt[v]=dt[u]+d;
				pq.push({dt[v],v});
			}
		}
	}
	for(ll i=1;i<=n;i++){
		ans[i]=dt[i];
	}
}
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>n;

	ll a,b,c;
	for(i=1;i<n;i++){
		cin>>a>>b>>c;
		vc[a].ps({b,c});
		vc[b].ps({a,c});
	}
	
	ll q;
	cin>>q>>k;
	dijs(k);
	
	while(q--){
		cin>>a>>b;
		cout<<ans[a]+ans[b]<<endl;
	}
	return 0;
}

Measured memory_bytes: 17008
a = input()
b = input()

if len(a)>len(b):
    print('GREATER')
elif len(a)<len(b):
    print('LESS')
else:
    if a==b:
        print('EQUAL')
    else:
        for i in range(0, len(a)):
            if a[i]>b[i]:
                print('GREATER')
                break
            elif a[i]<b[i]:
                print('LESS')
                break
        

Measured memory_bytes: 3060
import copy
import itertools
from itertools import product

def main():
    # productを使ってパターンを列挙して考える方法
    H, W, K = map(int, input().split())
    # あとで足し算で計算するので#は1にそれ以外は0へ
    C = [[1 if v == '#' else 0 for v in input()] for _ in range(H)]
    ans = 0
    # 塗り直すか塗り直さないかの01のパターンを出す
    HC = list(product([0,1], repeat=H))
    WC = list(product([0,1], repeat=W))
    # 選んだところは0に塗り直す
    c = copy.deepcopy(C)
    for hc in HC:
        for wc in WC:
            cnt = 0
            for hi, h in enumerate(hc):
                if h == 1:
                    for w in range(W):
                        c[hi][w] = 0
            for wi, w in enumerate(wc):
                if w == 1:
                    for h in range(H):
                        c[h][wi] = 0
            # flatten
            cnt = sum(list(itertools.chain.from_iterable(c)))
            if cnt == K:
                ans += 1
            c = copy.deepcopy(C)
    print(ans)

if __name__ == '__main__':
    main()


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

struct S {
	int x, y, cost;
	bool operator <(const S& x) const {
		return cost > x.cost;
	}
};

struct P {
	int x, y;
};

const int INF = 1 << 28;
int H, W;
int ng[31][31][4];
int d[31][31];
int gcost[31][31][4][31][31];

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

bool in(int x, int y) {
	return 0 <= x && x < W && 0 <= y && y < H;
}

void bfs(int x, int y, int k) {
	queue<P> q;
	q.push({ W - 1, H - 1 });
	gcost[y][x][k][H - 1][W - 1] = 0;
	while(q.size()) {
		int X = q.front().x, Y = q.front().y;
		q.pop();
		int d = gcost[y][x][k][Y][X];
		for(int i = 0; i < 4; i++) {
			int NX = X + dx[i], NY = Y + dy[i];
			if(!in(NX, NY)) continue;
			if(ng[Y][X][i]) continue;
			if(gcost[y][x][k][NY][NX] > d + 1) {
				gcost[y][x][k][NY][NX] = d + 1;
				q.push({ NX, NY });
			}
		}
	}
}

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

	while(cin >> H >> W, H) {
		memset(ng, 0, sizeof ng);
		for(int i = 0; i < 2 * H - 1; i++) {
			int h = i / 2;
			if(i % 2 == 0) {
				for(int j = 0; j < W - 1; j++) {
					int a;
					cin >> a;
					if(a) {
						int w = j;
						ng[h][w][0] = ng[h][w + 1][2] = 1;
					}
				}
			}
			else {
				for(int j = 0; j < W; j++) {
					int a;
					cin >> a;
					if(a) {
						int w = j;
						ng[h][w][1] = ng[h + 1][w][3] = 1;
					}
				}
			}
		}

		fill((int*)begin(gcost), (int*)end(gcost), INF);
		for(int y = 0; y < H; y++) {
			for(int x = 0; x < W; x++) {
				for(int k = 0; k < 4; k++) {
					if(ng[y][x][k]) continue;
					int nx = x + dx[k], ny = y + dy[k];
					ng[y][x][k] = 1;
					if(in(nx, ny)) ng[ny][nx][(k + 2) % 4] = 1;
					bfs(x, y, k);
					ng[y][x][k] = 0;
					if(in(nx, ny)) ng[ny][nx][(k + 2) % 4] = 0;
				}
			}
		}

		priority_queue<S> q;
		q.push({ W - 1,H - 1, 0 });
		fill((int*)begin(d), (int*)end(d), INF);
		d[H - 1][W - 1] = 0;

		while(q.size()) {
			int X = q.top().x, Y = q.top().y;
			int cost = q.top().cost;
			q.pop();
			if(d[Y][X] < cost) continue;
			for(int k = 0; k < 4; k++) {
				int NX = X + dx[k], NY = Y + dy[k];
				if(!in(NX, NY)) continue;
				int ncost = max(cost + 1, gcost[NY][NX][(k + 2) % 4][NY][NX]);
				if(d[NY][NX] > ncost) {
					d[NY][NX] = ncost;
					q.push({ NX, NY, ncost });
				}
			}
		}

		if(d[0][0] == INF) cout << -1 << endl;
		else cout << d[0][0] << endl;
	}
}

Measured memory_bytes: 17532
#include <cstdio>
#include <cstring>
#include <cmath>

int n, m;
int a[500005], b[500005];
int L[710], R[710], cnt[710][30];
int now[30];
char s[500005];

int main() {
    scanf("%d", &n);
    scanf("%s", s);
    int sz = std::sqrt(n);
    for (int i = 1; i <= n; ++i) a[i] = s[i - 1] - 'a', b[i] = (i - 1) / sz + 1;
    for (int i = 1; i <= b[n]; ++i) L[i] = (i - 1) * sz + 1, R[i] = i * sz;
    R[b[n]] = n;
    for (int i = 1; i <= b[n]; ++i)
        for (int j = L[i]; j <= R[i]; ++j)
            ++cnt[i][a[j]];
    scanf("%d", &m);
    for (int i = 1, opt; i <= m; ++i) {
        scanf("%d", &opt);
        if (opt == 1) {
            int x;
            char c[2];
            scanf("%d%s", &x, &c);
            --cnt[b[x]][a[x]];
            ++cnt[b[x]][a[x] = c[0] - 'a'];
        } else {
            int l, r;
            scanf("%d%d", &l, &r);
            int ans = 0;
            memset(now, 0, sizeof(now));
            if (b[l] == b[r]) {
                for (int i = l; i <= r; ++i) if (!now[a[i]]++) ++ans;
            } else {
                for (int i = b[l] + 1; i <= b[r] - 1; ++i)
                    for (int j = 0; j < 26; ++j) {
                        if (!now[j] && cnt[i][j]) ++ans;
                        now[j] += cnt[i][j];
                    }
                for (int i = l; i <= R[b[l]]; ++i) if (!now[a[i]]++) ++ans;
                for (int i = L[b[r]]; i <= r; ++i) if (!now[a[i]]++) ++ans;
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


int main()
{
  int a,b;
  cin>>a>>b;
   string A,B;
   for(int i=0;i<b;i++)
   {
       A +=to_string(a);
   }
  
  for(int i=0;i<a;i++)
  {
      B += to_string(b);
  }
  
   string ans = min(A,B);
  
    cout<<ans<<endl;
    
    return 0;

}


Measured memory_bytes: 256
#157C
N, M = map(int, input().split())
S = [input().split() for _ in [0]*M]

for i in range(1000):
    if len(str(i)) != N:
        continue
    for s, c in S:
        if str(i)[int(s)-1] == c:
            continue
        else:
            break

    else:
        print(i)
        break
else:
    print(-1)

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nq = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nq[0];
        var q = nq[1];
        var s = Console.ReadLine().Trim();
        var qs = new Tuple<char, int>[q];
        for (int i = 0; i < qs.Length; i++)
        {
            var td = Console.ReadLine().Split().Select(x => x[0]).ToArray();
            qs[i] = Tuple.Create(td[0], td[1] == 'R' ? 1 : -1);
        }

        var p = -1;
        var left = p;
        for (int i = 0; i < qs.Length; i++)
        {
            var ii = qs.Length - 1 - i;
            if (p > s.Length - 1)
            {
                break;
            }

            if (p >= 0)
            {
                if (s[p] == qs[ii].Item1 && qs[ii].Item2 > 0)
                {
                    if (left == p)
                    {
                        left--;
                    }
                    p--;
                    continue;
                }
            }

            var prev = p - qs[ii].Item2;
            if (prev < 0 || prev > s.Length - 1 || s[prev] != qs[ii].Item1 || p > prev)
            {
                continue;
            }

            left = Math.Max(left, prev);
            p = prev;
        }
        p = s.Length;
        var right = p;
        for (int i = 0; i < qs.Length; i++)
        {
            var ii = qs.Length - 1 - i;
            if (p < 0)
            {
                break;
            }

            if (p <= s.Length - 1)
            {
                if (s[p] == qs[ii].Item1 && qs[ii].Item2 < 0)
                {
                    if (right == p)
                    {
                        right++;
                    }
                    p++;
                    Console.Error.WriteLine($"|{right}, >{p} {qs[ii]}");
                    continue;
                }
            }

            var prev = p - qs[ii].Item2;
            if (prev < 0 || prev > s.Length - 1 || s[prev] != qs[ii].Item1 || p < prev)
            {
                continue;
            }

            right = Math.Min(right, prev);
            p = prev;
            Console.Error.WriteLine($"|{right}, >{p} {qs[ii]}");
        }
        
        Console.Error.WriteLine($"({left}, {right}]");
        Console.WriteLine(right - (left + 1));
    }
}


Measured memory_bytes: 26400
#include <iostream>

int main(){

    int n;
    std::cin >> n;
    
    for(int i = 1; i <= n; i++){
        if(i % 3 == 0){
            std::cout << " " << i;
        }else if(i % 10 == 3){
            std::cout << " " << i;
        } else if( (i /10) % 10 == 3){
            std::cout << " " << i;
        } else if( (i /100) % 10 == 3){
            std::cout << " " << i;
        } else if( (i /1000) % 10 == 3){
            std::cout << " " << i;
        } else if( (i /10000) % 10 == 3){
            std::cout << " " << i;
        }
    }
    std::cout << "\n";
    
    return 0;
}


Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {
	
	double a, b;

	cin >> a >> b;

	if (a == b) {
		cout << "EQUAL" << endl;
	}
	else if (a > b) {
		cout << "GREATER" << endl;

	}
	else {
		cout << "LESS" << endl;

	}

	
}

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

int main(void) {
    int N=999999;
    int p[N] , s[N];
    p[0]=0 , s[0]=0;
    for (int i=1; i<N; i++){
        p[i] = 1;
        s[i] = 0;
    }
    for (int i=1; i<N; i++){
        if (p[i]==1){
            int n=i+1 , m=2*n;
            while (m<=N){
                p[m-1] = 0;
                m += n;
            }
        }
    }
    
    for (int i=1; i<N; i++){
        s[i] = s[i-1]+p[i];
    }
    int n;
    while (1){
        cin >> n;
        if (cin.eof())
            break;
        cout << s[n-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 8968
#include <bits/stdc++.h>
using namespace std;
const int inf=1<<30;
struct edge{	int to,cost;	};
int main(){
	int n,m,k;	cin>>n>>m>>k;
	vector<edge> e[n];
	vector<int> dist(n,inf);
	for(int i=0;i<m;i++){
		int a,b,l;	cin>>a>>b>>l;	a--;	b--;
		e[a].push_back((edge){b,l});
		
		e[b].push_back((edge){a,l});
	}
	for(int i=0;i<k;i++){
		int s;	cin>>s;	s--;
		dist[s]=0;
		queue<int> q;	q.push(s);
		while(!q.empty()){
			int now=q.front();	q.pop();
			for(int i=0;i<(int)e[now].size();i++){
				if(dist[e[now][i].to]>dist[now]+e[now][i].cost){
					dist[e[now][i].to]=dist[now]+e[now][i].cost;
					q.push(e[now][i].to);
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<(int)e[i].size();j++){
			ans=max(ans,(dist[i]+dist[e[i][j].to]+e[i][j].cost+1)/2);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    cin >> N >> K;

    double res = 0;
    for(int i=1;i<=N;i++){
    	ll tmp = i;
    	ll need = 0;
    	while(tmp < K){
    		need++;
    		tmp *= 2;
    	}
    	res += pow(0.5, need);
    }
    res /= N;
    printf("%.10f\n", res);
    return 0;
}

Measured memory_bytes: 384
ret = ''
while True:
   h,w = map(int, raw_input().split())
   if h == w == 0: 
       break   
   ret += '#'*w+'\n'
   ret += ('#' + '.' * (w-2) + '#\n') * (h - 2)
   ret += '#'*w+'\n\n'
print ret, 

Measured memory_bytes: 6428
#include <cstdio>
#include <cstring>
#include <cstdlib>

typedef struct tree_{
    int value;
    struct tree_ *left;
    struct tree_ *right;
}tree;

void preorder(tree *p){
    if(p==NULL)return;
    printf(" %d",p->value);
    preorder(p->left);
    preorder(p->right);
}

void inorder(tree *p){
    if(p==NULL)return;
    inorder(p->left);
    printf(" %d",p->value);
    inorder(p->right);
}

tree *insert(tree *p, int x){
    if(p==NULL){
        p = (tree *)malloc(sizeof(tree));
        p->value = x;
        p->left = NULL;
        p->right = NULL;
    }else{
        if(p->value>x)p->left = insert(p->left, x);
        else if(p->value<x)p->right = insert(p->right, x);
    }
    return p;
}

int main(){
    int i, n, x;
    char cmd[7];
    tree *root = NULL;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",cmd);
        if(strcmp(cmd,"insert")==0){
            scanf("%d",&x);
            root = insert(root, x);
        }else if(strcmp(cmd,"print")==0){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }else return -1;
    }
    return 0;
}



Measured memory_bytes: 18196
#include <stdio.h>

void search(const int *T, int *ops, const int i) {
    if (i < 3) {
        ops[i] = 1;
        search(T, ops, i + 1);
        if (T[i + 1] == 0) {
            return;
        } else {
            int sum = T[0];
            for (int j = 0; j < 3; j++) {
                sum += T[j + 1] * ops[j];
            }
            if (sum == 7) {
                return;
            } else {
                ops[i] = -1;
                search(T, ops, i + 1);
            }
        }
    } else {
        return;
    }
}

int main() {
    char tmp;
    int T[4];
    for (int i = 0; i < 4; i++) {
        scanf("%c", &tmp);
        T[i] = tmp - '0';
    }

    int ops[3];
    search(T, ops, 0);

    printf("%d", T[0]);
    for (int i = 0; i < 3; i++) {
        printf("%c%d", (ops[i] == 1 ? '+' : '-'), T[i + 1]);
    }
    printf("=7\n");

    return 0;
}


Measured memory_bytes: 128