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

int dp[10];

int fact(int n){
    dp[1] = 1;
    if(dp[n]!=-1){
        return dp[n];
    }else{
        return dp[n] = n*fact(n-1);
    }
}
int main(){
    int n,sum1=1,sum2=1;
    cin >> n;
    int a[n+1];
    for(int i=0;i<=n;i++){
        dp[i] = -1;
        a[i] = i-1;
    }
    for(int i=n-1;i>=0;i--){
        int p;
        cin >> p;
        sum1+= a[p] * fact(i);
        for(int j=p+1;j<=n;j++){
            a[j]--;
        }
    }

    for(int i=0;i<=n;i++){
        a[i] = i-1;
    }

    for(int i=n-1;i>=0;i--){
        int p;
        cin >> p;
        sum2+= a[p] * fact(i);
        for(int j=p+1;j<=n;j++){
            a[j]--;
        }
    }

    if(sum1>sum2){
        cout << sum1-sum2;
    }else{
        cout << sum2-sum1;
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    void solve(){
        Scanner sc = new Scanner(System.in);
            int W = sc.nextInt();
        int H = sc.nextInt();
        String c= sc.next();
        for ( int i = 0; i < H; i++ ){
            for ( int j = 0; j < W; j++ ){
                if ( i == 0 && j == 0 || i == 0 && j == W-1 ||
                     i == H-1 && j == 0 || i == H-1 && j == W-1 ){
                    System.out.print("+");
                } else if ( i == 0 || i == H-1 ){
                    System.out.print("-");
                } else if ( j == 0 || j == W-1 ){
                    System.out.print("|");
                } else if ( i == H/2 && j == W/2 ){
                    System.out.print(c);
                } else {
                    System.out.print(".");
                }
            }
            System.out.println();
        }
    }
    public static void main(String[] args){ new Main().solve(); }
}



Measured memory_bytes: 26192
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def sol():
    N, x = map(int, input().split())

    if x == 1 or x == 2 * N - 1:
        print('No')
    else:
        print('Yes')
        ans = [None] * (2 * N - 1)
        numList = list(range(1, 2 * N))

        for i in range(3):
            ans[N - 2 + i] = x - 1 + i
            numList[x - 2 + i] = None
        if x > N:
            ans[N + 1] = 1
            numList[0] = None
        elif x < N:
            ans[N - 3] = 2 * N - 1
            numList[2 * N - 2] = None

        numList = list(filter(lambda n: n != None, numList))
        now = 0
        for a in ans:
            if a == None:
                print(numList[now])
                now += 1
            else:
                print(a)



sol()

Measured memory_bytes: 14552
while True:
    x = input()
    x = x.split(" ")
    a = int(x[0])
    op = str(x[1])
    b = int(x[2])
    
    if(op =="?"):
        break
    
    if(op == "+"):
        print(a+b)
        
    if(op == "-"):
        print(a-b)

    if(op == "*"):
        print(a*b)

    if(op == "/"):
        print(a//b)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  int mi=1001;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    mi=min(mi,a);
    x-=a;
  }
  cout<<n+(x/mi);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define FO(i,a,b) for (int i = a; i <= b; i++)
#define FOb(i,a,b) for(int i=b;i>=a;i--)
#define vi vector<int>
#define vulli vector<unsigned long long int>
using namespace std;
typedef unsigned long long int ulli;
int fact(int n){
    int f = 1;
    FO(i,2,n)
        f *= i;
    return f;
}
double dist(int i,int j,vi x ,vi y){
    double distance = ( (x[i] - x[j]) * (x[i] - x[j]) ) + ( (y[i] - y[j]) * (y[i] - y[j]) );
    return sqrt(distance);
}
void solve()
{   
    int n,k;
    double num = 0;
    cin >> n;
    k = n;
    vector<int> x(n+1),y(n+1);
    x[0] = y[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> x[i] >> y[i];
    }
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            num += dist(i,j,x,y) * 2;
    cout << fixed << setprecision(10) << num /n ;
}                                             
int main()
{
    std::ios_base::sync_with_stdio(false);
    ulli t=1;
   // cin>>t;   
    while(t--){ solve(); cout<<"\n"; }
    return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
typedef long long ll;
using namespace std;
const int k_mod = ( int )1e9 + 7;
void chmin (int &a, int b){
	if (a > b){
		a = b;
	}
}
int main( void ){
	int n;
	cin >> n;
	int* steps = new int[ n ]();
	rep( i, 0, n ){
		cin >> steps[ i ];
	}
	vector <int> dp_cost( n, k_mod );
	dp_cost[ 0 ] = 0;
	dp_cost[ 1 ] = abs( steps[ 1 ] - steps[ 0 ] );
	rep( i, 2, n ){
		rep(j,1,3){
			chmin(dp_cost[i], dp_cost[ i - j ] + abs( steps[ i ] - steps[ i - j ] ));
		}
	}
	printf( "%d\n", dp_cost[ n - 1 ] );
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*/
#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
    vector <string> v;
    stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x);
    return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
    cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
    err(++it, args...);
}
 
int ini(){int x; scanf("%d",&x);return x;}
long long inl(){ long long x;scanf("%lld",&x); return x;}
double ind(){double x; scanf("%lf",&x);return x;}
#define Iin ini();
#define Lin inl();
#define Din ind();

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;



int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int t=1,te=0;
    //cin>>t;
    while(t--){
        int a,b,c;
        cin>>a>>b>>c;

        if(a==b and b==c and c==a)printf("No\n");
        else if(a==b or b==c or c==a)printf("Yes\n");
        else{
            printf("No\n");
        }

        //printf("Case %d: ",++te);
    }
    return 0;
}




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

