akhauriyash/Code-Regression huggingface dataset:
number_select = int(input())
A = list(map(str,input().split()))
B = list(map(str,input().split()))
A_total = 0
B_total = 0
listA = []
def pattern(a):
    b = 1
    for r in range(1,a+1):
        b = b * r
    return b
def list_A(a):
    for i in range(1,a+1):
        listA.append(str(i))
list_A(number_select)
for i in range(number_select-1):
    A_total += listA.index(A[i]) * pattern(number_select-i-1)
    listA.remove(A[i])
listA.clear()
list_A(number_select)
for r in range(number_select-1):
    B_total += listA.index(B[r]) * pattern(number_select-r-1)
    listA.remove(B[r])
print(abs(A_total-B_total))

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h> 
using namespace std;

typedef long long ll;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) 
#define rep(pp,nn) for (int ii = pp; ii < nn; ++ii)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

string int_to_string(int x) {
    stringstream ss;
	ss << x;
	string ni = ss.str();
	return ni;
}
int string_to_int(string x) {
	int n;
	stringstream s(x);
	s >> n;
	return n;
}

int64_t power_mod(ll a, ll b, ll mo) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	}
	return ans;
}
int64_t POW(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = ans * a;
		}
		a = a * a;
		b /= 2;
	}
	return ans;
}

vector<int64_t> INVERSE(int64_t nn, int64_t mo) {
	vector<int64_t> inv(nn + 1);
	vector<int64_t> mul(nn + 1);
	inv[0] = 1;
    inv[1] = 1;
	for (ll i = 2; i <= nn; ++i) {
		inv[i] = (mo - (mo / i) * inv[mo % i] % mo) % mo; 
	}
	mul[0] = 1;
	for (int i = 1; i <= nn; ++i) {
		mul[i] = (mul[i - 1] * inv[i]) % mo;
	}
	return mul;
}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main() {
	IOS;
	int n, x, y;
	cin >> n >> x >> y;
	x--, y--;
	vector<vector<int>> edge(n, vector<int> (n));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			edge[i][j] = abs(i - j);
		}
	} 
	edge[x][y] = min(edge[x][y],1);
	int a[2] = {x,y};
	for (int e = 0; e < 2; ++e) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				edge[i][j] = min(edge[i][j],edge[i][a[e]] + edge[a[e]][j]);
			}
		}
	}	
	map<int,int> m;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			m[edge[i][j]]++;
		}
	}
	for (int i = 1; i < n; ++i) {
		cout << m[i] << endl;
	}
}














Measured memory_bytes: 19396
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> x >> y;

	f = 0;
	rep(i, n+1){
		if(x <= fn(i) && fn(i) <= y) f += i;
	}

	cout << f << endl;

}

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

void selectionSort(int *, int);

int main(){
  int A[100];
  int i, N;

  scanf("%d",&N);
  if(N < 1 || 100 < N) exit(1);

  for(i=0; i<N; i++){
    scanf("%d",&A[i]);
    if(A[i] < 0 || 100 < A[i]) exit(2);
  }

  selectionSort(A, N);

  return 0;
}

void selectionSort(int *A, int N){
  int i, j, k, minj, tem, num=0;

  for(i=0; i<=N-1; i++){
    minj=i;
    for(j=i; j<=N-1; j++){
      if(A[j] < A[minj]) minj=j;
    }
    tem=A[i];
    A[i]=A[minj];
    A[minj]=tem;
    if(i != minj) num++;
  }

  for(k=0; k<N; k++){
    if(k) printf(" ");
    printf("%d", A[k]);
  }
  printf("\n%d\n", num);
}


  



Measured memory_bytes: 2144
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();

        string ans = "APPROVED";

        for (int i = 0; i < n; i++)
        {
            //偶数
            if (a[i] % 2 == 1)
            {
                continue;
            }

            //3で割り切れるもしくは5で割り切れる
            if (a[i] % 3 == 0 || a[i] % 5 == 0)
            {
                continue;
            }
            else
            {
                ans = "DENIED";
            }

        }
        Console.WriteLine(ans);

    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
