akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int H, W;
int INF = 1e9;
vector<string> S;
vector<vector<ll> > d;
vector<vector<bool> > visited;
queue<pair<int, int> > nxt;
vector<int> dh = {1, 0, -1, 0};
vector<int> dw = {0, 1, 0, -1};

void BFS(int h, int w){
  queue<pair<int, int> > q;
  q.push({h, w});
  visited[h][w] = true;
  nxt.push({h, w});
  while(!q.empty()){
    auto cur = q.front(); q.pop();
    int ch = cur.first, cw = cur.second;
    REP(i, 4){
      if(ch+dh[i] < 0 || ch+dh[i] >= H || cw+dw[i] < 0 || cw+dw[i] >= W) continue;
      if(S[ch+dh[i]][cw+dw[i]] == '#') continue;
      if(visited[ch+dh[i]][cw+dw[i]]) continue;
      q.push({ch+dh[i], cw+dw[i]});
      d[ch+dh[i]][cw+dw[i]] = d[ch][cw];
      visited[ch+dh[i]][cw+dw[i]] = true;
      nxt.push({ch+dh[i], cw+dw[i]});
    }
  }
  return;
}

void magic(int h, int w){
  REP(i, 5){
    REP(j, 5){
      if(h-2+i < 0 || h-2+i >= H || w-2+j < 0 || w-2+j >= W || (i == 2 && j == 2)) continue;
      if(S[h-2+i][w-2+j] == '#') continue;
      if(visited[h-2+i][w-2+j]) continue;
      nxt.push({h-2+i, w-2+j});
      d[h-2+i][w-2+j] = d[h][w]+1;
      visited[h-2+i][w-2+j] = true;
    }
  }
  return;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  int Ch, Cw; cin >> Ch >> Cw; Ch--; Cw--;
  int Dh, Dw; cin >> Dh >> Dw; Dh--; Dw--;
  S.assign(H, "");
  d.assign(H, vector<ll>(W, INF));
  visited.assign(H, vector<bool>(W, false));
  REP(i, H){
    cin >> S[i];
  }
  d[Ch][Cw] = 0;
  BFS(Ch, Cw);
  if(d[Dh][Dw] == INF){
    while(!nxt.empty() && d[Dh][Dw] == INF){
      queue<pair<int, int> > tmp;
      swap(tmp, nxt);
      while(!tmp.empty()){
        auto cur = tmp.front(); tmp.pop();
        int cuh = cur.first, cuw = cur.second;
        magic(cuh, cuw);
      }
      swap(tmp, nxt);
      while(!tmp.empty()){
        auto cur = tmp.front(); tmp.pop();
        int cuh = cur.first, cuw = cur.second;
        BFS(cuh, cuw);
      }   
    }
  }
  if(d[Dh][Dw] != INF){
    cout << d[Dh][Dw] << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 12760
#include<iostream>
#include <iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main()
{
  ll n;
  cin >> n;
  vector<pair< ll,ll > >ab;
  for(int i = 0;i < n;i++)
  {
      ll a,b;
      cin >> a >> b;
      ab.push_back(make_pair(b,a));
  }
  sort(ab.begin(),ab.end());
  int ans = 0;
  for(int i = 0;i < n;i++)
  {
      ans += ab[i].second;
      if(ans > ab[i].first)
      {
          cout << "No" << endl;
          return 0;
      }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 6512
//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 1000000007LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#ifdef LOCAL_ENV
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define DUMP(x)
#define DEBUG(x)
#endif

#define MAX_VALUE 9223372036854775807LL

template <ull N, class T, class... Args, std::enable_if_t<N == 0, int> = 0>
auto make_multiple_vector(Args... args) {
    return T(args...);
}

template <ull N, class T, class... Args, std::enable_if_t<N != 0, int> = 0>
auto make_multiple_vector(ull size, Args... args) {
    using value_type = std::decay_t<decltype(make_multiple_vector<N - 1, T>(args...))>;
    return vector<value_type>(size, make_multiple_vector<N - 1, T>(args...));
}

// computational complexity: o(log(max(a, b))) 
inline ull get_gcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return get_gcd(b, a % b);
}

int solve() {
	ll N, N_;
	cin >> N;
	N_ = N;

	vector<ll> As;
	ll a;
	REPD(i, 0, N_) {
		cin >> a;
		if (a == 1) --N;
		else As.emplace_back(a);
	}

	if (N <= 1) RET("pairwise coprime");

	sort(As.begin(), As.end());
	ll max_A = *max_element(As.begin(), As.end());

	ll gcd = get_gcd(As[0], As[1]);
	REPD(i, 2, N) gcd = get_gcd(gcd, As[i]);

	if (gcd != 1LL) {
		if (N == N_) {RET("not coprime");}
		else {RET("setwise coprime");}
	}

	vector<bool> exist_a(max_A + 1, false);
	ll prev_a = -1;
	REPD(i, 0, N) {
		if (As[i] == prev_a) RET("setwise coprime");
		exist_a[As[i]] = true;
		prev_a = As[i];
	}

	ll sqrt_A;
	REPD(i, 0, max_A) {
		if (i * i <= max_A) {
			sqrt_A = i;
		}
		else break;
	}
	vector<bool> is_prime(max_A + 1, true);
	for (ll p = 2; p <= max_A; ++p) {
		if (!is_prime[p]) continue;
		ll multiple_count = 0;
		for (ll i = 1; p * i <= max_A; ++i) {
			is_prime[p * i] = false;
			if (exist_a[p * i]) ++multiple_count;
		}
		if (multiple_count >= 2) RET("setwise coprime");
	}

	RET("pairwise coprime");

	return 0;
}

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

	solve();
	// ll t;
	// cin >> t;
	// REPD(i, 0, t) solve();

	return 0;
}


Measured memory_bytes: 11484
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

priority_queue<pair<ll,int> > pq_w, pq_n;
int left_n = 0;
bool f_left[SIZE];
char name[SIZE][30];

void pq_ctrl(int member){

  
  while(pq_w.size() && f_left[pq_w.top().second]){
    pq_w.pop();
    left_n--;
  }
  
  while(pq_n.size() && f_left[pq_n.top().second])
    pq_n.pop();

  
  while((int)pq_w.size() - left_n > member/5){
    
    ll a = -pq_w.top().first;
    int b = pq_w.top().second;
    pq_w.pop();
    
    pq_n.push({a,b});

    printf("%s is not working now.\n",name[b]);

    while(pq_w.size() && f_left[pq_w.top().second]){
      pq_w.pop();
      left_n--;
    }
  }
  
  while(pq_w.size() - left_n < member/5){
    
    ll a = pq_n.top().first;
    int b = pq_n.top().second;
    pq_n.pop();
    
    pq_w.push({-a,b});

    printf("%s is working hard now.\n",name[b]);

    while(pq_n.size() && f_left[pq_n.top().second]){
      pq_n.pop();
    }
  }

}

int main(){
  int n,m,member;
  ll a[SIZE];
  map<string,int> dic;
  
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%s%lld",name[i],a+i);
    a[i] *= 1000000;
    a[i] += i;
    pq_w.push({-a[i],i});
    dic[name[i]] = i;
  }

  member = n;
  
  while(pq_w.size() > n/5){
    ll a = -pq_w.top().first;
    int b = pq_w.top().second;
    pq_w.pop();
    
    pq_n.push({a,b});
  }

  scanf("%d",&m);
  
  for(int i=n;i<n+m;i++){
    char c[2];

    scanf("%s",c);

    if(c[0] == '+'){
    
      scanf("%s%lld",name[i],a+i);
      dic[name[i]] = i;
      member++;
      
      a[i] *= 1000000;
      a[i] += i;

      if( (pq_w.empty() && member/5 >= 1 && pq_n.top().first < a[i]) ||
          (pq_w.size() && -pq_w.top().first < a[i]) ||
          (pq_n.size() && pq_n.top().first < a[i] && member%5 == 0)){

        pq_w.push({-a[i],i});
        printf("%s is working hard now.\n",name[i]);

      }else{
        pq_n.push({a[i],i});
        printf("%s is not working now.\n",name[i]);
      }
      
    }else{
      scanf("%s",name[i]);

      int id = dic[name[i]];

      f_left[id] = true;
      member--;

      if(pq_w.size() && -pq_w.top().first <= a[id]){
        left_n++;
      }
    }

    pq_ctrl(member);
  }
    
  
  
  return 0;
}

Measured memory_bytes: 13488
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  int n,x;
  cin>>n>>x;
  int sz=2*n-1;
  if(x==1||x==sz)cout<<"No\n";
  else {
    cout<<"Yes\n";
    rep(i,sz)cout<<1+(n+x+i-1)%sz<<"\n";
    }
  return 0;
  }
       