#define LLINF (1LL<<60)
typedef long long ll;

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

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

//C++14 (GCC 5.4.1)
int main() {
    int N;
    cin >>N;

    vector<int> H(N);
    rep(i,N) cin >> H[i];
    
    //-----------------------------------
    vector<int> I(N,INFINITY);
    I[0]=0;
    I[1]=abs(H[1]-H[0]);
    repd(i,2,N){
      I[i]=I[i-2]+abs(H[i]-H[i-2]);
        chmin(I[i],I[i-1]+abs(H[i]-H[i-1]));
    }
    cout << I[N-1] <<endl;
    return (0);
}

Measured memory_bytes: 1024
package main
 
import (
  "fmt"
)

func main() {
 
  var num int
  var count int = 0
  fmt.Scan(&num)
  arr := make([]int, num)
    
  for i := 0; i < num; i++ {
    fmt.Scan(&arr[i])
    if arr[i] != i + 1 {
      count++
    }
  }
  
  if count <= 2 {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2000 + 5;
int arr[maxn];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> arr[i];
    ll res = 0;
    sort(arr, arr + n);
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j + 1 < n; ++j) {
            auto ptr = lower_bound(arr + j + 1, arr + n, arr[i] + arr[j]);
            res += ptr - (arr + j + 1);
        }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;


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

	ll N;
	cin >> N;

	string s;
	cin >> s;

	ll r = 0;
	ll b = 0;

	for (auto c : s)
	{
		if (c == 'R')
		{
			r++;
		}
		else
		{
			b++;
		}
	}

	if (r > b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	//system("pause");
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

li n, a[57], c;

int main () {
    fastIO;
    cin >> n;
    for(li i = 0; i < n; i ++) cin >> a[i];
    for(li i = 0; i < n; i ++) {
        if(a[i]!=i+1) c++;
    }
    if(c>2) cout << "NO";
    else cout << "YES";
}


Measured memory_bytes: 256
import Control.Monad
import Data.List
import Data.Array
main=do
    [h,w]<-map read.words<$>getLine::IO[Int]
    a <- array ((1,1),(h,w)).concatMap (\(v,wl)->map (\(u,c)->((v,u),c)) wl).zip [1..] <$> replicateM h (zip [1..]<$>getLine)
    putStrLn $ case find (f a) [(i,j)|i<-[1..h-1], j<-[1..w-1]] of
        Just(_) -> "Impossible"
        Nothing -> "Possible"

f a (i,j)
    | a!(i,j+1)=='#'&&a!(i+1,j)=='#' = True
    | otherwise = False



Measured memory_bytes: 508
s = input()
count_0 = 0
count_1 = 0
for i, si in enumerate(s):
    if i % 2 == 0 and si == '1':
        count_0 += 1
    elif i % 2 == 1 and si == '0':
        count_0 += 1

for i, si in enumerate(s):
    if i % 2 == 0 and si == '0':
        count_1 += 1
    elif i % 2 == 1 and si == '1':
        count_1 += 1

print(min(count_0, count_1))

Measured memory_bytes: 3188
h, w = map(int, input().split())
maze = []
def where(step):
    hh = step // w
    tmp = step - (w*hh)
    if hh % 2 == 0:
        ww = tmp
    else:
        ww = w-1-tmp
    return [hh, ww]

for _ in range(h):
    l = map(int, input().split())
    l = list(l)
    maze.append(l)

res = []
for i in range(h*w - 1):
    hh1, ww1 = where(i)
    hh2, ww2 = where(i+1)
    #print(hh1, ww1,hh2,ww2)
    if maze[hh1][ww1] % 2 == 1:
        maze[hh2][ww2] += 1
        res.append((hh1,ww1,hh2,ww2))
#print(res)

print(len(res))
for i in range(len(res)):
    a,b,c,d = res[i]
    print(a+1,b+1,c+1,d+1)


Measured memory_bytes: 98916
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> a(m);
    int dp[n + 1] = {};
    rep(i,m){
        cin >> a[i];
        dp[a[i]]++;
    }
    int ans = min(count(dp, dp + x, 1),count(dp + x, dp + n + 1, 1));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

	string key = "keyence";

	int left, right;
	int count = 0;
	left = 0;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == key[left])
		{
			left++;
			count++;
		}
		else break;
	}

	right = key.size() - 1;
	for (int i = S.size() - 1; i >= 0; i--)
	{
		if (S[i] == key[right])
		{
			right--;
			count++;
		}
		else break;
	}

	if(count >= key.size())
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

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

