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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << endl;
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

void solve(){
    long int n,m,k;
    cin>>n>>m>>k;
    char c[n][m];
    for(long int i=0;i<n;i++){
        for(long int j=0;j<m;j++)
            cin>>c[i][j];
    }
    long int ans=0;
    for(ll bI=0;bI<(1<<n);bI++){
        for(ll bJ=0;bJ<(1<<m);bJ++){
            long int xx=0;
            for(long int i=0;i<n;i++){
                for(long int j=0;j<m;j++){
                    if((1<<i)&bI){
                        if((1<<j)&bJ){
                            if(c[i][j]=='#')
                                xx++;
                        }
                    }
                }
            }
            if(xx==k)
                ans++;
        }
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll n; cin >> n;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];
  map<ll,ll> x;
  rep(i,n) x[i-h[i]]++;
  ll ans=0;
  rep(i,n) ans+=x[i+h[i]];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27400
from collections import Counter
n = int(input())
if n == 1:
  print(1)
else:
  XY = tuple(tuple(map(int, input().split())) for _ in range(n))
  L = []
  for i in range(n-1):
    for j in range(i+1, n):
      x1, y1 = XY[i]
      x2, y2 = XY[j]
      L.append((x1-x2, y1-y2))
      L.append((x2-x1, y2-y1))
  C = Counter(L)
  ans = n - C.most_common()[0][1]
  print(ans)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int a,b;cin>>a>>b;
    ll int gcdval = __gcd(a,b);
    ll ans = (a*b)/gcdval;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <iostream>
#include <fstream>

using namespace std;

const int DIV = 1000000007;

void solve(int test, istream &in) {
    int k;
    in >> k;
    std::string s;
    for (int i = 0; i < k; i++) {
        s += "ACL";
    }
    printf("%s\n", s.c_str());
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
	//FILE *f = fopen("in.txt", "r");
    ifstream f("in.txt");
#else
	//FILE *f = stdin;
    istream &f = cin;
#endif
    int tests = 1;
    //f >> tests;
    for (int test = 0; test < tests; test++) {
        solve(test, f);
    }
	return 0;
}



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

#define ll long long
#define pb push_back
#define mp make_pair

#define INF (ll)9e17+3

const int MAXN = 4e3+5;

vector<ll> T;
ll dp[MAXN][MAXN];

ll suma(int left, int right) {
	ll s = 0;
	for(int i=left; i<= right; i++)
		s += T[i];
	return s;
}

ll res(int left, int right) {
	if (left == right)
		return 0;
	if(dp[left][right] != 0)
		return dp[left][right];
	dp[left][right] = INF;
	for(int i=left; i<= right; i++)
		dp[left][right] = min(dp[left][right], res(left, i) + res(i+1, right) + suma(left, right));
	return dp[left][right];
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
		int n;	cin >> n;
	for(int i=0; i<n; i++)	{
		ll x;	cin >> x;
		T.pb(x);
	}
	cout << res(0, n-1);
}


Measured memory_bytes: 13056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
 
int main(){
    ll N, K;
    cin >> N >> K;
    bool flag = false;
    vector<vector<ll>> G(N,vector<ll>(N,1));
    ll MM = 0;
    REP(i,1,N-1){
        MM += i;
    }
    if(K > MM){
        cout << -1 << endl;
        return 0;
    }
    rep(i,N){
        G[i][i] = 0;
    }
    ll cnt = 0;
    rep(i,N){
        REP(j,i+1,N-1){
            if(cnt == K){
                flag = true;
                break;
            }
            G[i][j] = 0;
            G[j][i] = 0;
            cnt++;
        }
        if(flag) break;
    }
    cout << (N*(N-1))/2 - K << endl;
    rep(i,N){
        REP(j,i+1,N){
            if(G[i][j]==0)continue;
            cout << i+1 <<" "<< j+1 << endl;
        }
    }
    /*
    ll s,t;
    REP(i,1,N){
        if(2*K == i*(i-1) + (N-i)*(N-i-1)){
            flag = true;
            s = i;
            t = N - i;
            break;
        }
    }
    if(K < N-1){
        flag = true;
    }
    if(!flag){
        cout << -1 << endl;
        return 0;
    }
    if(K >= N-1){
        cout << s*t << endl;
        REP(i,1,s+1){
            REP(j,s+1,N+1){
                cout << i << " " << j << endl;
            }
        }
    }else{
        cout << N*(N-1)/2 - K << endl;
        REP(i,1,N+1){
            REP(j,i+1,N+1){
                if(i == 1 && i > K) continue;
                cout << i << " " << j << endl;
            }
        }
    }*/
}

Measured memory_bytes: 3660
N, M = map(int, input().split())

arr = []
for i in range(N):
    a, b = map(int, input().split())
    arr.append([a,b])

arr = sorted(arr)

sum_count = 0
ans = 0
for i in range(N):
    sum_count += arr[i][1]
    ans += arr[i][1]*arr[i][0]
    if sum_count > M:
        sum_count -= arr[i][1]
        ans -= arr[i][1]*arr[i][0]
        ans += (M-sum_count) *arr[i][0]
        break
    else:
        pass

print(ans)

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

char c[8][8];
int cnt_h[8];
int cnt_w[8];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w, k;
    cin >> h >> w >> k;
    rep(i, h) rep(j, w) cin >> c[i][j];

    int cnt_black = 0;
    rep(i, h) rep(j, w) if (c[i][j] == '#') cnt_black++;

    int ans = 0;
    rep(bit_h, 1 << h) {
        rep(bit_w, 1 << w) {
            vector<vector<bool>> checked(h, vector<bool>(w, false));
            int minus = 0;
            rep(i, h) rep(j, w) {
                if (bit_h & (1 << i)) {
                    rep(x, w) {
                        if (c[i][x] == '#' and !checked[i][x]) {
                            minus++;
                            checked[i][x] = true;
                        }
                    }
                }
                if (bit_w & (1 << j)) {
                    rep(x, h) {
                        if (c[x][j] == '#' and !checked[x][j]) {
                            minus++;
                            checked[x][j] = true;
                        }
                    }
                }
            }
            if (cnt_black - minus == k) ans++;
        }
    }
    out(ans);
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	string S; cin >> S; 
	for(int i = 0; i < S.size(); i++){
		if(S.at(i) == '?') cout << 'D'; 
		else cout << S.at(i); 
	}
	cout << endl; 
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
#define int long long
#define rep(i,m,n) for(int i=m;i<n;i++)
#define repr(i,n,m) for(int i=n;i>=m ;i--)
#define MOD 1000000007
#define float long double
#define pb push_back
#define mp make_pair
#define pp pop_back
#define pi 3.141592653589793238
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
bool sortbysec(const pair<int,int> &a,
             const pair<int,int> &b)
{
   return (a.second < b.second);
}
int lcm(int a, int b)  
 {  
    return (a*b)/__gcd(a, b);  
 }  
bool sortinrev(const pair<int,int> &a,  
              const pair<int,int> &b)
{
      return (a.first > b.first);
}
void solve()
{
	int n,k,total=0;
	cin>>n>>k;
	map<int,int>mp1;
	rep(i,0,k)
	{
		int a;
		cin>>a;
		rep(i,0,a)
		{
			int b;
			cin>>b;
			mp1[b]++;
		}
	}rep(i,1,n+1)
	if(mp1[i]==0)
		total++;
	cout<<total;
}    
signed main()
{
                     // #ifndef ONLINE_JUDGE
                     // freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
                     // #endif 
  int t=1;
 //cin>>t;
  while(t--){
  solve();
}
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
 return 0;
}  


Measured memory_bytes: 3784
import java.util.Scanner;

public class Main{
  static int n;
  static long[] a;

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

    n = sc.nextInt();
    a = new long[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextLong();
    }

    long k = 0;
    while(true){
      long sum = 0;
      for(int i = 0; i < n; i++){
        sum += a[i] / n;
      }
      for(int i = 0; i < n; i++){
        a[i] = a[i] - (a[i] / n) * n + (sum - a[i] / n);
      }
      boolean check = true;
      for(int i = 0; i < n; i++){
        if(a[i] >= n){
          check = false;
          break;
        }
      }
      k += sum;
      if(check){
        break;
      }
    }

    System.out.println(k);
  }
}

