akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int64_t N, X, M;
    cin >> N >> X >> M;
    vector<int64_t> values(M + 5);
    vector<int64_t> seen(M, -1);
    int64_t a = X;
    values[0] = a;
    seen[a] = 0;
    int64_t total = a;

    for (int64_t i = 1; i < N; i++) {
        a = a * a % M;
        values[i] = a;

        if (seen[a] >= 0) {
            int64_t start = seen[a];
            int64_t len = i - start;

            for (int64_t j = start; j < i; j++) {
                int64_t occur = (N - j + len - 1) / len - 1;
                total += occur * values[j];
            }

            break;
        }

        seen[a] = i;
        total += a;
    }

    cout << total << '\n';
}


Measured memory_bytes: 4792
#include <iostream>

using namespace std;

int main()
{
    int map[10][10];
    int white = 0;
    int max_den = 0;
    int x, y, size;
    char comma;
    
    for (int i = 0; i < 10; i++) 
        for (int j = 0; j < 10; j++)
            map[i][j] = 0;

    while (cin >> x >> comma >> y >> comma >> size) {
        if (size == 1) {  // 小
            for (int i = -1; i <= 1; i++) {
                for (int j = -1; j <= 1; j++) {
                    if ((i == -1 && j == -1) || (i == 1 && j == -1) ||
                        (i == -1 && j == 1) || (i == 1 && j == 1)) 
                        continue;
                    
                    if ((x + i < 0) || (x + i > 9) || 
                        (y + j < 0) || (y + j > 9))
                        continue;

                    map[x + i][y + j]++;
                }
            }
        }
        else if (size == 2 || size == 3) {  // 中
            for (int i = -1; i <= 1; i++) {
                for (int j = -1; j <= 1; j++) {
                    if ((x + i < 0) || (x + i > 9) || 
                        (y + j < 0) || (y + j > 9))
                        continue;

                    map[x + i][y + j]++;
                }
            }
        }

        if (size == 3) {
            if (y >= 0 && y <= 9) {
                if (x - 2 >= 0 && x - 2 <= 9)
                    map[x - 2][y]++;
                if (x + 2 >= 0 && x + 2 <= 9)
                    map[x + 2][y]++;
            }
            if (x >= 0 && x <= 9) {
                if (y - 2 >= 0 && y - 2 <= 9)
                    map[x][y - 2]++;
                if (y + 2 >= 0 && y + 2 <= 9)
                    map[x][y + 2]++;
            }
        }
    }

    for (int i = 0; i < 10; i++)
        for (int j = 0; j < 10; j++) {
            if (map[i][j] == 0)
                white++;
            else
                max_den = max(max_den, map[i][j]);
        }

    cout << white << '\n' << max_den << endl;

    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//constants
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1<<28;


int main(int argc, char **argv) {
    string s;
    cin >> s;
    bool flag = false;
    REP(i, s.size()){
        if (s[i] == 'C') flag = true;
        if (flag && s[i] == 'F'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

//mod逆元を使ったnCkの計算(速)
const int64_t MAX = 510000;
const int64_t MOD = 1000000007;

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

// 二項係数計算
int64_t COM(int64_t n, int64_t 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(){
  int N;
  cin >> N;
  vector<int> vec(N+1);
  for(int i=0; i<N+1; i++){
    cin >> vec.at(i);
  }
  COMinit();
  map<int,int> mp;
  int first = -1;
  int second = -1;
  for(int i=0; i<N+1; i++){
    if(mp.count(vec.at(i))){
      first = mp[vec.at(i)];
      second = N - i;
    }
    else{
      mp[vec.at(i)] = i;
    }
  }
  for(int i=0; i<N+1; i++){
    int64_t ans = COM(N+1,i+1);
    ans -= COM(first+second,i);
    ans += MOD;
    ans %= MOD;
    cout << ans << endl;
  }
}

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

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

  // ここにプログラムを追記
  int i;
  char c;
  for(i=0; i<N; i++){
    cin >> c;
    if (c == 'Y')
      break;
  }
  if (i == N)
    cout << "Three" << endl;
  else
    cout << "Four" << endl;
  return 0;
}

Measured memory_bytes: 256
A = []
boo = 0
for i in range(3):
	A.append(list(map(int, input().split())))
for i in range(2):
	for j in range(2):
		if A[i + 1][j] - A[i][j] != A[i + 1][j + 1] - A[i][j + 1]:
			boo = 1

if boo:
	print("No")
else:
	print("Yes")

Measured memory_bytes: 3060
in_line = raw_input()
buf = ""
for i in xrange(len(in_line)):
    if in_line[i].isupper():
        buf += in_line[i].lower()
    elif in_line[i].islower():
        buf += in_line[i].upper()
    else:
        buf += in_line[i]
print buf

Measured memory_bytes: 6360
const MAX_H: usize = 100;

fn main() {
    let mut sc = Scanner::new();
    let mut w: usize = sc.read::<usize>() - 1;
    let mut b: usize = sc.read::<usize>() - 1;

    let mut is_white = vec![vec![false; MAX_H]; MAX_H];
    for i in 0..MAX_H {
        for j in 0..(MAX_H / 2) {
            if i % 2 == 0 || j == (MAX_H / 2) - 1 || j % 2 == 1 {
                is_white[i][j] = true;
            } else if b == 0 {
                is_white[i][j] = true;
            } else {
                is_white[i][j] = false;
                b -= 1;
            }
        }
        for j in (MAX_H / 2)..MAX_H {
            if i % 2 == 0 || j == (MAX_H / 2) || j % 2 == 0 {
                is_white[i][j] = false;
            } else if w == 0 {
                is_white[i][j] = false;
            } else {
                is_white[i][j] = true;
                w -= 1;
            }
        }
    }

    println!("100 100");
    for i in 0..MAX_H {
        for j in 0..MAX_H {
            print!("{}", if is_white[i][j] { '.' } else { '#' });
        }
        println!()
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n, m;
		string s;
		cin >> n >> m >> s;
		vector<int> x(n+1, -1);
		int f = n;
		x[n] = 0;
		while(f > 0){
			int nex = f;
			for(int i = f-1; i >= max(f-m, 0); i--){
				if(s[i] == '0'){
					x[i] = x[f] + 1;
					nex = i;
				}
			}
			if(nex == f){
				cout << -1 << endl;
				return;
			}
			f = nex;
		}
		f = 0;
		vector<int> ans;
		while(f < n){
			for(int i = f+1; ; i++){
				if(x[i] == x[f]-1){
					ans.push_back(i-f);
					f = i;
					break;
				}
			}
		}
		for(int i=0; i<ans.size(); i++)cout << ans[i] << " ";
		cout << "\n";
		
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 1480
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int n, m;
    while (cin >> n >> m)
    {
        if (n == 0 && m == 0)
            break;
        vector<int> mx(n + 1);
        vector<int> mn(n + 1);
        int a, b;
        rep(j, m)
        {
            cin >> a >> b;

            rep(i, b)
            {
                int temp;
                cin >> temp;
                if (b == 1)
                    mn[temp] += a;
                mx[temp] += a;
            }
        }
        int hoge = 0;
        int hogeposi = 0;
        int piyo = INT_MAX;
        int piyoposi = 0;
        REP(i,1, mx.size())
        {
            if (hoge < mx[i])
            {
                hoge = mx[i];
                hogeposi = i;
            }
        }
        REP(i,1, mn.size())
        {
            if (piyo > mn[i] && i != hogeposi)
            {
                piyo = mn[i];
                piyoposi = i;
            }
        }
        cout << hoge-piyo + 1 << endl;
    }
    return 0;
}

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

const int mod = 924844033;
const int N = 2005;

int n, k, f[N][N][2][2], prd[N], g[N][N];
vector<int> a;

void upd(int &x, int y) {
	x += y; if (x >= mod) x -= mod;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> k;
	prd[0] = 1;
	for (int i = 1; i <= n; ++i) prd[i] = 1LL * i * prd[i - 1] % mod;
	f[0][0][0][0] = 1;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			for (int k = 0; k <= 1; ++k) {
				for (int l = 0; l <= 1; ++l) {
					// tai mot vi tri khong chon canh noi	
					upd(f[i + 1][j][0][0], f[i][j][k][l]);
					// tai mot vi tri neu dang khong co canh ta tao chu trinh
					if (!k && !l) upd(f[i + 2][j + 2][0][0], f[i][j][k][l]);
					// tai mot vi tri ta tao them canh cung loai
					if (k) upd(f[i + 1][j + 1][k][l], f[i][j][k][l]);
					// tai mot vi tri ta tao them canh neu khong co canh
					if (!k && !l) {
						upd(f[i + 1][j + 1][1][0], f[i][j][k][l]);
						upd(f[i + 1][j + 1][1][1], f[i][j][k][l]);
					}
				}
			}
		}
	}
	for (int i = 0; i < k; ++i) {
		int cnt = 0;
		for (int j = i; j < n; j += k) cnt++;
		a.push_back(cnt);
	}
	//for (int i = 0; i <= 3; ++i) cout << f[3][i][0][0] << '\n';
	g[0][0] = 1;
	for (int i = 1; i <= k; ++i) {
		int cnt = a[i - 1];
		for (int j = 0; j <= cnt; ++j) {
			for (int k = 0; k + j <= n; ++k) {
				upd(g[i][k + j], 1LL * g[i - 1][k] * f[cnt][j][0][0] % mod);
			}
		}
	}
	int res = 0;
	for (int i = 0; i <= n; ++i) {
		int t;
		if (i % 2 == 0) t = 1; else t = -1;
		res = res + 1LL * t * g[k][i] * prd[n - i] % mod;
		if (res < 0) res += mod; if (res >= mod) res -= mod;
	}
	cout << res;
}

Measured memory_bytes: 78720
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std; 
int main()
{
	char a[1001],b[1001];
	int lena,lenb,i;
	gets(a);
	gets(b);
	lena=strlen(a);
	lenb=strlen(b);
	sort(a,a+lena);
	sort(b,b+lenb);
	for(i=0;i<fmax(lena,lenb);i++)
	{
		if(a[i]<b[lenb-i-1])
		{
			printf("Yes\n");
			exit(0);
		}
		if(a[i]>b[lenb-i-1])
			break;
	}
	printf("No\n");
}

Measured memory_bytes: 128
// 解き直し.
// https://img.atcoder.jp/hitachi2020/editorial.pdf
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const int MAX = 1 << 10;
int gCum[MAX][MAX], grid[MAX][MAX];

int main(){
    
    // 1. 入力情報.
    int N, M;
    scanf("%d %d", &N, &M);
    
    // 2. 大きい方を保存.
    int eMax = max(N, M);
    
    // 以下, 解説通り.
    // https://www.youtube.com/watch?v=z9zEs79hHPE
    // 3. 累積和作成.
    rep(i, 1 << eMax) rep(j, 1 << eMax) gCum[i][j] = __builtin_popcount(i & j) % 2;
    
    // 4. 累積和からグリッド復元.
    rep(i, (1 << eMax) - 1){
        rep(j, (1 << eMax) - 1){
            grid[i][j] = gCum[i + 1][j + 1] + gCum[i + 1][j] + gCum[i][j + 1] + gCum[i][j];
            grid[i][j] %= 2;
        }
    }
    
    // 5. 出力.
    rep(i, (1 << N) - 1){
        rep(j, (1 << M) - 1) printf("%d", grid[i][j]);
        puts("");
    }
    return 0;
    
}

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

int main()
{
  long long n, k;

  cin >> n >> k;

  long long waru = 1000000007;

  long long ans = 0;

  for (long long i = k; i <= n + 1; i++)
  {
    long long low = i * (i - 1) / 2;
    long long high = (2 * n - i + 1) * i / 2;
    long long dif = high - low + 1;
    ans = (ans+dif)%waru;

  }
  cout << ans;
}


Measured memory_bytes: 3624
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
char str[MAXN];
int sum[MAXN],dp[MAXN];
vector<int> pos[3],rep;
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
int main()
{
    scanf("%s",str+1);
    n=strlen(str+1);
    for(int i=1;i<=n;i++)
    {
        if(str[i]=='a') sum[i]=(sum[i-1]+1)%3; else sum[i]=(sum[i-1]+2)%3;
        pos[sum[i]].push_back(i);
        if(i<n&&str[i]==str[i+1]) rep.push_back(i);
    }
    if(!rep.size())
    {
        puts("1");
        return 0;
    }
    dp[0]=1;
    for(int i=0;i<n;i++)
    {
        add(dp[i+1],dp[i]);
        auto it=lower_bound(rep.begin(),rep.end(),i+1);
        if(it==rep.end()) continue;
        int p=*it+1;
        for(int k=1;k<=2;k++)
        {
            if(k==1&&str[i+1]=='a') continue;
            if(k==2&&str[i+1]=='b') continue;
            int s=(sum[i]+k)%3;
            it=lower_bound(pos[s].begin(),pos[s].end(),p);
            if(it==pos[s].end()) continue;
            add(dp[*it],dp[i]);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++) if(sum[i]==sum[n]) add(ans,dp[i]);
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 2296
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define full(x) (bin((x)+1)-1)
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=3e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or m<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	
	const int N=1e5+10;
	//------------------FIXED------------------
	
	void main()
	{
		int a=qread(),b=qread();write(a*b);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int n;
long long f1,f2,f3;
int main()
{
	f1=2;
	f2=1;
    cin>>n;
    if(n==0)
    {
    	cout<<f1<<endl;
    	return 0;
    }
    if(n==1)
    {
    	cout<<f2<<endl;
    	return 0;
    }
    for(int i=2;i<=n;i++)
    {
    	f3=f1+f2;
    	f1=f2;
    	f2=f3;
    }
    cout<<f3<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

long long gcd(long long a, long long b){
    while(b != 0){
        long long tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

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

    while(--t >= 0){
        long long h, w;
        cin >> h >> w;

        long long g = gcd(h, w);
        h /= g;
        w /= g;

        long long a = 1;
        long long b = 1;
        if((h * w) % 2 == 1){
            a = (h * w + 1) / 2;
            b = (h * w) / 2;
        }
        cout << a << ' ' << b << endl;
    }

    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=10000005;
const int mod=998244353;
int n;
ll inv[max_n];
int main(){
    scanf("%d",&n);
    int k=n/2;
    ll ans=1;
    for(int i=1;i<=n;i++)ans=ans*3%mod;
    inv[1]=1;
    for(int i=2;i<=n;i++)inv[i]=inv[mod%i]*(mod-mod/i)%mod;
    ll res=0;
    ll tmp=1,c=1;
    for(int i=0;i<k;i++){
        res+=tmp*c%mod;res%=mod;
        tmp=tmp*2%mod;
        c=c*(n-i)%mod*inv[i+1]%mod;
    }
    res=res*2%mod;
    ans=(ans-res+mod)%mod;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 78336
// AtCoder Grand Contest 025 - Problem A: Digits Sum (https://agc025.contest.atcoder.jp/tasks/agc025_a?lang=en) 
#include <bits/stdc++.h>

using namespace std;

int solve(int N)
{
    int ans = 0;

    do {
        ans += (N % 10);
        N /= 10;
    } while (N);

    return ans == 1 ? 10 : ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    auto ans = solve(N);

    cout << ans << '\n';

    return 0;
}


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

#define fin stdin
#define fout stdout
//FILE *fin=fopen("a.in", "r"), *fout=fopen("a.out", "w");

#define MAXN 100009

std::vector <int> g[MAXN+1];
int urm[MAXN+1];
bool viz[MAXN+1], done[MAXN+1];
int frunza, sol[MAXN+1];

void dfs(int x){
    viz[x]=1;
    bool f=1;
    for(auto y:g[x]){
        if(viz[y]==0){
            urm[y]=x;
            dfs(y);
            f=0;
        }
    }
    if(f) frunza=x;
}

int main(){
    int n, m;
    fscanf(fin, "%d%d", &n, &m);

    for(int i=1; i<=m; i++){
        int x, y;
        fscanf(fin, "%d%d", &x, &y);

        g[x].push_back(y);
        g[y].push_back(x);
    }

    dfs(1);

    int y=frunza;
    int x=1;
    while(y!=x){
        sol[++sol[0]]=y;
        done[y]=1;
        y=urm[y];
    }

    sol[++sol[0]]=x;
    done[x]=1;

    bool cauta=1;
    while(cauta){
        y=0;
        for(auto z:g[x]){
            if(done[z]==0){
                y=z;
            }
        }
        if(y==0) cauta=0;
        else x=y, sol[++sol[0]]=y, done[y]=1;
    }

    fprintf(fout, "%d\n", sol[0]);
    for(int i=1; i<=sol[0]; i++)
        fprintf(fout, "%d ", sol[i]);

    fclose(fin);
    fclose(fout);
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    string w;
    cin>>w;
    set<string> dict;
    dict.insert(w);
    size_t l=w.length();
    char c=w[l-1];
    bool flag=true;
    rep(i,n-1){
        string x;
        cin>>x;
        l=x.length();
        if(c!=x[0]){
            flag=false;
        }
        dict.insert(x);
        c=x[l-1];
    }
    if(n!=dict.size()) flag=false;
    if(flag) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
    return 0;
}

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

const int maxn=2e3+100;

char g[maxn][maxn];
int val[maxn][maxn],n,m;
vector <pair<int,int> > v;

void solve(int sum){
//	cout<<sum<<endl;
	for(int i=0;i<v.size();i++){
		int x=v[i].first;
		int y=v[i].second;
		val[x][y]+=sum;
	}
}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin>>g[i][j];
	int sum=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(g[i][j]=='.'){
				sum++;
				v.push_back(make_pair(i,j));
			}
			if(g[i][j]=='#'){
				solve(sum);
				v.clear();
				sum=0;
			}
			if(j==m-1){
				solve(sum);
				v.clear();
				sum=0;
			}
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(g[j][i]=='.'){
				v.push_back(make_pair(j,i));
				sum++;
			}
			if(g[j][i]=='#'){
				solve(sum);
				sum=0;
				v.clear();
			}
			if(j==n-1){
				solve(sum);
				sum=0;
				v.clear();
			}
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			ans=max(ans,val[i][j]-1);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 21632
N,K=map(int, input().split())
x = list(map(int, input().split()))

xp = []
xm = []
for i in range(N):
  if x[i] > 0:
    xp.append(x[i])
  elif x[i] < 0:
    xm.append(-x[i])
  else:
    K -= 1
xm.reverse()

ans = 1000000000
n = max(0, K - len(xp) )
for i in range(n, min(len(xm)+1,min(len(xp),K))):
  if i == 0:  m = 0
  else:       m = xm[i-1]
  ans = min(ans, m * 2 + xp[K - i - 1] )
#  print("p ",i,m,xp[K - i - 1],ans)

n = max(0, K - len(xm) )
for i in range(n, min(len(xp)+1,min(len(xm),K))):
  if i == 0:  p = 0
  else:       p = xp[i-1]
  ans = min(ans, p * 2 + xm[K - i - 1] )
#  print("m ",i,ans)
if ans == 1000000000: ans = 0
print(ans)


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

using ll = long long;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int N, K; cin >> N >> K;
    vector<int> A(N); cin >> A;

    vector<ll> sum;
    ll all_or = 0;
    rep(i, N) {
        ll s = 0;
        for (int j = i; j < N; j++) {
            s += A[j];
            sum.push_back(s);
            all_or |= s;
        }
    }
    // set<int> idx;
    // unordered_set<int> idx;
    // for (int i = 0; i < sum.size(); i++) {
    //     idx.insert(i);
    // }
    vector<int> idx;
    rep(i, sum.size()) idx.push_back(i);

    ll ans = 0;
    for (ll b = (1LL << 41); b > 0; b >>= 1) {
        if (!(all_or & b)) continue;
        // set<int> on;
        // unordered_set<int> on;
        vector<int> on;
        for (int i : idx) {
            if (sum[i] & b) {
                // on.insert(i);
                on.push_back(i);
            }
        }
        if (on.size() >= K) {
            ans |= b;
            idx = on;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8172
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;cin>>n;
  ll size_v=int(n/2);
  unordered_map<ll,ll> odd,even;
  vector<pl> odd_v,even_v; 
  ll temp;
  rep(i,size_v){
    cin>>temp;
    even[temp]++;
    cin>>temp;
    odd[temp]++;
  }
  reps(x,even){
    even_v.pb(mp(x.se,x.fi));
  }

  reps(x,odd){
    odd_v.pb(mp(x.se,x.fi));
  }

  even_v.pb(mp(0,0));
  odd_v.pb(mp(0,0));

  sort(all(even_v));
  sort(all(odd_v));

  vector<ll> ans;
  if(even_v[even_v.size()-1].se!=odd_v[odd_v.size()-1].se){
    cout<<n-even_v[even_v.size()-1].fi-odd_v[odd_v.size()-1].fi<<endl;
  }else{
    rep(i,odd_v.size()-1){
      ans.pb(n-even_v[even_v.size()-1].fi-odd_v[i].fi);
    }
    rep(i,even_v.size()-1){
      ans.pb(n-even_v[i].fi-odd_v[odd_v.size()-1].fi);
    }
    sort(all(ans)); 
    cout<<ans[0]<<endl;
  }  
}





Measured memory_bytes: 7440
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n; string s; cin >> s;
	if (s.size() == 3) {
		cout << s[2] << s[1] << s[0] << endl;
	}
	if (s.size() == 2) {
		cout << s[0] << s[1] << endl;
	}
	cin >> n;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	private void doit(){
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			while(n-- > 0){
				int [] data = new int[8];
				for(int i = 0; i < 8; i++){
					data[i] = sc.nextInt();
				}
				int [][] calc = new int[4][4];
				calc[0][0] = data[0] * data[4];
				calc[0][1] = data[0] * data[5];
				calc[0][2] = data[0] * data[6];
				calc[0][3] = data[0] * data[7];
				
				calc[1][0] = data[1] * data[5] * -1;
				calc[1][1] = data[1] * data[4];
				calc[1][2] = data[1] * data[7] * -1;
				calc[1][3] = data[1] * data[6];
				
				calc[2][0] = data[2] * data[6] * -1;
				calc[2][1] = data[2] * data[7];
				calc[2][2] = data[2] * data[4];
				calc[2][3] = data[2] * data[5] * -1;
				
				calc[3][0] = data[3] * data[7] * -1;
				calc[3][1] = data[3] * data[6] * -1;
				calc[3][2] = data[3] * data[5];
				calc[3][3] = data[3] * data[4];
				
				for(int i = 0; i < 4; i++){
					int sum = 0;
					for(int j = 0; j < 4; j++){
						sum += calc[j][i];
					}
					System.out.print(sum);
					if(i == 3){
						System.out.println();
					}
					else{
						System.out.print(" ");
					}
				}
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 23892
/*

#      #      #####   ##   ##  #####      ##     #  #      #   #  #####
#      #      #   #  #  ###  # #          # ##   #  #      #   #  #   #
#      #      #   #  #   #   # #          #  ##  #  #      #   #  #   #
#      #      #   #   #     #  #####      #   #  #  #       ###   #####
#      #      #   #    #   #   #          #  ##  #  #        #    #   #
#      #      #   #     ###    #          # ##   #  #        #    #   #
#      #####  #####      #     #####      ##     #  #####    #    #   #

*/

#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <int> vi;
typedef vector <string> vs;
typedef vector <vector <llong> > matrix;

typedef pair <llong, llong> pll;

typedef map <int, int> mii;

typedef set <llong> sl;

const llong MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const int INF = 1e9;
const llong LINF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;};

int n, k;
int a[MXN];

int main () {
    android;
    //freopen ("input.txt", "r", stdin);
    cin >> n >> k;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
    }
    sort (a + 1, a + n + 1);
    int mn = INF;
    for (int i = 1; i <= n - k + 1; i ++) {
        mn = min (mn, a[i + k - 1] - a[i]);
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    ll n,c,ans;
    ans = 0;
    string s = "";
    cin >> n;
    for (int i = 1; i < n; i++){
        c = n/i;
        if (c*i == n) c--;
        ans += c;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3624
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <utility>
#include <set>
#include <map>
using namespace std;

int n,pn,y=0,b,u;
map<int,int> ds;
bool rs=true;
//nを素因数分解
//配列内の数字が全て2つ以上か判別

int main(){
    scanf("%d",&pn);
    while(rs){
        n=pn-y;
        u=1;
        b=0;
        rs=false;
        while(ds.size()!=0)ds.erase(begin(ds));
        while(n!=1){
            u+=1;
            while(n%u==0){
                n/=u;
                ds[u]+=1;
                //printf("%d\n",u);
            }
        }
        //cout<<endl;
        for(auto itr=ds.begin();itr!=ds.end();++itr){
            
            if(itr->second==1 or (b!=0 and itr->second!=b)){rs=true;break;}
            b=itr->second;
        }
        y+=1;
    }
    printf("%d\n",pn-y+1);
    
}

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

int main() {
    int N;
    cin >> N;
    vector<int64_t> A(N);
    rep(i, N) {
        cin >> A[i];
    }
    sort(all(A));
    reverse(all(A));

    int64_t score = 0;

    for (int i = 0; i < N-1; i++) {
        score += A[(i+1)/2];
    }

    cout << score << endl;
    return 0;
}

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

int main(){
 int W;
 int a;
 int b;
 int ans;
 int temp;
 int oral;
 cin>>W>>a>>b;
 //あたり判定
 if(a<=b+W && b<=a+W){
 	ans=0;
 }else{
 	if(a+W<b){
		ans=b-(a+W);
	}else if(a>b+W){
		ans=a-(b+W);
	}
 }
 
 cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define SIZE 10
using namespace std;

int main() {
  string key;
  cin >> key;
  int n;
  cin >> n;
  string str[n];
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }

  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < SIZE; j++) {
      bool flag = false;
      for (int k = 0; k < key.size(); k++) {
	char s, t;
	s = key[k];
	if (j + k < SIZE) {
	  t = str[i][j + k];
	} else {
	  t = str[i][j + k - SIZE];
	}
	if (s != t) {
	  flag = true;
	  break;
	}
      }
      if (flag == false) {
	count++;
	break;
      }
    }
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 3172
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var D = F;
		var S = "Christmas";
		for (var i = 0; i < 25 - D; i++) S += " Eve";
		WriteLine(S);
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios::sync_with_stdio(false);
    
    int n, W;
    cin >> n >> W;
    int w[n], v[n];
    long long vsum = 0;
    for(int i=0;i<n;i++){
        cin >> w[i] >> v[i];
      	vsum += v[i];
    }
  
    long long *dp=new long long[vsum+1];
    for(int i=0;i<vsum+1;i++)
		dp[i] = pow(10, 18)+5;
    dp[0] = 0;
    
    for(int i=0;i<n;i++){
        for(long long j=vsum; j>=v[i]; j--){
            dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
        }
    }
    
    for(int i=vsum; i>=0; i--){
        if(dp[i]<=W){
            cout << i;
            break;
        }
    }
    delete []dp;
    return 0;
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const int MAXN = 305;

lint ipow(lint x, lint p){
	lint ret = 1, piv = x % mod;
	while(p){
		if(p&1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret % mod;
}

int n, d[MAXN];
lint fact[MAXN], invf[MAXN];
lint dp[MAXN][MAXN][MAXN];

lint f(int x, int y, int z){
	if(x == n) return (y == 0 && z == 0);
	if(y < 0 || z < 0) return 0;
	if(~dp[x][y][z]) return dp[x][y][z];
	lint ans = f(x + 1, y, z);
	if(d[x] > 1) ans += f(x + 1, y - 1, z - (d[x] - 2)) * (d[x] - 1);
	ans %= mod;
	return dp[x][y][z] = ans;
}

int main(){
	fact[0] = 1;
	for(int i=1; i<MAXN; i++) fact[i] = fact[i-1] * i % mod;
	for(int i=0; i<MAXN; i++) invf[i] = ipow(fact[i], mod-2);
	cin >> n;
	for(int i=0; i<n; i++) cin >> d[i];
	if(count(d, d + n, 2) == n){
		cout << fact[n-1] * ipow(2, mod - 2) % mod<< endl;
		return 0;
	}
	memset(dp, -1, sizeof(dp));
	lint ret = 0;
	for(int i=3; i<=n; i++){
		for(int j=1; j<=n; j++){
			lint ans = fact[n - 1 - i] * fact[i - 1] % mod;
			ans *= j;
			ans %= mod;
			ans *= f(0, i, j);
			ans %= mod;
			ret += ans;
		}
	}
	ret %= mod;
	for(int j=0; j<n; j++) ret *= invf[d[j] - 1], ret %= mod;
	ret %= mod;
	ret *= (mod + 1) / 2;
	cout << ret % mod << endl;
}


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


int main()
{
    map<int, int> cnt;
    int n;
    cin >> n;
    for ( int i = 1; i <= n; i++ ) {
        int a;
        cin >> a;
        cnt[a]++;
    }

    int ans = 0;

    for ( auto u : cnt ) {
        if ( u.second >= u.first ) ans += ( u.second - u.first );
        else ans += u.second;
    }

    cout << ans << endl;
}

Measured memory_bytes: 8088
import Data.List
import Data.Maybe

main = interact $ show . sol . read

sol :: Int -> Int
sol n = sum . map f . sig n $ takeWhile (\p -> p*p <= n) primes

f n = floor $ sqrt (2*fromIntegral n+0.25)-0.5

sig 1  _ = []
sig _ [] = [1]
sig n (p:ps) 
  | e > 0     = e:sig (n `div` p^e) ps
  | otherwise = sig n ps 
  where
  e = pred . fromJust $ find ((>0) . mod n . (p^)) [1..]

primes = 2:f [3,5..] where f (p:ps) = p:filter ((>0) . (`rem` p)) ps

Measured memory_bytes: 4924
/* Author VS_CODE */

#include<bits/stdc++.h>
#define int long long
#define TCI int t;cin>>t;while(t--)
#define foR(n) for(int i=1;i<=n;i++)
#define For(n) for(int i=0;i<n;i++)
#define ln "\n"
#define vpair vector< pair <int , int > >
#define fr first
#define sc second
#define pb emplace_back
#define vll vector<int>
#define inf INT64_MAX
#define Point complex<double>
using namespace std;

void online()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
/* CODE STARTS HERE */

const int N = 1e5;
int k=1;

void solve ()
{
	string s;
	cin>>s;
	int ans=0;
	for(auto i:s)
	{
		ans+=i-'0';
	}
	(ans%9)?cout<<"No":cout<<"Yes";

}


/* CODE ENDS HERE AND MAIN STaARTS */

int32_t main()
{
	online();
	// TCI
	solve();
}

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

#define ABS(X) ((X)<0?-(X):(X))
#define MIN(X,Y) ((X)<(Y)?(X):(Y))

int main(void){
  int n;
  long long ans, acc[200010];
  
  cin >> n;
  acc[0] = 0;
  for (int i=0; i<n; i++){
    long long t; cin >> t;
    acc[i+1] = acc[i] + t;
  }
  ans = acc[n];
  for (int i=0; i<n; i++){
    long long l,r;
    l = acc[i];
    r = acc[n]-acc[i];
    ans = MIN(ans, ABS(r-l));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
N,K = map(int,input().split())
sunuke = [0 for i in range(1,N+1)]

for i in range(K):
    input()
    have = list(map(int,input().split()))
    for d in have:
        sunuke[d-1] = 1
    #print(sunuke)
print(sunuke.count(0))


    

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (int i = 1; i <= N; i++)
const int intinf = numeric_limits<int>::max();

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define MOD 1000000007
#define NALPHABETS 26

void solve()
{
    int N;
    cin >> N;
    string S;
    cin >> S;

    set<int> s[NALPHABETS];
    rep(i, N)
    {
        s[S[i] - 'a'].insert(i);
    }
    rep(j, NALPHABETS)
    {
        s[j].insert(N);
    }

    int Q;
    cin >> Q;
    rep(q, Q)
    {
        int type;
        cin >> type;
        if (type == 1)
        {
            int i;
            char c;
            cin >> i >> c;
            i--;
            if (c == S[i])
                continue;
            s[S[i] - 'a'].erase(i);
            s[c - 'a'].insert(i);
            S[i] = c;
        }
        else if (type == 2)
        {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            int ans = 0;
            rep(j, NALPHABETS)
            {
                int m = *s[j].lower_bound(l);
                if (m <= r)
                    ans++;
            }
            printf("%d\n", ans);
        }
    }
}

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


Measured memory_bytes: 24196
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main() {
	int n;
	cin>>n;
	vi a(6);
	REP(i,n){
		double b;
		cin>>b;
		if(b<165.0){
			a[0]++;
		}else if(b<170.0){
			a[1]++;
		}else if(b<175.0){
			a[2]++;
		}else if(b<180.0){
			a[3]++;
		}else if(b<185.0){
			a[4]++;
		}else{
			a[5]++;
		}
	}
	REP(i,6){
		cout<<i+1<<":";
		REP(j,a[i]){
			cout<<"*";
		}
		cout<<endl;
	}

}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9 + 10;
const ll MOD = 998244353;

const int MAXN = 4e5 + 5;

char s[MAXN];
char d[MAXN];

ll ans[MAXN];
ll st2[MAXN];

vi divs[MAXN];

void solve(){
	int n;
	scanf("%d%s", &n, &s[0]);
	st2[0] = 1ll;
	REPN(i, 1, 2 * n) {
		st2[i] = (st2[i - 1] * 2) % MOD;
	}
	REPN(i, 1, 2 * n) {
		for(int j = i + i; j <= 2 * n; j += i) {
			divs[j].pb(i);
		}
	}
	REPN(i, 2, 2 * n) {
		if ((2 * n) % i == 0 && i % 2 == 0 && ((2 * n) / i) % 2 == 1) {
			int len = i / 2;
			REP(j, 0, len) {
				ans[len] = (ans[len] * 2 + s[j] - '0') % MOD;
			}
			REP(j, 0, n) {
				d[j] = s[j % len];
				if ((j / len) % 2 == 1) {
					d[j] ^= 1;
				}
			}
			if (strcmp(d, s) <= 0) {
				ans[len] = (ans[len] + 1) % MOD;
			}
			REP(j, 0, SZ(divs[len])) {
				ans[len] = (ans[len] + MOD - ans[divs[len][j]]) % MOD;
			}
		}
	}
	ll sum = 0ll;
	REPN(i, 0, 2 * n) {
		sum = (sum + ans[i] * 2 * i) % MOD;
	}
	cout << sum << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC
using namespace std;


template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

const int maxn=2000005;
int p[maxn];
int sz[maxn];
int cnt=0;
void clear(int n=maxn){
    rep(i,0,n+1)p[i]=i,sz[i]=1;
    cnt=n;
}
int root(int x){
   while(x!=p[x]){
       p[x]=p[p[x]];
       x=p[x];
   }
   return x;  
}
void merge(int x,int y){
    int p1=root(x);
    int p2=root(y);
    if(p1==p2)return;
    cnt--;
    if(sz[p1]>=sz[p2]){
        p[p2]=p1;
        sz[p1]+=sz[p2];
        sz[p2]=0;
    }
    else{
        p[p1]=p2;
        sz[p2]+=sz[p1];
        sz[p1]=0;
    }
}

int solve(){
 	int d,s,t;cin>>d>>s>>t;
 	if(s*t>=d){
 		cout<<"Yes"<<endl;
 	}
 	else{
 		cout<<"No"<<endl;
 	}
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
 

Measured memory_bytes: 3652
import sys, os
import collections

MOD = 10 ** 9 + 7

class Edge:
  def __init__(self, to, edge_id):
    super().__init__()
    self.to = to
    self.edge_id = edge_id

class DFSState:
  def __init__(self, vertex, parent_color = -1, parent = -1):
    super().__init__()
    self.vertex = vertex
    self.parent_color = parent_color
    self.parent = parent

def solve(input_stream):
  N = read_int(input_stream)
  graph = [[] for i in range(N)]
  answer = [0 for i in range(N - 1)]
  K = 0
  for index in range(N-1):
    i,j = read_ints(input_stream)
    i-=1
    j-=1
    graph[i].append(Edge(j, index))
    graph[j].append(Edge(i, index))
  dfs = [DFSState(0)]
  while len(dfs) > 0 :
    color = 1
    state = dfs.pop(0)
    for index, value in enumerate(graph[state.vertex]):
      to = value.to
      edge_id = value.edge_id
      if to == state.parent:
        continue
      if color == state.parent_color:
        color += 1
      answer[edge_id] = str(color)
      dfs.append(DFSState(to, color, state.vertex))
      color += 1
  for value in graph:
    K = max(K, len(value))
  ans = [str(K)]
  ans.extend(answer)
  return ans

    


def read_ints(input_stream):
  return [i for i in map(int, input_stream.readline().strip().split())]

def read_int(input_stream):
  return int(input_stream.readline().strip())


if __name__ == "__main__":
    outputs = solve(sys.stdin)
    for line in outputs:
      print(line)

Measured memory_bytes: 66748
mod = 10**9+7

def min_sum(k):
  return int(k*(k-1)/2)

def max_sum(n,k):
  return int((n+n-k+1)*k/2)

def main():
  N,K = [int(x) for x in input().split()]
  ans = 0
  for k in range(K,N+2):
    ans += max_sum(N,k) - min_sum(k) + 1

  print(ans%mod)

if __name__ == "__main__":
    main()
    pass

Measured memory_bytes: 9140
#include<iostream>
#include <stdlib.h>
#include <string.h>
#include <math.h>

using namespace std;
int main(){
    int H,W,A,B,i,j;
    cin >> H >> W >> A >> B;
    int h = H - 1;
    int w = W - 1;
    int matrix[H][W];

    
    for(i = 0; i <= B - 1; i++){
        for(j = 0; j <= A - 1; j++){
            matrix[i][j] = 0;
        }for(j = A; j <= w; j++){
            matrix[i][j] = 1;
        }
    }

    for(i = B; i <= h; i++){
        for(j = 0; j <= A - 1; j++){
            matrix[i][j] = 1;
        }for(j = A; j <= w; j++){
            matrix[i][j] = 0;
        }
    }

    for(i = 0; i < H; i++){
        for(j = 0; j < W; j++){
            cout << matrix[i][j];
        }cout << endl;
    }

return 0;
}

Measured memory_bytes: 5120