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

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n;cin>>n;

  if (n%2==1){
    cout << 0 << endl;
    return 0;
  }

  int num2 = 0;
  int num5 = 0;

  int x = 2;
  rep(i, 1, 61){
    num2 += n/x;
    x *= 2;
  }
  dump(num2);

  int y = 5;
  rep(i, 1, 61){
    num5 += n/(2*y);
    y *= 5;
    if (2*y>n) break;
  }
  dump(num5);

  cout << min(num2, num5) << endl;

  return 0;
}


Measured memory_bytes: 256
import copy
n = int(input())
S = list(input())

table = [{}]
cnt = {'R': 0, 'G': 0, 'B': 0}
for s in S:
    cnt[s] += 1
    table.append([s, copy.deepcopy(cnt)])

RGB = set(['R', 'G', 'B'])
ans = 0
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        if table[i][0] != table[j][0]:
            kigou_set = RGB ^ set([table[i][0], table[j][0]])
            kigou = list(kigou_set)[0]
            sa = table[-1][1][kigou] - table[j][1][kigou]
            ans += sa
            l = j + (j - i)
            # print(i, j, l)
            if l <= n:
                if table[l][0] == kigou:
                    # print(table[l][1],kigou)
                    ans -= 1
                
print(ans)


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

int main()
{
    int n;
    cin >> n;
    int a[n] = {};
    for(int i=0; i<n; i++) cin >> a[i];
    long long dp[n+1][n+1] = {};
    for(int len=1; len<=n; len++){
        for(int i=0; i+len<=n; i++){
            int j = i+len;
            if ((n - len) % 2 == 0)
                dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j-1] + a[j-1]); // first
            else
                dp[i][j] = min(dp[i+1][j] - a[i], dp[i][j-1] - a[j-1]); // second
                
           /* if((n - len) % 2 != 0){
                dp[i][j+1] = max(dp[i][j+1], a[j] + dp[i][j]);
                if(i>0) dp[i-1][j] = max(dp[i-1][j], a[i-1] + dp[i][j]);
            }else{
                 dp[i][j+1] = min(dp[i][j+1], -a[j] + dp[i][j]);
                if(i>0) dp[i-1][j] = min(dp[i-1][j], -a[i-1] + dp[i][j]);
            } */
        }
    /*    for(int i=0; i<n; i++){
            for(int j=0; j<=n; j++) cout << dp[i][j] << " ";
            cout << endl;
        }
        cout << endl;*/
    }
    cout << dp[0][n] << endl;
    return 0;
}

Measured memory_bytes: 70656
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
using namespace std;
  
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
  
#define csh(a,n) memset(a,n,sizeof(a));
char arr[30001];
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a==2){
		if(b==28){
			cout<<1<<endl;
		}
		else{
			cout<<0<<endl;
		}
	}
	else if(a<8&&a%2==1&&b==31||a<8&&a%2==0&&b==30||a>7&&a%2==0&&b==31||a>7&&a%2==1&&b==30){
			cout<<1<<endl;
	}
	else{
		cout<<0<<endl;
	}
} 

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

int n;
int s[1001][1024];
int calc(int y,int x,int n){
	int a,b,c,d;
	n--;
	a=s[y-1][x-1];
	b=s[y-1][x+n];
	c=s[y+n][x-1];
	d=s[y+n][x+n];
	return d-c-b+a;
}
int main(){
	while(cin>>n,n){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				char c;
				cin>>c;
				s[i][j] = (c=='*')+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
			}
		}
		int ans=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				int lb=ans,ub=n-max(i,j)+2;
				if(ub+1<=ans)continue;
				while(ub-lb>1){
					int m=(lb+ub)/2;
					if(calc(i,j,m))ub=m;
					else lb=m;
				}
				ans=max(ans,lb);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 5164
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n;

int dfs(int sum, int d, int c){
  //  printf("%d %d\n", sum, c);
  if(sum == n) return 1;
  if(c >= 4) return 0;
  int res = 0;
  for(int i = d; i*i <= n; i++){
    if(sum + i*i > n) break;;
    res += dfs(sum + i*i, i, c+1);
  }
  return res;
}

int main(){
  while(scanf("%d", &n) && n){
    printf("%d\n", dfs(0, 1, 0));
  }
  return 0;
}

