akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	int n = s.size() - 2;
	int cnt = 0;
	ll res = 0;
	bool skip = false;
	bool a_flag = false;
	REP(i, n) {
		if (skip) {
			skip = false;
		}
		else if (a_flag) {
			if (s[i + 1] == 'B' && s[i + 2] == 'C') {
				res += cnt;
				skip = true;
				a_flag = true;
			}
			else a_flag = false;
		}
		else if (s[i] == 'A') {
			cnt++;
			if (s[i + 1] == 'B' && s[i + 2] == 'C') {
				res += cnt;
				skip = true;
				a_flag = true;
			}
		}
		else cnt = 0;
	}

	cout << res << endl;

	return 0;
}



Measured memory_bytes: 720
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  if N%9==0:
    return 'Yes'
  return 'No'

# main()
print(main())


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

using namespace std;
typedef  long long ll;

#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sdo(a) scanf("%lf",&a)
#define sdo2(a,b) scanf("%lf %lf",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
const int maxn=1e6+10;
const int mod=1e9+7;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a==b)
    cout<<"Yes"<<endl;
   else 
    cout<<"No"<<endl;
    return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int w = ri();
	int a[n], b[n];
	for (int i = 0; i < n; i++) a[i] = ri(), b[i] = ri();
	std::vector<int64_t> dp(w + 1, 0);
	for (int i = 0; i < n; i++) for (int j = w - a[i]; j >= 0; j--)
		dp[j + a[i]] = std::max(dp[j + a[i]], dp[j] + b[i]);
	std::cout << *std::max_element(dp.begin(), dp.end()) << std::endl;
	return 0;
}


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

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i = 0; i < n; i++)
#define for1(i,n) for(int i = 1; i <= n; i++)
#define ford(i,n) for(int i = n-1; i >= 0; i--)
#define fore(i,a,b) for(int i = a; i <= b; i++)

using namespace std;

typedef long long ll;
typedef double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;


const  int MAXn= 3e5+5;
const  long long INF= 1e18;
const long long mod= 1e9+7;


int main(){
        ll n,m;
        cin>>n>>m;
        priority_queue<ll> q;
        forn(i,n){
			ll x;
			cin>>x;
			q.push(x);
		}
		while(m--){
			if(q.empty()) break;
			ll x= q.top();
			q.pop();
			x=x/2;
			if(x!=0){
				q.push(x);
			}
		}
		ll sum=0;
		while(!q.empty()){
			sum+=q.top();
			q.pop();
		}
		cout<<sum;
	}
        
        
        
    


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

int main()
{
    int N, Z, W;
    cin >> N >> Z >> W;
    vector<int> a(N);
    for(int i = 0; i < N; ++i) cin >> a[i];

    //dp_min[i] : 後ろからi番目をYが引いた時の|X-Y|の最小値
    //dp_max[i] : 後ろからi番目をXが引いた時の|X-Y|の最大値
    vector<int> dp_min(N+1), dp_max(N+1);
    dp_min[1] = 1e9;
    dp_max[1] = abs(a[N-1]-W);
    for(int i = 2; i < N+1; ++i) {
        dp_min[i] = abs(a[N-i] - a[N-1]);
        dp_max[i] = abs(a[N-i] - a[N-1]);
        for(int j = 1; j < i; ++j) {
            dp_min[i] = max(dp_min[i], dp_max[j]); //後ろからi番目をYが選んだらXはそれ以降で最もスコアが最大になるマスを選ぼうとする
            dp_max[i] = min(dp_max[i], dp_min[j]); //後ろからi番目をXが選んだらYはそれ以降で最もスコアが最小になるマスを選ぼうとする
        }
    }
    
    cout << *max_element(dp_max.begin(), dp_max.end()) << endl;
    return 0;
}

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

lx = {}
rx = {}

for i, ai in enumerate(a):
    li = (i + 1) + ai
    ri = (i + 1) - ai
    if li not in lx:
        lx[li] = set()
    lx[li].add(i + 1)
    if ri not in rx:
        rx[ri] = set()
    rx[ri].add(i + 1)
# print(lx)
# print(rx)

answer = 0
for x in lx.keys():
    if x in rx:
        s = lx[x]
        t = rx[x] - lx[x]
        answer += len(s) * len(t)

print(answer)


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


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

int main(){

    int n,h;
    int ans=0,wall=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h;
        if(h>=wall){
            wall=h;
            ans++;
        }
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};


int main()
{
int n;
cin>>n;
vector<int> d(n,0);
REP(i,n) cin>>d[i];
sort(d.begin(),d.end(),greater<int>());
int ans=1;
for(int i=0; i<n-1; i++)
{
    if(d[i]>d[i+1]) ++ans;
}
cout<<ans<<endl;
}

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

#define x first
#define y second
#define endl '\n'
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()
#define show(x) cout<<(#x)<<" is "<<(x)<<endl

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef vector<vector<int>> matrix;

const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=5e5+123;
const int M=1e6+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

char s[M];

