akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  ABC
//
//  Created by Amarsanaa Davaasuren on 2019/08/31.
//  Copyright © 2019 Amarsanaa Davaasuren. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)

using namespace std;
using ll = long long;


int main(){
    int N,K; cin >> N >> K;
    vector <int> A(N);
    rep(i,N) cin >> A[i];
    int ans = 0;
    while (N>0){
        (ans == 0 ? N-=K : N = N-K+1);
        ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int add(int x,int y){return x+y<3?x+y:x+y-3;}
const int mod=1e9+7;
int n;
char s[100100];
int a[100100];

int sum[100100];
int nd[100100];
int nxt[100100][3];
int dp[100100];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;++i)
	{
		a[i]=s[i]-'a'+1;
		sum[i]=add(sum[i-1],a[i]);
	}
	a[n+2]=4;
	nxt[n][0]=nxt[n][1]=nxt[n][2]=n+1;
	nxt[n+1][0]=nxt[n+1][1]=nxt[n+1][2]=n+1;
	nd[n+1]=n+1;
	for(int i=n;i>=0;--i)
	{
		memcpy(nxt[i],nxt[i+1],sizeof(nxt[i+1]));
		nxt[i][sum[i]]=i;
		nd[i]=nd[i+1];
		if(a[i+1]==a[i+2])nd[i]=i+2;
	}
	if(nd[1]==n+1&&a[1]!=a[2])
	{
		puts("1");
		return 0;
	}
	dp[0]=1;
	int p1,p2;
	for(int i=0;i<n;++i)
	{
		p1=nxt[nd[i]][add(sum[i],1)];
		p2=nxt[nd[i]][add(sum[i],2)];
		if(a[i+1]!=1)dp[p1]=(dp[p1]+dp[i])%mod;
		if(a[i+1]!=2)dp[p2]=(dp[p2]+dp[i])%mod;
		dp[i+1]=(dp[i+1]+dp[i])%mod;
	}

	int ans=0;
	for(int i=1;i<=n;++i)
		if(add(sum[n],3-sum[i])==0)
			(ans+=dp[i])%=mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
int A[100], N;
int main(){
  int res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY, Q5VJL1cS;
    if(N==0){
      Q5VJL1cS = 0;
    }
    else{
      Q5VJL1cS = A[0];
      for(KL2GvlyY=1;KL2GvlyY<N;KL2GvlyY++){
        Q5VJL1cS = min_L(Q5VJL1cS, A[KL2GvlyY]);
      }
    }
    {
      int cTE1_r3A, e98WHCEY;
      if(N==0){
        cTE1_r3A = 0;
      }
      else{
        cTE1_r3A = A[0];
        for(e98WHCEY=1;e98WHCEY<N;e98WHCEY++){
          cTE1_r3A = max_L(cTE1_r3A, A[e98WHCEY]);
        }
      }
      res =cTE1_r3A-Q5VJL1cS;
    }
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180707-1 [beta]

// --- original code ---
// int N, A[100];
// {
//   int res;
//   rd(N,A(N));
//   res = max(A(N))-min(A(N));
//   wt(res);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())

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

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  int64_t n;
  cin >> n;
  vector<int> v1(n);
  vector<int> v2(n);
  REP(i,n){
    cin >> v1.at(i);
  }
  v2 = v1;
  SORT(v1);
  int c = 0;
  REP(i,n){
    if (v1.at(i) != v2.at(i)){
      c++;
    }
  }
  if (c <= 2){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
# -*- coding:utf-8 -*-
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
if ((x in a) and (y in a)) or ((x in b) and (y in b)) or ((x in c) and (y in c)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

struct UnionFind{
    vector<ll> par;
    vector<ll> rank;
    vector<ll> W;

    UnionFind(ll N):par(N),rank(N),W(N){
        rep(i,N){
            par[i] = i;
            rank[i] = 0;
            W[i] = 0;
        }
    }

    ll root(ll x){
        if(par[x] == x) return x;
        ll rx = root(par[x]);
        W[x] += W[par[x]];
        return par[x] = rx;
    }

    bool same(ll x,ll y){
        return root(x) == root(y);
    }

    ll weight(ll x){
        root(x);
        return W[x];
    }
    
    void unite(ll x,ll y,ll d){
        d += weight(x) - weight(y);
        ll rx = root(x),ry = root(y);
        if(rx == ry) return ;
        if(rank[x] > rank[y]){
            W[ry] = d;
            par[ry] = rx;
        }else{
            W[rx] = -d;
            par[rx] = ry;
            if(rank[rx] == rank[ry]) rank[ry]++;
        }
    }

    ll diff(ll x,ll y){
        return weight(y) - weight(x);
    }
};

int main(){
    ll N,M;
    cin >> N >> M;
    UnionFind UF(100010);
    rep(i,M){
        ll l,r,d;
        cin >> l >> r >> d;
        l--;r--;
        if(UF.same(l,r)){
            if(UF.diff(l,r) != d){
                cout << "No" << endl;
                return 0;
            }
        }else{
            UF.unite(l,r,d);
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main()
{
	int a,b,c,x=0,y=0;
	while(scanf("%d,%d,%d",&a,&b,&c)==3)
	{
		if(a==b&&c<a+b)
			y++;
		else if(c*c==a*a+b*b)
			x++;
	}
	printf("%d\n%d\n",x,y);
	return 0;
}

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

int main() {
  int N,K,x,a=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>x;
    if(abs(K-x)<=abs(0-x))a+=abs(K-x)*2;
    else a+=abs(0-x)*2;
  }
  cout<<a<<endl;
 
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<pair<ll, ll>> Pi(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> Pi.at(i).first;
    Pi.at(i).second = i + 1;
  }
  sort(Pi.begin(), Pi.end(), greater<pair<ll, ll>>());

  ll ans = 0;
  multiset<ll> st = {0, 0, N + 1, N + 1};
  for (ll i = 0; i < N; i++)
  {
    ll p = Pi.at(i).first;
    ll c = Pi.at(i).second;
    st.emplace(c);
    auto it = st.lower_bound(c);
    it--;
    ll l1 = *it;
    it--;
    ll l0 = *it;
    it++, it++;
    it++;
    ll r0 = *it;
    it++;
    ll r1 = *it;

    ll tmp = p * ((l1 - l0) * (r0 - c) + (c - l1) * (r1 - r0));
    cerr << tmp << " " << tmp / p << " " << l0 << " " << l1 << " " << c << " " << r0 << " " << r1 << endl;
    ans += tmp;
  }
  cout << ans << endl;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int d;
  int b[110];
  rep(i,n){
    b[i] = 0;
  }
  rep(i,k){
    cin >> d;
    rep(j,d){
      int a[110];
      cin >> a[j];
      b[a[j]]++;
    }
  }
  int count = 0;
  rep(i,n){
    if(b[i] == 0){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n, a, b, tmp;
    int digitNumSum = 0;
    int total = 0;
    cin >> n >> a >> b;
    for (auto i = 1; i <= n; ++i) {
        tmp = i;
        digitNumSum = 0;
        for (auto j = 0; j < 5; ++j) {
            digitNumSum += tmp % 10;
            tmp /= 10;
        }
        if (digitNumSum >= a &&
            digitNumSum <= b)
        {
            total += i;
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(); 

    // long[] h = new long[N];
    long[] h = new long[N];
    for (int i=0; i < N ;i++) {
      h[i] =  sc.nextLong();
    }
    for (int i=N-1;i>0;i--) {
      // System.out.println(i);
      if(h[i-1]>h[i]){
        if(h[i-1] - h[i] ==1){
         h[i-1]--; 
        }else{
          System.out.println("No");
          return;
        }
      }

    }
    System.out.println("Yes");
  }
}



Measured memory_bytes: 49944
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            if(s - (i + j) <= k && s - (i + j) >= 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
void tree(vector<set<int>> &g,vector<vector<int>> &t,int p){
  while(!g.at(p).empty()){
    int cp=*begin(g.at(p));
    t.at(p).push_back(cp);
    g.at(p).erase(cp);
    g.at(cp).erase(p);
    tree(g,t,cp);
  }
  return;
}
void color(vector<vector<int>> &t,vector<int> &c,int k,int d,int p){
  for(int i=0;i<t.at(p).size();i++){
    c.at(t.at(p).at(i))=k-min(d,2)-i;
    color(t,c,k,d+1,t.at(p).at(i));
  }
  return;
}
int main(){
  int n,k;
  cin>>n>>k;
  vector<set<int>> g(n);
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    g.at(a-1).insert(b-1);
    g.at(b-1).insert(a-1);
  }
  vector<vector<int>> t(n);
  tree(g,t,0);
  vector<int> c(n);
  c.at(0)=k;
  color(t,c,k,1,0);
  int64_t p=1;
  for(int i=0;i<n;i++)
    p=p*c.at(i)%1000000007;
  cout<<p<<endl;
}

Measured memory_bytes: 24192
#include <cstdio>
#include <bitset>
using namespace std;

const int MAXN = 10010;
const int INF = 0x3f3f3f3f;
int R, C, ans;
bitset<10005> B[10];

void dfs(int k){
	int cnt = 0;
	if(k == R){
		for(int j = 0; j < C; j++){
			int t = 0;
			for(int i = 0; i < R; i++){
				t += B[i][j];
			}
			if(t > R-t){
				cnt += t;
			}else{
				cnt += R-t;
			}
		}
		if(cnt > ans) ans = cnt;
		return;
	}
	
	dfs(k+1);
	B[k].flip();
	dfs(k+1);

}

int main(){
	while(scanf("%d%d", &R, &C), R||C){
		for(int i = 0; i < R; i++){
			for(int j = 0; j < C; j++){
				bool t;
				scanf("%d", &t);
				B[i][j] = t;
			}
		}
		ans = 0;
		dfs(0);
		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>

using namespace std;

int main() {
	int n, m, in;
	map<int, int> d;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &in);
		d[in]++;
	}

	scanf("%d", &m);
	vector<int> t(m);
	for (int i = 0; i < m; i++) {
		scanf("%d", &t[i]);
	}

	bool ok = true;
	for (auto tt : t) {
		auto it = d.find(tt);
		if (it == d.end()) {
			ok = false;
			break;
		}

		if (it->second == 1) {
			d.erase(it);
		} else {
			it->second--;
		}
	}

	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int R,G,B,N,ret=0; cin>>R>>G>>B>>N;
	for (int r=0; r*R<=N; r++) {
		for (int g=0; r*R+g*G<=N; g++) {
			int left=N-r*R-g*G;
			if(left%B==0)
				ret++;
		}
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [(num,i) for i,num in enumerate(a)]
b = [(num,i) for i,num in enumerate(b)]
aa = a[:]
bb = b[:]
a.sort()
b.sort()
ans = 1
xs = [m]*n
ys = [n]*m
nx = 0
ny = 0
M = 10**9+7
for c in range(n*m, 0, -1):
    if (a and a[-1][0]>c) or (b and b[-1][0]>c):
        ans = 0
        break
    if a and b and a[-1][0]==b[-1][0]==c:
        num,i = a.pop()
        num,j = b.pop()
        xs[i] -= 1
        ys[j] -= 1
        nx += 1
        ny += 1
        if xs[i] < 0 or ys[j] < 0:
            ans = 0
            break
    elif a and a[-1][0]==c:
        num, i = a.pop()
        ans *= sum(bb[i][0]>=c for i in range(m))
        xs[i] -= 1
        nx += 1
        if xs[i] < 0:
            ans = 0
            break
    elif b and b[-1][0]==c:
        num, j = b.pop()
        ans *= sum(aa[i][0]>=c for i in range(n))
        ys[j] -= 1
        ny += 1
        if ys[j] < 0:
            ans = 0
            break
    else:
        ans *= (nx*ny - (n*m-c))
#         assert (nx*ny - (n*m-c))>=0
    ans %= M
print(ans%M)

Measured memory_bytes: 69384
line = input()
table = line.split(" ")
nuru = input()
nurut = nuru.split(" ")
table_sum = int(table[0]) * int(table[1])
table_sum = table_sum - int(nurut[0])*int(table[1]) - int(nurut[1])*int(table[0]) + int(nurut[0])*int(nurut[1])
print(table_sum)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] set = br.readLine().split(" ");
		int n = Integer.parseInt(set[0]);
		int m = Integer.parseInt(set[1]);
		int[][] A = new int[n][m];
		int[] b = new int[m];
		int[] c = new int[n];

		for(int i = 0; i < n; i++){
			String[] row = br.readLine().split(" ");
			for(int j = 0; j < m; j++) {
				A[i][j] = Integer.parseInt(row[j]);
			}
		}

		for(int j = 0; j < m; j++) {
			b[j] = Integer.parseInt(br.readLine());
		}

		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++) {
				c[i] += A[i][j] * b[j];
			}
		}

		for(int i = 0; i < n; i++){
			System.out.println(c[i]);
			}
		}

}

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

int main() {

    int h,w;

    cin >> h >> w;

    int n;

    cin >> n;

    int a[n];

    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    vector<int> v;

    for(int i=0; i<n; i++){
        for(int j=0; j<a[i]; j++) {
            v.push_back(i+1);
        }
    }


    int c[h][w];

    for(int i=0; i<h; i++){
        if(i % 2 == 0){
            for(int j=0; j<w; j++){
                c[i][j] = v[i*w + j];
            }
        }
        else{
            int count = 0;
            for(int j=w-1; j>=0; j--){
                c[i][j] = v[i*w + count];
                count++;
            }
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout << c[i][j] << ' ';
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#define rep(i, n) for (int i{ 0 }; i < n; ++i)

using namespace std;

int main() {
    int L, R, d;
    cin >> L >> R >> d;
    int cnt{ 0 };
    for (int i{ L }; i <= R; ++i)
        if (i % d == 0) cnt++;

    cout << cnt;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define MAXN 100000

/*
For each index i:
* Find the index of the first 2 larger number to the right of it
* Find the index of the first 2 larger number to the left of it

It can be done by processing number from large to small and maintain their indices in a set.

Then do contribution technique.
*/

int main() {
    /*
    right1[i] -> smallest j (j > i) such that P[j] > P[i]
    right2[i] -> second smallest j (j > i) such that P[j] > P[i];

    left1 and left2 defined similarly
    */

    int N, P[MAXN + 3], pos[MAXN + 3];
    int right1[MAXN + 3], right2[MAXN + 3], left1[MAXN + 3], left2[MAXN + 3];

    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> P[i];
        pos[P[i]] = i;
    }

    set<int> active;
    active.insert(0);
    active.insert(N + 1);

    //process from larger
    for (int num = N; num >= 1; num--) {
        int p = pos[num];

        auto rightPtr = active.lower_bound(p);

        right1[p] = *rightPtr;
        right2[p] = (right1[p] == N + 1 ? N + 1 : *(++rightPtr));

        auto leftPtr = active.lower_bound(p);
        --leftPtr;

        left1[p] = *leftPtr;
        left2[p] = (left1[p] == 0 ? 0 : *(--leftPtr));

        active.insert(p);
    }

    LL answer = 0;
    for (int i = 1; i <= N; i++) {
        if (right1[i] != N + 1) {
            int cntLeft = i - left1[i];
            int cntRight = right2[i] - right1[i];

            answer += (LL) P[i] * cntLeft * cntRight;
        }

        if (left1[i] != 0) {
            int cntLeft = left1[i] - left2[i];
            int cntRight = right1[i] - i;

            answer += (LL) P[i] * cntLeft * cntRight;
        }
    }

    cout << answer << endl;
}


Measured memory_bytes: 7296
#include<cstdio>
#include<vector>

#define	pb	push_back

using namespace std;

typedef	vector<int>	vi;

char field[5050];

bool vanish(int u,int l){
	vi rem;
	for(int i=l;i>=u;i--){
		if((field[i]&=31)!=31)	rem.pb(i);
	}
//printf("rem=%d\n",rem.size());
	int rnum=rem.size(),h=l-u+1;
	if(rnum!=l){
		for(int i=0;i<rnum;i++)	field[l-i]=field[rem[i]];
		for(int i=u-1;i>=0;i--)	field[h-rnum+i]=field[i];
		for(int i=0;i<rnum;i++)	field[i]=0;
	}
}

int main(){
	for(int n;scanf("%d",&n),n;){
		for(int i=0;i<5050;i++)	field[i]=0;
		for(int t=0;t<n;t++){
			int type,len,p;	scanf("%d%d%d",&type,&len,&p);
			p--;

			char blk;
			if(type==1)	blk=((1<<len)-1)<<(5-p-len);
			else		blk=1<<(4-p);

			for(int i=0;i<=5050;i++){
				if(i==5050 || (field[i]&blk)!=0){
					if(type==1){
						field[i-1]|=blk;
						vanish(i-1,i-1);
					}
					else{
						for(int j=1;j<=len;j++)	field[i-j]|=blk;
						vanish(i-len,i-1);
					}
					break;
				}
			}
//for(int i=4992;i<5000;i++){for(int j=0;j<5;j++)putchar(field[i]&(1<<4-j)?'@':'.');puts("");}puts("");
		}

		int cnt=0;
		for(int i=0;i<5050;i++){
			for(int j=0;j<5;j++)	if(field[i]&(1<<j))	cnt++;
		}
		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void){
    int h,m,s,total;
    scanf("%d",&total);
    h=total/3600;
    total-=h*3600;
    m=total/60;
    total-=m*60;
    s=total;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2140
import math

A, B, H, M = [int(x) for x in input().split()]

total_time_sec = H * 60 * 60 + M * 60

t1 = (2 * math.pi * total_time_sec) / (12 * 60 * 60)
t2 = (2 * math.pi * total_time_sec) / (60 * 60)

dist = math.sqrt(A*A + B*B - 2 * A * B * math.cos(t1 - t2))
print(dist)

Measured memory_bytes: 9508
#include<bits/stdc++.h>
using namespace std;
int n,a,b,f[5005];
long long dp[5005][5005];
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        f[x]=i;
    }
    for(int i=1;i<=n;i++)
    {
        int pos=f[i];
        long long t=1e18;
        for(int j=1;j<=n;j++)
        {
            t=min(t,dp[i-1][j]);
            if(pos==j) dp[i][j]=t;
            else if(pos>j) dp[i][j]=t+b;
            else dp[i][j]=t+a;
        }
    }
    long long ans=1e18;
    for(int i=1;i<=n;i++)
        ans=min(ans,dp[n][i]);
    printf("%lld\n",ans);
}
/*dp[i][j]表示将第i个数搬移到前j个位置的最小价值*/


Measured memory_bytes: 195840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[3005][3005];

ll dequeGame(ll arr[], ll n, ll i, ll j)
{
	if (i > j)
		return 0;
	if (j == i + 1)
		return max(arr[i], arr[j]);

	if (dp[i][j] != -1)
		return dp[i][j];

	//I select first;
	ll op1 = min(dequeGame(arr, n, i + 2, j), dequeGame(arr, n, i + 1, j - 1));
	//I select last;
	ll op2 = min(dequeGame(arr, n, i + 1, j - 1), dequeGame(arr, n, i, j - 2));

	return dp[i][j] = max(op1 + arr[i], op2 + arr[j]);
}

int main()
{

	ll n;
	cin >> n;

	ll arr[n + 1];
	ll tot = 0;

	for (ll i = 0; i < n; i++) {
		cin >> arr[i];
		tot += arr[i];
	}
	memset(dp, -1, sizeof(dp));
	ll tmp = dequeGame(arr, n, 0, n - 1);

	cout << tmp - (tot - tmp);
}

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

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

    int total = 0;
    int sum[n];
    int w;
    for (int i = 0; i < n; i++) {
        cin >> w;
        total += w;

        sum[i] = w;
        if (i > 0) {
            sum[i] += sum[i - 1];
        }
    }

    int ans = total;
    for (int i = 0; i < n; i++) {
        ans = min(ans, abs(total - sum[i] - sum[i]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
A, B, K = map(int, input().split())

if A > B :
  tmp = A
  A = B
  B = tmp

ki = 0
for i in range(A) :
  n = A-i
  if A%n == 0 and B%n == 0 :
    ki += 1
    if ki == K :
      print (n)
    
  
  


Measured memory_bytes: 38256
#include <iostream>
using namespace std;
typedef long long ll;

int main(void){
    int n;
    int MOD = 1e9+7;
    ll result, temp_10, temp_9, temp_8;
    cin >> n;
    
    temp_10 = 1;
    temp_9  = 1;
    temp_8  = 1;
    for (int i = 0; i < n; i++){
        temp_10 = temp_10 * 10 % MOD;
        temp_9  = temp_9 * 9 % MOD;
        temp_8  = temp_8 * 8 % MOD;
    }
    
    result = (temp_10 - 2 * temp_9 + temp_8) % MOD;
    if (result < 0) result += MOD;
    
    cout << result << endl;
}


Measured memory_bytes: 3600
N = int(input())
H = list(map(int, input().split()))

DP = [0] * N + [10**9]
for i in range(1, N):
  DP[i] = min(DP[i-1]+abs(H[i]-H[i-1]), DP[i-2]+abs(H[i]-H[i-2]))
print(DP[N-1])

Measured memory_bytes: 13924
#include<stdio.h>
int main(){
  int a,b,c,ans;
  scanf("%d %d %d",&a,&b,&c);
  a *= b;
  if(a > c){
    ans = c;
  }else{
    ans = a;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 
 

void func()
{
   ll h,w,k;
   cin>>h>>w>>k;
   char c[h][w];
   f(i,0,h) f(j,0,w) cin>>c[i][j];
   ll ans=0;
   f(mask1,0,1<<h)  // rows selected
   {
	   f(mask2,0,1<<w) // col selected
	   {
		   ll cnt=0;
		   f(i,0,h) 
		   {
			   f(j,0,w)
			   {
				   if(c[i][j]=='#' && (mask1&(1<<i))==0 && (mask2&(1<<j))==0 ) cnt++;
			   }
		   }
		   if(cnt==k) ans++;
	   }
   }
   
   cout<<ans<<endl;

}   
     
     
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE
        
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
       func();
    }
     
    return 0;
}


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

typedef long long int   ll;
typedef pair<ll, ll>    pll;
typedef pair<int, int>  pii;

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'

template<class T = ll>
T nxt() {T x; cin >> x; return x;}

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const ll N    = 400 + 10;
const ll MOD  = 1e9 + 7;
const ll INF  = 1e18;

ll n, c, A[N], B[N], p[N][N], dp[N][N];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> c;
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
    }
    for (int j = 1; j <= n; j++) {
        cin >> B[j];
    }
    for (int i = 0; i < N; i++) {
        p[i][0] = (i == 0);
        for (int j = 1; j < N; j++) {
            p[i][j] = (p[i][j - 1] + pw(j, i, MOD)) % MOD;
        }
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k <= j; k++) {
                dp[i][j] += dp[i - 1][j - k] * (p[k][B[i]] - p[k][A[i] - 1] + MOD) % MOD;
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[n][c] << endl;
    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans=n;
	FOR(i,n-1){
		if(s[i]==s[i+1])ans--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	int ans = 0;
	rep(bit1, (1 << h)) {
		rep(bit2, (1 << w)) {
			vector<vector<int>> g(h, vector<int>(w));
			rep(i, h) {
				if (bit1 & (1 << i)) {
					rep(j, w) if (s[i][j] == '#') g[i][j] = 1;
				}
			}
			rep(j, w) {
				if (bit2 & (1 << j)) {
					rep(i, h) if (s[i][j] == '#') g[i][j] = 1;
				}
			}
			int res = 0;
			rep(i, h)rep(j, w) {
				if (s[i][j] == '#' && g[i][j] != 1) res++;
			}
			if (res == k) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3660
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

		StringBuilder sb = new StringBuilder();
		while(true) {
			int M = sc.nextInt();
			int T = sc.nextInt();
			int P = sc.nextInt();
			int R = sc.nextInt();
			if(M == 0 && T == 0 && P == 0 && R == 0) {
				sc.close();
				break;
			}
			int[] m = new int[R];
			int[] t = new int[R];
			int[] p = new int[R];
			int[] j = new int[R];
			for(int i = 0; i < R; i++) {
				m[i] = sc.nextInt();
				t[i] = sc.nextInt();
				p[i] = sc.nextInt();
				j[i] = sc.nextInt();
			}
			sb.append(solve(T, P, R, m, t, p, j));
			sb.append("\n");
		}
		System.out.print(sb.toString());
		//System.out.print(debug.toString());
	}
	static StringBuilder debug = new StringBuilder();
	static String solve(int T, int P, int R, int[] m, int[] t, int[] p, int[] j) {
		StringBuilder sb = new StringBuilder();
		Data[] d = new Data[T];
		for(int i = 0; i < T; i++) {
			d[i] = new Data(i + 1, 0, 0);
			d[i].setP(P);
		}
		for(int i = 0; i < R; i++) {
			if(j[i] == 0) {
				d[t[i] - 1].n += 1;
				d[t[i] - 1].time += m[i] + 20 * d[t[i] - 1].cnt[p[i] - 1];
			}else {
				d[t[i] - 1].cnt[p[i] - 1] += 1;
			}
		}
		Arrays.sort(d, new MyComparator());
		for(int i = 0; i < T; i++) {
			debug.append(d[i].id).append(" ");
		}
		debug.append("\n");
		int[] rank = new int[T];
		for(int i = 1; i < T; i++) {
			if(d[i - 1].n > d[i].n) {
				rank[i] = rank[i - 1] + 1;
			}else {
				if(d[i - 1].time == d[i].time) {
					rank[i] = rank[i - 1];
				}else {
					rank[i] = rank[i - 1] + 1;
				}
			}
		}
		int[] g = new int[rank[T - 1] + 1];
		if(g.length == 1) {
			String temp = "";
			for(int i = T; i >= 1; i--) {
				if(i == T) {
					temp += Integer.toString(i);
				}else {
					temp += "=" + Integer.toString(i);
				}
			}
			return temp;
		}
		for(int i = 0; i < T; i++) {
			g[rank[i]]++;
		}
		String[] s = new String[g.length];
		int idx = 0;
		for(int i = 0; i < g.length; i++) {
			if(g[i] == 1) {
				s[i] = Integer.toString(d[idx].id);
				idx++;
			}else {
				String temp = "";
				for(int l = 0; l < g[i]; l++) {
					if(l == 0) {
						temp += Integer.toString(d[idx].id);
					}else {
						temp += "=" + Integer.toString(d[idx].id);
					}
					idx++;
				}
				s[i] = temp;
			}
		}
		for(int i = 0; i < g.length; i++) {
			if(i == 0) {
				sb.append(s[i]);
			}else {
				sb.append(",").append(s[i]);
			}
		}
		return sb.toString();
	}
	static class Data{
		int id, n, time, P;
		int []cnt;
		public Data(int id, int n, int time) {
			this.id = id;
			this.n = n;
			this.time = time;
		}
		public void setP(int P) {
			cnt = new int[P];
		}
	}
	static class MyComparator implements Comparator<Data>{
		@Override
		public int compare(Data d2, Data d1) {
			if(d1.n > d2.n) {
				return 1;
			}else if(d1.n < d2.n){
				return -1;
			}else {
				if(d1.time > d2.time) {
					return -1;
				}else if(d1.time == d2.time) {
					if(d1.id > d2.id) {
						return 1;
					}else {
						return -1;
					}
				}else {
					return 1;
				}
			}
		}
	}
}


Measured memory_bytes: 68876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)

int main(){
    ll N; cin >> N;
    ll A, B; cin >> A >> B;

    N %= 12;
    rep(i, 1, N+1){
        if(i & 1){
            A = A - B;
        }else{
            B = A + B;
        }
    }
    cout << A << " " << B << endl;
}


Measured memory_bytes: 3104
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int64, n)

	var sum, add, chosen int64
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
		sum += aa[i]
	}
	add = int64(n) * int64(n+1) / 2
	if sum%add != 0 || sum < add {
		fmt.Fprintln(writer, "NO")
		return
	}
	c := sum / add
	for i := 0; i < n; i++ {
		if aa[i]+c < aa[(i+1)%n] {
			fmt.Fprintln(writer, "NO")
			return
		}
		if (aa[i]+c-aa[(i+1)%n])%int64(n) != 0 {
			fmt.Fprintln(writer, "NO")
			return
		}
		chosen += (aa[i] + c - aa[(i+1)%n]) / int64(n)
	}
	if c != chosen {
		fmt.Fprintln(writer, "NO")
		return
	}
	fmt.Fprintln(writer, "YES")
}


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

int main (void){
    string s;
    cin>>s;
    if(s[0]=='7'||s[1]=='7'||s[2]=='7'){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

#define ll long long
#define ull unsigned long long 
#define endl "\n"
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    int n, y;
    cin >> n >> y;
    for(int i=0; i<=n; ++i){
        for(int j=0; j<=n; ++j){
            if(10000*i + 5000*j + (n-i-j)*1000 == y && n-i-j >=0){
                printf("%d %d %d", i, j, n-i-j);
                return 0;
            }
        }
    }
    cout << "-1 -1 -1";
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;

#define faster ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define debug(x) cout<<#x<<" = "<<(x)<< endl
#define nl "\n"
#define sp " "

const int MOD = 998244353;
int n, s, arr[3005];
ll memo[3005][3005];


inline ll fix(ll x){
	return (x % MOD + MOD) % MOD;
}

ll dp(int idx, int rem){
	if(rem < 0) return 0;
	if(idx == n) return rem == 0 ? 1 : 0;
	if(~memo[idx][rem]) return memo[idx][rem];

	ll take = dp(idx + 1, rem - arr[idx]);
	ll leave = 2LL * dp(idx + 1, rem);

	return memo[idx][rem] = fix(take + leave);
}

int main() {
	faster
	cin >> n >> s;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}

	memset(memo,-1,sizeof memo);
	cout << dp(0,s) << nl;
}


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

using namespace std;
typedef unsigned long long ull;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    string s, t;
    cin >> s >> t;

    int arr1[26] = {0};
    int arr2[26] = {0};

    for (int i = 0; i < s.size(); i ++)
        arr1[s[i] - 'a'] ++;

    for (int i = 0; i < t.size(); i ++)
        arr2[t[i] - 'a'] ++;

    vector<int> v1, v2;

    for (int i = 0; i < 26; i ++) {
        if (arr1[i] > 0)
            v1.push_back(arr1[i]);
        if (arr2[i] > 0)
            v2.push_back(arr2[i]);
    }

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    bool flag = false;
    if (v1.size() == v2.size()) {
        for (int i = 0; i < v1.size(); i ++){
            if (v1[i] != v2[i]) {
                flag = true;
                break;
            }
        }
    } else {
        flag = true;
    }
    if (!flag)
        cout << "Yes";
    else
        cout << "No";


    return 0;
}

Measured memory_bytes: 916
const input = require("fs").readFileSync("/dev/stdin", "utf8").split(/\s/);
const a = input[0] - 0;
const b = input[1] - 0;
const c = input[2] - 0;
const d = input[3] - 0;

if (a + b < c + d) {
  console.log("Right");
} else if (a + b > c + d) {
  console.log("Left");
} else {
  console.log("Balanced");
}

Measured memory_bytes: 7372
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))

cnt = 0
for t in T:
    S.append(t)
    i = 0
    while t != S[i]:
        i += 1
    if i != n:
        cnt += 1
    S.pop()

print(cnt)


Measured memory_bytes: 6544
#include<stdio.h>

int main(void)
{
    int i = 0, n;
    
    

    while (1){

        scanf("%d", &n);

        if(n == 0) break;

        else {
            printf("Case %d: %d\n", i+1, n);
        
            ++i;
        }

    }

    return 0;

}


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

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

  ll N; cin >> N;
  vector<vector<ll>> A(N, vector<ll>(N, 0));
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  ll MAX = (1 << N);
  ll MOD = 1e9 + 7;
  vector<ll> dp(MAX, 0);
  dp[0]=1;

  for (ll i = 0; i < N; i++) {
    vector<ll> dpN(MAX, 0);
    for (ll j = 0; j < MAX; j++) {
      if (dp[j] == 0) continue;
      for (ll k = 0; k < N; k++) {
        if ((j | (1<<k)) == j) continue;
        if (A[i][k] == 0) continue;
        (dpN[j | (1<<k)] += dp[j]) %= MOD;
      }
    }
    dp = dpN;
    // cout << dp[0]; for (int i = 1; i < dp.size(); i++) { cout << ' ' << dp[i]; }
    // cout << '\n';
  }
  cout << dp[MAX - 1] << '\n';
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount


template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  int n;
  F f;
  G g;
  T d1;
  vector<T> dat;
  SegmentTree(int n_,F f,G g,T d1,
        vector<T> v=vector<T>()){
    this->f=f;
    this->g=g;
    this->d1=d1;
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  void update(int k,E a){
    k+=n-1;
    dat[k]=g(dat[k],a);
    while(k>0){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
  T query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return d1;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
};

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

  int n,q;
  cin>>n>>q;
  SegmentTree<int,int> rmq(n,
         [](int a,int b){return min(a,b);},
         [](int a,int b){return b;},
         INT_MAX);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<rmq.query(x,y+1)<<endl;
    else rmq.update(x,y);
  }

  return 0;
}



Measured memory_bytes: 3908
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
const int N=100007,P=1000000007;
int n,m,ans,hd[N],nt[N<<1],to[N<<1],D[N];
void fly(int u,int f) {
	int d=D[u];
	for(int i=hd[u];i;i=nt[i])
	if(to[i]!=f) {
		fly(to[i],u);
		if(d>m) ans=0;
		ans=1LL*ans*(m-d)%P;
		--d;
	}
}
int main() {
	scanf("%d%d",&n,&m);
	ans=m;
	For(i,1,n-1) {
		int x,y;
		scanf("%d%d",&x,&y),++D[x],++D[y];
		nt[i*2-1]=hd[x],hd[x]=i*2-1,to[i*2-1]=y;
		nt[i*2]=hd[y],hd[y]=i*2,to[i*2]=x;
	}
	fly(1,-1);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,s;
    cin>>a>>b;
    s=a-b*2;
    if(s>0)
    {
        cout<<s<<endl;
    }
    else
    {
        cout<<"0"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()

int main()
{
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 4)
  {
    if(s.at(i)=='+'){
      ans++;
    }else{
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0 ; i < int(N);i++)
using namespace std ;
typedef long long ll;
typedef pair <int , int >pi;
typedef vector <int> vi ;
typedef vector <string> si;

// void solve(){
	
// }

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

	cin >> t ;

	if (t == 0) cout << 1;
	else cout << 0 ;
	

	return 0 ;
}

Measured memory_bytes: 3632
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int N;
	cin >> N;
	vector<ll> vec(N);
	for (int i = 0; i < N; i++) cin >> vec.at(i);
	ll ans = 0;
	ll mod = (ll)1e9 + 7;
	ll tmp = 0;
	for (int i = 1; i < N; i++) {
		tmp += vec.at(i-1);
		tmp %= mod;
		ans += vec.at(i) * tmp;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4840
#include<iostream>
#include<vector>
#include<string>
#include<cmath>

int main(){
    int N;
    std::vector<int> V,C;
    std::cin >> N;
    for(int i=0; i<N; i++){
        int _V;
        std::cin >> _V;
        V.emplace_back(_V);
    }
    for(int i=0; i<N; i++){
        int _C;
        std::cin >> _C;
        C.emplace_back(_C);
    }

    int res=0;

    for(int i=0; i<N; i++){
        if(V[i] > C[i]){
            res += (V[i] - C[i]);
        }
    }

    std::cout << res << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)

class UnionFind{
public:
	vector<int> par;
	vector<long long> g1,g2;
	//0-indexed
	void init(int n = 1) {
		par.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i;
		g1.resize(n,0);
		g2.resize(n,0);
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		else{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		g1[y] += g1[x];
		g2[y] += g2[x];
		par[x] = y;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int H,W;
	ll ans=0;
	cin >> H >> W;
	string s[H];
	FOR(i,0,H){
		cin >> s[i];
	}
	UnionFind uf;
	uf.init(H*W);
	// (x,y) -> W*x+y
	FOR(i,0,H){
		FOR(j,0,W){
			if(s[i][j]=='#'){
				uf.g1[W*i+j]=1;
			}else{
				uf.g2[W*i+j]=1;
			}
		}
	}
	FOR(i,0,H){
		FOR(j,0,W){
			int now = W*i+j;
			int to = W*(i-1)+j;
			if(i>0)if(s[i][j]!=s[i-1][j]){
				uf.unite(now,to);
				uf.root(to);
				uf.root(now);
			}
			to = W*i+j-1;
			if(j>0)if(s[i][j]!=s[i][j-1]){
				uf.unite(now,to);
				uf.root(to);
				uf.root(now);
			}
		}
	}
	set<int> se;
	FOR(i,0,H){
		FOR(j,0,W){
			int ro = uf.root(i*W+j);
			if(se.count( ro )==0){
				ans += uf.g1[ro]*uf.g2[ro];
				se.insert(ro);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 9728
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        if(a == 1 && b == 1){
            System.out.println(1);
        }else if(a == 1 || b == 1){
            System.out.println(a*b-2);
        }else{
            System.out.println(a*b-(a+b)*2+4);
        }
        
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 25376
import java.util.Scanner;
import java.util.HashMap;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    char[] w = scanner.next().toCharArray();
    boolean[] isOdd = new boolean[26]; // {false, false, false...}
    for(char c: w) {
      int i = c - 'a';
      isOdd[i] = !isOdd[i];
    }
	
    boolean isAllEven = true;
    for(boolean b: isOdd) {
      if(b) {
        isAllEven = false;
      }
    }
    
    if(isAllEven) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35364