akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

int M;
typedef vector<vector<int>> mat;

vector<int> mul(mat& a, vector<int>& b) {
	vector<int> c(a.size());
	rep(i, a.size()) {
		rep(k, b.size()) {
			c[i] = (c[i] + a[i][k] * b[k]) % M;
		}
	}
	return c;
}


inline void add(vector<int>& a, vector<int> b) {
	if (a.size() == 0) {
		a = b;
		return;
	}
	rep(i, a.size()) {
		a[i] += b[i];
		a[i] %= M;
	}
}

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

	int h, w;
	cin >> h >> w >> M;

	vector<string> m(h);
	rep(i, h) cin >> m[i];

	mat a = {
		{1, 0, 1, 0},
		{0, 0, 0, 1},
		{0, 0, 0, 0},
		{0, 0, 0, 1},
	};
	mat p = {
		{1, 0, 0, 0},
		{0, 0, 1, 0},
		{0, 0, 0, 0},
		{0, 0, 0, 1},
	};
	mat r = {
		{1, 0, 0, 0},
		{0, 1, 0, 0},
		{0, -1, 10, 0},
		{0, 0, 0, 1},
	};

	vector<int> start = {
		{0, 1, 0, 1},
	};
	vector<vector<vector<int>>> dp(h, vector<vector<int>>(w));
	r[2][1] = m[0][0] - '0';
	dp[0][0] = mul(r, start);
	rep(i, h) {
		rep(j, w) {
			rep(d, 2) {
				int ny = i + (d == 0);
				int nx = j + (d == 1);
				if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;

				mat t;
				if (m[ny][nx] == '+')
					add(dp[ny][nx], mul(a, dp[i][j]));
				else if (m[ny][nx] == '*')
					add(dp[ny][nx], mul(p, dp[i][j]));
				else {
					r[2][1] = m[ny][nx] - '0';
					add(dp[ny][nx], mul(r, dp[i][j]));
				}
				// cout << i << ' ' << j << ' ' << d << endl;
				// cout << ny<< ' ' << nx << ' ' <<  endl;
			}
		}
		if(i > 2) rep(j,w) dp[i - 2][j].clear();
	}

	vector<int>& ans = dp[h - 1][w - 1];
	// rep(i,4) show(ans[i][0])
	cout << (ans[0] + ans[2]) % M << endl;
}



Measured memory_bytes: 273776
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element



signed main()
{
	int y;
	int m;
	int d;
	scanf("%lld/%lld/%lld", &y, &m, &d);

	if (y >= 2020)
	{
		cout << "TBD" << endl;
	}
	else if (y >= 2019 && m >= 5)
	{
		cout << "TBD" << endl;
	}
	else if (y >= 2019 && m >= 4 && d > 30)
	{
		cout << "TBD" << endl;
	}
	else
	{
		cout << "Heisei" << endl;
	}
}



Measured memory_bytes: 3652
#include <stdio.h>
using namespace std;
int main(void){
   int n,x,a,b,c,q,w;

while(1){

    scanf("%d%d",&n,&x);
   w=0;a=1;b=2;c=3;
  if(n==0&&x==0)break;     
        while(a<=n-2){
         
           while(b<=n-1){
             
              while(c<=n){
            //   if(a==2&&b==3&&c==4){printf("@@\n");}
               q=a+b+c;
              if(q==x){
                  w=w+1;
            }
            c=c+1;
        }
        b=b+1;c=b+1;
      }
    a=a+1;b=a+1;c=b+1;
}
printf("%d\n",w);
    
}
}


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


int main() {
  char c;
  cin >> c;
  if(c=='A') cout << 'T';
  if(c=='T') cout << 'A';
  if(c=='C') cout << 'G';
  if(c=='G') cout << 'C';
  return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 1e6 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll INF = 1e18;
using namespace std;

int main() {
	fastIO;
#ifdef LOCAL
//	freopen("input.in", "rt", stdin);
#endif
	int n;
	cin >> n;
	cout << (double) (n+n) * PI;
	return 0;
}


Measured memory_bytes: 3800
n, k = map(int, input().split())
R, S, P = map(int, input().split())
t = input()

dp = [0] * n
dic = {'r': P, 's': R, 'p': S}

for i in range(n):
  if i >= k and (t[i-k] == t[i]) and dp[i-k] != 0:
    continue
  dp[i] = dic[t[i]]

print(sum(dp))

Measured memory_bytes: 4084
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::map<long long, std::pair<long long, long long>> map;

  for (long long i = -200; i <= 200; i ++) {
    long long x = i * i * i * i * i;

    for (long long j = -200; j <= 200; j ++) {
      long long y = j * j * j * j * j;

      map[x - y] = std::make_pair(i, j);
    }
  }

  long long X;

  std::cin >> X;

  std::cout << map[X].first << ' ' << map[X].second << std::endl;

  return 0;
}