int main(){
    int n,q,k;
    scanf("%d",&n);
    scanf("%s",s);
    scanf("%d",&q);
    while(q--){
        scanf("%d",&k);
        ll ans=0;
        ll d=0,m=0,cnt=0;
        for(int i=0;i<k;i++){
            if(s[i]=='D'){
                d++;
            }
            if(s[i]=='M'){
                m+=d;
                cnt++;
            }
            if(s[i]=='C'){
                ans+=m;
            }
        }

        for(int i=k;i<n;i++){
            if(s[i-k]=='D'){
                m-=cnt;
                d--;
            }
            if(s[i-k]=='M'){
                cnt--;
            }
            if(s[i]=='D'){
                d++;
            }
            if(s[i]=='M'){
                m+=d;
                cnt++;
            }
            if(s[i]=='C'){
                ans+=m;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 1280
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        long m = N / (A+B);
        long result = A * m + (Math.min(N%(A+B), A));
        System.out.println(result);
    }
}

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

int main(){
  string s;
  cin >> s;
  
  if(s == "Sunny")cout << "Cloudy";
  else if(s == "Cloudy")cout << "Rainy";
  else cout << "Sunny";
  
  return 0;
}

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

int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<int>> a(h+1,vector<int>(w+1)), b(h+1,vector<int>(w+1));
  rep(i,1,h+1) rep(j,1,w+1) cin >> a[i][j];
  rep(i,1,h+1) rep(j,1,w+1) cin >> b[i][j];
  vector<vector<vector<bool>>> ans(h+1,vector<vector<bool>>(w+1,vector<bool>(160*80+1,false)));
  ans[1][0][0] = true;
  rep(i,1,h+1) rep(j,1,w+1) {
    rep(k,0,160*80+1) {
      if (ans[i-1][j][k] || ans[i][j-1][k]) {
        ans[i][j][k+abs(a[i][j]-b[i][j])] = true;
        ans[i][j][abs(k-abs(a[i][j]-b[i][j]))] = true;
      }
    }
  }
  rep(i,0,160*80+1) {
    if (ans[h][w][i]) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 14180
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
int n;
const int MaxN = 1e5 + 5;
int box[3 * MaxN];
bool cmp(int x, int y){
	return x > y;
}
int main(){
	while(~scanf("%d", &n)){
		for(int i = 1; i <= 3 * n; i++)
			scanf("%d", &box[i]);
		sort(box + 1, box + 1 + 3 * n, cmp);
		LL ans = 0;
		int cnt = n;
		for(int i = 2; cnt; i += 2){	ans += box[i]; cnt--;}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1280
import numpy as np


def imos2d(x1, y1, x2, y2, board):
    board[y1][x1] += 1
    board[y2][x2] += 1
    board[y2][x1] -= 1
    board[y1][x2] -= 1


if __name__ == '__main__':
    N, K = map(int, input().split())
    lines = [input() for _ in range(N)]

    K2 = 2 * K
    add_dict = {"W": 0, "B": K}
    board = [[0 for _ in range(K2 + 1)] for _ in range(K2 + 1)]
    for line in lines:
        ls = line.split()
        x = int(ls[0]) % K2
        y = (int(ls[1]) + add_dict[ls[2]]) % K2
        x_ = x % K
        y_ = y % K

        # 左上・右上・中央・左下・右下
        if (x < K and y < K) or (K <= x and K <= y):
            # 左上
            imos2d(0, 0, x_ + 1, y_ + 1, board)
            # 右上
            imos2d(x_ + K + 1, 0, K2, y_ + 1, board)
            # 左下
            imos2d(0, y_ + K + 1, x_ + 1, K2, board)
            # 右下
            imos2d(x_ + K + 1, y_ + K + 1, K2, K2, board)
            # 中央
            imos2d(x_ + 1, y_ + 1, x_ + K + 1, y_ + K + 1, board)
        # 上・下・左・右
        else:
            # 上
            imos2d(x_ + 1, 0, x_ + K + 1, y_ + 1, board)
            # 下
            imos2d(x_ + 1, y_ + K + 1, x_ + K + 1, K2, board)

            # 左
            imos2d(0, y_ + 1, x_ + 1, y_ + K + 1, board)
            imos2d(x_ + K + 1, y_ + 1, K2, y_ + K + 1, board)

    board = np.array(board)
    for x in range(K2):
        board[:, x + 1] += board[:, x]
    for y in range(K2):
        board[y + 1, :] += board[y, :]

    print(board.max())


Measured memory_bytes: 83720
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < 10; i++){
        if(i*100+i*10+i < n && n <= (i+1)*100+(i+1)*10+(i+1) ){
            cout << (i+1)*100+(i+1)*10+(i+1) << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){
    // 変数宣言
    char judge[4];
    char s[4];
    char *p_judge;
    p_judge = judge;

    // 入力処理
    scanf( "%s", s );

    // 比較
    if( !(strcmp( "AAA", s )==0) && !(strcmp( "BBB", s )==0) ){
        p_judge = "Yes";
    }else{
        p_judge = "No";
    }

    // 出力
    printf( "%s", p_judge );
    

    return 0;
}

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

namespace find_confidence_back
{
	const int N=3010,M=N*2;
	int begin[N],next[M],to[M];
	int A[N],ans[N];
	int n,e,tot;
	void add(int x,int y,bool k=1)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		if(k)add(y,x,0);
	}
	void initialize()
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)scanf("%d",A+i);
		for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),add(u,v);
	}
	bool dfs(int p,int h=0)
	{
		bool ret=0;
		for(int i=begin[p],q;i;i=next[i])
			if((q=to[i])!=h)
			{
				if(A[q]>=A[p])continue;
				if(!dfs(q,p))ret=1;
			}
		return ret;
	}
	void solve()
	{
		initialize();
		tot=0;
		for(int i=1;i<=n;i++)if(dfs(i))ans[++tot]=i;
		for(int i=1;i<=tot;i++)printf("%d ",ans[i]);printf("\n");
	}
}

int main()
{
	find_confidence_back::solve();
	return 0;
}


Measured memory_bytes: 384
N = 4 * 10**6


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int num = a.at(0);
  int ans = 0;
  int count = 1;
  for(i = 1; i < n; i++)
  {
    if(a.at(i) != a.at(i-1))
    {
      ans += count%2;
      count = 1;
      num = a.at(i);
    }
    else
    {
      count++;
    }
  }
  ans += count%2;
  cout << ans << endl;
} 

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