int main() {
	int n; scanf("%d", &n);

	map <string, int> mp;

	int mx = 0;
	for(int i = 1; i <= n; i++) {
		char a[15]; scanf("%s", a);
		string s = a;
		mp[s]++;
		mx = max(mx, mp[s]);
	}

	for(auto o : mp) {
		if(o.second == mx)
			printf("%s\n", o.first.c_str());
	}

	return 0;
}

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

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

Measured memory_bytes: 764
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }
static const int MODVAL = 1000000007;
struct mint {
  int val;
  mint():val(0){}
  mint(int x):val(x%MODVAL) {}
  mint(size_t x):val(x%MODVAL) {}
  mint(long long x):val(x%MODVAL) {}
  mint& operator+=(mint y) { val+=y.val; if(val>=MODVAL) val-=MODVAL; return *this; }
  mint& operator-=(mint y) { val-=y.val; if(val<0) val+= MODVAL; return *this; }
  mint& operator*=(mint y) { val=(val*(long long)y.val)%MODVAL; return *this; }
  mint& operator/=(mint y) { val=(val*inv(y.val,MODVAL))%MODVAL; return *this; }
};
inline mint operator+(mint x, mint y) { return x+=y; }
inline mint operator-(mint x, mint y) { return x-=y; }
inline mint operator*(mint x, mint y) { return x*=y; }
inline mint operator/(mint x, mint y) { return x/=y; }
mint POW(mint x, long long n) { mint r(1); for(;n;x*=x,n>>=1) if(n&1) r*=x; return r; }
mint FAC(int n) { static vector<mint> FAC_(1,1);
  while(int(FAC_.size())<=n) FAC_.push_back(FAC_.back()*FAC_.size()); return FAC_[n]; }
inline mint CMB(int n, int k) { return k<0||n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
inline ostream& operator<<(ostream& os, mint a) { return os << a.val; }

int N;
int as[110];

mint dp[110][100000+10];
mint cs[110][100000+10];

int main(void) {
  int K;
  scanf("%d%d", &N, &K);
  REP(i, N) {
    scanf("%d", &as[i]);
  }
  dp[0][0] = 1;
  REP(i, N) {
    REP(j, K+1) {
      cs[i][j+1] = cs[i][j] + dp[i][j];
    }
    REP(j, K+1) {
      dp[i+1][j] = cs[i][j+1] - cs[i][max(0, j-as[i])];
    }
  }
  cout << dp[N][K] << endl;
  return 0;
}


Measured memory_bytes: 86144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    string a,b,c,ans;
    cin >> a >> b >> c;
    if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
L.reverse()
par = []
rank = [0]*N
size = [1]*N
for i in range(N):
  par.append(i)
def find(x,par):
  if x == par[x]:      
    return x
  else:
    return find(par[x],par)
def unite(x,y,par,rank,size):
  x = find(x,par)
  y = find(y,par)          
  if x != y:
    if rank[x] < rank[y]: 
      par[x] = y
      size[y] += size[x]
    else:
      par[y] = x
      size[x] += size[y]
      if rank[x] == rank[y]:
        rank[x] += 1
def same(x,y,par):
  return find(x,par) == find(y,par)

res = []
for i in range(M):
  A = find(L[i][0]-1,par)
  B = find(L[i][1]-1,par)
  if A == B:
    res.append(0)
  else:
    res.append(size[A]*size[B])
    unite(A,B,par,rank,size)
ans = 0
for i in range(M):
  ans += res[M-i-1]
  print(ans)

Measured memory_bytes: 35420
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int s,w;
int main() {
	cin >> s >> w;
	if (w >= s) {
		cout << "unsafe";
	} else cout << "safe";
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str, strtmp;
    int shuf, tmp;
    while (1) {
        cin >> str >> shuf;
        if (str == "-") break;
        for (int i=0; i < shuf; i++) {
            cin >> tmp;
            strtmp = str.substr(0, tmp);
            str.erase(0, tmp);
            str = str + strtmp;
        }
        cout << str << endl;
    }
}


Measured memory_bytes: 3172
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int cnt = 0;
            for(int i=0; i < 4; i++)
            {
                if (s[i] == '2') cnt++;
            }
            Console.WriteLine(cnt);
        }
    }
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N;
  string S;
  cin>>N>>S;
  vector<vector<ll>> v(26);
  for(ll i = 0LL; i < N; i++){
    int t = S[i]-'a';
    v[t].push_back(i);
  }
  ll Q;
  cin>>Q;
  for(ll i = 0LL; i < Q; i++){
    ll a;
    cin>>a;
    if(a==1LL){
      ll b;
      char c;
      cin>>b>>c;
      b--;
      int t = S[b]-'a';
      auto er = lower_bound(v[t].begin(),v[t].end(),b);
      v[t].erase(er);
      ll s = c-'a';
      auto ite = lower_bound(v[s].begin(),v[s].end(),b);
      v[s].insert(ite,b);
      S[b]=c;
    }
    if(a==2LL){
      ll l,r;
      cin>>l>>r;
      l--;
      r--;
      ll cnt = 0LL;
      for(int i = 0; i < 26; i++){
        auto ite = lower_bound(v[i].begin(),v[i].end(),l);
        if(ite==v[i].end()) continue;
        if(*ite<=r)cnt++;
      }
      cout<<cnt<<endl;
    }
  }
}

