akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
template <typename T>
T gcd(T m, T n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main(){
  double H,A;
  cin>>H>>A;
  cout<<ceil(H/A)<<endl;
  
  return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N, K; cin >> N >> K;
  string S; cin >> S;
  int ans = 0;
  rep(i, N) {
    ans += S[i] == 'L' && i && S[i - 1] == 'L';
    ans += S[i] == 'R' && i + 1 < N && S[i + 1] == 'R';
  }
  string T = S;
  T.erase(unique(T.begin(), T.end()), T.end());
  int swap_count = 0;
  REP(i, 1, T.size() - 1) {
    if (swap_count + 1 <= K) {
      T[i] = T[i] == 'L' ? 'R' : 'L';
      swap_count++;
      i++;
      ans += 2;
    }
  }
  T.erase(unique(T.begin(), T.end()), T.end());
  if (T.size() > 1 && swap_count + 1 <= K) {
    T[0] = T[0] == 'L' ? 'R' : 'L';
    ans++;
    swap_count++;
  }
  T.erase(unique(T.begin(), T.end()), T.end());
  if (T.size() > 1 && swap_count + 1 <= K) {
    T.back() = T.back() == 'L' ? 'R' : 'L';
    ans++;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 512
using System;
class aoj
{
    static void Main()
    {
        string a = Console.ReadLine();
        int b = int.Parse(a);
        string[] c = new string[b];
        string []d = new string [b];
        for(int i = 0; i < b; i++)
        {
            c[i] = Console.ReadLine();
            d[i] = c[i].Replace("Hoshino", "Hoshina");
        }
        for(int i = 0; i < b; i++)
        {
            Console.WriteLine(d[i]);
        }
    }
}

Measured memory_bytes: 8732
n,m=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]
x.sort()
a=[]
if m==1 or n>=m:
    print("0")
else:
    for i in range(m-1):
        a.append(x[i+1]-x[i])
    a.sort(reverse=True)
    if n==1:
        print(max(x)-min(x))
    else:
        result=0
        for i in range(n-1):
            result+=a[i]
        print(max(x)-min(x)-result)

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

int main(){
  string S;
  cin >> S;
  
  S[0]++;
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
 
int main(){
	long n,a,b;
    cin >> n >> a>>b;
    if(n==1 && a != b){
      cout << 0<< endl;
    }else if(a > b){
    	cout << 0 << endl;
    }else{
    	cout << (b-a)*(n-2)+1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long k;
	cin>>k;
	queue< long long > q;
	for(int i=1;i<=9;i++)
		q.push(i);
	while (q.size()!=0)
	{
		long long x=q.front();
		q.pop();
		k--;
		if(k==0)
		{
			cout<<x<<endl;
			break;
		}
		for(long long y=(x%10)-1;y<=(x%10)+1;y++)
		{
			if(y<0||y>=10)
				continue;
			q.push(x*10+y);
		}
	}
	return 0;
}

Measured memory_bytes: 1792
import math
x = int(input())
flag = True
if x==2 or x==3 :
    flag = False
while flag:
    y = int(math.sqrt(x))
    for i in range(2,y+1):
        if x % i == 0 :
            x+=1
            break
        elif i ==y:
            flag = False
print(x)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iterator>
#include <array>
#include <cmath>

#define int long long

using namespace std;

const int inf = 1e12 + 57;

signed main()
{   
    int n = 3;
    int f[3][3];
    for(int i = 0;i < n; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            cin >> f[i][j];
        }
    }
    int m;
    cin >> m;
    for(int i = 0;i < m; ++i)
    {
        int x;
        cin >> x;
        for(int k = 0; k < n; ++k)
        {
            for(int j = 0; j < n; ++j)
            {
                if (f[k][j] == x)
                {
                    f[k][j] = -1;
                }
            }
        }
    }
    for(int i = 0;i < n; ++i)
    {
        int cnt = 0;
        for(int j = 0;j < n; ++j)
        {
            if (f[i][j] == -1)
                ++cnt;
        }
        if (cnt == 3)
        {
            cout << "Yes";
            return 0;
        }
    }
    for(int j = 0;j < n; ++j)
    {
        int cnt = 0;
        for(int i = 0;i < n; ++i)
        {
            if (f[i][j] == -1)
                ++cnt;
        }
        if (cnt == 3)
        {
            cout << "Yes";
            return 0;
        }
    }
    if (f[0][0] == f[1][1] && f[1][1] == f[2][2] && f[0][0] == -1)
    {
        cout << "Yes";
        return 0;
    }
    if (f[0][2] == f[1][1] && f[1][1] == f[2][0] && f[1][1] == -1)
    {
        cout << "Yes";
        return 0;
    }
    cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
#include <vector>
#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int n;
    int k;
    vector<int> rsp(3);
    string t;
    int ans=0;

    cin >> n >> k;
    cin >> rsp[0] >> rsp[1] >> rsp[2];
    cin >> t;

    vector<int> tv(n);
    string rsp_s = "spr";
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            if(t[i]==rsp_s[j]){
                tv[i]=j;
            }
        }
    }
    vector<vector<int>> dp(n, vector<int>(3));

    for(int i=0; i<n; i++){
        if(i<k){
            for(int j=0; j<3; j++){
                if(j==tv[i]){
                    dp[i][j]=rsp[tv[i]];
                }else{
                    dp[i][j]=0;
                }
            }
        }else{
            for(int j=0; j<3; j++){
                int tmp=0;
                for(int l=0; l<3; l++){
                    if(l!=j){
                        tmp = max(tmp, dp[i-k][l]);
                    }
                    if(j==tv[i]){
                        dp[i][j]=tmp+rsp[tv[i]];
                    }else{
                        dp[i][j]=tmp;
                    }
                }
            }
        }
    }

	for(int i=n-1,j=k;i>=0 and j>0;--i,--j){
		ans+=max(max(dp[i][0],dp[i][1]),dp[i][2]);
	}
    cout << ans << endl;
}


Measured memory_bytes: 6272
#!/usr/bin/env python3
import bisect

def main():
    X = int(input())
    K = int(input())
    r = list(map(int, input().split()))
    Q = int(input())
    q_list = []
    for i in range(Q):
        q_list.append(list(map(int, input().split())))

    r = [0] + r
    a = [0]
    upper_limit = [X]
    lower_limit = [0]

    x, ux, lx = 0, X, 0
    for i in range(1, K + 1):
        diff = r[i] - r[i - 1]
        if i % 2 == 1:
            x -= diff
            ux -= diff
            ux = max(ux, 0)
            lx -= diff
            lx = max(lx, 0)
        else:
            x += diff
            ux += diff
            ux = min(ux, X)
            lx += diff
            lx = min(lx, X)
        a.append(x)
        upper_limit.append(ux)
        lower_limit.append(lx)

    asc_i = [0]
    dsc_i = [1]
    x = 0
    for i in range(2, K + 1, 2):
        if x < a[i]:
            x = a[i]
            asc_i.append(i)
    x = a[1]
    for i in range(3, K + 1, 2):
        if a[i] < x:
            x = a[i]
            dsc_i.append(i)

    asc_a = [a[i] for i in asc_i]
    dsc_a = [-a[i] for i in dsc_i]


    for [t, a0] in q_list:
        ri = bisect.bisect_right(r, t) - 1

        ui = bisect.bisect_left(asc_a, X - a0)
        li = bisect.bisect_left(dsc_a, a0)

        ai, di = None, None
        if ui < len(asc_i):
            ai = asc_i[ui]
            if ri < ai:
                ai = None
        if li < len(dsc_i):
            di = dsc_i[li]
            if ri < di:
                di = None

        d = 0
        if (not ai is None) or (not di is None):
            if ai is None:
                d = -1
            elif di is None:
                d = 1
            else:
                d = 1 if ai < di else -1

        x = a0 + a[ri]
        if d == 1:
            x = upper_limit[ri]
        elif d == -1:
            x = lower_limit[ri]
        x += (t - r[ri]) * (-1 if ri % 2 == 0 else 1)
        x = min(max(x, 0), X)

        print(x)

if __name__ == '__main__':
    main()



Measured memory_bytes: 45892
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

    ll i,j,h;
    ll Q,M,K,P,A,B,N,X;

    long double x;

    string S;
    char aaa;
    ll ans=0;
    ll count=0;
    ll flag=0;
    ll temp=0;

    vector<ll> aa, bb, hh, ff;
    ll a,b;
    
    ll d;


    cin >>aaa;
    
    if('A'<=aaa && 'Z'>=aaa){
    cout<<'A'<<endl;
    }else{
cout<<'a'<<endl;
    }
   

    return 0;
}