Measured memory_bytes: 23892
#include<iostream>
using namespace std;
int main() {
	int x,y; cin >> x >> y;
	//a+b=x
	//4a+2b=y
	//2a=y-2x
	int a=(y-2*x)/2;
	if(y>=2*x && ((y-2*x)&1)==0 && a<=x) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}


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

using namespace std;

typedef pair<int, int> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<P> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += abs(i - a[i].second) % 2;
    }
    cout << ans / 2 << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define modulo 998244353
#define endl '\n'
#define pb push_back
using namespace std;
vector <int> adj[100001];
ll fxp(ll a, ll b)
{
    if(b == 0)return 1;
	if(b%2 == 0){
		ll c = fxp(a,b/2);
		return (c*c)%1000000007;
	}
	return (a*fxp(a,b-1))%1000000007;
}
int lcm(int c,int d)
{
    int a=c;
    int b=d;
    int ans;
    if(a>=b)
    {
        while(b!=0)
        { 
            int x=b;
            b=a%b;
            a=x;
        }
        ans = ( c*d)/a;
    }
    else
    {
        while(a!=0)
        {
            int x=a;
            a=b%a;
            b=x;
        }
        ans = ( c*d)/b;  
    }
    return ans;
}
int root_find()
{
    ll x;
    for(int i=1;i<100001;i++)
    {
        if(adj[i].size()==1)
        {
            x = i;
            break;
        }
    }
    return x;
}
void dfs(int s,int y)
{
    for(int i=0;i<adj[s].size();i++)
    {
        if(adj[s][i]==y)
        continue;
        dfs(adj[s][i],s);
    }
}
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
ll smallestDivisor(ll n) 
{ 
    // if divisible by 2 
    if (n % 2 == 0) 
        return n/2; 
  
    // iterate from 3 to sqrt(n) 
    for (int i = 3; i * i <= n; i += 2) { 
        if (n % i == 0) 
            return n/i; 
    } 
  
    return n; 
}  
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    char ch;
    cin>>ch;
    if(ch>=65 && ch<=90)
    cout<<'A'<<endl;
    else
    {
        cout<<'a'<<endl;
    }
    
    return 0;
}

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

