akhauriyash/Code-Regression huggingface dataset:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {
    private static void solve() {
        final Scanner scanner = new Scanner(System.in);
        final Map<String, Integer> counts = new HashMap<String, Integer>();
        final String[] words = scanner.nextLine().split(" ");
        int maximumLength = 0;
        String maximumLengthWord = null;
        int maximumCount = 1;
        String maximumCountWord = null;
        for (String word: words) {
            if (word.length() > maximumLength) {
                maximumLength = word.length();
                maximumLengthWord = word;
            }
            int count;
            if (counts.containsKey(word)) {
                count = counts.get(word) + 1;
            } else {
                count = 1;
            }
            counts.put(word, count);
            if (count > maximumCount) {
                maximumCount = count;
                maximumCountWord = word;
            }
        }
        System.out.print(maximumCountWord);
        System.out.print(" ");
        System.out.print(maximumLengthWord);
        System.out.println();
    }

    public static void main(String... args) {
        solve();
    }
}

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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

int main()
{
	_upgrade
	int m; cin >> m;
	cout << (24 - m) + 24 << "\n";
	return 0;
}


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

# 最大値を取るf(x)のxを求める
# digitsは下位桁 < 上位桁で1になっているbitをカウントする
digits = [0] * 40
for i in range(40):
    for a in A:
        if (a >> i) & 1:
            digits[i] += 1

# Kを考慮してmax_xを求める方法がわからない
# 桁ごとに最適なbitはすでにわかっていて、他の桁のbitに影響を受けることはないので、
# 上位桁から見ていって、Kが1になっている部分ならフラグを立てる
# 上位桁から見てKが1のbitが出てから、K:1,max_x:0のフラグを立てたら、その桁より下位桁のbitはなんでもよくなる
check_K = True
max_x = 0
for i, d in enumerate(reversed(digits)):
    i = 40 - i - 1
    if check_K and K < pow(2, i):
        continue
    if d <= (N-d) and ((K >> i) & 1 == 1 or not check_K):
        max_x += 2 ** i
    elif (K >> i) & 1 == 1:
        check_K = False
    
#print(max_x)
ans = 0
for a in A:
    ans += a ^ max_x

print(ans)



Measured memory_bytes: 69644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>

int main() {

    int N;
    std::cin >> N;

    double m = (double) N / (double) 3;

    std::cout << std::fixed << std::setprecision(6) << m * m * m << "\n";

    return 0;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(all(d));
    ll res = 0;
    rep(i,d[n-1]+1){
        int j = lower_bound(all(d),i) - d.begin();
        if(j*2 == n) res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 640
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int l[] = new int[N];
		for(int i=0; i < l.length; i++){
			l[i] = sc.nextInt();
		}
		

		Arrays.sort(l);
		int ldo[] = new int[N];
		for(int i=0;i<l.length;i++){
			ldo[i] = l[l.length-1-i];
		}

		int ans = 0;
		for(int i=0;i<K;i++){
			ans += ldo[i];
		}

		System.out.println(ans);

	}
}




Measured memory_bytes: 22868
S = input()
Q = int(input())
flag = True  # 今の状態, 反転していない状態がTrue, 反転している状態がFalse
cnt = 0  # この値が最後に奇数であればもう一度反転する必要がある
before = []
after = []
for _ in range(Q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        # 反転するクエリ
        cnt += 1
        if flag:
            flag = False
        else:
            flag = True
    else:
        f, c = query[1], query[2]
        if f == "1":  # 先頭に追加する命令
            if flag:  # 反転していない状態であれば前に追加する
                before.append(c)
            else:  # 反転している状態であれば、後ろに追加する
                after.append(c)
        elif f == "2":  # 末尾に追加する命令
            if flag:  # 反転していない状態であれば末尾に追加する
                after.append(c)
            else:
                before.append(c)
before.reverse()
ans = "".join(before) + S + "".join(after)
if cnt % 2 == 1:
    ans = ans[::-1]
print(ans)


Measured memory_bytes: 5824
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 100000000
using namespace std;
int cnt = 0;
int divide(string num){
  int result = 0;
  for(int i=1; i<num.size(); i++){
    int left = atoi(num.substr(0,i).c_str());
    int right = atoi(num.substr(i,num.size()-i).c_str());
    //cout << left << " " << right << endl;
    result = max(result,left*right);
    //cout << result << endl;
  }
  cnt++;
  if(result>=10) return divide(to_string(result));
  else if(cnt==INF) return -1;
  else return 1;
}
int main(){
  int n;
  cin >> n;
  string num;
  rep(i,n){
    cin >> num;
    cnt = 0;
    if(atoi(num.c_str()) <= 9) cout << 0 << endl;
    else if(divide(num) == 1) cout << cnt << endl;
    else cout << -1 << endl;
  }
  return 0;
}



Measured memory_bytes: 3276
#include<stdio.h>

int main(void) {
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);

  for(int i = 1; i <= B; i++) {
    if((i*A) % B == C) {
      printf("YES\n");
      return 0;
    }
  }
  printf("NO\n");
  return 0;
}


