akhauriyash/Code-Regression huggingface dataset:
/*
    Those who cannot remember the past are condemned to repeat it.
                                            - Dynamic Programming
    
    I never lose, I either win or I learn.
                - Competitive Programming

*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        char[] c1 = br.readLine().toCharArray();
        char[] c2 = br.readLine().toCharArray();
        int n1 = c1.length;
        int n2 = c2.length;

        int[][] dp = new int[n1+1][n2+1];

        for(int i=1 ; i<=n1 ; i++) {
            for(int j=1 ; j<=n2 ; j++) {
                if(c1[i-1] == c2[j-1]) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                }
                else {
                    dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
                }
            }
        }

        char[] lcs = new char[dp[n1][n2]];

        int x = n1;
        int y = n2;
        int ind = lcs.length-1;
        while(x > 0 && y > 0) {
            if(c1[x-1] == c2[y-1]) {
                lcs[ind--] = c1[x-1];
                x--;
                y--;
            }
            else {
                if(dp[x][y] == dp[x-1][y]) {
                    x--;
                }
                else {
                    y--;
                }
            }
        }

        pw.println(lcs);

        
        
        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


Measured memory_bytes: 81620
N=int(input())
a=[0]*N
b=[0]*N
c=[0]*N
for i in range(N):
    a[i],b[i],c[i]=map(int,input().split())
dp=[[-1 for i in range(3)] for j in range(N+1)]
dp[0] = [0]*3
for i in range(0,N):
    dp[i+1][0] = max(dp[i][1],dp[i][2])+a[i]
    dp[i+1][1] = max(dp[i][2],dp[i][0])+b[i]
    dp[i+1][2] = max(dp[i][0],dp[i][1])+c[i]
print(max(dp[N]))

Measured memory_bytes: 62680
import math
import fractions
from functools import reduce

N = int(input())
a = list(map(int, input().split()))

#最小公倍数-1
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

MaxKoubai = lcm_list(a)
m = MaxKoubai - 1
result = 0

for i in range(N):
    result += m % a[i]
    
print(result)

Measured memory_bytes: 66792
# coding: utf-8

from math import pi
from math import cos
import math


def main():
    A, B, H, M = map(int, input().split())

    # return (A**2 + B**2 - 2*A*B*cos(math.radians(6*(5*H-M))))**0.5
    return (A**2 + B**2 - 2*A*B*cos(math.radians((60*H-11*M)/2)))**0.5


print(main())


Measured memory_bytes: 9488
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
s = p[0 : x] + q[0 : y] + r
s.sort(reverse = True)
ans = 0
for i in range(x + y):
    ans += s[i]
print(ans)

Measured memory_bytes: 110828
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	double r, g,re;
	cin >> r >> g;
	re = 2 * g - r;
	cout<<re;

}

Measured memory_bytes: 3800
#include<stdio.h>

int main(){
	int i, j, k;
	int N;
	scanf("%d\n", &N);

	int A[N];
	for(i = 0; i < N; i++)
		scanf("%d", &A[i]);
	for(i = 0; i < N; i++) {
		if(i == N-1)
			printf("%d\n", A[i]);
		else
			printf("%d ",A[i]);
	}

	//insertionSort(A, N)
	for(i = 1; i < N; i++) {
		int key = A[i];
		j = i - 1;
		while(j >= 0 && A[j] > key) {
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = key;

		for(k = 0; k < N; k++) {
			if(k == N-1)
				printf("%d\n", A[k]);
			else
				printf("%d ",A[k]);
		}
	}
    return 0;
}

Measured memory_bytes: 600
package main
import (
	"fmt"
)
func main() {
	var a, b, count, i int
	fmt.Scan(&a, &b)
	c:=b
	for c!=0{
		c/=10
		count++
	}
	for i=0;i<count;i++{
		a*=10
	}
	for i=1;i<=317;i++{
		if i*i==a+b{
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder str = new StringBuilder(br.readLine());
        int q = Integer.parseInt(br.readLine());    //????????°q

        for(int i = 0; i < q; i++){
            String[] query = br.readLine().split(" ");
            int begin = Integer.parseInt(query[1]);
            int end = Integer.parseInt(query[2]);

            if(query[0].equals("print")){
                String print = str.substring(begin, end + 1);
                System.out.println(print);

            }else if(query[0].equals("reverse")){
//              ????????????????????????????????????sb?????£??\
                StringBuilder re = new StringBuilder(str.substring(begin, end + 1));
//              ???????????????????????¢
                String reverse = re.reverse().toString();
//              ??¨????????????????????£???
                str.replace(begin, end +1, reverse);

            }else if(query[0].equals("replace")){
//              ???????????????????????????????????????
                String replace = query[3];
//              ???????????????
                str.replace(begin, end +1, replace);
            }
        }
    }
}

Measured memory_bytes: 24332
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, sum = 0;
	cin >> n;
	vector <int> a(n - 1);
	for (int i = 0; i < n - 1; ++i) {
		cin >> a[i];
	}
	sum += a[0] + a[n - 2];
	for (int i = 0; i < n - 2; ++i) {
		sum += min(a[i], a[i + 1]);
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 1000005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;

static const ll MOD = 1000000007;

ll mod_pow(ll x, ll n, ll mod){
  if(n==0) return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if(n & 1) res = res * x % mod;
  return res;
}

ll mod_comb_for_small_k_big_prime_mod(ll n, ll k, ll p){
  if(n<0 || k<0 || n<k) return 0;
  if(n-k < k) k = n-k;
  ll a1 = 1, a2 = 1;
  for(ll i=n-k+1; i<=n; i++) a1 = a1*i%p;
  for(ll i=1; i<=k; i++) a2 = a2*i%p;
  return a1 * mod_pow(a2, p-2, p) % p;
}

int main(){
  int n, a, b;
  cin >> n >> a >> b;

  mint ret = mutil.pow(2, n) - 1;


  ret -= mod_comb_for_small_k_big_prime_mod(n, a, MOD);
  ret -= mod_comb_for_small_k_big_prime_mod(n, b, MOD);

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 15872
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define PB push_back
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int n=s.size();
	ll sum = 0;

	rep(i,0,(1<<(n-1))){
		ll a=s[0]-'0';
		rep(j,0,n-1){
			if(i&(1<<j)){
				sum+=a;
				a=0;
			}
			a = a*10+(s[j+1]-'0');
		}
		sum+=a;
	}
	cout << sum <<endl;


	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        int[] a = new int[n];
        Set<Integer> set = new HashSet<>();
        for(int i = 0;i<n;i++){
            a[i] = sc.nextInt();
            set.add(a[i]);
        }
        System.out.println(set.size());
    }
}

Measured memory_bytes: 21588
d,g = map(int,input().split())
answer = 0
Q = []
for i in range(d):
    p,c=map(int,input().split())
    answer += p
    Q.append((i+1,p,c))

dp = [-10**9]*(answer+1) 
dp[0] = 0
for i,p,c in Q:
    for j in range(answer,-1,-1):
        for k in range(1,p+1):
            cc = i*100*k
            if k == p:
                cc += c
            if j-k >= 0:
                dp[j]=max(dp[j],dp[j-k]+cc)
        
for i in range(answer+1):
    if dp[i] >= g:
        print(i)
        exit()

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

int main() {
  int n;
  cin >> n;
  int s = 30;
  
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    int d = 0;
    while (a % 2 == 0) {
      d++;
      a /= 2;
    }
    if (d < s) s = d;
  }
  cout << s << endl;
}


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define drep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

//---------------------------------------------------------------------------------------------------
void _main() {
    int N, Y;
    cin >> N >> Y;
    int res_x = -1, res_y = -1, res_z = -1;
    rep(x, 0, N + 1) {
        rep(y, 0, N - x + 1) {
            int z = N - (x + y);
            if ( Y == (x*10000 + y * 5000 + z * 1000)) {
                res_x = x;
                res_y = y;
                res_z = z;
            };
        }
    }
    cout << res_x << " " << res_y << " " << res_z << endl;
}

Measured memory_bytes: 256
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
N,K=map(int,input().split())
A=list(map(int,input().split()))
b=sorted(A)
c=sorted(A,reverse=True)
D=[]
M=0
x=1
y=1
for l in range(K-1):
    x=(x*(N-l-1))%(10**9+7)
    y=(y*(l+1))%(10**9+7)
y=power(y,10**9+5)
M+=(x*y*(c[0]-b[0]))%(10**9+7)
for i in range(1,N-K+1):
    y1=power(N-i,10**9+5)
    x=(x*y1)%(10**9+7)
    x=(x*(N-K-i+1))%(10**9+7)  
    m=(x*y*(c[i]-b[i]))
    if m>0:
        m=m%(10**9+7)
    M+=m
    M%(10**9+7)

print(M%(10**9+7))







Measured memory_bytes: 63344
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, d;
  string s;
  cin >> n >> s >> d;
  vi v(n);
  rep(i, n) {
    if (s[i] == '1') continue;
    if (d) {
      v[i] = 1;
      d--;
    }
  }
  while (d--) {
    for (int i = n - 1; i >= 0; i--) {
      if (v[i]) continue;
      v[i] = 1;
      break;
    }
  }
  rep(i, n) s[i] = ((s[i] - '0') ^ v[i]) + '0';
  cout << s << endl;
}

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

const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

ll modpow(ll a, ll n)
{
  ll res=1;
  while (n>0) {
    if (n&1) res = res*a % mod;
    a = a*a % mod;
    n >>= 1;
  }
  return res;
}

int main()
{
  ll n; cin >> n;
  vector<ll> c(n);
  rep(i, n) cin >> c[i];
  sort(c.rbegin(),c.rend());

  ll ans = 0;
  rep(i, n) {
    ll tmp = c[i] * (i+2) % mod;
    ans = (ans + tmp) % mod;
  }
  ans = (ans * modpow(4, n-1)) % mod;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
constexpr ll MOD = 998244353;

class Enumeration {
public:
  explicit Enumeration(int n, uint64_t mod)
    : mod(mod), fact(n), inv(n), finv(n) {
    fact[0] = finv[0] = inv[1] = 1;
    for (int i = 2; i < n; ++i) inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    for (int i = 1; i < n; ++i) {
      fact[i] = fact[i - 1] * i % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }
  uint64_t operator()(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fact[n] * finv[n - k] % mod * finv[k] % mod;
  }
private:
  uint64_t mod;
  vector<uint64_t> fact, inv, finv;
};

int main() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  Enumeration e(n + 1, MOD);
  ll ans = 0;
  for (ll anum = 0; anum <= n; ++anum) {
    if (k < a * anum) break;
    ll rem = k - a * anum;
    if (rem % b != 0) continue;
    ll bnum = rem / b;
    ans = (ans + e(n, anum) * e(n, bnum) % MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10380
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

double P, E, T;

double solve(int K, double L, double R)
{
  const double H = (L + R)/2.0;
  if (K == 0) {
    if (fabs(T - H) < E) {
      return 1.0;
    } else {
      return 0.0;
    }
  }

  if (R < T-E || T+E < L) {
    return 0.0;
  } else if (T-E <= L && R <= T+E) {
    return 1.0;
  }

  if (H <= T) {
    return P*solve(K-1, L, H) + (1.0-P)*solve(K-1, H, R);
  } else {
    return P*solve(K-1, H, R) + (1.0-P)*solve(K-1, L, H);
  }
}

int main()
{
  int K;
  double L, R;
  cin >> K >> L >> R;
  cin >> P >> E >> T;

  printf("%.6f\n", solve(K, L, R));
  return 0;
}

Measured memory_bytes: 0
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " = " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
        __f(comma+1, args...);
    }
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 1e5 + 5;
ll n, a, b, ans, h[MAXN];

bool check(ll tot)
{
    if(!tot) return false;
    ll val = 0;
    for(int i=0;i<n;i++)
    {
        if(h[i] <= tot * b) continue;

        ll temp = (h[i] - tot * b ) / (a - b);
        
        if( (h[i] - tot * b ) % (a - b) )
            temp++;    

        val += temp;
    }

    if(val <= tot) return true;
    return false;
}

ll bs(ll start, ll end)
{
    // ll mid = (start + end) / 2;
    // bool f1 = check(mid);
    // bool f2 = check(mid - 1);
    // if(f1 && !f2) return mid;
    // else if(f2) end = mid - 1;
    // else start = mid + 1;
    // return bs(start, end);

    ll lo=start,hi=end,md,prev=-1;
    while(lo<=hi)
    {
        md=(lo+hi)/2;
        if(prev==md)
            break;
        prev=md;

        if(check(md))
            hi=md;
        else
            lo=md+1;
    }

    return hi;
}

int main()
{
    FAST_IO;
    ll x=0;
    cin >> n >> a >> b;
    for(int i=0;i<n;i++)
    {
        cin >> h[i];
        x+=h[i]/a;
        if(h[i]%a)
            x++;
    }
    cout << bs(1, x) << endl;
    return 0;
}

Measured memory_bytes: 4272
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

string s;cin>>s;
int p=0,q=0;
for(int i=0;i<3;i++){
	if(s[i]=='A') p++;
	else q++;
}
if(p>0 && q>0) cout<<"Yes";
else cout<<"No";

return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

signed main(){
  while(true){
    int h,w;
    cin>>w>>h;
    if(!h&&!w)break;
    vector<string> hw(h);
    for(int i=0;i<h;i++)cin>>hw[i];
    queue<int> x;
    queue<int> y;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(hw[i][j]=='@'){
          x.push(j);
          y.push(i);
        }
      }
    }
    int ans=0;
    int px[]={1,0,-1,0};
    int py[]={0,-1,0,1};

    while(x.size()){
      int nx=x.front();
      int ny=y.front();
      x.pop();
      y.pop();
      ans++;
      for(int i=0;i<4;i++){
        if(nx+px[i]>=0&&nx+px[i]<w&&ny+py[i]>=0&&ny+py[i]<h&&hw[ny+py[i]][nx+px[i]]=='.'){
          x.push(nx+px[i]);
          y.push(ny+py[i]);
          hw[ny+py[i]][nx+px[i]]='@';
        }
      }
    }
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 3140
using System;

public class AtCoderB
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();

        int answer = 0;
        for (int i = 0; i < n - 2; i++)
        {
            string str = s.Substring(i, 3);
            if ("ABC".Equals(str))
            {
                answer++;
            }
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11092
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<set>
#include<fstream>
#include<map>
#include<string>
#include <stdio.h>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<climits>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef vector<char>vc;
typedef vector<string>vs;
#define MP make_pair
#define all(v) v.begin(),v.end()
const ll mod = 1000000007;
const ll OO = (ll)1e18;
const int dx[] = { 0, 1, -1, 0 };
const int dy[] = { 1, 0, 0, -1 };
ll gcd(ll a, ll b){ if (b == 0){ return a; }return gcd(b, a % b); }
ll fast_power(double base, ll power){
	if (power == 1) return base;
	if (power % 2 == 0) return fast_power((base*base), power / 2);
	else return(base*fast_power((base*base), power / 2));
}
//#pragma warning (disable : 4996)
void Qalbaz()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
}
vl vec;
ll dp[100001];
ll solve(int i)
{
	if (i <= 0)
		return 0;
	ll &ret = dp[i];
	if (ret != -1)
		return ret;
	ret = max(ret, max(solve(i - 1), solve(i - 2) + vec[i] * i));
	return ret;
}
int main(){
	//Qalbaz();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	cout << 24 + (24 - n);
	return 0;
}

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

#define F first
#define S second
#define pb push_back
#define mp make_pair

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

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

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

	ll n,a=0,b=0,c=0,d=0,i;

	string s;

	cin >> n;

	while(n--)
	{
		cin >> s;
		if(s == "AC")
			a++;
		else if(s == "WA")
			b++;
		else if(s == "TLE")
			c++;
		else
			d++;
	}

	cout << "AC x " << a << endl << "WA x " << b << endl << "TLE x " << c << endl << "RE x " << d << endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;

int main() {
    int n, k, q; cin >> n >> k >> q;
    vector<int> ar(n,k-q);
    rep(i,q){
        int s; cin >> s;
        ar[s-1]++;
    }
    rep(i,n){
        if (ar[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a,b;
  cin >> a >> b;
  cout << (a+b)%24 << endl;
}

Measured memory_bytes: 256
#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 START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    string s;
    cin >> s;
    char ch, past;
    string Past, Now, init;
    Past = s.substr(0,1);
    int cnt = 1;
    rep1(i,s.size()-1) {
//        debug(i);
        Now.push_back(s[i]);
//        debug(Now);
        if(Past != Now) {
            ++cnt;
            Past = Now;
            Now = init;
        }
//        debug(Past);
    }

    cout << cnt<< '\n';

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

Measured memory_bytes: 848
h, w = (int(_) for _ in input().split())

s = [input() for i in range(h)]

for i in range(len(s)):
    t = list(s[i])
    t.insert(0,'#')
    t.append('#')
    s[i] = ''.join(t)


print('#'*(w+2))
for i in range(len(s)):
    print(s[i])
print('#'*(w+2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        ll a,b,k; cin >> a >> b >> k;
        if(k>=a){
            k-=a;
            a=0;
            if(k>0)b-=k,b=max(0LL,b);
            cout << a <<" "<< b << endl;

        }else{
            a-=k;
            cout << a << " " << b << endl;
        }

    }
}


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

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

    vector<int> v[M];
    for (int i = 0; i < M; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int s;
            cin >> s;
            v[i].push_back(s);
        }
    }

    vector<int> p(M);
    for (int i = 0; i < M; i++)
        cin >> p[i];

    int res = 0;
    for (int i = 0; i < (1 << N); i++) {
        vector<int> light;
        for (int j = 0; j < N; j++) {
            if ((i >> j) & 1)
                light.push_back(j + 1);
        }

        bool flag = true;
        for (int j = 0; j < M; j++) {
            int cnt = 0;
            for (int k = 0; k < v[j].size(); k++) {
                if (binary_search(light.begin(), light.end(), v[j][k])) {
                    cnt++;
                }
            }

            if (cnt % 2 != p[j]) {
                flag = false;
                break;
            }
        }
        if (flag) res++;
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	map<int, int> mp;
	for (int i = 0, x; i < n; ++i)
	{
		cin >> x;
		++mp[x];
	}

	vector<int> a;
	vector<pair<int, int>> b;
	int t = mp.begin()->S;
	for (auto &i : mp)
	{
		if (i.S == t)
			a.push_back(i.F);
		b.push_back({ i.S, i.F });
	}

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

	if ((mp.size() == 3 && a.size() == 3 && (a[0]^a[1])==a[2]) || (mp.size() == 2 && b[0].F*2 == b[1].F && !b[0].S) || (mp.size() == 1 && !b[0].S))
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    //y /= gcd(x,y);
    return (x*y);
}

#define WA printf("WA\n");
int main()
{
    ll n,count=0;
    cin >> n;
    vll a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    rep(i,n){
        if(i == 0)continue;
        if(a[i] != a[i-1])count++;
    }
    count++;
    cout << ((count % 2 == 0)? count-1:count) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<string.h>
#define FOR(n) for(int i = 0;i < n;i++)
#define PRN(n) printf("%d\n",n);
#define PRS(s) printf("%s\n",s);
int main(void) {
	char s[5];
	scanf("%s", s);
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
		PRS("Bad");
	}
	else {
		PRS("Good");
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
  int first = 0;
  int second = 0;
  int third = 0;
  int high, i;

  for(i = 0;i < 10;i++){
    scanf("%d", &high);
    
    if(high > first){
      third = second;
      second = first;
      first = high;
    }else if(high > second){
      third = second;
      second = high;
    }else if(high > third){
      third = high;
    }
  }
  printf("%d\n", first);
  printf("%d\n", second);
  printf("%d\n", third);
 
}

Measured memory_bytes: 2704
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

LL n, a, b, c, x, y;

int main(){
	scanf("%lld", &n);
	for (a=1; a<=3500; a++)
		for (b=a; b<=3500; b++){
			x = n * a * b;
			y = 4 * a * b - b * n - a * n;
			if (y > 0 && x % y == 0){
				printf("%lld %lld %lld\n", a, b, x/y);
				return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(std::string X, std::string Y){
    if(X[0] == Y[0]){
        cout << "=" << endl;
    }
    if(X[0] < Y[0]){
        cout << "<" << endl;
    }
    if(X[0] > Y[0]){
        cout << ">" << endl;
    }
}

int main(){

    std::string X;
    std::cin >> X;
    std::string Y;
    std::cin >> Y;
    solve(X, Y);
    return 0;
}



Measured memory_bytes: 256
from sys import stdin,stdout
def fn(mask):
    global ans
    cost=0
    b=[0]*(1+m)
    for i in range(n):
        if mask&(1<<i):
            cost+=a[i][0]
            for j in range(1,m+1):
                b[j]+=a[i][j]
    allowed=all([v>=c for v in b[1:]])
    if allowed:ans=min(ans,cost)
n,m,c=list(map(int,stdin.readline().split()))
a=[list(map(int,stdin.readline().split())) for _ in range(n)]
ans=float('inf')
for mask in range(1<<n):
    fn(mask)
print(ans if ans!=float('inf') else -1)


Measured memory_bytes: 9160
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <sstream>

using namespace std;

string swp(string s,const int&a,const int&b){swap(s[a],s[b]);return s;}

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

    string s = "01234567";

    queue<string> q;
    map<string, int> m;

    q.push(s);
    m[s] = 0;

    while (q.size()) {
        string t = q.front(); q.pop();
        int idx = t.find('0');
        string u;
        if (idx - 1 >= 0 && idx != 4) {
            u = swp(t, idx, idx - 1);
            if (m.find(u) == m.end()) {
                m[u] = m[t] + 1;
                q.push(u);
            }
        }
        if (idx + 1 < 8 && idx != 3) {
            u = swp(t, idx, idx + 1);
            if (m.find(u) == m.end()) {
                m[u] = m[t] + 1;
                q.push(u);
            }
        }
        if (idx - 4 >= 0) {
            u = swp(t, idx, idx - 4);
            if (m.find(u) == m.end()) {
                m[u] = m[t] + 1;
                q.push(u);
            }
        }
        if (idx + 4 < 8) {
            u = swp(t, idx, idx + 4);
            if (m.find(u) == m.end()) {
                m[u] = m[t] + 1;
                q.push(u);
            }
        }
    }

    string line; stringstream ss;
    while (getline(cin, line)) {
        ss << line;
        string t = "";
        for (int i = 0; i < 8; ++i) {char c;ss >> c;t += c;}
        cout << m[t] << endl;
    }
}

Measured memory_bytes: 3496
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.StringTokenizer;

public class Main  implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }
    public void run() {
    	FastScanner sc = new FastScanner(System.in);
		int n = Integer.parseInt(sc.next());
		PrintWriter out = new PrintWriter(System.out);
		int[][] a = new int[n][3];
		for (int i = 0; i < n; i++) {
			a[i][0] = Integer.parseInt(sc.next());
			a[i][1] = Integer.parseInt(sc.next());
			a[i][2] = Integer.parseInt(sc.next());
		}
		int htmp = a[0][2];
		int cx=0;
		int cy =0;
		int ch = 0;
		for (int i = 0; i <= 200; i++) {
			for (int j = 0; j <= 100; j++) {
				for (int k = 0; k <= 100; k++) {
					int eq = 1;
					int cxt = j;
					int cyt = k;
					int cht = htmp + i;
					if(cht<1)
					{
						eq =0;
					}
					for (int k2 = 0; k2 < n; k2++) {
						int x = a[k2][0];
						int y = a[k2][1];
						int h = a[k2][2];
						if(Math.max(cht-Math.abs(x-cxt)-Math.abs(y-cyt),0)!=h)
						{
							eq =0;
						}
					}
					if(eq == 1)
					{
						cx=cxt;
						cy =cyt;
						ch = cht;
					}
				}
			}
		}

		out.printf("%d %d %d", cx, cy, ch);
		out.flush();
	}

    
    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

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

            return tokenizer.nextToken("\n");
        }

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

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

    }

}


Measured memory_bytes: 24148
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main{
	static int l, c;
	public static void main(String args[]){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			ArrayList<StringBuilder> str_array = new ArrayList<StringBuilder>();
			while(true){
				String str = br.readLine();
				if(str.equals("END_OF_TEXT")) break;
				str_array.add(new StringBuilder(str));
			}
			l = 0;
			c = 0;

			String buffer = new String();
			boolean flag = true;
			while(flag){
				char command = br.readLine().charAt(0);

				switch(command){
				case 'a':
					c = 0;
					break;
				case 'e':
					c = str_array.get(l).length();
					break;
				case 'p':
					if(l != 0) l--;
					c = 0;
					break;
				case 'n':
					if(l != str_array.size() - 1) l++;
					c = 0;
					break;
				case 'f':{
					StringBuilder str = str_array.get(l);
					if(c != str.length()){
						// 行末じゃないとき
						c++;
					}else if(l != str_array.size() -1){
						// 行末だけど最終行じゃないとき
						l++;
						c = 0;
					}
					break;
				}
				case 'b':
					if(c != 0){
						// 行頭じゃないとき
						c--;
					}else if(l != 0){
						// 行頭だけど上に行があるとき
						l--;
						c = str_array.get(l).length();
					}
					break;
				case 'd':{
					StringBuilder str = str_array.get(l);
					if(c < str.length()){
						// 行末じゃないとき
						str.deleteCharAt(c);
					}else if(l < str_array.size() - 1){
						StringBuilder str2 = str_array.get(l+1);
						str.append(str2);
						str_array.remove(str2);
					}
					break;
				}
				case 'k':{
					StringBuilder str = str_array.get(l);
					if(c < str.length()){
						// 行末じゃないとき
						buffer = str.substring(c);
						str.delete(c, str.length());
					}else if(l < str_array.size() - 1){
						StringBuilder str2 = str_array.get(l+1);
						str.append(str2);
						str_array.remove(str2);
						buffer = "\n";
					}
					break;
				}
				case 'y':{
					StringBuilder str = str_array.get(l);
					if(buffer.equals("\n")){
						String temp = str.substring(c);
						str.delete(c, str.length());
						StringBuilder str2 = new StringBuilder(temp);
						str_array.add(l+1, str2);
						l++;
						c = 0;
					}else{
						str.insert(c, buffer);
						c += buffer.length();
					}
					break;
				}
				case '-':
					print(str_array);
					flag = false;
					break;
				}
				// System.out.println("(" + l + ", " + c + ")");
				// print(str_array);
				// System.out.println("Buffer:" + buffer);
			}
		}catch(Exception e){
			System.err.println(e);
		}
	}

	static void print(int a[]){
		for(int i = 0; i < a.length; i++){
			System.out.print(a[i] + "\t");
		}
		System.out.println();
	}

	static void print(int m[][]){
		for(int i = 0; i < m.length; i++){
			for(int j = 0; j < m[i].length; j++){
				System.out.print(m[i][j] + "\t");
			}
			System.out.println();
		}
	}

	static void print(ArrayList<StringBuilder> array){
		for(int i = 0; i < array.size(); i++){
			System.out.println(array.get(i));
		}
	}
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    int c = 0;
    for(int i = 1; i <= n; ++i) {
        int t = i;
        int d = 0;
        while(t > 0) {
            t /= 10;
            ++d;

        }
        if(d % 2 == 1) ++c;

    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

#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(a) (a).begin(), (a).end()

using namespace std;

int main() {
    int L = 0, R = 0;
    int tmp;

    cin >> tmp;
    L += tmp;
    cin >> tmp;
    L += tmp;
    cin >> tmp;
    R += tmp;
    cin >> tmp;
    R += tmp;

    if (L == R)
        cout << "Balanced" << endl;
    else if (L > R)
        cout << "Left" << endl;
    else
        cout << "Right" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,i;
int main(){
    scanf("%d%d%d",&a,&b,&c);
    for(i=1;i<=b+1;i++)
    {
        if((a*i)%b==c){cout<<"YES"<<endl;return 0;}
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
const int N = 200010;
 
vector <pii> g[N];
int ok[N];
const int mod = 1000*1000*1000+7;
void dijkstra (vector <ll> &dist, vector <ll> &ways, int s) {
	fill (dist.begin(), dist.end(), 100000000000000000LL);
	fill (ways.begin(), ways.end(), 0);
	memset (ok, 0, sizeof ok);
	dist[s] = 0;
	ways[s] = 1;
	priority_queue < pii, vector<pii>, greater<pii> > pq;
	pq.emplace(0, s);
	while(!pq.empty()) {
		ll u, d; tie(d, u) = pq.top();
		pq.pop();
		if (ok[u]) continue;
		ok[u] = 1;
		for (auto w : g[u]) {
			ll v, nd; tie(v, nd) = w;
			if (d + nd < dist[v]) {
				dist[v] = nd + d;
				ways[v] = ways[u];
				pq.emplace(dist[v], v);
			} else if (nd + d == dist[v]) ways[v] = (ways[v] + ways[u]) % mod;
		}
	}
}
int main (void) {
	int n, m; cin >> n >> m;
	int s, t; cin >> s >> t;
	vector < tuple<int, int, int> > edges;
	for (int i = 0; i < m; i++) {
		int u, v, d; cin >> u >> v >> d;
		edges.eb(u, v, d);
		edges.eb(v, u, d);
		g[u].eb(v, d);
		g[v].eb(u, d);
	}
	vector <ll> distST, distTS, waysST, waysTS;
	distST.resize(n+1);
	distTS.resize(n+1);
	waysST.resize(n+1);
	waysTS.resize(n+1);
	dijkstra(distST, waysST, s);
	dijkstra(distTS, waysTS, t);
	ll ans = waysST[t];
	ans = (waysST[t] * waysTS[s]) % mod;
//	1 -> 2 -> 3
//	1 -> 4 -> 3
 
//	3 -> 4 -> 1
//	3 -> 2 -> 1
	//vertice em comum
	for (int i = 1; i <= n; i++) {
		if (distST[i] + distTS[i] == distST[t] and distST[i] == distTS[i]) {
			ll w1 = waysST[i] * waysST[i], w2 = waysTS[i] * waysTS[i];
w1 %= mod; w2 %= mod;
			ans = (ans - w1 * w2) % mod;
			ans = (ans + mod) % mod;
		}
	}
	//aresta em comum
	for (auto e : edges) {
		int u, v, k; tie(u, v, k) = e;
		if (distST[u] + distTS[v] + k == distST[t]) {
			ll a = distST[u], b = distST[u] + k;
			ll c = distTS[v], d = distTS[v] + k;
 
			if (c >= b or d <= a) continue;
			ll w1 = waysST[u] * waysST[u], w2 = waysTS[v] * waysTS[v];
w1 %= mod; w2 %= mod;
			ans = (ans - w1 * w2) % mod;
			ans = (ans + mod) % mod;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 27820
import java.util.*;

public class Main {
	Scanner sc;
	int a,b;
	
	static String testInput = "998244353 99824435";
/*-------------
 * constructor
 */
	public Main() {
		sc = new Scanner(System.in);
	}
	public Main(String input) {
		sc = new Scanner(input);
	}
	
