akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1000000000100000000;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); 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; }


int main(){
    int n; cin >> n;
    if(n==1)cout << "Hello World" << ln;
    else{
        int a, b; cin >> a >> b;
        cout << a+b << ln;
    }
}

Measured memory_bytes: 3508
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 100;
    rep(i, 26){
        char c = 'a' + i;
        string tmp = s;
        int tmp_ans = 0;
        for(int j = tmp.size(); j >= 1 ; j --){
            bool flag = true;
            rep(k, j){
                if(tmp[k] != c){
                    flag = false;
                    break;
                }
            }
            if(flag){
                break;
            }
            rep(k, j - 1){
                if(tmp[k + 1] == c){
                    tmp[k] = c;
                }
            }
            tmp_ans ++;
        }
        ans = min(tmp_ans, ans);

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector <int > sam({0,2,5,5,4,5,6,3,7,6});
vector <pair<int , int > > allowed;

string find_max(string &curr,string  &temp){
	int sz =(int) curr.size();
	int tsz= (int) temp.size();
	bool flg = false;
	if(tsz > sz){
		flg = true ;
	}
	else if(tsz == sz ){
		
		for(int i = 0 ; i < sz ; i++){
			int a = curr[i]-'0';
			int b = temp[i]-'0';
			
			if(a > b)
				break ;
			if( a < b){
				flg = true ;
				break ;
			}
		}
	}
	
	if(flg )
		return temp;
	return curr ;
}

int main(){
	
	/* 5
	 * 117
	 * 711
	 * */
	 
	 int n, m;
	 scanf("%d%d",&n,&m);
	 
	 for(int i = 0 ; i< m ; i++){
		int temp ;
		scanf("%d",&temp);
		allowed.emplace_back(temp,sam[temp]);
	}

	sort(allowed.begin(),allowed.end(),[](pair<int,int> x , pair<int,int> y){

		return x.first > y.first;
		 
	 });

	const int nax = n+1;
	vector < string > dp(nax,"");
	for(auto x : allowed){
		char value = x.first + '0';
		int cost = x.second;
		for(int i = 1; i <= n ; i++){
			
			if(i-cost >=0 ){
				if(dp[i-cost]!="" || i-cost==0){
					string temp = dp[i-cost];
					temp += value ;
					if(temp.size()<dp[i].size())
						continue ;

					dp[i] = find_max(dp[i],temp);
				}
			}
			
			
		}
		
		
	}
	
	cout << dp[n] << endl;
	
	return 0;
}


Measured memory_bytes: 44288
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int h, a;
  cin >> h >> a;
  if(h % a == 0) {
    cout << h / a;
  }
  else {
    cout << h / a + 1;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

class BinaryIndexedTree
{
private:
    int n;
    vector<int> data;
public:
    BinaryIndexedTree(int n){ // ?????????????????????
        this->n = n;
        data.assign(n+1, 0);
    }
    void add(int k, int x){ // k?????????????´????x???????????????
        ++ k;
        while(k <= n){
            data[k] += x;
            k += k & -k;
        }
    }
    int sum(int k){ // ??????[0,k]??????????????????
        ++ k;
        int ret = 0;
        while(k > 0){
            ret += data[k];
            k -= k & -k;
        }
        return ret;
    }
    int sum(int a, int b){ // ??????[a,b]??????????????????
        return sum(b) - sum(a-1);
    }
};

int solve(const vector<int>& a, int m)
{
    int n = a.size();
    int ans = 0;
    int index = 0;
    BinaryIndexedTree bit(2*m);

    for(int i=0; i<n; ++i){
        bit.add(index, 1);
        bit.add(m+index, 1);
        index += m - a[i];
        index %= m;

        int left = 0;
        int right = m - 1;
        while(left < right){
            int mid = (left + right + 1) / 2;
            if(bit.sum(index, index+mid-1) <= i)
                left = mid;
            else
                right = mid - 1;
        }
        ans = max(ans, left);
    }

    return ans;
}

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<int> a(n);
        for(int i=0; i<n; ++i){
            long long x;
            cin >> x;
            a[i] = x % m;
        }

        cout << solve(a, m) << endl;
    }
}

Measured memory_bytes: 4276
v[2]['~~'],l,n,m,a,c,*i,*s;D(x){c=0;for(i=v+a;c<x;i+=2)c+=i[1];memmove(i+2,i,(v[a]+l-i)*4);l+=2;*i=i[-2]+(i[-1]-=i[1]=c-x);return i;}C(d,s,e){c=memmove(d,s,e-s)+e-s;}main(p,q,r,x,y){for(;scanf("%d%d%d%d%d",&n,&m,&p,&q,&r)*n;printf("%d\n",c)){v[a=**v=0][1]=n;for(l=2;m--;a^=1)scanf("%d%d",&x,&y),C(C(C(v[a^1],y,v[a]+l),x,y=D(y)),v[a],x=D(x));s=D(p-1);i=D(q);for(c=0;s-i;s+=2)c+=*s+s[1]>r?*s<r?r-*s:0:s[1];}}

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

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	if(a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES\n";
	else cout << "NO\n";
}