int main() {
  int a,b;
  string s;
  
  cin>>a>>b;
  cin>>s;
  
  string answer="Yes";
  
  for (int i=0;i<a+b+1;i++){
    if (i==a){
      if (s.at(i)!='-'){
        answer="No";
        break;
      }
    }
    
    else if (s.at(i)!='0' and s.at(i)!='1' and s.at(i)!='2' and s.at(i)!='3' and s.at(i)!='4' and s.at(i)!='5' and s.at(i)!='6' and s.at(i)!='7' and s.at(i)!='8' and s.at(i)!='9'){
      answer="No";
      break;
    }
  }
  
  cout<<answer<<endl;
  
  

  
  
}

  













Measured memory_bytes: 256
n, m = map(int, input().split())
count = dict(zip(range(1, m+1), [0]*m))
for _ in range(n):
    ka = list(map(int, input().split()))
    for a in ka[1:]:
        count[a] += 1

ans = sum([1 for k, v in count.items() if v == n])
print(ans)


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

int main() {
    int N,M;
    cin >> N;
    M = N;

    int S = 0;
    int s;

    for (int i = 9; i > -1; i--) {
        s = (int)(M/pow(10,i));
        S = S + s;
        M = M - s * pow(10,i);
    }

    if (N%S == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main(){
	int t,n;
	for(int i=0;i<4;i++){
	cin >> t >> n;
	int re;
	if(t==1){
	re=6000*n;
	}else if(t==2){
	re=4000*n;
	}else if(t==3){
	re=3000*n;
	}else if(t==4){
	re=2000*n;
	}
	cout<< re << "\n";
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <vector>
#include <algorithm>


using namespace std;

int* heap_index;

struct Info{
	Info(){
		id=0;
		score = 0;
	}
	Info(int arg_id,int arg_score){
		id = arg_id;
		score = arg_score;
	}
	int id,score;
};

class InfoPQ{
public:
	InfoPQ(int arg_n){
		array = new Info[arg_n];
		n = 0;
	}

	void push(Info arg_info){
		array[n] = arg_info;
		int tmp = n;
		while(tmp != 0 && array[tmp].id < array[(tmp-1)/2].id){
			std::swap(array[tmp], array[(tmp-1)/2]);
			tmp = (tmp-1)/2;
		}
		n++;
	}

	void writeHeapIndex(){
		for(int i=0;i<n;i++){
			heap_index[array[i].id] = i;
		}
	}

	void printTop(){
		printf("%d %d\n",array[0].id,array[0].score);
	}

	void update(int update_id,int div){

		array[heap_index[update_id]].score += div;
		int tmp = heap_index[update_id];

		if(div > 0){
			while(tmp != 0 && ((array[tmp].score > array[(tmp-1)/2].score) || (array[tmp].score ==array[(tmp-1)/2].score && array[tmp].id < array[(tmp-1)/2].id))){
				std::swap(heap_index[array[tmp].id],heap_index[array[(tmp-1)/2].id]);
				std::swap(array[tmp], array[(tmp-1)/2]);
				tmp = (tmp-1)/2;
			}
		}else{
			while(2*tmp+1 <= n-1){
				if(2*tmp+2 <= n-1){
					if(((array[2*tmp+2].score > array[tmp].score) || (array[2*tmp+2].score == array[tmp].score && array[2*tmp+2].id < array[tmp].id)) &&
							((array[2*tmp+2].score > array[2*tmp+1].score) || (array[2*tmp+2].score == array[2*tmp+1].score && array[2*tmp+2].id < array[2*tmp+1].id))){
						std::swap(heap_index[array[tmp].id],heap_index[array[2*tmp+2].id]);
						std::swap(array[2*tmp+2],array[tmp]);
						tmp = 2*tmp+2;
					}else if(((array[2*tmp+1].score > array[tmp].score) || (array[2*tmp+1].score == array[tmp].score && array[2*tmp+1].id < array[tmp].id)) &&
							((array[2*tmp+1].score > array[2*tmp+2].score) || (array[2*tmp+1].score == array[2*tmp+2].score && array[2*tmp+1].id < array[2*tmp+2].id))){
						std::swap(heap_index[array[tmp].id],heap_index[array[2*tmp+1].id]);
						std::swap(array[2*tmp+1],array[tmp]);
						tmp = 2*tmp+1;
					}else{
						break;
					}
				}else{
					if((array[2*tmp+1].score > array[tmp].score) || (array[2*tmp+1].score == array[tmp].score && array[2*tmp+1].id < array[tmp].id)){
						std::swap(heap_index[array[tmp].id],heap_index[array[2*tmp+1].id]);
						std::swap(array[tmp],array[2*tmp+1]);
						tmp = 2*tmp+1;
					}else{
						break;
					}
				}
			}
		}
	}

private:
	Info* array;
	int n;
};



int main(){
	int n,q,id,div;

	scanf("%d %d",&n,&q);

	InfoPQ Q(n);
	heap_index = new int[n+1];

	for(int i = 0; i < n; i++)Q.push(Info(i+1,0));

	Q.writeHeapIndex();

	for(int i = 0; i < q; i++){
		scanf("%d %d",&id,&div);
		Q.update(id,div);
		Q.printTop();
	}

    return 0;
}

Measured memory_bytes: 14476
H, W, K = gets.split.map(&:to_i)
A = H.times.map { gets.chomp.chars }

sy = -1
sx = -1

A.each_with_index do |row, y|
  row.each_with_index do |c, x|
    next if c != 'S'

    sy = y
    sx = x
  end
end

queue = []
queue << [sy, sx, 0]

DY = [-1, 0, 1, 0]
DX = [0, 1, 0, -1]

visited = Hash.new { |h, k| h[k] = Hash.new }
min_dist = Float::INFINITY

until queue.empty?
  y, x, dist = queue.shift

  next if dist > K
  next if visited[y][x]
  visited[y][x] = true

  min_dist = y if min_dist > y
  min_dist = x if min_dist > x

  down_dist = (H - 1) - y
  right_dist = (W - 1) - x
  min_dist = down_dist if min_dist > down_dist
  min_dist = right_dist if min_dist > right_dist

  DY.zip(DX) do |dy, dx|
    ny = y + dy
    nx = x + dx

    next if ny < 0 || nx < 0 || H <= ny || W <= nx
    next if A[ny][nx] == '#'

    queue << [ny, nx, dist + 1]
  end
end

if min_dist == 0
  puts 1
else
  puts 1 + Rational(min_dist, K).ceil
end


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

int main() {
    int n; cin >> n;
    int a[105];
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<=n;i++) {
        int tmp = a[i];
        int j = i;
        for( ;j>=2 && a[j-1]>=tmp;j--)
            a[j] = a[j-1];
        a[j] = tmp;
        for(int k=1;k<n;k++) cout << a[k] << " ";
        cout << a[n] <<endl;
    }
    return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

vector<vector<int> > map;
vector<vector<bool> > reach;
int w,h;

void dfs(int i, int j){
    if((reach[i][j]) or (map[i][j]==0))
        return;
    reach[i][j] = true;
    if(0<i && 0<j) dfs(i-1,j-1);
    if(0<i) dfs(i-1,j);
    if(0<i && j<w-1) dfs(i-1,j+1);
    if(0<j) dfs(i, j-1);
    if(j<w-1) dfs(i, j+1);
    if(i<h-1 && 0<j) dfs(i+1,j-1);
    if(i<h-1) dfs(i+1,j);
    if(i<h-1 && j<w-1) dfs(i+1,j+1);
}

int main(){

    while((cin >> w >> h) && (w>0 && h>0)){
        int res=0;
        for (int i = 0; i < h; i++) {
            vector<int> temp(w,0);
            for (int j = 0; j < w; j++)
                cin >> temp[j];
            map.push_back(temp);
        }
        for (int i = 0; i < h; i++){
            vector<bool> temp(w,false);
            reach.push_back(temp);
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if(map[i][j]==1 && !reach[i][j]){
                    res++;
                    dfs(i,j);
                }
            }
        }
        cout << res << endl;
        map.clear();
        reach.clear();

    }
    return 0;
}

Measured memory_bytes: 1424
#include <iostream>
#include <algorithm>
#include <cctype>
#include <string>
using namespace std;
 
string oom, mes;
 
 
void rJ() {
  const string tmp = mes;
  mes = tmp[tmp.length()-1] + tmp.substr(0, tmp.length()-1);
}
void rC() {
  const string tmp = mes;
  mes = tmp.substr(1) + tmp[0];
}
void rE() {
  string l = mes.substr(0, mes.length()/2);
  string r = mes.substr((mes.length()+1)/2);
  if(mes.length() % 2 != 0) {
    mes = r + mes[mes.length()/2] + l;
  } else {
    mes = r + l;
  }
}
void rA() {
  reverse(mes.begin(), mes.end());
}
 
void rP() {
  for(int i = 0; i < mes.length(); ++i) {
    if(isdigit(mes[i])) {
      mes[i] = (mes[i]-'0'+9)%10+'0';
    }
  }
}
void rM() {
  for(int i = 0; i < mes.length(); ++i) {
    if(isdigit(mes[i])) {
      mes[i] = (mes[i]-'0'+1)%10+'0';
    }
  }
}
 
void solve() {
  reverse(oom.begin(), oom.end());
  for(int i = 0; i < oom.length(); ++i) {
    switch(oom[i]) {
    case 'J': rJ(); break;
    case 'C': rC(); break;
    case 'E': rE(); break;
    case 'A': rA(); break;
    case 'P': rP(); break;
    case 'M': rM(); break;
    }
  }
  cout << mes << endl;
}
 
main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> oom;
    cin >> mes;
    solve();
  }
}

Measured memory_bytes: 1208
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX 1400

int dp[MAX][MAX], G[MAX][MAX];

int getLargestSquare(int H, int W){
	int maxWidth = 0;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			dp[i][j] = (G[i][j] + 1) % 2;
			maxWidth |= dp[i][j];
		}
	}

	for(int i = 1; i < H; i++){
		for(int j = 1; j < W; j++){
			if(G[i][j]){
				dp[i][j] = 0;
			}else{
				dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
				maxWidth = max(maxWidth, dp[i][j]);
			}
		}
	}

	return maxWidth * maxWidth;
}

