akhauriyash/Code-Regression huggingface dataset:
#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>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

const int NEU = -1;
const int UP = 1;
const int DOWN = 0;
int n;
int a[100010];
signed main() {
    cin >> n;
    rep(i,0,n) cin >> a[i];
    vector<int> v;
    int cnt = 1;
    int state = NEU;

    rep(i,0,n-1) {
        if(state == NEU) {
            if(a[i] < a[i+1]) state = UP;
            if(a[i] > a[i+1]) state = DOWN;
        }
        else if(state == UP) {
            if(a[i] > a[i+1]) {
                state = NEU;
                cnt++;
            }
        }
        else if(state == DOWN) {
            if(a[i] < a[i+1]) {
                state = NEU;
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

vvint g;
int n;

int dfs(set<int> path, int v) {
    int res = 0;
    path.insert(v);
    if (path.size() == n) return 1;
    for (int n_v : g[v]) {
        if (path.find(n_v) != path.end()) continue;
        res += dfs(path,n_v);
    }
    return res;
}

int main() {
    int m; cin >> n >> m;
    g.resize(n);
    rep(i,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    set<int> path;
    cout << dfs(path,0) << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  for(int i=0;i<n;i++)
    cin >> l.at(i);
  
  sort(l.begin(),l.end());
  
  int k=0;
  for(int i=1;i<n;i++){
    k+=l.at(i-1);
  }
  if(k>l.at(n-1)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int n;
  cin>>n;
  char s[n],t[n];
  rep(i,n) cin>>s[i];
  rep(i,n) cin>>t[i];
  rep(i,n){
    cout<<s[i]<<t[i];
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define arep(x,n) for (int x: n)
using namespace std;

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

    if(n%2 == 0) cout << n/2 << endl;
    else cout << n/2 + 1 << endl; 

}

Measured memory_bytes: 256
# 081B
N = int(input())
A = list(map(int, input().split())) 
c = 0
b = 0
while True:
    for i in range(N):
        if (A[i]%2) == 0:
            A[i] = A[i]/2
        else:
            c =1
            break
    if c == 1:
        break
    b += 1
    
print(b)

Measured memory_bytes: 63928
#include<stdio.h>
#include<string.h>
int main(){
    char s[11], t[12];
    int i;
    gets(s);
    gets(t);
    for(i = 0; i < strlen(s); i ++){
        if(s[i] != t[i]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");

    return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c){
        cout<<"1"<<endl;
    }else if(a==b || b==c || c==a){
        cout<<"2"<<endl;
    }else{
        cout<<"3"<<endl;
    }
}




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

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

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> gr(N);

    rep (i, N) cin >> gr[i];

    int cnt = 0;
    rep (i, N) {
        if (gr[i] >= K)
        {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3752
S = input()
K = int(input())
if S[0]*len(S) == S and S[0] == "1":
    print("1")
else:
    ans = 0
    ind = 0
    for i in range(len(S)):
        if S[i] != "1":
            ans = S[i]
            ind = i+1
            break
    if ind > K:
        print("1")
    else:
        print(ans)

Measured memory_bytes: 3060
#define scanf_s scanf
#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;

#define MAX 100000
//#define MAX_ 1000

int cou = 0;
struct tree
{
	int id;
	tree *pp;
	tree *next;
	tree *pchbegin, *pchend;
};
int main(void)
{
	int n, xid, xk, xdeep = 0, xc1, xc2;
	int depth, cou = 0,parent;
	tree node[MAX], first;
	first.id = -1;
	bool node_b[MAX] = { false };
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf_s("%d %d", &xid, &xk);
		node[xid].id = xid;
		if (node_b[xid] == false) { node[xid].pp = &first; }
		node[xid].pchbegin = node[xid].pchend;
		for (int j = 0; j < xk; ++j) {
			scanf_s("%d", &xc1);
			node[xc1].pp = &node[xid];
			node_b[xc1] = true;
			if (j == 0) {
				node[xid].pchbegin = &node[xc1];
				node[xc1].next = node[xid].pchend;
			}
			else {
				node[xc2].next = &node[xc1];
				node[xc1].next = node[xid].pchend;
			}
			xc2 = xc1;
		}
	}
	for (int i = 0; i < n; ++i) {
		depth = 0;
		for (tree *p = node[i].pp; p != &first; p = p->pp) { ++depth; }
		printf("node %d: parent = %d, depth = %d, ", node[i].id, node[i].pp->id, depth);
		if (node[i].pchbegin == node[i].pchend && node[i].pp->id != -1) { printf("leaf, ["); }
		else {
			if (node[i].pp->id == -1) { printf("root, ["); }
			else { printf("internal node, ["); }
			for (tree *j = node[i].pchbegin; j != node[i].pchend; j = j->next) {
				if (j == node[i].pchbegin) { printf("%d", j->id); }
				else printf(", %d", j->id);
			}
		}
		printf("]\n");
	}
}

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

typedef long long ll;

using namespace std;

// 最大公約数
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b; // Overflowに注意
}

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

  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ll t;
    cin >> t;
    ans = lcm(t, ans);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
  
class Main{
    public static void main(String[] args) throws Exception{
        
        String[] str;
        int x;
        int y;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        str = (br.readLine()).split(" ");
        x = Integer.parseInt(str[0]);
        y = Integer.parseInt(str[1]);
        
        System.out.println(x*y + " " + (x*2 + y*2));
    }
}

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

#define ll long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define infl 1e18+9
#define sz(a) ((int)a.size())
ll mod=1e9+7;

struct S{
  int w,s,v; 
  void read(){
    cin>>w>>s>>v; 
  }
  bool operator<(const S &a){
    return w+s < a.w+a.s ; 
  }
};

void solve(){
  int n; cin>>n; 
  vector<S> v(n); 
  for(int i=0;i<n;i++){
    v[i].read(); 
  }
  sort(v.begin(),v.end()); 
  vector<ll> best(1e4+5,-1); 
  best[0]=0; 
  ll ans=0; 
  for(int i=0;i<n;i++){
    for(int j=0;j<=v[i].s;j++){
      ans=max(ans,best[j]+v[i].v); 
    }
    for(int j=v[i].s;j>=0;j--){
      if(j+v[i].w<1e4+5 && best[j]>=0){
        best[j+v[i].w]=max(best[j+v[i].w],best[j]+v[i].v); 
      }
    }
  }
  cout<<ans<<endl;
}

int main(){
	fast_io;
	clock_t beg=clock();
  int t;
  t=1;
  while(t--){
	  solve();
  }
	clock_t end=clock();
	fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
const int N=1e5+5;
int n,k,q,a,d[N];
int main()
{
	scanf("%d%d%d",&n,&k,&q);
	for(int i=1;i<=q;i++){
		scanf("%d",&a);
		d[1]++,d[n+1]--;
		d[a]--,d[a+1]++;
	}
	for(int i=1;i<=n;i++){
		d[i]+=d[i-1];
		if(d[i]>=k) printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

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

        int shift = scanner.nextInt();
        scanner.nextLine();

        char[] alphabets = scanner.nextLine().toCharArray();

        for (int i=0; i<alphabets.length; i++) {
            alphabets[i] += shift;
            if (alphabets[i] > 'Z') alphabets[i] -= 26;
        }

        System.out.println(alphabets);
    }
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    int input[n];
    for (int i = 0; i < n; ++i) {
        cin >> input[i];
    }
    int dp [n];
    dp [0] = 0;
    for (int i = 1; i < n; ++i) 
    {
        int min_cost = 2e9;
        for (int j = 1; j <= k; ++j) {
            if (i - j < 0)
            {
                break;
            }
            int cost1 = abs(input[i] - input[i - j]) + dp[i - j];
            min_cost = min(cost1, min_cost);
        }
        dp [i] = min_cost;
    }
    
    cout << dp [n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <random>

#define ff first
#define ss second

using namespace std;

using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;

pii operator+(pii a, pii b)
{
    return {a.ff+b.ff,a.ss+b.ss};
}

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

    int n;
    cin>>n;
    int answer=0;
    for(int a=1; a<=n; a++){
        for(int b=1; a*b<=n; b++){
            if(n-a*b!=0) answer+=1;
        }
    }
    cout<<answer;

    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<queue>

using namespace std;
typedef pair<int,int> P;
int main(){
	int n,q; cin >> n >> q;
	int a[n+1];
	priority_queue<P> p;
	
	for(int k=0;k<n+1;k++){
		a[k] = 0;
	}

	int s,v;
	for(int i=0;i<q;i++){
		cin >> s >> v;
		a[s] += v;
		p.push(P(a[s],-s));

		for(;;){
			P t = p.top();
			if(t.first == a[-t.second]){
			cout << -t.second << " " << t.first << endl; break; }
			p.pop();
		}
	}
return 0;
}

Measured memory_bytes: 6008
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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 <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline LL ri() {LL x; scanf("%lld", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


LL c[100];


int main() {

  string s; cin >> s;
  LL n = s.length();

  LL res = n * (n - 1) / 2;
  rep(i, n) c[s[i] - 'a'] ++;
  rep(i, 26) res -= c[i] * (c[i] - 1) / 2;
  res ++;

  cout << res << endl;

  return 0;
}


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


typedef long double ld;
typedef long long ll;

using namespace std;

#define D 10 
#define MAXN (1 << 18)
#define MAXW (100010)

int dp[(1 << D)][MAXW];
int v[MAXN];
int w[MAXN];

int n, q;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> v[i] >> w[i];
	}
	for (int i = 1; i < (1 << D); i++) {
		int prevdp[MAXW];
		memcpy(prevdp, dp[i / 2], sizeof(dp[0]));
		for (int j = 0; j + w[i] < MAXW; j++) {
			dp[i][j + w[i]] = prevdp[j] + v[i];
		}
		for (int j = 0; j < MAXW; j++) {
			dp[i][j] = max(prevdp[j], dp[i][j]);
		}
		for (int j = 1; j < MAXW; j++) {
			dp[i][j] = max(dp[i][j], dp[i][j - 1]);
		}
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		int cur, cap;
		cin >> cur >> cap;
/*		if (cur < (1 << D)) {
			cout << dp[cur][cap] << endl;
		} else {*/
			vector<int> items;
			while (cur >= (1 << D)) {
				items.push_back(cur);
				cur >>= 1;
			}
			int m = items.size();
			int bestval = 0;
			for (int mask = 0; mask < (1 << m); mask++) {
				int curv = 0;
				int curw = 0;
				for (int j = 0; j < m; j++) {
					if (mask & (1 << j)) {
						curv += v[items[j]];
						curw += w[items[j]];
					}
				}
				if (curw > cap) {
					continue;
				}
				curv += dp[cur][cap - curw]; 
				bestval = max(curv, bestval);
			}
			cout << bestval << endl;
//		}
	}
	return 0;
}


Measured memory_bytes: 405720
import math
n,a,b =map(int,input().split())
v = list(map(int,input().split()))
v = sorted(v,key=lambda x:-x)
need = v[:a]
ti = min(need)
no = need.count(ti)
try:
  ona = v[a:].count(ti)
except:
  ona = 0
if ona == 0:
  print(sum(need)/a)
  print(1)
elif no == a:
  ans = 0
  for i in range(b+1-a):
    if ona == -1:
      break
    ans += math.factorial(ona+no)/math.factorial(ona)/math.factorial(no)
    ona -= 1
    no += 1
  print(sum(need)/a)
  print(int(ans))
else:
  print(sum(need)/a)
  print(int(math.factorial(ona+no)/math.factorial(ona)/math.factorial(no)))

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  if (a == b) {
    cout << 2 * b << endl;
  } else {
    cout << 2 * b - 1 << endl;
  }
}

Measured memory_bytes: 256
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f
let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

let list_of_string str = range 0 (String.length str) |> List.map (fun i -> str.[i])
let array_of_string str = Array.init (String.length str) (fun i -> str.[i])

let () =
  let h, w, d = scanf "%d %d %d" (fun a b c -> a, b, c) in
  let arr = Array.init h (fun _ -> Array.init w (fun _ -> scanf " %d" (fun x -> x))) in
  let qs = scanf " %d" (fun q -> Array.init q (fun _ -> scanf " %d %d" (fun x y -> x, y))) in
  let ps = Array.make (h*w+1) (-1, -1) in
  let cs = Array.make (h*w+1) (h*w) in

  for_iter_ 0 h (fun x -> for_iter_ 0 w (fun y -> ps.(arr.(x).(y)) <- (x, y)));

  for_iter_ 0 d (fun i -> cs.(i) <- 0);
  for_iter_ d (h*w+1) (fun i ->
    let (x, y) = ps.(i) in let (x', y') = ps.(i-d) in
    cs.(i) <- cs.(i-d) + abs (x-x') + abs (y-y'));

  qs
  |> Array.map (fun (i, j) -> cs.(j) - cs.(i))
  |> Array.iter (printf "%d\n")



Measured memory_bytes: 12544
## coding: UTF-8
s = input().split()
t = [int(p) for p in s]

#print(t[0])
#print(t[1])
N = t[0] #枚のお札
Y = t[1] #円

a = -1 # 10000yen
b = -1 # 5000yen
c = -1 # 1000yen

for i in range(N+1): # i枚の10000yen（0〜N枚）
    for j in range(N+1 - i): # j枚の5000yen（0〜N-i枚）
        #for k in range(N+1 - i - j): # k枚の1000yen(0~N-i-j枚)
        k = N - i - j # 1000yen 札は N-i-j枚
        #print('i:{}, j:{}, k:{}, n:{}, sum:{}'.format(i,j,k,i+j+k, 10000*i+5000*j+1000*k))
        sum = 10000*i+5000*j+1000*k
        if(sum == Y):
            a = i
            b = j
            c = k
            #print('i:{}, j:{}, k:{}, n:{}, sum:{}'.format(i,j,k,i+j+k, 10000*i+5000*j+1000*k))
print('{} {} {}'.format(a,b,c))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#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 all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

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

    long long r = 0, g = 0, b = 0;
    for (auto c : S) {
        if (c == 'R') ++r;
        else if (c == 'G') ++g;
        else if (c == 'B') ++b;
    }

    long long total = r * g * b;
    long long sub = 0l;
    rep (i, 0, N) {
        rep (j, i+1, N) {
            if (S[i] == S[j]) continue;
            int k = 2 * j - i;
            if (k >= N or S[i] == S[k] or S[j] == S[k]) continue;
            ++sub;
        }
    }

    cout << (total - sub) << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    int K,S;
    cin >> K >> S;
    vint sum(3*K+1,0);
    REP(i,K+1){
        REP(j,K+1){
            sum[i+j]++;
        }
    }
    ll ans = 0;
    for(int i=0; i<=2*K && S >= i; i++){
        if(S-i <= K)ans += sum[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
def solve():
  N, K, C = map(int, input().split())
  workable = [i for i, s in enumerate(input()) if s=="o"]
  if len(workable) == K:
    return workable
    
  latest = set()
  prev = workable[-1]+C+1
  for x in reversed(workable):
    if prev - x > C:
      latest.add(x)
      prev = x
  if len(latest) > K:
    return []
  must = []
  prev = -C-1
  for x in workable:
    if x - prev > C:
      if x in latest:
        must.append(x)
      prev = x
  return must

for i in solve():
  print(i+1)


Measured memory_bytes: 23576
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
// #define int long long    // %d=>%lld
#define pb push_back
#define INF (1e9+7)
#define llINF 1e17
#define EPS 1e-9
#define pi acos(-1)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;


string s[3]={"delicious","safe", "dangerous"};

int x,a,b;




signed main(){

    cin >> x>>a>>b;

    int i;
    (b-a<=0)?i=0:(b-a<=x)?i=1:i=2;
    cout<< s[i]<< endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define NL << endl

using namespace std;
using ll = long long;
using ull = unsigned long long;


int main() {

	int a, b, c, x, y;

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

	int ans = 1e9;

	for(int i = 0; i <= max(x, y); i++) {
		int p = i *c * 2;
		if (x > i) p += (x - i) * a;
		if (y > i) p += (y - i) * b;

		ans = min(ans, p);
	}
	
	cout << ans NL;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

const int MAXN = 100005;

//dsu
int fa[MAXN];

int find(int x)
{
	return (x == fa[x] ? x : fa[x] = find(fa[x]));	
}

void Union(int x, int y)
{
	int a = find(x), b = find(y);
	if (a != b)
		fa[b] = a;
}

int p[MAXN];

int n, m, x, y, res = 0;

void init()
{
	for (int i = 1; i <= n; i++)
		fa[i] = i;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> p[i];
	init();
	for (int i = 1; i <= m; i++)
	{
		cin >> x >> y;
		Union(x, y);
	}
	for (int i = 1; i <= n; i++)
		if (find(p[i]) == find(i))
			res++;
	cout << res << endl;
	return 0;	
}


Measured memory_bytes: 1024
#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 graph[2010][2010];


int main() {


  int N, X, Y;
  cin >> N >> X >> Y;

  vector<int> ans(N-1, 0);
    rep(i, N) {
      rep(j, N) {
        if (j <= i) continue;
        int from = i+1;
        int to = j+1;
        int num = min(to-from, abs(from-X) + 1 + abs(Y-to));
        ans[num-1]++;
      }
    }

  rep(i, N-1) {
    cout << ans[i] << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
		int N;
		cin >> N;
		int x[N], y[N];
		for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

		if (N == 1) {
				cout << 1 << endl;
				return 0;
		}

		int ans = 1e9;
		for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
						if (i == j) continue;
						int cp = x[j] - x[i];
						int cq = y[j] - y[i];
						
						int cnt = 0;
						for (int k = 0; k < N; k++) {
								for (int l = 0; l < N; l++) {
										int p = x[l] - x[k];
										int q = y[l] - y[k];
										if (p == cp && q == cq) {
												cnt++;
										}
								}
						}

						ans = min(ans, N - cnt);
				}
		}

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


Measured memory_bytes: 256
r,g,b,n = gets.split.map(&:to_i)

i = 0
ans = 0
while r * i <= n
    x = n - r * i
    j = 0
    while g * j <= x
        ans += 1 if (x - g * j) % b == 0
        j += 1
    end
    i += 1
end

puts ans

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

int main(){
    //FILE *inp = freopen("in.txt", "r", stdin);
    int n;
    cin>>n;
    int arr[n];
    for(int i = 0; i < n; ++i)
        cin>>arr[i];

    //algorithm
    for(int i = 0; i < n; ++i){
        int key = arr[i];
        int j = i-1;
        while(j >= 0 && arr[j]>key){
            arr[j+1] = arr[j];
            j--;
            arr[j+1] = key;
        }

        // each step sort print
        for(int x = 0; x < n; ++x){
            if(x) cout << " ";
            cout << arr[x];
        }
        cout << endl;
    }
    //fclose(inp);
    return 0;
}

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


#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000 //1e16

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

vi a(200005);

void solve()
{
    int t,n,m,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U; 
    // int a,b;
    cin>>n;
    vi bin;
    t=n;
    while(t)
    {
        m=t%26;
        if(!m) 
        {
            m=26;
            bin.pb(m);
            t/=26;
            t--;
            continue;
        }
        // if(m==-1) m=26;
        bin.pb(m);
        t/=26;
    }
    // vout(bin)cout<<"\n";
    reverse(all(bin));
    int x=sz(bin);
    rep(i,0,x)
    {
        cout<<(char)(bin[i]+'a'-1);
    }
}


signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 4648
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>

using namespace std;

vector<int> a;

int now;

int idx;

bool flg;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

void make(int tmp)
{
    a[now] = tmp;
    // flg true right
    // flg false left
    flg = !flg;
    if (flg) now = now + idx;
    else now = now - idx;
    idx++;
}

int main()
{
    int n;

    gc(n);

    a.resize(n);

    int tmp;

    if (n % 2 == 0)
    {
        now = n / 2;
        idx = 1;
        flg = true;
        for (int i = 0; i < n; i++)
        {
            gc(tmp);
            make(tmp);
        }
    }
    else
    {
        now = n / 2;
        idx = 1;
        flg = false;
        for (int i = 0; i < n; i++)
        {
            gc(tmp);
            make(tmp);
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (i != 0) printf(" ");
        printf("%d", a[i]);
    }

    printf("\n");
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int main() {
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.length();i++)
	    if(s[i]=='2')
	        ans++;
	printf("%d\n",ans);
    return 0;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end()); //昇順にソート
    sort(t.begin(), t.end(), greater<char>()); //降順にソート
    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

long long N;

int rec(long long i, int t, int f, int s){
    if (i > N) return 0;
    int self = (t >= 1 && f >= 1 && s >= 1) ? 1 : 0;
    return rec(10 * i + 3, t+1, f, s) 
         + rec(10 * i + 5, t, f+1, s) 
         + rec(10 * i + 7, t, f, s+1) 
         + self;
}

int main() {
    cin >> N;
    cout << rec(0LL, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数


int main (){
    string s,t;
    cin >> s;
    
    t = s;
    reverse(all(s));

    int ans = 0;

    REP(i,s.size()){
        if(t[i]!=s[i]) ans += 1;
    }

    cout << ans/2;

}

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

int N;

int main(){
    cin>>N;
    int ans=0;
    if(N%10==2)ans++;
    N/=10;
    if(N%10==2)ans++;
    N/=10;
    if(N%10==2)ans++;
    N/=10;
    if(N%10==2)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

map<long long, long long> prime_factor(long long n) {
    map<long long, long long> res;
    for (long long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main(){
    long long A, B;
    cin >> A >> B;
    auto pA = prime_factor(A);
    auto pB = prime_factor(B);
    long long ans = 1;
    for(auto x : pA){
        long long k = x.first;
        if(pB[k] > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define MAXN 3001

int A[MAXN],N;
long long dp[MAXN][MAXN][2];

int main() {
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	for(int i = 0; i < N; i++){
		dp[i][i][0] = A[i];
	}
	for(int k = 1; k < N; k++){
		for(int i = 0,j = k; j < N; i++,j++){
			// better choice is the take the leftmost item 
			if(A[i] + dp[i + 1][j][1] > A[j] + dp[i][j - 1][1]){
				dp[i][j][0] = A[i] + dp[i + 1][j][1];
				dp[i][j][1] = dp[i + 1][j][0];
			}else{
				dp[i][j][0] = A[j] + dp[i][j - 1][1];
				dp[i][j][1] = dp[i][j - 1][0];
			}
		}
	}
	cout << dp[0][N - 1][0] - dp[0][N - 1][1];
	return 0;
}

Measured memory_bytes: 139648
from heapq import heappush, heappop
inf = float('inf')
def dijkstra(graph:list, node:int, start:int) -> list:
    dist = [inf]*node

    dist[start] = 0
    heap = [(0,start)]
    while heap:
        cost,thisNode = heappop(heap)
        for NextCost,NextNode in graph[thisNode]:
            dist_cand = dist[thisNode]+NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap,(dist[NextNode],NextNode))
    return dist

N = int(input())
S1 = []
S2 = []
C = []
for i in range(N):
    s,c = input().split()
    S1.append(s)
    S2.append(s[::-1])
    C.append(int(c))

d_v = {('',''):0,('l',''):1,('r',''):2}
idx = 3
for i in range(N):
    s = S1[i]
    for j in range(len(s)):
        for k in range(j,len(s)):
            ss_l = s[j:k+1]
            ss_r = ss_l[::-1]
            if ss_l != ss_r:
                if ('l',ss_l) not in d_v:
                    d_v[('l',ss_l)] = idx
                    idx += 1
                if ('r',ss_r) not in d_v:
                    d_v[('r',ss_r)] = idx
                    idx += 1

edge = [[] for _ in range(len(d_v))]

for i in range(N):
    s_l = S1[i]
    s_r = S2[i]
    c = C[i]
    for lr,ss in d_v:
        if ss == '':
            if lr == '':
                t = s_l
                if t==t[::-1]:
                    t = ''
                edge[0].append((c,d_v[('l',t)]))
            else:
                continue
        if lr == 'l':
            if ss.startswith(s_r):
                t = ss[len(s_r):]
                if t==t[::-1]:
                    t = ''
                edge[d_v[(lr,ss)]].append((c,d_v[('l',t)]))
            if s_r.startswith(ss):
                t = s_r[len(ss):]
                if t==t[::-1]:
                    t = ''
                edge[d_v[(lr,ss)]].append((c,d_v[('r',t)]))
        elif lr == 'r':
            if ss.startswith(s_l):
                t = ss[len(s_l):]
                if t==t[::-1]:
                    t = ''
                edge[d_v[(lr,ss)]].append((c,d_v[('r',t)]))
            if s_l.startswith(ss):
                t = s_l[len(ss):]
                if t==t[::-1]:
                    t = ''
                edge[d_v[(lr,ss)]].append((c,d_v[('l',t)]))
            

dist = dijkstra(edge,len(d_v),0)
ans = min(dist[1],dist[2])
if ans == inf:
    ans = -1

print(ans)


Measured memory_bytes: 78876
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    llint n, k, l, r;
    cin >> n >> k >> l >> r;
    vector<llint> v(n);
    REP(i,n){
        cin >> v[i];
    }

    vector<vector<llint>> grid1(1+(n/2), vector<llint>()), grid2(1+(n+1)/2, vector<llint>());
    for (llint bit = 0; bit < (1<<(n / 2));bit++){
        llint tmp = 0;
        REP(j,n/2){
            if(bit&(1<<j)){
                tmp += v[j];
            }
        }
        grid1[__builtin_popcountll(bit)].push_back(tmp);
    }
    for (llint bit = 0; bit < (1<<((n+1) / 2));bit++){
        llint tmp = 0;
        REP(j,(n+1)/2){
            if(bit&(1<<j)){
                tmp += v[(n/2)+j];
            }
        }
        grid2[__builtin_popcountll(bit)].push_back(tmp);
    }

    REP(i,1+n/2){
        sort(grid1[i].begin(), grid1[i].end());
    }
    REP(i,1+(n+1)/2){
        sort(grid2[i].begin(), grid2[i].end());
    }
    llint result = 0;
    REP(i,1+(n/2)){
        if(i<=k){
            REP(j,grid1[i].size()){
                if(k-i>=0&&k-i<=(n+1)/2){
                    result += distance(lower_bound(grid2[k - i].begin(), grid2[k - i].end(),l-grid1[i][j] ),
                    upper_bound(grid2[k - i].begin(), grid2[k - i].end(),r-grid1[i][j] ));
                }
              //  cout << result << endl;
            }
        }
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 23420
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;

int main(){
	ll n, a, b;cin>>n>>a>>b;
	ll arr[100100];
	for(int i=1; i<=n; i++)cin>>arr[i];
	ll ans =0 ;
	for(int i=2; i<=n; i++){
		ans += min(b, (arr[i]-arr[i-1])*a);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int n,i,x,j,a=0;
    cin>>n>>x;
    while(!(n==0&&x==0)){
        for(i=1;i<n;i++){
            for(j=i+1;j<=n;j++){
                if((x-i-j)!=i&&(x-i-j)!=j&&(x-i-j)<=n&&i!=j&&j<(x-i-j)){
                    a++;
                }
            }
        }
        cout<<a<<endl;
        a=0;
        cin>>n>>x;
    }
    return 0;
}


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

// 外部変数 
int N, M, QNUM;
int ans = 0;
std::vector<int> a, b, c, d;

// 深さ優先探索 
void dfs(std::vector<int> A){
    if(A.size() != N+1){
        // 最終段になるまで下に潜る 
        A.push_back(A.back());  // Aの後ろに要素を付け加える 

        // 幅を移動する
        while(A.back() <= M){
            dfs(A);             // 今付け加えた要素を含む数列で下に潜る 
            A.back()++; 
        }
    }else{
        // 最終段のみ答えを見る 
        /*
        ** [問題文]
        ** aとbはできた数列のインデックス。cとdは渡された数値そのまま。
        */
        int tmp = 0;    // 得点を記録する 
        for(int i = 0; i < QNUM; i++){
            if((A[b[i]] - A[a[i]]) == c[i]){
                tmp += d[i];
            }
        }
        ans = std::max(ans, tmp);
    }
}

// メインプログラム 
int main(){
    // 入力 
    std::cin >> N >> M >> QNUM;

    a = b = c = d = std::vector<int>(QNUM);
    for(int cnt = 0; cnt < QNUM; cnt++){
        std::cin >> a[cnt] >> b[cnt] >> c[cnt] >> d[cnt];
    }

    // 全探索をする 
    dfs(std::vector<int>(1, 1));   

    // 出力 
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3644
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
aa = [inp() for _ in range(N)]

tmp = deque([])
first = True

for a in aa:
    if first:
        tmp.append(a)
        first = False
        continue

    if tmp[0] >= a:
        tmp.appendleft(a)
    else:
        ind = bisect.bisect_left(tmp,a)
        tmp[ind-1] = a

    #print(tmp)

print(len(tmp))


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

// template from zscoder

int h,w,b;
char grid[55][55];
int visit[55][55];
int dist[55][55];
int dx[4]={-1,0,0,1};
int dy[4]={0,-1,1,0};

void dfs(int x,int y)
{
    if(grid[x][y]!='.'||visit[x][y]==1)return;
    else
    {
        visit[x][y] = 1;
        queue < ii > S;
        S.push(mp(x,y));
        while(!S.empty())
        {
            int xx = S.front().fi;
            int yy = S.front().se;
            S.pop();
            for(int i = 0; i < 4; i++)
            {
                int X = xx + dx[i];
                int Y = yy + dy[i];
                if(X>=0&&X<h&&Y>=0&&Y<w&&grid[X][Y]=='.'&&visit[X][Y]==0)
                {
                    visit[X][Y] = 1;
                    dist[X][Y] = dist[xx][yy]+1;
                    S.push(mp(X,Y));
                }
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    cin >> h >> w;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin >> grid[i][j];
            if(grid[i][j] == '#')b++;
        }
    }
    dist[0][0]=1;
    dfs(0,0);

    if(dist[h-1][w-1]==0)cout << -1 << endl;
    else
    {
        int ans = h*w;
        ans -= dist[h-1][w-1];
        ans -= b;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> nums(N);
    vector<ll> sortNums(N);
    for (int i = 0; i < N; i++)
    {
        cin >> nums.at(i);
    }
    copy(nums.begin(), nums.end(), sortNums.begin());
    sort(sortNums.begin(), sortNums.end());
    ll median = sortNums.at(N / 2 - 1);
    for (int i = 0; i < N; i++)
    {
        cout << ((nums.at(i) > median) ? sortNums.at(N / 2 - 1) : sortNums.at(N / 2)) << "\n";
    }
    cout.flush();
    return 0;
}


Measured memory_bytes: 5376
import Control.Monad
import Data.List

main = do
  [n,l,t] <- map read . words <$> getLine
  xws <- map (map read . words) <$> replicateM n getLine :: IO [[Int]]
  mapM_ print $ solve n l t xws

solve n l t xws = drop d ps' ++ take d ps'
  where
  d = sum ds `mod` n
  moved x w = x + t * (3-w*2)
  ps' = sort ps
  (ds,ps) = unzip [ moved x w `divMod` l | [x,w] <- xws ]


Measured memory_bytes: 70012
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main()
{
    IOS;
    int x,y;
    cin>>x>>y;
    int ans=0;
    if(x==1 && y==1)
        ans=400000;
    if(x==1)
        ans+=300000;
    if(x==2)
        ans+=200000;
    if(x==3)
        ans+=100000;
    if(y==1)
        ans+=300000;
    if(y==2)
        ans+=200000;
    if(y==3)
        ans+=100000;
    cout<<ans;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    ll n, cnt=0;
    cin>>n;
    ll i = 1;
    while (n>0)
    {
        n/=2;
        cnt+=i;
        i*=2;
    }
    cout<<cnt;
}
int main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)foo();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
using namespace std;
main(){
//	freopen("input.txt","r",stdin);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    cout<<a-b+1;
}

Measured memory_bytes: 256
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main () {
	let N = read_line().parse::<usize>().unwrap();
	let mut l = read_line().split_whitespace().map(|e|e.parse().unwrap()).collect::<Vec<i32>>();
	l.sort();
	println!("{}",l[N-1] - l[0]);
}


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

int dfs(vector<vector<int>> &g, vector<int> &have_been, vector<int> &nums, vector<int> &nums_inv, vector<int> &parents, int v, int parent, int num){
	have_been[v] = 1;
	nums[v] = num;
	nums_inv[num] = v;
	parents[v] = parent;
	num++;
	for(int i = 0; i < g[v].size(); i++){
		if(g[v][i] != parent && have_been[g[v][i]] == 0){
			num = dfs(g, have_been, nums, nums_inv, parents, g[v][i], v, num);
		}
	}
	return num;
}

int main(){
	int N, M, A, B, i, j;
	scanf("%d%d", &N, &M);
	vector<vector<int>> g(N, vector<int>(0));
	for(i = 0; i < M; i++){
		scanf("%d%d", &A, &B);
		A--;
		B--;
		g[A].push_back(B);
		g[B].push_back(A);
	}
	if(M % 2 == 1){
		printf("-1\n");
		return 0;
	}
	vector<int> have_been(N, 0), nums(N), nums_inv(N), parents(N);
	int res = dfs(g, have_been, nums, nums_inv, parents, 0, -1, 0);
	if(res != N){
		for(i = 0; i < 1000000; i++){
			for(j = 0; j < 100000; j++){
				printf("%d %d\n", i, j);
			}
		}
	}
	vector<int> au(N, 0);
	for(i = N - 1; i >= 0; i--){
		int v = nums_inv[i];
		int cnt = 0;
		for(j = 0; j < g[v].size(); j++){
			if(nums[g[v][j]] < nums[v] && g[v][j] != parents[v]){
				printf("%d %d\n", v + 1, g[v][j] + 1);
				cnt++;
			}
		}
		if(parents[v] == -1){
			continue;
		}
		if((cnt + au[v]) % 2 == 0){
			printf("%d %d\n", parents[v] + 1, v + 1);
			au[parents[v]]++;
		}
		else{
			printf("%d %d\n", v + 1, parents[v] + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 19712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(int i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define prllclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
int main()
{
       int n,m;
       cin>>n>>m;
       priority_queue<ll> pq;
       fri(i,0,n){
              int xx;
              cin>>xx;
              pq.push(xx);
       }
       fri(i,0,m){
              ll xx = pq.top();
              pq.pop();
              pq.push(xx/2);
       }
       ll sum = 0;
       while(pq.size()){
              sum += pq.top();
              pq.pop();
       }
       cout<<sum<<endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
	int N,X;
	cin >> N>>X;
  vector<int> x(N);
  rep(i,N) cin >> x[i];
  auto gcd = [](auto a, auto b){
    while(1){
      swap(a,b);
      if(b == 0) return a;
      a = a%b;
    }
  };
  int ans = abs(X - x[0]);
  rep(i,N){
    ans = gcd(ans,abs(X - x[i]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	var t int
	var x, y float64
	t, x, y = 0, 0.0, 0.0 // initialized

	var tNext int
	var xNext, yNext float64

	flag := "Yes"
	for i := 0; i < n; i++ {
		fmt.Scan(&tNext, &xNext, &yNext)

		// 残り時間
		T := tNext - t
		// 目的地までの距離（マンハッタン距離）
		dist := math.Abs(xNext-x) + math.Abs(yNext-y)

		// 残り時間より必要な移動距離のほうが長い
		if T < int(dist) {
			flag = "No"
		}
		// 着いてからのあまり時間が偶数であれば行き帰りできる
		if (T-int(dist))%2 == 1 {
			flag = "No"
		}
		// updated
		t, x, y = tNext, xNext, yNext
	}
	fmt.Println(flag)

}


Measured memory_bytes: 5504