Measured memory_bytes: 3636
H, W = [int(x) for x in input().split()]

A = [[0]*W for i in range(H)]
for c in [1, -1]:
    for i in range(H):
        arr = [int(x) for x in input().split()]
        for j in range(W):
            A[i][j] += arr[j] * c

M = 160*80
dp = [[0]*W for i in range(H)]
dp[0][0] = 1 << M
for i in range(H):
    for j in range(W):
        if i > 0:
            dp[i][j] |= dp[i-1][j]
        if j > 0:
            dp[i][j] |= dp[i][j-1]
        a = abs(A[i][j])
        dp[i][j] = (dp[i][j] << a) | (dp[i][j] >> a)

ans = M
for i in range(2*M):
    if dp[H-1][W-1] & (1 << i) > 0:
        ans = min(ans, abs(M-i))
print(ans)

Measured memory_bytes: 20468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 


int main() {
	ll n;
	vector<tuple<string ,ll ,ll>>a;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;ll z;
		cin>>s>>z;
		z*=-1;
		a.push_back(make_tuple(s,z,i+1));
	}
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++){
		cout <<get<2>(a[i])<<endl;
	}
}

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

dic = {}
for i in range(n):
    inst, c = input().split()
    if inst[0] == 'i':
        if c in dic:
            dic[c] += 1
        else:
            dic[c] = 0
    else:
        if c in dic:
            print('yes')
        else:
            print('no')

Measured memory_bytes: 37324
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
ll A[200000];
ll sm(ll* A,ll n){
    ll s= 0;
    for (int i = 0; i < n; ++i) {
        s += A[i];
    }
    return s;
}

ll digit_sum(ll x){
    ll sum = 0;
    while(x){
       sum += x%10;
       x /= 10;
    }
    return sum;
}
unordered_set <ll> hashset;
int main() {
    int n;
    cin >> n;
    bool cond =1;
    int cnt = 0;
    int sum =0;
    for (int i = 0; i < n; ++i) {
        int t;
        cin >>t;
        if(t == i+1){
            cnt ++;
        }
        else {
            sum += (cnt+1)/2;cnt =0;
        }
    }
    sum += (cnt+1)/2;
    cout << sum;
}

Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

M=[0]*1001000

def main():
  n=I()
  l=LI()
  l.sort()
  MAX=l[-1]

  for x in l:
    M[x]+=1
    if M[x]==2:
      continue

    for i in range(2,1001000):
      y=i*x
      if MAX<y:
        break

      M[y]+=1

  ans=0
  for x in l:
    if M[x]==1:
      ans+=1

  # print(M[:100])
  return ans

# main()
print(main())


Measured memory_bytes: 41980
s = {}

temp = input()
s["a"] = [temp[i] for i in range(len(temp))]
temp = input()
s["b"] = [temp[i] for i in range(len(temp))]
temp = input()
s["c"] = [temp[i] for i in range(len(temp))]

next = "a"
while (1):
        if (len(s[next]) <= 0):
                print (next.upper())
                break
        else:
                next = s[next].pop(0)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	return (a / gcd(a, b))*b;
}

int main() {
	int n;
	ll ans = 1;
	cin >> n;
	for (int i = 0;i < n;i++) {
		ll a;
		cin >> a;
		ans = lcm(ans, a);
	}
	cout << ans << endl;
}

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

using namespace std;

