akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

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

    string n;
    cin >> n;
    int k;
    cin >> k;
    int m = n.size();
    vector<vector<vector<ll>>> dp(m + 1, vector<vector<ll>>(5, vector<ll>(2)));
    dp[0][0][1] = 1;
    rep(i, 0, m) {
        rep(j, 0, 4) {
            dp[i + 1][j][0] += dp[i][j][0];
            dp[i + 1][j + 1][0] += dp[i][j][0] * 9ll;
        }
        int t = n[i] - '0';
        if (t) {
            rep(j, 0, 4) {
                dp[i + 1][j + 1][1] += dp[i][j][1];
                dp[i + 1][j][0] += dp[i][j][1];
                dp[i + 1][j + 1][0] += dp[i][j][1] * (t - 1);
            }
        } else {
            rep(j, 0, 4) {
                dp[i + 1][j][1] += dp[i][j][1];
            }
        }
    }
    cout << dp[m][k][0] + dp[m][k][1] << endl;
    return 0;
}

Measured memory_bytes: 256
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int n;
	cin>>n;
	int arr[n];
	int brr[n];
	int crr[n];
	for (int i = 0; i < n; i++){
		cin>>arr[i];
		--arr[i];
	}
	for (int i = 0; i < n; i++){
		cin>>brr[i];
	}
	for (int i = 0; i < n-1; i++){
		cin>>crr[i];
	}
	int sum = 0;
	for (int i = 0; i < n; i++){
		sum += brr[arr[i]];
	}
	for (int i = 0; i <n ; ++i){
		if (i > 0 && arr[i] == arr[i-1]+1) {
			 sum += crr[arr[i-1]];
		}
	}
	cout<<sum<<endl;

}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define finish(x) reutrn cout << x << endl, 0;
#define ll long long

int n, x, k, dp[101][100001], dpsum[101][100001], mod = 1e9 + 7;
vector <int> a;

void summ(int row){
    dpsum[row][0] = dp[row][0];
    for(int i = 1 ; i <= k ; i++)
        dpsum[row][i] = (dpsum[row][i - 1] + dp[row][i]) % mod;
}
int sum(int row, int l, int r){
    int ret = dpsum[row][r];
    if(l != 0) ret -= dpsum[row][l - 1];
    if(ret < 0) ret += mod;
    if(ret >= mod) ret -= mod;
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0 ; i < n && cin >> x ; i++)
        a.push_back(x);
    for(int i = 0 ; i <= a[0] ; i++)
        dp[0][i] = 1;
    summ(0);
    for(int i = 1 ; i < n ; i++){
        for(int j = 0 ; j <= k ; j++)
            dp[i][j] = sum(i - 1, max(0, j - a[i]), j);
        summ(i);
    }
    cout << dp[n - 1][k] << endl;
}


Measured memory_bytes: 78848
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

template<typename T, typename E> class SegmentTree {
public:
  typedef function<T (T, T)> Operator;
  typedef function<T (T, E)> Apply;

  vector<T> data;
  ll n;
  T e;
  Operator op;
  Apply apply;

  SegmentTree(ll _n, T e, Operator op, Apply apply): e(e), op(op), apply(apply) {
    for(n = 1; n < _n; n *= 2);
    data.resize(n * 2 - 1, e);
  }

  T query(ll a, ll b) { return query(a, b, 0, 0, n); }
  T query(ll a, ll b, ll k, ll l, ll r) {
    if(r <= a || b <= l) return e;
    if(a <= l && r <= b) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return op(vl, vr);
  }

  void update(ll k, E x) {
    k += n - 1;
    data[k] = apply(data[k], x);
    while(k > 0) {
      k = (k - 1) / 2;
      data[k] = op(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
};

int main(void) {
  ll N;
  cin >> N;
  vector<ll> X(N);
  REP(i, 0, N) cin >> X[i];

  SegmentTree<ll, ll>::Operator op = [](ll a, ll b) { return a + b; };
  SegmentTree<ll, ll>::Apply apply = [](ll a, ll x) { return x; };
  SegmentTree<ll, ll> segtree(N * 2, 0, op, apply);

  REP(i, 0, N) {
    if(X[i] >= N * 2) {
      cout << "Yes" << endl;
    } else {
      if(segtree.query(0, 1) == 1) {
        cout << "No" << endl;
      } else if(segtree.query(X[i], X[i] + 1) == 1) {
        ll l = 0, h = X[i];
        while(h - l > 1) {
          ll m = (l + h) / 2;
          if(segtree.query(m, X[i] + 1) == X[i] - m + 1) h = m;
          else l = m;
        }

        if((l == 0 && segtree.query(X[i] + 1, N * 2) > 0)) {
          cout << "No" << endl;
        } else {
          cout << "Yes" << endl;
          segtree.update(l, 1);
          REP(j, l + 1, X[i] + 1) segtree.update(j, 0);
        }
      } else {
        cout << "Yes" << endl;
        segtree.update(X[i], 1);
      }
    }
  }
}


Measured memory_bytes: 23088
import bisect
def main():
    m,n  = list(map(int,input().split()))
    if n==0:
        exit()
    W = [int(input()) for _ in range(n)]

    w_total = 0
    w_sum =[]
    for w in W:
        w_total+=w
        w_sum.append(w_total)

    def judge(shelf_length):
        last_val = 0
        for i in range(m):
            _index= bisect.bisect_right(w_sum,last_val+shelf_length)
            #print(_index)
            if _index == n:
                return True
            if _index == 0:
                return False
            last_val =w_sum[ _index-1]
        return False


    def nibun(func ,min_ ,max_ ):
        left = min_
        right= max_
        while not(left==right):
            mid = (left+right) //2
            tmp = func(mid)
            if tmp:
                right = mid
            else:
                left = mid+1
        return left

    print(nibun(judge,0,1500009))

while True:
    main()

Measured memory_bytes: 7600
def f():
    n, k = map(int, input().split())

    d = {}
    key_list = set()

    for _ in range(n):
        a, b = map(int, input().split())
        if a in d.keys():
            d[a] += b
        else:
            d[a] = b

        key_list.add(a)

    key_list = sorted(key_list)

    curr_num = 0
    for key in key_list:
        curr_num += d[key]
        if curr_num >= k:
            print(key)
            return


if __name__ == "__main__":
    f()


Measured memory_bytes: 12708
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());

		int[][] man = new int[3][n];
		int total = 0;

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				man[i][j] = Integer.parseInt(sc.next());
			}
		}

		for (int i = 0; i < n-1; i++) {
			man[2][i] = Integer.parseInt(sc.next());
		}

		for(int i = 0; i < n; i++) {
			total += man[1][i];
		}

		for (int i = 0; i < n-1; i++) {
			if(man[0][i]==man[0][i+1]-1) {
				total+=man[2][man[0][i]-1];
			}
		}

		System.out.println(total);
	}
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int n, k, a[100];
bool dp[100100];

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

  for (int i = 0; i < k; i++) {
    if (not dp[i]) {
      for (int j = 0; j < n; j++) {
        if (i+a[j] <= k) {
          dp[i+a[j]] = true;
        }
      }
    }
  }

  cout << (dp[k] ? "First" : "Second") << endl;
  return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;