int main(void){
	int H, W;
	scanf("%d %d", &H, &W);

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++)scanf("%d", &G[i][j]);
	}

	printf("%d\n", getLargestSquare(H, W));

	return 0;
}

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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int n_close_max = 0;
    int n_close_net = 0;
    int n_close = 0;
    for (auto c : S){
        if (c == ')'){
            ++n_close;
            ++n_close_net;
            n_close_max = max(n_close_max, n_close_net);
        }else{
            --n_close_net;
        }
    }
    // n_open = N - n_close
    // n_open_head = n_close_max
    // n_open_head + n_open = n_close + n_close_tail
    int n_close_tail = n_close_max + N - 2 * n_close;
    cout << string(n_close_max, '(') << S << string(n_close_tail, ')') << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)


int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	ll a[n] ,b[m]; 
	rep(i, n) {
		cin >> a[i];

	}
	ll b_total = 0;
	rep(i, m) {
		cin >> b[i];
		b_total += b[i];
	}

	ll ans = 0;

	ll b_cur = m;

	ll a_total = 0;

	while(b_cur >= 0 && a_total + b_total > k) {
		b_cur--;
		if (b_cur >= 0) b_total -= b[b_cur];
	}

	if (a_total + b_total <= k) {
		ans = b_cur; 
	}

	//cout << "ans0:" << ans << endl;
	//cout << "b_cur:" << b_cur << endl;

	rep(i,n) {
		a_total += a[i];

		while(b_cur >= 0 && a_total + b_total > k) {
			b_cur--;
			if (b_cur >= 0) b_total -= b[b_cur];
		}

		if (a_total + b_total <= k && b_cur >= 0) {
			ans = max(ans, i + 1 + b_cur); 
		}

	}
	cout << ans << endl;




	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll n, u, v;
  cin>>n;
  ll ans=0;
  FOR(i, 1, n+1){
    ans+=(n-i+1)*i;
  }
  REP(i, n-1){
    cin>>u>>v;
    --u;--v;
    if(u>v){
      swap(u, v);
    }
    ans-=(u+1)*(n-v);
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 3656
package main

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

func main() {
	var n int
	s := bufio.NewScanner(bufio.NewReader(os.Stdin))
	s.Split(bufio.ScanWords)

	s.Scan()
	n, _ = strconv.Atoi(s.Text())
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n)

	for i := 0; i < n; i++ {
		s.Scan()
		a[i], _ = strconv.Atoi(s.Text())
		s.Scan()
		b[i], _ = strconv.Atoi(s.Text())
		s.Scan()
		c[i], _ = strconv.Atoi(s.Text())
	}

	fmt.Println(solve(n, a, b, c))
}

