akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var a, b, x float64
	fmt.Fscan(r, &a)
	fmt.Fscan(r, &b)
	fmt.Fscan(r, &x)

	s := x / a

	if s >= a*b/2 {
		h := (a*b - s) * 2 / a
		r := math.Atan2(h, a)
		fmt.Printf("%.9f\n", r/(2*math.Pi)*360)
	} else {
		w := s * 2 / b
		r := math.Atan2(b, w)
		fmt.Printf("%.9f\n", r/(2*math.Pi)*360)
	}
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
  int a[4],b[4],sum[2],i;
  sum[0]=0;
  sum[1]=0;
  for(i=0;i<4;i++){
    scanf("%d",&a[i]);
    sum[0]+=a[i];
  }
  for(i=0;i<4;i++){
    scanf("%d",&b[i]);
    sum[1]+=b[i];
  }
  if(sum[0]>sum[1]) printf("%d\n",sum[0]);
  else printf("%d\n",sum[1]);
  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#define MAX 1000000000000000000
using namespace std;

bool is_negative(long long int l){// 負の数が true
    return (l < 0);
}

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    long long ans = 1;

    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    //cout << A.size() << endl;
    if(count(A.begin(), A.end(), 0) > 0){
        cout << "0" << endl;
        return 0;
    }else {
        for (int i = 0; i < N; i++) {
            if(A[i] < 0){
                cout << "-1" << endl;
                return 0;
            }else if(ans <= MAX / A[i]){
                ans *= A[i];
            }else{
                cout << "-1" << endl;
                return 0;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4000
N=int(input())
a=[int(input()) for _ in range(N)]
b=[False]*N
count=0
i=0
b[i]=True
flag=True
while b[1]!=True:
    if(b[a[i]-1]==True):
        print(-1)
        flag=False
        break
    b[a[i]-1]=True
    i=a[i]-1
    count+=1
if flag:
    print(count)

Measured memory_bytes: 7852
#include<stdio.h>
 
int main(void)
{
  long long int a, b, k;
 
  scanf("%lld%lld%lld",&a,&b,&k);
 
  if(a>k) a=a-k;
  else if(b+a>k) {
    b=b+a-k;
    a=0;
  }
  else {
    a=0;
    b=0;
  }
 
  printf("%lld %lld\n",a,b);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
#define for(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    string s;
    int a=0;
    cin >> s;
    for(i,3){
        if(s[i] == '1') a++;
    }
    cout << a << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long x = long.Parse(input[0]);
		long y = long.Parse(input[1]);

		Console.WriteLine(x+y/2);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		System.out.println(Math.max(a * b, c * d));


		sc.close();

	}

}

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

int sumOfDigits(int n) {
  int sum = 0;
  while (n / 10 != 0) {
    sum += n % 10;
    n /= 10;
  }
  sum += n;
  return sum;
}

int main() {
  int N; cin >> N;
  int min = 90;
  for (int i = 1; i < N; i++) {
    int sum = sumOfDigits(i) + sumOfDigits(N - i);
    if (sum < min) min = sum;
  }
  cout << min << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
   char a;
   cin>>a;
   cout<<char(a+1);}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;

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

    if (s == "Sunny") cout << "Cloudy";
    else if (s == "Cloudy") cout << "Rainy";
    else cout << "Sunny";
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if((i % 2 == 0 && s[i] == 'L')
                || (i % 2 == 1 && s[i] == 'R')){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
possibility = False

N, M, X = [int(s) for s in input().split()]
A = []
C = []
for _ in range(N):
    x = list(map(int, input().split()))
    C.append(x[0])
    A.append(x[1:])

result = 10**8

for i in range(1, 2 ** N):
    cost = 0
    rikai = [0] * M
    for j in range(N):
        if (i >> j & 1):
            cost += C[j]
            for k in range(M):
                rikai[k] += A[j][k]
    if sum(map(lambda x: x >= X, rikai)) == M:
        possibility = True
        result = min(cost, result)

print(result if possibility else - 1)


Measured memory_bytes: 9096
N,K = map(int,input().split())
l = list()
for i in range(K,N+2):
    min = i*(i - 1)/2
    max = (2*N - i + 1)*i /2
    cases = max - min + 1
    l.append(cases)
print(int(sum(l)) % (10**9 + 7))

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

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

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

  long long ans = 0;
  for(int i = 28; i >= 0; i--) {
    long long tmp = 0;
    long long t = 1LL << i;
    for (int j = 0; j < n; j++) {
      a[j] %= 2*t;
      b[j] %= 2*t;
    }
    sort(b, b + n);
    for (int j = 0; j < n; j++) {
      tmp += lower_bound(b, b + n, 2*t - a[j]) - lower_bound(b, b + n, t - a[j]);
      tmp += lower_bound(b, b + n, 4*t - a[j]) - lower_bound(b, b + n, 3*t - a[j]);
    }
    ans += (tmp % 2) * t;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1920
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int K = sc.nextInt();
        sc.nextLine();
        int[] sunuke = new int[N];
        int kagaisha = 0;

        for (int i = 0; i < K; i++) {
            int okashi_num = Integer.parseInt(sc.nextLine());
            
            for(int j = 0; j < okashi_num; j++) {
                int sunuke_num = sc.nextInt();
                sunuke[sunuke_num-1]++;
            }
            sc.nextLine();
        }

        for (int i = 0; i < N; i++) {
            if (sunuke[i] == 0) {
                kagaisha++;
            }
        }
        
        System.out.println(kagaisha);
    }
}

Measured memory_bytes: 46952
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

long long X, t;
int main() {
    cin >> X >> t;
    cout << max(X - t, 0LL) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<long,long>mp;
int main()
{
    long i,j,t,a,b,n,c,y,m,prev,sum,ans=1;
    t=1;
    // cin>>t;
    while(t--)
    {
       string s;
       cin>>s;
       int arr[30];
       bool flag = false;
       memset(arr,0,sizeof(arr));
       for(i=0;i<s.length();i++)
       {
           arr[s[i]-'a']++;
       }
       for(i=0;i<=('z'-'a');i++)
       {
           if(arr[i]==0)
           {
               cout<<char('a'+i);
               flag=true;
               break;
           }
       }
       if(!flag)
        cout<<"None";
    }
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
from itertools import chain

MAX = 10 ** 18


def solve(N: int, A: "List[int]"):
    A = sorted(A)
    answer = 1
    for a in A:
        answer *= a
        if a > 0:
            if answer > MAX:
                return -1
    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, A = map(int, line.split())
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, A)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22832
import itertools

n,k = map(int,input().split())
d = [0]*k
A =[]
ans = 0

for i in range(k):
  d[i] = int(input())
  a = list(map(int,input().split()))
  A.append(a)
 
AS = list(itertools.chain.from_iterable(A))

for i in range(1,n+1):
    if i not in AS:
      ans += 1

print(ans)

Measured memory_bytes: 9244
# -*- coding: utf-8 -*-
n, k = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))

ans = 10 ** 18
h.sort()
for i in range(n - k + 1):
    if ans > h[i + k - 1] - h[i]:
        ans = h[i + k - 1] - h[i]
print(ans)


Measured memory_bytes: 7440
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    std::cin >> n;
    int a=0,b=0;
    int card[100];
    for (int i = 0; i < n; i++) {
        std::cin >> card[i];

    }
    sort(card,card+n);
    for (int i = n-1; i >=0; i--) {
        a+=card[i];
        i--;
        if(i>=0)b+=card[i];
        
    }
    std::cout << a-b << std::endl;
}


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

