akhauriyash/Code-Regression huggingface dataset:
#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 double EPS = 1e-12;

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


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

	cin >> N;
	//urdl
	int ans = MOD;
	vector<map<int, vector<pair<int, int>>>>wa(4);
	vector<map<int, vector<pair<int, int>>>>sa(4);
	vector<map<int,vector<int>>>x(4);
	vector<map<int,vector<int>>>y(4);
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		char c;
		cin >> c;
		if (c == 'U') {
			x[0][a].push_back(b);
			wa[0][a + b].push_back({ a,b });
			sa[0][a - b].push_back({ a,b });
		}
		if (c == 'R') {
			y[1][b].push_back(a);
			wa[1][a + b].push_back({ a,b });
			sa[1][a - b].push_back({ a,b });
		}
		if (c == 'D') {
			x[2][a].push_back(b);
			wa[2][a + b].push_back({ a,b });
			sa[2][a - b].push_back({ a,b });
		}
		if (c == 'L') {
			y[3][b].push_back(a);
			wa[3][a + b].push_back({ a,b });
			sa[3][a - b].push_back({ a,b });
		}
	}
	for (int i = 0; i < 4; i++) {
		for (auto &j : x[i]) {
			sort(j.second.begin(), j.second.end());
		}
		for (auto &j : y[i]) {
			sort(j.second.begin(), j.second.end());
		}
		for (auto &j : wa[i]) {
			sort(j.second.begin(), j.second.end());
		}
		for (auto &j : sa[i]) {
			sort(j.second.begin(), j.second.end());
		}
	}
	for (auto i : x[0]) {
		for (auto j : i.second) {
			auto it = lower_bound(x[2][i.first].begin(), x[2][i.first].end(), j);
			if (it != x[2][i.first].end()) {
				ans = min(ans, (*it - j));
			}
		}
	}
	for (auto i : y[1]) {
		for (auto j : i.second) {
			auto it = lower_bound(y[3][i.first].begin(), y[3][i.first].end(), j);
			if (it != y[3][i.first].end()) {
				ans = min(ans, (*it - j));
			}
		}
	}
	for (auto i : wa[1]) {
		for (auto j : i.second) {
			auto it = lower_bound(wa[0][i.first].begin(), wa[0][i.first].end(), j);
			if (it != wa[0][i.first].end()) {
				ans = min(ans, abs(it->first - j.first)*2);
			}
		}
	}
	for (auto i : wa[2]) {
		for (auto j : i.second) {
			auto it = lower_bound(wa[3][i.first].begin(), wa[3][i.first].end(), j);
			if (it != wa[3][i.first].end()) {
				ans = min(ans, abs(it->first - j.first)*2);
			}
		}
	}
	for (auto i : sa[0]) {
		for (auto j : i.second) {
			auto it = lower_bound(sa[3][i.first].begin(), sa[3][i.first].end(), j);
			if (it != sa[3][i.first].end()) {
				ans = min(ans, abs(it->first - j.first)*2);
			}
		}
	}
	for (auto i : sa[1]) {
		for (auto j : i.second) {
			auto it = lower_bound(sa[2][i.first].begin(), sa[2][i.first].end(), j);
			if (it != sa[2][i.first].end()) {
				ans = min(ans, abs(it->first - j.first)*2);
			}
		}
	}
	if (ans == MOD)cout << "SAFE\n";
	else cout << ans * 5 << endl;
}

Measured memory_bytes: 83976
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    S = input().split()

    print(S[0][0].upper()+S[1][0].upper()+S[2][0].upper())


main()


Measured memory_bytes: 4948
#!/usr/bin/perl

my ($n,$k) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @sa = sort { $a <=> $b } map { $_ - 0 } split(/\s+/,<STDIN>);

if( $k == 0 ){
  print "$sa[$#sa]\n"; exit(0);
}

my $mx = 10 ** 9;
my $mn = 1;

my $mx_c = &chk($mx);
my $mn_c = &chk($mn);

if( $mn_c < $k ){
  print "1\n"; exit(0);
}

while( $mx - $mn > 1 ){
  my $md = int( ($mx + $mn)/2 );
  my $md_c = &chk($md);
  if( $md_c <= $k and $k <= $mn_c ){
    $mx = $md;
    $mx_c = $md_c;
  } else { #( $mx_c <= $k < $md_c ){
    $mn = $md;
    $mn_c = $md_c;
  }
}

if( $mn_c == $k ){
  print "$mn\n";
} else {
  print "$mx\n";
}

exit(0);

sub chk {
  my $v = shift;
  my $s = 0;
  for(my $i=0;$i<$n;$i++){
    $s += int((( $v - 1 ) + $sa[$i]) / $v) - 1;
  }
  return $s;
}


Measured memory_bytes: 42900
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

int n, m, vis[25][25], dis[25][25], mx;
char a[25][25];

int dr[] = {0, 0, -1, 1};
int dc[] = {1, -1, 0, 0};

bool valid(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m && !vis[r][c] && a[r][c] == '.';
}