Measured memory_bytes: 1188
#include<cstdio>
int main()
{
    double x,y,q,e;
    scanf("%lf%lf%lf%lf",&x,&y,&q,&e);
    printf("%lf ",x*y/2);
    if(q*2==x&&e*2==y||q*2==y&&e*2==x)
        printf("1");
    else
        printf("0");
    return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N, M = map(int, input().split())
    graph = defaultdict(list)
    for _ in range(M):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)

    for a in graph[1]:
        if N in graph.get(a, []):
            print("POSSIBLE")
            return
    print("IMPOSSIBLE")


if __name__ == '__main__':
    main()


Measured memory_bytes: 51324
# Dinic's algorithm
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow

N = int(input())
ab = [ list(map(int,input().split())) for i in range(N)]
cd = [ list(map(int,input().split())) for i in range(N)]

D = Dinic(N*2+2)

for i in range(N):
    for j in range(N):
        if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
            D.add_edge(i,j+N,1)

for i in range(N):
    D.add_edge(N*2,i,1)
for i in range(N):
    D.add_edge(i+N,N*2+1,1)

print(D.flow(N*2,N*2+1))


Measured memory_bytes: 44764
#include <bits/stdc++.h>
using namespace std;
#define FILEIN freopen("in.txt","r",stdin)
#define ll long long
ll UNVISITED = 1e9 + 7;
int H,W;
vector< string > s;
int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};

ll BFS(int i,int j){
    queue< pair< int,int > > q;
    vector< vector< ll > > visit(H,vector< ll >(W,UNVISITED));
    q.push({i,j});
    visit[i][j] = 0;//first visited node
    while(!q.empty()){
        pair< int,int > current = q.front();
        q.pop();
        for(int k = 0;k<4;k++){
            int nx = current.first + dx[k], ny = current.second + dy[k];
            if(nx>= 0 && nx < H && ny>=0 && ny < W && s[nx][ny] == '.' && visit[nx][ny] == UNVISITED){
                visit[nx][ny] = visit[current.first][current.second] + 1;
                q.push(make_pair(nx,ny));
            }
        }
    }
    ll max1 = 0;
    for(int k = 0;k < H;k++){
        for(int z = 0; z< W;z++){
            if(visit[k][z] != UNVISITED){
                max1 = max(max1,visit[k][z]);
            }
        }
    }
    return max1;
}

int main()
{
   // FILEIN;
    cin >> H >> W;
    s.resize(H);
    ll step = 0;
    for(auto &i : s)    cin >> i;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(s[i][j] == '.'){
                step = max(step,BFS(i,j));//starting from different positions(i,j) each time
            }
        }
    }
    cout << step << endl;
}


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

Measured memory_bytes: 596
#include <stdio.h>
#include <math.h>

int main(){
  int i,cnt;
  double xa, ya, ra, xb, yb, rb, dist;
  scanf("%d", &cnt);
  for(i=0;i<cnt;i++){
    scanf("%lf %lf %lf %lf %lf %lf",&xa, &ya,&ra,&xb,&yb,&rb);
    dist = sqrt(pow(xa-xb,2)+pow(ya-yb,2));
    if(dist>ra+rb){
      printf("0\n");
    }else if(dist >= fabs(ra-rb)){
      printf("1\n");
    }else if(ra>rb){
      printf("2\n");
    }else{
      printf("-2\n");
    }
  }
  return 0;
}

Measured memory_bytes: 620
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn in_digit(mut x: u32, a: u32, b: u32) -> bool {
    let mut sum = 0;
    while x > 0 {
        sum += x % 10;
        x /= 10;
    }
    a <= sum && sum <= b
}

use std::collections::HashSet;
use std::collections::BTreeSet;

fn main() {
    input! {
        n: u32,
        m: [u32; n]
    }
    let mut v: Vec<u32> = m;
    v.sort();
    let mut mochi = BTreeSet::new();
    for &item in v.iter() {
        mochi.insert(item);
    }
    println!(
        "{}",
        mochi.len()
    )
}


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


typedef long long int ll;

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


	if(s[s.length() - 1] != 's')
	{	cout << s <<'s';}
	else
		cout << s << "es";
	

	return 0;
}


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

