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

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int t;
		int n;
		
		for(int i=1; i<=4; i++){
			t = scan.nextInt();
			n = scan.nextInt();
			
			if(t==1){
				System.out.println(6000*n);
			}else if(t==2){
				System.out.println(4000*n);
			}else if(t==3){
				System.out.println(3000*n);
			}else if(t==4){
				System.out.println(2000*n);
			}
		}
	}
}

Measured memory_bytes: 17360
n=int(input())
s=input()
m=10**9+7
l=1
for i in range(1,n+1):l=(l*i)%m
t=[0]*(2*n)
t[0]=1
for i in range(1,2*n):
    if s[i-1]==s[i]:
        t[i]=1-t[i-1]
    else:
        t[i]=t[i-1]
if t.count(1)==n and s[0]==s[-1]=="B":
    p=1
    c=0
    for i in t:
        c+=i
        if i==0:
            p=(p*c)%m
            c-=1
    print((p*l)%m)
else:
    print(0)

Measured memory_bytes: 4968
if __name__ == "__main__":
    a, b, c = map(int, input().split())
    if a == 5 and b == 5 and c == 7 or \
            a == 5 and c == 5 and b == 7 or \
            b == 5 and c == 5 and a == 7:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 2940
n,m = map(int,input().split())
a_list=[list(map(int,input().split())) for _ in range(m)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n # 各要素の親要素の番号を格納するリストparents 
                                # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する
    def find(self, x): # 要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y): # 要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    # 以下、便宜的に使えるメソッド。省略しても問題ない
    def size(self, x): # 要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]
    def same(self, x, y): # 要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)
    def members(self, x): # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self): # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self): # グループの数を返す
        return len(self.roots())
    def all_group_members(self): # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}
    def __str__(self): # print()での表示用 ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(n+1)

for i in range(m):
    uf.union(a_list[i][0], a_list[i][1])

max =0
for i in range(n+1):
    if max < uf.size(i):
        max = uf.size(i)
print(max)

Measured memory_bytes: 47184
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(void) {
    string s;
    int k;
    cin >> s >> k;

    int i = 0;
    while (s[i] == '1' and i < k-1) i++;
    cout << s[i] << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<set>

using namespace std;
int main(void){
    int N;
    cin>>N;
    int d[N];
    int E[110]={};
    
    
    for(int i=0;i<N;i++){
        cin>>d[i];
        E[d[i]]=E[d[i]]+1;
    
    }
    
    
   int T;
   T=0;
   for(int i=0;i<110;i++){
       if(E[i]>0){
           T=T+1;
       }
        
    }
   
   
    
     
    cout<<T<<endl;
    
    return 0;
    
}

Measured memory_bytes: 256
def main():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n-1):
        if a[i] >= a[i+1]:
            break
    else:
        print(1)
        return

    h = []
    heapq.heapify(h)
    kind = 1
    length = 0
    d = dict()
    for i in a:
        if length >= i:
            while h:
                hh = -heapq.heappop(h)
                if hh > i:
                    d.pop(hh)
                else:
                    heapq.heappush(h, -hh)
                    break
            for j in range(i, 0, -1):
                if j not in d:
                    d[j] = 2
                    heapq.heappush(h, -j)
                    kind = max(kind, 2)
                    while h:
                        hh = -heapq.heappop(h)
                        if hh > j:
                            d.pop(hh)
                        else:
                            heapq.heappush(h, -hh)
                            break
                    break
                else:
                    if d[j] < kind:
                        d[j] += 1
                        while h:
                            hh = -heapq.heappop(h)
                            if hh > j:
                                d.pop(hh)
                            else:
                                heapq.heappush(h, -hh)
                                break
                        break
            else:
                d[i] += 1
                kind += 1
        length = i

    def value(kind):
        length = 0
        d = dict()
        for i in a:
            if length >= i:
                del_list = []
                for j in d:
                    if j > i:
                        del_list.append(j)
                for j in del_list:
                    d.pop(j)
                for j in range(i, 0, -1):
                    if j not in d:
                        d[j] = 2
                        break
                    else:
                        if d[j] < kind:
                            d[j] += 1
                            break
                        else:
                            d.pop(j)
                else:
                    return False
            length = i
        return True

    def b_search(ok, ng, value):
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if value(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(b_search(kind, max(1, kind-30), value))


main()


Measured memory_bytes: 115792
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll sum=0;
void f(ll x,ll len)
{
	ll po=pow(10l,len-1);
	for(ll i=1;i<len;++i)
	{
		ll tem=x;
		//cout<<x/po<<" "<<x%po<<endl;
		sum+=x/po*pow(2,len-i-1);
		sum+=x%po;
		f(x%po,len-i);
		po/=10;
	}
}
int main()
{
	ll s;
	cin>>s;
	ll len=0;
	ll tem=s;
	sum=s;
	while(tem)
	{
		++len;
		tem/=10;
	}
	f(s,len);
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define itn int
#define gI gi

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int n, m, x, y, z, a[303];

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; i+=1) cin >> a[i];
	bool fl = true;
	for (int i = 1; i <= n; i+=1) if (a[i] % 2 == 0)
	{
		if (a[i] % 3 != 0 && a[i] % 5 != 0) fl = false;
	}
	if (fl) puts("APPROVED");
	else puts("DENIED");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////
struct graph{
    vi v;
};

void bfs(graph G[],int start,vl & d){
    queue<int> q;
    q.push(start);
    d[start] = 0;
   
    while(!q.empty()){
        int from = q.front();
        q.pop();
        for(int i=0;i<G[from].v.size();i++){
            int to = G[from].v[i];
          //  cout << from << "  " << to << "\n";
            if(d[to] == inf){
                d[to] = d[from]+1;
                q.push(to);
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,p;    cin>>n>>p;
    string str;    cin>>str;
    ll ans = 0;
    if(p==2 || p==5){
        for(int i =0;i<n;++i){
            if((str[i]-'0')%p == 0){
                ans += (i+1);
            }
        }
        cout << ans;
        return 0;
    }
    ll digit = 0,power = 1;  // upto that index value mod .. from back
    vl mo(p,0);
    for(int i = n-1;i>=0;--i){
        digit = digit + (str[i] - '0')*power;
        digit %= p;
        ans += mo[digit];
        ++mo[digit];
        if(digit==0){
            ++ans;
        }
        power = (power * 10)%p;
    }
    cout << ans ;
   
    return 0;
}
    


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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        int x,a; cin>>x>>a;
        cout<<(x<a?0:10)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		int c1 = a + b;
		int c2 = a - b;
		int c3 = a * b;

		int c=Math.max(c1, c2);
		int d=Math.max(c, c3);
		
		System.out.println(d);
		sc.close();
	}
}

Measured memory_bytes: 27044
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))


def main():
    n, m, p = map(int, input().split())

    nodes = []
    for _ in range(m):
        a, b, c = map(int, input().split())
        nodes.append((a - 1, b - 1, -(c - p)))
    
    d = [float("inf") for _ in range(n)]
    pre = [-1 for _ in range(n)]
    d[0] = 0
    for _ in range(n):
        for nod in nodes:
            if d[nod[1]] > d[nod[0]] + nod[2]:
                d[nod[1]] = d[nod[0]] + nod[2]
                pre[nod[1]] = nod[0]

    for i, nod in enumerate(nodes):
        if d[nod[1]] > d[nod[0]] + nod[2]:
            nodes[i] = (nod[0], nod[1], -float('inf'))
    
    d = [float("inf") for _ in range(n)]
    pre = [-1 for _ in range(n)]
    d[0] = 0
    for _ in range(n):
        for nod in nodes:
            if d[nod[1]] > d[nod[0]] + nod[2]:
                d[nod[1]] = d[nod[0]] + nod[2]
                pre[nod[1]] = nod[0]

    path = set()
    fr = n - 1
    while pre[fr] != -1:
        if fr in path:
            break
        path.add(pre[fr])
        fr = pre[fr]

    for nod in nodes:
        if d[nod[1]] > d[nod[0]] + nod[2]:
            if nod[0] in path:
                print(-1)
                return

    if d[n - 1] == -float('inf'):
        print(-1)
        return 

    if d[n - 1] > 0:
        print(0)
    else:
        print(-d[n - 1])
    

if __name__ == '__main__':
    main()


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

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

    if (a == b && c == b && a % 2 == 0) {
        std::cout << -1 << std::endl;
        return 0;
    }

    int count = 0;
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
        count++;
        int next_a = b / 2 + c / 2;
        int next_b = c / 2 + a / 2;
        int next_c = a / 2 + b / 2;

        a = next_a;
        b = next_b;
        c = next_c;
    }
    std::cout << count << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
	char a[11];
	int i=0;
	while((a[i]=getchar())!='\n')
	{
		if(a[i]=='B'&&i>=1)
		i=i-2;
		i++;
	}
	for(int j=0;j<i;j++)
	if(a[j]!='B')
	cout<<a[j];
	return 0;
}

