akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main () {

    int N, M;
    cin >> N >> M;

    bool map[N][N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            map[i][j] = false;
        }
    }

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        map[a][b] = map[b][a] = true;
    }

    int path[N - 1];
    for (int i = 0; i < N - 1; i++) {
        path[i] = i + 1;
    }

    int ans = 0;
    do {
        int cur = 0;
        bool all_visitable = true;
        for (int i = 0; i < N - 1; i++) {
            int next = path[i];
            if (!map[cur][next]) {
                all_visitable = false;
                break;
            }
            cur = next;
        }
        if (all_visitable) {
            ans++;
        }
    } while (next_permutation(path, path + N - 1));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  if (s[s.size()-1] == 's') cout << s << "es" << endl;
  else cout << s << "s" << endl;

  return 0;
}


Measured memory_bytes: 3624
use std::io::{self, BufRead};

fn main() {
    let si = io::stdin();
    let mut l = si.lock().split(b'\n').next().unwrap().unwrap();
    let pos = l.iter().position(|&b| b == b' ').unwrap();
    l.remove(pos);
    println!("{}", if is_square(String::from_utf8(l).unwrap().parse().unwrap()) {
        "Yes"
    } else {
        "No"
    });
}

fn is_square(n: u32) -> bool {
    let s = (n as f32).sqrt() as u32;
    s * s == n
}

Measured memory_bytes: 4352
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

a, b = inm()
print(a * b)


Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9 + 7;

int main() {
	int h, w;
	scanf("%d%d", &h, &w);
	string arr[h];
	vector<vector<int>>dp(h, vector<int>(w, 0));
	
	for(int row = 0; row < h; ++row) {
        cin>>arr[row];
    }
   
	
        dp[0][0]=1;
        
        for(int i=1;i<w;i++) {
        	if(arr[0][i] != '#')
            	dp[0][i]=1;
            else
            	break;
        }    	
        
        for(int i=1;i<h;i++) {
        	if(arr[i][0] != '#')
        		dp[i][0]=1;
        	else
        		break;
        }		
        
        for(int i=1;i<h;i++) {
            for(int j=1;j<w;j++) {
            	
            	if(arr[i][j] == '#')
            		dp[i][j]=0;
            		
            	else 
            		dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
            		
            	//if(dp[i][j] >= mod)	
            	//	dp[i][j]-=mod;
            		
            	//cout<<dp[i][j]<<" ";	
            	}    	
               
            
            //cout<<endl;
		}    
            
        
        cout<<dp[h-1][w-1]<<"\n";		
			
			
}

Measured memory_bytes: 5248
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;

int N;
string S[100000];

int main(){
    cin>>N;
    rep(i,N) cin>>S[i];

    map<string,int> m;
    rep(i,N) m[S[i]]++;

    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;
}

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

int main(void){
	int* num = new int[ 3 ];
	for( int loop = 0 ; loop < 3 ; loop++ ) cin >> num[loop];
	int memo;
	for( int loop = 0 ; loop < 3 ; loop++ ){
		for( int sort = 0 ; sort < 3-1-loop ; sort++ ){
			if( num[ sort ] > num[ sort+1 ] ){
				memo = num[ sort ];
				num[ sort ] = num[ sort+1 ];
				num[ sort + 1 ] = memo;
			}
		}
	}
	cout << num[ 0 ] << " "<< num[ 1 ] << " "<< num[ 2 ] << endl;
	delete[] num;
	num = 0;
	return 0;
}

Measured memory_bytes: 1200
v=[4,1,4,1,2,1,2,1]
while True:
    try:
        p=map(int,raw_input().split(" "))
        min=[]
        min_value=0
        
        for i in range(8):
            count=0
            for j in range(8):
                if p[(j)%8]-v[(j+i)%8]>=0:
                    count+=p[(j)%8]-v[(j+i)%8]
            if len(min)==0:
                min_value=count
                min.append(i)
            else:
                if count<min_value:
                    min_value=count
                    min=[]
                    min.append(i)
                elif count==min_value:
                    min.append(i)
        min1_value=41412122
        for i in range(len(min)):
            value=""
            for j in range(8):
                value+=str(v[(j+min[i])%8])
            if min1_value>int(value):
                min1_value=int(value)
                min1=min[i]
        solve=[]
        for i in range(8):
            solve.append(str(v[(i+min1)%8]))
        print " ".join(solve)
    except:
        break

