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

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

        int mn = n;
        for(int i=0; i<=n; i++){
                int cnt = 0, tmp = i;
                while(tmp){
                        cnt += tmp%6;
                        tmp /= 6;
                }
                tmp = n-i;
                while(tmp){
                        cnt += tmp%9;
                        tmp /= 9;
                }
                mn = cnt<mn? cnt:mn;
        }
        printf("%d\n", mn);
        return 0;
}

Measured memory_bytes: 256
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod = 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e18;
const int inf = 2e9;
const int nmax = 1e5+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;



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

    int n;
    cin>>n;
    vector<int>v(n);
    for(int &x : v) cin>>x;

    sort(v.rbegin(), v.rend());
    ll ret = v[0];
    for(int i=0, j=1; i<n-2; i++){
        ret += v[j];
        if(i%2) j++;
    }
    cout<<ret<<endl;

}
/*

*/


Measured memory_bytes: 3980
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b;
  cin >> a >> b;
  ll x = b - a;
  ll ans = 0;
  rep(i, x) ans += i;
  ans -= a;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		String[] inArray = in.split(" ");
		int a = Integer.parseInt(inArray[0]);
		int b = Integer.parseInt(inArray[1]);
		int ans = a -b;
		if (ans >=0){
			System.out.println(ans);
		} else {
			System.out.println(0);
		}

	}


}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.length();
    ll ans = n * 1LL * (n - 1) / 2;
    unordered_map <char, int> m;
    for (char z : s) {
        ans -= m[z];
        m[z]++;
    }
    ans++;
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=1e6+10;
const int mod=1e9+7;
const double pi=3.1415926535;
int w[3005],v[3005];
int dp[3005][3005][2];


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,t;
    cin>>n>>t;
    for(int i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=t-1;j++)
        {
            dp[i][j][1]=max(dp[i-1][j][1],dp[i-1][j][0]+v[i]);
            if(j>=w[i])
            {
                dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j-w[i]][0]+v[i]);
                dp[i][j][1]=max(dp[i][j][1],dp[i-1][j-w[i]][1]+v[i]);
            }
            else
            {
                dp[i][j][0]=dp[i-1][j][0];
            }
        }
    }
    cout<<dp[n][t-1][1]<<'\n';






}


Measured memory_bytes: 74076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