Measured memory_bytes: 256
n = input().split()
a = int(n[0])
b = int(n[1])
c = int(n[2])
if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
else:
    print(c, b, a)

Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
    int N;
    cin >> N;
  vector<int> a(N);
  int ans = 0;
  rep(i,N) cin >> a[i];
  sort(a.begin(),a.end());
  rep(i,N-1) ans +=a[i];
  if(ans <= a[N-1]) puts("No");
  else puts("Yes");
  
}



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

typedef long long LL;
typedef unsigned long long ULL;

#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
	LL res = 0, bo = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if (ch == '-') bo = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') { res = (res << 1) + (res << 3) + ch - '0'; ch = getchar(); }
	return bo * res;
}

template<typename T> void read(T &x) { x = read(); }
template<typename T, typename ...Argv> void read(T &a, Argv &...argv) { read(a); read(argv...); }

const int N = 4e5 + 10;
int tr[N], a[N], n;
LL a1, a2, a3;

void Modify(int x, int y) {
	for (; x <= n; x += x & -x) tr[x] += y;
}

int ask(int x) {
	int res = 0;
	for (; x; x -= x & -x) res += tr[x];
	return res;
}

int main() {
	n = read();
	for (int i = 1; i <= n; ++ i) {
		a[i] = read();
		if ((a[i] & 1) != (i & 1)) return puts("No"), 0;
		a1 += ask(n) - ask(a[i]);
		Modify(a[i], 1);
	}
	if (a1 % 3) return puts("No"), 0;
	memset(tr, 0, sizeof(tr));
	for (int i = 1; i <= n; i += 2) {
		a2 += ask(n) - ask(a[i]);
		Modify(a[i], 1);
	}
	memset(tr, 0, sizeof(tr));
	for (int i = 2; i <= n; i += 2) {
		a3 += ask(n) - ask(a[i]);
		Modify(a[i], 1);
	}
	if ((a2 + a3) * 3 != a1) return puts("No"), 0;
	puts("Yes");
	return 0;
}