using namespace std;

const int N = 100005;

int n, k, g, big, a[N];

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    g = __gcd(g, a[i]);
    big = max(big, a[i]);
  }
  if (k > big) {
    puts("IMPOSSIBLE");
    return 0;
  }
  if (k % g) {
    puts("IMPOSSIBLE");
    return 0;
  }
  puts("POSSIBLE");
  return 0;
}



Measured memory_bytes: 640
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=505;
PII l[N*N],r[N*N];
int ans[N*N];
int main(){
	//~ #ifndef ONLINE_JUDGE
    //~ freopen("file.in", "r", stdin);
	//~ #endif	
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		ans[x]=i;
		l[x]=mp(i-1,i);
		r[x]=mp(n-i,i);
	}int p=1;
	for(int i=1;i<=n*n;i++){
		if(ans[i])
			continue;
		while(p<=n*n and !l[p].ff)
			p++;
		if(p<=n*n and i<p)
			ans[i]=l[p].ss,l[p].ff--;
		else
			break;
	}
	while(p<=n*n and !l[p].ff)
		p++;
	if(p<=n*n)
		return 0*puts("No");
	p=n*n;	
	for(int i=n*n;i>=1;i--){
		if(ans[i])
			continue;
		while(p>0 and !r[p].ff)
			p--;
		if(p>0 and i>p)
			ans[i]=r[p].ss,r[p].ff--;
		else
			break;
	}
	while(p>0 and !r[p].ff)
		p--;
	if(p>0)	
		return 0*puts("No");
	puts("Yes");	
	for(int i=1;i<=n*n;i++)
		printf("%d ",ans[i]);
	puts("");	
	return 0;
}


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

const int32_t MAX_N = 100;
const int32_t MAX_V = 1000;