using namespace std;
#define ll long long int

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n,m;
	cin>>n>>m;
	ll arr[n+5];
	std::vector<int> v[n+5];
	for (int i = 1; i <= n; ++i)
	{
		cin>>arr[i];
	}
	ll a,b;
	for (int i = 0; i < m; ++i)
	{
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	ll ans=0;
	for (int i = 1; i <= n; ++i)
	{
		a=arr[i];
		bool iss=true;
		for (int j = 0; j < v[i].size(); ++j)
		{
			if(a<=arr[v[i][j]]){
				iss=false;
				break;
			}
		}
		if(iss)
			ans++;
	}
	cout<<ans;

	return 0;
}


Measured memory_bytes: 9588
#include <bits/stdc++.h> 
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  int n=s.length(),m=t.length();
  int a[n+1][m+1];
  
  for(int i=0;i<=n;i++){
	 for(int j=0;j<=m;j++)
		 a[i][j]=0;
  }

  
  for(int i=1;i<=n;i++)
  {
	  for(int j=1;j<=m;j++)
      {
        if(s[i-1]==t[j-1])
          a[i][j]=a[i-1][j-1]+1;
        else
          a[i][j]=max(a[i][j-1],a[i-1][j]);
	  }
  }
  
  vector<char> v;
  int i=n,j=m;
  while(i!=0 && j!=0)
  {
      if(a[i][j]==a[i-1][j])
        --i;
        else if(a[i][j]==a[i][j-1])
        --j;
	  else
	  {
		  v.push_back(s[i-1]);
		  --i;--j;
	  }
  }
  reverse(v.begin(),v.end());
  for(int i=0;i<v.size();i++)
	  cout<<v[i];
}
               

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int a,b,c;