Measured memory_bytes: 3072
import std.stdio, std.string, std.array, std.conv;

struct S {
    string name;
    int time;
}

struct T {
private:
    int n;
    S[] s;

public:
    this(int n) {
        this.s = new S[](n);
    }

    ulong length() {
        return s.length;
    }

    S front() {
        return s[0];
    }

    void pop() {
        s = s[1..$];
    }

    void push(S x) {
        s ~= x;
    }
}

void main() {
    int[] tmp = readln.chomp.split.to!(int[]);
    int n = tmp[0], q = tmp[1];
    T t = T(n);
    foreach (i; 0 .. n) {
        string[] process = readln.chomp.split;
        t.tupleof[1][i] = S(process[0], process[1].to!int);
    }
    int elaps = 0;
    while (t.length) {
        S s = t.front;
        t.pop;
        if (s.time > q) {
            elaps += q;
            t.push(S(s.name, s.time-q));
        } else {
            elaps += s.time;
            writeln(s.name, " ", elaps);
        }
    }
}


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



int main(){

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

  
  long long ans = b[0];

  for(int i = 1; i < n-1; i++){
  ans += min(b[i-1],b[i]);
  }

  ans += b[n-2];

  cout << ans << endl;



  return 0;



}

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

const int INF = 2e9;

int main(){
    ll x;
    cin >> x;
    ll t = x/11;
    ll s = x%11;
    t *= 2;
    if(0 < s && s < 7) t += 1;
    if(6 < s && s < 11) t += 2;
    cout << t << endl;
}

Measured memory_bytes: 3548
S = input()
MOD = 10**9+7
N = 13
mul = 1

#dp[k] -> 13で割ったあまりがkのパターン数
dp = [0] * N
dp[0] = 1

#後ろから解くアルゴリズム
# 1?2?3 : 0 -> 3 -> ?3 -> 2?3 -> ...
for i in range(len(S)-1, -1, -1):
    #次の状態
    next_dp = [0] * N
    c = S[i]

    if c == "?":
        for k in range(10):
            for j in range(N):
                next_dp[(k * mul + j) % N] += dp[j]
                next_dp[(k * mul + j) % N] %= MOD

    else:
        k = int(S[i])
        for j in range(N):
            next_dp[(k * mul + j) % N] += dp[j]
            next_dp[(k * mul + j) % N] %= MOD

    mul *= 10
    mul %= N
    dp = next_dp

print(dp[5])


