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

vector<int> adj[27];

int main() {
	string s;
	cin >> s;
	string str;
	cin >> str;
	int n = s.size();
	for(int i = 0; i < n; ++i)
		adj[s[i] - 'a'].push_back(i);
	long long answer = 1, last = -1;
	bool ok = false;
	n = str.size();
	for(int i = 0; i < n; ++i) {
		vector<int> :: iterator it = upper_bound(adj[str[i] - 'a'].begin(), adj[str[i] - 'a'].end(), last);
		if(it == adj[str[i] - 'a'].end()) {
			++answer;
			if(ok)
				return cout << -1, 0;
			ok = true;
			last = -1;
			--i;
			continue;
		}
		last = *it;
		ok = false;
	}
	--answer;
	n = s.size();
	cout << answer * n + last + 1;
}


Measured memory_bytes: 4248
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
#define mop2 998244353

using namespace std;

ll fastPow(ll a, ll b, ll mod = 0) {
	if (a == 0 and b == 0) {
		return -1;
	}
	if (a == 0) {
		return 0;
	}
	if (b == 0) {
		return 1;
	}
	long long tmp = fastPow(a, b / 2, mod);
	if (mod != 0) {
		if (b % 2 == 0) {
			return (tmp * tmp) % mod;
		}
		else {
			return ((tmp*tmp) % mod * (a % mod)) % mod;
		}
	}
	else {
		if (b % 2 == 0) {
			return (tmp*tmp);
		}
		else {
			return tmp * tmp * a;
		}
	}
}

int main() {
	ll x;
	cin >> x;
	vector <pair<ll, ll>> vList;
	ll tmp = 0;
	while (fastPow(tmp, 5) - fastPow(tmp - 1, 5) <= fastPow(10, 9)) {
		vList.push_back(make_pair(tmp, fastPow(tmp, 5)));
		tmp++;
	}
	ll n = vList.size();
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			if (vList[i].second + vList[j].second == x) {
				cout << vList[i].first << " " << -vList[j].first << endl;
				return 0;
			}
			else if(vList[i].second - vList[j].second == x){
				cout << vList[i].first << " " << vList[j].first << endl;
				return 0;
			}
		}
	}
} 

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

