akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define NMAX 100
using namespace std;

int main(){
    int n;
    int input;
    int class_room[NMAX][NMAX];
    int class_room_hand[NMAX][NMAX]; // 1 right 2 left 3 both
    int right[NMAX] = {0};
    int left[NMAX] = {0};
    int ans = 0;
    int ans_n = 0;
    while (cin >> n) {
        if (n == 0) {
            break;
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> input;
                class_room[i][j] = input;
            }
        }
        for (int i = 0; i < n; i++) {
            right[i] = class_room[i][0];
            for (int j = 0; j < n; j++) {
                if (right[i] > class_room[i][j]) {
                    right[i] = class_room[i][j];
                }
                if (left[i] < class_room[j][i]){
                    left[i] = class_room[j][i];
                }
            }
        }
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (right[i] == class_room[i][j]) {
                    class_room_hand[i][j] |= 1;
                }
                if (left[i] == class_room[j][i]){
                    class_room_hand[j][i] |= 2;
                }
            }
        }
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (class_room_hand[i][j] == 3) {
                    ans_n++;
                    ans = class_room[i][j];
                }
            }
        }
        if (ans_n >= 1) {
            cout << ans << endl;
        }else{
            cout << 0 << endl;
        }
        ans_n = 0;
        ans = 0;
        fill((int*)class_room,(int*)(class_room+NMAX),0);
        fill((int*)class_room_hand,(int*)(class_room_hand+NMAX),0);
        fill(right, right + (sizeof(right) / sizeof*(right)),0);
        fill(left, left + (sizeof(left) / sizeof*(left)),0);
    }
    return 0;
}

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

using namespace std;

const int MAX_V = 50010;
const int INF = 1 << 30;

struct Edge {
  int to;
  int capacity;
  int reverse;
};  // struct Edge

vector<Edge> G[MAX_V];
bool used[MAX_V];

void AddEdge(int from, int to, int capacity) {
  G[from].emplace_back(Edge{to, capacity, (int)G[to].size()});
  G[to].emplace_back(Edge{from, 0, (int)G[from].size() - 1});
}

int DFS(int source, int target, int flow) {
  if (source == target) return flow;
  used[source] = true;
  for (auto& edge : G[source]) {
    if (used[edge.to]) continue;
    if (edge.capacity <= 0) continue;

    int actualFlow = DFS(edge.to, target, min(edge.capacity, flow));
    if (actualFlow <= 0) continue;

    edge.capacity -= actualFlow;
    G[edge.to][edge.reverse].capacity += actualFlow;
    return actualFlow;
  }
  return 0;
}

int MaxFlow(int source, int target) {
  int totalFlow = 0;
  while (true) {
    memset(used, false, sizeof(used));
    int flow = DFS(source, target, INF);
    if (flow == 0) {
      break;
    }
    totalFlow += flow;
  }
  return totalFlow;
}

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> red(N), blue(N);
  for (int i = 0; i < N; i++) cin >> red[i].first >> red[i].second;
  for (int i = 0; i < N; i++) cin >> blue[i].first >> blue[i].second;

  for (int ir = 0; ir < N; ir++) {
    for (int ib = 0; ib < N; ib++) {
      if (red[ir].first <= blue[ib].first and
          red[ir].second <= blue[ib].second) {
        AddEdge(ir, ib + N, 1);
      }
    }
  }

  for (int ir = 0; ir < N; ir++) AddEdge(2 * N, ir, 1);
  for (int ib = 0; ib < N; ib++) AddEdge(ib + N, 2 * N + 1, 1);

  int maxMatches = MaxFlow(2 * N, 2 * N + 1);
  printf("%d\n", maxMatches);

  return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long S, long long W){
    if(W>=S) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}

int main(){
    long long S;
    scanf("%lld",&S);
    long long W;
    scanf("%lld",&W);
    solve(S, W);
    return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y; cin>>x>>y;
  int val=4*x-y;
  if(val<0||val%2!=0||(val/2>x)){cout<<"No"<<endl;}
  else{cout<<"Yes"<<endl;}
  return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int
#define mod 998244353
using namespace std;
int fact[200005];
int power(int a, int b)
{
    if(b==0)
        return 1;
    int t = power(a,b/2);
    t*=t;
    t%=mod;
    if(b&1)
        t*=a;
    return t%mod;
}

int ncr(int n, int r)
{
    if(r==0)
        return 1;
    int ans=1;
    ans*=fact[n];
    ans%=mod;
    ans*=power(fact[r],mod-2);
    ans%=mod;
     ans*=power(fact[n-r],mod-2);
    ans%=mod;

    return ans;
}

void solve()
{
    fact[1]=1;
    fact[0]=1;
    for(int i=2;i<200005;i++)
        fact[i]=fact[i-1]*i%mod;
    int n,m,k;
    cin>>n>>m>>k;
    if(m==1)
    {
        if(k==n-1)
            cout<<1<<endl;
        else
            cout<<0<<endl;
        return;
    }
    int ans=0;
    for(int i=0;i<=k;i++)
    {
        int g = ncr(n-1,i);
        // cout<<g<<endl;
        int t = (g*m%mod)*power(m-1,n-1-i)%mod;
        ans+=t;
        ans%=mod;

    }
    
    cout<<ans<<endl;



}
signed main()

{
    FAST_IO;
    int t = 1;

    // cin>>t;

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

Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
const int N = 20;

int n;
char a[N];

int main()
{
    cin >> a;
    n = strlen(a);
    int q = 0;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] == 'o')
            ++q;
    }
    if (q + (15 - n) >= 8)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;