Measured memory_bytes: 74332
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int i;
  int k;
  int j;
  for(i=1;i<=n;i++)
  {
      for(k=i;k/10>=10;)
      {
        k=k/10;
      }
        if(i%3==0 || k%10==3 || i%10==3|| i/100==3 ||i/1000==3 || i/10%10==3 || i/10==3){
      cout<<" "<<i;
    }
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define double long double
#define pb push_back
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define diff(a,b) (a>b?a-b:b-a)
const int N=1e6+5;
int32_t main()
{
    IOS;
    int n,k;
    cin >> n >> k;
    int a[n];
    int dp[n];
    for(int i = 0;i < n; i++){
        cin >> a[i];
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
    for(int i = 1;i < n; i++){
        for(int j = i-1;j >= max(i-k,0); j--)
            dp[i] = min(abs(a[i]-a[j])+dp[j],dp[i]);
    }
    cout << dp[n-1] << "\n";
    return 0;
}


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

using namespace std;
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int n, c = 0; cin >> n;

    for(int i=1, a; i<=n; i++){
        int div = 0;
        for(a=1; a<=i; a++)
            if(i%a==0) div++;
        if(div == 8 && i&1) c++;
    }
    cout << c;

    return 0;
}


Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

h,w,k = inp
ans  = 1e20
s = []
h.times{s<<gets.chomp.split("").map(&:to_i)}
(0...(2**(h-1))).each do |bi|
  wc = [0] * h

  c = 0
  f = false
  is_break = false
  is_continue = false
  (0...w).each do |wi|
    wdi = 0
    (0...h).each do |hi|
      if(s[hi][wi] == 1)
        wc[wdi] += 1
        if(wc[wdi] > k)
          unless(f)

            is_break = true
            break
          else
            wc = [0] * h
            c += 1
            f = false
            is_continue = true
            break
          end
        end
      end
      if(bi[hi] == 1)
        wdi += 1
      end
    end
#    p wc
    if(is_continue)
      wdi = 0
      is_continue = false
      (0...h).each do |hi|
        if(s[hi][wi] == 1)
          wc[wdi] += 1
          if(wc[wdi] > k)
            unless(f)
              is_break = true
              break
            else
              wc = [0] * h
              c += 1
              break
            end
          end
        end
        if(bi[hi] == 1)
          wdi += 1
        end
      end
      f = true
      next
    end
    if(is_break)
      break
    end
    f = true
  end
  ans = small(ans,bi.to_s(2).count("1")+c) unless is_break
  bi.to_s(2)
end
p ans


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

constexpr long double MAX = 1e18;

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

	vector<long double> a(n);
	for (long double& ai : a) {
		cin >> ai;
	}

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

	long double p = 1ULL;
	bool ok = true;
	for (int i = 0; i < n; ++i) {
		p *= a[i];
		if (p > MAX) {
			p = -1;
			break;
		}
	}

	if (p == -1) {
		cout << p;
	} else {
		cout << (unsigned long long)p;
	}

	return 0;
}
	

Measured memory_bytes: 4844
#include<iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <iomanip>
#include <queue>

#define PI 3.14159265358979
#define MOD 1000000007

//fixed << setprecision(15) <<

using namespace std;