int a[100000] = {};

signed main() {
	int k;
	int n;
	
	while (true) {
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
			for (int i = 0; i < n; i++) {
				cin >> a[i];
			}

			int m = -9999999999;
			int tmp = 0;
			int cnt = 0;

			for (int i = 0; i < n; i++) {
				if (i < k) {
					tmp += a[i];
				}
				else {
					tmp -= a[i - k];
					tmp += a[i];
					m = max(m, tmp);
				}
			}

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

Measured memory_bytes: 3372
#include <iostream>
#include <string>

using namespace std;

long long ans = 0;
string s;

void dfs(int i, long long sum, long long tmp){
  if(i == s.size()-1){
    ans += sum + (s[i]-'0') + tmp*10;
  }
  else{
    // not +
    dfs(i+1, sum, 10*tmp + (s[i]-'0'));
    // +
    dfs(i+1, sum + 10*tmp + (s[i]-'0'), 0);
  } 
}

int main(){
  cin >> s;

  dfs(0, 0, 0);

  cout << ans;

  return 0;
}


Measured memory_bytes: 256
h, w = list(map(int, input().split()))
src_img_list = [input() for i in range(h)]
dst_img_list = []

for img_row in src_img_list:
    for i in range(2):
        dst_img_list.append(img_row)

for img_row in dst_img_list:
    print(img_row)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int ans = 0;
        while(n > 0){
            n -= d * 2 + 1;
            ans += 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#!usr/bim/python
#! -*- coding: utf-8 -*-

import numpy as np

nc = raw_input()
nc = nc.split()
n,c = map(int,nc)

tt = np.zeros([(10**5),c],int)

for i in range(n):
    stc = raw_input()
    stc = stc.split()
    s,t,c = map(int,stc)
    j = s
    while j <= t:
        tt[j-1][c-1] = 1
        j += 1

ans = np.max(np.sum(tt, axis=1))

print ans


Measured memory_bytes: 44764
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

char map[50][50];
bool memoB[50][50];
bool memoW[50][50];

void search(int x, int y, int w, int h, char color) {
  if (color == 'B') {
    memoB[x][y] = true;
  } else if (color == 'W') {
    memoW[x][y] = true;
  }
  if (x > 0 && map[x-1][y] == '.') {
    if ((color == 'B' && !memoB[x-1][y]) || (color == 'W' && !memoW[x-1][y])) {
      search(x-1, y, w, h, color);
    }
  }
  if (y > 0 && map[x][y-1] == '.') {
    if ((color == 'B' && !memoB[x][y-1]) || (color == 'W' && !memoW[x][y-1])) {
      search(x, y-1, w, h, color);
    }
  }
  if (x < w-1 && map[x+1][y] == '.') {
    if ((color == 'B' && !memoB[x+1][y]) || (color == 'W' && !memoW[x+1][y])) {
      search(x+1, y, w, h, color);
    }
  }
  if (y < h-1 && map[x][y+1] == '.') {
    if ((color == 'B' && !memoB[x][y+1]) || (color == 'W' && !memoW[x][y+1])) {
      search(x, y+1, w, h, color);
    }
  }
}

int main() {
  int w, h, cntB, cntW, resB, resW;
  char tmp;
  string s;
  while (cin >> w >> h, w | h) {
    cntB = cntW = 0;
    for (int j = 0; j < h; j++) {
      cin >> s;
      for (int i = 0; i < w; i++) {
        tmp = s[i];
        map[i][j] = tmp;
        if (tmp == '.') memoB[i][j] = memoW[i][j] = false;
        if (tmp == 'B') memoB[i][j] = true, memoW[i][j] = false, cntB++;
        if (tmp == 'W') memoB[i][j] = false, memoW[i][j] = true, cntW++;
      }
    }
    for (int i = 0; i < w; i++) {
      for (int j = 0; j < h; j++) {
        search(i, j, w, h, map[i][j]);
      }
    }
    resB = resW = 0;
    for (int i = 0; i < w; i++) {
      for (int j = 0; j < h; j++) {
        if (memoB[i][j] && !memoW[i][j]) resB++;
        if (!memoB[i][j] && memoW[i][j]) resW++;
      }
    }
    cout << resB-cntB << " " << resW-cntW << el;
  }
}

Measured memory_bytes: 1260
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
using namespace std;

#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 FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

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

const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(void){
    double x, y, s;
    while(cin >> x >> y >> s, x){
        int ans = 0;
        for(int i = 1; i < 1000; i++){
            for(int j = 1; j < 1000; j++){
                int b = (double)i * (100.0 + x) / 100;
                b += (int)((double)j * (100.0 + x) / 100);
                if(b == s){
                    int a = (double)i * (100.0 + y) / 100;
                    a += (int)((double)j * (100.0 + y) / 100);
                    ans = max(ans, a);
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long LL;
typedef long double LD;

vector<int> make(vector<int> & V) {
  vector<int> H(V.size());


  // 11011101
  for (auto u : V) {
   // cerr << u;
  }
  //cerr << endl;

  int st = 0;
  while (st < V.size()) {
    //cerr << st << endl;
    if (V[st] == 1) {
      int en = st;
      while (en < V.size()) {
        if(V[en]==0){
          break;
        }
        en++;
      }
      int cnt = en - st;
      for (int i = st; i < en; i++) {
        H[i] = cnt;
      }
      st = en + 1;
    }
    else{
      st++;
    }
  }
  for (auto u : H) {
    //cerr << u;
  }
  //cerr << endl;
  return H;

}

int main()
{
  LL H, W;
  //static int M[205][205];
  cin >> H >> W;
  vector<vector<int>> M(H);
  for (LL h = 0; h < H; ++h) {
    M[h].resize(W);
  }
  for (LL h = 0; h < H; ++h) {
    string tmp;
    cin >> tmp;
    for (LL w = 0; w < W; ++w) {
      if (tmp[w] == '#') {
        M[h][w] = 0;
      }
      else {
        M[h][w] = 1;
      }
    }
  }

  vector<vector<int>> N(H);
  for (LL h = 0; h < H; ++h) {
    N[h].resize(W);
  }

  for (LL h = 0; h < H; ++h) {
    vector<int> V;
    for (LL w = 0; w < W; ++w) {
      V.push_back(M[h][w]);
    }

    vector<int> U = make(V);
    for (LL w = 0; w < W; ++w) {
      N[h][w] += U[w];
    }
  }
  for (LL w = 0; w < W; ++w) {
    vector<int> V;
    for (LL h = 0; h < H; ++h) {
      V.push_back(M[h][w]);
    }

    vector<int> U = make(V);
    for (LL h = 0; h < H; ++h) {
      N[h][w] += U[h];
    }
  }

  int max_val = 0;
  for (LL h = 0; h < H; ++h) {
    for (LL w = 0; w < W; ++w) {
      max_val = max(max_val, N[h][w]);
      //cerr << N[h][w] << " ";
    }
    //cerr << endl;
  }

  if (max_val > 0) {
    cout <<max_val - 1;
  }
  else {
    cout << 0;
  }



  return 0;
}

Measured memory_bytes: 31616
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class A9x9 {
public:
	void solve(std::istream& in, std::ostream& out) {
        int a,b;
        in >> a >> b;
        if(a>=10||b>=10){
            out <<-1 << endl;
            return ;
        }
        out << a*b << endl;
	}
};


int main() {
	A9x9 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int i, j, tmp;
int main(){
  int N, X, Y;
  int A[100];
  X = 0;
  Y = 0;
  scanf("%d", &N);
  for(i=0;i<N;i++){
    scanf("%d", &A[i]);
  }
  for(i=0;i<N-1;i++){
    for(j=N-1;j>i;j--){
      if(A[j-1] > A[j]){
        tmp = A[j-1];
        A[j-1] = A[j];
        A[j] = tmp;
      }
    }
  }
  for(i=0;i<N;i++){
  if(i % 2 == 0) X += A[i];
    else Y += A[i];
  }
  printf("%d", abs(Y-X));
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z, S;
string T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

int count(char a) {
    if (a == 'r') {
        return R;
    } else if (a == 's') {
        return S;
    } else {
        return P;
    }
}

signed main() {
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    string str;
    for (int i = 0; i < N; i++) {
        if (T[i] == 'r') {
            str += 'p';
        } else if (T[i] == 's') {
            str += 'r';
        } else {
            str += 's';
        }
    }
    vector<string> janken(K);
    for (int i = 0; i < N; i++) {
        janken[i % K] += str[i];
    }
    for (int k = 0; k < K; k++) {
        ans += count(janken[k][0]);
        for (int i = 1; i < janken[k].size(); i++) {
            if (janken[k][i] == janken[k][i - 1]) {
                janken[k][i] = 'x';
                continue;
            }
            ans += count(janken[k][i]);
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
    int n;
    cin >>n;
    set<string>tmp;
    char f,e;
    bool flg=true;
    for(int i=0;i<n;i++){
        string s;
        cin >>s;
        f=s[0];
        if(i&&f!=e)flg=false;
        e=s[s.size()-1];
        tmp.insert(s);
    }
    if(tmp.size()!=n)flg=false;
    if(flg)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
import bisect
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
B[0] = A[0]

for i in range(1,N):
  B[i] = B[i-1]+A[i]

p = B[-1]/2
q = bisect.bisect_left(B,p)

if q>=1:
  ans = min(abs(B[q-1]-p),abs(B[q]-p))*2
else:
  ans = abs(B[q]-p)*2
print(int(ans))

Measured memory_bytes: 26024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;


int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    int cnt = 0;
    for(int i = 0; i< N; i++) {
        cin >> h[i];
    }
    for(int i = 0; i < N; i++) {
        if(h[i] >= K) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
#define int long long
#define ld double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define sz(x) ((long long)x.size())
#define all(x) (x).begin(), (x).end()
#define popcount(x) __builtin_popcountll(x)
const int MOD =1e9+7;

mt19937_64 rng(high_resolution_clock::now().time_since_epoch().count());
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> istream& operator >> (istream &in,vector<T> &A){ for(auto &x:A) in>>x; return in; };
template<typename T> ostream& operator << (ostream &out,vector<T> &A){ for(auto &x:A) out<<x<<" "; return out; };
template<typename T,typename W> istream& operator >> (istream &in,pair<T,W> &A){ in>>A.fi>>A.se; return in; };
const int N = 2*1e5+3;

void solve()
{
	int n,d;
	cin>>n>>d;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		if(x*x+y*y<= d*d) ans++;
	}
	cout<<ans<<"\n";
}

int32_t main(){
	cin.tie(0)->sync_with_stdio(0);
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	#endif

	int t=1;
	// cin>>t;
	for(int _t=1;_t<=t;_t++){
		// cout<<"Case #"<<_t<<": ";
		solve();
	}
} 


Measured memory_bytes: 3652
def bubble_sort(data)
  num_swapped = 0
  begin
    swapped = false
    1.upto(data.size - 1) { |i|
      if data[i] < data[i - 1]
        data[i], data[i - 1] = data[i - 1], data[i]
        num_swapped += 1
        swapped = true
      end
    }
  end while swapped
  [data, num_swapped]
end

data = STDIN.read.lines[1].split("\s").map(&:to_i)
sorted, num_swapped = bubble_sort(data)
puts sorted.join(' ')
puts num_swapped

Measured memory_bytes: 8644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	cout << setprecision(10) << fixed;
	
	const int maxn = 1e5 + 5;
	
	vector<double> p(maxn);
	p[0] = 1.0;
	for(int i = 1; i < maxn; i++)
		p[i] = p[i - 1] * 0.5;
	
	int n, k;
	cin >> n >> k;
	
	double ans = 0.0;
	
	double prob = 1.0 / n;

	for(int i = 1; i <= n; i++){
		int cur = i;
		int steps = 0;
		while(cur < k){
			cur *= 2;
			steps++;
		}
		ans += prob * p[steps];
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1000000007;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<ll> n(2),m(2);cin >> n >> m;

    ll ans=-IINF;
    for (int i=0;i<2;++i){
        for (int j=0;j<2;++j){
            chmax(ans,n[i]*m[j]);
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <string.h>

#define S_MAX_LEN 10

int main(void)
{
  char s[0x100];
  char t[0x100];
  char t_cpy[0x100];
  int s_len;
  int t_len;
  
  scanf("%s", s);
  scanf("%s", t);
  
  s_len = strlen(s);
  t_len = strlen(t);
  
  if (1 <= s_len && s_len <= 10 && t_len == s_len + 1) {
    strcpy(t_cpy, t);
    t_cpy[s_len] = '\0';
    
    if (strcmp(s, t_cpy) == 0) {
      printf("Yes");
    }
    else {
      printf("No");
    }
  }
  else {
    printf("No");
  }
  
  return 0;
}


Measured memory_bytes: 1692
// AOJPlusPlus.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

//#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <regex>
#include <climits>
using namespace std;

int main()
{
	int n, minv = INT_MAX, maxd = INT_MIN, dis = 0;
	cin >> n;
	int *r = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> r[i];
		if (i == 0) minv = r[i];
		else {
			maxd = max(maxd, r[i] - minv);
			minv = min(minv, r[i]);
		}
	}
	cout << maxd << endl;
    return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = 998244353;
const long long INF_LL = 1e18+11; const int INF_int = 1e9+11;
#define ll long long
#define mp std::make_pair
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto x:a) cout << x << " ";cout << endl;
int main(){
    int n;
    ll d;
    cin >> n >> d;
    int cnt = 0;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        if((x*x+y*y)<=d*d) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#define MAX 100000007
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int H,W;
  cin >> H >> W;
  char c;
  int a[101][101]={0};
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> c;
      if(c=='#'){
        a[i][j]=1;
      }else{
        a[i][j]=5;
      }
    }
  }
  for(int i=0;i<H;i++){
    bool flag=true;
    for(int j=0;j<W;j++){
      if(a[i][j]==1) flag=false;
    }
    if(flag){
      for(int k=0;k<W;k++){
        a[i][k]=0;
      }
    }
  }
  for(int i=0;i<W;i++){
    bool flag=true;
    for(int j=0;j<H;j++){
      if(a[j][i]==1) flag=false;
    }
    if(flag){
      for(int k=0;k<H;k++){
        a[k][i]=0;
      }
    }
  }
  for(int i=0;i<H;i++){
    bool flag=false;
    for(int j=0;j<W;j++){
      if(a[i][j]!=0){
        if(a[i][j]==1){
          cout << '#';
          flag =true;
        }if(a[i][j]==5){
          cout << '.';
        }
      }
    }
    if(flag){
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
    int array[2];
    double ans;
    for(int i=0;i <= 1;i++){
        scanf("%d",&array[i]);
    }
    ans = array[0]*10000/array[1];
    printf("%lf",ans/10000);
 
 
    
  
    
    return 0;
}


Measured memory_bytes: 128
number = int(input())
list = map(int,input().split())
yon_num = 0
ni_num = 0
odd_num = 0
for num in list:
    if num%4 == 0:
        yon_num += 1
    elif num%2 == 0:
        ni_num +=1
    else:
        odd_num += 1

    if ni_num != 0:
        ni_num = ni_num//2 + ni_num%2

if yon_num >= (odd_num + ni_num  + yon_num) // 2 :
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11096
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  cout << 800 * n - 200 * (n / 15) << endl;


  
  return 0;
}

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

using namespace std;

int const MMM = 100009;
int n;
int dp[MMM][4];
int arr[MMM][4];

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

    cin >> n;
    for(int i = 1 ; i <= n ; i++)
        cin >> arr[i][1] >> arr[i][2] >> arr[i][3];

    for(int i = 1 ; i <= 3 ; i++)
        dp[1][i] = arr[1][i];

    for(int i = 2 ; i <= n ; i++)
    {
        dp[i][1] = max(dp[i - 1][2] , dp[i - 1][3]) + arr[i][1];
        dp[i][2] = max(dp[i - 1][1] , dp[i - 1][3]) + arr[i][2];
        dp[i][3] = max(dp[i - 1][1] , dp[i - 1][2]) + arr[i][3];
    }
    int resp = max(dp[n][1] , max(dp[n][2] , dp[n][3]));
    cout << resp;

    return 0;
}


Measured memory_bytes: 3328
n = int(input())
p = list(map(int, input().split()))

count = 0

for i in range(n-2):
  if (p[i] < p[i+1]) and (p[i+1] < p[i+2]):
    count += 1
  elif (p[i] > p[i+1]) and (p[i+1] > p[i+2]):
    count += 1
    
print(count)

Measured memory_bytes: 38704
#include <bits/stdc++.h>
//#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
 
 
int main(){
    int64_t n,ans=1,mini;
    cin>>n;
    vector<int64_t> p(n);
    rep(i,n)cin>>p.at(i);
    
    mini=p.at(0);
    
    for(int i=1;i<n;i++){
        if(mini>p.at(i)){
            ans++;
        }
        mini=min(mini,p.at(i));
    }
    
    
   
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define dec(i, l, r) for (int i = l; i >= r; i--)

const int maxn = 1e6 + 5;

int dp[maxn], len, s1, s2;
char c[maxn];
int cnt, ans[maxn];

void solve(int mod, char *d, int &s) {
    ll r = 1;
    s = 0;
    dec(i, len - 1, 0) {
        if (d[i] == '1') s = (s + r) % mod;
        r = r * 2 % mod;
    }
}

int main() {
    inc(i, 1, 200000) dp[i] = dp[i % __builtin_popcount(i)] + 1;
    cin >> len >> c;
    inc(i, 0, len - 1) cnt += c[i] == '1';
    if (cnt == 0) {
        inc(i, 0, len - 1) cout << "1\n";
        return 0;
    }
    solve(cnt + 1, c, s1);
    if (cnt - 1) solve(cnt - 1, c, s2);
    ll r1 = 1, r2 = 1, mod1 = cnt + 1, mod2 = cnt - 1;
    dec(i, len - 1, 0) {
        if (c[i] == '1') {
            if (mod2) {
                ll now = ((s2 - r2) % mod2 + mod2) % mod2;
                ans[i] = dp[now] + 1;
            } else
                ans[i] = 0;
        } else {
            ll now = (s1 + r1) % mod1;
            ans[i] = dp[now] + 1;
        }
        r1 = r1 * 2 % mod1;
        if (mod2) r2 = r2 * 2 % mod2;
    }
    inc(i, 0, len - 1) cout << ans[i] << "\n";
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int a, b, c,ans;
    vector<int>abc(3);
    rep(i, 3)cin >> abc[i];
    sort(abc.begin(), abc.end());

    a = abc[0], b = abc[1], c = abc[2];
    int diff = (c - a) + (c - b);

    if (diff % 2 == 0)ans = diff / 2;
    else ans = ((diff + 1) / 2) + 1;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[103]={0};
int main()
{
int x,n;
cin>>x>>n;
for(int i=0;i<n;i++)
{
	int y;
	cin>>y;
	a[y]=-1;
}
int mn=10000,ab,ans=0;
for(int i=0;i<103;i++)
{
	if(a[i]==-1)continue;
	if(!a[i])
	ab = fabs(x-i);
	if(ab<mn)
	{
		mn=ab;
		ans=i;
	}
	
}

cout<<ans<<endl;

}


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

using namespace std;

typedef long long ll;

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

	int a, b;
	cin >> a >> b;
	
	if(b % a == 0){
		cout << a + b << endl;
	}else{
		cout << b - a << endl;
	}
}


Measured memory_bytes: 256
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

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

bool solve() {
  ll a, b;
  if (scanf("%lld%lld", &a, &b) != 2) { return false; }

  if (a == b) {
    printf("%lld\n", 2 * a - 2);
    return true;
  }

  if (a > b) { swap(a, b); }
  ll x = (int)(sqrt(a + 0.0) * sqrt(b + 0.0));
  while (x * x < a * b) x += 1;
  while (x * x >= a * b) x -= 1;
/*  vector <int> ind;
  ind.push_back(1);
  ind.push_back(a);
  ind.push_back(x);

  const int D = 100;

  int ans = 0;
  ll last_used = a * b + 1;
  for (int i = 1; i <= D && i < a - D; ++i) {
    ll maxP = min(last_used - 1, (a * b - 1 + i - 1) / i);
    if (maxP == b) {
      maxP--;
    }
    if (maxP > 0) {
      ans++;
    }
    last_used = maxP;
  }
  ans += max(0, (a - D) - D - 1);
  for (int i = a - D; i <= a + 2 * D && i < x - D; ++i) {
    ll maxP = min(last_used - 1, (a * b - 1 + i - 1) / i);
    if (maxP == b) {
      maxP--;
    }
    if (maxP > 0) {
      ans++;
    }
    last_used = maxP;
  }
  ans += max(0, (x - D) - (a + D) - 1);
  for (int i = x - D; i <= x; ++i) {
    ll maxP = min(last_used - 1, (a * b - 1 + i - 1) / i);
    if (maxP == b) {
      maxP--;
    }
    if (maxP > 0) {
      ans++;
    }
    last_used = maxP;
  }
*/
  dbg("a %lld b %lld x %lld\n", a, b, x);

  int ans = 2 * (x - 1);
  if (a < x) {
    ans -= 1;
  }
  {
    ll y = (a * b - 1) / b;
    if (y > 0 && y != a) {
      if ((a * b - 1) / y == b && (a * b - 1) / (y + 1) == b - 1) {
        ans -= 1;
      }
    }
  }

  if ((a * b - 1) / x == x) {
    if (x != a && x != b) {
      ans += 1;
    }
  } else {
    if (x != a && (a * b - 1) / x != b) {
      ans += 1;
    }
    ans += 1;
  }

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

  return true;
}
/* 8 * 9 = 72


   1 71
   2 35
   3 23
   4 ??
   5 ??
   6 11
   7 10
   8 8
   

   */

int main() {
  scanf("%*d");
  while (solve());
  return 0;
}

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

using namespace std;
int mf(const int& a, const int& b, const int& c, const int& d) {
  return max(a, max(b, max(c, d)));
}
int main() {
  int n, m;
  cin >> n >> m;
  int mp[n][m];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      cin >> mp[i][j];
  int dp[n][m][n] = {};
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = max(0, i + j - m + 1); k < min(i + j + 1, n); ++k) {
        dp[i][j][k] = mf(i ? dp[i-1][j][k] : 0,
                         j ? dp[i][j-1][k] : 0,
                         i && k ? dp[i-1][j][k-1] : 0,
                         j && k ? dp[i][j-1][k-1] : 0)
                        + mp[i][j] + (i == k ? 0 : mp[k][i+j-k]);
      }
    }
  }
  cout << dp[n-1][m-1][n-1] << '\n';
  return 0;
}

Measured memory_bytes: 31616
#include<stdio.h>
int main(void){
  int i,j,a,sum,tmp,cnt=0;
  scanf("%d %d",&a,&sum);
  int p[a];
  for(i=0;i<a;i++){
    scanf("%d",&p[i]);
    sum-=p[i];
    cnt++;
  }
  for(i=0;i<a;i++){
    for(j=i+1;j<a;j++){
      if(p[i]>p[j]){
        tmp=p[i];
        p[i]=p[j];
        p[j]=tmp;
      }
    }
  }
  while(sum>=p[0]){
    sum-=p[0];
    cnt++;
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

#define N 2000

int solve(int,int);

int A[N],a;

int main(){
  int i,j,b,k;

  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&b);
  for(j=0;j<b;j++){
    scanf("%d",&k);
    if(solve(0,k)==1) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int solve(int i,int m){
  int res;

  if(m==0) return 1;
  if(i>=a) return 0;
  
  res=solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}



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

int main(void){
    string N;
    cin >> N;
    int n = N.size();
    int A[n];
    for(int i = 0; i < n; i++){
        A[i] = atoi(N.substr(i, 1).c_str());
    }

    int m;
    for(int i = n-1; i >= 0; i--){
        if(A[i] != 0){
            m = i;
            break;
        }
    }
    int S[m+1], M[m+1];
    for(int i = 0; i <= m; i++){
        S[i] = A[i];
        M[i] = 9-A[i];
    }
    M[m]++;


    int ans_S[m+1], ans_M[m+1];
    ans_S[m] = S[m];
    ans_M[m] = M[m];
    for(int i = m-1; i >= 0; i--){
        ans_S[i] = min(S[i]+ans_S[i+1], S[i]+1+ans_M[i+1]);
        ans_M[i] = min(M[i]+ans_M[i+1], M[i]+1+ans_S[i+1]);
    }
    int ans = min(ans_S[0], 1+ans_M[0]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 20868
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,k,sum=0,cnt; cin>>n>>k;
    vector<ll> a(n,0);
    rep(i,n){
        cin>>a[i]; sum+=a[i];
    }
    vector<ll> p={1,sum};
    for(ll i=2;i*i<=sum;i++){
        if(sum%i==0){
            p.push_back(i);
            if(i*i!=sum) p.push_back(sum/i);
        }
    }
    sort(al(p));
    vector<ll> m(n,0);
    for(ll i=p.size()-1;i>=0;i--){
        sum=0; cnt=0;
        for(ll j=0;j<n;j++){
            m[j]=a[j]%p[i]; sum+=m[j];
        }
        sort(al(m));
        for(ll j=0;j<n-sum/p[i];j++){
            cnt+=m[j];
        }
        if(cnt<=k){
            cout<<p[i]<<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
# include <iostream>
# include <vector>


using namespace std ;



int main () {
    int n;
    string s[110];
    cin>>n;
    bool ans=false;
    for (int i=0;i<n;i++){
        cin>>s[i];
    }
    for (int j=0;j<n-1;j++){
        if (s[j][s[j].length()-1]==s[j+1][0]){
            ans=true;
        }else{
          ans=false;
          break;
        }
    }
    for (int i=0 ; i<n-1;i++){
        for (int j=i+1 ; j<n;j++){
            if (s[i]==s[j]) ans=false;
        }
    }
    if (ans) {
        cout<<"Yes"<<endl;
    }else{
      	cout<<"No"<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<long long, long long>> a;
	vector<pair<long long, long long>> b;

	for (int i = 0; i < N; ++i) {
		long long x, y;
		cin >> x >> y;
		a.push_back(make_pair(x, y));
	}
	for (int i = 0; i < M; ++i) {
		long long x, y;
		cin >> x >> y;
		b.push_back(make_pair(x, y));
	}
	

	for (int i = 0; i < N; ++i) {
		long long minMan = INT_MAX;
		int _j = 0;
		for (int j = 0; j < M; ++j) {
			long long man = abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second);
			if (man < minMan) {
				_j = j + 1;
				minMan = man;
			}
		}
		cout << _j << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(){
    string s;
    cin >> s;
    int N = (int)s.size();
    for (int i = 0; i <= N-2; i++) {
        if (s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    for (int i = 0; i <= N-3; i++) {
        if (s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}

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

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

  int score_sum = 0, score[n];
  for (int i = 0; i < n; i++) {
    scanf(" %d", &score[i]);
    score_sum += score[i];
  }

  int count = 0;
  float thr = (float) score_sum / (float) (4 * m);
  for (int i = 0; i < n; i++) {
    if ((float) score[i] >= thr) {
      count++;
    }
  }

  if (count >= m) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
typedef long long ll;

ll MOD_N = 1e9 + 7;


int main() {
    int N, M;
    cin >> N >> M;
    int S[N];
    int T[M];
    for (int i = 0; i < N; ++i) {
        cin >> S[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> T[i];
    }
    ll **counts = new ll*[N];
    ll **sums = new ll*[N];
    for (int i = 0; i < N; ++i) {
        counts[i] = new ll[M];
        sums[i] = new ll[M];
    }
    for (int i = 0; i < N; ++i) {
        counts[i][0] = (S[i] == T[0]) ? 1 : 0;
    }
    for (int j = 0; j < M; ++j) {
        counts[0][j] = (S[0] == T[j]) ? 1 : 0;
    }
    sums[0][0] = counts[0][0];
    for (int i = 1; i < N; ++i) {
        sums[i][0] = sums[i-1][0] + counts[i][0];
    }
    for (int j = 1; j < M; ++j) {
        sums[0][j] = sums[0][j-1] + counts[0][j];
    }
    for (int i = 1; i < N; ++i) {
        for (int j = 1; j < M; ++j) {
            ll count, sum;
            if (S[i] == T[j]) {
                count = (sums[i-1][j-1] + 1) % MOD_N;
            } else {
                count = 0;
            }
            counts[i][j] = count;
            sum = sums[i-1][j] + sums[i][j-1] - sums[i-1][j-1] + count;
            sums[i][j] = (sum + MOD_N) % MOD_N;
        }
    }
    ll ans = (sums[N-1][M-1] + 1) % MOD_N;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 62848
#問題はガバだったけどおかげで良い練習になった
n,q = map(int,input().split())
peer = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(lambda x:int(x)-1,input().split())
  peer[a].append(b)
  peer[b].append(a)
mom = [0 for _ in range(n)]
mom[0] = 1
ans = [0 for _ in range(n)]
for j in range(q):
  p,x = map(int,input().split())
  p -= 1
  ans[p] += x
now = [0]
while now != []:
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if mom[y] == 0:
        mom[y] = 1
        ans[y] += ans[x]
        now.append(y)
print(' '.join(list(map(str,ans))))

Measured memory_bytes: 66848
#include<stdio.h>
int main()
{
  int input;
  int fore, back;
  
  scanf("%d", &input);
  fore=int(input/100);
  back=input%100;
  
  bool foreM = (fore>0&&fore<=12)? true:false;
  bool backM = (back>0&&back<=12)? true:false;
  
  if(foreM&&backM)
    printf("AMBIGUOUS");
  else if(foreM)
    printf("MMYY");
  else if(backM)
    printf("YYMM");
  else
    printf("NA");
  return 0;
}

Measured memory_bytes: 128
import java.io.*;

public class Main
{
  public static void main(String[] args) {
    try {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(br.readLine());
      String[] strArray = br.readLine().split(" ");
      int[] A = new int[n];
      for(int i=0; i<n; i++) {
        A[i] = Integer.parseInt(strArray[i]);
      }
      int totalCount = mergeSort(A, 0, n, 0);
      StringBuilder sb = new StringBuilder();
      for(int i=0; i<n-1; i++) {
        sb.append(A[i]).append(" ");
      }
      sb.append(A[n-1]);
      System.out.println(sb.toString());
      System.out.println(totalCount);
    } catch (IOException e) {
    }
  }

  public static int merge(int[] A, int left, int mid, int right, int count) {
    int n1 = mid - left;
    int n2 = right - mid;
    int[] L = new int[n1+1];
    int[] R = new int[n2+1];
    for(int i=0; i<n1; i++) {
      L[i] = A[left + i];
    }
    for(int i=0; i<n2; i++) {
      R[i] = A[mid + i];
    }
    L[n1] = Integer.MAX_VALUE;
    R[n2] = Integer.MAX_VALUE;

    int i = 0;
    int j = 0;

    for(int k = left; k<right; k++) {
      count += 1;
      if( L[i] <= R[j] ) {
        A[k] = L[i];
        i = i+1;
      } else {
        A[k] = R[j];
        j = j+1;
      }
    }

    return count;

  }

  public static int mergeSort(int[] A, int left, int right, int count) {
    int totalCount = count;
    if(left + 1 < right) {
      int mid = (left + right) / 2;
      totalCount += mergeSort(A, left, mid, count);
      totalCount += mergeSort(A, mid, right, count);
      totalCount += merge(A, left, mid, right, count);
    }
    return totalCount;
  }

}

Measured memory_bytes: 156624
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	if (n & 1) {
		cout << "No" << endl;
		return 0;
	}
	string s1 = s.substr(0, n/2);
	string s2 = s.substr(n/2, n/2);
	if (s1 == s2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, T = map(int, readline().split())

AB= list(map(int, read().split()))
A = AB[0::2]
B = AB[1::2]
ls = list(zip(A, B))
# 食べるのにかかる時間で昇順にソート
ls.sort()
# 上の並び順において、ls[i:]の美味しさの最大値をdeli[i]とする
deli = [0]*N
deli[- 1] = ls[-1][- 1]
for i in range(N - 2, - 1, - 1):
    deli[i] = max(deli[i - 1], ls[i][- 1])

res = 0
dp = [0]*T
for i in range(N - 1):
    for j in range(T - 1, - 1, - 1):
        if ls[i][0] <= j:
            dp[j] = max(dp[j], dp[j - ls[i][0]] + ls[i][1])
    res = max(res, dp[- 1] + deli[i + 1])
print(res)

Measured memory_bytes: 42868
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int N,K;
int D[9];
ll digit(ll n)
{
    ll i,r;
    while(n!=0){
        r=n%10;
        for(i=0;i<K;i++){
            if(D[i]==r){
                return 1;
            }
        }
        n/=10;
    }
    return 0;
}
void solve()
{
    ll i,s;
    cin>>N>>K;
    for(i=0;i<K;i++) cin>>D[i];
    s=N;
    while(1){
        if(digit(s)==0){
            break;
        }
        else s++;
    }
    cout<<s<<endl;return;
}
int main()
{
    solve();
}

Measured memory_bytes: 3644