int main(void){
    int N,K,Q,ans=0;

    cin >> N >> K >> Q;
    int A[Q];
    int p[N];
    
    REP(i,N) p[i]=0;
    REP(i,Q) cin >> A[i];
    
    REP(i,Q) p[A[i]-1]++; //正解数
    REP(i,N) {
        if(K - Q + p[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}
int main()
{
	int A,B;
	cin>>A>>B;
	cout<<A*B<<endl;
}

Measured memory_bytes: 3636
inputs = gets.split(' ')
H = inputs[0].to_i
W = inputs[1].to_i
outputs = []
H.times do
  outputs.push(gets.chomp)
end

# first line
(W+2).times do
  print '#'
end

print "\n"
outputs.each do |line|
  print "\##{line}#"
  print "\n"
end

(W+2).times do
  print '#'
end

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

int main() {
  int A, B;
  int meet=0;
  cin >> A >> B;
  for (int i = A; i <= B; i++) {
    int done=i%10;
    int dtwo=(i-done)/10%10;
    int dthree=((i-done)/10-dtwo)/10%10;
    int dfour=(((i-done)/10-dtwo)/10-dthree)/10%10;
    int dfive=((((i-done)/10-dtwo)/10-dthree)/10-dfour)/10%10;
    if(done==dfive&&dtwo==dfour)
      meet++;
    else
      continue;
  }
  cout << meet << endl;
}

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

using namespace std;
using Edge = pair<int, int>;
using EdgeList = vector<Edge>;
using Graph = vector<EdgeList>;

int dfs(Graph &g, int node, int pred = -1) {
    int res = 0;
    for(auto &e : g[node]) {
        if(e.first != pred) {
            res = max(res, e.second + dfs(g, e.first, node));
        }
    }
    return res;
}

int main(){
    int n;
    while(cin >> n, n) {
        vector<int> count(n+1), ps(n+1);
        for(int i=2; i<=n; i++) {
            cin >> ps[i];
            count[i]++;
            count[ps[i]]++;
        }
        auto isLeaf = [&](int i){ return count[i]==1; };
        Graph g(n+1);
        int cost_r = 0, cost_c = 0;
        if(isLeaf(1)) g[0].push_back(Edge(1, 0));
        for(int i=2; i<=n; i++) {
            int d;
            cin >> d;
            cost_r += d;
            if(!isLeaf(i)) {
                g[0].push_back(Edge(i, 0));
                if(!isLeaf(ps[i])) {
                    g[i].push_back(Edge(ps[i], d));
                    g[ps[i]].push_back(Edge(i, d));
                    cost_c += d;
                }
            }
        }
        int longest = dfs(g, 0);
        cout << cost_r + 2 * cost_c - longest << endl;
    }
    return 0;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int w;
  cin >> N;
 
  vector<int> value(N); // 
  vector<int> cost(N); // N個の
   for (int i = 0; i < N; i++) {
    cin >> value.at(i);
  }
   for (int i = 0; i < N; i++) {
    cin >> cost.at(i);
  } 
  for (int i = 0; i < N; i++) {
     if(value.at(i) > cost.at(i) ){
       w=w+value.at(i)-cost.at(i);
     }
  }
  cout<<w;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iterator>
#include <set>

using namespace std;
using ll = long long;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll N, string S) {
  set<char> se;
  size_t ma{};
  for (size_t i = 0; i != S.size(); ++i) {
    se.clear();
    string X = S.substr(0, i);
    string Y = S.substr(i, S.npos);
    sort(ALL(X));
    sort(ALL(Y));
    set_intersection(ALL(X), ALL(Y), inserter(se, se.end()));
    ma = max(ma,se.size());
  }
  cout << ma << endl;
}

int main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;
  solve(N, S);
  return 0;
}


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

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    string S;
    cin >> S;

    int minV = INT_MAX;

    for (int i = 0; i < S.size() - 2; i++) {
        string s = S.substr(i, 3);
        int d = stoi(s);
        minV = min(minV, abs(753 - d));
    }

    cout << minV;

    return 0;
}





























































Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a, b;
int n, m;
int main(){
  cin >> a >> b;
  n = a.size(); m = b.size();
  vector< vector<int> > dp (n + 1, vector<int> (m + 1, 0)), dir (n + 1, vector<int> (m + 1, 0));
  for (int i = 1; i <= n; i++){
    for (int j = 1; j <= m; j++){
      if (a[i - 1] == b[j - 1]){
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
        dir[i][j] = 2;
      }
      else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        if (dp[i - 1][j] == dp[i][j]){
          dir[i][j] = 1;
        }
        else {
         dir[i][j] = 0;
        }
      }
    }
  }
  
  string ans = "";
  int x = n;
  int y = m;
  while (x > 0 && y > 0){
    //cout << x << " " << y << endl;
    if (dir[x][y] == 2){
      ans += a[x - 1];
      x = x - 1;
      y  = y - 1;
      //cout << "hi\n";
    }
    else if (dir[x][y] == 1){
      x = x - 1;
    }
    else {
      y = y - 1;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
int main(){
  string s;
  cin>>s;
  vector<int>a(4);
  int sumplus=0;
  int summinus=0;
  int che=0;
  int bitans;
  for(int i=0;i<4;i++){a[i]=s[i]-'0';}
  for(int bit=0;bit<(1<<4);bit++){
    bitset<4>tm(bit);
    bitset<4>xo("1111");
    xo=xo^tm;
    sumplus=0;
    summinus=0;
    for(int i=0;i<4;i++){
      if(tm.test(i)){
	sumplus+=a[i];
      }
      if(xo.test(i)){
	summinus+=a[i];
      }//実際にはelse文でsumplusから引くという操作をするだけで十分であるが、ビット操作に慣れるためやや回りくどいことをした。
    }
    if(sumplus-summinus==7){che=1;bitans=bit;break;}

    
      //if(che==1)break;

  }
  bitset<4>bitman(bitans);
    string ans="";
    for(int i=0;i<4;i++){
      if(i!=0&&bitman.test(i))ans+="+";
      else if(i==0)ans+="";
      else ans+="-";
      ans+=s[i];
    }
    ans+="=7";
    cout<<ans<<endl;
    
    
  return 0;
}


Measured memory_bytes: 3608
def check(number)
  dfs(number.dup) == 4
end

def dfs(number)
  count = 0
  for i in 0...9 do
    next if number[i] < 3
    number[i] -= 3
    count = [count, 1 + dfs(number.dup)].max
    number[i] += 3
  end
  for i in 0...9-2 do
    next if number[i] == 0 || number[i + 1] == 0 || number[i + 2] == 0
    number[i] -= 1
    number[i + 1] -= 1
    number[i + 2] -= 1
    count = [count, 1 + dfs(number.dup)].max
    number[i] += 1
    number[i + 1] += 1
    number[i + 2] += 1
  end
  count
end

while line=gets do
  number = Array.new(9, 0)
  line.chop.chars.map{|e| e.to_i - 1}.each do |e|
    number[e] += 1
  end
  answer = Array.new
  for add in 0...9 do
    next if number[add] >= 4
    number[add] += 1
    for i in 0...9 do
      next if number[i] < 2
      number[i] -= 2
      answer.push(add + 1) if check(number.dup)
      number[i] += 2
    end
    number[add] -= 1
  end
  puts answer.empty? ? 0 : answer.uniq.join(" ")
end

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

using namespace std;

using ll = long long;
using ld = long double;

int main()
{
	int h, w;
	cin >> h >> w;
	int a, b;
	cin >> a >> b;
	cout << h * w - (a * w + b * h - a * b) << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int w = scanner.nextInt();
        int[][] wav = new int[n][2];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 2; j++){
                wav[i][j] = scanner.nextInt();
            }
        }
        System.out.println(new Main().f(wav, n, w));
    }

    public long f(int[][] wav, int n, int w) {
        int m = n * 1000 + 1;
        long[] dp = new long[m];
        for(int i = 1; i < m; i++){
            dp[i] = n * 1000000000l + 1;
        }
        long ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = m - 1; j >= 0; j--){
                if(j >= wav[i][1]){
                    dp[j] = Math.min(dp[j], dp[j-wav[i][1]] + wav[i][0]);
                }
                if(dp[j] <= w){
                    ans = Math.max(ans, j);
                }
            }
        }
        return ans;
    }
}


