akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <iomanip>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>

#include <numeric>
#include <algorithm>
#include <functional>

#include <cctype>

#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    int m;
    cin >> m;
    rep(k,m){
        string s;
        cin >> s;
        set<string> S;
        for(int i=1;i<s.length();i++){
            string h = s.substr(0,i);
            string t = s.substr(i);
            string rh = h;
            string rt = t;
            reverse(all(rh));
            reverse(all(rt));
            S.insert(h+t);
            S.insert(t+h);
            S.insert(rh+t);
            S.insert(t+rh);
            S.insert(h+rt);
            S.insert(rt+h);
            S.insert(rh+rt);
            S.insert(rt+rh);
        }
        cout << S.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 1292
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30, Array = int(1e5);
int main(){
  int n;
int seq[Array], dp[Array];
  scanf("%d", &n);
  fill(dp, dp + n, INF);
  for(int i = 0; i < n; i++)
    scanf("%d", &seq[ i ]);
  for(int i = 0; i < n; i++)
    *lower_bound(dp, dp + n, seq[ i ]) = seq[ i ];
  cout << lower_bound(dp, dp + n, INF) - dp << endl;
  return 0;
}

Measured memory_bytes: 1988
#include <stdio.h>
#include <string.h>
 
int read_line(char* out, size_t limit) {
    char* lf;
    if (fgets(out, limit, stdin) == NULL) return 0;
    if ((lf = strchr(out, '\n')) != NULL) *lf = '\0';
    return 1;
}
 
int main(void) {
    char str[1024];
    char command[4096];
    int q, query_count;
    if (!read_line(str, sizeof(str))) return 1;
    if (!read_line(command, sizeof(command)) || sscanf(command, "%d", &q) != 1) return 1;
    for (query_count = 0; query_count < q; query_count++) {
        int a, b;
        char *command_kind, *p;
        int i;
        if (!read_line(command, sizeof(command))) return 1;
        if ((command_kind = strtok(command, " ")) == NULL) return 1;
        if ((p = strtok(NULL, " ")) == NULL || sscanf(p, "%d", &a) != 1) return 1;
        if ((p = strtok(NULL, " ")) == NULL || sscanf(p, "%d", &b) != 1) return 1;
        if (strcmp(command_kind, "replace") == 0) {
            /* there doesn't seem a grantee that p consists of lowercase letters */
            if ((p = strtok(NULL, "")) == NULL) return 1;
            if (b < a || (size_t)(b - a + 1) != strlen(p)) return 1;
            memcpy(&str[a], p, b - a + 1);
        } else if (strcmp(command_kind, "reverse") == 0) {
            for (i = 0; a + i < b - i; i++) {
                char temp = str[a + i];
                str[a + i] = str[b - i];
                str[b - i] = temp;
            }
        } else if (strcmp(command_kind, "print") == 0) {
            for (i = a; i <= b; i++) putchar((unsigned char)str[i]);
            putchar('\n');
        } else return 1;
    }
    return 0;
}


Measured memory_bytes: 2148
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        this.RowCount = inpt[0];
        this.ColCount = inpt[1];
        this.Jump = inpt[2];

        for (int i = 0; i < RowCount; i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            for (int j = 0; j < ColCount; j++) {
                Map.Add(inpt[j], new Pos(i, j));
            }
        }

        int queryCount = int.Parse(Reader.ReadLine());
        List<int[]> query = new List<int[]>();
        for (int i = 0; i < queryCount; i++)
        {
            query.Add(Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray());
        }

        for (int i = 1; i <= Jump; i++) {
            this.JumpLen[i] = 0;
            int prevNum = i;
            for (int j = i+Jump; j <= this.RowCount * this.ColCount; j+=Jump) {
                int addNum = Math.Abs(Map[prevNum].Row - Map[j].Row) + Math.Abs(Map[prevNum].Col - Map[j].Col);
                JumpLen[j] = JumpLen[prevNum] + addNum;
                prevNum = j;
            }
        }

        StringBuilder ans = new StringBuilder();

        foreach(int[] q in query) {
            long tmp = JumpLen[q[1]] - JumpLen[q[0]];
            ans.AppendLine(tmp.ToString());
        }
        Console.Write(ans.ToString());
    }

    private int RowCount;
    private int ColCount;
    private int Jump;

    private Dictionary<int, Pos> Map = new Dictionary<int, Pos>();

    private Dictionary<int, long> JumpLen = new Dictionary<int, long>();

    private class Pos {
        public int Row;
        public int Col;
        public Pos(int r, int c) {
            this.Row = r;
            this.Col = c;
        }
    }


    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"