//#define debug1 cout<<"?"<<endl;
//#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=1e2+9;
const double pi=acos(-1);
const int mod=998244353;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	ll n,a,b,i;
	scanf("%lld%lld%lld",&n,&a,&b);
	ll ans=a*(n/(a+b));
	ans+=min(a,n%(a+b));
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(void)
{
    char c, p = ' ';
    while ((c = (char)getc(stdin)) != '\n') {
        if (isupper(c) && p == ' ') {
            putchar(c);
        }
        p = c;
    }
    putchar(c);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>

using namespace std;

int ex[5];
void work () {
	int i , a , b;
	for ( i = 1 ; i <= 3 ; i++ ) {
		scanf ( "%d%d" , &a , &b );
		ex[a]++;
		ex[b]++;
	}
	sort ( ex + 1 , ex + 4 + 1 );
	if ( ex[1] == 1 && ex[2] == 1 && ex[3] == 2 && ex[4] == 2 ) printf ( "YES\n" );
	else printf ( "NO\n" );
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>

int main()
{
    char str1[12],str2[12],str3[12];
    int ln1,ln2;

    while(scanf("%s %s %s",str1,str2,str3)==3)
    {
        ln1=strlen(str1);
        ln2=strlen(str2);

        if(str1[ln1-1]==str2[0]  &&  str2[ln2-1]==str3[0])
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }

    return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int ma=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    ma=max(ma,a[i]);
  }
  int count=0;
  vector<int> c(ma+1,0);
  for(int i=0;i<n;i++){
    c[a[i]]++;
  }
  for(int i=ma/2+1;i<=ma;i++){
    if(c[i]<2){
      cout << "Impossible" << endl;
      return 0;
    }
  }
  for(int i=0;i<(ma+1)/2;i++){
    if(c[i]>0){
      cout << "Impossible" << endl;
      return 0;
    }
  }
  if(ma%2){
    if(c[ma/2+1]!=2){
      cout << "Impossible" << endl;
      return 0;
    }
  }else{
    if(c[ma/2]!=1){
      cout << "Impossible" << endl;
      return 0;
    }
  }
  cout << "Possible" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll a, b, c, k, ans, mn;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> k;
    mn = min(a, k);
    ans += mn;
    k -= mn;
    mn = min(b, k);
    k -= mn;
    mn = min(c, k);
    ans -= mn;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>

int main(){
  char S[200000];
  int N=0;
  long ans=0;
  
  while (scanf("%c",&S[N])!=EOF){N++;}
  N--;

  int L=0,R=N;
  while (1)
  {
    if (R>L)
    {
      while (S[L]!='B'&&L<N){L++;}
      while (S[R]!='W'&&R>0){R--;}
      if(R>L){
        ans += R-L;
        L++;
        R--;
      }
    }else{
      break;
    }
  }
  
  printf("%ld",ans);

  return 0;
}

Measured memory_bytes: 1840
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord

--import qualified Data.IntSet as S
import qualified Data.Sequence as S

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)

main :: IO ()
main = do
    n <- readLn :: IO Int
    (h:hs) <- r' :: IO [Int]
    putStrLn $ if solve h hs then "Yes" else "No"




solve :: Int -> [Int] -> Bool
solve curH []       =  True
solve curH (h:hs)
    | curH <= h-1   = solve (h-1) hs
    | curH == h     = solve h hs
    | curH >  h     = False




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

int main(){
	double r, S, L;
	cin >> r;
	S=r*r*3.14159265358979;
	L=2*r*3.14159265358979;
	printf("%0.6lf %0.6lf\n", S, L);
	return 0;
}

Measured memory_bytes: 3208
package main

import "fmt"

func trace(a []int) {
  for i, v := range a {
    if i == 0 {
      fmt.Printf("%d", v)
    } else {
      fmt.Printf(" %d", v)
    }
  }
  fmt.Println("")
}

func main() {
  var n int
  fmt.Scan(&n)
  a := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&a[i])
  }
  trace(a)
  for i := 1; i < n; i++ {
    v := a[i]
    j := i - 1
    for j >= 0 && a[j] > v {
      a[j+1] = a[j]
      j--
    }
    a[j+1] = v
    trace(a)
  }
}



Measured memory_bytes: 1176
import java.util.*;

class Main{
	public static void main(String args[]) throws Exception{
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int min_m = 1001;
		for(int i = 0; i < N; i++){
			int m = sc.nextInt();
			if(m < min_m) min_m = m;
			X -= m;
		}
		System.out.println(N + X / min_m);
	}
}

Measured memory_bytes: 23764
# coding=utf-8

class Node:
    def __init__(self, ID, left, right):
        ### information for output ###
        self.id = ID
        self.parent = -1 #??????
        self.sibling = -1 #??????
        self.degree = -1 #??????
        self.depth = 0 #??????
        self.height = 0 #??????
        self.type = None #??????

        ### other information ###
        self.left_child = left
        self.right_child = right

def calc_depth(i):
    global node_list

    if node_list[i].depth != 0:
        return node_list[i].depth

    depth = 0
    if node_list[i].parent != -1:
        depth = calc_depth(node_list[i].parent) + 1

    node_list[i].depth = depth
    return depth


def calc_height(i):
    global node_list

    if node_list[i].height != 0:
        return node_list[i].height

    h1 = h2 = 0
    if node_list[i].right_child != -1:
        h1 = calc_height(node_list[i].right_child) + 1
    if node_list[i].left_child != -1:
        h2 = calc_height(node_list[i].left_child) + 1

    height = max(h1, h2)
    node_list[i].height = height
    return height