int main(){
    int N;
    cin >> N;
    char name[100000][11];
    long long m=0,a=0,r=0,c=0,h=0;
    for(int i=0;i<N;i++){
        cin >> name[i];
        switch(name[i][0]){
            case 'M':
                m++;
                break;
            case 'A':
                a++;
                break;
            case 'R':
                r++;
                break;
            case 'C':
                c++;
                break;
            case 'H':
                h++;
                break;
        }
    }
    long long ans;
    ans=m*(a*r + a*c + a*h + r*c + r*h + c*h) + a*(r*c + r*h + c*h) + r*c*h + 0;
    cout << ans;
    return 0;
}

Measured memory_bytes: 1280
import Data.List

main :: IO()
main = getContents >>= putOut.formatOut.solve.formatIn
  where putOut s | null s || last s == '\n' = putStr s
                 | otherwise                = putStrLn s

formatIn :: String -> [Int]
formatIn = map read.words.(!!1).lines

formatOut :: [[Int]] -> String
formatOut = unlines.map (unwords.(map show))

solve    :: [Int] -> [[Int]]
solve xs = zipWith (((\(x,y)-> sort x ++ y ).).splitAt)  [1..length xs] $repeat xs

Measured memory_bytes: 5048
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vishal Burman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            out.println((int) Math.pow(n, 3));
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}




Measured memory_bytes: 24264
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;

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

	cin >> N >> M;
	N <<= 1;
	vector<long long int>v(N);
	vector<long long int>w(N);
	for (auto &i : v)cin >> i;
	for (auto &i : w)cin >> i;
	long long int ans = v.front() + v.back();
	set<pair<long long int, int>>in;
	set<pair<long long int, int>>out;
	long long int insum = 0;
	vector<long long int>num(N);
	for (int i = 1; i < N - 1; i++) {
		ans += v[i];
		num[i] = w[i] - v[i];
		if (v[i] < w[i]) {
			in.insert({ num[i],i });
			ans += num[i];
		}
		else {
			out.insert({ -num[i],i });
		}
	}
	while (in.size() && in.begin()->first < 0) {
		int n = in.begin()->second;
		ans -= num[n];
		out.insert({ -in.begin()->first, in.begin()->second });
		in.erase(in.begin());
	}
	while (out.size() && out.begin()->first < 0) {
		int n = out.begin()->second;
		ans += num[n];
		in.insert({ -out.begin()->first, out.begin()->second });
		out.erase(out.begin());
	}
	if (in.size() & 1) {
		if (in.begin()->first > out.begin()->first) {
			in.insert({ -out.begin()->first,out.begin()->second });
			ans += num[out.begin()->second];
			out.erase(out.begin());
		}
		else {
			out.insert({ -in.begin()->first,in.begin()->second });
			ans -= num[in.begin()->second];
			in.erase(in.begin());
		}
	}
	while (M--) {
		cin >> K >> L >> R;
		K--;
		ans -= v[K];
		v[K] = L, w[K] = R;
		if (K == 0 || K == N - 1) {
			ans += v[K];
			cout << ans << endl;
			continue;
		}
		if (in.find({ num[K],K }) != in.end()) {
			ans -= num[K];
			in.erase({ num[K],K });
		}
		else {
			out.erase({ -num[K],K });
		}
		num[K] = w[K] - v[K];
		ans += L;
		if (num[K] > 0) {
			in.insert({ num[K],K });
			ans += num[K];
		}
		else {
			out.insert({ -num[K],K });
		}
		while (in.size() && in.begin()->first < 0) {
			int n = in.begin()->second;
			ans -= num[n];
			out.insert({ -in.begin()->first, in.begin()->second });
			in.erase(in.begin());
		}
		while (out.size() && out.begin()->first < 0) {
			int n = out.begin()->second;
			ans += num[n];
			in.insert({ -out.begin()->first, out.begin()->second });
			out.erase(out.begin());
		}
		if (in.size() & 1) {
			if (in.begin()->first > out.begin()->first) {
				in.insert({ -out.begin()->first,out.begin()->second });
				ans += num[out.begin()->second];
				out.erase(out.begin());
			}
			else {
				out.insert({ -in.begin()->first,in.begin()->second });
				ans -= num[in.begin()->second];
				in.erase(in.begin());
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 18944
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr ,greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,0 }, dy[] = { 1,0,-1,0,0 };
const int SIZE1 =3e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 22;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
ut N, M, K, X, L, Y,H,W,Q;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], nums[SIZE], maps[SIZE3][SIZE3], answer = zero;
LL A[SIZE], B[SIZE];
LL output(int x) {
	cout << x << endl;
	string k;
	cin >> k;
	if (k == "No") return 0;
	else if (k == "Yes") return 2;
	else return 1;
}
LL solve2() {
	LL num = 0;
	LL ans = 0;
	EFOR(i, 1, 9) {
		ans = output(i);
		if (ans == 2) return 0;
		else if (ans == 1) num += 1 << (i - 1);
	}
	assert(num <= N);
	assert(output(num)==2);
	return 0;
}
LL solve() {
	cin >> N >> K;
	if (N <=10) {
		cout << 0 << endl;
		REP(k,K)
			EFOR(i,1, N) {
				if (output(i)==2) break;
			}
	}
	else {
		Vpr v;
		EFOR(i, 1, 9)
			EFOR(j, 10, N) {
			if (j&(1 << (i - 1))) {
				v.pb(i, j);
			}
		}
		cout << v.size() << endl;
		REP(i, v.size()) cout << v[i].first << " " << v[i].second << endl;

		REP(i, K) solve2();
	}
	return 0;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	solve();
//	cin >> N;
	return 0;
}


Measured memory_bytes: 10296
N = int(input())

ALP = "abcdefghij"

result = []

def mx(s):
    m = 0
    for i in s:
        if m < int(i):
            m = int(i)
    return m

def add(res):
    res_c = []
    for r in res:
        m = mx(r)
        for i in range(1, m + 2):
            res_c.append(r + str(i))
    return res_c

for n in range(N):
    if n == 0:
        result.append("1")
    else:
        result = add(result)

v = []
for i in range(1, N + 1):
    v = []
    for j in result:
        a = j.replace(str(i), ALP[i - 1])
        v.append(a)
    result = v

for r in result:
    if r == 'abcdefghia0':
        print('abcdefghij')
    else:
        print(r)

Measured memory_bytes: 19576
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
	int H, W, h, w;

	scanf("%d %d %d %d", &H,&W,&h,&w);

	printf("%d\n", H*W - (h*W + H*w - h*w));

	return 0;
}

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

