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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> to(N, vector<int>());
  for (int i = 0; i < M; ++i) {
    int s, t;
    cin >> s >> t;
    --s, --t;
    to[s].push_back(t);
  }
  vector<double> dp(N, 0);
  for (int i = N - 2; i >= 0; --i) {
    for (int j : to[i]) {
      dp[i] += dp[j];
    }
    dp[i] /= to[i].size();
    ++dp[i];
  }
  double ans = dp[0];
  for (int i = 0; i < N - 1; ++i) {
    if (to[i].size() == 1) continue;
    int taken = -1;
    for (int j : to[i]) if (taken == -1 || dp[taken] < dp[j]) taken = j;
    double now = [&]() {
      dp[N - 1] = 0;
      for (int u = N - 2; u >= 0; --u) {
        dp[u] = 0;
        for (int v : to[u]) {
          if (u == i && v == taken) continue;
          dp[u] += dp[v];
        }
        double deg = to[u].size();
        if (u == i) --deg;
        dp[u] /= deg;
        ++dp[u];
      }
      return dp[0];
    }();
    ans = min(ans, now);
  }
  printf("%.10f\n", ans);
}


Measured memory_bytes: 1408
H, W = map(int, input().split())
S = [None for _ in range(H)]
for i in range(H):
  S[i] = list(input().split())
for i in range(H):
  for j in range(W):
    if S[i][j] == 'snuke':
      print(chr(ord('A')+j)+str(i+1))
      exit()

Measured memory_bytes: 9060
N = int(input())
h_arr = list(map(int, input().split(" ")))
dp = [9999999 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h_arr[1]-h_arr[0])

for i in range(2, N):
	dp[i] = min(abs(h_arr[i]-h_arr[i-1]) + dp[i-1], abs(h_arr[i]-h_arr[i-2]) + dp[i-2])
		
print(dp[-1])

Measured memory_bytes: 13924
fn main() {
    let mut sc = Scanner::new();
    let s: Vec<char> = sc.read::<String>().chars().collect();
    let n = s.len();
    if s[0] != s[n - 1] {
        if n % 2 == 0 {
            println!("Second");
        } else {
            println!("First");
        }
    } else {
        if n % 2 != 0 {
            println!("Second");
        } else {
            println!("First");
        }
    }
}

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

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

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

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

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

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

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

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

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


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
bool v[100][100],used[100],used2[100];
int V,E;

bool dfs(int p){
  if(used[p])return 1;
  if(used2[p])return 0;
  used2[p]=1;

  for(int i=0;i<V;i++){
    if(v[p][i]){
      used[p]=1;
      if(dfs(i))return 1;
      used[p]=0;
    }
  }
  return 0;
}