n = int(input())
data = [tuple(map(int, input().split())) for x in range(n)]
node_list = []

for data_row in data:
    ID, left, right = data_row
    node = Node(ID, left, right)
    node_list.append(node)

node_list.sort(key = lambda node: node.id)

for i, node in enumerate(node_list):
    left = node.left_child
    right = node.right_child
    degree = 0

    ### child information ###
    if left != -1:
        degree += 1
        node_list[left].parent = i
        node_list[left].sibling = right

    if right != -1:
        degree += 1
        node_list[right].parent = i
        node_list[right].sibling = left

    ### self information ###
    node.degree = degree

for i in range(n):
    calc_depth(i)
    calc_height(i)

    node = node_list[i]

    if node.depth == 0:
        node.type = 'root'
    elif node.height == 0:
        node.type = 'leaf'
    else:
        node.type = 'internal node'

    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(node.id, node.parent, node.sibling, node.degree, node.depth, node.height, node.type))

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef unsigned long long ull;
typedef long double ld; 
typedef tuple<int,int,int> State;

ll mod = 1e9 + 7;

#define citc(tc) int tc; cin>>tc; while(tc--){solve();}
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;

void solve()
{
	int A, B, M, ds, da, ff;
	cin>>A>>B>>M;
	cinal(a, A);
	cinal(b, B);
	vi x, y, c;
	rep(i, M)
	{
		cin>>ds>>da>>ff;
		x.pb(ds-1);
		y.pb(da-1);
		c.pb(ff);
	}	
	ll mi=5000006;
	rep(i, M)
	{
		mi = min(mi, a[x[i]]+b[y[i]]-c[i]);
	}
	sort(range(a));
	sort(range(b));
	mi = min(mi, a[0]+b[0]);
	cout<<mi<<endl;

}
int main()
{
	fastio();
	// citc(tc);
	solve();
}