func solve(n int, a, b, c []int) int {
	x, y, z := 0, 0, 0

	for i := 0; i < n; i++ {
		x, y, z = max(y, z)+a[i], max(x, z)+b[i], max(x, y)+c[i]
	}

	return max(x, max(y, z))
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 4608
import collections
N = int(input())
S = input()
minus = 0
for i in range(0, N):
    for j in range(1, N):
        if i+j*2 >= N:
            break
        if S[i] != S[i+j]:
            if S[i] != S[i+j*2]:
                if S[i+j] != S[i+j*2]:
                    minus += 1

count_dict = collections.Counter(S)

# if "R" in count_dict and "G" in count_dict and "B" in count_dict:
print(count_dict["R"]*count_dict["G"]*count_dict["B"]-minus)

Measured memory_bytes: 9352
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;

int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll a,  b ;
    cin >> a >> b ;
    cout << max({a + b , a - b , a * b}) << endl;
    
    return (0) ;
}

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

using namespace std;

typedef long long ll;

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

    queue<long long> que;
    for (int i = 1; i <= 9; i++)
        que.push(i);

    while (1) {
        ll l = que.size();
        if (k <= l) {
            for (int i = 0; i < k-1; i++)
                que.pop();
            cout << que.front() << endl;
            return 0;
        }
        for (int i = 0; i < l; i++) {
            ll x = que.front();
            que.pop();
            ll y = x%10;
            if (y == 0) {
                que.push(x*10);
                que.push(x*10+1);
            }
            else if (y == 9) {
                que.push(x*10+8);
                que.push(x*10+9);
            }
            else {
                que.push(x*10 + y-1);
                que.push(x*10+y);
                que.push(x*10+y+1);
            }
        }
        k -= l;
    }
}

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

using namespace std;

