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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
	return __builtin_parity(x);
}

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

int solve(int W,int H,int K){
	vector<int>gcd_Wv(H);
	for(int i=0;i<H;i++)gcd_Wv[i]=gcd(W,i);
	const int L=2*K+2*W-2;
	int ans=0;
	for(int y=1;y<W;y++){
		for(int x=1;x*W<=L&&x<H;x++){
			int gcd_xy=gcd(x,y);
			int s;
			int tmp=2*K+gcd_xy-2-(W-y)*x;
			if(tmp<=0)s=1;
			else s=tmp/y+1;
			chmax(s,x);
			chmin(s,H-1);
			ans+=s-x;
			for(int z=s;(W-y)*x+y*z<=2*K+gcd_xy+W-y+W-2&&z<H;z++){
				int num=(W-y)*x+y*z+2;
				num-=gcd_xy+gcd_Wv[z-x]+gcd(W-y,z);
				num/=2;
				if(num<=K)ans++;
			}
		}
	}

	ans*=2;
	for(int y=1;y<W;y++){
		for(int x=1;x*W<=L&&x<H;x++){
			int num=x*W+2;
			num-=gcd(x,y)+gcd(W-y,x)+W;
			num/=2;
			if(num<=K)ans--;
		}
	}
	
	ans*=2;
	return ans;
}

signed main(){
	int W,H,K;
	cin>>W>>H>>K;
	cout<<solve(W,H,K)+solve(H,W,K)<<endl;
	return 0;
}


Measured memory_bytes: 4364
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
    //
  int main(){
    lint N;
    cin >>N; lint A[N];
    P p[N];
    rep(i,N){
        cin>>A[i];
        p[i]=make_pair(A[i],i+1);
    }
    sort(p,p+N);
    set<lint> ss;
    ss.emplace(0);
    ss.emplace(N+1);
    lint ans=0;
    rep(i,N){
        lint s,v;
        tie(s,v)=p[i];
        ss.emplace(v);
        auto x=ss.find(v);
        lint mul1=*x;
        lint mul2=*(++x);
        lint mul3=*(--x);
        lint mul4=*(--x);
        ans+=(mul2-mul1)*(mul3-mul4)*s;
        //cout<<s*((*(++x)-*x)*(*x-*(--x)));
    }
    cout<<ans;
   
  
    }
     
  


Measured memory_bytes: 14336
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
#include <map>
#include <utility>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
 //各位の和　
int wa(ll x)
{
ll sum = 0;
while(x!=0){
  sum += x% 10;
  x /= 10;
}
return sum;
}
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文
//if(isupper('A'))->大なら真


//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  ll x;
  cin>>x;
  p=1;
  rep(i,x/2+1)
  {
    rep(j,x)
    {
      rep(k,j)
      {
        p*=i;
      }
      if(p<=x)q=max(p,q);
      p=1;
    }
  }
  print(q);
}

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

int main(){
  int N;
  cin >> N;
  vector<int> C(510),S(510),F(510);
  for(int i=1;i<=N-1;i++)cin >> C[i] >> S[i] >> F[i];
  for(int i=1;i<=N-1;i++){
    int t=S[i]+C[i];
    for(int j=i+1;j<=N-1;j++){
      if(t%F[j]==0){t=max(S[j],t);}
      else{t=max(S[j],(t/F[j]+1)*F[j]);}
      t+=C[j];
    }
    cout << t << endl;
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    const double PI = 3.14159265358979323846;
    int R;
    cin >> R;
    cout << R * 2 * PI << endl;
}


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

int main() {
    long long h;
    int n;
    vector<int> a;
    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        int ai;
        cin >> ai;
        a.push_back(ai);
    }

    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a.at(i);
    }

    if (sum >= h) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
typedef long long ll;

const ll MAX = 1e18;

int n;
ll a[401];
ll dp[401][401];

ll dps(int l, int r)
{
    ll mn = MAX;

    if(dp[l][r] != 0)
    {
        return dp[l][r];
    }
    if(l == r) return 0;

    ll sum = 0;
    for(int i = l; i <= r; i++) sum += a[i];

    for(int i = l; i < r; i++)
    {
        mn = min(mn, dps(l, i) + dps(i+1, r) + sum);
    }

    dp[l][r] = mn;
    return dp[l][r];
}

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

    cout << dps(0, n-1) << endl;

    return 0;
}

