akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <cassert>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <type_traits>
#include <fstream>
//#include <bits/stdc++.h>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// print(x, y, z);
// printVec(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << *it << " ";
    if ((it - begin) % 20 == 19 || it == end - 1) { std::cout << std::endl; }
  }
}
template<typename Iterator> void printVecPair(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << it->first << " " << it->second << " ";
    if ((it - begin) % 10 == 9 || it == end - 1) std::cout << std::endl;
  }
}

template<typename T> T bitnum(T x)
{
  T cnt = 1;
  T ret = 0;
  while (x > 0) {
    ret += (x % 2) * cnt;
    x /= 2;
    cnt *= 10;
  }
  return ret;
}

template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  std::string s;
  std::cin >> s;
  std::string a, b, c;
  for (ll i = 0; i < 10; i++) {
    if (i < 4) a += s[i];
    if (i == 5 || i == 6) b += s[i];
    if (i == 8 || i == 9) c += s[i];
  }
  ll y = atoi(a.c_str());
  ll m = atoi(b.c_str());
  ll d = atoi(c.c_str());

  std::string judge = "Heisei";
  if (y > 2019) judge = "TBD";
  if (y == 2019 && m > 4) judge = "TBD";
  if (y == 2019 && m == 4 && d > 30) judge = "TBD";
  std::cout << judge << std::endl;

  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc178/tasks/abc178_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll res = a * c;
  chmax(res, a * d);
  chmax(res, b * c);
  chmax(res, b * d);

  cout << res << "\n";
}


Measured memory_bytes: 3632
#include<stdio.h>