Measured memory_bytes: 21844
let ck cx cy (x1,y1,h1) = abs(cx-x1)+abs(cy-y1)+h1 in
Scanf.scanf "%d\n" (fun n->
  let rec loop i = 
    if i=n then [] else 
    let m = Scanf.scanf "%d %d %d\n" (fun x1 y1 h1->(x1,y1,h1)) in
    m::loop (i+1)
  in
  let ls = loop 0 in
  let (ls1,ls2) = List.partition(fun(x1, y1, h1)->h1>0) ls in
  for x= 0  to  100  do
   for y= 0  to  100  do
     match ls1 with
     | [] -> assert false
     | [(x1,y1,h1)] -> Printf.printf "%d %d %d\n" x1 y1 h1; exit 0
     | l::ls ->
     let h = ck x y l in
     if (List.for_all (fun (x1,y1,h1) -> ck x y (x1,y1,h1) = h) ls) then (
             Printf.printf "%d %d %d\n" x y h;
             exit 0
     )
   done
  done
)




Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
 
#define EPS (1e-10)
#define equals (fabs((a)-(b)<EPS)
int n;
 
struct Point
{
    double x, y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point operator +(Point a)
    {
        return Point(x+a.x,y+a.y);
    }
    Point operator -(Point a)
    {
        return Point(x-a.x,y-a.y);
    }
    Point operator *(double a)
    {
        return Point(x*a,y*a);
    }
 