int main(){
    cin>>a>>b>>c;
    int ans=-1;
    for(int i=0;i<62;i++){
        int d=c+60*i;
        int cy=d%(a+b);
        if(cy<=a){
            ans=d;
            break;
        }   
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  long N;
  cin>>N;
  vector<long> a(100005);

  //for(int i=0;i<N;i++) cin>>a[i];
  //sort(a.begin(),a.end());
  //reverse(a.begin(),a.end());
  //long ans=0;
  /*
  for(int i=1;i<=N;i++){
    long ans=0;
    for(int x=1;i-x*x>=4;x++){
      for(int y=1;i-x*x-y*y>=1;y++){
        for(int z=1;i-x*x-y*y-z*z>=1;z++){
          if(x*x+y*y+z*z+x*y+y*z+z*x==i) ans++;
        }
      }
    }
    cout<<ans<<endl;
  }
  */
  for(int x=1;x<=100;x++){
    for(int y=1;y<=100;y++){
      for(int z=1;z<=100;z++){
        a[x*x+y*y+z*z+x*y+y*z+z*x]++;
      }
    }
  }
  for(int i=1;i<=N;i++){
    cout<<a[i]<<endl;
  }
  //cout<<ans<<endl;
  }


Measured memory_bytes: 3888
#include<bits/stdc++.h>
#define ll long long
#define lson (rt << 1)
#define rson (rt << 1 | 1)
using namespace std;
const int MAXN = 2e5 + 7;
const ll INF = 1e17;
int x[MAXN];
ll y[MAXN];
struct segt
{
    ll T[MAXN << 2], lazy[MAXN << 2];
    void pushup(int rt) {T[rt] = min(T[lson], T[rson]);}
    void build(int rt, int l, int r, int sig)
    {
        if (l == r) {T[rt] = y[l] + sig * l; return;}
        int mid = (l + r) >> 1;
        build(lson, l, mid, sig);
        build(rson, mid + 1, r, sig);
        pushup(rt);
    }
    void update(int rt, ll v) {T[rt] += v; lazy[rt] += v; return;}
    void pushdown(int rt)
    {
        if (!lazy[rt]) return;
        update(lson, lazy[rt]);
        update(rson, lazy[rt]);
        lazy[rt] = 0;
    }
    void modify(int rt, int l, int r, int L, int R, ll v)
    {
        if (L <= l && r <= R) {update(rt, v); return;}
        pushdown(rt);
        int mid = (l + r) >> 1;
        if (L <= mid) modify(lson, l, mid, L, R, v);
        if (mid <  R) modify(rson, mid + 1, r, L, R, v);
        pushup(rt);
    }
    void modify_p(int rt, int l, int r, int pos, ll v)
    {
        if (l == r) {T[rt] = min(T[rt], v); return;}
        pushdown(rt);
        int mid = (l + r) >> 1;
        if (pos <= mid) modify_p(lson, l, mid, pos, v);
        else modify_p(rson, mid + 1, r, pos, v);
        pushup(rt);
    }
    ll query(int rt, int l, int r, int L, int R)
    {
        if (L <= l && r <= R) return T[rt];
        pushdown(rt);
        int mid = (l + r) >> 1;
        ll res = 1e18;
        if (L <= mid) res = min(res, query(lson, l, mid, L, R));
        if (mid <  R) res = min(res, query(rson, mid + 1, r, L, R));
        return res;
    }
}dp[3];
int main()
{
    int n, q; scanf("%d%d", &n, &q); n++;
    int A, B; scanf("%d%d", &A, &B);
    for (int i = 1; i <= q; i++) scanf("%d", &x[i]);
    for (int i = 1; i <= n; i++) y[i] = INF;
    y[A] = abs(x[1] - B); 
    y[B] = abs(x[1] - A);
    dp[0].build(1, 1, n, 0);
    dp[1].build(1, 1, n, 1);
    dp[2].build(1, 1, n, -1);
    for (int i = 2; i <= q; i++)
    {
        ll res = dp[1].query(1, 1, n, x[i] + 1, n) - x[i];
        res = min(res, dp[2].query(1, 1, n, 1, x[i]) + x[i]);
        dp[0].modify(1, 1, n, 1, n, abs(x[i - 1] - x[i]));
        dp[0].modify_p(1, 1, n, x[i - 1], res);
        dp[1].modify(1, 1, n, 1, n, abs(x[i - 1] - x[i]));
        dp[1].modify_p(1, 1, n, x[i - 1], res + x[i - 1]);
        dp[2].modify(1, 1, n, 1, n, abs(x[i - 1] - x[i]));
        dp[2].modify_p(1, 1, n, x[i - 1], res - x[i - 1]);
    }
    printf("%lld\n", dp[0].query(1, 1, n, 1, n));
    return 0;
}

Measured memory_bytes: 40064
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int asc(const void* a, const void* b) {
	return *(int*)a- *(int*)b;
}

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (c - a + b < 0) {
		cout << 0 << endl;
	}
	else {
		cout << c - a + b << endl;
	}
}

Measured memory_bytes: 256
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	s_list = list(S())
	ans = ''
	for s in s_list:
		if s == 'B':
			if len(ans) > 0:
				ans = ans[:-1]
		else:
			ans += s
	print(ans)


if __name__ == '__main__':
    main()

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