int main()
{
	int h, w, i, j;
	char s[300];

	while(1) {
		scanf("%d%d", &h, &w);

		if(h == 0 && w == 0) break;

		for(i = 0; i < h; i++) {
			for(j = 0; j < w; j++) {
				printf((i + j) % 2 == 0? "#" : ".");
			}
			printf("\n");
		}

		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main(void){ 
    int a,b,k;
    cin >> a >> b >> k;
    ll g = gcd(a,b);
    vector<ll> div = divisor(g);
    sort(div.begin(), div.end());
    reverse(div.begin(), div.end());
    int ans = div[k-1];
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
def solve():
	X, N = map(int, input().split())
	arr = set(map(int, input().split()))
	if X not in arr:
		return X
	i = X - 1
	j = X + 1
	while True:
		if i not in arr:
			return i
		else:
			i -= 1
		if j not in arr:
			return j
		else:
			j += 1
		


def main():
	print(solve())


if __name__ == '__main__':
	main()

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

int main()
{
	while (true)
	{
		string s;
		cin >> s;
		if (s == "0")
		{
			return 0;
		}
		int sum = 0;
		for (int i = 0; i < s.size(); i++)
		{
			sum += s[i] - '0';
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;cin >> N;
    int res = 0;
    int diff = 111;
    for(int i=1;i<=9;i++){
        if(N<=diff*i){
            res = diff*i;
            break;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  vector<int> a(2000,0);
  int aa,b,n;
  cin >> aa >> b >> n;
  rep(i,n){
    int f,g;
    cin >> f >> g;
    for(int j=f;j<g;j++){
      a[j]=1;
    }
  }
  bool t=true;
  for (int i=aa;i<b;i++){
    if (a[i]==1) t=false;
  }
  if (t) cout << 0 << endl;
  else cout << 1 << endl;
}



Measured memory_bytes: 3124
//
// ABC163A
// URL : https://atcoder.jp/contests/abc162/tasks/abc163_a
// 
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace AtCoder
{
    class ABC163A
    {
        static void Main(string[] args)
        {
            preprocess();


            // 整数の入力
            long r = long.Parse(Console.ReadLine());

            var ans = r * 2 * Math.PI;

            Console.WriteLine(ans.ToString());
            Console.Out.Flush();
        }

        //---------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        public static void preprocess()
        {
            //出力高速化
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
        }


        /// <summary>
        /// 与えられた数が素数かどうかを計算する
        /// </summary>
        /// <param name="num">対象数</param>
        /// <returns>true:素数, false:素数ではない(合成数)</returns>
        public static bool isPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

        /// <summary>
        /// 順列mPnを計算する
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static long Permutation(long m, long n)
        {
            long ret = 1;
            for(var i = 0; i < n; ++i)
            {
                ret *= m - i;
            }
            return ret;
        }
        /// <summary>
        /// 組み合わせmCnを計算する
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static long Combination(long m, long n)
        {
            if(m == n || n == 0)
            {
                return 1;
            }
            long ans = 1;
            for(var i = 0; i <= n; ++i)
            {
                ans *= (m - i + 1) / i;
            }
            return ans;
        }

        static long Gcd(long m, long n)
        {
            if (n == 0) return m;
            return Gcd(n, m % n);
        }

        static long Lcm(long m, long n)
        {
            var gcd = Gcd(m, n);
            //return (m * n) / gcd;
            return m / gcd * n;//桁あふれ対策
        }
    }
}



Measured memory_bytes: 27444
def main():
    n, T = map(int, input().split())
    c_list = []

    for _ in range(n):
        c, t = map(int, input().split())
        if t <= T:
            c_list.append(c)

    if c_list:
        print(min(c_list))
    else:
        print("TLE")


if __name__ == "__main__":
    main()


Measured memory_bytes: 62560
#include<iostream>
int main()
{
    int a,b,c ;
    std::cin >> a >> b >> c;
    if(a==b and b==c and a==c){
        std::cout<<"No"<<std::endl;
    }
    else if(a!=b and b!=c and a!=c){
        std::cout<<"No"<<std::endl;
    }
    else{
        std::cout<<"Yes"<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
def bellman_ford(vertex_num: int, edges: list, source: int, sink: int) -> list:
    # 1) initialize distance
    distances = [float('inf')] * (vertex_num)
    distances[source] = 0

    # 2) update distances (upto vertex_num-1 times)
    for _ in range(vertex_num):
        for u, v, c in edges:
            distances[v] = min(distances[v], distances[u] + c)

    # 3) detect negative-loop
    for u, v, c in edges:
        if distances[u] + c < distances[v]:
            distances[v] = distances[u] + c

            if v == sink:
                return []

    return distances


def score_attack(N: int, M: int, edges: list) -> int:
    distances = bellman_ford(N, [(u-1, v-1, -c) for u, v, c in edges], 0, N-1)

    return -distances[N - 1] if distances else float('inf')


if __name__ == "__main__":
    M = 0
    N, M = map(int, input().split())
    edges = [tuple(map(int, input().split())) for _ in range(M)]
    ans = score_attack(N, M, edges)
    print(ans)


Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define ll             long long int
#define lb             lower_bound
#define ub             upper_bound
#define fi             first
#define mp             make_pair
#define vll            vector<ll>
#define se             second
#define sz             size()
#define mod            1000000007
#define endl           "\n"
#define fast           ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define allr(v)        v.rbegin(),v.rend()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
               const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.second >b.second);
    }
    else
        return (a.fi<b.fi);
}

int main()
{
     fast;
     int q=1;
   // cin>>q;
     while(q--)
    {
     ll n,i,j,k,m,sum=0,ans=0,a=0,b=0,c=0,d=0,e;
       char ch;
        cin>>ch;
        if(ch>=65 && ch<=90)
            cout<<'A'<<endl;
         else cout<<'a'<<endl;


    }
   return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>
#include <cassert>
#include<map>
#include<bitset>

using lli = long long int;
lli inf = 1000000007;
using namespace std;

void solve() {
	string S;
	cin >> S;
	int c = S.length();
	for (int i = 0; i < c; i++)cout << "x";
	cout << endl;
}

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

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


def count_a(A, X):
    l = -1
    r = N
    while r - l > 1:
        m = (r + l) // 2
        if A[m] < b:
            l = m
        else:
            r = m
    return l + 1


def count_c(C, X):
    l = -1
    r = N
    while r - l > 1:
        m = (r + l) // 2
        if C[m] > b:
            r = m
        else:
            l = m
    return N - r


A.sort()
B.sort()
C.sort()

ans = 0
A_min = A[0]
C_max = C[-1]

for b in B:
    if b <= A_min or b >= C_max:
        continue

    ans += count_a(A, b) * count_c(C, b)

print(ans)


Measured memory_bytes: 23972
#pragma comment(linker, "/STACK:66777216")
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#include<cassert>
#include<bitset>
#include<ctime>
using namespace std;
using ll = long long;

vector<vector<int>> g;

int DFS(int v, int level, int p = -1) {
	int cnt = 1;
	if (level) {
		for (int u : g[v]) {
			if (u != p)
				cnt += DFS(u, level - 1, v);
		}
	}
	return cnt;
}

void Solve() {
	ll n;
	scanf("%lld", &n);
	vector<ll> a(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		sum += a[i];
	}
	if (sum % ((n*(n+1))/2) != 0)
		printf("NO");
	else {
		ll k = sum / ((n*(n+1))/2);
		bool flag = true;
		for (int i = 0; i < n && flag; i++) {
			ll d = a[i] - a[(i+1)%n] + k;
			if (d < 0 || d % n)
				flag = false;
		}
		if (flag)
			printf("YES");
		else
			printf("NO");
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	Solve();

#ifdef LOCAL
	cerr << double(clock()) / CLOCKS_PER_SEC << endl;
#endif

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <cmath>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;


int main(){

    int N, D;
    cin >> N >> D;

    ll x[N][D];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < D; j++){
            cin >> x[i][j];
        }
    }

    ll ans = 0;
    for(int i1 = 0; i1 < N; i1++){
        for(int i2 = i1 + 1; i2 < N; i2++){

            ll dist = 0;
            for(int d = 0; d < D; d++){
                dist += (x[i1][d] - x[i2][d]) * (x[i1][d] - x[i2][d]);
            }

            ll d_route = sqrt( (double)(dist) );
            for(ll i = -1; i <= 1; i++){
                if( (d_route + i) * (d_route + i) == dist  ){
                    ans ++;
                }
            }

        }
    }
    cout << ans << endl;






}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int a,b,c,d;cin>>a>>b>>c>>d;
  int tmp = min(abs(a-b),min(abs(b-c),abs(a-c)));
  if(tmp <= d){
    if(abs(a-c) > d && (abs(a-b) > d || abs(b-c) > d)){
      print("No");
    }else print("Yes");
  }
  else print("No");
  return 0;
}


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

int main() {
  int N, K, res;
  cin >> N >> K;
  res = 1;
  for (int i = 0; i < N; i++){
    int A = res * 2;
    int B = res + K;
    if (A <= B)
      res = A;
    else
      res = B;
  }
  cout << res << endl;
}

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


void solve(long long A, long long B, long long C){
    long long ans = C - (A - B);
    if(ans >= 0) cout << ans << endl;
    else cout << 0 << endl; 
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int> >
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int> >
#define VPII vector<pair<int,int> >

#define INT ll

using namespace std;
/*........................................Define functions.........................................*/


/*....................................Define global variables .....................................*/



/*.........................................kemkemG0................................................*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);


	int K, X;

	cin >> K >> X;

	FOR(i, X - K + 1, X + K - 1) {if(-1000000 <=i && i<=1000000)cout << i << " ";}
	cout << endl;





	return 0;
}




Measured memory_bytes: 3624
use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        n: u64,
    }
    if n == 1 {
        println!("{}", 0);
        return;
    }
    println!(
        "{:?}",
        primal_factorization(n)
            .values()
            .map(|&v| divival(v))
            .fold(0, |sum, x| sum + x)
    );
}

fn primal_factorization(n: u64) -> HashMap<u64, u64> {
    let mut map = HashMap::new();
    let (mut prime, mut remain) = (1, n);
    while prime * prime <= n + prime {
        prime += 1;
        while remain % prime == 0 {
            remain /= prime;
            map.entry(prime).and_modify(|e| *e += 1).or_insert(1);
        }
    }
    if remain > 1 {
        map.entry(remain).and_modify(|e| *e += 1).or_insert(1);
    }
    map
}

// 1 + 2 + ... + n = n(n+1)/2
// n(n-1)/2 < x < n(n+1)/2
fn divival(x: u64) -> u64 {
    let mut i = 1;
    while !(i * (i - 1) / 2 <= x && x < i * (i + 1) / 2) {
        i += 1
    }
    i - 1
}


Measured memory_bytes: 2196
# 2019/08/12
import sys

input=sys.stdin.readline

n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
    aa,bb=map(int,input().split())
    a[i]=aa%bb
    b[i]=bb

cnt=0
for i in range(n-1,-1,-1):
    res=(cnt+a[i])%b[i]
    if res:cnt+=b[i]-res
    
print(cnt)

Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  vector<char> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  int ans=0;
  for(int i=1;i<N;i++){
    int count=0;
    for(int j=0;j<26;j++){
      char al='a'+j;
      bool jug=false;
      for(int a=0;a<i;a++){
        for(int b=i;b<N;b++){
          if(S.at(a)==al&&S.at(b)==al){
            jug=true;
          }
        }
      }
      if(jug) count++;
    }
    ans=max(ans,count);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#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
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {

	string S;
	cin >> S;
	string s="No";
	if (S.at(0)!=S.at(1)&& S.at(0) != S.at(2)&& S.at(2) != S.at(1)) {
		s = "Yes";
	}
	cout << s << endl;
}


Measured memory_bytes: 256
let h, w = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ans = Array.make (h * w) (0, 0, 0, 0)
let m = ref 0
let a_ss = Array.(init h @@ fun _ -> init w @@ fun _ -> Scanf.scanf " %d" (+) 0)
let _ = Array.(iteri (fun i a_s -> iteri (fun j a -> let k, d = if i mod 2 = 1 then w - 1 - j, -1 else j, 1 in if a_s.(k) mod 2 = 1 && (j <> w - 1 || i <> h - 1) then let i1, j1 = if j = w - 1 then i + 1, k else i, k + d in ans.(!m) <- i + 1, k + 1, i1 + 1, j1 + 1; incr m; a_ss.(i1).(j1) <- a_ss.(i1).(j1) + 1) a_s) a_ss); Printf.printf "%d\n" !m; Array.iteri (fun i (a, b, c, d) -> if i < !m then Printf.printf "%d %d %d %d\n" a b c d) ans

Measured memory_bytes: 14080
import heapq

N, M = map(int, input().split())
lst = [int(x) * -1 for x in input().split()]
heapq.heapify(lst)
for _ in range(M):
    n = heapq.heappop(lst)
    n = n * -1 // 2 * -1
    heapq.heappush(lst, n)
print(sum(lst) * -1)

Measured memory_bytes: 14180
s=input()
#print(s)
i=0
r=1
l=1
for c in s:
#  print(c)
  if i%2==0:
    if c=='L':
      r=0
  if i%2==1:
    if c=='R':
      l=0
  i+=1
if l==1 and r==1:
  print("Yes")
else:
  print("No")


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

typedef long long ll;
const int maxn = 1e5 + 5;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

inline int gc()
{
	char c = getchar();
	while (c != '-' && c != '+') c = getchar();
	return c == '+' ? 1 : -1;
}

inline void chkmax(ll &a, ll b) {if (a < b) a = b;}

int n, a[maxn], b[maxn], pw[3];
ll f[maxn][3];

int main()
{
	n = gi();
	a[1] = gi(); b[1] = 1;
	for (int i = 2; i <= n; ++i) b[i] = gc(), a[i] = gi();

	memset(f, -63, sizeof(f));
	f[1][0] = a[1];
	pw[0] = pw[2] = 1; pw[1] = -1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= 2; ++j)
			if (f[i][j] > -1e18) {
				chkmax(f[i + 1][j], f[i][j] + a[i + 1] * b[i + 1] * pw[j]);
				if (j) chkmax(f[i + 1][j - 1], f[i][j] + a[i + 1] * b[i + 1] * pw[j - 1]);
				if (b[i + 1] < 0 && j < 2) chkmax(f[i + 1][j + 1], f[i][j] + a[i + 1] * b[i + 1] * pw[j]);
				if (b[i + 1] < 0 && j) chkmax(f[i + 1][j], f[i][j] + a[i + 1] * b[i + 1] * pw[j - 1]);
			}
	}

	printf("%lld\n", max(f[n][0], max(f[n][1], f[n][2])));
	
	return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<math.h>

int main(void){
    int x[4], i, index, max;
    int y=0;

    for(i=0; i<4; i++){
        scanf("%d", &x[i]);
    }
    index = 0; max = x[0];
    for(i=0; i<3; i++){
        if(max < x[i]){
            index = i;  max = x[i];
        }
        y = y + x[i];
    }
    y = y - x[index];
    y = y + x[index]*pow(2,x[3]);
    printf("%d\n", y);
    return 0;
}

Measured memory_bytes: 2468
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(0,n-2):
    if (p[i]<p[i+1] and p[i+1]<p[i+2]) or (p[i]>p[i+1] and p[i+1]>p[i+2]):
        count += 1
print(count)

Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll num2=0;
  ll num4=0;
  for(int i=0;i<n;i++)
    cin >> a[i];
  for(int i=0;i<n;i++){
    if(a[i]%2==0&&a[i]%4!=0){
      num2++;
    }
    if(a[i]%4==0){
      num4++;
    }
  }
  if(num2>=2)
    n-=(num2);
  if(num2<=1){
    if(n/2<=num4){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else{
    if(n%2==1) n++;
    if(n/2<=num4){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int b, i, ans;
    long a;
    int h[100000];
    scanf("%ld%d", &a, &b);
    for(i = 0; i < a;  i++){
        scanf("%d", &h[i]);
    }
    ans = 0;
    for(i = 0; i < a; i++){
        if(h[i] >= b){
            ans = ans + 1;
        }
    }
    printf("%d", ans);
}


Measured memory_bytes: 2036
n = int(input())

l = [0]
l.extend(list(map(int, input().split())))
l.append(0)

m = 0
for i in range(n+1):
    m += abs(l[i] - l[i+1])

for i in range(1, n+1):
    print(m - abs(l[i]-l[i-1]) - abs(l[i+1]-l[i]) + abs(l[i+1]-l[i-1]))

Measured memory_bytes: 14044
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

void Init() {
	std::cin.tie(0); std::ios::sync_with_stdio(false);
	struct Init_caller { Init_caller() { Init(); } }caller;
}

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INT_INF 1<<29
#define LL_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using ppi = pair<pi, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;
using vppi = vector<ppi>;


#pragma endregion

struct edge {
	int from, to, cost;
};

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL vmax(vi v, LL n) {
	int MAX = 0;
	f(i, 0, n) {
		MAX = max(MAX, v[i]);
	}
	return MAX;
}

LL vmin(vi v, LL n) {
	int MIN = LL_INF;
	f(i, 0, n) {
		MIN = min(MIN, v[i]);
	}
	return MIN;
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//エラトステネスの篩
void sieve(LL n) {
	vb s(n + 1, true);
	f(i, 2, n + 1) {
		for (int j = 2; i*j <= n; j++) {
			s[i*j] = false;
		}
	}
	cout << "2から" << n << "までの素数" << endl;
	f(i, 2, n + 1) {
		if (s[i]) {
			cout << i << " ";
		}
	}
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}


#pragma endregion 


/*****************************************************************************/
signed main(void) {
	int n;
	cin >> n;
	if (n < 1000) {
		cout << "ABC";
	}
	else {
		cout << "ABD";
	}
	return 0;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}
template <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

int main()
{
	fast;
	ll n, ans = 0;
	cin >> n;
	vector<int> a(n);
	for (ll i = 1; i <= n; i++)
		for (ll j = i; j <= n; j += i)
			a[j]++;
	for (ll i = 1; i <= n; i++)
	{
		ans += i * a[i];
	}
	cout << ans << en;
}


Measured memory_bytes: 42260
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
 
using namespace std;
int main(){
    int n,m;std::cin >> n>>m;
    int k[n];std::vector<int> b(m,0) ;
    std::vector<vector<int>> a(n,vector<int>(m)) ;
    rep(i,n){std::cin >> k[i];
        rep(j,k[i]){std::cin >> a[i][j];b[a[i][j]-1]++;}
    }
    int ans=0;
    rep(i,m){if(b[i]==n)ans++;}
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
def int_to_char(num):
  return chr(num + 97)

def name(num):
  ret = []
  while num != 0:
    num -= 1
    d = num % 26 
    ret.insert(0, d)
    num = num // 26

  return ''.join(map(int_to_char, ret))

if __name__ == "__main__":
  print(name(int(input())))

Measured memory_bytes: 9044
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

pair<int, int> p[10];
int X;
int ans = 0;

int main() {
    p[0].first = 500;
    p[0].second = 1000;
    p[1].first = 5;
    p[1].second = 5;

    cin >> X;

    rep(i, 2) {
        int tmp = X / p[i].first;
        ans += tmp * p[i].second;
        X %= p[i].first;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
  int n;
  cin >> n;
  int ans = 0;
  rep(i,n){
    if(i%2 == 0) continue;
    int cnt = 0;
    rep(j,i) if(i%j == 0) cnt++;
    if(cnt == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

const int N = 100005, mod = 998244353;
const char TYP[4] = "RGB";

int n, x[3*N], y[3*N], z[N][3], c1[3], c2[N], llv[3], hlv[3], ans = 1;
char a[3*N];

int main()
{
	scanf("%d%s",&n,a+1);
	for(int i=1;i<=3*n;i++) {
		for(int j=0;j<3;j++) {
			if(a[i] == TYP[j]) {
				a[i] = j;
				break;
			}
		}
		x[i] = ++c1[a[i]];
	}
	for(int i=1;i<=3*n;i++) {
		y[i] = c2[x[i]]++;
		z[x[i]][y[i]] = a[i];
	}
	for(int i=1;i<=3*n;i++) {
		if(y[i] == 0) {
			llv[a[i]]++;
		}
		else if(y[i] == 1) {
			int T = z[x[i]][0];
			ans = (1ll * ans * llv[T]--) % mod;
			hlv[3-T-a[i]]++;
		}
		else {
			ans = (1ll * ans * hlv[a[i]]--) % mod;
		}
	}
	for(int i=1;i<=n;i++) {
		ans = (1ll * ans * i) % mod;
	}
	printf("%d\n", ans);
}


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

using namespace std;

typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	ll a,b,sums  = 0;
	cin >> a >> b;
	vector<ll> v(b);
	for(ll i = 0;i<b;i++){
		cin >> v[i];
		sums += v[i];
	}
	if(sums > a)
		cout << -1 << "\n";
	else
		cout << a - sums << "\n";
}



Measured memory_bytes: 3728
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Sat Dec  1 03:28:15 2018
//
package main

import "fmt"

const MOD = 1e9 + 7

var h, w, k int
var dp [][]int

func main() {
	fmt.Scan(&h, &w, &k)

	if w == 1 {
		if k == 1 {
			fmt.Println(1)
		} else {
			fmt.Println(0)
		}
		return
	}

	dp = make([][]int, h+1)
	for i := range dp {
		dp[i] = make([]int, w)
	}
	dp[0][0] = 1

	lines := make([]int, 0)

	for i := 0; i < 1<<uint64(w-1); i++ {
		invalid := false
		for j := 0; j < w; j++ {
			if i&(0x03<<uint64(j)) == (0x03 << uint64(j)) {
				invalid = true
			}
		}
		if invalid {
			continue
		}

		lines = append(lines, i)
	}

	for i := 1; i <= h; i++ {
		for j := 0; j < w; j++ {
			left, middle, right := 0, 0, 0
			for _, line := range lines {
				if line&(1<<uint64(j)) != 0 {
					right++
				} else if j > 0 && line&(1<<uint64(j-1)) != 0 {
					left++
				} else {
					middle++
				}
			}

			if j == 0 {
				dp[i][j] = right*dp[i-1][j+1]%MOD + middle*dp[i-1][j]%MOD
			} else if j == w-1 {
				dp[i][j] = middle*dp[i-1][j]%MOD + left*dp[i-1][j-1]%MOD
			} else {
				dp[i][j] = (left*dp[i-1][j-1]%MOD+middle*dp[i-1][j]%MOD)%MOD + right*dp[i-1][j+1]%MOD
			}
			dp[i][j] %= MOD
		}

	}
	fmt.Println(dp[h][k-1] % MOD)
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n; cin >> n;
    vec<ll> a(n); rep(i,n) cin >> a[i];

    // 累積和をとる。累積和配列で同じ値のものがあればそのような二つの間の和は０
    vll csum(n);
    csum[0] = a[0];
    rep1(i,n-1) csum[i] = csum[i-1] + a[i];

    sort(all(csum));
    csum.push_back(csum[n-1]-1);  // 番兵
//    for(auto i: csum) debug(i);

    ll ans = 0;
    ll cnt = 1;
    for(int i = 0; i < n; ++i) {
        int j = i+1;
        if(csum[i] == 0) ++ans;
        if(csum[i] == csum[j]) ++cnt;
        else {
            ans += cnt*(cnt-1)/2;
            cnt = 1;
        }
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define re(i,n,a) for(int i=a;i<n;i++)
using namespace std;
typedef pair<int,int>P;
int w,h,a[16][16],md=14,b[16][16],s1,s2;
bool used[16][16];
string s[16];
int dx[]={-1,-1,-1,0,0,0,1,1,1};
int dy[]={-1,0,1,-1,0,1,-1,0,1};
vector<P>v;
map<int,int>m;
int greedy(){
  int res=0,sum=0;
  memset(a,0,sizeof(a));
  memset(used,0,sizeof(used));
  r(i,h){
      r(j,w){
        if(s[i][j]=='0'){
        r(k,9){
          int y=i+dy[k];
          int x=j+dx[k];
          if(y<0||x<0||y>=h||w>=x)continue;
          used[y][x]=1;
        }
      }
      else if(s[i][j]=='.')used[i][j]=1;
      else if(isdigit(s[i][j]))a[i][j]=s[i][j]-'0',res+=a[i][j];
      }
    }
    while(res>0){
      memset(b,0,sizeof(b));
      int f=0;
      r(i,h)r(j,w)if(!used[i][j]){
        int p=0;
        r(k,9){
          int y=i+dy[k];
          int x=j+dx[k];
          if(y<0||x<0||y>=h||x>=w)continue;
          if(a[y][x])p++;
        }
        b[i][j]=p;
        f=max(p,f);
      }
      int i=0,j=0;
      r(kk,h*w){
        i=(i+1)%h;
        j=(j+1)%w;
        if((unsigned int)rand()%5==0)i=(unsigned int)rand()%h;
        if((unsigned int)rand()%5==0)j=(unsigned int)rand()%w;
        if(used[i][j])continue;
        if(b[i][j]==f){
          int p=0;
          r(k,9){
          int y=i+dy[k];
          int x=j+dx[k];
          if(y<0||x<0||y>=h||x>=w)continue;
          if(a[y][x])p++;
        }
        if(p==f){
          r(k,9){
            int y=i+dy[k];
            int x=j+dx[k];
            if(y<0||x<0||y>=h||x>=w)continue;
            if(used[y][x])continue;
            if(a[y][x])a[y][x]--;
          }
          sum++;
          res-=f;
          used[i][j]=1;
        }
      } 
    }}
    m[sum]++;
    return sum;
}
int main(){
  while(cin>>h>>w,w){
    int ans=1e9;
    r(i,h)cin>>s[i];
    r(t1,2){
      r(i,h/2)swap(s[i],s[h-1-i]);
      r(t2,2){
        r(i,h)reverse(s[i].begin(),s[i].end());
        r(t3,2){
          string t[16];
          r(i,16)t[i]="";
          r(i,w)r(j,h)t[i]+=s[j][i];
          swap(h,w);
          r(i,w)s[i]="";
          r(i,h)s[i]=t[i];
          int pp;
          set<int>st;
          m.clear();
          r(t4,150){
            srand((unsigned int)time(NULL));
            pp=greedy();
            st.insert(pp);
            ans=min(ans,pp);
          }
          //cout<<m[ans]<<endl;
          if(st.count(ans)&&ans%md==0)
            if(rand()%2&&ans)ans--;
        }
      }
    }if(ans==28)exit(1);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string toString(int n) {
    ostringstream os; os << n;
    return os.str();
}
string add(string a, string b) {
    if (a.size() > 80 || b.size() > 80) {
        return "overflow";
    }
    while (a.size() > b.size()) b = "0" + b;
    while (b.size() > a.size()) a = "0" + a;

    string res = "";
    int carry = 0;
    for (int i=a.size()-1; i>=0; --i) {
        int t = (a[i] - '0') + (b[i] - '0') + carry;
        res = toString(t % 10) + res;
        carry = t / 10;
    }
    if (carry) {
        res = "1" + res;
    }

    if (res.size() > 80) {
        return "overflow";
    }
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string a, b;
    for (int i=0; i<n; ++i) {
        cin >> a >> b;
        cout << add(a, b) << endl;
    }
    return 0;
}

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

int main() {
	long long x[10000], y[10000],i;
	i = 0;

	do {
		i++;
		cin >> x[i] >> y[i];
		if (x[i] != 0 || y[i] != 0) {
			if (x[i] < y[i])
				cout << x[i] << " " << y[i] << endl;
			else
				cout << y[i] << " " << x[i] << endl;

		}
	} while (x[i] != 0 || y[i] != 0);
}

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

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  
  if(-a+b <= 0) 
    cout << "delicious" << endl;
  else if(-a+b <= x) 
    cout << "safe" << endl;
  else 
    cout << "dangerous" << endl;
}

Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
int a[2][100001], b[2][100001];

int main(int argc, char const* argv[])
{
  string s, t;
  cin >> s >> t;
  rep(i, s.size()){
    if(i > 0){
      rep(j, 2)a[j][i] = a[j][i-1];
    }
    if(s[i] == 'A')a[0][i]++;
    else a[1][i]++;
  }
  rep(i, t.size()){
    if(i > 0){
      rep(j, 2)b[j][i] = b[j][i-1];
    }
    if(t[i] == 'A')b[0][i]++;
    else b[1][i]++;
  }
  int q;
  cin >> q;
  rep(i, q){
    int x, y, z, w;
    cin >> x >> y >> z >> w;
    x--; y--; z--; w--;
    int atmp = a[1][y];
    if(x > 0)atmp -= a[1][x-1];
    atmp -= a[0][y];
    if(x > 0)atmp += a[0][x-1];
    atmp %= 3;
    if(atmp < 0)atmp += 3;
    int btmp = b[1][w];
    if(z > 0)btmp -= b[1][z-1];
    btmp -= b[0][w];
    if(z > 0)btmp += b[0][z-1];
    btmp %= 3;
    if(btmp < 0)btmp += 3;
    if(atmp == btmp)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
	return 0;
}


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

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

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u32 n;
  map<string, u32> s;

  cin >> n;
  u32 max = 0;
  rep(i, n) {
    string si;
    cin >> si;
    s[si] += 1;
    if (s[si] > max) {
      max = s[si];
    }
  }

  for (auto &si : s) {
    if (si.second == max) {
      cout << si.first << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 19252
N,M,C=map(int,input().split())
base=list(input().split())
base=[int(s) for s in base]
kekka=[]
for i in range(N):
    a=list(input().split())
    a=[int(s) for s in a]
    kekka.append(a)
count=0

#print(base)
#print(kekka)
for i in range(N):
    summ=C
    for j in range(M):
        summ+=base[j]*kekka[i][j]
    if summ>0:
        #print(base[j],kekka[i]
        count+=1
print(count)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	string p;
	cin >> p;
	bool R = 0;
	for (int i = 0; i < p.size()-1; i++) {
		if (p[i] != p[i + 1]) {
			R = 1; break;
		}
	}
	if (!R) {
		cout << 0 << endl; return 0;
	}
	int ans = 5000;
	for (char x = 'a'; x <= 'z'; x++) {
		string h = p;
		int z = 0;
		while (1) {
			bool f = 0, b = 0;;
			int t = 0,d=99999;

			f = 1; h.erase(h.size() - 1, 1); b++;
			
		//	cout << d;
			for (int i = 0; i < h.size(); i++) {
					if (h[i] == x)t++;
					else if (h[i + 1] == x) {
						h[i] = x; t++; b++;
					}
					else b++;
				}
			z++;
		//	cout<<h<<" "<<z<<" "<<t<<endl;
			
			if (!b)z--;
			if (t == h.size())break;
		}
		
		ans = min(z, ans);
	}
	cout << ans << endl;
		return 0;

}




Measured memory_bytes: 256