3 3 2
1 4 3
2 5 7
8 9 6
1
4 8


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 37084
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) for (int i = x; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 300;

int n;
vii dp(401, vi(401, INF64));
vi a;
vi p;

void f(int l, int r) {
    if (dp[l][r] != INF64) return;

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

    for (int i = l; i < r; ++i) {
        f(l, i);
        f(i + 1, r);
        dp[l][r] = min(dp[l][r], dp[l][i] + dp[i + 1][r] + p[r] - p[l - 1]);
    }
}

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

    cin >> n;
    a.resize(n + 1);
    p.resize(n + 1);

    in(a, 1);

    p[0] = 0;
    for (int j = 1; j <= n; ++j) {
        p[j] = p[j - 1] + a[j];
    }

    f(1, n);
    cout << dp[1][n];
}


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

int main(){
    string s,t;
    getline(cin,s);
    for(int i=0;i<s.size();i++){
        if(isalpha(s[i])){
            if(isupper(s[i])) t+=tolower(s[i]);
            else t+= toupper(s[i]);
        }
        else{
            t+=s[i];
        }
    }
    cout<<t<<'\n';
}


Measured memory_bytes: 3024
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);
  int a; cin >> a;cout << "ABC" << a  << LF;

  return 0;
}



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

long long N, A[100010], neg=0, mini=1000000001, sum=0;

int main () {
	cin >> N;
	for(int i=1; i<=N; i++) {
		cin >> A[i];
		mini = min(mini, abs(A[i]));
		sum += abs(A[i]);
		if (A[i] < 0) neg++;
	}
	if (neg%2==0)
		cout << sum << endl;
	else
		cout << sum-2*mini << endl;	
	return 0;
}

Measured memory_bytes: 1024
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, a;
	scanf("%d", &n);
	unordered_map<int, int> p;
	rep(i, n) {
		scanf("%d", &a);
		++p[a];
	}
	ll ans = 0;
	for (auto aa : p) {
		if (aa.second >= aa.first)ans += aa.second - aa.first;
		else ans += aa.second;
	}
	printf("%lld\n", ans);

	Please AC;
}


Measured memory_bytes: 4128
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <time.h>
#include <stdlib.h>
#include <bitset>
#include <algorithm>

#include <chrono>

#define INF 1e9
#define LL_INF 1e18

#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 1000000007
#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

typedef long long int ll;

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

#define nmax 100010

int n, m;
int dp[nmax];
bool fr[nmax];
vector <int> g[nmax];

void dfs(int node)
{
    fr[node] = true;

    for (int i = 0; i < SZ(g[node]); i++)
        if (!fr[g[node][i]]) {

            dfs(g[node][i]); 
            
            dp[node] = max(dp[node], dp[g[node][i]] + 1);
        }
        else
            dp[node] = max(dp[node], dp[g[node][i]] + 1);
}