Measured memory_bytes: 3068
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

int N,M,K;

const int MAX = 5e5;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    if (!fac[n]) COMinit();
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve() {
    cin>>N>>M>>K;
 
    int ans = 0;
    REP1(d, N-1) {
        int add = d*(N-d) % MOD;
        (add *= M*M)%=MOD;
        (ans += add)%=MOD;
    }
    REP1(d, M-1) {
        int add = d*(M-d) % MOD;
        (add *= N*N)%=MOD;
        (ans += add)%=MOD;
    }
    (ans *= COM(N*M-2,K-2))%=MOD;
    cout << ans << endl;
}

Measured memory_bytes: 12032
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let vec: Vec<&str> = buf.split_whitespace().collect();
    let n: i32 = vec[0].parse().unwrap();

    let mut ans: i32 = n;
    for x in 1..n/2{
        let a = x;
        let b = n-x;
        let c = culdigit(a) + culdigit(b);
        ans = if ans > c {c} else {ans};
    }
    println!("{:?}", ans);
}

fn culdigit(a: i32) -> i32{
    let mut ans = 0;
    let mut cnt = a;
    while cnt > 0{
        ans = ans + (cnt % 10);
        cnt = cnt / 10;
    }
    return ans;
}


Measured memory_bytes: 4352
MOD = 10**9+7
s = int(input())
x = s//3