int32_t values[MAX_N + 5], weights[MAX_N + 5];
int64_t dp[MAX_N + 5][MAX_N * MAX_V + 5];

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

	int32_t n, w;
	std::cin >> n >> w;

	for(int32_t i = 1; i <= n; i++) { 
		std::cin >> weights[i] >> values[i];
	}
	
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	for(int32_t i = 1; i <= n; i++) {
		for(int32_t j = 0; j <= MAX_N * MAX_V; j++) {
			if(j < values[i]) {
				dp[i][j] = dp[i - 1][j];
			}
			else {
				int64_t aux1 = dp[i - 1][j];
				int64_t aux2 = dp[i - 1][j - values[i]];

				if(aux1 == -1) {
					if(aux2 == -1) {
						dp[i][j] = -1;
					}
					else {
						dp[i][j] = aux2 + weights[i];
					}
				}
				else {
					if(aux2 == -1) {
						dp[i][j] = aux1;
					}
					else {
						dp[i][j] = std::min(aux1, aux2 + weights[i]);
					}
				}
			}
		}
	}

	for(int32_t i = MAX_N * MAX_V; i >= 0; i--) {
		if(dp[n][i] <= w && dp[n][i] != -1) {
			std::cout << i << '\n';
			return 0;
		}
	}
}



Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
const int Max=1e5+10;
int h[Max];
int n,a,b;
bool check(long long x){
    //cout<<x<<"!!!!!!!!!!";
    long long base=x*b;
    long long cnt=0;
    for(int i=1;i<=n;i++){
        if(h[i]>base){
            cnt+=((h[i]-base)/(a-b));
            if((h[i]-base)%(a-b)){
                cnt++;
            }
            if(cnt>x){
                return 0;
            }
        }
    }
    //cout<<cnt<<endl;
    return 1;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>a>>b;
    long long l=0,r=0;
    for(int i=1;i<=n;i++){
        cin>>h[i];
        r+=h[i]/a;
        if(h[i]%a){
            r++;
        }
    }
    sort(h+1,h+1+n);
    while(l<=r){
        long long mid=l+r>>1;
        if(check(mid)){
            r=mid-1;
        }else{
            l=mid+1;
        }
    }
    cout<<l<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
ll N;
vector<ll> v[(ll)1e5];
void bfs(ll start, ll *dist){
    memset(dist, 1145148931919810, N);
    queue<ll> q;
    q.push(start);
    bool used[N] = {};
    used[start] = 1;
    dist[start] = 0;
    while(q.size()){
        ll now = q.front();
        q.pop();
        for(ll next : v[now]){
            if(used[next]) continue;
            dist[next] = dist[now] + 1;
            used[next] = 1;
            q.push(next);
        }
    }
}
int main(){
    cin >> N;
    for(ll i = 1; i < N; i++){
        ll a, b;
        cin >> a >> b;
        v[--a].push_back(--b);
        v[b].push_back(a);
    }
    ll po[N], yo[N];
    bfs(0, po);
    bfs(N - 1, yo);
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        if(po[i] <= yo[i]) ans++;
        else ans--;
    }
    cout << (ans <= 0 ? "Snuke\n" : "Fennec\n");
    return 0;
}

Measured memory_bytes: 8132
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int d = in.nextInt();
        int n = in.nextInt();

        if (n == 100) {
            out.println((int) Math.pow(100, d) * 101);
        } else {
            out.println((int) Math.pow(100, d) * n);
        }
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


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

using ll = long long;

constexpr ll INF = 1'010'000'000'000'000'017LL;
constexpr ll MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(ll i = (start); i < end; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }

template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
using pint = pair<int, int>;
using pll = pair<ll, ll>; using vp = V<pll>;

ll mod(ll val, ll m){ ll res = val % m; if(res < 0) res += m; return res;}
ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u;}
ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }


//---------------------------------------------------------------

void Main()
{
    int N;
    ll ans;
    cin >> N;
    vi X(N);

    int x_min, x_max;
    REP(i, N){
        cin >> X[i];
        x_min = min(x_min, X[i]);
        x_max = max(x_max, X[i]);
    }

    sort(ALL(X));

    ll strg;
    ans = INF;
    FOR(p, x_min, x_max+1){
        strg = 0;
        REP(i, N){
            strg += (X[i] - p) * (X[i] - p);
        }
        ans = min(ans, strg);
    }

    cout << ans << endl;
}