    double norm()
    {
        return x*x+y*y;
    }
};
Point p1,p2,p;
double cross(Point a,Point b)
{
    return a.x*b.y-b.x*a.y;
}
double dot(Point a,Point b)
{
    return a.x*b.x+a.y*b.y;
}
void solve()
{
    Point a=p2-p1;
    Point b=p-p1;
    if(cross(a,b)>EPS) printf("COUNTER_CLOCKWISE\n");
    else if(cross(a,b)<-EPS) printf("CLOCKWISE\n");
    else if(dot(a,b)<-EPS) printf("ONLINE_BACK\n");
    else if(a.norm()<b.norm()) printf("ONLINE_FRONT\n");
    else printf("ON_SEGMENT\n");
 
}
 
int main()
{
    scanf("%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y);
    scanf("%d",&n);
    while(n--)
    {
        scanf("%lf%lf",&p.x,&p.y);
        solve();
    }
    return 0;
}

Measured memory_bytes: 3196
#include <iostream>
using namespace std;
using ll = long long;

int main(){
	ll N,K;
	cin >> N >> K;
	ll a=1;
	for(int i=0;i<N-1;i++){
		a = a * (K-1);
	}
	
	cout << K*a << endl;
	return 0;
}

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

n = ni()
g = []
gg = []
for i in range(n):
    x,y = na()
    g.append(x-y)
    gg.append(x+y)

ans = max(max(g)-min(g),max(gg)-min(gg))

print(ans)

Measured memory_bytes: 92724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
const constexpr ll mod = 1000000007;
void solve() {
	var(int, h, w, k);
	vv(ll, dp, h + 1, w + 1, 0LL);
	dp[0][1] = 1;
	rep(i, 1, h + 1) {
		rep(mask, 0, (1 << (w - 1))) {
			if (mask & (mask >> 1))
				continue;
			rep(j, 1, w + 1) {
				if (mask >> (j - 1) & 1) {
					dp[i][j] += dp[i - 1][j + 1];
				} else if (j >= 2 && (mask >> (j - 2) & 1)) {
					dp[i][j] += dp[i - 1][j - 1];
				} else {
					dp[i][j] += dp[i - 1][j];
				}
				dp[i][j] %= mod;
			}
		}
	}
	print(dp[h][k]);
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
// const ll MOD=998244353;

int main(){
  int N; cin>>N;
  cout<<1LL*N*(N-1)/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    int N, ans=0;
    cin >> N;
    vector<ll> A(0);
    vector<ll> C(0);
    for (int i = 0; i < N ; ++i){
        ll r;
        std::cin >> r;
        A.push_back(r);
    }
        for (int i = 0; i < N; ++i){
        ll r;
        std::cin >> r;
        ans += r; 
    }
    for (int i = 0; i < N-1; ++i){
        ll r;
        std::cin >> r;
        C.push_back(r);
    }
    REP(i, N-1){
        if (A[i] + 1 == A[i+1]) ans += C[A[i]-1];
    }
    cout << ans;
 }




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

struct mint { // auto MOD int
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}  //コンストラクタ
  mint operator-() const { return mint(-x);} //符号変換
  //算術演算子
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  mint pow(ll t) const { //累乗
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(MOD-2); } // for prime mod
  //代入演算子
  mint& operator+=(const mint a) { if((x+=a.x) >= MOD) x-=MOD; return *this; }
  mint& operator-=(const mint a) { if((x+=MOD-a.x) >= MOD) x-=MOD; return *this; }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  friend ostream& operator<<(ostream &stout, const mint &ans){ //出力
    stout << ans.x;
    return stout;
  }
};

mint com(int n, int a){
  mint x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  return x/y;
}

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,a,b; cin >> n >> a >> b;
  mint ans = mint(2).pow(n);
  ans -= 1;
  ans -= com(n,a);
  ans -= com(n,b);
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3604
poll_table = {}

poll_times = int(input())

max_poll = 0

for i in range(poll_times):
  polled = input()
  if polled in poll_table.keys():
    poll_table[polled] += 1
  else:
    poll_table[polled] = 1

  if max_poll < poll_table[polled]:
    max_poll = poll_table[polled]

max_list = []
for key in poll_table.keys():
  if poll_table[key] == max_poll:
    max_list.append(key)

max_list.sort()

for polled in max_list:
  print(polled)

Measured memory_bytes: 32096
#include<stdio.h>

int main(){
  int n,a[100000],b[100000],i,j,k,cnt,max=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d %d",&a[i],&b[i]);
  for(i=n;i>=1;i--){
    cnt=0;
    for(j=0;j<n;j++){
      if(cnt+n-j<i)
        break;
      if(a[j]<=i+1&&b[j]>=i+1)
        cnt++;
    }
    if(cnt>=i){
      max=i;
      break;
    }
  }
  printf("%d\n",max);
}


Measured memory_bytes: 2576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long int n;
  cin >> n;
  int a = 0;
  int b = 0;
  for (int i = 0; i < n; i++) {
    long long int num;
    cin >> num;
    if (num%4==0){
      a++;
    }
    else if (num%2==0){
      b++;
    }
  }
 if (a+(b/2) >= n/2)
    cout<<"Yes";
  else
    cout<<"No";
 
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1e9+7;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
const int biggg = 1000000000;
const long eps = .0000000001;
int n;
pair<long long, int> arr[2000];
bool memoo[2000][2000];
long long memo[2000][2000];
long long func(int left, int right){
    int cur = left+right;
    if (cur >= n){
        return 0;
    }
    if (memoo[left][right]){
        return memo[left][right];
    }
    
    // put on left;
    long long res = arr[cur].first*abs(left-arr[cur].second)+func(left+1, right);
    res = max(res, arr[cur].first*abs(n-right-1-arr[cur].second)+func(left, right+1));
    memoo[left][right] = true;
    memo[left][right] = res;
    return res;
    
}
int main ()
{
  prep();
  cin >> n;
  for (int i=0; i<n; i++){
      cin >> arr[i].first;
      arr[i].second = i;
  }
  sort(arr, arr+n);
  reverse(arr, arr+n);
  cout << func(0, 0);
  return 0;
}


Measured memory_bytes: 30324
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N,M,par[MAXN];
vector<int> adjList[MAXN];

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>M;
	FOR(i,1,M){
		int u,v; cin>>u>>v;
		adjList[u].pb(v);
		adjList[v].pb(u);
	}
	memset(par,-1,sizeof par);
	
	queue<int> q; q.push(1);
	while (!q.empty()){
		int u=q.front();
		q.pop();
		for (auto v:adjList[u]){
			if (par[v] == -1) {
				par[v] = u;
				q.push(v);
			}
		}
	}
	
	bool ok = 1;
	FOR(i,2,N) if (par[i] == -1) ok=0;
	if (!ok) {
		cout<<"No";
		exit(0);
	}
	cout<<"Yes\n";
	FOR(i,2,N) cout<<par[i]<<"\n";
}


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