double ab(double aaa){if(aaa<0.0)return -aaa;else return aaa;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n;
    int t,a;cin>>t>>a;
    double now = 10000.0;
    int ans = 0;
    rep(i, n){
        double h;cin>>h;
        if(chmin(now, ab(a-(t-h*0.006)))){
            ans = i+1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
int pr[10004];
main (){
      int n;
      cin >> n;
      
      for (int i = 2; i*i <= n; i++){
             if (pr[i] == 0)
             for (int j = 2*i; j <=n; j+=i)
                  pr[j] = 1;
      }
      int ans = 1;
      for (int i = 2; i <= n ;i++){
             if (pr[i] == 0){
                     int k = i,a = 0;
                     while (n/k > 0){
                           a+=n/k;
                           k = k*i;
                     }
                     if (a > 0) ans*=(a + 1),ans%=1000000007;
             }
      }
      cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

string s;

int n;

void check()
{
	if(s=="Vacant")
		exit(0);
}

void query(int i)
{
	cout << i << endl;
	fflush(stdout);
	cin >> s;
	check();
}

int32_t main()
{
	cin >> n;

	query(0);

	if(s=="Male")
	{
		query(n-1);

		int l = 1, r = n-2;

		while(l<r)
		{
			int m = (l+r)/2;

			query(m);

			if((m%2==0 && s=="Female") || (m%2==1 && s=="Male"))
				r = m-1;
			else
				l = m+1;
		}

		query(l);
	}
	else
	{
		query(n-1);

		int l = 1, r = n-2;

		while(l<r)
		{
			int m = (l+r)/2;

			query(m);

			if((m%2==1 && s=="Female") || (m%2==0 && s=="Male"))
				r = m-1;
			else
				l = m+1;
		}

		query(l);
	}
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------


void _main() {
	int N, X;
	cin >> N >> X;
	int D=0;
	int L;
	int count = 1; //１はD1＝０の１回分
	rep (i,2,N+2) { //2からN+1まで
		cin >> L;
		D += L;
		if (D <= X) {
			count++;
		}
		else {
			break;
		}
	}
	
	cout << count << endl;
}

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

const int MAX_N = 200005;
const int R = 256 * 1024;

vector<int> P[MAX_N];
int n, q, B[MAX_N], T[2 * R];

int get_min(int x, int y) {
    x += R;
    y += R;
    int w = min(T[x], T[y]);
    while(x / 2 != y / 2) {
        if(x % 2 == 0) w = min(w, T[x + 1]);
        if(y % 2 == 1) w = min(w, T[y - 1]);
        x /= 2;
        y /= 2;
    }
    return w;
}

void update(int x, int w) { 
    x += R;
    T[x] = w;
    while(x > 1) {
        x /= 2;
        T[x] = min(T[2 * x], T[2 * x + 1]);
    }
}

int main() {
    for(int i = 1; i < 2 * R; i++) T[i] = MAX_N;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> B[i];
    cin >> q;
    for(int i = 1; i <= q; i++) {
        int l, r;
        cin >> l >> r;
        P[l].push_back(r);
    }
    int result = 0;
    for(int i = 1; i <= n; i++) if(B[i] == 0) result++;
    update(0, 0);
    for(int i = 1; i <= n; i++) {
        for(int r : P[i]) update(r, get_min(i - 1, r));
        update(i, min(T[i + R], T[i - 1 + R] + (B[i] == 1 ? 1 : -1)));
    }
    cout << result + T[n + R];
    
    return 0;
}


Measured memory_bytes: 11776
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def bfs(s):
    from collections import deque
    check = [0] * (n + 1)
    check[s] = 1
    q = deque([s])
    while q:
        now = q.popleft()
        for next in graph[now]:
            if check[next] == 0:
                check[next] = str(now)
                q.append(next)
    return check


n, m = map(int, readline().split())
graph = [[] for _ in range(n + 1)]
for i in range(m):
    a, b = map(int, readline().split())
    graph[a].append(b)
    graph[b].append(a)
print('Yes')
print('\n'.join(bfs(1)[2:]))


Measured memory_bytes: 40592
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) 
{ v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i]; }
template<class T, class U> void read_n(vector<pair<T, U>>& v, size_t n)
{ v = vector<pair<T, U>>(n); 
  for (lli i=0; i<n; ++i) cin >> v[i].first >> v[i].second; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, c;
vector<pair<lli, lli>> v[31];
multiset<pair<lli, lli>> m;
int main() {
  cin >> n >> c;
  for (lli i=0; i<n; ++i) {
    lli s, t, c; cin >> s >> t >> c;
    v[c].emplace_back(s, t);
  }
  for (lli i=0; i<=c; ++i) {
    sort(begin(v[i]), end(v[i]));
    if (!v[i].empty()) {
      lli s = v[i][0].first, t = v[i][0].second;
      for (lli j=1; j < v[i].size(); ++j) {
	lli ss = v[i][j].first, tt = v[i][j].second;
	if (t == ss) {
	  t = tt;
	} else {
	  m.emplace(s, t);
	  s = ss; t = tt;
	}
      }
      m.emplace(s, t);
    }
  }
  lli ans = 0;
  while (!m.empty()) {
    auto it = m.begin();
    auto p = *it;
    m.erase(it);
    while (true) {
      auto it = m.lower_bound(make_pair(p.second+1, p.second+1));
      if (it == m.end()) break;
      p = *it;
      m.erase(it);
    }
    ++ans;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 8576
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t w,h,n;
    cin >> w >> h >> n;
    vi x(n),y(n),a(n);
    rep(i,n) cin >> x.at(i) >> y.at(i) >> a.at(i);
    string white,black;
    rep(i,w) white.push_back('w');
    rep(i,w) black.push_back('b');
    vector<string> v(h,white);
    for(int i=0; i<n; i++){
        if(a.at(i)==1){
            for(int j=0; j<h; j++){
                for(int k=0; k<x.at(i); k++){
                    v.at(j).at(k) = 'b';
                }
            }
        }
        if(a.at(i)==2){
            for(int j=0; j<h; j++){
                for(int64_t k=x.at(i); k<w; k++){
                    v.at(j).at(k) = 'b';
                }
            }
        }
        if(a.at(i)==3){
            for(int j=0; j<w; j++){
                for(int k=0; k<y.at(i); k++){
                    v.at(k).at(j) = 'b';
                }
            }
        }
        if(a.at(i)==4){
            for(int j=0; j<w; j++){
                for(int64_t k=y.at(i); k<h; k++){
                    v.at(k).at(j) = 'b';
                }
            }
        }
    }
    int64_t res = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            res += v.at(i).at(j)=='w';
        }
    }
    cout << res << endl;
}


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

using namespace std;

int main(void) {
    int n;

    cin >> n;

    vector<int> ls(n);

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ls[i] = x;
    }

    sort(ls.begin(), ls.end());

    int count = 0;

    for (int i = n-1; i >= 1; i--) {
        for (int j = i-1; j >= 1; j--) {
            int d = j - min((long) j, (lower_bound(ls.begin(), ls.end(), ls[i] - ls[j] + 1) - ls.begin()));
            count += d;
        }
    }

    cout << count << endl;

    return 0;
}


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

/*
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <set>
*/

using namespace std;

typedef long long LL;
typedef double DB;
typedef unsigned int UI;
typedef pair<int, int> PII;

const int inf = 0x7f7f7f7f;

#define rdi() read<int>()
#define rdl() read<LL>()
#define rds(a) scanf("%s", a)
#define mk(i, j) make_pair(i, j)
#define pb push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = j; i <= k; i ++)
#define Rep(i, j, k) for (int i = j; i >= k; i --)
#define Edge(i, u) for (int i = head[u]; i; i = e[i].nxt)

template<typename t> t read() {
    t x = 0;
    int f = 1;
    char c = getchar();
    while (c > '9' || c < '0') f = c == '-' ? -1 : 1 , c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - 48 , c = getchar();
    return x * f;
}

template<typename t> void write(t x) {
    if (x < 0) {
        putchar('-'), write(-x);
        return;
    }
    if (x >= 10) write(x / 10);
    putchar(x % 10 + 48);
}

#define N 200010
struct aa {
    int l, r;
} a[N];
int n, m, i, ans, now;

bool cmp(aa a, aa b) {
    if (a.l == b.l) return a.r > b.r;
    return a.l < b.l;
}

struct bb {
    int val;
    bool operator < (const bb &t) const{
        return val > t.val;
    }
};

priority_queue < bb > Heap;

int main() {
    n = rdi(), m = rdi();
    for (i = 1; i <= n; i++) a[i].l = rdi(), a[i].r = rdi();
    sort(a + 1, a + n + 1, cmp);
    for (now = 1; now <= n; now++) if (a[now].l) break;
    now--;
    for (i = 1; i <= now; i++) Heap.push((bb){a[1].r});
    for (i = 1; i <= m; i++) {
        while (now < n && a[now + 1].l < i) now++, Heap.push((bb){a[now].r});
        if (now < n) {
            now++;
            if (++ans == n) break;
            continue;
        }
        if (!Heap.empty() && Heap.top().val <= i) {
            Heap.pop();
            if (++ans == n) break;
            continue;
        }
    }
    printf("%d\n", n - ans);
    return 0;
}

Measured memory_bytes: 2936
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 123456789;

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

int W, H;
int tab[30][30];
int bfs(PII a, PII b){
  VVI visited(30, VI(30, -1));
  visited[a.second][a.first] = 0;
  queue<PII> q;
  q.push(a);

  while(!q.empty()){
	PII p = q.front(); q.pop();
	if(p == b) return visited[b.second][b.first];
	REP(i,4){
	  PII t = p;
	  t.first += dx[i];
	  t.second += dy[i];
	  if(tab[t.second][t.first]!=0 && visited[t.second][t.first]==-1){
		visited[t.second][t.first] = visited[p.second][p.first]+1;
		q.push(t);
	  }
	}
  }
  return INF;
}

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

  while(true){
	cin >> W >> H;
	if(W == 0) break;
	fill((int*)tab, (int*)tab+30*30, 0);

	vector<PII> node;
	int px, py;
	for(int y=1;y<=H;++y) for(int x=1;x<=W;++x){
	  char c; cin >> c;
	  if(c == 'o'){
		px = x, py = y, tab[y][x] = 1;
	  }
	  else if(c == '*'){
		tab[y][x] = 1;
		node.PB(MP(x,y));
	  }
	  else if(c == '.')
		tab[y][x] = 1;
	}

	int sz = SZ(node);
	VI path(sz, 0), dist(30*30+1, 0);
	for(int i=0;i<sz;++i)
	  path[i] = bfs(MP(px,py), node[i]);

	VVI G(sz, VI(sz, INF));
	for(int i=0;i<sz;++i){
	  G[i][i] = 0;
	  for(int j=i+1;j<sz;++j){
		G[i][j] = G[j][i] = bfs(node[i], node[j]);
	  }
	}

	int ans = INF;
	int dp[1<<10][10];
	REP(i,1<<10) REP(j, 10) dp[i][j] = INF;
	REP(i,sz) dp[1<<i][i] = path[i];
	
	REP(i,1<<sz) REP(j,sz) REP(k,sz)
	  dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + G[j][k]);
	REP(i,sz) ans = min(ans, dp[(1<<sz)-1][i]);
	cout << (ans == INF? -1: ans) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1276
n = int(input())
s = input()
l = []

for i in range(1, len(s)):
    
    f = s[:i]
    b = s[i:]
    fset = list(set(s[:i]))
    bset = list(set(s[i:]))
    cnt = 0
   
    for j in fset:
        if bset.count(j) != 0:
            cnt += 1
    l.append(cnt)
   
print(max(l))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define intt long long
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
#define ii pair<intt,intt>
using namespace std;
int chek(int num)
{
    int sum=0;
    while(num!=0)
    {
        sum++;
        num/=10;
    }
    return sum%2;
}
int main()
{
    int n;
    cin>>n;
    int i;
    int ans=0;
    for(i=1;i<=n;i++)
        ans+=chek(i);
   cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b, x = 0;
    while (x == 0)
    {
        scanf ("%d %d", &a, &b);
        if (a != 0 && b != 0)
        {
            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < b; j++)
                {
                    printf("#");
                }
                printf("\n");
            }
            printf("\n");
        }
        if (a == 0 && b == 0)
        {
            x = 1;
        }
    }
}