void bfs(int srcr, int srcc){
    memset(vis, 0, sizeof vis);
    memset(dis, 0, sizeof dis);
    vis[srcr][srcc] = 1;
    queue<pair<int, int> > q;
    q.push({srcr, srcc});
    while(q.size()){
        int r = q.front().first, c = q.front().second;
        q.pop();
        for(int i = 0; i < 4; i++){
            int rr = r + dr[i], cc = c + dc[i];
            if(valid(rr, cc)){
                vis[rr][cc] = 1;
                dis[rr][cc] = dis[r][c] + 1;
                mx = max(dis[rr][cc], mx);
                q.push({rr, cc});
            }
        }
    }

}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(a[i][j] == '.'){
                bfs(i, j);
            }
        }
    }
    cout << mx;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int a[maxn];
int n, z, w;
int main() {
    while(~scanf("%d%d%d", &n, &z, &w)) {
        for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
        int ans;
        if(n == 1) ans = abs(a[n] - w);
        else ans = max(abs(a[n] - w), abs(a[n] - a[n - 1]));
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
vector<pair<long long int,long long int>> stockBuySell(vector<long long int> price, long long int n)
{
    long long int i = 0;
    vector<pair<long long int,long long int>> design;
    while (i < n - 1) {

        while ((i < n - 1) && (price[i + 1] <= price[i]))
            i++;

        if (i == n - 1)
            break;

        long long int buy = i++;

        while ((i < n) && (price[i] >= price[i - 1]))
            i++;

        long long int sell = i - 1;
        design.push_back(make_pair(buy,sell));

    }
    return design;
}
int main() {
    jaldi

    long long int n;
    cin>>n;
    vector<long long int> a(n);

    for(long long int i=0;i<n;i++) {
        cin>>a[i];
    }

        vector<pair<long long int,long long int>> ans = stockBuySell(a,n);
        long long int res =1000;
        long long int numstocks =0;
        for(long long int i=0;i<ans.size();i++) {
            long long int buy = ans[i].first;
            long long int sell = ans[i].second;
            long long int valbuy = a[buy];
            long long int valsell = a[sell];
            numstocks += floor(res/valbuy);
            res -= (numstocks*valbuy);
            res += (numstocks*valsell);
            numstocks = 0;
        }

        cout<<res<<'\n';
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<long double> r(N),p(N);
    for(int i=0;i<N;i++){
        cin>>r[i];
    }
    
    p[0]=r[0];
    
    for(int i=1;i<N;i++){
        for(int j=0;j<i;j++){
            long double a=r[j],b=r[i];
            p[i]=max(p[i],p[j]+2.0*sqrt(a*b));
        }
    }
    
    long double left=INF,right=-INF;
    
    for(int i=0;i<N;i++){
        left=min(left,p[i]-r[i]);
        right=max(right,p[i]+r[i]);
    }
    
    cout<<setprecision(25)<<right-left<<endl;
}





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

int main(){
    
    int a,b,c;cin>>a>>b>>c;
    int ans = 0;
    
    for(int i=a; i <= b; ++i){
        ans += c%i==0;
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>
#define F first
#define S second
#define PI 3.141592653589793238
#define pb push_back

using namespace std;

//doesn't work for arrays
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const lli mod=1000000007;

lli gcd(lli a,lli b)
{
    if(a==0)
        return b;
    return (b%a,a);
}

lli binpow(lli x,lli y,lli m)
{
    if (y==0)
        return 1;
    lli p=binpow(x,y/2,m)%m;
    p=(p*p)%m;
    if(y%2)
        return (x*p)%m;
    else
        return p;
}

lli modi(lli a,lli m)
{
    return binpow(a,m-2,m);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i,j,tt=1;
    //cin>>tt;
    while(tt--)
    {
        lli n,sm=0,ans=0;
        cin>>n;
        lli a[n];
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sm+=a[i];
        }
        sm=(sm)%mod;
        for(i=0;i<n;i++)
        {
            sm=((sm-a[i])%mod+mod)%mod;
            ans=(ans+((a[i]*sm)%mod))%mod;
        }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 5204
H,W = map(int,input().split())
N=int(input())
a=list(map(int,input().split()))
acnt=cnt=0
Hcnt=Wcnt=0
ans = [[str(-1)]*W for i in range(H)]

for i in range(W*H):
    ans[Hcnt][Wcnt]=str(acnt+1)
    if Hcnt % 2 ==0:
        if Wcnt == W-1:
            Hcnt+=1
        else:
            Wcnt+=1
    else:
        if Wcnt == 0:
            Hcnt+=1
        else:
            Wcnt-=1

    cnt+=1
    if cnt == a[acnt]:
        cnt=0
        acnt+=1

for i in range(H):
    print(" ".join(ans[i]))

Measured memory_bytes: 3828
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int N = 25;
const int maxn = 1E4 + 10;

int n,m,A,B;
char s[maxn][N],t[N],g[N];

int cmp(int k)
{
	int len = min(k,m);
	for (int i = 1; i <= len; i++)
	{
		if (g[i] < t[i]) return -1;
		if (g[i] > t[i]) return 1;
	}
	if (k == m) return 0;
	if (k > m) return 1; return -1;
}

void Check(int k)
{
	bool flag = 1;
	int len = min(m,(int)(strlen(s[k] + 1)));
	for (int i = 1; i <= len; i++)
	{
		if (s[k][i] == '?') {flag = 0; break;}
		if (s[k][i] < t[i]) {++A; return;}
		if (s[k][i] > t[i]) return;
	}
	if (flag)
	{
		if (m < strlen(s[k] + 1)) return;
		if (m == strlen(s[k] + 1)) {++B; return;}
		++A; return;
	}
	len = strlen(s[k] + 1);
	for (int i = 1; i <= len; i++)
		g[i] = s[k][i] == '?' ? 'a' : s[k][i];
	int now = cmp(len);
	if (now == 0) {++B; return;}
	if (now == 1) return;
	for (int i = 1; i <= len; i++)
		g[i] = s[k][i] == '?' ? 'z' : s[k][i];
	now = cmp(len); if (now == -1) ++A; else ++B;
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) scanf("%s",s[i] + 1);
	scanf("%s",t + 1); m = strlen(t + 1);
	for (int i = 1; i <= n; i++) Check(i);
	if (!B) cout << A + 1 << endl;
	else
	{
		for (int i = 0; i < B; i++) printf("%d ",A + i + 1);
		cout << A + B + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 512
mod my {

    use std::io;
    use std::io::{Read, Error, ErrorKind};
    use std::str::FromStr;

    pub fn read<T: FromStr>() -> Result<T, io::Error> {
        let mut s = String::new();
        let mut stdin = io::stdin();
        let mut buf = [0];
        while let Ok(1) = stdin.read(&mut buf) {
            let c = buf[0] as char;
            if c.is_whitespace() {
                if s.is_empty() {
                    continue;
                } else {
                    break;
                }
            } else {
                s.push(c);
            }
        }
        if s.is_empty() {
            return Result::Err(Error::new(ErrorKind::InvalidData, "no content"));
        }
        return match s.parse() {
            Ok(v) => Ok(v),
            Err(_) => Result::Err(Error::new(ErrorKind::InvalidData, "invalid")),
        }
    }
}

fn main() {
    loop {
        let H = my::read::<i32>().unwrap();
        let W = my::read::<i32>().unwrap();

        if H == 0 && W == 0 {
            break;
        }

        for i in 0..H {
            for j in 0..W {
                print!("{}", if (i + j) % 2 == 0 { '#' } else { '.' })
            }
            println!();
        }

        println!();
    }
}



Measured memory_bytes: 5028
s = input()
t = input()
n = int(len(s)) - int(len(t)) + 1
kari = []

for i in range(n):
    kari.append(s[i:i+int(len(t))])

ans = []
n_2 = int(len(t))
for j in kari:
    t_2 = 0
    for k in range(n_2):
        if j[k] == t[k]:
            t_2 += 1
    ans.append(n_2-t_2)

print(min(ans))


Measured memory_bytes: 67856
N = int(input())
csf = [[int(x) for x in input().split()] for _ in range(N - 1)]

from math import ceil
def f(t, i):
    for j in range(i, N - 1):
        c, s, f = csf[j]
        d, m = divmod(t, f)
        t = max(s, ceil(t / f) * f) + c
    return t

for i in range(N):
    print(f(0, i))

Measured memory_bytes: 3188
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ei13333
 */

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

class TaskA
{
public:
  void solve(istream &in, ostream &out)
  {
    char X, Y;
    in >> X >> Y;
    if(X < Y) {
      out << "<";
    } else if(X == Y) {
      out << "=";
    } else {
      out << ">";
    }

  }
};


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  TaskA solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);

}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         998244353
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

ll mod_power(ll base , ll up , ll mod)
{
	ll val = 1;
	while(up)
	{
		if(up%2)
			val = (val * base)%mod;
		base = (base * base)%mod;	
		up/=2;
	}	
	
	return val;
}

int main()
{
	
//	vector<ll> fact(200001);
//	fact[0] = 1;
//	for(int i = 1;i<=200000;i++)
//	{
//		fact[i] = (i * fact[i-1])%MOD;
//	}
	
	ll n,m,k;
	cin>>n>>m>>k;
	ll sum = 0;
	ll val = 1;
	for(int l = 0;l<=k;l++)
	{
		ll temp = mod_power(m-1 , n - l - 1 , MOD);
		temp = (temp * m)%MOD;
		if(l != 0)
		{
			val = (val * (n - l))%MOD;
			val = (val * mod_power(l , MOD - 2 , MOD))%MOD;
		}
		temp = (temp * val)%MOD;
		
		sum = (sum + temp)%MOD;
	}
	
	
	cout<<sum<<endl;
	
	return 0;
}

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

int n, k, dp[5][105][3];
char s[105];

int dfs(int use, int m, int lim) {
	if (use > k) return 0;
	if (m > n) return use == k;
	if (dp[use][m][lim] != -1) return dp[use][m][lim];
	int ans = 0;
	int up = lim == 1 ? s[m] - '0' : 9;
	for (int i = 0; i <= up; i++)
		ans += dfs(use + (i != 0), m + 1, lim and i == up);
	return dp[use][m][lim] = ans;
}

int main() {
	cin >> (s + 1) >> k;
	n = strlen(s + 1);
	memset(dp, -1, sizeof dp);
	cout << dfs(0, 1, 1);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
#include <string>

#include <vector>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

int mypow(int a, int n) {
    int res = 1;
    for (int i = 0; i < n; i ++) {
        res *= a;
    }
    return res;
}

int main(int argc, char const *argv[]) {
    int h, w, k;
    cin >> h >> w >> k;
    string mass[h];
    
    for (auto &x : mass) {
        cin >> x;
    }

    int count = 0;
    for (int i = 0; i < mypow(2, h); i ++) {
        for (int j = 0; j < mypow(2, w); j ++) {
            string tmp[h];
            for (int m = 0; m < h; m ++) {
                tmp[m] = mass[m];
            }

            for (int a = 0; a < h; a ++) {
                if ((i >> a) & 1) {
                    for (int b = 0; b < w; b ++) {
                        tmp[a][b] = '.';
                    }
                }
            }
            for (int b = 0; b < w; b ++) {
                if ((j >> b) & 1) {
                    for (int a = 0; a < h; a ++) {
                        tmp[a][b] = '.';
                    }
                }
            }

            int S = 0;
            for (int a = 0; a < h; a ++) {
                for (int b = 0; b < w; b ++) {
                    S += (tmp[a][b] == '#');
                }
            }
            count += (S == k);
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3616
MOD = 998244353
a, b, c, d = map(int, input().split())
dp = [[0]*(d+1) for _ in range(c+1)]
dp[a][b] = 1
for i in range(a, c+1):
  for j in range(b, d+1):
    if i == a and j == b:
      continue
    if i == a:
      dp[i][j] = dp[i][j-1]*i
    elif j == b:
      dp[i][j] = dp[i-1][j]*j
    else:
      dp[i][j] = dp[i-1][j]+dp[i][j-1]
      dp[i][j] += dp[i-1][j-1]*(i-1)*(j-1)
      dp[i][j] += (dp[i-1][j]-dp[i-1][j-1]*(i-1))*(j-1)
      dp[i][j] += (dp[i][j-1]-dp[i-1][j-1]*(j-1))*(i-1)
    dp[i][j] %= MOD
ans = dp[i][j]
print(ans)

Measured memory_bytes: 133916
import sys


def resolve():
    readline = sys.stdin.readline    # 1行だけ文字列にする

    N = int(readline())
    H = [int(x) for x in readline().split()]

    # DP配列全体を「DPの種類に応じた初期値」で初期化
    dp = [0] * N
    
    # 初期条件を入力
    dp[0] = 0
    dp[1] = dp[0] + abs(H[1] - H[0])

    # ループを回す
    for i in range(2, N):
        dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]),
                    dp[i - 2] + abs(H[i] - H[i - 2]))
    
    # テーブルから解を得て出力
    print(dp[-1])


resolve()

Measured memory_bytes: 20492
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cstdlib>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(fabs(a-c)<=d)
        cout<<"Yes"<<endl;
    else
    {
        if(fabs(a-b)<=d&&fabs(b-c)<=d)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


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

int main() {
  int n, k, cnt = 1; string s; cin >> n >> k >> s;
  vector<int> a;
  if (s[0] == '0') a.push_back(0);
  rep(i, n-1) {
    if (s[i] == s[i+1]) cnt++;
    else {
      a.push_back(cnt);
      cnt = 1;
    }
  }
  a.push_back(cnt);
  if (s[n-1] == '0') a.push_back(0);
  vector<int> S(a.size()+1);
  rep(i, a.size()) S[i+1] = S[i] + a[i];
  int ans = 0;
  for (int i = 0; i < S.size(); i += 2)
    ans = max(ans, S[min((int)S.size() - 1, i + 2 * k + 1)] - S[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <algorithm>
using namespace std;
int dp[1401][1401], G[1401][1401];

int main()
{
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; ++i)
		for (int j = 0; j < W; ++j)
			cin >> G[i][j];
	int	maxWidth = 0;
	for (int i = 0; i < H; ++i)
		for (int j = 0; j < W; ++j)
		{
			dp[i][j] = (G[i][j] == 1 ? 0 : 1);
			if (maxWidth < dp[i][j])
				maxWidth = dp[i][j];
		}
		
	for (int i = 1; i < H; ++i)
		for (int j = 1; j < W; ++j)
		{
			if (G[i][j])
				dp[i][j] = 0;
			else
			{
				dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
				maxWidth = max(maxWidth, dp[i][j]);
			}
		}
	cout << maxWidth * maxWidth << endl;
	return 0;
}


Measured memory_bytes: 18424
// AOJ DSL_4_A Union of Rectangles
// 2018.5.14 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX_N 2005
#define MAX   4005

typedef struct { int x1, y1, x2, y2; } TBL;
TBL tbl[MAX_N];

int x[MAX], xs;
int y[MAX], ys;
short s[MAX][MAX];

int cmp(int *a, int *b) { return *a - *b; }

int bsch(int *a, int x, int r)
{
	int m, l = 0;

    while (l < r) {
        m = (l + r) >> 1;
		if (a[m] == x) return m;
        if (a[m] < x) l = m + 1; else r = m;
    }
	return l-1;
}

int uniq(int *a, int n)
{
	int i, j;
	
	for (i = 0, j = 1; j < n; j++) {
		while (j < n && a[j] == a[i]) j++;
		if (j < n) if (++i != j) a[i] = a[j];
	}
	return i+1;
}

int main()
{
	int N, i, j, x1, y1, x2, y2;
	long long ans;

	N = in(); xs = ys = 0;
	for (i = 0; i < N; i++) {
		tbl[i].x1 = x1 = in(), tbl[i].y1 = y1 = in();
		tbl[i].x2 = x2 = in(), tbl[i].y2 = y2 = in();
		x[xs++] = x1, x[xs++] = x2;
		y[ys++] = y1, y[ys++] = y2;
	}
	qsort(x, xs, sizeof(int), cmp); xs = uniq(x, xs);
	qsort(y, ys, sizeof(int), cmp); ys = uniq(y, ys);

	for (j = 0, i = 0; i < N; i++) {
		x1 = bsch(x, tbl[i].x1, xs);
		x2 = bsch(x, tbl[i].x2, xs);
		y1 = bsch(y, tbl[i].y1, ys);
		y2 = bsch(y, tbl[i].y2, ys);

		s[y1][x1]++, s[y1][x2]--;
		s[y2][x1]--, s[y2][x2]++;
	}

	ans = 0;
	for (j = 0; j < ys; j++) {
		for (i = 1; i < xs; i++) s[j][i] += s[j][i-1];
	}

	for (j = 1; j < ys; j++) {
		for (i = 0; i < xs; i++) s[j][i] += s[j-1][i];
	}

	for (j = 0; j < ys; j++) {
		for (i = 0; i < xs; i++) if (s[j][i]) {
			ans += (long long)(x[i+1]-x[i])*(long long)(y[j+1]-y[j]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 33144
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll w[1000000],v[1000000],dp[102][100002];
ll fun(ll n,ll value)
{
    if(dp[n][value]!=-1)
    return dp[n][value];
    if(value==0)
    return 0;
    if(n<=0)
    return 999999999;
    else
    {
        if(value>=v[n])
        {
            return dp[n][value]=min(w[n]+fun(n-1,value-v[n]),fun(n-1,value));
        }
        else
        return dp[n][value]=(fun(n-1,value));
    }
}
int main()
{
    ll n,W,i,ans,s=0;
    cin>>n>>W;
    memset(dp,-1,sizeof(dp));
    for(i=1;i<=n;i++)
    {
    cin>>w[i]>>v[i];
    s+=v[i];
    }
    for(i=0;i<=s;i++)
    {
        if(fun(n,i)<=W)
        ans=i;
    }
    cout<<ans;
}

Measured memory_bytes: 83336
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <list>
#include <iomanip>
#include <numeric>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int h, n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

	vector<vector<int>> mp(n, vector<int>(h + 1, INF));
	for (int i = 0; i < n; i++) mp[i][0] = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < h; j++) {
			int nj = min(j + a[i], h);
			if (0 < i) mp[i][j] = min(mp[i][j], mp[i - 1][j]);
			if (mp[i][j] != INF) mp[i][nj] = min(mp[i][nj], mp[i][j] + b[i]);
			if (0 < i) mp[i][nj] = min(mp[i][nj], mp[i - 1][nj]);
		}
	}
	cout << mp[n - 1][h] << endl;
}

Measured memory_bytes: 39424
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll H,N; cin >> H >> N;
    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i] >> B[i];

    vector<vector<ll>> dp(N+1, vector<ll>(30000,1e18));
    dp[0][0] = 0;
    rep(i,N) {
        rep(j,30000) dp[i+1][j] = dp[i][j];
        rep(j,30000) {
            if (j < A[i]) continue;
            chmin(dp[i+1][j],dp[i+1][j-A[i]] + B[i]);
        }
    }
    ll ans = 1e18;
    for (int i = H; i < 30000; i++) chmin(ans,dp[N][i]);
    cout << ans << endl;

}

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

int main(){

    int K, S;
    int ans = 0;
    cin >> K >> S;
    
    for(int X = 0; X <= K; X++){
        for(int Y = 0; Y <= K; Y++){
            if(S-X-Y <= K && S-X-Y >= 0) ans++;
        }
    }

   cout << ans << endl;
}


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

int main()
{
	int left{}, right{}, top{}, bottom{}, n;
	scanf("%d%d%d", &right, &top, &n);
	for (int i = 0; i < n; i++)
	{
		int x, y, a;
		scanf("%d%d%d", &x, &y, &a);
		switch(a)
		{
		case 1:
			left = std::max(left, x);
			break;
		case 2:
			right = std::min(right, x);
			break;
		case 3:
			bottom = std::max(bottom, y);
			break;
		case 4:
			top = std::min(top, y);
			break;
		}
	}
	if (top < bottom || left > right)
		printf("0\n");
	else
		printf("%d\n", (top - bottom) * (right - left));

	return 0;
}

Measured memory_bytes: 256
import numpy as np

N, K= map(int, input().split())
p = np.array(list(map(int, input().split())))

tmp = np.sum(p[:K])
max = tmp
for i in range(N-K):
    tmp = tmp-p[i]+p[i+K]
    if tmp>max:
        max = tmp

print((max+K)/2)

Measured memory_bytes: 33764
import heapq

N = int(input())
a = list(map(int, input().split(" ")))

q = a[:N]
heapq.heapify(q)
x = [sum(q)]

for k in range(N, 2*N):
    ## in : a[k], out : v
    out = heapq.heappushpop(q, a[k])
    x.append(x[-1]+a[k]-out)
    
a = a[::-1]    
q = [-v for v in a[:N]]
heapq.heapify(q)
y = [-sum(q)]
for k in range(N, 2*N):
    out = -heapq.heappushpop(q, -a[k])
    y.append(y[-1]+a[k]-out)
    
print(max(v-w for v,w in zip(x, y[::-1])))

Measured memory_bytes: 38292
n,a,b,c = map(int,input().split())
takelist = [a,b,c]

li = [int(input()) for _ in range(n)]
li2 = [0 for _ in range(n)]
min = 10**100

def movelist(li,n):
    for i in range(n):
        if li[i] != 3:
            li[i] += 1
            break
        else:
            li[i] = 0

for i in range(4**n):
    li3 = [0,0,0,0]
    sum = 0
    for j in range(n):
        if li3[li2[j]] != 0 and li2[j] != 3:
            sum += 10
        li3[li2[j]] += li[j]
    if li3[0] != 0 and li3[1] != 0 and li3[2] != 0:
        for k in range(3):
            sum += abs(li3[k] - takelist[k])
        if sum < min:
            min = sum
    movelist(li2,n)

print(min)


Measured memory_bytes: 3064
#include<cmath>
#include<cstdio>
#include<algorithm>

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

using namespace std;

const double EPS=1e-11;
const double INF=1e77;
const double PI=acos(-1);

struct point{
	double x,y;
	point(double x,double y):x(x),y(y){}
};

double arg(const point &a){
	double t=atan2(a.y,a.x);
	return t<0?t+2*PI:t;
}

struct interval{
	double a,b;
	interval():a(0),b(0){}
	interval(const double &a,const double &b):a(a<b?a:b),b(a<b?b:a){}
	bool operator<(const interval &I)const{ return b+EPS<I.b || abs(b-I.b)<EPS && a+EPS<I.a; }
};

bool cover(const interval &I,double x){
	return I.a-EPS<x && x<I.b+EPS;
}

int solve(int n,const interval *I){
	int res=0;
	double x=-INF;
	rep(i,n) if(x+EPS<I[i].a) res++, x=I[i].b;
	return res;
}

int main(){
	int n; scanf("%d",&n);
	int t[2000],l[2000],b[2000],r[2000];
	rep(i,n) scanf("%d%d%d%d",l+i,b+i,r+i,t+i);

	interval I[2000];
	rep(i,n){
		I[i].a=INF;
		I[i].b=-INF;
		if(l[i]>0 && t[i]>=0 && b[i]<0){ // x 軸の正の部分をまたぐ
			I[i].a=min(I[i].a,arg(point(l[i],b[i])));
			I[i].a=min(I[i].a,arg(point(r[i],b[i])));
			I[i].b=max(I[i].b,arg(point(l[i],t[i]))+2*PI);
			I[i].b=max(I[i].b,arg(point(r[i],t[i]))+2*PI);
		}
		else{
			I[i].a=min(I[i].a,arg(point(l[i],t[i])));
			I[i].a=min(I[i].a,arg(point(l[i],b[i])));
			I[i].a=min(I[i].a,arg(point(r[i],t[i])));
			I[i].a=min(I[i].a,arg(point(r[i],b[i])));
			I[i].b=max(I[i].b,arg(point(l[i],t[i])));
			I[i].b=max(I[i].b,arg(point(l[i],b[i])));
			I[i].b=max(I[i].b,arg(point(r[i],t[i])));
			I[i].b=max(I[i].b,arg(point(r[i],b[i])));
		}
	}
	sort(I,I+n); // 必要!!

	int ans=n;
	rep(i,n){
		int m=0;
		interval J[2000];
		for(int j=i+1;j<n;j++){
			if(!cover(I[j],I[i].b)
			&& !cover(I[j],I[i].b+2*PI)
			&& !cover(I[j],I[i].b-2*PI)) J[m++]=I[j];
		}
		rep(j,i){
			if(!cover(I[j],I[i].b)
			&& !cover(I[j],I[i].b+2*PI)
			&& !cover(I[j],I[i].b-2*PI)) J[m++]=interval(I[j].a+2*PI,I[j].b+2*PI);
		}
		sort(J,J+m); // 必要!!
		ans=min(ans,solve(m,J)+1);
	}
	printf("%d\n",ans);

	return 0;
}

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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	
	int ans = 0;
	
	rep(i,n-2){
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
			ans++;
			i += 2;
		}
	}
	
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S, C;
    C = "Coffee";
    bool flag = false;
    cin >> S;
    if (S[2]==S[3] && S[4]==S[5]) flag=true;
    if (flag) cout <<"Yes"<<endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/**
     **author : _KMS_
     **created : 17-03-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+100,MOD=2e9;
typedef long long ll;
ll mx=1e16;
int occ[30],occ2[30];
int main() 
{ 
      
ios::sync_with_stdio(false);
cin.tie(0);
string s,p;
cin>>s>>p;
for(int i=0;i<s.size();i++)occ[s[i]-97]++;
for(int i=0;i<p.size();i++)occ2[p[i]-97]++;
sort(occ,occ+26);
sort(occ2,occ2+26);
bool f=1;
for(int i=0;i<26;i++)if(occ2[i]!=occ[i])f=0;
(f)?puts("Yes"):puts("No");

	return 0; 
} 

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

using namespace std;

int main(){
  string str;  
  int i,j,k,o,r,b;
  char right[]={'y','u','i','o','p','h','j','k','l','n','m'};

  while(cin >> str){
    if(str[0]=='#')
      break;
    o=0;
    r=0;
    for(j=0; j<11; j++){
      if(str[0]==right[j])
	r=1;
    }
    b=r;
    for(i=0; i<str.size(); i++){
      r=0;
      for(j=0; j<11; j++){
	if(str[i]==right[j])
	  r=1;
      }
      if(b!=r){
	o++;
      }
      b=r;
    }
    cout << o << endl;
  }
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
const int N = 16;
const int NN = 1<<16;
ll in[N][N] , pre[NN];
ll dp[NN];


void rec(int i , vll &not_taken , int curr_mask , int mask ){
    if(i == sz(not_taken)){
        dp[mask^curr_mask] =  max(dp[mask^curr_mask] , pre[curr_mask] +  dp[mask]);
        return;
    }
    
    rec(i+1 , not_taken , curr_mask , mask);
    rec(i+1 , not_taken , curr_mask^(1<<not_taken[i]) , mask);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    int n; cin >> n;
    for(int i = 0 ;i < n; i++){
        for(int j = 0; j < n ; j++)
            cin >> in[i][j];
    }

    for(int i = 0 ;i < (1<<n) ; i++){
        for(int j = 0 ;j < n; j++){
            if(i&(1<<j)){
                for(int k = j+1; k < n ; k++){
                    if(i&(1<<k))
                        pre[i] += in[j][k];
                }
            }
        }
    }

    
    for(int mask = 0 ; mask < (1<<n) ; mask++){
        vll not_taken;
        for(int i = 0 ;i < n ; i++){
            if(!(mask&(1<<i)))
                not_taken.pb(i);
        }
        rec(0 , not_taken , 0 , mask);
    }

    cout << dp[(1<<n)-1] << endl;



    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
constexpr int kMax = 301;

int N;
double dp[kMax][kMax][kMax];

double ans(int i, int j, int k) {  // three, two, one count
  // dp(i, j, k)  = (i/N) * dp(i-1, j+1, k)   (dice shows three-count-sushi plate No)
  //              + (j/N) * dp(i, j-1, k+1)   (dice shows two-count-sushi plate No)
  //              + (k/N) * dp(i, j, k-1)     (dice shows one-count-sushi plate No)
  //              + (N-i-j-k)/N * dp(i, j, k) (else)
  //              + 1;
  // --> dp(i, j, k) = {i*dp(i-1, j+1, k) + j*dp(i, j-1, k+1) + k*dp(i, j, k-1) + N} / (i+j+ k)

  if (dp[i][j][k] >= 0) return dp[i][j][k];

  if ((i + j + k) == 0) {
    dp[i][j][k] = 0;
  } else {
    double f = 0;
    if (i>0) f += i * ans(i-1, j+1, k);
    if (j>0) f += j * ans(i, j-1, k+1);
    if (k>0) f += k * ans(i, j, k-1);
    f += N;

    dp[i][j][k] = f / (i+j+k);
  }
  return dp[i][j][k];
}

int main() {
  std::cin >> N;
  int count[4] = {};  // zero, one, two, three
  for (int i = 0; i < N; ++i) {
    int a; std::cin >> a;
    ++count[a];
  }

  // Initialize.
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N; ++j) {
      for (int k = 0; k <= N; ++k) {
        dp[i][j][k] = -1;
      }
    }
  }

  // Output.
  std::cout << std::fixed << std::setprecision(10)
            << ans(count[3], count[2], count[1]) << std::endl;
}


Measured memory_bytes: 213376
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S;
	cin>>S;
	int n=0,s=0,w=0,e=0;
	rep(i,S.size()){
		if(S[i]=='N')n++;
		if(S[i]=='W')w++;
		if(S[i]=='S')s++;
		if(S[i]=='E')e++;
	}
	string ans="Yes";
	if(n>0 and s==0)ans="No";
	if(n==0 and s>0)ans="No";
	if(w>0 and e==0)ans="No";
	if(w==0 and e>0)ans="No";
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,int> d[110];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int p,q;
		scanf("%d%d",&p,&q);
		p--;q--;
		d[i]=(make_pair(p,q));
	}
	int now=-1;
	int use=0;
	bool ok=true;
	for(int i=0;i<a;i++){
		if(now<i){
			int val=-1;
			for(int j=0;j<b;j++){
				if(d[j].first<=i)val=max(val,d[j].second);
			}
			if(val<i){ok=false;break;}
			use++;
			now=val;
		}
	}
	if(!ok)printf("Impossible\n");
	else printf("%d\n",use);
}

Measured memory_bytes: 1028
#include<stdio.h>

int main(void){
	int n,x=0,y=0,z=0,count=0;
	scanf("%d",&n);
	for(int i=1;i<n+1;i++){
		for(x=1;;x++){
			for(y=x;;y++){
				for(z=y;;z++){
					if((x+y)*(x+y)+(y+z)*(y+z)+(z+x)*(z+x)==2*i){
						//printf("(%d,%d,%d),",x,y,z);
						if(x==y&&y==z){
							count+=1;
						}else if(x==y||y==z){
							count+=3;
						}else{
							count+=6;
						}
					}
					if((x+y)*(x+y)+(y+z)*(y+z)+(z+x)*(z+x)>2*i){
						break;
					}
				}
				if(z==y){
					break;
				}
			}
			if(y==x){
				break;
			}
		}
		printf("%d\n",count);
		count=0;
	}
}

Measured memory_bytes: 1652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

//begin( weighted Union-Find )//

const ll MAX_N = 1000000;


//親の番号
ll par[MAX_N];
//ノードの高さ
ll rk[MAX_N];

ll diff[MAX_N];


//n要素で初期化
void init(ll n) {
  for (ll i = 0; i < n; i++) {
    par[i] = i;
    rk[i] = 0;
    diff[i] = 0;
  }
}

//木の根を求める
ll find(ll x) {
  if (par[x] == x) {
    return x;
  } else {
    ll r = find(par[x]);
    diff[x] += diff[par[x]];
    return par[x] = r;
  }
}

ll weight(ll x) {
  find(x);
  return diff[x];
}

ll var(ll x, ll y) {
  return weight(y)-weight(x);
}

//xとyの属する集合を併合 (weight(y)-weight(x) = w)
bool unite(ll x, ll y, ll w) {
  w += weight(x); w -= weight(y); 
  x = find(x);
  y = find(y);
  if (x == y) return false;
  
  if (rk[x] < rk[y]) {
    swap(x, y); w = -w;
  }
  if (rk[x] == rk[y]) rk[x]++;
  par[y] = x;
  diff[y] = w;
  return true;
}

//xとyが同じ集合に属するか否か
bool same(ll x, ll y) {
  return find(x) == find(y);
}

//end( Union-Find )//

int main() {
  ll N, M; cin >> N >> M;
  init(N);
  bool ok = true;
  for (ll i = 0; i < M; i++) {
    ll l, r, d; cin >> l >> r >> d; l--; r--;
    if (!same(l,r)) {unite(l,r,d);}
    if (same(l,r)) {
      if (var(l,r) != d) {ok = false;}
    }
  }
  if (ok) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 9344
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

S = ns()
Q = ni()


def solve():
    ds = collections.deque(S)
    rev = False
    for i in range(Q):
        qt, *q = ns().split()
        if qt == "1":
            rev = not rev
            continue
        assert qt == "2"
        if (q[0] == "1") ^ rev:
            ds.appendleft(q[1])
        else:
            assert (q[0] == "2") ^ rev
            ds.append(q[1])
    if rev:
        ds = reversed(ds)
    return "".join(ds)


print(solve())


Measured memory_bytes: 8684
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

struct P
{
  double x;
  double y;

  bool operator<(const P& rhs) const
  {
    return x == rhs.x ? y < rhs.y : x < rhs.x;
  }
};

using Points = std::vector<P>;

double solve(int n, Points points)
{
  std::sort(points.begin(), points.end());

  double sum = 0;
  int count = 0;
  do {
    double tmp = 0;
    for (std::size_t i = 0; i < points.size() - 1; ++i) {
      const auto delta_x = points[i].x - points[i + 1].x;
      const auto delta_y = points[i].y - points[i + 1].y;
      tmp += std::sqrt(delta_x * delta_x + delta_y * delta_y);
    }
    sum += tmp;
    ++count;
  } while (std::next_permutation(points.begin(), points.end()));

  return sum / count;
}

int main()
{
  int n;
  std::cin >> n;

  Points points(n);
  for (auto& p : points) {
    std::cin >> p.x >> p.y;
  }

  std::cout << std::setprecision(20) << solve(n, points) << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];

  bool ans = true;
  H[0] -= 1;
  for(int i = 0; i < N-1; i++){
    if(H[i+1] - H[i] > 0){
      H[i+1] -=1;
      continue;
    }
    if(H[i+1] - H[i] == 0){
      continue;
    }
    ans = false;
    break;
  }

  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll N, A[100000], S = 0;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
        S ^= A[i];
    }
    REP(i, N) A[i] &= ~S;

    int r = 0;
    vector<int> top(N);
    RREP(i, 61) {
        int j = r;
        for (; j < N; j++) {
            if (A[j] >> i & 1) {
                swap(A[r], A[j]);
                break;
            }
        }
        if (j == N) continue;
        top[r] = i;
        REP(k, N) if (k != r && (A[k] >> i & 1)) A[k] ^= A[r];
        r++;
    }

    ll x = 0;
    RREP(i, 61) {
        ll nx = x | (1LL << i);
        REP(j, r) if (nx >> top[j] & 1) nx ^= A[j];
        if ((nx & (x | (1LL << i))) == 0) x |= (1LL << i);
    }
    cout << S + x * 2 << endl;
    return 0;
}


Measured memory_bytes: 1408
//130c.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
/*namespace*/
using namespace std;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(x) (x).begin(),(x).end()

int main(){
    double W,H,x,y;
    cin>>W>>H>>x>>y;
    double G;
    G=W*H/2;
    cout<<G<<" ";
    if(x==W/2&&y==H/2){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    string S;
    cin >> S;

    for(ll i = 0; i < S.length(); i++){
        cout << 'x';
    }
    cout << endl;

}



Measured memory_bytes: 256