akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <cstring>
using namespace std;
typedef pair<int,int> pp;
int N,M;
vector< vector<bool> > A;

bool reachable(int from){
    bool c[N];
    memset(c, false, sizeof c);

    c[from] = true;
    queue<int> Q;
    Q.push(from);

    while(!(Q.empty())) {
        int u = Q.front();
        Q.pop();
        for(int v=0; v<N; v++) {
            if(A[u][v] == false && A[v][u] == false) continue;
            if(c[v] == false) {
                c[v] = true;
                Q.push(v);
            }
        }
    }
    bool ans = true;
    for(int index=0; index<N; index++) {
        if(c[index] == false){
            ans = false;
            break;
        }
    }
    return ans;
}

int main() {
    cin >> N >> M;
    queue<pp> Q;
    A.resize(N);
    for(int i=0; i<N; i++) {
        A[i].resize(N);
        A[i][i] = true;
        for(int j=0; j<N; j++) A[i][j] = false;
    }
    
    for(int i=0; i<M; i++) {
        int a,b;
        cin >> a >> b;
        A[a-1][b-1] = true;
        A[b-1][a-1] = true;
        Q.push(pp(a-1,b-1));
    }

    int cnt = 0;
    while(!(Q.empty())) {
        pp ns = Q.front(); Q.pop();
        A[ns.first][ns.second] = false;
        A[ns.second][ns.first] = false;
        for(int i=0; i<N; i++) {
            if(!(reachable(i))) {
                cnt++;
                break;
            }
        }
        A[ns.first][ns.second] = true;
        A[ns.second][ns.first] = true;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

public final class Main {

	class UnionFind {
		int[] arr;

		public UnionFind(int size) {
			arr = new int[size];
			for (int i = 0; i < size; i++) {
				arr[i] = -1;
			}
		}

		public int find(int x) {
			if (arr[x] == -1)
				return x;
			int temp = x;
			while (arr[temp] != -1) {
				temp = arr[temp];
			}
			int root = temp;
			temp = x;
			while (arr[temp] != -1) {
				temp = arr[x];
				arr[x] = root;
			}
			return root;
		}

		public int union(int x, int y) {
			int rx = find(x);
			int ry = find(y);
			if (rx == ry)
				return 0;
			if (Math.abs(rx) > Math.abs(ry)) {
				arr[ry] = rx;
			} else if (Math.abs(rx) < Math.abs(ry)) {
				arr[rx] = ry;
			} else {
				arr[rx] = ry;
				arr[ry] += 1;
			}
			return 1;
		}
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] in = br.readLine().split(" ");
		int n = Integer.parseInt(in[0]);
		int k = Integer.parseInt(in[1]);
		int l = Integer.parseInt(in[2]);
		UnionFind road = new Main().new UnionFind(n);
		UnionFind rail = new Main().new UnionFind(n);
		for (int i = 0; i < k; i++) {
			in = br.readLine().split(" ");
			road.union(Integer.parseInt(in[0]) - 1, Integer.parseInt(in[1]) - 1);
		}
		for (int i = 0; i < l; i++) {
			in = br.readLine().split(" ");
			rail.union(Integer.parseInt(in[0]) - 1, Integer.parseInt(in[1]) - 1);
		}
		int[] ans = new Solver().solve(road, rail, n);
		Arrays.stream(ans).mapToObj(e -> e + " ").forEachOrdered(System.out::print);

	}
}

class Solver {

	int[] solve(Main.UnionFind road, Main.UnionFind rail, int n) {
		int ans[] = new int[n];
		HashMap<Integer, HashSet<Integer>> roadComps = new HashMap<Integer, HashSet<Integer>>();
		for (int i = 0; i < n; i++) {
			int rt = road.find(i);
			if (!roadComps.containsKey(rt)) {
				roadComps.put(rt, new HashSet<Integer>());
			}
			roadComps.get(rt).add(i);
		}
		for (HashSet<Integer> set : roadComps.values()) {
			HashMap<Integer, HashSet<Integer>> railComps = new HashMap<Integer, HashSet<Integer>>();
			for (int entry : set) {
				int root = rail.find(entry);
				if (!railComps.containsKey(root)) {
					railComps.put(root, new HashSet<Integer>());
				}
				railComps.get(root).add(entry);
			}
			for (HashSet<Integer> res : railComps.values()) {
				int len = res.size();
				for (int resi : res) {
					ans[resi] = len;
				}
			}
		}

		return ans;

	}

}


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

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

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


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

#define int long long
#define pb push_back
#define ff first
#define ss second
bool ch(vector<int> &a,vector<int> &b,int n,int m,int mid,int k)
{
    if(mid-1<n && a[mid-1]<=k)
        return 1;
    if(mid-1<m && b[mid-1]<=k)
        return 1;
    for(int i=0;i<mid;i++)
    {
        if(i-1>=0 && mid-1-1>=0 && i-1<n && mid-i-1<m && a[i-1]+b[mid-i-1]<=k)
            return 1;
    }
    return 0;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   
    int n,m,k;
    cin>>n>>m>>k;
    
    vector<int> a(n);
    vector<int> b(m);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i!=0)
            a[i]=a[i-1]+a[i];
    }
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
        if(i!=0)
            b[i]=b[i-1]+b[i];
    }
    
    int low=0;
    int high=n+m+1;
    int ans=0;
    while(low<=high)
    {
        int mid=low+(high-low)/2;
        if(ch(a,b,n,m,mid,k))
        {
             
            ans=max(ans,mid);
            low=mid+1;
        }
        else
            high=mid-1;
       
    }
    cout<<ans;
}
        
    