/*
enumerate non-bridge
*/

using pint=pair<int,int>;

struct EnumerateBridges{
	vector<vector<pint>>G;
	int N,M;

	vector<int>vis,ord,low;

	EnumerateBridges(int n):N(n),M(0),G(n),vis(n),ord(n),low(n){}

	void addEdge(int a,int b){
		G[a].emplace_back(b,M);
		G[b].emplace_back(a,M);
		M++;
	}

	void dfs(int v,int p,int &k,vector<int>&bridge){
		vis[v]=true;
		ord[v]=k;
		low[v]=ord[v];

		k++;
		
		for(auto &e:G[v]){
			int u,id;
			tie(u,id)=e;

			if(u==p)continue;

			if(!vis[u]){
				dfs(u,v,k,bridge);
				low[v]=min(low[v],low[u]);
				if(ord[v]<low[u])bridge.push_back(id);
			}
			else{
				low[v]=min(low[v],ord[u]);
			}
		}
	}

	vector<int>enumerate(){
		vector<int>bridge;
		int k=0;
		dfs(0,-1,k,bridge);
		return bridge;
	}
};

//O(M)
vector<int>enumerate(int N,vector<int>&A,vector<int>&B,vector<int>&used){
	int M=A.size();
	EnumerateBridges eb(N);
	for(int i=0;i<M;i++){
		if(used[i])continue;
		eb.addEdge(A[i],B[i]);
	}

	vector<int>nb(M,1);
	auto bs=eb.enumerate();
	for(auto k:bs)nb[k]=0;

	vector<int>ret;
	for(int i=0;i<M;i++)if(nb[i])ret.push_back(i);
	return ret;
}

/*
A[i]--B[i] i=1,2,...,M
C[i]--D[i] i=1,2,...,M
*/
int solve(int N,vector<int>&A,vector<int>&B,vector<int>&C,vector<int>&D){
	int M=A.size();
	for(int i=0;i<M;i++){
		A[i]--;B[i]--;C[i]--;D[i]--;
	}
	vector<int>used(M);

	while(true){

		auto src=enumerate(N,A,B,used);
		auto snk=enumerate(N,C,D,used);

		//exchange graph
		vector<vector<int>>EG(M);
		for(int i=0;i<M;i++){
			if(!used[i])continue;
			used[i]=false;

			auto listY1=enumerate(N,A,B,used);
			auto listY2=enumerate(N,C,D,used);
			for(auto j:listY1)EG[i].push_back(j);
			for(auto j:listY2)EG[j].push_back(i);

			used[i]=true;
		}
	}
}