MAX = s+1
fac = [0] * MAX 
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n, k):
    res = 1
    for i in range(k):
        res = res * (n-i) % MOD
    return res * finv[k] % MOD


COMinit()
ans = 0

for i in range(x):
    ans = (ans + COM(s-2*(i+1)-1, i)) % MOD
    #print(COM(s-2*(i+1)-1, i))
print(ans)


Measured memory_bytes: 9192
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;
#define ll long long

int main(){
    ll a[5],k;
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
    for(int i = 0; i < 4; i++){
       for(int j = i + 1; j < 5; j++){
           if(a[j]-a[i] > k){
               cout << ":(" << endl;
               return 0;
           }
        } 
    }
    cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 256
t = sorted(list(map(int, input().split())), reverse=True)
m = max(t)
ans = 0
if t[1] % 2 != t[2] % 2:
    t[0] += 1
    t[1] += 1
    m += 1
    ans += 1
while any([x != m for x in t]):
    if t[1]+2 <= m: t[1] += 2
    elif t[2]+2 <= m: t[2] += 2
    elif t[1]+1 <= m and t[2]+1 <= m:
        t[1] += 1
        t[2] += 1
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll n;
  cin >> n;
  vl a,b,c;
  rep(i,n){
    ll x,y,z;
    cin >> x >> y >> z;
    a.push_back(x);
    b.push_back(y);
    c.push_back(z);
  }
  vector<vector<ll> > dp(n, vector<ll>(3,0));
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for(ll i=1; i<n; i++){
    dp[i][0] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
    dp[i][1] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i]);
    dp[i][2] = max(dp[i-1][0] + c[i], dp[i-1][1] + c[i]);
  }
  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
 return 0;
}

Measured memory_bytes: 8032
def printnum(x):
	l = ''
	for _ in range(x):
		l += '#'
	return l
		
while True:
	try:
		line = input()
		if line != '0 0':
			dim = line.split(' ')
			dim = list(map(int, dim))
			
			for _ in range(dim[0]):
				print(printnum(dim[1]))
			print('')
			
		else:
			break
		
	except EOFError:
		break



Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "No" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
const int MAXX=1010;
const int MAXY=1010;
bool map2d[MAXX][MAXY];
bool map3d[MAXX][MAXY];
int depth[MAXX][MAXY];
int depth2[MAXX][MAXY];
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};

ll bfs(ll sx, ll sy) {
    if(depth[sx][sy]!=-1 or map2d[sx][sy]==0) return 0;
    deque<P> dq; //探索予定地 必要ならpairにしてどこから来たのか記録
    dq.emplace_back(sx,sy);
    depth[sx][sy]=0;
    ll ct1=0,ct2=0;
    while(!dq.empty()) {
        ll vx = dq.front().first;
        ll vy = dq.front().second;
        if((vx+vy)%2) ++ct1;
        else ++ct2;
        dq.pop_front();
        rep(i,4){
            ll x=vx+dx[i]; ll y=vy+dy[i];
            if(x<0 or x>=MAXX or y<0 or y>=MAXY) continue;
            if(map2d[x][y]==0) continue;
            if(depth[x][y]!=-1) continue;
            depth[x][y]=depth[vx][vy]+1;
            dq.emplace_back(x,y);
        }
    }
    return ct1*ct2;
}