Measured memory_bytes: 128
// AtCoder Beginner Contest 158 D.cpp

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

string sswap(string s) {
	int size = s.size();
	char c;
	for (int i = 0; i < size / 2; i++) {
		c = s[i];
		s[i] = s[size - 1 - i];
		s[size - 1 - i] = c;
	}
	return s;
}

int main()
{
	string s;
	int q;
	bool inv = false; //反転しているか
	cin >> s >> q;
	int t = 0, f = 0;
	s.reserve(q);
	char c = 0;
	for (int i = 0; i < q; i++) {
		cin >> t;
		if (t == 1) {
			inv = !inv;
			continue;
		}
		else {
			cin >> f >> c;

			if (f == 1) {
				if (!inv) {
					s.insert(0, 1, c);
				}
				else {
					s += c;
				}
			}
			else {
				if (!inv) {
					s += c;
				}
				else {
					s.insert(0, 1, c);
				}
			}
		}
	}
	if (inv) {
		s = sswap(s);
	}
	std::cout << s << endl;
}

Measured memory_bytes: 924
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=3e3+2;
int n,ans,mod,f[N],g[N][N],C[N][N];

inline int mul(int x,int y) {return 1ll*x*y%mod;}
int modpow(int x,int y,int p,int res=1) {
	for(;y;y>>=1,x=1ll*x*x%p) if(y&1) res=1ll*res*x%p;
	return res;
}
int main() {
    scanf("%d%d",&n,&mod);
    for(int i=0;i<=n;++i) {
        C[i][0]=g[i][0]=1;
        for(int j=1;j<=i;++j) 
            C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod,
            g[i][j]=(g[i-1][j-1]+mul(j+1,g[i-1][j]))%mod;
    }
    for(int i=0;i<=n;++i) {
        int tmp=modpow(2,modpow(2,n-i,mod-1),mod);
        int num=modpow(2,n-i,mod),qaq=1,res=0;
        for(int j=0;j<=i;++j) res=(res+mul(g[i][j],qaq))%mod,qaq=mul(qaq,num);
        ans=(ans+mul(mul((i&1)?mod-C[n][i]:C[n][i],tmp),res))%mod;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 69376
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int pop(void);
void push(int);

int main(){
  int x, y, top, n[101];
  char s[100];
  top = 0;

  while(scanf("%s", s) != EOF){
    if(s[0] == '+'){
      x = n[top-1];
      y = n[top];
      top--;
      n[top] = x+y;
    }
 else if(s[0] == '-'){
      x = n[top-1];
      y = n[top];
      top--;
      n[top] = x-y;
    }
 else if(s[0] == '*'){
      x = n[top-1];
      y = n[top];
      top--;
      n[top] = x*y;
    }
 else{
      top++;
      n[top] = atoi(s);
    }
  }
  printf("%d\n",n[top]);
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define ll long long
#define INF 100000000
#define clr(x) memset(x,0,sizeof(x))
using namespace std;

inline int read()
{
	register int ret=0,c=getchar();
	while(!isdigit(c))c=getchar();
	while(isdigit(c))ret=ret*10+c-'0',c=getchar();
	return ret;
}

ll n,a,b;

int main()
{
	n=read(),a=read(),b=read();
	printf("%lld\n",max(0LL,(n-2)*(b-a)+1));
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n+1];
    int b[n+1];
    memset(b, 0, sizeof(b));

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

    for (int i=n; i>=1; i--) {
        int num = 0;
        for (int x=2*i; x<=n; x+=i) {
            num += b[x];
        }
        if (num % 2 == a[i]) {
            b[i] = 0;
        } else {
            b[i] = 1;
        }
    }

    int sum = 0;
    for (int i=1; i<=n; i++)
        sum += b[i];

    //cout << "debug: ";
    //for (int i=1; i<=n; i++) {
    //    if (i != 1)
    //        cout << " ";
    //    cout << b[i];
    //}
    //cout << endl;

    if (a[1] == sum % 2) {
        cout << sum << endl;
        if (sum != 0) {
            bool first = true;
            for (int i=1; i<=n; i++) {
                if (b[i] == 1) {
                    if (!first) {
                        cout << " ";
                    } else {
                        first = false;
                    }
                    cout << i;
                }
            }
            if (!first) {
                cout << endl;
            }
        }
    } else {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
template<typename T = int, T mod = 1'000'000'007, typename U = long long>
struct umod{
    T val;
    umod(): val(0){}
    umod(U x){ x %= mod; if(x < 0) x += mod; val = x;}
    umod& operator += (umod oth){ val += oth.val; if(val >= mod) val -= mod; return *this; }
    umod& operator -= (umod oth){ val -= oth.val; if(val < 0) val += mod; return *this; }
    umod& operator *= (umod oth){ val = ((U)val) * oth.val % mod; return *this; }
    umod& operator /= (umod oth){ return *this *= oth.inverse(); }
    umod& operator ^= (U oth){ return *this = pwr(*this, oth); }
    umod operator + (umod oth) const { return umod(*this) += oth; }
    umod operator - (umod oth) const { return umod(*this) -= oth; }
    umod operator * (umod oth) const { return umod(*this) *= oth; }
    umod operator / (umod oth) const { return umod(*this) /= oth; }
    umod operator ^ (long long oth) const { return umod(*this) ^= oth; }
    bool operator < (umod oth) const { return val < oth.val; }
    bool operator > (umod oth) const { return val > oth.val; }
    bool operator <= (umod oth) const { return val <= oth.val; }
    bool operator >= (umod oth) const { return val >= oth.val; }
    bool operator == (umod oth) const { return val == oth.val; }
    bool operator != (umod oth) const { return val != oth.val; }
    umod pwr(umod a, U b) const { umod r = 1; for(; b; a *= a, b >>= 1) if(b&1) r *= a; return r; }
    umod inverse() const {
        U a = val, b = mod, u = 1, v = 0;
        while(b){
            U t = a/b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        if(u < 0)
            u += mod;
        return u;
    }
};
using U = umod<>;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	auto coef = [&](int n, int r){
		U ans = 1;
		for(int i = 0; i < r; i++){
			ans *= (n - i);
			ans /= i + 1;
		}
		return ans;
	};
	int n, a, b; cin >> n >> a >> b;
	U ans = U(2) ^ n;
	ans -= 1;
	ans -= coef(n, a);
	ans -= coef(n, b);
	cout << ans.val << '\n';
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

struct UFTree(T)
{
    struct Node
    {
        T parent;
        T rank = 1;
    }

    ///
    T min_size, max_size;

    ///
    this(T n)
    {
        nodes.length = n;
        sizes.length = n;
        foreach (i, ref node; nodes) {
            node = Node(i.to!T);
            sizes[i] = 1;
        }

        min_sizes.length = n + 1;
        min_sizes[1] = n;
        min_size = 1;
        max_size = 1;
    }

    ///
    bool unite(T a, T b)
    {
        a = root(a);
        b = root(b);

        if (a == b) return false;

        auto a_size = sizes[a];
        auto b_size = sizes[b];
        --min_sizes[a_size];
        --min_sizes[b_size];
        ++min_sizes[a_size + b_size];
        foreach (nxt_size; min(a_size, b_size)..min_sizes.length) if (min_sizes[nxt_size] != 0) {
            min_size = nxt_size.to!T;
            break;
        }
        max_size = max(max_size, a_size + b_size);

        if (nodes[a].rank < nodes[b].rank) {
            sizes[a] += sizes[b];
            nodes[b].parent = a;
        } else {
            sizes[b] += sizes[a];
            nodes[a].parent = b;
            if (nodes[a].rank == nodes[b].rank) ++nodes[b].rank;
        }

        return true;
    }

    ///
    bool is_same(T a, T b)
    {
        return root(a) == root(b);
    }

    ///
    T size(T i)
    {
        return sizes[root(i)];
    }

    T root(T i)
    {
        if (nodes[i].parent == i) return i;

        return nodes[i].parent = root(nodes[i].parent);
    }

private:
    Node[] nodes;
    T[] sizes;
    T[] min_sizes;
}

///
UFTree!T uftree(T)(T n)
{
    return UFTree!T(n);
}

alias P = Tuple!(int, "i", int, "x", int, "y");

void main()
{
    auto N = readln.chomp.to!int;
    P[] ps;
    foreach (i; 0..N) {
        auto xy = readln.split.to!(int[]);
        ps ~= P(i, xy[0], xy[1]);
    }
    auto uft = uftree(N);
    sort!"a.x < b.x"(ps);
    foreach (i; 1..N) if (ps[i-1].x == ps[i].x) uft.unite(ps[i-1].i, ps[i].i);
    sort!"a.y < b.y"(ps);
    foreach (i; 1..N) if (ps[i-1].y == ps[i].y) uft.unite(ps[i-1].i, ps[i].i);
    auto xs = new long[][N];
    auto ys = new long[][N];
    foreach (i; 0..N) {
        auto p = ps[i];
        auto r = uft.root(p.i);
        xs[r] ~= p.x;
        ys[r] ~= p.y;
    }

    long res;
    foreach (i; 0..N) if (!xs[i].empty) {
        sort(xs[i]);
        sort(ys[i]);
        res += xs[i].uniq.array.length * ys[i].uniq.array.length - uft.size(i);
    }
    writeln(res);
}

Measured memory_bytes: 14472
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
#define MAX_NUM 10000000
vector<int> p;
int flag[MAX_NUM/32+1];

//sieve eratosthenes
void setPrime(vector<int> &p){

    for(int i=1;2*i*(i+1)<(MAX_NUM>>1);++i){

        if(flag[i>>5] & (1<<(i%32)))continue;
        //(2*j+1) == (2*i+1)*(2*i+1)
        //(2*i+1)*(2*i+1) -> (2*i+1)*(2*(i+1)+1) -> ... set not prime
        for(int j=2*i*(i+1); j<(MAX_NUM>>1); j+=2*i+1)
            flag[j>>5] |= (1<<(j%32));

    }

    p.push_back(2);
    for(int i=1;2*i+1<=MAX_NUM;++i){
        for(;flag[i>>5] & (1<<i);++i);
        if(2*i+1>MAX_NUM)break;
        p.push_back(2*i+1);
    }

}

int ans[1000001];
int cnt = 0;

int main(){

    vector<int> primes;
    setPrime(primes);

    for(int i=0;i<=1000000;++i){

        if(primes[cnt]==i)++cnt;

        ans[i]=cnt;

    }

    int N;
    while(cin>>N){

        cout << ans[N] << endl;

    }

    return 0;
}

Measured memory_bytes: 9420
#include <stdio.h>

int main(void)
{
	int dp[4][64] = {0};
	int n;
	int i, j, k;

	for (i = 0; i < 10; i++) dp[0][i] = 1;
	for (i = 1; i < 4; i++){
		for (j = 0; j <= 36; j++){
			if (dp[i - 1][j]){
				for (k = 0; k <= 9; k++){
					dp[i][j + k] += dp[i - 1][j];
				}
			}
		}
	}

	while (~scanf("%d", &n)){
		printf("%d\n", dp[3][n]);
	}

	return (0);
}

Measured memory_bytes: 596
n = int(input())
 
 
x = [list(input().split(" ")) for i in range(n)]
 
for i in range(n):
    x[i][1] = int(x[i][1])
 
test2 = sorted(x, key = lambda k:(k[0],-k[1]))
 
for i in range(n):
    print(x.index(test2[i]) + 1)

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

int main(){
  unsigned long int N;
  cin>>N;
  string temp;
  char cc;
  unsigned long int m,a,r,c,h;
  m=a=r=c=h=0;
  for (unsigned long int i=0;i<N;i++) {
    cin>>temp;
    cc=temp[0];
    if (cc=='M') m++;
    else if (cc=='A') a++;
    else if (cc=='R') r++;
    else if (cc=='C') c++;
    else if (cc=='H') h++;
  }
  unsigned long long int count=0;
  count+=m*a*r;
  count+=m*a*c;
  count+=m*a*h;
  count+=m*r*c;
  count+=m*r*h;
  count+=m*c*h;
  count+=a*r*c;
  count+=a*r*h;
  count+=a*c*h;
  count+=r*c*h;

  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    N = int(input())
    K = int(input())
    x = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        if abs(x[i]) <= abs(K-x[i]):
            ans += 2*abs(x[i])
        elif abs(x[i]) >= abs(K-x[i]):
            ans += 2*abs(K-x[i])
    print(ans)
resolve()

Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let num: i32 = read();
    let mut vec: Vec<(i32, i32, i32)> = Vec::new();

    for i in 0..num {
        let each_vec: (i32,i32,i32) = (read(),read(),read());
        vec.push(each_vec);
    }

    let mut t = 0;
    let mut x = 0;
    let mut y = 0;

    let mut ans = "Yes";

    for &i in vec.iter() {
        let target_t = i.0;
        let target_x = i.1;
        let target_y = i.2;

        let diff = calc_distance(x,y,target_x,target_y);
        let time_diff = (target_t - t).abs();

        if diff > time_diff {
            ans = "No";
            break;
        }

        if (time_diff - diff) % 2 != 0 {
            ans = "No";
            break;
        }

        t = target_t;
        x = target_x;
        y = target_y;
    }

    println!("{}", ans);
}

fn calc_distance(x: i32, y: i32, target_x: i32, target_y: i32) -> i32 {
    let diff_x = (target_x - x).abs();
    let diff_y = (target_y - y).abs();

    return diff_x + diff_y;
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    double START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    // 選んだペアから得られる幸福度の下限を二分探索
    // 1. 幸福度の下限を決め打ち
    // 2. そこから左手の人を決めた時に右手に配置できる人を二分探索で求める
    // 3. Mペアを越えてしまったら下限をあげる。超えなかったら下限を下げる
    // -> 4. Mペアを下回らないぎりぎりになる幸福度の下限を見つけられる
    // 5. Mペアちょうどにならない場合、余分に含まれているのはlbちょうどのものであるためそれらを引く
    //    -> これは自分の場合あんまり自明に思えなかったんですけど、二分探索で下限を1区切りで特定したので
    //       確かにズレはたかだかそれくらいにしかならなさそう
    // 行くぞ

    i64 n,m; cin >> n >> m;
    vl a(n); rep(i,n) cin >> a[i];
    sort(all(a));

    vl csum(n+1); rep(i,n) csum[i+1] += csum[i] + a[i];

    i64 happy_cnt, pair_cnt;
    i64 l = -1, lb, u = infll;
    while(u-l > 1) {
        lb = (u+l)/2;
        happy_cnt = 0, pair_cnt = 0;
        for(auto aa : a) {
            i64 idx = lower_bound(all(a), lb - aa) - a.begin();
            happy_cnt += csum[n] - csum[idx] + aa*(n-idx);
            pair_cnt += n - idx;
        }
        if(pair_cnt > m) l = lb;
        else u = lb;
    }

    happy_cnt = 0, pair_cnt = 0;
    for(auto aa : a) {
        i64 idx = lower_bound(all(a), l - aa) - a.begin();
        happy_cnt += csum[n] - csum[idx] + aa*(n-idx);
        pair_cnt += n - idx;
    }
    happy_cnt -= l * (pair_cnt - m);

    cout << happy_cnt << '\n';

//     printf("ElapsedTime: %5.3f ms\n",1000*((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 4828
#include <bits/stdc++.h>
#include <unordered_map> 
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI1 3.14159265358979311599796346854418516159057617187500

typedef long long int ll;  
ll MOD = 1e9 + 7;


int main() 
{ 
    FIO
    int t;
    t = 1;
    while(t--)
    {
        int k;
        cin >> k;
        string s;
        cin >> s;

        if((int)s.length()<=k)
        {
            cout << s << endl;
            continue;
        }
        for(int i=0;i<k;i++)
            cout << s[i];
        cout << "...";
    }
    return 0; 
}

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

using namespace std;

typedef long long LL;

const int nmax = 100005;

char s[nmax];
int N,a[nmax];
bool ok;

int main()
{
    int i,j,q,x;
//    #ifndef ONLINE_JUDGE
//        freopen ("txt.in","r",stdin);
//        freopen ("txt.out","w",stdout);
//    #endif
   ios::sync_with_stdio(false);

    cin>>N >>(s+1);

   for(i = 0; i < 2; ++i)
      for(j = 0; j < 2; ++j){
         a[1] = i;
         a[2] = j;
         ok = true;

         for(q = 1; q <= N; ++q){
               char ch = s[q];
               if(a[q] && ch == 'o')ch = 'x';
               else if(a[q] && ch == 'x')ch = 'o';

            if(ch == 'o'){

               if(q == 1)
                 a[N] = a[2];
               else{
                  if(q == N-1 && a[q-1] != a[N])
                     ok = false;
                  if(q == N && a[q-1] != a[1])
                     ok = false;
                  a[q+1] = a[q-1];
               }
            }
            else{
               if(q == N-1 && (a[q-1]^1) != a[N])
                     ok = false;
                if(q == N && (a[q-1]^1) != a[1])
                     ok = false;
               if(q == 1)
                 a[N] = (a[2]^1);
               else
                  a[q+1] = (a[q-1]^1);
            }

         }

      if(ok){
         for(i = 1; i <= N; ++i)
            if(a[i])cout << 'W';
            else cout << 'S';
         cout << '\n';
         return 0;
      }
   }
   cout << "-1\n";
    return 0;
}


Measured memory_bytes: 896
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	i, err := strconv.Atoi(readString())
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func vi(n int, args ...int) []int {
	res := make([]int, n)
	if len(args) == 0 {
		return res
	}
	v := args[0]
	if v == 0 {
		return res
	}
	for i := 0; i < n; i++ {
		res[i] = v
	}
	return res
}

func vvi(n int, args ...int) [][]int {
	res := make([][]int, n)
	m := n
	if len(args) > 0 {
		m = args[0]
	}
	v := 0
	if len(args) > 1 {
		v = args[1]
	}
	for i := 0; i < n; i++ {
		res[i] = vi(m, v)
	}
	return res
}

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func main() {
	defer stdout.Flush()

	// readString() string
	// readInt() int
	// readIntSlice(n int) []int
	// readLengthAndSlice() []int

	n := readInt()
	total := 0

	a := make([]int, n+2)
	for i := 1; i <= n; i++ {
		a[i] = readInt()
		total += abs(a[i] - a[i-1])
	}
	total += abs(a[n])

	for i := 1; i <= n; i++ {
		if a[i-1] <= a[i] && a[i] <= a[i+1] || a[i-1] >= a[i] && a[i] >= a[i+1] {
			println(total)
		} else {
			println(total - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1]))
		}
	}
}


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

using namespace std;

const int N = 100010;
const int md = 1e9 + 7;

int n;
char s[N];
int freq[26];

int main() {
  scanf("%d", &n);
  scanf("%s", s);
  fill_n(freq, 26, 1);
  for (int i = 0; i < n; i++) {
    freq[s[i] - 'a']++;
  }
  int ans = 1;
  for (int i = 0; i < 26; i++) {
    ans = (long long)ans * freq[i] % md;
  }
  ans--;
  if (ans < 0) {
    ans += md;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

int main() {
	char S[100001];
	int N, ans;
	scanf("%s",S);
	ans = 0;
	N = strlen(S);
	for (int i = 0; i < N-1; i++) {
		if (S[i] != S[i + 1]) {
			ans++;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    private static Scanner sc;

    public static void main(final String[] args) {
        sc = new Scanner(System.in);
        int a = sc.nextInt(),b = sc.nextInt();
        if(a*4 >= b && a*2 <= b && b%2 == 0)System.out.println("Yes");
        else System.out.println("No");
    }
}








Measured memory_bytes: 35600
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  int n,k;
  cin >> n >> S >> k;
  char x = S[k-1];
  for(int i = 0;i < n;i++){
    if(S[i] == x)cout << x;
    else cout << "*";
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long k=sc.nextLong(),a=sc.nextLong(),b=sc.nextLong();
		sc.close();
		if(a+1<b) {
			if(k<=a-1) System.out.println(k+1);
			else {
				if((k-a+1)%2==0) System.out.println(b*(k-a+1)/2-a*((k-a+1)/2-1));
				else{
					if((k-a+1)/2==0) System.out.println(a+1);
					else System.out.println(b*((k-a+1)/2)-a*((k-a+1)/2-1)+1);
				}
			}
		}else System.out.println(k+1);
	}
}

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

int main() {
    string s;
    cin >> s;
    int counter = 0;
    if (s[0] == '1') counter++;
    if (s[1] == '1') counter++;
    if (s[2] == '1') counter++;
    cout << counter << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long

int main() {
    int n;
    int h[100000];
    int c[100000];

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

    c[0] = 0;
    c[1] = abs(h[1] - h[0]);

    for(int i=2; i < n; i++){
        int c1 = c[i - 1] + abs(h[i - 1] - h[i]);
        int c2 = c[i - 2] + abs(h[i - 2] - h[i]);
        int cost = min(c1, c2);
        c[i] = cost;
    }
    

    std::cout << c[n - 1] << endl;


    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize ("O3,unroll-loops")
#define f first
#define s second
#define ri register int
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
#define MAXN 100000
#define INF 100000000000000LL
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, w, items[MAXN][3];
	ll dp[MAXN + 1];
	cin >> n >> w;
	for(int k = 0; k < n; ++k)
		cin >> items[k][0] >> items[k][1];
	for(int k = 0; k <= w; ++k) dp[k] = -INF;
	dp[0] = 0;
	for(int k = 0; k < n; ++k)
		for(int i = w - items[k][0]; i >= 0; --i)
			dp[i + items[k][0]] = max(dp[i + items[k][0]], dp[i] + items[k][1]);
	cout << *max_element(dp, dp + w + 1) << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main(){
    vector<ll> conv(100001, 1);
    conv[2]++;

    for (int i = 3; i < 100001;i++)
        conv[i] = (conv[i - 1] + conv[i - 2]) %mod;

    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for (int i = 0; i < M;i++)
        cin >> A[i];

    ll ans = 1;
    ll t = 0;
    for (int i = 0; i < M;i++){
        if(t != 1 && A[i] == t)
        {
            cout << 0 << endl;
            return 0;
        }else{
            if(A[i] - t - 1 >= 0)
                ans = (ans * conv[(A[i] - t - 1)]) % mod;
            t = A[i] + 1;
        }
    }
    ans = (ans * conv[N - t]) % mod;
    cout << ans  << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
const int dx4[4] = {1,0,-1,0};
const int dy4[4] = {0,1,0,-1};
const int dx8[8] = {-1,0,1,1,1,0,-1,-1};
const int dy8[8] = {1,1,1,0,-1,-1,-1,0};
typedef long long ll;
const int mod = 1e9+7;

int main(){
  int n[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << n[k-1] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    long long int a,b,c,g=0;
    scanf("%ld%ld",&a,&b);
    c=a-b;
    if(a>b) {
        printf("%ld", c);
    }
    else if(a<b){
        printf("%ld\n",g);
    }
    else
    {
        printf("%ld\n",g);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
    int N,M; cin >> N >> M;
    vector<int> h(N+1,0);
    vector<int> G[N+1];
    for(int i=0; i<M; i++){
        int x,y;cin >> x >> y;
        G[x].push_back(y);
        h[y]++;
    }
    vector<int> dp(N+1,0);
    queue<int> q;
    for(int i=1; i<=N; i++){
        if(h[i]==0) q.push(i);
    }
    while(!q.empty()){
        int now=q.front();q.pop();
        for(auto Next: G[now]){
            h[Next]--;
            if(h[Next]==0){
                q.push(Next);
                dp[Next]=max(dp[Next],dp[now]+1);
            }
        }
    }
    int ans=0;
    for(int i=1; i<=N; i++) ans=max(ans,dp[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <iostream>

using namespace std;

int main(){
    int N, K;
    int h[100000];

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

    int dp[100000];
    dp[0] = 0;
    for(int i = 1; i < N; i++){
        int temp = 2000000000;
        for(int j = 1; j <= K; j++){
            int before = i - j;
            if(before < 0){
                break;
            }

            int temp2 = dp[before] + abs(h[i] - h[before]);
            if(temp2 < temp){
                temp = temp2;
            }
        }
        dp[i] = temp;
    }

    printf("%d\n", dp[N - 1]);
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void B_task();

int main()
{
	B_task();

	fflush(stdout);
	return 0;
}

static void B_task()
{
	int N, L;
	get2int(N, L);

	int taste[201] = { 0 };
	int tSum = 0;
	int minIdx, minTaste = 10000;
	for (int i = 0; i < N; i++) {
		taste[i] = L + i;
		tSum += taste[i];
		if (minTaste > tp_abs(taste[i])) {
			minIdx = i;
			minTaste = tp_abs(taste[i]);
		}
	}

	printf("%d\n", tSum - taste[minIdx]);
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<long long, long long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

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

vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

void dfs(int from) {
	int c = 1;
	for (auto t : tree[from]) {
		c = c != color[from] ? c : c + 1;
		color[t] = c;
		colorMap[make_pair(from, t)] = c;
		m = max(c, m);
		dfs(t);
		c++;
	}
}

int main() {
	ll A, B;
	cin >> A >> B;

	ll x = A * B;

	if (A < B) {
		int tmp = A;
		A = B;
		B = tmp;
	}

	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}

	ll ans = x / B;
	cout << ans << endl;
}

Measured memory_bytes: 2560
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ITP1_11-B
 
Structure and Class - Dice II
Time Limit : 1 sec, Memory Limit : 65536 KB
???????????? II

Dice I ??¨????§????????????§?????\??????????????°????????????????????????????????????????????????

????????????????????? Dice I ???????????§?????¢????????????????????¢??¨?????¢?????°??????????????¨??????????????????????????§????????´?????¢?????°???????????????????????°????????????????????????????????????



Input

?????????????????¢?????°???????????????????????????????????????????????§?????????????????????
???????????????????????° q

????????????????????????

?¶???? q

???????????????????????????????????????????????§????????¢??¨?????¢?????°????????¨??????????????´??°????????????????????§??????????????????????????????
Output

??????????????¨??????????????????????????´?????¢?????°??????????????????????????????????????????
Constraints

    0???

??\?????????????????????????????¢?????°??? ???100
??\?????????????????????????????¢?????°?????????????????°??????
1???q???24

Sample Input

1 2 3 4 5 6
3
6 5
1 3
3 2

Sample Output

3
5
6

=end
class Dice
  def initialize(f)
    @face = Array.new(7,"")
    (0.upto(f.length-1)).each {|i| @face[i+1] = f[i]} 
  end

  def dump
    puts @face[1] + " " +  @face[2] + " " + @face[6] + " " +  @face[5] + " " + @face[4] + " " +  @face[3]
  end

  def e
    tmp = @face[1] 
    @face[1] = @face[4]
    @face[4] = @face[6]
    @face[6] = @face[3] 
    @face[3] = tmp
    @face[1]
  end

  def w
    tmp = @face[1] 
    @face[1] = @face[3]
    @face[3] = @face[6]
    @face[6] = @face[4]
    @face[4] = tmp
    @face[1]
  end

  def n
    tmp = @face[1] 
    @face[1] = @face[2]
    @face[2] = @face[6]
    @face[6] = @face[5]
    @face[5] = tmp
    @face[1]
  end

  def s
    tmp = @face[1] 
    @face[1] = @face[5]
    @face[5] = @face[6]
    @face[6] = @face[2]
    @face[2] = tmp
    @face[1]
  end

  def upface
    @face[1]
  end

  def frontface
    @face[2]
  end

  def rightface
    @face[3]
  end

  def srchRight(s,t)
    (1..4).each {|i|
      break if self.frontface() == t;
      self.s
    }
    if self.frontface() != t then
      self.e
      (1..4).each {|i|
        break if self.frontface() == t;
        self.s
      }
    end
    abort "strange #{t} not found" if self.frontface() != t;
    (1..4).each {|i|
      break if self.upface() == s;
      self.e
    }
    abort "strange #{s} not found" if self.upface() != s;

    self.rightface()
  end
end

class Main
  def initialize
    #fh = open("IPT1_11_B.txt")
    fh = STDIN
    fl = fh.gets.chomp.split
    abort "small face data" if fl.length != 6
    d = Dice.new(fl)
    n = fh.gets.chomp.to_i
    (1..n).each {|i|
      fl = fh.gets.chomp.split
      puts d.srchRight(fl[0],fl[1])
    }
  end
end

if $0==__FILE__ then
  Main.new()
end

Measured memory_bytes: 8728
//ICPC??????????¨???????????????§??¢???????????°????????§???

import java.util.Scanner;
import java.util.Arrays;

public class Main{
	public static void main(String[] args){
		int n,sum;
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		while(n!=0){
			sum = 0;
			
			//?????°???????´???????????????????????????£?¨???????????´?????´?
			int[] score = new int[n];
			for(int i=0; i<n; i++){
				score[i] = in.nextInt();
			}
			
			//??????????????????????????????????????????
			Arrays.sort(score);
			
			//????°??????¨?????§???????????????????¨????????¨????
			for(int i=1; i<n-1; i++){
				sum += score[i];
			}
			
			//??????????????????
			System.out.println(sum/(n-2));
			
			//n?????´??°
			n = in.nextInt();
		}
		
		in.close();
	}
}

Measured memory_bytes: 20936
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll N, dp[5001][5001] = {}, ans = 0;
string S;

int main() {
	cin >> N;
	cin >> S;
	for (int i = N - 1; i >= 0; i--) {
		for (int j = N - 1; j >= 0; j--) {
			if (S[i] == S[j])dp[i][j] = dp[i + 1][j + 1] + 1;
		}
	}
	rep(i, N) {
		for (int j = i + 1; j < N; j++) {
			ans = max(ans, min(dp[i][j], (ll)j - i));
		}
	}
	cout << ans << endl;
	return 0;
}

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

// セグメントツリー
template<class Monoid> struct SegTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int SIZE_R;
    vector<Monoid> dat;

    SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, UNITY);
    }

    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k)
            dat[k] = F(dat[k*2], dat[k*2+1]);
    }

    /* update a, a is 0-indexed */
    void update(int a, const Monoid &v) {
        int k = a + SIZE_R;
        dat[k] = v;
        while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
    }

    /* get [a, b), a and b are 0-indexed */
    Monoid get(int a, int b) {
        Monoid vleft = UNITY, vright = UNITY;
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = F(vleft, dat[left++]);
            if (right & 1) vright = F(dat[--right], vright);
        }
        return F(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }

    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            cout << (*this)[i];
            if (i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};

long long gcd(long long a, long long b){
    if(b==0) return a;
    return gcd(b,a%b);
}


int main(){

    int n;
    cin>>n;

    SegTree<int> seg(n,[](int a,int b){return gcd(a,b);},0);
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        seg.set(i,a[i]);
    }
    seg.build();

    int ans=seg.get(1,n);
    for(int i=0;i<n;i++){
        int k=gcd(seg.get(0,i),seg.get(i+1,n));
        ans=max(ans,k);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    a = root(a);
    return -Parent[a];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }
};

int main(){
  vl v(3); rep(i,3) cin >> v[i];

  sort(all(v));
  ll s = v[0]*v[1];
  cout << s*(v[2]%2LL) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,value,sum=0;
    while(scanf("%d",&n)==1)
    {
        value=n;
        while(n!=0)
        {
            sum=sum*10+(n%10);
            n=n/10;
        }
        if(sum==value)printf("Yes\n");
        else printf("No\n");
        sum=0;
    }
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  char str1[n];
  char str2[n];
  scanf("%s %s",str1,str2);
  for(int i=0;i<n;i++){
    printf("%c%c",str1[i],str2[i]);
  }
  return 0;
}

Measured memory_bytes: 128