akhauriyash/Code-Regression huggingface dataset:
#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 FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int H, W, D, Q;
vector<vector<int>> A;
vector<int> L, R;
vector<pair<int, int>> b;

int main(){
  cin >> H >> W >> D;
  A.resize(H, vector<int>(W, 0));
  b.resize(H*W+1, make_pair(-1, -1));
  REP(i, H){
    REP(j, W){
      cin >> A[i][j];
      b[A[i][j]] = make_pair(i, j);
    }
  }
  cin >> Q;
  L.resize(Q), R.resize(Q);
  REP(i, Q){
    cin >> L[i] >> R[i];
  }

  vector<int> cost(H*W+1, 0);
  FOR(i, 1, H*W+1){
    for(int j=1; i+j*D <= H*W; j++){
      int idx2 = i+j*D, idx1=i+(j-1)*D;
      if(b[idx2].first == -1|| cost[idx2] != 0){
        break;
      }
      cost[idx2]+=cost[idx1] +abs(b[idx1].first-b[idx2].first)+abs(b[idx1].second-b[idx2].second);
    }
  }
  int ans = 0;
  REP(i, Q){
    cout << cost[R[i]] - cost[L[i]] << endl;
  }

  return 0;
}


Measured memory_bytes: 3328
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	mod int = 1e9 + 7
)

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	N := float64(getInt())
	fmt.Println(math.Ceil(N / 2) / N)
}

