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


#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned

#define mod 1000000007
#define MAXN 100000
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main() 
{ 
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans = a*(n/(a+b));
    ans += min(n%(a+b),a);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 510000;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const ll longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


ll n, a[5], ans;

int main() {

	cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

	sort(a, a + 5);

	if (n % a[0] != 0)ans = n / a[0] + 1;
	else ans = n / a[0];

	cout << ans + 4 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define llint long long
#define inf 1e9

using namespace std;
typedef pair<llint, llint> P;

struct edge{
  llint to, cost;
  edge(){}
  edge(llint a, llint b){
    to = a, cost = b;
  }
};

llint n, m, c;
vector<edge> g[105], G[150005];
llint dist[150005];

void dijkstra()
{
  for(int i = 1; i <= n+m*n; i++) dist[i] = inf;
  dist[1] = 0;

  priority_queue<P, vector<P>, greater<P> > Q;
  Q.push(make_pair(0, 1));

  llint v, d;
  while(Q.size()){
    d = Q.top().first;
    v = Q.top().second;
    Q.pop();
    if(dist[v] < d) continue;
    for(int i = 0; i < G[v].size(); i++){
      if(dist[G[v][i].to] > d + G[v][i].cost){
        dist[G[v][i].to] = d + G[v][i].cost;
        Q.push(make_pair(dist[G[v][i].to], G[v][i].to));
      }
    }
  }
}

int main(void)
{
  while(1){
    cin >> n >> m >> c;
    if(n == 0 && m == 0 && c == 0) break;
    for(int i = 1; i <= n; i++) g[i].clear();

    llint u, v, w;
    for(int i = 1; i <= m; i++){
      cin >> u >> v >> w;
      g[u].push_back(edge(v, w));
    }

    for(int i = 1; i <= n; i++){
      for(int j = 0; j <= m; j++){
        G[i+j*n].clear();
      }
    }
    for(int i = 1; i <= n; i++){
      for(int j = 0; j < g[i].size(); j++){
        llint v = g[i][j].to;
        for(int k = 0; k <= m; k++){
          G[i+k*n].push_back(edge(v+k*n, g[i][j].cost));
          if(k+1 <= n) G[i+k*n].push_back(edge(v+(k+1)*n, 0));
        }
      }
    }

    dijkstra();
    llint ans;
    for(int i = 0; i <= m; i++){
      if(dist[n+i*n] <= c){
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 39196
from heapq import heapify, heappop, heappush
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1
S = [input().rstrip() for _ in [0]*H]

INF = 10**10
D = [[INF]*W for _ in [0]*H]
used = set()

q = []
heappush(q, (0, Ch*W+Cw))


while q:
    d, ij = heappop(q)
    i, j = divmod(ij, W)

    for di in range(-2, 3):
        for dj in range(-2, 3):
            if di == dj == 0:
                continue
            I = i+di; J = j+dj
            if 0 <= I < H and 0 <= J < W and S[I][J] == '.':
                if abs(di)+abs(dj) == 1:
                    if D[I][J] <= d:
                        continue
                    D[I][J] = d
                    heappush(q, (d, I*W+J))
                else:
                    if D[I][J] <= d+1:
                        continue
                    D[I][J] = d+1
                    heappush(q, (d+1, I*W+J))

ans = D[Dh][Dw]
print(ans if ans < INF else -1)


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

int main() {
  int N, L;
  std::cin >> N >> L;
  std::string S[N];
  for (int i = 0; i < N; ++i) {
    std::cin >> S[i];
  }

  std::sort(S, S + N);
  for (int i = 0; i < N; ++i) {
    std::cout << S[i];
  }
  std::cout << std::endl;

  return 0;
}


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

using i64 = std::int64_t;

#define REP(i, n) for (i64 i = 0; i < (n); ++i)

namespace io {
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline i64 scan() {
    i64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(i64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

using P = pair<i64, i64>;

i64 collect(i64 n, const vector<i64> &G, const vector<i64> &H, i64 u, i64 v, i64 p) {
  if (u == v) return 0;
  REP(i, n - 1) {
    if (!((G[u] >> i) & 1)) continue;
    i64 t = H[i] ^ u;
    if (t == p) continue;
    i64 s = collect(n, G, H, t, v, u);
    if (s != -1) {
      return s | (1LL << i);
    }
  }
  return -1;
}

signed main() {
  i64 n = io::scan();
  auto G = vector<i64>(n);
  auto H = vector<i64>(n);
  REP(i, n - 1) {
    i64 a = io::scan() - 1;
    i64 b = io::scan() - 1;
    G[a] |= 1LL << i;
    G[b] |= 1LL << i;
    H[i] = a ^ b;
  }
  i64 m = io::scan();
  auto paths = vector<i64>(m, 0);
  REP(j, m) {
    i64 u = io::scan() - 1;
    i64 v = io::scan() - 1;
    paths[j] = collect(n, G, H, u, v, -1);
  }
  i64 ans = 0;
  REP(s, 1LL << m) {
    i64 mask = 0;
    REP(j, m) {
      if ((s >> j) & 1) {
        mask |= paths[j];
      }
    }
    if (__builtin_parityll(s)) {
      ans -= 1LL << (n - 1 - __builtin_popcountll(mask));
    } else {
      ans += 1LL << (n - 1 - __builtin_popcountll(mask));
    }
  }
  io::print(ans);
  io::flush();
}


Measured memory_bytes: 256
n = int(input())
aoki, takahashi = [], []
for i in range(n):
    t, a = [ int(v) for v in input().split() ]
    aoki.append((-t-a, -a, i))
    takahashi.append((-a-t, -t, i))
dish_list = [1] * n
aoki.sort(), takahashi.sort()

a_score, t_score = 0, 0
a_counter, t_counter = 0, 0
for i in range(n):
    stop = 0
    if i % 2 == 0:
        while not stop:
            if dish_list[takahashi[t_counter][2]] == 1:
                t_score -= takahashi[t_counter][1]
                dish_list[takahashi[t_counter][2]] = 0
                stop = 1
            t_counter += 1
    else:
        while not stop:
            if dish_list[aoki[a_counter][2]] == 1:
                a_score -= aoki[a_counter][1]
                dish_list[aoki[a_counter][2]] = 0
                stop = 1
            a_counter += 1
print(t_score - a_score)

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

using namespace std;

vector<int> g[100001];
int col[100001];

int dfs(int v, int c) {
	col[v] = c;
	int ans = c - 1;
	for (int u : g[v]) {
		if (col[u] == 0)
			ans += dfs(u, 3 - c);
		if (col[u] == col[v])
			return -1e8;
	}
	return ans;
}

int main() {
	int n, m, a, b;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	a = dfs(1, 1);
	if (a < 0)
		printf("%lld\n", (long long) n * (n - 1) / 2 - m);
	else
		printf("%lld\n", (long long) a * (n - a) - m);
}

Measured memory_bytes: 7168
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node  {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur = nil->next;
    while ( cur != nil && cur->key != key ) {
        cur = cur->next;
    }
    return cur;
}

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while (1) {
        if ( cur == nil ) break;
        if ( isf++ > 0 ) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t) {
    if ( t == nil ) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}


void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}


int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for ( i = 0; i < n; i++ ) {
        scanf("%s%d", com, &key);
        if ( com[0] == 'i' && com[5] == 't') { insert(key); np++; size++; }
        else if ( com[0] == 'd' ) {
            if ( strlen(com) > 6 ) {
                if ( com[6] == 'F' ) deleteFirst();
                else if ( com[6] == 'L' ) deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }

    printList();

    return 0;
}


Measured memory_bytes: 33944
#include <iostream>
#include <map>

using namespace std;

int main() {
  int N;
  cin >> N;
  map<int, int> ds;
  int d;
  for(int i = 0; i < N; ++i) {
    cin >> d;
    ds[d]++;
  }

  int M;
  cin >> M;
  int t;
  for(int i = 0; i < M; ++i) {
    cin >> t;
    ds[t]--;
  }

  for(auto d : ds) {
    if(d.second < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }

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

Measured memory_bytes: 9600
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,m;
    char s[100];
    scanf("%d",&n);
    scanf("%s",s);
    m=strlen(s);
    if(m<=n)
        printf("%s",s);
    else
        {
            for(i=0;i<n;i++)
                printf("%c",s[i]);
            printf("...");
        }
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int n;
int mi=INF;

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

	cin>>n;
	REP(i,n) {
		int a;cin>>a;
		int cnt=0;
		while(a%2==0) {
			cnt++,a/=2;
			if(cnt>=mi) break;
		}
		mi=min(cnt,mi);
	}
	cout<<mi<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
using Attack = pair<int, int>; // 与えるダメージ 回数 1 or 0

int main() {
  int N, Hp;
  cin >> N >> Hp;
  vector<Attack> attacks;
  {
    int a, b;
    for(int i = 0; i < N; ++i) {
      cin >> a >> b;
      attacks.push_back(Attack(-a, 0));
      attacks.push_back(Attack(-b, 1));
    }
  }
  sort(attacks.begin(), attacks.end());
  int count = 0;
  int ai = 0;
  while(Hp > 0) {
    auto atk = attacks[ai];
    // cout << Hp << " : " << atk.first << endl;
    if(atk.second == 1) {
      Hp += atk.first; // ダメージはマイナスなので
      ai++;
      count++;
    } else {
      auto d = -atk.first;
      count += Hp / d + (Hp % d == 0 ? 0 : 1);
      Hp += atk.first * count;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    int n,a,b;
    cin>>n>>a>>b;
    cout << min(a*n,b);
}



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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x + r <= W && y + r <= H && x - r >= 0 && y - r >= 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	
	return 0;
}


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

long long x[3] = {2, 3, 5};
long long a[3] = {};
long long t, n, d;

long long solve();

int main() {
  cin >> t;
  while (t--) {
    cin >> n >> a[0] >> a[1] >> a[2] >> d;
    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  map<long long, long long> mp;
  mp[n] = 0;
  mp[0] = 1e18;
  using P = pair<long long, long long>;
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push(P(0, n));
  while (pq.size()) {
    auto [cost, num] = pq.top();
    pq.pop();
    if (cost > mp[0]) return mp[0];
    if (cost > mp[num]) continue;
    if (num == 0) return cost;
    long long nextcos = cost, nextnum = num;
    if (cost + num * d >= 0) mp[0] = min(mp[0], cost + num * d);
    for (int i = 0; i < 3; ++i) {
      nextnum = num, nextcos = cost;
      long long tmp = x[i] - num % x[i];
      nextnum += tmp;
      nextnum /= x[i];
      nextcos += d * tmp;
      nextcos += a[i];
      if (mp.find(nextnum) == mp.end() || mp[nextnum] > nextcos) {
        mp[nextnum] = nextcos;
        pq.push(P(nextcos, nextnum));
      }
      nextnum = num, nextcos = cost;
      tmp = num % x[i];
      nextnum -= tmp;
      nextnum /= x[i];
      nextcos += d * tmp;
      nextcos += a[i];
      if (mp.find(nextnum) == mp.end() || mp[nextnum] > nextcos) {
        mp[nextnum] = nextcos;
        pq.push(P(nextcos, nextnum));
      }
    }
  }
  return mp[0];
}

Measured memory_bytes: 4624
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long long n, i, j, k, best, a, b, c;
	cin >> n;
	best = 1000;
	for (i = 1; i <= sqrt(n); i++) {
		if (n % i == 0) {
			a = i;
			b = n / i;
			c = max(to_string(a).length(), to_string(b).length());
			best = min(best, c);
		}
	}

	cout << best << "\n";

	return 0;
}



Measured memory_bytes: 512
//#pragma GCC optimize ("-O3","unroll-loops")
// #pragma GCC target("avx")
#include<bits/stdc++.h>
 
using namespace std;
 
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
 
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;

void solve() {
	int A[3];
	REP(i,3)cin>>A[i];
	int sum=0;
	REP(i,3)sum+=A[i];
	if(sum>=22)print("bust");
	else print("win");
}
 
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 256
#include<stdio.h>


typedef struct{
int v[100];
int k;
} Roll;


int jag(Roll,int);
int main(){
  int n;
  Roll A[101];
  int i,j;
  int T;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&T);
    scanf("%d",&A[i].k);
    for(j=0;j<A[i].k;j++){
      scanf("%d",&A[i].v[j]);
    }
  }
  
  for(i=1;i<=n;i++){
    for(j=1;j<n;j++){
      if(jag(A[i],j)) printf("1 ");
      else printf("0 ");
    }
    if(jag(A[i],j)) printf("1\n");
    else printf("0\n");
  }
  
  return 0;
}

int jag(Roll A,int j){
  int i;
  for(i=0;i<A.k;i++){
    if(A.v[i]==j) return 1;
  }
  return 0;
}



Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
ios::sync_with_stdio(false);

 int x,y,n,m,a[256],b[256];
 cin>>x>>y>>n>>m;
 for(int i=0;i<x;i++){
   cin>>a[i];
 }
 for(int j=0;j<y;j++){
   cin>>b[j];
 }
 sort(a,a+x,greater<int>());
 sort(b,b+y);
 if(a[0]>=b[0] || b[0]<=n || a[0]>=m){
   cout<<"War"<<"\n";
 }

 else{
   cout<<"No War"<<"\n";
 }

 return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<algorithm>
#include<cmath>
#define EPS 1e-8
using namespace std;

typedef complex<double> P;

P center(P a,P b){
  P m = (a+b)/2.0;
  P n = (a-b)*P(0,1);
  n = n/abs(n);

  double x = abs(a-b)/2.0;
  return m + n*sqrt(1.0 - x*x);
}

int main(){
  int n;
  P p[300];

  while(cin >> n && n){
    for(int i=0;i<n;i++)cin >> p[i].real() >> p[i].imag();

    int ans = 1;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i!=j){
	  if(abs(p[i]-p[j])+EPS>2.0)continue;
	  P c = center(p[i],p[j]);
	  int num = 0;
	  for(int k=0;k<n;k++)
	    if(abs(c-p[k])<1.0+EPS)num++;
	  ans = max(ans,num);
	}
      }
    }
    cout << ans << endl;
  }
}

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

int main()
{
    int a,b;
    cin>>a>>b;
    string s1="";
    string s2="";
    char aa= a + '0';
    char bb= b + '0';
    for (int i=0 ; i<a; i++){
         s2.push_back(bb);
    }
    for (int i=0 ; i<b ; i++){
         s1.push_back(aa);
    }
    cout<<min(s1,s2);
    return 0;
}

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

int fx (int n){
  string s;
  s =to_string(n);
  int cnt =0;
  if (s.size()%2==0){
    for (int i=0;i<s.size();i++){
      if(s[i] != s[s.size()-1-i]){
        break;
      }else if (i == s.size()-i-2){
        cnt =1;
        break;
      }
    }
  }else{
    for (int i=0;i<s.size();i++){
      if(s[i] != s[s.size()-1-i]){
        break;
      }else if (i == s.size()-i-1){
        cnt =1;
        break;
      }
    }
  }
  return cnt;
}

int main(){
  int a,b;
  cin>>a>>b;
  int ans=0;
  for (int i=a;i<=b;i++){
    ans +=fx(i);
  }
  cout <<ans<<endl;
return 0;
}

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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int A, B;
	cin >> A >> B;
	for (int i = 1; i <= 3; i++) {
		if (A * B * i % 2 == 1) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int i,x, y;
	
	for(i = 0;i < 3000;i++)
	{
		scanf("%d %d", &x, &y);
		if ((x == 0) && (y == 0))break;
		if ((0 <= x) && (0 <= y) && (x <= 10000) && (y <= 10000) && (x >= y))
		{
			printf("%d %d\n",y,x);
		}
		else
		if ((0 <= x) && (0 <= y) && (x <= 10000) && (y <= 10000))
		{
			printf("%d %d\n",x,y);
		}
	}
	return 0;
}

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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

            var b = a.OrderByDescending(x => x).ToArray();
            var alice = Enumerable.Range(0,n).Where(x => x % 2 == 0).Select(x => b[x]).Sum();
            var bob = Enumerable.Range(0,n).Where(x => x % 2 != 0).Select(x => b[x]).Sum();

            Console.WriteLine(alice - bob);
        }
    }
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,a[maxn],ans;

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    a[0]=1e9+7;
    for(int i=1;i<=n;i++){
        int j=i;
        while(j<=n&&a[j]<=a[j-1]){
            j++;
        }
        ans=max(ans,j-i);
        j--;
        a[j]=1e9+7;
        i=j;
    }
    printf("%d\n",ans-1);

}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 640
# D - Factorization

N, M = map(int, input().split())
MOD = 10**9 + 7

def prime_factorization(n):
    prime_factors = []
    if n < 2:
        return 0
    for i in range(2, int(pow(n, 0.5)+1)):
        if n%i==0:
            ex = 0
            while n%i==0:
                ex += 1
                n //= i
            prime_factors.append((i, ex))
    if n!=1:
        prime_factors.append((n,1))
    return prime_factors

fac = [1, 1]
inv = [0, 1]
finv = [1, 1]

for i in range(2, N+36):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD)

def comb_mod(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m

primes = prime_factorization(M)
ans = 1
if primes != 0:
    for (p, ex) in primes:
        ans = (ans * comb_mod(ex+N-1, N-1, MOD)) % MOD

print(ans)

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 3010, mod = 1e9 + 7;

int inc(int a, int b) { a += b; return a >= mod ? a - mod : a; }

int n, m, f[N][N][2];

int main()
{
	gii(n, m);
	for (int i = 0; i <= n; ++i) f[0][i][!!i] = 1;
	for (int i = 1; i <= m; ++i) 
	{
		for (int j = 0; j <= n; ++j)
		{
			//2 * x
			f[i][j][0] = inc(f[i][j][0], f[i - 1][j + 1][0]);
			f[i][j][!!j] = inc(f[i][j][!!j], f[i - 1][j + 1][1]);
			
			//x ... y
			if (j) f[i][j][0] = inc(f[i][j][0], f[i - 1][j][0]);
			if (j) f[i][j][!!(j - 1)] = inc(f[i][j][!!(j - 1)], f[i - 1][j][1]);
			
			//y ... x
			if (j != n) f[i][j][0] = inc(f[i][j][0], f[i - 1][j][0]);
			if (j != n) f[i][j][!!j] = inc(f[i][j][!!j], f[i - 1][j][1]);
			
			//2 * y
			if (j) f[i][j][0] = inc(f[i][j][0], f[i - 1][j - 1][0]);
			if (j) f[i][j][1] = inc(f[i][j][1], f[i - 1][j - 1][1]);
		}
	}
	int ans = 0;
	for (int i = 0; i <= n; ++i) ans = inc(ans, f[m][i][0]);
	printf("%d\n", ans);
	return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 200
i64 memo[MAX_N + 1][MAX_N + 1];

i64 gcd(i64 a, i64 b) {
    if (a < b) swap(a, b);
    if (memo[a][b] >= 0) return memo[a][b];

    i64 t;
    while(b > 0) {
        t = a % b;
        a = b;
        b = t;
    }

    return memo[a][b] = a;
}

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

    REPS(i, MAX_N) REPS(j, MAX_N) memo[i][j] = -1;

    i64 s = 0;
    REPS(i, N) REPS(j, N) REPS(k, N) {
        i64 g1 = gcd(i, j);
        s += gcd(g1, k);
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3968
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define pi acos(-1.0)
#define maxd 1000000007
typedef long long ll;
int a,b,c,d,ok[20]; 

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int main()
{
	cin >> a >> b >> c >> d;
	ok[a]=ok[b]=ok[c]=ok[d]=1;
	if ((ok[1]) && (ok[9]) && (ok[7]) && (ok[4])) cout << "YES";
	else cout << "NO";
	return 0;
}


Measured memory_bytes: 256
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main(){
	 ios::sync_with_stdio(false);
	 cin.tie(nullptr);
	 cout.tie(nullptr);
	 int T = 1;
	 for(int t = 1; t <= T; t++){
		 int n;
		 cin >> n;
		 int input[n + 1];
		 for(int i = 1; i <= n; i++){
			 cin >> input[i];
		 }
		 int64_t cost = 0;
 		 for(int i = 2; i <= n; i++){
			 if(input[i] < input[i - 1]){
				 cost += (input[i - 1] - input[i]);
				 input[i] += (input[i - 1] - input[i]);
			 }
		 }
		 cout << cost << "\n";
	 }
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

int main(){
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;

    if (a1 + a2 + a3 >= 22) cout << "bust";
    if (a1 + a2 + a3 < 22) cout << "win";
    cout << endl;

    return 0;
    
}

Measured memory_bytes: 256
S = str(input())
a = []
ans = 0

def sumn(x):
    y = x * (x+1)//2
    return y
    
cnt = 1

if len(S) == 1:
    ans = 1
    print(ans)
else:
    for i in range(len(S)-1):
        if S[i+1] == S[i]:
            cnt += 1
            if i+1 == len(S)-1:
                a.append(cnt)
        
        else:
            a.append(cnt)
            cnt = 1
            if i+1 == len(S)-1:
                a.append(cnt)
            
    if S[0] == '<':
        for i in range(len(a)):
            if i % 2 == 0:
                ans += sumn(a[i])
            else:
                if a[i] > a[i-1]:
                    ans += (sumn(a[i]) - a[i-1])
                else:
                    ans += sumn(a[i]-1)
    else:
        for i in range(len(a)):
            if i == 0:
                ans += sumn(a[i])
            elif i % 2 == 1:
                ans += sumn(a[i])
            else:
                if a[i] > a[i-1]:
                    ans += (sumn(a[i]) - a[i-1])
                else:
                    ans += sumn(a[i]-1)
    print(ans)

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

int main() {
  int N,A;
  int flag=0;
  int pay;
  
  cin >> N >> A;
  N=N%500;
  
  if(N<=A) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0; 
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;
import java.io.*;
import java.text.*;

class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = (long) 1e9 + 7;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long sub(long a, long b) {
        return ((a % mod - b % mod) + mod) % mod;
    }

    static int maxn = 1000005;

    static int pow(int n) {
        return (int) (Math.log10(n) / Math.log10(2));
    }

    static long modpow(long x, long y) {
        long res = 1l;
//        x %= mod;
        while (y > 0) {
            if (y % 2 != 0)
                res *= x;
            x = x * x;
            y /= 2;
        }
        return res;
    }

    static class pair {
        String a;
        int b;

        pair(String x, int y) {
            a = x;
            b = y;
        }
    }

    static long modInverse(long n) {
        BigInteger n1 = new BigInteger(Long.toString(n));
        String s = (n1.modInverse(new BigInteger(Long.toString(mod)))).toString();
        return Long.parseLong(s);
    }

    static boolean v[] = new boolean[1000005];

    static void seive() {
        v[1] = true;
        for (int i = 2; i < 1000005; i++) {
            if (!v[i]) {
                for (int j = 2 * i; j < 1000005; j += i)
                    v[j] = true;
            }
        }
    }

    static boolean isprime(long n) {
        if (n == 1)
            return false;
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0)
                return false;
        }
        return true;
    }

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

    static DecimalFormat df = new DecimalFormat("0.000000000000000000000");

    static void solve() {
        String s=sn();
        String t=sn();
        if(t.substring(0,s.length()).equals(s))
            out.println("Yes");
        else
            out.println("No");
    }
}



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

int sum(int n) {
  if (n == 0) {
    return 0;
  }
 
  // sum関数の中でsum関数を呼び出している
  int s = sum(n - 1);
  return s + n;
}

int main(){
  int N;
  cin >> N;
  
  cout << sum(N) <<endl;
}
  
  

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    string s;
    cin>>s;
    if(s<="2019/04/30")
    {
        cout<<"Heisei"<<endl;
    }
    else cout<<"TBD"<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    s = input()
    t = input()

    st = dict()
    ts = dict()
    cond = True
    for sc, tc in zip(s, t):
        if st.get(sc, None) is None:
            st[sc] = tc
        if st[sc] != tc:
            cond = False
            break
        if ts.get(tc, None) is None:
            ts[tc] = sc
        if ts[tc] != sc:
            cond = False
            break

    print('Yes' if cond else 'No')


if __name__ == '__main__':
    main()

# s->tで、ある文字に対し,2文字以上の対応はできない
# t->sで、ある文字に対し,2文字以上の対応はできない
# s->tで、ある文字に対し,どの文字にも対応しないということはない（が気にしない）
# t->sで、ある文字に対し,どの文字にも対応しないということはない（が気にしない）
# 未対応があるとき26文字種出ていれば、重複が出ているし、
# 出ていない文字種があれば、未対応は隠れてしまう


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, k; cin>>n>>k;
    string s; cin>>s;

    vector<int> cnt;
    for(int i=0; i<n; i++){
        int num=1;
        while(i + 1 < n && s[i] == s[i+1]){
            num++;
            i++;
        }

        cnt.eb(num);
    }

    int m=cnt.size();

    int st;
    if(s[0] == '0') st = 1;
    else st = 0;

    vector<int> sum(m+10, 0);
    for(int i=0; i<m; i++){
        sum[i+1] = sum[i] + cnt[i];
    }

    int ans=0;
    for(int i=st; i<=m; i+=2){
        int ub = sum[min(i+k*2-1, m)];
        int lb = sum[max(i-2, 0)];

        chmax(ans, ub - lb);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1272
from operator import lt, gt

n = int(input())
a = tuple(map(int, input().split()))

ans = n + 1
for first_checker in (lt, gt):
    cnt = 1
    prev = a[0]
    f = first_checker
    for x in a:
        if x == prev:
            pass
        elif f is None:
            if x > prev:
                f = gt
            else:
                f = lt
        elif f(x, prev):
            pass
        else:
            f = None
            cnt += 1
        prev = x
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 14252
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)


int n,s;
int ans=0;


int solve(int c,int d,int s){
	if(c==n){
		if(s<=9&&s>=d){
			ans++;
		}
	}
	else{
		for(int i=d;i<10;i++){
			solve(c+1,i+1,s-i);
		}
	}
	return ans;
}
	
	

int main(){
	while(cin>>n>>s,n||s){
		//if(s>45) cout<<0<<endl;
		ans = 0;
		cout << solve(1,0,s) <<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void){
  long long int a,b;
  scanf("%lld %lld",&a,&b);
  for(int loop=1;loop<=b;loop++){
    if((a*loop)%b==0){
      printf("%lld",a*loop);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")



int main() {
 
    ll n,m,a; cin >> n >> m;
    ll ans = 0;
    priority_queue<ll> q;
    rep(i,n){
        cin >> a;
        q.push(a);
    }
    rep(i,m){
        a = q.top()/2;
        q.pop();
        q.push(a);
    }
    while(!q.empty()){
        ans += q.top();
        q.pop();
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4336
require 'set'
loop do
    c, n, m, s, d = gets.split.map(&:to_i)
    break if c == 0
    g = {}
    (1..n).each {|i| g[i] = {}}
    m.times do
        a, b, f = gets.split.map(&:to_i)
        g[a][b] = f
        g[b][a] = f
    end
    start_node = [s, c]
    nodes = Set[start_node]
    cost = Hash.new(Float::INFINITY)
    cost[start_node] = 0
    reached = Set.new
    loop do
        u = nodes.min_by {|v| cost[v]}
        nodes.delete(u)
        reached << u
        i, k = u
        if i == d
            puts cost[u]
            break
        end
        g[i].each do |j, f|
            if k > 0
                v = [j, k - 1]
                if !reached.include?(v)
                    cost[v] = cost[u] + f / 2 if cost[v] > cost[u] + f / 2
                    nodes << v
                end
            end
            v = [j, k]
            if !reached.include?(v)
                cost[v] = cost[u] + f if cost[v] > cost[u] + f
                nodes << v
            end
        end
    end
end



Measured memory_bytes: 7280
N, Y = map(int, input().split())
Y //= 1000

for x in range(N+1):
    for y in range(N-x+1):
        z = N - x - y
        if 10*x  + 5*y + z == Y:
            print(x, y, z)
            exit()

print(-1, -1, -1)


Measured memory_bytes: 3060
import itertools
import math

N = int(input())

d = {}
for i in range(N):
    d[i+1] = list(map(int, input().split()))

pattern = itertools.permutations(range(1,N+1),  N)

ans = 0

for p in pattern:
    before = ()
    count = 0
    for place in p:
        if before:
            count += math.sqrt((d[before][0] - d[place][0])**2 + (d[before][1] - d[place][1])**2)
        before = place
    ans += count

ans /= math.factorial(N)

print(ans)




Measured memory_bytes: 39408
from sys import stdin


def main() -> int:
    n, k = map(int, input().split())
    l = [next_int() for _ in range(n)]
    l.sort()
    l.reverse()

    ans = sum(l[:k])
    print(ans)
    return 0


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

int main()
{
    bool seat[50][50] = {};
    int countSeat[50][50] = {};
    int dx[5] = {0,0,0,-1,1};
    int dy[5] = {0,-1,1,0,0};

    int h, w, x, y;
    char c;
    bool flag;
    cin >> h >> w;
    for(int i = 0; i < h*w; ++i)
    {
        cin >> c;
        x = i%w;
        y = i/h;
        flag = c == '#';
        seat[x][y] = flag;
        for(int j = 0; j < 5 && flag; ++j)
        {
            int nx = x + dx[j];
            int ny = y + dy[j];
            if(0 <= nx && nx < 50
            && 0 <= ny && ny < 50)
            {
                countSeat[nx][ny] += 1;
            }
        }
    }

    bool result = true;
    for(int i = 0; (i < h) && result; ++i)
    {
        for(int j = 0; (j < w) && result; ++j)
        {
            //cout << countSeat[i][j] << " ";
            if(seat[i][j]
            && countSeat[i][j] == 1)
            {
                result = false;
            }
        }
        //cout << endl;
    }

    if(result)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

void solve() {
    int n;
    cin >> n;
    while (n>1000) {
        n-=1000;
    }
    if (n==0) {
        cout << 0 << endl;
    } else {
        cout << (1000-n) << endl;
    }
}

int main() {
    FAST_INPUT;

    solve();
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
ll a[51];
ll p[51];
ll f(ll n, ll x){
    if(n == 0){
        return x <= 0 ? 0 : 1;
    }else if(x <= 1 + a[n - 1]){
        return f(n-1, x -1);
    }else {
        return p[n-1] + 1 + f (n-1, x-2-a[n-1]);
    }
}

int main() {
    ll n , x;
    cin >> n >> x;
    p[0] = 1;
    a[0] = 1;
    reps(i, n){
        a[i] = a[i-1] * 2 + 3;
        p[i] = p[i-1] * 2 + 1;
    }
    cout << f(n, x) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define     ll              long long
#define     MAX             100000
#define     FI              freopen("input.txt","r",stdin)
#define     FO              freopen("output.txt","w",stdout)
#define     fast            ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define     sc(a)           scanf("%d",&a)
#define     sc2(a,b)        scanf("%d %d",&a,&b)


map<string,int>SMS;
map<string,int>::iterator it;


int main()
{
   // FI;
    int test;
    scanf("%d",&test);
    while(test--)
    {
        int cs;
        scanf("%d",&cs);
        switch(cs)
        {
        case 0:
            {
                string s;
                int a;
                cin>>s>>a;
                SMS[s]=a;
            }
            break;
        case 1:
            {
                string s;
                cin>>s;
                it = SMS.find(s);
                cout<<it->second<<"\n";
            }
            break;
        case 2:
            {
                string s;
                cin>>s;
                SMS.erase(s);
            }
            break;
        case 3:
            {
                string a,b;
                cin>>a>>b;
                it = SMS.lower_bound(a);
                for(;it!=SMS.upper_bound(b);it++)
                    cout<<it->first<<" "<<it->second<<"\n";
            }
            break;
        default:
            break;
        }
    }
    return 0;
}




Measured memory_bytes: 27880
from bisect import bisect
from collections import defaultdict

n = int(input())
up = [defaultdict(list), defaultdict(list), defaultdict(list)]
dp = [defaultdict(list), defaultdict(list), defaultdict(list)]
lp = [defaultdict(list), defaultdict(list), defaultdict(list)]
rp = [defaultdict(list), defaultdict(list), defaultdict(list)]

for _ in range(n):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    if u == 'U':
        up[0][x].append(y)
        up[1][x + y].append(x)
        up[2][x - y].append(x)
    elif u == 'D':
        dp[0][x].append(y)
        dp[1][x + y].append(x)
        dp[2][x - y].append(x)
    elif u == 'L':
        lp[0][y].append(x)
        lp[1][x + y].append(x)
        lp[2][x - y].append(x)
    else:
        rp[0][y].append(x)
        rp[1][x + y].append(x)
        rp[2][x - y].append(x)

INF = 10 ** 18
ans = INF

for x in up[0]:
    if x not in dp[0]:
        continue
    us = up[0][x]
    us.sort()
    for y in dp[0][x]:
        i = bisect(us, y)
        if i > 0:
            tmp = y - us[i - 1]
            ans = min(ans, tmp * 5)

for y in rp[0]:
    if y not in lp[0]:
        continue
    rs = rp[0][y]
    rs.sort()
    for x in lp[0][y]:
        i = bisect(rs, x)
        if i > 0:
            tmp = x - rs[i - 1]
            ans = min(ans, tmp * 5)

for xy in rp[1]:
    if xy not in up[1]:
        continue
    rs = rp[1][xy]
    rs.sort()
    for x in up[1][xy]:
        i = bisect(rs, x)
        if i > 0:
            tmp = x - rs[i - 1]
            ans = min(ans, tmp * 10)

for xy in dp[1]:
    if xy not in lp[1]:
        continue
    ds = dp[1][xy]
    ds.sort()
    for x in lp[1][xy]:
        i = bisect(ds, x)
        if i > 0:
            tmp = x - ds[i - 1]
            ans = min(ans, tmp * 10)

for xy in up[2]:
    if xy not in lp[2]:
        continue
    us = up[2][xy]
    us.sort()
    for x in lp[2][xy]:
        i = bisect(us, x)
        if i > 0:
            tmp = x - us[i - 1]
            ans = min(ans, tmp * 10)

for xy in rp[2]:
    if xy not in dp[2]:
        continue
    rs = rp[2][xy]
    rs.sort()
    for x in dp[2][xy]:
        i = bisect(rs, x)
        if i > 0:
            tmp = x - rs[i - 1]
            ans = min(ans, tmp * 10)

if ans == INF:
    print('SAFE')
else:
    print(ans)


Measured memory_bytes: 121608
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX=2e5+20;
vector<int> adj[MAX];
int dist[2][MAX];

void bfs(int source, int ir) {
    queue<int> q;
    dist[ir][source]=0;
    q.push(source);

    while(!q.empty()) {
        int x = q.front();q.pop();
        for(auto other : adj[x]) {
            if(dist[ir][other]==-1){
                //printf("%d -> %d\n",x+1,other+1);
                dist[ir][other]=dist[ir][x]+1;
                q.push(other);
            }
        }
    }
}

int main() {

    int n,y,x;
    scanf("%d%d%d",&n,&x,&y);
    --x,--y;

    for(int i=0;i<n-1;i++) {
        int a,b;
        scanf("%d%d",&a,&b);
        --a,--b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    //for(int i=0;i<MAX;i++) dist[0][i]=INF,dist[1][i]=INF;
    memset(dist,-1,sizeof(dist));

    bfs(y,1);
    bfs(x,0);

    int ans=-1;

    for(int i=0;i<n;i++) {
        if(i==y) continue;
        if(adj[i].size()==1) {
            if(dist[0][i]<dist[1][i]) {
                ans=max(ans,dist[1][i]-1);
            }
        }
    }

    
    for(int i=0;i<n;i++) {
        //printf("%d,%d\n",dist[0][i],dist[1][i]);
    }

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

    return 0;
}


Measured memory_bytes: 9728