akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 211;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;



int n, k, m, x;
bool was[N];

main () {
	cin >> n >> k;
	while (k--) {
		cin >> m;
		while (m--) {
			cin >> x;
			was[x] = 1;
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; ++i)
		if (!was[i])
			++ans;
	cout << ans << endl;
}





Measured memory_bytes: 3620
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		int T=s.nextInt();
		for(int i=0;i<T;i++){
			int a=s.nextInt();
			int b=s.nextInt();
			int c=s.nextInt();
			if(a*a==b*b+c*c||a*a+b*b==c*c||a*a+c*c==b*b)System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 12000
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

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

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

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

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	N := readInt()
	S := readString()
	n := N / 2
	s1 := S[:n]
	s2 := S[n:]

	if s1 == s2 {
		println("Yes")
	} else {
		println("No")
	}

}

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


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

signed main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<int> A(N + 1);
  for (int i = N; ~i; --i) cin >> A[i];

  set<int> ans;

  int g = 0;
  for (int a : A) g = __gcd(g, abs(a));
  for (int &a: A) a /= g;
  for (int i = 2; i * i <= g; ++i) {
    if (g % i == 0) {
      while (g % i == 0) g /= i;
      ans.insert(i);
    }
  }
  if (1 < g) ans.insert(g);

  set<int> primes; {
    int c = A[0];
    for (int i = 2; i * i <= c; ++i) {
      if (c % i == 0) {
        while (c % i == 0) c /= i;
        primes.insert(i);
      }
    }
    if (1 < c) primes.insert(c);
    vector<int> np(N + 1);
    for (int i = 2; i < N + 1; ++i) {
      if (np[i]) continue;
      primes.insert(i);
      for (int j = 2*i; j < N + 1; j += i) {
        np[j] = 1;
      }
    }
  }

  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  for (int p : primes) {
    auto valid = [&rng, &N, &A](int p) {
      const int _t = 20;
      for (int _ = 0; _ < _t; ++_) {
        int x = uniform_int_distribution<int>(0, 1e9)(rng);
        if (_ * 2 < _t) x *= -1;
        int s = 0;
        for (int i = 0, n = 1; i < N + 1; ++i) {
          s += 1LL * n * A[i] % p;
          s %= p;
          n = 1LL * n * x % p;
        }
        if (s) return false;
      }
      return true;
    };
    if (valid(p)) ans.insert(p);
  }

  for (int p : ans) cout << p << '\n';

  return 0;
}

Measured memory_bytes: 384
N,A,B,C=map(int, input().split())
l=[int(input()) for i in range(N)]
from itertools import product
p=list(product([0,1,2,3],repeat=N))
t=10000
for i in p:
    a=b=c=ac=0
    for j in range(N):
        if i[j]==1:
            a+=l[j]
            ac+=1
        elif i[j]==2:
            b+=l[j]
            ac+=1
        elif i[j]==3:
            c+=l[j]
            ac+=1
    if a and b and c:
        tt=abs(a-A)+abs(b-B)+abs(c-C)+(ac-3)*10
        if t>tt:
            t=tt
print(t)

Measured memory_bytes: 51256
#include<iostream>
using namespace std;
int main(){
int W,H,x,y,r;
cin>>W>>H>>x>>y>>r;
if(0<=x-r&&0<=y-r&&r+x<=W&&r+y<=H)


cout<<"Yes"<<endl;

else
cout<<"No"<<endl;

return 0;
}