/*------------------
 * instance methods
 */
	void out(Object o) {
		System.out.println(o);
		System.out.flush();
	}
	
	public void exec() throws Exception {
		a = sc.nextInt();
		b = sc.nextInt();
		
		int k = (a+b)/2;
		if (k*2 != a+b) out("IMPOSSIBLE");
		else out(k);
	}
	
/*------
 * main
 */
	public static void main(String[] args) throws Exception {
		Main m = new Main();
		m.exec();
	}
}

	

Measured memory_bytes: 23636
#include<stdio.h>
 
int main(){
   int i,n,ans=0;
   scanf("%d", &n);
   int a[n],b[n],c[n-1];
   for(i=0;i<n;i++){
   	scanf("%d ", &a[i]);
    a[i] = a[i] - 1;
   }
   for(i=0;i<n;i++){
   	scanf("%d ", &b[i]);
   }
   for(i=0;i<n-1;i++){
   	scanf("%d ", &c[i]);
   }
   for(i=0;i<n;i++){
   	ans = b[a[i]] + ans;
    if(i<n-1){
     if(a[i]+1==a[i+1]){
     	ans = c[a[i]] + ans;
     }
    }
   }
   printf("%d",ans);
   return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

void solve(){
    ll n;
    cin>>n;
    vector<ll>a(n);
    ll sum=0,sum2=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll sum3=sum,sum4=0;
    ll ans=0,ans2;
    rep(i,n){
        sum-=a[i];
        sum2+=a[i];
        if(sum2>=sum){
            ans=abs(sum2-sum);
            break;
        }
    }
    for(int i=n-1;i>=0;--i){
        sum3-=a[i];
        sum4+=a[i];
        if(sum4>=sum3){
            ans2=abs(sum4-sum3);
            break;
        }
    }
    cout<<min(ans2,ans)<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 1792