int main(){
  long long int  H, W;
  cin >> H >> W;
  //川の字に割る
  long long int ans = 99999999999;
  long long int tmp = 99999999999;

  if(H % 3 == 0){
    ans = 0;
  }else{
    tmp = W;
  }
  
  if(W % 3 == 0){
    ans = 0;
  }else{
    tmp = min(tmp,H);
  }
  
  
  
  //Tの字に割る
    for(int i = 1; i <= H-1; i++){
      vector<long long int> s(3);
      long long int tmpmax = -1LL;
      long long int tmpmin = 9999999999;
      s[0] = W*i;
      s[1] = W/2 * (H-i);
      s[2] = (W - W/2) * (H-i);
      for(int i = 0; i < 3; i++){
        tmpmax = max(tmpmax,s[i]);
        tmpmin = min(tmpmin,s[i]);
      }
    tmp = min(tmp, tmpmax-tmpmin);
    }
    for(int i = 1; i <= W-1; i++){
      vector<long long int> s(3);
      long long int tmpmax = -1LL;
      long long int tmpmin = 9999999999;
      s[0] = H*i;
      s[1] = H/2 * (W-i);
      s[2] = (H - H/2) * (W-i);
      for(int i = 0; i < 3; i++){
        tmpmax = max(tmpmax,s[i]);
        tmpmin = min(tmpmin,s[i]);
      }
      tmp = min(tmp, tmpmax-tmpmin);
    }
  cout << min(ans, tmp);
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int P = 998244353;
const int MAX = 500100;
int mul(int a,int b){
  return a * b % P;
}
void add(int &a,int b){
  a += b;
  if(a >= P)
    a -= P;
}
void sub(int &a,int b){
  a -= b;
  if(a < 0){
    a += P;
  }
}
int pot(int a,int w){
  int r = 1;
  while(w){
    if(w & 1){
      r = r * a % P;
    }
    w/=2;
    a = a * a % P;
  }
  return r;
}
int n,m,sil[MAX],odw[MAX];
int dwu(int a,int b){
  return mul(sil[a], mul(odw[b],odw[a-b]));
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  sil[0] = 1;
  R(i,MAX-1){
    sil[i+1] = mul(sil[i], i + 1);
  }
  R(i,MAX){
    odw[i] = pot(sil[i], P-2);
  }
  cin >> n >> m;
  int res = 0;
  R(i,min(n,m)+1){
    int ak = mul(dwu(n,i), dwu(m,i));
    ak = mul(ak, sil[i]);
    ak = mul(ak, pot(n+1,m-i));
    ak = mul(ak, pot(m+1,n-i));
    if(i & 1){
      sub(res,ak);
    }else{
      add(res,ak);
    }
  }
  cout << res << "\n";
}


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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

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

const ll mod = 1e9+7;
ll get(int l,int r,vector<ll> &A){
	ll res = A[r];
	if(l-1 >= 0)res -= A[l-1];
	return res;
}
ll mul(ll a,ll b){
	ll res = ((a%mod)*(b%mod))%mod;
	return res;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N; cin >> N;
	vector<ll> A(N);
	vector<ll> ac(N);
	forn(i,0,N){
		cin >> A[i];
		ac[i] = A[i];
		if(i)ac[i] += ac[i-1];
	}
	ll res = 0;
	forn(i,0,N-1){
		ll sum = get(i+1,N-1,ac);
		//debug(i+1,N-1,A[i],sum);
		res += mul(A[i],sum);
		res %= mod;
	}
	if(res < 0)res += mod;
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define mp make_pair
#define pb  push_back
#define ALL(_a)   _a.begin(), _a.end()
#define PI acos(-1.0)
#define MAX 200005
#define MOD 1000000007
#define nl '\n'
#define pqmin(x) priority_queue<x, vector<x>, greater<x>>
#define pqmax(x) priority_queue<x>
#define testCase(x) int x; cin>>x; for(int tc=1;tc<=x;tc++)
//#define int ll
void c_p_c() {
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
//............................................................
//   A'udhu Billaahi min ash-shaitwanir rajeem
//       Bismillah-ir Rahman-ir Raheem
//           Rabbi zidnee 'ilmaa
//............................................................
void solve() {
   int n, m; cin >> n >> m;
   int a[n + 1], b[n + 1] = {0}, c[n + 1] = {0};
   for (int i = 1; i <= n; i++) cin >> a[i];
   int x[m + 1], y[m + 1], cnt = 0;
   for (int i = 1; i <= m; i++) {
      cin >> x[i] >> y[i];
      b[x[i]]++;
      b[y[i]]++;
      if (a[x[i]] > a[y[i]])c[x[i]]++;
      if (a[x[i]] < a[y[i]]) c[y[i]]++;
   }
   for (int i = 1; i <= n; i++) {
      if (c[i] == b[i] || b[i] == 0)cnt++;
   }
   cout << cnt  << nl;
}
int32_t main() {
   c_p_c();
   //testCase(t)
   solve();
   return 0;
}


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

using namespace std;
typedef long long ll;

typedef pair<int, int> P;

int dp[3001][3001];
P pre[3001][3001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string s, t;
    cin >> s >> t;
    int len = 0;
    P fin = P(0, 0);
    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j < t.size(); j++){
            if(s[i] == t[j]){
                if(dp[i][j]+1 > dp[i+1][j] && dp[i][j]+1 > dp[i][j+1]){
                    dp[i+1][j+1] = dp[i][j]+1;
                    pre[i+1][j+1] = P(i, j);
                    if(len < dp[i+1][j+1]){
                        fin = P(i, j);
                        len = dp[i+1][j+1];
                    }
                }else if(dp[i][j+1] > dp[i+1][j]){
                    dp[i+1][j+1] = dp[i][j+1];
                    pre[i+1][j+1] = P(i, j+1);
                }else{
                    dp[i+1][j+1] = dp[i+1][j];
                    pre[i+1][j+1] = P(i+1, j);
                }
            }else{
                if(dp[i][j+1] > dp[i+1][j]){
                    dp[i+1][j+1] = dp[i][j+1];
                    pre[i+1][j+1] = P(i, j+1);
                }else{
                    dp[i+1][j+1] = dp[i+1][j];
                    pre[i+1][j+1] = P(i+1, j);
                }
            }
        }
    }
    //cout << dp[s.size()][t.size()] << endl;
    vector<char> ans;
    int l = fin.first+1, r = fin.second+1;
    //cout << l << ' ' << r << endl;
    while(l > 0 && r > 0){
        P p = pre[l][r];
        if(s[l-1] == t[r-1] && l != p.first && r != p.second){
            ans.push_back(s[l-1]);
           // cout << l << ' ' << r << endl;
        }
        l = p.first; r = p.second;
    }
    //cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[ans.size()-i-1];
    }
    cout << endl;
}