//---------------------------------------------------------------
int main()
{
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;cin>>a>>b>>c>>d;
  if(a+b>c+d) printf("Left\n");
  if(a+b<c+d) printf("Right\n");
  if(a+b==c+d) printf("Balanced\n");
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

dp = [0 for _ in range(N)]
for i in range(1, N):
    if i == 1:
        dp[i] = dp[i-1] + abs(H[i]-H[i-1])
    else:
        dp[i] = min(dp[i-1] + abs(H[i]-H[i-1]), dp[i-2] + abs(H[i]-H[i-2]))

print(dp[N-1])

Measured memory_bytes: 13908
<?php
$nums = fscanf(STDIN, '%d %d %d %d %d %d:w');
fscanf(STDIN, '%s', $line);

$directions = preg_split('//', trim($line), -1, PREG_SPLIT_NO_EMPTY);

$dice = array_reduce($directions, function ($dice, $direction) {
    return $dice->moveTo($direction);
}, new Dice($nums));

echo $dice->getCenter()."\n";

class Dice
{
    private $numbers;

    private $north;
    private $south;
    private $west;
    private $east;
    private $center;

    public function __construct(array $numbers=array(1,2,3,4,5,6))
    {
        $this->numbers = $numbers;

        $this->north  = 5;
        $this->center = 1;
        $this->south  = 2;
        $this->west   = 4;
        $this->east   = 3;
    }

    public function getCenter()
    {
        return $this->numbers[$this->center-1];
    }

    public function moveTo($direction)
    {
        switch ($direction) {
        case 'N':
            $this->moveToNorth();
            break;
        case 'S':
            $this->moveToSouth();
            break;
        case 'E':
            $this->moveToEast();
            break;
        case 'W':
            $this->moveToWest();
            break;
        }

        return $this;
    }

    public function moveToEast()
    {
        $this->east   = $this->center;
        $this->center = $this->west;
        $this->west   = 7 - $this->east;

        return $this;
    }

    public function moveToWest()
    {
        $this->west   = $this->center;
        $this->center = $this->east;
        $this->east   = 7 - $this->west;
    }

    public function moveToNorth()
    {
        $this->north  = $this->center;
        $this->center = $this->south;
        $this->south  = 7 - $this->north;
    }

    public function moveToSouth()
    {
        $this->south  = $this->center;
        $this->center = $this->north;
        $this->north  = 7 - $this->south;

        return $this;
    }
}

Measured memory_bytes: 6764
import java.io.*;class Main{
public static void main(String[]_)throws Exception{
int i;
double l[]=new double[8];
BufferedReader B=new BufferedReader(new InputStreamReader(System.in));
for(String s;(s=B.readLine())!=null;
System.out.println(
((l[0]-l[2])*(l[5]-l[1])+(l[1]-l[3])*(l[0]-l[4]))*
((l[0]-l[2])*(l[7]-l[1])+(l[1]-l[3])*(l[0]-l[6]))<0||
((l[4]-l[6])*(l[1]-l[5])+(l[5]-l[7])*(l[4]-l[0]))*
((l[4]-l[6])*(l[3]-l[5])+(l[5]-l[7])*(l[4]-l[2]))<0
?"NO":"YES")){
_=s.split(",");
for(i=0;i<8;i++)l[i]=Double.valueOf(_[i]);
}
}
}

Measured memory_bytes: 9804
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a; i < b; ++i)

int debug = 0;

const int N = 5000;

int n, cnt[30][N], ans = 0;
string s;

main() {
    cin >> n;
    cin >> s;
    s = '_' + s;
    rep(c, 0, 26) {
        rep(i, 1, n + 1) {
            cnt[c][i] = cnt[c][i - 1] + ((s[i]-'A') == c);
        }
    }
    rep(i, 1, n + 1) {
        rep(k, i + 2, n + 1) {
            if (s[i] == s[k]) {
                continue;
            }
            int c1 = s[i] - 'A', c2 = s[k] - 'A';

            int cur = (k - i - 1);
            cur -= (cnt[c1][k-1] - cnt[c1][i]);
            cur -= (cnt[c2][k-1] - cnt[c2][i]);
            if ((i + k) % 2 == 0) {
                int mid = (i + k) / 2;
                if (s[i] != s[mid] && s[mid] != s[k]) {
                    cur--;
                }
            }
            if (debug) {
                cerr << " cur: " << cur << " c1: " << c1 << endl;
            }
            ans += cur;
        }
    }
    cout << ans;
}

Measured memory_bytes: 4560
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int h,w;
    cin >> h >> w;
    for (int i=0; i<h; i++) {
        string s;
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a>=k)
		printf("%d\n",k);
	else if(a+b>=k)
		printf("%d\n",a);
	else
		printf("%d\n",a - min(k-a-b,c));
}


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

typedef struct
{
    long long score;
    bool is_first;
}WORKER;