Measured memory_bytes: 2116
n=int(input())
lis=list()
for i in range(n):
    a,b=map(str,input().split())
    b=int(b)
    
    if a=="S":
        lis.append(b)
    elif a=="H":
        lis.append(b+13)
    elif a=="C":
        lis.append(b+26)
    elif a=="D":
        lis.append(b+39)
        
for i in range(1, 53):
	if not (i in lis):
		if i <= 13:
			print("S {}".format(i - 0))
		elif i <= 26:
			print("H {}".format(i - 13))
		elif i <= 39:
			print("C {}".format(i - 26))
		else:
			print("D {}".format(i - 39))


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

int main(){
   int n,k; cin>>n>>k;
   vector<int> h(n);
   rep(i,n) cin>>h[i];
   sort(h.begin(),h.end());
   int mini=1e9;
   for(int i=0;i+k-1<n;i++){
      if((h[i+k-1]-h[i])<mini) mini=h[i+k-1]-h[i];
   }
   cout<<mini<<endl;
   return 0;
}

Measured memory_bytes: 640
s = input()
n = len(s)

if s[0] != "1" or s[n - 1] != "0":
  print("-1")
  exit()

for i in range(n):
  if s[i] != s[n - 2 - i]:
    print("-1")
    exit()

x = 1
for i in range(1, n):
  print(x, i + 1)
  if s[i - 1] == "1": x = i + 1