Measured memory_bytes: 6916
import           System.IO
import           Control.Monad
import           Control.Applicative
import           Control.Monad.State

kuku :: [String]
kuku =
  [ show a ++ "x" ++ show b ++ "=" ++ show (a * b)
  | a <- [1 .. 9]
  , b <- [1 .. 9]
  ]

main = mapM putStrLn kuku



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,b,ans=0;
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++){
       int x=i,sum=0;
        while(x!=0){
            sum+=x%10;
            x/=10;
             
        }
        if(sum>=a && sum<=b){
            
            ans+=i;
            continue;
        }
    }
    cout << ans << endl;
    
    
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var T = new long[N];
        for (int i = 0; i < N; i++)
        {
            T[i] = long.Parse(ReadLine());
        }
        long ans = T[0];
        for (int i = 0; i < N; i++)
        {
            ans = LCM(ans, T[i]);
        }
        WriteLine(ans);
    }
    static long GCD(long a,long b)
    {
        return a == 0 ? b : GCD(b%a,a);
    }
    static long LCM(long a,long b)
    {
        return a / GCD(a, b) * b;
    }
}


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

using namespace std;

vector<string> v;

int main() { 
    string s, t;
    while (cin >> s >> t) {
        int n = s.length();
        int m = t.length();
        for (int i = 0; i <= n-m; ++i) {
            if (s[i] == '?' || s[i] == t[0]) {
                bool bad = 0;
                for (int j = 0; j < m && !bad; ++j) {
                    if (s[i+j] != '?' && t[j] != s[i+j]) 
                        bad = 1;
                }
                if (!bad) {
                    string tmp = "";
                    for (int j = 0; j < n; ++j) {
                        if (s[j] == '?') {
                            if (j < i || j >= i+m) tmp += 'a';
                            else tmp += t[j-i];
                        } else tmp += s[j];
                    }
                    v.push_back(tmp);
                }
            }
        }
        if (!v.size()) cout << "UNRESTORABLE\n";
        else {
            sort(v.begin(), v.end());
            cout << v[0] << "\n";
            v.clear();
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef complex<double> pt;
typedef pair<pt,pt> L;
typedef vector<P> poly;
const double EPS = 1e-15;
#define x real()
#define y imag()
 
double dot(pt a,pt b){
	return (conj(a)*b).x;
}
double cross(pt a,pt b){
	return (conj(a)*b).y;
}
int ccw(pt a,pt b,pt c){
	b -= a; c -= a;
	if(cross(b,c) > EPS) return 1; // counter clockwise
	if(cross(b,c) < -EPS) return -1; // clockwise
	if(dot(b,c) < -EPS) return 2; //c-a-b
	if(norm(b) < norm(c)) return -2; //a-b-c
	return 0; //a-c-b
}
bool cmp(const pt& a,const pt& b){
	if(-EPS < a.x-b.x && a.x-b.x < EPS) return a.y < b.y;
	else return a.x < b.x;
}
vector<pt>convex_hull(vector<pt>ps)
{
	sort(ps.begin(),ps.end(),cmp);
	int k=0,n = ps.size();
	vector<pt>qs(n*2);
	for(int i=0;i<n;i++)
	{
		while(k>1 && ccw(qs[k-2],qs[k-1],ps[i]) == -1) k--;
		qs[k++] = ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--)
	{
		while(k>t && ccw(qs[k-2],qs[k-1],ps[i]) == -1) k--;
		qs[k++] = ps[i];
	}
	qs.resize(k-1);
	return qs;
}
pt intersect(pt a,pt b,pt c,pt d){
	double dev = (b.y-a.y)*(d.x-c.x)-(b.x-a.x)*(d.y-c.y);
	
	double d1, d2;
 
	d1 = (c.y*d.x-c.x*d.y);
	d2 = (a.y*b.x-a.x*b.y);
 
	pt ap1;
	ap1.x = d1*(b.x-a.x) - d2*(d.x-c.x);
	ap1.x /= dev;
	ap1.y = d1*(b.y-a.y) - d2*(d.y-c.y);
	ap1.y /= dev;
 
	return ap1;
}
bool par(pt a,pt b,pt c,pt d){
	b.x -= a.x; b.y -= a.y;
	d.x -= c.x; d.y -= c.y;
	if(abs(b.y*d.x - b.x*d.y) < EPS){
		return 1;
	}
	return 0;
}
double PI = 3.1415926535897932;
int main(){
	while(1){
		int n; scanf("%d",&n); if(!n) return 0; 
		pt p[305];
		for(int i=1;i<=n;i++){
			double a,b; scanf("%lf%lf",&a,&b);
			p[i] = pt(a,b);
		}
		int ans = 1;
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				pt q = (p[i]+p[j])/2.0;
				pt r = (p[i]-p[j]); if(abs(r) >= 2.0) continue;
				pt p1 = q + r / abs(r) * polar(sqrt(1.0-abs(r)*abs(r)/4.0),PI/2);
				pt p2 = q - r / abs(r) * polar(sqrt(1.0-abs(r)*abs(r)/4.0),PI/2);
				int c=0,d=0;
				for(int k=1;k<=n;k++){
					if(k==i || k==j || abs(p1-p[k]) <= 1.0+EPS) c++;
					if(k==i || k==j || abs(p2-p[k]) <= 1.0+EPS) d++;
				}
				ans = max(ans,max(c,d));
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 3460
<?php

fscanf(STDIN, "%d%d%d", $H, $W, $K);
$map = [];
$map[0] = array_fill(0,$W,0);
for($i=1;$i<=$H;$i++){
    fscanf(STDIN, "%s", $temp);
    $number = 0;
    for($j=0;$j<$W;$j++){
        if($temp[$j] === "1"){
            $number++;
        }
        if(isset($map[$i-1][$j])){
            $map[$i][$j] = $number + $map[$i-1][$j];
        }else{
            $map[$i][$j] = $number;
        }

    }
}

$ans=PHP_INT_MAX;
$ans_temp = 0;
$hiku = 0;
$haba = 0;
for($i=0;$i<$W;$i++){
    if($map[$H][$i] - $hiku > $K){
        if($i - $haba == 0){
            break;
        }
        $i--;
        $haba = $i;
        $hiku = $map[$H][$i];
        $ans_temp++;
    }
}
if($i == $W){
    $ans = min($ans, $ans_temp);
}


$limit = 1;
if($limit == $H){
    echo $ans;
    exit;
}
if($ans <= $limit ){
    echo $ans;
    exit;
}
//1本
for($a=1;$a<pow(2,$H-1);$a++){

    $ans_temp = bitnum($a);
    $haba = array_fill(0,$H,0);
    for($i=0;$i<$W;$i++){
        $flag = 0;
        $last = 0;
        for($j=0;$j<$H;$j++){
            if((pow(2,$j) & $a) != 0 || $j == $H-1){
                if($map[$j+1][$i]- $map[$last][$i] - $haba[$j] > $K){
                    if($i == 0 || $map[$j+1][$i-1]- $map[$last][$i-1]== $haba[$j]){
                        break 2;
                    }
                    $flag = 1;

                }
                $last = $j + 1;
            }
        }
        if($flag == 1){

            $last = 0;
            for($j=0;$j<$H;$j++) {
                if ((pow(2, $j) & $a) != 0 || $j == $H - 1) {
                    $haba[$j] = $map[$j + 1][$i - 1] - $map[$last][$i - 1];
                    $last = $j + 1;
                }
            }
            $i--;
            $ans_temp++;
        }

    }
    if($i == $W){
        $ans = min($ans, $ans_temp);
    }


}

echo $ans;

function bitnum($bits){
    $bits = ($bits & 0x55555555) + ($bits >> 1 & 0x55555555);
    $bits = ($bits & 0x33333333) + ($bits >> 2 & 0x33333333);
    $bits = ($bits & 0x0f0f0f0f) + ($bits >> 4 & 0x0f0f0f0f);
    $bits = ($bits & 0x00ff00ff) + ($bits >> 8 & 0x00ff00ff);
    return ($bits & 0x0000ffff) + ($bits >>16 & 0x0000ffff);
}

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

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

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int A, B, H, M; std::cin >> A >> B >> H >> M;

  const double pi = 3.1415926535897932;
  double Atheta = (double)(H+(double)M/60.)*2*pi/12;
  double Btheta = (double)M*2*pi/60;

  double x = (double)A*std::cos(Atheta);
  double y = (double)A*std::sin(Atheta);

  double a = (double)B*std::cos(Btheta);
  double b = (double)B*std::sin(Btheta);

  std::cout << std::fixed << std::setprecision(15) << std::sqrt( (x-a)*(x-a) + (y-b)*(y-b) ) << std::endl;

  return 0;
}



Measured memory_bytes: 4180
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,K;cin>>N>>K;
  vector<long>A(N);for(long i=0;i<N;i++)cin>>A[i];
  
  long x=0,ans=0;
  for(long b=LONG_MAX-LONG_MAX/2;b>0;b/=2){
    long c=0;
    for(long j=0;j<N;j++)c+=((A[j]&b)!=0);
    if(x+b<=K&&c<N-c){x+=b;ans+=b*(N-c);}
    else ans+=b*c;
  }
  cout<<ans;
}



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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const intll INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int l , r , d ;
  cin >> l >> r >> d ;
  int ans = 0 ;
  
  for(int i=l;i<=r;i++){
    if(i%d == 0) ans ++ ;
  }
  
  cout << ans ;
  
}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll M;
vl A;
ll t;
string s;
ll ret = 0;
ll sum = 0;

void input() {
  IN(N);
  IN(M);
  REP(i, N) {
    IN(t);
    A.pb(t);
    sum += t;
  }
  sort(ALL(A), greater<ll>());
}

void solve() {
  double b = ((double)sum) / (4.0 * (double)M);
  bool ok = true;
  REP(i, M) {
    if (A[i] < b) {
      ok = false;
    }
  }
  PRINT((ok)?"Yes":"No");
}

int main(void){
  input();
  solve();
}


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

int main(){
  int H, W;
  cin >> H >> W;

  vector<string> s(H);
  for(int h = 0; h < H; h++){
    cin >> s[h];
  }

  vector<vector<int>> dp(H, vector<int>(W, 1e9));
  dp[0][0] = 0;
  if(s[0][0] == '#'){
    dp[0][0] = 1;
  }
  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      if(h > 0){
        int plus = 0;
        if(s[h - 1][w] == '.' && s[h][w] == '#'){
          plus = 1;
        }
        dp[h][w] = min(dp[h][w], dp[h - 1][w] + plus);
      }
      if(w > 0){
        int plus = 0;
        if(s[h][w - 1] == '.' && s[h][w] == '#'){
          plus = 1;
        }
        dp[h][w] = min(dp[h][w], dp[h][w - 1] + plus);
      }
    }
  }

  cout << dp[H - 1][W - 1] << endl;
}