int main(void) {
	double a, b, l, m, n;
	int x[10][10];
	int y[10];
	int i, j, k;
	bool flag = true;
	vector <long long int> e;
	cin >> n >> m >> l;
	a = n / l;
	if(a <= m)cout << "Yes" << endl;
		else cout << "No" << endl;
	return 0;
}

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

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var m = int.Parse(spl[1]);
        var q = int.Parse(spl[2]);

        var AA = new List<int[]>();
        for (int i = 0; i < q; i++) {
            var ary = ToIntArray(input.ReadLine(), 4);
            AA.Add(ary);
        }

        Func<int[], long> count = (A) => {
            long sum = 0;
            foreach (var aa in AA) {
                var ai = aa[0] - 1;
                var bi = aa[1] - 1;
                var ci = aa[2];
                var di = (long)aa[3];
                sum += (A[bi] - A[ai] == ci ? di : 0);
            }
            return sum;
        };


        int[] tmp = new int[n];
        for (int i = 0; i < tmp.Length; i++) tmp[i] = 1;

        long max = 0;
        bool end = false;

        while (!end) {
            //print(tmp);
            var sum = count(tmp);
            max = Math.Max(max, sum);

            int idx = n - 1;
            while (idx >= 0 && tmp[idx] == m) {
                idx--;
            }
            if (idx < 0) {
                break;
            } else {
                tmp[idx]++;
                for (int j = idx + 1; j < n; j++)
                    tmp[j] = tmp[idx];
            }
        }

        return max;
    }

    static void print(int[] A) {
        var buil = new StringBuilder();
        foreach (var i in A) {
            buil.Append(i);
            buil.Append(',');
        }
        Debug.WriteLine(buil.ToString());
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 27768
n=int(input())
P1=input().split()
P2=[]
for i in range(n):
    P2.append(int(P1[i]))

c=0
for i in range(n-2):
    if max(P2[i:i+3])!=P2[i+1] and min(P2[i:i+3])!=P2[i+1]:
        c+=1

print(c)


Measured memory_bytes: 3064
k = int(input())
ans = [1,2,3,4,5,6,7,8,9]
now = 0
for i in ans:
  if now == 100000:
    break
  x = int(str(i)[-1])
  for j in range(max(0,x-1),min(x+2,10)):
    mini_ans = i * 10 + j
    ans.append(mini_ans)
    now += 1
print(ans[k-1])

Measured memory_bytes: 7316
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;

void main() {
    ulong[] nt = readln.split.to!(ulong[]);
    ulong[][] ct;

    foreach(_; 0..nt[0]) {
        ulong[] i = readln.chomp.split.to!(ulong[]);
        ct ~= i;
    }
    ct.sort!("a[0] < b[0]");
    foreach(c; ct) {
        if (c[1] <= nt[1]) {
            c[0].writeln;
            return;
        }
    }
    "TLE".writeln;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>

class Tree
{
public:
	Tree(const int nodeNum)
	{
		nodes = new Node[nodeNum];
		for (int i = 0; i < nodeNum; i++)
		{
			nodes[i].parent = NIL;
			nodes[i].rightSibling = NIL;
			nodes[i].leftChild = NIL;
		}
	}
	~Tree()
	{
		delete nodes;
	}
	int GetParent(int nodeNum)const { return nodes[nodeNum].parent; }
	void SetParent(int nodeNum,int parent) { nodes[nodeNum].parent = parent; }
	void SetLeftChild(const int nodeNum, const int leftChild) { nodes[nodeNum].leftChild = leftChild; }
	void SetRightSibling(const int nodeNum, const int rightSibling) { nodes[nodeNum].rightSibling = rightSibling; }
	int GetDepth(int nodeNum);
	std::string GetType(int nodeNum);
	std::string GetChildren(const int nodeNum);
private:
	struct Node
	{
		int parent, leftChild, rightSibling;
	};
	Node* nodes;
public:
	 const static int NIL = -1;
};

int Tree::GetDepth(int nodeNum)
{
	int depth=0;
	while (nodes[nodeNum].parent != NIL)
	{
		nodeNum = nodes[nodeNum].parent;
		depth++;
	}
	return depth;
}

std::string Tree::GetType(int nodeNum)
{
	std::string type;
	if (nodes[nodeNum].parent == NIL)
	{
		type = "root";
	}
	else if (nodes[nodeNum].leftChild == NIL)
	{
		type = "leaf";
	}
	else if (nodes[nodeNum].parent != NIL && nodes[nodeNum].leftChild != NIL)
	{
		type = "internal node";
	}
	return type;
}

std::string Tree::GetChildren(const int nodeNum)
{
	int child = nodes[nodeNum].leftChild;
	std::string output = "[";
	while (child != NIL)
	{
		output += std::to_string(child) + ", ";
		child = nodes[child].rightSibling;
	}
	if (output[output.size() - 1] == ' ')
	{
		for (int i = 0; i < 2; i++)output.pop_back();
	}
	output += "]";
	return output;
}

int main(void)
{
	int nodeSum;
	std::cin >> nodeSum;
	Tree tree(nodeSum);

	for (int i = 0; i < nodeSum; i++)
	{
		int nodeNum, degree;
		std::cin >> nodeNum >> degree;
		int buff = 0;
		if (degree != 0)
		{
			for (int j = 0; j < degree; j++)
			{
				int child;
				std::cin >> child;
				tree.SetParent(child, nodeNum);
				if (j != 0)
				{
					tree.SetRightSibling(buff, child);
					if (j == degree - 1)
					{
						tree.SetRightSibling(child, Tree::NIL);
						break;
					}
				}
				else
				{
					tree.SetLeftChild(nodeNum,child);
				}
				buff = child;
			}
		}
	}
	for (int i = 0; i < nodeSum; i++)
	{
		int node = i;
		int parent = tree.GetParent(node);
		int depth = tree.GetDepth(node);
		std::string type = tree.GetType(node);
		std::string children = tree.GetChildren(node);
		std::cout << "node " << node << ": " << "parent = " << parent << ", " << "depth = " << depth << ", " << type + ", " << children << std::endl;
	}

	return 0;
}


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

using namespace std;

typedef long long int lli;

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

    int n;
    string s;

    cin >> n >> s;

    cout << ((n < 3200) ? "red" : s) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];

		String str[] = br.readLine().split(" ");

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			if (a[i] == i + 1) {
				int temp = a[i];
				a[i] = a[i + 1];
				a[i + 1] = temp;
				ans++;
			}
		}

		if (a[n - 1] == n) {
			ans++;
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 45380
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){ 
  // 入力
  int n;
  cin >> n;
  vector<int> xvec(n);
  vector<int> yvec(n);
  int x = 0;
  int y = 0;
  
  for(int i = 0; i < n; i++){
    cin >> x;
    xvec.at(i) = x;
  }
  for(int i = 0; i < n; i++){
    cin >> y;
    yvec.at(i) = y;
  }
  
  // 計算
  double p1, p2, p3, p4;
  for(int i = 0; i < n; i++){
    p1 += fabs(xvec.at(i) - yvec.at(i));
    p2 += (xvec.at(i) - yvec.at(i))*(xvec.at(i) - yvec.at(i));
    p3 += fabs((xvec.at(i) - yvec.at(i))*(xvec.at(i) - yvec.at(i))*(xvec.at(i) - yvec.at(i)));
    p4 = (p4 < fabs(xvec.at(i) - yvec.at(i))?fabs(xvec.at(i) - yvec.at(i)):p4);
  }
  p2 = sqrt(p2);
  p3 = cbrt(p3);
  
  printf("%lf\n",p1);
  printf("%lf\n",p2);
  printf("%lf\n",p3);
  printf("%lf\n",p4);

  return 0;
}  



