akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int N;
   cin>>N;
   ll A,s=10000000000,b=-100;
   rep(i,N){
       cin>>A;
       s=min(s,A);
       b=max(b,A);
   }
    cout<<b-s<<endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
#include<numeric>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

Int fact[1100000];
Int revfact[1100000];
Int rev[1100000];

Int mod_pow(Int x, Int a, Int m){
    if(a == 0)return 1;
    Int res = mod_pow(x, a / 2, m);
    res = res * res % m;
    if(a % 2)res *= x;
    return res % m;
}

Int inv(Int x, Int m){
    return mod_pow(x, m-2, m);
}


void init(){
    Int m = MOD;
    fact[0] = 1;
    revfact[0] = 1;
    rev[0] = 0;
    rev[1] = 1;
    for(int i = 1;i < 1100000;i++){
        fact[i] = fact[i-1] * i % m;
        if(i>1)rev[i] = MOD / i * (MOD-rev[MOD % i]) % MOD;
        revfact[i] = revfact[i-1] * rev[i] % MOD;
    }
}

Int nCk(Int n, Int k){
    if(n < k)return 0;
    return fact[n] * revfact[n-k] % MOD * revfact[k] % MOD;
}



class UnionFind{
public:
    int n;
    vector<int> u;
    UnionFind(int _n = 0){
        n = _n;
        u = vector<int>(n, -1);
    }
    int r(int x){
        if(u[x] < 0)return x;
        return u[x] = r(u[x]);
    }
    void unite(int x, int y){
        x = r(x);
        y = r(y);
        if(x == y)return;
        if(-u[x] < -u[y])swap(x,y);
        u[x] += u[y];
        u[y] = x;
    }
    int size(int x){
        return -u[r(x)];
    }
};

Int pwn[5500];
int p[5500];
Int dp[5500];
vector<int> root;
int cnt;
Int ans;
int main(){
    init();
    int n;    
    cin >> n;
    UnionFind uf(n);
    for(int i = 0;i < n;i++){
        cin >> p[i];
        if(p[i] != -1){
            p[i]--;
            if(uf.r(i) != uf.r(p[i])){
                cnt++;
                uf.unite(i, p[i]);
            }
        }
        else{
            root.push_back(i);
        }
    }
    ans = (root.size() + cnt) *  mod_pow(n-1, root.size(), MOD) % MOD;
    dp[0] = 1;
    pwn[0] = 1;
    for(int i = 1;i < 5500;i++)pwn[i] = pwn[i-1] * (n-1) % MOD;
    for(auto x:root){
        for(int i = 0;i < root.size();i++){
            Int t = uf.size(x);
            if(i==0)t--;
            ans -= dp[i] * fact[i] %MOD * t % MOD * pwn[root.size()-i-1] % MOD;
            ans %= MOD;
        }
        for(int i = n; i> 0;i--){
            dp[i] += dp[i-1] * uf.size(x) %MOD;
            dp[i] %= MOD;
        }
    }
    if(ans < 0)ans += MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 29152
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
A = readInts()
B = readInts()
ans = 0
for i in range(n):
    v = B[i]
    # kill = A[i] + A[i+1]
    nya = min(v, A[i])
    A[i] -= nya
    v -= nya
    ans += nya
    nya = min(A[i+1], v)
    ans += nya
    A[i+1] -= nya
print(ans)


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

int main()
{
  int n, i, m=1000000000, s=0, sum = 0;
  int w[100];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> w[i];
    sum += w[i];
  }
  for (i = 0; i < n; i++) {
    s += w[i];
    m = min(m, abs(sum-2*s));
  }
  cout << m << endl;
}


Measured memory_bytes: 256
use strict;
use warnings;
use utf8;

my $line = <STDIN>;
my @md = split(/\s/, $line);
my $M = $md[0];
my $D = $md[1];

my $d10 = int($D/10);
my $d1  = $D - $d10*10;

my $c = 0;

for(my $i=1; $i <= $M; $i++){
    for(my $j=1; $j <= $D; $j++){
        $d10 = int($j/10);
        $d1  = $j - $d10*10;

        if($d10 >= 2 && $d1 >= 2){
            if($d10 * $d1 == $i){
                $c++;
            }
        }
     }
}

print($c);