int main()
{
  int i,N;
  int k;
  int sum;
  int min;
  vector<int> P;
  sum=1;
  cin >> N;
  for( i=0;i<N;i++)
  {
    cin >>k;
    P.push_back(k);
  }
  min=P[0];
  for( i=1;i<N;i++)
  {  
    if(P[i]<min)
     {
        min=P[i];
        sum++;
     }
  }
  cout << sum<<endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <string>
#include <stack>
#include <cstdlib>

using namespace std;

int main()
{
  stack<int> num;
  string s;
  int a, b;
  while(cin >> s){
    if(s >= "0")
      num.push(atoi(s.c_str()));
    else if(s == "+" || s == "-" || s == "*"){
      a = num.top();
      num.pop();
      b = num.top();
      num.pop();
      if(s == "+")
	num.push(a + b);
      else if(s == "-")
	num.push(b - a);
      else
	num.push(a * b);
    }
  }
  cout << num.top() << endl;
 }

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> cnt(N+1,0);
  for(int i=1;  i<=N; i++){
    for(int j=1; j<=N; j++){
      int d = abs(i-j);
      d = min(d, abs(X-i)+abs(Y-j)+1);
      d = min(d, abs(Y-i)+abs(X-j)+1);
      cnt[d]++;
    }
  }
  for(int i=1; i<=N-1; i++){
    cout << cnt[i]/2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
l=list(map(int,input().split()))
m=0
zf=0
for i in range(n):
    if l[i]==0:
        zf=1
if zf==0:
    l.append(0)
    l.sort()
else:
    k-=1
if k==0:
    print(0)
    exit()
n=len(l)
pl=[]
nl=[]
for i in range(n):
    if l[i]==0:
        m=i
    elif l[i]>0:
        pl.append(l[i])
    else:
        nl.append(-l[i])
        
ans=1e10
for i in range(min(k-1,len(pl))):
    a=len(nl)-k+i+1
    if a>=0 and a<len(nl):
        ans=min(ans,2*pl[i]+nl[len(nl)-k+i+1])
for i in range(min(k-1,len(nl))):
    a=len(nl)-i-1
    b=k-i-2
    if b>=0 and b<len(pl):
        ans=min(ans,2*nl[a]+pl[k-i-2])
if k<=len(pl):
    ans=min(ans,pl[k-1])
if k<=len(nl):
    ans=min(ans,nl[len(nl)-k])
print(ans)




Measured memory_bytes: 14172
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 25
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
  scanf("%d",&head);
  RI(tail...);
}
using namespace std;
typedef long long LL;
int in[M];
int main()
{ 
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> in[i];
	int ans = 0;
	for(int i = 1; i < n-1; i++) {
		if(in[i-1] > in[i] && in[i] > in[i+1] ) ans++;
		else if(in[i-1] < in[i] && in[i] < in[i+1] ) ans++;
	}
	cout << ans << endl;
  return 0;
}


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

int main() {
	string s; cin >> s;
	string ans = "AC";
	int L = s.size();

	if (s[0] != 'A') ans = "WA";

	int cnt = 0;
	for (int i = 1; i < L; i++) {
		if (isupper(s[i])) {
			if (i == 1 || i == L - 1 || s[i] != 'C') {
				ans = "WA";
			}
			cnt++;
		}
	}

	if (cnt != 1) ans = "WA";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

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

    vector<bool> dp(X + 105);

    dp[0] = true;

    for (int i = 0; i < X; i++) {
        if (dp[i]) {
            dp[i + 100] = dp[i + 101] = dp[i + 102] = dp[i + 103] =
                dp[i + 104] = dp[i + 105] = true;
        }
    }

    cout << dp[X] << endl;
    return 0;
}

Measured memory_bytes: 3556
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Node{
public:
	int color{-1};
	int room{-1};
};

class Edge{
public:
	int start,end;
	int sc,ec;
};

vector<Edge> edge;

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

bool DFS(vector<Node>& node,ConnectNodeInfo& connect,int index){
	bool result = true;
	int color = node[index].color==1? 0 : 1;
	for(int i=0,ei=connect[index].size();i<ei;i++){
		int connect_index = connect[index][i].first;
		//node[connect_index].color = color;
		if(node[connect_index].color!=-1 && node[connect_index].color==node[index].color){
			return false;
		}
		if(node[connect_index].color==-1){
			Edge e;
			e.start=index,e.end=connect_index;
			edge.emplace_back(e);
			node[connect_index].color = color;
			result &= DFS(node,connect,connect_index);
		}
	}
	return result;
}

class WarshallFloyd{
	vector<vector<ll>> dist;
public:
	void CalcShortestPath(ConnectNodeInfo& connect){
		int V = connect.size();
		dist.resize(V,vector<ll>(V,1LL<<60));

		REP(i,V){
			dist[i][i]=0;
			int U = connect[i].size();
			REP(j,U){
				dist[i][connect[i][j].first] = connect[i][j].second;
			}
		}

		REP(k,V){
			REP(i,V){
				REP(j,V){
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
	}
	ll CalcDiameter(){
		ll diameter = -(1LL<<60);
		int V = dist.size();
		REP(i,V){
			REP(j,V){
				if(dist[i][j]<1LL<<60){
					diameter = max(diameter,dist[i][j]);
				}
			}
		}
		return diameter;
	}
};

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

	int N=in();
	ConnectNodeInfo connect(N);
	REP(i,N){
		string S=in<string>();
		for(int j=1+i;j<N;j++){
			if(S[j]=='1') connect.AddNonDirectionalConnection(i,j,1);
		}
	}
	vector<Node> node(N);
	node[0].color = 0;
	bool result = DFS(node,connect,0);
	if(!result){
		out(-1);
		return 0;
	}

	WarshallFloyd WF;
	WF.CalcShortestPath(connect);

	out(WF.CalcDiameter()+1LL);
	return 0;
}


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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

const int N = 200500;
stack <char> q;
string s;

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	srand(time(NULL));

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	//cout << setprecision(5) << fixed;
	cin >> s;

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'S'){
			q.push(s[i]);
		}
		else
		{
			if (!q.empty() && q.top() == 'S'){
				q.pop();
			}
			else                           {
				q.push(s[i]);
			}
		}
	
	}

	cout << q.size() << endl;;
		

	return 0;
}

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

long long gcd(long long a, long long b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

long long lcm(long long a, long long b)
{
    return a * b / gcd(a, b);
}

void solve(long long A, long long B){
  cout << lcm(A, B) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Work[] work = new Work[N];
		Main main = new Main();
		for (int i=0;i<N;i++) {
			Work temp = main.new Work();
			temp.a = sc.nextLong();
			temp.b = sc.nextLong();
			work[i] = temp;
		}
		Arrays.sort(work);
		long now =0;
		for (int i=0;i<N;i++) {
			now+=work[i].a;
			if (now>work[i].b) {
				System.out.println("No");
				return ;
			}
		}
		System.out.println("Yes");
	}

	public class Work implements Comparable<Work> {
		long a;
		long b;
		@Override
		public int compareTo(Work o) {
			if (this.b>o.b)
				return 1;
			if (this.b==o.b) {
				return 0;
			}
			return -1;
		}

	}
}

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