Measured memory_bytes: 4284
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, k;
    cin >> n >> k;
    ll res = 0, h;
    REP(i, n){
        cin >> h;
        if(h >= k) res++;
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<map<char, int> > vec(N);
    string str;
    cin >> str;
    for(int i=0; i<str.size(); i++) {
        vec[0][str[i]]++;
    }
    for(int n=1; n<N; n++) {
        cin >> str;
        
        for(int i=0; i<str.size(); i++) {
            if(vec[n][str[i]]<vec[n-1][str[i]]) {
                vec[n][str[i]]++;
            }
        }
    }
    
    string ans;
    for(auto itr=vec[N-1].begin(); itr!=vec[N-1].end(); itr++) {
        for(int i=0; i<itr->second; i++) {
            ans += itr->first;
        }
    }
    
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int H,W,N;
    cin >> H >> W >> N;
    int ans = N/max(H,W);
    if (N%max(H,W)!=0){
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n;
	int a[100],sol[100];
	int i;
	
	scanf("%d",&n);
	for(i=0; i<n; i++) {scanf("%d",&a[i]); sol[n-i-1]=a[i];}
	
	for(i=0; i<n; i++) {printf("%d",sol[i]); if(i<n-1)printf(" ");}
	printf("\n");
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  int count=0;
  for(int i=1;i<=n;i++){
    int c=0;
    for(int j=1;j<=i;j++){
      if(i%j==0){
        c++;
      }
    }
    if(c==8 && i%2==1){
      count++;
    }
  }
  cout<<count<<endl;
}

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

int main(){
    string s ; cin >> s ;
    int cnt = 0 ;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='0') cnt++ ;
    }
    cout << 2*min(cnt,(int)s.size()-cnt) << endl ;
}

Measured memory_bytes: 512
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
int N,M;
int L[100010],R[100010],F[100010] = {0};
int main(){
	cin >> N >> M;
	int ans = 0;
	vector<pair<int,int>> v;
	for(int i=0;i<M;i++){
		cin >> L[i] >> R[i];
		v.push_back({R[i],L[i]});
	}
	sort(v.begin(),v.end());
	int t =0;
	for(int i=0;i<v.size();i++){
		if(t<=v[i].second){
			ans++;
			t = v[i].first;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
#define N 100055
#define ll long long
int dp[N],ar[N];
int main() {
    memset(dp, 25,sizeof dp);
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)
        scanf("%d",&ar[i]);
    dp[0] = dp[1] = 0;
    for(int i=2; i<=n; ++i) {
        dp[i] = dp[i-1] + abs(ar[i-1] - ar[i] );
        if(i>2) {
            dp[i] = min(dp[i], dp[i-2] + abs(ar[i-2] - ar[i] ) );
        }
    }
    printf("%d",dp[n]);
    return 0;
}


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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("C.in", "r", stdin);
	freopen ("C.out", "w", stdout);
#endif
}

const int N = 1e5 + 1e3;

int n, a[N], sgn[N];

long long sum, ans, opt, res;

int main () {

	File();

	For (i, 1, n = read()) a[i] = read();

	res = 1e18;
	for (sgn[n] = 1; sgn[n] >= -1; sgn[n] -= 2) {
		Fordown (i, n - 1, 1) sgn[i] = - sgn[i + 1];
		sum = ans = 0;
		For (i, 1, n) {
			sum += a[i];
			if (sum * sgn[i] > 0) continue;
			ans += abs(sum) + 1; sum = sgn[i];
		}
		chkmin(res, ans);
	}
	printf ("%lld\n", res);

	return 0;

}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>
#include<numeric>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

const long long MAX = 2002;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	long long N, K, cnt = 0, tmp, ans = 0;

	cin >> N >> K;

	COMinit();

	for (int i = 1; i <= K; i++) {
		cout << (COM(K-1, i - 1) * COM(N - K + 1, i)) % MOD << endl;
	}

	char qq;
	cin >> qq;
	return 0;
}

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