int main()
{
    scanf("%d %d", &n, &m);

    for (int i = 1; i <= m; i++)
    {
        int x, y;

        scanf("%d %d", &x, &y);

        g[x].pb(y);
    }

    for (int i = 1; i <= n; i++) 
        if (!fr[i]) dfs(i);

    int answer = 0;

    for (int i = 1; i <= n; i++) answer = max(answer, dp[i]);

    printf("%d", answer);

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 8192
#!/usr/bin/env python3

n, k = map(int, input().split())

if n == 0 or n == k:
    print(0)
elif k == 1:
    print(0)
else:
    if n > k:
        r = n % k
        if r == 0:
            print(0)
        else:
            n_1 = abs(r - k)
            n_2 = abs(n_1 - k)
            print(min(n_1, n_2))
    else:
        n_1 = abs(n - k)
        n_2 = abs(n_1 - k)
        print(min(n_1, n_2))


Measured memory_bytes: 38452
#include<stdio.h>
int main(){
int H,W,a[300],b[300],i=0,N=0;
scanf("%d %d",&a[0],&b[0]);
while(a[i]!=0||b[i]!=0)
{
N++;
i++;
scanf("%d %d",&a[i],&b[i]);
}
for(i=0;i<=N-1;i++)
{
   for(H=1;H<=a[i];H++)
    {
      if(H%2==1)
	  {
	    if(b[i]%2==0)
		{
		for(W=1;W<=b[i]/2;W++)
		 printf("#.");
        }
		 if(b[i]%2==1)
		{
		for(W=1;W<=(b[i]-1)/2;W++)
		{
		 printf("#.");
        }
		printf("#");
		}
	  }
	 if(H%2==0)
	  {
	    if(b[i]%2==0)
		{
		for(W=1;W<=b[i]/2;W++)
		 printf(".#");
        }
		 if(b[i]%2==1)
		{
		for(W=1;W<=(b[i]-1)/2;W++)
		{
		 printf(".#");
        }
		printf(".");
		}
	  }

     printf("\n");
    }
printf("\n");
}
return 0;
}


Measured memory_bytes: 2104
// ABC044
// A - 高橋君とホテルイージー / Tak and Hotels (ABC Edit)
#include<bits/stdc++.h>

using namespace std;

int main(){
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    if(n<=k) cout << n*x << endl;
    else cout << k*x+(n-k)*y << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools

def solve():     
    N = int(input())
    S = input()
    l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    p = itertools.product(l,repeat=3)
    count = 0
    for v in p:
        S_temp = S
        dig_0_index = S_temp.find(v[0])
        if dig_0_index != -1:
            S_temp = S_temp[dig_0_index+1::]
            dig_1_index = S_temp.find(v[1])
            if dig_1_index != -1:
                S_temp = S_temp[dig_1_index+1::]
                dig_2_index = S_temp.find(v[2])
                if dig_2_index != -1:
                    count += 1
    print(count)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 72416
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int w, a, b;
    cin >> w >> a >> b;
    int c = min(a, b);
    int d = max(a, b);
    cout << max(0, d - (c+w)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n,s,i,j,tmpc,tmpt,count;
	int c[1001];
	int t[1001];
	scanf("%d %d",&n,&s);
	for(i=0;i<n;i++){
		scanf("%d %d",&c[i],&t[i]);
	}
	for (i=0; i<n; ++i) {
    	for (j=i+1; j<n; ++j) {
    		if (c[i] > c[j]) {
        		tmpc = c[i];
        		c[i] = c[j];
		        c[j] = tmpc;
        		tmpt = t[i];
        		t[i] = t[j];
        		t[j] = tmpt;
    		}
    	}
	}
	for(i=0;i<n;i++){
		if(t[i]<=s) {
			break;
		}else{
			count++;
		}
	}
	if(count!=n){
    	printf("%d",c[i]);
	}else{
		printf("TLE");
	}

	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 5)

def find(parent, i):
  t = parent[i]
  if t < 0:
    return i
  t = find(parent, t)
  parent[i] = t
  return t

def unite(parent, i, j):
  i = find(parent, i)
  j = find(parent, j)
  if i == j:
    return
  parent[j] += parent[i]
  parent[i] = j

n, m = map(int, input().split())
parent = [-1] * n
inconvenience = n * (n - 1) // 2
data = [[int(c) - 1 for c in input().split()] for _ in range(m)]
data.reverse()
result = []
for a, b in data:
  result.append(inconvenience)
  if find(parent, a) != find(parent, b):
    inconvenience -= parent[find(parent, a)] * parent[find(parent, b)]
  unite(parent, a, b)
result.reverse()
for i in result:
  print(i)


Measured memory_bytes: 39280
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int, int> pii;
typedef std::pair<int, double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;







void solve(){
    int n,h,w;
    cin >> n >> h >> w;
    int ans = 0;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        if (a >= h && b >= w) ans++;
    }
    cout << ans;
}


int main() {
    int T;
    //cin >> T;
    T = 1;
    while (T--) {
        solve();
        cout << endl;
    }
}












Measured memory_bytes: 3624
from collections import deque
INF = float("inf")
def MAIN():
    n = int(input())
    G = [[i, INF] for i in range(n)]
    G[0][1] = 0
    m = {}
    for _ in range(n):
        A = list(map(int, input().split()))
        m[A[0]] = {}
        for i in range(2, len(A), 2):
            m[A[0]][A[i]] = A[i + 1]
    dp = deque([0])
    while dp:
        u = dp.popleft()
        for v, c in m[u].items():
            if G[v][1] > G[u][1] + c:
                G[v][1] = G[u][1] + c
                dp.append(v)
    print("\n".join(" ".join(map(str, a)) for a in G))
MAIN()



Measured memory_bytes: 6304
/* code by AbhiTaker
         ____
        /    \
       /  __  \              _______      __       _   _    _____    _____
      /  /  \  \            |__   __|    /  \     | | / /  |  ___|  |  _  \
     /  /____\  \     ___      | |      / /\ \    | |/ /   | |__    | |_)  )
    /  /______\  \   |___|     | |     / /__\ \   |   /    |  __|   |    _/
   /  /        \  \            | |    / /----\ \  | |\ \   | |___   | |\ \
  /__/          \__\           |_|   /_/      \_\ |_| \_\  |_____|  |_| \_\
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M 1000000007
#define N 1000016
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define inf 9000000000000000000


int main()
{
   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s;
    cin>>s;
    ll ans = 0,cnt=0;
    for(ll i=0; i<s.size(); i++) {
        if(s[i]=='B')
            cnt++;
        else
            ans += cnt;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 720
import java.util.*
import kotlin.comparisons.compareValues

fun main(args: Array<String>) {
    data class Price(val p: Int) : Comparable<Price> {
        override fun compareTo(other: Price): Int {
            return compareValues(other.p, p)
        }

    }

    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val m = scanner.nextInt()
    val a = IntArray(n) { scanner.nextInt() }

    val pq = PriorityQueue<Price>()
    a.forEach { pq.add(Price(it)) }

    (1..m).forEach {
        val p = pq.poll()
        pq.add(Price(p.p / 2))
    }

    val ret = pq.map { it.p.toLong() }.sum()


    println(ret)
}

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

using namespace std;

const int maxn = 100000 + 50;

int n, a[maxn];
map<int,int> mp;

int main(void){
	scanf("%d", &n); int cnt = 1;
	for (int i = 1; i <= n; ++i){
		scanf("%d", &a[cnt]);
		mp[a[cnt]] ++;
		if (mp[a[cnt]] == 1) ++ cnt;
	}
	int ans = 0;
	for (int i = 1; i <= cnt - 1; ++i){
		int b = mp[a[i]];
//		printf("%d %d\n", a[i], b);
		ans += (b >= a[i] ? b - a[i] : b);
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 5120
function Main(input) {
  var line = input.split(' ');
  var N = Number(line[0]);
  var K = Number(line[1]);
  var log2 = Math.ceil(Math.log2(N + 1));
  // console.log('log2=' + log2);
  var log10 = Math.ceil(Math.log10(N + 1));
  // console.log('log10=' + log10);
  if (K == 2) {
    console.log(log2);
  } else if (K == 10) {
    console.log(log10);
  } else {
    for (var i = log10; i <= log2; i ++) {
      var n = Math.pow(K, i);
      // console.log('n(' + i + ')=' + n);
      if (N < n) {
        console.log(i);
        break;
      }
    }
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
  for (ll i = 0; i < v.size(); ++i) \
    cout << v[i] << " ";            \
  cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define get(n) \
  ll n;        \
  cin >> n
#define getvec(v, n)         \
  vector<ll> v(n);           \
  for (ll i = 0; i < n; i++) \
    cin >> v[i];
#define getstr(s) \
  string s;       \
  cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
  get(n);
  get(m);
  get(k);
  ll ans = 0;
  char arr[n][m];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> arr[i][j];
  for (int i = 0; i < (1 << n); i++)
    for (int j = 0; j < (1 << m); j++)
    {
      ll black = 0;
      for (int a = 0; a < n; a++)
        for (int b = 0; b < m; b++)
        {
          if (((i & (1 << a)) == 0) && ((j & (1 << b)) == 0) && arr[a][b] == '#')
            ++black;
        }
      if (black == k)
        ++ans;
    }
  p1(ans);
}

int main()
{
  fio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  //get(t);
  ll t = 1;
  while (t--)
  {
    mainSolve();
  }
  return 0;
}


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

using namespace std;

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

    vector< pair<int,int> > arr;
    for(int i=1; i<=n; i++){
        int temp;
        cin >> temp;
        arr.push_back({temp, i});
    }

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

    for(int i=0; i<n; i++){
        cout << arr[i].second << " ";
    }cout << "\n";

    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<bool> check(N,true);
  
  for(int i = 0; i < K; i++){
    int d;
    cin >> d;
    vector<int> A(d);
    for(int j = 0; j < d; j++){
      cin >> A[j];
      check[A[j]-1] = false;
    }
  }
  
  int sum = 0;
  
  for(int i = 0; i < N; i++){
    if(check[i])
      sum++;
  }
  
  cout << sum << endl;
  
  return 0;
  
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,m[101],tot=0;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=min(a,b);i>=1;i--)
	{
		if(a%i==0&&b%i==0) m[++tot]=i;
	}
	printf("%d",m[c]);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define i64 long long
#define vi32 vector<int>
#define vi64 vector< long long>
#define  ii pair<int,int>
const  long long mod = 1e9 + 7, inf = 1e9, linf = 1 << 30; //linf = 9223372036854775807;
const long long hashmod[4] = { (int)1e9 + 2277, (int)1e9 + 5277, (int)1e9 + 8277, (int)1e9 + 9277 };
const long double EPS = 0.000000001L, pi = acos(-1);
using namespace std;
#define pb push_back
#define mp make_pair
#define N 200005
//int base = 311;
using namespace std;
vi32 pa[N];
int f[N];
int vis[N];
void dfs(int u)
{
    vis[u]=1;
    for(auto z:pa[u])
    {
        if(vis[z]==0)
        {
            f[z]+=f[u];
            dfs(z);
        }
    }
}
int main()
{

    int n,q;
    cin>>n>>q;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        pa[u].pb(v);
        pa[v].pb(u);
    }
    while(q--)
    {

        int p,x;
        cin>>p>>x;
        f[p]+=x;

    }
    dfs(1);
    for(int i=1;i<=n;i++)
        cout<<f[i]<<' ';
   return 0;


}




/* Written by a random fan of Mr.Siro 

Association of people who died from abandonment

Gb_H

*/


Measured memory_bytes: 21120
#include <iostream>
#include <algorithm>
#include <queue>

#define MAXK 100000
#define MAXN 100
#define MOD 1000000007

using namespace std;

int d[MAXN+1][MAXK+1];
int lim[MAXN+1], sum[MAXN+1];

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

    int n, k;

    cin >> n >> k;
    for(int i=1 ; i<=n ; i++) cin >> lim[i];
    for(int i=1 ; i<=n ; i++) sum[i] = sum[i-1] + lim[i];

    d[0][0] = 1;
    for(int i=1 ; i<=n ; i++)
    {
        for(int j=1 ; j<=k ; j++)
        {
            d[i-1][j] += d[i-1][j-1];
            d[i-1][j] %= MOD;
        }
        for(int j=0 ; j<=lim[i] ; j++) d[i][j] = d[i-1][j];
        for(int j=lim[i]+1 ; j<=min(sum[i], k) ; j++) d[i][j] = (d[i-1][j] - d[i-1][j-lim[i]-1] + MOD) % MOD;
    }

    cout << d[n][k];

    return 0;
}

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