int main(){
	int N,M;cin>>N>>M;
	vector<int>A(M),B(M);
	EnumerateBridges eb(N);
	for(int i=0;i<M;i++){
		cin>>A[i]>>B[i];
		eb.addEdge(A[i],B[i]);
		if(A[i]>B[i])swap(A[i],B[i]);
	}

	auto bs=eb.enumerate();
	vector<pint>ans;
	for(auto k:bs)ans.emplace_back(A[k],B[k]);
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++){
		cout<<ans[i].first<<" "<<ans[i].second<<endl;
	}
	return 0;
}


Measured memory_bytes: 5264
#include <stdio.h>

int main(void) {
   int a = 2;
   int N, r, x, tmp;

   scanf("%d", &N);
   if(N == EOF) {
      printf("error\n");
      return -1;
   }

   x = a * N;

   if(a<N) {
      tmp = a;
      a = N;
      N = tmp;
   }

   r = a % N;
   while(r!=0) {
      a = N;
      N = r;
      r = a % N;
   }

   printf("%d\n", x/N);

   return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;
const int MAXN = 2e6 + 5;

int p[MAXN];
//int main() {
//	long long n;
//	while (~scanf("%lld", &n)) {
//		printf("%lld\n", n * (n + 1) / 2); 
//	}
//	return 0;
//}

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1;i <= n; i++) 
		scanf("%d", p + i);
	sort(p + 1, p + n + 1);
	long long sum = 0;
	for (int i = 1; i <= min(n , k); i++) {
		sum += p[i];
	}
	printf("%lld\n", sum);
}

Measured memory_bytes: 3184
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
using namespace std;


int main()
{
    int a,b;
    cin>>a>>b;
    int z=b;
    while(a%b!=0)
    {
        z=a%b;
        a=b;
        b=z;
    }
    cout<<z<<endl;
}



Measured memory_bytes: 3108
#include <stdio.h>

void trace(int *A, int n){
	for(int i = 0; i < n; i++){
		if(i > 0) printf(" ");
		printf("%d", A[i]);
	}

	printf("\n");
}

int main(){
	int i, j, n, A[100];

	scanf("%d", &n);

	for(i = 0; i < n; i++)
		scanf("%d", A + i);

	// Selection Sort
	int count = 0;
	int minj;
	int t;

	for(i = 0; i < n; i++){
		minj = i;

		for(j = i+1; j < n; j++){
			if(A[j] < A[minj]){
				minj = j;
			}
		}

		if(minj != i){
			t = A[i];
			A[i] = A[minj];
			A[minj] = t;
			count++;
		}
	}

	trace(A, n);
	printf("%d\n", count);

	return 0;
}



Measured memory_bytes: 2080
#include<cstdio>  
#include<vector>  
#include<queue>  
#include<string>  
#include<map>  
#include<iostream>  
#include<cstring>  
#include<algorithm>  
using namespace std;  
typedef long long LL;  
const int INF = 0x7FFFFFFF;  
const int maxn = 1e5 + 10;  
   
#define MAX_W 100  
#define MAX_H 100  
char farm[MAX_W][MAX_H];  
int W, H;  
const int direction[4][2] = {  
  { -1, 0 },  
  { 1, 0 },  
  { 0, -1 },  
  { 0, 1 },  
};  
   
void dfs(int x, int y, char tree)  
{  
  farm[x][y] = 'x';  
  for (int i = 0; i < 4; ++i)  
  {  
    int nx = x + direction[i][0];  
    int ny = y + direction[i][1];  
    if (nx >= 0 && nx < W && ny >= 0 && ny < H && farm[nx][ny] == tree)  
    {  
      dfs(nx, ny, tree);  
    }  
  }  
}  
   
int main()  
{  
   
  while (cin >> H >> W, W > 0)  
  {  
    int res = 0;  
    int x, y;  
    for (y = 0; y < H; ++y)  
    {  
      for (x = 0; x < W; ++x)  
      {  
        cin >> farm[x][y];  
      }  
    }  
   
    for (y = 0; y < H; ++y)  
    {  
      for (x = 0; x < W; ++x)  
      {  
        if (farm[x][y] != 'x')  
        {  
          dfs(x, y, farm[x][y]);  
          ++res;  
        }  
      }  
    }  
    cout << res << endl;  
  }  
  return 0;  
} 

Measured memory_bytes: 3532
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

constexpr LL MOD = 1000000007;

constexpr int LIM = 200001;

LL fact[LIM];
LL fact_inv[LIM];