Measured memory_bytes: 3352
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long 
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    SYNC
    ll a,b,c,k,sum=0;
    in(a)>>b>>c>>k;
    if(k==a+b+c)
    {
        sum+=(a-c);
    }
    else if(k<=a+b && k>=a)
    {
        sum+=a;
    }
    else if(k>a+b)
    {
        sum+=a;
        k-=(a+b);
        sum-=k;
    }
    else if(k<a)
    {
        sum+=k;
    }
    o(sum);
    
}








Measured memory_bytes: 3620
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision; 
using namespace std;
int128_t solve(unsigned long long int arr[],long long int n){
   int128_t MOD=1000000000000000000 ; 
     int128_t ans = 1 ; 
     for(int i=0 ;i<n ;i++){
         ans=(int128_t) ans*arr[i] ; 
       if(ans%MOD!=ans && ans!=MOD){
         return -1 ; 
       }
     }
  return ans;    
 }
int main() {
	int t=1;
	while(t--)
	{ 
      long long int n; cin>>n ; 
      unsigned long long int arr[n] ;
      for(int i=0 ; i<n ; i++){
        cin>>arr[i] ;
        if(arr[i]==0){
            cout<<"0"<<"\n" ;return 0 ; 
        } 
      }
	  cout<<solve(arr,n)<<"\n" ; 
	}
	return 0;
}

Measured memory_bytes: 4380
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,N,a[500010],b[500010],ans;
void upd(int x,int y){
	if (a[y]>a[x]){
		b[x]=a[x];
		a[x]=a[y];
	}
	else if (a[y]>b[x])
		b[x]=a[y];
	if (b[y]>b[x])
		b[x]=b[y];
}
int main(){
	cin>>n;
	N=1<<n;
	FOR(i,0,N-1) getint(a[i]),b[i]=0;
		FOR(j,0,n-1)
	FOR(i,0,N-1){
			if ( !((i>>j)&1) ) upd(i|(1<<j),i);
	}
	FOR(i,0,N-1){
		if (b[i]>0) ans=max(ans,a[i]+b[i]);
		if (i) printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 5120
let
    h, w = Int[parse(Int, x) for x in split(readline())]
    s = Array(Char, w, h)
    for i = 1:h
        s[:,i] = Vector{Char}(strip(readline()))
    end

    s1 = deepcopy(s)
    s2 = deepcopy(s)
    for y = 1:h
        for x = 1:w
            if x == 1 || x < w && y % 2 == 0
                s1[x,y] = '#'
            end
            if x == w || 1 < x && y % 2 == 1
                s2[x,y] = '#'
            end
        end
    end
    for y = 1:h
        println(ASCIIString(vec(s1[:,y])))
    end
    println()
    for y = 1:h
        println(ASCIIString(vec(s2[:,y])))
    end
end


Measured memory_bytes: 77744
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <unordered_map>
#define fi first
#define se second
#define iis std::ios::sync_with_stdio(false)
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;
const int MXN = 1e6 + 5;
const int MXT = 2e7 + 6;
const uLL base = 99959;

unordered_map<uLL, int> mp;
int n, m, tn;
int head[MXN], tot;
struct lp {
    int v, c, nex;
}cw[MXT];
int dis[MXT], vis[MXT], fa[MXN];
void add_edge(int u,int v,int w) {
    cw[++tot].v = v;cw[tot].c = w;cw[tot].nex = head[u];
    head[u] = tot;
    cw[++tot].v = u;cw[tot].c = w;cw[tot].nex = head[v];
    head[v] = tot;
}
void dij() {
    priority_queue<pii,vector<pii>,greater<pii> >Q;
    for(int i = 1; i <= n; ++i) dis[i] = INF, vis[i] = 0;
    dis[1] = 0;
    Q.push({dis[1], 1});
    while(!Q.empty()) {
        pii now = Q.top();Q.pop();
        int u = now.se;
        if(vis[u]) continue;
        vis[u] = 1;
        for(int i = head[u]; ~i; i = cw[i].nex) {
            int v = cw[i].v;
            //if(vis[v]) continue;
            if(dis[v] > dis[u] + cw[i].c) {
                dis[v] = dis[u] + cw[i].c;
                Q.push({dis[v], v});
            }
        }
    }
    int ans = dis[tn];
    while(!Q.empty()) Q.pop();
    if(ans == INF) ans = -2;
    printf("%d\n", ans/2);
}
int Fi(int x) {
    return fa[x] == x? x: fa[x] = Fi(fa[x]);
}
int get(int x, int y) {
    uLL tmp = x;
    tmp = tmp * base * base + y * base + x ^ y;
    if(mp[tmp]) return mp[tmp];
    mp[tmp] = ++n;
    return n;
}
int main(int argc, char const *argv[]) {
    while(~scanf("%d%d", &n, &m)) {
        memset(head, -1, sizeof(head));
        tot = -1;
        mp.clear();
        tn = n;
        for(int i = 1; i <= n; ++i) fa[i] = i;
        for(int i = 0, u, v, c, pa, pb, uc, vc; i < m; ++i) {
            scanf("%d%d%d", &u, &v, &c);
            pa = Fi(u), pb = Fi(v);
            fa[pa] = pb;
            uc = get(u, c); vc = get(v, c);
            add_edge(u,uc,1);add_edge(uc,vc,0);add_edge(vc,v,1);
            add_edge(v,vc,1);add_edge(vc,uc,0);add_edge(uc,u,1);
        }
        if(Fi(tn) != Fi(1)){
            printf("-1\n");
            continue;
        }
        dij();
    }
    return 0;
}

Measured memory_bytes: 61940
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;


namespace abc94_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();
            int[] redPoint = ReadLine().Split().Select(int.Parse).ToArray();
            int ahead=0;
            int back=0;

            foreach(var p in redPoint)
            {
                if(input[2] > p) back++;
                if(input[2] < p) ahead++;
            }
            WriteLine(Min(ahead, back));
        }
    }
}