Measured memory_bytes: 6368
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T> ostream& operator << (ostream &s, multiset<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

const int MAX = 10001000;
bool IsPrime[MAX];
vector<int> Era(int n = MAX) {
    vector<int> res;
    IsPrime[0] = false; IsPrime[1] = false;
    for (int i = 2; i < n; ++i) IsPrime[i] = true;
    for (int i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            res.push_back(i);
            for (int j = i*2; j < n; j += i) IsPrime[j] = false;
        }
    }
    return res;
}


int N;
int main() {
    while (cin >> N) {
        vector<int> pr = Era();
        vector<int> res;
        for (int i = 0; i < pr.size(); ++i) {
            if (pr[i] % 5 == 1) res.push_back(pr[i]);
            if (res.size() == N) break;
        }
        for (int i = 0; i < res.size(); ++i) {
            cout << res[i];
            if (i != (int)res.size() - 1) cout << " ";
        }
        cout << endl;
    }
}




















Measured memory_bytes: 15984
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
#define ll long long
using namespace std;
int main() {
  int n, ac = 0, wa = 0, tle = 0, re = 0;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (s[i] == "AC") {
      ac++;
    } else if (s[i] == "WA") {
      wa++;
    } else if (s[i] == "TLE") {
      tle++;
    } else if (s[i] == "RE") {
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 6428
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001

using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int a, b, c; cin >> a >> b >> c;
    
    cout << min(b / a, c) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000005
 
ll n, ans, x, y;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> n;
    for (int i = 1; i <= sqrt(n); i++){
        x = i + 1;
        if (n%x == 0){
            if (n/i == n/x) ans += i;
            y = n/x;
            y--;
            if (y > 0){
                if (n/y == n/(y + 1)) ans += y;
            }
        }
    }
    if (n > 1){
        if (n/(n - 1) == 1 && n%(n - 1) == 1) ans += n - 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# import array
# from bisect import *
# from collections import *
# import fractions
# import heapq 
# from itertools import *
# import math
# import re
# import string

def max_minus_min(areas):
    # print("areas", areas)
    return max(areas) - min(areas)

def solve2(h, w):
    area1 = h * (w // 2)
    area2 = h * w - area1
    return [area1, area2]

def solve(h, w):
    w_div_3 = w // 3;
    ans = 1e9
    for w2 in range(w_div_3, w_div_3 + 2):
        area1 = w2 * h
        ans = min(ans, max_minus_min([area1] + solve2(h, w - w2)))
        ans = min(ans, max_minus_min([area1] + solve2(w - w2, h)))
    return ans

H, W = map(int, raw_input().split())
print(min(solve(H,W), solve(W,H)))


Measured memory_bytes: 2568
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl(1);
const ll mod = 1000000007;
//const ll mod = 998244353;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

void solve(){
  ll n;cin>>n;
  ll ans=1;
  rep(i,n){
    ans*=i+1;
    ans%=mod;
  }
  cout<<ans<<endl;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);cout<<fixed;
  cout<<setprecision(30);
  solve();
}


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

int main(){

    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int> b;
    b = a;
    sort(b.begin(), b.end());
    map<int, int> m;
    for(int i = 1; i <= n; i++){
        m[b[i - 1]] = i;
    }

    for(int i = 0; i < n; i++){
        a[i] = m[a[i]];
    }

    int cnt = 0;
    for(int i = 1; i < n; i += 2){
        cnt += (a[i] % 2);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <string.h>

using namespace std;
#define LL long long
using VS = vector<string>;
using VI = vector<int>;
using VL = vector<LL>;
using VVI = vector<VI>;
using VVL = vector<VL>;
#define FOR(i,s,e) for(i = s; i < e; i++)
#define FORR(i,s,e) for(i = e-1; i >= s; i--)
const LL INF = (LL)1e16;
const LL MOD = (LL)1e9 + 7;

int p,q,a,n,limit;
int dfs(int x, int y, int n, int i){
  int ans = 0;
  if (x*q > y*p) return 0;
  if (x*q == y*p) return 1;
  if (n == limit) return 0;
  for(int j = i; j*y<=a; j++){
    ans += dfs(x*j+y,y*j,n+1,j);
  }
  return ans;
}

int main(){
  while (1){
    cin >> p >> q >> a >> limit;
    if (p == 0){
      return 0;
    }
    cout << dfs(0,1,0,1) << endl;
  }
  return 0;
}



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

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

  int X = 0, Y = 0;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    X += d;
    Y += d * d;
  }

  cout << (X * X - Y) / 2 << endl;
}

Measured memory_bytes: 256
/*
 * 2643.cc: AI
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 50;
const int MAX_W = 50;
const int MAX_PC = 2000000;

const int INF = 1 << 30;

const int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};

/* typedef */

/* global variables */

int h, w;
int sx, sy, gx, gy, di;
string flds[MAX_H];
int ans, pc;

/* subroutines */

void stop(int x) {
  printf("%d\n", x);
  exit(0);
}

bool condition(string &s, int &pos, bool run) {
  bool no = false;
  if (s[pos] == '~') no = true, pos++;

  char op = s[pos++];
  if (! run) return false;
  
  switch (op) {
  case 'N': return (di == 1) ^ no;
  case 'E': return (di == 0) ^ no;
  case 'S': return (di == 3) ^ no;
  case 'W': return (di == 2) ^ no;
  case 'C': return (flds[sy + dys[di]][sx + dxs[di]] == '#') ^ no;
  }
  return true ^ no;
}

void prog(string &s, int &pos, bool run) {
  while (pos < s.size() && s[pos] != ']' && s[pos] != '}') {
    // 'if' statement
    if (s[pos] == '[') {
      pos++; // '['
      bool cf = condition(s, pos, run);
      prog(s, pos, run && cf);
      pos++; // ']'

      if (++pc >= MAX_PC) stop(-1);
      continue;
    }

    // 'while' statement
    if (s[pos] == '{') {
      pos++; // '{'
      int pos0 = pos;
      while (condition(s, pos, run)) {
	prog(s, pos, true);
	pos = pos0;
	if (++pc >= MAX_PC) stop(-1);
      }
      prog(s, pos, false);
      pos++; // '}'
      continue;
    }

    // 'action' statement
    char op = s[pos++];
    if (run) {
      int x0, y0;
    
      switch (op) {
      case '^':
	x0 = sx + dxs[di], y0 = sy + dys[di];
	if (flds[y0][x0] == '.') sx = x0, sy = y0;
	break;
      case 'v':
	x0 = sx - dxs[di], y0 = sy - dys[di];
	if (flds[y0][x0] == '.') sx = x0, sy = y0;
	break;
      case '<':
	di = (di + 1) & 3;
	break;
      case '>':
	di = (di + 3) & 3;
	break;
      }
      ans++;
      //printf("action(%c): (%d,%d)[%d]\n", op, sx, sy, di);
      
      if (sx == gx && sy == gy) stop(ans);
      if (++pc >= MAX_PC) stop(-1);
    }
  }
}

/* main */

int main() {
  cin >> h >> w;

  for (int y = 0; y < h; y++) {
    cin >> flds[y];
    for (int x = 0; x < w; x++) {
      switch (flds[y][x]) {
      case 's': flds[y][x] = '.'; sx = x; sy = y; break;
      case 'g': flds[y][x] = '.'; gx = x; gy = y; break;
      }
    }
  }
  di = 1;
  
  string s;
  cin >> s;

  int pos = 0;
  prog(s, pos, true);

  puts("-1");
  return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<math.h>
#include<set>
#define M 1000000007
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,i;
	cin>>n;
	multiset<int> a;
	for(i=0;i<n;i++)
	{
		int p;
		cin>>p;
		a.insert(p);
	}
	int b[n-1][2];
	i=0;
	auto it=a.begin();
	auto it1=it;
	for(;;i++)
	{
		if(a.size()==2)
		{
			b[i][1]=*it;
			it++;
			b[i][0]=*it;
			break;
		}
		it1++;
		if(*it1<0)
		{
			it1=a.end();
			it1--;
			b[i][0]=*it1;
			b[i][1]=*it;
			a.erase(it);
			a.erase(it1);
		}
		else
		{
			b[i][0]=*it;
			b[i][1]=*it1;
			a.erase(it);
			a.erase(it1);
		}
		a.insert(b[i][0]-b[i][1]);
		it=a.begin();
		it1=it;
	}
	cout<<b[n-2][0]-b[n-2][1]<<endl;
	for(i=0;i<n-1;i++)
		cout<<b[i][0]<<' '<<b[i][1]<<endl;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int a[5000];

int main() {
    int N, k; cin >> N >> k;
    int n = 0;
    rep(i, N) {
        int b; cin >> b;
        if(k <= b) continue;
        a[n++] = b;
    }
    sort(a, a + n);
    reverse(a, a + n);
    int r = 0, lastr = 0;
    ll cnt = 0;
    while(r < n) {
        cnt += a[r];
        if(k <= cnt) {
            lastr = r + 1;
            cnt -= a[r];
        }
        r++;
    }
    cout << (n - lastr) << endl;
    return 0;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN,"%d%d%d%d", $a,$b,$c,$k);

$sum = 0;

$zan = $k;
$zan -= $a;
if($zan <= 0){
    echo $k;
    exit;
}else{
    $sum += $a;
}

$zan -= $b;
if($zan <=0){
    echo $sum;
    exit;
}

echo $sum - $zan;


Measured memory_bytes: 16224
N,A,B,C,D=map(int,input().split())
S=input()
c=0
if '##' in S[A:C] or '##' in S[B:D]:
    c=1
if C<D:#大きい方から先に目的地に配置
    if c==0:
        print("Yes")
    else:
        print("No")

elif C>D:
    if '...' in S[B-2:D+1] and c==0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3572
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int n,c,k,a[maxn];

int main() {
  //freopen("in.cpp","r",stdin);
  cin>>n>>c>>k;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  int ret=0;
  for(int i=0;i<n;i++){
    int cur=i;
    for(int j=i+1;j<n;j++){
      if(j-i+1>c||a[j]>a[i]+k)break;
      cur=j;
    }
    ret++;
    i=cur;
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
 
int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i, j;
 
  for ( ; ; )
  {
    int h, w;
 
    scanf ( "%d%d", &h, &w );
    if ( h == 0 && w == 0 ) break ;
 
    for ( i = 0; i < h; ++i )
    {
      for ( j = 0; j < w; ++j )
      {
        if ( i == 0 || i == h - 1
          || j == 0 || j == w - 1 )
        {
          putchar ( '#' );
        }
        else
        {
          putchar ( '.' );
        }
      }
      puts ( "" );
    }
    puts ( "" );
  }
 
  return ( 0 );
}

Measured memory_bytes: 2548
DEVISOR = 2019

L, R = (int(word) for word in input().split())

if (R // DEVISOR) > (L // DEVISOR):
    print(0)
    exit()

L %= DEVISOR
R %= DEVISOR

print(min(i * j % DEVISOR for i in range(L, R) for j in range(i+1, R+1)))


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;


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

	if ((a*b) % 2==1)
		cout << "Odd" << endl;
	else
		cout << "Even" << endl;


	return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,k,ans{};
    in>>n>>k;
    while(n) n/=k,++ans;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define ld double
#define inf 2001
#define infm inf*inf
#define mod ((ll)1e9+7)
#define INF (int)(1e9) 
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;

ll getinv(ll x){
	ll k=mod-2,ans=1;
	while (k){
		if (k&1){
			ans=ans*x%mod;
		}
		x=x*x%mod;
		k/=2;
	}
	return ans;
}

ll fact[infm],invf[infm];

void prework(int N){
	fact[0]=1;
	for (int i=1;i<=N;i++){
		fact[i]=fact[i-1]*i%mod;
	}
	invf[N]=getinv(fact[N]);
	for (int i=N-1;i>=0;i--){
		invf[i]=invf[i+1]*(i+1)%mod;
	}
	return;
}

ll C(int x,int y){
	return fact[x]*invf[y]%mod*invf[x-y]%mod;
}

ll cal(int x,int y){
	return C(x+y,x);
}

int n,K;
int f[inf][inf];

int main(){
	rd(n) rd(K)
	if (K==1){
		puts("1");
		return 0;
	}
	prework(n*K);
	f[0][0]=1;
	for (int i=1;i<=n;i++){
		ll sum=0;
		for (int j=i;j>=1;j--){
			sum=(sum+f[i-1][j-1])%mod;
			f[i][j]=sum*cal((i-1)*K-j+1,K-2)%mod;
		}
	}
	ll ans=0;
	for (int i=0;i<=n;i++){
		ans=(ans+f[n][i])%mod;
	}
	printf("%lld\n",ans*fact[n]%mod);
	return 0;
}



Measured memory_bytes: 77568
#include <stdio.h>

int main(void)
{
    int N;
    int t[100000],x[100000],y[100000];
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
    }
    int can=1;
    for(int i=0;i<N;i++){
        int can2=0;
        for(int n=0;x[i]+y[i]+2*n<=t[i];n++){
            if(x[i]+y[i]+2*n==t[i]){
                can2=1;
                //printf("n=%d ok\n",n);
            }
        }
        //printf("can2=%d\n",can2);
        if(can2==0){
            can=0;
            break;
        }
    }
    if(can==1)
        printf("Yes\n");
    else
        printf("No\n");
    
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
     char x;
     cin >> x;
     if(x == 'a' || x== 'i' || x == 'u' || x == 'e' || x == 'o')  cout << "vowel" << endl;
        else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<time.h>
#include<sstream>
#define MINN -1e8 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF=0x3f3f3f3f3f3f;
const int P=1e9+7;
const int MAXN=32000;
const double pi=3.1415926;
//const int MINN=-1e8;
const ll mod=1000000007;

//map<string,ll> m;
//map<ll,ll> m;

//set<ll> s;

//vector<ll> v;

//scanf("%lld",&t);
ll n;
int main()
{
	cin>>n;
	if(n%2)n/=2;
	else n=n/2-1;
	cout<<n;
	return 0;
}
//ll n,m,t,a,x,ans,res;
//ll powmod(ll a,ll b)     //快速幂 
//{
//	ll tmp=a%mod;
//	ll ans=1;
//	while(b)
//	{
//		if(b&1)ans=ans*tmp%mod;
//		tmp=tmp*tmp%mod;
//		b>>=1;
//	}
//	return ans%mod;
//}


//bool is_prime(ll a)     //判断素数 
//{
//	if(a==2)return 1;
//	else if(a==1||a%2==0)return 0;
//	else
//	{
//		for(ll i=3;i*i<=a;++i)
//		{
//			if(a%i==0)return 0;
//		}
//	}
//	return 1;
//}


Measured memory_bytes: 256
n = int(input())
P = list(map(int, input().split()))
c = 1
minv = P[0]  # その数より左にあるかずは全大きくさくなければならない
for i in range(1, len(P)):
    if minv > P[i]:
        c += 1
    minv = min(minv, P[i])
print(c)


Measured memory_bytes: 32272
mod = 10**9+7
n,k = map(int,input().split())
ans = 0
mod = 10**9 + 7
inv_t = [0,1]
for i in range(2,n+2):
  inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
a = n
b = n-1
for i in range(1,min(n,k)+1):
    ans += a*b % mod
    a = a*(n-i)*inv_t[i+1] % mod
    b = b*(n-i-1)*inv_t[i+1] % mod
    ans %= mod
if k > 1:
    ans += 1
print(ans % mod)


Measured memory_bytes: 11052
#include<bits/stdc++.h>
using namespace std;
int main(){
unordered_set<string>a;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
      string s;
    cin>>s;
a.insert(s);
  }
  cout<<a.size()<<endl;
}


Measured memory_bytes: 17656
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
 
public class Main {
    static int sortCount = 0;
    static int addValue = 1;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int[] A = new int[n];
        for(int i = 0; i < n; i++){
            A[i] = Integer.parseInt(scanner.next());
        }
        List<Integer> intervalList = new ArrayList<Integer>();
        shellSort(A, intervalList, n);
        System.out.println(intervalList.size());
        int ansCnt = 0;
        for(int i: intervalList){
            System.out.print(i);
            if(ansCnt < (intervalList.size() - 1)){
                System.out.print(" ");
            }else{
                System.out.println("");
            }
            ansCnt++;
        }
        System.out.println(sortCount);
        for(int i: A){
            System.out.println(i);
        }
    }
 
    private static void shellSort(int[] A, List<Integer> intervalList, int n){
        intervalList.add(addValue);
        while(true){
            addValue = (3 * addValue) + 1;
            if(n <= addValue){
                break;
            }
            intervalList.add(addValue);
        }
        Collections.reverse(intervalList);
        Iterator it = intervalList.iterator();
        while(it.hasNext()){
            int g = (int) it.next();
            insertionSort(A, g, n);
        }
    }
 
    private static void insertionSort(int[] A, int g, int n){
        for(int i = g; i < n; i++){
            int v = A[i];
            int j = i - g;
            while(j >= 0 && A[j] > v){
                A[j + g] = A[j];
                j = j - g;
                sortCount++;
            }
            A[j + g] = v;
        }
    }
}

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

using namespace std;

int main()
{
    int n ,result = 1e32;
    cin >> n ;
    int arr[n];
    for(int i=0 ; i<n ; i++)
        cin >> arr[i];

    sort(arr,arr+n);

    for(int i=arr[0] ;i<=arr[n-1]; i++){
        int sum = 0 ;
        for(int j=0 ; j<n ; j++){
            sum += (arr[j] - i) * (arr[j] - i) ;
        }
        if(sum < result){
            result = sum;
        }
    }

    cout << result ;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
D = tuple(map(int, input().split()))
maxd = max(D)
mod = 998244353
cd = [0] * (maxd+1)
for d in D:
    cd[d] += 1

pre_nodes = cd[0]
if pre_nodes != 1 or D[0] != 0:
    print(0)
    exit(0)

ans = 1
for i in range(1, maxd+1):
    nodes = cd[i]
    ans *= pow(pre_nodes, nodes, mod)
    ans %= mod
    pre_nodes = nodes
else:
    print(ans)


Measured memory_bytes: 85808
"use strict"
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const n = input.split("")
function main(n){
  	let ans = ""
	for(const n2 of n){
      	switch(n2){
          case "1" :
           	ans+="9"
           break
          case "9" :
          	ans+="1"
          break
          default :
          	ans+=n2
          break
        }
    }
  	return ans
}
        
console.log(main(n));

Measured memory_bytes: 21064
n, m = map(int, input().split())
if n%2==1:
    for i in range(m):
        print(i+1, n-i)
else:
    a = 0
    b = ((n-1)//2)//2
    if n%4 != 0:
        b -= 1
    for i in range(m):
        if i > b:
            a = 1
        print(i+1, n-i-a)

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

int main() {
  char x;
  cin >> x;
  if(x == 'A')
    cout << "T" << endl;
  if(x == 'T')
    cout << "A" << endl;
  if(x == 'C')
    cout << "G" << endl;
  if(x == 'G')
    cout << "C" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int M=105;
int n,m,a[M],b[M];
bool cmp(int a,int b){
	return (a&1)>(b&1);
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
		scanf("%d",&a[i]);
	if (m==1){
		if (a[1]==1)
			printf("%d \n%d\n%d",a[1],1,a[1]);
		else
			printf("%d \n%d\n%d %d",a[1],2,a[1]-1,1);
		return 0;
	}
	int t=0;
	for (int i=1;i<=m;i++)
		t+=a[i]&1;
	if (t>2)
		return puts("Impossible"),0;
	sort(a+1,a+m+1,cmp);
	if (a[2]&1)
		swap(a[2],a[m]);
	for (int i=1;i<=m;i++)
		b[i]=a[i];
	int _m=m;
	b[1]++,b[m]--;
	if (b[m]==0)
		_m--;
	for (int i=1;i<=m;i++)
		printf("%d ",a[i]);
	puts("");
	printf("%d\n",_m);
	for (int i=1;i<=_m;i++)
		printf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#ifndef debug_on
#define debug_on 0
#endif

#define dbg \
    if(debug_on) cerr << "DEBUG:"
#define ast(cond)           \
    do {                    \
        if((cond) == false) \
        {                   \
            if(debug_on)    \
            cerr << "ASSERT" << #cond " failed at line:" << __LINE__ << endl;   \
            exit(1);        \
        }                   \
    }while(0)

struct C
{
    int a, b, c;
};
int N, Ma, Mb;
vector<C> A;


int solve(int pick, int acc_cost, int acc_na, int acc_nb, int target_sum)
{
    if(acc_na + acc_nb > target_sum)
        return -1;
    if(pick >= 0)
    {
        const C c = A[pick];
        acc_na += c.a;
        acc_nb += c.b;
        acc_cost += c.c;
    }
    if(acc_na + acc_nb > target_sum)
        return -1;
    if(acc_na + acc_nb  == target_sum)
        return (acc_na * Mb == acc_nb * Ma) ? acc_cost : -1;

    int min_cost = -1;
    for(size_t i = pick + 1; i < A.size(); ++i)
    {
        const int cost = solve(i, acc_cost, acc_na, acc_nb, target_sum);
        if(cost >= 0 && (min_cost < 0 || min_cost > cost))
            min_cost = cost;
    }
    return min_cost;
}

int dp[41][401][401]; //target_na,target_nb = min_cost

int solve2(size_t pick, int target_na, int target_nb)
{
    if(pick >= A.size())
        return -1;
    int &d = dp[pick][target_na][target_nb];
    if(d != 0)
        return d;

    const C c = A[pick];
    if(c.a > target_na || c.b > target_nb)
        return d = -1;

    if(c.a == target_na && c.b == target_nb)
        return d = c.c;

    int min_cost = -1;
    for(int i = pick - 1; i >= 0; --i)
    {
        const int cost = solve2(i, target_na - c.a, target_nb - c.b);
        if(cost >= 0 && (min_cost < 0 || min_cost > cost))
            min_cost = cost;
    }
    if(min_cost > 0)
        return d = min_cost + c.c;

    return d = -1;
}


int main(int, char *[])
{
    cin >> N >> Ma >> Mb;
    int total_weight = 0;
    for(int i = 0; i < N; ++i)
    {
        C c;
        cin >> c.a >> c.b >> c.c;
        A.push_back(c);
        total_weight += c.a + c.b;
    }
    sort(A.begin(), A.end(), [] (C a, C b)->bool{return (a.a+a.b) < (b.a+b.b);});


    int min_cost = -1;
    for(int i = 1; i <= total_weight / (Ma + Mb); ++i)
    {
        const int ma = Ma * i;
        const int mb = Mb * i;
        for(size_t j = 0; j < A.size(); ++j)
        {
            const int cost = solve2(A.size() - 1 - j, ma, mb);
            if(cost >= 0 && (min_cost < 0 || min_cost > cost))
                min_cost = cost;
            dbg << "i:" << i << " j:" << j << " cost:" << cost << endl;
        }
    }
    cout << min_cost << endl;
    return 0;
}


Measured memory_bytes: 24448
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
using namespace boost::multiprecision;  
using namespace boost::math;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
//inline int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
//inline int lcm(int a,int b){ return a / gcd(a,b) * b;}
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
//}}}

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

    int n,k;
    cin >> n >> k;
    vector<int> h(n);

    rep(i,n){
        cin >> h[i];
    }

    int res = 0;
    sort(all(h));

    rep(i,n - k){
        res += h[i];
    }

    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    i = -1
    j = -1
    for k in range(len(S)-1):
        if S[k] == S[k+1]:
            i = k+1
            j = k+2
            break
        if k+2 < len(S) and S[k] == S[k+2]:
            i = k+1
            j = k+3
            break
    return '%d %d' % (i, j)


def main():
    S = read_str().strip()

    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 67692
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
		long x = sc.nextLong();

		long a[] = new long[n];
		long sum = 0;


		for(int i=0;i<n;i++) {
			a[i] = sc.nextLong();
			sum += a[i];
		}

		Arrays.sort(a);

		if(sum == x) {
			System.out.println(n);
		}else {
			int k = 0;
			for(int i=0;i<n;i++) {
				if(x >= a[i]) {
					x -= a[i];
					k += 1;
				}
			}
			if(k == n) {
				k -= 1;
			}
			System.out.println(k);
		}

    }

}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define plll pair<ll,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
//#define endl "\n"
const int MAX = 1e5+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll INF = 1e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

ll n,x[MAX],y[MAX],z,ttl,nw;

int main(){
//	cout<<fixed<<setprecision(15);
//    freopen("output.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    rep(i,1,n)cin>>x[i], z+=x[i];
    if(z%(n*(n+1)/2)!=0)return cout<<"NO\n",0;
    z/=n*(n+1)/2;
    rep(i,2,n){
    	if((z+x[i-1]-x[i])%n!=0)return cout<<"NO\n",0;
    	y[i-1] = (z+x[i-1]-x[i])/n;
	}
	if((z+x[n]-x[1])%n!=0)return cout<<"NO\n",0;
    y[n] = (z+x[n]-x[1])/n;
    rep(i,1,n)ttl+=y[i];
    if(ttl!=z)return cout<<"NO\n",0;
    nw = x[n]+z-n*y[n];
    rep(i,1,n){
    	if(nw!=x[i]||y[i]<0)return cout<<"NO\n",0;
    	nw+=z-n*y[i];
	}
	if(nw!=x[1])return cout<<"NO\n",0;
	cout<<"YES\n";
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
A = [int(x) for x in input().split()]

t = []

for i in range(N)[::-1]:
	if i%2!=(N%2):
		t.append(A[i])

for i in range(N):
	if i%2==(N%2):
		t.append(A[i])



print(*t)

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

int main() {
	// input
	int N; cin >> N;
	vector<int> V(N);
	vector<int> C(N);
	for (int i = 0; i < N; ++i) {
		cin >> V[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> C[i];
	}

	// compute
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		if (V[i] - C[i] > 0) {
			ans = ans + V[i] - C[i];
		}
	}

	//output
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define double long double
#define all(x) x.begin(), x.end()
 
using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
 
const i64 MOD = 998244353;
const i64 INF = 2e15;

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

	int n;
	cin >> n;

	vi a(n);
	REP(i, 0, n-1) cin >> a[i];

	REP(i, 0, n-1) {
		REP(j, 0, n-1) {						
			swap(a[i], a[j]);

			bool f = true;

			for (int b = 1; b < n; b++) {				
				if (a[b] <= a[b-1]) f = false;
			}

			if (f) {
				cout << "YES" << endl;
				return 0;
			}

			swap(a[i], a[j]);
		}
	}

	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(raw_input())
count = 0
res = 0
ais = map(int , raw_input().split())

for i,a in enumerate(ais):
	
	if a == i +1:
		count += 1
	else:
		#flush the count
		res += (count + 1)/2# + 1
		count = 0

if count: res +=  (count+1)/2 
print res

Measured memory_bytes: 88068
#include <cstdio>
typedef double db;
const db bas = 380000;
int n;
db ans;
inline char readc() {
    char ch = getchar();
    while (ch < 'A' || ch > 'Z') ch = getchar();
    return ch;
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        db t;
        scanf("%lf", &t);
        char opt = readc();
        if (opt == 'J') ans += t;
        else ans += t * bas;
        opt = readc(); opt = readc();
    }
    printf("%f\n", ans);
    return 0;
}


Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: i32,
        b: i32,
    }
    let mut ans = 0;
    for number in a..b+1 {
        if palindrome(number) {
            ans += 1;
        }
    }
    println!("{}",ans);
}

fn palindrome(number : i32) -> bool {
    let s = number.to_string().chars().collect::<Vec<char>>();
    let l = s.len() as usize;
    for id in 0..l/2 {
        if s[id] != s[l-1-id] {
            return false;
        }
    }
    true
}

Measured memory_bytes: 2196
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
using namespace std;

int main(){
  long n,k;
  cin >>n >>k;
  long ans=0;
  for(int i=0;n>0;i++){
    n/=k;
    ans++;
  }
  cout << ans << endl;
}



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

typedef unsigned long long ull;

int main(){
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	int n = s.size();
	int ans = 0, cnt = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'g'){
			if(cnt < n /2){
				cnt++;
				ans++;
			}
		} else {
			if(cnt >= n / 2) ans--;
			else cnt++;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define MOD 1000000007
char grid[1005][1005];
int dp[1005][1005];
int32_t main(){
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		cin>>grid[i];
	}
	for(int i=1;i<=h;i++){
		for(int j=0;j<w;j++){
			if(i==1 && j==0) dp[i][j]=1;
			else dp[i][j] = (grid[i][j]=='.')*((dp[i-1][j]+dp[i][j-1])%MOD);
		}
	}
	/*for(int i=1;i<=h;i++){
		for(int j=0;j<w;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<"\n";
	}*/
	cout<<dp[h][w-1];
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 998244353;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
const int biggg = 2000000000;
const long long bigggest = 1000000000000000000LL;
const double eps = .0000000001; 

int c[200001];
int colorcnt[200001];
vector<int> graph[200001];
long long cnts[200001];

int func(int node, int par){
    
    int mysub = 0;
    int b4 = colorcnt[c[node]];
    for (int i : graph[node]){
        if (i == par) continue;
        long long past = colorcnt[c[node]];
        int many = func(i, node);
        mysub += many;
        long long now = colorcnt[c[node]]-past;
        // ^ = how many is in tree below of same color
        long long res = many-now;
        cnts[c[node]] -= res*(res+1)/2;
        
    }
    colorcnt[c[node]] = b4+mysub+1;
    return mysub+1;
}
int main ()
{
  prep();
  long long n;
  cin >> n;
  for (int i=0; i<n; i++) cin >> c[i+1];
  for (int i=0; i<n-1; i++){
      int a, b;
      cin >> a >> b;
      graph[a].push_back(b);
      graph[b].push_back(a);
  }
  for (int i=1; i<=n; i++) cnts[i] = n*(n+1)/2;
  func(1, -1);
  for (int i=1; i<=n; i++){
      long long left = n-colorcnt[i];
      cnts[i] -= left*(left+1)/2;
  }
  for (int i=1; i<=n; i++) cout << cnts[i] << '\n';
  return 0;
}


Measured memory_bytes: 36392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll x; cin >> x;
    FOR(i, -200, 200)FOR(j, -200, 200) {
        if (ll(i) * i * i * i * i - ll(j) * j * j * j * j == x) {
            cout << i << " " << j << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 3608
n = int(input())
xy = [[int(i) for i in input().split()] for i in range(n)]
import itertools
l = [int(i) for i in range(n)]
path_length = 0
for p in list(itertools.permutations(xy)):
    for (x1,y1),(x2,y2) in zip(p,p[1:]):
        path_length += ((x1-x2)**2 + (y1-y2)**2)**0.5
print(path_length / len(list(itertools.permutations(l))))

Measured memory_bytes: 8052