//--MAIN-----------------------------------
void Main() {
    ll H,W; cin>>H>>W;
    ll a=0,b=0;
    rep(i,H){
        rep(j,W){
            char c; cin>>c;
            if(c=='#' xor i%2 xor j%2) map2d[i][j]=1;
            else map3d[i][j]=1;
        }
    }
    ll ans=0;
    rep(i,MAXX) rep(j,MAXY) depth[i][j]=-1;
    rep(i,H){
        rep(j,W){
            ans+=bfs(i,j);
        }
    }
    rep(i,MAXX) rep(j,MAXY) depth[i][j]=-1,map2d[i][j]=map3d[i][j];
    rep(i,H){
        rep(j,W){
            ans+=bfs(i,j);
        }
    }
    cout<< ans <<"\n";

}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 7552
def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))


    for _ in range(K):
        counter=[0 for _ in range(N)]

        for i in range(len(A)):
            left=max(0,i-A[i])
            right=min(N-1,i+A[i])
            counter[left]+=1
            if right+1<N:
                counter[right+1]-=1
        for i in range(len(counter)-1):
            counter[i+1]+=counter[i]

        if counter==A:
            break
        else:
            A=counter

    for i in range(N):
        if i!=N-1:
            print(str(A[i])+" ",end="")
        else:
            print(A[i])

if __name__ == "__main__":
    main()


Measured memory_bytes: 169176
#include <iostream>

using namespace std;

