akhauriyash/Code-Regression huggingface dataset:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int,sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()

res = 0
for i in range(N):
    res += (i+1)*(N-i)

for _ in range(N-1):
    i, j = LI()
    i -= 1
    j -= 1
    if i > j: i, j = j, i
    res -= (i+1)*(N-j)

print(res)


Measured memory_bytes: 68412
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a;
	cin>>b;
	cin>>c;
	cin>>d;
	a=a>b?b:a;
	c=c>d?d:c;
	cout<<a+c;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"
import "bufio"
import "os"
import "strconv"

var _sw = bufio.NewScanner(os.Stdin)

func main() {
	N := NextInt()
	H := make([]int, N)

	max := 0
	cnt := 0
	for i := range H {
		H[i] = NextInt()
		if i > 0 {
			if H[i] <= H[i-1] {
				cnt++
			} else {
				cnt = 0
			}
		}
		max = Max(cnt, max)
	}

	fmt.Println(max)
}

func init() {
	_sw.Split(bufio.ScanWords)
}

func NextInt() int {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	i, e := strconv.Atoi(_sw.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func NextString() string {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	return _sw.Text()
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func Min(x, y int) int {
	if x > y {
		return y
	}
	return x
}


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

int main() {
    ll X;
    cin >> X;
    ll ans = 0;
    ans += (X/500)*1000;
    X %= 500;
    ans += (X/5)*5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include<iomanip>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);    
    float l;
    cin>>l;
    cout << std::setprecision(16)<<l*l*l/27;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int i, n, q, q1, q2, arr[100011], num_ap[100011] = {0};
  long sum = 0, ans[100011];
  scanf("%d", &n);
  for(i = 0 ; i < n ; i++)
  {
    scanf("%d", &arr[i]);
    num_ap[arr[i]]++;
    sum += arr[i];
  }
  scanf("%d", &q);
  for(i = 0 ; i < q ; i++)
  {
      scanf("%d %d", &q1, &q2);
      long nums = num_ap[q1];
      num_ap[q1] = 0;
      num_ap[q2] += nums;
      sum += (q2 * nums);
      sum -= (q1 * nums);
      ans[i] = sum;
  }
  for(i = 0 ; i < q ; i++)
      printf("%ld\n",ans[i]);
  return 0;
}


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

using namespace std;

int main()
{
	string s;
	
	cin >> s;
	
	if (s[0] == 'S')
	{
		cout << "Cloudy" << endl;
	}
	if (s[0] == 'C')
	{
		cout << "Rainy" << endl;
	}
	if (s[0] == 'R')
	{
		cout << "Sunny" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }

ll f(ll x){
  string s = to_string(x);
  return sz(s);
}

int main(int argc, char const *argv[]) {
  ll n;
  cin >> n;
  ll ans = INF;
  for (ll i = 1; i <= sqrt(n); i++){
    if (n % i != 0) continue;
    ll j = n / i;
    ll tmp = max(f(i), f(j));
    chmin(ans, tmp);
    if (i == 1) i++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3708
#include <stdio.h>

int main()
{
    int h,m,s,t;
    scanf("%d",&t);
    h = t/3600;
    t = t%3600;
    m = t/60;
    s = t%60;

    printf("%d:%d:%d\n",h,m,s);
    return (0);
}

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

typedef long long ll;
const int maxn = 8e5 + 3;
const ll mo = 1e9 + 7;
int n, p[maxn], s[maxn];
std::vector<int> E[maxn];

ll fact[maxn], ract[maxn], fin[maxn];

ll mpow(ll u, ll k) {
    ll ans = 1;
    while(k > 0) {
        if(k & 1)
            ans = ans * u % mo;
        k >>= 1;
        u = u * u % mo;
    }
    return ans;
}

ll rev(const ll &u) {
    return mpow(u, mo - 2);
}

int clk, ca[maxn], cl[maxn], cr[maxn];
ll md[maxn], dm[maxn];

void dfs(int u) {
    s[u] = 1;
    cl[u] = clk;
    ca[clk++] = u;
    for(auto &&v : E[u]) {
        if(p[u] == v)
            continue;
        p[v] = u;
        dfs(v);
        s[u] += s[v];
    }
    cr[u] = clk;
}

void modify(int l, int r, const ll &v) {
    md[l] *= v;
    md[l] %= mo;
    md[r] *= rev(v);
    md[r] %= mo;
}

void trans(int i) {
    int l = cl[i], r = cr[i];
    int ps = n - s[i];
    ll domi = ract[ps];
    for(auto &&v : E[i]) {
        if(v == p[i])
            continue;
        domi = domi * ract[s[v]] % mo;
    }
    dm[i] = domi;
    if(p[i]) {
        ll w = domi * fact[ps] % mo * fact[s[i] - 1] % mo;
        modify(0, clk, w);
        modify(l, r, rev(w));
    }
    for(auto &&v : E[i]) {
        if(v == p[i])
            continue;
        ll w = domi * fact[s[v]] % mo * fact[n - s[v] - 1] % mo;
        modify(cl[v], cr[v], w);
    }
}

int main() {
    for(int i = 0; i < maxn; ++i) {
        md[i] = 1;
    }
    fact[0] = 1;
    for(int i = 1; i < maxn; ++i) {
        fact[i] = fact[i - 1] * (ll)i % mo;
    }
    ract[maxn - 1] = rev(fact[maxn - 1]);
    for(int i = maxn - 2; i >= 0; --i) {
        ract[i] = ract[i + 1] * (ll)(i + 1) % mo;
    }
    scanf("%d", &n);
    for(int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        E[u].push_back(v);
        E[v].push_back(u);
    }
    dfs(1);
    for(int i = 1; i <= n; ++i) {
        trans(i);
    }
    ll pm = 1;
    for(int i = 0; i < clk; ++i) {
        pm = pm * md[i] % mo;
        int u = ca[i];
        ll ans = fact[n - 1] * dm[u] % mo * pm % mo;
        ans = (ans + mo) % mo;
        fin[u] = ans;
    }
    for(int i = 1; i <= n; ++i)
        printf("%lld\n", fin[i]);
    return 0;
}

Measured memory_bytes: 66036
#!/usr/bin/env python3

def main():
    n, m = map(int, input().split())
    x = []
    y = []
    z = []
    for i in range(n):
        a, b, c = map(int, input().split())
        x.append(a)
        y.append(b)
        z.append(c)

    res = 0
    for pattern in [(1, 1, 1), (1, 1, -1), (1, -1, 1), (1, -1, -1),
        (-1, 1, 1), (-1, 1, -1), (-1, -1, 1), (-1, -1, -1)]:
        li = []
        for i in range(n):
            kariscore = pattern[0] * x[i] + pattern[1] * y[i] + pattern[2] * z[i]
            li.append((kariscore, i))
        li = list(reversed(sorted(li)))
        eatlist = [i for k, i in li[:m]]
        res = max(res, score(eatlist, x, y, z))
    print(res)

def score(eatlist, x, y, z):
    xx = 0
    yy = 0
    zz = 0
    for i in eatlist:
        xx += x[i]
        yy += y[i]
        zz += z[i]
    return abs(xx) + abs(yy) + abs(zz)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#define DEBUG
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
#define all(x) begin(x), end(x)
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
#define TCC template<class C
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
#define ENI typename enable_if<
#define DTOR , Dbg&>::type operator<<
#define RIS return *this
TCC> static auto o(C *x)->decltype(os << *x, 0);
TCC> static char o(...);
TCC> ENI sizeof o<C>(0)!=1 DTOR(const C &x) {os<<x; RIS;}
TCC> Dbg &dump(C b, C e) {
    int ii = 0;
    for(C i = (os << "\n[", b); i!=e and ii<26; i++, ii++) *this << ", "+2*(i==b) << *i;
    RIS << ']';
}
TCC> ENI sizeof o<C>(0)==1 DTOR(const C &x) {
    return dump(all(x));
}
TCC, size_t X> ENI !is_same<C, const char>::value DTOR(C (&x)[X]) {
    return dump(all(x));
}
TCC, class D> Dbg &operator<<(const pair<C, D> &x) {RIS<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(ostream&)) { os << x; RIS; }
} dbg;
void err(istringstream *iss) { delete iss; }
TCC, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#ifdef DEBUG
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#else
#define bug(args...) 0
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
int T = 1, Q, cn;
const int inf = 1000000007, mxn = 105;

int n,l[mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    // cin >> T;
    auto inputAll = [&]()->void {
        
    };
    auto kase = [&]()->void {
        // cout << "Case " << cn << ": ";
        cin>>n;
        int ans=0;
        for(int i=1;i<=n;i++)cin>>l[i];
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                for(int k=j+1;k<=n;k++){
                    vector<int>v={l[i],l[j],l[k]};
                    sort(all(v));
                    ans+=v[1]!=v[0] and v[1]!=v[2] and v[0]+v[1]>v[2];
                }
            }
        }
        cout<<ans<<'\n';
    };
    auto resetAll = [&]()->void {
        
    };
    while (cn++!=T) inputAll(), kase(), resetAll();
}


Measured memory_bytes: 3668
#include<cstdio>
using namespace std;
int main(){
    int len;
    scanf("%d",&len);
    int x[len];
    for(int i=0;i<len;i++){
        scanf("%d",&x[i]);
    }
    for(int j=(len-1);j>=0;j--){
        printf("%d",x[j]);
        if(j!=0){
            printf(" ");
        }
    }
    printf("\n");
}


Measured memory_bytes: 2588
#include<bits/stdc++.h>
using namespace std;
char ch[20];
int n;
int main(){

	cin>>(ch+1);
	int n=strlen(ch+1);
	int flag=0;
	for (int i=2;i<=n;i++){
		if (ch[i]!='9') flag=1;
	}
	if (flag){
		cout<<(n-1)*9+(ch[1]-'1')<<"\n";
	}
	else {
		cout<<(n-1)*9+(ch[1]-'0')<<"\n";
	}
	return 0;
} 

Measured memory_bytes: 256
N = int(input())
seats = []
for i in range(0, 100000):
	seats.append(False)
for i in range(0, N):
	left, right = map(int, input().split())
	for j in range(left-1, right):
		seats[j] = True
cnt = 0
for i in range(0, 100000):
	if seats[i]: cnt += 1
print(cnt)

Measured memory_bytes: 45104
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int N,A,B,c;
	scanf("%d %d %d",&N,&A,&B);
	c = B-A;
	if(c%2==0&&c!=0) printf("Alice\n");
	else printf("Borys\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int setcount;
  double x1, y1, x2, y2, x3, y3, x4, y4;
  double r1, r2;
  int i;

  scanf("%d", &setcount);
  for(i=0; i<setcount; i++){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
    r1=(y2-y1)*(x4-x3);
    r2=(y4-y3)*(x2-x1);
    if(r1==r2) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long

int solve2(int N, int gA, int sA, int gB, int sB){
//	printf("(%lld, %lld, %lld, %lld, %lld)\n", N, gA, sA, gB, sB);
	int ans = 0, i;
	for(i = 0; i * gA <= N; i++){
		ans = max(ans, i * gB + ((N - i * gA) / sA) * sB + (N - i * gA) % sA);
	}
//	printf("ans = %lld\n", ans);
	return ans;
}

signed main(){
	int N, gA, gB, sA, sB, bA, bB, i, ans = 0;
	scanf("%lld", &N);
	scanf("%lld%lld%lld", &gA, &sA, &bA);
	scanf("%lld%lld%lld", &gB, &sB, &bB);
	int cnt = 0;
	cnt += (gA <= gB);
	cnt += (sA <= sB);
	cnt += (bA <= bB);
	if(cnt == 0){
		for(i = 0; i * gB <= N; i++){
			ans = max(ans, i * gA + solve2(N - i * gB, sB, bB, sA, bA));
		}
	}
	else if(cnt == 1){
		if(sA <= sB){
			swap(gA, sA);
			swap(gB, sB);
		}
		if(bA <= bB){
			swap(gA, bA);
			swap(gB, bB);
		}
		ans = solve2((N / gA) * gB + (N % gA), sB, bB, sA, bA);
	}
	else if(cnt == 2){
		if(sA > sB){
			swap(gA, sA);
			swap(gB, sB);
		}
		if(bA > bB){
			swap(gA, bA);
			swap(gB, bB);
		}
		N = solve2(N, sA, bA, sB, bB);
		ans = (N / gB) * gA + (N % gB);
	}
	else{
		swap(gA, gB);
		swap(sA, sB);
		swap(bA, bB);
		for(i = 0; i * gB <= N; i++){
//			printf("i = %lld\n", i);
//			printf("%lld\n", i * (gA - gB));
			ans = max(ans, i * gA + solve2(N - i * gB, sB, bB, sA, bA));
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS; ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MX 100001
#define FF freopen("input.in","r",stdin); freopen("output.txt","w",stdout);
int n,k;
pair<int ,int> a[MX];
ll dp[101][MX];
ll f(int i,int w)
{
    if(w>k)return -1e18;
    if(i==n)return 0;
    if(dp[i][w]!=-1)return dp[i][w];
    return dp[i][w]=max(f(i+1,w+a[i].first)+a[i].second,f(i+1,w));
}
int main()
{
    //FF;
    IOS;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        int x,y;
        cin>>x>>y;
        a[i]=make_pair(x,y);
    }
    memset(dp,-1,sizeof dp);
    cout<<f(0,0);
}



Measured memory_bytes: 79232
#include<stdio.h>
int linearSearch(int *,int,int);

int main(){
  int i,j,n,q,S[10000],T[10000],count=0;
    scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
    }
  
  for(i=0;i<q;i++){
  if(linearSearch(S,n,T[i])!=0){
    count++;
  }
  }
  
  printf("%d\n",count);
  
  return 0;
}

int linearSearch(int *S,int n,int x){
  int i=0,count;
  S[n]=x;
  while(S[i]!=x){
    i++;
    if(i==n){
      return 0;
    }
  }
  return 1;
  }


Measured memory_bytes: 2108
#include <stdio.h>
#include <math.h>

int main(void)
{
	int n, i;
	double l1, l2, l3;
	double temp, c;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%lf %lf %lf", &l1, &l2, &l3);
		
		if (l2 <= l1 && l3 <= l1){
			temp = l1;
			l1 = l3;
			l3 = temp;
		}
		else if (l1 <= l2 && l3 <= l2){
			temp = l2;
			l2 = l3;
			l3 = temp;
		}
		
		c = (l1 * l1) + (l2 * l2);
		c = sqrt(c);
		
		if (c == l3){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 616
#include <stdio.h>

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

   n_2 = n%1000;
   if(n_2!=0){
   ans = 1000-n_2;
 }else{
   ans=0;
 }
   printf("%d",ans);

return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())

using ll = long long;
using pset = multiset<pair<int,int>>;

const int N = 100005;

int n;

pset x, y;

pair<int,int> walk(int l, int r, int pos) {
  if (l <= pos && pos <= r)
    return {pos, 0};
  if (pos < l)
    return {l, l-pos};
  return {r, pos-r};
}

ll go(pset x, pset y, int iter) {
  ll result = 0;
  int pos = 0;
  
  while (true) {
    if (x.empty() && y.empty())
      break;
    pair<int,int> now;
    if (!iter) {
      now = *y.begin();
      swap(now.first, now.second);
      y.erase(y.begin());
      x.erase(x.find(now));
    } else {
      now = *(--x.end());
      x.erase(--x.end());
      y.erase(y.find({now.second, now.first}));
    }
    now = walk(now.first, now.second, pos);
    result += now.second;
    pos = now.first;
    iter ^= 1;
  }
  result += abs(pos);
  return result;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    x.insert({l, r});
    y.insert({r, l});
  }
  cout << max(go(x, y, 0), go(x, y, 1)) << '\n';
}


Measured memory_bytes: 19072
# -*- coding: utf-8 -*-

import os
import sys

def main():
    li = input().split()
    x = int(li[0])
    y = int(li[1])
    xheight = height(y-x-1)
    print(xheight - x)

def height(x):
    return sum(range(1, x + 1))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int K;
    cin >> K;
    int A, B;
    cin >> A >> B;
    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3676
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let N = parseInt(input[0][0], 10);
	a = input[1].map(e => parseInt(e, 10));
	kukanDP = Array.from({length: N}, () => []);

	console.log(DP(0, N - 1));
}

function DP(l, r){
	if (kukanDP[l][r] != null) return kukanDP[l][r];
	if (r === l + 1) {
		kukanDP[l][r] = Math.abs(a[l] - a[r]);
		return kukanDP[l][r];
	}
	if (r === l){
		kukanDP[l][r] = a[l];
		return kukanDP[l][r];
	}
	let tmp1 = a[l] - DP(l + 1, r);
	let tmp2 = a[r] - DP(l, r - 1);
	kukanDP[l][r] = Math.max(tmp1 ,tmp2);
	return kukanDP[l][r];
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 149748
import java.io.BufferedReader
import java.util.*
import kotlin.math.abs
import kotlin.math.min

fun main() = abc119d()

@OptIn(ExperimentalStdlibApi::class)
fun abc119d() = SimpleFastIOWithToken_abc119d().exec {
    val n = readInt()
    val abc = IntArray(3) { readInt() }
    val bamboos = IntArray(n) { readInt() }

    var answer = Int.MAX_VALUE

    searchAllPatterns(arrayOf(-1, 0, 1, 2), n) { groups ->
        val lengths = IntArray(3)
        var merge = 0
        groups.forEachIndexed { index, group ->
            if (group != -1) {
                if (lengths[group] != 0) merge++
                lengths[group] += bamboos[index]
            }
        }
        if (lengths.any { it == 0 }) return@searchAllPatterns
        val diffSum = (0..2).sumBy { abs(lengths[it] - abc[it]) }
        answer = min(answer, diffSum + merge * 10)
    }

    println(answer)
}

private inline fun <reified T> searchAllPatterns(patterns: Array<T>, length: Int, action: (Array<T>) -> Unit) {
    val patternSize = patterns.size
    val pow = (1..length).fold(1L) { acc: Long, _: Int -> acc * patternSize }
    val allPatterns = if (pow in 1..Int.MAX_VALUE) pow.toInt() else error("$pow is too large!")
    for (i in 0 until allPatterns) {
        val array = Array(length) { patterns[0] }
        var div = 1
        for (j in 0 until length) {
            array[length - j - 1] = patterns[(i / div) % patternSize]
            div *= patternSize
        }
        action(array)
    }
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc119d(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc119d.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 45216
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
typedef long long ll;
using namespace std;

int main(){
  ll i,j,k,n,ret=0;
  cin >> n;
  for(i=0;i*i<=n;i++){
    if(n%(i+1)==0){
      if(n/(i+1)>0 && n/(i+1)<i)ret+=i;
      if(i+1<(n/(i+1)-1))ret+=n/(i+1)-1;
    }
  }
  cout << ret << endl;
  return 0;
}


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

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

  vector<pair<pair<string, int>, int>> p(N);
  
  rep(i , N)
  {
    string s;
    int po;
    cin >> s >> po;
    p[i] = make_pair(make_pair(s, -po), i);
  }
  sort(p.begin(), p.end());
  rep(i , N)
  {
    cout << p[i].second+1 << endl;
  }
}

Measured memory_bytes: 256
from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    l[0]=0
    l[1]=0
    prime=[2]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0
    
    for i in range(3,limit+1,2):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)
                
def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r


def solve():
    n,d=mp()
    c=0
    for _ in range(n):
        a,b=mp()
        z=(a*a+b*b)**0.5
        if z<=d:
            c+=1
    print(c)
    


for _ in range(1):
    solve()
    


Measured memory_bytes: 9800
#include <iostream>
#include <algorithm>

using namespace std;

int N;
int A[100];

void solve() {
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        swap(A[i], A[minj]);
        if (i != minj) { cnt++; }
    }

    cout << A[0];
    for (int i = 1; i < N; i++) {
        cout << " " << A[i];
    }
    cout << endl;

    cout << cnt << endl;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 1164
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""





n = onem()

po = input()
#num = int("0B" + po,0)
co = po.count("1")

num = [0,0]

for i in range(n):
	num[0] *= 2
	num[1] *= 2
	if po[i] == "1":
		num[0] += 1
		num[1] += 1
	if co > 1:
			num[0] %= co-1
	num[1] %= co+1
	

for i in range(n):
	if po[i] == "0":
		coco = co + 1

		ima = num[1] + pow(2,(n-1-i),coco)
		ima %= coco
		coco = format(ima,"b").count("1")
		count = 1
		while True:
			if ima == 0:
				break
			else:
				ima %= coco
				count += 1
				"""
				if ima >= 10**5 + 1:
					coco = dp[ima-(10**5 + 1)]
				else:
				"""
				coco = format(ima,"b").count("1")

	else:
		coco = co - 1
		if coco == 0:
			count = 0
			print(count)
			continue
		ima = num[0] - pow(2,(n-1-i),coco)
		ima %= coco
		count = 1
		coco = format(ima,"b").count("1")
		while True:
			if ima == 0:
				break
			else:
				ima %= coco
				count += 1
				"""
				if ima >= 10**5 + 1:
					coco = dp[ima-(10**5 + 1)]
				else:
				"""
				coco = format(ima,"b").count("1")
	print(count)







Measured memory_bytes: 81536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, s;
ll f(ll b, ll n)
{
	return n < b ? n : f( b , n / b ) + n % b;
}
template <class T>
inline void _read(T &x)
{
	x = 0;
	char t = getchar();
	while (!isdigit(t)) t = getchar();
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
int main()
{
	_read(n), _read(s);
	if (s > n)
    {
        return puts("-1"), 0;
    }
	if (s == n)
	{
		printf("%lld", n + 1);
		return 0;
	}
	ll bs = sqrt(n) + 1;
	for (ll i = 2; i <= bs; ++i)
	{
		if (f(i, n) == s)
		{
			printf("%lld", i);
			return 0;
		}
	}
	ll ans = 1e18;
	n -= s;
	for (ll i = 1; i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			ll tmp = n / i + 1;
			if (f(tmp, n + s) == s) ans = min(ans, tmp);
		}
	}
	printf("%lld\n" , ans == 1e18 ? -1 : ans);
	return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);


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

    vint dp(x + 110);
    dp[0] = 1;

    Rep(i, x + 1)
    {
        if (dp[i] == 0) continue;
        dp[i + 100] = dp[i + 101] = dp[i + 102] = dp[i + 103] = dp[i + 104] = dp[i + 105] = 1;
    }

    cout << dp[x] << endl;

    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
ll l, r;

ll solve() {
	if (r - l + 1 >= 2019) return 0;
	ll mn = (l * r) % 2019;
	for (ll i = l; i <= r; i++)
		for (ll j = i + 1; j <= r; j++)
			mn = min(mn, (i * j) % 2019);
	return mn;
}

int main() {
	scanf("%lld%lld", &l, &r);
	printf("%lld\n", solve());
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
long long best(long long a, long long b, long long c, long long d){
    long long mn = LONG_LONG_MAX;
    if(8 * a < mn) mn = 8 * a;
    if(4 * b < mn) mn = 4 * b;
    if(2 * c < mn) mn = 2 * c;
    if(d < mn) mn = d;
    return mn;
}
long long best1(long long a, long long b, long long c){
    long long mn = LONG_LONG_MAX;
    if(4 * a < mn) mn = 4 * a;
    if(2 * b < mn) mn = 2 * b;
    if(c < mn) mn = c;
    return mn;
}
int main(){
    long long q, h, s, d;
    cin >> q >> h >> s >> d;
    long long n;
    cin >> n;
    if(n & 1){
        cout << n / 2 * best(q, h, s, d) + best1(q, h, s);
    } else cout << n / 2 * best(q, h, s, d);
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
//#define ivorysi
#define MAXN 100005
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
	res = 0;char c = getchar();T f = 1;
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) out(x / 10);
	putchar('0' + x % 10);
}
int N;
int A[MAXN];
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	read(N);
	for(int i = 1 ; i <= N ; ++i) read(A[i]);
	sort(A + 1,A + N + 1);
	if(N & 1) {
		int t = N / 2 + 1;
		int L = 1,R = N;int64 res = 0;
		for(int i = 1 ; i <= t - 2; ++i) {
			res -= 2 * A[i];
		}
		res = res - A[t - 1] - A[t];
		for(int i = t + 1 ; i <= N ; ++i) res += 2 * A[i];
		int64 tmp = 0;
		t = N - (N / 2 + 1) + 1;
		for(int i = N ; i >= t + 2 ; --i) tmp += 2 * A[i];
		tmp += A[t + 1] + A[t];
		for(int i = 1 ; i < t ; ++i) tmp -= 2 * A[i];
		res = max(res,tmp);
		out(res);enter;
	}
	else {
		int L = 1,R = N;
		int64 res = 0;
		for(int i = 1 ; i <= N - 2 ; ++i) {
			if(i & 1) res -= 2 * A[L++];
			else res += 2 * A[R--];
		}
		res += A[R] - A[L];
		out(res);enter;
	}
	return 0;
}


Measured memory_bytes: 640
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

void main() {
    string s;
    scan(s);

    int n = s.length.to!int;

    int btm = 1, top = n + 1;

    bool check(int k) {
        if (2*k <= n) {
            return true;
        }

        bool b = 1;
        char ch = s[n-k];

        foreach (i ; n-k .. k) {
            b &= s[i] == ch;
        }

        return b;
    }

    while (top - btm > 1) {
        int mid = (btm + top) / 2;

        if (check(mid)) {
            btm = mid;
        }
        else {
            top = mid;
        }
    }

    writeln(btm);
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 2428
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(repr(item))
        stderr.write(sep)
    stderr.write(end)


x1,y1,x2,y2 = f()
x3 = y1 - y2 + x2
x4 = y1 - y2 + x1
y3 = x2 - x1 + y2
y4 = x2 - x1 + y1
print(x3,y3,x4,y4)

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

int main()
{
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	if(s.size()!=(a+b+1)){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0; i<s.size(); i++){
		if(i!=a){
			if(!isdigit(s[i])){
				cout<<"No"<<endl;
				return 0;
			}
		}else if(s[i]!='-'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	
	return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

#ifdef OJ
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#else
#define debug(x)
#define debugv(x)
#endif

#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 1e9+7;
const int MAXN = 2e5+3;
const int INF = 1e9;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    vector<int> a(6);
    fori(i,5) {
        int x; cin >> x;
        a[x] = 1;
    }

    fore(i,1,5) if(!a[i]) RETURN(i);
    //int ntest; cin >> ntest; while(ntest--) 
    //{
    //}
    cout << '\n';
    return 0;
}


Measured memory_bytes: 3604
import java.util.*;
import java.lang.Math;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		double x1= Double.parseDouble(line[0]);
		double y1= Double.parseDouble(line[1]);
		double x2= Double.parseDouble(line[2]);
		double y2= Double.parseDouble(line[3]);
		double n=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		double answer = Math.sqrt(n);
		System.out.printf("%.5f",answer);
		System.out.println();
	}
}

Measured memory_bytes: 26428
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

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

long long modinv(long long a, long long m=MOD) {
    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;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


int main(){
    int N,K;
    int MAXN=101;
    bool OK[101];
    rep(i,101)OK[i] = false;
    cin >> N  >> K;    
    rep(i,K) {
        int d;
        cin >> d;
        rep(j,d) {
            int a;
            cin >> a;
            OK[a] = true;
        }
    }
    int count = 0;
    for(int i=1;i<=N;i++) {
        if(!OK[i])count++;
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;


int main (void) 
{

  /* Variable_Proclamation */
  int N;    // input

  int i, j;    // subscript
  int divid;
  int count;
  int max_cnt;
  int max_div;

  /* Input, Array_Proclamation */
  cin >> N;


  /* Initialize */
  max_cnt = 0;


  /* Calculation */
  for(i=1; i<=N; i++)
  {

    divid = i;
    count = 0;
    while(divid%2 == 0 && divid != 0)
    {
      divid /= 2;
      count++;
    }

    if(max_cnt <= count)
    {
      max_cnt = count;
      max_div = i;
    }

  }
  

  /* Output */
  cout << max_div << endl;


  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

vector<int> A;
vector<int> gcds;

int gcd(int a, int b) {
  if (min(a,b) == 0) return max(a,b);  //便宜上
  while (true) {
    if (a>b) {
      a %= b;
      if (a==0) return b;  
    } else {
      b %= a;
      if (b==0) return a;
    } 
  }
}

int multi_gcd(int b, int e) {
  int res = A[b];
  for (auto i=b+1; i<e; i++) {
    res = gcd(res, A[i]);
  }
  return res;
}

void solve(int b, int e, int acc) {
  int mid;
  mid = (b+e)/2;
  if (e-b == 1) {
    //cout << b << " " << acc << endl;
    gcds[b] = acc;
  } else {
    solve(b, mid, gcd(multi_gcd(mid, e), acc));
    solve(mid, e, gcd(multi_gcd(b, mid), acc));
  }
}

signed main() {
	  int N;	
    cin >> N;
    A.resize(N);
    gcds.resize(N);
    cin >> A;
    
    solve(0, N, 0);
    cout << *max_element(all(gcds)) << endl;

    return 0;
}


Measured memory_bytes: 1792
// AOJ Volume 0 Problem 0035

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

int map[8][8];

int get_map(int x, int y)
{
    if (x < 0 || x >= 8){
        return (0);
    }
    if (y < 0 || y >= 8){
        return (0);
    }

    return (map[y][x]);
}

int main(void)
{
    char line[12];
	int x, y;
    int i, j;

	while (1){
        x = y = -1;
        for (i = 0; i < 8; i++){
            if (fgets(line, 10, stdin) == NULL){
                exit(0);
            }
            for (j = 0; j < 8; j++){
                map[i][j] = line[j] - '0';
                if (map[i][j] == 1 && x == -1){
                    x = j;
                    y = i;
                }
            }
        }
        
        if (get_map(x, y + 3) == 1){
            printf("B\n");
        }
        else if (get_map(x + 3, y) == 1){
            printf("C\n");
        }
        else if (get_map(x - 1, y + 2) == 1){
            printf("D\n");
        }
        else if (get_map(x + 2, y + 1) == 1){
            printf("E\n");
        }
        else if (get_map(x + 1, y + 2) == 1){
            printf("F\n");
        }
        else if (get_map(x + 1, y) == 1 && get_map(x - 1, y + 1) == 1){
            printf("G\n");
        }
        else {
            printf("A\n");
        }
            if (fgets(line, 10, stdin) == NULL){
                exit(0);
            }
	}
    
    return (0);
}

Measured memory_bytes: 0
import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer

case class Dice(var d:Array[String]) {
  private val s = Array(4,0,2,3,5,1)
  private val w = Array(2,1,5,0,4,3)
  private val h = Array(0,2,4,1,3,5)
  private var all = Array.empty[Array[String]]

  def rotateAll() = {
    val buf = ArrayBuffer.empty[Array[String]]

    buf += d
    buf += s.map(d)
    buf += s.map(s).map(d)
    buf += s.map(s).map(s).map(d)
    buf += w.map(d)
    buf += w.map(w).map(w).map(d)

    buf += h.map(d)
    buf += s.map(s).map(s).map(h).map(d)
    buf += w.map(h).map(d)
    buf += w.map(w).map(w).map(h).map(d)
    buf += s.map(h).map(d)
    buf += s.map(s).map(h).map(d)

    buf += h.map(h).map(d)
    buf += s.map(s).map(s).map(h).map(h).map(d)
    buf += w.map(h).map(h).map(d)
    buf += w.map(w).map(w).map(h).map(h).map(d)
    buf += s.map(h).map(h).map(d)
    buf += s.map(s).map(h).map(h).map(d)

    buf += h.map(h).map(h).map(d)
    buf += s.map(s).map(s).map(h).map(h).map(h).map(d)
    buf += w.map(h).map(h).map(h).map(d)
    buf += w.map(w).map(w).map(h).map(h).map(h).map(d)
    buf += s.map(h).map(h).map(h).map(d)
    buf += s.map(s).map(h).map(h).map(h).map(d)
    all = buf.toArray
  }

  def getAll = all

  override def toString() = d(0)
}

object Main extends App {
  val faces = readLine.split(" ")
  val n = readInt
  val dice = Dice(faces)

  dice.rotateAll()
  (0 until n).foreach { s =>
    val l =  readLine.split(" ")
    println(dice.getAll.find(t => t(0) == l(0) && t(1) == l(1)).get(2))
  }
}

Measured memory_bytes: 43996
import itertools

N = int(input())
words_count = {
  'M': 0,
  'A': 0,
  'R': 0,
  'C': 0,
  'H': 0
}
  
for _ in range(N):
  name = input()
  if name[0] in words_count.keys():
    words_count[name[0]] += 1

ans = 0
patterns = itertools.combinations(words_count.keys(), 3)
for a, b, c in patterns:
  ans += words_count[a] * words_count[b] * words_count[c]

print(ans)

Measured memory_bytes: 3064
import java.util.*;

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 = A + B;
		if (C >= 24) C -= 24;
		System.out.printf("%d", C);
	}
}


Measured memory_bytes: 23636
#include <iostream>
using namespace std;
int main(void){
    int p,q,r;
    cin >> p >> q >> r;
    int ac,ab,bc;
    ac = p + q;
    ab = q + r;
    bc = r + p;
    if(ac<=ab && ac<=bc){
        cout << ac << endl;
    }else if(ab<=bc && ab<=ac){
        cout << ab << endl;
    }else{
        cout << bc << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
int main()
{
    int n;
    cin>>n;
    int i,j,k,x,y;
    vector<pair<int,int>> vp;
    
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        vp.pb({x,y});
    }
    sort(vp.begin(),vp.end());//Sorting is most necessary here!!!
    map<pair<int,int>,int> mp;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            mp[{vp[j].fi-vp[i].fi, vp[j].se-vp[i].se}]++;
        }
    }
    
    int mx=0;
    for(auto m :mp)
    {
        if(m.se>mx) mx=m.se;

    }
    cout<<n-mx;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
using namespace std;
typedef string::const_iterator State;
class ParseError {};

int term(State &begin);
int expression(State &begin);
int factor(State &begin);
int number(State &begin);
void consume(State &begin, char expected);

int expression(State &begin){
    int ret = term(begin);
    for(;;){
        if(*begin == '+'){
            begin++;
            ret += term(begin);
        }else if(*begin == '-'){
            begin++;
            ret -= term(begin);
        }else{
            break;
        }
    }
    return ret;
}

int term(State &begin){
    int ret = factor(begin);
    for(;;){
        if(*begin == '*'){
            begin++;
            ret *= factor(begin);
        }else if(*begin == '/'){
            begin++;
            ret /= factor(begin);
        }else{
            break;
        }
    }
    return ret;
}

int factor(State &begin){
    if(*begin == '('){
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;
    }else{
        return number(begin);
    }
}

int number(State &begin){
    int ret = 0;
    while(isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

// begin???expected?????????????????????begin?????????????????????
void consume(State &begin, char expected) {
    if (*begin == expected) {
        begin++;
    } else {
        cerr << "Expected '" << expected << "' but got '" << *begin << "'"
            << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        throw ParseError();
    }
}

int main(){
    int N;
    cin >> N;
    cin.ignore();
    for(int i = 0; i < N; i++){
        string s;
        getline(cin, s);
        State begin = s.begin();
        int ans = expression(begin);
        cout << ans <<endl;
    }
}

Measured memory_bytes: 3072
n, m = map(int, input().split())
X = [[0, 0] for _ in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    X[i][0], X[i][1] = a, b

X.sort(key= lambda x:x[1])
#print(X)

t = -1
ans = 0
for i in range(m):
    a, b = X[i]
    if a >= t:
        ans += 1
        t = b
    else:
        continue
print(ans)

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

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

Measured memory_bytes: 256
#include <stdio.h>

//????????????????????????????????????????????????????????????????????????????????????????????§??????
//x1,y1 : Queen1 position
//x2,y2 : Queen2 position
int Check( int x1 , int y1 , int x2 , int y2 )
{
	//X??§?¨????Y??§?¨???????????????¨????????????
	if( x1 == x2 || y1 == y2 )
	{
		return 1;
	}

	//??????????????????????????°????????????
	//X??§?¨???¨Y??§?¨???????????????¶????????????????????¨????????????????????????
	int sub_x = ( x1 < x2 ) ? ( x2 - x1 ) : ( x1 - x2 );
	int sub_y = ( y1 < y2 ) ? ( y2 - y1 ) : ( y1 - y2 );

	return sub_x == sub_y;
}

//x,y?????°????????????????????????????????¨????????¢????????????????????¨??????????????????????????§????????????
int Validate( int x , int y , int* pos )
{
	for( int i = 0 ; i < 8 ; i++ )
	{
		//??????????????????????????????????????§?????§???????????????
		if( 0 <= pos[ i ] )
		{
			if( Check( x , y , pos[ i ] , i ) )
			{
				//????????????
				return 0;
			}
		}
	}
	//??????????????????
	return 1;
}

//????????????
void Print( const int* pos )
{
	for( int y = 0 ; y < 8 ; y++ )
	{
		for( int x = 0 ; x < 8 ; x++ )
		{
			if( pos[ y ] == x )
			{
				printf( "Q" );
			}
			else
			{
				printf( "." );
			}
		}
		printf( "\n" );
	}
}

//???????????????????????????????????¢???
int Search( int index , int* pos )
{
	//?????????????????????????????????????????´????????????????????????????????????
	if( index == 8 )
	{
		Print( pos );
		return 1;
	}

	if( 0 <= pos[ index ] )
	{
		//?????§?????????????????????????????????????????\?????¨??????????????????????????´??????????????????
		return Search( index + 1 , pos );
	}
	else
	{
		//????????§????????´????????????????????´????????¢???
		for( int i = 0 ; i < 8 ; i++ )
		{
			if( Validate( i , index , pos ) )
			{
				//????????´????????????????????????????????§?????????????±?????????§??????
				pos[ index ] = i;
				if( Search( index + 1 , pos ) )
				{
					return 1;
				}
				//??????????±???§???????????£????????§????????????
				pos[ index ] = -1;
			}
		}
	}
	return 0;
}

int main( int argc , char** argv )
{

	//initialize
	//???????????????????????????Y??§?¨??????\??£???????????????X??§?¨????
	int queen_pos[ 8 ];
	for( int i = 0 ; i < 8 ; i++ )
	{
		queen_pos[ i ] = -1;
	}

	//input
	int input_count;
	scanf( "%d" , &input_count );

	for( int i = 0 ; i < input_count ; i++ )
	{
		int pos_x;
		int pos_y;
		scanf( "%d %d" , &pos_y , &pos_x );
		queen_pos[ pos_y ] = pos_x;
	}

	//search
	Search( 0 , queen_pos );

	return 0;
}

Measured memory_bytes: 1004