int main()
{
    string s; cin >> s;
    int n=s.size();
    int n2=(s.size()-1)/2;
    string res="Yes";
    for(int i=0;i<n2;i++){
        if(s[i]!=s[n2-1-i]){
            res="No";
        } else if(s[n2+1+i]!=s[n-1-i]){
            res="No";
        } else if(s[i]!=s[n-1-i]){
            res="No";
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N = 2e5 + 54;
int n, k, c, id[N], tot, d1[N], d2[N];
char s[N];
inline int check(int x) {
	if (x == 1) return d2[2] < k;
	if (x == tot) return d1[x - 1] < k;
	if (d1[x - 1] + d2[x + 1] >= k) return 0;
	if (d1[x - 1] + d2[x + 1] + 1 < k) return 1;
	int l = 1, r = x - 1;
	int L = -1, R = -1;
	while (l <= r) {
		int mid = l + r >> 1;
		if (d1[mid] == d1[x - 1]) L = mid, r = mid - 1;
		else l = mid + 1;
	}
	while (l <= r) {
		int mid = l + r >> 1;
		if (d2[mid] == d2[x + 1]) R = mid, l = mid + 1;
		else r = mid - 1;
	}
	if (id[R] - id[L] > c) return 0;
	else return 1;
}
int main() {
	std::cin >> n >> k >> c;
	std::cin >> s + 1;
	for (int i = 1; i <= n; ++i)
		if (s[i] == 'o') id[++tot] = i;
	for (int i = 1; i <= tot; ++i) {
		int l = 1; int r = i - 1;
		int ID = 0;
		while (l <= r) {
			int mid = l + r >> 1;
			if (id[mid] <= id[i] - c - 1) ID = mid, l = mid + 1;
			else r = mid - 1;
		}
		d1[i] = d1[ID] + 1;
	}
	for (int i = tot; i; --i) {
		int l = i + 1; int r = tot;
		int ID = tot + 1;
		while (l <= r) {
			int mid = l + r >> 1;
			if (id[mid] >= id[i] + c + 1) ID = mid, r = mid - 1;
			else l = mid + 1;
		}
		d2[i] = d2[ID] + 1;
	}
	//for (int i = 1; i <= tot; ++i) std::cout << d1[i] << ' ' << d2[i] << '\n';
	for (int i = 1; i <= tot; ++i)
		if (check(i)) std::cout << id[i] << '\n';
}


Measured memory_bytes: 4096
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner br = new Scanner(System.in);
		int x;
		int y;
		StringBuilder sb = new StringBuilder();
		while (true){
			x = br.nextInt();
			y = br.nextInt();
			if (x == 0&&y==0){
				break;
			} else if (x<y){
				sb.append(x).append(" ").append(y).append("\n");
			} else {
				sb.append(y).append(" ").append(x).append("\n");
			}
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 35540
#include <iostream>

using namespace std;

int main() {

  int n, l, s = 0, m = 0;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> l;
    s += l;
    m = max(m, l);
  }
  if(m < s - m){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] num=new int[10];
		for(int i=0; i<N; i++){
			for(int j=0; j<10; j++){
				num[j]=sc.nextInt();
			}
			if(dfs(0,0,0,num))System.out.println("YES");
			else System.out.println("NO");
		}
	}
	
	static boolean dfs(int pos, int l, int r, int[] num){
		if(pos==10)return true;
		
		boolean flag1 = false;
		boolean flag2 = false;
		if(l<num[pos])flag1=dfs(pos+1,num[pos],r,num);
		if(r<num[pos])flag2=dfs(pos+1,l,num[pos],num);
		
		if(flag1==true || flag2==true)return true;
		else return false;
	}
}

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

using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll LIM = 1e13;
int main(){
    ll n;
    cin >> n;
    ll i;
    ll ret = 0;
    for(i=1;i<=n;i++){
        ll now = i;
        ll cnt=0;
        while(now!=0){
            now/=10;
            cnt++;
        }
        if(cnt%2==1)ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

N, M, K = map(int, input().split())
uf = UnionFind(N)

friend =[[] for _ in range(N)]
block = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    uf.union(a, b)
    friend[a].append(b)
    friend[b].append(a)

for _ in range(K):
    c, d = map(int, input().split())
    c, d = c-1, d-1
    if uf.same(c, d):
        block[c].append(d)
        block[d].append(c)
ans = [0] * N
for i in range(N):
    ans[i] = uf.size(i) - len(friend[i]) - len(block[i]) - 1
print(*ans)

Measured memory_bytes: 46864
#include <bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
using namespace std;
typedef long long ll;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();c!='-'&&(c<'0'||c>'9');c=getchar());
	if (c=='-') f=-1,c=getchar();
	for(;c>='0'&&c<='9';c=getchar()) n=(n<<3)+(n<<1)+(c&15);
	return n*f;
}
const int maxn=2e5+5;
int n,s,i,ans,a[maxn],j;
bool bz[maxn];
int main(){
	n=read();
	fo(i,1,n) a[i]=read();
	sort(a+1,a+n+1);
	for(s=1<<30;s;s>>=1){
		j=n;
		fo(i,1,n) if (!bz[i]) {
			for(;j>i&&(a[j]>s-a[i]||bz[j]);j--);
			if (j<=i) break;
			if (a[j]==s-a[i]) bz[i]=bz[j]=1,ans++;
		}
	}
	printf("%d\n",ans);
}

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

int main(){
	
	long long int N, K, tmp, high, mid, low, res=0;
	priority_queue<long long int> A;

	cin >> N >> K;

	rep(i, N){
		cin >> tmp;
		A.push(tmp);
	}

	high = A.top()+1;
	low = 0;
	
	while(high > low){
		mid = (high + low)/2;
		if(mid == 0){
			break;
		}
		priority_queue<long long int> tmp_que = A;
		long long int count = 0;
		rep(i, N){
			long long int tmp = tmp_que.top();
			if(tmp <= mid){
				break;
			}
			if(tmp%mid == 0){
				count += (tmp / mid -1);
			}else{
				count += tmp/mid;
			}
			tmp_que.pop();
		}
		if(count <= K){
			res = mid;
			high = mid;
		}else{
			low = mid+1;
		}
	}
	

	cout << res;

	return 0;
}

Measured memory_bytes: 6296
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
	int M = scan.nextInt();
    int a[] = new int[M];
    int b[] = new int[M];
    for (int i = 0; i < M; i++) {
      a[i] = scan.nextInt();
      b[i] = scan.nextInt();
    }
    int load[] = new int[N];
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < N; j++) {
        if(a[i] == j+1 ) {
          load[j]++;
        }
        if (b[i] == j+1) {
          load[j]++;
        }
      }
    }
    for (int i = 0; i < N; i++) {
      System.out.println(load[i]);
    }
  }
}