Measured memory_bytes: 888
#include <stdio.h>

typedef long long ll;

int main() {

	ll N, K, X, Y;

	scanf("%lld", &N);
	scanf("%lld", &K);
	scanf("%lld", &X);
	scanf("%lld", &Y);

	if (N - K >= 0) {
		printf("%lld\n", (K*X) + (N - K)*Y);
	}
	else {
		printf("%lld\n",N*X);
	}
	return 0;
}

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

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"

pair <ll, ll> a[4];

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	for (int i = 0; i < 4; ++i) {
		cin >> a[i].f;
		a[i].s = 1 << i;
	}
	for (int i = 0; i < 4; ++i) {
		for (int j = i + 1; j < 4; ++j) {
			if (a[j].s * a[i].f > a[i].s * a[j].f) {
				swap(a[i], a[j]);
			}
		}
	}
	ll n;
	cin >> n;
	n *= 4;
	ll ans = 0;
	for (int i = 0; i < 4; ++i) {
		ans += a[i].f * (n / a[i].s);
		n %= a[i].s;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int m1,d1,m2,d2;
  scanf("%d %d %d %d",&m1,&d1,&m2,&d2);
  if(m2==m1+1)
    printf("1\n");
  else
    printf("0\n"); 
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> h(n);
    vector<int> memo(n, 0);
    rep(i, n)
    {
        cin >> h[i];
    }
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        if (h[a - 1] > h[b - 1])
        {
            memo[b - 1]++;
        }
        else if (h[a - 1] == h[b - 1])
        {
            memo[a - 1]++;
            memo[b - 1]++;
        }
        else
        {
            memo[a - 1]++;
        }
    }
    int ans = 0;
    rep(i, n)
    {
        if (memo[i] == 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4580
// 解説前
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

// スライムは自分より小さい体力を持ったスライムを生成する
// ⇒ 可能な限り体力の大きいスライムから順に生成するとして調べれば良い
//
// スライムの増殖回数の合計は$\sum_{t=1}^{N} 2^{t-1} = 2^N$となる
// S_iより小さく最も近い値を探すにはおおよそ$O(\log 2^N)$かかる
// ⇒ 全体の計算量はおおよそ$O(2^N \log 2^N)$となる
// このとき、$2^N \le 2^18 = 262144 < 10^6$なので、制限時間に十分に間に合うだろう
// （参考：https://cppx.hatenablog.com/entry/2017/08/06/104144）
int solve_F() {
  size_t N = 0;  // スライムの増殖回数
  std::cin >> N;
  const size_t total_slime_count = size_t(1) << N;

  // Sを読み取る
  std::multiset<uint64_t> unspawned_slime_set;  // まだ生まれていないスライムのセット
  for (size_t i = 0; i < total_slime_count; ++i) {
    uint64_t slime = 0;
    std::cin >> slime;
    unspawned_slime_set.insert(slime);
  }

  // 最も体力の大きなスライムを最初の一体として生成する
  std::vector<uint64_t> spawned_slimes;  // 生まれたスライムの配列
  spawned_slimes.reserve(total_slime_count);
  spawned_slimes.push_back(*--unspawned_slime_set.end());
  unspawned_slime_set.erase(--unspawned_slime_set.end());

  // スライムを増殖させる
  for (size_t t = 0; t < N; ++t) {
    const size_t slime_count = spawned_slimes.size();
    spawned_slimes.resize(slime_count * 2);
    for (size_t j = 0; j < slime_count; ++j) {
      // 自身より小さく最も近い体力を持つ未生成のスライムを探す
      // iterはその1つ先を指す
      auto iter = unspawned_slime_set.lower_bound(spawned_slimes[j]);

      // 自身より小さい体力を持つスライムが存在しない場合、
      // スライムの体力をSに一致させることができない
      if (iter == unspawned_slime_set.begin()) {
        std::cout << "No";
        return 0;
      }

      // そのスライムを生成する
      spawned_slimes[slime_count + j] = *--iter;
      unspawned_slime_set.erase(iter);
    }
  }

  std::cout << "Yes";
  return 0;
}

int main() {
  return solve_F();
}


Measured memory_bytes: 14592
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define PB push_back
#define MOD 10000007
#define PI 3.14159265359

using namespace std;

int main(){

    string s;
    cin >> s;

    if(s[0] != s[1] && s[1] != s[2] && s[2] != s[3]) puts("Good");
    else puts("Bad");
    
}

Measured memory_bytes: 256
"use strict";
function main(input) {
    const line = input.split("\n");
    let arr = line[0].split(" ");
    const A = parseInt(arr[0]);
    const B = parseInt(arr[1]);
    console.log(Math.max(A + B, A - B, A * B));
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29524
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ret = 0;
    for (int i = 1; i < (int)s.size(); ++i) {
        if (s[i] != s[i - 1])
            ret++;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 512
N,Y=map(int, input().split())
res=(-1,-1,-1)
for x in range(N+1):
  for y in range(N+1-x):
    if N-x-y>=0 and 10000*x+5000*y+1000*(N-x-y)==Y:
      res=[x,y,N-x-y]
print(res[0],res[1],res[2])

Measured memory_bytes: 3064
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int x, y;
    cin >> x >> y;

    Int ans = 0;
    while (x <= y) {
        ans++;
        x <<= 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n , k;
  int p[1000];

  scanf("%d",&n);
  scanf("%d",&k);

  int i = 0;
  for(i = 0; i < n; i++){
    scanf("%d",&p[i]);
  }

  int l,m;
  int buff;
  for(l = 0; l < n; l++){
    for(m = l + 1; m < n; m++){
      if(p[l] > p[m]){
        buff = p[l];
        p[l] = p[m];
        p[m] = buff;
      }
    }
  }

  int sum = 0;
  for(i = 0; i < k; i++){
    sum = sum + p[i];
  }
  printf("%d\n",sum);
}


Measured memory_bytes: 1732
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():

    def prime_factor(n):
        lst = []
        while n%2 == 0:
            n //= 2
            lst.append(2)
        f = 3
        while f**2 <= n:
            if n%f == 0:
                n //= f
                lst.append(f)
            else:
                f += 2
        if n != 1:
            lst.append(n)
        return lst

    n = I()
    ans = 1
    dic = collections.defaultdict(int)
    mod = 10**9 + 7

    for i in range(1,n+1):
        count = collections.Counter(prime_factor(i))
        for k, v in count.items():
            dic[k] += v

        
    for v in dic.values():
        ans *= v+1
        ans %= mod

    print(ans)
        


main()


Measured memory_bytes: 9980
def solve(n, a):
    S, T = {}, {}
    for i in range(n):
        b = a[i] + i
        if not b in S:
            S[b] = 0
        S[b] += 1

        c = -a[i] + i
        if not c in T:
            T[c] = 0
        T[c] += 1
    ans = 0
    for x, num in S.items():
        if x in T:
            ans += S[x] * T[x]
    return ans

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Measured memory_bytes: 56668
#include <bits/stdc++.h>
using namespace std;
#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, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

typedef pair<int, int> P;

ll mod = 1e9 + 7;

bool color[400][400];

ll h, w;

const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};

bool isin_(int i, int j){
	return i >= 0 && i < h && j >= 0 && j < w;
}

bool check_(int i, int j, int d){
	int ni = i + di[d];
	int nj = j + dj[d];
	if(!isin_(ni, nj)) return false;
	if(color[i][j] == color[ni][nj]) return false;
	return true;
}

bool used[400][400];

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

  string s[h];
  REP(i, h){
    cin >> s[i];
    REP(j, w){
      color[i][j] = (s[i][j] == '#');
    }
  }

  ll ans = 0, bl, wh;

  REP(i, h){
    REP(j, w){
      if(used[i][j]) continue;
      bl = 0;
      wh = 0;
      queue<P> que;
      used[i][j] = true;
			que.push(P(i, j));
      while(!que.empty()){
        P p = que.front();
        que.pop();
        int ci = p.first, cj = p.second;
				if(color[ci][cj]) bl++;
				else wh++;

        REP(d, 4){
					if(!check_(ci, cj, d)) continue;
					int ni = ci + di[d], nj = cj + dj[d];
					if(used[ni][nj]) continue;
					used[ni][nj] = true;
					que.push(P(ni, nj));
				}
      }
      ans += bl * wh;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, X = mi()

def rec(level, pos, score):
    #print(level, pos, score)
    if level == 0:
        return score + 1
    half = 2**(level+1) - 2
    if pos == 0:
        return score
    elif pos == half * 2:
        return score + 2**(level+1) - 1
    elif pos == half:
        return score + 2**(level)
    elif pos > half:
        score += 2**(level)
        pos -= half + 1
    else:
        pos -= 1
    return rec(level-1, pos, score)
    
X -= 1
print(rec(N, X, 0))

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int h, n;
	cin >> h >> n;
	int a[n], sum{};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	if (sum >= h) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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


fn main() {
    input! {
        n: i64,
    }
    let mut s = n;
    let mut v = Vec::new();
    while s != 0 {
        v.push(s % 10);
        s /= 10;
    }
    //let sum: i64 = v.iter().fold(0, |sum, a| sum + a.count);
    let sums: i64 = v.iter().sum();
    if n % sums == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

using namespace std;

int sg(int n, int k) {
    if (n%k == 0) return n/k;
    int t = n/k + 1;
    return sg(n - (n%k +t-1)/t *t, k);
}

void solve() {
    int n;cin >> n;
    int res = 0;
    for (int _ = 0; _ < n; _++) {
        int x,y;
        cin >> x >> y;
        res ^= sg(x,y);
    }
    cout << (res?"Takahashi":"Aoki");
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
using namespace std;
const int mod=998244353;
int n,x[205],y[205],tw[205]; 
int main()
{
	cin>>n;tw[0]=1;
	for(int i=0;i<n;i++)
		cin>>x[i]>>y[i];
	for(int i=1;i<=n;i++)
		tw[i]=tw[i-1]*2%mod;
	int ans=(tw[n]-n-1+mod)%mod; 
	for(int i=0;i<n;i++)
		for(int j=0;j<i;j++)
		{
			int cnt=0;
			for(int k=0;k<j;k++)
				if((x[i]-x[j])*(y[i]-y[k])==(x[i]-x[k])*(y[i]-y[j]))
					cnt++;
			ans=(ans-tw[cnt]+mod)%mod;
		}
	cout<<ans<<endl;
}

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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int n;
	cin>>n;

	vector<int> a(n+1);

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

	vector<int> b(n+1);

	for(int i=n; i>=1; --i){
		int sum =0;

		for(int j= i+i;  j<=n; j +=i){
			sum ^= b[j];
		}
		b[i] = sum^a[i];
	}
	vector<int> ans;

	for(int i=1; i<=n; i++){
		if(b[i])ans.push_back(i);
	}
	cout<<ans.size()<<endl;

	for(int i=0; i<ans.size(); i++){
		printf("%d%c",ans[i] ,i+1 == ans.size() ? '\n':' ');
	}




}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, K;
	long long ans=0;
	priority_queue<int> Q;
	cin>>N>>K;
	if(K>=N) {
		cout<<"0\n";
		return 0;
	}
	for(int i=0;i<N;i++) {
		int a;
		cin>>a;
		Q.push(a);
	}
	while(K--) Q.pop();
	while(Q.size()) {
		ans+=Q.top();
		Q.pop();
	}
	cout<<ans<<'\n';
	return 0;
}

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

def main():
    
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    t=sum(a)
    a.sort()
    a.reverse()
    
    if a[m-1]>=t/(4*m):
        print("Yes")
    else:
        print("No")

main()



Measured memory_bytes: 2940