int main()
{
    int n;
    while(1)
    {
        WORKER worker[4000];
        vector<int> id_list;
        int cnt = 0;
        for(int i=0; i<4000; i++)
        {
            worker[i].score = 0;
            worker[i].is_first = true;
        }
        cin >> n;
        if(n == 0)
        {
            break;
        }
        for(int i=0; i<n; i++)
        {
            int id;
            long long p;
            long long q;
            cin >> id >> p >> q;
            worker[id].score += p * q;
            if(worker[id].score >= 1000000 && worker[id].is_first)
            {
                id_list.push_back(id);
                worker[id].is_first = false;
            }
        }
        for(int i=0; i<id_list.size(); i++)
        {
            cout << id_list[i] << endl;
        }
        if(id_list.size() == 0)
        {
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3164
class UnionFind:

    def __init__(self, n):
        self.t = [-1] * (n + 1)

    def flatten(self):
        for i, _ in enumerate(self.t):
            self.find_root(i)

    def union(self, a, b):
        ra = self.find_root(a)
        rb = self.find_root(b)
        if ra != rb:
            self.t[max(ra, rb)] = min(ra, rb)

    def find_root(self, x):
        t = []
        while self.t[x] > 0:
            t.append(x)
            x = self.t[x]
        for _t in t:
            self.t[_t] = x
        return x


def solve(string):
    n, m, k, *abcd = map(int, string.split())
    r = [0] * (n + 1)
    uf = UnionFind(n)
    for a, b in zip(*[iter(abcd[:2 * m])] * 2):
        r[a] += 1
        r[b] += 1
        uf.union(a, b)
    uf.flatten()
    for i, v in enumerate(uf.t):
        uf.t[i] = i if v < 0 else v
    mp = {k: set([]) for k in set(uf.t[1:])}
    for i, v in enumerate(uf.t[1:], start=1):
        mp[v].add(i)
    for c, d in zip(*[iter(abcd[2 * m:])] * 2):
        r[c] += 1 if d in mp[uf.t[c]] else 0
        r[d] += 1 if c in mp[uf.t[d]] else 0
    mp = {k: len(v) for k, v in mp.items()}
    return " ".join([str(mp[uf.t[i]] - 1 - r[i]) for i in range(1, n + 1)])


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

using std::cin;
using std::endl;
using std::cout;
using std::string;

int main() {
	string a,b;
	cin >> a >> b;
	int pos = -1;
	while ((pos = a.find(b,pos+1)) != string::npos) {
		cout << pos << endl;
	}
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    if(s=="SUN"){
        cout << 7 << endl;
    }else if(s=="MON"){
        cout << 6 << endl;
    }else if(s=="TUE"){
        cout << 5 << endl;
    }else if(s=="WED"){
        cout << 4 << endl;
    }else if(s=="THU"){
        cout << 3 << endl;
    }else if(s=="FRI"){
        cout << 2 << endl;
    }else if(s=="SAT"){
        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
if N == 1:
    for _ in range(Q):
        v, w = map(int, input().split())
        print(min(v, w))
else:
    L = [1]
    aa = 1
    def ch(k):
        return (k-2)//N+1
    
    def chh(a, b):
        if a == b:
            return a
        
        if a > b:
            a, b = b, a
        
        return chh(a, ch(b))
        
    for _ in range(Q):
        v, w = map(int, input().split())
        print(chh(v, w))


Measured memory_bytes: 68696
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n, l[max];
    int ans=0;
    
    scanf("%d", &n);
    rep(i, n){
        scanf("%d", &l[i]);
    }
    
    qsort(l, n, sizeof(int), up_comp);
    
    rep(i, n-1){
        ans+=l[i];
    }
    
    if (ans>l[n-1]) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int n;
    cin >> n;
    pii a[n];
    rep(i, 0, n) cin >> a[i].first, a[i].second = i+1;
    sort(a, a + n);
    rep(i, 0, n-1)
        cout << a[i].second << ' ';
    cout << a[n-1].second << '\n';
    return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>

#define MAX 1000000

main(){
  int in_num;
  int i, j;
  int count = 0;
  int res;
  int pres[MAX];

  while(1){
    res = scanf("%d", &in_num);

    if(res == EOF) break;

    /* initialization */
    for(i = 0 ; i <= in_num ; i++){
      pres[i] = 1;
    }

    /* 0,1 -> 1 */
    pres[0] = 0;
    pres[1] = 0;

    /* 2~ */
    for(i = 2 ; i <= in_num ; i++){
      if(pres[i] == 1){
        /* pres[i*2~] -> 0 */
        for(j = 2 ; i * j <= in_num ; j++){
          pres[i * j] = 0;
        }
      }
    }

    /* count */
    for(i = 2 ; i <= in_num ; i++){
      if(pres[i] == 1){
        count++;
	//printf("%d\n", i);
      }
    }

    printf("%d\n", count);
    count = 0;
  }
  return 0;
}

Measured memory_bytes: 4500
from typing import List, Tuple


def bubble_sort(A: List[int]) -> Tuple[List[int], int]:
    flag: bool = True
    count: int = 0

    while flag == True:
        flag = False
        for j in range(len(A) - 1, 0, -1):
            if A[j - 1] > A[j]:
                A[j - 1], A[j] = A[j], A[j - 1]
                flag = True
                count += 1

    return A, count


def main():
    _ = int(input())
    A: List[int] = list(map(int, input().split()))

    lst, count = bubble_sort(A)
    print(*lst, sep=" ")
    print(count)


if __name__ == "__main__":
    main()



Measured memory_bytes: 7188
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int h, w; cin >> h >> w;
    vector<vector<P>> ar(h, vector<P>(w));
    rep(i,h)rep(j,w) cin >> ar[i][j].first;
    rep(i,h)rep(j,w) cin >> ar[i][j].second;
    vector<vector<int>> mz(h+1,vector<int>(w+1,0));
    rep(i,h)rep(j,w) mz[i][j] = abs(ar[i][j].second-ar[i][j].first);
    vector<vector<vector<bool>>> dp(h+1,vector<vector<bool>>(w+1,vector<bool>(13000,false)));
    dp[0][0][mz[0][0]] = true;
    rep(i,h){
        rep(j,w){
            rep(k,13000){
                if (dp[i][j][k]){
                    dp[i][j+1][k+mz[i][j+1]] = true;
                    dp[i][j+1][abs(k-mz[i][j+1])] = true;
                    dp[i+1][j][k+mz[i+1][j]] = true;
                    dp[i+1][j][abs(k-mz[i+1][j])] = true;
                }
            }
        }
    }
    rep(i,13000){
        if(dp[h-1][w-1][i]){
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 11264
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#include <queue>

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


int main(){
    int N;
    string S;
    cin >> N >> S;
    if( S.length() %2 == 1){
        cout << "No" << endl;
        return 0;
    }

    int half = S.length() / 2;
    rep(i,half){
        if( S[i] != S[i+half]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
n = int(input())
def all_search(array):
    if len(array) == n:
        print(array)
    else:
        kind = len(set(array))
        fin = min(kind + 1, len(array) + 1)
        for i in range(fin):
            res = array + chr(i + ord('a'))
            all_search(res)
all_search("")


Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int a, b;
	 cin >> a >> b;
	 int k = a;
	 string s,t;
	 while(a > 0){
	 	s += (b + '0');
	 	a --;
	 }
	 while(b > 0){
	 	t += (k + '0');
	 	b --;
	 }
	 cout << min(s,t);
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
#define _GLIBCXX_DEBUG
                    
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}


int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  string S; cin >> S;
  rep(i, S.size()) {
    if(('Z' - S.at(i))>=N) S.at(i) += N;
    else S.at(i) = 'A' + (N - 1) - ('Z' - S.at(i));
    cout << S.at(i);
  }  
  
}


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

int n, m, v, p, a[100009];
vector<int> pv;

bool ps(int pi)
{
	pv.clear();
	for (int i = 0; i < n && pv.size() < p; i++) {
		if (i == pi) continue;
		int t = a[pi] + m - a[i];
		if (t < 0) return false;
		pv.push_back(t);
	}
	long long s = 0;
	for (int i = 0; i < pv.size(); i++) 
		s += min(pv[i], m);
	s += 1LL * (n - p) * m;
	return (s >= 1LL * m * v);
}

int bs(int s, int e)
{
	int md = (s + e) / 2;
	if (s >= e) return md;
	if (ps(md)) bs(s, md);
	else bs(md + 1, e);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> v >> p; p = n - p;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	cout << n - bs(0, n - 1) << '\n';
	return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////

ll N;
ll prm[101010];
ll prmn;
ll ans[1010][1010];
ll i, j, k;
ll gcd(ll a,ll b){
    if(b==0)
        return a;
    return gcd(b, a % b);
}
int main(){
    scanf("%lld",&N);
    if(N==2){
        printf("4 7\n23 10");
        return 0;
    }
    i = 3;
    prm[0] = 2;
    prmn = 1;
    while(prmn<=N*2){
        fornum(k,1,prmn){
            if(i%prm[k]==0){
                break;
            }
        }
        if(k==prmn){
            prm[prmn] = i;
            prmn++;
            //printf("%lld,%lldd\n", i, prmn);
        }
        i += 2;
    }
    
    fornum(i,0,N){
        ans[i+10][N+10
        ] =ans[N+10][i+10] = ans[i+10][9] =ans[9][i+10] = 1;
        fornum(j,0,N){
            if((i+j)%2)
                continue;
            //printf("%lld,%lld:%lld,%lld\n", i, j,(i-j+N)/2,(i+j)/2+N);
            ans[i + 10][j + 10] = prm[(i - j + N) / 2] * prm[(i + j) / 2 + N];
        }
    }
    ll mx = 0;
    fornum(i,0,N){
        fornum(j,0,N){
            if((i+j)%2){
                ll d1 = ans[i + 9][j + 10]/gcd(ans[i + 9][j + 10] , ans[i + 10][j + 9]) * ans[i + 10][j + 9];
                ll d2 = ans[i + 11][j + 10]/gcd(ans[i + 11][j + 10] , ans[i + 10][j + 11]) * ans[i + 10][j + 11];
                ll d = d1 / gcd(d1, d2) * d2;
                ans[i + 10][j + 10] = d + 1;
            }
            if(mx<ans[i+10][j+10]){
                mx = ans[i + 10][j + 10];
            }
            printf("%lld ", ans[i + 10][j + 10]);
        }
        printf("\n");
    }
    //printf("%lld\n",mx);
    return 0;
}

Measured memory_bytes: 9216
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
   int n;
   cin>>n;
   VI w(n);
   rep(i,n) cin>>w[i];

   ll s1=w[0],s2=0;
   for(int i=1;i<n;i++){
       s2+=w[i];
   }

   ll ans=abs(s1-s2);
   for(int i=1;i<n-1;i++){
       s1+=w[i];
       s2-=w[i];
       if(ans>abs(s1-s2)) ans=abs(s1-s2);
   }
   
   cout<<abs(ans)<<endl;

}



Measured memory_bytes: 256
#include<iostream>

int main(void){
    int x;
    std::cin >> x;

    bool flag;
    while(true){
	flag = true;
	for(int i = 2; i < x; i++){
	    if(x % i == 0){
		flag = false;
		break;	
	    }
	}
	if(flag) break;
	x++;
    }
    std::cout << x << std::endl;
    return 0;
}



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

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];

    vector<vector<bool>> visited(H, vector<bool>(W));

    const int d[4] = {1, -1, 0, 0};
    auto routeCount = [&](int h, int w){
        i64 black = 0;
        i64 white = 0;
        queue<pair<int,int>> que;
        que.push({h, w});
        
        while(!que.empty()){
            int y, x;
            tie(y, x) = que.front(); 
            que.pop();

            for(int i = 0; i < 4; i++){
                int ny = y + d[i];
                int nx = x + d[i^2];
                if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
                if(visited[ny][nx] || S[y][x] == S[ny][nx]) continue;

                if(S[ny][nx] == '#') ++black;
                else ++white;
                visited[ny][nx] = true;
                que.push({ny, nx});
            }
        }

        return black*white;
    };
    
    i64 ans = 0;
    for(int h = 0; h < H; h++){
        for(int w = 0; w < W; w++){
            if(visited[h][w]) continue;
            ans += routeCount(h,w);
        }
    }
    cout << ans << endl;
}


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


bool LR(char c){

  if(('a'<=c && c<='g') || ('q'<= c && c <= 't') 
     || c=='v' || c=='w' || c=='x' || c=='z')
    return true;

  else
    return false;


}

int main(){

  char in;
  int sum;
  bool prev;

  while(1){

    scanf("%c",&in);
    if(in == '#'){ break; }
    prev = LR(in);


    sum = 0;

    
    while(scanf("%c",&in)){
      if(in == '\n'){
	break;
      }
      else{

	if(prev != LR(in) ){
	  sum ++;
	  prev = LR(in);
	}

      }

    }

    cout << sum << endl;



  }

  return 0;
}

Measured memory_bytes: 1152
N=int(input())
A=list(map(int,input().split()))
import heapq
B=A[:N]
C=[]
for i in range(N):
  C.append(-1*A[-1*(i+1)])
BP=[]
CP=[]
heapq.heapify(B)
heapq.heapify(C)
Bnow=sum(B)
Cnow=sum(C)*(-1)
BP.append(Bnow)
CP.append(Cnow)
for i in range(N):
  heapq.heappush(B,A[N+i])
  heapq.heappush(C,A[2*N-i-1]*(-1))
  b=heapq.heappop(B)
  c=heapq.heappop(C)
  Bnow+=A[N+i]-b
  Cnow+=c-A[2*N-i-1]*(-1)
  BP.append(Bnow)
  CP.append(Cnow)
D=CP[::-1]
ans=BP[0]-D[0]
for i in range(1,N+1):
  d=BP[i]-D[i]
  ans=max(ans,d)
print(ans)

Measured memory_bytes: 38676
// Facts.cpp
#include <iostream>
#include <vector>
using namespace std;

class Facts
{
public:
    long long mod = 1000000007;
    int n_max = 1;
    vector<long long int>  fact{1, 1};
    vector<long long int>  inv{1, 1};
    vector<long long int>  factinv{1, 1};

    Facts();
    Facts(int64_t mod);
    int64_t cmb(int n, int r);
    void setup_table(int t);
};

Facts::Facts(int64_t m){
  mod = m;
}

int64_t Facts::cmb(int n, int r){
  if(r < 0 || n < r) return 0;
  if(n_max < n) setup_table(n);
  int64_t res = fact[n] * (factinv[r] * factinv[n-r] % mod) % mod;
  if(res<0) res+=mod;
  return res;
}

void Facts::setup_table(int t){
  for(int i=n_max+1; i<=t; i++){
    fact.push_back( fact.back() * i % mod );
    inv.push_back( -inv[mod % i] * (mod / i) % mod );
    factinv.push_back( factinv.back() * inv.back() % mod );
  }
  n_max = t;
}

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

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main(){
  
  int64_t mod = 998244353;
  
  int64_t n, m, k;
  cin >> n >> m >> k;
  
  int64_t ans = 0, t;
  Facts f = Facts(mod);
  t = m * modpow(m-1, n-1-k, mod) % mod;
  
  for(int i=k; i>=0; i--){
    ans += f.cmb(n-1, i) * t % mod;
    ans %= mod;
    t = t * (m-1) % mod;
  }
  
  // if(ans < 0) ans += mod;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 8208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inputs;
		inputs = br.readLine().split(" ");
		int n = Integer.parseInt(inputs[0]);
		int m = Integer.parseInt(inputs[1]);
		@SuppressWarnings("unchecked") ArrayList<Integer>[] jobs = new ArrayList[m + 1]; // 遅延日数ごとに仕事をグルーピングする
		for ( int i = 0; i <= m; i++ ) {
			ArrayList<Integer> a = new ArrayList<>();
			a.add(0); // ダミー要素
			jobs[i] = a;
		}

		for ( int i = 0; i < n; i++ ) {
			inputs = br.readLine().split(" ");
			int d = Integer.parseInt(inputs[0]);
			int f = Integer.parseInt(inputs[1]);
			if ( d > m ) continue; // 遅延日数的に候補になりえない仕事は除外
			jobs[d].add(f);
		}

		long total = 0;
		
		PriorityQueue<Integer> pool = new PriorityQueue<Integer>(Collections.reverseOrder()); // job候補のプール

		// m日目をゼロとして考え後退していく days:残り日数
		for ( int today = 0; today <= m; today++ ) {
			pool.addAll(jobs[today]);
			total += (long) pool.poll();
		}

		System.out.println(total);
		br.close();
	}
}

Measured memory_bytes: 53920
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <sstream>
using namespace std;

class Judge{
public:
  vector<string>getCts(int n, vector<string>outVec){
    int nAC = 0;
    int nWA = 0;
    int nTLE = 0;
    int nRE = 0;
    for(int i=0;i<n;i++){
      string s = outVec[i];
      if(s=="AC"){
	nAC++;
      }else if(s=="WA"){
	nWA++;
      }else if(s=="TLE"){
	nTLE++;
      }else if(s=="RE"){
	nRE++;
      }
    }
    vector<string>retVec;
    stringstream acSS,waSS,tleSS,reSS;
    acSS<<"AC x "<<nAC;
    waSS<<"WA x "<<nWA;
    tleSS<<"TLE x "<<nTLE;
    reSS<<"RE x "<<nRE;
    retVec.push_back(acSS.str());
    retVec.push_back(waSS.str());
    retVec.push_back(tleSS.str());
    retVec.push_back(reSS.str());      
    return retVec;
  }
};

int main(int argc, const char*argv[]){
  Judge j;
  string nLn;
  getline(cin,nLn);
  int n = atoi(nLn.c_str());
  vector<string>outputs;
  for(int i=0;i<n;i++){
    string outLn;
    getline(cin,outLn);
    outputs.push_back(outLn);
  }
  vector<string>ctVec = j.getCts(n,outputs);
  int len = ctVec.size();
  for(int i=0;i<len;i++){
    cout<<ctVec[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 9548
H, W, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]

place = [[0, 0] for _ in range(H * W)]
for h in range(H):
	for w in range(W):
		place[a[h][w] - 1] = [h, w]

cost = [abs(place[i][0] - place[i + d][0]) + abs(place[i][1] - place[i + d][1]) for i in range(H * W - d)]

ans = [0 for _ in range(H * W)]

for i in range(d, H * W):
	ans[i] = ans[i - d] + cost[i - d]

Q = int(input())

for q in range(Q):
	l, r = map(int, input().split())
	print(ans[r - 1] - ans[l - 1])

Measured memory_bytes: 71056