Measured memory_bytes: 4808
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	string s ; cin >> s ;
	cout << yorn(s.at(2)==s.at(3)&&s.at(4)==s.at(5)) << endl ;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def main():
    goal = int(stdin.readline().rstrip())
    kane = 100
    count = 0
    while kane < goal:
        count += 1
        kane = int(kane * 1.01)
    print(count)
    
main()

Measured memory_bytes: 9968
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<iomanip>
#include<string>
#include<map>
using namespace std;

vector<int> a;
vector<int> b;

bool compare(const int &a,const int &b)
{
	return a > b;
}

int main()
{
	int n;
	scanf("%d", &n);
	a.resize(n);
	b.resize(n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		b[i] = a[i];
	}
	sort(a.begin(), a.end(),compare);
	int n1 = a[n / 2 - 1];
	int n2 = a[n / 2];
	for (int i = 0; i < n; i++)
	{
		if (b[i] <= n2)
			printf("%d\n", n1);
		else
			printf("%d\n", n2);
	}
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

template <class Integer>
auto boost_irange(Integer last) { return boost::irange(static_cast<Integer>(0), last); }
template <class Integer>
auto boost_irange(Integer first, Integer last) { return boost::irange(first, last); }

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << std::endl; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << val << ' ';
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val << ' ';
        return {};
    }
};

