akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    rep(i, (int)(s.length())-1) {
        if ( s[i] == 'A' && s[i+1] == 'C' ) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    vector<int> dp(n, -1);
    rep(i, n){
        *(--lower_bound(dp.begin(), dp.end(), a[i])) = a[i];
    }
    int ans = n - (lower_bound(dp.begin(), dp.end(), 0) - dp.begin());
    cout << ans << endl;
}

Measured memory_bytes: 1024
import math
# from itertools import product
from functools import reduce

def main():
#     def gcd(*numbers): return reduce(math.gcd, numbers)
    K = int(input())
    ans = 0
#     valiation = list(itertools.product(range(1, K+1), repeat=3))
#     for v in valiation:
#         ans += gcd(v)
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                ans += math.gcd(math.gcd(i, j), k)
    print(ans)
        
    
if __name__ == '__main__':
    main()

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i,n) {
    int l,r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <math.h> // sqrt()

using namespace std;

int main(){
    int n, a;
    cin >> n;
    vector<int> yolo;
    vector<int> bruh;
    cin >> a;
    yolo.push_back(a);
    for (int i = 1; i < n; i++){
        if (i % 2 == 1){
            cin >> a;
            yolo.push_back(a);
        }
        else{
            cin >> a;
            bruh.push_back(a);
        }
        
    }
    if (n % 2 ==0){
    reverse(yolo.begin(), yolo.end());
    for (int i : yolo)
        cout << i << ' ';
    for (int i : bruh)
        cout << i << ' ';


    
    }
    else {
        reverse(bruh.begin(), bruh.end());
        for (int i : bruh)
            cout << i << ' ';
        for (int i : yolo)
            cout << i << ' ';
        
    }
    cout << endl;

}


Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}
void min_self(ll& a, ll b) {
    a = min(a, b);
}

const ll INF = 1e18L + 5;