int main()
{
    ll K, S; cin >> K >> S;

    ll ans = 0;
    for (ll x = 0; x <= K; ++x) {
        for (ll y = 0; y <= K; ++y) {
            ll z = S - x - y;
            if (z >= 0 && z <= K) ans++;
        }
    }
    cout << ans << endl;

}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

struct FenwickTree{
	vector<ll> data;
	FenwickTree(int n):data(n+1){}
	void Add(int i,int x){
		for(i++;i<data.size();i+=i&-i)
			data[i]+=x;
	}
	ll Sum(int i){
		ll res=0;
		for(;i;i-=i&-i)
			res+=data[i];
		return res;
	}
	ll Sum(int i,int j){
		return Sum(j)-Sum(i);
	}
};

ll InversionNumber(const vi& a)
{
	FenwickTree ft(a.size());
	ll res=0;
	rep(i,a.size()){
		res+=ft.Sum(a[i],a.size());
		ft.Add(a[i],1);
	}
	return res;
}

bool test(vector<tuple<int,int,int>> src,vector<tuple<int,int,int>> dst)
{
	int n=src.size();
	rep(i,n){
		int x,y,z;
		tie(x,y,z)=src[i];
		src[i]=x<z?mt(x,y,z):mt(z,y,x);
		tie(x,y,z)=dst[i];
		dst[i]=x<z?mt(x,y,z):mt(z,y,x);
	}
	sort(all(src)); sort(all(dst));
	return src==dst;
}