Measured memory_bytes: 49336
import sys
input = sys.stdin.readline

h,w,a,b=map(int,input().split())
l=[]
for i in range(b):
    l.append([0]*a+[1]*(w-a))
for _ in range(h-b):
    l.append([1]*a+[0]*(w-a))
for k in range(h):
    s=""
    for v in range(w):
        s+=str(l[k][v])
    print(s)

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

struct Product{
	std::string name;
	int amount;
};

int main(){
	std::vector<Product> v;

	int n;
	std::cin >> n;
	for(int i=0;i<n;i++){
		std::string name;
		int amount;
		std::cin >> name >> amount;
		auto it = std::find_if(v.begin(), v.end(), [&name](Product p){
					return p.name == name;
			});
		if(it == v.end()){
			v.push_back({name, amount});
		}else{
			it->amount += amount;
		}
	}

	std::sort(v.begin(), v.end(), [](Product lp, Product rp){
			if(lp.name.size() != rp.name.size())return lp.name.size() < rp.name.size();
			for(int i=0;i<lp.name.size();i++){
				if(lp.name[i] != rp.name[i])return lp.name[i] < rp.name[i];
			}
		});

	for(auto p : v){
		std::cout << p.name << " " << p.amount << std::endl;
	}
}

Measured memory_bytes: 1232
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

int n, a[100100];

int cmp(const void *x, const void *y){
    return *(int*)x - *(int*)y;
}

main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++)scanf("%d", &a[i]);
    qsort(a, n, 4, cmp);
    if(n%3){
        puts(a[n-1]?"No": "Yes");
        return 0;
    }
    if(a[0] == 0 && a[n/3-1] == 0 && a[n/3] == a[n-1]){
        puts("Yes");
    }else {
        if(a[0] == a[n/3-1] && a[n/3] == a[2*n/3-1] && a[2*n/3] == a[n-1] && (a[0] ^ a[n/3] ^ a[2*n/3]) == 0){
            puts("Yes");
        }else {
            puts("No");
        }
    }
    return 0;
}

Measured memory_bytes: 892
#include <cstdio>

int main()
{
	int N;
	int sum = 0;

	scanf("%d", &N);
	int tmp = N;
	while (tmp > 0) {
		sum += tmp % 10;
		tmp /= 10;
	}
	if (N % sum == 0) {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cstring>
#include <iomanip>
#include <queue>
#include <deque>
#include <cmath>
using namespace std;
#define inf 280201280201280201
#define mn 100005
#define FLN "test"
#define int long long
typedef pair<int, int> ii;
//constance

//common data structures and templates
template<typename T>
struct SegmentTree{
};
//gb
int n;
int a[mn];
int b[mn];
int s;
//functions here
void input(){
}
void solve(){
}

//#define LOCAL 1

signed main(signed argc, char** argv) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#ifdef LOCAL
	   freopen(FLN".inp", "r", stdin);
	   freopen(FLN".out", "w", stdout);
#endif
  cin >> n;
  for(int i=1; i<= n; ++i) cin >> a[i];
  a[0] = a[n+1] =  0;
  s = 0;
  for(int i=0; i<= n; ++i) b[i] = abs(a[i+1]- a[i]), s += b[i];
  for(int i=1; i<= n; ++i){
    cout << s-b[i-1]-b[i] + abs(a[i+1]-a[i-1]) << "\n";
  }
	return 0;
}


Measured memory_bytes: 2816
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  cout.precision(12);

  long X, A;

  cin >> X >> A;

  cout << (X < A ? 0 : 10) << endl;

  return 0;
}


