akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
using namespace std;
long long int N;
long long int ans;
int main() {
	cin >> N;
	int i = floor(sqrt(N));
	while (N % i != 0) {
		i--;
	}
	cout << i + (N/i) - 2 << endl;
	return 0;
}


Measured memory_bytes: 256
import bisect
def main():
    while True:
        n, m = map(int, input().split())
        if n == 0:
            break
        p = [0] + list(int(input()) for i in range(n))
        point = []
        for i in range(n):
            for j in p[i:]:
                a = p[i] + j
                if a < m:
                    point.append(a)
        point.sort()

        print(max(i + point[bisect.bisect_left(point, m - i) - 1] for i in point))
            
if __name__=="__main__":
	main()


Measured memory_bytes: 28084
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <deque>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_set>
#define int long long
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

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

void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

signed main()
{
	fast();
	int n;
	cin >> n;
	bool prev2 = 0, prev3 = 0;
	bool sec = 0;
	for (int i = 0; i < n; ++i)
	{
		int d1, d2;
		cin >> d1 >> d2;

		if (prev2 && prev3 && d1 == d2)
			sec = 1;
		prev3 = prev2;
		prev2 = d1 == d2;
	}
	if (sec)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 3608
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/16 17:42:54
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 2e5 + 5, MOD = 1e9 + 7;

int qpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;   
    }
    return res;   
}

int n;
vector <int> G[N];
int sz[N], f[N];

void dfs(int u, int fa) {
    sz[u] = 1;
    for (auto v : G[u]) if (v != fa) {
        dfs(v, u);
        sz[u] += sz[v];
    }
}

void dfs2(int u, int fa) {
    for (auto v : G[u]) if (v != fa) {
        f[v] = 1ll * f[u] * sz[v] % MOD * qpow(n - sz[v], MOD - 2) % MOD;
        dfs2(v, u);
    }
}

void run() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1, 0);
    f[1] = 1;
    for (int i = 1; i <= n; i++) {
        f[1] = 1ll * f[1] * i % MOD;
    }
    for (int i = 1; i <= n; i++) {
        f[1] = 1ll * f[1] * qpow(sz[i], MOD - 2) % MOD;
    }
    dfs2(1, 0);
    for (int i = 1; i <= n; i++) {
        cout << f[i] << '\n';   
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 15476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, A, B;
	cin >> N >> A >> B;
	if (A > B) co(0);
	else if (A == B) co(1);
	else {
		if (N == 1) co(0);
		else {
			ll C = B - A;
			co(1 + C * (N - 2));
		}
	}

	Would you please return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main()
        {
            int l,i,n;
           char str1[1000], str2[1000], str[1000];
           scanf("%s",str1);
           scanf("%s",str2);
           strcat(str1,str2);
           //puts(str1);
           l=atoi(str1);
           n=sqrt(l);

       if(n*n==l)
       {
           printf("Yes\n");
       }
       else
        printf("No");

        }


Measured memory_bytes: 128
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val W, H , x, y, r = sc.nextInt
  val res = if(x -r <0 || x+r > W) "No"
  else if( y- r < 0 || y + r > H) "No"
  else "Yes"
  println(res)
}


Measured memory_bytes: 45000
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=1030,M=1000000007;
string s[N];
int i,j,n,m,dp[N][N];
bool vis[N][N];
int play(int x,int y){
	if(x==n||y==m) return 0;
	if(s[x][y]=='#') return 0;
	if(vis[x][y]) return dp[x][y];
	vis[x][y]=true;
	if(x==n-1&&y==m-1) return dp[x][y]=1;
	return dp[x][y]=(play(x+1,y)+play(x,y+1))%M;
}
int main(){
	ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(NULL);
	cin>>n>>m;
	for(i=0;i<n;++i) for(j=0;j<m;++j) vis[i][j]=false;
	for(i=0;i<n;++i) cin>>s[i];
	cout<<play(0,0);
	return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b,int c){
  long long ans=1;
  for(int i=1;i<=min(min(a,b),c);i++){
    if(a%i==0 && b%i==0 && c%i==0) ans=i;
  }
  return ans;
}

int main() {
  long long n;
  cin>>n;
  long long ans=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        ans+=gcd(i,j,k);
      }
    }
  }
  cout<<ans;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  else return gcd(b, a % b);
  // return (b == 0) ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
  ll g = gcd(a, b);
  return a / g * b;
}


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

  int n;
  cin >> n;
  vector<int> v(n);
  vector<ll> left(n);
  vector<ll> right(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  left[0] = v[0];
  for (int i = 1; i < n; i++) {
    left[i] = gcd(v[i], left[i-1]);
  }
  right[n-1] = v[n-1];
  for (int i = n-2; i >= 0; i--) {
    right[i] = gcd(right[i+1], v[i]);
  }


  // print(left);
  // print(right);
  ll res = max(right[1], left[n-2]);
  for (int i = 1; i < n-1; i++) {
    res = max(res, gcd(left[i-1], right[i+1]));
  }

  cout << res << endl;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int count = 0;
		
		for(int i = a;i <= b;i++){
			if(c % i == 0)
				count++;
		}
		
		System.out.println(count);
	}
}