int main(){
    int a,b;
    scanf("%2d%2d",&a,&b);

    if(1<=b && b<=12){
        if(1<=a && a<=12) cout << "AMBIGUOUS" << endl;
        else cout << "YYMM" << endl;
    }else if(1<=a && a<=12){
        if(1<=b && b<=12) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int i;
    int n,k;
    string s;
    cin>>n>>k;
    cin >>s;
    if(s[k-1]=='A')s[k-1]='a';
    if(s[k-1]=='B')s[k-1]='b';
    if(s[k-1]=='C')s[k-1]='c';
    int ans=0;
    n=3;
    for (i=0;i<n;i++){
        if(s[i]=='1')ans++;
        
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque



def main():
    num = int(input())
    data = list(map(int, input().split()))
    aaa = [0 for i in range(num)]

    for i in range(num):
        aaa[i] = [data[i], i + 1]

    aaa.sort()

    for i in range(num):
        print(aaa[i][1],end='')
        if i == num - 1:
            print()
        else:
            print(' ',end='')





if __name__ == '__main__':
    main()


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

struct P{
	int x, y;
	P(){}
	P(int x_, int y_){ x = x_; y = y_; }
};

int D(P a, P b){
	return abs(a.x - b.x) + abs(a.y - b.y);
}

int main(){
	const int INF = 1e+8;
	int n, a, b, c, d, ans = INF;
	cin >> n >> a >> b >> c >> d;
	a--; b--; c--; d--;
	for(int w = 1; w <= n; w++){
		int k = 0;
		P pa, pb, pc, pd;
		for(int y = 0; y < n; y++){
			for(int x = 0; x < w; x++){
				if( k == a ) pa = P(x, y);
				if( k == b ) pb = P(x, y);
				if( k == c ) pc = P(x, y);
				if( k == d ) pd = P(x, y);
				k++;
			}
		}
		int d = D(pa, pb) + D(pc, pd);
		ans = min(ans, d);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1164
fn main() {
    const MOD: usize = 998244353;

    let [a, b, c, d]: [usize; 4] = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        [
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        ]
    };

    let mut dp = vec![vec![[0; 2]; d + 1]; c + 1];
    dp[a][b][1] = 1;
    for i in a..=c {
        for j in b..=d {
            if i + 1 <= c {
                dp[i + 1][j][0] = (dp[i][j][0] + dp[i][j][1]) * j % MOD;
            }
            if j + 1 <= d {
                dp[i][j + 1][1] = (dp[i][j][0] + dp[i][j][1] * i) % MOD;
            }
        }
    }

    let ans = (dp[c][d][0] + dp[c][d][1]) % MOD;
    println!("{}", ans);
}

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

int main(){

    int array[6];
    for(int i=0;i<6;++i) cin >> array[i];

    int dist=array[4]-array[0];

    if(dist <= array[5])cout << "Yay!" << endl;
    else cout << ":(" << endl;

    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

typedef long double Double;

const Double eps = 1e-18;

typedef ll Int;


const int N = 128;
ll dp[N][N];

ll rec(int n, int r) {
  if (n < 0 || r < 0) return 0;
  if (dp[n][r] != -1) return dp[n][r];
  if (n == 0 || n == r) return dp[n][r] = 1;
  return dp[n][r] = rec(n-1, r) + rec(n-1, r-1);
}

class C_cls {
  static const int N = 1000000;
  vector<Int> facts;
public:
  C_cls() : facts(vector<Int>(N, 1)){
    FOR(i,1,N) facts[i] = facts[i-1] * Int(i);
  }
  Int choose(int n, int r) { return rec(n, r); }
};

C_cls C;

Double error(Double a, Double b) {
  Double abs_error = fabs(a - b);
  if (a > eps) { return min(abs_error, abs_error / a); }
  return abs_error;
}


int main() {
  REP(i,N) REP(j,N) dp[i][j] = -1;
  
  int n, a, b;
  while (cin >> n >> a >> b) {
    vll v(n);
    REP(i,n) cin >> v[i];
    sort(RALL(v));

    Double average = 0;
    auto ave = [&](int c) { return accumulate(v.begin(), v.begin() + c, 0.0L) / c; };
    FOR(c,a,b+1) {
      gs(average, ave(c));
    }

    ll cnt = 0;
    FOR(c,a,b+1) if (error(average, ave(c)) < eps) {
      // cout << "# c = " << c << endl;
      map<ll,int> mn, mr;
      ll t = 1;
      REP(i,n) mn[v[i]]++;
      REP(i,c) mr[v[i]]++;
      for (const auto& e: mr) {
        // cout << "+= " << mn[e.first] << " C " << e.second << " = " <<
        //   C.choose(mn[e.first], e.second) << endl;
        t *= C.choose(mn[e.first], e.second);
      }
      cnt += t;
    }

    printf("%.9Lf\n%lld\n", average, cnt);
  }
}


Measured memory_bytes: 8440
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(string, "x", long, "y");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, m;
    scan(n, m);
    long[long] AC;
    long[long] WA;
    long accnt, wacnt;
    foreach (_; iota(m))
    {
        long p;
        string s;
        scan(p, s);
        if (s == "AC")
        {
            if (p in AC)
                continue;
            else
                AC[p] = 1;
        }
        else
        {
            if (p in AC)
            {
                continue;
            }
            else
            {
                if (p in WA)
                    WA[p]++;
                else
                    WA[p] = 1;
            }
        }
    }
    foreach (i; iota(n))
    {
        if ((i + 1) in AC)
        {
            accnt++;
            if ((i + 1) in WA)
                wacnt += WA[i + 1];
        }
    }
    writefln("%s %s", accnt, wacnt);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 12284
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, C := sc.nextInt(), sc.nextInt()
	D := make([][]int, C)
	for i := 0; i < C; i++ {
		D[i] = sc.nextIntSlice(C)
	}
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		G[i] = sc.nextIntSlice(N)
	}
	var X [3][]int
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			ind := (i + 1 + j + 1) % 3
			X[ind] = append(X[ind], G[i][j])
		}
	}
	var Sum [3][31]int
	for x := 0; x < 3; x++ {
		for to := 1; to <= C; to++ {
			sum := 0
			for _, color := range X[x] {
				sum += D[color-1][to-1]
			}
			Sum[x][to] = sum
		}
	}
	ans := INF
	for i := 1; i <= C; i++ {
		for j := 1; j <= C; j++ {
			for k := 1; k <= C; k++ {
				if i == j || i == k || j == k {
					continue
				}
				sum := Sum[0][i]
				sum += Sum[1][j]
				sum += Sum[2][k]
				if sum < ans {
					ans = sum
				}
			}
		}
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

const int mod=2019;
string s;
ll dp[2][2019];

void solve()
{
	const int n = s.length();
	ll ans = 0;
	memset(dp,0,sizeof(dp));
	dp[0][s[0]-'0']=1;
	for(int i=1;i<n;++i){
		int pr=(i-1)%2, cu= i%2;
		memset(dp[cu],0,sizeof(dp[cu]));
		int c = s[i]-'0';
		dp[cu][c]=1;
		for(int j=0;j<2019;++j)if(dp[pr][j]){
		    int rem = (j*10+c)%mod;
			dp[cu][rem]+=dp[pr][j];
			if(rem==0)ans+=dp[pr][j];
		}
		for(int k=0;k<2019;++k)dp[pr][k]=dp[cu][k];
	}
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s;
	solve();
	return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main(){
  string s; cin >> s;
  int q; cin >> q;
  bool f = true;
  int cnt = 0;

  while(q > 0){
    int t; cin >> t;
    if(t == 1){f = !f; cnt++;}
    else{
      int c; cin >> c;
      if(c == 1){f = !f;}
      char p; cin >> p;
      if(f){s.push_back(p);}
      else{s.insert(s.begin() + 0, p);}
      if(c == 1){f = !f;}
    }
    q--;
  }
  if(cnt % 2 == 0){cout << s << endl;}
  else{
    reverse(s.begin(), s.end());
    cout << s << endl;
  }
}
    

Measured memory_bytes: 900
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int k;
	cin >> k;
	cout << (k / 2) * (k - k / 2) << endl;
} 

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
long long combination(int n,int r){
  if(r==0 || r==n)return 1;
  else if (r==1)return n;
  return (combination(n-1,r-1)+combination(n-1,r));
}
int main(){
  int n;
  cin>>n;
  map<string,int> moji;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    moji[s]++;
  }
  long long ans=0;
  for(auto x:moji){
    int p=x.second;
    if(p==1)continue;
    ans+=combination(p,2);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 11372
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>

using namespace std;

#define pb push_back
#define int long long


int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++){
        cin >> v[i];
    }
    for (int i = k; i < n; i++){
        if (v[i] > v[i - k]){
            cout << "Yes\n";
        }
        else{
            cout << "No\n";
        }
    }
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int n,m,i,j;
	cin>>n>>m;
	int k,temp,c;

	int arr[30];
	for ( i = 0; i < 30; ++i)
    {
    	arr[i]=0;
    }


    for (i = 0; i < n; ++i)
    {
    	cin>>k;
        
        for( j=0;j<k;j++)
        {
        	cin>>temp;
        	arr[temp-1]++;
        }
    }

    c=0;
    for ( i = 0; i < 30; ++i)
    {
    	if(arr[i]==n)
    		c++;
    }


    cout<<c;


	return 0;
}			

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

typedef std::pair<int, int> pii;

int main()
{
  std::vector<pii> AE(5);
  for (int i = 0; i < 5; i++)
  {
    std::cin >> AE.at(i).second;
    AE.at(i).first = (10 - AE.at(i).second%10)%10;
  }
  sort(AE.begin(), AE.end());
  int ans = 0;
  for (int i = 0; i < 4; i++)
  {
    ans += AE.at(i).first + AE.at(i).second;
  }
  std::cout << ans + AE.at(4).second << std::endl;
}


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

ll n,cou=0;
void dfs(ll x,int a,int b,int c){
  if(x>n)
    return ;
  if(a&b&c)
    cou++;
    dfs(10*x+3,1,b,c);
  dfs(10*x+5,a,1,c);
  dfs(10*x+7,a,b,1);
  return;
}
      
int main() {
cin>>n;
  dfs(0,0,0,0);
  cout<<cou<<endl; 
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner sc;
	String S,T;

	public Main() {
		sc = new Scanner(System.in);
	}
	
	private void calc() {
		S = sc.next();
		T = sc.next();
		int c = 0;
		for (int i = 0; i < 3; i++) {
			if (S.charAt(i) == T.charAt(i)) c++;
		}
		System.out.println(c);
		System.out.flush();
	}

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

}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1000000000;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n,k,s;
    cin >> n >> k >> s;
    vector<int> a(n);
    if(s==INF){
        rep(i,0,k-1)a[i] = s;
        rep(i,k,n-1)a[i] = 1;        
    }else{
        rep(i,0,k-1)a[i] = s;
        rep(i,k,n-1)a[i] = INF;
    }

    rep(i,0,n-1)cout << a[i] << endl;

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 1792
#include <vector>
#include <functional>

using namespace std;

template<typename T>
class SegmentTree
{
    int n;
    function<T(T,T)> op;
    vector<T> V;

    T q(int l, int r)
    {
        if (l >= r)
            return V[0];
        T a = q((l+1)/2, r/2);
        if (l%2 != 0)
            a = op(a, V[l]);
        if (r%2 != 0)
            a = op(a, V[r-1]);
        return a;
    }

public:
    SegmentTree(int n_, function<T(T,T)> op, T init):
        op(op)
    {
        n = 1;
        while (n < n_)
            n *= 2;
        V = vector<T>(2*n, init);
        for (int i=n-1; i>0; i--)
            V[i] = op(V[i*2], V[i*2+1]);
    }

    T get(int p) const
    {
        return V[p+n];
    }

    void set(int p, T v)
    {
        p += n;
        V[p] = v;
        for (p/=2; p>0; p/=2)
            V[p] = op(V[p*2], V[p*2+1]);
    }

    //  init OP v[l] OP v[l+1] OP ... OP v[r-1]
    T query(int l, int r)
    {
        return q(l+n, r+n);
    }
};

#include <iostream>
#include <string>

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

    vector<SegmentTree<bool>> ST(26, SegmentTree<bool>(N, [&](bool a, bool b){return a||b;}, false));
    for (int c=0; c<26; c++)
        for (int i=0; i<N; i++)
            if (S[i]=='a'+c)
                ST[c].set(i, true);

    int Q;
    cin>>Q;
    for (int q=0; q<Q; q++)
    {
        int x;
        cin>>x;
        if (x==1)
        {
            int i;
            char c;
            cin>>i>>c;
            i--;
            ST[S[i]-'a'].set(i, false);
            S[i] = c;
            ST[S[i]-'a'].set(i, true);
        }
        else
        {
            int l, r;
            cin>>l>>r;
            l--;
            int ans = 0;
            for (int c=0; c<26; c++)
                if (ST[c].query(l, r))
                    ans++;
            cout<<ans<<endl;
        }
    }
}


Measured memory_bytes: 4216
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, K, R, S, P; string T;
string grp[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K >> R >> S >> P >> T;
	rep(i, 0, N) grp[i % K] += T[i];

	int ans = 0;
	rep(k, 0, K) {
		int r = 0, s = 0, p = 0;
		if (grp[k][0] == 'r') p = P;
		if (grp[k][0] == 's') r = R;
		if (grp[k][0] == 'p') s = S;

		int n = grp[k].size();
		rep(i, 1, n) {
			int rr = max(s, p);
			int ss = max(r, p);
			int pp = max(r, s);

			if (grp[k][i] == 'r') pp += P;
			if (grp[k][i] == 's') rr += R;
			if (grp[k][i] == 'p') ss += S;

			r = rr;
			s = ss;
			p = pp;
		}

		ans += max({ r, s, p });
	}
	cout << ans << endl;
}


Measured memory_bytes: 5328
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		Set<Integer> j = new HashSet<>();
		boolean judge = true;

		for (int i = 0; i < m; i++) {
			int tmp1 = scanner.nextInt();
			int tmp2 = scanner.nextInt();
			if (tmp1 == 1 && judge) {
				if (j.contains(tmp2)) {
					judge = false;
					break;
				}
				j.add(tmp2);
			} else if (tmp2 == n && judge) {
				if (j.contains(tmp1)) {
					judge = false;
					break;
				}
				j.add(tmp1);
			}
		}

		if (judge) {
			System.out.println("IMPOSSIBLE");
		} else {
			System.out.println("POSSIBLE");
		}

	}
}


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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n;
LL m;
LL x[N], v[N];
LL s[N], rs[N];