tuple<bool,bool> calc(vector<tuple<int,int,int>> src,vector<tuple<int,int,int>> dst)
{
	int m=src.size(),flip=0;
	rep(i,m){
		int x,y,z;
		tie(x,y,z)=src[i];
		src[i]=x<z?mt(x,y,z):(flip++,mt(z,y,x));
		tie(x,y,z)=dst[i];
		dst[i]=x<z?mt(x,y,z):(flip++,mt(z,y,x));
	}
	map<tuple<int,int,int>,int> f;
	rep(i,m) f[dst[i]]=i;
	vi a(m);
	rep(i,m) a[i]=f[src[i]];
	return mt(InversionNumber(a)&1,flip&1);
}

bool solve(int n,vvi grid)
{
	array<bool,2> inv,flip;
	rep(i,2){
		vector<tuple<int,int,int>> src,dst;
		rep(j,n) if(j%2==i){
			if(j/2%2==0){
				src.emplace_back(mt(3*j+1,3*j+2,3*j+3));
				dst.emplace_back(mt(grid[0][j],grid[1][j],grid[2][j]));
			}
			else{
				src.emplace_back(mt(3*j+3,3*j+2,3*j+1));
				dst.emplace_back(mt(grid[2][j],grid[1][j],grid[0][j]));
			}
		}
		if(!test(src,dst)) return false;
		tie(inv[i],flip[i])=calc(src,dst);
	}
	return inv[0]==flip[1]&&inv[1]==flip[0];
}

int main()
{
	for(int n;cin>>n&&n;){
		vvi grid(3,vi(n));
		rep(i,3) rep(j,n) cin>>grid[i][j];
		cout<<(solve(n,grid)?"Yes":"No")<<endl;
	}
}


Measured memory_bytes: 8876
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL){
    y = x;
    if(z->key < x->key){
      x =x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }else {
    if(z->key < y->key){
      y->left = z;
    }else{
      y->right = z;
    }
  }
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key );
  inorder(u->right);
}

void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key );
  preorder(u->left);
  preorder(u->right);
}

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}



int main(){
  int n/*最初の入力数*/, i, x;
  char com[20];/*insert or print*/

  scanf("%d", &n);/*最初の入力数*/

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    
    if ( com[0] == 'i' ){

      scanf("%d", &x);/* insert */
      insert(x);

    } else if ( com[0] == 'p' ){

      inorder(root);
      printf("\n");

      preorder(root);
      printf("\n");

    }else  if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
  }
}

  return 0;
}


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

