akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define im 2147483647
#define lm 9223372036854775807
#define ll long long
#define vb vector<bool>
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vector<int>>
#define ii pair<int, int>
#define lower_str(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define upper_str(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define debug(index, num) cout << "Case #" << index << ": " << num << endl
#define mx(an, na) an = max(an, na)
#define mn(an, na) an = min(an, na)
#define rep(i, a, b) for (long long i = a; i < b; i++)
#define rep2(i, a, b) for (long long i = a; i <= b; i++)
#define repp(i, a, b) for (long long i = a; i >= b; i--)
#define repp2(i, a, b) for (long long i = a - 1; i >= b; i--)
#define be(x) x.begin(), x.end()
#define rbe(x) x.rbegin(), x.rend()
#define pb push_back   

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    int n;
    cin >> n >> s;
    int ans = 0;
    rep(i, 2, n) {
        if(s[i] == 'C' && s[i-1] == 'B' && s[i-2] == 'A') ans++;
    }
    cout << ans;
    return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template <typename T1, typename T2> 
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  set<char> st;
  rep(i, s.size()) { st.insert(s[i]); }
  if(st.size() == s.size())
    cout << "yes" << endl;
    else
      cout << "no" << endl;
    return 0;
}


Measured memory_bytes: 3620
#include  <bits/stdc++.h>
using namespace std;
int main()
{
  int h,n,sum=0;
  cin>>h>>n;
  vector<int>vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
    sum+=vec.at(i);
}
  if(h>sum)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
  
}

Measured memory_bytes: 640
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end());

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    string s;
    cin>>s;
    REP(i,s.size()-8)cout<<s[i];cout<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio> 