Measured memory_bytes: 13268
import math
import collections
N = int(input())
mod = 10 ** 9 + 7

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = collections.Counter(prime_factorize(math.factorial(N)))
prime_factors = list(c.values())
answer = 1

for i in range(len(prime_factors)):
    answer *= (prime_factors[i] + 1)

print(answer % mod)


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

using namespace std;

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

  string s;
  cin >> s;

  int count[26] = {0};

  for (char c: s) count[c - 'a']++;

  for (int x: count) {
    if (x & 1) {
      cout << "No" << "\n";
      return 0;
    }
  }
  cout << "Yes" << "\n";
}


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(10)





void solve() {

	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a * n, b);
	
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	solve();

	return 0;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    long long K;
    cin >> K;
    long long a;
    vector<long long> A(N+1);
    vector<long long> B(M+1);
    A[0] = 0;
    B[0] = 0;
    for (int i = 1; i < N+1; i++) {
        cin >> a;
        A[i] = A[i-1] + a;
    }
    for (int i = 1; i < M+1; i++) {
        cin >> a;
        B[i] = B[i-1] + a;
    }
    int ans = 0;
    int J = M;
    for (int i = 0; i < N+1; i++) {
        if (A[i] > K) break;
        auto it = upper_bound(B.begin(), B.end(), K-A[i]);
        int j = it - B.begin();
        ans = max(ans, i+j-1);
    }
    cout << ans << endl;
}