Measured memory_bytes: 21716
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

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

	vector<int> B(M);

	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}

	LL ans = 0;
	for (int i = 0; i < N; i++) {
		
		LL tmp = 0;
		for (int j = 0; j < M; j++) {
			LL a; cin >> a;
			tmp += a * B[j];
		}

		tmp += C;

		if (tmp > 0) {
			ans++;
		}
	}

	cout << ans << endl;


	return 0;
}

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


int main() {
  int n;
  cin >> n;
  int mod = 1000000007;

  ll ten = 1, nine = 1, eight = 1;
  rep(i, n) {
    ten = (ten * 10) % mod;
    nine = (nine * 9) % mod;
    eight = (eight * 8) % mod;
  }

  ll ans = (ten + eight - nine - nine + 2 * mod) % mod;

  cout << ans << endl;

  return 0;
}
/*
*/


Measured memory_bytes: 3636
import Data.List
main = do
  _ <- getLine
  [t,a] <- map read . words <$> getLine
  h <- map read . words <$> getLine
  let i = map (f a t) h
  print $ 1 + g 0 (elemIndex (minimum i) i)
f z y x = abs (y - x * 0.006 - z)
g d value =
  case value of
    Nothing -> 0
    Just a -> a


Measured memory_bytes: 1276
from collections import defaultdict, deque
from heapq import heappop, heappush
def inpl(): return list(map(int, input().split()))