LL mod_pow(LL a, LL b) {
    if (b == 0) {
        return 1;
    }
    if (b == 1) {
        return a;
    }
    if (b % 2 == 0) {
        LL c = mod_pow(a, b/2);
        return (c * c) % MOD;
    }
    return a * mod_pow(a, b-1) % MOD;
}

LL mod_inv(LL a) {
    return mod_pow(a, MOD - 2);
}

LL comb(int n, int k) { return (fact[n] * fact_inv[k] % MOD) * fact_inv[n-k] % MOD; }

int main() {
    LL H, W, A, B;

    fact[0] = fact_inv[0] = 1;
    for (int j = 1; j < LIM; ++j) {
        fact[j] = fact[j-1] * j % MOD;
        fact_inv[j] = (fact_inv[j-1] * mod_inv(j)) % MOD;
    }

    cin >> H >> W >> A >> B;

    LL ans = 0;

    for (int j = B; j < W; ++j) {
        ans = ( ans + comb((H-A-1) + j, H-A-1) * comb(A-1 + (W-j-1), A-1) ) % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define Would
#define you
#define please

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

	int N, A[100];
	cin >> N;
	rep(i, N) cin >> A[i];
	sort(A, A + N);

	int a = 0, b = 0;
	rep(i, N) {
		if (i % 2) a += A[i];
		else b += A[i];
	}
	co(abs(a - b));
	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  ll X;
  cin >> X;
  ll Y;
  cin >> Y;
  ll Z;
  cin >> Z;
  
  cout << Z << ' ' << X << ' ' << Y << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

int main()
{
    lint n, m;
    scanf("%lld", &n);
    scanf("%lld", &m);

    std::vector<std::vector<lint>> a(n, std::vector<lint>(n, 0));
    std::vector<std::vector<lint>> b(m, std::vector<lint>(m, 0));

    for (int i = 0; i < n; ++i)
    {
        std::string s;
        std::cin >> s;
        for (int j = 0; j < n; ++j)
        {
            if (s[j] == '.')
                a[i][j] = 1;
        }
    }
    for (int i = 0; i < m; ++i)
    {
        std::string s;
        std::cin >> s;
        for (int j = 0; j < m; ++j)
        {
            if (s[j] == '.')
                b[i][j] = 1;
        }
    }

    for (int i = 0; i <= (n - m); ++i)
    {
        for (int j = 0; j <= (n - m); ++j)
        {
            lint ok = 1;
            for (int y = 0; y < m; ++y)
            {
                for (int x = 0; x < m; ++x)
                {
                    if (a[i + y][j + x] != b[y][x])
                    {
                        ok = 0;
                        break;
                    }
                }
                if (ok == 0)
                    break;
            }
            if (ok)
            {
                printf("Yes");
                return 0;
            }
        }
    }

    printf("No");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,t,i,x,y,a=(1<<29)*-1,b=1<<29;
  scanf("%d",&n);
  for(i=1;i<=n;i++){scanf("%d",&t);if(t>a){x=i;a=t;}if(t<b){y=i;b=t;}}
  printf("%d\n",n*2-1);
  if(-b>a){for(i=1;i<=n;i++)printf("%d %d\n",y,i);for(i=n;i>1;i--)printf("%d %d\n",i,i-1);return 0;}
  for(i=1;i<=n;i++)printf("%d %d\n",x,i);for(i=1;i<n;i++)printf("%d %d\n",i,i+1);
}


Measured memory_bytes: 1692
from itertools import accumulate

S = input()
T = input()
Q = int(input())
ABCD = [list(map(int, input().split())) for _ in range(Q)]

SL = [1 if s == "A" else 2 for s in S]
TL = [1 if t == "A" else 2 for t in T]

AcumS = [0] + list(accumulate(SL))
AcumT = [0] + list(accumulate(TL))

for a, b, c, d in ABCD:
    s = AcumS[b] - AcumS[a - 1]
    t = AcumT[d] - AcumT[c - 1]
    if (s - t) % 3 == 0:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 80768
#include<bits/stdc++.h>
using namespace std;
int n,m,has,k;
char arr[10][10],sim[10][10];
void reset()
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++) arr[i][j]=sim[i][j];
	}
}
void f(int a,int b)
{
	int t;
	for(int i=0;i<6;i++)
	{
		t=1<<i;
		if(a&t)
		{
			for(int j=0;j<m;j++) arr[i][j]='*';
		}
	}
	for(int i=0;i<6;i++)
	{
		t=1<<i;
		if(b&t)
		{
			for(int j=0;j<n;j++) arr[j][i]='*';
		}
	}
	int now=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++) if(arr[i][j]=='#') now++;
	}
	if(now==k) has++;
}
int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++) cin>>arr[i][j],sim[i][j]=arr[i][j];
	}
	for(int i=0;i<pow(2,n);i++)
	{
		for(int j=0;j<pow(2,m);j++)
		{
			f(i,j);
			reset();
		}
	}
	cout<<has<<endl;
}