int main(){
  cin>>V>>E;
  for(int i=0,s,t;i<E;i++){
    cin>>s>>t;
    v[s][t]=1;
  }
  for(int i=0;i<V;i++){
    if(!used2[i]&&dfs(i)){cout<<1<<endl;return 0;}
  }
  cout<<0<<endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    for(int rep=0; rep<n; rep++){
        int g[5][5];
        for(int i=0; i<5; i++){
            for(int j=0; j<5; j++){
                cin >> g[i][j];
            }
        }
        int ans = 0;
        for(int i=0; i<5; i++){
            for(int j=i; j<5; j++){
                for(int k=0; k<5; k++){
                    for(int l=k; l<5; l++){
                        int count = 0;
                        for(int x=i; x<=j; x++){
                            for(int y=k; y<=l; y++){
                                if(g[x][y] == 1) count++;
                            }
                        }
                        if(count == (j-i+1)*(l-k+1)){
                            ans = max(ans, count);
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const double eps = 1e-10;
int dcmp(double x) { if(fabs(x) < eps) return 0; else return x<0?-1:1; }
const int N = 1e5+5;
const ll MOD = 1e9+7;

int a[N], vis[N];
ll c[N], c0[N], fac[N];

ll quick_pow(ll a, ll b) {
    ll ret = 1;
    while(b) {
        if(b & 1) ret = ret*a%MOD;
        a = a*a%MOD;
        b >>= 1;
    }
    return ret;
}

int main() {
    memset(vis, 0, sizeof(vis));
    memset(c, 0, sizeof(c));
    memset(c0, 0, sizeof(c0));
    int n, l, r;
    scanf("%d", &n);
    for(int i = 0; i <= n; i++) {
        scanf("%d", &a[i]);
        vis[a[i]]++;
        if(vis[a[i]] == 2) r = i;
    }
    for(int i = 0; i <= n; i++) {
        if(vis[a[i]] == 2) {
            l = i;
            break;
        }
    }

    l = n-r+l;
    fac[0] = 1;
    for(int i = 1; i <= n+1; i++) fac[i] = fac[i-1]*(ll)i%MOD;
    for(int i = 0; i <= l; i++) c[i] = fac[l]*quick_pow(fac[i]*fac[l-i]%MOD, MOD-2)%MOD;
    for(int i = 0; i <= n+1; i++) c0[i] = fac[n+1]*quick_pow(fac[i]*fac[n+1-i]%MOD, MOD-2)%MOD;
    for(int i = 1; i <= n+1; i++) {
        printf("%lld\n", (c0[i]-c[i-1]+MOD)%MOD);
    }
    return 0;
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        int[] a = Read.ints();
        Console.WriteLine(Math.Max(0,a[0]-a[1]));
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b)
    {
        return a / gcd(a, b) * b;
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

        for (long i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] longs()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 13268
n = int(input())
d = {}
for i in range(26):
    d[chr(i+97)] = []

for i in range(n):
    s = input()
    char_set = set(list(s))
    for c in char_set:
        d[c].append(s.count(c))

ans = ""
for i in range(26):
    c = chr(i+97)
    if len(d[c]) == n:
        ans += c*min(d[c])
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n;
  n = s.length();
  int ans = 100000;

  for(int i = 0; i <= n-3; i++){
    int a = s[i] - '0';
    int b = s[i+1] - '0';
    int c = s[i+2] - '0';
    int x = 100*a + 10*b + c;
    ans = min(ans, abs(753-x));
  }
  cout << ans << endl;

}


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

int main()
{
    int X, Y, A, B, C, a = 0, b = 0, c = 1;
    unsigned long long int sum = 0;
    bool a_ = true, b_ = true;
    cin >> X >> Y >> A >> B >> C;

    vector<unsigned long long int> p(A), q(B), r(C);

    rep(i, A)
    {
        cin >> p.at(i);
    }
    rep(i, B)
    {
        cin >> q.at(i);
    }
    rep(i, C)
    {
        cin >> r.at(i);
    }

    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    sort(r.begin(), r.end());

    rep(i, C)
    {
        if (C - c >= 0)
        {
            if (p.at(A - X + a) > q.at(B - Y + b) && b_ == true)
            {
                if (q.at(B - Y + b) < r.at(C - c))
                {
                    q.at(B - Y + b) = r.at(C - c);
                    b++;
                    c++;
                    if (B - Y + b == B)
                    {
                        b--;
                        b_ = false;
                    }
                }
            }
            else if (p.at(A - X + a) <= q.at(B - Y + b) && a_ == true)
            {
                if (p.at(A - X + a) < r.at(C - c))
                {
                    p.at(A - X + a) = r.at(C - c);
                    a++;
                    c++;
                    if (A - X + a == A)
                    {
                        a--;
                        a_ = false;
                    }
                }
            }
        }
    }

    rep(i, X)
    {
        sum += p.at(A - i - 1);
    }

    rep(i, Y)
    {
        sum += q.at(B - i - 1);
    }

    cout << sum << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////

int main() {
	int N, M;
	int k[31];
	int A[31][31];
	cin >> N >> M;
	int count[31];
	for (int i = 0; i < 31; ++i) {
		count[i] = 0;
	}
	for (int i = 0; i < N; ++i) {
		cin >> k[i];
		for (int j = 0; j < k[i]; ++j) {
			cin >> A[i][j];
			count[A[i][j]]++;
		}
	}
	int ans = 0;
	for (int i = 1; i <= M; ++i) {
		if (count[i] == N) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int getDigits(ll num) { return to_string(num).length(); }

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

  ll n;
  cin >> n;

  ll a;
  ll b;
  for (int i = sqrt(n); i > 0; i--) {
    if (n % i == 0) {
      a = i;
      b = n / i;
      break;
    }
  }

  int ans = max(getDigits(a), getDigits(b));

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
///////////////////////////////////////////////
int main(){
	int N; SCD(N);
	int W; SCD(W);
	static int w[100002] = {};
	static ll v[100002] = {};

	FORq(i,1,N){
		SCD(w[i]);
		SCLLD(v[i]);
	}

	static ll dp[101][100002] = {};

	FORq(i,1,N){
		FORq(j,0,W){
			if (j < w[i]) dp[i][j] = dp[i-1][j];
			else dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]] + v[i]);
		}
	}

	PRINTLLD(dp[N][W]);
}


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

#define INF 1234567890
#define ll long long

int N, K, Q;
int X[200201];
int L[20][200201], R[20][200201]; //
ll LS[20][200201], RS[20][200201]; //
// LS[i][j] : j를 포함해서 만나는 2^i개의 정점의 번호 합

int main()
{
	scanf("%d %d", &N, &K);
	for(int i=1; i<=N; i++)
		scanf("%d", &X[i]);

	// L[] 채우기
	map<int, int> m;
	for(int i=1; i<=N; i++)
	{
		m[X[i]] = i;
		auto it = m.upper_bound(X[i]-K);
		if (it == m.begin()) continue;
		
		it = prev(it);
		L[0][i] = it->second;
	}

	m.clear();
	for(int i=N; i>=1; i--)
	{
		m[X[i]] = i;
		auto it = m.lower_bound(X[i]+K);
		if (it == m.end()) continue;

		R[0][i] = it->second;
	}

	for(int i=1; i<=N; i++)
		LS[0][i] = RS[0][i] = i;

	for(int i=1; i<20; i++)
		for(int j=1; j<=N; j++)
		{
			L[i][j] = L[i-1][L[i-1][j]];
			R[i][j] = R[i-1][R[i-1][j]];
			LS[i][j] = LS[i-1][j] + LS[i-1][L[i-1][j]];
			RS[i][j] = RS[i-1][j] + RS[i-1][R[i-1][j]];
		}

	scanf("%d", &Q);
	while(Q--)
	{
		int l, r;
		scanf("%d %d", &l, &r);
		ll ls = 0, rs = 0, cnt = 0;

		int n = r;
		for(int i=19; i>=0; i--)
			if (L[i][n] != 0 && l <= L[i][n])
				rs += LS[i][n], n = L[i][n], cnt += (1<<i);
		rs += LS[0][n]; cnt++;

		n = l;
		for(int i=19; i>=0; i--)
			if (R[i][n] != 0 && R[i][n] <= r)
				ls += RS[i][n], n = R[i][n];
		ls += RS[0][n];

		//printf("%lld, %lld, %lld : ", rs, ls, cnt);
		printf("%lld\n", rs-ls+cnt);
	}
	return 0;
}

Measured memory_bytes: 107764
program noguchi_maisu
    integer n
    integer :: a = 0
    read *, n
    if(mod(n, 1000) == 0)then
        a = mod(n, 1000)
        print *, a
    else
        a = (n/1000 + 1)*1000-n
        print *, a
    end if
end program

Measured memory_bytes: 2828
import math

def digit_sum(x, y):
    if x < y:
        return x
    else:
        return digit_sum(math.floor(x/y), y) + (x % y)

n, a, b = map(int, raw_input().split())
ans = 0

for i in range(1, n + 1):
    if a <= digit_sum(i, 10) <= b:
        ans += i

print ans

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

int main() {
	char in1, in2, in3, in4;
	cin >> in1 >> in2 >> in3 >> in4;
	
	int flag=0;
	//文字が同じか判定
	if (in1 == in2) {
		if (in3 == in4&&in1!=in3){
			flag = 1;
			}
	}
	else if (in1 == in3) {
		if (in2 == in4) {
			flag = 1;
		}
	}
	else if (in1 == in4) {
		if (in2 == in3) {
			flag = 1;
		}
	}

	if (flag == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

ll x,y;

void input(){
    cin >> x >> y;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int cnt = 0;
    ll a = x;
    while(a <= y){
        a = a * 2;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
namespace LCY{
	#define double long double
	const double EPS=1e-10;
	inline int dcmp(double x){if(fabs(x)<EPS)return 0;return (x<0)?-1:1;}
	struct Point{double x,y;Point(double _x=0,double _y=0){x=_x;y=_y;}};
	struct Vector{double x,y;Vector(double _x=0,double _y=0){x=_x;y=_y;}};
	
	Vector operator - (Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
	Vector operator * (Vector a,double d){return Vector(a.x*d,a.y*d);}
	Point operator + (Point a,Vector b){return Point(a.x+b.x,a.y+b.y);}
	
	inline double dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
	inline double cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
	inline double norm(Vector a){return dot(a,a);}
	
	struct Line{
		Point p1,p2;
		Line(Point _p1=Point(0,0),Point _p2=Point(0,0)){p1=_p1;p2=_p2;}
	};
	
	Point project(Line l,Point p){
		Vector base=l.p2-l.p1;
		double r=dot(p-l.p1,base)/norm(base);
		return l.p1+base*r;
	}
}
using namespace LCY;
int main(){
	Point p1,p2;cin>>p1.x>>p1.y>>p2.x>>p2.y;
	int n;cin>>n;while(n--){
		Point q;cin>>q.x>>q.y;Point res=project(Line(p1,p2),q);
		cout<<setiosflags(ios::fixed)<<setprecision(10)<<res.x<<" "<<res.y<<endl;
	}
	return 0;
}


Measured memory_bytes: 3300
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }
 
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int W, H, N; 
int b[16], k[16];
int s[10][10];
int ans[10][10];
int used[10][10];
int TX[20], TY[20];
class DFSError {};
void dfs(int idx){
  if(idx == N) {
    if(ans[0][0] != -1) throw DFSError();
    REP(y, H)REP(x, W) ans[y][x] = used[y][x];
    return;
  }
  /*
  printf("idx = %d\n", idx);
  REP(y, H){
    REP(x, W){
      cout << used[y][x];
      if(x != W - 1) cout << " ";
      else cout << endl;
    }
  }
  */
  int tx = TX[b[idx] - 1];
  int ty = TY[b[idx] - 1];
  //printf("idx = %d tx = %d ty = %d\n", idx, tx, ty);
   
  assert(idx < N);
  assert(b[idx] >= 1 && b[idx] <= N);
  assert(tx != -1);
  for(int h = 1; h <= k[idx]; h++) if(k[idx] % h == 0){
    int w = k[idx] / h;
    for(int by = 0; by > -h; by--) for(int bx = 0; bx > -w; bx--){
      int sx = tx + bx;
      int sy = ty + by;
      bool ok = true;
      for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) {
        if(!valid(sx + x, sy + y, W, H) || used[sy + y][sx + x] != -1) ok = false;
      }
      if(ok){
        int tmp[10][10];
        memcpy(tmp, used, sizeof(used));
        for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) {
          used[sy + y][sx + x] = b[idx];
        }
        dfs(idx + 1);
        memcpy(used, tmp, sizeof(used));
      }
    }
  }
}
 
int main(){
  while(cin >> W >> H >> N && (W | H | N)){
    REP(i, N) cin >> b[i] >> k[i];
    REP(y, H)REP(x, W) cin >> s[y][x];
    try{
      memset(used, -1, sizeof(used));
      memset(ans, -1, sizeof(ans));
      memset(TX, -1, sizeof(TX));
      memset(TY, -1, sizeof(TY));
      REP(y, H) REP(x, W) if(s[y][x] > 0) TX[s[y][x] - 1] = x, TY[s[y][x] - 1] = y;
      REP(i, N)if(TX[i] == -1){
        /*
        cerr << W << " " << H << " " << N << endl;
        REP(j, N) cerr << b[j] << " " << k[j] << endl;
        REP(y, H) { REP(x, W) cerr << s[y][x] << " "; cerr << endl; }
        assert("bord is dissapeared" == "");
        */
        throw 0;
      }
      dfs(0);
      if(ans[0][0] == -1) throw DFSError();
      REP(y, H){
        REP(x, W){
          cout << ans[y][x];
          if(x != W - 1) cout << " ";
          else cout << endl;
        }
      }
    }catch(...){
      cout << "NA" << endl;
    }
  }
  return 0;
}


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

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    double x = 1., y = 0;
    int n;

    scanf ( "%d", &n );
    if ( n == -1 )  break ;

    while ( --n )
    {
      const double th = atan2 ( y, x ) + M_PI / 2.;
      x += cos ( th );
      y += sin ( th );
    }

    printf ( "%.2f\n%.2f\n", x, y );
  }

  return ( 0 );
}

Measured memory_bytes: 0
# def f(P):
#     """与えられたPのときに、運べる荷物の数vを返す関数"""
#     i = 0  # 荷物の番号
#     v = 0  # 運べる荷物の数
#     k = 0  # トラックの番号
#     current_weight = 0  # 現在のトラックの重さ
#     # current_v = 0  # 現在のトラックに積まれている荷物の数
#
#     while True:
#         # print(i, v, k)
#
#         if W[i] > P:
#             i += 1
#         else:
#             current_weight += W[i]
#
#             if current_weight > P:
#                 k += 1
#             elif current_weight == P:
#                 i += 1
#                 v += 1
#                 k += 1
#             else:  # current_weight < P:
#                 i += 1
#                 v += 1
#
#         if i == N or k == K:
#             break
#     return v

def f(P):
    i = 0
    for k in range(K):
        current_weight = 0
        while current_weight + W[i] <= P:
            current_weight += W[i]
            i += 1
            if i == N:
                return N

    return i


def solve_binary():
    left = 0
    right = max(W)  # ではない！これだとトラックが足りなくて積み切れない場合がある。
    right = 100000 * 10000

    while (right - left) > 1:  # つまり、これが境目の証！！！
        mid = (left + right) // 2
        mid_v = f(mid)

        if mid_v >= N:
            right = mid
        elif mid_v < N:
            left = mid

    return right


def solve_linear():
    p = 1
    while True:
        v = f(p)
        # print(p, v, N)

        if v == N:
            # print(p)
            return p

        p = p + 1


N, K = map(int, input().split())
# W = list(map(int, input().split()))
W = [int(input()) for _ in range(N)]
# print(n, k, W)

# print(solve_linear())
print(solve_binary())



Measured memory_bytes: 9576
import math

A, B, H, M = map(int, input().split())

m = H*60+M

ch = math.radians(m*360/720)
hx, hy = A*math.cos(ch), A*math.sin(ch)
cm = math.radians(M*6)
mx, my = B*math.cos(cm), B*math.sin(cm)

ans = pow(pow(hx-mx, 2) + pow(hy-my, 2), 0.5)
print(ans)

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

using namespace std;

int main()
{
    string s1;
    cin >> s1;
    int x=0;
    int i;
    for(i=0;i<4;i++){
      if(s1[i] == '+')  x++;
      else  x--;
    }
    cout << x << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;



public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		boolean[][] path =new boolean[N][N];
		for(int i=0;i<N;i++) for(int j=0;j<N;j++) path[i][j]=false;
		for(int i=0;i<M;i++){	//隣接行列の受け取り
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			path[(a-1)][(b-1)] = true;
			path[(b-1)][(a-1)] = true;
		}
		
		boolean[] position = new boolean[N];//訪問済みならtrue
		position[0]=true;
		for(int i = 1; i<N;i++) position[i]=false;//初期化;
		
		int cnt = Search(N, 0, position, path);
		
		System.out.println(cnt);
		sc.close();
	}

	public static int Search(int N, int NowPos, boolean[] PastPos, boolean[][] path){
		int cnt=0;
		boolean all_visited = true;//全て訪問済みならtrue
		for(boolean Posi: PastPos) all_visited = (all_visited && Posi);
		
		
		if(all_visited)	cnt=1;
		for(int j=1;j<N;j++){
			boolean[] NewPos = new boolean[N];
			for(int i=0;i<N;i++) NewPos[i]=PastPos[i];
			if((!PastPos[j])&&path[NowPos][j]){
				NewPos[j]=true;
				//for(int k=0;k<N; k++)System.out.println(NewPos[k]);
				//System.out.println("is NewPos.");
				cnt+=Search(N,j,NewPos,path);
			}
		}
		return cnt;
	}
}


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

int main(){
    //input
    int n,k;
    cin >> n >> k;

    double sum = 0;
    for(int i=1;i<=n;i++){
        double t = 1.0 / n;
        int j;
        for(j=0;i*pow(2,j)<k;j++){
            t /= 2;
        }
        sum += t;
    }

    printf("%.16f",sum);

    return 0;
}

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

int main() {
    int n, temp, h, cx, cy;
    cin >> n;
    vector<vector<int>> info(n, vector<int>(3));
    rep(i, n) {
        cin >> info.at(i).at(0) >> info.at(i).at(1) >> info.at(i).at(2);
        if(info.at(i).at(2)) temp = i;
    }
    rep(i, 101) rep(j, 101) {
        int height = info.at(temp).at(2) + abs(i - info.at(temp).at(0)) + abs(j - info.at(temp).at(1));
        bool flag = true;
        rep(k, n) if(info.at(k).at(2) != max(0, height - abs(i - info.at(k).at(0)) - abs(j - info.at(k).at(1)))) flag = false;
        if(flag) {
            cx = i;
            cy = j;
            h = height;
        }
    }
    cout << cx << " " << cy << " " << h << endl;
}

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

//template
#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 ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

int mod=1e9+7;
struct Mint {
    int val;
    Mint inv() const{
        int tmp,a=val,b=mod,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return Mint(x);
    }
public:
    Mint():val(0){}
    Mint(ll x){if((val=x%mod)<0)val+=mod;}
    Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
    Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
    Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
    Mint& operator/=(const Mint& x){return *this*=x.inv();}
    Mint operator+(const Mint& x) const{return Mint(*this)+=x;}
    Mint operator-(const Mint& x) const{return Mint(*this)-=x;}
    Mint operator*(const Mint& x) const{return Mint(*this)*=x;}
    Mint operator/(const Mint& x) const{return Mint(*this)/=x;}
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx){
        Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
    }
    Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
    Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
    Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

Mint pre[62];

int main(){
    int n; scanf("%d",&n);
    vector<ll> a(n); pre[0]=1;
    rep(i,0,61)pre[i+1]=pre[i]*2;
    rep(i,0,n)scanf("%lld",&a[i]);
    int cnt[62]={};
    rep(i,0,n)rep(j,0,61)if(a[i]>>j&1)cnt[j]++;
    Mint ans;
    rep(i,0,n){
        int cnt2[62];
        rep(j,0,62)cnt2[j]=cnt[j];
        rep(j,0,62){
            if(a[i]>>j&1){
                ans+=pre[j]*Mint(n-cnt2[j]);
            }
            else ans+=pre[j]*Mint(cnt2[j]);
        }
    } ans/=2;
    printf("%d\n",ans.val);
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;

typedef long long ll;

int cnt;
int l;
int arr[10000000];
int n;
vector<int> G;

void insertionSort(int arr[], int g) {
    FOR(i, g, n) {
        int v = arr[i];
        int j = i - g;
        while (j >= 0 && arr[j] > v) {
            arr[j+g] = arr[j];
            j -= g;
            ++cnt;
        }
        arr[j+g] = v;
    }
}

void shellSort(int arr[]) {
    // 数列生成
    int h = 1;
    while(h <= n) {
        G.push_back(h);
        h = 3*h + 1;
    }

    // 逆順にG[i] = gを指定
    REPR(i, G.size() - 1) {
        insertionSort(arr, G[i]);
    }
}

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

    REP(i, n) cin >> arr[i];
    cnt = 0;

    shellSort(arr);

    int size = G.size();
    cout << size << endl;
    REPR(i, size - 1) {
        cout << G[i];
        if (i) cout << " ";
    }
    cout << "\n";
    cout << cnt << "\n";
    REP(i, n) cout << arr[i] << "\n";
}


Measured memory_bytes: 7080
H, W = map(int,input().split())
S = []
for _ in range(H):
    S.append(input())

ans = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ans[i][j] = "#"
            if j-1 >= 0 and ans[i][j-1] != "#":
                ans[i][j-1] += 1
            if j-1 >= 0 and i-1 >= 0 and ans[i-1][j-1] != "#":
                ans[i-1][j-1] += 1
            if j-1 >= 0 and i+1 <= H-1 and ans[i+1][j-1] != "#":
                ans[i+1][j-1] += 1

            if i-1 >= 0 and ans[i-1][j] != "#":
                ans[i-1][j] += 1
            if i+1 <= H-1 and ans[i+1][j] != "#":
                ans[i+1][j] += 1
            
            if j+1 <= W-1 and ans[i][j+1] != "#":
                ans[i][j+1] += 1
            if j+1 <= W-1 and i-1 >= 0 and ans[i-1][j+1] != "#":
                ans[i-1][j+1] += 1
            if j+1 <= W-1 and i+1 <= H-1 and ans[i+1][j+1] != "#":
                ans[i+1][j+1] += 1                        

for i in range(H):
    print(''.join(map(str,ans[i])))

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

int main(){
    int n;
    cin >> n;
    string s;
    map<string,int> mp;
    int cnt = 0;
    for (int i = 0;i < n;i++){
        cin >> s;
        if (mp[s] == 0){
            cnt++;
            mp[s]++;
        }
    }
    if (cnt == 3){
        cout << "Three" << endl;
    }
    else{
        cout << "Four" << endl;
    }

}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

string calc(string s,lli left,lli right){
	return s.substr(0,left)+s.substr(right);
}

signed main(){

	string s;
	cin>>s;

	string t = "keyence";

	lli nowCnt = 0;
	lli now = 0;
	if(s==t){
		cout<<"YES"<<endl;
		return 0;
	}
	REP(i,0,s.size()){
		REP(j,i+1,s.size()){
			if(t == calc(s,i,j)){
				cout<<"YES"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define array(N,t) (t*)calloc(N,sizeof(t))
typedef long long LL;
inline LL IN(void)
{
  LL x=0;short f=0,c=getchar();
  while(c<48||c>57)f^=c==45,c=getchar();
  while(c>47&&c<58)x=x*10+c-48,c=getchar();
  return f?-x:x;
}
signed main(void)
{
  int N=IN(),i,j,p;LL K=IN();
  int *A=array(N,int),*town=array(N,int);
  for(i=0;i<N;i++)A[i]=IN(),town[i]=-1;
  for(i=0,j=0;;i=A[i]-1,j++)if(town[i]<0)town[i]=j;else break;
  for(p=0;K>0;p=A[p]-1,K--)if(i==p){K%=town[i]-j;if(!K)break;}
  free(A),free(town);
  return printf("%d\n",p+1),0;
}

Measured memory_bytes: 2924
#include<stdio.h>
 
int main()
{
    int i, j = 0, seisu[10000], max = -10000000, min = 10000000, num;
    long int sum = 0;
    scanf("%d", &i);
 
    while(j != i)
    {
        scanf("%d", &seisu[j]);
 
        j++;
    }
 
    j = 0;
 
    for(j=0; j<i; j++)
    {
        num = seisu[j];
 
        if(max < num)
        {
            max = num;
        }
         
        if(min > num)
        {
            min = num;
        }
 
        sum = sum + num;
    }
 
    printf("%d %d %ld\n", min, max, sum);
 
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#define N 10000

int main(){
  int i ,j ,m ,l ,a=0 ,b=0 ,c=0 ,n[N];
  double v;

  scanf("%d",&m);

  for(i=0;i<m;i++){
    scanf("%d",&n[i]);
    if(n[i]==2 || n[i]==3 || n[i]==5) b++;
    else {
      v=n[i];
      v=sqrt(v);
      for(j=2;j<=v;j++){ 
	if(n[i]%2==0) break;
	c++;
	if(n[i]%j==0) a++;
      }
      if(c!=0 && a==0) b++;
      a=0;
      c=0;
    }
  }
   
  printf("%d\n" ,b);

  return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>
#include<math.h>
int main(void) {
double a,b,c,d;
double e;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
e=(a-c)*(a-c)+(b-d)*(b-d);
e=sqrt(e);
printf("%f",e);
  return 0;
}



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

const int inf = 1e9+7;
int a[1007];
int n;
long long ans;

int main(){
	
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 2;i<=n;i++){
		int x = i;
		for(int j = 2;j<=sqrt(n);j++){
			while(x%j==0){
				a[j]++;
				x/=j;
			}
		}
		if(x>1) a[x]++;
	}
	ans = 1;
	for(int i = 2;i<=n;i++){
		if(a[i]){
			ans*=(a[i]+1)%inf;
			ans%=inf;
		}
	}
	cout << ans;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         // if (siz[rx] < siz[ry]) swap(rx,ry);
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

int main(void) {
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double theta = abs(0.5*(60*H+M)-6.0*M);
    cout << fixed << setprecision(15) << sqrt(A*A+B*B-2.0*A*B*cos(M_PI*min(theta,360-theta)/180.0)) << endl;

    return 0;
}


Measured memory_bytes: 4188
from itertools import permutations as perm
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

comb = list(perm(range(1, N+1)))
def find(x):
    for i, n in enumerate(comb):
        if x == n:
            return i
a = find(P)
b = find(Q)
ans = abs(a - b)
print(ans)

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

typedef long long ll;

template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

int main()
{
  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL), vb(N, 0LL), vc(N, 0LL);
  for (ll i = 0; i < N;   i++) { std::cin >> va[i]; }
  for (ll i = 0; i < N;   i++) { std::cin >> vb[i]; }
  for (ll i = 0; i < N-1; i++) { std::cin >> vc[i]; }

  ll pre = 9999;
  ll sum = 0LL;
  for (ll i = 0; i < N; i++) {
    ll idx = va[i] - 1;
    sum += vb[idx];
    if (pre + 1 == idx) sum += vc[pre];
    pre = idx;
  }

  print(sum);
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
mon=1000
kai=0
for i in range(n-1):
  if a[i]>a[i+1]:
    mon+=kai*a[i]
    kai=0
  elif a[i]<a[i+1] and kai==0:
    kai=int(mon/a[i])
    mon-=kai*a[i]

mon+=kai*a[n-1]

print(mon)


Measured memory_bytes: 9120
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int K = Integer.parseInt(sc.next());
		int S = Integer.parseInt(sc.next());
		int ans = 0;
		for(int x=0; x<=K; x++){
			for(int y=0; y<=K; y++){
				int z = S-(x+y);
				if(z>=0 && z<=K)ans++;
			}
		}
		System.out.println(ans);
		sc.close();
	}
	
}


Measured memory_bytes: 23508
#include<cstdio>
#include<ctype.h>
using namespace std;
int n,cnt2,cnt5;
long long b[200005],cnt[35][35],ans,nown;
inline long long get_lf()
{
	long long x=0,pp=100000000LL;
	char c;
	for(c=getchar();!isdigit(c);c=getchar());
	for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+c-'0';
	x*=1000000000LL;
	if(c=='.') for(c=getchar();isdigit(c);c=getchar(),pp/=10LL) x=x+(c-'0')*pp;
	return x;
}
int main() {
	scanf("%d",&n);nown=(long long)n;for(int i=1;i<=n;++i) b[i]=get_lf();
	for(int i=1;i<=n;++i) {
		if(!b[i]) {ans+=(2LL)*(nown-1LL);nown--;continue;}
		cnt2=0;cnt5=0;
		while(!(b[i]%2)) {
			b[i]/=2;cnt2++;
		}
		while(!(b[i]%5)) {
			b[i]/=5;cnt5++;
		}
		cnt[cnt2>18?18:cnt2][cnt5>18?18:cnt5]++;
	}
	for(int i=0;i<=18;++i)
		for(int j=0;j<=18;++j)
			for(int k=0;k<=18;++k)
				for(int h=0;h<=18;++h) {
					if(i==k&&j==h&&i>=9&&j>=9) {
						ans+=cnt[i][j]*(cnt[i][j]-1LL);
						continue;
					}
					if(i+k>=18&&j+h>=18)
						ans+=cnt[i][j]*cnt[k][h];
				}
	printf("%lld",ans/(2LL));				
	return 0;
}

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

typedef long long ll;

vector<pair<ll, int>> factor(ll x) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= x; i++) {
    int cnt = 0;
    while (x % i == 0) x /= i, cnt++;
    if (cnt) res.emplace_back(i, cnt);
  }
  if (x != 1) res.emplace_back(x, 1);
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, int>> fs = factor(n);
  int ans = 0;
  for (pair<ll, int> p : fs) {
    // cout << p[i].first << ' ' << p[i].second << endl;
    int b = 1;
    int x = p.second;
    while (x >= b) {
      x -= b;
      b++;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

readString = map BS.unpack . BS.words

getIntList = readIntList <$> BS.getLine

getString = readString <$> BS.getLine

main = do
  [s, t] <- getString
  [a, b] <- getIntList
  [u] <- getString
  let abs
        | u == s = [a -1, b]
        | u == t = [a, b -1]
  mapM_ putStr (map (\x -> show x ++ " ") abs)


Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
	cin>>a;b=a;
	reverse(b.begin(),b.end());
	for(int i=0;i<b.size();i++)
	{
		if(b[i]=='b') b[i]='d';
		else if(b[i]=='d') b[i]='b';
		else if(b[i]=='q') b[i]='p';
		else b[i]='q';
	}
	if(a==b) cout<<"Yes";
	else cout<<"No";
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int X;
signed main() {
    cin >> X;
    long double cur = 100;
    int ans = 0;
    while (cur < X) { cur = floor(cur * 1.01), ans++; }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int a[100005];
int b[100005],c[100005];
ll ans;
int main(void){
	cin>>n>>m;
	map<ll,ll> M;
	for(int i=0;i<n;i++){
		cin>>a[i];
		M[a[i]]++;
	}
	for(int i=0;i<m;i++){
		cin>>b[i]>>c[i];
		M[c[i]]+=b[i];
	}
	map<ll,ll>::iterator ite;
	ite=M.end();
	ite--;
	//cout<<n<<" "<<ite->second<<endl;
	while(true){
		if(n>=ite->second){
			ans=ans+ite->second*ite->first;
			n=n-ite->second;
			//cout<<ans<<" "<<n<<endl;
		}else{
			ans=ans+n*ite->first;
			n=0;
			//cout<<ans<<" "<<n<<endl;
		}
		if(n==0){
			cout<<ans<<endl;
			return 0;
		}
		ite--;
	}
	
	
}


Measured memory_bytes: 15744
/*
created on 21/4/2020
*/
#include<bits/stdc++.h>
using namespace std;
#define Endl '\n'
typedef long long int lli;
void solve();
int main(int argc, char const *argv[]){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
int const maxlen = (1e5) + 5;
int dp[maxlen];
int N, M;
bool visited[maxlen];
vector<int> adjList[maxlen];
void dfs(int u){
  visited[u] = true;
  for(int v: adjList[u]){
    if(visited[v] ==false)
      dfs(v);

    dp[u] = max(dp[u], 1 + dp[v]);
  }
}

void solve(){
  cin>>N>>M;
  for(int i=0;i<M;i++){
    int xi, yi;
    cin>>xi>>yi;
    adjList[xi].push_back(yi);
  }
  for(int i=1;i<=N;i++){
    if(visited[i] == false)
      dfs(i);
  }
  int ans = *max_element(dp, dp+maxlen);
  cout<<ans<<Endl;
}


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

int main(){
	int n,ans;

	while( cin >> n ){
		ans = 0;
		if(n<=36){
			for(int a=0 ; a<=9 ; a++){
				for(int b=0 ; b<=9 ; b++){
					for(int c=0 ; c<=9 ; c++){
						for(int d=0 ; d<=9 ; d++){
							if((a+b+c+d)==n){
								ans++;
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}  

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define translow transform(s.begin(),s.end(),s.begin(),::tolower);
#define transup transform(s.begin(),s.end(),s.begin(),::toupper);
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;
 
 
int main() {
				fast
                // #ifndef ONLINE_JUDGE
                // freopen("input.txt","r",stdin);
                // freopen("output.txt","w",stdout);
                // #endif

              ll n,m;
              cin>>n>>m;
              ll x=(n*(n-1))/2;
              ll y=(m*(m-1))/2;
              cout<<x+y;
                return 0;
            }

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

int main()
{
  string s;
  vector<bool> c(26, true);
  bool flag = true;

  cin >> s;
  for (int i = 0; i < s.size(); i++)
    c[s[i] - 'a'] = !c[s[i] - 'a'];
  for (int i = 0; i < 26; i++)
  {
    if (!c[i])
    {
      flag = false;
      break;
    }
  }
  cout << (flag ? "Yes" : "No") << endl;
}

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

int main() {
  int n;
  while(cin >> n) {
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    sort(p.begin(), p.end());

    long long ans = 0, total = 0;
    for(int i = 0; i < n; i++) {
      ans += total + p[i];
      total += p[i];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007ll
#define rep(i,L,R) for(i=L;i<R;i++)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
const ll INF = 1e18l+10,N = 1e5+10,MAX = 5000000;
#define sq(X) ((X)*(X))

int main()
{
    ll n,i,j,sum=0;
    cin>>n;
    string s;
    cin>>s;
    
    for(i=1;i<n-1;i++)
    {
        ll r =0,b=0,g=0;
        for(j=0;j<i;j++)
        {
            if(s[j]!=s[i] && s[j]=='R') r++;
            else if(s[j]!=s[i] && s[j]=='G')g++;
            else if(s[j]!=s[i] && s[j]=='B')b++;
        }
        ll r1 =0,b1=0,g1=0;
        for(j=i+1;j<n;j++)
        {
            if(s[j]!=s[i] && s[j]=='R') r1++;
            else if(s[j]!=s[i] && s[j]=='G')g1++;
            else if(s[j]!=s[i] && s[j]=='B')b1++;
            
            if(s[j]!=s[i] && 2*i-j>-1&&s[i]!=s[2*i-j]&& s[j]!=s[2*i-j] )sum--;
        }
        // deb1(r,g,b,r1,g1,b1);
        if(s[i]=='R')sum+= b*g1 + g*b1;
        else if(s[i]=='B')sum+= r*g1+g*r1;
        else if(s[i]=='G')sum+= r*b1 + b*r1;
    }
    cout<<sum<<"\n";
}   

Measured memory_bytes: 3636