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

template<size_t max_N, size_t prime_size>
struct Prime{
    bool sieve[max_N];
    int_fast64_t prime[prime_size];
    size_t counter = 0;
    constexpr Prime() : sieve(), prime() {
        for(int_fast64_t i = 0; i < max_N; ++i)
            sieve[i] = true;
        for(int_fast64_t i = 2; i < max_N; ++i){
            if(sieve[i] && i % 5 == 2){
                prime[counter] = i;
                ++counter;
                if(counter > prime_size)break;
            }
            for(int_fast64_t j = i * i; j < max_N; j += i)
                sieve[j] = false;
        }
    }
};

constexpr auto p = Prime<55555, 6000>();

long long int N;

int main(){

    scanf("%lld", &N);
    for(int i = 0; i < N; ++i)cout << p.prime[i] << " ";
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=100005;
const int P=998244353;

int n,m;
int per[N];
int p[N],ans;

int find(int x){
	if(p[x]==0) return x;
	return p[x]=find(p[x]);
}

inline void onion(int x,int y){
	x=find(x); y=find(y);
	if(x==y) return ;
	p[x]=y;
}

void init(){
	int x1,x2;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&per[i]);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x1,&x2);
		onion(x1,x2);
	}
	for(int x=1;x<=n;x++) if(find(x)==find(per[x])) ans++;
	//for(int x=1;x<=n;x++) printf("%d\n",find(x));
	printf("%d\n",ans);
}

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

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
A - AtCoder Beginner Contest 999
https://atcoder.jp/contests/abc111/tasks/abc111_a