Measured memory_bytes: 3308
#include<bits/stdc++.h>
#define d double
#define lli	long long int
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
#define rep(i,a,b)	for(i=a;i<b;i++)
using namespace std;
lli sod(lli n)
{
	lli ans=0;
	while(n)
	{
		ans+=(n%10);
		n/=10;
	}
	return ans;
}
int main()
{
	lli n,i;
	string s1,s2;
	cin >> n;
	cin >> s1 >> s2;
	for(i=0;i<n;i++)	cout << s1[i] << s2[i];
	cout << endl;
	
	
	
	
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	string s = res();
	int c = 0;
	for(int i=0;i<s.length();i++){
		if(s[i] == 'x'){
			c++;
		}
	}
	if(c < 8){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  ll N;cin >> N;
  vector<ll> vec(N);
  rep(i,N) cin >> vec[i];
  sort(All(vec));
  ll res = 1;
  for(int i=0;i<N;i++){
    if(vec[i] == 0) {
      cout << 0 << endl;
      return 0;
    }

    if(vec[i] <= (1000000000000000000 / res)) res*=vec[i];
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << res << endl;
}

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

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

typedef long long ll;
// ll mod_pow(ll x, ll n, ll mod){//x^n % mod
//     if (n == 0)
//         return 1;
//     ll res = mod_pow(x * x % mod, n / 2, mod);
//     if (n & 1)
//         res = res * x % mod;
//     return res;
// }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll N, M; cin >> N >> M;
    ll g = gcd(N, M);
    ll kou = (N/g) * (M/g) * g;
    string S, T;
    cin >> S;
    cin >> T;
    for (int i = 0, j = 0; i < (int)S.size() && j < (int)T.size(); i += kou/M, j += kou/N) {
        if (S[i] == T[j]) {
            continue;
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << kou << endl;
    return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int k, x; cin >> k >> x;
	cout << (500 * k >= x ? "Yes" : "No") << endl;
	return 0;
}

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

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007
#define tc             ll tc;scanf("%lld",&tc);while(tc--)

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

/*ll dx[]= {0,0,1,-1};
ll dy[]= {1,-1,0,0};*/


int main()
{
    ll n;
    string ss;
    cin >> n >> ss;
    string ans;
    vector<ll> al(27,0);
    for(ll i=0;i<ss.size();i++)
    {

        ll c=ss[i]- 'a';
        if(al[c]==0)
        {

            for(ll i=0;i<27;i++) al[i]=0;
            al[c]=1;
            ans.pb(ss[i]);
        }
    }
    cout << ans.size() << endl;
}


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

const mod = 10 ^^ 9 + 7;
alias mint = FactorRing!mod;

void main()
{
  auto rd = readln.split.to!(size_t[]), n = rd[0], m = rd[1];
  auto x = readln.split.to!(int[]);
  auto y = readln.split.to!(int[]);

  auto cx = new mint[](n), cy = new mint[](m);
  cx[0] = x[0]; cy[0] = y[0];
  foreach (i; 1..n) cx[i] = cx[i-1] + x[i];
  foreach (i; 1..m) cy[i] = cy[i-1] + y[i];

  auto sx = new mint[](n+1), sy = new mint[](m+1);
  foreach (i; 0..n) sx[i+1] = sx[i] + mint(i+1)*x[i] - cx[i];
  foreach (i; 0..m) sy[i+1] = sy[i] + mint(i+1)*y[i] - cy[i];

  writeln(sx[n]*sy[m]);
}

struct FactorRing(int m, bool pos = false)
{
  version(BigEndian) {
    union { long vl; struct { int vi2; int vi; } }
  } else {
    union { long vl; int vi; }
  }

  @property int toInt() { return vi; }
  alias toInt this;

  this(int v) { vi = v; }
  this(int v, bool runMod) { vi = runMod ? mod(v) : v; }
  this(long v) { vi = mod(v); }

  ref FactorRing!(m, pos) opAssign(int v) { vi = v; return this; }

  pure auto mod(int v) const
  {
    static if (pos) return v % m;
    else return (v % m + m) % m;
  }

  pure auto mod(long v) const
  {
    static if (pos) return cast(int)(v % m);
    else return cast(int)((v % m + m) % m);
  }

  static if (m < int.max / 2) {
    pure auto opBinary(string op: "+")(int rhs) const { return FactorRing!(m, pos)(mod(vi + rhs)); }
    pure auto opBinary(string op: "-")(int rhs) const { return FactorRing!(m, pos)(mod(vi - rhs)); }
  } else {
    pure auto opBinary(string op: "+")(int rhs) const { return FactorRing!(m, pos)(mod(vl + rhs)); }
    pure auto opBinary(string op: "-")(int rhs) const { return FactorRing!(m, pos)(mod(vl - rhs)); }
  }
  pure auto opBinary(string op: "*")(int rhs) const { return FactorRing!(m, pos)(mod(vl * rhs)); }

  pure auto opBinary(string op)(FactorRing!(m, pos) rhs) const
    if (op == "+" || op == "-" || op == "*") { return opBinary!op(rhs.vi); }

  static if (m < int.max / 2) {
    auto opOpAssign(string op: "+")(int rhs) { vi = mod(vi + rhs); }
    auto opOpAssign(string op: "-")(int rhs) { vi = mod(vi - rhs); }
  } else {
    auto opOpAssign(string op: "+")(int rhs) { vi = mod(vl + rhs); }
    auto opOpAssign(string op: "-")(int rhs) { vi = mod(vl - rhs); }
  }
  auto opOpAssign(string op: "*")(int rhs) { vi = mod(vl * rhs); }

  auto opOpAssign(string op)(FactorRing!(m, pos) rhs)
    if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(rhs.vi); }
}


Measured memory_bytes: 10696
package main

import (
    "fmt"
    "os"
    "bufio"
    "strconv"
    // "sort"
)
var sc = bufio.NewScanner(os.Stdin)


func dump(a []int){
    for i, v := range a {
        if i > 0{
            fmt.Print(" ")
        }
        fmt.Print(v)
    }
    fmt.Println("")
}

func gcd(y, x int) int {
    if y < x {
        return gcd(x, y)
    }
    if (x == 0) {
        return y;
    }
    return gcd(x, y%x);
    
}

func main() {
    sc.Split(bufio.ScanWords)
    // code goes here
    
    fmt.Println(gcd(nextInt(), nextInt()))
    
}



func nextInt() int {
    sc.Scan()
    v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}
func nextInt64() int64 {
    sc.Scan()
    v, e := strconv.ParseInt(sc.Text(), 10, 64)
    if e != nil { panic(e) }
    return v
}
func nextString() string {
    sc.Scan()
    return sc.Text()
}
func nextFloat() float64 {
    sc.Scan()
    v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}
func Max(x, y int) int { if x > y { return x }; return y }
func Min(x, y int) int { if x < y { return x }; return y }
func Abs(x int) int { if x > 0 { return x }; return -x }




Measured memory_bytes: 1120
<?php
fscanf(STDIN, "%d%d", $n, $m);
for($i = 0; $i < $m; $i++){
    fscanf(STDIN, "%d%d", $a[], $b[]);
}
array_multisort($a, SORT_DESC, $b);
$minX = 10**10;
$count = 0;
for($i = 0; $i < $m; $i++){
    if($minX >= $b[$i]){
        $count++;
        $minX = $a[$i];
    }
}
echo $count;

Measured memory_bytes: 26228
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N;
    io.read(N);
    cout << "ABC" << N;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
#include <deque>
#include <algorithm>
using namespace std;

const int maxn = 2e6, mod = 1e9 +7;

int n, m, cnt[maxn], used[maxn];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	int ans = 1;
	for(int i = 1; i <= n; i++) cnt[i] = 1;
	used[1] = 1;
	for(int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		cnt[u]--, cnt[v]++;
		if(!used[v] && used[u]) ans++, used[v] = 1;
		if(cnt[u] == 0 && used[u]) ans--, used[u] = 0;
	}
	cout<<ans;
}


//22 84 84 22
//1  2  3 4  2
//

Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [] a = new int [n];
        for(int i = 0; i < n ; i++) {
        	a[i] = sc.nextInt();
        }
        solve(a);
	}

	private static void solve(int [] a) {
		double d = 0;
		for(int i = 0; i < a.length; i++) {
			d += (1.0/a[i]);
		}
		double ans = 1 / d;
		System.out.println(ans);
	}
}