using namespace std;
#define ll long long
int main()
{
   int n,m;
   cin>>n>>m;
   vector<ll>h(n);
   for (int i=0;i<n;i++)
    cin>>h[i];
    vector<bool>b(n,1);
   int ans=n;
   for (int i=0;i<m;i++)
   {
       int u,v;
       cin>>u>>v;
       v--,u--;
       if (h[v]>=h[u])
       {
           if (b[u]==1)
            ans--;
           b[u]=0;
       }
       if (h[v]<=h[u])
       {
           if (b[v]==1)
            ans--;
           b[v]=0;
       }
   }
   cout<<ans;
   return 0;
}


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

int main() {
	int a;
	while (cin>>a,a) {
		int b = a*(a - 1) / 2;
		b = a*(a - 1) / 2;
		int x = 0;
		for (int c = 0; c < b; c++) {
			int d;
			cin >> d;
			x += d;
		}
		cout << x / (a-1) << endl;
	}
}

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

void maxHeapify(int H, int A[], int i){
    int l = 2*i;//left
    int r = 2*i + 1;//right
    //左の子、自分、右の子で最大を選ぶ
    int largest;
    if(l <= H && A[l] > A[i]){
        largest = l;
    } else {
        largest = i;
    }
    if(r <= H && A[r] > A[largest]){
        largest = r;
    }

    if(largest != i){//iの子の方が大きい
        int p = A[i];
        A[i] = A[largest];
        A[largest] = p;
        maxHeapify(H, A, largest);
    } 
};

void buildMaxHeap(int H, int A[]){
    for(int i = H/2; i > 0; i--){
        maxHeapify(H, A, i);
    }
};