Measured memory_bytes: 1536
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int dp[200005][2];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	string s;
	cin >> s;
	rep(i, 200005) rep(j, 2) dp[i][j] = 0;
	dp[0][0] = (s[0] != '.');
	dp[0][1] = (s[0] != '#');
	repn(i, 1, n){
		dp[i][0] = dp[i - 1][0] + (s[i] != '.');
		dp[i][1] = min(dp[i - 1][1], dp[i - 1][0]) + (s[i] != '#');
	}
	cout << min(dp[n - 1][1], dp[n - 1][0]) << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/

Measured memory_bytes: 2196
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

string x;

int main(){

	while (cin>>x)
	{
		if (x == "0") break;
		int sum = 0;
		
		for (int i = 0; i < x.size(); i++){
			sum += x[i]-'0';
		}
		
		//Output
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        q[i] = p[i];
    }
    sort(all(q));
    int count = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] != q[i]) {
            count++;
        }
    }
    if (count <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
def show_nums(nums):
    for i in range(len(nums)):
        if i != len(nums) - 1:
            print(A[i], end = ' ')
        else:
            print(A[i])
            

N = int(input())
input_list = input().split(' ')
A = []
for i in input_list:
    A.append(int(i))
if len(input_list) != N:
    raise ValueError('N個の整数を入力してください。')

for i in range(N):
    v = A[i]
    j = i - 1
    while j >= 0 and v < A[j]:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    show_nums(A)



Measured memory_bytes: 5980
#include <iostream>

using namespace std;

unsigned long long n,t[100005],fv[100005],i,j,k,a,b,sum;

int main() 
{
    cin>>n;
    for (i=1; i<=n; i++)
        cin>>t[i],
        fv[t[i]]++,
        sum+=t[i];
        
    cin>>k;
    while(k--){
        cin>>a>>b;
        sum-=a*fv[a];
        sum+=b*fv[a];
        fv[b]+=fv[a];
        fv[a]=0;
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 5152
import sys
import itertools
import bisect

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


a, b = na()

if 1 <= a <= 9 and 1 <= b <= 9:
    print(a * b)
else:
    print(-1)





Measured memory_bytes: 3060
n = int(input())
AB = list(list(map(int,input().split())) for _ in range(n))
CD = list(list(map(int,input().split())) for _ in range(n))

CD.sort() # sort x in ascending order
AB.sort(key=lambda z: z[1], reverse=True) # sort x in descending order

dim_b = [[] for _ in range(n)]
for b in range(n):
    for r in range(n):
        if AB[r][0] < CD[b][0] and AB[r][1] < CD[b][1]:
            dim_b[b] += [r]

vis_r = [False]*(n)
for b in range(n): # ascending order of x
    max_ry = max_r = -1
    for r in dim_b[b]: # descending order of y
        if vis_r[r]: continue
        if max_ry < AB[r][1]: max_ry = AB[r][1]; max_r = r
    if max_r >= 0: vis_r[max_r] = True
print(sum(vis_r))


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	Rapid_pleaseAC_fast;

	int a, b;
	cin >> a >> b;

	for (double i = 10; i <= 1250; i += 1) {
		double x = i * 0.08;
		double y = i * 0.1;

		if ((int)x == a && (int)y == b) {
			cout << i << rt;
			return 0;
		}
	}

	cout << -1 << rt;

	please AC;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
int main() {
	int q;
	cin >> q;
	while (q--) {
		ll a, b;
		cin >> a >> b;
		ll l = 0, r = 2e9, m, res;
		while (l <= r) {
			m = (l + r) / 2;
			ll mid = max(1ll, m / 2 - 2);
			ll mx = 0;
			for (ll idx = mid; idx <= m && idx <= mid + 4; ++idx) {
				ll first = idx + (a <= idx);
				ll second = (m - idx + 1) + (b <= m - idx + 1);
				mx = max(mx, first*second);
			}
			if (mx < a*b) {
				res = m;
				l = m + 1;
			}
			else
				r = m - 1;
		}
		cout << res << endl;
	}
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define INF 1000000007
int main(){
int n,m;
cin>>n>>m;
if(abs(n-m)>1){
  cout<<0<<endl;
  return 0;
}
if(n==m){
  ll ans=1;
  while(n>0){
ans=(ans*n)%1000000007;
n--;
//cout<<ans<<endl;
  }
ans=(((ans*ans)%INF)*2)%1000000007;
cout<<ans<<endl;
return 0;
}else
{
  n=min(n,m);
  int A=n;
   ll ans=1;
  while(n>0){
ans=(ans*n)%1000000007;
n--;
  }
ans=(((ans*ans)%INF)*(A+1))%1000000007;
cout<<ans<<endl;
return 0;
}


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INT long long
#define oo (INT)(6e18)
using namespace std;

string s, t;
bool f(string x, string y)
{
    for(int i = 0 ; i < y.size() ; i++ )
    {
        if( x[i] == '?' ) continue;
        if( x[i] != y[i] ) return false;
    }
    return true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>s>>t;
	for(int i = s.size()-t.size() ; i >= 0 ; i-- )
    {
        if( f(s.substr(i, t.size()), t) )
        {
            for(int j = 0 ; j < s.size() ; j++ )
                if( i <= j and j < i+t.size() ) cout<<t[j-i];
                else
                {
                    if( s[j] == '?' ) cout<<"a";
                    else cout<<s[j];
                }
            return 0;
        }
    }
    cout<<"UNRESTORABLE\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int,int>> job(n);
	priority_queue<int> que;

	rep(i, n)
	{
		int a, b;
		cin >> a >> b;
		job[i] = make_pair(a, b);
	}
	sort(all(job));
	reverse(all(job));
	ll ans = 0;
	rep2(i, 1, m + 1)
	{
		while(job.back().first <= i){
			que.push(job.back().second);
			job.pop_back();
		}
		if(que.size()){
			ans += que.top();
			que.pop();
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n;
    cin>>n;
    int a[n];
    int cnt=1;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int b[n];
    for(int i=0;i<n;i++){
        b[i]=a[i]-(i+1);
    }
    ll ans=0;
    sort(b,b+n);
    int c=b[(n+1)/2-1];
    for(int i=0;i<n;i++){
        ans+=abs(b[i]-c);
    }
    cout<<ans<<endl;
 return 0;   
}

Measured memory_bytes: 1792
n=int(input())
A=list(map(int,input().split()))

def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)

l=[A[0]]* n
r=[A[-1]]*n
for i in range(n-1):
    l[i+1]=gcd(l[i], A[i+1])
    r[-i-2]= gcd(r[-i-1], A[-i-2])

ans=0
for i in range(n):
    if i==0:
        ans=max(ans, r[1]);continue
    if i==n-1:
        ans=max(ans, l[-2]);continue
    ans=max(ans, gcd(l[i-1], r[i+1]))
print(ans)

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    ll A, B, C;
    cin >> A >> B >> C;
    ll ans = 0;
 
    ll D = min(A, C); 
    ans += D;
    A -= D;
    C -= D;
    ll E = min(B, C);
    ans += E*2;
    B -= E;
    C -= E;
    ans += B;
    ans += (C>0);
    cout << ans << "\n";
    return 0;
}

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


int main() {
	int N;
	cin >> N;
	vector<long long> A(N);
	for (int n = 0;n<N;++n) {
		cin >> A[n];
	}
	vector<vector<long long>> DP(N, vector<long long >(2, -1e18));
	// i 番目までからj個を選んだ
	// jの範囲は i/2 -1 から(i+1)/2)
	for (int i = 1; i <= N; ++i) {
		for (int j = (i + 1) / 2; j >= i / 2 - 1; --j) {
			if (j < 0) {
				continue;
			}
			DP[j][0] = max(DP[j][0] ,DP[j][1]); 
			if (j>0) {
				if (-1e18 != DP[j - 1][0]) {
					DP[j][1] = DP[j - 1][0] + A[i-1];
				}
				else {
					DP[j][1] = A[i-1];
				}
			}
		}
	}
	long long ans = 0;
	ans = max(DP[N/2][0], DP[N/2][1]);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 15640
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator
const int MxN= 1e5+1;
ll ar[MxN];
void solve() {
    ll n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++) {
        ll a,b;
        cin>>a>>b;
        ar[a] += b;
    }
    int i=0;
    while(k>0) {
        k -= ar[i];
        i++;
    }
    cout<<i-1<<endl;
}

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

Measured memory_bytes: 1024
import std.stdio, std.algorithm;

char[111] chair; 
int n, m;

void main(){
	char ch;
	while (readf("%d %d\n", &n, &m), n || m) {
		chair[] = '#';
		foreach (i; 0..m) {
			readf("%c\n", &ch);
			if (ch == 'A') A();
			if (ch == 'B') B();
			if (ch == 'C') C();
			if (ch == 'D') D();
		}
		writeln(chair[0..n]);
	}
}

void A(){
	foreach (i; 0..n) {
		if (chair[i] == '#') {
			chair[i] = 'A';
			return;
		}
	}
}

void B(){
	foreach_reverse (i; 0..n) {
		if (chair[i] == '#' && (i == 0 || chair[i-1] != 'A') && (i == n-1 || chair[i+1] != 'A')) {
			chair[i] = 'B';
			return;
		}
	}
	foreach (i; 0..n) {
		if (chair[i] == '#') {
			chair[i] = 'B';
			return;
		}
	}
}

void C(){
	foreach (i; 0..n) {
		if (i+1 < n && chair[i] != '#' && chair[i+1] == '#') {
			chair[i+1] = 'C';
			return;
		}
		if (i-1 >= 0 && chair[i] != '#' && chair[i-1] == '#') {
			chair[i-1] = 'C';
			return;
		}
	}
	chair[n/2] = 'C';
}

void D(){
	int max = -1;
	int id = 0;
	foreach (i; 0..n) {
		if (chair[i] == '#' && distance(i) > max) {
			max = distance(i);
			id = i;
		}
	}
	chair[id] = 'D';
}

int distance(int p){
	int f, b;
	f = b = 0;
	foreach (i; p..n) {
		if (chair[i] != '#') break;
		b++;
	}
	if (b == n-p) b = 9999;
	foreach_reverse (i; 0..p+1) {
		if (chair[i] != '#') break;
		f++;
	}
	if (f == p+1) f = 9999;
	return min(b, f);
}

Measured memory_bytes: 1024
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((abs(b - a) <= d && abs(c - b) <= d) || abs(c - a) <= d) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

m,d = na()

a = 2
ans = 0

for a in range(2,10):
    for i in range(2,10):
        if a*10+i > d:
            continue
        if a*i <= m:
            ans += 1

print(ans)

Measured memory_bytes: 3064
def set_info(i, p, d):
    r = T[i]
    r[1], r[2] = p, d
    for c in r[0]:
        set_info(c, i, d+1)


n = int(input())
root = set(range(n))
T = [None] * n

for _ in range(n):
    A = list(map(int, input().split()))
    children = A[2:]
    T[A[0]] = [children, None, None]
    root -= set(children)

set_info(root.pop(), -1, 0)

for i,node in enumerate(T):
    ch, p, d = node
    print('node {}: parent = {}, depth = {}, {}, {}'.format(
            i, p, d, 'root' if not d else 'internal node' if ch else 'leaf', ch
        ))


Measured memory_bytes: 29428
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, k;
int f[N];

int32_t main()
{
	IOS;
	cin >> n >> k;
	for(int i = 1; i <= k; i++)
	{
		int x;
		cin >> x;
		for(int j = 1; j <= x; j++)
		{
			int y;
			cin >> y;
			f[y]++;
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++)
		ans += (f[i] == 0);
	cout << ans;
	return 0;
}

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

int main() {
  int N, K, d;
  cin >> N >> K;
  d = 0;
  for (int i = 0; i < N; i++) {
    int a, b, x;
    cin >> x;
    a = x * 2;
    b = (K - x) * 2;
    if (a > b) {
      d += b;
    }
    else {
      d += a;
    }
  }
  cout << d << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ac
//
//  Created by ?????£??? on 2017/5/26.
//  Copyright ?? 2017??´ ?????£???. All rights reserved.
//

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <memory>
#include <stdlib.h>
#include <cstring>
using namespace std;

struct task{
    string name;
    int time;
};

queue<task> t;

int n,q;
int sum=0;

void solve();
int main(){
    //freopen("/Users/mac/Desktop/C++?¨????/test/test.txt", "r", stdin);
    cin>>n>>q;
    for (int i=0; i<n; i++) {
        task p;
        cin>>p.name>>p.time;
        t.push(p);
    }
    solve();
    return 0;
}

void solve()
{
    while (t.size()) {
        task tmp=t.front();
        if (tmp.time<=q) {
            sum+=tmp.time;
            cout<<tmp.name<<' '<<sum<<endl;
            t.pop();
        }
        else{
            tmp.time-=q;
            sum+=q;
            t.pop();
            t.push(tmp);
        }
    }
}

Measured memory_bytes: 6252
#include <bits/stdc++.h>
#define int long long
using namespace std;
int d,p[15],c[15],g,ans=10000007;
signed main(){
	cin>>d>>g;
	for(int i=1;i<=d;i++){
		cin>>p[i]>>c[i];
	}
	for(int i=1;i<(1<<d);i++){
		int cnt=g,ansmemo=0;
		for(int j=0;j<d;j++){
			if((i>>j)&1){
				int memo=(p[d-j]-1)*(d-j)*100;
				if(cnt>memo){
					ansmemo+=p[d-j];
					cnt-=(d-j)*100*p[d-j]+c[d-j];
					if(cnt<=0)break;
				}else {
					if(cnt%((d-j)*100)){
						ansmemo+=cnt/((d-j)*100)+1;
						cnt-=(cnt/((d-j)*100)+1)*(d-j)*100;
					}else {
						ansmemo+=cnt/((d-j)*100);
						cnt-=(cnt/((d-j)*100))*(d-j)*100;
					}
					if(cnt<=0)break;
				}
			}
		}
		if(cnt<=0){
			ans=min(ans,ansmemo);
		}
	}
	cout<<ans<<endl;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main(){
    ll n,k;
    cin >> n >> k;
    // ll temp = abs(n - k);
    // while(temp > 0) {
    //     temp = temp - k;
    // }
    ll temp = n % k;
    // for(int i = 0; i < n; i++){
    //     temp = temp - k;
    //     if(temp < 0)break;
    // }

    ll ans = min(temp, abs(temp-k));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll t,a,b,i,j,k,n,x;
    cin>>n>>x;
    vector<ll>v;
    for(i=0;i<n;i++)
    {
        cin>>k;
        v.push_back(k);
    }
    ll c=0;
    for(i=0;i<n-1;i++)
    {
        ll p=v[i]+v[i+1];
        if(p>x)
        {
            ll q=p-x;
            if(v[i+1]>=q)
            {
                v[i+1]=v[i+1]-q;
                c+=q;
            }
            else
            {
                v[i+1]=0;
                q-=v[i+1];
                v[i]=v[i]-q;
                c+=q;
            }
        }

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


Measured memory_bytes: 4316
#include <iostream>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define YES(i) cout<<(i?"YES":"NO")<<endl
using namespace std;
int main(void){
    string s,t; cin>>s>>t;
    int x[100001]={},y[100001]={};
    FOR(i,0,s.size()){
        x[i+1]=x[i]+(s[i]=='A'?1:2);
    }
    cout<<endl;
    FOR(i,0,t.size()){
        y[i+1]=y[i]+(t[i]=='A'?1:2);
    }
    int q; cin>>q;
    FOR(i,0,q){
        int a,b,c,d; cin>>a>>b>>c>>d;
        YES((x[b]-x[a-1]-y[d]+y[c-1]+300000000)%3==0);
    }
}


Measured memory_bytes: 1664
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Main m = new Main();
    m.exec();
  }

  private void exec() {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    String s = scan.next();
    int max = 0;
    for (int i = 1; i < s.length() - 1; i++) {
      Set<String> x = createSet(s.substring(0, i));
      Set<String> y = createSet(s.substring(i));
      int count = 0;
      for (String value : x) {
        if (y.contains(value)) {
          count++;
        }
      }
      if (count > max) {
        max = count;
      }
    }
    System.out.println(max);
  }

  private Set<String> createSet(String value) {
    Set<String> charSet = new HashSet<String>();
    for (int i = 0; i < value.length(); i++) {
      charSet.add(value.substring(i, i + 1));
    }
    return charSet;
  }
}

Measured memory_bytes: 23508
//
// Created by Myabu on 2020/01/17.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>

using namespace std;
int gcd(int a, int b) {
    if (a%b == 0)
        return b;

    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main(void){
    int N;
    cin>>N;


    cout<<lcm(N,2)<<endl;



    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let s = get!(String).chars().collect::<Vec<_>>();

    if s.len()%2 == 1 {
        println!("No");
        return;
    }
    for i in 0..s.len()/2 {
        if !(s[2*i] == 'h' && s[2*i+1] == 'i') {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

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

    for(int i=0;i<S.length()-1;i++){
        if(S.at(i)==S.at(i+1)){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
}

Measured memory_bytes: 256
#N = int(input())
lis = []
N=1
for T in range(N):
	c = list(map(int, input().split()))
	maxi = max(c)
	sum = 0
	for i in c:
		sum = sum + (maxi - i)
	if sum%2 == 0:
		lis.append(sum//2)
	else:
		lis.append((sum+3)//2)
for i in lis:
	print(i)

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;


vector<P> split(ll w, ll h) {
    vector<P> ans;
    if (w > 1) {
        ll wa = w / 2;
        ans.push_back(P(wa * h, (w - wa) * h));
    }
    if (h > 1) {
        ll ha = h / 2;
        ans.push_back(P(ha * w, (h - ha) * w));
    }

    for (P p : ans) assert(p.second > 0 && p.first > 0);
    return ans;

}

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


    ll ans = INF;

    for (ll i = 1; i < h; i++) {
        ll bar1 = w * i;
        for (P bar23 : split(w, h - i)) {
            vector<ll> choco = {bar1, bar23.first, bar23.second};
            sort(choco.begin(), choco.end());
            ll now = choco.back() - choco.front();
            cmin(ans, now);
        }
    }
    for (ll i = 1; i < w; i++) {
        ll bar1 = h * i;
        for (P bar23 : split(h, w - i)) {
            vector<ll> choco = {bar1, bar23.first, bar23.second};
            sort(choco.begin(), choco.end());
            ll now = choco.back() - choco.front();
            cmin(ans, now);
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(a >= k) cout << k << endl;
    else if(a+b >= k) cout << a << endl;
    else cout << a-(k-a-b) << endl;
}


Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

//????????????????????????????´???¨?????????????°????
template<typename T>
T min_diff(const vector<T> &v, T x) {
	auto u = upper_bound(v.begin(), v.end(), x);
	if (u == v.begin())return v.front() - x;
	if (u == v.end())return x - v.back();
	return min(*u - x, x - *(u - 1));
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int d; cin >> d&&d;) {
		int n; cin >> n;
		int m; cin >> m;
		vector<int> D(n); rep(i, 1, n) { cin >> D[i]; }
		vector<int> k(m); rep(i, 0, m) { cin >> k[i]; }
		sort(all(D));
		D.emplace_back(d);
		dump(D);
		int ans = 0;
		rep(i, 0, m) {
			int u = upper_bound(D.begin(), D.end(), k[i]) - D.begin();
			ans += min_diff(D, k[i]);
			dump(ans);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
  int n, m, k;
  cin >> n >> m >> k;
  int count = 0;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      count = i * m;
      count = count + (n-i) * j - i * j;
      if(count == k){
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
S=input()
alf=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for i in range(len(S)):
  if S[i] in alf:
    alf.remove(str(S[i]))
  
if len(alf)>0:
  print(alf[0])
  exit()
print('None')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    string S;cin >> S;
    sort(all(S));
    bool ans = false;
    if(S[0] == S[1])if(S[1] != S[2])if(S[2] == S[3])ans = true;
    cout << (ans ? "Yes":"No") << endl;
    
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

struct union_find {
	vector<int> parent; //親の番号を格納する。親だった場合は-(その集合のサイズ)
	union_find(int N) {
		parent = vector<int>(N, -1); //parentの値を-1にする(すべてバラバラ)
	}
	int root(int A) { //Aがどのグループに属しているか調べる
		if (parent[A] < 0) return A;
		return parent[A] = root(parent[A]);
	}
	int size(int A) { //自分のいるグループの頂点数を調べる
		return -parent[root(A)];//親をとってきたい]
	}
	bool connect(int A, int B) { //AとBをくっ付ける．すでにつながっていた場合false
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) return false; //すでにくっついてるからくっ付けない
		if (size(A) < size(B)) swap(A, B); //大小が逆だったらひっくり返しちゃう。
		parent[A] += parent[B]; //Aのサイズを更新する
		parent[B] = A; //Bの親をAに変更する
		return true;
	}
};

int main(void)
{
    int N,M;
    cin >> N >> M;
    vector<int> X(M), Y(M), Z(M);
    union_find uf(N);
    REP(i, M){
        cin >> X[i] >> Y[i] >> Z[i];
        X[i]--;Y[i]--;
        uf.connect(X[i], Y[i]);
    }
    vector<int> ok(N, 0);
    int ans = 0;
    REP(i, N){
        if(uf.parent[i] < 0) ans++;
    }
    pr(ans);
}

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

int main(){
	int N;
	cin>>N;
	
	int L[N];
	for(int i=0;i<N;i++){
		cin>>L[i];
	}
	
	sort(L,L+N);
	int sum=0;
	for(int i=0;i<N-1;i++){
		sum+=L[i];
	}
	
	
	
	if(sum>L[N-1])
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<bitset>
#include<functional>
#include<climits>
using namespace std;
typedef pair<int,int>pii;
const int INF=1e9;
const int dx[]={0,-1,0,1},dy[]={-1,0,1,0};


int main(){
    int n;
    bool flag=false;
    while(scanf("%d",&n)!=EOF){
        if(flag)puts("");
        else flag=true;

        int a[5];
        for(int i=4;i>=0;i--){
            a[i]=n%10;
            n/=10;
        }

        for(int i=0;i<2;i++){
            for(int j=0;j<5;j++){
                if(a[j]/5==i)printf("*");
                else printf(" ");
            }
            puts("");
        }
        puts("=====");

        for(int i=0;i<5;i++){
            for(int j=0;j<5;j++){
                if(a[j]%5==i)printf(" ");
                else printf("*");
            }
            puts("");
        }
    }
    return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>
#include <list>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

int a, b, c, d;
vector<vl> dp;
lint mod = 998244353;

lint res(int x, int y){
    if (dp[x][y] != 0) return dp[x][y];
    if (x == a && y == b) return dp[x][y] = 1;
    if (x == a){
        return dp[x][y] = res(x, y-1)*x%mod;
    }
    if (y == b){
        return dp[x][y] = res(x-1, y)*y%mod;
    }
    lint ans = (res(x-1, y) + res(x, y-1));
    ans += (x-1)*res(x, y-1);
    ans += (y-1)*res(x-1, y);
    ans -= res(x-1, y-1)*(x-1)*(y-1);

    return dp[x][y] = ((ans % mod) + mod)%mod;
}

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

     cin>>a>>b>>c>>d;
     dp.assign(c+1, vl(d+1, 0));


     lint ans = res(c, d);
     cout<<ans;


}


Measured memory_bytes: 73996
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

diff = 0
m = 1000
n = 0
for i in range(N):
    temp = T - H[i] * 0.006
    diff = abs(temp - A)
    if diff < m:
        m = diff
        n = i+1
print(n)

Measured memory_bytes: 3060
if __name__ == '__main__':
    s = input().rstrip().split(' ')
    N = int(s[0])
    M = int(s[1])
    L = []
    R = []
    for i in range(M):
        s = input().rstrip().split(' ')
        L.append(int(s[0]))
        R.append(int(s[1]))

    res = list(range(1,N+1))
    res_min = 1
    res_max = N

    for i in range(M):
        res_min = max(res_min,L[i])
        res_max = min(R[i],res_max)

    print(max(res_max-res_min+1,0))


Measured memory_bytes: 14960
#include<bits/stdc++.h>
using namespace std;
int a[27][27];
int b[27];
int main(){
    int n,m,c;
    cin>>n>>m>>c;
    for(int i=1;i<=m;i++)
        cin>>b[i];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    int sum=0;
    for(int i=1;i<=n;i++){
        int ans=0;
        for(int j=1;j<=m;j++){
            ans+=a[i][j]*b[j];
        }
        ans+=c;
        if(ans>0)
            sum++;
    }
    cout<<sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;

int n, x;

int main(){
	while(cin >> n >> x){
		if(n == 0 && x == 0) break;
		int ans = 0;
		for(int i = 1; i <= n; i++){
			for(int j = i+1; j <= n; j++){
				for(int k = j+1; k <= n; k++){
					if(i+j+k == x) ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160