Measured memory_bytes: 8688
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int H,W,h,w,x,y;
    while (1) {
        scanf("%d %d",&H,&W);
        if (H == 0 && W == 0) {
            break;
        } else {
            for(x=0;x<W;x++){
                printf("#");
            }
            printf("\n");
            
            for(h=0;h<(H-2);h++){
                printf("#");
                for(w=0;w<(W-2);w++){
                    printf(".");
                }
                printf("#");
                printf("\n");
            }
            
            for(y=0;y<W;y++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

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

int main() {
  int N;
  vector<int> positions;

  cin >> N;

  for (int i = 0; i < N; i++) {
    int input;
    cin >> input;
    positions.push_back(input);
  }

  int ans = INT_MAX;
  for (int k = 1; k <= 100; k++) {
    int stamina = 0;
    for (int j = 0; j < N ; j++) {
      stamina += pow((positions[j] - k), 2);
    }
    ans = min(ans, stamina);
  }

  cout << ans;

  return 0;

}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	auto N = IN();
	map<char, int> mp;
	REP(i, N)
	{
		char c;
		cin >> c;
		mp[c]++;
	}
	print(SIZE(mp)==3 ? "Three" : "Four");
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
def solve(n,list)
  total = 0
  list.each do |e|
    total += e
  end

  os = (n * (n + 1) / 2)
  return "NO" if total % os != 0

  count = total / os
  hand = 0

  (0...n).each do |idx|
    ni = idx + 1
    ni = 0 if ni == n
    diff = list[ni] - list[idx]
    return "NO" if (count - diff) % n != 0
    hand_diff = ((count - diff) / n)
    return "NO" if hand_diff < 0
    hand += hand_diff
  end
  if hand == count
    return "YES"
  else
    return "NO"
  end
end

def main
  n = gets.to_i
  list = gets.split.map {|e| e.to_i}
  puts solve(n,list)
end

main


Measured memory_bytes: 8460
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  int n,i,b;
  const int mod=1e9+7;
  long ans;
  string s1,s2;
  cin >> n >> s1 >> s2;
  if (s1[0]==s2[0]) ans=3;
  else ans=6;
  for (i=0;i<n-1;i++){
    if (i<n-1 && s1[i]==s1[i+1]) continue;
    if (s1[i]==s2[i] && s2[i+1]==s2[i+1]) b=2;
    if (s1[i]==s2[i] && s1[i+1]!=s2[i+1]) b=2;
    if (s1[i]!=s2[i] && s1[i+1]==s2[i+1]) b=1;
    if (s1[i]!=s2[i] && s1[i+1]!=s2[i+1]) b=3;
    ans=(ans*b)%mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INS(x) (x).begin(),(x).end()
#define gcd(x,y) __gcd((x),(y))



int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin>>s;


    if (s=="ABC")
        cout<<"ARC";
    else cout<<"ABC";
    
    return 0;
}

Measured memory_bytes: 3620
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 
#define int ll
using namespace std;

const int N = 3e5 + 5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const long double eps = 1e-9 ;

using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

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

void solve()
{
    int n ;
    cin >> n ;
    int x , res = 1;
    int a[n];
    rep(i , n) {
        cin >> a[i];
        if(a[i] == 0){
            cout << 0;
            return ;
        }
    }
    rep(i , n){
        x = a[i];
        if(res > (inf + x - 1) / x){
            cout << -1;
            return ;
        }
        res = res * x ;
        if(res > inf){
            cout << -1;
            return ;
        }
    }
    cout << res; 
}
     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


Measured memory_bytes: 4384
#include <cstdlib>
#include <iostream>
#include <vector>


static inline bool
isAccept(int pay, const std::vector<int>& ds)
{
  for (; pay != 0; pay /= 10) {
    int p = pay % 10;
    for (const auto& d : ds) {
      if (p == d) {
        return false;
      }
    }
  }
  return true;
}


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

  int n, k;
  std::cin >> n >> k;
  std::vector<int> ds(k);
  for (auto&& d : ds) {
    std::cin >> d;
  }
  for (; !isAccept(n, ds); n++);
  std::cout << n << std::endl;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
//using System.Linq;
class Program
{
	static void Main(string[] args)
	{
		// 入力フェーズ
				int N = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');

				// 偶数番目の数列と奇数番目の数列のそれぞれの数字の登場回数を数える
				Dictionary<int, int> even = new Dictionary<int, int>();
				Dictionary<int, int> odd = new Dictionary<int, int>();
				for(int i=0; i<N; i++)
				{
					int v = int.Parse(input[i]);
					if(i%2 == 0)
					{
						if(even.ContainsKey(v))
						{
							even[v] = even[v] + 1;
						}
						else
						{
							even.Add(v, 1);
						}
					}
					else
					{
						if(odd.ContainsKey(v))
						{
							odd[v] = odd[v] + 1;
						}
						else
						{
							odd.Add(v, 1);
						}
					}
				}

				int cntMax = 0, vMax = 0;
				// evenの最大回数出てくる数字とその回数を調べる
				foreach(var e in even)
				{
					if(e.Value > cntMax)
					{
						cntMax = e.Value;
						vMax = e.Key;
					}
				}

				// 2回目に大きな回数出てくる数字とその回数を調べる
				int cntMax2nd = 0, vMax2nd = 0;
				foreach(var e in even)
				{
					if(e.Key != vMax && e.Value > cntMax2nd)
					{
						cntMax2nd = e.Value;
						vMax2nd = e.Key;
					}
				}

				// oddについて同様に調べる
				int o_cntMax = 0, o_vMax = 0;
				// evenの最大回数出てくる数字とその回数を調べる
				foreach(var e in odd)
				{
					if(e.Value > o_cntMax)
					{
						o_cntMax = e.Value;
						o_vMax = e.Key;
					}
				}

				// 2回目に大きな回数出てくる数字とその回数を調べる
				int o_cntMax2nd = 0, o_vMax2nd = 0;
				foreach(var e in odd)
				{
					if(e.Key != o_vMax && e.Value > o_cntMax2nd)
					{
						o_cntMax2nd = e.Value;
						o_vMax2nd = e.Key;
					}
				}
				int ret = 0;
				// 1番目に大きい同士が違う数字ならOK
				if(vMax != o_vMax)
				{
						ret = N - cntMax - o_cntMax;
				}
				else
				{
					// 1番目と2番目 or 2番目と1番目
					ret = N - Math.Max(cntMax + o_cntMax2nd, cntMax2nd + o_cntMax);
				}
				Console.WriteLine(ret);

    }

		class point
		{
			public int x{set; get;}
			public int y{set; get;}
			public int h{set; get;}
		}
}


Measured memory_bytes: 21600
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
15 6
1 2 7 8 12 50

output:
2
"""

import sys


def solve():
    rec[0] = 0
    for i in range(c_num):
        for j in range(money - coins[i] + 1):
            rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1)

    return rec


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    money, c_num = map(int, _input[0].split())
    coins = list(map(int, _input[1].split()))
    assert len(coins) == c_num
    rec = [float('inf')] * (money + 1)
    ans = solve()
    print(ans[-1])

Measured memory_bytes: 9504
S = input()
length = len(S)
p1 = [0 if i % 2 == 0 else 1 for i in range(length)]
p2 = [1 if i % 2 == 0 else 0 for i in range(length)]
ans1 = 0
ans2 = 0
for index,s in enumerate(S):
  if int(s) != p1[index]:
    ans1 += 1
  if int(s) != p2[index]:
    ans2 += 1
  
print(min(ans1,ans2))

Measured memory_bytes: 85456
N, K, C = map(int, input().split())
S = input()
L = [-1] * K
R = [-1] * K
L_index = 0
L_count = 0
R_index = N - 1
R_count = K - 1

while L_index < N and L_count < K:
    if S[L_index] == "o":
        L[L_count] = L_index
        L_index += (C + 1)
        L_count += 1
    else:
        L_index += 1
while R_index >= 0 and R_count >= 0:
    if S[R_index] == "o":
        R[R_count] = R_index
        R_index -= (C + 1)
        R_count -= 1
    else:
        R_index -= 1

for i in range(K):
    if L[i] == R[i]:
        print(L[i] + 1)


Measured memory_bytes: 20616
import java.io.*;
import java.util.*;

class FastReader 
{ 
    BufferedReader br; 
    StringTokenizer st; 
    
    public FastReader() 
    { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    
    String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    
    int nextInt() 
    { 
        return Integer.parseInt(next()); 
    } 
    
    long nextLong() 
    { 
        return Long.parseLong(next()); 
    } 
    
    double nextDouble() 
    { 
        return Double.parseDouble(next()); 
    } 
    
    String nextLine() 
    { 
          String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
} 

class Solution
{
    void solve()
    {
        FastReader sc = new FastReader();

        int x = sc.nextInt();

        if(x == 0)
            System.out.println(1);
        else
            System.out.println(0);
    
    }
}
  
public class Main
{ 
    public static void main(String[] args) 
    { 
        Solution ob = new Solution();

        ob.solve();
    } 
} 

Measured memory_bytes: 32656
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = [0, 0]
for i in range(len(a)):
    if i % 2 == 0:
        ans[0] += a[i]
    else:
        ans[1] += a[i]
print(ans[0]-ans[1])

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) {
		try{
			BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
			String str;
			if((str = stdReader.readLine()) != null)
			{
				int x = Integer.parseInt(str);
				System.out.println(x*x*x);
			}
			
		}
		catch (Exception e)
		{
			e.getStackTrace();
			System.exit(0);
		}
	}
}

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

int calc_fee(int w) {
    if (w <= 10) return 1150;
    if (10 < w && w <= 20) {
        return 1150 + (w - 10) * 125;
    } 
    if (20 < w && w <= 30) {
        return 1150 + 10 * 125 + (w - 20) * 140;
    }
    if (30 < w) {
        return 1150 + 10 * 125 + 10 * 140 + (w - 30) * 160;
    }
}

int main() {
    int n; int prev_fee = 4280;
    while (cin >> n, n != -1) {
        cout << - (calc_fee(n) - prev_fee) << endl;
    }
    return 0;
} 

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

using namespace std;

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

  int n;
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    if (x & 1) {
      continue;
    }
    if (x % 3 and x % 5) {
      cout << "DENIED";
      return 0;
    }
  }
  cout << "APPROVED";

  return 0;
}

Measured memory_bytes: 256
n = [input() for _ in range(2)]
ans = 0
a = []

for i in range(int(n[0])):

	if n[1][i] == "I":
		ans = ans + 1
		a.append(ans)
	elif n[1][i] == "D":
		ans = ans - 1
		a.append(ans)

print(max(0,max(a)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var < (end); var++)
#define RFOR(var, begin, end) for (int var = (begin) - 1; var >= (end); var--)
#define REP(var, length) FOR(var, 0, length)
#define RREP(var, length) RFOR(var, length, 0)
#define SORT(vector) sort(vector.begin(), vector.end())

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int n, m;
  multiset<int> a;
  cin >> n >> m;
  REP(i, n) {
    int input;
    cin >> input;
    a.insert(input);
  }
  REP(i, m) {
    auto itr = a.end();
    itr--;
    int max = *itr;
    a.erase(itr);
    a.insert(max / 2);
  }

  ll ans = 0;
  for (auto v : a) {
    ans += v;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 4992
N,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(1,N):
    tmp=a[i-1]+a[i]
    if tmp>x:
        ans+=tmp-x
        if a[i]>=tmp-x:
            a[i]-=tmp-x
        else:
            a[i]=0
print(ans)


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

int main() {
	int n;
	int u, k, v;
	cin >> n;
	int a[101][101] = {};
	for (int i = 1;i <= n;++i) {
		cin >> u >> k;
		for (int j = 1;j <k+1;++j) {
			cin >> v;
			a[i][v] = 1;
		}
	}
	for (int i = 1;i <= n;++i) {
		for (int j = 1;j <=n;++j) {
			cout << a[i][j] ;
			if (j!= n)cout << " ";
		}
		cout << endl;
	}
	return 0;
}


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

const int N = 1e5;
int n, m, k;

struct UF {
  int par[N * 4];
  int n;
  UF(int n): n(n) {
    for(int i=0; i < n;i++) {
      par[i] = -1;
    }
  }
  int find(int i) {
    return par[i] < 0 ? i : par[i] = find(par[i]);
  }
  int same(int a, int b) {
    return find(a) == find(b);
  }
  void unite(int a,int b){
    a =find(a);
    b =find(b);
    if(a==b)return;
    if(par[a] < par[b]) swap(a, b);
    if(a < m) swap(a,b);
    par[b] += par[a];
    par[a] = b;
  }
};

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int yes = 1;
  int g[N]={};
  cin >> n >> m >> k;
  UF uf(n + m + 10);
  for(int i = 0; i < k; i++) {
    int c,a,b;
    cin >> c >> a >> b;
    if(c==1){
      a--;b--;
      if(uf.find(a+m) < m && uf.find(b+m) < m && uf.find(a+m) != uf.find(b+m)) {yes = -i-1;break;}
      uf.unite(a+m,b+m);
    }else{
      a--;b--;
      if(uf.find(a+m) < m && uf.find(a+m) != b) {yes = -i-1;break;}
      uf.unite(b, a+m);
    }
  }
  if(yes==1) cout << 0 << endl;
  else cout << -yes << endl;
  return 0;
}



Measured memory_bytes: 3944
U = 3*10**5
MOD = 998244353
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
    fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
 
for i in range(U,0,-1):
    fact_inv[i-1] = (fact_inv[i]*i)%MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    z = fact[n]
    z *= fact_inv[k]
    z %= MOD
    z *= fact_inv[n-k]
    z %= MOD
    return z
  
n, a, b, k = map(int, input().split())
ans = 0
for i in range(n+1):
  r = k - i*a
  if r%b==0 and 0 <= r//b <= n:
    ans += comb(n, i) * comb(n, r//b)
    ans %= MOD
print(ans)

Measured memory_bytes: 26740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3F3F3F3F;
const int maxn = 2e5 + 555;
ll xpow(ll a, ll b, const int MOD) {
    ll ret = 1;
    a %= MOD;
    assert(b >= 0);
    while (b) {
        if (b & 1)
            ret = ret * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ret;
}
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout << fixed;
    int n;
    string sb;
    cin >> n >> sb;
    auto gao = [](int x) {
        int ret = 0;
        while (x) {
            ret++;
            x %= __builtin_popcount(x);
        }
        return ret;
    };
    vector<int> V;
    for (int i = 0; i <= 200000 + 55; i++) {
        V.push_back(gao(i));
    }
    int cnt = 0;
    for (auto &i : sb)
        cnt += i == '1';
    int MOD1 = cnt - 1, MOD2 = cnt + 1;
    int res1 = 0, res2 = 0;
    for (auto &i : sb) {
        if (MOD1 != 0)
            res1 = (res1 * 2 + i - '0') % MOD1;
        res2 = (res2 * 2 + i - '0') % MOD2;
    }
    for (int i = 0; i < (int)sb.size(); i++) {
        int len = (int)sb.size() - 1 - i;
        if (sb[i] == '0') {
            int add = xpow(2, len, MOD2);
            int now = (res2 + add) % MOD2;
            cout << V[now] + 1 << '\n';
        } else {
            if (MOD1 == 0)
                cout << 0 << '\n';
            else {
                int sub = xpow(2, len, MOD1);
                int now = ((res1 - sub) % MOD1 + MOD1) % MOD1;
                cout << V[now] + 1 << '\n';
            }
        }
    }
    return 0;
}

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

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

    vector<int> anser(N);

    rep(i,M) {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        anser[a]+=1;
        anser[b]+=1;
    }

    rep(i,N) {
        cout<<anser[i]<<endl;
        
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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

int main(){
	int N;
	cin >> N;
	vector<int> a(N), ans(N);
	rep(i,N) cin >> a[i];
	int k=0;
	rep(i,N) k=k^a[i];
	rep(i,N) ans[i]=k^a[i];
	rep(i,N-1) cout << ans[i] << " ";
	cout << ans [N-1] << endl;

	return 0;
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

int main() {
  int X, t;
  cin >> X >> t;
  cout << max(0, X - t) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(a,b) for(int a = 0; a < b; a++)
using namespace std;
int main(){
  long long a,b;
  string s;
  cin>>a>>s>>b;
  cout << (s == "+" ? a + b : a - b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef std::string str;
#define elif else if

void FAST() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main() {
    FAST();
    str s;
    int k;
    cin >> k >> s;
    str ans;
    if (s.size() > k) {
        ans = s.substr(0, k);
        ans.append("...");
    }
    else {
        ans = s;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
int n,a[10],inf=1e8;
typedef vector<int> vi;
typedef pair<int,vi> P;
map<vi,int> d,d2;
void bfs(vi s){
	d[s]=0;
	priority_queue< P,vector<P>,greater<P> > que;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		vi v=p.sc;
		if(d[v]==4) break;
		rep(i,n) rep(j,i){
			vi vc=v;
			reverse(vc.begin()+j,vc.begin()+i+1);
			if(d.count(vc)) continue;
			d[vc]=d[v]+1;
			que.push(P(d[vc],vc));
		}
	}
}
int bfs2(vi s){
	d2[s]=0;
	priority_queue< P,vector<P>,greater<P> > que;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		vi v=p.sc;
		if(d.count(v)) return d[v]+d2[v];
		if(d2[v]==4) return 9;
		rep(i,n) rep(j,i){
			vi vc=v;
			reverse(vc.begin()+j,vc.begin()+i+1);
			if(d2.count(vc)) continue;
			d2[vc]=d2[v]+1;
			que.push(P(d2[vc],vc));
		}
	}
}

int main(){
	cin>>n;
	rep(i,n) cin>>a[i];
	vi s,t;
	rep(i,n) s.pb(i+1);
	rep(i,n) t.pb(a[i]);
	bfs(s);
	cout<<bfs2(t)<<endl;
}

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

int main() {
	int n;
	int count = 0;
	int sum = 0;
	int x = 9;
	cin >> n;
	int y = n;

	while (y != 0){
		y = y / 10;
		count++;
	}
	
	if (count % 2 == 0){
		for (int i = 1; i <= count - 1; i+=2){
			sum += x;
			x *= 100;
		}
	}else{
		for (int i = 1; i <= count - 2; i+=2){
			sum += x;
			x *= 100;
		}
		sum += n - pow(10, count-1)+1;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 888
#include <vector>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  ll ans = 0;
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == 0) {
      ans += sum / 2;
      sum = 0;
    } else {
      sum += a[i];
    }
  }
  ans += sum / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
/*
	Created by Rahul Goel.
*/

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1000000000;

#define pii pair < int, int >
#define vi vector < int >
#define vvi vector < vector < int > >
#define vpii vector < pair < int, int > >
#define vvpii vector < vector < pair < int, int > > >
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

int main()
{
	int n, m;
	cin >> n >> m;
	cout << n*(n-1)/2 + m*(m-1)/2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;
    vector<int> a(n), b(m);
    int sa = 0, sb = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sa += a[i];
    }
    for (int j = 0; j < m; j++) {
      cin >> b[j];
      sb += b[j];
    }
    int s = 1e9, t = 1e9;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (sa - a[i] + b[j] == sb - b[j] + a[i]) {
          if (s + t > a[i] + b[j]) {
            s = a[i];
            t = b[j];
          }
        }
      }
    }
    if (s == 1e9)
      cout << -1 << endl;
    else
      cout << s << " " << t << endl;
  }
  return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MX = 1e10 + 10;;
unsigned long long fac[1000010];

#include <math.h>
#define PI 3.14159265358979323846264338327950L

long long gcd(long long a, long long b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
    return (a * b) / gcd(a, b);
}
long long digits(long long m) {
    long long cnt = 0;
    while (m) {
        cnt++;
        m /= 10;
    }
    return cnt;
}

unsigned long long power(unsigned long long x, unsigned long long y){
    unsigned long long res = 1;
    x = x % MOD;

    while (y > 0) {
        // If y is odd, multiply x with result 
        if (y & 1)
            res = (res * x) % MOD;

        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % MOD;
    }
    return res;
}
unsigned long long modInverse(unsigned long long n) {
    return power(n, MOD - 2);
}


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int cnt = 0;
    for (int i = 1; i < n - 1; i++) {
        if ((a[i] < a[i - 1] && a[i] > a[i + 1]) || (a[i] > a[i - 1] && a[i] < a[i + 1])) {
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int sub(int a,vector<char>b,int c,int d){
  if(c%2019==0&&c!=0)return 1;
  return sub(a+1,b,c+b[d]*a,d+1);
}
int main(){ 
  int a,b,c=0,d,e=0,f;
  cin>>a>>b>>f;
  c=b;
  rep(i,a-1){
    cin>>d;
        e+=b;
       if(f+b>d)c+=b-(b-d+f);
       else     c+=b;
       f=d;
     }
     cout<<c;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 105
#define INF (1<<26)
int T,N;
int t[MAX],M[MAX];
int mem[MAX][MAX];

int solve(int x,int y){
  if(mem[x][y]!=-1)return mem[x][y];
  if(x==100)return 0;
  int res=solve(x+1,1)+1;
  if(t[y]<=M[x])res=min(res,solve(x+1,(y+1)%T));
  return mem[x][y]=res;
}

void init(){
  for(int i=0;i<MAX;i++){
    M[i]=INF;
    for(int j=0;j<MAX;j++){
      mem[i][j]=-1;
    }
  }
}
int main(){
  while(1){
    cin>>T;
    if(T==0)break;
    init();
    for(int i=0;i<T;i++)cin>>t[i];
    cin>>N;
    for(int i=0;i<N;i++){
      int a,b;
      cin>>a>>b;
      M[a-1]=min(M[a-1],b);
    }
    cout<<solve(0,0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <iostream>
#include <stack>
#include <vector>
#include <utility>
using namespace std;
int binarySearch(int a[], int n, int key)
{
    int right = n-1;
    int left = 0;
    int mid;
    while (left < right)
    {
        mid = (right + left) / 2;
        if(key < a[mid])
            right = mid - 1;
        else if(key > a[mid])
            left = mid +1;
        else 
            return 1;
    }
    return key == a[left];
}
int main()
{
    int count = 0;
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; i++)
        cin >> S[i];
    int q;
    cin >> q;
    int T;
    for (int i = 0; i < q; i++)
    {
        cin >> T;
        if (binarySearch(S, n, T))
            count++;
    }
    cout << count << "\n";
}


Measured memory_bytes: 3444
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

// int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    string s, t;
    cin >> s >> t;

    vector<int> s_c, t_c;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    char s_now = '0';
    char s_counter = 0;
    for(int i = 0 ; i < s.size(); i++){
        if (s[i] == s_now){
            s_counter++;
        }else{
            s_c.push_back(s_counter);
            s_counter = 1;
            s_now = s[i];
        }
    }
    if (s_counter != 1){
        s_c.push_back(s_counter);
    }

    char t_now = '0';
    char t_counter = 0;
    for(int i = 0 ; i < t.size(); i++){
        if (t[i] == t_now){
            t_counter++;
        }else{
            t_c.push_back(t_counter);
            t_counter = 1;
            t_now = t[i];
        }
    }
    if (t_counter != 1){
        t_c.push_back(t_counter);
    }

    sort(s_c.begin(), s_c.end());
    sort(t_c.begin(), t_c.end());

    bool ans = true;
    if (s_c.size() != t_c.size()) {
        ans = false;
    }
    for (int i = 0; i < min(s_c.size(), t_c.size()); i++){
        if (s_c[i] != t_c[i]) ans = false;
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}





















Measured memory_bytes: 776
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    int h, w; cin >> h >> w;

    char s[w][h];

    for(int j=0; j<h; j++){
        for(int i=0; i<w; i++){
            cin >> s[i][j];
        }
    }
    
    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, -1, 0, 1};

    bool isPossible = true;
    for(int j=0; j<h; j++){
        for(int i=0; i<w; i++){
            if(s[i][j] == '#'){
                isPossible = false;

                for(int dir=0; dir<4; dir++){
                    int x = i + dx[dir];
                    int y = j + dy[dir];

                    if(s[x][y] == '#'){
                        isPossible = true;
                        break;
                    }
                }
                if(isPossible == false) break;
            }
            if(isPossible == false) break;
        }
        if(isPossible == false) break;
    }

    cout << (isPossible ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 10000
#define NIL -1

typedef struct{
    int parent;
    int left;
    int right;
}node;

node T[MAX];
int n;

void preParse(int u){
    if(u==NIL){
        return;
    }
    printf(" %d", u);
    preParse(T[u].left);
    preParse(T[u].right);
}

void inParse(int u){
    if(u==NIL){
        return;
    }
    inParse(T[u].left);
    printf(" %d", u);
    inParse(T[u].right);

}

void postParse(int u){
    if(u==NIL){
        return;
    }
    postParse(T[u].left);
    postParse(T[u].right);
    printf(" %d", u);

}

int main(void){
    int i, v, l, r, root;
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        T[i].parent=NIL;
    }
    for(int i=0; i<n; i++){
        scanf("%d %d %d", &v, &l, &r);
        T[v].left=l;
        T[v].right=r;
        if(l!=NIL){
            T[l].parent=v;
        }
        if(r!=NIL){
            T[r].parent=v;
        }

    }
    for(int i=0; i<n; i++){
        if(T[i].parent==NIL){
            root=i;
        }
    }

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

    return 0;

}




Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h, w;
  cin >> h >> w;
  
  string prev, s, next;
  int a;
  char b;
  
  for (int i = 0; i < h; i++) {
    
    if (i == 0) {
      cin >> s;
      if (h > 1) {
        cin >> next;
      }
    }
    else if (i != h - 1) {
      cin >> next;
    }
    
    for (int j = 0; j < w; j++, a = 0) {
      
      if (s.at(j) != '#') {
      
        //左
        if (j != 0) {
          if (s.at(j - 1) == '#') {
            a++;
          }
        }
        //右
        if (j != w - 1) {
          if (s.at(j + 1) == '#') {
            a++;
          }
        }   

        //上の行
        if (i != 0) {
          //左上
          if (j != 0) {
            if (prev.at(j - 1) == '#') {
              a++;
            }
          }
          //上
          if (prev.at(j) == '#') {
            a++;
          }
          //右上
          if (j != w - 1) {
            if (prev.at(j + 1) == '#') {
              a++;
            }
          } 
        }
      
        //下の行
        if (i != h - 1) {
           //左下
          if (j != 0) {
            if (next.at(j - 1) == '#') {
              a++;
            }
          }
          //下
          if (next.at(j) == '#') {
            a++;
          }
          //右下
          if (j != w - 1) {
            if (next.at(j + 1) == '#') {
              a++;
            }
          } 
        }
        
        b = '0' + a;
        s.at(j) = b;
      }
          
    }
    
    cout << s <<endl;
    
    prev = s;
    s = next;
  }
  
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0)
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  IO;
  int n; cin>>n;
  vector<int> v(n+3);
  for (int i = 1; i <= n; i++) cin>>v[i];
  vector<int> dp(n+3, 1e9);
  dp[1] = 0;
  for (int i = 1; i < n; i++) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(v[i + 1] - v[i]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(v[i + 2] - v[i]));
  }

  cout<<dp[n]<<"\n";
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define INF (int)1e9+4
#define INFL (ll)1e18+4
#define md (int)1e9+7
#define mx 10000000  //use fixed<<setprecion
#define mk make_pair
#define pi pair<int,int>
#define ss second
#define ff first
#define pb emplace_back
#define onell(x) __builtin_popcountll(x)
#define one(x) __builtin_popcount(x)
#define maxi(a) *max_element(a.begin(),a.end());
#define mini(a) *min_element(a.begin(),a.end());
#define all(s) s.begin(),s.end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, a) for (auto& x: a)
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sz(x) ((long long)x.size())
#define mez(s) memset(s,0,sizeof s)
#define mex(s) memset(s,-1,sizeof s)
#define metr(s) memset(s,true, sizeof s)
typedef vector<int> vi;
typedef vector<ll>vl;
typedef map<int,int> mp;
typedef queue<int> que;
typedef vector<pi> vp;
const int mod=1e9+7;
void solve(){
ll n=0,x=0,y=0,z=0,m=0,k=0;ll ans=0;
cin>>n;
vl a(n);rep(i,0,n)cin>>a[i];
reverse(all(a));
vl pre(n-1);pre[0]=a[0];
rep(i,1,n-1){
	pre[i]=pre[i-1]+a[i];
}
reverse(all(pre));
pre.pb(0);
reverse(all(a));
rep(i,0,n){
//	cout<<pre[i]<<" "<<a[i]<<"\n";
	ans=ans+((pre[i]%mod)*a[i])%mod;
	ans%=mod;
}
cout<<ans;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  //cin>>t;
  while(t--){
  	solve();
  }
  return 0;
}


Measured memory_bytes: 7948
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    for(int i=0;i<n;i++)
    {
        cout<<"x";
    }
	return 0;
}







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

int main(){
  int N; cin >> N;
  int a = 0;
  
  int answer = 1;
  for (int i = 0; i < N; i++){
    cin >> a;
    if (a % 2 == 0){
      if (a % 3 != 0 && a % 5 != 0){
        answer = 0;
        break;
      }
    }
  }
  
  if (answer == 1){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
  
}

Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    H, W = il()
    HW = [sl() for _ in range(H)]
    h = [False] * H
    w = [False] * W

    for n in range(H):
        hw = HW[n]
        if '#' in hw[0]:
            h[n] = True
        for m in range(W):
            if hw[0][m] == '#':
                w[m] = True

    for n in range(H):
        if h[n]:
            str = ''
            for m in range(W):
                if w[m]:
                    str += HW[n][0][m]
            print(str)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10164
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int w,h;
string map[40];
int vec[4][2]={{0,1},{0,-1},{-1,0},{1,0}};

struct pos{
	pos(int X,int Y){
		x=X,y=Y;
	}
	int x,y;
};

int move(int x,int y){
	int ans=0;
	map[x][y]='#';
	stack<pos> bfs;
	bfs.push(pos(x,y));
	while(!bfs.empty()){
		pos n=bfs.top();bfs.pop();
		x=n.x;
		y=n.y;
		ans++;
		for(int i=0;i<4;i++){
			if((x+vec[i][0]>=0)&&(y+vec[i][1]>=0)&&(x+vec[i][0]<h)&&(y+vec[i][1]<w)){
				if(map[x+vec[i][0]][y+vec[i][1]]=='.'){
					map[x+vec[i][0]][y+vec[i][1]]='#';
					bfs.push(pos(x+vec[i][0],y+vec[i][1]));
				}
			}
		}
		
	}
	
	
	return ans;
}

int main(){
	while(cin>>w>>h,w){
		int fx,fy;
		for(int i=0;i<h;i++){
			cin>>map[i];
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]=='@'){
					fx=i;
					fy=j;
					break;
				}
			}
		}
		int ans=move(fx,fy);
		cout<<ans<<endl;
		
	}
}

Measured memory_bytes: 1212
def main():

    N = int(input())
    act = []
    for _ in range(N):
        a, b, c = map(int, input().split())
        act.append([a, b, c])
    dp = [[0, 0, 0] for _ in range(N+1)]
    for i in range(N):
        dp[i+1][0] = act[i][0] + max(dp[i][1], dp[i][2])
        dp[i+1][1] = act[i][1] + max(dp[i][2], dp[i][0])
        dp[i+1][2] = act[i][2] + max(dp[i][0], dp[i][1])
    # print(dp)
    return max(dp[N])

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 42468
#include<stdio.h>

int main(void){
	int hon;
	scanf("%d",&hon);
	switch(hon%10){
		case  2:
		case 4:
		case 5:
		case 7:
		case 9:
			puts("hon");
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			puts("pon");
			break;
		default:
			puts("bon");
		}
		return 0;
	}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> v1(n);
    vector<int> v2(n);
    for (int i=0 ; i<n ; i++){
        int k;
        cin >> k;
        v1[i] = k;
    }
    for (int i=0 ; i<n ; i++){
        int k;
        cin >> k;
        v2[i] = k;
    }
    int max=0;
    for (int i=0 ; i<n ; i++){
        int sum=0;
        for (int j=0 ; j<=i ; j++){
            sum += v1[j];
        }
        for (int j=i ; j<n ; j++){
            sum += v2[j];
        }
        if (sum > max) max = sum;
    }
    
    cout << max << endl;
    
    return 0;
}

Measured memory_bytes: 256