int main()
{
	scanf("%d%lld", &n, &m);
	for (int i = 1; i <= n; i ++ ) scanf("%lld%lld", &x[i], &v[i]);
	
	for (int i = 1; i <= n; i ++ ) s[i] = s[i - 1] + v[i];
	for (int i = n; i; i -- ) rs[i] = rs[i + 1] + v[i];
	
	for (int i = 1; i <= n; i ++ )
	{
		s[i] = max(0LL, s[i] - x[i]);
		s[i] = max(s[i], s[i - 1]);
	}
	
	for (int i = n; i; i -- )
	{
		rs[i] = max(0LL, rs[i] - (m - x[i]));
		rs[i] = max(rs[i], rs[i + 1]);
	}
	
	LL res = 0;
	for (int i = 1; i <= n; i ++ ) res = max(res, s[i] + max(0LL, rs[i + 1] - x[i]));
	for (int i = n; i; i -- ) res = max(res, rs[i] + max(0LL, s[i - 1] - (m - x[i])));
	printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 6952
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

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

int n, d, ans, a[N], dp[N];

int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    scanf("%d %d",&n ,&d);
    int son = 1;
    for(int i = 1; i <= n; i++){
      if(i - son >= d){
        son = i + d + 1;
        ans++;
      }
    }
    if(son <= n)
      ans++;
    printf("%d\n", ans);
    return 0;
}


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