Measured memory_bytes: 4020
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	K, S := ReadInt(), ReadInt()
	c := 0
	for x := 0; x <= K; x++ {
		for y := 0; y <= K; y++ {
			z := S - x - y
			if 0 <= z && z <= K {
				c++
			}
		}
	}
	fmt.Println(c)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1852
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }

    if a >= 0 && c >= 0 {
        println!("{}", b * d);
    } else if b <= 0 && d <= 0 {
        println!("{}", a * c);
    } else {
        println!("{}", (a * c).max((a * d).max((b * c).max(b * d))));
    }
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int a, b; scanf("%d%d", &a, &b);
	
	printf("%d\n", std::max(0, a - 2 * b));
	return 0;
}


Measured memory_bytes: 764
import itertools

N, M, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(Q)]
data = list(range(1, M + 1))
L = list(itertools.combinations_with_replacement(data, N))
ans = 0
for l in L:
    tmp = 0
    for a, b, c, d in X:
        if l[b - 1] - l[a - 1] == c:
            tmp += d
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 84416
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
#define ALL(a) a.begin(),a.end()
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
 
int main(){
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	int ans = 0;
	if (a+b > c*2){
		ans += min(x, y) * c * 2;
		if (x > y){
			ans += min((x - y) * c * 2, (x - y) * a); 
		}else{
			ans += min((y - x) * c * 2, (y - x) * b);
		}
	}else{
		ans += x * a + y * b;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
	int x;
	int ans = 0;
	for(int i = 0; i < 5; i++){
		cin >> x;
		if(x != i+1) ans = i+1;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	ll a;
	string s;
	cin>>a>>s;
	ll b = (s[0]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0')*1;
	cout << a*b / 100 <<endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>  
using namespace std;  
int main(){  
    char cha,chb;  
    cin>>cha>>chb;  
    if(cha=='9') cout<<"Yes"<<endl;  
    else if(chb=='9') cout<<"Yes"<<endl;  
    else cout<<"No"<<endl;  
}  


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			int n=in.nextInt();
			if(n==0)break;
			double s[]=new double[n], ave=0;
			
			for(int i=0;i<n;i++) {
				s[i]=Integer.parseInt(in.next());
				ave+=s[i];
			}
			ave/=n;
			double dev=0;
			for(int i=0;i<n;i++)dev+=Math.pow(s[i]-ave, 2);
			dev=Math.sqrt(dev/n);
			out.printf("%f\n",dev);
		}
		out.flush();
	}
}



Measured memory_bytes: 30864
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i=0;i<n;i++)cin >> a.at(i);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  long long ans = 0;
  list<int> s;
  s.push_front(a.at(0));
  for(int i=1;i<n;i++){
    ans += s.back();
    s.pop_back();
    s.push_front(a.at(i));
    s.push_front(a.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 11168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>
#define int long long 

char c;
signed main(){
    cin>>c;
    int num=c-'a';
    num++;
    cout<<(char)('a'+num)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long func(long long x){
long long count=0;
  while(x%2!=1){
    count++;
  x/=2; 
  }
  return count;
}
int main(){
int N;
  cin>>N;
  vector<long long> a(N);
  for(int i=0;i<N;i++)
    cin>>a.at(i);
  long long min=func(a.at(0));
  for(int i=0;i<N;i++){
    if(min>func(a.at(i)))
      min=func(a.at(i));
  }
  cout<<min<<endl;
}

Measured memory_bytes: 3600
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll X,K,D;
    cin >> X >> K >> D;
    if(X > 0){
        ll num = X / D;
        if(K < num){
            print(X - D*K);
        }else{
            ll v1 = X % D, v2 = D - v1;
            ll amari = K - num;
            if(amari % 2 == 0){
                print(v1);
            }else{
                print(v2);
            }
        }

    }else if(X < 0){
        ll num = (-X) / D;
        if(K < num){
            print(abs(X + D*K));
        }else{
            ll v1 = (-X) % D, v2 = D - v1;
            ll amari = K - num;
            if(amari % 2 == 0){
                print(v1);
            }else{
                print(v2);
            }
        }
    }else{
        if(K % 2 == 0){
            print(0);
        }else{
            print(D);
        }
    }


}

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

Measured memory_bytes: 3616
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
mod = 10**9 + 7

# n = int(input())
# a = list(map(int, input().split()))
def fac(n):
    a = n
    t = 1
    while a > 0:
        t *= a
        t %= mod
        a -= 1
    return t


def C(n,r):
    return (fac(n) * pow(fac(r),mod-2,mod) * pow(fac(n-r),mod-2,mod) )%mod

x,y = map(int,input().split())

ans = 0

if (x+y)%3==0 and max(x,y)-min(x,y)<=min(x,y):
    diff = max(x,y)-min(x,y)
    total = (x+y)//3
    ans = C(total,(total-diff)//2)

print(ans)

Measured memory_bytes: 38512