Measured memory_bytes: 105856
// ALDS1_4_A.cpp
// Linear Search

#include <iostream>
#include <set>
using namespace std;

int intersectionCnt(set<int>& S, set<int>& T)
{
    int C = 0;
    set<int>::iterator it1 = S.begin();
    set<int>::iterator it2 = T.begin();
    while (it1 != S.end() && it2 != T.end()) {
        if (*it2 == *it1) {
            C++;
            ++it1;
            ++it2;
        }
        else if (*it2 < *it1) {
            ++it2;
        }
        else {
            ++it1;
        }
    }
    return C;
}

int main()
{
    int n;
    cin >> n;
    set<int> S;
    int tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        S.insert(tmp);
    }

    int q;
    cin >> q;
    set<int> T;
    for (int i = 0; i < q; i++) {
        cin >> tmp;
        T.insert(tmp);
    }

    int C = intersectionCnt(S, T);
    cout << C << endl;
    return 0;
}

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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<ll, P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main(){
    int a, b;
    cin >> a >> b;
    cout << max(0,a - b*2) << endl;
    
    return 0;
}

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

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

  vector<pair<double, i64>> vec;

  vector<double> x(N), y(N);

  for(i64 i = 0;i < N;i++) {
    double s, t;
    cin >> s >> t;
    x[i] = s * 1e6 / (1e6 - 100.0);
    y[i] = t * 1e6 / (1e6 - 100.0);
  }

  double Gx = 0, Gy = 0;
  for(i64 i = 0;i < N;i++) {
    Gx += x[i] / N;
    Gy += y[i] / N;
  }

  for(i64 i = 0;i < N;i++) {
    x[i] -= Gx;
    y[i] -= Gy;
    vec.push_back({ atan2(y[i], x[i]), -i - 1 });
  }

  i64 Q;
  cin >> Q;
  vector<double> a(Q), b(Q);
  for(i64 i = 0;i < Q;i++) {
    cin >> a[i] >> b[i];
    a[i] -= Gx;
    b[i] -= Gy;
    vec.push_back({ atan2(b[i], a[i]), i });
  }

  sort(begin(vec), end(vec));

  vector<i64> ans(Q);

  {
    i64 before = 0;
    i64 after = 0;
    i64 ai = 0;
    for(i64 i = vec.size(); i --> 0;) {
      if(vec[i].second < 0) {
        before = vec[i].second * -1 - 1;
        break;
      }
    }
    for(i64 i = 0;i < vec.size();i++) {
      if(vec[i].second < 0) {
        after = vec[i].second * -1 - 1;
        ai = i;
        break;
      }
    }


    for(i64 i = 0;i < vec.size();i++) {
      if(vec[i].second >= 0) {
        i64 idx = vec[i].second;
        double A = a[idx];
        double B = b[idx];
        double X1 = x[before];
        double Y1 = y[before];
        double X2 = x[after];
        double Y2 = y[after];
        if((X2 - X1) * (B - Y1) - (Y2 - Y1) * (A - X1) >= 0) {
          ans[idx] = 1;
        }
        else {
          ans[idx] = 0;
        }
      }
      else {
        before = after;
        while(ai = (ai + 1) % vec.size(), vec[ai].second >= 0) {
        }
        after = vec[ai].second * -1 -1;
      }
    }
  }

  for(i64 i = 0;i < Q;i++) {
    cout << ans[i] << endl;
  }
}