Measured memory_bytes: 17356
main = do
  s <- getContents
  mapM_ print . map calc . takeWhile(\[a,op,b] -> op /= "?") . map words . lines $ s

calc :: [String] -> Int
calc [sa, op, sb] 
  | op == "+" = a + b
  | op == "-" = a - b
  | op == "*" = a * b
  | op == "/" = a `div` b
  | otherwise = 0
  where 
    a = read sa :: Int
    b = read sb :: Int

Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(void){
 string s; cin >> s;
 for(int i=0;i<s.size();i++)for(int j=0;j<i;j++){
  if (s[i]==s[j]) {cout << "no" << endl; return 0;} 
 }
 cout << "yes" << endl;
 return 0;
}

Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int n,cost[100100];
signed main() {
    cin >> n;
    fill(cost,cost+n+10,inf);
    cost[0]=0;
    vi h(n+1);
    rep(i, n)cin >> h[i];
    rep(i, n) {
        chmin(cost[i+1],cost[i]+abs(h[i+1]-h[i]));
        chmin(cost[i+2],cost[i]+abs(h[i+2]-h[i]));
    }
    // rep(i, n+1) cout << cost[i] << ' ';cout << endl;
    cout << cost[n-1] << endl;
    return 0;
}

Measured memory_bytes: 4844
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
const long long mod = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int dp[110000];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	rep(i, 110000)dp[i] = n;
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j *= 6) {
			chmin(dp[i], dp[i - j] + 1);
		}
		for (int j = 1; j <= i; j *= 9){
			chmin(dp[i], dp[i - j] + 1);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

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

int main(){
  string n;
  int c = 0;
  int t;
  cin >> n;
  for(int i = 0;i < n.size();i++){
    t = (int)n.at(i) -48;
    c += t;
  }
  if(c % 9 == 0)
    cout << "Yes";
  else
    cout << "No";
}




Measured memory_bytes: 3732
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<string.h>

int main(){
    char n[4];
    scanf("%s",n);
    int i;
    for(i=0;i<3;i++){
        if(n[i]=='1'||n[i]=='9'){
            if(n[i]=='1') n[i]='9';
            else n[i]='1';
        }
    }
    printf("%s",n);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>

using namespace std;

int main() {
	int h, w;
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++) {
			if (i == 0 || i == h - 1) {
				for (int j = 0; j < w; j++) {
					cout << '#';
				}
			}
			else{
				cout << '#';
				for (int j = 1; j < w - 1; j++) {
					cout << '.';
				}
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1156
using System;
using System.Collections.Generic;
using System.Linq;
 
class Hello
{
    public static List <string> S=new List<string>{"1","2","3","4","5","6","7","8","9","10","11","12","13"};
    public static List <string> H=new List<string>{"1","2","3","4","5","6","7","8","9","10","11","12","13"};
    public static List <string> C=new List<string>{"1","2","3","4","5","6","7","8","9","10","11","12","13"};
    public static List <string> D=new List<string>{"1","2","3","4","5","6","7","8","9","10","11","12","13"};
    
    //リスト内から削除
    static void aiueo(string mark,string num)
    {
        if(mark=="S")S.Remove(num);
        else if(mark=="H")H.Remove(num);
        else if(mark=="C")C.Remove(num);
        else if(mark=="D")D.Remove(num);
    }
    
    static void Main()
    {
        int kosu=int.Parse(Console.ReadLine());
        
        string [] str;
        string mark;
        string num;
        
        for(int i=0;i<kosu;i++)
        {
            str=Console.ReadLine().Split(' ');
            mark=str[0];
            num=str[1];
            aiueo(mark,num);
        }
        //出力
        for(int i=0;i<S.Count;i++){
            Console.WriteLine("S "+S[i]);
        }
        for(int i=0;i<H.Count;i++){
            Console.WriteLine("H "+H[i]);
        }
        for(int i=0;i<C.Count;i++){
            Console.WriteLine("C "+C[i]);
        }
        for(int i=0;i<D.Count;i++){
            Console.WriteLine("D "+D[i]);
        }
    }
}


Measured memory_bytes: 17832
#include <iostream>
#include <vector>
#include <algorithm>
#define mod 1000000000+7;
typedef long long ll;
using namespace std;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n,m,k; cin >> n >> m >> k;
    vector<int> a(n),b(m);
    for(int i{}; i<n; i++){
        cin >> a[i];
    }
        ll t{};
    for(int i{}; i<m; i++){
        cin >> b[i];
        t+=b[i];
    }

    int j = m;
    int ans{};
    for(int i{}; i<n+1; i++){
        while(j>0 && t>k){
            --j;
            t -=b[j];
        }
        if(t>k) break;
        ans = max(ans,i+j);
        if(i==n) break;
        t+=a[i];
    }
    cout << ans << "\n";




}

Measured memory_bytes: 4736
#045c
S = list(input())

#allは2**9=512なので全探索でOK
if len(S)==1:
  print(int(S[0]))
else:
  ans = 0

  for i in range(0,2**(len(S)-1)):
      bit = str(bin(i))[2:].zfill(len(S)-1)
      #print(bit,":",end="") 
      number = int(S[0])

      for j in range(len(bit)):

          if bit[j] == "0":
              number = number*10 + int(S[j+1])
          else:
              #print("+",number,end="")
              ans += number
              number = int(S[j+1])

      #print("+",number)
      ans += number

  print(ans)

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

int main() {
  int M;
  int D;

  cin >> M;
  cin >> D;

  int ans = 0;

  for (int i = 1; i <= M; i++){
    for(int j = 1; j <= D; j++){
      if (j>20 && (j%10)!=0 && (j%10)!=1){
      if (i == (j/10) * (j % 10)){
        ans++;
      }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import Data.List (intercalate)

drawLine :: Int -> IO ()
drawLine n = putStrLn $ intercalate "" $ replicate n "#"

draw :: Int -> Int -> IO ()
draw w h
  | w > 0     = drawLine h >> draw (w - 1) h
  | otherwise = putStrLn ""


main :: IO ()
main = do
    line <- getLine
    let [w, h] = map (\n -> read n :: Int) $ words line
    if w == 0 && h == 0 then
        return ()
    else do
        draw w h
        main


Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
int main() {
  	int n; cin >> n;
	int A[123];
	int a = 0, b = 0;
	for (int i = 0; i < n; ++i) {
		cin >> A[i];
	}
	sort(A, A+n, greater<int>());
	for (int i = 0; i < n; ++i) {
		if (i%2) b += A[i];
		else a += A[i];
	}
	cout << a-b;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
struct node{
	int mins,id1;
	int smin,id2;
}dp[262149];
using std::min;
using std::max;
int n,a[262149];
void merge(int i,int j){
	if(dp[i].mins<dp[j].mins){
		dp[i].smin=max(dp[i].mins,dp[j].smin);
		dp[i].id2=dp[i].mins>dp[j].smin?dp[i].id1:dp[j].id2;
		dp[i].mins=dp[j].mins; dp[i].id1=dp[j].id1;
	}
	else if(dp[i].smin<dp[j].mins&&dp[j].id1!=dp[i].id1)
		dp[i].smin=dp[j].mins,dp[i].id2=dp[j].id1;
	return ;
}
int main(){
	scanf("%d",&n);
	memset(dp,0,sizeof dp);
	for(int i=0;i<(1<<n);++i) scanf("%d",&a[i]);
	dp[0]=(node){a[0],0,-1,-1};
	for(int i=1;i<(1<<n);++i){
		if(dp[i].smin) continue;
		dp[i]=(node){a[i],i,-1,-1};
		for(int j=0;j<n;j++)
			if((1<<j)&i) merge(i,i^(1<<j));
	}
	int lans=-1;
	for(int k=1;k<(1<<n);k++){
		printf("%d\n",lans=max(lans,dp[k].smin+dp[k].mins));
	}
	return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>

int main(void)
{
  int i, j;
  char buffer[100];
  
  for(i = 1; i <= 9; i++) {
    for(j = 1; j <= 9; j++) {
      sprintf(buffer, "%dx%d=%d", i, j, i*j);
      printf("%s\n", buffer);
    }
  }

  return(0);
}

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

#define iter(T, o, i) for(T::iterator i = o.begin(); i != o.end(); i++)

using namespace std;

class Tree {
	int size;
	vector<vector<int> > adj;
	vector<int> parent;
	vector<int> depth;
	vector<int> maxDepth;
	void reroot_internal(int r, int back) {
		if(back == -1) {
			depth[r] = 0;
			parent[r] = r;
		} else {
			depth[r] = depth[back] + 1;
			parent[r] = back;
		}
		maxDepth[r] = depth[r];
		
		iter(vector<int>, adj[r], i)
			if(*i != back) {
				reroot_internal(*i, r);
				if(maxDepth[*i] > maxDepth[r])
					maxDepth[r] = maxDepth[*i];
			}
	}
public:
	Tree(int n) {
		adj.resize(size = n);
		parent.resize(n);
		depth.resize(n);
		maxDepth.resize(n);
	}
	void connect(int a, int b) {
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	void reroot(int r) {
		reroot_internal(r, -1);
	}
	int getParent(int n) {
		return parent[n];
	}
	int getDepth(int n) {
		return depth[n];
	}
	int getMaxDepth(int n) {
		return maxDepth[n] - depth[n];
	}
};

int main() {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	int n, u, v, l, m, x;
	cin >> n >> u >> v;
	Tree t(n);
	u--; v--;
	x = u;
	for(int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		t.connect(--a, --b);
	}
	
	t.reroot(v);
	l = t.getDepth(u);
	m = (l - 1)/2;
	for(int i = 0; i < m; i++)
		x = t.getParent(x);
	cout << (m + t.getMaxDepth(x) + !(l & 1));
	return 0;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ff first 
#define ss second
#define mod 1000000007
#define lim 100005
#define nfs_mw ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

ll dp[1<<21][22] = {};

int main()
{
	nfs_mw;
	int i,j,n,comp[21] = {},v,mask;
	cin>>n;
	for(i=1; i<=n; i++)
		for(j=0; j<n; j++){
			cin>>v;
			comp[i] |= (v<<j);
		}

	dp[0][0] = 1;
	
	for(i=1; i<=n; i++)
		for(mask=1; mask<(1<<n); mask++){
			if(__builtin_popcount(mask) != i) continue;
			int p = mask&comp[i];
			while(p){
				int match = p&(-p);
				dp[mask][i] = (dp[mask][i] + dp[mask^match][i-1])%mod;
				p ^= match;
			}
		}

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

Measured memory_bytes: 360704
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	d := iScan()
	ans := 0
	for i := 0; i < n; i++ {
		x, y := iScan(), iScan()
		if x*x+y*y <= d*d {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4892
S = raw_input()
N = len(S)
r = 0
for i in range(1<<(N-1)):
  t = S[N-1]
  si = 0
  for j in range(N-1):
    x = S[N-2-j]
    if (1<<j & i)>0:
      si += int(t)
      t = x
    else:
      t = x+t
  si += int(t)
  r += si
print r

Measured memory_bytes: 2568
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int,int> pii;
typedef std::pair<int,double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;



void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int wc = 0, rc = 0;
    for(auto e:s){
        if (e=='W') wc++;
        else rc++;
    }
    
    int ans = 0;
    rep(i,rc){
        if (s[i] == 'W') ans++;
    }
    
    cout << ans;
}


int main(){
    int T;
    //cin >> T;
    T = 1;
    while(T--){
        solve();
        cout << endl;
    }
}











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

using namespace std;
typedef long long ll;
ll inf = (ll)1 << 60;

ll n;
vector<vector<ll>> v;
vector<ll> cost;
vector<ll> dp;

ll getval(ll mask) {
    vector<ll> on;
    for(ll i = 0; i < n; i++) {
        if(mask & (1<<i)) {
            on.push_back(i);
        }
    }

    ll total = 0;
    for(ll i = 0; i < on.size(); i++) {
        for(ll j = i+1; j < on.size(); j++) {
            total += v[on[i]][on[j]];
        }
    }

    return total;
}

ll solve(ll mask) {
    if(dp[mask] != -inf) return dp[mask];
    if(mask == 0) return 0;
    ll val = cost[mask];

    for(ll sub = mask; sub; sub = (sub-1)&mask) {
        if(sub == mask) continue;
        val = max(val, solve(sub) + solve(mask^sub));
    }

    return dp[mask] = val;
}

int main() {
    cin >> n;

    dp.resize(1<<n,-inf);
    v.resize(n,vector<ll>(n));

    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j < n; j++) {
            cin >> v[i][j];
        }
    }

    cost.resize(1<<n,-inf);
    for(ll i = 0; i < 1<<n; i++) {
        cost[i] = getval(i);
    }

    cout << solve((1<<n)-1) << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int n, k;
    cin >> n >> k;
    int sum = 0;
    rep(i, n)
    {
        int x;
        cin >> x;
        int left = abs(2 * x);
        int right = abs(2 * (k - x));
        sum += min(left, right);
    }
    cout << sum << endl;
}

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

int main (){
  int n;
  cin >> n;
  vector<int> v(n);
  int total_xor = 0;
  int ans = 0 ;
  for(int i = 0; i<n; i++) {
    cin >> v[i];
    total_xor ^= v[i];
  }

  for(int i = 0; i <n; i ++) {
    cout << (total_xor ^ v[i]) << ' ';
  }
}

Measured memory_bytes: 4040
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ ) {
    if ( A[j] <= x ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i + 1;
}

int main() {
  int i, q;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  q = partition(0, n - 1);

  for ( i = 0; i < n; i++ ) {
    if ( i ) printf(" ");
    if ( i == q ) printf("[");
    printf("%d", A[i]);
    if ( i == q ) printf("]");
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 992
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m;
	cin >> n >> m;

	cout << (n==m ? "Yes" : "No") << '\n';
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
#define RANGE 100000

typedef struct Node{
  int parent;
  int left;
  int right;
}Node;
struct Node T[RANGE];

int main(){
  int id,k,i,j,n,m,d[RANGE];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=NIL;
    T[i].left=RANGE;
    T[i].right=RANGE;
    d[i]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);
    if(k == 1){
      scanf("%d",&T[id].left);
      m=T[id].left;
      T[m].parent=id;
    }
    else if(k>1){
      scanf("%d",&T[id].left);
      m=T[id].left;
      for(j=1;j<k;j++){
	scanf("%d",&T[m].right);
	T[m].parent=id;
	m=T[m].right;
      }
      T[m].parent=id;
    }
  }
  for(i=0;i<n;i++){
    m=T[i].parent;
    while(1){
      if(m==NIL){
	break;
      }
      else{
	m=T[m].parent;
	d[i]++;
      }
    }
    printf("node %d: parent = %d, depth = %d,",i,T[i].parent,d[i]);
	   if(T[i].parent==NIL){
	     if(T[i].left==RANGE){
	       printf(" root, []\n");
	     }
	     else{
	       printf(" root, [%d",T[i].left);
	       m=T[i].left;
	       while(T[m].right!=RANGE){
		 printf(", %d",T[m].right);
		 m=T[m].right;
	       }
	       printf("]\n");
	     }
	   }
	   else if(T[i].left == RANGE) printf(" leaf, []\n");
	   else{
	     printf(" internal node, [%d",T[i].left);
	     m=T[i].left;
	     while(T[m].right!=RANGE){
	       printf(", %d",T[m].right);
	       m=T[m].right;
	     }
	     printf("]\n");
	   }
	   } 
      return 0;
  }



Measured memory_bytes: 3356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string[] hm = Console.ReadLine().Split(':');
                int hh= int.Parse(hm[0]);
                int mm = int.Parse(hm[1]);
                decimal hr = 30*hh+(decimal)0.5*mm;
                decimal sr = 6 * mm;
                decimal r = Math.Min(Math.Abs(hr-sr),360-Math.Abs(hr-sr));
                if (r >= 0 && r < 30) Console.WriteLine("alert");
                else if (r >= 90 && r <= 180) Console.WriteLine("safe");
                else Console.WriteLine("warning");
            }
        }
    }
}

Measured memory_bytes: 19736
#include <stdio.h>
     
    int main(){
      int k,x;
      if(scanf("%d",&k)==1 && scanf("%d",&x)==1){
        if(k >= 1 && k <= 100 && x >=0 && x <= 100){
          for(int i = x-k+1;i < x+k;i++){
            printf("%d ",i);
          }
        }else printf("error");
      }else printf("error");
    }

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>

using namespace std;
int main() {
    int N; cin >> N;
    vector<int> v(N);
    for(int i=0; i<N; ++i) cin >> v[i];
     
    int ans=0;
    int cnt=0;
	for(int i=0; i<N-1; ++i){
        if(v[i]==v[i+1]) cnt++;
        if(v[i]!=v[i+1]||i==N-2){
            ans += (cnt+1)/2;
            cnt=0;
        }
        
    }
    cout << ans << endl;
		return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;

int N,M;
int A[1111],B[1111];

signed main(){
    cin>>N>>M;
    rep(i,N)cin>>A[i];
    rep(i,M)cin>>B[i];

    sort(A,A+N);sort(B,B+M);

    int ans=1;

    int h=0,w=0;
    for(int i=N*M;i>=1;i--){
        bool fh=h<N&&A[N-h-1]==i;
        bool fw=w<M&&B[M-w-1]==i;

        if(fh&&fw){
            h++;w++;
        }
        else if(fh){
            h++;
            ans=ans*w%mod;
        }
        else if(fw){
            w++;
            ans=ans*h%mod;
        }
        else{
            ans=ans*max(0ll,h*w-(N*M-i))%mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main(){
  ll H,W;
  cin>>H>>W;
  if (H*W%3==0) {
    cout<<0<<endl;
    return 0;
  }
  ll X=H,Y=W;
  ll ans = INF;
  for (ll i=1;i<Y;i++){
    ll S1 = i*X;
    ll S2,S3;
    ll mm;
    ll D;

    D = (Y-i)/2;
    S2 = D*X;
    S3 = (Y-i-D)*X;
    mm = max(S1,max(S2,S3)) - min(S1,min(S2,S3));
    ans = min(ans,mm);
    D = X/2;
    S2 = (Y-i)*D;
    S3 = (Y-i)*(X-D);
    mm = max(S1,max(S2,S3)) - min(S1,min(S2,S3));
    ans = min(ans,mm);
  }

  X=W;Y=H;
  for (ll i=1;i<Y;i++){
    ll S1 = i*X;
    ll S2,S3;
    ll mm;
    ll D;

    D = (Y-i)/2;
    S2 = D*X;
    S3 = (Y-i-D)*X;
    mm = max(S1,max(S2,S3)) - min(S1,min(S2,S3));
    ans = min(ans,mm);
    D = X/2;
    S2 = (Y-i)*D;
    S3 = (Y-i)*(X-D);
    mm = max(S1,max(S2,S3)) - min(S1,min(S2,S3));
    ans = min(ans,mm);
  }

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


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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b;
  cin >> a >> b;
  cout << a*b << ' ' << 2*a + 2*b << endl;
  return 0;
}



Measured memory_bytes: 3012
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[200010];
    rep(i, N) cin >> A[i];
    int lower = -INF, upper = INF;
    int ans2 = INF2;
    while(lower < upper - 2) {
        int mid1 = (lower * 2 + upper) / 3;
        int mid2 = (lower + upper * 2) / 3;
        int k1 = 0, k2 = 0;
        rep(i, N) {
            k1 += abs(A[i] - (mid1 + i + 1));
            k2 += abs(A[i] - (mid2 + i + 1));
        }
        if(k1 < k2) upper = mid2;
        else lower = mid1;
    }
    REP(i, lower, upper) {
        int k = 0;
        rep(j, N) {
            k += abs(A[j] - (i + j + 1));
        }
        ans2 = min(ans2, k);
    }
    cout << ans2 << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int[] num = { a, b, c };
        Arrays.sort(num);
        int max = num[2];
        for(int i = 0;i < k;i ++){
            max *= 2;
        }
        int ans = num[0] + num[1] + max;
        System.out.println(ans);
    }
}

Measured memory_bytes: 21460
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        int ci;
        
        int[][] aij = new int[n][m];
        int[] bj = new int[m];
        
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                aij[i][j] = sc.nextInt();
            }
        }
        for(int j = 0; j < m; j++){
               bj[j] = sc.nextInt();
        }
        
        for(int i = 0; i < n; i++){
            ci = 0;
            for(int j = 0; j < m; j++){
               ci += aij[i][j]*bj[j];
            }
            System.out.println(ci);
        }
    }
}


Measured memory_bytes: 40536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{

    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            int c0 = s.Count(x => x == '0');
            Console.WriteLine(Math.Min(c0, s.Length - c0) * 2);
        }
        

    }
}


Measured memory_bytes: 11360
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 100005
#define oo 1000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

struct coin {
    int a, b, c;
};

bool cmpBC(const coin &a, const coin &b) {
    return (a.b-a.c > b.b-b.c);
}

int x, y, z;
ll dpB[maxN], dpC[maxN];
coin c[maxN];

int main () {
    scanf("%d%d%d", &x, &y, &z);
    fto(i, 1, x+y+z) scanf("%d%d%d", &c[i].a, &c[i].b, &c[i].c);

    sort(c+1, c+x+y+z+1, cmpBC);
//    fto(i, 1, x+y+z) printf("%d %d %d\n", c[i].a, c[i].b, c[i].c);
    multiset<int> s;

    ll sum;
    sum = 0;
    fto(i, 1, x+y+z) {
        s.insert(c[i].b-c[i].a);
        sum += c[i].b;
        if (sz(s) > y) {
            sum -= *s.begin();
            s.erase(s.begin());
        }
        dpB[i] = sum;
    }

    s.clear();
    sum = 0;
    fdto(i, x+y+z, 1) {
        s.insert(c[i].c-c[i].a);
        sum += c[i].c;
        if (sz(s) > z) {
            sum -= *s.begin();
            s.erase(s.begin());
        }
        dpC[i] = sum;
    }

    ll ans = 0;
    fto(i, y, x+y) ans = max(ans, dpB[i]+dpC[i+1]);
//    fto(i, 1, x+y+z) printf("%lld %lld\n", dpB[i], dpC[i]);


    cout << ans;

    return 0;
}


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

#define INF_LL (int64_t)1e18
#define INF (int32_t)1e9

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

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

  vector<vector<int>> s(M);
  vector<int> p(M);

  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    s[i].resize(k);
    for (auto&& e : s[i]) {
      cin >> e;
      e--;
    }
  }
  for (auto&& e : p) cin >> e;

  int res = 0;
  for (int sw = 0; sw < (1 << N); sw++) {
    int cnt = 0;
    for (int i = 0; i < M; i++) {
      int on = 0;
      for (int j = 0; j < s[i].size(); j++) {
        on += (sw >> s[i][j] & 1);
      }
      cnt += (on % 2 == p[i]);
    }
    res += (cnt == M);
  }
  cout << res << endl;
}


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

bool is_valid(long long b, long long n, long long s);

int main() {
    long long n, s;
    cin >> n >> s;
    if (n == s){
        cout << n + 1 << endl;
        return 0;
    }
    for (long long b = 2; b != 1000000; ++b){
        if (is_valid(b, n, s)){
            cout << b << endl;
            return 0;
        }
    }
    // p*b + q = n
    // p   + q = s
    // p*(b - 1) = n - s
    long long d = n - s;
    long long b = -1;
    for (long long p = 1; p*p <= d; ++p){
        if (d % p == 0){
            long long tmp = d / p + 1LL;
            long long q = s - p;
            if (tmp > p and q < tmp and q >= 0){
                b = tmp;
            }
        }
    }
    cout << b << endl;
    return 0;
}



bool is_valid(long long b, long long n, long long s){
    long long c = 0;
    while (n){
        c += n % b;
        n /= b;
    }
    return c == s;
}


Measured memory_bytes: 256
import heapq
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        return heapq.heappop(self.hq) * self.sign
 
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
 
    def top(self):
        return self.hq[0] * self.sign

q = int(input())
queries = [tuple(map(int, input().split())) for i in range(q)]
INF = 10 ** 12
small = Heapq([-INF],desc=True)
large = Heapq([INF])
fx_min = queries[0][2]
median = queries[0][1]
k = 0
for query in queries[1:]:
  if query[0] == 1:
    k += 1
    a,b = query[1],query[2]
    fx_min += abs(median-a) + b
    small_max, large_min = small.top(), large.top()
    if k % 2: 
      if (a <= median):
        small.push(a)
        large.push(median)
        median = small.top()
      else:
        small.push(median)
        large.push(a)
    else:
      if (a <= small_max):
        small.pop()
        small.push(a)
      elif (small_max < a <= large_min):
        fx_min -= abs(median-a)
        median = a
      else:
        large.push(a)
        newmed = large.pop()
        fx_min -= abs(median-newmed)
        median = newmed 
  else:
    print(median,fx_min)

Measured memory_bytes: 111960
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D ;
  // int A[N];

  while(1){
    C = C - B;
    if(C<=0){
      cout << "Yes" << endl;
      break;
    }
    A = A - D;
    if(A<=0){
      cout << "No" << endl;
      break;
    }
  }


}