Measured memory_bytes: 25684
#include<iostream> 
using namespace std; 
int main()
{
	int A,B,K,i;
	string a="NG";
	scanf("%d%d%d",&K,&A,&B);
	for(i=A;i<=B;i++){
		if(i%K==0){
			a="OK";
		}
	}
	cout<<a;	
	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n;
  cin >> n;
  
  if (n.at(0) == '7' || n.at(1) == '7' || n.at(2) == '7' ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n,eu,ev,sid,dis[2][100100];
vector<int> ga[100100];
void dfs(int u,int p){
	dis[sid][u]=dis[sid][p]+1;
	for(int v:ga[u])
		if(v!=p) dfs(v,u);
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>eu>>ev;
		ga[eu].push_back(ev);
		ga[ev].push_back(eu);
	}
	sid=0;
	dfs(1,0);
	sid=1;
	dfs(n,0);
	int fen;
	fen=0;
	for(int i=1;i<=n;i++)
		if(dis[0][i]<=dis[1][i]) fen++;
	if(fen>=(n/2)+1) cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
	return 0;
}


Measured memory_bytes: 14580
import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val a = input.nextLine()
      a.foreach {
        case '1' => print('9')
        case '9' => print('1')
      }
      println()
    }

  }

}


Measured memory_bytes: 25548
#!/usr/bin/ruby
def Z(a,i)b=[];1.step(i){b<<$x;$x+=1}
b.reverse!if$c>0
$c^=1;a<<b
end
t=0
while(n=gets.to_i)>0
puts"Case #{t+=1}:"
a=[];$x=$c=1
1.step(n){|i|Z(a,i)}
(n-1).step(1,-1){|i|Z(a,i)}
n.times{|i|n.times{|j|$><<"%3d"%a[i+j].shift};puts}
end

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, k; cin >> n >> k;

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

    sort(p.begin(), p.end());

    int ans = 0;
    for (int i = 0; i < k; ++i) {
        ans += p[i];
    }

    cout << ans << endl;
}

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

struct node {
	struct node *r;
	struct node *l;
	struct node *p;
	int key;
};
typedef struct node * Node;

#define NIL NULL

Node root;

Node treeMinimum(Node x) {
	while (x->l != NIL) x = x->l;

	return x;
}

Node treeSuccessor(Node x) {
	Node y = malloc(sizeof(struct node));
	if (x->r != NIL) return treeMinimum(x->r);

	y = x->p;
	while (y != NIL && x == y->r) {
		x = y;
		y = y->p;
	}

	return y;
}

void deleteTree(Node z) {
	Node x,y;
	x = malloc(sizeof(struct node));
	y = malloc(sizeof(struct node));

	if (z->l == NIL || z->r == NIL) y = z;
	else y = treeSuccessor(z);

	if (y->l != NIL) x = y->l;
	else x = y->r;

	if (x != NIL) x->p = y->p;

	if (y->p == NIL) root = x;
	else if (y == y->p->l) y->p->l = x;
	else y->p->r = x;

	if (y != z) z->key = y->key;
}

Node searchTree(Node x,int key) {
	if (x == NIL || key == x->key) return x;
	if (key < x->key) {
		return searchTree(x->l, key);
	}
	else {
		return searchTree(x->r, key);
	}
}

void insert(int k) {
	Node y = NIL;
	Node x = root;
	Node z;

	z = malloc(sizeof(struct node));
	z->key = k;
	z->l = NIL;
	z->r = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) x = x->l;
		else x = x->r;
	}

	z->p = y;
	if (y == NIL) root = z;
	else if (z->key < y->key) y->l = z;
	else y->r = z;

	return;
}

void inorder(Node x) {
	if (x == NIL) return;
	inorder(x->l);
	printf(" %d",x->key);
	inorder(x->r);
	return;
}

void preorder(Node x) {
	if (x == NIL) return;
	printf(" %d",x->key);
	preorder(x->l);
	preorder(x->r);
	return;
}