Measured memory_bytes: 640
open System
let n = stdin.ReadLine() |> int
let cards = stdin.ReadLine().Split(' ') |> Array.map int |> Array.toList
let sortedCards = cards |> List.sortDescending

let helper a b =
    if a < b then (Some b, Some a) else (Some a, Some b)

let rec pop (pairs: (int option * int option) list) (reminder: int list) =
    match reminder with
    | [] -> pairs
    | [ a ] -> (Some a, None) :: pairs
    | a :: b :: rem -> pop ((helper a b) :: pairs) rem

let bind x =
    match x with
    | Some a -> a
    | None -> 0

pop [] sortedCards
|> List.map (fun x -> (x |> fst |> bind, x |> snd |> bind))
|> List.fold (fun x y -> (fst x + fst y, snd x + snd y)) (0,0)
|> fun x -> fst x - snd x
|> printfn "%d"

Measured memory_bytes: 15068
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
typedef long long ll;

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define MAX_INT 100000
#define MOD 1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)


vector<int> adj[1000002];
int vis[1000002],dep[1000002],siz[1000002];


void dfs(ll cur,ll par)
{
    vis[cur]=1;
    siz[cur]=1;
    for(auto x:adj[cur])
    {
        if(vis[x]!=1)
        {
            dep[x]=dep[cur]+1;
            dfs(x,cur);
            siz[cur]+=siz[x];
        }    
    }
}


void solve()
{
    ll n;cin>>n;
    // ll m;cin>>m;
    // ll k;cin>>k;
    // string s="",s1="",s2="";
    // ll tmp=0,cnt=0,ans=0,tmp1=0,fg=0,fg1=0;
    // ll a[n];
    cout<<setprecision(12)<<float(n)*2*3.1415926535897932384626;
    
    
    
}
    
int main()
{
    IOS;
    
    // ll t;cin>>t;while(t--)
        solve();
 
    return 0;
}

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

using namespace std;

int main()
{
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	int sum = 0;

	if(A >= K) {
		sum = K;
		cout << sum << endl;
		return 0;
	} else {
		sum = A;
		K -= A;
		// cout << "K is " << K << "\n";
	}

	if(B >= K) {
		cout << sum << endl;
		return 0;
	} else {
		K -= B;
		// cout << "K is " << K << "\n";
	}

	sum = sum + (-1 * K);
	// cout << "K is " << K << "\n";
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

LL x[100009];

int main(){
	DRII(n,m);
	LL xv=0,yv=0;
	REP(i,n){
		scanf("%lld",&x[i]);
		xv=(xv+x[i]*(2*i-(n-1)))%MOD;
	}
	REP(i,m){
		scanf("%lld",&x[i]);
		yv=(yv+x[i]*(2*i-(m-1)))%MOD;
	}
	printf("%lld",(xv*yv)%MOD);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL N, K;
  cin >> N >> K;
  VEC<int> A(N);
  REP(i, 0, N) {
    cin >> A[i];
    A[i]--;
  }
  VEC<int> index(N, -1);
  index[0] = 0;
  int pos = 0;
  int loopst = -1;
  int loopsize = -1;
  REP(i, 1, N+1) {
    int next = A[pos];
    if (index[next] == -1) {
      pos = next;
      index[next] = i;
    } else {
      loopst = next;
      loopsize = i - index[next];
      break;
    }
  }
  // DUMP(index);
  // DUMP(loopst, loopsize);
  if (K <= index[loopst]) {
    REP(i, 0, N) {
      if (index[i] == K) {
        cout << i + 1 << endl;
        return 0;
      }
    }
  } else {
    K -= index[loopst];
    K %= loopsize;
    int pos = loopst;

    REP(i, 0, K) {
      int next = A[pos];
      pos = next;
    }
    cout << pos + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 4748
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static long mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			ulong[] vs = Console.ReadLine().Split().Select(ulong.Parse).ToArray();
			ulong a = Math.Max(vs[0] - 1, 0);
			ulong b = vs[1];
			ulong c = 0;
			ulong ans = 0;
			for (int i = 0; i < 64; i++) {
				c = Count1(b, i) - Count1(a, i);
				if (c % 2 == 1) {
					ans = ans + (1UL << i);
				}
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}

		static ulong Count1(ulong value, int pos)
		{
			ulong x = 1UL << pos;
			ulong y = 1UL << (pos + 1);
			ulong a = value / y * x;
			ulong z = (ulong)~(-1L << pos);
			ulong b = (value & x) == 0 ? 0 : (value & z) + 1;
			return a + b;
		}

	}
}


Measured memory_bytes: 13396
#include<stdio.h>

int main(void)
{
    int n,i,j;
    char s[51];

    scanf("%d%s",&n,s);
    j=0;
    for(i=0;i<n;i++)
        if((s[i]=='A')&&(s[i+1]=='B')&&(s[i+2]=='C')) j++;
    printf("%d\n",j);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <functional>

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

using namespace std;

int main() {
    int N, a[100];
    cin >> N;
    REP(i, N) cin >> a[i];

    sort(a, a + N, greater<int>());
    int A = 0, B = 0;
    for (int i = 0; i < N; i += 2)
        A += a[i];
    for (int i = 1; i < N; i += 2)
        B += a[i];
    cout << A - B << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;

	if (a % 3==0 || b % 3==0 || (a + b) % 3==0) {
		cout << "Possible";
	}
	else {
		cout << "Impossible";
	}
}

Measured memory_bytes: 256
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted([(a, i) for i, a in enumerate(A)], reverse=True)

    # dp[i][j] := i番目の幼児まで見て、左に詰める選択をj回行った場合のうれしさの最大値
    dp = [[0] * (N + 1) for _ in range(N + 1)]
    for i, (a, p) in enumerate(A):
        for j in range(i + 1):
            # 左に詰める場合
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + (p - j) * a)
            # 右に詰める場合
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + ((N - (i - j) - 1) - p) * a)

    print(max(dp[-1]))