Measured memory_bytes: 256
n,m=list(map(int,input().split()))
p=[]
for i in range(n):
  a=list(map(int,input().split()))
  p.append(a)
p.sort(key=lambda x:x[0])
num=0
ans=0
i=0
while num<m:
  ans=ans+p[i][0]*p[i][1]
  num=num+p[i][1]
  
  i=i+1
  
print(ans-(-m+num)*p[i-1][0])

  

Measured memory_bytes: 28476
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
using namespace std;
bool unusecol[101],unuserow[101];
int main(){
	int n,m;
	cin>>n>>m;
	char ch[n][m];
	for(int i=0;i<n;i++){
		bool b=true;
		for(int j=0;j<m;j++){
			cin>>ch[i][j];
			b=b&&(ch[i][j]=='.');
		}
		if(b)
			unuserow[i]=true;
	}
	for(int i=0;i<m;i++){
		bool b=true;
		for(int j=0;j<n;j++)
			b=b&&(ch[j][i]=='.');
		if(b)
			unusecol[i]=true;
	}
	for(int i=0;i<n;i++){
		bool b=false;
		for(int j=0;j<m;j++)
			if(unuserow[i]+unusecol[j]==0)
				cout<<ch[i][j],b=true;
		if(b)
			cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import fractions


def gcd(l, t):
    a = l.pop(0)
    for v in l:
        a = fractions.gcd(a, v)
        if a <= t:
            break
    return a


N = int(input())
*A, = map(int, input().split())
A.sort()

dp = [[1]*N for i in range(2)]
dp[0][0] = A[0]

a, b = A[0], A[-1]
for i in range(1, N):
    a = fractions.gcd(a, A[i])
    dp[0][i] = a
    b = fractions.gcd(b, A[N-i])
    dp[1][N-i] = b

ans = 1
for i in range(N):
    g = 1
    if i == 0:
        g = dp[1][1]
    elif i == (N-1):
        g = dp[0][-2]
    else:
        g = fractions.gcd(dp[0][i-1], dp[1][i+1])
    if g > ans:
        ans = g
print(ans)


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

struct Node {
    int id, cost;
    Node(int id, int cost) : id(id), cost(cost){}
};

int main() {
    int N, M;
    cin >> N >> M;
    int L[M], R[M], D[M];
    vector<Node> adj[N];
    for (int i = 0; i < M; i++) {
        cin >> L[i] >> R[i] >> D[i];
        L[i]--;
        R[i]--;
        adj[L[i]].push_back(Node(R[i], D[i]));
        adj[R[i]].push_back(Node(L[i], -D[i]));
    }
    int x[N];
    int flag[N]{};
    fill(x, x + N, INT32_MAX);
    for (int i = 0; i < N; i++) {
        if (flag[i] != 0) continue;
        x[i] = 0;
        deque<int> q;
        q.push_back(i);
        while (!q.empty()) {
            int v = q.front();
            flag[v] = 1;
            q.pop_front();
            for (int j = 0; j < adj[v].size(); j++) {
                int id = adj[v][j].id;
                int cost = adj[v][j].cost;
                if (x[id] == INT32_MAX) {
                    x[id] = x[v] + cost;
                    q.push_back(id);
                    flag[id] = 1;
                } else {
                    if (x[id] != x[v] + cost) {
                        cout << "No\n";
                        return 0;
                    }
                }
            }
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 12104
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
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;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int i,j,n,a,b;
	cin>>n;
	for(i=0;i<15;i++){
		for(j=0;j*4<26;j++){
			if(i*7+j*4==n){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
int n;
char c;

int main()
{
    int flag=1;
    cin>>n;
    cin>>c;
    if (n<2019) flag=0;
    cin>>n;
    cin>>c;
    if (n<5) flag=0;
    cin>>n;
    if (flag==0)
        cout<<"Heisei"<<endl;
    else cout<<"TBD"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
	int a, b, c, x, y;

	cin >> a >> b >> c >> x >> y;

	if (a + b < 2 * c){
		cout << a * x + b * y << endl;
	}
	else{
		int minNum = x < y ? x : y;
		int cost = minNum * 2 * c;
		if (x > y){
			if (a > 2 * c){
				cost += 2 * c * (x - minNum);
			}
			else{
				cost += a * (x - minNum);
			}
		}
		else{
			if (b > 2 * c){
				cost += 2 * c * (y - minNum);
			}
			else{
				cost += b * (y - minNum);
			}
		}
		cout << cost << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    ll n , a[200010] , b[200010],now=0;
    vector<pii> v;
    cin>>n;
    rep(i,n){
        cin>>a[i]>>b[i];
        v.pb(pii(b[i],a[i]));
    }
    sort(all(v));
    rep(i,n){
        now+=v[i].second;
        if(now>v[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

using namespace std;

using int64 = long long;

int main() {
  int N;
  int64 A[60];

  cin >> N;
  vector< int > neg2, neg1;
  bool used[60] = {};
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    if(A[i] == 2) used[i] = true;
    if(A[i] == -2) neg2.emplace_back(i);
    else if(A[i] == -1) neg1.emplace_back(i);
  }

  if(neg2.size() % 2 == 1) {
    if(neg1.size()) neg2.emplace_back(neg1[0]);
    else neg2.pop_back();
  }
  for(auto &p : neg2) used[p] = true;

  int ret = 0;
  for(int i = 0; i < N; i++) {
    if(used[i]) ++ret;
  }
  cout << ret << endl;
  for(int i = 0; i < N; i++) {
    if(used[i]) {
      cout << i + 1 << endl;
    }
  }
}


Measured memory_bytes: 3160
MODE = "stdio"
require 'matrix'

tmp = Array.new

class Integer
  def divisor_list2
    return [1] if self == 1
    (1..Math.sqrt(self).to_i).select do |i|
      self%i == 0
    end.map {|e| [e, self/e]}.flatten.uniq.sort
  end
end

if(defined? MODE)
  tmp = STDIN.read.split("\n")
else
  iotmp = "\
  5 4 2 4 1
  ".split("\n")
  iotmp.each{|s|
    tmp << s.strip
  }
end

class Rec
  def initialize(w,h,x,y,r)
    @w = w
    @h = h
    @x = x
    @y = y
    @r = r
  end

  def display
    if ((@x-0)-@r >= 0) && ((@w-@x)-@r >= 0)
      if(((@y-0)-@r >= 0) && ((@h-@y)-@r >= 0))
        return puts"Yes"
      end
    end
    puts"No"
  end
end


w,h,x,y,r = tmp[0].split(" ").map(&:to_i)

rec = Rec.new(w,h,x,y,r)

rec.display

Measured memory_bytes: 9260
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main() {
    ll H;cin>>H;
    ll ans=0;
    ll x=1;
    while(H>0){
        ans+=x;
        H/=2;
        x*=2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

string S;

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

  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0) {
      if (S[i] == 'R' || S[i] == 'U' || S[i] == 'D') {
      } else {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if (S[i] == 'L' || S[i] == 'U' || S[i] == 'D') {
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}

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

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let 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! {
    n: usize,
    q: usize,
    s: chars,
    query: [(usize, usize); q],
  }
  let mut dp = vec![0; n + 1];
  let mut prev_a = false;
  for (i, &c) in s.iter().enumerate() {
    dp[i + 1] = dp[i];
    if c == 'C' && prev_a {
      dp[i + 1] += 1;
    }
    prev_a = c == 'A';
  }
  for &(l, r) in &query {
    println!("{}", dp[r] - dp[l]);
  }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 1e5;

ll K, A, B;

ll solve() {
    if (A+2 >= B || K <= A)
        return K+1;
    ll k = K-(A-1);
    return A + k/2*(B-A) + (k&1);
}

int main() {
    cin >> K >> A >> B;
    cout << solve() << endl;
}


Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let b = v[1];
	let x = v[2];
	if x - a > b {
		println!("NO");
	}else if x < a {
		println!("NO");
	}else{
		println!("YES");
	}
}

Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        HashSet<Character> set = new HashSet<>();
        set.add('A');
        set.add('T');
        set.add('C');
        set.add('G');
        int max = 0;
        int count = 0;
        for( Character c : s.toCharArray()) {
            if (set.contains(c)) {
                count += 1;
                max = Math.max(count, max);
                continue;
            }
            max = Math.max(count, max);
            count = 0;
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int N = 3001;
const int mod = 1e9 + 7;
int power(int a, int b){
    int res = 1;
    while(b > 0){
        if(b % 2){
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
        b /= 2;
    }
    return res;
}
int dp[N][N], ndp[N][N];
int main(){
    int n, q, x, y, inv2 = power(2, mod - 2), ans = 0, a[N];
    scanf("%d %d", &n, &q);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            dp[i][j] = (a[i] > a[j]);
        }
    }
    for(int i = 1; i <= q; i++){
        scanf("%d %d", &x, &y);
        for(int j = 1; j <= n; j++){
            ndp[x][j] = (1LL * dp[y][j] * inv2 % mod + 1LL * inv2 * dp[x][j] % mod) % mod;
            ndp[j][x] = (1LL * dp[j][x] * inv2 % mod + 1LL * inv2 * dp[j][y] % mod) % mod;
        }
        for(int j = 1; j <= n; j++){
            ndp[y][j] = (1LL * dp[x][j] * inv2 % mod + 1LL * inv2 * dp[y][j] % mod) % mod;
            ndp[j][y] = (1LL * dp[j][y] * inv2 % mod + 1LL * inv2 * dp[j][x] % mod) % mod;
        }
        ndp[x][x] = ndp[y][y] = 0;
        for(int j = 1; j <= n; j++){
            if(j != x && j != y){
                dp[x][j] = ndp[x][j];
                dp[y][j] = ndp[y][j];
                dp[j][x] = ndp[j][x];
                dp[j][y] = ndp[j][y];
            }
        }
        dp[x][y] = (1LL * dp[y][x] * inv2 % mod + 1LL * inv2 * dp[x][y] % mod) % mod;
        dp[y][x] = dp[x][y];
    }
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            ans += dp[i][j];
            ans %= mod;
        }
    }
    ans = 1LL * ans * power(2, q) % mod;
    printf("%d\n", ans);
    return 0;
}

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

int main(){
        int n, m = 2, a[35] = {1, 1, 2};
        while(cin >> n && n){
                if(n > m){
                        for(int i = m+1; i <= n; i++){
                                    a[i] = a[i-3] + a[i-2] + a[i-1];
                        }
                        m = n;
                }
                cout << (a[n] + 3649) / 3650 << endl;
        }
        return 0;
}

Measured memory_bytes: 1160
n = gets.to_i
array = []
for i in (0..n-1)
  array[i]=gets.to_i
end
m=0
array.each do |a|
  if a%2 ==0 then
    m +=1
end
end

if m == array.size then
  answer = "second"
else
  answer = "first"
end

puts answer


Measured memory_bytes: 3144
#include<stdio.h>
int main(void){
  char s[3];
  int x=0;
  scanf("%s",s);
  
  for(int j=0;j<3;j++){
    if(s[j]=='a'){
      x+=1;
    }
    else if(s[j]=='b'){
      x+=2;
    }
    else if(s[j]=='c'){
      x+=3;
    }
  }

  if(x==6){
    printf("Yes");
  }
  else
    printf("No");
 return 0;
}

Measured memory_bytes: 128
/*
    ~A_Pessimist~:)
*/

#include<bits/stdc++.h>
#define ll long long int
using namespace std;

void solve()
{
    ll x,k,d,rem,dis,fro,bac,lagbe;
    cin>>x>>k>>d;
    x=abs(x);
    dis=x;
    lagbe=dis/d;

    if(lagbe<=k) x-=lagbe*d, k-=lagbe;
    else x-=k*d, k=0;

    if(k>0 && k%2)
    {
        fro=x+d;
        bac=x-d;
        x=min(abs(fro), abs(bac));
    }
    cout<<x<<endl;
}

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

    int t=1;
    //cin>>t;

    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3616
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__ == "__main__":
    n = int(input())
    x = list(map(int,input().split()))
    y = x[:]
    y.sort()
    L = y[n//2-1]
    R = y[n//2]
    for i in range(n):
        if x[i] <= L:
            print(R)
        else:
            print(L)

Measured memory_bytes: 25708
import sys
import statistics

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    ave = statistics.mean(A)

    diff = f_inf
    res = 0
    for i in range(n):
        if diff > abs(A[i] - ave):
            res = i
            diff = abs(A[i] - ave)

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 5068
#include<cstdio>
int a,b,c,x,ans;
int main(){//500*a,100*b,c*50
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++)
				if(i*500+j*100+k*50==x)
					ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 128
n=int(input())

dish=[]

for s in range(n):
    a,b=map(int,input().split())
    dish.append([a+b,a,b])

dish.sort()
dish.reverse()

ans=0
takahashi=True

for turn in dish:
    if takahashi:
        takahashi=False
        ans+=turn[1]
    else:
        takahashi=True
        ans-=turn[2]

    #print(ans)
print(ans)

Measured memory_bytes: 24916
#include<stdio.h>

int main(void){
  int n,k,q;
  
  scanf("%d %d %d",&n,&k,&q);
  
  int a[100000]={}, m;
  
  for(int i=0; i < q; i++){
    scanf("%d",&m);
    a[m-1] ++;
  }
  
  for(int i=0; i < n; i++)
    printf("%s\n",a[i]+k <= q ? "No" : "Yes");
  
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
long long gcd(long long a, long long b){
    if(b==0) return a;
    return gcd(b,a%b);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
    ll q;
    cin>>q;
    while(q--){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        if(a<b || b>d){
            cout << "No\n";
            continue;
        }
        if(b-1<=c){
            cout << "Yes\n";
            continue;
        }
        ll g = gcd(b,d);
        ll t = (b - a%g + g-1)/g*g + a%g - g;
        if(c>=t){
            cout << "Yes\n"; 
        }
        else cout << "No\n";

    }
    
}

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

int ans[2001];

inline void gs(int x){
	for(int i=1;i<x;++i)ans[i]+=x-i;
}

inline void gp(int a,int b){
	//cout<<a<<" "<<b<<endl;
	int i;
	if(b<=a){
		for(i=1;i<=b;++i)ans[i]+=i;
		for(;i<=a;++i)ans[i]+=b;
		for(;i<a+b;++i)ans[i]+=a+b-i;
	}
	else{
		for(i=1;i<=a;++i)ans[i]+=i;
		for(;i<=b;++i)ans[i]+=a;
		for(;i<a+b;++i)ans[i]+=a+b-i;
	}
	for(i=1;i<=b;++i)--ans[i];
}

inline void ks(int x){
	--ans[1];
	for(int i=2;i<=x>>1;++i)ans[i]-=2;
}

inline void hs(int x){
	for(int i=1;i<=x>>1;++i)ans[i]+=x;
	if(x%2==0)ans[x>>1]-=x>>1;
}

int main(){
	int n,x,y;
	cin>>n>>x>>y;
	memset(ans,0,sizeof(ans));
	
	int i;
	int huan=y-x-1,mh=x+y>>1,zh=mh-x,yh=huan-zh;
	
	gs(n-huan);
	//for(i=1;i<n;++i)cout<<ans[i]<<endl;
	
	if(huan>0){
		gp(x,zh);
		//for(i=1;i<n;++i)cout<<ans[i]<<endl;
		
		gp(x+1,yh);
		//for(i=1;i<n;++i)cout<<ans[i]<<endl;
		
		gp(n-y+2,yh);
		//for(i=1;i<n;++i)cout<<ans[i]<<endl;
		
		gp(n-y+1,zh);
		//for(i=1;i<n;++i)cout<<ans[i]<<endl;
		
		ks(huan+2);
		//for(i=1;i<n;++i)cout<<ans[i]<<endl;
		
		hs(huan+2);
		
	}
	
	
	for(i=1;i<n;++i)cout<<ans[i]<<endl;
	
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
using namespace std;

typedef pair<int, int> p;
typedef pair<p, int> dat;
const int size = 1000;

int main(){
	int H, W, N;
	int sx, sy, nx, ny, c, res;
	char field[size + 1][size + 1];
	bool checked[size][size];
	queue<dat> que;
	p point, P, goal;
	dat save;
	
	scanf("%d%d%d", &H, &W, &N);
	for(int i = 0; i < H; i++) scanf("%s", field[i]);
	
	for(int y = 0; y < H; y++){
		for(int x = 0; x < W; x++){
			if(field[y][x] == 'S'){
				point.first = x; point.second = y;
				break;
			}
		}
	}
	
	res = 0;
	for(int i = 0; i < N; i++){
		for(int y = 0; y < H; y++){
			for(int x = 0; x < W; x++){
				if(field[y][x] == i + 49){
					goal.first = x; goal.second = y;
					break;
				}
			}
		}
		for(int y = 0; y < H; y++){
			for(int x = 0; x < W; x++){
				checked[y][x] = false;
			}
		}
		
		save.first = point; save.second = 0;
		que.push(save);
		while(!que.empty()){
			dat d = que.front(); que.pop();
			P = d.first; c = d.second;
			
			nx = P.first; ny = P.second;
			
			if(nx == goal.first && ny == goal.second){
				res += c;
				while(!que.empty()) que.pop();
				break;
			}
			//up
			if(ny > 0 && !checked[ny - 1][nx] && field[ny - 1][nx] != 'X'){
				checked[ny - 1][nx] = true;
				point.first = nx; point.second = ny - 1;
				save.first = point; save.second = c + 1;
				que.push(save);
			}
			//down
			if(ny + 1 < H && !checked[ny + 1][nx] && field[ny + 1][nx] != 'X'){
				checked[ny + 1][nx] = true;
				point.first = nx; point.second = ny + 1;
				save.first = point; save.second = c + 1;
				que.push(save);
			}
			//left
			if(nx > 0 && !checked[ny][nx - 1] && field[ny][nx - 1] != 'X'){
				checked[ny][nx - 1] = true;
				point.first = nx - 1; point.second = ny;
				save.first = point; save.second = c + 1;
				que.push(save);
			}
			//right
			if(nx + 1 < W && !checked[ny][nx + 1] && field[ny][nx + 1] != 'X'){
				checked[ny][nx + 1] = true;
				point.first = nx + 1; point.second = ny;
				save.first = point; save.second = c + 1;
				que.push(save);
			}
		}
		
		point.first = goal.first; point.second = goal.second;
	}
	
	printf("%d\n", res);
	
	return 0;
}

Measured memory_bytes: 3004