akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define endl "\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

ll const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 1e9+7;

// code begins here
vector<string> tmp;

void gen(int n, int arr[], int i) { 
    if (i == n) { 
        string s;
        for(ll i=0;i<n;i++)
            s.push_back('0'+arr[i]);
        tmp.push_back(s);
        return; 
    } 
 
    arr[i] = 0; 
    gen(n, arr, i + 1); 
  
    arr[i] = 1; 
    gen(n, arr, i + 1); 
} 

int main(){
    fast;

    ll h,w,k;
    cin>>h>>w>>k;
    
    int arr[h];
    gen(h, arr, 0);
    
    vector<string> crr(tmp);
    tmp.clear();
    
    int brr[w];
    gen(w, brr, 0);
    
    vector<string> drr(tmp);
    
    ll black = 0;
    
    vector<string> in(h);
    for(ll i=0;i<h;i++)
        cin>>in[i];
    
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            if(in[i][j]=='#')
                black++;
        }
    }
    
    ll cnt = 0;
    
    ll vis[h][w];
    
    for(auto u: crr){
        for(auto v: drr){
            
            for(ll i=0;i<h;i++)
                for(ll j=0;j<w;j++)
                    vis[i][j] = 0;
                    
            ll res = 0;        
                    
            for(ll i=0;i<h;i++){
                if(u[i]=='1'){
                    for(ll j=0;j<w;j++){
                        if(in[i][j]=='#'){
                            vis[i][j] = 1;
                            res++;
                        }
                    }
                }
            }
            
            for(ll i=0;i<w;i++){
                if(v[i]=='1'){
                    for(ll j=0;j<h;j++){
                        if(!vis[j][i] && in[j][i]=='#'){
                            res++;
                            vis[j][i] = 1;
                        }
                    }
                }
            }
            
            if((black-res)==k)
                cnt++;
        }
    }
    
    cout<<cnt<<endl;
    

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    priority_queue<pair<ll, ll >> q;
    int s = 1;
    rep(i, n-1) {
        if(a[i] == a[i+1]) s+= 1;
        else {
            q.push(make_pair(a[i], s));
            s = 1;
        }
    }
    q.push(make_pair(a[n-1], s));

    ll ans = 0;
    ll a1 = 0;
    ll a2 = 0;
    while(q.size() != 0) {
        auto qt = q.top();
        q.pop();
        //cout << qt.first << " " << qt.second << endl;
        if(a1 == 0 and a2 == 0 and qt.second >= 4 ) {
            a1 = qt.first;
            a2 = qt.first;
        } else if(a1 == 0 and a2 == 0 and qt.second >= 2) {
            a1 = qt.first;
        } else if(a1 != 0 and a2 == 0 and qt.second >= 2) {
            a2 = qt.first;
        }

        if(a1 != 0 && a2 != 0) break;
    }

    ans = a1 * a2;
    cout << ans << endl;
}

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp44 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            Console.WriteLine(N * (N + 1) / 2);

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include<vector>
#include<unordered_map>
#define ll long long
const ll mx=1e5;
using namespace std;
ll mp[mx];
int main( ) {
 
     ll t,i,j,m ;
     ll k=0,n;
       ll a,b;
       ll cnt=0;
		   cin>>n>>m;
		   m*=m;
		   for(i=1;i<=n;i++)
		   {
		   	cin>>a>>b;
		   	k= (a*a)+(b*b) ;
		   	if(k<=m) cnt++;
		   }
		   cout<<cnt;
	  
	return 0;
}



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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main() {
    fast;
    ll n, m, c;
    cin >> n >> m >> c;
    vector<ll> b(m);
    ll cnt = 0;
    for (auto &i: b)
        cin >> i;
    ll a, sum = 0;;
    for (ll i = 0; i < n; i++) {
        sum = 0;
        for (ll j = 0; j < m; j++) {
            cin >> a;
            sum += a*b[j];
        }
        if (sum + c > 0)
            cnt++;
    }
    cout << cnt << endl; 
    return 0;
}

Measured memory_bytes: 256
import java.util.*
fun main(args:Array<String>) {
    val (A,B,K) = readLine()!!.split(" ").map(String::toLong)
    val list: MutableList<Long> = mutableListOf()

    
    for(i in A.until(A+K)) {
        list.add(i)
    }

    for(i in (B-K+1)..B) {
        list.add(i)

    }

    list.sorted().filter{ it >= A && it <= B }.toSet().forEach{ println(it)}
}