int main(){
    int H;
    cin >> H;
    int A[H+1];
    for(int i=1; i<=H; i++){
        cin >> A[i];
    }
    buildMaxHeap(H, A);

    for(int j=1; j<=H; j++){
        cout << " " << A[j];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4940
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long N;
    cin >> N;
    long long min_num = 2000000000000000;
    for(int i=0;i<5;i++){
        long long num;
        cin >> num;
        min_num = min(min_num,num);
    }
    long long ans = (N + min_num - 1) / min_num + 4;
    cout << ans << endl;
}


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

const ll MOD = 1000000007LL;

int main(){
    ll x, y;
    cin >> x >> y;

    ll cnt = 0;
    while(x <= y){
        x *= 2;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535
typedef tree<ll, null_type, less<ll>, rb_tree_tag,                    //if  using ll change ll to ll
        tree_order_statistics_node_update> pbset;
#define fob(x) find_by_order(x)
ll po(ll x)
{
	ll ans = 1;
	for (int i = 1; i <= x; i++)
	{
		ans *= 2;
		ans %= mod;
	}
	ans--; ans += mod; ans %= mod;
	return ans;
}
int main()
{
	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

	ll n;
	cin >> n;
	ll a[n + 1]; ll b[n + 1];
	map<pair<ll, ll>, ll> mp; mp[mk(0, 0)] = 0;
	for (ll i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i];
	}
	for (ll i = 1; i <= n; i++)
	{
		if (a[i] == 0 && b[i] == 0)
		{

			mp[mk(0, 0)]++;
			continue;
		}
		else if (a[i] == 0)
		{
			auto it = mp.find(mk(0, 1));
			if (it == mp.end())
				mp[mk(0, 1)] = 1;
			else
				mp[mk(0, 1)]++;
			continue;
		}
		else if (b[i] == 0)
		{
			auto it = mp.find(mk(1, 0));
			if (it == mp.end())
				mp[mk(1, 0)] = 1;
			else
				mp[mk(1, 0)]++;
			continue;
		}
		ll c = __gcd(abs(a[i]), abs(b[i]));
		a[i] /= c;
		b[i] /= c;
		int y1 = 1; int y2 = 1;
		if (a[i] < abs(a[i]))
			y1 = -1;
		if (b[i] < abs(b[i]))
			y2 = -1;
		if (y1 * y2 > 0)
		{
			a[i] = abs(a[i]);
			b[i] = abs(b[i]);
			auto it = mp.find(mk(a[i], b[i]));
			if (it == mp.end())
				mp[mk(a[i], b[i])] = 1;
			else
				mp[mk(a[i], b[i])]++;
		}
		else
		{
			a[i] = abs(a[i]); a[i] *= -1;
			b[i] = abs(b[i]);
			auto it = mp.find(mk(a[i], b[i]));
			if (it == mp.end())
				mp[mk(a[i], b[i])] = 1;
			else
				mp[mk(a[i], b[i])]++;
		}
	}
	ll ans = 1;
	auto it = mp.begin();
	for (; it != mp.end(); it++)
	{
		//cout << ans << "d ";
		ll cc = it->ss;
		ll aa = it->ff.ff;
		ll bb = it->ff.ss;
		if (aa == 0 && bb == 0)
			continue; //cout << cc << endl;
		if (cc == 0)
			continue;
		else
		{
			it->ss = 0;

			//cout << aa << " " << bb << " " << cc << endl;
			aa = abs(aa);
			bb = abs(bb);
			swap(aa, bb);
			if (it->ff.ff > 0)
				aa *= -1;
			auto itr = mp.find(mk(aa, bb));
			if (itr == mp.end())
			{
				ll ans1 = po(cc); ans1++;
				//cout << ans1 << endl;
				ans1 %= mod;
				ans *= ans1;
				ans %= mod;
			}
			else
			{

				ll g = itr->ss; itr->ss = 0;
				ll ans1 = po(cc) + po(g);
				ans1++;
				ans1 %= mod;
				ans *= ans1;
				ans %= mod;
			}

		}

	}
	//cout << ans << endl << mp[mk(0, 0)] << endl;
	ans += mp[mk(0, 0)];
	ans--;
	ans += mod;
	ans %= mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 19244
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<char> Aij(H * W);
    set<int> keyBlacks;
    for(int row = 0; row < H; ++row){
        for(int col = 0; col < W; ++col){
            cin >> Aij[row * W + col];
            if(Aij[row * W + col] == '#')
            {
                keyBlacks.insert(row * W + col);
            }
        }
    }

    int count = 0;
    for(;;){
/*
        for(int i = 0; i < H; ++i){
            for(int j = 0; j < W; ++j){
                cout << Aij[i * W + j];
            }
            cout << endl;
        }
        cout << endl;
*/
        set<int> nextKeys;
        for(const int key : keyBlacks){
            // 上側
            if(key >= W && Aij[key - W] == '.'){
                nextKeys.insert(key - W);
            }
            // 下側
            if(key < W * (H - 1) && Aij[key + W] == '.'){
                nextKeys.insert(key + W);
            }
            // 左側
            if(key % W != 0 && Aij[key - 1] == '.'){
                nextKeys.insert(key - 1);
            }
            // 右側
            if(key % W != W - 1 && Aij[key + 1] == '.'){
                nextKeys.insert(key + 1);
            }
        }

        if(nextKeys.empty()){
            break;
        }
        for(const int i : nextKeys){
            Aij[i] = '#';
        }
        keyBlacks = nextKeys;
        ++count;
    }
    cout << count;

    return 0;
}

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

const int MOD = 1000000007;
string s;

void add(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

int main() {
    cin >> s;
    int n = (int)s.size();
    
    // 累積和
    vector<int> sum(n+1, 0);
    for (int i = 0; i < n; ++i) {
        int par = (s[i] == 'a' ? 1 : 2);
        sum[i+1] = (sum[i] + par) % 3;
    }
    
    // 次の累積和が「０」「１」「２」になる瞬間の切れ目
    vector<vector<int> > next(n+1, vector<int>(3, n+1));
    for (int i = n-1; i >= 0; --i) {
        next[i][sum[i+1]] = i+1;
        for (int j = 0; j < 3; ++j) next[i][j] = min(next[i][j], next[i+1][j]);
    }
    
    // 次の「同じ文字 2 連続」を含む切れ目
    vector<int> next2(n+1, n);
    for (int i = n-2; i >= 0; --i) {
        if (s[i] == s[i+1]) next2[i] = i+1;
        else next2[i] = min(next2[i], next2[i+1]);
    }
    
    // DP
    vector<long long> dp(n+1, 0);
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        add(dp[i+1], dp[i]);
        int ne = next[next2[i]][(sum[i]+(s[i]=='a'?2:1))%3];
        if (ne <= n) add(dp[ne], dp[i]);
    }
    
    // res
    long long res = 0;
    if (next2[0] == n) res = 1;
    else {
        for (int i = 1; i <= n; ++i) {
            if (sum[i] == sum[n]) add(res, dp[i]);
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std ;
#define rep(i,a,n) for(int i =a;i<n;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	ios;
	int n,m;
    float s=0;
    cin>>n>>m;
    int a[n],cnt=0;
    rep(i,0,n)
	{
	 cin>>a[i];
	 s+=a[i];
	}
    s/=(4*m);
	rep(i,0,n)
	{
	 if(a[i]>=s)
	{cnt++;
	}
     if(cnt==m)
    {
	 cout<<"Yes"<<endl;
     break;
	}
     if(i==n-1)
	{
	 cout<<"No"<<endl;
    }
	}
	return 0;	
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

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

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = r / d - (l - 1) / d;
    cout << ans << endl;
}

Measured memory_bytes: 3588
n,m = map(int,input().split())
li = ['NO']*n
wa = [0]*n
ac = [0]*n

for _ in range(m):
    p,s = input().split()
    p = int(p) - 1
    if s == 'WA':
        if li[p] != 'AC':
            li[p] = 'WA'
            wa[p] += 1
    else:
        if li[p] != 'AC':
            li[p] = 'AC'
            ac[p] += 1

wa1 = 0
for i in range(n):
    if ac[i]:
        wa1 += wa[i]

print(sum(ac),wa1)


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

int main(){
  int K;
  string str;
  cin >> K >> str;
  int s = str.size();
  if(K >= s){
    for(int a = 0; a < s; a++){
      cout << str.at(a);
    }
    cout << endl;
  }else if(K < s){
    for(int b = 0; b < K; b++){
      cout << str.at(b);
    }
   cout << "..." << endl;
  }
}

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

int main(){
  ll n,mx=0;
  ll a[200009];
  cin>>n;
  for(ll i=0;i<n;i++){
    cin>>a[i];
    mx=max(mx,a[i]);
    mp[a[i]]++;
  }
  mx*=2;
  sort(a,a+n);
  reverse(a,a+n);

  ll cnt=0;
  for(ll i=0;i<n;i++){
    if(mp[a[i]]==0)continue;
    mp[a[i]]--;
    for(ll j=2;j<=mx;j*=2){
      if(j>=a[i]&&mp[j-a[i]]>0){
	cnt++;
	mp[j-a[i]]--;
      }
    }
  }
  cout<<cnt<<endl;
  return(0);
}


Measured memory_bytes: 40192
import java.util.*

fun main(args: Array<String>) {
    val (H, N) = readIntList()
    val list = Array(N) { readIntList().toPair() }.sortedBy { it.first }

    val mp = IntArray(H + 1) { Int.MAX_VALUE }
    mp[0] = 0
    for (h in 0 until H) {
        if (mp[h] == Int.MAX_VALUE) continue
        for ((a, b) in list) {
            val tag = if (h+a > H) H else h+a
            mp[tag] = Math.min(mp[tag], mp[h]+b)
        }
    }

    println(mp[H])
}

fun readString() = readLine()!!
fun readStringList() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun <E> List<E>.toPair() = this[0] to this[1]

Measured memory_bytes: 40640
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include <bits/stdc++.h>
#define ll long long
#define read(x) scanf("%d",&x)
using namespace std;
const int maxn = 1e5 + 10;

int n;
int k,q;
int a[maxn];

int main()
{   
	cin>>n>>k>>q;
	int x;
	int m = q;
	while(q--){
		read(x);
		a[x]++;
	}
	for(int i=1;i<=n;i++){
		if(k-m+a[i]>0){
			puts("Yes");
		}else{
			puts("No");
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second

const int mod = 1e9+7;
ll inv(int x){
    ll now = x;
    ll ret = 1;
    ll p = 1e9 + 5;
    while(p){
        if(p&1){
            ret *= now;
            ret %= mod;
        }
        now *= now;
        now %= mod;
        p >>= 1;
    }
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    while(cin >> n){
        map<int,int>mp;
        vector<ll>v(n);
        for(auto &i:v){
            cin >> i;
        }
        for(auto i:v){
            for(int j = 2 ; j <= sqrt(i) ; j++){
                if(i%j)continue;
                int cnt = 0;
                while(i % j == 0){
                    i /= j;
                    cnt++;
                }
                mp[j] = max(mp[j], cnt);
            }
            if(i >1){
                mp[i] = max(mp[i],1);
            }
        }
        ll tot = 1;
        for(auto i:mp){
            while(i.S--){
                tot *= i.F;
                tot %= mod;
            }
        }
        ll sum = 0;
        for(auto i:v){
            sum += tot * inv(i);
            sum %= mod;
        }
        cout << sum << '\n';
    }
}

Measured memory_bytes: 768
#include<stdio.h>
int main()
{
	int a,b,r;
	char op;
	while(op!='?'){
	scanf("%d %c %d",&a,&op,&b);

		if(op=='+')
		{	r=a+b;
			printf("%d\n",r);

		}
		else if(op=='-')
		{
			r=a-b;
			printf("%d\n",r);
		}
		else if(op=='*')
		{
			r=a*b;
			printf("%d\n",r);

		}
		else if
			(op=='/')
		{r=a/b;
			printf("%d\n",r);
		}
	}return 0;


}



Measured memory_bytes: 2000
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
int main(void){
	ll x,y;
	cin>>x>>y;
	y/=x;
	ll ans=0,z=1;
	while(y>=z){
		ans++;
		z*=2;
	}
	cout<<ans<<endl;
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C;
    cin>>A>>B>>C;
  vector<int> vec={A,B,C};


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

  cout<<vec.at(2)*10+vec.at(1)+vec.at(0)<<endl;
}

Measured memory_bytes: 256
int main(){
	int n,x,count,i,j,k;
	while (1){
		scanf("%d %d",&n,&x);
		if (n==0) break;
		count=0;
		for (i=1;i<n-1;i++){
			for (j=i+1;j<n;j++){
				for (k=j+1;k<n+1;k++){
					if (i+j+k==x) count+=1;
				}
			}
		}
		printf("%d\n",count);
	}
	return 0;	
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;

int main()
{
    string s, t,x,s1;
    vector<string> vs;
    cin >>s>>t;
    string ans="UNRESTORABLE";
    if(s.size()<t.size()){
        cout <<ans <<endl;
    }
    else{
        for(int i=0;i<s.size();i++){
            x =s.substr(i,t.size());
        
        bool can=true; 
        for(int j=0;j<t.size();j++){
            if(x[j] !=t[j] && x[j] !='?'){
                can =false;
            }
        }
        if(can) {
            s1=s;
            s1.replace(i,t.size(),t);
            for(int j=0;j<s1.size();j++){
                if(s1[j] =='?') s1[j] ='a';
            }
            vs.push_back(s1);
        }
        }
        if(vs.size()){
            sort(vs.begin(),vs.end());
            cout <<vs.front()<<endl;
        }
        else    cout <<ans <<endl;
    }
    return 0;
}

Measured memory_bytes: 256