Measured memory_bytes: 3120
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    string S;
    cin >> S;
    int64_t K;
    cin >> K;
    bool all_one = true;
    int64_t one_break_index = 0;
    int s_size = S.size();
    for (int i=0; i<s_size; i++) {
        if (S[i] != '1') {
            all_one = false;
            one_break_index = i;
            break;
        }
    }

    if (all_one || one_break_index >= K) {
        cout << 1 << endl;
    } else {
        cout << S[one_break_index] << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
from collections import defaultdict


def solve(n, m, s):
    i = n
    res_list = []
    while i > 0:
        flag = True
        for j in range(min(i, m), 0, -1):
            if s[i - j] == "0":
                res_list.append(j)
                i -= j
                flag = False
                break
        if flag:
            return [-1]
    return list(reversed(res_list))


def main():
    n, m = map(int, input().split())
    s = input()
    res_list = solve(n, m, s)
    print(*res_list)


def test():
    assert solve(9, 3, "0001000100") == [1, 3, 2, 3]
    assert solve(5, 4, "011110") == [-1]
    assert solve(6, 6, "0101010") == [6]


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 6628
N,M =[int(i)for i in input().split()]
X =[int(i)for i in input().split()]
X =sorted(X)
dx =[]
for i in range(len(X)-1):
    dx.append(X[i+1]-X[i])
dx =sorted(dx)
if N>=M:
    print(0)
else:
    print(sum(dx[0:M-N]))


Measured memory_bytes: 13840
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
  int n,i,co=0,comax=0;
  string s,t;
  cin >> n;
  cin >> s;
  for(i=0;i<n;i++){
    t=s.substr(i,1);
    if(t=="("){
      co--;
    }else{
      co++;
      comax=max(co,comax);
    }
  }
  co-=comax;
  for(i=0;i<comax;i++)
    cout << "(";
  cout << s;
  for(i=co;i<0;i++)
    cout << ")";
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++)cin>>a[i];
	ll dp[n]={0};
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	// if(n>=2)
	for(ll i=2;i<n;i++){
		ll min1=1000000000000000;
		for(ll j=i-1;j>=max((ll)0,i-k);j--){
			min1=min(min1,dp[j]+abs(a[i]-a[j]));
		}
		dp[i]=min1;
		// dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
		// cout<<dp[i]<<" ";
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <unordered_map>
#include <stack>

int N;
std::vector<std::vector<int>> A;

std::pair<int,int> GetMaxInd(int in){
  std::pair<int,int> L (-1,-1);
  std::vector<int> memo(N, -1);
  std::stack<int> q;
  q.push(in); memo[in] = 0;
  while(!q.empty()){
    auto cur = q.top(); q.pop();
    for(int i=0; i<A[cur].size(); i++) {
      int next = A[cur][i];
      if ( memo[next] == -1 ) {
        memo[next] = (memo[cur] + 1);
        if ( L.first < memo[next] ) L = { memo[next], next } ;
        q.push(next);
      }
    }
  }
  return L;
}

int GetDiameter () {
  auto s = GetMaxInd(0);
  auto g = GetMaxInd(s.second);
  return g.first;
}

int main (void) {
  std::cin >> N;
  A.resize(N);

  for(int i=0; i<N-1; i++){
    int a,b; std::cin >> a >> b;
    A[a-1].push_back(b-1);
    A[b-1].push_back(a-1);
  }

  int L = GetDiameter();
  if ( L % 3 == 1 ) std::cout << "Second" << std::endl;
  else std::cout << "First" << std::endl;

  return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    char c1, c2, c3;
    c1 = s1.at(0)-'a'+'A';
    c2 = s2.at(0)-'a'+'A';
    c3 = s3.at(0)-'a'+'A';
    
    cout << c1 << c2 << c3 << endl;
    return 0;
}


Measured memory_bytes: 3528
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
cnt=array(N+1,0)
def primes(n)
    primes=[]
    2.upto((n**0.5).to_i+1) do|i|
      while (n%i).zero?
          primes.push(i)
          n/=i
      end
    end
    primes.push(n) if n!=1
    return primes 
end

N.times do|i|
  prime=primes(N-i)
  prime.each do|p_|
      cnt[p_]+=1
  end
end
ans=1
cnt.each do|c|
    ans*=(c+1)
    ans%=(10**9+7)
end
puts ans

Measured memory_bytes: 1916
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

#include<vector>

#define INF 999999
using namespace std;
bool prime[55000]={0};
int main(){
    prime[1]=1;
    for(int i=2;i*i<55000;i++){
        if(prime[i]==0){
            for(int j=i;j<=55000;j+=i){
                if(prime[j]==0){
                    prime[j]=1;
                }
            }
            prime[i]=0;
        }
    }
    int N;
    while(~scanf("%d",&N)){
        for(int i=N-1;;i--){
            if(prime[i]==0){cout<<i<<" ";break;}
        }
        for(int i=N+1;;i++){
            if(prime[i]==0){cout<<i<<endl;break;}
        }
    }
    return 0;
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

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

    long long a, ans, c = 2;
    cin >> a;
    ans = a - 1;

    rep(i,n - 1){
        cin >> a;
        if(a == c) c++;
        else ans += (a - 1) / c;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		dPA();

	}

	private static void dPA() {
		Scanner scanner = null;
		int numAshiba = 0;
		int numK = 0;

		try {
			scanner = new Scanner(System.in);
			numAshiba = scanner.nextInt();
			numK = scanner.nextInt();
			int[] heightArray = new int[numAshiba];
			int[] koufukuArray = new int[numAshiba];
			Arrays.fill(koufukuArray, Integer.MAX_VALUE);

			for (int i = 0; i < numAshiba; i++) {
				heightArray[i] = scanner.nextInt();
			}
			koufukuArray[0] = 0;
			for (int i = 0; i < numAshiba; i++) {
				for (int j = 1; j <= numK; j++) {
					if (i + j >= numAshiba)
						continue;
					koufukuArray[i + j] = Math.min(koufukuArray[i] + Math.abs(heightArray[i] - heightArray[i + j]),
							koufukuArray[i + j]);
				}
			}

			System.out.println(koufukuArray[numAshiba - 1]);
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 58500
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int i=1;
	if(b!=a)i++;
	if(c!=a&&c!=b)i++;
	cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

double dp[3000][3000]; //! [index of the coin tried][# of head coins]


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

    int N;
    cin >> N;

    rep(i, N) {
        double p;
        cin >> p;
        if (i == 0) {
            dp[0][0] = 1.0-p;
            dp[0][1] = p;
        } else {
            for (int j = 0; j <= i+1; ++j) {
                dp[i][j] = (j ? dp[i-1][j-1] * p : 0) + dp[i-1][j] * (1.0-p);
            }
        }
    }

    // cout << endl;
    // rep(i, N) {
    //     rep(j, N+1) {
    //         cout << dp[i][j] << ' ';
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    double ans = 0;
    for (int j = N/2+1; j <=N; ++j) {
        ans += dp[N-1][j];
    }

    cout << setprecision(10) << ans << endl;


    return 0;
}


Measured memory_bytes: 68864
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int ans[100010];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int H,W; cin >> H >> W;
    int N; cin >> N;
    map<pi,int> m;
    rep(i,N) {
        int a,b; cin >> a >> b;
        a--; b--;
        rng(j,-1,2){
            rng(k,-1,2){
                int s=a+j,t=b+k;
                if(s>=1 && s<H-1 && t>=1 && t<W-1){
                    m[pi(s,t)]++;
                }
            }
        }
    }
    for(auto p:m){
        ans[p.se]++;
    }
    ans[0]=(H-2)*(W-2);
    rng(i,1,10){
        ans[0]-=ans[i];
    }
    rep(i,10){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 56576
#include <bits/stdc++.h>
#define offset 110
#define maxsize 250
using namespace std;

struct data {
  int h, n;
};
struct die {
  int t, f;
};

vector<vector<data>> v;
vector<die> vd;
vector<int> ans;
die dis[6][6][4];
int d[4] = {1, 0, -1, 0};
int n;

void setdis();
void solve();

int main() {
  setdis();
  while(1) {
    cin >> n;
    if(n == 0) break;
    vd.resize(n);
    for(int i = 0; i < n; ++i) cin >> vd[i].t >> vd[i].f;
    v.assign(maxsize, vector<data>(maxsize, {0, -1}));
    ans.assign(6, 0);
    solve();
    for(int i = 0; i < 6; ++i) {
      if(i != 0) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}

void setdis() {
  for(int i = 0; i < 6; ++i)
    for(int j = 0; j < 6; ++j)
      for(int k = 0; k < 4; ++k) dis[i][j][k] = {0, 0};
  dis[0][1][1] = {2, 6};
  dis[0][1][2] = {3, 2};
  dis[0][2][0] = {2, 3};
  dis[0][2][1] = {3, 6};
  dis[0][3][2] = {2, 4};
  dis[0][3][3] = {3, 1};
  dis[0][4][0] = {3, 5};
  dis[0][4][3] = {2, 1};
  dis[1][0][0] = {3, 1};
  dis[1][0][1] = {1, 5};
  dis[1][2][1] = {3, 5};
  dis[1][2][2] = {1, 3};
  dis[1][3][0] = {1, 4};
  dis[1][3][3] = {3, 2};
  dis[1][5][2] = {3, 6};
  dis[1][5][3] = {1, 2};
  dis[2][0][1] = {1, 4};
  dis[2][0][2] = {2, 1};
  dis[2][1][0] = {1, 2};
  dis[2][1][1] = {2, 4};
  dis[2][4][2] = {1, 5};
  dis[2][4][3] = {2, 3};
  dis[2][5][0] = {2, 6};
  dis[2][5][3] = {1, 3};
  dis[3][0][0] = {2, 1};
  dis[3][0][1] = {1, 3};
  dis[3][1][1] = {2, 3};
  dis[3][1][2] = {1, 2};
  dis[3][4][0] = {1, 5};
  dis[3][4][3] = {2, 4};
  dis[3][5][2] = {2, 6};
  dis[3][5][3] = {1, 4};
  dis[4][0][1] = {1, 2};
  dis[4][0][2] = {3, 1};
  dis[4][2][0] = {1, 3};
  dis[4][2][1] = {3, 2};
  dis[4][3][2] = {1, 4};
  dis[4][3][3] = {3, 5};
  dis[4][5][0] = {3, 6};
  dis[4][5][3] = {1, 5};
  dis[5][1][0] = {3, 2};
  dis[5][1][1] = {2, 1};
  dis[5][2][1] = {3, 1};
  dis[5][2][2] = {2, 3};
  dis[5][3][0] = {2, 4};
  dis[5][3][3] = {3, 6};
  dis[5][4][2] = {3, 5};
  dis[5][4][3] = {2, 6};

  for(int i = 0; i < 6; ++i)
    for(int j = 0; j < 6; ++j)
      for(int k = 0; k < 4; ++k) {
        --dis[i][j][k].f;
        --dis[i][j][k].t;
      }
}

void solve() {
  for(int i = 0; i < n; ++i) {
    int x = offset, y = offset;
    die nowdie = vd[i];
    --nowdie.t, --nowdie.f;
    while(1) {
      int nextdir = -1;
      for(int j = 0; j < 4; ++j)
        if(dis[nowdie.t][nowdie.f][j].t != -1 &&
           v[x][y].h > v[x + d[j]][y + d[1 ^ j]].h &&
           (nextdir == -1 ||
            dis[nowdie.t][nowdie.f][j].t <
                dis[nowdie.t][nowdie.f][nextdir].t))
          nextdir = j;
      if(nextdir == -1) break;
      nowdie = dis[nowdie.t][nowdie.f][nextdir];
      x += d[nextdir];
      y += d[nextdir ^ 1];
    }
    ++v[x][y].h;
    v[x][y].n = nowdie.t;
  }
  for(int i = 0; i < maxsize; ++i)
    for(int j = 0; j < maxsize; ++j)
      if(v[i][j].n >= 0) ++ans[v[i][j].n];
}


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

int main(){
  int N, K; cin>>N>>K;
  int X;
  for(int i=0; i<N; i++){
    int A; cin>>A;
    if(A==1) X==i; //最小値の位置
  }
  // 左にX個、右にN-(X+1)個　1回でK-1個まで増える
  int L=X;
  int R=N-(X+1);
  int ansL, ansR;
  if(L%(K-1)==0) ansL=L/(K-1);
  else ansL=1+L/(K-1);
  if(R%(K-1)==0) ansR=R/(K-1);
  else ansR=1+R/(K-1);
  cout<<ansL+ansR<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   int n;
   cin >> n;
   vector<int>a(n);
   rep(i,n)cin >> a[i];
   int b[8];
   int hoge =0;
   rep(i,8)b[i]=0;
   rep(i,n)
   {
      if(a[i]<400)
      b[0]=1;
      else if(a[i]<800)
      b[1]=1;
      else if(a[i]<1200)
      b[2]=1;
      else if(a[i]<1600)
      b[3]=1;
      else if(a[i]<2000)
      b[4]=1;
      else if(a[i]<2400)
      b[5]=1;
      else if(a[i]<2800)
      b[6]=1;
      else if(a[i]<3200)
      b[7]=1;
      else hoge ++;
   }
   int ans =0;
   rep(i,8)if(b[i])ans++;
   cout<<max(ans,1)<<" "<<ans+hoge<<endl;
   return 0;
}

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

int main() {
  //input
  vector<vector<int> > v;
  while(1) {
    vector<int> nx(2, 0);
    cin >> nx[0] >> nx[1];

    if(nx[0] == 0 && nx[1] == 0) break;
    v.push_back(nx);
  }

  //output
  rep(i, v.size()) {
    vector<int> nx = v[i];
    int count = 0;
    for(int j=1; j<=nx[0]-2; j++)
      for(int k=j+1; k<=nx[0]-1; k++)
	for(int l=k+1; l<=nx[0]; l++){
	  if(nx[1] == j+k+l) count++;
	}
    
    cout << count << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3136
import math
a, b, h, m = map(int, input().split())
if m != 0:
    h += m / 60

ax = math.cos(math.radians(h * 30)) * a
ay = math.sin(math.radians(h * 30)) * a
bx = math.cos(math.radians(m * 6)) * b
by = math.sin(math.radians(m * 6)) * b

print(math.sqrt((ax - bx) ** 2 + (ay - by) ** 2))

Measured memory_bytes: 9580
n,k = map(int,input().split())
r,l=(n+1)*n//2 - (n-k)*(n-k+1)//2,(k-1)*(k)//2;an=0;p=10**9+7
for i in range(k,n+2):
	an=(an+r-l+1)%p
	r+=n-i
	l+=i
#;print(l,r)
print(an)


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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if(a.back()==b.front()&&b.back()==c.front()){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
x, y = map(int, input().split())

group_1 = [1, 3, 5, 7, 8, 10, 12]
group_2 = [4, 6, 9, 11]

if x == 2 and y == 2:
    print("Yes")

else:
    if x in group_1 and y in group_1:
        print("Yes")

    elif x in group_2 and y in group_2:
        print("Yes")

    else:
        print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const double EPS = 1e-10;
int main(){
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
char a[100], b[100], c[100];
int main()
{
	int n, total = 0;
	scanf("%d%s%s%s", &n, a, b, c);
	for(int i = 0; i < n; ++i)
	{
		if(a[i] == b[i])
		{
			if(a[i] == c[i])
			{
				total += 0;
			}
			else
			{
				total += 1;
			}
		}
		else
		{
			if(a[i] == c[i])
			{
				total += 1;
			}
			else if(b[i] == c[i])
			{
				total += 1;
			}
			else
			{
				total += 2;
			}
		}
	}
	printf("%d\n", total);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long long int i,H,W,w,h,ans=0;
	scanf("%lld%lld",&H,&W);

	
	if(H==1 || W==1)ans=1;
	else
	{
		w=W/2;
		if(W%2!=0)w++;
		ans+=w*(H/2);
		if(H%2!=0)ans+=w;	
		
		w=W/2;
		ans+=w*(H/2);
		
	}	
	printf("%lld",ans);
		
	return 0;
}

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

namespace IO
{
    const int S=(1<<20)+5;
    char buf[S],*H,*T;
    inline char Get()
    {
        if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
        if(H==T) return -1;return *H++;
    }
    inline int read()
    {
        int x=0;char c=Get();
        while(!isdigit(c)) c=Get();
        while(isdigit(c)) x=x*10+c-'0',c=Get();
        return x;
    }
    char obuf[S],*oS=obuf,*oT=oS+S-1,c,qu[55];int qr;
    inline void flush(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
    inline void putc(char x){*oS++ =x;if(oS==oT) flush();}
    template <class I>inline void print(I x)
    {
        if(!x) putc('0');
        while(x) qu[++qr]=x%10+'0',x/=10;
        while(qr) putc(qu[qr--]);
        putc('\n');
    }
}

using namespace IO;
typedef long long LL;
const int N=300010;
int n,cost[N];
LL pre[N],suf[N],s[N],h[N];

struct Line
{
    LL k,b;
    Line(LL _k=0,LL _b=0):k(_k),b(_b){}
    LL get(int x){return k*x+b;}
    double intersec(const Line &a){return (double)(a.b-b)/(k-a.k);}
} stk[N];

void prework(LL* f)
{
    for(int i=1;i<=n;i++) s[i]=s[i-1]+cost[i];
    for(int i=1,top=0;i<=n;i++)
    {
        while(top&&stk[top].get(i)<=stk[top-1].get(i)) top--;
        f[i]=max(f[i-1],stk[top].get(i)-s[i]+1ll*i*(i+1)/2);
        Line tmp=Line(-i,f[i]+1ll*i*(i-1)/2+s[i]);
        while(top&&stk[top-1].intersec(stk[top])<=stk[top-1].intersec(tmp)) top--;
        stk[++top]=tmp;
    }
}

void divide(int L,int R)
{
    if(L==R){h[L]=1-cost[L];return;}
    int M=(L+R)/2,top=0;
    divide(L,M);divide(M+1,R);
    for(int i=L-1;i<M;i++)
    {
        Line tmp=Line(-i,pre[i]+1ll*i*(i-1)/2+s[i]);
        while(top>1&&stk[top-1].intersec(tmp)>=stk[top-1].intersec(stk[top])) top--;
        stk[++top]=tmp;
    }
    LL mx=-INT64_MAX;int now=1;
    for(int i=R;i>M;i--)
    {
        while(now<top&&stk[now].intersec(stk[now+1])>=i) now++;
        mx=max(mx,stk[now].get(i)+1ll*i*(i+1)/2-s[i]+suf[i+1]);
        h[i]=max(h[i],mx);
    }
    top=0;
    for(int i=M+1;i<=R;i++)
    {
        Line tmp=Line(-i,suf[i+1]+1ll*i*(i+1)/2-s[i]);
        while(top>1&&stk[top-1].intersec(tmp)>=stk[top-1].intersec(stk[top])) top--;
        stk[++top]=tmp;
    }
    now=top;mx=-INT64_MAX;
    for(int i=L-1;i<M;i++)
    {
        while(now>1&&stk[now].intersec(stk[now-1])<=i) now--;
        mx=max(mx,stk[now].get(i)+1ll*i*(i-1)/2+s[i]+pre[i]);
        h[i+1]=max(h[i+1],mx);
    }
}

int main()
{
    n=read();
    for(int i=1;i<=n;i++) cost[i]=read();
    prework(pre);
    reverse(cost+1,cost+1+n);
    prework(suf);
    reverse(cost+1,cost+1+n);
    reverse(suf+1,suf+1+n);
    for(int i=1;i<=n;i++) s[i]=s[i-1]+cost[i];
    divide(1,n);
    for(int m=read(),p,x;m;m--)
    {
        p=read();x=read();
        print(max(pre[p-1]+suf[p+1],h[p]+cost[p]-x));
    }
    flush();
    return 0;
}

Measured memory_bytes: 19840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] c = s.toCharArray();
		int z = 0;
		int o = 0;
		for(int i = 0;i < c.length; i++) {
			if(c[i] == '0') {
				z++;
			}
			else {
				o++;
			}
		}
		System.out.println(Math.min(z, o)*2);
	}
}


Measured memory_bytes: 39400
import java.util.Scanner;
    
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String aa = scan.next();
    String bb = scan.next();
    int a = Integer.parseInt(aa);
    int b = Integer.parseInt(bb);
    if(a > b) {
      System.out.println("a > b");
    } else if(a < b) {
      System.out.println("a < b");
    } else {
      System.out.println("a == b");
    }
  }
}

Measured memory_bytes: 26024
import numpy as np


def main(A):
    ans = 1
    for i in A:
        if i == 0:
            return 0
    for i in A:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
    return ans


N = int(input())
A = list(map(int, input().split()))
print(main(A))


Measured memory_bytes: 39872
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[10000100];

int main(){
  ll n; cin >> n;
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j+=i){
      dp[j]++;
    }
  }
  ll ans=0;
  for(int i=1;i<=n;i++){
    ans+=i*dp[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 81716
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T1, T2; cin >> T1 >> T2;
    int A1, A2, B1, B2;
    cin >> A1 >> A2;
    cin >> B1 >> B2;
    if(A1 > B1) {
        swap(A1, B1);
        swap(A2, B2);
    }
    int dA1 = T1 * A1, dA2 = dA1 + T2 * A2;
    int dB1 = T1 * B1, dB2 = dB1 + T2 * B2;
    // cout << dA1 << " " << dA2 << endl;
    // cout << dB1 << " " << dB2 << endl;
    if(dA2 == dB2) {
        cout << "infinity" << endl;
        return 0;
    }
    int diff = dA2 - dB2;
    int ok = -1;
    int ng = 1e+18;
    map<int, int> mp;
    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        double c = T1 * A1 + (diff * (double)mid);
        if(c > 2e+18) ng = mid;
        int dA1 = T1 * A1 + diff * mid, dA2 = dA1 + T2 * A2;
        int dB1 = T1 * B1, dB2 = dB1 + T2 * B2;
        //cerr << mid << " " << dA1 << " " << dB1 << " " << dA2 << " " << dB2 << endl;
        if(dA1 <= dB1 && dA2 >= dB2) {
            ok = mid;
            if(dA1 < dB1 && dA2 >= dB2) {
                mp[mid] = 1;
            }
        }
        else ng = mid;
    }
    cout << max(0LL,ok * 2 + mp[ok]) << endl;


    return 0;
}
// 1 1
// 2 1
// 1 3


// 0 2 3 5 
// 0 1 4 5

// 0 3 4 7
// 0 2 5 7

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

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

  ll d = 1;
  for (ll i=1; i<=n; i++) {
    d = i;
    ll s = i*(i+1)/2;
    if (s >= n) break;
  }

  ll e = d*(d+1)/2 - n;
  for (int i=1; i<=d; i++) {
    if (e != i) cout << i << endl;
  }

  return 0;
}


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

int main(){
    int n, a;
    cin >> n;
    int v = n;

    vector<vector<int>> cost_graph(v, vector<int>(v,0));
    vector<vector<int>> mask(v, vector<int>(v,0));

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


    for(int k=0;k<v;k++){
        for(int i=0;i<v;i++){
            for(int j=0;j<v;j++){
                if(k==i || k==j || i==j){continue;}
                if(cost_graph[i][k] + cost_graph[k][j] > cost_graph[i][j]){

                }else if(cost_graph[i][k] + cost_graph[k][j] == cost_graph[i][j]){
                    mask[i][j] = 1;
                    mask[j][i] = 1;
                }else if(cost_graph[i][k] + cost_graph[k][j] < cost_graph[i][j]){
                    cout << "-1" << endl;
                    return 0;
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            ans += mask[i][j] ? 0 : cost_graph[i][j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A, B, M;
int a[100004], b[100004];

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

  cin >> A >> B >> M;
  int mina = INF, minb=INF;
  rep(i, A) {
    cin >> a[i];
    mina = min(a[i], mina);
  }
  rep(i, B) {
    cin >> b[i];
    minb = min(b[i], minb);
  }
  int minx = mina+minb;
  int x=0,y=0,c=0;
  rep(i, M) {
    cin >> x >> y >>c;
    x--;y--;
    minx = min(a[x]+b[y]-c, minx);
  }

  cout << minx << "\n";
  return 0;
}

Measured memory_bytes: 1024
/*
n>=m
假设y=x对角线上不猜-->答案=n
对角线上每个点单独计算对答案的贡献
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1000010
#define ll long long
#define mod 998244353
using namespace std;
int n, m, jc[N], inv[N], INV, ans;
inline int C(int n, int m){return (ll)jc[n]*inv[m]%mod*inv[n-m]%mod;}
inline int inv_C(int n, int m){return (ll)inv[n]*jc[m]%mod*jc[n-m]%mod;}
int main(){
	scanf("%d%d", &n, &m); if(n<m)swap(n, m);
	jc[0]=1; for(int i=1; i<=n+m; i++)jc[i]=(ll)jc[i-1]*i%mod;
	inv[0]=inv[1]=1; for(int i=2; i<=n+m; i++)inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
	INV=inv[2]; for(int i=1; i<=n+m; i++)inv[i]=(ll)inv[i-1]*inv[i]%mod;
	ans=n;
	for(int i=1; i<=m; i++)ans=(ans+(ll)C(i*2, i)*C(n+m-i*2, m-i)%mod*INV%mod*inv_C(n+m, m)%mod)%mod;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 7936
from collections import defaultdict
import numpy as np

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

d = defaultdict(int)

for a in A:
    d[a] += 1

values = np.array(list(d.values()))

if np.where(values >= 2)[0].shape[0] < 2:
    print(0)
else:
    over_4 = []
    over_2 = []

    for n, v in d.items():
        if v >= 4:
            over_4.append(n)
        if v >= 2:
            over_2.append(n)

    over_2 = sorted(over_2, reverse=True)

    ans_4 = 0
    if len(over_4) > 0:
        ans_4 = max(over_4)
    ans_2 = over_2[0] * over_2[1]

    print(max(ans_4**2, ans_2))

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

int main() {int n;cin>>n;bool f=false;
  for(int i=1;i<10;i++){for(int j=1;j<10;j++){
  if(i*j==n){f=true;}}}if(f){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

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


int main(){
char a[55],b[55];

	scanf("%s",&a);
	scanf("%s",&b);
	int len1 = strlen(a);
	int len2 = strlen(b);
	for(int i = 0; i < len1; i++)
	{
		printf("%c",a[i]);
		if(i < len2) printf("%c",b[i]);
		
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# N = int(input())
# N = int(input().split())
# N, K = [int(x) for x in input().split()]

N = int(input())
S = input()

c = 0

for n in range(N-2):
    if S[n:n+3] == "ABC":
        c += 1

print(c)


Measured memory_bytes: 2940
#include<stdio.h>
#define N 10000
#define NIL -1

typedef struct Node{
  int parent,right,left;
}Node;

Node T[N];
int n,D[N],H[N];

void setDepth(int u,int d){
  if(u==NIL) return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL){
    h1 = setHeight(T[u].left)+1;
  }
  if(T[u].right!=NIL){
    h2 = setHeight(T[u].right)+1;  
  }
  return H[u]=(h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].parent==NIL) return NIL;
  else if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
  else if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
  else return NIL;
  
}

void print(int u){
  printf("node %d: ", u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);
  
  if(T[u].parent == NIL){
    printf("root\n");
  }
  else if(T[u].left == NIL && T[u].right == NIL){
    printf("leaf\n");
  }
  else {
    printf("internal node\n");
  }
}
main(){
  
  int i,r,l,v,root=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=NIL;
  }
  
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL) T[l].parent=v;
    if(r!=NIL) T[r].parent=v;
  }
  
  for(i=0;i<n;i++){
    if(T[i].parent==NIL) root=i;
  }
  setDepth(root,0);
  setHeight(root);
  
  for(i=0;i<n;i++) print(i);
  
  return 0;
}

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

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

int r[100000];
int c[100000];
int H, W, D;
vector<vector<int>> v;

int calc(int x, int y)
{
	return abs(r[x] - r[y]) + abs(c[x] - c[y]);
}

void init()
{
	cin >> H >> W >> D;
	rep(i, H) {
		rep(j, W) {
			int t;
			cin >> t;
			r[t] = i;
			c[t] = j;
		}
	}
	v.RS(H*W/D+2, vector<int>(D, 0));
	reps(i, 1, H*W+1-D) {
		int r = i / D + 1;
		int c = i % D;
		v[r][c] = calc(i, i+D);
	}
	rep(i, D) {
		reps(j, 1, v.size()) {
			v[j][i] += v[j-1][i];
		}
	}
}

void solve()
{
	int Q;
	cin >> Q;
	while(Q--) {
		int l, r;
		cin >> l >> r;
		cout << v[r/D][r%D] - v[l/D][l%D] << endl;
	}
}



Measured memory_bytes: 7424
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
// it is a knapsack dummy
int knp(int wei[],int val[],int n,int mxl){
	int dp[n+1][mxl+1]; // consider items for all possible weight
	//for(int i=0;i<n;++i) cout<<wei[i]<<" "<<val[i]<<"\n";
	for(int i=0;i<=n;++i) for(int j=0;j<=mxl;++j){
		if(i==0 || j==0) dp[i][j]=0;
		else if(wei[i-1]<=j) {
			// consider the weight
			dp[i][j] = max(val[i-1]+dp[i-1][j-wei[i-1]],dp[i-1][j]);
			// either include or not
		}
		else {
			// now i cannot include it 
			dp[i][j]=dp[i-1][j];
		}
	}
	//for(int i=0;i<=n;++i){
	//	for(int j=0;j<=mxl;++j) cout<<dp[i][j]<<" ";
	//	cout<<"\n";
	//}
	return dp[n][mxl]; // all items considered
}
int knp2(int wei[],int val[],int n,int mxl,bool inc[]){
	int dp[n+1][mxl+1]; 
	for(int i=0;i<=n;++i) for(int j=0;j<=mxl;++j){
		if(i==0 || j==0) dp[i][j]=0;
		else if(wei[i-1]<=j) {
			dp[i][j] = max(val[i-1]+dp[i-1][j-wei[i-1]],dp[i-1][j]);
		}
		else {
			dp[i][j]=dp[i-1][j];
		}
	}
	// if it comes form top -> not include else include
	// for minimum we if include == not include then not include;
	int ans=dp[n][mxl];
	int curr_w=mxl;
	for(int i=n;i>0;--i){
		if(ans<=0) break; // no solution
		if(ans==dp[i-1][curr_w]) continue; // not include
		else{
			// include
			inc[i-1]=1;
			ans-=val[i-1]; curr_w-=wei[i-1];
		}
	}
	return dp[n][mxl]; 
}
vector<int> prime;
void seive(){
	int arr[200005]={0};
	for(int i=2;i<200005;++i){
		if(arr[i]==0){
			prime.push_back(i);
			for(int j=2*i;j<200005;j+=i)
				arr[j]=1;
		}
	}
}
int fx(int n){
	for(auto it : prime){
		if(n%it==0) return it;
	}
	return n;
}
int lcm(int a,int b){
	a/=__gcd(a,b);
	return a*b;
}
void solve(){
	int n,k; cin>>n>>k;
	int a[n],b[n];
	for(int i=0;i<n;++i) cin>>a[i];
	for(int i=0;i<n;++i) cin>>b[i];
	sort(a,a+n);
	sort(b,b+n);
	int i=0,j=n-1;
	while(i<n && a[i]<b[j]){
		a[i]=b[j];
		++i; --j;
	}
	int s=0;
	for(int i=0;i<n;++i) s+=a[i];
	cout<<s<<"\n";
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	map<int,string> mp;
	mp[0]="pon";
	mp[1]="pon";
	mp[2]="hon";
	mp[3]="bon";
	mp[4]="hon";
	mp[5]="hon";
	mp[6]="pon";
	mp[7]="hon";
	mp[8]="pon";
	mp[9]="hon";
	int n; cin>>n;
	cout<<mp[n%10]<<"\n";
	return 0;
}



Measured memory_bytes: 3664
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <map>

using namespace std;

#define unomap unordered_map
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itr iterator
#define rtr reverse_iterator

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

typedef set<int> si;
typedef set<pi> spi;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;

typedef vector<vb> vmb;
typedef vector<vi> vmi;
typedef vector<si> vsi;
typedef vector<vpi> vmpi;
typedef vector<spi> vspi;

inline int readInt()       {char c;while(c=getchar(),c<'0'||c>'9');bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),!(c<'0'||c>'9'))n=10*n+c-'0';return(sign)?-n:n;}
inline int readLong()      {char c;while(c=getchar(),c<'0'||c>'9');bool sign=(c=='-');if(sign)c=getchar();ll  n=c-'0';while(c=getchar(),!(c<'0'||c>'9'))n=10*n+c-'0';return(sign)?-n:n;}
inline void getInt(int& n) {char c;while(c=getchar(),c<'0'||c>'9');bool sign=(c=='-');if(sign)c=getchar();    n=c-'0';while(c=getchar(),!(c<'0'||c>'9'))n=n*10+(c-'0');   if(sign)n=-n;}
inline void getLong(ll& n) {char c;while(c=getchar(),c<'0'||c>'9');bool sign=(c=='-');if(sign)c=getchar();    n=c-'0';while(c=getchar(),!(c<'0'||c>'9'))n=n*10+(c-'0');   if(sign)n=-n;}

int query()
{



    return 0;
}

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

    vi a(n);
    for (int &x : a) x = readInt();

    vi dp(n, 0);
    dp[0] = 0;
    for (int i = 1; i < n; ++i)
    {
        dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
        for (int j = 2; j <= k; ++j)
            if (i - j >= 0)
                dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
    }

    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;

const int MAX_L = 500;

char buf[MAX_L + 1];
int stat[0x100];

bool init(){
	scanf("%[^\n]%*c", buf);
	return strcmp(buf, "#");
}

bool solve(){
	const int L = strlen(buf);
	char cs[3];
	for(int i=0, k=0; i<L; i++){
		if(buf[i] == '('){
			memset(stat, 0, sizeof(stat));
			k = 0;
		}
		else if(buf[i] == '~'){
			char ch = buf[++i];
			cs[k++] = ch;
			stat[ch] |= 2;
		}
		else if(isalpha(buf[i])){
			char ch = buf[i];
			cs[k++] = ch;
			stat[ch] |= 1;
		}
		else if(buf[i] == ')'){
			if(stat[cs[0]] != 3 && stat[cs[1]] != 3 && stat[cs[2]] != 3){
				return true;
			}
		}
	}

	return false;
}

int main(){
	while(init()){
		puts(solve() ? "yes" : "no");
	}

	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>

using namespace std;

int main() {

   int A,B,C;

   cin>>A>>B>>C;

   int D;

   D= C / A * B ;

   cout<<D;

}

Measured memory_bytes: 256
st=input()
def iskaibun(s):
  if(s==""):
      return 1;
  else:
      if(s[0]==s[-1]):
          return iskaibun(s[1:-1])
      else:
          return 0

l = len(st)
q = (l-1)//2
st1 = st[0:q]
st2 = st[q+1:]

if(st1 == st2[::-1] and iskaibun(st1)==1 and iskaibun(st2)==1):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll( Console.ReadLine().Split(' '), int.Parse);
            int sum = 0;
            int prev = -1;
            for(int i = 0; i < a.Length; ++i)
            {
                if (a[i] == prev)
                {
                    sum++;
                    prev = -1;
                }
                else
                {
                    prev = a[i];
                }
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=805;
int h,w,k;
char grid[N][N];
int v[N][N];

int foo(int x,int y) {
    int res=INF;
    res=min(res,x);
    res=min(res,h-1-x);
    res=min(res,y);
    res=min(res,w-1-y);
    return (res+k-1)/k;
}

int ans=INF;

struct node {
    int x,y;
};

int d[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

void bfs(int x,int y) {
    queue<node> q;
    q.push({x,y});
    memset(v,INF,sizeof(v));
    v[x][y]=0;
    ans=min(ans,foo(x,y));
    while (!q.empty()) {
        node cur=q.front();
        q.pop();
        for (int i=0;i<4;i++) {
            int xx=cur.x+d[i][0];
            int yy=cur.y+d[i][1];
            if (xx>=0&&xx<h&&yy>=0&&yy<w&&v[xx][yy]==INF&&grid[xx][yy]!='#') {
                ans=min(ans,foo(xx,yy));
                v[xx][yy]=v[cur.x][cur.y]+1;
                if (v[xx][yy]<k) q.push({xx,yy});
            }
        }
    }
}

int main() {
    scanf("%d%d%d",&h,&w,&k);
    for (int i=0;i<h;i++) {
        scanf("%s",grid[i]);
    }
    int sx,sy;
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            if (grid[i][j]=='S') {
                sx=i;
                sy=j;
            }
        }
    }
    bfs(sx,sy);
    printf("%d\n",ans+1);
}


Measured memory_bytes: 3456