if __name__ == "__main__":
    resolve()

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

	int t[n+3];
	t[0] = 0;
	t[1] = 0;
	rep(i, n) {
		cin >> t[i+2];
		t[i+2] += t[i+1];
	}
	t[n+2] = t[n+1];

	int mt = t[n+1];

	int v[n+2];
	v[0] = 0;
	rep(i, n) cin >> v[i+1];
	v[n+1] = 0;

	double mnv[2*mt+1];
	rep(i, 2*mt+1) mnv[i] = 1000.0;

	rep(i, n+2){
		int l = 2*t[i];
		int r = 2*t[i+1];
		
		rep(j, 2*mt+1){
			if(j < l) mnv[j] = min(mnv[j], 0.5 * (l - j)+ v[i]);
			else if(l <= j && j < r) mnv[j] = min(mnv[j], 1.0 * v[i]);
			else mnv[j] = min(mnv[j], 0.5 * (j - r)+ v[i]);
		}
	}

	double ans = 0.0;
	rep(i,2*mt){
		ans += 0.5 * (mnv[i] + mnv[i+1]) / 2;
	}

	cout << fixed << setprecision(5) << ans << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <functional>
#pragma warning(disable : 4996)

using namespace std;

void solve_case();

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

	solve_case();

	return 0;
}

void solve_case() {
	int n, min_val = 1234567890;
	vector<int> a, b;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
		min_val = min(tmp, min_val);
	}

	while (a.size() > 1) {
		for (int i = 0; i < a.size(); i++) {
			a[i] %= min_val;
			if (a[i] != 0)
				b.push_back(a[i]);
		}
		b.push_back(min_val);
		a.clear();
		min_val = 1234567890;
		for (int i = 0; i < b.size(); i++) {
			a.push_back(b[i]);
			min_val = min(min_val, b[i]);
		}
		b.clear();
	}

	cout << a[0] << "\n";
}

Measured memory_bytes: 1400
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 = sc.nextInt();
        int d = sc.nextInt();
        int sm=c,bg=d;
        if(a>c){
            sm=a;
        }
        if(b<d){
            bg=b;
        }
        if(bg>sm){
            System.out.println(bg-sm);

        }
        else{
            System.out.println(0);
        }
       
    }
}