int main() {
	int i,n, key;
	char s[10];

	scanf("%d", &n);

	for (i = 0;i < n;i++) {
		scanf("%s", s);
		if (s[0] == 'i') {
			scanf("%d", &key);
			insert(key);
		} else if (s[0] == 'f'){
			scanf("%d", &key);
			if (searchTree(root, key) != NIL) printf("yes\n");
			else printf("no\n");
		} else if (s[0] == 'd'){
			scanf("%d", &key);
			deleteTree(searchTree(root,key));
		} else {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}


	return 0;
}

Measured memory_bytes: 19364
#include <iostream>
#include <string>
#include <queue>

using namespace std;

int main()
{
    int n, q;
    queue<string> name;
    queue<int> time;

    cin >> n >> q;
    for (int i = 0; i < n; i++){
        string buf_s;
        int buf_n;
        
        cin >> buf_s >> buf_n;
        name.push(buf_s);
        time.push(buf_n);
    }
    
    queue<string> res_name;
    queue<int> res_time;
    int now_time = 0;
    while (!name.empty()){
        string one_name = name.front();
        int one_time = time.front();
        name.pop();
        time.pop();

        if (one_time <= q){
            now_time += one_time;
            res_name.push(one_name);
            res_time.push(now_time);
        } else {
            now_time += q;
            name.push(one_name);
            time.push(one_time - q);
        }
    }

    for (int i = 0; i < n; i++){
        cout << res_name.front() << " " << res_time.front() << endl;
        res_name.pop();
        res_time.pop();
    }

    return 0;
}




Measured memory_bytes: 5724
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main() {

	int p, q, r;

	cin >> p >> q >> r;

	if (p + q <= q + r && p + q <= p + r) {
		cout << p + q << endl;
	}
	else if (q + r <= p + r) {
		cout << q + r << endl;
	}
	else {
		cout << p + r << endl;
	}

	return 0;
}

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

#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	int N;
	cin >> N;
	vector<vi> ed(N);
	rep(i,1,N) {
		int a;
		cin >> a;
		--a;
		ed[a].push_back(i);
		ed[i].push_back(a);
	}
	function<int(int, int)> dfs = [&](int at, int par) -> int {
		vi d;
		trav(x, ed[at]) if (x != par) {
			d.push_back(dfs(x, at));
		}
		sort(all(d));
		int r = 0;
		rep(i,0,sz(d)) r = max(r, d[i] + sz(d) - i);
		return r;
	};
	cout << dfs(0, -1) << endl;
	exit(0);
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    if (a + b + 1 >= c) {
        cout << b + c << endl;
        return 0;
    } else {
        cout << a + b + 1 + b << endl;
        return 0;
    }

}


Measured memory_bytes: 256
from itertools import combinations

n, d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for a, b in combinations(X, 2):
    dist = 0
    for i in range(d):
        dist += (a[i] - b[i]) ** 2
    if dist ** 0.5 % 1 == 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 3188
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;

signed main(){

    int n,m;
    cin >> n >> m;
    queue<int> a[310];
    int used[310] = {0};
    int ans = 500;
    rep(i,n){
        rep(j,m){
            int v;
            cin >> v;
            a[i].push(v);
        }
    }

    rep(i,m){
        rep(j,n){
            while(used[a[j].front()] == 1)a[j].pop();
        }
        int cnt[310] = {0};
        rep(j,n) cnt[a[j].front()]++;
        int maxi = 0;
        int s = 0;
        for(int j = 1;j <= m;j++){
            if(maxi < cnt[j]){
                maxi = cnt[j];
                s = j;
            }
        }
        // for(int j = 1;j <= m;j++)cerr << cnt[j] << " ";
        // cerr << endl;
        // cerr << i << " " << maxi << endl;
        ans = min(ans,maxi);
        used[s] = 1;
    }
    cout << ans << endl;

    return 0;   
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://agc018.contest.atcoder.jp/tasks/agc018_b
// rm -r -f test;oj dl http://yahoo-procon2017-qual.contest.atcoder.jp/tasks/yahoo_procon2017_qual_c

Measured memory_bytes: 1024
#include <stdio.h>

long long dp[1003][1003];
const long long m=1000000007;

long long solve(long long i,long long j)
{
  if(i==0 && j==0) return dp[i][j]=1;
  if(dp[i][j]!=-1) return dp[i][j];
  else if(i==0) return dp[i][j]=solve(i,j-1);
  else if(j==0) return dp[i][j]=solve(i-1,j);
  else return dp[i][j]=(solve(i-1,j)+solve(i,j-1))%m;
}

int main()
{
  char c;
  long long h,w,ans;
  for(int i=0;i<1003;i++)
  {
    for(int j=0;j<1003;j++)
      dp[i][j]=-1;
  }
  scanf("%lld%lld",&h,&w);
  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
    {
      scanf(" %c",&c);
      if(c=='#')
        dp[i][j]=0;
    }
  }
  ans=solve(h-1,w-1);
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 8064
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


N=int(input())
if N <1200:
    print("ABC")
elif N <2800:
    print("ARC")
else:
    print("AGC")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int m = 200001; //minimum
  int t; //test
  int count = 0;
  rep(i, N){
    cin >> t;
    //cout << t << " " << m << "|";
    if(t < m){
      count++;
      m = t;
    }
  }
  cout << count;
  cout << endl;
  return 0;
}


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