#define pb push_back
#define PQ priority_queue
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

typedef long long ll;
typedef long double ld;

//__builtin_popcount(x)

using namespace std;

/*const int mod = 1e9 + 7;

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

ll sub(ll a, ll b) {
    ll res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

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

int powm(int a, long long n) {
	if (n == 0) {
		return 1;
	}
	else if (n & 1) {
		return mul(a, powm(a, n - 1));
	}
	else {
		return powm(mul(a, a), n / 2);
	}
}*/

/* Z-FUNCTION
ll l = 0, r = 0, n = (int)s.size();
vector<int> z(n, 0);
for (int i = 1; i < n; i++) {
    if (r >= i) {
        z[i] = min(1ll*z[i-l], r-i+1);
    }
    while (z[i] + i < n && s[z[i]] == s[z[i] + i]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
}
*/

/*vector<ll> find_dividers(ll x) {
    vector<ll> dividers;

    for (ll i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
           dividers.push_back(i);
            if (1ll*i * i != x) {
                dividers.push_back(1ll*x / 1ll*i);
            }
        }
    }

    return dividers;
}*/

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

// ceil(a/b) = (a+b-1)/b

void solve() {
    string s;
    cin >> s;
    if (s.back() == 's') {
        s += "es";
    } else {
        s += "s";
    }
    cout << s << endl;

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(10);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3620
from sys import stdin
input = stdin.readline

n, k, q = map(int, input().split())
arr = list(int(input()) for _ in range(q))
cnt = [k] * n
for i in arr:
    cnt[i-1] += 1
print('\n'.join(['Yes' if cnt[i]-q>0 else 'No' for i in range(n)]))


Measured memory_bytes: 53724
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		long ans=1;
		for(int i=2;i<=n;i++) {
			ans*=i;
			ans%=1000000007;
		}
		System.out.println(ans);

	}
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a), _##i = (b); i < _##i; ++i)
#define REP(i, a) for (int i = 0, _##i = (a); i < _##i; ++i)
#define pb push_back
typedef long long LL;