int main(){
  	string s;
  	cin >> s;
  	int n = count(s.begin(), s.end(), 'R');
  	if(n == 2 && s[1] == 'S') n = 1; 
    cout << n << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

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

using namespace std;

int main(){
  long long a,b;
  cin >> a >> b;
  long long c = max(a,b);
  long long d = min(a,b);
  cout << c / gcd(c,d) * d << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >>n;
  if (n<=111) cout << 111 <<endl;
	else if (n<=222) cout << 222 <<endl;
	else if (n<=333) cout << 333 <<endl;
	else if (n<=444) cout << 444 <<endl;
	else if (n<=555) cout << 555 <<endl;
	else if (n<=666) cout << 666 <<endl;
	else if (n<=777) cout << 777 <<endl;
	else if (n<=888) cout << 888 <<endl;
	else if (n<=999) cout << 999 <<endl;

}

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

vector<int> divisor(int n)
{
  vector<int> res;
  for (int i=1; i*i<=n; i++) {
    if (n%i == 0) {
      res.push_back(i);
      if (i != n/i) res.push_back(n/i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int main()
{
  int N;
  scanf("%d",&N);
  int K;
  scanf("%d",&K);
  vector<int> A(N);
  int sum = 0;
  for(int i=0; i<N; i++){
    scanf("%d",&A[i]);
    sum += A[i];
  }
  vector<int> div = divisor(sum);
  int ans = 1;
  for (auto v:div) {
    if (v==1) continue;
    vector<int> mods;
    for (int i=0; i<N; i++) {
      int mod = A[i]%v;
      if (mod>0) mods.push_back(mod);
    }
    if (mods.empty()) {
      ans = v;
      continue;
    }
    sort(mods.begin(),mods.end());
    vector<int> acc;
    for (auto m:mods) {
      if (acc.empty()) acc.push_back(m);
      else acc.push_back(acc.back()+m);
    }
    int acclen = acc.size();
    for (int j=0; j<acclen; j++) {
      int dl = acc[j];
      int dr = v*(acclen-j-1)-(acc.back()-acc[j]);
      if (dl==dr && dl<=K && dr<=K) {
        ans = v;
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// Problem : A - A?C
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//I_love_coding...
//I_will_win
//I_can_win
//I_must_win
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
/*
1)Substring : 
string s;
	cin>>s;
	string s1 = s.substr(1,4);
    cout<<s1<<"\n";

2)Vector-with-pairs : - 
 vector< pair <ll,ll> > v; 
   
    v.push_back( make_pair(x,y) );
    
    
    sort(v.begin(),v.end(),compare);
    
    cout<<v[i].first<<" "<<v[i].second<<"\n";
    
    bool compare(const pair<ll,ll>&p1, const pair<ll,ll>&p2)
{
    if(p1.first < p2.first) return true;
        if(p1.first == p2.first) return p1.second < p2.second;
        return false;
}



3)Binary-search-on-normal-vector :-
 
vector<ll> a1;
auto mg = upper_bound(a1.begin(),a1.end(),100);
auto kf = mg - a1.begin();
ll ram=kf;//returns__the index of number slightly greater than 100 in array/.
		  //cout<<ram<<"\n";
ll lol = a1[ram] ; 

4)Binary-Search-on-vectors-of-vectors....
///vector<vector<ll>> a1;
//a1[x].push_back(y); //RAM-RAM!!!!

auto mg = upper_bound(a1[i].begin(),a1[i].end(),100);
		  auto kf = mg - a1[i].begin();
		  ll ram=kf;
		  //cout<<ram<<"\n";
		  ll lol = a1[i][ram] ; //returns__the index of number slightly greater than 100 in array"i"/.
		  //cout<<ram<<"\n";
5)Binary-exponentiation:-->
calculates : x^n%M
long long int me(long long int x,long long int n,long long int M)
{
 long long int result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}


calculates : (1/(a^b))%M;
ll modInverse(ll A,ll B,ll M)
{
    ll k=B*(M-2);
    return me(A,k,M);
}



6)Calculating factorial and inverse factorial : 
vector<ll> fact;
vector<ll> invfact;
void computefactorial(ll n,ll p)
{
    fact.resize(n+1); 
    invfact.resize(n+1);
    fact[0]=1;
    for(ll i=1;i<=n;i++)
    {
        fact[i]=i*fact[i-1];
        fact[i]%=p;
    }
    invfact[n]=modInverse(fact[n],1,p);
    for(ll i=n-1;i>=0;i--){
        invfact[i]=(i+1)*invfact[i+1];
        invfact[i]%=p;
    }
}

7)Computing nCr

ll nCr(ll n, ll r, ll p) 
{ 
return (  ((fact[n]*invfact[r])%p) * (invfact[n-r]%p) ) % p; 
}


8)Binary-format-of-the-given-number :- 



for (int i = 31; i >= 0; i--) 
{ 
        int k = n >> i; 
        if (k & 1) 
            cout << "1"; 
        else
            cout << "0"; 
} 


*/
int main()
{
	ios_base::sync_with_stdio(false) ; 
	cin.tie(NULL);
        cout.tie(NULL);	
        string s;cin>>s;
        if(s=="ABC")
        {
        	cout<<"ARC";
        }else
        {
        	cout<<"ABC";
        }
	return 0;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

long long f(long long b, long long n)
{
    if(n < b)
        return n;
    else
        return f(b, n / b) + n % b;
}

int main()
{
    long long n, s;
    cin >> n >> s;
    if(n == s){
        cout << (n + 1) << endl;
        return 0;
    }

    for(long long b=2; b*b<=n; ++b){
        if(f(b, n) == s){
            cout << b << endl;
            return 0;
        }
    }

    // n == x * b + y
    // s == x + y
    long long ans = -1;
    for(long long x=1; x*x<n; ++x){
        long long b = (n - s) / x + 1;
        if(b >= 2 && f(b, n) == s)
            ans = b;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
main = do
    s <- getLine

    print $ solve [] [read [x] :: Int | x <- s]

    
solve :: [Int] -> [Int] -> Int
solve xs [] = sum xs
solve [] (y:ys) = solve [y] ys
solve (x:xs) (y:ys) = solve (y:x:xs) ys + solve ((10 * x + y):xs) ys


Measured memory_bytes: 3852
#include<stdio.h>
#include<string.h>
int main(void){
	int i,j,l, k[6],s[6], n[6], n2[6];
	char c;
	for (i = 0; i<6; i++){
		scanf("%d", &s[i]);
		n[i] = i;
	}
	for (i = 0; i<6; i++){
		scanf("%d", &k[i]);
	}
		for (j = 0; j < 5000; j++){
			if (j%6<3&&j%5==4){
				n2[0] = n[1]; n2[1] = n[5]; n2[3] = n[3]; n2[4] = n[0]; n2[2] = n[2]; n2[5] = n[4];
			}
			else {
				n2[0] = n[3]; n2[1] = n[1]; n2[3] = n[5]; n2[4] = n[4]; n2[2] = n[0]; n2[5] = n[2];
			}
			for (i = 0; i < 6; i++){
				n[i] = n2[i];
			}
			for (l = 0; l < 6; l++){
					if (s[l] != k[n[l]])break;
				
			}
			if (l == 6){ printf("Yes\n"); break; }
		}
		if (j == 5000)printf("No\n");
	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int ans=0;

    char prev = s[0];
    string ss = "";
    for(int i=1; i<n; i++){
        if(s[i]==prev){
            ans+=1;
        }
        else{
            ss.push_back(prev);
            prev = s[i];
        }
    }
    ss.push_back(prev);
    dd(ans, ss)
    int nn = ss.size();
    if(2*k >= nn){
        ans = n-1;
    }
    else{
        ans+= 2*k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#include<vector>
#include<cstring>
#include<iostream>
#include<cstdio>
#define ull unsigned long long
#define ll long long
const ll mod=1e9+7;
using namespace std;
//priority_queue
inline ll in()
{
    ll res=0;
    char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return res;
}

 ll gcd(ll a,ll b)
 {
     return b==0?a:gcd(b,a%b);
 }
 ll kc(ll a,ll b)
 {
     ll c=1;
     while(b)
     {
         if(b&1)c=(c*a)%mod;
         a=(a*a)%mod;
         b>>=1;
     }
     return c;
 }
 ll a[10003];

  vector<ll>q[10003];
   ll cc[10003];
   ll tt;
  void dfs(int x)
  {
      cc[x]=a[tt--];
      for(int i=0;i<q[x].size();i++)
         if(!cc[q[x][i]])dfs(q[x][i]);
  }
struct A {

 ll x,y;
 bool operator <(A z)
 {
     return y>z.y;
 }
}ss[100003];
ll aa[100003],bb1[100003];
int main()
{  ios::sync_with_stdio(false);

 ll t;
 cin>>t;tt=t;
 ll x,y;
 for(ll i=1;i<t;i++){
     cin>>x>>y;aa[i]=x,bb1[i]=y;
     q[x].push_back(y);
     q[y].push_back(x);
 }
 ll ans=0;
 for(ll i=1;i<=t;i++)
    ss[++ans].x=i,ss[ans].y=q[i].size();
    sort(ss+1,ss+1+t);
 for(ll i=1;i<=t;i++)
 {
     cin>>a[i];
 }
  sort(a+1,a+1+t);
    dfs(ss[1].x);
   ll sum=0;
   for(ll i=1;i<=t;i++)
     sum+=min(cc[aa[i]],cc[bb1[i]]);
   cout<<sum<<endl;
   for(ll i=1;i<=t;i++)
    printf(i==t?"%lld\n":"%lld ",cc[i]);
}


Measured memory_bytes: 1536
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

n = int(input())

li = []
for i in range(n):
    li.append(int(input()))

li.sort()

cnt = 1
for i in range(1,n):
    if li[i-1] != li[i]:
        cnt += 1

print(cnt)


Measured memory_bytes: 2940
import java.util.Scanner;

class Main {
    static public void main(String args[]) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long Abomb = scan.nextLong();
        long Bbomb = scan.nextLong();
        long mon[] = new long[n];
        for (int i = 0; i < n; i++) {
            mon[i] = scan.nextLong();
        }
        long l = 0;
        long r = (long) 1e9 + 1;

        long m = 0;
        long cent = 0;
        while (l < r - 1) {

            m = (l + r) / 2;
            cent = 0;

            for (int i = 0; i < n; i++) {
                long HP = mon[i] - (Bbomb * m);
                if (HP > 0) {
                    cent += HP / (Abomb - Bbomb) + ((HP % (Abomb - Bbomb) == 0) ? 0 : 1);
                }
            }

            if (cent > m) {
                l = m;
            } else {
                r = m;
            }
        }
        System.out.println(r);
    }
}

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

#define ll long long
#define endl "\n";
#define mod 1000000007
#define pii pair<int,int>
#define vii vector<pii>
#define mp make_pair
#define all(a) a.begin(), a.end()
#define mk(arr,n,type) type *arr=new type[n];

void fastio() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

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

	cout << a*b;
	return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<map>

int main(void){
    std::string s;
    std::cin >> s;
    if(s == "Sunny") std::cout << "Cloudy" << std::endl;
    else if(s == "Cloudy") std::cout << "Rainy" << std::endl;
    else std::cout << "Sunny" << std::endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

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

Measured memory_bytes: 3100
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

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

#define PB push_back
#define MP make_pair

#define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
#define FORD(prom, a, b) for(int prom = (a); prom > (b); prom--)
#define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
#define R1(a) do{scanf("%d", &(a));}while(0)
#define R2(a, b) do{scanf("%d%d", &(a), &(b));}while(0)
#define R3(a, b, c) do{scanf("%d%d%d", &(a), &(b), &(c));}while(0)
#define SV(vec) do{int s_v_;scanf("%d", &(s_v_));vec.PB(s_v_);}while(0)
#define MM(co, cim) memset((co), (cim), sizeof((co)))
#define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
#define INF 1000000007

int n, pref[3][4014], suff[3][4014];
string s;
vector<char> chars = {'B', 'G', 'R'};
ll res;

int gi (char c)
{
  if (c == 'B') return 0;
  else if (c == 'G') return 1;
  return 2;
}

int main ()
{
  cin >> n >> s;
  FOR(i, 0, 3)
  {
    pref[i][0] = (s[0] == chars[i]);
    FOR(j, 1, n) pref[i][j] = pref[i][j - 1] + (s[j] == chars[i]);
    suff[i][n] = 0;
    FORDE(j, n - 1, 0) suff[i][j] = suff[i][j + 1] + (s[j] == chars[i]);
  }
  res = 0;
  do
  {
    FOR(i, 1, n - 1) if (s[i] == chars[1])
    {
      res += pref[gi(chars[0])][i - 1] * suff[gi(chars[2])][i + 1];
      FOR(j, 1, n)
      {
        int npref = i - j;
        int nsuff = i + j;
        if (npref < 0 || nsuff >= n) break;
        if (s[npref] == chars[0] && s[nsuff] == chars[2]) --res;
      }
    }
  } while (next_permutation(chars.begin(), chars.end()));
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 3768
#pragma warning (disable :4996)
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;

int n, k;
int w[N];
ll maxn = 0;
int check(int m) {
	int cnt = 0;
	for (int i = 0; i < k; i++) {
		ll sum = 0;
		while (sum + w[cnt] <= m) {
			sum += w[cnt];
			cnt++;
			if (cnt == n) return 1;
		}
	}
	return 0;
}
void solve() {
	ll le = 0, r = maxn, mid;
	while (le <= r) {
		mid = (le + r) / 2;
		if (check(mid))
			r = mid - 1;
		else
			le = mid + 1;
	}
	if (check(r)) cout << r << endl;
	else cout << le << endl;
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) { 
		scanf("%d", &w[i]); 
		maxn += w[i];
	}
	solve();
	return 0;

	 
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>

using namespace std;

#define MOD 1000000007

int main(){
  long long ans = 0;
  int n, k, t;
  cin >> n >> k;
  vector<pair<int, int>> p(n+1);
  set<pair<int, int>> range;
  p[0] = {-1, 0};
  range.insert({-1, 0});
  bool flag = false;
  vector<int> great(n+1, 0);
  for(int i = 1; i <= n; i++){
    cin >> t;
    p[i] = {t, i};
    range.insert({t, i});
    if(p[i].first > p[i-1].first){
      great[i] = great[i-1]+1;
    }
    if(i > k-1){
      auto it = range.find(p[i-k]);
      if(i == k){
        if(great[i] - great[i-(k-1)] == k-1) flag = true;
        ans++;
      }
      else if(great[i] - great[i-(k-1)] == k-1){
        if(!flag) ans++, flag = true;
      }
      else if(it != range.begin() || range.rbegin()->second != i){
        ans++;
      }
      range.erase(it);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 12032
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
  
	cout << fixed << setprecision(10);
  	long double a,b;
  cin>>a>>b;
  cout<<1.0/(1.0/a+1.0/b)<<endl;
} 


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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
  
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)3e2+11;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        cin>>n;
        
        vll a(n);
        ll sum=0;
        ll tt=0;
        for(i=0;i<n;i++){
                cin>>a[i];
                sum+=a[i];
        }
        for(i=1;i<n;i+=2){
                tt+=a[i];
        }
        vll ans(n);
        ans[0]=sum-2*tt;
        
        for(i=1;i<n;i++){
                ans[i]=-ans[i-1] + 2*a[i-1];
        }
        for(i=0;i<n;i++){
                cout<<ans[i]<<" ";
        }
        
        
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int N;
    cin >> N;
    vector<ll> a(3*N);
    REP(i, 3*N) cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll res = 0;
    REP(i, 2*N) if(i%2==1) res += a[i];
    cout << res << endl;
    return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int flag=0;
    for(int i=1;i<=b;i++){
        if(a*i%b==c){
            cout<<"YES";
            flag=1;
            i=b+1;
        }
    }
    if(flag==0){
        cout<<"NO";
    }
    return 0;
}


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

int main(){
  int n;cin >> n;
  pair<pair<string, int>, int> p[110];
  for(int i=0;i<n;++i){
      string s;int score;
      cin >> s >> score;
      p[i] = make_pair(make_pair(s, -score), i);
  }

  sort(p, p+n);
  for(int i=0;i<n;++i)cout << p[i].second+1 << endl;

}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> Pair;
const int Nmax = 1e5 + 5, Mod = 1e9 + 7;
const int inf = 1e6;

int dp[2*Nmax], i, mask, n, j;
map<int,int> mp; string a;

int take(int pos)
{
    if(mp.find(pos) == mp.end()) return inf;
    return mp[pos];
}

int main()
{
 //   freopen("input", "r", stdin);
  //  freopen("output", "w", stdout);
    cin.sync_with_stdio(false);

    cin >> a;
    n = a.size();
    mp[0] = 0;

    mask = 0;
    for(i=0; i<n; ++i)
    {
        mask ^= (1<<(a[i] - 'a'));
        dp[i] = take(mask);

        for(j=0; j<26; ++j)
            dp[i] = min(dp[i], take(mask ^ (1<<j)));

        if(dp[i] != inf) ++dp[i];

        if(mp.find(mask) == mp.end()) mp[mask] = dp[i];
            else mp[mask] = min(mp[mask], dp[i]);
    }

    cout << dp[n-1] << '\n';

    return 0;
}


Measured memory_bytes: 10644
#include<iostream>
#include<string>
using namespace std;
int main() {
  int K;
  string S;
  cin >> K >> S;
  int i;
  for(i=0;i<min(K,(int)S.length());i++)cout << S[i];
  cout << (K<S.length()?"...":"") << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main() {
	int a, b, c, x, y,ans=1000000000;
	scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
	for (int i = 0; i <= x || i <= y; i++) {
		int nab = 2 * i, na = x - i, nb = y - i;
		if (na < 0)na = 0;
		if (nb < 0)nb = 0;
		int t = a * na + nb * b + nab * c;
		if (t < ans)ans = t;
	}
	
	printf("%d", ans);
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> A(N),B(N);
  for(pair<int,int> &i:A)
    cin>>i.first>>i.second;
  A.push_back(make_pair(-1,-1));
  for(pair<int,int> &i:B)
    cin>>i.first>>i.second;
  sort(B.begin(),B.end());
  set<int> a;
  for(int i=0;i<N;i++)
    a.insert(i);
  int l=0;
  for(int i=0;i<N;i++){
    set<int> C;
    for(int j:a)
      if(A[j].first<B[i].first && A[j].second<B[i].second)
        C.insert(j);
    if(C.size()==0)
      continue;
    int k=N;
    for(int j:C)
      if(A[k].second<A[j].second)
        k=j;
    a.erase(k);
    l++;
  }
  cout<<l<<endl;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int N, X, T; cin >> N >> X >> T;
  int ans = N / X;
  if (N % X != 0) ans ++;
  cout << ans * T << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main() { cin.tie(0); ios::sync_with_stdio(false);
    int N = in;
    vector<pair<lint,lint>> BA(N);
    rep( i, N ) BA[i].second = in, BA[i].first = in;

    sort( all(BA) );

    lint sum = 0;
    rep( i, N ) {
        sum += BA[i].second;
        if( sum > BA[i].first ) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    int x[200],tot=0;
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&x[i]);tot+=x[i];
    }
    int P=round((double)tot/n);
    long long ans=0;
    for (int i=1;i<=n;++i) ans+=(P-x[i])*(P-x[i]);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<set>
#include<iomanip>
using namespace std;

int main()
{
	int a[4];cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[2]*10+a[1]+a[0]<<endl;
	return 0;
}

Measured memory_bytes: 888
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;
#define DUMPR(v) REP(_i,v.size()){std::cerr<< #v << "[" << _i << "] = " << (v[_i]) << std::endl;}
#define CIN_VEC(v,N) {v.clear(); v.reserve(N); REP(i,N){typename decltype(v)::value_type x; cin>>x; v.emplace_back(x);}};
#define DECL_CIN(type,valname) type valname; cin >> valname;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

int main() {
  DECL_CIN(int,A);
  DECL_CIN(int,B);
  DECL_CIN(int,C);
  DECL_CIN(int,X);
  DECL_CIN(int,Y);

  int a = A*X + B*Y;

  int z = min(X,Y);
  int b = A*(X-z) + B*(Y-z) + C*2*z;

  int c = C*2*max(X,Y);

  DUMP(a);
  DUMP(b);
  cout<<min(min(a,b),c)<<endl;

  return 0;
}


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

typedef complex<int> point;
typedef long long int lli;
typedef long double ld;
#define pii pair<int,int>
#define lasB(b) (b&(-b))
#define pld pair<ld,ld>
#define mod 1000000007
#define PI acos(-1.0)
#define PB push_back
#define N      555
#define EPS (1e-8)
#define ss substr
#define S second
#define IM image
#define F first
#define RE real
#define B begin
#define E end

int n;

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

    for(int i=n;i<=1000;i++)
    {
        if(i%10==(i/10)%10 && (i/10)%10==(i/100)%10 )
            return cout<<i,0;
    }
    return 0;
}


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

using namespace std;

using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
const int INF = numeric_limits<int>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
#define ALL(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(b); a > l(c); a--)

// #define ONLINE_JUDGE
#if defined ONLINE_JUDGE
const bool enable_log = false;
#else
const bool enable_log = true;
#endif
struct VoidStream { void operator&(std::ostream&) { } };
#define LOG !(enable_log) ? (void) 0 : VoidStream() & cerr

const l MOD = e9 + 7;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  l N;
  while (cin >> N) {
    vl dp(N + 1);
    dp[0] = 1;
    dp[1] = N;
    l sum = N;
    F(x, 2, N + 1) {
      l& r = dp[x];
      r = ((N - 1) * (N - 1) + sum + N - x + 2 - dp[x - 2] + MOD) % MOD;
      sum = (sum + r) % MOD;
    }
    cout << dp[N] << '\n';
  }
}


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

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define nfor(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i < int(r); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define x first
#define y second

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int, int> pti;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

template<typename A, typename B> inline ostream& operator<< (ostream& out, const pair<A, B>& p) { return out << "(" << p.x << ", " << p.y << ")"; }
template<typename T> inline ostream& operator<< (ostream& out, const vector<T>& a) { out << "["; forn(i, sz(a)) { if (i) out << ','; out << ' ' << a[i]; } return out << " ]"; }
template<typename T> inline ostream& operator<< (ostream& out, const set<T>& a) { return out << vector<T>(all(a)); }
template<typename X, typename Y> inline ostream& operator<< (ostream& out, const map<X, Y>& a) { return out << vector<pair<X, Y>>(all(a)); }
template<typename T> inline ostream& operator<< (ostream& out, const pair<T*, int>& a) { return out << vector<T>(a.x, a.x + a.y); }

inline ld gett() { return ld(clock()) / CLOCKS_PER_SEC; }

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;

#ifdef SU1
//#define GEN
#ifndef GEN
#define LOG
#endif
#endif

const int X = 333, Q = 100'000;

int n, m, d;
int a[X][X];
int k;
pti q[Q];

bool read() {
  if (!(cin >> n >> m >> d)) return false;
  forn(i, n) forn(j, m) assert(scanf("%d", &a[i][j]) == 1);
  assert(cin >> k);
  forn(i, k) assert(scanf("%d%d", &q[i].x, &q[i].y) == 2);
  return true;
}

pti pos[X * X];
int dist(int x, int y) {
  return abs(pos[x].x - pos[y].x) + abs(pos[x].y - pos[y].y);
}

li z[X * X];

li solve(int v) {
  li& ans = z[v];
  if (ans != -1) return ans;
  if (v + d > n * m) return ans = 0;
  return ans = dist(v, v + d) + solve(v + d);
}

void solve() {
  memset(z, -1, sizeof(z));
  forn(i, n) forn(j, m) pos[a[i][j]] = mp(i, j);
#ifdef LOG
  forn(i, n) {
    forn(j, m) clog << solve(a[i][j]) << ' ';
    clog << endl;
  }
#endif
  forn(i, k) {
    auto ans1 = solve(q[i].x);
    auto ans2 = solve(q[i].y);
#ifdef LOG
    clog << "q[i]: " << q[i] << " ans1: " << ans1 << " ans2: " << ans2 << endl;
#endif
    auto ans = ans1 - ans2;
    printf("%lld\n", ans);
  }
}

int main() {
#ifdef SU1
  assert(freopen("input.txt", "rt", stdin));
  //assert(freopen("output.txt", "wt", stdout));
#endif

  cout << setprecision(10) << fixed;
  cerr << setprecision(5) << fixed;

  while (read()) {
    ld stime = gett();
    solve();
#ifdef SU1
    cerr << "Time: " << gett() - stime << endl;
#endif
    //break;
  }

  return 0;
}


Measured memory_bytes: 6656
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
int main(){
	string r;int c;char ny;
while(scanf("%c",&ny)!=EOF){
	
	//if(ny==EOF)break;
	r+=ny;
	}
	char a='a';
	int count[26]={0};//aが0,zが25
	
	for(int i=0;i<r.size();i++){
		for(int j=0;j<26;j++){
		r[i]=tolower(r[i]);
		if(r[i]-'a'==j)count[j]++;
		}
	}
	for(int i=0;i<26;i++){
	printf("%c : %d\n",a,count[i]);
	a++;
	}
return 0;
}

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


int main() {
  int64_t N,K,S;
  cin>>N>>K>>S;
  
  if(S==1000000000){
    for(int i=0;i<K;i++){
      cout<<1000000000<<endl;
    }
    for(int i=0;i<N-K;i++){
      cout<<1<<endl;
    }
  }
  else{
    for(int i=0;i<K;i++){
      cout<<S<<endl;
    }
    for(int i=0;i<N-K;i++){
      cout<<1000000000<<endl;
    }
  }
  
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int n, q;
  fscanf(stdin, "%d", &n);
  vector<int> S(n);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%d", &S[i]);
  }
  S.push_back(-1);
  fscanf(stdin, "%d", &q);
  int ans = 0, val = 0;
  for (int i = 0; i < q; ++i) {
    fscanf(stdin, "%d", &val);
    S.back() = val;
    int j = 0;
    while (S[j] != val) { ++j; }
    ans += (j != n);
  }
  fprintf(stdout, "%d\n", ans);
  return 0;
}

Measured memory_bytes: 1288
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

s = ['.'*(W+2)]
for i in range(H):
    row = input()
    s.append('.' + row + '.')
s.append('.'*(W+2))

flg = 1
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == "#":
            if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] == "." and s[i][j+1] == ".":
                flg = 0

if flg:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 13584
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>

void bubblesort(int a[],int N){
    for(int i=0; i<N; i++){
        for(int j=0; j<N-1; j++){
            if(a[j+1]>a[j]){
                int swap = a[j];
                a[j] = a[j+1];
                a[j+1] = swap;
            }
        }
    }
}

int main(void){
    int N,M,X,Y;
    scanf("%d%d%d%d",&N,&M,&X,&Y);

    int x[N], y[M];
    for(int i=0; i<N; i++){
    scanf("%d",&x[i]);
    }
    for(int i=0; i<M; i++){
    scanf("%d",&y[i]);
    }

    bubblesort(x,N);
    bubblesort(y,M);

    if((y[M-1]-x[0]) <= 0){
            printf("War\n");
            return 0;
    }

    else if((Y-x[0]) <= 0 || (y[M-1]-X) <= 0){
        printf("War\n");
        return 0;
    }
    printf("No War\n");
    return 0;
    
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef ll Weight;
void add_edge(vector<vector<Weight>> &g, Weight from, Weight to, bool isDirected) {
  g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

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

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

	char c; cin >> c;
	
	if ( c >= 'a') cout << "a" << endl;
	else cout << "A" << endl;

}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define MAX 111111
#define endl '\n'
#define boost ios_base::sync_with_stdio(0);cin.tie(0)
#define INF LONG_MAX
const int MOD=1e9+7;

int mod(int n)
{
	while(n<MOD)
		n+=MOD;
	return n%MOD;
}

int32_t main()
{
    boost;
    
    int one[62]={0};
    int ans=0;
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	for(int j=0;j<62;j++)
    	{
    		if(a[i]&(1ll<<j))
    			one[j]++;
    	}
    }

    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<62;j++)
    	{
			if(a[i]&(1ll<<j))
				continue;
			ans=mod(ans+ mod(mod(1ll<<j)*one[j]));
		}
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	vector<double> vec(n);
	double ans; ans=0;
	rep(i,0,n){
		double a; cin>>a;
		vec[i]=a;
	}
	sort(all(vec));
	rep(i,0,n-1){
		vec[i+1]=(vec[i]+vec[i+1])/2;
	}
	cout<<vec[n-1];
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	for(int i = 0; i < n; ++i){
		cin >> a[i] >> b[i] >> c[i];
	}
	int DP[n][3];
	tie(DP[n-1][0], DP[n-1][1], DP[n-1][2]) = tie(a[n-1], b[n-1], c[n-1]);
	for(int i = n-2; i >= 0; --i){
		DP[i][0] = a[i] + max(DP[i+1][1], DP[i+1][2]);
		DP[i][1] = b[i] + max(DP[i+1][0], DP[i+1][2]);
		DP[i][2] = c[i] + max(DP[i+1][0], DP[i+1][1]);
	}
	cout << max({DP[0][0], DP[0][1], DP[0][2]}) << endl;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long l;

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

int max(int a, int b){return a > b ? a: b;}
int min(int a, int b){return a < b ? a: b;}

int main(void){
	
	char c;
	int sum = 0;
	
	while (scanf("%c", &c) != EOF){
		if(c == '2'){
			sum++;
		}
	}
	
	printf("%d\n", sum);
	
	return 0;
}

Measured memory_bytes: 128