func getInt() int {
	sc.Scan()
	str := sc.Text()
	value, _ := strconv.Atoi(str)
	return value
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 640
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int a[4]={},cnt=0;
  string s;
  cin >> s;
  for(int i=0; i<4; i++) {
    a[i]=s[i]-'0';
  }
  for(int i=0; i<(1<<3); i++) {
    cnt=a[0];
    for(int j=0; j<3; j++) {
      cnt+=a[j+1]*(i&(1<<j)?1:-1);
    }
    if(cnt==7) {
      for(int j=0; j<3; j++) {
        cout << a[j];
        if(i&(1<<j)) {
          cout << "+";
        }
        else {
          cout << "-";
        }
      }
      cout << a[3] << "=7" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
use proconio::{input, marker::Usize1};

fn main() {
    input! {
        r: usize,
        c: usize,
        k: usize,
        rcv: [(Usize1, Usize1, u64); k],
    }

    println!("{}", DP::new(&rcv, r, c).calc());
}

struct DP {
    dp: Vec<Vec<Vec<Option<u64>>>>,
    b: Vec<Vec<u64>>,
    r: usize,
    c: usize,
}

impl DP {
    fn new(rcv: &Vec<(usize, usize, u64)>, r: usize, c: usize) -> DP {
        DP {
            dp: vec![vec![vec![None; 3 + 1]; c]; r],
            b: DP::make_board(&rcv, r, c),
            r: r,
            c: c,
        }
    }

    fn make_board(rcv: &Vec<(usize, usize, u64)>, r: usize, c: usize) -> Vec<Vec<u64>> {
        let mut b = vec![vec![0; c]; r];
        for &(i, j, v) in rcv {
            b[i][j] = v;
        }
        b
    }

    fn calc(&mut self) -> u64 {
        let (r, c) = (self.r, self.c);
        self.dp[0][0][0] = Some(0);
        for i in 0..r {
            for j in 0..c {
                for k in (0..3).rev() {
                    if let Some(v) = self.dp[i][j][k] {
                        self.set_v(i, j, k + 1, v + self.b[i][j]);
                    }
                }
                for k in 0..=3 {
                    if let Some(v) = self.dp[i][j][k] {
                        if i + 1 < r {
                            self.set_v(i + 1, j, 0, v);
                        }
                        if j + 1 < c {
                            self.set_v(i, j + 1, k, v);
                        }
                    }
                }
            }
        }
    
        self.get_ans()
    }

    fn set_v(&mut self, i: usize, j: usize, k: usize, v: u64) {
        let nv = &mut self.dp[i][j][k];
        let v = if let Some(nv) = *nv { nv.max(v) } else { v };
        *nv = Some(v);
    }

    fn get_ans(&self) -> u64 {
        let mut ans = 0;
        for k in 0..=3 {
            if let Some(v) = self.dp[self.r - 1][self.c - 1][k] {
                ans = ans.max(v);
            }
        }
        ans
    }
}


Measured memory_bytes: 995772
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=200005;

int N,M,A[MAXN],B[MAXN];
map<int,int> cnt;

int val[MAXN];

int fa[MAXN],sz[MAXN];
int Root(int x)
{
    if(fa[x]==0)
        return x;
    return fa[x]=Root(fa[x]);
}
void Union(int x,int y)
{
    int r1=Root(x),r2=Root(y);
    if(r1==r2)
        return;
    fa[r1]=r2;
    sz[r2]+=sz[r1];
}

int main()
{
    int sum=0,tmp=0;
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
    {
        scanf("%d",&A[i]);
        cnt[A[i]]++;
        sum^=A[i];
    }
    cnt[sum]++;
    A[N+1]=sum;
    for(int i=1;i<=N;i++)
    {
        scanf("%d",&B[i]);
        tmp^=B[i];
    }
    B[N+1]=tmp^sum;
    for(int i=1;i<=N;i++)
    {
        if(cnt[B[i]]==0)
        {
            puts("-1");
            return 0;
        }
        cnt[B[i]]--;
    }
    for(int i=1;i<=N+1;i++)
    {
        val[i*2-1]=A[i];
        val[i*2]=B[i];
    }
    sort(val+1,val+(N+1)*2+1);
    M=unique(val+1,val+(N+1)*2+1)-val-1;
    for(int i=1;i<=N+1;i++)
    {
        A[i]=lower_bound(val+1,val+M+1,A[i])-val;
        B[i]=lower_bound(val+1,val+M+1,B[i])-val;
    }
    sum=find(val+1,val+M+1,sum)-val;

    fill(sz+1,sz+M+1,1);

    int ans=0;
    for(int i=1;i<=N;i++)
        if(A[i]!=B[i])
        {
            Union(A[i],B[i]);
            ans++;
        }
    for(int i=1;i<=M;i++)
        if(Root(i)==i&&sz[i]>1)
            ans++;
    if(Root(sum)!=sum||sz[sum]>1)
        ans--;
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 8832
n,m = map(int,input().split())
a = set([int(input()) for i in range(m)])
mod = 10**9+7

dp = [0]*(n+1)
dp[0] = 1
for i in range(n):
    if i+1<n+1 and not i+1 in a:
        dp[i+1] += dp[i]
        dp[i+1] %= mod
    if i+2<n+1 and not i+2 in a:
        dp[i+2] += dp[i]
        dp[i+2] %= mod

print(dp[n])

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

typedef struct {
  long head;
  long prev;
} S_DATA;

int main(void) {

  long n,m,k;
  scanf("%ld %ld %ld", &n, &m, &k);
  long **friend,**block;
  friend = (long **)malloc(sizeof (long*) * (n+1));
  block = (long **)malloc(sizeof (long*) * (n+1));
  for (long i = 0; i < n+1; i++) {
    friend[i] = (long *)malloc(sizeof (long) * (n+1));
    friend[i][0] = 0;
    block[i] = (long *)malloc(sizeof (long) * (n+1));
    block[i][0] = 0;
  }
  for (long i = 1; i <= n; i++) {
    friend[0][i] = 0;
    block[0][i] = 0;
  }
  long a,b;
  for (long i = 0; i < m; i++) {
    scanf("%ld %ld", &a, &b);
    friend[a][0]++;
    friend[a][friend[a][0]] = b;
    friend[b][0]++;
    friend[b][friend[b][0]] = a;
  }
  for (long i = 0; i < k; i++) {
    scanf("%ld %ld", &a, &b);
    block[a][0]++;
    block[a][block[a][0]] = b;
    block[b][0]++;
    block[b][block[b][0]] = a;
  }
  S_DATA users[n+1];
  long group_size[n+1];
  for (long i = 0; i <= n; i++) {
    users[i].head = 0;
    users[i].prev = 0;
    group_size[i] = 0;
  }
  users[1].head = 1;
  group_size[0] = 1;
  group_size[1] = 1;
  long current = 1;
  while (1) {
    friend[0][current]++;
    if (friend[0][current] <= friend[current][0]) {
      if (users[friend[current][friend[0][current]]].head == 0) {
        users[friend[current][friend[0][current]]].head = users[current].head;
        group_size[users[current].head]++;
        group_size[0]++;
        if (group_size[0] == n) {
          break;
        }
        users[friend[current][friend[0][current]]].prev = current;
        current = friend[current][friend[0][current]];
      } else {
        continue;
      }
    } else {
      if (users[current].prev == 0) {
        for (long i = users[current].head+1; i <= n; i++) {
          if (users[i].head == 0) {
            users[i].head = i;
            current = i;
            group_size[current]++;
            group_size[0]++;
            break;
          }
        }
        if (group_size[0] == n) {
          break;
        }
      } else {
        current = users[current].prev;
      }
    }
  }
  long suggestion;
  for (long i = 1; i <= n; i++) {
    suggestion = group_size[users[i].head]-friend[i][0]-1;
    for (long j = 1; j <= block[i][0]; j++) {
      if (users[block[i][j]].head == users[i].head) {
        suggestion--;
      }
    }
    if (i != n) {
      printf("%ld ", suggestion);
    } else {
      printf("%ld\n", suggestion);
    }
  }

  return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion



int main() {
    int n; cin >> n;
    vector<double> r(n), x(n, -1e9);
    rep(i, 0, n) cin >> r[i];
    x[0] = 0;
    rep(i, 1, n) {
        rep(j, 0, i) {
            x[i] = max(
                x[i],
                x[j] + sqrt((r[i] + r[j]) * (r[i] + r[j]) - (r[i] - r[j]) * (r[i] - r[j]))
            );
        }
    }
    double xmin = x[0] - r[0], xmax = x[0] + r[0];
    rep(i, 1, n) {
        xmin = min(xmin, x[i] - r[i]);
        xmax = max(xmax, x[i] + r[i]);
    }
    cout << fixed << setprecision(9) << (xmax - xmin) << endl;
}


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

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

constexpr int UNKNOWN = INT_MAX;

inline bool valid(const function<bool(int, int)> &compare, int a, int b) {
	return b == UNKNOWN || compare(a, b);
}

string solve(const vector<int> &a) {
	const int n = a.size();

	const function<bool(int, int)> comparators[] = {less<int>(), greater<int>()};

	int low = INT_MIN;
	int high = INT_MAX;
	for(int i = 0; i < n; ++i) {
		if(a[i] == UNKNOWN) {
			if(i > 0) {
				if(i & 1) chmax(low, a[i - 1] + 1);
				else chmin(high, a[i - 1] - 1);
			}
			if(i < n - 1) {
				if(a[i + 1] == UNKNOWN) return "none";
				if(i & 1) chmax(low, a[i + 1] + 1);
				else chmin(high, a[i + 1] - 1);
			}
		}
		else {
			const auto &c = comparators[i & 1];
			if((i > 0 && !valid(c, a[i], a[i - 1])) || (i < n - 1 && !valid(c, a[i], a[i + 1]))) {
				return "none";
			}
		}
	}

	if(low > high) return "none";
	if(low < high) return "ambiguous";
	return to_string(low); // low == high
}

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

	for(int n; cin >> n && n;) {
		vector<int> a(n);
		for(auto &e : a) {
			string in;
			cin >> in;

			if(in[0] == 'x') {
				e = UNKNOWN;
			}
			else {
				e = stoi(in);
			}
		}

		cout << solve(a) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1264
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	int A[10];
	cin>>A[0]>>A[1]>>A[2];
	sort(A,A+3);
	cout<<A[0]+A[1]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll l = 0, r = mod; // ng, ok;
    
    while(r - l > 1) {
        ll m = (l + r) / 2;
        ll a = 0;
        rep(i, N) {
            if(A[i] >= m) {
                a += (A[i] - 1) / m;
            }
        }
        if(a <= K) r = m;
        else l = m;
    }
    output(r);
    return 0;
}


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

// stackを用いた深さ優先探索

int main() {
  string s;
  cin >> s;
  vector<string> options = {"dream", "dreamer", "erase", "eraser"};
  
  stack<int> DFS;  // index管理用stack
  DFS.push(0);
  
  bool divisible = false;
  while (!DFS.empty()) {
    int t = DFS.top();
    DFS.pop();
    
    if (t == s.size()) {  // 綺麗に分割できたとき
      divisible = true;
      break;
    }
    
    for (string c : options) {
      // sのi番目からc.size要素までがoptionsのどれかと一致したら、
      // 現在地からc.size文字分進めてstackにpushする
      if (s.substr(t, c.size()) == c) {
        DFS.push(t + c.size());
      }
    }
  }
 
  cout << (divisible ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3768
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int nb = sc.nextInt();
        int total = sc.nextInt();
        ArrayList<Integer> ansList = new ArrayList<>();
        ansList.add(-1);
        ansList.add(-1);
        ansList.add(-1);

        for(int i=0; i<=nb; i++){
            for(int j=0; j<=nb; j++){
                int k = nb - i - j;
                int nb_sum = i + j + k;
                if (nb_sum != nb || k < 0){
                    continue;
                } else {
                    int total_sum = i*10000 + j*5000 + k*1000;
                    if (total_sum == total){
                        ansList.set(0, i);
                        ansList.set(1, j);
                        ansList.set(2, k);

                        break;
                    }
                }
            }
        }

        for(int i=0; i<ansList.size(); i++){
            if (i == ansList.size() - 1){
                System.out.println(ansList.get(i));
            } else {
                System.out.print(String.format("%d ", ansList.get(i)));
            }
        }
    }
}


Measured memory_bytes: 24660
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *r,*l,*parent;
  int point;
};
typedef struct node * Node;

Node root;

Node tree(Node t, int k){
  while((t != NIL) && (k != t->point)){
    if (k < t->point){
    t = t->l;
    } 
    else t = t->r;
  }
  return t;
}
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->point = k;
  z->l = z->r =NIL;
 
  while(x != NIL){
    y = x;
    if (z->point < x->point)x = x->l;
    else x = x->r;
  }
  z->parent = y;
  if (y == NIL)root = z;
  else if(z->point < y->point) y->l = z;
  else y->r = z;
}
void treeDelete(Node z){
  Node y,x; 
}
void in(Node t){
  if(t != NIL) {
    if(t->l != NIL) in(t->l);
    printf(" %d",t->point);
    if(t->r != NIL) in(t->r);
  }
}
void pre(Node u){ 
  if(u != NIL) {
    printf(" %d",u->point);
    if(u->l!= NIL) pre(u->l);
    if(u->r != NIL) pre(u->r);
  }
}
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%s", com);
    switch(com[0]){
        case 'f':
            scanf("%d", &x);
            Node t = tree(root, x);
            ( t != NIL ) ? printf("yes\n") : printf("no\n");
            break;
        case 'i':
            scanf("%d", &x);
            insert(x);
            break;
        case 'p':
            in(root);
            printf("\n");
            pre(root);
            printf("\n");
            break;
        case 'd':
            scanf("%d", &x);
            treeDelete(tree(root, x));
            break;
    }
  }
  return 0;
}


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

signed main() {
  int n; cin >> n;
  vector<int> vec(n);
  for(int i = 0; i < n; i++) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  cout << vec.at(vec.size()-1) - vec.at(0) << endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    S = input()

    kuro_num = 0
    siro_num = 0
    for moji in S:
        if moji == "#":
            kuro_num += 1
        else:
            siro_num += 1

    if siro_num == N:
        print(0)
        exit()

    # ..........############ のパターン
    rest_kuro_num = kuro_num
    rest_siro_num = siro_num
    ans = siro_num
    for i in range(0, len(S)):
        num = rest_siro_num
        if S[i] == "#":
            num += 1 + (kuro_num - rest_kuro_num)
            rest_kuro_num -= 1
        else:
            num -= 1
            num += kuro_num - rest_kuro_num
            rest_siro_num -= 1
        ans = min(ans, num)

    print(ans)

"""
26
...##..##...##.....#..#..#
"""
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3500
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef pair<int,int> pii;
// cin.tie(0);
// std::ios::sync_with_stdio(false);
// tree <pii,null_type,greater<pii>,rb_tree_tag,tree_order_statistics_node_update> tr;
typedef long long LL;
const int N = 50005;
const int M = 2000005;
const int INF = 0x3f3f3f3f;
const double Pi = acos(-1);
const int MOD = 1e9+7;
const double eps = 1e-8;
int n,m;
int main()
{
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    while (cin>>n>>m)
    {
        cout<< ((n-m)*100+m*1900)*(1<<m)<<endl;
    }
    return 0;
}

/*

5 2 3 2

*/

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

int main(){
    string S;
    cin >> S;
 
    int l;
    l = S.size();
    set<char> alphabet;
    for(int i=0;i<l;i++)
        alphabet.insert(S[i]);

    if(l != 26){
        // 未使用のアルファベットのうち、最小のものを語尾に付加
        for(int i=0;i<26;i++){
            auto itr = alphabet.find('a' + i);
            if(itr == alphabet.end()){
                cout << S <<(char)('a' + i) << endl;
                break;
            }
        }
    }else if(S == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
    }else{
        string T = S;
        next_permutation(T.begin(), T.end());
        int i;
        for(i=0;i<l && S[i] == T[i];i++)
            cout << T[i];
        cout << T[i] << endl;
    }

    return 0;
}

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

int N;
vector<int> W;

void solve() {
  vector<int> S(N);
  int res = 1000000;
  S[0] = W[0];
  for (int i = 1; i < N; i++) {
    S[i] = S[i - 1] + W[i];
  }
  for (int i = 0; i < N; i++) {
    int S_c = S[N - 1] - S[i];
    res = min(res, abs(S_c - S[i]));
  }

  cout << res << '\n';
}

int main() {
  cin >> N;
  W.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> W[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
using ll = long long ;
using namespace std;
int n;
int c=0;
int esx;int esy;
vector<vector<int>> vec;
vector<int> reg;
void dfs(int x){
  //  cout<<"  "<<x<<endl;
    for(int i=0;i<vec[x].size();i++){
        if(reg[vec[x][i]]==0){
            if((x==esx&&vec[x][i]==esy)||(x==esy&&vec[x][i]==esx))continue;
            reg[vec[x][i]]=1;
            dfs(vec[x][i]);
        }
    }
    return;
}
int main(){
    int m;
    cin >> n >> m;
    vec.resize(n+100);
    reg.resize(n+100);
    vector<pair<int,int>> es(n+100);
    for(int i=1;i<=m;i++){
        int a,b;
        cin >> a >> b;
        vec[a].push_back(b);
        vec[b].push_back(a);
        es[i]=pair<int,int>(a,b);
    }
    for(int i=1;i<=m;i++){
        esx=es[i].first;
        esy=es[i].second;
        reg[1]=1;
        dfs(1);
        bool h=true;
        for(int j=1;j<=n;j++){
            if(reg[j]==0){
                h=false;
                break;
            }
        }
        if(!h){
            c++;
        //    cout<<i<<endl;
        }
        for(int j=1;j<=n;j++){
            reg[j]=0;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int[] p = new int[N];
		
		for(int i=0;i<N;i++) {
			p[i]=sc.nextInt();
		}
		
		Arrays.sort(p);
		
		int sum=0;
		
		for(int i=0;i<N-1;i++) {
			sum+=p[i];
		}
		
		System.out.println(sum+p[N-1]/2);
		
		sc.close();
	}
}


Measured memory_bytes: 21844
#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>;

const ll INF = 1e18;
const int MX = 2005;

int a[4];
string S;

int cal(string ans,int i,int j,int sum){
  if(i == 4){
    if(sum == 7){
      S = ans;
    }
    return 0;
  }
  cal(ans + "+" + to_string(a[i]),i+1,0,sum + a[i]);
  cal(ans + "-" + to_string(a[i]),i+1,1,sum - a[i]);
  return 0;
}

int main() {
  string s;
  cin >> s;
  rep(i,4) a[i] = s[i] - '0';
  cal(to_string(a[0]),1,0,a[0]);
  cal(to_string(a[0]),1,1,a[0]);
  cout << S << "=7" << endl;
  return 0;
}

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

int main(){
    ll x;
    cin >> x;
    ll a=100, counter=0;
    while(1){
        a += a/100;
        ++counter;
        if(a >= x){
            break;
        }
    }
    cout << counter << "\n";
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

const int MAX=510000;
const int mod=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a){
  return modpow(a,mod-2);
}

void init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  rep(i,MAX){
    if(i>1){
      fac[i]=fac[i-1]*i%mod;
      inv[i]=mod-inv[mod%i]*(mod/i)%mod;
      finv[i]=finv[i-1]*inv[i]%mod;
    }
  }
}

ll com(int n,int k){
  if(n<k) return 0;
  if(n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}


int main(){
  ll N,A,B,C;
  cin>>N>>A>>B>>C;
  ll ans=0;
  init();
  rep(i,N){
    ll AA=A*modinv(A+B)%mod;
    ll BB=B*modinv(A+B)%mod;
    ll tmp=(modpow(AA,N)*modpow(BB,i)%mod+modpow(AA,i)*modpow(BB,N)%mod)%mod;
    tmp=tmp*com(N+i-1,i)%mod*(N+i)%mod;
    (ans+=tmp)%=mod;
  }
  ans=ans*100%mod*modinv(100-C)%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 12160
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define int long long
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int INF = 1e18;
const int M = 1e9 + 7;





signed main()
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	string s;
	cin >> s;
	for(int i = 1; i < 4; ++i){
		if(s[i] == s[i - 1]){
			puts("Bad");
			return 0;
		}
	}
	puts("Good");




    
	return 0;
}

Measured memory_bytes: 256
import java.math.*

fun main(args: Array<String>) {
    var (a, b) = readInputLine().split(" ").map { it.toInt() }
    
    var ans = Math.max(a, b)
    
    if (a > b) {
        a--
    } else {
        b--
    }
    
    ans += Math.max(a, b)

    println(ans)
}
 
fun readInputLine(): String {
    return readLine()!!
}


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

using P = pair<ll, ll>;

constexpr int INF = 1e9;

int main() {
    int N;
    cin >> N;
    N *= 2;
    vector<int> L(N);
    for(int i=0; i<N; ++i) {
        cin >> L[i];
    }
    sort(L.rbegin(), L.rend());
    int res = 0;
    for(int i=0; i+1<N; i+=2) {
        res += min(L[i], L[i+1]);
    }
    cout << res << endl;
}


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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int n;
  string s;
  cin >> n >> s;
  ll ans=0;
  ll r=0,g=0,b=0;
  if(n<3){
    cout << 0 << endl;
  }
  else{
  for(int i=0;i<n;i++){
    if(s[i]=='R')
      r++;
    if(s[i]=='G')
      g++;
    if(s[i]=='B')
      b++;
  }
  ans=r*g*b;
  for(int i=1;i<=(n-1)/2;i++){
    for(int j=0;j<n-2*i;j++){
      if(s[j]!=s[i+j]&&s[i+j]!=s[j+2*i]&&s[j]!=s[j+2*i]){
        ans--;
      }
    }
  }
  cout << ans << endl;
  }
}


Measured memory_bytes: 3640
n, m = map(int, input().split())
a = list(map(int, input().split()))

ans = 'No'
cnt = 0
b = sum(a)/(4*m)
for i in range(n):
  if a[i] >= b:
    cnt +=1
    if cnt >= m:
      ans = 'Yes'
      break
  
print(ans)

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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>


int ans, A,B,M, a[MAXM], amin = MAXM,  b[MAXM], bmin = MAXM, x[MAXM], y[MAXM], c[MAXM];

void solve(){
    ans = amin + bmin;

    rep(i, M){
        ans = min(ans, a[x[i]-1]+b[y[i]-1] - c[i]);
    }
    
    cout << ans << endl;
}

int main(){
    cin >> A >> B >> M;

    rep(i, A){
        cin >> a[i];
        amin = min(amin, a[i]);
    }

    rep(i, B){
        cin >> b[i];
        bmin = min(bmin, b[i]);
    }

    // cout << amin << bmin << endl;

    rep(i, M){
        cin >> x[i] >> y[i] >> c[i];
    }

    solve();
}


Measured memory_bytes: 2176
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static PrintWriter out;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        out = new PrintWriter(new BufferedOutputStream(System.out));
        String s = sc.next();
        int slength = s.length();
        char c = s.charAt(slength - 1);
        if (c == 's') {
            out.println(s + "es");
        } else {
            out.println(s + "s");
        }
        sc.close();
        out.close();
    }

}

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

int main(){
  char c;
  cin >> c;
  
  if (c != 'a' && c != 'i' && c != 'u' && c != 'e' && c !=  'o'){
    cout << "consonant" << endl;
  }
  else{
    cout << "vowel" << endl;
  }
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
def solve():
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
    Cake = []
    heapify(Cake)
    for i in range(X):
        for j in range(min(Y,K//(i+1)+1)):
            for k in range(min(Z,K//((i+1)*(j+1))+1)):
                heappush(Cake,-A[i]-B[j]-C[k])
    ans = []
    for i in range(K):
        ans.append(abs(heappop(Cake)))
    return ans
print(*solve(),sep='\n')

Measured memory_bytes: 9468
#ABC044C

n,a=map(int,raw_input().split())
x=map(int,raw_input().split())
dp=[[0 for i in xrange(n*a+1)] for j in xrange(n+1)]
dp[0][0]=1
for k in xrange(n):
 for i in xrange(k,-1,-1):
  for j in xrange(n*a,x[k]-1,-1):
   dp[i+1][j]+=dp[i][j-x[k]]
res=0
for i in xrange(1,n+1):
 res+=dp[i][a*i]
print res


Measured memory_bytes: 3844
N, M, K = map(int, input().split())
P = 10**9+7
fact = [1]
for i in range(N*M):
    fact.append(fact[-1]*(i+1)%P)
def inv(n):
    return pow(n, P-2, P)
def C(a, b):
    return fact[a]*inv(fact[a-b]*fact[b])%P
print((M**2*(N**3-N)+N**2*(M**3-M))//6*C(M*N-2, K-2)%P)

Measured memory_bytes: 52464
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long int a[n + 1];
    a[0] = 0;
    map<long long int,long long int> mp;
    mp.insert(make_pair(a[0],1));
    for(int i = 1;i < n + 1;i++)
    {
        cin >> a[i];
        a[i] += a[i - 1];
        if(mp.find(a[i]) == mp.end())
        {
            mp.insert(make_pair(a[i],1));
        }
        else
        {
            mp[a[i]]++;
        }
    }
    long long int ans = 0;
    auto itr = mp.begin();
    while(itr != mp.end())
    {
        long long int x = itr -> second;
        ans += (x * (x - 1)) / 2;
        itr++;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;



int main(){FIN

    ll n; cin>>n;
    vll a(n);
    REP(i,n) cin>>a[i];
    ll mn = inf;
    ll mx = 0;
    REP(i,n){
        mn = min(mn,a[i]);
        mx = max(mx,a[i]);
    }
    cout<<mx-mn<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = [int(input()) for i in range(n)]

def gcd(x, y):
    while y != 0:
        x, y = y, x%y
    return x

def lcm(x, y):
    return (x*y) // gcd(x, y)

for i in range(n-1):
    A[i+1] = lcm(A[i], A[i+1])
    
print(A[-1])

Measured memory_bytes: 3064
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int T = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();

    int[] max = new int[N];
    max[N - 1] = a[N - 1];
    for (int i = N - 2; i >= 0; i--) max[i] = Math.max(a[i], max[i + 1]);

    int cnt = 0;
    int maxDiff = 0;
    for (int i = 0; i < N; i++) {
      int diff = max[i] - a[i];
      if (diff > maxDiff) {
        cnt = 1;
        maxDiff = diff;
      } else if (diff == maxDiff) {
        cnt++;
      }
    }

    System.out.println(cnt);
  }
}


Measured memory_bytes: 50172
#include<cstdio>
#include<map>
#define ll long long
using namespace std;
const int N=405;
int n,i,j,k,x,c[N][4];ll a[N],v[4],ans;
ll num(int a,int b,int c,int d){
	return ((ll)a<<30)+(b<<20)+(c<<10)+d;
}
map<ll,int> mp;
void add(ll x,int k){
	for (int i=4;i--;x=x>>10|(x&1023)<<30) mp[x]+=k;
}
int main(){
	scanf("%d",&n);
	for (i=1;i<=n;add(a[i],1),i++) for (j=0;j<4;j++)
		scanf("%d",&c[i][j]),a[i]=(a[i]<<10)+c[i][j];
	for (i=1;i<=n-5;i++)
		for (add(a[i],-1),j=i+1;j<=n;j++){
			add(a[j],-1);
			for (k=4;k--;){
				v[0]=num(c[i][0],c[j][k],c[j][(k+3)&3],c[i][1]);
				v[1]=num(c[i][1],c[j][(k+3)&3],c[j][(k+2)&3],c[i][2]);
				v[2]=num(c[i][2],c[j][(k+2)&3],c[j][(k+1)&3],c[i][3]);
				v[3]=num(c[i][3],c[j][(k+1)&3],c[j][k],c[i][0]);
				if (!mp[v[0]]||!mp[v[1]]||!mp[v[2]]||!mp[v[3]]) continue;
				ll res=1;
				for (x=4;x--;) res*=mp[v[x]],add(v[x],-1);
				for (ans+=res,x=4;x--;) add(v[x],1);
			}
		 	add(a[j],1);
		}
	printf("%lld",ans);
}

Measured memory_bytes: 20352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, k[1000];
string s;

int main(){
	while (cin >> n&&n){
		REP(i, n)cin >> k[i];
		cin >> s;
		int key = 0;
		REP(i, s.size()){
			REP(j, k[key]){
				if (s[i] == 'a'){
					s[i] = 'Z';
				}
				else if (s[i] == 'A'){
					s[i] = 'z';
				}
				else{
					s[i]--;
				}
			}
			key++;
			if (key >= n)key = 0;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a) for(i = 0 ; i < a ; i++)
#define whln(t) while(t--)
#define whlp(t) while(t++)
ll i=0,j=0;


int main(void){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif
	ll n,d ;
	cin>>n>>d;
	vector<pair<ll,ll>>v(n);

	rep(i,n)
		cin>>v[i].first>>v[i].second ;
	
	ll cnt = 0;

	rep(i,n){
		if((v[i].first*v[i].first + v[i].second*v[i].second)<=d*d)
			cnt++ ;
	}	

	cout<<cnt ;
}
//   *****  *******   !
//   *		     *    !
//   ***       *      !
//   *       *        !
//   *****  *******   !

Measured memory_bytes: 6420
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

a,b,c = map(int, input().split())

if a%2==1 or b%2==1 or c%2==1:
    print(0)
    exit()

if a==b==c and a%2==0:
    print(-1)
    exit()

sabc = a+b+c

cnt = 0
while True:
    a = (sabc-a)/2
    b = (sabc-b)/2
    c = (sabc-c)/2
    cnt+=1
    if a%2==1 or b%2==1 or c%2==1: break

print(cnt)


Measured memory_bytes: 3064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()

print(N.count("2"))


Measured memory_bytes: 10388
def main():

    L = input()
    mod = pow(10, 9) + 7
    n = len(L)
    dp1 = [0 for _ in range(n+1)]
    dp2 = [0 for _ in range(n+1)]
    dp2[0] = 1
    for i in range(n):
        if L[i] == "0":
            dp1[i+1] = dp1[i] * 3
            dp2[i+1] = dp2[i]
        else:
            dp1[i+1] = dp1[i] * 3 + dp2[i]
            dp2[i+1] = dp2[i] * 2
        dp1[i+1] %= mod
        dp2[i+1] %= mod
    # print(dp1)
    # print(dp2)
    return (dp1[n] + dp2[n]) % mod

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 46428
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int score = 0;
  string s;
  cin >> s;
  int gu = 0, pa = 0;
  for(int i = 0; i < s.size(); i++){
    if(pa <= gu - 1){
      if(s[i] == 'g')pa++, score++;
      else pa++;
    }else{
      if(s[i] == 'g')gu++;
      else gu++, score--;
    }
  }
  cout << score << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    
    map <int, int> count;

    for (int i = 0; i < M; i++){
        int a;
        cin >> a;
        count[a] ++;
    }
    int ans = N;
    int sum = 0;
    for (int i = X; i >= 0; i--){
        sum += count[i];
    }
    if (sum < ans){
        ans = sum;
    }
    
    sum = 0;
    for (int i = X; i <= N; i++){
        sum += count[i];
    }
    if (sum < ans){
        ans = sum;
    }
    
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0; i<(n); ++i)

int main(){
    int n; std::cin >> n;
    std::vector<int> p(n);
    rep(i,n) std::cin >> p[i];
    int ans=1, m=p[0];
    for(int i=1; i<n; ++i){
        if(m >= p[i]){
            m = p[i];
            ++ans;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 4048
#include <stdio.h>

int binarysearch(int a[], int key, int n)
{
  int left = 0, right = n, mid;
  
  while (left < right) {
    mid = (left + right) / 2;
    if (a[mid] == key)
      return 1;
    if (a[mid] > key)
      right = mid;
    else
      left = mid + 1;
  }
  
  return 0;
}

int main(void)
{
  int n, q, t, cnt = 0;
  int s[1000000];
  
  scanf("%d", &n);
  
  for (int i = 0; i < n; i++)
    scanf("%d", &s[i]);
  
  scanf("%d", &q);
  
  while(q--) {
    scanf("%d", &t);
    if (binarysearch(s, t, n))
      cnt++;
  }
  
  printf("%d\n", cnt);
  
  return 0;
}


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

using ll = long long;

int main()
{
  int a_health, a_attach, b_health, b_attach;
  cin >> a_health >> a_attach >> b_health >> b_attach;
  int i=1;
  while(true){
    if(b_health <= a_attach*i){
      cout << "Yes" << endl;
      return 0;
    }else if(a_health <= b_attach*i){
      cout << "No" << endl;
      return 0;
    }
    i++;
  }

}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N, S;
int A[3000];
ll dp[3005][3005];
const ll MOD = 998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> S;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    dp[0][0] = 1;
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= S; j++){
            dp[i+1][j] += dp[i][j]*2;
            dp[i+1][j] %= MOD;
            if(j+A[i] <= S){
                dp[i+1][j+A[i]] += dp[i][j];
                dp[i+1][j+A[i]] %= MOD;
            }
        }
    }
    cout << dp[N][S] << endl;
}

Measured memory_bytes: 74036
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1005,M=1e6+5;
int a[N][N],bg[N],vis[N][N],qx[M],qy[M],d[M],h,t,n,res;
inline void swap(R int x,R int y){R int t=x;x=y,y=t;}
int main(){
	scanf("%d",&n);
	fp(i,1,n)fp(j,1,n-1)scanf("%d",&a[i][j]);
	fp(i,1,n)bg[i]=1;
	h=1;
	fp(i,1,n){
		R int j=a[i][bg[i]];
		if(i<j&&a[j][bg[j]]==i)++t,qx[t]=i,qy[t]=j,d[t]=1,vis[i][j]=1;
	}
	while(h<=t){
		R int di=d[h];
		while(h<=t&&d[h]==di){
			R int i=qx[h],j=qy[h],dd=d[h];
//			printf("qwq %d %d %d\n",i,j,dd);
			++h;
			++bg[i],++bg[j];
			if(bg[i]<=n-1){
				R int p=a[i][bg[i]];
				if(i>p)swap(i,p);
				if(bg[p]<=n-1&&a[p][bg[p]]==i&&!vis[i][p]){
					++t,qx[t]=i,qy[t]=p,d[t]=dd+1,vis[i][p]=1;
				}
			}
			if(bg[j]<=n-1){
				R int p=a[j][bg[j]];
				if(j>p)swap(j,p);
				if(bg[p]<=n-1&&a[p][bg[p]]==j&&!vis[j][p]){
					++t,qx[t]=j,qy[t]=p,d[t]=dd+1,vis[j][p]=1;
				}
			}
		}
	}
	if(t!=n*(n-1)>>1)return puts("-1"),0;
	return printf("%d\n",d[t]),0;
}

Measured memory_bytes: 19712
import sys
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N, M = MAP()
    X = LIST()

    if M == 1 or N >= M:
        print(0)
        sys.exit()

    X = sorted(X)

    H = []
    heapify(H)
    for i in range(len(X)-1):
        heappush(H, (X[i+1] - X[i])*(-1))

    for i in range(N-1): heappop(H)

    print(sum(H)*(-1))


if __name__ == '__main__':
    main()

Measured memory_bytes: 57256
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int H, W, x, popcount[1024];
int main() {
    for (int i = 0; i < 1024; i++) {
        for (int j = 0; j < 10; j++) {
            if (i & (1 << j)) popcount[i]++;
        }
    }
    while (scanf("%d%d", &H, &W), H) {
        vector<int> bit(W);
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                scanf("%d", &x);
                bit[j] |= x << i;
            }
        }
        vector<int> cnt(1 << H);
        for (int i = 0; i < W; i++) cnt[bit[i]]++;
        int ret = 0;
        for (int i = 0; i < 1 << (H - 1); i++) {
            vector<int> f(1 << H);
            for (int j = 0; j < 1 << H; j++) {
                f[j] = popcount[i ^ j];
                f[j] = max(f[j], H - f[j]);
            }
            int res = 0;
            for (int j = 0; j < 1 << H; j++) res += cnt[j] * f[j];
            ret = max(ret, res);
        }
        printf("%d\n", ret);
    }
    return 0;
}


Measured memory_bytes: 3188
def knapsack2(weight_value, w):
    v = sum(value for weight, value in weight_value)
    cur = [float("inf")] * (v + 1)
    cur[0] = 0

    for weight, value in weight_value:
        for i in reversed(range(value, v + 1)):
            cur[i] = min(cur[i], cur[i - value] + weight)

    for value in reversed(range(v + 1)):
        if cur[value] <= w:
            return value


def main():
    n, w = [int(x) for x in input().split()]
    weight_value = [None] * n
    for i in range(n):
        weight_value[i] = [int(x) for x in input().split()]
    return knapsack2(weight_value, w)


print(main())


Measured memory_bytes: 86996
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

const int MAX_N = 1000;

const ll MOD = 1E+09 + 7;

int N;

int spf[MAX_N + 1];

int prime[MAX_N + 1];

void smallestPrimeFactors();
void factorization(int n);

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

    cin >> N;

    smallestPrimeFactors();

    for (int i = 2; i <= N; i++) {
        factorization(i);
    }

    ll ans = 1;
    for (int i = 0; i <= N; i++) {
        if (prime[i]) {
            ans = (ans * (prime[i] + 1)) % MOD;
        }
    }

    cout << ans << "\n";

    return 0;
}

void smallestPrimeFactors()
{
    for (int i = 0; i <= N; i++) {
        spf[i] = i;
    }

    for (int i = 2; i <= N; i++) {
        if (spf[i] == i) {
            for (int j = i * i; j <= N; j += i) {
                spf[j] = i;
            }
        }
    }
}

void factorization(int n)
{
    if (n == spf[n]) {
        prime[n]++;
        return;
    }
    prime[spf[n]]++;
    factorization(n / spf[n]);
    return;
}

Measured memory_bytes: 3616