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

int main()
{
	int n; cin >> n;	
	
	string ans = "No";

	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {			
			if (n == i * j) ans = "Yes";
		}	
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
using Graph = vector<vector<int>>;
const ll INF = 1LL << 60;

bool augment(const Graph& g, int u,vector<int>& matchTo, vector<bool>& visited) {
    if (u < 0) return true;
    for(auto to : g[u]){
        if (!visited[to]) {
            visited[to] = true;
            if (augment(g, matchTo[to], matchTo, visited)) {
                matchTo[u] = to;
                matchTo[to] = u;
                return true;
            }
        }
    }
    return false;
}

int bipartiteMatching(const Graph& g, int L, vector<pair<int,int>> &matching) {
    const int n = g.size();
    vector<int> matchTo(n, -1);
    int match = 0;
    rep(u,L) {
        vector<bool> visited(n);
        if (augment(g, u, matchTo, visited)) ++match;
    }
    rep(u, L) if (matchTo[u] >= 0) // make explicit matching
    matching.push_back(make_pair(u,matchTo[u]));
    return match;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n),d(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    rep(i,n){
        cin >> c[i] >> d[i];
    }
    vector<vector<int>> g(2*n);
    rep(i,n){
        rep(j,n){
            if(a[i]<c[j] && b[i]<d[j]){
                g[i].pb(n+j);
                g[n+j].pb(i);
            }
        }
    }
    //print2(g);
    vector<pair<int,int>> matching;
    //print(bipartiteMatching(g, n, matching));
    //printvt(matching);
    cout << bipartiteMatching(g, n, matching);
}


Measured memory_bytes: 256
from operator import attrgetter
class Guide(object):
    def __init__(self,no,name,val):
        self.no=no+1
        self.name=name
        self.val=val

n=int(input())
l=[]
for i in range(n):
    name,val=list(input().split())
    val=int(val)
    l.append(Guide(i,name,val))

l.sort(key=attrgetter('val'),reverse=True)
l.sort(key=attrgetter('name'))

for h in l:
    print(h.no)


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

int main() {
	
	string w;
	int beautiful = 1;
	int charcount;
	char searching_char;

	cin >> w;
	
	for (int i = 0; i < 26; i++) {

		searching_char = 'a' + i;
		charcount = 0;

		for (int j = 0; j < w.size(); j++) {
			if (searching_char == w[j]) {
				charcount++;
			}
		}
		
		if (charcount % 2 == 1) {
			beautiful = 0;
			break;
		}
	}
	
	if (beautiful == 1) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;

}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int numa = 0;
  int numb = 0;
  rep(i, n) {
    if(s.at(i) == 'a') {
      if(numa < a + b) {
        cout << "Yes" << endl;
        numa++;
      }
      else cout << "No" << endl;
    }
    else if(s.at(i) == 'b') {
      if(numa < a + b && numb < b) {
        cout << "Yes" << endl;
        numa++;
        numb++;
      }
      else {
        numb++;
        cout << "No" << endl;
      }
    }
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 896
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;

void main(){
	auto ip = readln.split.to!(int[]), r=ip[0], D=ip[1], x=ip[2];
	int[] X = new int[](10);
	X[0] = x;

	foreach(i; 0..10){
		X[i+1] = (r*X[i]-D);
		writeln(X[i+1]);
	}
}

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

int main() {

	/* ----- 変数宣言 ----- */

	int a, b;
	string s;

	int i;
	int ans = 0;

	/* ----- 入力 ----- */
	
	cin >> a >> b;
	cin >> s;
	
	/* ----- 計算 ----- */

	for (i = 0; i<a+b+1; i++) {
		if (i < a && s[i] == '-')	ans = 1;
		if (i == a && s[i] != '-')	ans = 1;
		if (i > a && s[i] == '-')	ans = 1;
	}

	/* ----- 出力 ----- */

	if(ans == 1)	cout << "No" << endl;
	else			cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String str1 = sc.next();
		String str2 = sc.next();
		String str3 = sc.next();
		
		String a = str1.toUpperCase();
		String b = str2.toUpperCase();
		String c = str3.toUpperCase();
		String aa = a.substring(0, 1);
		String bb = b.substring(0, 1);
		String cc = c.substring(0, 1);
		
		System.out.println(aa + bb + cc);
	  }
	}

Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <string>
using namespace std;
typedef long long LL;
const LL N = 998244353;

int main(){
	LL q,a,b,c,d;
	cin >> q;
	while(q --){
		LL l,r,mid,la,lb,ra,rb,k,ans = -1;
		cin >> a >> b >> c >> d;
		l = 0; r = a + b;
		k = (a + b) / (min(a,b) + 1);
		while(l <= r){
			mid = (l + r) >> 1;
			la = a - mid / (k + 1) * k - mid % (k + 1);
			lb = b - mid / (k + 1);
			if(lb <= la * k){
				ans = mid;
				l = mid + 1;
			}
			else r = mid - 1;
		}
		l = ans + 1;
		la = a - l / (k + 1) * k - l % (k + 1);
		lb = b - l / (k + 1);
		r = l + lb - la * k + 1;
		for(LL i = c;i <= d;i ++){
			if(i <= l){
				if(i % (k + 1) == 0) cout << 'B';
				else cout << 'A';
			}
			else{
				if((i - r) % (k + 1) == 0) cout << 'A';
				else cout << 'B';
			}
		}
		cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Person[] people = new Person[n];
		for (int i = 0; i < n; i++) {
		    people[i] = new Person(i, sc.nextDouble());
		}
		Arrays.sort(people);
		int[] topNums = new int[n];
		int[] botNums = new int[n];
		double prev = -1;
		int prevCount = 0;
		double next = Double.MAX_VALUE;
		int nextCount = n;
		for (int i = 0; i < n; i++) {
		    if (people[i].score == prev) {
		        topNums[i] = prevCount;
		    } else {
		        topNums[i] = i + 1;
		    }
		    prevCount = topNums[i];
		    prev = people[i].score;
		    if (people[n - i - 1].score == next) {
		        botNums[n - i - 1] = nextCount;
		    } else {
		        botNums[n - i - 1] = i + 1;
		    }
		    nextCount = botNums[n - i - 1];
		    next = people[n - i - 1].score;
		}
		int[] scores = new int[n];
		for (int i = 0; i < n; i++) {
		    scores[people[i].idx] = (topNums[i] - 1) * 3 + n - (topNums[i] - 1) - (botNums[i] - 1) - 1;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    sb.append(scores[i]).append("\n");
		}
		System.out.print(sb);
	}
	
	static class Person implements Comparable<Person> {
	    int idx;
	    double score;
	    
	    public Person(int idx, double score) {
	        this.idx = idx;
	        this.score = score;
	    }
	    
	    public int compareTo(Person another) {
	        if (score == another.score) {
	            return 0;
	        } else if (score < another.score) {
	            return -1;
	        } else {
	            return 1;
	        }
	    }
	}
}



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

ll digit(ll n) {
  ll x = 1;
  while (n >= 10) {
    n/=10; x++;
  }
  return x;
}

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> v[100001];
  map<ll, ll> count;
  ll p[M], y[M];
  for (ll i = 0; i < M; i++) {
    cin >> p[i] >> y[i];
    
    v[p[i]].push_back(y[i]);
    count[p[i]]++;
  }
  map<ll, ll> x;
  for (ll i = 1; i <= N; i++) {
    if (count[i] > 0) {
      sort(v[i].begin(), v[i].end());
      for (ll j = 0; j < v[i].size(); j++) {
        x[v[i][j]] = j+1;
      }
    }
  }
  
  for (ll i = 0; i < M; i++) {
    for (ll j = 0; j < 6-digit(p[i]); j++) {
      cout << 0;
    }
    cout << p[i];
    for (ll j = 0; j < 6-digit(x[y[i]]); j++) {
      cout << 0;
    }
    cout << x[y[i]] << endl;
  }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  int sum = 0;
  for(int i = 0; i < N; i++){
    sum += data.at(i);
  }
  if(sum%2 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  int ok = N;
  int ng = 0;
  while(ok-ng > 1){
    int mid = (ok+ng)/2;

    if(mid*(mid+1)/2 >= N) ok = mid;
    else ng = mid;
  }

  RFOR(i, 1, ok+1){
    if(N-i >= 0){
      cout << i << endl;
      N -= i;
    }
  }

  return 0;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, ans =0;
	string s;
	cin >> s;
	
	s[0]='2';
	s[1]='0';
	s[2]='1';
	s[3]='8';
	cout << s <<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e7;

int main(){
    int D;
    ll G;
    cin >> D >> G;
    vector<ll> p(D + 1, 0), c(D + 1, 0);

    for (int i = 1; i <= D; i++)
    {
        cin >> p[i] >> c[i];
    }
    
    int ans = INF;
    for (int bit = 1; bit < (1<<(D+1)); bit++)
    {
        int temp = 0;
        ll sum = 0;
        //cerr << bitset<10>(bit) << endl;
        for (int i = 1; i <= D; i++)
        {
            if (bit & (1<<i))
            {
                //cerr<<"i="<< i <<"marked" << endl;
                sum += 100 * i * p[i] + c[i];
                
                temp += p[i];
            }   
        }
        // cerr << "sum="<<sum << "temp=" << temp<< endl;

        if (sum >= G)
        {
            ans = min(ans, temp);
        } else
        {
            for (int i = D; i > 0; i--)
            {
                if (sum >= G)
                {
                    break;
                }
                
                if (bit & (1<<i))
                {
                    continue;
                }                
                for (int j = 1; j < p[i]; j++)
                {
                   
                    
                    sum += 100 * i;
                    temp++;

                      if (sum >= G)
                    {
                        // cerr <<"temp=" << temp <<endl;
                         ans = min(ans, temp);
                        break;
                    }
                   
                    
               }
                   
            }           
        }
        
        // ans = min(ans,temp);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL
#define M 200005

using namespace std;


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int f=0;
    int n;
    cin >> n;

    lli ans =0;
    for(int i=1;i<=(n-1);i++)
    {
        int cnt = 0;
        for(int j=1;j*j<=i;j++)
        {
            if(i%j==0)
            {
                cnt += 1;
                if(j*j!=i) cnt+=1;
            }
        }
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 2005
#define inf 10000000
int f[MN][MN],siz[MN];
int n,k,ans;
struct edge{int to,nex;}e[MN*2];int hr[MN],cnt;
inline void ins(int u,int t){e[++cnt]=(edge){t,hr[u]};hr[u]=cnt;}
inline void dfs(int fa,int x){
	for(int i=hr[x];i;i=e[i].nex)
	if(e[i].to!=fa)dfs(x,e[i].to),siz[x]+=siz[e[i].to];
	if(siz[x]){
		f[x][0]=siz[x];
		for(int i=1;i<k;i++){
			int maxx=-inf;
			for(int j=hr[x];j;j=e[j].nex)if(e[j].to!=fa){
				f[x][i]+=f[e[j].to][min(i-1,k-1-i)];maxx=max(maxx,f[e[j].to][min(i-1,k-1-i)]-f[e[j].to][i-1]);
			}
			if(maxx>0) f[x][i]-=maxx;
		}
		f[x][k]=inf;
		for(int j=hr[x];j;j=e[j].nex)if(e[j].to!=fa){
			f[x][k]=min(f[x][k],siz[x]-siz[e[j].to]+f[e[j].to][k-1]);
		}
		for(int i=1;i<=k;i++) f[x][i]=min(f[x][i],f[x][i-1]);
	}
	siz[x]++;
}
int main(){
	n=read(),k=read();
	int a,b;
	for(int i=1;i<n;i++) a=read(),b=read(),ins(a,b),ins(b,a);
	dfs(0,1);ans=inf;
	for(int i=1;i<=n;i++)ans=min(ans,n-siz[i]+f[i][k]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 16000
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>

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

using namespace std;
typedef long long ll;
const int INF = INT_MAX / 4;

const int max_n = 1e3;

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

  int N;
  cin >> N;

  int types[(int)(1e5) + 1];
  REP(i, 1e5 + 1) types[i] = 0;
  int a;
  REP(i, N) {
    cin >> a;
    types[a] = 1;
  }

  int total = 0;
  REP(i, 1e5 + 1) total += types[i];
  if (total % 2 == 0) total--;

  cout << total << "\n";
  return 0;
}


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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int A;
	int B;
	cin >> A>> B;
	int ans;
	
	ans = (B+A-3) / (A - 1);
	
	print(ans);

}

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

int main()
{
int i,j,k,n,L;
cin>>n>>L;
j=0;
for(i=1;i<=n;i++)j+=L+i-1;
k=1000000;
int ans=1;
for(i=1;i<=n;i++)
{
	if(abs(L+i-1)<k)
	{
		ans=j-(L+i-1);
		k=abs(L+i-1);
	}
}
cout<<ans;
}

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



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

  ll x=0, ans=0;
  int mod=1000000007;
  rep(i, n){
    ans += (a[i]*x)%mod;
    ans%=mod;
    x+=a[i];
    x%=mod;
  }
cout << ans << endl;
  
  return 0;
}


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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	cout << ((s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) ? "Yes" : "No");
}

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

int main(){
  string X;
  cin >> X;
  int x=X.size();
  int Tcount=0;
  int ans=x;
  for(int i=x-1;i>=0;i--){
    if(X[i]=='T'){Tcount++;}
    else{
      if(Tcount>=1){Tcount--; ans-=2;}
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) (i%(ll)(1e9 + 7))


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

	rep(i,0,s.size()-1){
    	if(s[i] == s[i+1]){
         	cout << i+1 << " " << i+2 << endl;
         	return 0;
    	}
	}

	rep(i,0,s.size()-2){
    	if(s[i] == s[i+2]){
         	cout << i+1 << " " << i+3 << endl;
         	return 0;
    	}
	}

	cout << -1 << " " << -1 <<endl;
	return 0;
}

Measured memory_bytes: 512
/**
 * Road to ROI
**/ 
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn for(int i=0;i<n;i++)
#define form for(int j=0;j<m;j++)
#define pb push_back
#define mp make_pair
#define sc second
#define f first
#define kek cout<<"\n"
#define all(v)        ((v).begin()), ((v).end())
#define pob pop_back()
const ll MOD=1e9+7;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int n; 
cin >> n; 
vector<vector<pair<int,int>>> v(n); 
forn
{ 
  int t; 
  cin >> t; 
  for(int j=0;j<t;j++) 
{ 
int t1, t2; 
cin >> t1 >> t2; 
t1--; 
v[i].push_back({ t1,t2 }); 
} 
} 
int ans = 0; 

for(int i=0;i<(1<<n);i++) 
{ 
bool is = 1; 
for(int j=0;j<n;j++) 
{ 
for(int k=0;k<v[j].size();k++) 
{ 
if (((i >>j) & 1) && ((i >> v[j][k].f) & 1) != v[j][k].sc) 
{ 
is = 0; 
} 
} 
} 
if (is) 
{ 
int o = 0; 
for(int j=0;j<30;j++) 
{ 
if ((i >> j) & 1) 
o++; 
} 
ans = max(o, ans); 
}

          
}
cout<<ans;
return 0;
  
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
    FIO;
    int n; cin >> n;
    int x = ceil((1.0 * n) / 1000);

    cout << x * 1000 - n << '\n'; 
    return 0;
}

Measured memory_bytes: 3744
#include <tuple>
#include <iostream>
using namespace std;

constexpr long long INF = 1LL<<60;

using T = tuple<long long, int, int>;

inline bool operator<(const T lhs, const T rhs) {
    return get<0>(lhs) < get<0>(rhs);
}

class Solver {
    int N;
    long long D;
    int* A;
    pair<long long, int> *Ap, *Am, *Bp, *Bm;
    T* C;
public:
    Solver(int* a, int n, int d) : D(d) {
        N = 1;
        while (N < n) N *= 2;
        A = a;
        Ap = new pair<long long, int>[2*N-1];
        Am = new pair<long long, int>[2*N-1];
        Bp = new pair<long long, int>[2*N-1];
        Bm = new pair<long long, int>[2*N-1];
        C = new T[2*N-1];
        fill(Ap, Ap+2*N-1, make_pair(INF, -1));
        fill(Am, Am+2*N-1, make_pair(INF, -1));
        for (int i = 0; i < n; i++) {
            Bp[i+N-1] = {A[i] + D * i, i};
            Bm[i+N-1] = {A[i] - D * i, i};
            C[i+N-1] = {INF, -1, -1};
        }
        for (int i = n; i < N; i++) {
            Bp[i+N-1] = {INF, i};
            Bm[i+N-1] = {INF, i};
            C[i+N-1] = {INF, -1, -1};
        }
        for (int x = N-2; x >= 0; x--) {
            Bp[x] = min(Bp[2*x+1], Bp[2*x+2]);
            Bm[x] = min(Bm[2*x+1], Bm[2*x+2]);
            C[x] = min(C[2*x+1], C[2*x+2]);
        }
    }
    T query() { return C[0]; }
    void add(int i) {
        int x = i + N - 1;
        Ap[x] = {A[i] + D * i, i};
        Am[x] = {A[i] - D * i, i};
        Bp[x] = Bm[x] = {INF, -1};
        while (x > 0) {
            x = (x - 1) / 2;
            const int lc = 2*x+1, rc = 2*x+2;
            Ap[x] = min(Ap[lc], Ap[rc]);
            Am[x] = min(Am[lc], Am[rc]);
            Bp[x] = min(Bp[lc], Bp[rc]);
            Bm[x] = min(Bm[lc], Bm[rc]);
            long long v1 = Am[lc].first + Bp[rc].first;
            int i1 = Am[lc].second, j1 = Bp[rc].second;
            long long v2 = Ap[rc].first + Bm[lc].first;
            int i2 = Ap[rc].second, j2 = Bm[lc].second;
            C[x] = min({{v1, i1, j1}, {v2, i2, j2}, C[lc], C[rc]});
        }
    }
};

int main() {
    int N, D; cin >> N >> D;
    int a[N];
    for (int i = 0; i < N; i++) cin >> a[i];
    Solver S(a, N, D);
    long long ans = 0;
    S.add(0);
    int cnt = 1;
    bool added[N];
    fill(added, added+N, false);
    added[0] = true;
    while (cnt < N) {
        T r = S.query();
        long long d = get<0>(r);
        int i = get<1>(r), j = get<2>(r);
        ans += d;
        if (added[i]) swap(i, j);
        S.add(i);
        cnt++;
        added[i] = true;
    }
    cout << ans << endl;
}


Measured memory_bytes: 44288
#include <bits/stdc++.h>
using namespace std;
// 型エイリアス
using pii = pair<int, int>;
using tisb = tuple<int, string, bool>;
using vi = vector<int>;
using vii = vector<vi>;

int m;
long long cnt=0;
vi G;

int fib(int i){
  if(i == 0) return 1;
  if(i == 1) return 1;
  return fib(i-1) + fib(i-2);
}

void insertionSort(vi &A, int n, int g){
  for(int i=g; i<n; ++i){
    int v = A[i];
    int j = i - g;
    while(j >= 0 && A[j] > v){
      A[j+g] = A[j];
      j-=g;
      ++cnt;
    }
    A[j+g] = v;
  }
}

void shellSort(vi &A, int n){
  int h=1;
  while(h <= n){
    G.insert(G.begin(), h);
    h = 3*h + 1;
  }
  m = G.size();

  for(int i=0; i<m; ++i) insertionSort(A, n, G[i]);
}

int main(){
  int n; cin >> n;
  vi A(n);
  for(int i=0; i<n; ++i) scanf("%d", &A[i]);

  shellSort(A, n);

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

  for(int i=0; i<G.size(); ++i){
    if(i>0) printf(" ");
    printf("%d", G[i]);
  }
  printf("\n");

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

  for(int i=0; i<n; ++i) printf("%d\n", A[i]);
}


Measured memory_bytes: 6688
def main():
  _map = map
  _range = range
  _len = len
  _max = max
  _input = input
  _int = int
  n, m = _map(_int, _input().split())
  d1 = {}
  for _ in _range(n):
    a, b = _map(_int, _input().split())
    if a in d1:
      d1[a].append(b)
    else:
      d1[a] = [b]
  result = 0
  d2 = {}
  maxb = -1
  for i in _range(1, m + 1):
    if i in d1:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 1
        else:
          d2[j] += 1
        if j > maxb:
          maxb = j
    else:
      if _len(d2) == 0:
        continue
    result += maxb
    d2[maxb] -= 1
    if d2[maxb] == 0:
      del d2[maxb]
      if _len(d2) == 0:
        maxb = -1
      else:
        maxb = _max(d2.keys())
  print(result)
main()

Measured memory_bytes: 64728
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

//const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main(){
	vll A;
	for (int i = 0; i < 3; i++){
		ll a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end(), greater<int>());
	ll ans = 0;
	ans += A[0] - A[1];
	A[2] += ans;
	ll temp = A[0] - A[2];
	if (temp % 2 == 0){
		ans += temp / 2;
	}
	else{
		ans += temp / 2 + 2;
	}
	cout << ans << endl;	
}


Measured memory_bytes: 256
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
void solve()
{
   int N;cin>>N;
   cout<<(N+1)/2<<"\n";
   
}
int main()
{
   fastio
   solve();
  return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

vector<bool> seen;
vector<int> h;
int ans = 0;

void dfs(const Graph& G, int v)
{
    seen[v] = true;

    bool flag = true;
    for (auto next_v : G[v]) {
        if (h.at(v) <= h.at(next_v))
            flag = false;
        if (seen.at(next_v))
            continue;
        dfs(G, next_v);
    }
    if (flag)
        ans++;
}
int main()
{
    int n, m;
    cin >> n >> m;
    h.assign(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> h.at(i);
    }
    Graph G(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    seen.assign(n, false);
    for (int i = 0; i < n; i++) {
        if (seen[i] == false) { // どこかとはつながっている
            dfs(G, i);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 10900
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c=0, d[100000], e[100000],f=0, count = 0;
	char uc[100000];
	cin >> a>>b>>c;
	if (a == b) {
		cout << c << endl;
	}
	else if (b == c) {
		cout << a << endl;
	}
	else { cout << b << endl; }
		return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
typedef long long ll;
int arr[505][505], lst[505];
bool vis[100005];
int main()
{
	// freopen("TK1-D.in", "r", stdin);
	int n, k = 1;
	scanf("%d", &n);
	while (k * (k - 1) < 2 * n)
		k++;
	if (k * (k - 1) != 2 * n)
	{
		puts("No");
		return 0;
	}
	puts("Yes");
	printf("%d\n", k);
	int cur = 0;
	for (int i = 0; i < k; i++)
	{
		printf("%d ", k - 1);
		for (int j = 0; j < i; j++)
		{
			while (vis[arr[j][lst[j]]])
				lst[j]++;
			arr[i][j] = arr[j][lst[j]];
			vis[arr[i][j]] = true;
		}
		for (int j = i; j < k - 1; j++)
			arr[i][j] = ++cur;
		for (int j = 0; j < k - 1; j++)
			printf("%d%c", arr[i][j], " \n"[j + 1 == k - 1]);
	}
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    string s;
    cin >> s;
    int n = s.length();
    vector<int> cnt(3);
    forn(i, 0, n) ++cnt[s[i] - 'a'];
    forn(i, 0, 3) if (cnt[i] > (n + 2) / 3) {
        cout << "NO\n";
        return 0;
    }
    cout << "YES\n";
}


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define pb push_back
#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

void solve()
{
	ll n,m;
	cin>>n>>m;
	vector<vector<PLL>> arr(n+1,vector<PLL>());
	fr(i,0,m)
	{
		ll p,y;
		cin>>p>>y;
		arr[p].pb({y,i});
	}
	vector<string> ans(m,"");
	fr(i,1,n+1)
	{
		sort(ALL(arr[i]));
		//vector<PLL> tmp=arr[i];
		fr(j,0,arr[i].size())
		{
			string str(6,'0'),final="",str2(6,'0');
			ll idx=5;
			ll x=i;
			while(x)
			{
				str[idx]='0'+x%10;
				x/=10;
				idx--;
			}
			idx=5;
			x=j+1;
			while(x)
			{
				str2[idx]='0'+x%10;
				x/=10;
				idx--;
			}
			final=str+str2;
			ans[arr[i][j].S]=final;
		}
	}
	fr(i,0,m)
	{
		cout<<ans[i]<<"\n";
	}
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	solve();
	return 0;
}

Measured memory_bytes: 12416
#include <stdio.h>

int
main(void)
{
        int a, b;
        int x = 0;

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

        for (int i = 0; i < 2; i++) {
                if (a >= b) {
                        x += a;
                        a--;
                } else {
                        x += b;
                        b--;
                }
        }

        printf("%d", x);
}


Measured memory_bytes: 128
S = str(raw_input())

ans = 'NA'
pre = int(S[:2])
latter = int(S[2:])
flag1 = 0
flag2 = 0

if (1 <= latter) and (latter <= 12):
    flag1 = 1
if (1 <= pre) and (pre <= 12):
    flag2 = 1

if (flag1 == 1) and (flag2 == 1):
    ans = 'AMBIGUOUS'
elif (flag1 == 1):
    ans = 'YYMM'
elif (flag2 == 1):
    ans = 'MMYY'


print ans

Measured memory_bytes: 2568
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
 
char a[105], b[105];
 
int main()
{
	const int Y = 2016;
 
	int Test=1; while (Test--){
    scanf("%s%s", a, b);
    int n = strlen(a);
    bool ans = false;
    for(int i = 0; i < n; i++) {
      bool good = true;
      for(int j = 0; j < n; j++) good &= (a[j] == b[(i+j)%n]);
      if(good) {
        ans = true;
        break;
      }
    }
    puts(ans ? "Yes" : "No");
	}
 
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;

typedef long double db;
typedef long long ll;
typedef pair<db, db> pd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;


#define printlist(ans) for(auto x: ans) cout << x << ' '; cout << endl;
#define printstring(ans)  for(auto x: ans) cout << x; cout << endl;


#define mod 1000000007
#define maxn 100005

ll tst;
void cleanData();

ll n, m, k, a[maxn];

void solve() {
	cin >> n >> k;
	set<ll> st;
	for (ll i = 1; i <= n; i++)
	{
		st.insert(i);
	}
	
	for (ll i = 0; i < k; i++)
	{
		ll d;
		cin >> d;
		for (ll j = 0; j < d; j++)
		{
			ll x;
			cin >> x;
			st.erase(x);
		}
	}
	cout << st.size();
}

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

	tst = 1;
	//cin >> tst;
	while (tst--) {
		solve();
	}

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

void cleanData() {}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long int
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define inputv(a) forall(i,0,a.size()) cin>>a[i]
#define outputv(a) for(auto i:a) cout<<i<<" ";br;
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define br cout<<"\n"
using namespace std;
int dr[]={1,-1,0,0};
int dc[]={0,0,1,-1};
ll mod=1000000007;
ll po(ll x,ll n){
    ll res = 1;
    while(n>0){
        if(n%2==1)
            res = ((res)*(x));
        x = (x*x);
        n = n/2;
    }
    return res;
}
ll ceil(ll x,ll y)
{
    if(x%y==0)
        return x/y;
    else
        return(x/y)+1;
}
ll reverse(ll num)
{
     ll n, reversedNumber = 0, remainder;
     n=num;
    while(n != 0)
    {
        remainder = n%10;
        reversedNumber = reversedNumber*10 + remainder;
        n /= 10;
    }
    return reversedNumber;
}

int main(){
	 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll a[n];
    rep(i,0,n) cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    rep(i,0,k) ans+=a[i];
    cout<<ans;
    return 0;
}


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

int main()
{
    string M;
    cin >> M;
    int N=M.size();
    bool A=true;
    for(int i=0; i<N; i++)
    {
        if(!(M.at(i)==M.at(N-1-i)))
        {
            A=false;
        }
        if((i==(N-1-i))||(i==N/2))
        {
            break;
        }
    }
        for(int i=0; i<N; i++)
    {
        if(!(M.at(i)==M.at(((N-1)/2)-1-i)))
        {
            A=false;
        }
        if(i==(((N-1)/2)-1-i)||(N/4))
        {
            break;
        }
    }

    for(int i=0; i<N; i++)
    {
        if(!(M.at(((N+3)/2)-1+i)==M.at((N-1)-i)))
        {
            A=false;
        }
        if(((((N+3)/2)-1+i)==((N-1)-i))||N/4)
        {
            break;
        }
    }

    if(A==true)
    {
        cout << "Yes" <<endl;
    }
    else
    {
        cout << "No" <<endl;
    }
    
}

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

int main(void) {
	string s;
	cin >> s;
	char i = 'a';
	while (s.find(i) != -1) {
		i++;
	}
	if (i <= 'z') cout << i << endl;
	else cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const ll mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int main(){
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int ti;
	if(h1 < h2){
		ti = 60 - m1 + 60*(h2-h1-1) + m2;
	}else ti = m2 - m1;
	cout << ti-k << endl;
	return 0;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

template <class T, class F>
vector<T> cumulative_sum(size_t n, F f) {
    vector<T> acc(n+1);
    repeat (i,n) {
        acc[i+1] = acc[i] + f(i);
    }
    return acc;
}
template <class T, class F>
vector<vector<T> > cumulative_sum(size_t h, size_t w, F f) {
    vector<vector<T> > acc(h+1, vector<T>(w+1));
    repeat (y,h) {
        repeat (x,w) {
            acc[y+1][x+1] = acc[y+1][x] + f(y, x);
        }
    }
    repeat (y,h) {
        repeat (x,w+1) {
            acc[y+1][x] += acc[y][x];
        }
    }
    return acc;
}

int main() {
    int h, w, query; scanf("%d%d%d", &h, &w, &query);
    vector<vector<bool> > f = vectors(h, w, bool());
    repeat (y,h) {
        repeat (x,w) {
            char c; scanf(" %c", &c);
            f[y][x] = c != '0';
        }
    }
    auto g_hr = [&](int y, int x) { return x >= 1 and f[y][x-1] and f[y][x]; };
    auto g_vr = [&](int y, int x) { return y >= 1 and f[y-1][x] and f[y][x]; };
    auto g = [&](int y, int x) { return g_hr(y, x) + g_vr(y, x); };
    vector<vector<int> > acc = cumulative_sum<int>(h, w, [&](int y, int x) { return f[y][x] - g(y, x); });
    vector<vector<int> > hr(h); repeat (y,h) hr[y] = cumulative_sum<int>(w, [&](int x) { return g_vr(y, x); });
    vector<vector<int> > vr(w); repeat (x,w) vr[x] = cumulative_sum<int>(h, [&](int y) { return g_hr(y, x); });
    while (query --) {
        int ly, lx, ry, rx; scanf("%d%d%d%d", &ly, &lx, &ry, &rx); -- ly; -- lx; // [ly, ry) * [lx, rx)
        int result = 0;
        result += acc[ry][rx] - acc[ry][lx] - acc[ly][rx] + acc[ly][lx];
        result += hr[ly][rx] - hr[ly][lx];
        result += vr[lx][ry] - vr[lx][ly];
        printf("%d\n", result);
    }
    return 0;
}


Measured memory_bytes: 49536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int64_t CalcD(pair<int,int> X, pair<int,int> Y){
    return abs(X.first-Y.first)+abs(X.second-Y.second);
}

int main(){
    int H,W,D; cin>>H>>W>>D;
    vector<pair<int,int>> A(H*W);
    rep(h,0,H)rep(w,0,W){
        int a; cin>>a;
        A.at(a-1)=make_pair(h,w);
    }

    vector<int> Ans(H*W,0);
    rep(d,0,D){
        for(int i=d; i+D<H*W; i+=D){
            Ans.at(i+D)+=Ans.at(i)+CalcD(A.at(i),A.at(i+D));
        }
    }

    int Q; cin>>Q;
    rep(q,0,Q){
        int l,r; cin>>l>>r;
        l--; r--;

        int64_t ans=Ans.at(r)-Ans.at(l);
        cout<<ans<<endl;
    }
}

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

int main() {
	int a,b,k;
	cin >> a >> b >> k;
	int ct = 0;
	for(int i = 100;i > 0;i--)
	{
		if(a % i == 0 && b % i == 0)
		{
			ct++;
		}
		if(ct == k)
		{
			cout << i << endl;
			return 0;
		}
	}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

ll n;
ll ans = 0;

void dfs(ll idx, V sum) {
	ll v[3] = { 7, 5, 3 };
	ll num = 0;
	ll x = 1;
	bool is_used[3] = { false };

	if (idx != -1) {
		sum.push_back(idx);
	}

	if (sum.size() >= 3 ) {
		rep(i, sum.size()) {
			num += v[sum[i]] * x;
			x *= 10;
			is_used[sum[i]] = true;
		}
		
		if (is_used[0] && is_used[1] && is_used[2] && num <= n) {
			ans++;
		}

		if (num > n) {
			return;
		}
	}

	rep(i, 3) {
		dfs(i, sum);
	}
}

void solve_abc_c() {
	//ll n;
	//ll ans = 0;
	//float ans = 0;
	cin >> n;

	dfs(-1, V(0));

	cout << ans << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed;
	//cout << setprecision(7);

	solve_abc_c();

	return 0;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a=1,b,cnt=0;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++)cin>>v.at(i);
	for(int i=0;i<n;i++){
		cnt++;
		a=v.at(a-1);
		if(a==2){
			cout<<cnt<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn dfs(cn: usize, map: &Vec<Vec<usize>>, cnt: &mut usize, is_done: &mut Vec<bool>) {
    if is_done[cn] {
        return;
    }

    is_done[cn] = true;
    if is_done.iter().all(|&x| x == true) {
        *cnt += 1;
    }
    for i in &map[cn] {
        if is_done[*i] == true {
            continue;
        }
        let mut copy_done = is_done.clone();
        dfs(*i, map, cnt, &mut copy_done);
    }
}

fn main() {
    let n: i64 = read();
    println!("{}", n * 800 - (200 * (n / 15)))
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
using namespace std;
main()
{
	int a,b,c,s=0,t=0;
	while(~scanf("%d,%d,%d",&a,&b,&c))
	{
		if(a*a+b*b==c*c)s++;
		if(a==b)t++;
	}
	cout<<s<<endl<<t<<endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector <int64_t> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  int64_t min  = v.at(n-1);
  for (int i = 0; i+(k-1) < n; i++) {
    if (min > v.at(i+(k-1)) - v.at(i)) {
      min = v.at(i+(k-1)) - v.at(i);
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 1024
#include <cmath>
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

size_t max_len(uint64_t a, uint64_t b)
{
  return max(to_string(a).size(), to_string(b).size());
}

int32_t main()
{
  uint64_t N;
  cin >> N;

  uint64_t n = (uint64_t)sqrt(N);

  uint64_t m = UINT64_MAX;
  for (uint64_t i = 1; i <= n; i++) {
    if ((N % i) == 0) {
      m = min(m, max_len(i, N / i));
    }
  }
  cout << m << endl;

  return 0;
}


Measured memory_bytes: 256
/**
 * 
 */
import java.util.Scanner;

/**
 * @author Neeraj
 *
 */
 class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num=sc.nextInt();
		int res=num%10;
		switch(res) {
		case 2:			
		case 4:
		case 5:
		case 7:
		case 9:
			System.out.println("hon");
			break;
			
		case 0:
		case 1:
		case 6:
		case 8:
			System.out.println("pon");
			break;
		case 3:
			System.out.println("bon");
		}
		

	}

}


Measured memory_bytes: 35592
#include<stdio.h>
int main(void){
	int n,x,i,sum=0,cnt=1;
	int L[100];
	scanf("%d%d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&L[i]);
		sum+=L[i];
		if(sum<=x){
			cnt++;
		}
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 1736
#include <stdio.h>
#include <math.h>

int main(void)
{
	double x1, y1, x2, y2,distance;

	scanf("%lf %lf %lf %lf",&x1, &y1, &x2, &y2);

	distance = sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));

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

	return 0;
}


Measured memory_bytes: 2052
#include<cstdio>
#include<iostream>
using std::swap;
long long n,a,b,c,d;
int main(){
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	n--;
	if(a>b) swap(a,b);
	if(c>d) swap(c,d);
	long long dis=b-a,minl=c*n,maxl=d*n;
	long long nav=c-d-2*c,bav=d-c-2*d;
	for(int i=0;i<=n;i+=2){
		if(minl<=dis&&maxl>=dis){puts("YES");return 0;}
		minl+=nav;maxl+=bav;
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	
	while(cin >> n){
		if(n < 50)c++;
		cout << stop[n] << endl;
	}
	while(c>=5){return 1;};
	
}

Measured memory_bytes: 0
S=gets.chomp
K=gets.to_i
rle=S.chars.inject([]){|s,c|
	if s.empty? || s[-1][0]!=c then
		s << [c,1]
	else
		s[-1][1]+=1
	end
	s
}
ans=rle.map{|x|x[1]/2}.inject(:+)*K
if rle.size==1 then
	ans=S.size()*K/2
elsif rle[0][0]==rle[-1][0] then
	ans+=(rle[0][1]%2+rle[-1][1]%2)/2*(K-1)
end
p ans

Measured memory_bytes: 1788
#include<stdio.h>

int main(){
  int amount;
  long max=-2147483647,min=2147483647,sum=0;
  int input[10000];
  scanf("%d",&amount);
  for(int i=0;i<amount;i++){
    scanf("%d",&input[i]);
  }
  
  for(int i=0; i<amount; i++){
    if(input[i] > max)max=input[i];
    if(input[i] < min)min=input[i];
    sum += input[i];
  }
  printf("%ld %ld %ld\n",min,max,sum);
  return 0;
}



Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

int dp[3005][3005][2], n, m;

int f(int x, int g, int p){
	if(x == m) return p;
	if(~dp[x][g][p]) return dp[x][g][p];
	lint ret = 0;
	if(g < n) ret += f(x+1, g+1, p);
	if(g > 0) ret += f(x+1, g, p | (g == 1));
	if(g < n) ret += f(x+1, g, p);
	if(g > 0) ret += f(x+1, g-1, p | (g == 1));
	return dp[x][g][p] = ret % mod;
}

int main(){
	cin >> n >> m;
	memset(dp, -1, sizeof(dp));
	lint ret = 0;
	for(int i=0; i<=n; i++) ret += f(0, i, i == 0);
	cout << ret % mod;
}


Measured memory_bytes: 71040
N, M = map(int, input().split())

min_NM = min(N,M)
max_NM = max(N,M)

if min_NM == 1 and max_NM == 1:
    print(1)
elif min_NM == 1:
    print(max_NM-2)
else:
    if min_NM == 2:
        print(0)
    else:
        ans = (N-2)*(M-2)
        print(ans)


Measured memory_bytes: 3060