int n;
LL a[100004];

LL solve(LL sum){
	
	LL res = 0;	
	FOR(i,1,n){	
		if(sum < 0){
			if( sum + a[i] > 0){			
				sum += a[i];
				continue;		
			}		
			res+= 1 - (sum + a[i]);
			sum = 1;
		}else{
			if( sum + a[i] < 0) {			
				sum += a[i];
				continue;		
			}
			res+= (sum + a[i]) + 1;
			sum = -1;
		}
	}	
	return res;
}

int main(){
//	freopen("test.in","r",stdin);
	cin>> n;
	REP(i,n){
		cin >> a[i];
	}
	LL sum = a[0];
	if(sum){
		if( sum > 0){
			LL res = min( solve(-1) + sum + 1, solve(sum) );
			cout << min( solve(1) + sum - 1, res ) << endl;
		}else{
			LL res = min( solve(1)  - sum + 1, solve(sum) );
			cout << min( solve(-1)  - sum - 1, res ) << endl;
		}
		//cout << solve(sum) << endl;
	}else{
		cout << min( solve(1), solve(-1) ) + 1 << endl;
	}	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <numeric>
#include <algorithm>

#include <cctype>

using namespace std;
using ulli = unsigned long long int;
using uchar = unsigned char;

int main(void){
	int n, m;
	
	cin >> n >> m;
	
	cout << (n - 1) * (m - 1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
import itertools
n,m = map(int,raw_input().split())

permutations = list(itertools.permutations(range(1,n)))


arr = [[-1 for i in range(n)] for j in range(n)]


for i in range(m):
	f,t = map(int,raw_input().split())
	f -= 1
	t -= 1
	arr[f][t] = 1
	arr[t][f] = 1


ans = 0
for p in permutations :
	count = 0
	if arr[0][p[0]] == 1 :
		count += 1
	else:
		next

	for i in range(0,len(p)-1):
		if arr[p[i]][p[i+1]] == 1 :
			count += 1

		else:
			break

	if count == n-1 :
		ans += 1
print ans

Measured memory_bytes: 3204
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define mp make_pair
#define rep(a,b,c) for(int a=1;a<=b;a+=c)
#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)

const double PI=acos(-1);
const double EPS=1e-12;
const int MOD=1e9+7;
const int INF=1<<30;


using namespace std;

int maxx[100005];

int main(){
	//ios::sync_with_stdio(false);cin.tie(NULL);	cout.tie(NULL);
	int in,n,t,w;
	rep(i,100000,1){
		maxx[i]=INF;
	}
	cin>>in>>n;
	rep(i,in,1){
		cin>>t>>w;
		for(int j=100000;j>=w;j--){
			maxx[j]=min(maxx[j],maxx[j-w]+t);
		}
	}
	int res=0;
	for(int i=100000;i>=1;i--){
		if(maxx[i]<=n){
			res=i;
			break;
		}
	}
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
const ll MOD = 1e9 + 7;
const ll INF = (ll)1e18;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  int arr[2][n];
  fi(0,2)
    fj(0,n)
      cin>>arr[i][j];
  int sum=arr[0][0] + accumulate(arr[1],arr[1]+n,0);
  int max=sum;
  fi(1,n){
    sum+=arr[0][i];
    sum-=arr[1][i-1];
    if(sum>max)max=sum;
  }
  cout << max << endl;
  return 0;
}



Measured memory_bytes: 256
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	h,w,k = readline() |> split |> parseMap
	c = String["" for i in 1:h]
	for i in 1:h
		c[i] = readline() |> chomp
	end
	s = 0
	b = 0
	while b<2^(h+w)
		x = 0
		for i in 1:h
			for j in 1:w
				if b>>(i-1)%2==0&&b>>(h+j-1)%2==0&&c[i][j]=='#'
					x += 1
				end
			end
		end
		if x == k
			s += 1
		end
		b += 1
	end
	println(s)
end

main()

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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

ll pow(ll x, ll y) {
	if(y == 0)
	return 1;
	ll temp = pow(x, y/2);
	temp = (temp*temp);
	if(y%2 == 1)
		temp *= x;
	return temp;
}

const int MAXN = 5E5 + 100;

int n, q;
vector<bool> seg_tree[3*MAXN + 100];
string s;

void build(int node, int l, int r)  {
	//error(node, l, r);
	if(l == r) {
		seg_tree[node][s[l] - 'a'] = 1; 
		return;
	}
	int mid = (l + r)/2;
	build(2*node + 1, l, mid);
	build(2*node + 2, mid + 1, r);
	for(int i = 0; i < 26; i++)
		seg_tree[node][i] = seg_tree[2*node + 1][i] | seg_tree[2*node + 2][i];
}

vector<bool> get(int node, int l, int r, int tl, int tr) {
	if(tr < tl) {
		vector<bool> v(26, 0);
		return v;
	}
	if(l == tl && r == tr)
		return seg_tree[node];
	int mid = (l + r)/2;
	vector<bool> v1, v2;
	v1 = get(2*node + 1, l, mid, tl, min(mid, tr));
	v2 = get(2*node + 2, mid + 1, r, max(mid + 1, tl), tr);
	vector<bool> v3(26, 0);
	for(int i = 0; i < 26; i++)
		v3[i] = v1[i] | v2[i];
	return v3; 
}

void update(int node, int l, int r, int m, int val) {
	if(l == m && r == m) {
		vector<bool> b(26, 0);
		b[val] = 1;
		seg_tree[node] = b;
		return;
	}
	int mid = (l + r)/2;
	if(m > mid)
		update(2*node + 2, mid + 1, r, m, val);
	else
		update(2*node + 1, l, mid, m, val);
	for(int i = 0; i < 26; i++)
		seg_tree[node][i] = seg_tree[2*node + 1][i] | seg_tree[2*node + 2][i];
}

int main() {
	cin >> n >> s >> q;
	for(int i = 0; i < 3*MAXN + 100; i++) {
		vector<bool> b(26, 0);
		seg_tree[i] = b;
	}
	build(0, 0, n - 1);
	//mainspring;
	while(q--) {
		int flag;
		cin >> flag;
		if(flag == 1) {
			int i;
			char c;
			cin >> i >> c;
			--i;
			update(0, 0, n - 1, i, c - 'a');
		}
		else {
			int l, r;
			cin >> l >> r;
			--l, --r;
			vector<bool> v = get(0, 0, n - 1, l, r);
			int res = 0;
			for(int i = 0; i < sz(v); i++)
				res += v[i];
			cout << res << '\n';
		}
	}
}

Measured memory_bytes: 106372
#include <iostream>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;

signed main() {
  int A, B, C, K; cin >> A >> B >> C >> K;
  std::cout << ((K % 2 == 0) ? A - B : B - A) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#ifdef ConanYu
#include "local.hpp"
#else
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

void Main() {
  int a, b; cin >> a >> b;
  int k = 1, ans = 0;
  while(b > k) {
    k = k - 1 + a;
    ans++;
  }
  cout << ans << "\n";
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


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

#define MOD (long)(1e9 + 7)
const ll mod =  (long)(1e9 + 7);

long long modPow(int x, int n){
  if(n == 0) return 1;
  if(n % 2 == 0) {
    long long sqrtX = modPow(x,n/2);
    return sqrtX * sqrtX % MOD ;
  }else{
    return x * modPow(x,n-1) % MOD;
  }
}

ll kaizyouMemo[2000000];
ll kaizyou(ll x){
  if(kaizyouMemo[x] != 0) return kaizyouMemo[x];
  if(x == 0) return 1;
  if(x == 1) return 1;
  kaizyouMemo[x] = (kaizyou(x-1) * x ) % mod;
  return kaizyouMemo[x];
}

long long modCombi(long long a, long long b){
  if(b > a/2) return modCombi(a,a-b);
  return ((kaizyou(a) * modPow(kaizyou(b),MOD - 2)) % MOD)* modPow(kaizyou(a-b),MOD - 2) % MOD;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a,b,c;

  cin >> n >> a >> b >> c;

  a *= modPow(100,mod-2), a %= mod;
  b *= modPow(100,mod-2), b %= mod;

  ll ans = 0;
  ll A = a * modPow((a+b)%mod, mod-2);
  ll B = b * modPow((a+b)%mod, mod-2);
  A %= MOD;
  B %= MOD;

  FOR(i,n, 2 * n){
    ll tmp1 = modCombi(i-1,n-1) * modPow(A,n);
    tmp1 %= MOD;
    tmp1 *= modPow(B,i-n);
    tmp1 %= MOD;

    ll tmp2 = modCombi(i-1,n-1) * modPow(B,n);
    tmp2 %= MOD;
    tmp2 *= modPow(A,i-n);
    tmp2 %= MOD;

    ans += i * (tmp1 + tmp2) % mod;
    ans %= mod;
  }
  ans *= modPow(a+b,mod-2);
  ans %= mod;

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


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define lli long long int
#define pb push_back
#define FORA(i,s,e) for(int i = s; i < e; i++)
#define FORB(i,s,e) for(int i = s; i <= e; i++)

using namespace std;


int main(void)
{
	string s;
	cin >> s;
	string t;
	cin >> t;
	int maxi = -1;
	int cnt = 0;
	int len1 = s.size(), len2 = t.size();
	for(int i = 0 ; i <= len1 - len2; i++)
	{
		for (int j = 0; j < len2; j++)
		{
			if (s[i + j] == t[j])
				cnt++;
		}
		if (maxi < cnt)
		{
			maxi = cnt;
		}
		cnt = 0;
	}
	if (maxi == -1)
	{
		cout << len2 << endl;
	}
	else
		cout << len2 - maxi << endl;
	return 0;
}

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

n = int(input())

a = list()
for i in range(n):
    a.append(int(input()))

a_sorted = sorted(a, reverse=True)

for i in range(n):
    if a[i] == a_sorted[0]:
        print(a_sorted[1])
        continue

    print(a_sorted[0])


Measured memory_bytes: 70360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll H, W, N;
    cin >> H >> W >> N;
    vector<ll> a(N);
    rep(i, 0, N) cin >> a[i];

    vector<vector<ll>> ans(H, vector<ll>(W)); 
    ll h = 0, w = 0;
    rep(n, 0, N){
        rep(i, 0, a[n]){
            ans[h][w] = n+1;
            if(h % 2 == 0 && w == W-1){
                h++;
            }else if(h % 2 == 1 && w == 0){
                h++;
            }else{
                if(h % 2 == 0) w++;
                else w--;
            }
        }
    }
    rep(i, 0, H){
        rep(j, 0, W){
            cout << ans[i][j];
            if(j != W-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for ( int i=1; i<=int(n); i++ )
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template <class T>
inline bool RD(T &ret) {
        char c; int sgn;
        if (c = getchar(), c == EOF) return 0;
        while (c != '-' && (c<'0' || c>'9')) c = getchar();
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
        ret *= sgn;
        	return 1;
}
template <class T>
inline void PT(T x) {
        if (x < 0) putchar('-') ,x = -x;
        if (x > 9) PT(x / 10);
        putchar(x % 10 + '0');
}
typedef unsigned long long LL;
typedef pair<int, int> pii;
typedef long double LD;
const int INF = 0x3f3f3f3f;


const int N = 2e5 + 100;
struct node {
	int v, col, id;
	node(int v = 0, int col = 0, int id = 0):v(v), col(col), id(id){}
};
bool cmp(node a, node b) {
	return a.col < b.col;
}
vector<node> G[N];
int vis[N];
bool book[N];

int ans[N];
int que[N], t;
int top;
int s;
int q[N], tail;
int n;
void BFS(int col) {
    for(int i = 0; i < tail; i ++) {
        int u = q[i];
        if(u == n) return ;
        int lb = -1, ub = SZ(G[u]);
        while(ub - lb > 1) {
            int mid = (lb + ub) >> 1;
            if(G[u][mid].col >= col) ub = mid;
            else lb = mid;
        }
        if(ub == SZ(G[u]) || G[u][ub].col != col) continue;
        for(int i = ub; i < SZ(G[u]); i ++) {
            if(G[u][i].col != col) break;
            int v = G[u][i].v, id = G[u][i].id;
            if(vis[v] == top) continue;
            if(book[id]) break;
            vis[v] = top;
            book[id] = 1;
            if(ans[v] == INF) ans[v] = ans[s] + 1, que[t ++] = v;
            q[tail ++] = v;
        }
    }
}
int main() {
	memset(ans, 0x3f, sizeof(ans));
	int m;
	RD(n), RD(m);
	for(int i = 1;  i <= m; i ++) {
		int u, v, c;
		RD(u), RD(v), RD(c);
		G[u].PB(node(v, c, i));
		G[v].PB(node(u, c, i));
	}
	for(int i = 1; i <= n; i ++) sort(G[i].begin(), G[i].end(), cmp);
	ans[1] = 0;
	vis[1] = ++ top;
	que[t ++] = 1;
	for(int i = 0; i < t; i ++) {
		int u = que[i];
		if(u == n) break;

		for(int i = 0; i < SZ(G[u]); i ++) {
			int id = G[u][i].id, v = G[u][i].v;
			if(book[id]) continue;
			vis[u] = ++ top;
			s = u;
			tail = 0;
			q[tail ++] = s;
			BFS(G[u][i].col);
		}
	}
	if(ans[n] == INF) puts("-1");
	else printf("%d\n", ans[n]);
}


Measured memory_bytes: 15104
"use strict";
    
class PriorityQueue {
  constructor() {
    this.heap = [];
  }

  push(item) {
    let heap = this.heap;
    let i = heap.length++;
    let j;

    while(i) {
      j = Math.floor((i - 1) / 2);
      if(heap[j] <= item) break;
      heap[i] = heap[j]
      i = j;
    }

    heap[i] = item;
  }

  pop() {
    let heap = this.heap;
    let top = heap[0];
    let popped = heap.pop();

    let i = 0;
    let k = Math.floor(heap.length / 2);
    let j;

    while(i < k) {
      j = (i * 2) + 1;
      if(heap[j+1] < heap[j]) ++j;

      if(popped <= heap[j]) break;

      heap[i] = heap[j];

      i = j;
    }

    if(heap.length) {
      heap[i] = popped;
    }

    return top;
  }

  size() {
    return this.heap.length;
  }

  top() {
    return this.heap[0];
  }
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    
    const A = arg[1].split(" ").map(n=>parseInt(n));
    const B = arg.slice(2, M + 2).map(n=>n.split(" ").map(l=>parseInt(l)));
    
    B.sort((a,b)=>b[1] - a[1])
    
    let pq = new PriorityQueue();
    
    for(let i=0; i<N; i++) {
        pq.push(A[i]);
    }
    
    // console.log(pq.heap)
    
    for(let i=0; i<M; i++) {
        let target = B[i][0];
        let num = B[i][1];
        
        let temp = pq.top();
        
        for(let j=0; j<target; j++) {
            if(num > temp) {
                pq.pop();
                pq.push(num);
            } else {
                break;
            }
        }
    }
    
    console.log(pq.heap.reduce((m,n)=>m+n));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 59180
package main

import (
  	"bufio"
	"fmt"
	"os"
	"strconv"
	"sync"
)

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func maxt(a ...int) int {
	t := a[0]
	for _, x := range a {
		t = max(t, x)
	}
	return t
}

const nax = 3003

func main() {
	var dp [nax][nax]float64
	dp[0][0] = 1
	n := ReadInt()
	for i := 1; i <= n; i++ {
		a := ReadFloat()
		for j := 1; j <= n + 1; j++ {
			dp[i][j - 1] += dp[i - 1][j - 1] * (1 - a)
			dp[i][j] += dp[i - 1][j - 1] * a
		}
	}
	var ans float64
	for i := (n + 1) / 2; i <= n; i++ {
		ans += dp[n][i]
	}
	fmt.Println(ans)
}


var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.ParseInt(intStr, 10, 32)
	return int(i)
}
func ReadFloat() float64 {
	intStr := ReadString()
	i, _ := strconv.ParseFloat(intStr, 64)
	return float64(i)
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)
 
	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)
 
	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()
 
		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}

Measured memory_bytes: 73344
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=924844033,gi=554906420;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=(1<<19)+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void Add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int fac[N],ifac[N],r[25][N],rt[2][N],f[N],g[N],inv[25];
int n,lim,d;
inline void swap(R int &x,R int &y){R int t=x;x=y,y=t;}
inline int C(R int n,R int m){return m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
void init(){
	fac[0]=ifac[0]=1;fp(i,1,262144)fac[i]=mul(fac[i-1],i);
	ifac[262144]=ksm(fac[262144],P-2);fd(i,262143,1)ifac[i]=mul(ifac[i+1],i+1);
    fp(d,1,19){
        fp(i,1,(1<<d)-1)r[d][i]=(r[d][i>>1]>>1)|((i&1)<<(d-1));
        inv[d]=ksm(1<<d,P-2);
    }
    for(R int t=(P-1)>>1,i=1,x,y;i<=262144;i<<=1,t>>=1){
        x=ksm(5,t),y=ksm(gi,t),rt[0][i]=rt[1][i]=1;
        fp(k,1,i-1)
            rt[1][i+k]=mul(rt[1][i+k-1],x),
            rt[0][i+k]=mul(rt[0][i+k-1],y);
    }
}
void NTT(int *A,int ty){
	fp(i,0,lim-1)if(i<r[d][i])swap(A[i],A[r[d][i]]);
	R int t;
	for(R int mid=1;mid<lim;mid<<=1)
		for(R int j=0;j<lim;j+=(mid<<1))
			fp(k,0,mid-1)
				A[j+k+mid]=dec(A[j+k],t=mul(rt[ty][mid+k],A[j+k+mid])),
				A[j+k]=add(A[j+k],t);
	if(!ty){
		t=inv[d];
		fp(i,0,lim-1)A[i]=mul(A[i],t);
	}
}
int sz[N];
void dfs(int u,int fa){
	sz[u]=1;
	go(u)if(v!=fa){
		dfs(v,u),sz[u]+=sz[v];
		++f[n-sz[v]],++f[sz[v]];
	}
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),Add(u,v),Add(v,u);
	dfs(1,0);init();
	lim=1,d=0;
	while(lim<=(n<<1))lim<<=1,++d;
	fp(i,0,n)f[i]=mul(f[i],fac[i]),g[i]=ifac[n-i];
	NTT(f,1),NTT(g,1);
	fp(i,0,lim-1)f[i]=mul(f[i],g[i]);
	NTT(f,0);
	fp(i,1,n)printf("%d\n",dec(mul(n,C(n,i)),mul(f[i+n],ifac[i])));
	return 0;
}

Measured memory_bytes: 72320
#include<iostream>
using namespace std;
int main()
{
    long long int a,b=0,c=0;
    string s;
    cin>>a;
    cin>>s;
    int i=0,len;
    len=s.size();
    do{
        b=b*10+(s[i]-'0');
        i++;
    }while(s[i]!='.');
    i++;
    while(i<len)
    {
        c=c*10+(s[i]-'0');
        i++;
    }
    cout<<a*b+a*c/100;
   return 0;
}




Measured memory_bytes: 3164
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {
	
	int A, B;
	scanf("%d%d", &A, &B);
	int a = A + B;
	int b = A - B;
	int c = A * B;
	if (a >= b&&a >= c) {
		printf("%d", a);
	}
	else if (b >= a && b >= c) {
		printf("%d", b);
	}
	else {
		printf("%d", c);
	}


	return 0;

}

Measured memory_bytes: 128