int32_t main(){
    string s0; cin >> s0;
    deque<char> s;
    for(int i=0; i<s0.length(); ++i){
        s.push_back(s0[i]);
    }
    int flipped=0;
    int q; cin >> q;
    for(int i=0; i<q; ++i){
        int t; cin >> t;
        if(t == 1) flipped ^=1;
        else{
            int f; cin >> f; --f;
            char c; cin >> c;
            if(f^flipped){
                s.push_back(c);
            }
            else {
                s.push_front(c);
            }
        }
    }
    if(flipped) reverse(s.begin(), s.end());
    for(char c:s) cout << c;
    cout << endl;
}



Measured memory_bytes: 896
package main

import (
	"fmt"
	"math/big"
)

func main() {
	var n int64
	var m int64 = 1000000007
	fmt.Scan(&n)
	a := big.NewInt(0).Exp(big.NewInt(10), big.NewInt(n), big.NewInt(m))
	b := big.NewInt(0).Exp(big.NewInt(9), big.NewInt(n), big.NewInt(m))
	c := big.NewInt(0).Exp(big.NewInt(8), big.NewInt(n), big.NewInt(m))
	fmt.Println(
		big.NewInt(0).Mod(
			big.NewInt(0).Sub(
				big.NewInt(0).Add(a, c),
				big.NewInt(0).Add(b, b),
			),
			big.NewInt(m),
		).Int64(),
	)
}


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

typedef long long ll;
typedef pair<int, int> pi;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_op(i, a, n) for (int i = a; i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

int main()
{

    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i, n)
    {
        cin >> p[i];
        --p[i];
    }

    rep(i, n)
    {
        q[p[i]] = i;
    }

    rep(i, n)
    {
        cout << q[i] + 1 << " ";
    }

    cout << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    ll a,b;
    cin >> a >> b;
    if((a - b) % 2 == 0) cout << (a + b) / 2 << endl;
    else cout << "IMPOSSIBLE" << endl;
}

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

int main()
{

	int i, H, W, D, Q, MP;
	int L, R;
	pair<int, int> myhash[90001];	//値に対応するマス目の添え字i,jを格納

	cin >> H >> W >> D;
	for (i = 1; i < H + 1; ++i)
		for (int j = 1; j < W + 1; ++j){
			cin >> Q;	//一時的にQを代用
			myhash[Q].first = i;
			myhash[Q].second = j;
		}
	cin >> Q;

	int Move_MP[90001];

	for (i = 0; i < D + 1; ++i)
		Move_MP[i] = i;

	for (i = D + 1; i < H*W + 1; ++i)
		Move_MP[i] = Move_MP[i - D]
		+ abs(myhash[i].first - myhash[i - D].first)
		+ abs(myhash[i].second - myhash[i - D].second);

	int x, y;
	while (Q--){
		cin >> x >> y;
		MP = 0;
		if (x != y)
			MP = Move_MP[y] - Move_MP[x];
		cout << MP << endl;
	}

	return 0;

}



Measured memory_bytes: 2176
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 num = 3;
        if(a == b && b == c){
            num = 1;
        }else if(a == b || b == c || c == a){
            num = 2;
        }
        System.out.println(num);
    }
}

Measured memory_bytes: 35832
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		/*var N = len;
		var ls = new List<string>[N];
		for (var i = 0; i < N; i++) ls[i] = new List<string>();
		for (var i = 0; i < N; i++) ls[0].Add(i.ToString());
		for (var n = 1; n < N; n++) foreach (var s in ls[n - 1]) { var u = new HashSet<char>(s); for (var i = 0; i < N; i++) if (!u.Contains((char)(i + '0'))) ls[n].Add(s + i); }
		var l = new List<string>();
		foreach (var x in ls) l.AddRange(x);
		l.Sort(Compare);
		for (var i = 0; i < l.Count; i++)
		{
			if (i == 0) WriteLine($"{l[i]}");
			else
			{
				var t = Solve(l[i - 1]);
				WriteLine($"{l[i]}\t{t}\t{(l[i] == t ? "" : "ng")}");
			}
		}*/
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		WriteLine(Solve(ReadLine()));
		Out.Flush();
	}
	int Compare(string S, string T)
	{
		for (var i = 0; ; i++)
		{
			if (i >= S.Length && i >= T.Length) return 0;
			if (i >= S.Length) return -1;
			if (i >= T.Length) return 1;
			if (S[i] > T[i]) return 1;
			if (S[i] < T[i]) return -1;
		}
	}
	const char lower = 'a';
	const char upper = 'z';
	const int len = upper - lower + 1;
	string Solve(string S)
	{
		if (S.Length < len)
		{
			var used = new HashSet<char>(S);
			for (var c = lower; c <= upper; c++) if (!used.Contains(c)) return S + c;
		}
		for (var i = 0; i < len; i++) if (S[i] == upper)
			{
				var used = new HashSet<char>();
				for (var j = len - 1; j >= i + 2; j--)
					if (S[j - 1] < S[j])
					{
						for (var k = 0; k < j - 1; k++) used.Add(S[k]);
						for (var c = (char)(S[j - 1] + 1); c <= upper; c++) if (!used.Contains(c)) return S.Substring(0, j - 1) + c;
					}
				if (i == 0) break;
				for (var j = 0; j < i; j++) used.Add(S[j]);
				for (var c = (char)(S[i - 1] + 1); c <= upper; c++) if (!used.Contains(c)) return S.Substring(0, i - 1) + c;
			}
		return "-1";
	}
}


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

