akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
const ll mod=1e9+7;
struct node{
	ll x,y,id;
}a[N];
struct edge{
	ll u,v,w;
}e[N];
bool cmp1(node a,node b)
{
	return a.x<b.x;
}
bool cmp2(node a,node b) 
{
	return a.y<b.y;
}
bool cmp(edge a,edge b)
{
	return a.w<b.w;
}
int fa[N];
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main()
{
	int n;
	while(cin>>n)
	{
		for(int i=1;i<=n;i++)
			scanf("%I64d%I64d",&a[i].x,&a[i].y),fa[i]=i,a[i].id=i;
		sort(a+1,a+1+n,cmp1);
		int cnt=0;
		for(int i=2;i<=n;i++)
			e[cnt].u=a[i].id,e[cnt].v=a[i-1].id,e[cnt++].w=abs(a[i].x-a[i-1].x);	
		sort(a+1,a+1+n,cmp2);
		for(int i=2;i<=n;i++)
			e[cnt].u=a[i].id,e[cnt].v=a[i-1].id,e[cnt++].w=abs(a[i].y-a[i-1].y);
		sort(e,e+cnt,cmp);
		int num=n;
		ll ans=0;
		for(int i=0;i<cnt;i++)
		{
			int u=e[i].u,v=e[i].v;
			int fx=find(u),fy=find(v);
			if(fx!=fy)
			{
				ans+=e[i].w;
				fa[fx]=fy;
				num--;
				if(num==1)
					break;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}
 

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

string str[20];

int main() {
    //ifstream cin("f.in");
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++ i) {
        cin >> str[i];
        str[i] = " " + str[i];
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++ i) {
        for (int j = 1; j <= m; ++ j) {
            if (str[i][j] == '#') {
                cnt += 1;
            }
        }
    }
    if (cnt != n + m - 1) {
        cout << "Impossible\n";
        return 0;
    }
    int x = 1, y = 1;
    while (x != n || y != m) {
        if (x == n) {
            if (str[x][y + 1] != '#') {
                cout << "Impossible\n";
                return 0;
            }
            y += 1;
        } else if (y == m) {
            if (str[x + 1][y] != '#') {
                cout << "Impossible\n";
                return 0;
            }
            x += 1;
        } else {
            if (str[x][y + 1] == '#') {
                y += 1;
            } else if (str[x + 1][y] == '#') {
                x += 1;
            } else {
                cout << "Impossible\n";
                return 0;
            }
        }
    }
    cout << "Possible\n";
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;



int main() {
	vector<int> a(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	
	sort(a.begin(), a.end());

	int cnt = 0;
	if (a[1] < a[2]) {
		cnt += a[2] - a[1];
		a[0] += a[2] - a[1];
		a[1] = a[2];
	}
	if (a[2] > a[0]) {
		cnt += (a[2] - a[0]) / 2;
		a[0] += ((a[2] - a[0]) / 2) * 2;
		
	}
	if( (a[2] - a[0])%2) {
		cnt += 2;
	}

	cout << cnt << endl;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

ll solve(int n,int m,vi& x,vi& y) {
    ll W = 0, H = 0;
    for (int i=0; i<n-1; ++i) {
        ll dx = (ll)x[i+1] - x[i];
        ll before = i+1, after = (n-1)-i;
        // printf("%d) %lld x %lld x %lld \n", i,dx,before,after);
        W = ADD(W, MUL(dx, MUL(before,after)));
    }
    for (int i=0; i<m-1; ++i) {
        ll dy = (ll)y[i+1] - y[i];
        ll before = i+1, after = (m-1)-i;
        // printf("%d) %lld x %lld x %lld \n", i,dy,before,after);
        H = ADD(H, MUL(dy, MUL(before,after)));
    }
    return MUL(W,H);
}

int main() {
    int n,m; cin >> n >> m;
    read_cr();
    vi x(n), y(m);
    loadvec(x, n);
    loadvec(y, m);
    cout << solve(n,m,x,y) << endl;
    return 0;
}


Measured memory_bytes: 2048
n = input()
  
d = [-1 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
color = [0 for i in range(n)]
  
def BFS(s):
  color[0] = 1
  q = []
  q.append(s)
  d[s] = 0
  while len(q) != 0:
    u = q[0]
    q.pop(0)
    for v in range(n):
      if M[u][v] == 1 and color[v] == 0:
        color[v] = 1
        d[v] = d[u] + 1
        q.append(v)
  color[u] = 2
  for i in range(n):
    print i+1, d[i]
  
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(G[1]):
    M[G[0]-1][G[2+j]-1] = 1
  
BFS(0)

Measured memory_bytes: 6488
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> a;
  for (int i = 0; i< N; i++) {
    string s;
    int p;
    cin >> s >> p;
    p = 0 - p;
    a.push_back(make_tuple(s, p, i + 1));
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < N; i++) {
    int x;
    tie(ignore, ignore, x) = a.at(i);
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 2e5+5, M = 1e6+6, OO = 0x3f3f3f3f;
int tc;

int main()
{
    FIO
    int n; cin>>n;
    vector<int> a(n), b(n);
    for(auto &it : a)
        cin>>it;
    for(auto &it :b)
        cin>>it;
    reverse(b.begin(), b.end());
    int lp = -1;
    for (int i = 0; i < n; i++)
    {
        if(a[i] == b[i])
        {
            lp = i;
            break;
        }
    }
    int rp = n;
    for(int i = n-1 ; i != -1; i-- )
    {
        if(a[i] == b[i])
        {
            rp = i;
            break;
        }
    }
    if(lp == -1)
    {
        cout<<"Yes"<<endl;
        for(auto x : b)
            cout<<x<<" ";
        return 0;
    }
    for(int i = 0 ; i< n ; i++)
    {
        if(b[i]!= b[lp] && b[lp] != a[i] && lp <= rp)
        {
            swap(b[i], b[lp]);
            lp++;
        }
    }
    if(lp <= rp)
       return  cout<<"No"<<endl, 0;
    cout<<"Yes"<<endl;
        for(auto x : b)
            cout<<x<<" ";
    
    
    return 0;
}

Measured memory_bytes: 4772
def main():
    n = int(input())
    h = list(map(int, input().split()))

    dp = [0]*(n)

    dp[1] = dp[0] + abs(h[1]-h[0])
    for i in range(2, n):
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))

    print(dp[-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 52208
#include <bits/stdc++.h>
#define f first
#define s second
#define INF 1e9
using namespace std;
typedef pair <int,int> P;
int n;
string str[101];

int get_idx(string a){
  int i=0;
  while(str[i].substr(0,str[i].size()-1)!=a) i++;
  return i;
}


int bfs(){
  int D[101],used[101]={};
  for(int i=0;i<n;i++) D[i]=INF;
  priority_queue <P,vector<P>,greater<P> > Q;
  Q.push(P(0,0));
  D[0]=0;
  while(!Q.empty()){
    P t=Q.top();Q.pop();
    int pos=t.s,cost=t.f;
    if(used[pos])continue;
    if(pos==n) return cost; 
    used[pos]=1;
    string a;
    int i=0;
    while(str[pos][i]!=' '&&str[pos][i]) a+=str[pos][i++];
    if(a=="goto"){
      string lab;
      i++;
      while(str[pos][i]!=';') lab+=str[pos][i++];
      int nx=get_idx(lab);
      Q.push(P(cost,nx));
      D[nx]=min(D[nx],cost); //goto

      Q.push(P(cost+1,pos+1));
      D[pos+1]=min(D[pos+1],cost+1); //cut
    }
    else{
      Q.push(P(cost,pos+1));
      D[pos+1]=min(D[pos+1],cost);
    }
  }
  return -1;
}

int main(){
  cin>>n;
  getline(cin,str[0]);
  for(int i=0;i<n;i++) getline(cin,str[i]);
  cout << bfs()<<endl;
  return 0;
}

Measured memory_bytes: 1224
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
right = 0
for i in range(n):
    if b[i] >= a[i] + a[i+1]:
        ans += a[i] + a[i+1]
        a[i] = 0
        a[i+1] = 0
    elif b[i] <= a[i]:
        ans += b[i]
        a[i] = a[i] - b[i]
    else: # b[i] < a[i] + a[i+1]
        ans += b[i]
        a[i+1] = a[i+1] - (b[i] - a[i])
        a[i] = 0
print(ans)
        

Measured memory_bytes: 82148
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  long long int N,K;
  cin>>N>>K;
  long long int res=0;
  if(K>N) res=min(N,K-N);
  else{
    res=N%K;
    res=min(res,K-res);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include <stdio.h>
#include<unordered_map>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vpll vector<pair<ll,ll> >
#define P complex<ld>
#define X real()
#define Y imag()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n)   for(int i=0;i<n;i++)
#define repp(i,s,n)   for(int i=s;i<=n;i++)
#define print(v) {for(auto i:v)cout<<i<<" ";cout<<"\n";}
#define mkp make_pair
#define clr(ar,v) memset(ar,v,sizeof(ar));
#define TC ll amr_abdelazim;cin>>amr_abdelazim;while(amr_abdelazim--)
#define popcnt(x) __builtin_popcount(x)
#define EPS 1e-9
#define INF 1000000000000000009
using namespace std;
//freopen("output.txt", "w", stdout);
//freopen("input.txt", "r", stdin);
const int mod = 1000000007;
const int N = 2 * 100000 + 9;
const double pi = acos(-1);
class cmp{
public:
	bool operator() (ll &A, ll &B){
		return A > B;
	}
};
bool by_sec(const pll &a, const pll &b){
	if ((abs(a.first) == abs(b.first)))
		return (abs(a.second) < abs(b.second));
	return (abs(a.first) < abs(b.first));
}
bool byth(const tuple<ll, ll, ld>& a, const tuple<ll, ll, ld>& b){
	return (get<2>(a) < get<2>(b));
}
ld dist(P a, P b){
	return (ld)abs(a - b);
}
ll fact[1000009], inv[1000009];
ll fp(ll a, ll b){
	if (b == 0)
		return 1;
	ll ans = fp(a, b / 2);
	ans = (ans * ans) % mod;
	if (b % 2 != 0)
		ans = (ans * (a % mod)) % mod;
	return ans;
}
void FacInv(ll n){
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = ((i%mod) * fact[i - 1] % mod) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}
ll ncr(ll n, ll r){
	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a%b);
}
ll max(ll a, ll b){
	if (a >= b)return a;
	else return b;
}
ll min(ll a, ll b){
	if (a <= b)return a;
	else return b;
}



int main()
{
	Amr_Abdelazim

		ll n,k,ans=0,q=0;
	cin >> n >> k;
	vll a(n);
	map<ll, ll>mp;
	rep(i, n){
		cin >> a[i];
		q += a[i];
		mp[q % k]++;
	}
	for(auto i:mp){
		ll c = i.second;
		if (c > 0){
			ans += (c*(c - 1)) / 2;
		}
	}
	ans += mp[0];
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 7828
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	[a, b] <- readIntToList <$> BS.getLine
	putStrLn $ if a < b then replicate b (head $ show a) else replicate a (head $ show b)


Measured memory_bytes: 380
#include <iostream>
using namespace std;
#define max(a,b) (a)>(b)?(a):(b)
#define max3(a,b,c) max(a,max(b,c))
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int s = (a*b*c)/(max3(a,b,c))/2;
  cout<<s<<endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c, x, y := nextInt(), nextInt(), nextInt(), nextInt(), nextInt()
	ans1 := a*x + b*y
	var ans2, ans3 int
	if x <= y {
		ans2 = c*x*2 + b*(y-x)
		ans3 = c * 2 * y
	} else {
		ans2 = c*y*2 + a*(x-y)
		ans3 = c * 2 * x
	}
	puts(min(ans1, ans2, ans3))
	wt.Flush()
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	int n,m,min_time[101][101],min_cost[101][101],from,to,cost,time,num,r;

	while(true){
		scanf("%d %d",&n,&m);
		if(n == 0 && m == 0)break;

		for(int i = 1; i <= m; i++){
			for(int k = 1; k <= m; k++){
				if(i != k){
					min_time[i][k] = 2000000000;
					min_cost[i][k] = 2000000000;
				}else{
					min_time[i][k] = 0;
					min_cost[i][k] = 0;
				}
			}
		}

		for(int i = 0; i < n; i++){
			scanf("%d %d %d %d",&from,&to,&cost,&time);
			min_time[from][to] = time;
			min_cost[from][to] = cost;
			min_time[to][from] = time;
			min_cost[to][from] = cost;
		}

		for(int k = 1; k <= m; k++){
			for(int i = 1; i <= m; i++){
				if(min_time[i][k] == 2000000000)continue;
				for(int p = 1; p <= m; p++){
					if(min_time[k][p] == 2000000000)continue;
					min_time[i][p] = min(min_time[i][p],min_time[i][k] + min_time[k][p]);
				}
			}

			for(int i = 1; i <= m; i++){
				if(min_cost[i][k] == 2000000000)continue;
				for(int p = 1; p <= m; p++){
					if(min_cost[k][p] == 2000000000)continue;
					min_cost[i][p] = min(min_cost[i][p],min_cost[i][k] + min_cost[k][p]);
				}
			}
		}

		scanf("%d",&num);

		for(int i = 0; i < num; i++){
			scanf("%d %d %d",&from,&to,&r);
			if(r == 1){
				printf("%d\n",min_time[from][to]);
			}else{
				printf("%d\n",min_cost[from][to]);
			}
		}
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=1; i<n; i++) {
    a[i] = a[i-1]*a[i]/__gcd(a[i-1], a[i]);
  }
  cout << a[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1160
n = int(input())
num_list = list(map(int,input().split()))
i = 0
neg_count = 0
while(i < n):
    if num_list[i] < 0:
        neg_count += 1
        num_list[i] *= -1
    i += 1
num_list = sorted(num_list)
if neg_count %2 == 0:
    print(sum(num_list))
else:
    num_list[0] *= -1
    print(sum(num_list))


Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll INF = 2e18;

int main(){
  ll n, k;
  cin >> n >> k;
  ll w[n], d[n];
  rep(i,n) cin >> w[i] >> d[i];
  ll l = 0, r = INF;
  while(r - l > 1) {
    ll m = (l + r) / 2;
    ll res = 0;
    rep(i,n) {
      if(res >= k) break;
      res += max((ll)0,(m-w[i])/d[i]+1);
    }
    if(res >= k) r = m;
    else l = m;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 5164
'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");

input = input.split('\n')

let seq = input[1].split(' ').map(x => parseInt(x))
let pause = 1;
let diffSign = 0;

for(let i = 1; i < seq.length; i++){
	let nowSign = Math.sign(seq[i-1] - seq[i]); 
  	if(nowSign*diffSign < 0){
    	pause++;
      	diffSign = 0; 
    } else if(diffSign === 0){
		diffSign = nowSign;    
    }
}
    
console.log(pause)


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


int main() {
  string s;
  cin >> s;
  
  bool ans = true;
  if(s[0] == s[1] && s[1] == s[2]){
    ans = false;
  }
  
  if(ans){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 256
def _input():
    return

def solve():
    _input()
    a, b, c, d = list(map(int, input().split()))
    if ((abs(a-b)<=d and abs(b-c)<=d) or abs(a-c)<=d):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    solve()

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
using namespace std;

long long  mod = 1000000007;

long max(long x, long y) {
	return x > y ? x : y;
}

long min(long x, long y) {
	return x < y ? x : y;
}

long factorial(long n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n * factorial(n - 1);
	}
}

long long  fel(long long  n,long long  f) {

		if (f == 1) {
			return n % mod;
		}
		else if (f % 2 == 0) {
			return (fel(n,f / 2) * fel(n,f / 2)) % mod;
		}
		else {
			return ((n  * fel(n,f / 2) %mod) * fel(n,f / 2))% mod;
		}
	

}


int main()
{
	long count;
	long x;
	cin >> x;
	count = 0;
	bool flag1 = true;
	while (flag1) {
	    long i = 2;
		while (true) {
			if ((x + count) % i == 0) {
				break;
			}
			if (i == int(sqrt(x + count))+1) {
				flag1 = false;
				break;
			}
				i++;
			}
		count++;
		}
	if (x == 2 or x==1) {
		cout << 2;
	}
	else {
		cout << x + count - 1;
	}

	}






Measured memory_bytes: 256
use std::io;
fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let input : i32 = input.trim().parse().ok().unwrap();
    if input % 111 == 0 {
        println!("{}", input);
        return;
    }
    
    println!("{}", (input / 111 + 1) * 111);
}



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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    int count = 0;
    for(int i = 0; i < N ; i++){
        cin >> a.at(i);
        while(1){
            if(a.at(i) % 2 == 1){
                break;
            }else{
                count++;
                a.at(i) /= 2;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
int64_t N,P,a,c[1<<20],i,j;std::string S;main(){std::cin>>N>>P>>S;if(10%P)for(c[0]=j=1;N--;i+=(S[N]-48)*(j=j*10%P),a+=c[i%=P]++);else for(;i<N;a+=(S[i++]-8)%P?0:i);std::cout<<a;}

Measured memory_bytes: 644
using namespace std;
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define w(x) int x;cin>>x;while(x--)

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define ll long long

void abc()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int mod = 1000000007;
vector<vector<int>> dp;
string s, t;





int main()
{
	abc();
	cin >> s >> t;
	dp.resize(s.size() + 1, vector<int>(t.size() + 1, 0));

	for (int i = 0; i <= s.size(); i++) {
		for (int j = 0; j <= t.size(); j++) {
			if (i == 0 or j == 0) continue;
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = 1 + dp[i - 1][j - 1];
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}



	string res;
	int i = s.size(), j = t.size();

	while (i >= 1 and j >= 1) {

		if (s[i - 1] == t[j - 1]) {

			res.push_back(s[i - 1]);
			i--;
			j--;
		} else if (dp[i - 1][j] > dp[i][j - 1]) {
			i--;
		} else {
			j--;
		}
	}

	reverse(res.begin(), res.end());
	cout << endl;
	cout << res;


}

Measured memory_bytes: 38520
#include <math.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& v) {
    return is >> v.first >> v.second;
}

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (T& i: v) is >> i;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) {
    return os << v.first << " " << v.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    int n = (int) v.size();
    for (int i = 0; i < n; ++i) os << v[i] << (i == n - 1 ? "" : " ");
    return os;
}

template <typename T>
void in(T& x) {
    std::cin >> x;
}

template <typename T1, typename... T2>
void in(const T1 H, const T2... T) {
    std::cin >> (H); in(T...);
}

template <typename T>
void out(const T H) {
    std::cout << (H);
}

template <typename T1, typename... T2>
void out(const T1 H, const T2... T) {
    std::cout << (H) << " "; out(T...);
}

template <typename T>
void eout(const char *s, const T H) {
    std::cerr << s << "=" << H << "\n";
}

template <typename T1, typename... T2>
void eout(const char *s, const T1 H, const T2... T) {
    while (*s != ',') std::cerr << *s++;
    std::cerr << "=" << H << " | "; eout(++s, T...);
}

#define nl                std::cout << "\n"
#define err(args...)      eout(#args, args)

#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define sz(v)             ((int) v.size())
#define all(v)            (v).begin(), (v).end()
#define lla(v)            (v).rbegin(), (v).rend()

#define no                std::cout << "NO\n"
#define yes               std::cout << "YES\n"

const int INF           = 2147483647;
const long long int LNF = 9223372036854775807LL;

using ll  = long long int;
using vi  = std::vector<int>;
using vb  = std::vector<bool>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N  = 505050;
const int MD = 1000*1000*1000 + 7;

int solve();
int main() {
    std::ios_base::sync_with_stdio(0); std::cin.tie(0);
    //std::cout.tie(0);

    //int t; in(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}

int solve() {
    int n; in(n);
    vi a(n); in(a);

    double s = 0;
    for (int i: a) s += (1.0/i);
    out(1/s);

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = {}
for i in range(N):
    s = input()
    if s in S:
        S[s] += 1
    else:
        S[s] = 1

max_count = 0
max_str = []
for s, count in S.items():
    if count > max_count:
        max_count = count
        max_str = [s]
    elif count == max_count:
        max_str.append(s)

max_str.sort()
for s in max_str:
    print(s)


Measured memory_bytes: 32096
s = input()
n = len(s)
mod = 1000000007
dp = [[0 for i in range(13)] for j in range(n+1)]
dp[0][0] = 1
s = s[::-1]
dec = 1
for i in range(n):
    x = s[i]
    dec %= 13
    if x != '?':
        x = int(x)
        r = (dec * x) % 13
        for j in range(13):
            dp[i+1][j] = dp[i][(j-r)%13]
    else:
        for j in range(10):
            r = (dec * j) % 13
            for k in range(13):
                dp[i+1][k] += dp[i][(k-r)%13] % mod
    dec *= 10
print(dp[-1][5] % mod)
#print(dp)        

Measured memory_bytes: 66652
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, ll A, ll B, vector<ll> X) {
  ll res = 0;
  REP(i,N-1) {
    res += min((X[i+1] - X[i]) * A, B);
  }
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll A;
	ll B;
	ll N;
	scanf("%lld", &N);
	vector<ll> X(N-1+1);
	scanf("%lld", &A);
	scanf("%lld", &B);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &X[i]);
	}
	solve(N, A, B, X);
	return 0;
}


Measured memory_bytes: 1792
import numpy as np

h, w = map(int, input().strip().split())

maze = np.ones((h + 2, w + 2), dtype=np.int)

for i in range(1, h + 1):
    row = input().strip()
    for j in range(1, w + 1):
        maze[i, j] = 0 if row[j - 1] == '.' else 1


def bfs(maze, si, sj):
    assert maze[si, sj] == 0
    infty = -1
    distances = np.full((h + 2, w + 2), infty, dtype=np.int)
    queue = []
    queue.append((si, sj))
    distances[si, sj] = 0
    while len(queue) > 0:
        ci, cj = queue.pop(0)
        d = distances[ci, cj]
        left = (ci, cj - 1)
        right = (ci, cj + 1)
        up = (ci - 1, cj)
        down = (ci + 1, cj)
        nexts = [left, right, up, down]
        for ni, nj in nexts:
            if not (1 <= ni and ni <= h \
               and 1 <= nj and nj <= w):
                continue
            if distances[ni, nj] != infty:
                continue
            if maze[ni, nj] == 1:
                continue
            distances[ni, nj] = d + 1
            queue.append((ni, nj))

    return distances


max_dist = 0
for si in range(1, h + 1):
    for sj in range(1, w + 1):
        if maze[si, sj] == 0:
            distances = bfs(maze, si, sj)
            mx = np.max(distances)
            max_dist = max(max_dist, mx)

print(max_dist)


Measured memory_bytes: 12500
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<memory>

using namespace std;

long long fact( long long n )
{
  if ( n == 1 ) return 1;

  return n * fact( n - 1 );
  
}

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

  cout << fact( n ) << endl;
  
  return 0;
}

Measured memory_bytes: 1152
var
	N,i:Longint;
	p,A,T:int64;
begin
	read(N,p);
	T:=1000;
	for i:=2 to N do begin
		read(A);
		if p<A then begin
			T:=T mod p+T div p*A;
		end;
		p:=A;
	end;
	writeln(T);
end.

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




typedef long long int ll;
int main()
{
    ll n,a[100005],b[100005];
    cin>>n;
    for(ll i=1; i<=n; i++)
    {
        cin>>a[i];
        b[i] = INT_MAX;
    }
    b[1] = 0;
    for(ll i=1; i<n; i++)
    {
        b[i+1] = min(b[i+1],b[i]+abs(a[i]-a[i+1]));

        if(i+1<n)
            b[i+2] = min(b[i+2],b[i]+abs(a[i]-a[i+2]));
    }
    cout<<b[n]<<endl;



}



Measured memory_bytes: 1792
program abc135b
   implicit none
   integer :: n, counter, i, j
   integer, allocatable :: p(:), q(:)

   read(*,*) n
   allocate(p(n), q(n))
   read(*,*) p(:)

   do i = 1, n
      q(i) = i
   end do

   counter = 0
   do i = 1, n
      if (p(i) /= q(i)) counter = counter + 1
   end do

   if ( counter <= 2) then
      write(*, *) 'YES'
   else
      write(*,*) 'NO'
   end if
end program abc135b


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
using namespace std;



int main(){
    int n,m ;
    cin >> n >> m ;
    vector<bool> sa(n-1,0) ;
    int i = 1 ;
    int j = n ;
    int count = 0 ;
    while (count < m)
    {
        if (sa.at(j-i-1) == 0 && sa.at(i+n-j-1) == 0 && j-i != i+n-j)
        {
            cout << i << " " << j << endl ;
            count ++ ;
            sa.at(j-i-1) = 1 ;
            sa.at(i+n-j-1) = 1 ;
            i++ ;
            j-- ;
        }else
        {
            j-- ;
        }
        
           
    }
    
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
int main(){
  int r,mi,mj,i,c[1010]={0};
  char s[1010],l[1010][40],*w;
  fgets(s,1010,stdin);
  w=strtok(s," \n");
  strcpy(l[0],w);
  c[mj=0]=r=1;
  while(w=strtok(NULL," \n")){//printf("%s\n",w);
    strcpy(l[r],w);
    for(i=0;strcmp(l[i],w);i++);
    c[i]++;
    if(i==r){
      r++;
      if(strlen(w)>strlen(l[mi]))mi=i;
    }
    if(c[i]>c[mj])mj=i;
  }
  printf("%s %s\n",l[mj],l[mi]);
  return 0;
}
  

Measured memory_bytes: 556
def abc177_d():
    n, m = map(int, input().split())

    par = [x for x in range(n)]
    rank = [0]*n

    def find(x):
        if par[x] == x:
            return x
        else:
            par[x] = find(par[x])
            return par[x]

    def unite(x, y):
        x = find(x)
        y = find(y)
        if x == y: return
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]: rank[x] += 1

    for _ in range(m):
        a, b = map(lambda x: int(x)-1, input().split())
        unite(a, b)

    for i in range(n):
        _ = find(i)

    from collections import Counter
    ans = Counter(par).most_common()[0][1]
    print(ans)

if __name__ == '__main__':
    abc177_d()

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

int main(){
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d) cout<<"Left"<<endl;
	if(a+b==c+d) cout<<"Balanced"<<endl;
	if(a+b<c+d) cout<<"Right"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

using namespace std;

struct bar {
    int h, p, q;

    bool operator <(const bar& b) const {
        return h < b.h;
    }
};

int main()
{
    int n, m, a;
    while(cin >> n >> m >> a, n|m|a){
        priority_queue<bar> que;
        for(int i = 0; i < m; i++){
            int h, p, q;
            cin >> h >> p >> q;
            que.push((bar){h, p, q});
        }
        int high = 1000, pos = a;
        while(!que.empty() && high > 0){
            if(high == que.top().h){
                if(pos == que.top().p)
                    pos = que.top().q;
                else if(pos == que.top().q)
                    pos = que.top().p;
                que.pop();
            }else{
                high--;
            }
        }
        cout << pos << endl;
    }
    return 0;
}

Measured memory_bytes: 1240
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

int main(){
  int n;
  cin>>n;
  vector<lint> a(3*n);
  rep(i,3*n)cin>>a[i];
  vector<lint> l(3*n),r(3*n);
  lint t=0;
  priority_queue<lint,vector<lint> >que;
  rep(i,3*n){
    t+=-a[i];
    que.push(-a[i]);
    if(que.size()>n){
      t-=que.top();que.pop();
    }
    l[i]=-t;
  }
  t=0;
  while(que.size())que.pop();
  for(int i=3*n-1;i>=0;--i){
    t+=a[i];
    que.push(a[i]);
    if(que.size()>n){
      t-=que.top();
      que.pop();
    }
    r[i]=t;
  }
  lint ma=-1e18;
  for(int i=n-1;i<2*n;++i)ma=max(ma,l[i]-r[i+1]);
  cout<<ma<<endl;
}


Measured memory_bytes: 8440
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
//    cout << fixed << setprecision(10);
    int N;
    cin >> N;
    
    int n = N % 10;
    switch(n) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon";
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon";
            break;
        case 3:
            cout << "bon";
            break;
    }

    return 0;
}

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

int main(){

    string s,t;
    cin >> s >> t;

    int size = s.size();
    int ans = 0;
    for(int i=0; i<size; i++){
        if(s.at(i) != t.at(i)) ans++;
    }

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

Measured memory_bytes: 3896
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200010];
int c[200010];
int main()
{
	int n,m,s,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
		for(j=0;j<n;j++)
		c[j]=a[j];
		sort(c,c+n);
	for(i=0;i<n;i++)
	{
	    if(a[i]==c[n-1])
	    printf("%d\n",c[n-2]);
	    else 
		printf("%d\n",c[n-1]);
	}
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,m;
    int *a;
    int homework=0;

    do{
        scanf("%d%d",&n,&m);
    }while(n<1||n>1000000||m<1||m>10000);

    a=(int *)malloc(m*sizeof(int));

    for(int i=0;i<m;i++){
        do{
            scanf("%d",&a[i]);
        }while(a[i]<1||a[i]>10000);
        homework+=a[i];
    }

    if(n-homework>=0){
        printf("%d",n-homework);
    }
    else{
        printf("%d",-1);
    }

    return 0;
}

Measured memory_bytes: 1708
from collections import deque

def func(x):
    return x - 1

def main():
    N = int(input())
    A = [deque(map(func,map(int, input().split()))) for _ in range(N)]
    # 前日試合した人
    pre_players = range(N)
    game_cnt = 0
    day_cnt = 0
    max_cnt = N * (N - 1) // 2
    while day_cnt < max_cnt:
        # 当日試合した人
        players = set()
        for p in pre_players:
            if p in players:
                continue
            if not A[p]:
                continue
            opp = A[p][0]
            if opp in players:
                continue

            if p == A[opp][0]:
                A[p].popleft()
                A[opp].popleft()
                players |= {p,opp}
                game_cnt += 1

        pre_players = players
        day_cnt += 1

        if max_cnt == game_cnt:
            break

    if game_cnt != max_cnt:
        print(-1)
    else:
        print(day_cnt)
    
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 76032
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    string s;
    cin >> n >> s;

    vector<int> lr(n * 2); //l:0, r:1
    rep(i, n * 2 - 1){
        if(s[i] == s[i+1]){
            lr[i+1] = (lr[i] + 1) % 2;
        }else{
            lr[i+1] = lr[i];
        }
    }

    int cnt = 0;
    rep(i, n * 2){
        if(lr[i]) cnt++;
    }

    if(s[0] == 'W' || s.back() == 'W'){
        cout << 0 << endl;
        return 0;
    }

    int r = 0;
    int l = 0;
    int ans = 1;
    for(int i = n * 2 - 1; i >= 0; i--){
        if(lr[i]){
            r++;
        }else{
            if(r - l <= 0){
                cout << 0 << endl;
                return 0;
            }
            ans *= r - l;
            ans %= MOD;
            l++;
        }
    }
    if(l != r){
        cout << 0 << endl;
        return 0;
    }

    rep(i, n){
        ans *= i + 1;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2172
H, W, D = map(int, input().split())
P = [[] for i in range(H * W)]
for i in range(H):
  for j, a in enumerate(input().split()):
    P[int(a) - 1] = [i, j]
C = [[0 for j in range(-(-H * W // D) + 1)] for i in range(D)]
for i in range(H * W - D):
  C[i % D][i // D + 1] = abs(P[i][0] - P[i + D][0]) + abs(P[i][1] - P[i + D][1])
for i in range(D):
  for j in range(1, -(-H * W // D) + 1):
    C[i][j] += C[i][j - 1]
Q = int(input())
for i in range(Q):
  L, R = [int(x) - 1 for x in input().split()]
  print(C[R % D][R // D] - C[L % D][L // D])

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second

typedef long long LL;

int n;
int a[123456];
int cnt1[123456],cnt2[123456],cnt3[123456];
int maxi;

int main() {
  //  freopen("test.txt","r",stdin);
    cin >> n;
    for (int i =1 ; i <= n ; i++) {
        cin >> a[i];
        cnt1[a[i]-1]++;
        cnt2[a[i]]++;
        cnt3[a[i]+1]++;
    }
    for (int i = -1  ; i <= 100006; i++ ) {
        maxi = max(maxi,cnt1[i] + cnt2[i] + cnt3[i]);
    }
    cout << maxi;
}


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

int main() {
    string s;
    cin >> s;
    map<char, int> m;
    for (auto& e : s) m[e]++;
    string ans = "None";
    for (char c = 'a'; c < 'z' + 1; c++) {
        if (m[c] == 0) {
            ans = c;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
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(a > b){ a = b; return 1; } return 0; }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vii = vector<vi>;
using vl = vector<ll>; using vll = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
struct UFT{
  vector<int> par;//親
  vector<int> rank;//木の深さ
  vector<int> size;//木の大きさ
  int n;
  
  UFT(int _n)
  {
    n = _n;
    par.resize(n);
    rank.assign(n,0);
    size.assign(n,1);
    rep(i,n){
      par[i] = i;
    }
  }
  
  //xの根を返す
  int find(int x)
  {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  //x,yを併合
  void unite(int x,int y)
  {
    x = find(x);
    y = find(y);
    if(x == y) return;

    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]++;
    }
  }

  //x,yが同じグループにいるかどうかを返す
  bool same(int x,int y)
  {
    return find(x) == find(y);
  }

  //xの属する木のサイズを探す
  int usize(int x)
  {
    return size[find(x)];
  }
};


int main()
{
  int n,m; cin >> n >> m;
  UFT uf(n);
  while(m-- > 0) {
    int a,b; cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
  }

  vi v(n, 0);
  int cnt = 0;  
  rep(i,n) {
    if(v[uf.find(i)] == 0) cnt++;
    v[uf.find(i)]++;
    
  }

  cout << cnt-1 << "\n";
  
  return 0;
}


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

#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      ll d,t,s;
      cin>>d>>t>>s;

      ll vagfol=d/s;
      if(d%s) vagfol++;

      if(vagfol<=t){cout<<"Yes"<<endl;}
      else cout<<"No"<<endl;


      bye;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);
 
#define f first
#define s second
 
#define inf (int)1e9 + 7
 
#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
#define mp(x,y) make_pair(x,y)
 
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)
 
#define pb push_back
#define ppb pop_back
 
#define bitcoin __builtin_popcount
 
#define endl "\n"
 
#define in(x) insert(x)
 
#define sz(x) (int)x.size()
 
#define all(x) x.begin(),x.end()
 
#define pw2(x) (1ll<<x) //2^x
 
#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
 
#define sqr(x) ((x) * 1ll * (x))
 
#define UpdateRandom srand (time(NULL));
 
using namespace std;
 
const int N = (int)3e3 + 7, MOD = (int)1e9 + 7;

int n;
int a[N];
ll dp[N][N][4];
bool was[N][N][4];

ll calc(int l,int r,int cur){
	if(l>r)return 0;
	if(was[l][r][cur])return dp[l][r][cur];
	was[l][r][cur]=1;
	if(cur == 1){
		dp[l][r][cur]=min(calc(l+1,r,(cur^1))-a[l],calc(l,r-1,(cur^1))-a[r]);
	}
	else{
		dp[l][r][cur]=max(calc(l+1,r,(cur^1))+a[l],calc(l,r-1,(cur^1))+a[r]);
	}
	return dp[l][r][cur];
}

int main(){
		
	NFS
	
	cin >> n;
	
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	
	cout << calc(1,n,0) << endl;

	ioi
}

Measured memory_bytes: 317952
def get_survivors(n, pairs):
    survivors = {v: {v} for v in range(n)}
    for x, y in reversed(pairs):
        for v, srv in survivors.copy().items():
            if x in srv:
                if y in srv:
                    del survivors[v]
                else:
                    srv.add(y)
            elif y in srv:
                srv.add(x)
    return survivors


def solve(n, pairs):
    survivors = get_survivors(n, pairs)
    ans = 0
    for u, su in survivors.items():
        for v, sv in survivors.items():
            if u >= v:
                continue
            if su.isdisjoint(sv):
                ans += 1
    return ans


n, m = map(int, input().split())
pairs = []
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    pairs.append((x, y))
print(solve(n, pairs))


Measured memory_bytes: 54616
#include<iostream>
#include<iomanip>
#define _USE_MATH_DEFINES
#include<math.h>
using namespace std;

int main(){
	double r,S,L;
	cin>>r;
	S=r*r*M_PI;
	L=2*r*M_PI;
	cout<<fixed<<setprecision(5)<<S<<" "<<fixed<<setprecision(5)<<L<<endl;
	return 0;
}

Measured memory_bytes: 3236