Measured memory_bytes: 3636
import math

n = int(input())
town = [tuple(map(int, input().split())) for _ in range(n)]

D = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    for j in range(n):
        if i == j:
            D[i][j] = 0
        else:
            D[i][j] = math.sqrt((town[i][0]-town[j][0])**2 + (town[i][1]-town[j][1])**2)

print(sum([sum(k) for k in D]) / n)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>

using namespace std;

#define index(i,k) i-1+k

int min_cost_bottomup(int*,int,int);

int main()
{
    int N,K;
    cin >> N >> K;
    int *h;
    h = new int[N+K];
    for(int i=0;i<K;i++){
        h[i]=pow(10,5);
    }
    for(int i=1;i<=N;i++){
        cin >> h[index(i,K)];
    }

    cout << min_cost_bottomup(h,N,K) << endl;

    return 0;
}

int min_cost_bottomup(int *h, int N, int K)
{
    long long *m;
    m = new long long[N+K];
    for(int i=0;i<K;i++){
        m[i]=pow(10,5);
    }
    m[index(1,K)]=0;
    
    int cost,min;
    for(int i=2;i<=N;i++){
        min = m[index(i-1,K)] + abs(h[index(i,K)]-h[index(i-1,K)]);
        for(int j=2;j<=K;j++){
            cost = m[index(i-j,K)] + abs(h[index(i,K)]-h[index(i-j,K)]);
            if(cost<min){
                min = cost;
            }
        }
        m[index(i,K)]=min;
    }
    return m[index(N,K)];
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {
	/*
	boolean[] furui() {
		boolean[] tab = new boolean[100000001];
		tab[0] = tab[1] = true;
		for (int i = 2; i <= tab.length/2; i++) {
			if (tab[i]) continue;
			for (int j = i + i; j < tab.length; j+=i) {
				tab[j] = true;
			}
		}
		return tab;
	}*/

	boolean isPrime(int x) {
		if (x==2) return true;
		if (x < 2 || x % 2 == 0) return false;
		for (int i = 3; i <= Math.sqrt(x); i += 2) {
			if (x % i == 0) return false;
		}
		return true;
	}

	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] ary = new int[n];
		for (int i = 0; i < n; i++) {
			ary[i] = scan.nextInt();
		}
		//boolean[] table = furui();
		int count = 0;
		for (int i = 0; i < ary.length; i++) {
			/*
			if (table[ary[i]] == false) {
				count++;
				System.out.println(ary[i]);
			}*/
			if (isPrime(ary[i])) {
				count++;
			}
		}
		System.out.println(count);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}



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