int main() {
    int a, b;
    cin >> a >> b;
    char grid[100][100];
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            grid[i][j] = i < 50 ? '#' : '.';
        }
    }
    for (int i = 0; i < a - 1; i++) {
        grid[i/50*2][i%50*2] = '.';
    }
    for (int i = 0; i < b - 1; i++) {
        grid[51+i/50*2][i%50*2] = '#';
    }
    cout << 100 << " " << 100 << endl;
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            cout << grid[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  vector<ll> a(n), b(n), c(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  for (int i = 0; i < n; i++){
    cin >> b[i];
  }
  for (int i = 0; i < n; i++){
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  
  sort(b.begin(), b.end());
  
  sort(c.begin(), c.end());
  
  ll res = 0;
  for (int i = 0; i < n; i++){
    ll A = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    ll C = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    res += A*C;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 2560
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

signed main() {
    string S;
    cin >> S;

    int ret = INF;

    for (int i = 0; i <= S.size() - 3; i++) {
        int tmp = 0;
        tmp += (S[i] - '0') * 100;
        tmp += (S[i+1] - '0') * 10;
        tmp += (S[i+2] - '0') * 1;

        int diff = abs(tmp - 753);
        ret = min(diff, ret);
    }
    cout << ret << endl;

    return 0;
}

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

int main(){
	int n,m,a[1000+2],b[1000+2],s=1,ans;
while(1){
s=1;
	scanf("%d%d",&n,&m);
if(n==0&&m==0)break;
	for(int i=1;i<n+1;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<m+1;i++){
		scanf("%d",&b[i]);
	}
	for(int i=1;;i++){
		s+=b[i];
		if(s>=n){ans=i; break;}
		s+=a[s];
		if(s>=n){ans=i; break;}
	}
	printf("%d\n",ans);
}
}
		

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


string add(string& a, string& b) {
  int n = max(a.size(), b.size()) + 1;
  reverse(begin(a), end(a));
  reverse(begin(b), end(b));
  while (a.size() < n) a += '0';
  while (b.size() < n) b += '0';
  string c(n, 0);
  int d = 0;
  for (int i = 0; i < n; ++i) {
    int x = (a[i] - '0') + (b[i] - '0') + d;
    if (x < 10) {
      c[i] = '0' + x;
      d = 0;
    } else {
      c[i] = '0' + x - 10;
      d = 1;
    }
  }
  while (c.size() > 1 and c.back() == '0') c.pop_back();
  reverse(begin(c), end(c));
  return c;
}

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  for (int _ = 0; _ < n; ++_) {
    string a, b; cin >> a >> b;
    auto c = add(a, b);
    if (c.size() > 80) cout << "overflow" << '\n';
    else cout << c << '\n';
  }
}


Measured memory_bytes: 3216
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        cs: Chars
    }
    let mut cs = cs;
    for i in 0..cs.len() {
        if cs[i] == '?' {
            cs[i] = 'D';
        }
    }

    println!("{}",cs.into_iter().collect::<String>());
}

Measured memory_bytes: 3300
#include<stdio.h>
int main()
{
    int a,b,c,k;
    scanf("%d%d%d%d",&a,&b,&c,&k);
    if(a>=k)
    printf("%d",k);
    else if(a+b>=k)
    printf("%d",a);
    else
    printf("%d",a-(k-a-b));
    
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n; cin >> n;
	vector<int> p(n + 1);
	for(int i = 1; i <= n; i++) {
		int x; cin >> x;
		p[x] = i;
	}
	set<int> s;
	s.insert(0);
	s.insert(n + 1);
	long long ans = 0;
	for(int i = 1; i <= n; i++) {
		int pos = p[i];
		auto j = s.upper_bound(pos);
		int r = *j;
		j--;
		int l = *j;
		ans += i * 1LL * (pos - l) * 1LL * (r - pos);
		s.insert(pos);
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 10368