Measured memory_bytes: 6660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
struct edge
{
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

//Weighted edge set
template <typename T>
using Edges = vector<edge<T>>;

//Weighted graph
template <typename T>
using WeightedGraph = vector<Edges<T>>;

//昇順
priority_queue<int, vector<int>, greater<int>> que;
int N, M;

vector<int> color;
vector<bool> visited;

void dfs(WeightedGraph<int> &g, int start, int to, int cost)
{
    if (visited[to] == true)
        return;
    visited[to] = true;
    if (cost % 2 == 1)
        color[to] = !color[start];
    else
        color[to] = color[start];
    for (auto &e : g[to])
    {
        dfs(g, to, e.to, e.cost);
    }
}

int main()
{
    cin >> N;
    WeightedGraph<int> G(N);
    for (int i = 0; i + 1 < N; i++)
    {
        int a, b, w;
        cin >> a >> b >> w;
        a--, b--;
        G[a].emplace_back(b, w);
        G[b].emplace_back(a, w);
    }
    color = vector<int>(N);
    visited = vector<bool>(N, false);

    dfs(G, 0, G[0][0].to, G[0][0].cost);

    for (int i = 0; i < N; i++)
    {
        cout << color[i] << endl;
    }
}

Measured memory_bytes: 9344
use std::cmp;
use std::collections::VecDeque;
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let p: Vec<_> = (0..(n * n)).map(|_| sc.read::<usize>() - 1).collect();
    let mut dist = vec![0; n * n];
    for x in 0..(n * n) {
        let (i, j) = (x / n, x % n);
        let h = cmp::min(i, n - 1 - i);
        let w = cmp::min(j, n - 1 - j);
        dist[x] = cmp::min(h, w);
    }

    let mut empty = vec![false; n * n];
    let mut sum = 0;
    let mut q = VecDeque::new();
    for p in p.into_iter() {
        empty[p] = true;
        let (i, j) = (p / n, p % n);
        sum += dist[p];
        for &(di, dj) in [(0, 1), (0, !0), (1, 0), (!0, 0)].iter() {
            let ni = i.wrapping_add(di);
            let nj = j.wrapping_add(dj);
            if ni >= n || nj >= n {
                continue;
            }
            let np = ni * n + nj;
            if dist[np] > dist[p] {
                dist[np] = dist[p];
                q.push_back((ni, nj));
            }
        }

        while let Some((i, j)) = q.pop_front() {
            let p = i * n + j;
            let cost = if empty[p] { 0 } else { 1 };
            for &(di, dj) in [(0, 1), (0, !0), (1, 0), (!0, 0)].iter() {
                let ni = i.wrapping_add(di);
                let nj = j.wrapping_add(dj);
                if ni >= n || nj >= n {
                    continue;
                }
                let np = ni * n + nj;
                if dist[np] > dist[p] + cost {
                    dist[np] = dist[p] + cost;
                    q.push_back((ni, nj));
                }
            }
        }
    }
    println!("{}", sum);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6196
import sys
input = sys.stdin.readline
import math

def Main(a, b, x):
    h = x / (a*a)
    r = 0
    if(h >= b/2):
        r = math.atan2(b-h, a/2)
    else:
        y = 2*x/(a*b)
        r = math.atan2(b,y)
    return math.degrees(r)

def main():
    A, B, X = map(int, input().split())
    print(Main(A, B, X))


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define mod 1000000007
#define mx 10005
//#define y 3
using namespace std;
typedef  long long int ll;
#define  f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#include <bitset>

void input(){
 int a, b; cin>> a>> b;
 if(a >= 13)cout << b <<endl;
 else if(a >=6 && a <= 12)cout << b/2 <<endl;
 else cout <<0<< endl;
}
int main(){
    input();
    return 0;
}



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

int main(){
    int a, b;
    cin >> a >> b;
    if (a <= 0 && 0 <= b) cout << "Zero" << endl;
    else if (b<0 && (b-a)%2==0) cout << "Negative" << endl;
    else cout << "Positive" << endl;
    return 0;
}

Measured memory_bytes: 256
w = eval(input())
n = eval(input())
numlist = [item for item in range(1, w + 1)]
for t in range(n):
	i, j = [eval(item) - 1 for item in input().split(',')]
	numlist[i], numlist[j] = numlist[j], numlist[i]
for item in numlist:
	print(item)

Measured memory_bytes: 7400
#include <iostream>
using namespace std;
int main(){

  int h,w;
  char c;
  cin>>w>>h>>c;
  cout<<"+";
  for(int i=0;i<w-2;i++) cout<<"-";
  cout<<"+"<<endl;

  for(int i=0;i<h-2;i++){
    cout<<"|";
    for(int j=0;j<w-2;j++) cout<<(i==(h-2)/2&&j==(w-2)/2?c:'.');
    cout<<"|"<<endl;
  }

  cout<<"+";
  for(int i=0;i<w-2;i++) cout<<"-";
  cout<<"+"<<endl;
  
  return 0;

}

Measured memory_bytes: 3084