int main(void)
{
    int r, g, b, x;

    cin >> r >> g >> b;

    x = r*100+g*10+b;

    if(x%4==0){
        cout << "YES" << endl;
    }

    else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import math


def main():
    a, b, h, m = map(int, input().split())
    th = (h * 60 + m) / 720 * 2 * math.pi
    tm = m / 60 * 2 * math.pi
    xh = a * math.cos(th)
    yh = a * math.sin(th)
    xm = b * math.cos(tm)
    ym = b * math.sin(tm)
    dx = xh - xm
    dy = yh - ym
    ans = math.sqrt(dx ** 2 + dy ** 2)
    print("%.10f" % ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9520
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
//#include "atcoder/all"

using namespace std;
//using namespace atcoder;

typedef long long ll;

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};


const int MAX = 510000;
const int MOD = 1000000007;

class UnionFind {
public:
    std::vector<int> RANK;
    std::vector<int> par;

public:
    UnionFind(int n)
    {
        RANK.resize(n);
        par.resize(n);
        for(int i = 0; i < n; ++i) par[i] = i;
    }

    int FindRoot(int x)
    {
        if (par[x] == x) return x;
        par[x] = FindRoot(par[x]);
        return par[x];
    }

    bool IsSame(int x, int y)
    {
        return FindRoot(x) == FindRoot(y);
    }

    void Union(int x, int y)
    {
        x = FindRoot(x);
        y = FindRoot(y);
        if (x == y) return;
        else{
            if(RANK[x] > RANK[y]){
                par[y] = x;
            }
            else{
                par[x] = y;
                if(RANK[x] == RANK[y]){
                    RANK[x]++;
                }
            }
        }
    }
};

int main() {
    ios::sync_with_stdio(false);

    ll h, w; cin >> h >> w;
    if(h%3==0 || w%3==0){cout<<0<<endl;return 0;}

    ll ans = 10000000009;
    for(ll i = 1; i < h; ++i)
    {
        ll s1 = i * w;
        ll s2 = (h-i) * (w / 2);
        ll s3 = h*w - s1 - s2;
        ll L = max(s1,max(s2,s3));
        ll M = min(s1,min(s2,s3));
        ans = min(ans,L-M);
    }

    for(ll i = 1; i < w; ++i)
    {
        ll s1 = i * h;
        ll s2 = (w-i) * (h / 2);
        ll s3 = h*w - s1 - s2;
        ll L = max(s1,max(s2,s3));
        ll M = min(s1,min(s2,s3));
        ans = min(ans,L-M);
    }

    for(ll i = 1; i < w; ++i)
    {
        ll s1 = i * h;
        ll s2 = ((w-i) /2) * h;
        ll s3 = h*w - s1 - s2;
        ll L = max(s1,max(s2,s3));
        ll M = min(s1,min(s2,s3));
        ans = min(ans,L-M);
    }

    for(ll i = 1; i < h; ++i)
    {
        ll s1 = i * w;
        ll s2 = ((h-i)/2) * w;
        ll s3 = h*w - s1 - s2;
        ll L = max(s1,max(s2,s3));
        ll M = min(s1,min(s2,s3));
        ans = min(ans,L-M);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main(void){
    char s[3];
    cin >>s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7')cout <<"Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	char a;
	cin >> a;

	if (a == 'A')
		cout << "T" << endl;
	else if (a == 'T')
		cout << "A" << endl;
	else if (a == 'G')
		cout << "C" << endl;
	else
		cout << "G" << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
    cin >> S;
  if(S.at(0) == S.at(1))
    cout<<"Bad"<<endl;
  else if(S.at(1)==S.at(2))
    cout<<"Bad"<<endl;
  else if(S.at(2)==S.at(3))
    cout<<"Bad"<<endl;
  else
    cout<<"Good"<<endl;
  }

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

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

const ll mod = 1000000007;

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

int main(void){
    int n;
    cin >> n;
    ll inf = 0, zero = 0, id = 0;
    map<PL, ll> mp;
    REP(i,n){
        ll a = lin(), b = lin();
        if (a == 0 && b == 0) id++;
        else if (a == 0) zero++;
        else if (b == 0) inf++;
        else {
            if (b < 0) {
                a *= -1;
                b *= -1;
            }
            ll d = gcd(abs(a), b);
            PL p(a / d, b / d);
            mp[p]++;
        }
    }
    ll ans = 1;
    set<PL> counted;
    for (auto tmp : mp){
        PL p = tmp.first;
        ll x = tmp.second;
        if (counted.count(p)) continue;
        PL q(-p.second, p.first);
        if (q.second < 0) {
            q.first *= -1;
            q.second *= -1;
        }
        if (mp.count(q)){
            ll y = mp[q];
            counted.insert(q);
            ans = (ans * (powll(2, x) + powll(2, y) - 1)) % mod;
        }else{
            ans = (ans * powll(2, x)) % mod;
        }
    }
    ans = (ans * (powll(2, zero) + powll(2, inf) - 1)) % mod;
    ans = (ans + id - 1 + mod) % mod;
    cout << ans << endl;
    return 0;
}


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

int main() {
  vector<int> x(5);
  cin >> x.at(0) >> x.at(1) >> x.at(2) >> x.at(3) >> x.at(4);
  
  rep(i, 5){
    if(x.at(i) == 0){
      cout << i+1 << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
int n,m,u,v;
int f[1000000];
int main() {
	//freopen("a.inp", "r", stdin);
	scanf("%d %d", &n, &m);
	for(int i=0;i<m;i++) {
		scanf("%d %d", &u, &v);
		if (u==1) {
			f[v] ++;
		}
		if (v==n) {
			f[u] ++;
		}
	}
	for(int i=1;i<=n;i++) {
		if (f[i] > 1) {
			cout<<"POSSIBLE";
			return 0;
		}
	}
	cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 998244353
using namespace std;

int n,dp[200010][3][3][2];
string s;

inline void add(int &x,int y)
{
	x+=y;
	if(x>=MOD) x-=MOD;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	n=s.size();
	if(n==2){
		if(s[0]==s[1]) cout<<1<<endl;
		else cout<<2<<endl;
		return 0;
	}
	if(n==3){
		if((s[0]==s[1])&&(s[1]==s[2])) cout<<1<<endl;
		else if((s[0]==s[1])&&(s[1]!=s[2])) cout<<6<<endl;
		else if((s[0]==s[2])&&(s[0]!=s[1])) cout<<7<<endl;
		else if((s[1]==s[2])&&(s[0]!=s[2])) cout<<6<<endl;
		else cout<<3<<endl;
		return 0;
	}
	bool flag=false;
	for(int i=0;i<n-1;i++) if(s[i]!=s[i+1]){
		flag=true;
		break;
	}
	if(!flag){
		cout<<1<<endl;
		return 0;
	}
	int ans=1;
	for(int i=0;i<n-1;i++) if(s[i]==s[i+1]){
		ans--;break;
	}
	int num=0;
	for(int i=0;i<n;i++){
		num+=s[i]-'a';
	}
	num%=3;
	dp[0][0][0][0]=1;
	dp[0][1][1][0]=1;
	dp[0][2][2][0]=1;
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				for(int l=0;l<3;l++){
					add(dp[i][(k+j)%3][j][1],dp[i-1][k][l][1]);
					if(j==l) add(dp[i][(k+j)%3][j][1],dp[i-1][k][l][0]);
					else add(dp[i][(k+j)%3][j][0],dp[i-1][k][l][0]);
				}
			}
		}
	}
	for(int i=0;i<3;i++) add(ans,dp[n-1][num][i][1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14612
#include <iostream>

using namespace std;

int main()
{
    int matrix[100][100] = {};
    int vector[100] = {};
    int answer[100] = {};

    int n;
    int m;

    cin >> n >> m;

    // input matrix
    for (int x = 0; x < n; x++)
    {
        for (int y = 0; y < m; y++)
        {
            cin >> matrix[x][y];
        }
    }

    // input vector
    for (int x = 0; x < m; x++)
    {
        cin >> vector[x];
    }
    
    // output answer
    for (int x = 0; x < n; x++)
    {
        for (int y = 0; y < m; y++)
        {
            answer[x] += matrix[x][y] * vector[y];
        }

        cout << answer[x] << endl;
    }

    return 0;
}



Measured memory_bytes: 3140
#include<stdio.h>

int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a < b) 
 {if(b < c)
  {printf("Yes\n");
  }
  else
  {printf("No\n");
  }
 }
 else
 {printf("No\n");
 }
return 0;
}

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

int main() {
	
	int a, b;
	cin >> a >> b;
	int ans = a - b * 2;
	if(ans <= 0) cout << 0 << endl; 
	else cout << ans << endl; 
	
	return 0;
}

Measured memory_bytes: 764
// SeeAlso: https://atcoder.jp/contests/abc057/tasks/abc057_a

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 50
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int A,B;

int main() {
    cin >> A >> B;
    int ans = (A+B)%24;
    print(ans);
    return 0;
}


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

int main() {
	// your code goes here
	int a , b, c;
	
	cin  >> a >> b >> c;
	
	if ((a < b) && (b < c)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
	int m,f,r;
	while(1){
		cin >> m >> f >> r;
		if(m == -1 && f == -1 && r == -1) break;
		if(m == -1 || f == -1) cout << "F" << endl;
		else if(m+f >= 80) cout << "A" << endl;
		else if(m+f >= 65) cout << "B" << endl;
		else if(m+f >= 50 || (m+f >= 30 && r >= 50)) cout << "C" << endl;
		else if(m+f >= 30) cout << "D" << endl;
		else if(m+f < 30) cout << "F" << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

//最大積載量Pのk大のトラックで何個の荷物を積めるか？
int check(llong P){
    int i=0;
    for(int j=0; j<k; j++){
        llong s=0;
        while(s + T[i] <= P){
            s += T[i];
            i++;
            if(i==n) return n;
        }
    }
    return i;
}

int solve(){
    llong left = 0;
    llong right = 100000 * 10000; //荷物の個数　×　一個当たりの最大重量
    llong mid;
    while(right - left > 1){
        mid = (left + right) / 2;
        int v = check(mid); // mid == P を決めて何個積めるかチェック
        if(v >= n) right = mid;
        else left = mid;
    }

    return right;
}

main(){
    cin >> n >> k;
    for(int i=0; i<n; i++) cin >> T[i];
    llong ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3872
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int h,w;
  cin >> h >> w;
  vector<string> a(h);
  int count = 0;
  for(int i = 0;i < h;i++){
    cin >> a[i];
    for(int j = 0;j < w;j++){
      if(a[i][j] == '#')count++;
    }
  }
  bool res = false;
  if(count == h + w - 1)res = true;
  if(res)cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]

def main():
    ans = 0
    for i in range(N):
        n = A[i]
        while True:
            quotient, reminder = divmod(n, 2)
            if reminder != 0:
                break
            n = quotient
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 4148
#include <stdio.h>

int main(void) {

int n,i,a;long min,max,sum;
sum=0;min=1000000;max=-min;
scanf("%d\n",&n);
if(n==0) exit(0);
for(i=1;i<n;i++){
scanf("%d ",&a);
max=(max<=a) ? a : max;
min=(min>=a) ? a :min;
sum=sum+a;
}
scanf("%d\n",&a);
max=(max<=a) ? a : max;
min=(min>=a) ? a :min;
sum+=a;

printf("%d %d %ld\n",min,max,sum);
return 0;
}

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

string s;
int main(){
  cin >> s;
  bool flag = false;
  if(s[1]==s[2]&&(s[0]==s[2]||s[2]==s[3]))flag=true;
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
    int X;
    char A[10];
    char *S = "Sunny";
    char *R = "Rainy";
    char *C = "Cloudy";
    gets(A);
    if(strcmp(A,S)==0){
        printf("%s\n","Cloudy");
    }else if(strcmp(A,C)==0){
        printf("%s\n","Rainy");
    }else{
        printf("%s\n","Sunny");
    }

}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

struct Edge {
	int n;
	int64_t p;
};

int64_t score[2501] = {};
bool ng[2501] = {};

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

	int n, m, p; cin >> n >> m >> p;

	vector<vector<Edge>> edges(n + 1);
	FOR_LT(i, 0, m) {
		int a, b, c; cin >> a >> b >> c;
		edges[a].push_back({ b, c - p});
	}
	FOR_LE(i, 1, n) score[i] = INT64_MIN;
	score[1] = 0;

	FOR_LT(i, 0, n * 3) {
		FOR_LE(v, 1, n) {
			for (auto& edge : edges[v]) {
				if (score[v] == INT64_MIN) continue;

				int64_t np = score[v] + edge.p;
				if (np > score[edge.n]) {
					score[edge.n] = np;
					if (n <= i) {
						ng[edge.n] = true;
					}
				}
				ng[edge.n] = (ng[v] || ng[edge.n]);

				if (edge.n == n && ng[edge.n]) {
					cout << "-1" << endl;
					return 0;
				}
			}
		}
	}

	if (score[n] < 0) cout << 0 << endl;
	else  cout << score[n] << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> g(n+1);
    vector<pair<int, int>> ab(n-1);
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        ab[i] = make_pair(a, b);
    }

    map<pair<int, int>, int> cols;
    vector<int> pre(n+1, -1);
    queue<int> q;
    q.push(ab[0].first);
    int maxCol = 0;
    while(!q.empty()){
        int v = q.front(); q.pop();
        int col = 1;
        int vp = pre[v];
        int usedCol = cols[make_pair(v, vp)];
        for(int vc: g[v]){
            pair<int, int> vvc, vcv;
            vvc = make_pair(v, vc);
            vcv = make_pair(vc, v);
            if (cols[vvc] != 0 || cols[vcv] != 0) continue;
            if (col == usedCol) col++;
            cols[vvc] = cols[vcv] = col;
            col++;
            pre[vc] = v;
            q.push(vc);
        }
        maxCol = max(maxCol, col-1);
    }
    cout << maxCol << endl;
    rep(i,n-1){
        cout << cols[ab[i]] << endl;
    }
}

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

using namespace std;

int main(){
    string s;
    cin>>s;
    int m[26]={0};
    if(s=="zyxwvutsrqponmlkjihgfedcba")cout<<"-1"<<endl;
    else if(s.length()<26){
        for(int i=0;i<s.length();++i){
            m[s[i]-'a']=1;
        }
        for(int i=0;i<s.length()+1;++i){
            if(m[i]==0){
                s+=i+'a';
                break;
            }
        }
        cout<<s<<endl;
    }else{
        for(int i=25;i>0;--i){
            if(s[i-1]<s[i]){
                if(s[i]=='z'){
                    char c='z';
                    for(int j=i;j<26;++j){
                        if(s[i-1]<s[j])c=min(c,s[j]);
                    }
                    s[i-1]=c;
                    s=s.substr(0,i);
                }
                else{
                    char c='z';
                    for(int j=i;j<26;++j){
                        if(s[i-1]<s[j])c=min(c,s[j]);
                    }
                    s[i-1]=c;
                    s=s.substr(0,i);
                }
                break;
            }
        }
        cout<<s<<endl;
    }
}


Measured memory_bytes: 256
def main():
    input()
    H = list(map(int, input().split()))
    ans = 0
    prev = float('inf')
    cnt = -1
    for cur in H:
        if prev >= cur:
            cnt += 1
        else:
            if ans < cnt:
                ans = cnt
            cnt = 0
        prev = cur
    if ans < cnt:
        ans = cnt
    print(ans)
    return


main()


Measured memory_bytes: 15020
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
double a,b,x;
double tmp,h,ans,c,s;
int main(){
	cin>>a>>b>>x;
	if(a*a*b<x*2){
		x=a*a*b-x;
		h=2*x/(a*a);
		tmp=h/a;
		printf("%.8lf",atan(tmp)*1.0/acos(-1.0)*180);
		return 0;
	}
	double h=x*2/(a*b);
	printf("%.8lf",atan(b/h)*1.0*180/acos(-1.0));
}

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

int main(){
    int a,b;
    char c;
    while(true){
        cin >> a >> c >> b;
        if(c=='?')
        break;
        else if(c=='+')
        cout << a+b << endl;
        else if(c=='-')
        cout << a-b << endl;
        else if(c=='*')
        cout << a*b << endl;
        else if(c=='/')
        cout << a/b << endl;
    }
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main(){
    fast;
    int h,w;
    cin>>h>>w;
    char ans[h][w];
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            cin>>ans[i][j];
    int arr[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)
           arr[i][j]=0;
    }
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++){
            if(ans[i][j]=='#'){
                if(i-1>=0)
                {
                    arr[i-1][j]++;
                    if(j+1<w)
                        arr[i-1][j+1]++;
                    if(j-1>=0)
                        arr[i-1][j-1]++;
                }
                if(j-1>=0)
                    arr[i][j-1]++;
                if(i+1<h)
                {
                    arr[i+1][j]++;
                    if(j+1<w)
                        arr[i+1][j+1]++;
                    if(j-1>=0)
                        arr[i+1][j-1]++;
                }
                if(j+1<w)
                    arr[i][j+1]++;
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)
        	if(ans[i][j]=='.')
	            cout<<arr[i][j];
	        else
	        	cout<<'#';
            cout<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 100100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
	
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}

int LCS[3010][3010];
int32_t main(){
	fastio;
	LCS[0][0] = 0;
	
	string res="";
	string s,t;
	cin>>s>>t;
	int n = s.size();
	int m = t.size();
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i==0 || j==0){
				LCS[i][j] = 0;
			}else{
				if(s[i-1]==t[j-1])LCS[i][j] = 1 + LCS[i-1][j-1];
				else LCS[i][j] = max(LCS[i-1][j],LCS[i][j-1]);
			}
		}
	}
	int x =n,y=m;
	while(x && y){
		if(x==0 || y==0){
			break;
		}
		if(s[x-1]==t[y-1]){
			res+=s[x-1];
			x--;
			y--;
		}else{
			if(LCS[x-1][y]>=LCS[x][y-1]){
				x--;
			}else y--;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	
	
	
	
}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N), b(N);
    REP(i, N) { cin >> a[i]; }
    REP(i, N) { cin >> b[i]; }
    // https://emtubasa.hateblo.jp/entry/2019/04/26/010044
    //(1) aiに2たす
    //(2) bjに１たす
    // (a) ai<biのときはなんとかなる
    // (b) ai>biのときbiに１足してajに２を足す
    // (b)の回数が限られている
    ll c = 0;
    ll d = 0;
    REP(i, N) {
        c += max(0LL, a[i] - b[i]);
        d += max(0LL, (b[i] - a[i]) / 2LL);
    }
    if(c <= d) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<MOD>;

ll gcd(ll x, ll y) {
    if (x == 0) return y;
    return gcd(y%x,x);
}

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

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<int> P(1000001);
    rep(i,N) {
        int K = A[i];
        for (int j = 2; j*j<= K; j++) {
            int cnt = 0;
            while (K%j==0) {
                cnt++;
                K /= j;
            }
            chmax(P[j],cnt);
        }
        if (K != 1) chmax(P[K],1);
    }
    mint p = 1;
    rep(i,1000001) {
        while (P[i] > 0) {
            p *= i;
            P[i]--;
        }
    }
    vector<mint> B(N);
    rep(i,N) B[i] = p/A[i];
    mint ans = 0;
    rep(i,N) ans += B[i];

    cout << ans.a << endl;
}

Measured memory_bytes: 4352
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);

            System.out.println(8 < A || 8 < B ? ":(" : "Yay!");
        }
    }
}


Measured memory_bytes: 21204