Measured memory_bytes: 37460
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  long ans = 0;
  long odd = 0;
  long even = 0;
  if (S.size() % 2 == 0) {
    for (int i = 0; i < S.size() / 2; i++) {
      if (S.at(2 * i + 1) == '0') {
        even++;
      }
      if (S.at(2 * i) == '0') {
        odd++;
      }
    }
    if (S.size() / 2 - odd + even > S.size() / 2 - even + odd) {
      ans = S.size() / 2 - even + odd;
    } else {
      ans = S.size() / 2 - odd + even;
    }
  } else {
    if (S.at(S.size()-1) == '0') {
        odd++;
    }
    for (int i = 0; i < S.size() / 2; i++) {
      if (S.at(2 * i + 1) == '0') {
        even++;
      }
      if (S.at(2 * i) == '0') {
        odd++;
      }
    }
    if (S.size() / 2 + 1 - odd + even > S.size() / 2 - even + odd) {
      ans = S.size() / 2 - even + odd;
    } else {
      ans = S.size() / 2 - odd + even + 1;
    }
  }
  cout << ans << endl;
}

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

typedef long long int ll;
ll INF = 999999999999;

ll gcd(ll a,ll b){
    if(a < b){
        return gcd(b,a);
    }
    ll r = INF;
    while(r){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(ll i = 0;i < N;i++)cin >> A[i];
    ll ans = 0;
    ll memo = gcd(A[0],A[1]);
    for(int i = 2;i < N;i++){
        memo = gcd(memo,A[i]);
    }
    cout << memo << endl;
}


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

int tt;
string s;

int main() {
	cin >> s >> tt;
	bool reverse = false;
	deque<char> q;
	for (char c : s) {
		q.push_back(c);
	}
	for (int i=0; i<tt; i++) {
		int t;
		cin >> t;
		if (t == 1)
			reverse ^= 1;
		else {
			int f; char c;
			cin >> f >> c;
			if ((f == 1 && !reverse) || (f == 2 && reverse))
				q.push_front(c);
			else
				q.push_back(c);
		}
	}
	if (reverse) {
		while (!q.empty()) {
			cout << q.back();
			q.pop_back();
		}
	}
	else {
		while (!q.empty()) {
			cout << q.front();
			q.pop_front();
		}
	}
}

Measured memory_bytes: 3960
#include <iostream>
#include <cmath>
#include <cstdio>
#include<cstring>
using namespace std;

int find(int n)
{
  int sum = 0;
  while(n>0)
    {
      sum += n % 10;
      n /= 10;
    }
  return sum;
}
int main()
{
  int N;
  cin >> N;
  if(N % find(N) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl; 
}


Measured memory_bytes: 256
let rec fb a b n numA =
    if b = 1 then 0
    elif numA >= b then n
    else
        let tmpNum =
          if n = 0 then 0
          elif n = 1 then a
          else a + (a-1) * (n-1)
        if tmpNum >= b then n
        else fb a b (n+1) tmpNum

//let input = [| [|4, 10|]; [| 8, 9 |]; [| 8, 8 |]; [| 2, 1|]; [| 20, 1 |] |]
//for [|a,b|] in input do fb a b 0 |> printfn "%d"

[<EntryPoint>]
let main argv =
    let input = stdin.ReadLine().Split(' ') |> Array.map int
    let a = input.[0]
    let b = input.[1]
    fb a b 0 0 |> printfn "%d"
    0

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

int main() {
  char c;
  cin >> c;

  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
  	cout << "vowel" << endl;
  } else {
  	cout << "consonant" << endl;
  }
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

#define TOPLEFT 0
#define TOP 1
#define LEFT 2
#define MAX 2000

void printLcs(string &l, vector<vector<short> > &b, const string &x, int i, int j, int k){
  if(i==0 || j==0) return;
  if(b[i][j]==TOPLEFT){
    printLcs(l, b, x, i-1, j-1, k-1);
    l[k] = x[i-1];
  }else if(b[i][j]==TOP){
    printLcs(l, b, x, i-1, j, k);
  }else{
    printLcs(l, b, x, i, j-1, k);
  }
}

void lcs(string &x, string &y, string &l){
  int m, n;
  vector<vector<short> > c, b;
  m = x.size();
  n = y.size();

  c.resize(m+1, vector<short>(n+1));
  b.resize(m+1, vector<short>(n+1));
  
  for(int i=0; i<=m; i++) c[i][0] = 0;
  for(int j=0; j<=n; j++) c[0][j] = 0;

  for(int i=1; i<=m; i++){
    for(int j=1; j<=n; j++){
      if(x[i-1]==y[j-1]){
	c[i][j] = c[i-1][j-1]+1;
	b[i][j] = TOPLEFT;
      }else if(c[i-1][j]>=c[i][j-1]){
	c[i][j] = c[i-1][j];
	b[i][j] = TOP;
      }else{
	c[i][j] = c[i][j-1];
	b[i][j] = LEFT;
      }
    }
  }

  l.resize(c[m][n]);

  printLcs(l, b, x, m, n, l.size()-1);
}

int main(){
    string s1, s2, l;
    while( cin >> s1 ){
	s2 = s1;
	reverse(s2.begin(), s2.end());
	lcs(s1, s2, l);
	cout << l << endl;
    }
    return 0;
}

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

long long N, K, A[1 << 18];

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

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i];

	long long S = 0, ans = 1;
	for (int i = 0; i < N; i++) S += A[i];

	vector<long long> J;
	for (int i = 1; i*i <= S; i++) {
		if (S%i != 0) continue;
		J.push_back(i);
		J.push_back(S / i);
	}
	sort(J.begin(), J.end());

	for (long long t : J) {
		vector<long long> V1, V2; long long sum = 0, c = 0;
		for (int i = 0; i < N; i++) {
			if (A[i] % t == 0) { c += A[i]; continue; }
			long long e1 = (A[i] % t);
			long long e2 = t - e1;
			if (e1 < e2) { c += (A[i] - e1); sum += e1; V1.push_back(e2 - e1); }
			else { c += (A[i] + e2); sum += e2; V2.push_back(e1 - e2); }
		}
		sort(V1.begin(), V1.end());
		sort(V2.begin(), V2.end());

		if (S < c) {
			for (int i = 0; i < (c - S) / t; i++) sum += V2[i];
		}
		else {
			for (int i = 0; i < (S - c) / t; i++) sum += V1[i];
		}
		if (sum <= 2LL * K) ans = max(ans, t);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

A, B, K = map(int, input().split())

for i in range(K):
    if i % 2 == 0:
        if A % 2 == 1:
            A -= 1
        A //= 2
        B += A
    else:
        if B % 2 == 1:
            B -= 1
        B //= 2
        A += B
print(A, B)

Measured memory_bytes: 3060
dice = gets.split.map(&:to_i)
throw = {E: [3, 2, 6, 1, 5, 4], N: [5, 1, 3, 4, 6, 2],
         S: [2, 6, 3, 4, 1, 5], W: [4, 2, 1, 6, 5, 3]}
th = {}
throw.each_key {|k| th[k] = throw[k].map(&:pred)}
gets.to_i.times do
  top, front = gets.split.map(&:to_i)
  stack = []
  loop do
    [:E, :N, :S, :W].each {|d| stack << [dice, d]}
    dice, dir = stack.shift
    next_dice = Array.new(6, 0)
    dice.each_with_index do |d, i|
      next_dice[th[dir][i]] = d
    end
    if next_dice[0] == top and next_dice[1] == front
      puts next_dice[2]
      break
    else
      dice = next_dice
    end
  end
end



Measured memory_bytes: 6884
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/*
 * 
 */
int main(int argc, char** argv) {
    
    int Num;
    scanf("%d",&Num);
    int A[100+5]; 
    for(int a = 0; a < Num; a++){
        
        scanf("%d",&A[a]);
    }

    int swap = 0;
    int temp;
    for(int i = 0; i < Num - 1; i++){
       for(int j = 0; j <  Num - i - 1 ; j++){
          if(A[j] > A[j+1]){
              swap++;
              temp = A[j+1];
              A[j+1] = A[j];
              A[j] = temp;
              
          } 
       }   
    }
    
    
    for(int a = 0; a < Num; a++){
        
            printf("%d",A[a]);
            if(a < Num - 1){
                printf(" ");
            } 
    }
    
    printf("\n%d\n",swap);
    return (0);
}



Measured memory_bytes: 2108
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

typedef struct node{
    lld d, c;
    double p;
}node;

int cmpDscP(const void* a, const void* b){
    double x = ((node*)a)->p, y = ((node*)b)->p;
    if(x < y){
        return 1;
    }
    if(x > y){
        return -1;
    }
    return 0;
}

int cmpDscD(const void* a, const void* b){
    int x = ((node*)a)->d, y = ((node*)b)->d;
    if(x < y){
        return 1;
    }
    if(x > y){
        return -1;
    }
    return 0;
}

int cmpAscD(const void* a, const void* b){
    int x = ((node*)a)->d, y = ((node*)b)->d;
    if(x > y){
        return 1;
    }
    if(x < y){
        return -1;
    }
    return 0;
}

int main(){
    int h, n;
    scanf("%d %d", &h, &n);
    node a[n];
    rep(i, 0, n){
        int d, c;
        scanf("%d %d", &d, &c);
        a[i].d = d;
        a[i].c = c;
        a[i].p = (double)d / c;
    }
    qsort(a, n, sizeof(node), cmpAscD);
    int t[n][h+1];
    rep(i, 0, n){
        t[i][0] = 0;
    }
    rep(i, 1, h+1){
        t[0][i] = ((i + a[0].d - 1) / a[0].d) * a[0].c;
    }
    rep(i, 1, n){
        rep(j, 1, h+1){
            if(j < a[i].d){
                if(a[i].c < t[i-1][j]){
                    t[i][j] = a[i].c;
                }else{
                    t[i][j] = t[i-1][j];
                }
            }else{
                if(a[i].c + t[i][j - a[i].d] < t[i-1][j]){
                    t[i][j] = a[i].c + t[i][j - a[i].d];
                }else{
                    t[i][j] = t[i-1][j];
                }
            }
        }
    }
    /*rep(j, 0, n){
    rep(i, 0, h+1){
        printf("%d ", t[j][i]);
    }
    printf("\n");
    }*/
    printf("%d", t[n-1][h]);

    return 0;
}

Measured memory_bytes: 39292
'use strict';
(function(stdin) {
  var lines = stdin.toString();
  var result = (function(data) {
    return data
      .map(function(v){return v.split(' ').map(Number)})
      .map(grade).join('\n');

    function grade(v) {
      var scoresum = v[0] + v[1];
      var absence  = v[0] * v[1] < 0;
      var retake = v[2];
      switch(true) {
        case absence || scoresum < 30 : return 'F';
        case scoresum >= 80 : return 'A';
        case scoresum >= 65 : return 'B';
        case scoresum >= 50 || retake >= 50 : return 'C';
        default : return 'D';
      }        
    }
  }(
    lines.split('-1 -1 -1')[0].trim().split('\n')
    ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7644
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		String s;
		while((s=r.readLine())!=null){
			double n=Double.parseDouble(s);
			int ans=0;
			double f=(n*n/19.6);
			ans=(int)(f/5+2);
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 16904
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */
namespace utils{

    class Repeater{
        int st;
        int ed;
        int d;
    public:
        class rep_iterator{
            int i; int d;
        public:
            rep_iterator(int x, int pd) :i(x), d(pd) {}

            int& operator*(){ return i; }
            bool operator==(const rep_iterator& k) const { return i == k.i; }
            bool operator!=(const rep_iterator& k) const { return i != k.i; }
            rep_iterator& operator++(){ i+=d; return *this; }
        };

        Repeater(int N) :st(0), ed(N), d(1) {}
        Repeater(int b, int e) :st(b), ed(e), d(1) {if(st > ed){ st--; ed--; d = -1; } }

        rep_iterator begin() const{ return rep_iterator(st, d); }
        rep_iterator end() const{ return rep_iterator(ed, d); }

    };

    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
};
using namespace utils;


void sub_main(istream &cin) {
    ll N;
    cin >> N;
    if(!cin) return;
    vector<int> V(N), C(N);
    for (auto &&v : V) { cin >> v; } // end v
    for (auto &&v : C) { cin >> v; } // end v

    ll ans = 0;
    for (auto &&i : Repeater(0, N)) {
        ans += max(0, V[i] - C[i]);
    } // end i
    cout << ans << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test_B.txt";
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

typedef long int li;

int main() {
    li n;
    li* m;

    std::cin >> n;
    m = new li[n];

    li max = -1;

    for (li i=0; i<n; ++i) {
        std::cin >> m[i];
        max = m[i] > max ? m[i] : max;
    }

    double mid = double(max)/2.;
    li r = -1;
    for (li i=0; i<n; ++i) {
        auto val = double(m[i]);
        if ((std::abs(val-mid) < std::abs(double(r)-mid)) and (m[i] != max)) {
            r = m[i];
        }
    }

    std::cout << max << " " << r << std::endl;

    delete[](m);

    return 0;
}

Measured memory_bytes: 1024
from math import sqrt, floor

X = int(input())

def isPrimeNum(num):
    if num == 2:
        return True
    
    for i in range(3, floor(sqrt(num)), 2):
        if num % i == 0:
            return False
    return True



if X == 2:
    print("2")
    exit()

if X%2 == 0:
    X += 1

for kazu in range(X, 100004, 2):
    if isPrimeNum(kazu):
        print(kazu)
        exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	
	int H, A;  cin >> H >> A;
	cout << ((H % A) ? H / A + 1 : H / A) << endl;
	return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 h,w,d;
    cin >> h >> w >> d;
    pii a_pos[h*w];
    REP(i,h)REP(j,w){
        int32 a;
        cin >> a;
        a--;
        a_pos[a] = mp(i,j);
    }
    int32 dist[h*w];
    REP(i,d)dist[i] = 0;
    FOR(i,d,h*w){
        int32 py,px,ny,nx;
        tie(py,px) = a_pos[i-d];
        tie(ny,nx) = a_pos[i];
        dist[i] = dist[i-d] + abs(py - ny) + abs(px - nx);
    }
    int32 q;
    cin >> q;
    REP(i,q){
        int32 l,r;
        cin >> l >> r;
        l--;r--;
        int32 cost = dist[r] - dist[l];
        ANS(cost);
    }
    // REP(i,h*w)ANS(dist[i]);
    return 0;
}

Measured memory_bytes: 3200
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		String str;
		Stack<Integer> S1 = new Stack<Integer>();
		Stack<pair> S2 = new Stack<pair>();
		str = cin.next();
		int i, sum = 0;
		for (i = 0; i < str.length(); i++)
		{
			char ch = str.charAt(i);
			if (ch == '\\') {
				S1.push(i);
			} else if (ch == '/' && !S1.empty()) {
				int j = S1.peek();
				S1.pop();
				int a = i - j;
				sum += a;
				while (!S2.empty() && S2.peek().first > j) {
					a += S2.peek().second;
					S2.pop();
				}
				S2.push(new pair(j, a));
			}
		}
		System.out.printf("%d\n%d", sum, S2.size());
		ArrayDeque<Integer> deque = new ArrayDeque<Integer>();
		while(S2.size() > 0) {
			deque.offer(S2.peek().second);
			S2.pop();
		}
		while (deque.size() > 0) {
			System.out.printf(" %d", deque.pollLast());
		}
		System.out.println();
	}
}

class pair {
	int first;
	int second;
	pair(int f, int s) {
		first = f;
		second = s;
	}
}


Measured memory_bytes: 34324
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{


    vi a(3);
    in(3,a);
    sort(all(a));
    if(a[0] == a[1] && a[1] != a[2]) cyes;
    else if(a[1] == a[2] && a[0] != a[2]) cyes;
    else cno;
    
    
    

    return 0;
}


Measured memory_bytes: 256
// A - キャンディーとN人の子供イージー / Children and Candies (ABC Edit) https://atcoder.jp/contests/abc043/tasks/abc043_a

  import io.Source

  object Main extends App {
    Source.stdin.getLines().foreach { line =>
      val n = line.toInt
      println(solve(n))
    }

    def solve(n: Int): String = {
      ((1 + n) * n / 2).toString
    }
  }


Measured memory_bytes: 25428
#include<iostream>
#include<vector>
#include<climits>
#include<algorithm>
using namespace std;
int main() {
	int kind, srh, min_problems=INT_MAX;
	cin >> kind >> srh;
	vector<pair<int, int>> vec(kind);
	for (int i = 0; i < kind; ++i) {
		cin >> vec[i].first >> vec[i].second;
	}
	for (int bit = 0; bit < (1 << kind); ++bit) {
		int sum = 0;
		int problems = 0;
		for (int i = 0; i < kind; ++i) {
			if (bit & (1 << i)) {
				sum += 100 * (i + 1) * vec[i].first + vec[i].second;
				problems += vec[i].first;
			}
		}
		for (int i = kind-1; i >=0; --i) {
			if (sum >= srh) {
				min_problems = min(min_problems, problems);
				break;
			}
			if (!( bit & (1 << i))) {
				for (int n = 0; n < vec[i].first; ++n) {
					int sum_local = 100 * (i + 1) * n;
					int problems_local = n;
					if (sum + sum_local >= srh) {
						min_problems = min(min_problems, problems + problems_local);
						break;
					}

				}
				break;
			}
		}
	}
	cout << min_problems << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

vector<ll> primes;
void make_primes(){
    primes.pb(2);
    for(ll n = 3; n <= 2200; n++){ // 2200^3 > 10^10
        bool isPrime = true;
        for(ll i = 0; primes[i] * primes[i] <= n && i < primes.size(); i++){
            if(n % primes[i] == 0) {
                isPrime = false;
                break;
            }
        }
        if(isPrime) primes.pb(n);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    make_primes();
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
        for(ll prime: primes){
            while(1){
                if(A[i] % (prime * prime * prime) == 0){
                    A[i] /= prime * prime * prime;
                }
                else{
                    break;
                }
            }
        }
    }
    sort(all(A));
    vector<pair<ll, int>> C;
    map<ll, int> M;
    ll num = -1;
    rep(i, N){
        if (num == A[i]){
            C.back().second++;
        }
        else{
            C.pb(mp(A[i], 1));
            M[A[i]] = (int)C.size(); // index + 1
        }
        num = A[i];
    }
    
    vector<int> vis(C.size(), 0); // チェックしたか
    int ret = 0;
    
    // a*b^2 and a^2*b
    rep(i, C.size()){
        if(vis[i] > 0 || C[i].first == 1) continue;
        ll a = C[i].first;
        ll b = 1;
        for(ll prime: primes){
            if(a % (prime * prime) == 0){
                a /= (prime * prime);
                b *= prime;
            }
        }
        if(M[a * a * b] > 0){
            ret += max(C[i].second, C[M[a * a * b] - 1].second);
            vis[i] = 1, vis[M[a * a * b] - 1] = 1;
        }
        else{
            ret += C[i].second;
            vis[i] = 1;
        }
    }
    
    // a and a^2
    rep(i, C.size()){
        if(C[i].first > 100000) break; // (10^5)^2=10^10
        if(vis[i] > 0 || C[i].first == 1) continue;
        ll a = C[i].first;
        ll b = a * a;
        if(M[b] > 0){
            ret += max(C[i].second, C[M[b] - 1].second);
            vis[i] = 1, vis[M[b] - 1] = 1;
        }
        else{
            ret += C[i].second;
            vis[i] = 1;
        }
    }
    
    // 1だけ特別に処理
    rep(i, C.size()){
        if(vis[i] == 0){
            if(C[i].first == 1) ret++;
            else ret += C[i].second;
        }
    }
    
    output(ret, 0);
    return 0;
}

Measured memory_bytes: 15472
use std::io::stdin;
use std::collections::{HashSet};

fn main() {
    let mut nm = String::new();
    stdin().read_line(&mut nm).unwrap();
    let nm: Vec<isize> = nm.trim().split_whitespace().flat_map(str::parse).collect();
    let (n, m) = (nm[0], nm[1]);

    let mut xs = String::new();
    stdin().read_line(&mut xs).unwrap();
    let mut xs: Vec<isize> = xs.trim().split_whitespace().flat_map(str::parse).collect();

    if n > m {
        println!("0");
        return;
    }
    xs.sort();

    let mut df: Vec<_> = xs.iter().zip(xs.iter().skip(1)).enumerate().map(|(i, (&a, &b))| (a - b, i)).collect();
    df.sort();
    let tp: HashSet<_> = df.into_iter().take((n - 1) as usize).map(|(_, i)| i + 1).collect();
//    println!("{:?}", tp);
    let mut cp = None;
    let mut cv = 0;
    for (i, x) in xs.into_iter().enumerate() {
        if i == 0 || tp.contains(&i) {
//            println!("reset");
            cp = Some(x);
        } else if let Some(p) = cp {
//            println!("add {}", x - p);
            cv += x - p;
            cp = Some(x);
        } else {
//            println!("set {}", x);
            cp = Some(x);
        }
//        println!("cv = {}", cv);
    }
    println!("{}", cv);
}


Measured memory_bytes: 12540
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int X = sc.nextInt();
    String R = "No";
    if(K*500>=X){
      R = "Yes";
    }
    System.out.println(R);
  }
}

Measured memory_bytes: 35656
(defparameter n (read))
(defparameter s (read-line))
(defparameter k (read))

(defun f (str i)
  (let ((not* (char str (1- i))))
    (map 'string
         (lambda (c) (if (char= not* c) c #\*))
         str)))

(princ (f s k))


Measured memory_bytes: 15076
c={}
input()
for i in list(map(int,input().split())):
    if i in c:
        c[i]+=1
    else:
        c[i]=1
d=[i for i in c.items() if i[1]>1]
c=sorted(d)
if len(d)==0 or (len(d)==1 and c[-1][1]<4):
    print(0)
else:
    if c[-1][1]>3:
        print(c[-1][0]**2)
    else:
        print(c[-1][0]*c[-2][0])

Measured memory_bytes: 18316
#include <bits/stdc++.h>
#define MAXN 1000010
#define inf 0x3f3f3f3f
#define LL long long
#define pi acos(-1)
#define MOD 1000000007
using namespace std;

char s[MAXN];
int ans = 0;

int main()
{
	cin >> s;
	for (int i = 1; i < strlen(s); i++) {
		if (s[i]==s[i-1]) {
			ans++;
			if (s[i]=='1') s[i]='0';else s[i]='1';
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <bitset>

std::bitset<10010> mask;

int main() {
  int n;
  mask[0] = 1;
  for (scanf("%d", &n); n--;) {
    int s;
    scanf("%d", &s);
    mask |= mask << s;
  }
  int ans = 0;
  for (int i = 0; i < 10010; ++i) if (mask[i]) ans = std::max(ans, i % 10 ? i : 0);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
K=input()
N=len(K)
D=int(input())
mod=10**9+7

dp=[[[0 for i in range(0,2)] for j in range(0,D)] for k in range(0,N+1)]

dp[N][0][0]=1
dp[N][0][1]=1

for _ in range(0,N):
    i=N-_-1
    for j in range(0,D):
        ans=0
        for k in range(0,10):
            ans+=dp[i+1][(j+k)%D][0]

        dp[i][j][0]=ans%mod

        ans=0
        for k in range(0,int(K[i])):
            ans+=dp[i+1][(j+k)%D][0]

        ans+=dp[i+1][(j+int(K[i]))%D][1]

        dp[i][j][1]=ans%mod

print((dp[0][0][1]-1)%mod)

Measured memory_bytes: 130140
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

void
solve() {
  string s;
  string t;

  cin>>s;
  cin>>t;

  bool valid = true;
  for (int i=0; i<s.length(); i++)
    if (s[i] != t[i]) {
      valid = false;
      break;
    }

  if (valid)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3652
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

static int DIC[50];

static int fibonacci_with_dic(int n) {
    if ( DIC[n] > 0 ) {
        return DIC[n];
    }

    DIC[n - 2] = fibonacci_with_dic(n - 2);
    DIC[n - 1] = fibonacci_with_dic(n - 1);

    return DIC[n - 1] + DIC[n - 2];
}

int main (int argc, char* argv[]) {
    int n, i;
    int f;

    for ( i = 0; i < sizeof(DIC)/sizeof(DIC[0]); i++ ) {
        DIC[i] = -1;
    }
    DIC[0] = DIC[1] = 1;

    scanf("%d\n", &n);

    f = fibonacci_with_dic(n);

    printf("%d\n", f);

    return 0;
}



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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		long n = Long.parseLong(input.readLine( ));
		long a = 1;
		long b = 1;
		long answer = String.valueOf(n).length();

		while(a < Math.sqrt(n)+1){
			if(n%a == 0){
				b = n / a;
				if(answer > String.valueOf(b).length() && String.valueOf(b).length() >= String.valueOf(a).length()){
					answer = String.valueOf(b).length();
				}
			}
			a++;
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 22868
while True:
    n = int(input())
    if n == 0:
        break
    p = list(map(int,input().split()))
    j = list(map(int,input().split()))
    j.sort()
    j.reverse()
    s = sum(p)
    ans = s*n
    for i in range(n-1):
        s += j[i]
        if ans < s*(n-1-i):
            ans = s*(n-1-i)
    print(ans)



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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  ll sum_a = 0, sum_b = 0;
  rep(i, n) sum_a += a[i];
  rep(i, n) sum_b += b[i];
  ll o = sum_b - sum_a;

  ll r = 0;
  rep(i, n) {
    if (a[i] > b[i]) r += a[i] - b[i];
    else if ((b[i] - a[i]) % 2) ++r;
  }

  // printf("sum_a = %lld, sum_b = %lld\n", sum_a, sum_b);
  // printf("o = %lld, r = %lld\n", o, r);

  if (o >= r) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3720
def A():
    seq = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K = int(input())
    print(seq[K-1])

A()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int main(){
  int A,B;
  double T;
  cin>>A>>B>>T;
  int sub=0;
  int count=A;
  while(count<=T+0.5){
      sub+=B;
      count+=A;
  }
  cout<<sub<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> v[N];
int visited[N];


void dfs(int i) {
	visited[i] = 1;
	for(auto j : v[i]) {
		if(!visited[j]) dfs(j);
	}
}




int main() {
	int n , m ; cin >> n >> m;
	for(int i = 0 ;i < m ;i ++ ) {
		int x,y,z; cin >> x >> y >> z;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	
	int ans = 0;
	
	for(int i = 1; i <= n; i ++) {
		if(!visited[i]) {
			ans ++;
			dfs(i);
		}
	}
	cout << ans;
	
}


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1e9;
const int MOD = 1000000007;
const int N = 202055;
const int M = 1211;

int main() {
    double n;
    cin >> n;
    
    cout << n*n;


    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>

const int N = 100;

int a[N];

int main()
{
    int n;
    scanf("%d", &n);
    int avg = 0;
    for (int i = 0; i < n; ++ i) {
        scanf("%d", a + i);
        avg += a[i];
    }
    avg = round((double)avg / n);
    int result = 0;
    for (int i = 0; i < n; ++ i) {
        result += (a[i] - avg) * (a[i] - avg);
    }
    printf("%d\n", result);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=1e6+10;
int n,k,a[maxn],ma,ans;
int main()
{
	scanf("%d%d",&k,&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=2;i<=n;i++) ans=max(ans,a[i]-a[i-1]);
	ans=max(ans,a[1]+k-a[n]);
	printf("%d\n",k-ans);
return 0;
}

Measured memory_bytes: 1024
import sys
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
b=[list(map(int,input().split())) for i in range(N)]
flat=[j for i in A for j in i]
for i,value in enumerate(flat):
    if [value] in b:
         flat[i]=-1
for i in range(3):
    if flat[i*3]==flat[i*3+1]==flat[i*3+2]==-1:
        print('Yes')
        sys.exit()
    if flat[i]==flat[i+3]==flat[i+6]==-1:
        print('Yes')
        sys.exit()
if flat[0]==flat[4]==flat[8]==-1 or flat[2]==flat[4]==flat[6]==-1:
    print('Yes')
    sys.exit()
print('No')

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

int main(){
    int N;
    cin >> N;
    string S,T,ans;
    cin >> S >> T;

    rep(i,N){
        cout << S[i] << T[i];
    }
    cout << endl;
    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()  
#define sz(x) int(x.size()) 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=63;
const int mxn=0;
bool DEBUG=0;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    string s; cin>>s;
    int cnt=0,ans=0;
    for(int i=0; i<3; i++){
		if(s[i]=='R')cnt++;
		else cnt=0;
		ans=max(ans,cnt);
	}
	cout<<ans;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3652
h, w, k = map(int, input().split())

C = [list(input()) for _ in range(h)]

ans = 0

for i in range(2**h):
    for j in range(2**w):
        count = 0
        for m in range(h):
            for n in range(w):
                if (i >> m) & 1 == 0 and (j >> n) & 1 == 0 and C[m][n] == '#':
                    count += 1
                else:
                    continue
        if count == k:
            ans += 1

print(ans)

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

int To_num(char);
int Calculate(string);

int main(void)
{
  string roma;
  
  while(cin >> roma) cout << Calculate(roma) << endl;
  return 0;
}

int Calculate(string str)
{
  int ans = 0;
  int now;
  int next;
  
  for(int i = 0 ; i < str.size() ; i++)
    {
      now = To_num(str[i]);
      if(i != str.size() - 1) next = To_num(str[i+1]);
      else next = -1;

      if(now >= next) ans += now;
      else
	{
	  ans += next - now;
	  i++;
	}
    }
  return ans;
}
      
int To_num(char c) /* ツδ債ーツマツ青板篠堋づーツ個サツ催敖づ個青板篠堋づ個表ツ記ツづ可陛渉つヲツづゥ */
{
  if(c == 'I') return 1;
  if(c == 'V') return 5;
  if(c == 'X') return 10;
  if(c == 'L') return 50;
  if(c == 'C') return 100;
  if(c == 'D') return 500;
  if(c == 'M') return 1000;
  return -1;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
        }
        
        Arrays.sort(nums);
        
        int min = nums[0];
        int max = nums[n - 1];
        if (min == max) {
            System.out.println("0");
            return;
        }
        
        int answer = Integer.MAX_VALUE;
        for (int i = min; i <= max; i++) {
            int sum = 0;
            for (int num : nums) {
                sum += (int)Math.pow(num - i, 2);
            }
            
            answer = Math.min(answer, sum);
        }
        
        System.out.println(answer);
    }
}


Measured memory_bytes: 23764
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c,d; cin >> a>>b>>c>>d;
    while(a>0 || c>0) {
        if (c-b<=0) {
            ct("Yes");
            return 0;
        } else {
            c-=b;
        }
        if (a-d<=0) {
            ct("No");
            return 0;
        } else {
            a-=d;
        }

        
    }
}


Measured memory_bytes: 3640
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    P = list(in_all())
    Q = [0] * (N + 1)

    if N == 1:
        print(0)
        exit()

    for i in range(N):
        Q[P[i]] = i

    dc = []
    for i in range(1, N):
        if Q[i] < Q[i + 1]:
            dc.append(1)
        else:
            dc.append(0)

    gr = itertools.groupby(dc)

    cnt = 1
    for k, v in gr:
        v = sum(1 for _ in v)
        if k == 1:
            cnt = max(cnt, v + 1)

    print(N - cnt)


if __name__ == '__main__':
    main()


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

int main() {
  ll K;
  string S;
  cin >> S >> K;
  int slen = S.length();
  vector<int> r;
  int t = 1;
  int first = 0;
  int last = 0;
  bool all_same = true;
  REP(i,slen-1) {
    if (S[i] == S[i+1]) {
      t++;
      if ( i == 0 ) first = 1;
      if ( i == slen-2 ) {
        last = t;
      }
    } else {
      all_same = false;
      if (t != 1) {
        if (first==1) first = t;
        else r.push_back(t);
      }
      t = 1;
    }
  }
  if (S[0] == S[slen-1]) {
    if (first==0) first = 1;
    if (last==0) last = 1;
  } else {
    r.push_back(first);
    r.push_back(last);
    first = 0;
    last = 0;
  }
//  cout << first << " " << last << endl;
//  for(auto x:r) cout << x << " "; cout << endl;
  ll mid = 0;
  for(auto x:r) mid += x/2;
  ll ans = 0;
  if (K==1) {
    ans = first/2 + last/2 + mid;
  } else if (K==2) {
    ans = first/2 + last/2 + mid * 2 + (first+last) / 2;
  } else {
    ans = ((first+last) / 2) * (K-1);
    ans += mid * (K-2);
    ans += first/2 + last/2 + mid * 2;
  }
  if ( all_same ) ans = (last * K) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  int a[A], b[B], x[M], y[M],c[M];
  rep(i,0,A-1) cin >> a[i];
  rep(i,0,B-1) cin >> b[i];
  rep(i,0,M-1) cin >> x[i] >> y[i] >> c[i];
  int ans = 1<<20;
  rep(i,0,M-1) ans = min(ans, a[x[i]-1] + b[y[i]-1] - c[i]);
  sort(a, a+A);
  sort(b, b+B);
  ans = min(ans, a[0] + b[0]);
  cout << ans << endl;
  return 0;
}


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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	lnt N, D, x, y; cin >> N >> D;
	int ans = 0;
	REP(i, N){
		cin >> x >> y;
		if((x*x + y*y) <= D*D) ans++;
	}
	cout << ans << ln;
}

Measured memory_bytes: 3668
S = input()

s1 = S[0]
s2 = S[1]
s3 = S[2]
s4 = S[3]

n = int(0)

if s1 == "+":
    n += 1
elif s1 == "-":
    n -= 1


if s2 == "+":
    n += 1
elif s2 == "-":
    n -= 1

if s3 == "+":
    n += 1
elif s3 =="-":
    n -= 1

if s4 == "+":
    n += 1
elif s4 == "-":
    n -= 1

print(n)

Measured memory_bytes: 9008