N, M = inpl()
S, T = inpl()
G = [[] for _ in range(N+1)]
MOD = 10**9 + 7
for _ in range(M):
    u, v, d = inpl()
    G[u].append((v, d))
    G[v].append((u, d))

cost = [10**18]*(N+1)
appear = [0]*(N+1)

Q = [(0, S)]
cost[S] = 0
appear[S] = 1

while Q:
    c, p = heappop(Q)
    if cost[p] < c:
        continue
    for q, d in G[p]:
        if cost[p] + d == cost[q]:
            appear[q] = (appear[q] + appear[p])%MOD
        elif cost[p] + d < cost[q]:
            cost[q] = cost[p] + d
            appear[q] = appear[p] % MOD
            heappush(Q, (cost[q], q))

end = cost[T]*1
ans = pow(appear[T], 2, MOD)

Q = [(0, T)]
cost2 = [10**18]*(N+1)
cost2[T] = 0
appear2 = [0]*(N+1)
appear2[T] = 1
while Q:
    c, p = heappop(Q)
    if cost2[p] < c:
        continue
    for q, d in G[p]:
        if cost[p] - d != cost[q]:
            continue
        if cost2[p] + d == cost2[q]:
            appear2[q] = (appear2[q] + appear2[p])%MOD
        elif cost2[p] + d < cost2[q]:
            cost2[q] = cost2[p] + d
            appear2[q] = appear2[p] % MOD
            heappush(Q, (cost2[q], q))

Q = deque([S])
searched = [False]*(N+1)
searched[S] = True

while Q:
    p = Q.pop()
    if 2*cost2[p] == end:
        ans = (ans - (appear[p]*appear2[p])**2)%MOD

    for q, d in G[p]:
        if cost2[p] - d != cost2[q]:
            continue
        if 2*cost2[q] < end < 2*cost2[p]:
            ans = (ans - (appear[p]*appear2[q])**2)%MOD
        if not searched[q]:
            Q.append(q)
            searched[q] = True
print(ans)

Measured memory_bytes: 114336
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout << '\n';
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n';
#define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n';
#define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n';