Measured memory_bytes: 35720
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,t,m_v=10000000000,b_dis=0,ans=0;
  cin >> n >> t;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(m_v>a[i]){
      m_v = a[i];
    }
    b_dis = max(b_dis,a[i]-m_v);
  }
  m_v = 10000000000;
  for(int i=0;i<n;i++){
    if(m_v > a[i]){
      m_v = a[i];
    }
    if(b_dis == a[i]-m_v){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M; cin >> N >> M;
    vl x(M), y(M);
    REP(i, M){
        cin >> x[i] >> y[i]; x[i]--; y[i]--;
    }
    
    vb ex(N, false); ex[0] = true;
    vl cnt(N, 1);
    
    REP(i, M){
        ll xx = x[i], yy = y[i];
        cnt[xx]--; cnt[yy]++;
        if(ex[xx]){
            ex[yy] = true;
        }
        if(cnt[xx] == 0){
            ex[xx] = false;
        }
    }
    ll ans = 0;
    REP(i, N) if(ex[i]) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  ll K;
  string S;
  cin>>S>>K;
  for (int i(0);i<S.size();i++){
    if (S[i]=='1'&&i+1<K)continue;
    else if (S[i]=='1'&&K==i+1){
      cout << 1 <<endl;
      return 0;
    } else if (S[i]!='1'){
      cout << S[i]<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
N = int(input())
a =[int(_) for _ in input().split()]
ans = 10**15
cardsum = sum(a)
ruiseki = [0]

for i in range(N-1):
    ruiseki.append(ruiseki[i]+a[i])
    snuke = ruiseki[i+1]
    arai = cardsum - snuke
    diff = abs(snuke - arai)
    if diff < ans:
        ans = diff

print(ans)

Measured memory_bytes: 24828
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
const int MOD = 1e9+7;
const int INF = 1001001001;
const ll LINF = 1e18;
 
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; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

int dp[3005][3005];

signed main()
{
  string s,t; cin>>s>>t;
  reps(i,s.size()){
    reps(j,t.size()){
      if(t[j-1]==s[i-1]) dp[i][j]=dp[i-1][j-1]+1;
      else dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
    }
  }

  int len=dp[s.size()][t.size()];
  string ans="";
  int i=s.size()-1;
  int j=t.size()-1;
  while(len>0){
    if(s[i]==t[j]){
      ans.push_back(s[i]);
      len--;
      i--;
      j--;
    }else if(dp[i+1][j+1]==dp[i][j+1]){
      i--;
    }else{
      j--;
    }
  }
  reverse(ans.begin(), ans.end());
  cout<<ans<<endl;
}


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

int main() {
  int a, b, c;
  char s, t;
  cin >> a >> s >> b >> t >> c;
  
  if(b < 5)
    cout << "Heisei" << endl;
  else
    cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define all(a) a.begin(), a.end()
#define sz(a) a.size()
#define pb push_back
using namespace std;

const ll mod = 1e9+7;

ll n, d[10000001], ans=0;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("A.txt", "r", stdin);
    #endif
    cin >> n;
    d[1] = 1;
    for(int i=2; i<=n; i++){
        d[i]++;
        for(int j=i; j<=n; j+=i){
            d[j]++;
        }
    }
    for(int i=1; i<=n; i++){
        ans += i*d[i];
    }
    cout << ans;
}


Measured memory_bytes: 81704
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

struct UnionFind {
  int n,num;
  vector<int> r,p;
  UnionFind() {}
  UnionFind(int n):n(n),num(n),r(n,1),p(n,0){iota(p.begin(),p.end(),0);}
  int find(int x) {
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y) {
    return find(x)==find(y);
  }
  void unite(int x,int y) {
    x=find(x);y=find(y);
    if (x==y) return;
    if (r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
    num--;
  }
  int size(int x) {
    return r[find(x)];
  }
  int count() {
    return num;
  }
};

int N,W,H;
int x[40010],y[40010];
vector<int> vx[100010],vy[100010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> W >> H;
  int flag = 0;
  REP(i,N) {
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
    vx[x[i]].push_back(i);
    vy[y[i]].push_back(i);
    if (x[i] == 0 || x[i] == W-1 || y[i] == 0 || y[i] == H-1) flag = 1;
  }
  UnionFind uf(N);
  REP(i,100010) {
    for (int j = 0; j+1 < vx[i].size(); j++) {
      uf.unite(vx[i][j],vx[i][j+1]);
    }
    for (int j = 0; j+1 < vy[i].size(); j++) {
      uf.unite(vy[i][j],vy[i][j+1]);
    }
  }
  set<pii> st;
  REP(i,N) st.insert(pii(uf.find(i),uf.size(i)));
  int ans = 0;
  for (auto p : st) ans += p.second-1;
  if (uf.count() > 1) ans += 2*uf.count()-1-flag;
  cout << ans << endl;

  return 0;
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    int N, X;
    cin >> N >> X;
    int amari = X, res = N;
    vector<int> m(N);
    for (int i = 0; i < N; i++) {
        cin >> m.at(i);
        amari -= m.at(i);
    }
    //cout << amari << endl;
    sort(m.begin(), m.end());
    int c = m.at(0);
    int d = amari / c;
    cout << res + d << endl;
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a>=13) cout << b << endl;
    else if(6<=a&&a<=12) cout << b/2 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 256
#C
import math
X = int(input())


for j in range(10000):
    x = X+j
    xn = math.ceil(math.sqrt(x))
    flag = 0
    for i in range(xn-2):
        I = i+2
        if x%I == 0:
            flag = 1
            break
    if flag == 0:
        print(x)
        break
    



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

//素因数分解
map<ll, ll> prime_factor(ll n)
{
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++)
	{
		while (n % i == 0)
		{
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1)
		ret[n] = 1;
	return ret;
}

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	int ans = 0;
	rep(i, n)
	{
		cin >> v[i];
		rep(k,i){
			ans += v[i]*v[k];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<string> s(n);
            vector<int> A(n);
            REP(i, n) cin >> s[i];
            REP(i, n) A[i] = s[i].size();
            int ans;
            bool ok = false;
            REP(i, n + 1){
                int a = 0;
                bool tanka =  false;
                int now = 0; 
                FOR(j, i, A.size()){
                    a += A[j];
                    if(a > 7) break;
                    if((now == 0 or now == 2) and a == 5){
                        now++;
                        a = 0;
                    }
                    if((now == 1 or now == 3) and a == 7){
                        now++;
                        a = 0;
                    }
                    if(now == 4 and a == 7){
                        ok = true;
                        ans = i + 1;
                        break;
                    }
                }
                if(ok) break;
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 3160
n = int(raw_input())
ans_xy =[]
tmp = []
for i in range(1,int(n**0.5)+1):
  if n%i==0:
    ans_xy.append(i)
    ans_xy.append(n/i)
    tmp.append(ans_xy)
    ans_xy = []
ans=tmp[0][0]+tmp[0][1]-2
for i in range(1,len(tmp)):
  ans = min(ans,tmp[i][0]+tmp[i][1]-2)
print ans

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

int main()
{
    int n;
    int a[101];

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

    sort(a, a + n, greater<int>());
    int alice = 0;
    int bob = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }

    cout << alice - bob << endl;
}

Measured memory_bytes: 3192
def main():
    n = int(input())
    k = int(input())
    x = int(input())
    y = int(input())

    ans = 0
    for i in range(n):
        if i < k:
            ans += x
        else:
            ans += y
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import numpy as np

N = int(input())
A, a = [], []
A = list(map(int, input().split()))

for i in range(N+1):
  a.append([])

for i in range(N-1):
  a[A[i]].append(1)

for i in range(N):
  print(sum(a[i+1]))

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

int main(){

    int S,h,m,s;
    cin >>S;

    if (S>=3600) h = S/(60*60);
    else h=0;

    if (S>=60) m = S%(60*60)/(60);
    else m = 0;

    s = S%(60*60)%(60);


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




Measured memory_bytes: 3200
import sys
x = int(input())
import math

# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

# 関数の呼び出し
# print(callIsPrime(100000+4)[-1])

for i in callIsPrime(100000+4):
    if i>=x:
        print(i)
        sys.exit()

Measured memory_bytes: 9412
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it before "scanf" and other c input!

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    ll sum = 0;
    ll init = n + 1;
    ll init_plus = n - 2;
    const int mod = 1000000007;
    for (int i = 1;i <= n + 1;i ++) {
        if (i >= k) sum = (sum + init) % mod;
        init = init + init_plus;
        init_plus = init_plus - 2;
    }
    printf("%lld\n",sum);
    return 0;
}


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

void solve () {
    int n;
    cin >> n;
    unordered_map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        mp[x]++;
        if (mp[x] > 1) {
            cout << "NO";
            return;
        }
    }
    cout << "YES";
}

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


Measured memory_bytes: 11260
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 998244353;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

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

    vector<int> B(n-1);
    for(int i=0; i<n-1; i++)
        cin >> B[i];
    
    int sol=0;

    for(int i=0; i<n; i++){
        if(i==0)
            sol+=B[i];
        else if(i==n-1)
            sol+=B[i-1];
        else
            sol+=min(B[i], B[i-1]);
    }
    cout << sol;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long
#define ld double
#define ull unsigned long long
#define PI pair < int, int > 

const int N = 1e5 + 123;
const int M = 123;
const ld Pi = acos(-1);
const ll Inf = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int Sz = 501;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) {
  return 1ll * a * b % mod;
}
int sum(int a, int b) {
  add(a, b);
  return a;
}

int a[10];
ll ans;

void solve() { 
  for (int i = 0;i < 7;i++) cin >> a[i];
  ll now = a[1] * 2ll + (a[0] / 2) * 4ll + (a[3] / 2) * 4ll + (a[4] / 2) * 4ll; 
  ans = max(ans, now);
  if (a[0] > 0 && a[3] > 0 && a[4] > 0) {
    now = 6 + a[1] * 2ll + (a[0] - 1) / 2 * 4ll + (a[3] - 1) / 2 * 4ll + (a[4] - 1) / 2 * 4ll;
    ans = max(ans, now);
  }
  cout << ans / 2ll << endl;
}
  
int main() {
  #ifdef wws
   freopen("in", "r", stdin);
   // freopen("in", "w", stdout);
  #endif 
  ios_base::sync_with_stdio(0);
  int tt = 1; 
  while(tt--) solve();
  return 0;
}

Measured memory_bytes: 256
m = int(input())
cnt = 0
res = None
for _ in range(m):
    d,c = map(int,input().split())
    while c:
        if c%2:
            if res is None:
                res = d
            else:
                res += d
                cnt += 1
                if res > 9:
                    res = res//10 + res%10
                    cnt += 1 
        d *= 2
        c //= 2
        cnt += c
        if d > 9:
            d = d//10 + d%10
            cnt += c
print(cnt)

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

struct Node {
  Node *ch[2];
  Node() { ch[0] = ch[1] = NULL; }
};

void build(Node *node, const string &s, int &i) {
  if( s[i] == '(' ) {
    i++; // (
    node->ch[0] = new Node();
    build(node->ch[0], s, i);
    i++; // ,
    node->ch[1] = new Node();
    build(node->ch[1], s, i);
    i++; // )
  }
}

void print(Node* node) {
  if( node == NULL || (node->ch[0] == NULL && node->ch[1] == NULL) ) return;
  cout << "(";
  print(node->ch[0]);
  cout << ",";
  print(node->ch[1]);
  cout << ")";
}

void erase(Node *node) {
  for(int i = 0; i < 2; i++) if( node->ch[i] ) erase(node->ch[i]);
  delete node;
}

void Intersection(Node *res, Node *a, Node *b) {
  for(int i = 0; i < 2; i++)
    if( a && a->ch[i] && b && b->ch[i] ) {
      res->ch[i] = new Node();
      Intersection(res->ch[i], a->ch[i], b->ch[i]);
    }
}

void Union(Node *res, Node *a, Node *b) {
  for(int i = 0; i < 2; i++)
    if( (a && a->ch[i]) || (b && b->ch[i]) ) {
      res->ch[i] = new Node();
      Union(res->ch[i], ( a ? a->ch[i] : NULL ), (b ? b->ch[i] : NULL ));
    }
}


int main() {
  for(string cmd, A, B; cin >> cmd >> A >> B;) {
    Node *roota = new Node();
    Node *rootb = new Node();
    Node *rootc = new Node();

    int i = 0;
    build(roota, A, i);

    i = 0;
    build(rootb, B, i);

    if( cmd[0] == 'i' ) Intersection(rootc, roota, rootb);
    else Union(rootc, roota, rootb);

    print(rootc); cout << endl;

    erase(roota);
    erase(rootb);
    erase(rootc);
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,i;
	cin>>a>>b;
	for(c=1;c<=3;c++)
	{
		if((a*b*c)%2==1)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
    return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n-1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i ; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


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

    cout<<180*(N-2);
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val scanner = System.`in`.bufferedReader()
    val input = scanner.readLine().split(" ").map(Integer::parseInt)
    val apples = input[0]
    var pieces = input[1]
    pieces += apples * 3
    val pies = pieces / 2
    println(pies)
}

Measured memory_bytes: 35880
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

data Dice = Dice [Int] deriving Show

rollDice :: Char -> Dice -> Dice
rollDice 'N' (Dice [a,b,c,d,e,f]) = Dice [b,f,c,d,a,e]
rollDice 'E' (Dice [a,b,c,d,e,f]) = Dice [d,b,a,f,e,c]
rollDice 'S' d = foldr1 (.) (replicate 3 $ rollDice 'N') $ d
rollDice 'W' d = foldr1 (.) (replicate 3 $ rollDice 'E') $ d

topDice :: Dice -> Int
topDice (Dice (a:_)) = a

question :: Dice -> Int -> Int -> Int
question d x y = topDice . rollDice 'W' $ setFront
  where
    setTop = head . filter ((==x) . topDice) $ ([d] ++ [rollDice 'N' . rollDice 'N' $ d] ++ map (flip rollDice d) "NESW")
    setFront = head . filter ((==y) . topDice) $ iterate (rollDice 'E') $ rollDice 'N' setTop 

main = do
  as <- map read . words <$> getLine
  let dice = Dice as
  q <- readLn
  replicateM_ q $ do
    [t, f] <- map read . words <$> getLine
    print $ question dice t f
    

Measured memory_bytes: 4052
// AOJ 2008: Dragon Fantasy
// 2017.11.22 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <math.h>

#define R 100
typedef long long ll;
#define dist(x, y)	((ll)(hypot(x, y)))

int cx[22], cy[22], n, lim;
ll dd[22];
ll dc[22][22];

int rec(int i, int s, double d)
{
	int j, jj;

	if (s == lim) return 1;
	for (jj = 1, j = 0; j < n; j++, jj <<= 1) {
		if (s & jj) continue;
		if (dd[j] <= d + dc[i][j]) return 0;
	}
	for (jj = 1, j = 0; j < n; j++, jj <<= 1) {
		if (s & jj) continue;
		if (rec(j, s | jj, d + dc[i][j])) return 1;
	}
	return 0;
}

int main()
{
	int i, j, hx, hy, dx, dy, x, y;

	while (scanf("%d%d%d%d%d", &n, &hx, &hy, &dx, &dy) && n > 0) {
		hx *= R, hy *= R, dx *= R, dy *= R;
		n++; lim = (1<<n)-1;
		cx[0] = hx, cy[0] = hy;
		for (i = 1; i < n; i++) {
			scanf("%d%d", &x, &y), cx[i] = x*R, cy[i] = y*R;
		}
		for (i = 0; i < n; i++) {
			dd[i] = dist(cx[i]-dx, cy[i]-dy);
			for (j = i+1; j < n; j++) {
				dc[i][j] = dc[j][i] = dist(cx[i]-cx[j], cy[i]-cy[j]);
			}
		}
		puts(rec(0, 0, 0) ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 1692
import sys
input = sys.stdin.buffer.readline

def floyd_warshall(dist):                                               # 動的計画法。頂点 k まで経由することが可能な場合の最短距離という部分問題を考えて、k = 0 から漸化式的に計算する
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]                # dist は頂点 k までを経由した場合の最短距離。dist[i][k]は k を経由することは無いので、dist[i][k]は k ステップ目で更新されることはない。
                                                                        # よって、min の中身は全て k-1 ステップ目の情報で構成されており、漸化式となっている。
    return dist

##############################
V, E = map(int, input().split())                                        # V:頂点数　E:辺の数

INF = float("inf")

dist = [[INF] * V for _ in range(V)]                           # 辺が存在しない事をコスト無限大で表現
for _ in range(E):
    i,j,weight = map(int,input().split())
    # i -= 1                                                            # 番号のデクリメントが必要な場合、コメントアウトを消す
    # j -= 1
    dist[i][j] = weight
    # dist[j][i] = weight                                               # 無向グラフの場合はコメントアウトを消す
for i in range(V):
    dist[i][i] = 0                                                      # 自身のところに行くコストは０

d = floyd_warshall(dist)                                                # 各点間の距離が隣接行列の形で与えられる

nagativity = False                                                      # 負のサイクルかどうかを判定
for i in range(V):
    if d[i][i] < 0:
        nagativity = True
if nagativity:
    print('NEGATIVE CYCLE')
else:
    for a in d:
        print(*[x if x != INF else "INF" for x in a])              # inf をどのように記述するかを指定


Measured memory_bytes: 6272
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

int main() {
  int N; cin >> N;
  int res = 0;
  for(int i = 0; i < 4; i++){
    if(N % 10 == 2) res++;
    N /= 10;
  }
  cout << res << endl;
}



Measured memory_bytes: 256
#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昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#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>;  // 2次元配列
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(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    string t; cin >> t;
    i32 n = t.size();

    if(t[0] == '?') t[0] = 'D';

    rep(i,n-1) {
        if(t[i] == 'P' && t[i+1] == '?') {
            t[i+1] = 'D';
        }
    }

    rep(i,n-1) {
        if(t[i] == '?' && t[i+1] == '?') {
            t[i] = 'P', t[i+1] = 'D';
            i++;
        }
    }

    rep(i,n) {
        if(t[i] == '?') t[i] = 'D';
    }



    cout << t << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define MOD 1000000007

using namespace std;

char s[100007];
LLI dp[100007][17]={};

int main()
{
    int i,j,k;

    scanf("%s",s);
    int len=strlen(s);
    dp[0][0]=1;
    for(i=1;i<=len;i++)
    {
        if(s[i-1]=='?')
        {
            for(j=0;j<13;j++)
            {
                for(k=0;k<=9;k++)
                {
                    dp[i][(j*10+k)%13]+=dp[i-1][j];
                    dp[i][(j*10+k)%13]%=MOD;
                }
            }
        }
        else
        {
            for(j=0;j<13;j++)
            {
                dp[i][(j*10+(s[i-1]-'0'))%13]+=dp[i-1][j];
                dp[i][(j*10+(s[i-1]-'0'))%13]%=MOD;
            }
        }
    }
    printf("%lld\n",dp[len][5]);

    return 0;
}


Measured memory_bytes: 13568
n,m = map(int,input().split())
ali = [int(input()) for _ in range(m)]
dif = []
cap = 0
for num in ali:
  dif.append(num-cap)
  cap = num
dif.append(n-cap+1)
dif[0] += 1
ref = [0,0,1,1]
a,b = 1,1
for i in range(100000):
  a,b = b,a+b 
  ref.append(b)
ans = 1
for num in dif:
  ans *= (ref[num] % 1000000007)
print(ans % 1000000007)

Measured memory_bytes: 464816
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int a = in.nextInt();
		int b = in.nextInt();
		if (a < 10 && b < 10)
			System.out.println(a * b);
		else
			System.out.println(-1);
		in.close();
	}
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

const int MAXN = 3000;
const ll sentinel = 1e15;
ll dp[MAXN + 5][MAXN + 5][2]; // len, start, player

auto minn(auto& a, auto b){a = (a == sentinel) ? b : min(a, b);}
auto maxx(auto& a, auto b){a = (a == sentinel) ? b : max(a, b);}

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

  int n;
  cin >> n;
  vi a(n);
  trav(i, a) cin >> i;

  rep(len, 0, n + 1) rep(i, 0, n) rep(k, 0, 2)
    dp[len][i][k] = sentinel;
  rep(i, 0, n) rep(k, 0, 2)
    dp[0][i][k] = 0;
    
  rep(len, 1, n + 1) {
    rep(i, 0, n - len + 1) {
      int j = i + len - 1;
      maxx(dp[len][i][0], a[i] + dp[len - 1][i + 1][1]);
      maxx(dp[len][i][0], a[j] + dp[len - 1][i][1]);
      minn(dp[len][i][1], dp[len - 1][i + 1][0] - a[i]);
      minn(dp[len][i][1], dp[len - 1][i][0] - a[j]);
    }
  }  
  cout << dp[n][0][0] << '\n';
}


Measured memory_bytes: 141184