int main(){
   long long n,a,b;
  cin >> n>>a>>b;
  if(n%(a+b)>=a)
    cout << (n/(a+b))*a+a << endl;
  else
    cout << n-(n/(a+b))*b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
using V = vector<int>;
using VV = vector<V>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

VV ans;

void rec(int l, int r, int c) {
  int s = r-l;
  if (s <= 1) return;
  int k = s/2;
  rep2(i, l, l+k) rep2(j, l+k, r) ans[i][j] = c;
  rec(l, l+k, c+1);
  rec(l+k, r, c+1);
}


int main() {
  int n; cin >> n;
  ans.assign(n, V(n));

  rec(0, n, 1);
  rep(i, n-1) {
    rep2(j, i+1, n) cout << ans[i][j] << " ";
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    rep(i,3){
        if(s[i] == '1') s[i] = '9';
        else s[i] = '1';
    }
    cout << s << endl;
    return 0;
}

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

int main() {
 int n; cin >> n;
  string s; cin >> s;
  vector<bool> flag(n,1);
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1])flag[i]=0;
  }
  int cnt=0;
 for(int i=0;i<n;i++){
   if(flag[i])cnt++;
 }
 cout << cnt << endl;

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,0,1,-1};
int dy[4]={-1,1,0,0};
int a[100010],b[100010];
int main(){
	ll n,k;cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	bitset<31> bk(k);
	ll ans=0;
	for(int i=0;i<n;i++){
		bitset<31> ba(a[i]);
		bool f=true;
		for(int j=0;j<=30;j++){
			if((!bk[j]&1)&&(ba[j]&1)){
				f=false;
				break;
			}
		}
		if(f){
			ans+=b[i];
		}
	}
	for(int i=31;i>=0;i--){
		bitset<31> bit=bk;
		if(!bk[i])continue;
		bit[i]=0;
		for(int j=i-1;j>=0;j--){
			bit.set(j);
		}
		ll co=0;
		for(int j=0;j<n;j++){
			bitset<31> ba(a[j]);
			bool f=true;
			for(int k=0;k<=30;k++){
				if((!bit[k]&1)&&(ba[k]&1)){
					f=false;
					break;
				}
			}
			if(f){
				co+=b[j];
			}
		}
		ans=max(ans,co);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>

using namespace std;

void solve()
{
	map<int, char> Map;
	Map[11] = 'a'; Map[12] = 'b'; Map[13] = 'c'; Map[14] = 'd'; Map[15] = 'e';
	Map[21] = 'f'; Map[22] = 'g'; Map[23] = 'h'; Map[24] = 'i'; Map[25] = 'j';
	Map[31] = 'k'; Map[32] = 'l'; Map[33] = 'm'; Map[34] = 'n'; Map[35] = 'o'; 
	Map[41] = 'p'; Map[42] = 'q'; Map[43] = 'r'; Map[44] = 's'; Map[45] = 't'; 
	Map[51] = 'u'; Map[52] = 'v'; Map[53] = 'w'; Map[54] = 'x'; Map[55] = 'y'; 
	Map[61] = 'z'; Map[62] = '.'; Map[63] = '?'; Map[64] = '!'; Map[65] = ' '; 
	string str;
	while(cin >> str)
	{
		int size = str.size();
		if(size % 2)
		{
			cout << "NA" << endl;
		}
		else
		{
			bool flag = true;
			for(int i = 0; i < size; i += 2)
			{
				if(str[i] > '6' || str[i] < '1' || str[i + 1] > '5' || str[i + 1] < '1')
				{
					flag = false;
				}
			}
			if(flag)
			{
				for(int i = 0; i < size; i += 2)
				{
					int temp = (str[i] - '0') * 10 + str[i + 1] - '0';
					cout << Map[temp];
				}
			}
			else
			{
				cout << "NA";
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}

int main() {
  char x;
  cin  >> x;
  if(x>='a'&& x<='z'){
    cout << 'a';
  }
  else{
    cout << 'A';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3620
#include        <map>
#include      <cmath>
#include      <queue>
#include     <string>
#include     <cstdio>
#include     <vector>
#include    <cstring>
#include   <iostream>
#include  <algorithm>
using namespace std;
#define ll long long
const ll inf = 0x3f3f3f3f;
const int maxn = 1e5+5;
const ll mod = 1e9+7;

int main(){
    int k,x;
    scanf("%d%d",&k,&x);
    int t = min(x+k-1,1000000);
    for(int i=max(x-k+1,-1000000);i<=t;i++)
        printf("%d%c",i," \n"[i==t]);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
  int n, i, j, temp;
  char s[101], t[101];
  gets(s);
  gets(t);  
  n = strlen(s);
  if(strcmp(s,t)==0)
  {
      printf("Yes\n");
      return 0;
  }
  for(i=1; i<n; i++)
  {
      temp = s[0];
      for(j=0; j<n-1; j++)
      {
          s[j] = s[j+1];
      }
      s[j] = temp;
      
      if(strcmp(s,t)==0)
      {
          printf("Yes\n");
          return 0;
      }
  }
  printf("No\n");
  
  return 0;
}

Measured memory_bytes: 128
X,Y,Z,K=[int(s) for s in input().split()]
xls=sorted([int(s) for s in input().split()],reverse=True)
yls=sorted([int(s) for s in input().split()],reverse=True)
zls=sorted([int(s) for s in input().split()],reverse=True)
xyls=[]
for x in xls[:K]:
  for y in yls[:K]:
    xyls.append(x+y)
xyls=sorted(xyls,reverse=True)
cake=[]
for xy in xyls[:K]:
  for z in zls[:K]:
    cake.append(xy+z)
cake=sorted(cake,reverse=True)
for i in range(K):
  print(cake[i])

Measured memory_bytes: 164488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<28;
const int MAX_N=20000000;
const double eps=1e-07;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        vector<int> dp(1<<N);
        if(N==0) break;
        vector<double> x(N),y(N),r(N),c(N);
        for(int i=0;i<N;i++){
            cin>>x[i]>>y[i]>>r[i]>>c[i];
            c[i]--;
        }
        
        dp[0]=1;
        
        for(int bit=0;bit<(1<<N);bit++){
            if(!dp[bit]) continue;
            
            vector<vector<int>> use(4,vector<int>());
            
            for(int j=0;j<N;j++){
                if(bit&(1<<j)) continue;
                bool ok=true;
                
                for(int k=0;k<j;k++){
                    if(bit&(1<<k)) continue;
                    
                    if(hypot(x[j]-x[k],y[j]-y[k])<=r[j]+r[k]-eps){
                        ok=false;
                        break;
                    }
                }
                
                if(ok) use[c[j]].push_back(j);
            }
            
            for(int i=0;i<4;i++){
                if(use[i].size()<=1) continue;
                
                for(int j=0;j<(1<<use[i].size());j++){
                    if(__builtin_popcount(j)!=2) continue;
                    int to=bit;
                    
                    for(int k=0;k<use[i].size();k++){
                        if(j&(1<<k)) to|=(1<<use[i][k]);
                    }
                    
                    dp[to]=1;
                }
            }
        }
        
        int ans=0;
        
        for(int bit=0;bit<(1<<N);bit++){
            if(dp[bit]) ans=max(ans,__builtin_popcount(bit));
        }
        
        cout<<ans<<endl;
    }
}





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

int main(void){
    int X,Y,T,P;
    while(cin>>X>>Y>>T>>P, X|Y|T|P){
        vector<vector<int>> s(2500, vector<int>(2500, 0));
        int x1 = 0, y1 = 0, x2 = X, y2 = Y;
        rep(y,Y) rep(x,X) s[y][x] = 1;
        rep(_,T){
            int d,c;
            cin>>d>>c;
            if(d == 1){
                rep(i,c){
                    FOR(y, y1, y2){
                        int rx = x1+c*2-1-i;
                        s[y][rx] += s[y][x1+i];
                        s[y][x1+i] = 0;
                    }
                }
                x2 = max(x2, x1+2*c);
                x1 += c;
            }else{
                FOR(x, x1, x2){
                    rep(i,c){
                        int uy = y1+c*2-1-i;
                        s[uy][x] += s[y1+i][x];
                        s[y1+i][x] = 0;
                    }
                }
                y2 = max(y2, y1+2*c);
                y1 += c;
            }
        }
        rep(_,P){
            int x,y;
            cin>>x>>y;
            cout<<s[y1+y][x1+x]<<endl;
        }
    } 
    return 0;
}



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

namespace AtCoder.ABC141
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            char[] s = Console.ReadLine().ToCharArray();

            for(int i = 0; i < s.Length; i++)
            {
                if(i % 2 == 0)
                {
                    if (s[i] == 'L')
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                else
                {
                    if(s[i] == 'R')
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
            }

            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13140
MOD=10**9+7
N,K=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
ls.sort()

MAX = N+1
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, MAX):
  fac.append(fac[i - 1] * i % MOD)
  inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD)
  finv.append(finv[i - 1] * inv[i] % MOD)
 
def COM(n, k):
  if n < k: 
    return 0
  if n < 0 or k < 0:
    return 0
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

m=0
M=0
for i in range(N-K+1):
  m+=ls[i]*COM(N-i-1,K-1)%MOD
  M+=ls[-1-i]*COM(N-i-1,K-1)%MOD

print((M-m)%MOD)



Measured memory_bytes: 20544
#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,k;
char s[15];
int main()
{
    scanf("%d %s %d",&n,s,&k);
    for(i=0;i<n;i++)
    {
        if(s[i]!=s[k-1])printf("*");
        else printf("%c",s[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include <sstream>
using namespace std;
int main(void){

    string str;
    while(getline(cin,str)){
        double ans = 0;
        stack<double> s;
        stringstream ss(str);
        string tmp;
        while(ss>>tmp){
            stringstream s1(tmp);
            stringstream s2(tmp);
            int n;
            char c;
            if(s1>>n){
                s.push(n);
            }
            else if(s2>>c){

                double y = s.top();
                s.pop();
                double x = s.top();
                s.pop();
                if(c=='+'){
                    s.push(x+y);
                }
                else if(c=='-'){
                    s.push(x-y);
                }
                else if(c=='*'){
                    s.push(x*y);
                }
                else if(c=='/'){
                    s.push(x/y);
                }

            }

        }
        ans = s.top();
        s.pop();
        printf("%.6lf\n",ans);
    }

    return 0;
}

Measured memory_bytes: 1284
n= int(input())
listw = [int(i) for i in input().split()]
sum_all=sum(listw)

s1=0
s2=sum_all
lists=[]
for i in range(n-1):
	s1=s1+listw[i]
	s2=s2-listw[i]
	s=abs(s1-s2)
	lists.append(s)
	
#print(lists)

print(min(lists))
	

Measured memory_bytes: 38384
#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <vector>
#include <algorithm>
#include <string>

class R{
public:
  std::string S;
  int P;
  int n;
};

int main(){
  int N;
  std::cin >> N;
  R r[N];
  for(int i=0;i<N;i++){
    std::cin >> r[i].S >> r[i].P;
    r[i].n = i+1;
  }

  std::stable_sort(r,r+N,[](R a,R b){return a.P > b.P;});
  std::stable_sort(r,r+N,[](R a,R b){return a.S < b.S;});

  for(int i=0;i<N;i++) std::cout << r[i].n << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
using namespace std;
int main(){
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  for(int i = 0; i < Q; i++){
    cin >> A[i];
  }
  vector<int> B(N,K-Q);
  for(int i = 0; i < Q; i++){
    B[A[i]-1]++;
  }
  for(int i =0; i < N; i++){
    if(B[i] <=0){
      cout <<"No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long

int MAX = 100001;
int INF = -(1e9+7);

vector<int> p(10);

int main() {
  p[1] = 2;
  p[2] = 5;
  p[3] = 5;
  p[4] = 4;
  p[5] = 5;
  p[6] = 6;
  p[7] = 3;
  p[8] = 7;
  p[9] = 6;

  int N, M;
  cin >> N >> M;
  vector<int> dp(MAX, INF); // i本マッチで作れる桁数
  dp[0] = 0;

  vector<int> A(M);
  rep(i, 0, M) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  rep(i, 1, N + 1) {
    rep(j, 0, A.size()) {
      int a = A[j];
      int cost = p[a];
      if (i - cost < 0) continue;
      if (dp[i - cost] != INF) {
        dp[i] = max(dp[i - cost] + 1, dp[i]);
        continue;
      }
    }
  }

  int tmp = N;

  for (int i = dp[N]; i > 0; i--) {
    rep(j, 0, A.size()) {
      int a = A[j];
      int cost = p[a];
      if (tmp - cost < 0) continue;
      if (dp[tmp - cost] == dp[tmp] - 1) {
        cout << a;
        tmp -= cost;
        break;
      }
    }
  }
  cout << endl;

};


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 1; i <= 10000; i++) {
            int x = sc.nextInt();
            if (x == 0) {
                break;
            }
            System.out.println("Case " + i + ": " + x);
        }
        sc.close();
    }    
}


Measured memory_bytes: 41140
from collections import deque

n = int(input())
A = [int(a) for a in input().split()]

B = deque()
for i in range(n):
    if n%2 == 0:
        if i%2 == 0:
            B.append(A[i])
        else:
            B.appendleft(A[i])
    else:
        if i%2 == 0:
            B.appendleft(A[i])
        else:
            B.append(A[i])
        
B = list(B)
print(*B)

Measured memory_bytes: 25412
#include <bits/stdc++.h>
using namespace std;
#define data_type int
#define endl "\n"

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

    if(400<=n && n<= 599)
        cout<<8<<endl;
    else if(600<=n && n<= 799)
        cout<<7<<endl;
    else if(800<=n && n<= 999)
        cout<<6<<endl;
    else if(1000<=n && n<= 1199)
        cout<<5<<endl;

    else if(1200<=n && n<= 1399)
        cout<<4<<endl;

    else if(1400<=n && n<= 1599)
        cout<<3<<endl;

    else if(1600<=n && n<= 1799)
        cout<<2<<endl;

    else if(1800<=n && n<= 1999)
        cout<<1<<endl;



    return 0;
}



Measured memory_bytes: 3636