int main() {
    int n, W;
    scanf("%d%d", &n, &W);
    vector<int> weight(n), value(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d%d", &weight[i], &value[i]);
    }
    int sum_value = 0;
    for(int x : value) {
        sum_value += x;
    }
    vector<ll> dp(sum_value + 1, INF); // 0 ... W
    dp[0] = 0;
    // dp[i] - the minimum total weight of items with total value exactly i
    for(int item = 0; item < n; ++item) {
        for(int value_already = sum_value - value[item]; value_already >= 0; --value_already) {
        //~ for(int weight_already = 0; weight_already <= W - weight; ++weight_already) {
            min_self(dp[value_already+value[item]], dp[value_already] + weight[item]);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= sum_value; ++i) {
        if(dp[i] <= W) {
            answer = max(answer, (ll) i);
        }
        //~ min_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
}

Measured memory_bytes: 4044
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N;
	while (cin >> N, N) {
		int num[150][150] = { { 0 } };
		for (int i = 0;i<N;i++) {
			for (int j = 0;j<N;j++) {
				cin >> num[i][j];
				num[i][N] += num[i][j];
				num[N][j] += num[i][j];
				num[N][N] += num[i][j];
			}
		}
		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				if (num[i][j]<10) {
					for (int k = 0;k<4;k++)cout << " ";
				}
				else if (num[i][j]<100) {
					for (int k = 0;k<3;k++)cout << " ";
				}
				else if (num[i][j]<1000) {
					for (int k = 0;k<2;k++)cout << " ";
				}
				else if (num[i][j]<10000) {
					for (int k = 0;k<1;k++)cout << " ";
				}
				cout << num[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

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

int main()
{
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << (h2 - h1) * 60 + (m2 - m1) - k << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=1e5+5;
vector<lli> v[N];
bool vis[N];
lli dp[N][2],M=1e9+7;

void dfs(lli x)
{
    if(vis[x]) return ;
    vis[x]=true;
    
    dp[x][0]=1;
    dp[x][1]=1;
    for(auto j : v[x])
    {
        if(!vis[j])
        {
            dfs(j);
            lli white=dp[x][0];
            lli black=dp[x][1];
            
            dp[x][0]=(white*dp[j][0])%M;
            dp[x][0]+=(white*dp[j][1])%M;
            
            dp[x][1]=(black*dp[j][0])%M;
        }
    }
}
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i,x,y;
    memset(vis, false, sizeof(vis));
    
    for(i=0;i<n-1;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    dfs(1);
    
    cout<<(dp[1][0]+dp[1][1])%M;
    return 0;
}

Measured memory_bytes: 11520
module Main where

import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [x, a, b] <- fmap read . words <$> getLine :: IO [Int]
    let over = b - a
    case () of
        _ | over <= 0 -> putStrLn "delicious"
          | over <= x -> putStrLn "safe"
          | otherwise -> putStrLn "dangerous"

Measured memory_bytes: 508
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

int main(void) {
    ll a, b, c;
    cin >> a >> b >> c;

    if (c - a - b <= 0) {
        cout << "No" << endl;
        return 0;
    }

    ll x = (c - a - b) * (c - a - b);
    if (x > 4 * a * b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(void){

    int64_t x; cin >> x;

    int sum, sum_2;
    sum = x / 500;
    x -= sum*500;
    sum *= 1000;
    
    sum_2 = x/5;
    sum += sum_2 * 5;
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3640
import numpy as np


def inputs(func=lambda x: x, sep=None, maxsplit=-1):
	return map(func, input().split(sep=sep, maxsplit=maxsplit))

def input_row(n : int, type=np.int, *args, **kwargs):
	return np.fromiter(inputs(type, *args, **kwargs), dtype=type)

def input_2d(nrows : int, ncols : int, type=np.int, *args, **kwargs):
	data = np.zeros((nrows, ncols), dtype=type)
	for i in range(nrows):
		data[i, :] = input_row(ncols, type, *args, **kwargs)
	return data

class Repeat (object):
	__slots__ = [
		'element',
		'times'
	]
	
	def __init__(self, element, times : int):
		self.element = element
		self.times = int(times)
	
	def __len__(self):
		return self.times
	
	def __iter__(self):
		return iter(self.element for _ in range(self.times))

def repeat(element, times : int):
	return Repeat(element, times)

class IntAddition (object):
	'''整数の加法'''
	def operate(self, x, y):
		return x + y
	@property
	def identity(self):
		return 0
	def cancel(self, x, y):
		return x - y
	def invert(self, x):
		return -x
	def accumulate(self, x, count):
		return x * count

class UnionFind (object):
	'''重み付きUnion-Find木'''
	def __init__(
			self,
			num_nodes=0,
			abelian_operator=IntAddition()):
		self.parent = []
		self.potential = []
		self.op = abelian_operator
		
		self.extend(num_nodes)
	
	def append(self):
		self.parent.append(-1)
		self.potential.append(self.op.identity)
	
	def extend(self, num_nodes):
		self.parent.extend(repeat(-1, num_nodes))
		self.potential.extend(repeat(self.op.identity, num_nodes))
	
	def root(self, x):
		parent = self.parent[x]
		if 0 <= parent:
			self.parent[x] = self.root(parent)
			self.potential[x] = self.op.operate(
				self.potential[x], self.potential[parent]
			)
			x = self.parent[x]
		return x
	
	def difference_from_root_to(self, x):
		self.root(x)
		return self.potential[x]
		
	def size(self, x):
		return -self.parent[self.root(x)]
	
	def difference(self, x, y):
		if not self.issame(x, y):
			raise RuntimeError('x と y は同じ集合に属していません。')
		return self.op.cancel(
			self.difference_from_root_to(y),
			self.difference_from_root_to(x)
		)
	
	def unite(self, x, y, difference=None):
		if difference is None:
			difference = self.op.identity
		
		x, px = self.root(x), self.potential[x]
		y, py = self.root(y), self.potential[y]
		difference = self.op.cancel(difference, py)
		difference = self.op.operate(difference, px)
		if x == y:
			return difference == 0
		
		if self.size(x) < self.size(y):
			x, y = y, x
			difference = self.op.invert(difference)
		self.parent[x] += self.parent[y]
		self.parent[y] = x
		self.potential[y] = difference
		
		return True
	
	def issame(self, x, y):
		return self.root(x) == self.root(y)



N, M = inputs(int)
uf = UnionFind(num_nodes=N)

valid = True
for i in range(M):
	L, R, D = inputs(int)
	L -= 1
	R -= 1
	
	if not uf.unite(L, R, D):
		valid = False

print('Yes' if valid else 'No')


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

using namespace std;

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

  int N;
  cin >> N;
  vector<int> v(2 * N);
  for (int i = 0; i < 2 * N; ++i)
    cin >> v[i];
  sort(v.begin(), v.end());
  
  int ans = 0;
  for (int i = 0; i < 2 * N; i += 2) {
    ans += v[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,c=map(int,input().split())
stc=[list(map(int,input().split())) for _ in range(n)]
ts=[t[1] for t in stc]
mst=max(ts)
xstc=[[] for _ in range(c)]
for i in range(n):
    xstc[stc[i][2]-1].append([stc[i][0],stc[i][1]])
for i in range(c):
    xstc[i]=sorted(xstc[i],key=lambda x:x[0])
    for j in range(1,len(xstc[i])):
        if xstc[i][j-1][1]==xstc[i][j][0]:
            xstc[i][j][0]=xstc[i][j-1][0]
            xstc[i][j-1]=[]
z=[]
for i in range(c):
    for j in range(len(xstc[i])):
        if len(xstc[i][j])>0:
            z.append(xstc[i][j])
x=[0 for _ in range(mst+2)]
for i in range(len(z)):
    x[z[i][0]-1]+=1
    x[z[i][1]]-=1
for i in range(1,mst+2):
    x[i]+=x[i-1]
print(max(x))

Measured memory_bytes: 37756
import numpy as np

N = int(input())
S = np.zeros(5)
S[0] = int(input())
S[1] = int(input())
S[2] = int(input())
S[3] = int(input())
S[4] = int(input())

ANS=4-(-N//S.min())

print(str(int(ANS)))

Measured memory_bytes: 21112
str=raw_input().strip().split()
list=list()


ans=0
for ss in str:
    if ss=="*":
        a=list.pop()
        b=list.pop()
        list.append(a*b)
    elif ss=="+":
        a=list.pop()
        b=list.pop()
        list.append(a+b)

    elif ss=="-":
        a=list.pop()
        b=list.pop()
        list.append(b-a)
        
    else:
        list.append(int(ss))
   
    
print list.pop()


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long int> a(n);
  int ans = 50;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int kans = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      kans++;
    }
    ans = min(ans, kans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
		Scanner stdIn = new Scanner(System.in);
		int H, W; 		
		
		do {
			H = stdIn.nextInt();
			W = stdIn.nextInt();
			
			if( W == 0 && H == 0)break;
			
			for(int i = 1; i <= H; i++) {
				for(int j = 1; j <= W; j++) {
					if( i == 1 || i == H || j == 1 || j == W) {
						if( j == W) {
							System.out.println("#");
						}else {
							System.out.print("#");
						}
					}else {
						System.out.print(".");
					}
				}
		
			}
			
			System.out.print("\n");
			
		}while(true);			
	}
}


Measured memory_bytes: 37416
#include<iostream>

using namespace std;
int d, t, s;

int main() {
	cin >> d >> t >> s;
	if (s != 0) {
		if (1.0*d / s <= t) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main(void)
{
	int a,b,c,d,s1,s2;
	
	scanf("%d%d%d%d",&a,&b,&c,&d);
	
	s1=a*b;
	s2=c*d;
	
	if(s1>=s2){
		printf("%d",s1);
	}
	else{
		printf("%d",s2);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define N 15

int n,e;
int edge[N][N];
int py[N],px[N];

int solve_dp(){
    int (*dp)[N];
    dp = (int(*)[N])malloc(sizeof(int)*(1<<n)*N);
    int m = 1<<n;
    int i,j,k,l,b;
    for(i = 0;i < m;i++) for(j = 0;j < n;j++) dp[i][j] = -1;
    dp[1][0] = 0;
    for(i = 1;i < n;i++){
        for(j = 0;j < m;j++){
            if(i != __builtin_popcount(j)) continue;
            for(k = 0;k < n;k++){
                if(dp[j][k] < 0) continue;
                for(l = 0;l < n;l++){
                    b = 1<<l;
                    if((b&j) || edge[k][l] == -1) continue;
                    b = j|b;
                    if(dp[b][l] < 0 || dp[b][l] > dp[j][k]+edge[k][l]) dp[b][l] = dp[j][k]+edge[k][l];
                }
            }
        }
    }
    int res = -1;
    for(i = 0;i < n;i++){
        if(dp[(1<<n)-1][i] == -1 || edge[i][0] == -1) continue;
        int a = dp[(1<<n)-1][i] + edge[i][0];
        if(res == -1 || res > a) res = a;
    }
    free(dp);
    return res;
}

int solve(){
    int i,j;
    int a,b,d;
    scanf("%d %d",&n,&e);
    for(i = 0;i < n;i++){
        for(j = 0;j < n;j++){
            edge[i][j] = -1;
        }
    }
    for(i = 0;i < e;i++){
        scanf("%d %d %d",&a,&b,&d);
        edge[a][b] = d;
    }
    return solve_dp();
}

int main(){
    printf("%d\n",solve());
}



Measured memory_bytes: 4240
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
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; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
template <typename T>
struct UnionFind {
   vector<T> par; 
 
   UnionFind(T N) : par(N) { 
        for(T i = 0; i < N; i++) par[i] = i;
   }
 
   int root(T x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
   }
 
   void unite(T x, T y) { 
       T rx = root(x); 
       T ry = root(y); 
       if (rx == ry) return; 
       par[rx] = ry; 
   }
 
   bool same(T x, T y) { 
       T rx = root(x);
       T ry = root(y);
       return rx == ry;
   }
};
 

bool is_product_overflow(long double a, long double b) {

	long double prod = a * b;
	
	return (prod / b != a);
}


int main(){

    long double a,b,c;
    cin >> a >> b >> c;
    long double d=c-a-b;


    if(d>0 && 4*a*b<d*d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
 
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

vector<pair<ll, ll> > v;

ll calc(ll x, ll y) {
    return x * x * x * x * x - y * y * y * y * y;
} 

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    ll x;
    cin >> x;
    for (int i = -1000; i <= 1000; ++i) {
        for (int j = -1000; j <= 1000; ++j) {
            if (calc(i, j) == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        } 
    }
    
    return 0;
}



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

int main() {
  int N;
  string S;
  cin >> N >> S;
  for (int i = 0; i < N - 1; i++) {
  	if (S[i] == S[i + 1]) {
      S[i] = '-';
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
  	if (S[i] != '-') {
    	count++;
    }
  }
  cout << count << endl;
}

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

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

Measured memory_bytes: 3088
S = input()
r = 1
arr = [0]
for c in S[::-1]:
    arr.append((arr[-1] + int(c) * r) % 2019)
    r *= 10
    r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

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

namespace ABC132A
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            char[] A = new char[4];
            A[0] = S[0];
            A[1] = S[1];
            A[2] = S[2];
            A[3] = S[3];
            string ans = "No";
            if (A[0]==A[1]&&A[2]==A[3]&&A[0]!=A[2])
            {
                ans = "Yes";
            }
            if (A[0]==A[2]&&A[1]==A[3]&&A[0]!=A[1])
            {
                ans = "Yes";
            }
            if (A[0]==A[3]&&A[1]==A[2]&&A[0]!=A[1])
            {
                ans = "Yes";
            }
            Console.WriteLine(ans);
            //入力例
            // ASSA
            // STOP
            // FFEE
            // FREE
        }
    }
}


Measured memory_bytes: 11092
def solve(fld)
  $h.times do |y|
    fld[y].each_cons(2).with_index do |(a, b), x|
      if a != b
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
        return true if search(adjust(fld.transpose))
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
      end
    end
  end
  false
end

def search(fld)
  return true if fld.flatten.all?{ |v| v == '.' }
  res_x = counter(fld, $h)
  fld = fld.transpose
  res_y = counter(fld, $w)
  return false if res_x.size == 0 && res_y.size == 0
  res_x.each do |y, x|
    $n.times{ |i| fld[x + i][y] = nil }
  end
  res_y.each do |y, x|
    $n.times{ |i| fld[y][x + i] = nil }
  end
  search(adjust(fld))
end

def counter(fld, r)
  res = []
  r.times do |y|
    fld[y].each_cons($n).with_index do |ar, x|
      next if ar[0] == '.'
      res << [y, x] if ar.all?{|v| v == fld[y][x] }
    end
  end
  res
end

def adjust(fld)
  $w.times do |x|
    fld[x].map! { |v| v if v =~ /[A-Z]/ }.compact!
    ($h - fld[x].size).times{ fld[x].unshift('.') }
  end
  fld.transpose
end

$h, $w, $n = gets.split.map(&:to_i)
fld = $h.times.map{ gets.chomp.split('') }
puts solve(fld) ? 'YES' : 'NO'

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

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

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

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int n=read();
	map<int,int> cnt;
	int ans=0;
	REP(i,n)
		cnt[read()]++;
	for(auto kv:cnt){
		if(kv.first<=kv.second)ans+=kv.second-kv.first;
		else ans+=kv.second;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string N;
    cin >> N;
    if((N[0]==N[1]&&N[0]==N[2])||(N[1]==N[2]&&N[1]==N[3])){
        cout << "Yes" << endl;
    }
    else cout <<"No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005;
ll a[N],b[N],num[N];
int x[100][100];
int n,m,k;
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld",&a[i]);
    }
    for(int i=1; i<=n; i++)
    {
        if(i%2==1)
            b[1]+=a[i];
        else
            b[1]-=a[i];
    }
    for(int i=2;i<=n;i++)
	{
		b[i]=2*a[i-1]-b[i-1];
	}
	 for(int i=1;i<=n;i++)
	{
		cout<<b[i]<<" ";
	}
	

    
    return 0;
}


Measured memory_bytes: 3840
#include <stdio.h>

int main()
{
	int d, n, N;
	scanf("%d", &N);
	for (n = N, d = 0; n > 0; d += n % 10, n /= 10);
	if (N % d == 0) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1620
#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint k, x;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> k >> x;
	if(500*k >= x) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int, pair<int, int> >P;

int R;
int W[2],H[2],X[2],Y[2];
int o[2][512][512];
int cost[2][100005];
int vis[2][512][512];
int dy[]={0,-1,0,1},dx[]={-1,0,1,0};

int main(){
  while(scanf("%d",&R) && R){
    for(int i=0;i<2;i++){
      scanf("%d%d%d%d",&W[i],&H[i],&X[i],&Y[i]); X[i]--; Y[i]--;
      for(int j=0;j<H[i];j++) for(int k=0;k<W[i];k++) scanf("%d",&o[i][j][k]);
    }
    memset(vis, 0, sizeof vis);
    for(int i=0;i<2;i++) for(int j=0;j<=R;j++) cost[i][j] = 1<<29;
    for(int i=0;i<2;i++){
      cost[i][0] = 0;
      priority_queue<P, vector<P>, greater<P> >q;
      q.push(make_pair(o[i][Y[i]][X[i]], make_pair(Y[i], X[i])));
      vis[i][Y[i]][X[i]] = 1;
      for(int r=1;r<=min(R, W[i]*H[i]);r++){
	P p = q.top(); q.pop();
	int c = p.first, y = p.second.first, x = p.second.second;
	cost[i][r] = max(cost[i][r-1], c);
	for(int d=0;d<4;d++){
	  int nx=x+dx[d],ny=y+dy[d];
	  if(ny<0||ny>=H[i]||nx<0||nx>=W[i]||vis[i][ny][nx]) continue;
	  q.push(make_pair(o[i][ny][nx], make_pair(ny, nx)));
	  vis[i][ny][nx] = 1;
	}
      }
    }

    int res = 1<<29;
    for(int i=0;i<=R;i++){
      res = min(res, cost[0][i]+cost[1][R-i]);
    }
    printf("%d\n", res);
  }
  return 0;
}

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

int main() {
  int N;
  ll D, A;
  cin >> N >> D >> A;
  ll X, H;
  vector<P> mypair(N);
  rep(i, N) cin >> mypair[i].first >> mypair[i].second;
  sort(mypair.begin(), mypair.end());

  D *= 2;
  ll tot = 0; // 今与えているダメージの総和;
  queue<pair<ll, ll> > q; // (いつまで有効か、ダメージがどれくらいか)
  ll ans = 0;
  rep(i, N) {
    ll X = mypair[i].first;
    ll H = mypair[i].second;
    while (q.size() && q.front().first < X) {
      tot -= q.front().second;
      q.pop();
    }
    H -= tot;
    if (H > 0) {
      ll num = (H + A -1) / A; // ceil(H / A);
      ans += num;
      ll damage = num * A;
      tot += damage;
      q.emplace(X + D, damage);  // emplace = push + make_pair?
    }
  }

  cout << ans << endl;
  return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (c - a - b < 0ll) {
    cout << "No" << endl;
  } else {
    ll tmp = c - a - b;
    if (tmp*tmp > (4*a*b)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ll n, m = 0, M = 0;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  ll r = 0;
  set<ll> c;
  REP(i, n) {
    if (a[i] < 3200)
      c.insert((ll)floor((double)a[i] / 400));
    else
      r++;
  }
  REP(i, 8) {
    if (c.count(i)) {
      m++;
      M++;
    }
  }
  if (r ==n) m++;
  M += r;
  cout << m << " " << M << endl;
  return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define EPS 1e-8
#define INF 1e9+10
#define INFL 1e18
typedef long long ll;
using namespace std; //576
int main()
{
  int X;
  cin >> X;
  for(int i=1;i*100<=X;i++){
      if(0<=X-100*i&&X-100*i<=5*i){
          cout << 1 << endl;return 0;
      }
  }
  cout << 0 << endl;
}



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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

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

ll A, B;
// 0:white 1:black
vector<VL> grid(100, VL(100, 0));

signed main() {
    cin >> A >> B;
    REP(i, 50) REP(j, 100) { grid[i][j] = 1; }
    ll wcnt = 1, bcnt = 1;
    REP(i, 25) REP(j, 50) {
        if(++wcnt <= A) grid[2 * i + 1][2 * j + 1] = 0;
        if(++bcnt <= B) grid[50 + 2 * i + 1][2 * j + 1] = 1;
    }
    cout << 100 << " " << 100 << "\n";
    REP(i, 100) {
        REP(j, 100) { cout << (grid[i][j] == 0 ? "." : "#"); }
        cout << "\n";
    }
}


Measured memory_bytes: 384
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define M 500020
using namespace std;
int n,p[M],sum,now;
char ch[M];
int main(){
	scanf("%s",ch),n=strlen(ch),p[n]=10;
	for(int i=0;i<n;i++) p[n-i]=ch[i]-'0',p[n-i]*=9;
	for(int i=1;i<=n;i++) p[i+1]+=p[i]/10,p[i]%=10,sum+=p[i];
	sum+=p[n+1];
	for(int k=1;true;k++){
		for(p[now=1]+=9,sum+=9;p[now]>=10;now++) sum-=9,p[now+1]++,p[now]-=10;
		if(sum<=9*k){printf("%d\n",k);return 0;}
	}
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long long int N, M, T;
	cin >> N >> M >> T;
	vector<long long int>data( N );
	for( size_t i = 0; i < N; i++ ) {
		cin >> data[i];
	}
	long long int ans = 0;
	for( size_t i = 0; i < N - 1; i++ ) {
		ans += max( data[i + 1] - data[i] - 2 * M, 0LL );
	}
	ans += data[0] - M;
	ans += max( T - data[data.size() - 1] - M, 0LL );
	cout << ans << endl;
}

Measured memory_bytes: 3096
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	int k = 0;
	rep(i, N) {
		int a, b;
		cin >> a >> b;

		if (a == b) k++;
		else k = 0;
		if (k >= 3) {
			co("Yes");
			return 0;
		}
	}
	co("No");

	Would you please return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdint>
#include <cstdio>
using namespace std;

int main(int argc, char const* argv[])
{
  int64_t A, P;
  scanf("%ld %ld", &A, &P);
  P += A*3;
  printf("%ld\n", P / 2);
  return 0;
}


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

struct edge{int to;long long cost;};
typedef pair<int,int> pii;
typedef pair<long long,int> pli;
const long long INF = 1000000000000000000;

vector<int> g[100000];
vector<edge> G[100000];

int main(){
  int n,m,k,s,p,q;
  int dng[100000];
  scanf("%d %d %d %d %d %d",&n,&m,&k,&s,&p,&q);
  fill(dng,dng+n,0);
  queue<pii> que;
  for(int i=0;i<k;i++){
    int c;
    scanf("%d",&c);
    dng[c-1] = 2;
    que.push(pii(c-1,s));
  }
  for(int i=0;i<m;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  while(!que.empty()){
    int v = que.front().first;
    int ns = que.front().second;
    que.pop();
    if(ns==0) continue;
    for(int i=0;i<g[v].size();i++){
      int to = g[v][i];
      if(dng[to]==0){
        dng[to] = 1;
        que.push(pii(to,ns-1));
      }
    }
  }
  for(int i=0;i<n;i++){
    if(g[i].size()==0) printf("555\n");
    for(int j=0;j<g[i].size();j++){
      edge e;
      e.to = g[i][j];
      if(dng[e.to]==0) e.cost = p;
      else if(dng[e.to]==1) e.cost = q;
      //else if(dng[e.to]==2) e.cost = 0;
      if(dng[e.to]!=2) G[i].push_back(e);
    }
  }
  long long d[n];
  priority_queue<pli,vector<pli>,greater<pli> > pq;
  fill(d,d+n,INF);
  d[0] = 0;
  pq.push(pli(0,0));
  while(!pq.empty()){
    int v = pq.top().second;
    long long c = pq.top().first;
    pq.pop();
    if(d[v]<c) continue;
    for(int i=0;i<G[v].size();i++){
      int to = G[v][i].to;
      if(d[to]>d[v]+G[v][i].cost){
        d[to] = d[v]+G[v][i].cost;
        pq.push(pli(d[to],to));
      }
    }
  }
  if(dng[n-1]==0) d[n-1]-=p;
  else if(dng[n-1]==1) d[n-1]-=q;
  printf("%lld\n",d[n-1]);
  return 0;
}

Measured memory_bytes: 22184
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;
vec d2(201, 0);
mat dist(201, vec(201,INF));

bool dfs(ll v, ll c){//c>0 :even c<0 :odd
    if(d2[v] == -c) return false;
    if(d2[v] == c) return true;
    d2[v] = c;
    rep(i,N){
        if(dist[v][i] == 1){
            if(!dfs(i,-c)) return false;
        }
    }
    return true;
}

int main() {
    cin>>N;
    rep(i,N){
        cin>>S;
        rep(j,N) if(S[j] == '1') dist[i][j] = dist[j][i] = 1;//list
    }
    ll num = 0;
    rep(i,N){
        if(d2[i] == 0) {//距離計算していない
            ++num;//group index
            if (!dfs(i, num)) {
                cout << -1 << endl;//2分木でない
                return 0;
            }
        }
    }
    rep(k,N){
        rep(i,N){
            rep(j,N){
                if(dist[i][j] > dist[i][k] + dist[k][j]){
                    dist[i][j] = dist[i][k] + dist[k][j];//わーシャルフロイドで最短距離
                }
            }
        }
    }
    mat group(num,vec(0));//group index : set
    rep(i,N) group[abs(d2[i]) - 1].push_back(i);
    ll ans = 0;
    for(vec &g : group){
        ll temp = 0;
        for(ll i : g){
            for(ll j : g){
                if(i != j) temp = max(temp,dist[i][j]);
            }
        }
        ans += temp + 1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3888
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long int ll;

int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> s(n);
  rep(i, n) cin >> s.at(i);

  vector<ll> v, v10;
  rep(i, n) {
    if (s.at(i) % 10 != 0) v.push_back(s.at(i));
    else v10.push_back(s.at(i));
  }
  ll ans = 0;

  if (v.size() != 0) {
    sort(all(v));
    ans = accumulate(all(v), 0);
    if (ans % 10 == 0) ans -= v.at(0);
    ans += accumulate(all(v10), 0);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){

    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if ( a <= b && b <= c )    printf("%d %d %d\n", a, b, c);
    else if ( a < c && c <= b )    printf("%d %d %d\n", a, c, b);
    else if ( b <= a && a <= c )    printf("%d %d %d\n", b, a, c);
    else if ( b <= c && c <= a )    printf("%d %d %d\n", b, c, a);  
    else if ( c <= a && a <= b )    printf("%d %d %d\n", c, a, b);
    else if ( c <= b && b <= a )    printf("%d %d %d\n", c, b, a);

    return 0;
    

    
}




Measured memory_bytes: 2036
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
lAend = 0
lBstart = 0
lAe_Bs = 0
cnt = 0

for i in range(N):
    S = input().rstrip()
    if S[0]=='B' and S[-1] =='A':
        lAe_Bs+=1
    elif S[0] == 'B':
        lBstart+=1
    elif S[-1] == 'A':
        lAend+=1
    cnt += S.count('AB')

if lAe_Bs >0:
    cnt += lAe_Bs -1
    
if lAe_Bs > 0 and lAend >0:
    cnt += 1
    lAend -=1
if lAe_Bs > 0 and lBstart>0:
    cnt +=1
    lBstart -=1

cnt += min(lAend,lBstart)

print(cnt)


Measured memory_bytes: 9276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define rALL(x) x.rbegin(), x.rend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll n;   cin >> n;
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];
    ll res=0;
    rep(i, n){
        while(0<a[i]){
            FOR(j, i, n){
                if(!a[j]) break;
                a[j] -= 1;
            }
            res += 1;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  if(n/100==n%10) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

struct Node{
	Node* l;
	Node* r;
	double R;
	string s;
	set<string> se;
	Node() : l(nullptr), r(nullptr){}
};

int c;
int N;
string s;

map<pair<Node*, Node*>, int> compm;
// X????????????????§°??§????????? -1
// ?????? 0
// Y????????????????§°??§?????????  1
int comp(Node* X, Node* Y){
	if(compm.count({ X, Y })) return compm[{X, Y}];
	if(X->R != Y->R){
		if(X->R < Y->R) return compm[{X, Y}] = -1;
		return compm[{X, Y}] = 1;
	}
	if(X->s == "()" && Y->s == "()"){
		return compm[{X, Y}] = 0;
	}

	Node *xmin, *xmax;
	Node *ymin, *ymax;
	if(comp(X->l, X->r) < 0){
		xmax = X->l, xmin = X->r;
	}
	else{
		xmin = X->l, xmax = X->r;
	}
	if(comp(Y->l, Y->r) < 0){
		ymax = Y->l, ymin = Y->r;
	}
	else{
		ymin = Y->l, ymax = Y->r;
	}
	int res = comp(xmax, ymax);
	if(res != 0){
		if(res < 0) return compm[{X, Y}] = -1;
		return compm[{X, Y}] = 1;
	}
	return compm[{X, Y}] = comp(xmin, ymin);
}

Node* f(){
	Node* n = new Node();
	if(s[c] == 'x'){
		c++;
		n->s = "()";
		n->se.insert("()");
		n->R = 0;
		return n;
	}
	assert(s[c] == '(');
	c++;
	n->l = f();
	assert(s[c] == ' ');
	c++;
	n->r = f();
	int cnt = 0;
	for(auto v : n->l->se){
		n->se.insert(v);
		if(n->r->se.count(v)) cnt++;
	}
	for(auto v : n->r->se){
		n->se.insert(v);
	}
	n->R = double(cnt) / n->se.size();

	string ls = n->l->s, rs = n->r->s;
	if(ls > rs) swap(ls, rs);
	n->s = "(" + ls + rs + ")";
	n->se.insert(n->s);

	assert(s[c] == ')');
	c++;
	return n;
}

void g(Node* n, bool left){
	if(n->s == "()"){
		cout << "x";
		return;
	}
	if(left && comp(n->l, n->r) > 0){
		swap(n->l, n->r);
	}
	if(!left && comp(n->l, n->r) < 0){
		swap(n->l, n->r);
	}

	cout << "(";
	g(n->l, true);
	cout << " ";
	g(n->r, false);
	cout << ")";
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	while(getline(cin, s), s != "0"){
		compm.clear();
		N = s.size();
		c = 0;
		Node* r = f();
		//cout << s << endl;
		g(r, 1);
		cout << endl;
	}
}

Measured memory_bytes: 8988
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define pi (acos(-1))
// https://atcoder.jp/contests/abc172/tasks/abc172_d
int main()
{
        int n; std::cin>>n;int ac=0, wa=0,tle=0,re=0;
        std::string s;  for(int i=0;i!=n;++i){
                std::cin>>s;
        if(s=="AC"){ac++;}else if(s=="WA"){wa++;
        }else if(s=="TLE"){tle++;}else{re++;}
        }
        std::cout<<"AC x "<<ac<<std::endl;
        std::cout<<"WA x "<<wa<<std::endl;
        std::cout<<"TLE x "<<tle<<std::endl;
        std::cout<<"RE x "<<re<<std::endl;
    return 0;
}


Measured memory_bytes: 3624
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var n int
	var x float64
	fmt.Scan(&n)
	a := atof(nextSlice())
	for i := 0; i < n; i++ {
		x += 1 / a[i]
	}
	fmt.Println(1 / x)
}

func nextSlice() []string {
	sc.Scan()
	return strings.Split(sc.Text(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func scanSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func scanFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

// ---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func larger(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func largest(a, b, c int) (lgst int) {
	if a > b {
		lgst = a
	} else {
		lgst = b
	}
	if c > lgst {
		lgst = c
	}
	return
}

func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func smallest(a, b, c int) (slst int) {
	if a < b {
		slst = a
	} else {
		slst = b
	}
	if c < slst {
		slst = c
	}
	return
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

// ---------------------------------------------------

func yesOrNo(b bool) string {
	if b {
		return "Yes"
	}
	return "No"
}

func yesorNO(b bool) string {
	if b {
		return "YES"
	}
	return "NO"
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	
	static Scanner input = new Scanner(System.in);
	static int n;
	static int[] values;
	
	public static void main(String[] args) {
		
		getInput();
		
		int maximumProfit = values[1] - values[0];
		int minimumValue = Math.min(values[0], values[1]);
		
		for(int i = 2; i < n; i++) {
			
			maximumProfit = Math.max(values[i] - minimumValue, maximumProfit);
			
			minimumValue = Math.min(minimumValue, values[i]);
			
		}
		
		System.out.println(maximumProfit);
		
	}
	
	public static void getInput() {
		n = input.nextInt();
		values = new int[n];
		
		for(int i = 0; i < n; i++) {
			values[i] = input.nextInt();
		}
	}

}


Measured memory_bytes: 101716
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

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

  int x,y;
  cin>>x>>y;

  for(int a=0;a<=x;a++){
    int b=x-a;
    if(a*2+b*4==y) drop("Yes");
  }
  drop("No");
  return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<vector<int>>A(2,vector<int>(N));
  for(int i=0;i<2;i++){
  for(int j=0;j<N;j++)
    cin>>A.at(i).at(j);
  }
vector<int>B(N);
  int sum=A.at(0).at(0);
  for(int i=0;i<N;i++)
    sum+=A.at(1).at(i);
  B.at(0)=sum;
  for(int i=1;i<N;i++){
  B.at(i)=B.at(i-1)+A.at(0).at(i)-A.at(1).at(i-1);
  }
  sort(B.begin(),B.end());
  cout<<B.at(N-1)<<endl;
  return 0;
}

Measured memory_bytes: 256