#include<cstring>
using namespace std;
int n,m,a[333][333],mx,ans,num[333],mxi;
bool used[333];
int main()
{
	ans=1e9;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		scanf("%d",&a[i][j]); 
	} 
	for (int i=1;i<=m;i++)
	{
		memset(num,0,sizeof(num));
		for (int j=1;j<=n;j++)
		{
			for (int k=1;k<=m;k++)
			{
				if (!used[a[j][k]]) 
				{
					num[a[j][k]]++;
					break;
				}
			}
		}
		mx=0;
		for (int j=1;j<=m;j++)
		{
			if (num[j]>mx) 
			{
				mx=num[j];
				mxi=j;
			}
		}
		ans=min(ans,mx);
		used[mxi]=1;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 640
import sys


def input():
    return sys.stdin.readline().strip()

def main():

    # i have too make index as weight and value as value
    import numpy as np

    n, capacity = map(int, input().split())
    value_max = 10 ** 5
    dp = np.full(value_max + 1, capacity + 1)
    dp[0] = 0

    for i in range(n):
        w, v = map(int, input().split())
        np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])

    print(np.where(dp <= capacity)[0][-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 14836
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <list>
#include <stack>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

#define dump(x) cout << (x) << endl;
typedef long long Int;

Int mod = 1e9+7;
Int MOD = 998244353;

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    for (Int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    int dp[41][401][401] = {};
    for (Int i = 0; i <= n; i++) {
        for (Int j = 0; j <= 400; j++) {
            for (Int k = 0; k <= 400; k++) {
                dp[i][j][k] = 1e9;
            }
        }
    }
    dp[0][0][0] = 0;
    for (Int i = 0; i < n; i++) {
        for (Int j = 0; j < 400; j++) {
            for (Int k = 0; k < 400; k++) {
                if (dp[i][j][k] == 1e9) continue;
                dp[i+1][j][k] = min(dp[i][j][k], dp[i+1][j][k]);
                dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
            }
        }
    }
    int res = 1e9;
    for (Int i = 1; i <= 400; i++) {
        for (Int j = 1; j <= 400; j++) {
            if (i*mb == j*ma) res = min(res, dp[n][i][j]);
        }
    }
    dump(res == 1e9 ? -1 : res);
    return 0;
}  

Measured memory_bytes: 25984
#include <iostream>
#include <string>
#include <vector>

using namespace std;

const string APPROVED   = "APPROVED";
const string DENIED     = "DENIED";

bool IsApproved( vector<int> &vec )
{
    for (auto &data : vec) {
        if (data % 2 == 0 ) {
            if ( ( data % 3 != 0 ) &&
                 ( data % 5 != 0 ) ) {
                 return false;
             }
        }
    }
    return true;    
}

int main()
{
    int num;
    vector<int> datalist;

    cin >> num;
    datalist.resize(num);
    for (auto i = 0; i < num; i++) 
    {
        cin >> datalist[i];
    }

    if ( IsApproved( datalist ) ) {
        cout << APPROVED << endl;
    }
    else {
        cout << DENIED << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

template<typename T> map<T, int> prime_factorize(T N) {
  map<T, int> res;
  for (T a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    T ex = 0;

    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    res[a] = ex;
  }

  if (N != 1) res[N] = 1;
  return res;
}

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

  ll n,p; cin >> n >> p;
  ll ans = 1;
  auto fac = prime_factorize(p);
  for(auto& f:fac) {
    for(int i = 0; i < f.second / n; ++i) {
      ans *= f.first;
    }
  }
  cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    int a[n],sum=0;
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
    }
    cout << sum-n << endl;
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        uf.union(a-1, b-1)
    ans = 0
    for i in range(n):
        x = uf.size(i)
        if ans < x:
            ans = x
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14396
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  i64 r, d, x;
  cin >> r >> d >> x;
  F0R(i, 10) {
    x = r * x - d;
    cout << x << newl;
  }
}
#endif


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int fare[101][101], dist[21][101][101];
int cost[101];
int P[21];
int N, M, C, S, G;
typedef pair<int, int> pint;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M >> C >> S >> G && N){
        S--; G--;
        rep(i, 21) rep(j, 101) rep(k, 101) dist[i][j][k] = INF;
        rep(i, 21) rep(j, 101) dist[i][j][j] = 0;
        rep(i, 101) rep(j, 101) fare[i][j] = INF;
        rep(i, 101) fare[i][i] = 0;
        int x_, y_, d_, c_;
        rep(i, M){
            cin >> x_ >> y_ >> d_ >> c_;
            x_--; y_--; c_--;
            dist[c_][x_][y_] = dist[c_][y_][x_] = min(dist[c_][x_][y_], d_);
        }
        rep(c, C) rep(k, N) rep(i, N) REP(j, i + 1, N)
          dist[c][j][i] = dist[c][i][j] = min(dist[c][i][j], dist[c][i][k] + dist[c][k][j]);
        rep(c, C) cin >> P[c];
        rep(c, C){
            vector<int> Q(P[c] + 1, INF), R(P[c]), f(P[c]);
            REP(i, 1, P[c]) cin >> Q[i];
            Q[0] = 0;
            rep(j, P[c]) cin >> R[j];
            f[0] = 0;
            REP(i, 1, P[c]) f[i] = R[i - 1] * (Q[i] - Q[i - 1]) + f[i - 1];
            rep(i, N - 1) REP(j, i + 1, N){
                if(dist[c][i][j] == INF) continue;
                int it = lower_bound(Q.begin(), Q.end(), dist[c][i][j]) - Q.begin();
                it--;
                int temp = f[it] + R[it] * (dist[c][i][j] - Q[it]);
                fare[i][j] = fare[j][i] = min(fare[i][j], temp);
            }
        }
        priority_queue<pint, vector<pint>, greater<pint> > que;
        fill(cost, cost + N, INF);
        cost[S] = 0;
        que.push(pint(0, S));
        while(!que.empty()){
            pint now = que.top(); que.pop();
            int v = now.second;
            if(cost[v] < now.first) continue;
            rep(i, N){
                if(fare[v][i] == INF || v == i) continue;
                if(cost[i] > cost[v] + fare[v][i]){
                    cost[i] = cost[v] + fare[v][i];
                    que.push(pint(cost[i], i));
                }
            }
        }
        int ans = cost[G];
        if(ans == INF) ans = -1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2188
# https://atcoder.jp/contests/agc038/tasks/agc038_a

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    h, w, a, b = input_int_list()
    grid = []
    for i in range(h):
        if i < b:
            grid.append("1" * a + "0" * (w - a))
        else:
            grid.append("0" * a + "1" * (w - a))
    for line in grid:
        print(line)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 71188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		int max = -1;
		for(int i = 0 ; i < n ; i++) {
			max = Math.max(max, a[i]);
		}
		int gcd = 0;
		for(int i = 0 ; i < n ; i++) {
			gcd = gcd(a[i], gcd);
		}
		System.out.println(max >= k && k % gcd == 0 ? "POSSIBLE" : "IMPOSSIBLE");
	}

	static int gcd(int x, int y) {
		while(y > 0) {
			int w = x;
			x = y;
			y = w % y;
		}
		return x;
	}

}


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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

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

    int n, m, x;
    cin >> n >> m >> x;

    vector<vector <int>> book(n);

    for(int i = 0; i < n; i++){
        int c;
        cin >> c;
        book[i].push_back(c);
        for(int j = 0; j < m; j++){
            int a;
            cin >> a;
            book[i].push_back(a);
        }
    }

    int sol = mod;
    for(int b = 0; b < (1<<n); b++){
        vi subset;
        vi alg(m);
        for(int i = 0; i < n; i++){
            if (b & (1 << i)) subset.push_back(i);
        }
        int price = 0;
        for(int y : subset){
            price += book[y][0];
            for(int i = 1; i <= m; i++){
                alg[i - 1] += book[y][i];
            }
        }
        bool check = true;
        for(int i = 0; i < m; i++){
            if(alg[i] < x)
                check = false;
        }
        if(check)
            sol = min(sol, price);
    }
    if(sol == mod)
        cout << -1;
    else
        cout << sol;
}

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    while (n > 0) {
        n /= k;
        ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#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 <fstream> //ofstream
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int ans,data1,data2;
void solve(){
        if(data1==1||data2==1) {
                if(data1==2||data2==2) {
                        cout<<"3"<<endl;
                }
                if(data1==3||data2==3) {
                        cout<<"2"<<endl;
                }
        }
        if(data1==2||data2==2) {
                if(data1==3||data2==3) {
                        cout<<"1"<<endl;
                }
        }
}

int main(){

        cin>>data1>>data2;

        solve();
        return 0;
}


Measured memory_bytes: 504
[K,S]=list(map(int,input().split()
              )
          )
goukei=0
for x in range(K+1):
  for y in range(K+1):
    z=S-x-y
    if z<K+1 and z>=0:
      #print(x,y,z)
      goukei=goukei+1

print(goukei)

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

color = [1] * n
for i in range(n):
    if i == 0:
        continue
    if a[i - 1] * 2 >= a[i]:
        color[i] += color[i - 1]
    a[i] += a[i - 1]

print(color[-1])


Measured memory_bytes: 14252
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()

signed main() {
    int n, x, y;
    cin >> n >> x >> y;

    int a[2001];
    memset(a, 0, sizeof(int) * 2001);
    repeat(i, n) {
        int k = i + 1;
        for (int j = k + 1; j <= n; ++j) {
            int d = min(j - k, abs(x - k) + 1 + abs(y - j));
            ++a[d];
        }
    }

    repeat(i, n - 1) {
        cout << a[i + 1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
struct data{int a;int val;}s[1000];
bool cmp(data aa,data bb){return aa.val<bb.val;}
int n=5,ans=0;
int main()
{
	for(int i=1;i<=5;++i)scanf("%d",&s[i].a),s[i].val=(10-s[i].a%10)%10;
	sort(s+1,s+n+1,cmp);
	for(int i=1;i<=n;++i)ans=ans%10==0?ans:(ans/10+1)*10,ans+=s[i].a;
	printf("%d",ans);
	
 } 

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,x ;
	cin >> x >> n ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	ll ans = -100 ;
	ll d = 1000 ;
	for(int i=-10;i<=110;i++){
		bool ok = true ;
		for(int j=0;j<n;j++) ok &= (i!=a.at(j)) ;
		if(ok){
			if(d>abs(i-x)){
				ans = i ;
				d = abs(i-x) ;
			}
		}
	}
	cout << ans << endl ;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; ++i) cin >> s[i];
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; ++i) cin >> t[i];

  int res = 0;
  for (int i = 0; i < N; ++i) {
    int money = 0;
    string say = s[i];
    for (int j = 0; j < N; ++j) {
      if (s[j] == say) money++;
    }
    for (int j = 0; j < M; ++j) {
      if (t[j] == say) money--;
    }
    res = max(res, money);
  }
  cout << res << endl;
}

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

int main()
{
    ll n,ans=0;  cin>>n;
    map<string,ll> a;  string s;
    for(ll i=0;i<n;++i){
        cin>>s;
        sort(begin(s),end(s));
        a[s]++;
    }
    for(auto x:a) ans+=x.second*(x.second-1)/2;
    cout<<ans<<endl;
}


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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

string field[12];
bool b[12][12];

int f(int x, int y){
	int dx[4] = {1, 0, -1, 0};
	int dy[4] = {0, 1, 0, -1};
	for(int i=0; i< 4; i++){
		int nx = x+dx[i], ny=y+dy[i];
		if(!(0 <= nx && nx < 12 && 0 <= ny && ny < 12)) continue;
		if(field[nx][ny] == '1' && b[nx][ny]){
			b[nx][ny] = false;
			f(nx, ny);
		}
	}
}

int main(){
	while(cin >> field[0]){
		int ret = 0;
		for(int i=0; i <12; i++) for(int j=0; j < 12;j++) b[i][j] = true;
		for(int i=1; i< 12; i++) cin >> field[i];
		for(int i=0; i<12; i++){
			for(int j=0; j < 12; j++){
				if(field[i][j] == '1' && b[i][j]){
					b[i][j] = false;
					f(i, j);
					ret++;
				}
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
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() {
	string s;
	cin >> s;
	if (s == "A")cout << "T" << endl;
	else if (s == "T")cout << "A" << endl;
	else if (s == "C")cout << "G" << endl;
	else cout << "C" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100

int main() {
  int i,j,ryoma,hira,sawa,pine[MAX], m[MAX][MAX],que;
 
  scanf("%d",&sawa);
  
  for ( i = 1; i <= sawa; i++ ) {
    scanf("%d %d",&pine[i-1],&pine[i]);
  }
    
  for ( i = 1; i <= sawa; i++ ) m[i][i] = 0;
  for ( hira = 2; hira <= sawa; hira++ ) {
    for ( i = 1; i <= sawa - hira + 1; i++ ) {
      j = i + hira - 1;
      m[i][j] = 100000000;
      for ( ryoma = i; ryoma <= j - 1; ryoma++ ) {
	que = m[i][ryoma] + m[ryoma + 1][j] + pine[i - 1] * pine[ryoma] * pine[j];
	if(m[i][j] > que) m[i][j] = que; 
      }
    }
  }
  printf("%d\n",m[1][sawa]);  
  return 0;
}

Measured memory_bytes: 636
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール
ll solve(vector<vector<vector<ll>>> &dp, vector<ll> &a, ll l, ll r, ll i) {
    if (l == r) return 0;
    if (dp[l][r][i] != -LINF) return dp[l][r][i];
    const ll sgn = !i ? 1 : -1;
    ll c1 = solve(dp, a, l+1, r, !i) + a[l  ] * sgn;
    ll c2 = solve(dp, a, l, r-1, !i) + a[r-1] * sgn;
    return dp[l][r][i] = !i ? max(c1, c2) : min(c1, c2);
}

// 処理内容
int main() {

    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    
    // dp[l][r][i] := [l,r)が残っててiの番が来た時に達成できるX-Yの最大値
    vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(n+1, vector<ll>(2, -LINF)));
    cout << solve(dp, a, 0, n, 0) << endl;
    
}

Measured memory_bytes: 493056
bingo = [list(map(int,input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
cnt = [0]*8
for i in range(3):
    for j in range(3):
        if bingo[i][j] in b:
            cnt[i] += 1
            cnt[j+3] += 1
            if i == j:
                cnt[-1] += 1
            if i+j == 2:
                cnt[-2] += 1
ans = "No"
for i in cnt:
    if i >= 3:
        ans = "Yes"
        break
print(ans)

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

using namespace std;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(11);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n+1, vector<int>());
  vector<int> deg(n+1, 0);
  for(int i = 0; i < m; i++){
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
  }
  vector<int> dp(n+1, 0);
  vector<int> was(n+1, 0);
  function<int(int)> dfs = [&](int u){
    if(was[u]) return dp[u];
    was[u] = true;
    for(auto v : g[u]){
      dp[u] = max(dp[u], dfs(v) + 1);
    } 
    return dp[u];
  };
  int ans = 0;
  for(int i = 1; i <= n; i++){
    ans = max(ans, dfs(i));
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 9600
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                    cerr<<#x<<": "<<x<<endl
#define trace2(x, y)                 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)                 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)             cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)         cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

ll n,t;
ll ti[M];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> t;
    ll ans=0;
    ll cur=0;
    rep(i,0,n){
        cin >> ti[i];
        if(cur<ti[i]){
            ans+=t;
            cur=ti[i]+t;
        }
        else{
            ll prev=cur;
            cur=ti[i]+t;
            ans+=(cur-prev);
        }
    }
    cout << ans;
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<(n);++i)
#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define out(i) cout<<i<<endl;
#define m_p make_pair
#define m_t make_tuple
#define Vec vector
typedef long long ll;
typedef string str;
typedef vector<int> V;
typedef vector<pair<int,int>> VP;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}
int gcd(int a,int b){if(b==0)return a; return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
const ll INF=1ll<<60;
const ll MOD=1e9+7;

// AOJ Course The Number of Windows

signed main(){
  int n,m;
  cin>>n>>m;
  V a(n),b(m),ans(m,0);
  rep(i,n)cin>>a[i];
  rep(i,m)cin>>b[i];

  rep(i,m){
    int sum=0,right=0;
    for(int left=0;left<n;++left){
      while(right<n&&sum+a[right]<=b[i]){
        sum+=a[right];
        ++right;
      }
      ans[i]+=(right-left);
      if(right==left)right++;
      else sum-=a[left];
    }
  }
  rep(i,m)cout<<ans[i]<<endl;
  
  return 0;
}



Measured memory_bytes: 3576
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	d,g = readline() |> split |> parseMap
	pc = Array{Int}(2,d)
	for i in 1:d
		pc[:,i] = readline() |> split |> parseMap
	end
	minim = 999999999
	pat = 2^d-1
	for i in 0:pat
		count = 0
		point = 0
		k = parseMap(split(bin(i,d),""))
		for j in 1:d
			count += k[j]*pc[1,j]
			point += k[j]*(pc[1,j]*100*j+pc[2,j])
		end
		if point >= g
			minim = min(minim, count)
		else
			x = 0
			for j in 1:d
				if k[j] == 0
					x = j
				end
			end
			add = ceil(Int,(g-point)/(x*100))
			if add < pc[1,x]
				count += add
				minim = min(minim, count)
			end
		end
	end
	print(minim)
end

main()

Measured memory_bytes: 114332
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

int n,m;

string s1,s2;

int main()
{
    cin >> n >> m;
    for (int i=0;i<m;i++)
    {
        s1+=n+'0';
    }
    for (int i=0;i<n;i++)
    {
        s2+=m+'0';
    }
    if(s1<s2)cout << s1 << endl;
    else cout << s2 << endl;
}



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int n;cin>>n;
  vector<int> b(n);
  rep(i,n)cin>>b[i];

  vector<int> result;
  rep(i,n){
    int c=-1;
    rep(j,b.size()){
      if(j+1==b[j] && j+1>c)c=j+1;
    }
    if(c==-1){
      cout<<-1<<endl;
      return 0;
    }
    auto it = b.begin();
    rep(i,c-1)it++;
    b.erase(it);
    result.push_back(c);
  }

  rep(i,n)cout<<result[n-1-i]<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int ans,a,b,n,s[101],tot;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        tot+=s[i];
    }
    b=tot;
    ans=100000;
    for(int i=0;i<n-1;i++){
        a+=s[i];
        b-=s[i];
        ans=min(abs(a-b),ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define NAMELEN 20

typedef struct {
  int number;
  long int mass;
} bigint;

int cmp( const void *p, const void *q ) {
    return ((bigint*)p)->mass - ((bigint*)q)->mass;
}

int main(){
  int N,i;
  scanf("%d",&N);
  bigint X[N];
  for(i=0;i<N;i++){
    scanf("%ld",&X[i].mass);
    X[i].number=i;
  }
  qsort(X, N, sizeof(bigint), cmp );
  long int ans[N];
  for(i=0;i<N;i++){
    if(i<=N/2-1){
      ans[X[i].number]=X[N/2].mass;
    }else{
      ans[X[i].number]=X[N/2-1].mass;
    }
  }
  for(i=0;i<N;i++){
    printf("%ld\n",ans[i]);
  }
  return 0; 
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}



const int MAX_N = 3005;
ll C[MAX_N][MAX_N];
ll choose(int n, int r) {
  return C[n][r];
}

ll mod_pow(ll a, ll b, ll p) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}



int main2() {
  int P = nextLong();
  vector<ll> a(P-1);
  REP(i, P) a[i] = nextLong();

  for (int i = 0; i < MAX_N; i++) {
    for (int j = 0; j <= i; j++) {
      C[i][j] = (j == 0) ? 1 : (C[i-1][j-1] + C[i-1][j]);
      if (C[i][j] >= P) C[i][j] -= P;
    }
  }

  vector<ll> b(P);
  REP(i, P) {
    if (a[i] == 0) continue;
    b[0]++;

    ll jj = 1;
    int sign = 1;
    REP(k, P) {
      sign *= -1;
      b[P-1-k] += (sign * jj * choose(P-1, k)) % P;
      jj *= i;
      jj %= P;
    }
    REP(j, P) {
      b[j] = (b[j] % P + P) % P;
    }
  }

  REP(i, P) {
    if (i) cout << ' ';
    cout << b[i];
  }
  cout << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 49992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> b(9);
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        b[min(a / 400, 8)]++;
    }

    int ans = 0;
    for(int i = 0; i < 8; ++i)
        ans += (b[i] > 0);
    cout << max(ans, 1) << " " << ans + b[8] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
    int n, t=0, h=0;
    char s[101],d[101];
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++)
    {
        scanf("%s %s", s,d);
        
        if (strcmp(s,d)>0)
        {
            t=t+3;
        }
        else if (strcmp(s,d)<0)
        {
            h=h+3;
        }
        else
        {
            t++;
            h++;
        }

    }
printf("%d %d\n",t,h);
return 0;
}



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

#define _GLIBCXX_DEBAC

using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	if (a == b && a != c)ans = 1;
	if (a == c && a != b)ans = 1;
	if (b == c && a != b)ans = 1;
	if (ans) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}









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

int main(){
  int N;
  cin >>N;
  int sum=0;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
    sum += a.at(i);
  }
  int d=1000;
  int x;
  int ans;
  for(int i=0;i<N;i++){
    x=abs(sum-a.at(i)*N);
    if(d > x){
      d = x;
      ans = i;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    int s; cin >> s;
    int h = s/3600;
    int m = (s/60)-(60*h);
    s -= (h*3600 + m*60);
    cout << h << ':' << m << ':' << s << endl;
	return 0;
}



Measured memory_bytes: 3108
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n, k;
	cin >> n >> k;
	VI a(n);
	REP(i, n) { cin >> a[i]; }

	// 0: 0 0 0 0 0 | 1 0 0 0 0 | 2 0 0 0 0 | 1 0 0 1 0
	// 1: 1 1 1 1 1 | 1 2 1 1 1 | 1 2 2 1 1 | 1 2 2 1 2
	// 2: 2 3 3 3 2 | 2 3 3 4 2 | 3 3 3 4 3 | 3 3 4 4 3
	// 3: 4 4 5 4 4 | 4 4 5 4 4 | 4 5 5 5 4 | 4 5 5 5 4
	// 4: 5 5 5 5 5 | 5 5 5 5 5 | 5 5 5 5 5 | 5 5 5 5 5

	REP(i, k) {
		VI b(n + 1, 0);
		REP(j, n) {
			b[max(j - a[j], 0)]++;
			b[min(j + a[j] + 1, n)]--;
		}
		int tmp = 0;
		bool end = true;
		REP(j, n) {
			tmp += b[j];
			a[j] = tmp;
			end = end && a[j] == n;
		}
		if(end) {
			break;
		}
	}

	REP(j, n) { cout << a[j] << " "; }
	cout << endl;
	return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair <ll,ll>
#define vl vector <ll>
#define vp vector <pair<ll,ll>>
#define sort(x) sort(x.begin(), x.end())
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,i,ans =0;
    string s;
    cin>>n>>s;
    for(i=2;i<n;i++)
        if(s[i-2] == 'A' and s[i-1] == 'B' and s[i] == 'C')
            ans++;
    cout<<ans;
    return 0;
}


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

int n;
int a[200000], b[200000];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
  vector<int> v;
  for (int i = 0; i < n; ++i) v.push_back(i);
  sort(v.begin(), v.end(), [](int i, int j) { return b[i] < b[j]; });
  
  long sum = 0;
  bool ok = true;
  for (int i = 0; i < n; ++i) {
    sum += a[v[i]];
    if (sum > b[v[i]]) ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 2936
#include<stdio.h>
int main(){
  char a[110],b[110],k;
  int c,i;
  scanf("%d\n",&c);
  for(i=0;i<c;i++){
    scanf("%c",&a[i]);
  }
  scanf("%c",&k);
  for(i=0;i<c;i++){
    scanf("%c",&b[i]);
  }
  for(i=0;i<c;i++){
    printf("%c%c",a[i],b[i]);
  }
  printf("\n");
  return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<string> c(n); 
  vector<vector<int>> g(n);
  rep(i,n) cin>>c[i];
  rep(i,n)rep(j,n) if(c[i][j]=='1') g[i].pb(j);
  int ans=0;
  
  rep(i,n){
    queue<int> que;
    vector<int> dist(n,-1);
 
    que.push(i);
    dist[i]=1;
    while(!que.empty()){
      int x=que.front();
      que.pop();
      for(auto nx:g[x]){
        if(dist[nx]!=-1) continue;
        que.push(nx);
        dist[nx]=dist[x]+1;
      }
    }
    vector<vector<int>> l(n);
    
    rep(i,n){
      l[dist[i]-1].pb(i);
      ans=max(ans,dist[i]);
    }
    rep(i,n){
      rep(j,(int)l[i].size()) rep(k,(int)l[i].size()){
        if(c[l[i][j]][l[i][k]]=='1'){
          cout<<"-1"<<endl;
          return 0;
        }
      }
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for(int i = 0; i < n; i++)
#define int long long
#define mod 1000000007

int n, t, dp[3001][3001];
pair<int, int> p[30001];

int calc(int idx, int sm) {
        if (idx == n) return 0;
        if (sm <= 0) return 0;
        int &ret = dp[idx][sm];
        if (ret != -1) return ret;
        else ret = 0;
        ret = max(ret, calc(idx + 1, sm - p[idx].first) + p[idx].second);
        ret = max(ret, calc(idx + 1, sm));
        return ret;
}

int32_t main() {
ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
        cin >> n>> t;
        lp(i, 3001) lp(j, 3001) dp[i][j] = -1;
        lp(i, n) {
                int a, b; cin >> a>> b;
                p[i] = {a, b};
        }
        sort(p, p + n);
        cout << calc(0, t);
return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#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 print(s) cout << s << endl
using namespace std;
const int INF = 1e9;
typedef long long lint;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}
 
int main(){
	int N;
	cin >> N;
    string s = "";
    int n = N;
    while(n!=0) {
        if(n%2) {
            s = '1' + s;
            n--;
            n/= -2;
        } else {
            s = '0' + s;
            n/= -2;
        }
    }
    if(N == 0) cout << 0 << endl;
    else cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc153_d
{
  class Program
  {
    static void Main(string[] args)
    {
      var H = CIn.ReadLong();

      Console.WriteLine((long)Math.Pow(2, Math.Floor(Math.Log(H, 2)) + 1) - 1);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => 
      long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(long h, long w)
    {
      var array = new char[h, w];
      for (var i = 0L; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0L; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


Measured memory_bytes: 13268