int main(){
  int q,h,s,d;cin >> q >> h >> s >> d;
  int n; cin >> n;
  long long ans = 0;
  long long two_min[4] = {q*8, h*4, s*2, d};
  long long one_min[3] = {q*4, h*2, s};
  sort(two_min, two_min+4);
  sort(one_min, one_min+3);
  if(n % 2 == 0){
    ans = (n/2)*(two_min[0]);
  }else{
    ans += (n/2)*(two_min[0]) + one_min[0];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<bits/stdc++.h>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}
int dfs(int n, vector<bool> ver, int N, vector<vector<bool>> path) {
	ver[n] = true;
	bool last = true;
	rep(i, N) {
		last = last && ver[i];
	}
	if (last) {

		return 1;
	}
	ll ans = 0;
	rep(i, N) {
		if (!ver[i]&&path[i][n]) {
			ans += dfs(i, ver, N, path);
			//cout << ans << endl;
		}
	}
	return ans;
}
int main() {
	int n, m;
	cin >> n >> m;
	vector < vector < bool>> path(n, vector<bool>(n, false));
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		path[a][b] = true;
		path[b][a] = true;
	}
	vector<bool> ver(n, false);
	//ver[0] = true;
	cout << dfs(0, ver, n, path) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
//pi = 3.14159265358979323846

int main() {

    rep(i, 10000){
        int h, w;
        cin >> h >> w;
        if(h == 0  && w == 0) break;
        rep(i, h){
            rep(j, w){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }

}


Measured memory_bytes: 3116
import re
S_ = input()
T = input()
Tr = T[::-1]
Sr = S_[::-1]
reg = "".join(map(lambda x: "[{}?]".format(x), Tr))
ans = re.sub(reg, Tr, Sr, count=1)
if ans.count(Tr)==1:
    print(ans.replace("?", "a")[::-1])
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
typedef long long ll;

void ans(bool qus)
{
    if (qus == true)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

void Ans(bool qust)
{
    if (qust == true)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
}

using namespace std;

/////////////////////////////////////////

bool solve(int a,int b){
    if(a % 2 == 0 || b % 2 == 0)
        return true;
    else
        return false;
}

int main(){
    int a,b;
    cin >> a >> b;
    if (solve(a,b)){
        cout << "Even" << endl;
    }
    else
        cout << "Odd" << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

is_possible = True
for i in range(n):
    if a[i] > 2**i - 1:
        is_possible = False
        break
if a[n] > 2**n:
    is_possible = False

s = 0
for i in range(n + 1):
    s += a[i] * (2**(n - i))
if s > 2**n:
    is_possible = False

b = [0] * (n + 1)
for i in range(n):
    b[i + 1] = (a[i] + b[i]) * 2

c = [0] * (n + 1)
c[n] = a[n]
ans = a[n]
for i in reversed(range(n)):
    if (c[i + 1] + 1) // 2 + a[i] + b[i] > 2**i:
        is_possible = False
        break
    c[i] = min(c[i + 1], 2**i - a[i] - b[i]) + a[i]
    ans += c[i]

# print(a)
# print(b)
# print(c)

if is_possible:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 711676
h, w = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(h)]
ls = [[bool(a % 2) for a in l] for l in ls]

res = []
started = False
steps = []
for i in range(h):
    odd = i % 2
    for j in range(w):
        if odd:
            j = w - j - 1
        if started:
            steps.append((i, j))
        if ls[i][j]:
            if not started:
                steps = [(i, j)]
                started = True
            else:
                for s, t in zip(steps, steps[1:]):
                    res.append((s[0], s[1], t[0], t[1]))
                started = False

print(len(res))
for row in res:
    row = map(lambda x: x + 1, row)
    print(*row)

Measured memory_bytes: 23536
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <complex>
using namespace std;

int main()
{
	int R,G,B,N;
	cin>>R>>G>>B>>N;
	int cnt = 0;
	for(int i=0; R*i<=N; i++)
	{
		for(int j=0; R*i+B*j<=N; j++)
		{
			int remain = N-(R*i+B*j);
			if(remain%G == 0)
			{
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 256
#                           जय श्री राम

import sys; import math; from collections import *
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, input().split())
def get_list(): return list(get_ints())
def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9+7); SEXYMOD = 998244353; MAXN = int(1e5)

# sys.stdin  = open("input.txt","r"); sys.stdout = open("output.txt","w")

# for _testcases_ in range(int(input())):
n = int(input())
ans = []
while n:
    n -= 1
    n, r = divmod(n, 26)
    ans.append(chr(ord('a') + r))
print("".join(reversed(ans)))



'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Measured memory_bytes: 65188
use std::io;


fn main() {
    let (w, h, x, y) = {
        let i = read::<f64>();
        (i[0], i[1], i[2], i[3])
    };

    let area = w * h / 2.0;
    let way = if x + x == w && y + y == h { 1 } else { 0 };
    println!("{} {}", area, way);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
n = int(input())
nlist = list(map(int, input().split()))
def SelectionSort(A, n):
    count = 0
    for i in range(n):
        mini = i
        a = A[i]
        for j in range(i, n):
            if(A[j] < A[mini]):
                mini = j
        if(mini != i):
            A[i] = A[mini]
            A[mini] = a
            count += 1
            
    for i in range(n):
        if(i == n-1):
            print('{}'.format(A[i]), end = '')
        else:
            print('{}'.format(A[i]), end = ' ')
    print()
    print(count)
SelectionSort(nlist, n)


Measured memory_bytes: 5612
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> // sqrt
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int num;
    cin >> num;
    int sum = 0;
    for(int i = 0; i < num; i++) {
        int val;
        cin >> val;
        sum += (val%2);
    }
    int ans = (sum == 0 ? 0 : 1);
    cout << (ans ? "first" : "second") << endl;
    return 0;
}

Measured memory_bytes: 3604
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    n, m = getList()
    g = []
    for i in range(m):
        g.append(getList())
    # print(g)
    ll = [defaultdict(int) for i in range(3)]

    for i in range(n):
        l = getZList()
        for j, nn in enumerate(l):
            ll[(i+j) % 3][nn] += 1
    # print(ll)
    ans = INF
    for i in range(m):
        for j in range(m):
            if i == j:
                continue
            for k in range(m):
                if i == k or j == k:
                    continue
                tmp = 0
                for kk, vv in ll[0].items():
                    tmp += g[kk][i] * vv
                for kk, vv in ll[1].items():
                    tmp += g[kk][j] * vv
                for kk, vv in ll[2].items():
                    tmp += g[kk][k] * vv
                    # print(tmp)
                # print(i, j, k, tmp)
                ans = min(ans, tmp)

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 75596
n,k = map(int,input().split())
a_input = list(map(lambda x:int(x)-1,input().split()))

visited = [0]*n
route=[0]
stack=[a_input[0]]

def dfs(visited,route,stack,k):
    while True:
        x = stack.pop(0)
        k-=1
        if k==0:
            print(x+1);exit()
            break
        if visited[x]==1:
            break
        stack.append(a_input[x])
        route.append(x)
        visited[x]=1
    return route,x,k+1

route,x,k = dfs(visited,route,stack,k)
loop = route[route.index(x):]

print(loop[k%len(loop)-1]+1)
        

Measured memory_bytes: 32304
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1:
        break
    sum=m+f
    if m==-1 or f==-1 :
        print("F")
    elif sum>=80:
        print("A")
    elif sum>=65:
        print("B")
    elif sum>=50:
        print("C")
    elif sum>=30:
        if r>=50:
            print("C")
        else:
            print("D")
    else:
        print("F")
        


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

int main(){
    int N; cin >> N;
    int A,B,C; cin >> A >> B >> C;
    //先読みが必要
    vector<string> s(N);
    for(int i=0; i<N; i++){
        cin >> s.at(i);
    }
    
    string result;
    
    
    bool ok = true;
    for(int i=0;i<N; i++){
        
        if(s.at(i)=="AB"){
            
            if(A==1 && B==1 && i!=N-1){
                if(s.at(i+1)=="AC"){
                    A++;
                    B--;
                    result.push_back('A');
                }else{
                    A--;
                    B++;
                    result.push_back('B');
                }
            }
            
            else if(A==0 && B==0){
                cout << "No" << endl;
                ok = false;
                break;
            }
            
            else if(A>=B){
                A--;
                B++;
                result.push_back('B');
            }
            else{
                A++;
                B--;
                result.push_back('A');
            }
            
        }else if(s.at(i)=="AC"){
            
            if(A==1 && C==1 && i!=N-1){
                if(s.at(i+1)=="AB"){
                    A++;
                    C--;
                    result.push_back('A');
                }else{
                    A--;
                    C++;
                    result.push_back('C');
                }
            }
            
            
            else if(A==0 && C==0){
                cout << "No" << endl;
                ok = false;
                break;
            }
            
            else if(A>=C){
                A--;
                C++;    result.push_back('C');
            }
            else{
                A++;
                C--;
                result.push_back('A');
            }
        }
        else{
            
            
            if(B==1 && C==1 && i!=N-1){
                if(s.at(i+1)=="AB"){
                    B++;
                    C--;
                    result.push_back('B');
                }else{
                    B--;
                    C++;
                    result.push_back('C');
                }
            }
            
            
            else if(B==0 && C==0){
                cout << "No" << endl;
                ok = false;
                break;
            }
            
            else if(B>=C){
                B--;
                C++;
                result.push_back('C');
            }
            else{
                B++;
                C--;
                result.push_back('B');
            }
        }
    }//for
    
    if(ok){
        
        cout << "Yes" << endl;
        
        for(int i=0; i<N; i++){
            cout << result.at(i) << endl;
        }
        
        
    }
    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6672
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll n, m, d;
    cin >> n >> m >> d;

    ld ans = 0;

    for(int i = 1; i < m; i++){
        ll ma = n - d;
        ld p = ((d==0?1.0:2.0) * (ld)ma) / ((ld)n * (ld)n);
        ans += p;
    }

    cout << fixed << setprecision(15) << ans << endl;
}

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


void change(char word[])
{
	int i;

	for(i=0;word[i]!='\0';i++){
		word[i] = tolower(word[i]);
	}
}

int main(void)
{
	char w[11], t[1001];
	char *adr;
	long long count;

	scanf("%s", w);
	change(w);

	count = 0;
	while(scanf("%s", t)!=EOF && strcmp("END_OF_TEXT", t)!=0){
		change(t);
		if(strcmp(t, w)==0){
			count++;
		}

	}

	printf("%ld\n", count);

	return 0;
}

Measured memory_bytes: 552
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-9;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int k,a,b;
	scanf("%d%d%d",&k,&a,&b);
	for(int i=a;i<=b;i++){
		if(i%k==0){
			printf("OK\n");return 0;
		}
	}
	printf("NG\n");
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
ll s[100010],t[100010];
int a,b;
ll unders(ll x){
    if(x<s[0])return -inf*1000;
    if(x>=s[a-1])return s[a-1];
    int l=0,r=a-1;
    while(r-l>1){
        if(s[(r+l)/2]<=x)l=(r+l)/2;
        else r=(r+l)/2;
    }
    return s[l];
}
ll uppers(ll x){
    if(x>s[a-1])return inf*1000;
    if(x<=s[0])return s[0];
    int l=0,r=a-1;
    while(r-l>1){
        if(s[(r+l)/2]>=x)r=(r+l)/2;
        else l=(r+l)/2;
    }
    return s[r];
}
ll undert(ll x){
    if(x<t[0])return -inf*1000;
    if(x>=t[b-1])return t[b-1];
    int l=0,r=b-1;
    while(r-l>1){
        if(t[(r+l)/2]<=x)l=(r+l)/2;
        else r=(r+l)/2;
    }
    return t[l];
}
ll uppert(ll x){
    if(x>t[b-1])return inf*1000;
    if(x<=t[0])return t[0];
    int l=0,r=b-1;
    while(r-l>1){
        if(t[(r+l)/2]>=x)r=(r+l)/2;
        else l=(r+l)/2;
    }
    return t[r];
}
ll solve(ll x){
    ll ds=unders(x),dt=undert(x),us=uppers(x),ut=uppert(x);
    ll ret;
    ret=min({x-ds+min(ds-undert(ds),uppert(ds)-ds),
             x-dt+min(dt-unders(dt),uppers(dt)-dt),
             us-x+min(us-undert(us),uppert(us)-us),
             ut-x+min(ut-unders(ut),uppers(ut)-ut)
             });
    return ret;
}
int main(){
    cin>>a>>b;
    int q;cin>>q;
    rep(i,a)cin>>s[i];
    rep(i,b)cin>>t[i];
    rep(i,q){
        ll x;cin>>x;
        cout<<solve(x)<<endl;
    }
}

Measured memory_bytes: 2816
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	int hit,blow;
	char num[11];
};

vector<Info> info;
int Keta,num_candidate;
ll POW[12] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000};
ll ans;

int calc_hit(char left[11],char right[11]){

	int hit = 0;

	for(int i = 0; i < Keta; i++){
		if(left[i] == right[i])hit++;
	}
	return hit;
}

int calc_blow(char left[11],char right[11],int right_num){

	int blow = 0;

	int check_left[10];
	for(int i = 0; i < 10; i++)check_left[i] = -1;
	for(int i = 0; i < Keta; i++){
		check_left[left[i]-'0'] = i;
	}

	for(int i = 0; i < right_num;i++){
		if(check_left[right[i]-'0'] != -1 && check_left[right[i]-'0'] != i)blow++;
	}
	return blow;
}



void recursive(char buf[11],bool used[10],int count){
	if(num_candidate > 1)return;

	bool FLG;

	if(count == Keta){

		FLG = true;
		for(int i = 0; i < info.size(); i++){
			if(calc_blow(info[i].num,buf,count) != info[i].blow || calc_hit(info[i].num,buf) != info[i].hit){
				FLG = false;
				break;
			}
		}

		if(FLG){
			num_candidate++;
			if(num_candidate >= 2){
				return;
			}
			ans = 0;
			for(int i = 0; i < count; i++){
				ans = 10*ans + buf[i] - '0';
			}
		}

		return;
	}

	FLG = true;
	int blow;
	for(int i = 0; i < info.size(); i++){
		if((blow = calc_blow(info[i].num,buf,count)) > info[i].blow || blow+(Keta-count) < info[i].blow){
			FLG = false;
			break;
		}
	}
	if(!FLG)return;

	for(int i = 0; i < 10; i++){
		if(!used[i]){
			char next_buf[11];
			bool next_used[10];
			for(int k = 0; k < Keta; k++)next_buf[k] = buf[k];
			next_buf[count] = '0' + i;
			for(int k = 0; k < 10; k++)next_used[k] = used[k];
			next_used[i] = true;
			recursive(next_buf,next_used,count+1);
		}
	}
}

void func(int H){

	info.clear();

	num_candidate = 0;

	for(int loop = 0; loop < H; loop++){
		Info data;
		scanf("%s %d %d",data.num,&data.hit,&data.blow);
		info.push_back(data);
	}

	char buf[11];
	bool used[10];
	for(int i = 0; i < 10; i++)used[i] = false;
	recursive(buf,used,0);

	if(num_candidate == 1){
		ll tmp = POW[Keta-1];
		if(tmp > ans){
			printf("0");
		}
		printf("%lld\n",ans);
	}else{
		printf("NO\n");
	}
}


int main(){

	int H;

	while(true){
		scanf("%d %d",&Keta,&H);
		if(Keta == 0 && H == 0)break;

		func(H);
	}
	return 0;
}

Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
const int N=200005,M=1e9+7;
typedef long long ll;
int fac[N],a[N];
ll X;
int out[N],l,fa[N],in[N],sd[N],f[20][N],ne[N],tot,fi[N],zz[N],T,n,m;
struct Ask{
	int x,y,z;
}A[N];
int cmp(Ask x,Ask y){
	return x.z<y.z;
}
int find(int x){
	if (x==fa[x])return x;
	return fa[x]=find(fa[x]);
}
int pd(int x,int y){
	if (!x)return 1;
	return in[x]<=in[y]&&out[x]>=out[y];
}
int lca(int x,int y){
	if (x==y)return x;
	if (sd[x]>sd[y])swap(x,y);
	for (int i=19;i>=0;i--)
		if (!pd(f[i][x],y))x=f[i][x];
	return f[0][x];	
}
void dfs(int x,int y,int z){
	sd[x]=z;f[0][x]=y;in[x]=++l;
	for (int i=fi[x];i;i=ne[i])dfs(zz[i],x,z+1);
	out[x]=++l;
}
void jb(int x,int y){
	ne[++tot]=fi[x];
	fi[x]=tot;
	zz[tot]=y;
}
int main(){
	T=1;
	fac[0]=1;
	for (int i=1;i<N;i++)fac[i]=fac[i-1]*2%M;
	while (T--){
		tot=0;memset(fi,0,sizeof fi);
		memset(zz,0,sizeof fi);
		memset(ne,0,sizeof ne);
		memset(f,0,sizeof f);
		memset(in,0,sizeof in);
		memset(out,0,sizeof out);
		memset(a,0,sizeof a);
		scanf("%d%d%lld",&n,&m,&X);
		for (int i=1;i<=m;i++)scanf("%d%d%d",&A[i].x,&A[i].y,&A[i].z);
		sort(A+1,A+m+1,cmp);
		for (int i=1;i<2*n;i++)fa[i]=i;
		l=0;ll num=0;int cnt=n;
		for (int i=1;i<=m;i++){
			int x=find(A[i].x),y=find(A[i].y);
			if (x!=y){
				cnt++;
				jb(cnt,x);jb(cnt,y);
				a[cnt]=A[i].z;
				fa[x]=fa[y]=fa[cnt];
				num+=a[cnt];
			}
		}
		dfs(2*n-1,0,0);int ans=0;
		for (int i=1;i<=19;i++)
			for (int j=1;j<2*n;j++)f[i][j]=f[i-1][f[i-1][j]];
		for (int i=1;i<=m;i++)A[i].z-=a[lca(A[i].x,A[i].y)];
		sort(A+1,A+m+1,cmp);	
		for (int i=2;i<=m;i++)
			if (num+A[i].z==X)(ans+=fac[m-i])%=M;
		printf("%d\n",ans*2%M);	
	}
	return 0;
}

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

int main(){
    int a, b, c, i;

    scanf("%d %d %d", &a, &b, &c);
    for(i = 0; i < (b + 1); i++){
        if(c == ((a * i) % b)) {
            printf("YES");
            exit(0);
        }
    }
    printf("NO");
    return 0;
}

Measured memory_bytes: 128
#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<int, int>;
int main(void){
  int x[5];
  rep(i,5) cin >> x[i];

  rep(i,5){
    if (x[i] == 0) {
      cout << i + 1 << endl;
      break;
    }
  }
}


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

template <class S, class F>
struct SegTreeL {
  using FX = function<S(S, S)>;
  using FA = function<S(S, F)>;
  using FF = function<F(F, F)>;
  int n;
  FX fx;
  FA fa;
  FF ff;
  const S es;
  const F ef;
  vector<S> dat;
  vector<F> laz;
  SegTreeL(int n_, FX fx_, FA fa_, FF ff_, S es_, F ef_)
    : fx(fx_), fa(fa_), ff(ff_), es(es_), ef(ef_) {
      n = 1;
      while(n_ > n) n <<= 1;
      dat.assign(n*2-1, es);
      laz.assign(n*2-1, ef);
  }
  inline int chld(int k) {return k*2+1;}
  inline int chrd(int k) {return k*2+2;}
  void set(int i, S s) {dat[i+n-1] = s;}
  void build() {
    for(int k = n-2; k >= 0; k--) dat[k] = fx(dat[chld(k)], dat[chrd(k)]);
  }
  void eval(int k) {
    if(laz[k] == ef) return;
    if(k < n-1) {
      laz[chld(k)] = ff(laz[chld(k)], laz[k]);
      laz[chrd(k)] = ff(laz[chrd(k)], laz[k]);
    }
    dat[k] = fa(dat[k], laz[k]);
    laz[k] = ef;
  }
  void update(int a, int b, F x, int k, int l, int r) {
    eval(k);
    if(a <= l and r <= b) {
      laz[k] = ff(laz[k], x);
      eval(k);
    }
    else if(a < r and l < b) {
      update(a, b, x, chld(k), l, (l+r)>>1);
      update(a, b, x, chrd(k), (l+r)>>1, r);
      dat[k] = fx(dat[chld(k)], dat[chrd(k)]);
    }
  }
  void update(int a, int b, F x) {update(a, b, x, 0, 0, n);}
  S query(int a, int b, int k, int l, int r) {
    eval(k);
    if(r <= a or b <= l) return es;
    else if(a <= l and r <= b) return dat[k];
    else {
      S vl = query(a, b, chld(k), l, (l+r)>>1);
      S vr = query(a, b, chrd(k), (l+r)>>1, r);
      return fx(vl, vr);
    }
  }
  S query(int a, int b) {return query(a, b, 0, 0, n);}
  //debug
  inline const S operator[](const int i) {return query(i, i+1);}
  void print() {for(int i = 0; i < n; i++) cout << (*this)[i] << (i == n-1?'\n':' ');}
};

struct alph {
  vector<int> a;
  alph():a(26) {}
  alph(char c):a(26) {a[c-'a']++;}
  alph(char c, char u):a(26) {a[c-'a']--;}
  inline const int &operator[](const int i) const {return a[i];}
  inline int &operator[](const int i) {return a[i];}
  bool operator==(const alph &A) {
    for(int i = 0; i < 26; i++) if(A[i] != a[i]) return false;
    return true;
  }
};


int main() {
  int n, q;
  string s;
  cin >> n >> s >> q;
  auto fx = [](alph u, alph v)->alph{alph res; for(int i = 0; i < 26; i++) res[i] += u[i]+v[i]; return res;};
  SegTreeL<alph, alph> seg(n, fx, fx, fx, alph(), alph());
  for(int i = 0; i < n; i++) seg.set(i, alph(s[i]));
  seg.build();
  while(q--) {
    int type;
    cin >> type;
    if(type == 1) {
      int id;
      char c;
      cin >> id >> c;
      id--;
      seg.update(id, id+1, alph(s[id], 'u'));
      s[id] = c;
      seg.update(id, id+1, alph(s[id]));
    }
    else {
      int l, r;
      cin >> l >> r;
      alph aa = seg.query(l-1, r);
      int cnt = 0;
      for(int i = 0; i < 26; i++) if(aa[i]) cnt++;
      cout << cnt << '\n';
    }
  }
}

Measured memory_bytes: 282292
def main():
    s=int(input())
    a=s//(10**9)
    b=s%(10**9)
    if s!=10**18:
        print(0)
        print(0)
        print(10**9)
        print(1)
        print(10**9-b)
        print(a+1)
    else:
        print(0)
        print(0)
        print(0)
        print(10**9)
        print(10**9)
        print(0)

if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
import math
import sys
from collections import Counter
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    s = [readline().rstrip() for _ in range(n)]
    c = Counter(s)
    lis = ['AC', 'WA', 'TLE', 'RE']
    for li in lis:
        print(li+' x ' + str(c[li]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16620
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; }
}
void solve() {
  int soremade = INF;
  int ans = 0;
  rep(i, 0, N - 1) {
    chmin(soremade, va[i]);
    // debug2(i, soremade);
    if (soremade >= va[i]) {
      //  debug(va[i]);
      ans++;
    }
  }
  cout << ans << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;

int dp[300][300]; //dp[i][j]:=[i,j)で取り除けるブロックの最大値
vector<int> W;

int rec(int l,int r){ //[r,l)
    if(~dp[l][r]) return dp[l][r];
    if(r-l<=1) return dp[l][r]=0;
    else if(r-l==2){
        if(abs(W[r-1]-W[l])<=1) return dp[l][r]=2;
        else dp[l][r]=0;
    }
    int ret=0;
    if(l+1<r-1&&abs(W[l]-W[r-1])<=1&&rec(l+1,r-1)==r-l-2){
        ret=max(ret,rec(l+1,r-1)+2);
        return dp[l][r]=ret;
    }
    for(int i=l+1;i<r;i++){
        ret=max(ret,rec(l,i)+rec(i,r));
    }
    return dp[l][r]=ret;
}


int main(){
    int n;
    while(cin >> n){
        if(!n) break; 
        W.clear();
        for(int i=0;i<n;i++){
            int w;
            cin >> w;
            W.push_back(w);
        }
        memset(dp,-1,sizeof(dp));
        cout << rec(0,n) << endl;
    }
    return 0;
}


Measured memory_bytes: 3504
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    set<int> as;
    set<int> sames;
    for (int i = 0; i < N; ++i)
    {
        int ai; cin >> ai;
        if (as.count(ai))
        {
            sames.insert(ai);
        }
        as.insert(ai);
    }
    int sameNum = sames.size();
    if (as.count(1))
    {
        if(sames.count(1)) cout << 0 << endl;
        else cout << 1 << endl;
        return 0;
    }
    for(auto itr = as.begin(); itr != as.end();)
    {
        int ai = *itr;
        bool deleted = false;
        for (int d = 2; d * d <= ai; ++d)
        {
            if (ai % d == 0)
            {
                if (as.count(d))
                {
                    deleted = true;
                    break;
                }
                if (as.count(ai / d))
                {
                    deleted = true;
                    break;
                }
            }
        }
        if (deleted)
        {
            itr = as.erase(itr);
            if (sames.count(ai))
            {
                --sameNum;
            }
        }
        else
        {
            ++itr;
        }
    }
    cout << as.size() - sameNum << endl;
}


Measured memory_bytes: 12968
import sys



if(__name__ == "__main__"):

    NK= input().strip().split()
    N = int( NK[0] )
    K = int( NK[1] )
    prices = [0] * N
    prices_str = input().strip().split()
    for i in range(N):
        prices[i] = int(prices_str[i])
    prices.sort()
    sum = 0
    for j in range(K):
        sum += prices[j]
    print(sum)


Measured memory_bytes: 9248
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  map<string, int> S;
  rep(i, N) {
    string s;
    cin >> s;
    S[s]++;
  }
  int num = 0;
  for (auto s : S) {
    num = max(num, s.second);
  }

  for (auto s : S) {
    if (num == s.second) cout << s.first << endl;
  }
  return 0;
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int ll
#define For(a, b, c) for(int a = b; a <= c; ++a)
#define Ford(a, b, c) for(int a = b; a >= c; --a)
#define All(a, b) for(auto &a : b)
#define Rep(a, b, c) for(int a = b; a < c; ++a)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define reset(a, b) memset(a, b, sizeof(a))
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))
#define bitone(i) __builtin_popcountll(i)
#define bitl(i) __builtin_clz(i)
#define bitr(i) __builtin_ctz(i)
#define vll vector<ll>
/********************************************************

Digvijay Bahadur Singh
MNNIT

*********************************************************/
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}


const int MOD=1e9+7;
const int N = 1e6+100;
/********************************************************************/
                 /* GRAPH*/
//vector<vector<ll>> g;
//vector<bool> vis1,vis2;
/*******************************************************************/
ll power(ll a,ll b)
{
   ll ans =1;
   while(b>0){
   if(b&1) ans = (ans%MOD * a%MOD)%MOD;
   a = (a%MOD * a%MOD)%MOD;
   b=b>>1;
   }
   return ans%MOD;
}


signed main(){
  ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
  ll n;

  
  ll T=1;
 // cin>>T;
  
   // T=1;
    
        while(T--)
        {
          string s;
          cin>>s;
          if(s[2]==s[3]&&s[4]==s[5])
          {
            cout<<"Yes\n";
          }
          else cout<<"No\n";
        }
    
      

  }

  



Measured memory_bytes: 256