Measured memory_bytes: 6436
#include<stdio.h>
#include<stdlib.h>
int main(){
    int N;
    scanf("%d", &N);
    int *H = malloc( N * sizeof(int));
    for(int i = 0; i < N; i++) scanf("%d", &H[i]);
    int count = 0;
    int max_count = 0;
    for(int i = 1; i < N; i++){
        if(H[i-1] < H[i]) count = 0;
        else count++;
        if(count > max_count) max_count = count;
    }
    printf("%d", max_count);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

int H, W;
int c[10][10];

bool Search(int cur, int s, int g, int cost){
   if(cur==g){
      if(c[s][g]>cost){
	 c[s][g] = cost;
	 return true;
      }else return false;
   }

   for(int i=0; i<10; ++i){
      if(i==cur) continue;
      if(c[s][g]>cost+c[cur][i]){
         Search(i,s,g,cost+c[cur][i]);
      }
   }
   return true;
}

int main(){
   std::cin >> H >> W;

   for(int i=0; i<10; ++i){
      for(int j=0; j<10; ++j)
	 std::cin >> c[i][j];
   }

   for(int i=0; i<10; ++i){
      Search(i,i,1,0);
   }

   int ans = 0;
   int A;
   for(int i=0; i<H; ++i){
      for(int j=0; j<W; ++j){
	 std::cin >> A;
	 if(A>=0) ans += c[A][1];
      }
   }
   std::cout << ans << std::endl;
   return 0;
}


Measured memory_bytes: 256
#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;
int n;
string s;

signed main(){

    cin >> n >> s;
    int m[4][n] = {0};
    m[0][0] = m[1][0] = m[1][1] = m[3][1] = 1;
    m[0][1] = m[2][0] = m[2][1] = m[3][0] = -1;

    rep(j,4){
        for(int i = 1;i < n-1;i++){
            if(s[i] == 'o'){
                if(m[j][i] == 1) m[j][i+1] = m[j][i-1];
                else m[j][i+1] = -1*m[j][i-1];
            }else{
                if(m[j][i] == 1) m[j][i+1] = -1*m[j][i-1];
                else m[j][i+1] = m[j][i-1];
            }
        }
    }
    // rep(i,4){
    //     rep(j,n){
    //         cerr << m[i][j];
    //     }
    //     cerr << endl;
    // }
    rep(j,4){
        int x;
        int y;
        if(s[n-1] == 'o'){
            if(m[j][n-1] == 1) x = m[j][n-2];
            else x = -1*m[j][n-2];
        }else{
            if(m[j][n-1] == 1) x = -1*m[j][n-2];
            else x = m[j][n-2];
        }
        if(s[0] == 'o'){
            if(m[j][0] == 1) y = m[j][1];
            else y = -1*m[j][1];
        }else{
            if(m[j][0] == 1) y = -1*m[j][1];
            else y = m[j][1];
        }
        if(x == m[j][0] && y == m[j][n-1]){
            rep(i,n){
                if(m[j][i] == 1)cout << "S";
                else cout << "W";
            }
            return 0;
        }

    }
    cout << -1 << endl;
    // rep(i,4){
    //     rep(j,n){
    //         cerr << m[i][j];
    //     }
    //     cerr << endl;
    // }
    
    
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
#define NMAX 10001000
using namespace std;
int used[NMAX] = {};
bool tmp = false;
int cnt =0;
/*
void dfs(vector<int> a,int loc){
	used[loc] = true;
	cnt++;
	if(loc == 2){
		tmp = true;
		return;
	}else if(!used[a[loc]]){
		dfs(a,a[loc]);
	}else{
		return;
	}
}
*/
int main(){
	int N;
	cin >> N;
	vector<int> a(N+1);
	rep(i,0,N){
		cin >> a[i+1];
	}
	int loc = 1;
	while(true){
		cnt++;
		if(loc == 2){ 
			tmp = true;
			break;
		}
		else if(used[loc]){
			tmp = false;
			break;
		}
		used[loc] = true;
		loc = a[loc];
	}
	if(!tmp){
		cout << "-1" << endl;
		return 0;
	}
	cout << cnt-1 << endl;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

int main(){
    int H, W, D;
    cin >> H >> W >> D;
    pair<int,int> A[H*W+1];
    rep(i, H) {
        rep(j, W){
            int tmp;
            cin >> tmp;
            A[tmp] = make_pair(i+1, j+1);
        }
    }
    int Q;
    cin >> Q;
    int C[H*W+1];
    REP(i,1, D+1) {
        int j = i;
        int res = 0;
        while(j < H*W+1) {
            C[j] = res;
            j += D;
            if (j < H*W+1) {
                res += abs(A[j].first - A[j-D].first) + abs(A[j].second - A[j-D].second);
            }
        }
    }
    rep(i, Q){
        int L, R;
        cin >> L >> R;
//        cout << C[R] << " " << C[L] << endl;
        cout << C[R] - C[L] << endl;
    }
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
} 
int a[334][334];
int memh[114514],memw[114514];
int l[114514],r[114514];
signed main(){
	ic(h) ic(w) ic(d)
	rep(0,i,h)rep(0,j,w)cin>>a[i][j];
	rep(0,i,h){
		rep(0,j,w){
			memh[a[i][j]-1]=i;
			memw[a[i][j]-1]=j;
		}	
	}	
	int sa[d][h*w/d+1];
	ic(q)
	rep(0,i,q)cin>>l[i]>>r[i];
	rep(0,i,d){
		int sum=0;
		rep(0,j,(h*w+d-i)/d){
			sa[i][j]=sum;
			sum+=abs(memh[i+j*d]-memh[i+(j+1)*d])+abs(memw[i+j*d]-memw[i+(j+1)*d]);
		}
	}	
	rep(0,i,q)c(sa[(r[i]-1)%d][(r[i]-1)/d]-sa[(l[i]-1)%d][(l[i]-1)/d])
}		


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

using namespace std;

int n;
vector<int> v;

int memo[100100];

int vai( int x ){

	if( memo[x] != -1 ){
		return memo[x];
	}

	if( x == n-1 ){
		return 0;
	}

	if( x == n-2 ){
		return abs(v[n-2]-v[n-1]);
	}

	int um =   vai(x+1) + abs(v[x]-v[x+1]);
	int dois = vai(x+2) + abs(v[x]-v[x+2]);

	return (memo[x] = min(um, dois));
}


int main(){

	memset(memo, -1, sizeof(memo));

	cin >> n;

	v = vector<int>(n);

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

	cout << vai(0) << endl;

	return 0;
}


Measured memory_bytes: 5760
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long  ←保留
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

/*signed*/int main() {
    int n, d;
    cin >> n >> d;
    int ans = (n + d * 2) / (d * 2 + 1);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
int main() {
  int k,a,b;
  scanf("%d%d%d",&k,&a,&b);
  int d;
  d=(b/k)-(a/k);
  if(d>0) {printf("OK");}
  else if(b%k==0 || a%k==0) {printf("OK");}
  else {printf("NG");}
  return 0;
  }

Measured memory_bytes: 1736
#include <stdio.h>

int main(void)
{
        int a,b,i,j,c,s[5];

        scanf("%d%d",&a,&b);

        c=0;
        for(i=a;i<=b;i++){
                s[0]=i/10000;
                s[1]=i%10000/1000;
                s[2]=i%10000%1000/100;
                s[3]=i%10000%1000%100/10;
                s[4]=i%10000%1000%100%10;
                if(s[0]==s[4] && s[1]==s[3]) c++;
        }

        printf("%d\n",c);
        return 0;
}


Measured memory_bytes: 128