typedef long long ll;
typedef pair<ll, ll> P;

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

const ll MAX = 2 * 1e3 + 10;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int N, M, S[MAX], T[MAX];
ll dp[MAX][MAX], sum[MAX][MAX];

int main(){
    cin >> N >> M;
    rep(i, N) cin >> S[i];
    rep(i, M) cin >> T[i];

    rep(i, N)rep(j, M){
        if(S[i] == T[j]){
            dp[i+1][j+1] = (sum[i][j] + 1) % MOD;
        } else {
            dp[i+1][j+1] = 0;
        }
        sum[i+1][j+1] = (sum[i][j+1] + sum[i+1][j] - sum[i][j] + dp[i+1][j+1]) % MOD;
        if(sum[i+1][j+1] < 0) sum[i+1][j+1] += MOD;
    }

    ll ans = (sum[N][M] + 1) % MOD;
    
    cout << ans << endl;
}

Measured memory_bytes: 63232
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll a,b;
string s;
cin>>a>>s>>b;
char q=s.at(b-1);
rep(i,a){
if(s.at(i)==q){
cout << q;}
else{
cout << "*";}}
cout <<endl;}


Measured memory_bytes: 3600
#include<stdio.h>

int main(){
    int N, M, X;
    int A[110];
    int tmp;
    int sumR=0, sumL=0;
    int i;

    scanf("%d %d %d", &N, &M, &X);
    for(i=0; i<N; i++){
        A[i]=0;
    }
    A[N] = -1;
    A[X] = -1;
    for(i=0; i<M; i++){
        scanf("%d", &tmp);
        A[tmp] = 1;
    }
    for(i=0; i<X; i++){
        if(A[i]==1){
            sumL += 1;
        }
    }
    for(i=X; i<=N; i++){
        if(A[i]==1){
            sumR += 1;
        }
    }
    //printf("%d %d ", sumL, sumR);
    if(sumL<sumR){
        printf("%d", sumL);
    }else{
        printf("%d", sumR);
    }

    return 0;
}