void solve(){
  int x; cin>>x;
  vector<pair<int,int>> v;
  for(int i=0 ; i*i*i*i*i<=1e18 ; i++){
      v.pb({i*i*i*i*i,i});
  }
  vector<int> ans;
  for(int i=0 ; i<sz(v) ; i++){
    for(int j=0 ; j<=i ; j++){
      if(x==v[j].f-v[i].f){
        cout<<v[j].s<<' '<<v[i].s;LOL
        return;
      }
      else if(x==v[i].f-v[j].f){
        cout<<v[i].s<<' '<<v[j].s;LOL
        return;
      }
      else if(x==v[i].f+v[j].f){
        cout<<v[i].s<<' '<<-v[j].s;LOL
        return;
      }
      else if(x==-v[i].f-v[j].f){
        cout<<-v[i].s<<' '<<v[j].s;LOL
        return;
      }
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int _ = 1; //cin >> _;
  for(int i = 1 ; i <= _ ; i++){
    //cout << "Case #" << i << ": ";
    solve();
  }
  return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,hh;
    int k,kk;
    int a,b,c,d;
    cin>>h>>hh>>k>>kk;
    cin>>a>>b>>c>>d;
    int x=(a*h+c*(h/10))+(b*hh+d*(hh/20));
    int y=(a*k+c*(k/10))+(b*kk+d*(kk/20));
    if(x==y){
        cout<<"even"<<endl;
    }else if(x>y){
        cout<<"hiroshi"<<endl;
    }else{
        cout<<"kenjiro"<<endl;
    }
    return 0;
}




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

int n;
int a[3];
int b[3];

int mx;
long long knapsack[25000005];

int main()
{
    #ifdef NOT_DMOJ
    freopen("data.txt","r",stdin);
    #endif // NOT_DMOJ
    scanf("%d",&n);
    for (int i=0; i<3; i++) scanf("%d",a+i);
    for (int i=0; i<3; i++) scanf("%d",b+i);
    // exchange a -> b
    // knapsack problem, weight = a[i], pay = b[i]-a[i]
    memset(knapsack,0,sizeof knapsack);
    for (int i=0; i<3; i++) {
        for (int j=a[i]; j<=n; j++) {
            if (knapsack[j]<knapsack[j-a[i]]+b[i]-a[i]) {
                knapsack[j]=knapsack[j-a[i]]+b[i]-a[i];
            }
        }
    }
    n+=knapsack[n];
    // exchange b -> a, weight = b[i], pay = a[i]-b[i]
    memset(knapsack,0,sizeof knapsack);
    for (int i=0; i<3; i++) {
        for (int j=b[i]; j<=n; j++) {
            if (knapsack[j]<knapsack[j-b[i]]+a[i]-b[i]) {
                knapsack[j]=knapsack[j-b[i]]+a[i]-b[i];
            }
        }
    }
    printf("%lld\n",n+knapsack[n]);
}


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

int main() {
  string s; cin >> s;
  if (s[2] == s[3] && s[4]==s[5]) cout << "Yes";
  else cout << "No";
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (H, W): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let s: Vec<Vec<char>> = (0..H).map(|_| {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    }).collect();

    let mut q = std::collections::VecDeque::new();
    let mut dp = vec![vec![-1; W]; H];
    q.push_back((0, 0));
    dp[0][0] = 0;
    while !q.is_empty() {
        let (i, j) = q.pop_front().unwrap();
        for (di, dj) in vec![(1, 0), (0, 1), (-1, 0), (0, -1)] {
            let (i2, j2) = (i + di, j + dj);
            if 0 <= i2 && i2 < (H as i64) && 0 <= j2 && j2 < (W as i64) &&
                dp[i2 as usize][j2 as usize] == -1 && s[i2 as usize][j2 as usize] == '.' {
                dp[i2 as usize][j2 as usize] = dp[i as usize][j as usize] + 1;
                q.push_back((i2, j2));
            }
        }
    }
    let ans = if dp[H - 1][W - 1] == -1 {
        -1
    } else {
        let w = (0..H).map(|i| (0..W).filter(|&j| s[i][j] == '.').count() as i64).sum::<i64>();
        w - dp[H - 1][W - 1] - 1
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
let (n1, n2, n_limit) = (4, 16, 45)

let area =
  [| [1; 4]; [0; 2; 5]; [1; 3; 6]; [2; 7]
   ; [0; 5; 8]; [1; 4; 6; 9]; [2; 5; 7; 10]; [3; 6; 11]
   ; [4; 9; 12]; [5; 8; 10; 13]; [6; 9; 11; 14]; [7; 10; 15]
   ; [8; 13]; [9; 12; 14]; [10; 13; 15]; [11; 14] |]

let goal = Array.init n2 (fun i -> (i + 1) mod n2)

let md = Array.make_matrix n2 n2 0

let initialize_md () =
  for i = 0 to n2 - 2 do
    for j = 0 to n2 - 1 do
      md.(i+1).(j) <- abs (i / n1 - j / n1) + abs (i mod n1 - j mod n1)
    done
  done

let idastar a limit space lower =
  let rec doit i space moved lower =
    if i = limit then
      if a <> goal then ()
      else begin
        Printf.printf "%d\n" limit;
        exit 0;
      end
    else
      List.iter (fun j ->
        let x = a.(j) in
        if x = moved then ()
        else
          let lower = lower - md.(x).(j) + md.(x).(space) in
          if lower + i > limit then ()
          else begin
            a.(j) <- 0;
            a.(space) <- x;
            doit (i + 1) j x lower;
            a.(j) <- x;
            a.(space) <- 0;
          end)
      area.(space) in
  doit 0 space (-1) lower

let findi a x =
  let n = Array.length a in
  let rec doit i =
    if i = n then assert false
    else if a.(i) = x then i
    else doit (i + 1) in
  doit 0

let () =
  initialize_md ();
  let a = Array.init n2 (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let space = findi a 0 in
  let lower =
    Array.fold_left (fun (i, sum) e -> (i + 1, sum + md.(e).(i))) (0, 0) a |> snd in
  for limit = lower to n_limit do
    idastar a limit space lower
  done

Measured memory_bytes: 4500
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
int N;
vector<int> p;
set<ll> ans;

ll lcm(ll a, ll b) {
  ll c = a * b;
  if (a < b)swap(a,b);
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

void solve(int index,ll lcm_value=-1){
  if(index==N){
    if(lcm_value!=-1)ans.insert(lcm_value);
    return;
  }
  solve(index+1,lcm_value);
  if(lcm_value==-1)
    lcm_value=p[index];
  lcm_value=lcm(lcm_value,p[index]);
  solve(index+1,lcm_value);  
  return;
}

int main(){
  cin >> N;
  for(int i=0;i<N;++i){
    int temp;
    cin >> temp;
    p.push_back(temp);
  }
  solve(0);
  cout << ans.size() << endl;
}


Measured memory_bytes: 4068
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long count = 0, ans = 0;
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'W') {
			ans += i - count;
			count++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int c1,c2,p1 = 0,p2 = 0;
  while(scanf("%d",&n)){
    if(n == 0)break;
    p1 = p2 = 0;
    while(n--){
      scanf("%d %d",&c1,&c2);
      if(c1 > c2)p1 += c1+c2;
      else if(c1 < c2)p2 += c1+c2;
      else{
	p1 += c1;
	p2 += c2;
      }
    }
    printf("%d %d\n",p1,p2);
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<char,int> CI;

//const int dy[] = {-1, 0, 1, 0 };
//const int dx[] = { 0, 1, 0,-1 }; 
const int dy[] = { 1, 0, -1, 0 };
const int dx[] = { 0, 1,  0,-1 };
bool c[25][25];

int main()
{
//	cut here before submit 
//	freopen ("testcase.MG", "r", stdin );
	map<char,int> dir; dir.clear();
	dir['N'] = 0; dir['E'] = 1; dir['S'] = 2; dir['W'] = 3;

	int n;
	while (scanf ("%d", &n ), n ){
		memset (c, false, sizeof (c ) );
		rep (i, n ){
			int jx,jy;
			scanf ("%d %d", &jx, &jy );
			c[jy][jx] = true;
		} // end rep
		int m;
		scanf ("%d", &m );
		vector<CI> com(m );
		rep (i, m ){
			char d; int len;
			scanf (" %c %d", &d, &len );
			com[i].first  = d;
			com[i].second = len;
		} // end rep
		int cx = 10, cy = 10;
		rep (i, m ){
			char  d = com[i].first;
			int len = com[i].second;
			rep (j, len ){	
				cx += dx[dir[d]];
				cy += dy[dir[d]];
				c[cy][cx] = false;
			} // end rep
		} // end rep

		bool ok = true;
		rep (i, 25) rep (j, 25 )
			if (c[i][j] ){ ok = false; break; }
		
		if (ok ){
			printf ("Yes\n" );
		}else{
			printf ("No\n" );
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <tuple>
using namespace std;
int numd(int x)
{
	int ans = 0;
	while(x)
	{
		ans++;
		x=x/10;
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int i,n;
	cin>>n;
	int ans = 0;
	for(i=1;i<=n;i++)
	{
		int nd = numd(i);
		if(nd%2)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: usize,
    }
    let mut table = vec![true; 2 * x];
    for i in 2..x {
        for j in (i..2 * x).step_by(i).filter(|j| *j >= x) {
            table[j] = false;
        }
    }
    println!("{}", (x..2 * x).find(|i| table[*i]).unwrap());
}


Measured memory_bytes: 2272