"""
import sys


def solve(n):
    return n.translate(str.maketrans('19', '91'))


def main(args):
    n = input()
    ans = solve(n)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    string s;
    int k;
    vector<string> vs;
    cin >> s;
    cin >> k;
    int size = s.size();
    vs.reserve(size*k);
    for(int i=0;i<size;i++){
        for(int j=1;j<=min(k,size-i);j++){
            vs.push_back(s.substr(i,j));
        }
    }
    sort(vs.begin(),vs.end());
    unique(vs.begin(),vs.end());
    cout << endl;
    cout << vs[k-1] << endl;
    return 0;
}

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

using Int = long long;

int main() {    
    Int n;
    cin >> n;
    
    Int ans = 0;
    
    for (Int i = 1; i <= n; ++i) {
        if (i % 3 && i % 5) ans += i;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3636
using System;
using System.Linq;

namespace AtCoderContest
{
    class Program
    {
        static void Main()
        {
            var (k, x) = ReadLineAsInt();

            var answer = Enumerable.Range(-100000, 200001)
                                   .Where(i => i > x - k && i < x + k)
                                   .Aggregate("", (ans, i) => ans + i + " ")
                                   .Trim(' ');
            Console.WriteLine(answer);
        }
        static (int, int) ReadLineAsInt()
        {
            var line = Console.ReadLine();
            var ts = line.Split(" ").Select(int.Parse).ToList();
            return (ts[0], ts[1]);
        }
    }
}


Measured memory_bytes: 28532
#include <bits/stdc++.h>
using namespace std;
int a[110];
int ans1, ans2;
int main(){
  int x, y;
  cin >> x >> y;
  if(y == 0)
  {
    cout << x;
    return 0;
  }
  for(int i = 0;i < y;i++)
  {
    cin >> a[i];
  }
  sort(a, a + y);
  for(int i = 0;i != -1;i++){
    if(binary_search(a, a+y, x + i) == false){
      ans1 = x + i;
      break;
    }
  }
  for(int i = 0;i != -1;i++){
    if(binary_search(a, a+y, x - i) == false){
      ans2 = x - i;
      break;
    }
  }
  if(fabs(ans2 - x) <= fabs(ans1 - x)){
    cout << ans2;
    return 0;
  }
  cout << ans1;
  return 0;
}

Measured memory_bytes: 3632
h,w = map(int,input().split())
gaze = ["W"+input()+"W" for _ in range(h)]
gaze = ["W"*(w+2)]+gaze+["W"*(w+2)]

for i in range(1,h+1):
    for j in range(1,w+1):
        count = 0
        if gaze[i][j] == ".":
            if gaze[i-1][j-1] == "#":
                count += 1
            if gaze[i-1][j] == "#":
                count += 1
            if gaze[i-1][j+1] == "#":
                count += 1
            if gaze[i+1][j-1] == "#":
                count += 1
            if gaze[i+1][j] == "#":
                count += 1
            if gaze[i+1][j+1] == "#":
                count += 1
            if gaze[i][j-1] == "#":
                count += 1
            if gaze[i][j+1] == "#":
                count += 1
            gaze[i] = gaze[i][:j]+str(count)+gaze[i][j+1:]

for i in range(1,h+1):
    for j in range(1,w+1):
        if j == w:
            print(gaze[i][j])
        else:
            print(gaze[i][j],end="")


    

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;

int n;

int main()
{
    cin>>n;
    cout<<(n-2)*180<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  int N;
  cin >> N;
  vector<int> ans(10000000);
  for(int i = 1; i < 1000; i++){
    for(int j = 1; j < 500; j++){
      for(int t = 1; t < 500; t++){
        int x = i*i + j*j + t*t + i*j + j*t + t*i;
        if(x <= N){
          ans[x]++;
        }
      }
    }
  }
  for(int i = 1; i <= N; i++){
    cout << ans[i] <<endl;
  }
}


Measured memory_bytes: 42200
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 205;
int n;
char tmp[maxn];
vector<int> g[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    g[i].clear();
    scanf("%s", tmp);
    for (int j = 0; j < n; j++) {
      if (tmp[j] == '1') {
        g[i].push_back(j);
      }
    }
  }
  return true;
}

int col[maxn];

bool dfs(int v) {
  for (int i = 0; i < sz(g[v]); i++) {
    int u = g[v][i];
    if (col[u] != -1) {
      if (col[u] == col[v]) {
        return false;
      }
      continue;
    }
    col[u] = (col[v] ^ 1);
    if (!dfs(u)) {
      return false;
    }
  }
  return true;
}

int d[maxn];
vector<int> q;

void solve() {
  for (int i = 0; i < n; i++) {
    col[i] = -1;
  }
  col[0] = 0;
  if (!dfs(0)) {
    printf("-1\n");
    return;
  }
  int res = 0;
  for (int s = 0; s < n; s++) {
    q.clear();
    for (int i = 0; i < n; i++) {
      d[i] = inf;
    }
    d[s] = 0;
    q.push_back(s);
    for (int l = 0; l < sz(q); l++) {
      int v = q[l];
      res = max(res, d[v] + 1);
      for (int i = 0; i < sz(g[v]); i++) {
        int u = g[v][i];
        if (d[v] + 1 < d[u]) {
          d[u] = d[v] + 1;
          q.push_back(u);
        }
      }
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 512
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> p(n);
	rep(i, n) {
		cin >> p[i].first >> p[i].second;
	}

	int sum = 0;
	rep(i, n) {
		sum += (p[i].second + 1 - p[i].first);
	}
	cout << sum << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    mat c(3,vec(3));
    rep(i,3) rep(j,3) cin>>c[i][j];
    bool yes = true;
    rep(i,2){
        if((c[i+1][0] - c[i][0] != c[i+1][1] - c[i][1]) ||(c[i+1][2] - c[i][2] != c[i+1][1] - c[i][1])) yes = false;
    }
    rep(j,2){
        if((c[0][j+1] - c[0][j] != c[1][j+1] - c[1][j]) ||(c[2][j+1] - c[2][j] != c[1][j+1] - c[1][j])) yes = false;
    }
    cout<<(yes ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,x,m,c=0,v,ans=0;
  cin >> n >> x >> m;
  vector<ll> pr(m,-1);
  v = x;
  ll pre=x;
  while(true){
    pre = v;
    v = (v*v)%m;
    if(pr[v]!=-1){
      break;
    }
    pr[v] = c;
    c++;
  }
  ll pv = v,loop_c=c-pr[v],sum;
  v = (v*v)%m;
  sum = v;
  while(v!=pv){
    v = (v*v)%m;
    sum = (sum+v);
  }
  ll val = x;
  ans = x;
  n--;
  while(n!=0){
    val = (val*val)%m;
    if(val==v&&n>=loop_c){
      ans = (ans+(n/loop_c)*sum);
      n -= (n/loop_c)*loop_c;
      val = pre;
    }else{
      ans = (ans+val);
      n--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3988
let words str =
  let len = String.length str in
  let buf = Buffer.create 8 in
  let rec aux i l =
    if i >= len then List.rev (Buffer.contents buf :: l)
    else 
      match str.[i] with
      | ' ' ->
        let s = Buffer.contents buf in
        Buffer.clear buf;
        aux (i+1) (s :: l)
      | c   ->
        Buffer.add_char buf c;
        aux (i+1) l
  in
  aux 0 []
    
let () =
  let _ = read_int () in
  let nums  = List.map int_of_string (words (read_line ())) in
  let mi = List.fold_left (fun acc n -> min acc n) max_int nums in
  let ma = List.fold_left (fun acc n -> max acc n) min_int nums in
  let sum = List.fold_left (fun acc n -> acc + n) 0 nums in
  print_endline (Printf.sprintf "%d %d %d" mi ma sum)

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<std::pair<i64, i64>> v;
    for (int i = 0; i < n; i++) {
        int a, b;
        std::cin >> a >> b;
        v.emplace_back(b, a);
    }
    std::sort(v.begin(), v.end());
    i64 t = 0;
    for (int i = 0; i < n; i++) {
        t += v[i].second;
        if (t > v[i].first) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 6564
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

using VB = vector<bool>;
#define P_N 55555

vector<bool> primes_create(int n){
	vector<bool> p(n+1, true);
	p[0] = p[1] = false;
	for(int i=2; i*i<=n; ++i)
		if(p[i]) for(int j=i+i; j<=n; j+=i) p[j] = false;
	return p;
}

int main(){
	int N; cin>>N;
	VB P = primes_create(P_N);
	vi ans;
	for(int p=11; p<P.size(); p+=10){
		if(!P[p]) continue;
		if(p < 10) continue;
		if(p%5 != 1) continue;
		ans.push_back(p);
		if(ans.size() == N) break;
	}
	for(auto a:ans) cout<<a<<" ";
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
    int n=1;
    cin >> n;
    switch(n%10){
        case 3: cout << "bon" << endl;break;
        case 0:
        case 1:
        case 6:
        case 8: cout << "pon" << endl;break;
        default: cout << "hon" << endl;break;
    }
}

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

#define N 5005
typedef long long ll;

int n, A, B;
int a[N], b[N], s[N], g[N][N];
ll dp[N];

int main() {
    scanf("%d %d %d", &n, &A, &B);
    for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i ++) {
        int j = i-1;
        while (j>0&&a[j]<a[i]) j = b[j];
        b[i] = j;
    }
    for (int i = 1; i <= n; i ++) {
        int j = i-1;
        while (j>0&&a[j]>a[i]) j = s[j];
        s[i] = j;
    }
    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j <= n; j ++) g[i][j] = g[i-1][j];
        for (int j = a[i]; j <= n; j ++) g[i][j] ++;
    }
    ll ans = 1e18;
    dp[0] = 0;
    for (int i = 1; i <= n; i ++) {
		dp[i] = 1e18;
        for (int j = 0; j < i; j ++) if (a[j] < a[i]) {
            int x = g[i-1][a[i]-1] - g[j][a[i]-1];
            dp[i] = min(dp[i], dp[j] + 1ll * x * B + 1ll * (i-j-1-x) * A);
        }
        ans = min(ans, dp[i]+1ll*(n-i)*B);
    }
    printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 98176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(a,j,n) for(ll i=a;i<j;i=i+n )
typedef pair<ll,ll> P;
const ll mod = 1000000007;
const ll INF = 1000000009;
ll i;

int main(){
    V v(3);
    rep(0,3,1)cin>>v.at(i);
    sort(v.begin(),v.end());
    if(v==V{5,5,7})cout<<"YES";
    else cout<<"NO";
    cout<<endl;
}



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.length();
	REP(i, n) {
		int flag = 1;
		REP(j, n) {
			if (s[j] != t[(i + j) % n])flag = 0;
		}
		if (flag) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib> //func147bでインクルード
#include <vector>  //func146b
 
using namespace std;
 
void func144b()
{
    int n;
    cin >> n;
    string m = "No";
    for (int i = 1; i < 10; ++i) {
        if (n % i == 0 && (n /i) <10) {
            m = "Yes";
            }
    }
    cout << m << endl;
}
 
int main()
{
  func144b();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;
 

 
const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	string str;
	while(cin >> str){
		int s = str.size();
		
		if(s == 0 || s == 1){
			cout << 0 << endl;
		}
		else{
			int r=0;
			for(int i=1;i<s;i++){
				if(str[i]!=str[i-1]){
					r++;
				}
			}
			cout << r << endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 640
x,n=map(int,input().split())
p=list(map(int,input().split()))
if n==0:
    print(x)
    exit()

px=[]
for i in range(n):
    #abs_px.append(abs(p[i]-x))
    px.append(p[i]-x)
k=0
cnt=0
while cnt<n:
    px.append(k)
    if px.index(k) == n:
        print(x+k)
        break
    else:
        px.pop(n)
        cnt+=1
        if k>=0:
            k=-1*(k+1)
        else:
            k*=-1
        if cnt==n:
            print(x+k)
    
    

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
const int mod = 1000000007;
struct mint
{
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }
    mint inv() const
    {

        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
};
struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1)
    {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; i++)
        {
            fact[i] = fact[i - 1] * i;
        }
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
        {
            ifact[i - 1] = ifact[i] * i;
        }
    }
        mint operator()(int n, int k)
        {
            if (k < 0 || k > n)
                return 0;
            return fact[n] * ifact[k] * ifact[n - k];
        }
};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    mint ans = 0;
    combination c(n + 4);
    rep(i,n){
        mint now = c(i, k - 1); //iCk-1 k-1>i = 0
        ans += now * a[i];
    }
    reverse(a.begin(), a.end());
    rep(i, n)
    {
        mint now = c(i, k - 1); //iCk-1 k-1>i = 0
        ans -= now *a[i];
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 2176
<?php
fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%d", $K);
$arr = str_split($S);
$target = $arr[$K - 1];
echo implode("", array_map(function($c)use($target){return ($c === $target) ? $c : '*'; }, $arr));


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

int M,N;
string S[130];

int dp[(1<<11)][(1<<11)];


bool check(int st,int fr){
  int mem[130]={};
  int n = __builtin_popcount(st);
  for(int i=0;i<M;i++){
    if( st & (1<<i) ) {
      for(int j=0;j<N;j++){
	if( S[j][i] == '0' && !(fr & (1<<i)) ){
	  mem[j]++;
	} else if( S[j][i] == '1' && (fr & (1<<i) ) ) {
	  mem[j]++;
	}
      }
    }
  }
  int cnt=0;
  for(int j=0;j<N;j++){
    if( mem[j] == n ) cnt++;
  }
  if( cnt == 1 ) return true;
  return false;
}

int solve(int st,int fr){
  if( dp[st][fr] != -1 ) return dp[st][fr];
  if( st>0 && check(st,fr) ) return dp[st][fr] = 0;
  if( st == (1<<M) - 1 ) return dp[st][fr] = 0;
  int ret = 100000;
  for(int i=0;i<M;i++){
    if( (st&(1<<i)) ) continue;
    ret = min( ret,
	       max( solve(st|(1<<i),fr|(1<<i))+1,
		    solve(st|(1<<i),fr)+1 ) );
  }
  return dp[st][fr] = ret;
}

int main() {
  while( cin >> M >> N && ( M||N ) ){
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<N;i++) cin >> S[i];
    if( N == 1) cout << 0 << endl;
    else cout << solve( 0, 0 ) << endl;
  }
}

Measured memory_bytes: 17612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        var inputs = new int[10];
        foreach (var i in Enumerable.Range(0, inputs.Length))
        {
            inputs[i] = int.Parse(Console.ReadLine());
        }

        foreach (var x in inputs.OrderByDescending(x => x).Take(3))
        {
            Console.WriteLine(x);
        }


    }
}

Measured memory_bytes: 10128
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cstdio>
using namespace std;

vector<long long int> p;
vector<long long int> p2;

int main(void){
	int a,b,n,m;
	while(1){
		long long int ans=0;
		scanf("%d%d",&n,&m);
		if(n==0 && m==0)break;
		p.clear();
		p2.clear();
		for(a=0;a<n;a++){
			int num;
			scanf("%d",&num);
			p.push_back(num);
		}
		sort(p.begin(),p.end());
		p2.push_back(0);
		for(a=0;a<n;a++){
			p2.push_back(p[a]);
			for(b=0;b<n;b++){
				p2.push_back(p[a]+p[b]);
			}
		}
		p2.push_back(0);
		sort(p2.begin(),p2.end());
		for(a=0;a<p2.size();a++){
			long long int res=m-p2[a];
			if(m-p2[a]<0)continue;
			long long int pp=*(lower_bound(p2.begin(),p2.end(),res)-1);
			if(ans<pp+p2[a])ans=pp+p2[a];
			//cout << pp+p2[a] << endl;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 10568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string s;
  ll n, m;
  cin >> n >> m;
  
  //vector<int> a(n);  rep(i, 0, n) cin >> a.at(i);
  
  cout << n*(n-1)/2 + m*(m-1)/2 << "\n";
  
  //cout << fixed << setprecision(10) << n << "\n";

}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  int mx_a = 0, mn_b;
  while (n--) {
    int a, b; cin >> a >> b;
    if (mx_a < a) {
      mx_a = a;
      mn_b = b;
    }
  }
  cout << mx_a + mn_b << '\n';
  return 0;
}


Measured memory_bytes: 256
x,k,d=map(int,input().split())
if x>0:
  if x-k*d>=0:
    print(x-k*d)
  else:
    t=x%d
    if (int((x-t)/d))%2==(k%2):
      print(t)
    else:
      print(d-t)
    
elif x<0:
  if x+k*d<=0:
    print(-(x+k*d))
  else:
    t=(-x)%d
    if (int((-x-t)/d))%2==(k%2):
      print(t)
    else:
      print(d-t)
else:
  if k%2==0:
    print(0)
  else:
    print(d)
    
    


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

bool is_prime[2000000];

int a[2000000];
vector<int>v[2000000];

int main(){
	memset(is_prime,true,sizeof(is_prime));
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<2000000;i++){
		if(!is_prime[i])continue;
		v[i].push_back(i);
		for(int j=2*i;j<2000000;j+=i){
			is_prime[j]=false;
			v[j].push_back(i);
		}
	}
	int n;cin>>n;
	int g=0;
	unordered_map<int,int>mp;
	rep(i,n){
		scanf("%d",&a[i]);
		g=gcd(g,a[i]);
		for(int u:v[a[i]]){
			mp[u]++;
		}
	}
	bool ok=true;
	for(auto p:mp){
		if(p.second!=1)ok=false;
	}
	if(ok)puts("pairwise coprime");
	else if(g==1)puts("setwise coprime");
	else puts("not coprime");
}

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

typedef long long ll;
using namespace std;

int main(){

	int n,k;
	cin >> n;// >> k;
	k = 3;
	vector< vector<int> > happ(n, vector<int>(k));
	int INF = 1<<30;

	for(int i=0;i<n;++i)
		for(int j=0;j<k;++j)
			cin >> happ[i][j];

	//dp[i][j] es la mayor felicidad del dia i con la actividad anterior j
	vector< vector<int> > dp(1+n, vector<int>(k,0));

	for(int i=0;i<k;++i){
		/*int maxi = 0;
		for(int j=0;j<k;j++){
			if(i!=j)
				maxi = max(maxi, happ[0][j]);
		}*/
		dp[0][i] = 0;
	}




	for(int day=1;day<=n;++day){
		for(int i=0;i<k;++i){
			for(int j=0;j<k;++j){
				if(i!=j){
					dp[day][j]=max(dp[day][j],dp[day-1][i]+happ[day-1][j] );
					//cout << "day " << day << " i " << i << " j " << j << " dp "  << dp[day][j] << endl;
				}
			}
		}
	}

	int maxi = -INF;
	for(int i=0;i<k;++i){
		maxi = max(maxi,dp[n][i]);
	}
	cout << maxi << endl;

	/*for(int i=0;i<n;++i){
		for(int j=0;j<k;j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/





	return 0;
}


Measured memory_bytes: 11136
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		ArrayList<Integer> numlist = new ArrayList<Integer>();

		numlist.add(2);
		for (int i = 3; i < 123457*2; i += 2) {
			boolean TF = true;
			for (Integer integer : numlist) {
				if (integer * 2 > i) {
					break;
				}
				if ((i % integer) == 0) {
					TF = false;
					break;
				} else {
					continue;
				}
			}
			if (TF) {
				numlist.add(i);
			}
		}

		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			int count = 0;
			for (Integer integer : numlist) {
				if (n < integer) {
					if (integer <= 2 * n) {
						count++;
					} else {
						break;
					}
				}
			}
			System.out.println(count);
		}

	}

}

Measured memory_bytes: 28276
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n);
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); ++i)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)          (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)          (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define mp                  make_pair

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

int check(int n, int s, vector<string> &v){
    FOREACH(it, v){
        if(s-2 >= 0 && (*it)[s-2] == '1'){
            s--; continue;
        }
        if(s-1 < n-1 && (*it)[s-1] == '1'){
            s++; continue;
        }
    }
    return s;
}

void solve(int n, int s, int g, int d, vector<string> &v){
    if(g == check(n, s, v)){
        cout << 0 << endl;
        return;
    }
    REP(i,d){
        REP(j,n-1){
            bool flag = true;
            REPEAT(k,-1,3){
                int l = j+k;
                if(l < 0 || l >= n-1) continue;
                if(v[i][l] == '1') flag = false;
            }
            if(!flag) continue;

            v[i][j] = '1';
            if(g == check(n, s, v)){
                cout << i+1 << " " << j+1 << endl;
                return;
            }
            v[i][j] = '0';
        }
    }
    cout << 1 << endl;
}

int main(){
    while(1){
        int n, m, g, d;
        cin >> n;
        if(n == 0) break;
        cin >> m >> g >> d;
        string s;
        vector<string> v;
        REP(i,d){
            cin >> s;
            v.push_back(s);
        }
        solve(n,m,g,d,v);
    }
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>

using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int ans=0;
    for(int i=1; i<=n; i++){
        int tmp=i/10000+(i%10000)/1000+(i%1000)/100+(i%100)/10+(i%10);
        if(tmp>=a && tmp<=b){
            ans+=i;
        }
    }
    cout << ans;
    
    return 0;
}

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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	ll k;
	cin >> k;
	ll s = 0;
	for (ll a = 1; a <= k; a++)
		for (ll b = 1; b <= k; b++)
			for (ll c = 1; c <= k; c++)
				s += __gcd(a, __gcd(b,c));
	cout << s << ende;
  return 0;
}


Measured memory_bytes: 3612
// ABC099_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

#define zero_pad(num) setfill('0') << right << setw(num)
#define space_pad(num) setfill(' ') << right << setw(num)

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N;
    cin >> N;
    
    // calculation
    if (N <= 999) {
        cout << "ABC" << "\n";
    } else {
        cout << "ABD" << "\n";
    }
    
    return 0;
}

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

using namespace std;

const int N = 1e5+2;
vector<int>G[N],v;
int n,m;
bool odw[N];
int dp[N];


void toposort(int start){

    odw[start] = true;

    for (int next:G[start]){
        if (!odw[next]) toposort(next);
    }

    v.push_back(start);
}



int main(){
    ios_base::sync_with_stdio(0);

    cin >> n >> m;

    int a,b;
    for (int i=0; i<m; i++){

        cin >> a >> b;
        G[a].push_back(b);
    }

    for (int i=1;i<=n;i++){

        if (!odw[i]) toposort(i);
    }

    reverse(v.begin(),v.end());

    int maks=0;

    for (int i:v){

        for (int next:G[i]){

            dp[next] = max(dp[next], dp[i]+1);
        }
        maks=max(maks,dp[i]);
    }

    cout << maks;

}

Measured memory_bytes: 8824
#include <iostream>
#include <vector>
using namespace std;
int s[20], h[20], c[20], d[20];

int main( void ) {
    int n, num;
    char ch;
    cin >> n;
    for( int i = 0; i < n; ++i ) {
        cin >> ch >> num;
        switch( ch ) {
            case 'S': s[num] = 1; break;
            case 'H': h[num] = 1; break;
            case 'C': c[num] = 1; break;
            case 'D': d[num] = 1; break;
        }
    }
    for( int i = 1; i <= 13; ++i ) if( !s[i] ) cout << "S " << i << '\n';
    for( int i = 1; i <= 13; ++i ) if( !h[i] ) cout << "H " << i << '\n';
    for( int i = 1; i <= 13; ++i ) if( !c[i] ) cout << "C " << i << '\n';
    for( int i = 1; i <= 13; ++i ) if( !d[i] ) cout << "D " << i << '\n';
    return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

#define P 1000000007

using namespace std;

int main() {
  int n;
  vector<long long> a;
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int t = 0, f = 0;
  for(int i = 0; i < n; i++) {
    if(a[i] % 4 == 0){ f++;
      continue;
    }
    if(a[i] % 2 == 0) t++;
  }
  if(n - f - t <= f) {
    cout << "Yes" << endl;
  } else {
    if(t == 0 && n - f - 1 <= f) {
      cout << "Yes" << endl;
    } else
      cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    map<ll, ll, greater<ll>> mp;
    rep(i, n) {
        ll m; cin >> m;
        mp[m]++;
    }

    ll v;
    ll count = 0;
    for (auto elem : mp) {
        if (elem.second > 3 && count == 0) {
            cout << elem.first * elem.first << endl;
            return 0;
        }
        if (elem.second > 1) {
            if (count == 0) {
                v = elem.first;
                count++;
            } else {
                cout << v * elem.first << endl;
                return 0;        
            }
        }
    }
    cout << 0 << endl;
    
    return 0;
}

Measured memory_bytes: 6528
h,w=map(int,input().split())
c=[list(map(int, input().split())) for _ in range(10)]
A=[list(map(int, input().split())) for _ in range(h)]
o=[c[i][1] for i in range(10)]#初期状態として各iから直接1にいく場合の魔力を入れる
#print(c)
ans=0
#print(o)
for _ in range(5):#o[i],o[j]は更新されていくので、最低10回は回す（最長移動距離が10のため）
    for i in range(10):
        for j in range(10):
            o[i]=min(o[i],c[i][j]+o[j])#例えば4から1に行く場合、直接行くと9かかるが、4→9→1といくと4で済む。
    #print(o)
    
for s in range(h):
    for t in range(w):
        if A[s][t]!=-1:
            ans+=o[A[s][t]]
print(ans)

Measured memory_bytes: 3316
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	ll a[200] = {};
	ll b[200] = {};
	ll v[3] = {};
	//ll *a, *b, *x;
	string S,T,U[52];
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	vector<int> c(3);
	//char p;


	

	

	//cin >> S;
	
	//a = (ll *)malloc(M * sizeof(ll));
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(50);

	//vector<bool> flag(N);
	
	cin >> N;
	/*rep(i, 0, M) {
		cin >> ch[i].first >> ch[i].second;
	}*/
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;



	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	if(N <= 111)
	cout << 111 << endl;
	else if (N <= 222)
		cout << 222 << endl;
	else if(N <= 333)
		cout << 333 << endl;
	else if(N <= 444)
		cout << 444 << endl;
	else if(N <= 555)
		cout << 555 << endl;
	else if(N <= 666)
		cout << 666 << endl;
	else if(N <= 777)
		cout << 777 << endl;
	else if(N <= 888)
		cout << 888 << endl;
	else if (N <= 999)
		cout << 999 << endl;


	return 0;

}

ll gcd(ll a, ll b) {
	ll c;
	c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}

	return b;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(void) {
    int n;
    cin >> n;
    int max = 0, sum = 0;;
    for(int i = 0 ; i < n ; ++i) {
        int l;
        cin >> l;
        sum += l;
        if (max < l) {
            max = l;
        }
    }
    sum -= max;
    cout << (max < sum ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
points = [0, 0]
for i in range(n):
    cards = input().split()
    c0, c1 = len(cards[0]), len(cards[1])
    c = min(c0, c1)
    for i in range(c):
        if cards[0][i] > cards[1][i]:
            points[0] += 3
            break
        elif cards[0][i] < cards[1][i]:
            points[1] += 3
            break
    else:
        if c0 > c1:
            points[0] += 3
        elif c0 < c1:
            points[1] += 3
        else:
            points[0] += 1
            points[1] += 1
print(points[0], points[1])


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

int main() {
  ll n, d;
  cin >> n >> d;

  int c = 0;
  
  for (int i = 0; i < n; i++) {
      ll x;
      ll y;
      cin >> x >> y;
      if (x*x+y*y <= d*d) {
          c++;
      }
  }


  cout << c << endl;

}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define fo(i) for(int i=0;i<=(1e7);++i)
#define Fo(i,k,n) for(int i=k;i<n;++i)
typedef long long int lli;
int main(){
    FIO
    int i,k; cin>>k;
    int total=0;
    int flag=0;
    fo(i){
        total=(total*10+7)%k;//appending the number by 7
        if(total==0)
            {
                cout<<i+1<<endl;
                flag=1;
                break;
            }
    }
      if(flag==0){
            cout<<-1<<endl;
    }
}




Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(), w = sc.nextInt(), d = sc.nextInt();
		int[][] num = new int[h][w];
		int[] index = new int[h*w+1];
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				num[i][j] = sc.nextInt();
				index[num[i][j]] = w*i+j;
			}
		}
		int p[] = new int[h*w+1];
		for(int i = 1; i <= h*w-d; i++) {
			p[i] = Math.abs(index[i]/w-index[i+d]/w) + Math.abs(index[i]%w-index[i+d]%w);
		}
		for(int i = h*w-d; i >= 0; i--) {
			p[i] += p[i+d];
		}
		int q = sc.nextInt();
		for(int i = 0; i < q; i++) {
			System.out.println(p[sc.nextInt()] - p[sc.nextInt()]);
		}
	}
}

Measured memory_bytes: 94068
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<stack>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
#define MAX 510000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;

int A[1000000],n;

int binarySearch(int key){
    int left=0,right=n,mid;
    while(left<right){
        mid=(left+right)/2;
        if(key==A[mid]) return 1;
        if(key>A[mid]) left=mid+1;
        else if(key<A[mid]) right=mid;
    }
    return 0;
}

int main(){
    int i,q,k,sum=0;
    
    scanf("%d",&n);
    REP(i,n) scanf("%d",&A[i]);
    
    scanf("%d",&q);
    REP(i,q){
        scanf("%d",&k);
        if(binarySearch(k)) sum++;
    }
    printf("%d\n",sum);
    
    return 0;
}


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

using namespace std;

const int MOD = 1000000007;
const int MAX32 = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (b > a * c) {
    cout << c << endl;
  } else {
    cout << b / a << endl;
  }
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 100100

bitset<2300> bs;
vi primes;
vi cubes;
ll N;
ll A[MAXN];
ll ans;
map<ll, pi> M;
ll B[MAXN];

int main(){
	bs.set();
	for (ll i=2;i<=2200;++i)if (bs[i]){
		primes.pb(i);
		for (ll j=i*i;j<=2200;j+=i)bs[j] = 0;
	}
	for (auto i:primes)cubes.pb(i*i*i);
	cin>>N;
	for (ll i=1;i<=N;++i){
		cin>>A[i];
		for (auto x:cubes)while(A[i]%x == 0)A[i] /= x;
		ll t = A[i];
		for (auto i:primes)while(t%i == 0)t /= i;
		if (t == 1)continue;
		// Only way to not bust is if t is a square number or a prime number
		ll rt = floor(sqrt(t));
		if (rt * rt == t){
			B[i] = rt;
		}else if (t > 100000){
			++ans;
			A[i] = 0;
		}else{
			B[i]=A[i]*A[i];
		}
	}
	ll ones = 0;
	for (ll i=1;i<=N;++i)if(A[i]){
		if (A[i] == 1){++ones;continue;}
		ll opp = 1;
		ll act = A[i];
		for (auto j:primes){
			if (A[i] % (j*j) == 0)opp *= j, A[i] /= (j*j);
			else if (A[i] % j == 0)opp *= j*j, A[i] /= j;
		}
		if (A[i] != 1){
			assert(B[i] != 0);
			opp*=B[i];
		}
		assert(opp != act);
		if (opp > act){
			M[act].f++;
		}else{
			M[opp].s++;
		}
	}
	for (auto i : M)ans += max(i.s.f,i.s.s);
	if (ones)++ans;
	cout<<ans;
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<cstring>
#define maxn 2007
#define SDOI2020 RP++ 
using namespace std;
char s1[maxn],s2[maxn],s3[maxn]; 
inline int read()
{
	int x=0;
	int flag=0;
	char ch;
	ch=getchar();
	while(!isdigit(ch)) 
	{
		if(ch=='-') flag=1;
	ch=getchar();	
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
		}
		if(flag==1) x=-x;	
		return x;
}

inline int check(string ss)
{
	string q = ss;
	reverse(q.begin(),q.end());
	return ss == q;
}


int main()
{
	scanf("%s",s1 + 1);
	int len = strlen(s1 + 1);
	for(register int i = 1;i <= len / 2;i++)
	{
		s2[i] = s1[i];
		s3[i] = s1[i + len / 2 + 1];
	}
	
	if(check(s1 + 1) && check(s2 + 1) && check(s3 + 1))
	{
		printf("Yes\n");
	}
	else printf("No\n");
	return 0;
} 

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

int main() {
	int t;
	cin >> t;
	long long ans = 0;
	if (t >= 500) {
		ans += (t / 500) * 1000;
		t %= 500;
	}
	if (t >= 5) {
		ans += (t / 5) * 5;
	}
	cout << ans;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main{
	
	public static void main(String[] args){
	
	MyScanner sc = new MyScanner();
	out = new PrintWriter(new BufferedOutputStream(System.out));
	
	/**/

	String s = sc.next();
	String t = sc.next();
	int counter = 0;
	int min = t.length();
	
	for(int i = 0; i <= s.length() - t.length(); i++){
		
		for(int i2 = 0; i2 < t.length(); i2++){
			
			if(s.charAt(i + i2) == t.charAt(i2)){
				
			}else{
				counter++;
			}
				
		}
		
		min = Math.min(counter, min);
		counter = 0;
	}
	
	System.out.println(min);
	
	/**/
	 
	 out.close();	
	}
	
	
	
	public static PrintWriter out;
	
	public static class MyScanner{
		
		BufferedReader br;
		StringTokenizer st;
		
		public MyScanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
	
}


Measured memory_bytes: 32984