Measured memory_bytes: 128
###ncrのmodあまりの話
mod=10**9+7
N=100005
kaidan=[1 for i in range(N)]
gyaku=[1 for i in range(N)]
for i in range(1,N):
    kaidan[i] = (i * kaidan[i-1])%mod
    gyaku[i]=pow(kaidan[i], mod-2, mod)
def comb(a,b):
    return kaidan[a]*gyaku[b]*gyaku[a-b]
n,m=map(int,input().split())
if abs(n-m)>=2:
    print(0)
else:
    if n==m:
        print(kaidan[n]*kaidan[n]*2%mod)
    else:
        a=max(n,m)
        b=min(n,m)
        print(kaidan[a]*kaidan[b]%mod)

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

int main() {
	string S,T;
	cin >> S >> T;
	int ss = 0;
	for(int i = 0;i < 3 ;i++)
	{
		if(S.at(i) == T.at(i))
		{
			ss++;
			}
  }
  cout << ss << endl;
}


Measured memory_bytes: 256
a,b,c,=map(int,input().split())
k=int(input())
while k>0:
    if max(a,b,c)==c:
        c=2*c
        k-=1
    elif max(a,b,c)==b:
        b=2*b
        k-=1
    else:
        a=2*a
        k-=1
print(sum([a,b,c]))

Measured memory_bytes: 3060
lst = []
min = int(input())
for i in range(4):
    x = int(input())
    if x%10 != 0 and x%10 <= min%10:
       lst.append(min)
       min = x
    else:
        lst.append(x)
sum = 0
for i in lst:
    if i%10 == 0:
        sum += i
    else:
        sum += (i//10)*10 + 10
print(sum+min)

Measured memory_bytes: 3060