int main()
{
    input in;
    output out;

    auto S = in.read<std::string>();
    for (std::size_t i = 0; i < S.size(); ++i) {
        if ((i + 1) % 2) {
            if (S[i] == 'L') {
                out << "No";
                return 0;
            }
        } else {
            if (S[i] == 'R') {
                out << "No";
                return 0;
            }
        }
    }
    out << "Yes";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <math.h>
#include <cstdio>
#include <iomanip>
typedef  long long ll;
using namespace std;

int main(void) {
	string s;
	cin >> s;
	int ans = 0;

	for (int i = 0; i < s.length(); i++)
	{
		for (int j = 1; j <= s.length() - i; j++)
		{
			string a = s.substr(i,j);
			bool acgt = true;
			for (int k = 0; k < a.length(); k++)
			{
				if (a[k] == 'A' || a[k] == 'C' || a[k] == 'G' || a[k] == 'T') ;
				else acgt = false;
			}
			if (acgt)
			{
				ans = max(ans, (int)a.length());
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# 2 "1114.cpp"
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>


namespace solution {
    using namespace std;

    typedef istringstream ISS;
    typedef ostringstream OSS;
    typedef vector<string> VS;
    typedef long long LL;
    typedef int INT;
    typedef vector<INT> VI;
    typedef vector<VI> VVI;
    typedef pair<INT, INT> II;

    const int SIZE = 5;
    bool T[SIZE][SIZE];
    int L[SIZE][SIZE];

    class Solution {
    private:
        void init() {
        }

        bool input() {
            for ( int i = 0; i < SIZE; ++ i ) {
                for ( int j = 0; j < SIZE; ++ j ) {
                    int t;
                    cin >> t;
                    T[i][j] = t;
                }
            }
            return true;
        }

        int solve() {
            for ( int i = 0; i < SIZE; ++ i ) {
                for ( int j = 0; j < SIZE; ++ j ) {
                    L[i][j] = T[i][j];
                }
            }
            for ( int i = 0; i < SIZE; ++ i ) {
                int cnt = 0;
                for ( int j = SIZE - 1; j >= 0; -- j ) {
                    if ( T[i][j] ) {
                        cnt ++;
                    } else {
                        cnt = 0;
                    }
                    L[i][j] = cnt;
                }
            }
            int res = 0;
            for ( int i = 0; i < SIZE; ++ i ) {
                for ( int j = 0; j < SIZE; ++ j ) {
                    if ( L[i][j] == 0 ) continue;
                    int min_l = L[i][j];
                    for ( int k = 0; k < SIZE; ++ k ) {
                        int r = i + k;
                        if ( r >= SIZE ) break;
                        int c = j;
                        min_l = min( min_l, L[r][c] );
                        res = max( res, min_l * ( k + 1 ) );
                    }
                }
            }
            return res;
        }

    public:
        int run() {
            int tests;
            cin >> tests;
            for ( int i = 0; i < tests; ++ i ) {
                input();
                cout << solve() << endl;
            }
            return 0;
        }
    };
}

int main() {
    using namespace solution;
    Solution s;
    return s.run();
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main(){
int a,b;cin>>a>>b;
cout<<a*b<<endl;
}

Measured memory_bytes: 3588
def main():
  n = int(input())
  a = input_list()
  b = input_list()
  c = [a[i] - b[i] for i in range(n)]
  s = sum(c)
  if s < 0:
    print(-1)
    exit(0)
  c.sort()
  ans = 0
  for i in range(n):
    if c[i] < 0:
      pass
    elif c[i] <= s:
      ans += 1
      s -= c[i]
    else:
      break
  print(n-ans)
    
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
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

import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 20376
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=0;
    if(b<c){
        ans=2*b;
    c-=b;
    
    if(a>=c){
        ans=ans+c;
        cout<<ans<<endl;
    }else{
        ans=ans+a+1;
        cout<<ans<<endl;
    }
    }else{
        cout<<b+c<<endl;
    }
    
    
    
    
return 0;
}


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

typedef long long ll;

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll sum;
  ll memo1 = 0,memo2 = 0,memo3 = 0;
  for(ll i = 0;i < N;i++){
    cin >> A[i];
    A[i] -= i+1;
  }
  sort(A.begin(),A.end());
  ll x;
  if(N % 2 == 1){
    x = A[N / 2];
  }else{
    x = (A[N / 2 - 1] + A[N/2]) / 2;
  }
  ll ans = 0;
  for(int i = 0;i < N;i++){
    ans += abs(A[i] - x);
  }
  cout << ans << endl;
}

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

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':


H, W, K = map(int, input().rstrip().split())

# dp[i][j] := i_th row で j に到達する場合の数
dp = [[0 for j in range(W+2)] for i in range(H+1)]
dp[0][1] = 1

# ge_patnum(p] := 横棒を引くところがp個並んでいるときの場合の数
patnum = [1, 2, 3, 5, 8, 13, 21]

def get_patnum(i):
	if i <= 0:
		return 1
	else:
		return patnum[i]

for i in range(H):
	for j in range(1, W+1):
		# 下へ移動
		move_down = dp[i][j] * get_patnum(j-2) * get_patnum(W-j-1)

		# 左下へ移動
		move_left = dp[i][j+1] * get_patnum(j-2) * get_patnum(W-j-2)

		# 右下へ移動
		move_right = dp[i][j-1] * get_patnum(j-3) * get_patnum(W-j-1)

		dp[i+1][j] = (move_down + move_left + move_right) % 1000000007
		
print(dp[H][K])

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
signed main()
{
  int x=0,y=0,z=0,w=0,n=0,m=0;
  std::cin >> x>>y;
  std::vector<pair<int,int> > v(x);
  rep(i,x){
    std::cin >> v[i].first>>v[i].second;
  }
  sort(all(v));
  rep(i,x){
    if(v[i].second+z>=y){
      w+=v[i].first*(y-z);
      z+=v[i].second;
      break;
    }else{
      w+=v[i].first*v[i].second;
      z+=v[i].second;
    }
  }
  std::cout << w << '\n';
}


Measured memory_bytes: 1792
N = int(input())
A = [int(a)-1 for a in input().split()]
ans = sum([int(a) for a in input().split()])
C = [int(a) for a in input().split()]
for i in range(1, N):
    if A[i] == A[i-1] + 1:
        ans += C[A[i-1]]
print(ans)

Measured memory_bytes: 38256
N = gets.strip.to_i
counter = 0
array = gets.split(" ").map(&:to_i)

0.upto(N-1) do |i|
  (N-1).downto(i+1) do |j|
    if array[j] < array[j-1]
      array[j],array[j-1] = array[j-1],array[j]
      counter += 1
    end
  end
end

puts array.join(" ")
puts counter

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

int main(){
  int i, n, t, a, tmp, place;
  float min = 1000000.0;
  cin >> n;
  cin >> t >> a;
  
  for( i=0; i<n; i++ ){
  	cin >> tmp;
    if( abs(t-tmp*0.006-a) < min ){
      min = abs(t-tmp*0.006-a);
      place = i;
    }
  }
  
  cout << place+1 << endl;
  return 0;
}

Measured memory_bytes: 256
from fractions import gcd
a, b, c, d = map(int, input().split())
if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)
    exit()
cd_lcm = c * d // gcd(c, d)
print(b - a + 1 - (b // c - (a-1) // c) - (b // d - (a-1) // d) + (b // cd_lcm - (a-1) // cd_lcm))

Measured memory_bytes: 5048
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    vector<int> b(N);
    for (int i = 0; i < N; ++i) {
        cin >> b[i];
        b[i]--;
    }

    vector<int> ans;
    for (int i = 0; i < N; ++i) {
        int j = b.size() - 1;
        while (j >= 0) {
            if (b[j] == j) {
                break;
            }
            --j;
        }

        if (j == -1) {
            cout << -1 << endl;
            return 0;
        }

        ans.emplace_back(j);
        b.erase(begin(b) + j);
    }

    reverse(begin(ans), end(ans));

    for (int i = 0; i < N; ++i) {
        cout << ans[i] +1 << endl;
    }

    return 0;
}


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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n;
	int p,m,s;
	while(cin>>n,n){
		vector<pii> data;
		data.clear();
		rep(i,n){
			cin>>p;
			int sum = 0;
			for(int i =0; i <4;i++){
				cin>>m>>s;
				sum +=(60*m+s);
			}
			data.push_back(pii(sum,p));
		}
		sort(data.begin(),data.end());
		cout <<data[0].second<<endl;
		cout <<data[1].second<<endl;
		cout <<data[data.size()-2].second<<endl;
	}
	return 0;
}

Measured memory_bytes: 1304
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            char[] chars = sc.next().toCharArray();
            Arrays.sort(chars);
            String s = new String(chars);
            Integer cnt = map.get(s);
            if (cnt == null) {
                cnt = 0;
            }
            map.put(s, cnt + 1);
        }
        for (long num : map.values()) {
            ans += num * (num - 1) / 2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 53184
#include <stdio.h>

int main(void)
{
    int w;
    int i;
    
    while (scanf("%d", &w) != EOF){
        for (i = 1; i < 1023; i *= 2){
            if ((w / i) & 1){
                printf("%d%c", i, w / (i * 2) ? ' ' : '\n');
            }
        }
    }
    
    return (0);
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

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

  sort(vc.begin(), vc.end(), greater<int>());

  int m = accumulate(vc.begin() + 1, vc.end(), 0);
  cout << m << '\n';

  vector<int> ans(n);
  int cur = 0;
  queue<int> q;
  vector<bool> seen(n, false);
  q.push(0);
  while (!q.empty()) {
    int idx = q.front();
    q.pop();
    if (seen[idx]) {
      continue;
    }

    seen[idx] = true;
    ans[idx] = vc[cur++];
    for (auto c : g[idx]) {
      q.push(c);
    }
  }

  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
  }
}

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

int main(void){
        int counter=0;
        string W;
        string T;
        cin>>W;
        int len_W=(int)W.length();
        int len_T;
        while(1) {
                cin>>T;
                len_T=(int)T.length();
                if(T=="END_OF_TEXT") {
                        cout<<(int)counter<<endl;
                        return 0;
                }
                transform(T.begin(),T.end(),T.begin(),::tolower);
                if(T==W){
                    counter+=1;
                }
        }
}



Measured memory_bytes: 3172
#include<stdio.h>

int main(){
	char s[22];
	scanf("%[^\n]", s);
	for (int i=0 ; s[i]!='\0' ; i++){
		if (s[i]!=','){
			printf ("%c", s[i]);
		} else{
			printf(" ");
		}
	}
	puts("");
	return 0;
}

Measured memory_bytes: 1584
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    map<char, ll> ma;
    string S;
    rep(i, N) {
        cin >> S;
        ma[S[0]]++;
    }
    char s[5] = {'M', 'A', 'R', 'C', 'H'};

    ll ans = 0;

    REP(i, 0, 4) {
        REP(j, i+1, 4) {
            REP(k, j+1, 4) {
                ans += ma[s[i]] * ma[s[j]] * ma[s[k]];
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

#define lint long long
#define P pair<int, int>


int main() {
    int N;
    cin >> N;
    
    int A[2][N];
    
    for(int i = 0; i < N; ++i){
        cin >> A[0][i];
    }
    for(int i = 0; i < N; ++i){
        cin >> A[1][i];
    }
    
    int dp[2][N + 1];
    dp[0][0] = 0; dp[1][0] = 0;
    
    for(int i = 1; i <= N; ++i){
        dp[0][i] = dp[0][i - 1] + A[0][i - 1];
        dp[1][i] = max(dp[1][i - 1],dp[0][i]) + A[1][i - 1];
    }
    
    cout << dp[1][N] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int d[100000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) {
    cin >> d[i];
  }

  sort(d, d + n);
  int n21 = n / 2 - 1;
  if(d[n21] == d[n21 + 1]) cout << 0 << endl;
  else cout << (d[n21 + 1] - d[n21]) << endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
} //三項演算子を使ったgcd(最大公約数)

int main()
{
    int K;
    cin >> K;
    ll ans = 0;
    for (int i = 1; i < K + 1; i++)
    {
        for (int j = 1; j < K + 1; j++)
        {
            for (int k = 1; k < K + 1; k++)
            {
                int a = gcd(i, j);
                int s = gcd(a, k);
                ans += s;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
n = int(input())

if n % 2 == 1:
	print('0')
		
else:
	five = 0
	two = 0
	for i in range(1, n):
		f = n // (2*(5**i))
		t = n // (2**i)
		if f == t == 0:
			break
		five += f
		two += t
	print(min(five, two))

Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define INF (0x3f3f3f3f)
using namespace std;

const int MAXN = 100055;

int A[MAXN], B[MAXN];

int N, K;

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

	cin >> N >> K;
	for(int i = 1; i <= N; i++) cin >> A[i];
	for(int i = 2; i <= N; i++) {
		int &ret = B[i]; ret = INF;
		for(int j = max(1, i-K), t; j < i; j++) {
			t = B[j] + abs(A[i] - A[j]);
			if(t < ret) ret = t;
		}
	}

	cout << B[N] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef pair<string, ll> psl;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

vector< vector<psl> > ans;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    N--;
    ans = vector< vector<psl> > (10, vector<psl>(0));
    ans[0].push_back(psl("a", 0));
    REP(i, 0, N) {
        REP(j, 0, ans[i].size()) {
            psl p = ans[i][j];
            string s = p.first;
            ll num = p.second;
            REP(k, 0, num + 1) {
                char c = 'a' + k;
                ans[i + 1].push_back(psl(s + c, num));
            }
            char lastc = 'a' + num + 1;
            ans[i + 1].push_back(psl(s + lastc, num + 1));
        }
    }
    REP(i, 0, ans[N].size()) {
        cout << ans[N][i].first << endl;
    }
}


Measured memory_bytes: 10736
import fractions
import sys

def times_div2(n):
  times=0
  while(n%2==0):
    n//=2
    times+=1
  return times

N,M=map(int,input().split())
alist=list(map(int,input().split()))

aset=set()
tset=set()
for a in alist:
  aset.add(a)
  tset.add(times_div2(a))
  
if len(tset)>1:
  print(0)
  sys.exit(0)
  
lcm_a2s=1
for a in aset:
  a2=a//2
  lcm_a2s*=(a2)//fractions.gcd(lcm_a2s,a2)

#print(lcm_a2s)
print((M-lcm_a2s)//(2*lcm_a2s)+1)

Measured memory_bytes: 16320
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
bool graph1[2][200010];
bool graph2[200010][2];
ll a[200010],b[200010];
int main() {
        ll n,m;
        cin>>n>>m;
       
        for(int i=0;i<m;i++){
            cin>>a[i]>>b[i];
            a[i]--;
            b[i]--;
            if(a[i]==0) graph1[0][b[i]]=true;
            if(b[i]==n-1) graph2[a[i]][0]=true;
        }
        bool flag=false;
        for(int i=1;i<n-1;i++){
            if(graph1[0][i]==true && graph2[i][0]==true){
                flag=true;
                break;
            }
        }
        if(flag) cout<<"POSSIBLE"<<endl;
        else cout<<"IMPOSSIBLE"<<endl;
        




    return 0;
}

Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
using namespace std;

typedef long long ll;

ll n,p;

vector<pair<ll,int>>factorize(ll p){
	vector<pair<ll,int>>res;
	for(long long i=2;i*i<=p;i++){
		if(p%i)continue;
		res.emplace_back(i,0);
		while(p%i==0){
			p/=i;
			res.back().second++;
		}
	}
	if(p!=1)res.emplace_back(p,1);
	return res;
}


int main(){
	cin>>n>>p;
	vector<pair<ll,int>> res=factorize(p);
	ll ans=1;
	for(int i=0;i<res.size();i++){
		ans*=pow((res[i].first),(res[i].second/n));
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  int maxi = 0;
  int cnt = 0;
  int pre = INT_MIN;
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    if (pre >= h) {
      cnt++;
      maxi = max(maxi, cnt);
    } else {
      cnt = 0;
    }
    pre = h;
  }
  cout << maxi << '\n';
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	while (1) {
		int x,y;
		char c;
		cin >> x >> c  >> y;

		if (c == '?')break;
		int z;
		switch (c) {
		case '+':
			z = x + y;
			break;
		case '-':
			z = x - y;
			break;
		case '*':
			z = x*y;
			break;
		case '/':
			z = x / y;
			break;
		case '%':
			z = x%y;
			break;
		}
		printf("%d\n",z);
	}

	return 0;
}

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

using namespace std;
#define int int64_t
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

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

   int a, b;
   cin >> a >> b;

   if (a % b == 0)
   {
      cout << a / b << '\n';
   }
   else
      cout << a / b + 1 << '\n';
}

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

vector<ll> num753;

void append(ll n){
    if(n < 1e9){
        num753.push_back(n);
        append(n*10+3);
        append(n*10+5);
        append(n*10+7);
    }
}
int main(){
    int N;  cin >> N;
    append(0);

    int n = num753.size();
    int ans = 0;
    for(int i=0; i<n; i++){
        if(num753[i]<=N){
            string S = to_string(num753[i]);
            if(find(S.begin(), S.end(), '3') != S.end() && find(S.begin(), S.end(), '5') != S.end() && find(S.begin(), S.end(), '7') != S.end()){
                ans++;
            }
        }
    }
    cout << ans << endl;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

// a^n % mod を計算する O(log n)
ll powmod(ll a, ll n, ll mod) {
	ll ret = 1;
	while (n > 0) {
		if (n % 2 == 1) { ret = ret * a % mod; }
		a = a * a % mod;
		n /= 2;
	}
	return ret;
}

// nCr % mod を計算する O(r)
ll combmod(ll n, ll r, ll mod)
{
	ll x = 1, y = 1;
	for(ll i = 0; i < r; ++i) { x = x * (n - i) % mod; }	// 分子
	for(ll i = 1; i <= r; ++i) { y = y * i % mod; }			// 分母
	return x * powmod(y, mod - 2, mod) % mod;	// nCr = (分子) * (分母)^-1 mod M
}

void solve()
{
	ll n, a , b;
	cin >> n >> a >> b;

	a = min(a, n - a);
	b = min(b, n - b);

	// 2^n - nCa ^- nCb
	cout << (powmod(2, n, MOD) - 1 - combmod(n, a, MOD) + MOD - combmod(n, b, MOD) + MOD) % MOD;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

// A - Blackjack
// https://atcoder.jp/contests/abc147/tasks/abc147_a
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A1 = Integer.parseInt(scanner.next());
        int A2 = Integer.parseInt(scanner.next());
        int A3 = Integer.parseInt(scanner.next());
        scanner.close();

        if (A1 + A2 + A3 >= 22 ) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
    }
}


Measured memory_bytes: 22228
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL H,W,D;
vector<pair<LL,LL>> A;//iと書かれたマスが(x,y)に位置する時、A[i]=(x,y)とする
LL Q;
vector<pair<LL,LL>> LR;
 
vector<LL> ans;

void solve(){
	//i(1<=i<=D)と書かれたマスからjと書かれたマスに移動するのに必要なコストをcost[(i,j)]とおく
	map<pair<LL,LL>,LL> cost;

	for(int start=1;start<=D && start<=H*W;start++){
		for(int end=start+D;end<=H*W;end+=D){
			//cout << start << " " << end << endl;
			LL i = A[end-D].second;
			LL j = A[end-D].first;
			LL x = A[end].second;
			LL y = A[end].first;
			cost[pair<LL,LL>(start,end)] = cost[pair<LL,LL>(start,end-D)] + abs(x-i) + abs(y-j);
		}
	}

	for(int i=0;i<Q;i++){
		LL start = LR[i].first%D;
		if(start==0) start = D;
		//cout << LR[i].first << " " << LR[i].second << " start=" << start << endl;
		ans.push_back(cost[pair<LL,LL>(start,LR[i].second)] - cost[pair<LL,LL>(start,LR[i].first)]);
	}
}

int main(){
    cin >> H >> W >> D;
    A = vector<pair<LL,LL>>(H*W+1);
    for(int h=1;h<=H;h++){
    	for(int w=1;w<=W;w++){
    		int i;cin >> i;
    		A[i] = pair<LL,LL>(h,w);
    	}
    }
	cin >> Q;
	for(int i=0;i<Q;i++){
		int L,R;cin >> L >> R;
		LR.push_back(pair<LL,LL>(L,R));
	}
 
    solve();

    for(int i=0;i<Q;i++) cout << ans[i] << endl;
    return 0;
}

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

int main(){
    int n,a[3];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[0] >> a[1] >> a[2];
        std::sort(a,a+3);
        cout << (a[0]*a[0]+a[1]*a[1] == a[2]*a[2]?"YES":"NO") << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
	string str;
	//int n,k;
	string a,b,c;
	//int num = 0;
	//int cnt = 0;
	//sort(v.begin(),v.end());
	//vector<pair<int, int> > v;

    cin >> a >> b >> c;
    if(a[a.size()-1] == b[0]){
    	if(b[b.size()-1] == c[0]){
    		cout << "YES" << endl;
    		return 0;
    	}
    }
    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

int n, mn, k;
int a[MAXN];

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

void solve()
{
	for(int i = 0; i < n; i++)
		chkmin(mn, a[i]);

	int answer = 0;
	for(int i = 0; i < n; i++)
		if(a[i] != mn)
		{
			int cnt_mn = 0;
			for(int j = i; j < min(n, i + k); j++) cnt_mn += (a[j] == mn);
			if(cnt_mn) { answer++; for(int j = i; j < min(n, i + k); j++) a[j] = mn; }
			else 
			{
				answer++;
				for(int j = i; j < min(n, i + k - 1); j++) 
					a[j] = mn;
			}
		}

	cout << answer << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 640
#include <stdio.h>
int main()
{
    int n,rev=0,rem,a;
    scanf("%d",&n);
    a=n;
    rem=n%10;
    rev=rev*10+rem;
    n=n/10;
    rem=n%10;
    rev=rev*10+rem;
    n=n/10;
    rem=n%10;
    rev=rev*10+rem;
    if(a==rev){
        printf("Yes");
    }
    else printf("No");



    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	for( int x = 0; x <= 50000; ++x ){
		int p = 1.08*x;
		if( n == p ){
			cout << x << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n, m; cin >> n >> m;
    priority_queue<P, vector<P>, greater<P>> q;
    priority_queue<int> p;
    rep(i, n){
        int a, b; cin >> a >> b;
        q.push(make_pair(a, b));
    }

    ll ans = 0;
    for(int i=1; i<=m; i++){
        while(q.top().first<=i && !q.empty()){
            p.push(q.top().second);
            q.pop();
            if(q.empty()){
                break;
            }
        }

        if(!p.empty()) {
            ans += p.top();
            p.pop();
        }
        dump(ans);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1908
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    rep(i,101){
        if(i>=a && i<b && i>=c && i<d){
            ans += 1;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
l=[]
l2=[]
for i in range(2):
  l.append(input().split())
for i in range(n):
  l2.append(int(l[0][i])-int(l[1][i]))
t=0
for i in l2:
  if i>0:
    t=t+i
print(t)

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

int func(int n) {

  int i = 1;
  
  for(int j=2; j<=n; ++j) 
    i *= j;

  return i;

}

int main() {
  
  int n;
  double sum = 0;
  cin >> n;

  double x[n], y[n];
  int a[n];	//順列生成のための配列
  for(int i=0; i<n; ++i) { 
    cin >> x[i] >> y[i];
    a[i] = i+1;
  }
  
  do {
    
    for(int i=0; i<n-1; ++i) {
      sum += sqrt(pow(x[a[i+1]-1]-x[a[i]-1],2)+pow(y[a[i+1]-1]-y[a[i]-1],2));
    }
    
  }while(next_permutation(a, a+n));


  cout << fixed;
  cout << setprecision(6) << sum/func(n) << endl;
  
  return 0;
}

Measured memory_bytes: 256