akhauriyash/Code-Regression huggingface dataset:
N,P=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
odd=false
for i in a do
  i%2==1&&odd=true
end
if odd==false
  if P==0
    puts(2**N)
  else
    puts(0)
  end
else
  puts(2**(N-1))
end


Measured memory_bytes: 1788
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j;
    string str,str1;
    cin>>str>>str1;
    int arr[3001][3001];
    memset(arr,0,sizeof(arr));
    for(i=0;i<=str.length();i++)
    for(j=0;j<=str1.length();j++)
    {
        if(i==0||j==0)
        arr[i][j] = 0;
        else if(str[i-1]==str1[j-1])
        {
            arr[i][j] = arr[i-1][j-1]+1;
        }
        else
            arr[i][j] = max(arr[i-1][j],arr[i][j-1]);
    }
    i = str.length();
    j = str1.length();
    int len = arr[i][j];
    char lcs[len+1];
    int tmp = len;
    while(i>=0 && j>0)
    {
        if(str[i-1]==str1[j-1])
        {
            lcs[len--] = str[i-1];
            i--;
            j--;
            
        }
        else if(arr[i-1][j]>=arr[i][j-1])
        i--;
        else
        j--;
    }
    for(i=1;i<=tmp;++i)
    cout<<lcs[i];
    cout<<endl;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n, a, b;
        cin >> n >> a >> b;
        int c1 = 0, c2 = 0, c3 = 0;
        for(int i = 0; i < n; i++){
            int x;
            cin >> x;
            if(x <= a){
                c1++;
            }else if(x > a and x < b + 1){
                c2++;
            }else if(x >= b + 1){
                c3++;
            }
        }
        cout << min({c1, c2, c3}) << '\n';
    }
}

Measured memory_bytes: 31488
from operator import itemgetter
from itertools import accumulate
 
n = int(input())
a = sorted(tuple(map(int, reversed(input().split()))) for _ in range(n))
c, d = (map(itemgetter(i), a) for i in (0, 1))
print('YNeos'[any(x < y for x, y in zip(c, accumulate(d)))::2])                    


Measured memory_bytes: 29516
# -*- coding: utf-8 -*-

import sys
import os
import math


x1, y1, x2, y2 = list(map(float, input().split()))
x_diff = x1 - x2
y_diff = y1 - y2
d = math.sqrt(x_diff ** 2 + y_diff ** 2)
print(d)

Measured memory_bytes: 7604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    ll n,m,ans=0LL,tmp;
  	cin >> n >> m;
    string s;
    vector<ll> vec(n,0);
    map<int,int> mp;
    rep(i,n)mp[i]=0;
    rep(i,m){
        cin >> tmp >> s;
        tmp--;
        if(s=="WA"&&mp[tmp]==0)vec.at(tmp)++;
        else if(s=="AC"&&mp[tmp]==0){
            mp[tmp]=1;
            ans++;
        }
    }
    cout << ans << " ";
    ans=0;
    rep(i,n)if(mp[i]==1)ans+=vec.at(i);
    cout << ans << endl;
}

Measured memory_bytes: 7680
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#define MOD 1000000007
#define EPS 1e-10
using namespace std;

int main() {
   int n, m;
   vector<int> ans;
   cin >> n >> m;
   ans.assign(n+1, 0);
   int u, v;
   while (m--) {
      cin >> u >> v;
      ans[u]++;
      ans[v]++;
   }

   for (int i = 1; i <= n; i++) {
      cout << ans[i] << endl;
   }
}


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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	string s, t;
	cin >> s >> t;
	int ans = 1e9, n = s.length(), m = t.length();
	for (int i = 0; i <= n - m; i++) {
		int k{};
		for (int j = 0; j < m; j++) k += (s[i + j] != t[j]);
		ans = min(k, ans);
	}
	cout << ans;
}

Measured memory_bytes: 3628
/*
    handle - pruvi007
    questionName - 
    Contest - 
    Topic - 
    Platform - 
*/
#include<bits/stdc++.h>
using namespace std;
#define ll          long long int
#define fast         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define INF          1e18
#define MOD          1000000007
#define Vi           vector<ll> 
#define Vs           vector<string>
#define VI           vector<vector<ll> >
#define PII          pair<ll,ll> 
#define PSI          pair<string,ll>
#define PB           push_back


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

int main()
{
    fast;
    int n;
    cin >> n;
    ll a[n];
    for(int i=0;i<n;i++)
    	cin >> a[i];
   	ll dp[n];
   	dp[0] = a[0];
   	for(int i=1;i<n;i++)
   		dp[i] = max(dp[i-1],a[i]);
   	ll ans = 0;
   	for(int i=0;i<n;i++)
   		ans += dp[i]-a[i];
   	cout << ans << '\n';
}


Measured memory_bytes: 6780
#include "bits/stdc++.h"

using namespace std;

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

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int n;
vector<vector<pair<int, int>>> g;
vector<int> color;

void dfs(int now, int prev, int c) {
	for (auto p : g[now]) {
		if (p.first == prev) {
			continue;
		}

		if (p.second % 2 == 0) {
			color[p.first] = c;
		} else {
			color[p.first] = !c;
		}

		dfs(p.first, now, color[p.first]);
	}
}

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

	cin >> n;

	g.resize(n);
	color.resize(n);

	for (int i = 0; i < n - 1; i++) {
		int a, b, w;
		cin >> a >> b >> w;
		a--; b--;

		g[a].emplace_back(b, w);
		g[b].emplace_back(a, w);
	}

	color[0] = 1;
	dfs(0, 0, 1);

	for (auto v : color) {
		cout << v << endl;
	}
	return 0;
}


Measured memory_bytes: 8192
#include <stdio.h>

int main()
{   char s[4],t[4];
    scanf("%s",s);
    scanf("%s",t);
    int ans=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i])ans++;
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main(){
	ll r,c;
	ll mod = 1e9+7;
	cin>>r>>c;
	char grid[r+1][c+1];
	for(ll i=1;i<=r;i++){
		string s;
		cin>>s;
		// cout<<s<<endl;
		for(ll j=1;j<=c;j++){
			grid[i][j] = s[j-1];
		}
	}
	for(ll j=0;j<=c;j++){
		grid[0][j] = '#';
	}
	for(ll j=0;j<=r;j++){
		grid[j][0] = '#';
	}
	// for(ll i=0;i<=r;i++){
	// 	for(ll j=0;j<=c;j++){
	// 		cout<<grid[i][j];
	// 	}
	// 	cout<<endl;
	// }
	ll dp[r+1][c+1];
	for(ll i=1;i<=r;i++){
		for(ll j=1;j<=c;j++){
			dp[i][j] = 0;
		}
	}
	// dp[1][1] = 1;
	for(ll i=1;i<=r;i++){
		for(ll j=1;j<=c;j++){
			if(i==1 && j==1){
				dp[i][j] = 1;
			}
			else if(grid[i][j-1] == '.' && grid[i-1][j] == '.'){
				dp[i][j] = (dp[i][j-1]%mod + dp[i-1][j]%mod)%mod;
			}
			else if(grid[i][j-1] == '#' && grid[i-1][j] == '#'){
				dp[i][j] = 0;
			}
			else if(grid[i][j-1] == '.'){
				dp[i][j] = dp[i][j-1];
			}
			else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	// for(ll i=1;i<=r;i++){
	// 	for(ll j=1;j<=c;j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	cout<<dp[r][c]%mod<<endl;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int h, w;
string a[10];

int main(){
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> a[i];
	}
	
	bool b = 1;
	if(a[0][0] != '#') b = 0;
	P now = make_pair(0,0);
	while(1){
		a[now.first][now.second] = '.';
		if(now.first < h && a[now.first+1][now.second] == '#'){
			now.first++;
			continue;
		}
		if(now.second < w && a[now.first][now.second+1] == '#'){
			now.second++;
			continue;
		}
		if(now.first != h-1 || now.second != w-1) b = 0;
		break;
	}
	
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(a[i][j] == '#') b = 0;
		}
	}
	if(b) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

input = sys.stdin.readline


class AtCoder:
    def main(self):
        H, W = map(int, input().split())
        A = [list(input().rstrip()) for _ in range(H)]

        blacks = []
        for h in range(H):
            for w in range(W):
                if A[h][w] == '#':
                    blacks.append((h + 1, w + 1))

        moving_range = ((1, 0), (-1, 0), (0, -1), (0, 1))

        ans = 0
        while blacks:
            next_blacks = []
            for b_h, b_w in blacks:
                for m_h, m_w in moving_range:
                    h, w = b_h + m_h, b_w + m_w
                    if not (0 < h <= H and 0 < w <= W):
                        continue
                    if A[h-1][w-1] == '.':
                        A[h-1][w-1] = '#'
                        next_blacks.append((h, w))
            if len(next_blacks) > 0:
                ans += 1
            blacks = next_blacks

        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 132432
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  VAR(i64, N, M);
  OUTL((M >= 2 * N) ? N + (M - 2 * N) / 4 : M / 2);
  return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        os.println((int)Math.ceil((double)N/2.0));
    }
}

Measured memory_bytes: 21716
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

ll d(ll n,ll m){
	string s=to_string(n);
	string t=to_string(m);
	return max((ll)s.size(),(ll)t.size());
}

int main(){
	ll ans=INF;
	ll N;
	cin>>N;
	for(ll i=1;i*i<=N;i++){
		if(N%i!=0)continue;
		ll j=N/i;
		ans=min(ans,d(i,j));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
a,b = map(int,input().split())
p = list(map(int,input().split()))

res = [0]*3

for v in p:
    if v <= a:
        res[0]+=1
    elif a < v <= b:
        res[1]+=1
    else:
        res[2]+=1
print(min(res))

Measured memory_bytes: 8940
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
   int n;
   cin>>n;
   ll a[n];
   for(int i=0;i<n;i++){
      cin>>a[i];
   }
   int num=0;
   ll minus=1LL<<60;
   ll ans=0;
   for(int i=0;i<n;i++){
      if(a[i]<0)num++;
      minus=min(minus,abs(a[i]));
      ans+=abs(a[i]);
   }
   if(num%2==0){
      cout<<ans<<endl;
   }else{
      cout<<ans-2*minus<<endl;
   }
   return 0;
}

Measured memory_bytes: 1024
A = input()

num = [int(A[0])]
hugou = ['']*3
ans = [0]*4
ans[0] = int(A[0])

for i in range(1,len(A)):
    num.append(A[i])

for i in range(2**3):
    tmp = format(i,'03b')
    for j in range(len(tmp)):
        if tmp[j] == "0":
            ans[j+1] = -int(num[j+1])
            hugou[j] = '-'
        else:
            ans[j+1] = int(num[j+1])
            hugou[j] = '+'
    if sum(ans) == 7:
        print(str(ans[0]) + hugou[0] \
              + str(abs(ans[1])) + hugou[1] \
              + str(abs(ans[2])) + hugou[2] \
              + str(abs(ans[3]))+"=7")
        exit()
    

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

bool dfs(int v, vector<vector<int>>& g, vector<bool>& visited, vector<int>& matched){
    for(auto u : g[v]){
        if(visited[u]) continue;
        visited[u]=true;
        if(matched[u]==-1 || dfs(matched[u], g, visited, matched)){
            matched[u]=v;
            return true;
        }
    }
    return false;
}

int main(){
    int n; cin >> n;
    vector<pair<int, int>> abs(n), cds(n);
    for(int i=0; i<n; ++i){
        cin >> abs[i].first >> abs[i].second;
    }
    for(int i=0; i<n; ++i){
        cin >> cds[i].first >> cds[i].second;
    }
    vector<vector<int>> g(n, vector<int>());
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            if(abs[i].first < cds[j].first && abs[i].second < cds[j].second){
                g[i].push_back(j);
            }
        }
    }
    int ans=0;
    vector<int> matched(n, -1);
    for(int i=0; i<n; ++i){
        vector<bool> visited(n);
        if(dfs(i, g, visited, matched)) ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int binary_search_left(vector<int> &vec, long long left, long long right){
    if(right-left<2){
        return right;
    }
    long long mid=(left+right)/2;
    for(int i=0; i<vec.size(); i++){
        mid-=mid%vec[i];
    }
    if(mid==2){
        return binary_search_left(vec, left, mid);
    }else{
        return binary_search_left(vec, mid, right);
    }
}

int binary_search_right(vector<int> &vec, long long left, long long right){
    if(right-left<2){
        return left;
    }
    long long mid=(left+right)/2;
    for(int i=0; i<vec.size(); i++){
        mid-=mid%vec[i];
    }
    if(mid==2){
        return binary_search_right(vec, mid, right);
    }else{
        return binary_search_right(vec, left, mid);
    }
}

int main(){
    int K;
    cin >> K;
    vector<int> A(K);
    for(int i=0; i<K; i++){
        cin >> A[i];
    }

    long long max_=3;
    long long min_=2;
    if(A[K-1]!=2){
        max_=2;
    }
    for(int i=K-2; i>=0; i--){
        min_=(min_/A[i]+(min_%A[i]>0))*A[i];
        max_=(max_/A[i]+1)*A[i]-1;
    }
    if(min_>=max_){
        cout << -1 << endl;
    }else{
        cout << min_ << ' ' << max_ << endl;
    }

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define re register
long long d[1001000];
int p[1001000],pq[1001000],fa[1001000],sz[1001000],n;
inline bool cmp(re int A,re int B){return d[A]<d[B];}
inline bool cmp1(re int A,re int B){return d[A]-n+2*sz[A]<d[B]-n+2*sz[B];}
int main()
{
	re int ta=1;
	scanf("%d",&n);
	for(re int i=1;i<=n;i++)scanf("%lld",&d[i]),p[i]=i,sz[i]=1;
	sort(p+1,p+n+1,cmp);
	pq[1]=p[n];
	for(re int i=n-1;i;i--)
	{
		while(ta&&d[p[i]]==d[pq[1]]-n+2*sz[pq[1]])
		{
			fa[pq[1]]=p[i];sz[p[i]]+=sz[pq[1]];
			pop_heap(pq+1,pq+ta+1,cmp1);
			ta--;
		}
		pq[++ta]=p[i];
		push_heap(pq+1,pq+ta+1,cmp1);
	}
	if(ta!=1)puts("-1");
	else
	{
		re long long ans=0;
		for(re int i=1;i<=n;i++)if(fa[i])ans+=sz[i];else ans-=d[i];
		if(ans==0){for(re int i=1;i<=n;i++)if(fa[i])printf("%d %d\n",i,fa[i]);}
		else puts("-1");
	}
}

Measured memory_bytes: 14976
#include<stdio.h>
#include<string.h>

void reverse( char *str )
{
    int i , len ;
    len = strlen( str ) ;

    char temp , *p ;

    p = &str[len - 1] ;

    for( i = 0 ; i < len / 2 ; i++)
    {
        temp = *str ;
        *str = *p ;
        *p = temp;

        str++ ;
        p-- ;
    }
}

int main()
{
    char str[20 + 3] ;

    while( gets( str ) )
    {
        reverse( str ) ;
        puts( str ) ;
    }

    return 0 ;
}

Measured memory_bytes: 524
fn main() {
    let (n, x, t): (usize, usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let ans = (n + x - 1) / x * t;
    println!("{}", ans);
}

Measured memory_bytes: 2108
import java.util.*;
class Main {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       int[] num = new int[100001];
       long sum = 0;
       for(int i = 0;i < n;i++){
            int a = sc.nextInt();
            sum += a;
            num[a]++;
       }
       int q = sc.nextInt();
       for(int i = 0;i < q;i++){
            int data = sc.nextInt();
            int change = sc.nextInt();
            int sa = change - data;
            sum += sa * num[data];
            num[change] += num[data];
            num[data] = 0;
            System.out.println(sum);
       }
   }
}


Measured memory_bytes: 60816
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
//#define int long long
using LL = long long;
using namespace std;
using Graph = vector<vector<int>>;
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 int INF = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

// うしさんのライブラリを少し改造した
template<int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

const int mod = 2019;
using modint = ModInt<mod>;

modint fact[200010];

modint nCr(int n, int r){
    return fact[n]/(fact[n-r]*fact[r]);
}

// 初期化
// fact[0] = 1; rep(i, 200001) fact[i] = (fact[i-1] * i);

modint dp[202020];

signed main(){
    fastcin();

    string s;
    cin >> s;

    int n = s.size();
    reverse(all(s));
    rep(i, n){
        int x = s[i]-'0';
        dp[i+1] = dp[i] + modint(10).pow(i)*x;
        // cout << dp[i+1] << endl;
    }
    map<int, int> mp;
    rep(i, n+1){
        mp[dp[i].x]++;
    }
    LL ans = 0;
    rep(i, 2019){
        ans += mp[i]*(mp[i]-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5312
#include<bits/stdc++.h>
using namespace std;
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
using vii = vector<vi>;
using pii = pair<int, int>;

using vc = vector<char>;
using vcc = vector<vc>;
using vb = vector<bool>;
using vbb = vector<vb>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using vd = vector<double>;
using vdd = vector<vd>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


const int MOD = 1e9 + 7;

vector<pii> prime_factorization(int n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pii> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}
vector<pli> prime_factorization(ll n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pli> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}

// n は 2以上の素数表を返す
vb Primes(int n){
  vector<bool> res(n + 1, true);
  res.at(0) = false; res.at(1) = false;
  for(int i = 2; i <= sqrt(n); i++){
    if(res.at(i)){
      for(int j = 2 * i; j <= n; j += i){
        res.at(j) = false;
      }
    }
  }
  return res;
}
// ===================================================

int main(){
  int n, m, nxm; cin >> n >> m; nxm = n * m;
  vi A(n + 1, 0), B(m + 1, 0);
  REP(i, n) cin >> A.at(i);
  REP(j, m) cin >> B.at(j);
  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  REP(i, n - 1) if(A.at(i) == A.at(i + 1)){
    cout << "0\n"; return 0;
  }
  REP(j, m - 1) if(B.at(j) == B.at(j + 1)){
    cout << "0\n"; return 0;
  }
  if((A.at(0) != nxm) || (B.at(0) != nxm) ){
    cout << "0\n"; return 0;
  }
  ll res = 1;
  int i = 0, j = 0;
  for(int t = nxm; t > 0; t--){
    int koho;
    if(A.at(i) == t){
      if(B.at(j) == t){
        koho = 1;
        j++;
      }
      else koho = j;
      i++;
    }
    else{
      if(B.at(j) == t){
        koho = i;
        j++;
      }
      else koho = i * j - (nxm - t);
    }
    res = (res * koho) % MOD;
  }
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                                                                               
using namespace std;
#define FOR(v1, v2) for (v1 = 0; v1 < v2; ++v1)

int main () {
  int n;
  cin >> n;
  int h[n];
  int dp[n+2];
  int i;
  FOR(i, n) {
    cin >> h[i];
  }

  FOR(i, n+2) {
    dp[i] = INT_MAX;
    cerr << dp[i] << " ";
  }
  cerr << endl;

  dp[0] = 0;
  FOR(i, n) {
    int s1 = abs(h[i] - h[i+1]) + dp[i];
    int s2 = abs(h[i] - h[i+2]) + dp[i];
    if (s1 < dp[i + 1]) {
      dp[i + 1] = s1; 
    }   

    if (s2 < dp[i + 2]) {
      dp[i + 2] = s2; 
    }   
  }

  cout << dp[n-1] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main(void){
	int A,B;
	int i;
	int s;
 
	scanf("%d %d", &A, &B);

	for(i=0; i < 2; i++){
		if(A >= B){
			s += A--;
		}else{
			s += B--;
		}
	}

	printf("%d\n", s);
 
	return 0;
}

Measured memory_bytes: 128
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=true;

      string str;


set<char>s;
  cin>>str;

  map<char,ll>mp;

   for(auto x : str)
    {
        s.insert(x);

        mp[x]++;
    }
    for(auto x : str)
    {
        if(mp[x]!=2)
        {
            flag=false;
            break;
        }
    }

   if(s.size()==2 && flag)cout<<"Yes"<<endl;

   else cout<<"No"<<endl;









}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
//#define int long long

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v){ t = v; }

template<typename T,typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--, b--, c--, d--;
    string s;
    cin >> s;

    if(c < d)
    {
        while(b < d)
        {
            if(s[b+1] == '.') b += 1;
            else if(s[b+2] == '.') b += 2;
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
        while(a < c)
        {
            if(s[a+1] == '.') a += 1;
            else if(s[a+2] == '.') a += 2;
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    else 
    {
        while(b < d && (s[b-1] != '.' || s[b+1] != '.'))
        {
            if(s[b+1] == '.') b += 1;
            else if(s[b+2] == '.') b += 2;
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
        s[b] = '#';
        while(a < c)
        {
            if(s[a+1] == '.') a += 1;
            else if(s[a+2] == '.') a += 2;
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
        while(b < d)
        {
            if(s[b+1] == '.') b += 1;
            else if(s[b+2] == '.') b += 2;
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

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

int main(){

	int date;
	cin >> date;

	switch(date){
		case 22 :
			cout << "Christmas Eve Eve Eve" << endl;
			break;
		case 23 :
			cout << "Christmas Eve Eve" << endl;
			break;
		case 24 :
			cout << "Christmas Eve" << endl;
			break;
		case 25 :
			cout << "Christmas" << endl;
			break;
		default :
			exit(1);
			break;
	}

	return 0;

}

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

int main() {
  for (int i = 0; i< 4; i++){
    char j; cin >> j;
        cout << j;
}
cout << " ";
for (int i = 0; i < 8; i++) {
  char j; cin >> j;
  cout << j;
}
cout << endl;}



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

int main(){
	int N;
	char S[N];
	int K;
	char res[N];

	cin >> N;
	cin >> S;
	cin >> K;
	for (int i = 0; i < N; i++){
		if (S[i] == S[K-1]){
			res[i] = S[i];
		}else{
			res[i] = '*';
		}
	}
  	cout << res << endl;
}

Measured memory_bytes: 2304
from collections import deque
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
adjL = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    adjL[a].append(b)
    adjL[b].append(a)
querys = [tuple(map(int, input().split())) for _ in range(Q)]

anss = [0] * N
for p, x in querys:
    anss[p-1] += x

def bfs(vSt):
    useds = [False] * (N)
    useds[vSt] = True
    Q = deque([vSt])
    while Q:
        vNow = Q.popleft()
        ans = anss[vNow]
        for v2 in adjL[vNow]:
            if not useds[v2]:
                anss[v2] += ans
                Q.append(v2)
                useds[v2] = True

bfs(0)

print(' '.join(map(str, anss)))


Measured memory_bytes: 144092
#include <cstdio>
using namespace std;
int n,m,a[100005],head[100005],cnt=0;
struct Edge{
  int to,nxt;
}e[200005];
void add_edge(int u,int v){
  e[++cnt].to=v;
  e[cnt].nxt=head[u];
  head[u]=cnt;
}
int main()
{
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;++i)
    scanf("%d",&a[i]);
  for(int i=1;i<=m;++i){
    int a,b;
    scanf("%d%d",&a,&b);
    add_edge(a,b);add_edge(b,a);
  }int ans=0;
  for(int i=1;i<=n;++i){
    bool flag=1;
    for(int j=head[i];j;j=e[j].nxt){
      if(a[e[j].to]>=a[i]){
        flag=0;break;
      }
    }
    ans+=flag;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 4056
#include <stdio.h>
int main(void){
    // Your code here!
    int H,W;
    int i,j;
    
    while(1){
        scanf("%d %d",&H,&W);
        
        if(H==0&&W==0) break;
        
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if(i==0||j==0||i==H-1||j==W-1){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2036
import java.util.*;

public class Main {
public static int M;
public static int N;
    public static void main(String[] ano) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        while(true){
        M= scan.nextInt();
        N= scan.nextInt();
        if((M |N )== 0)break;
        scan.nextLine();
        
        char [][] map = new char[M][N];
        for(int i=0;i<M;i++){
        	String line = scan.nextLine();
        	for(int j=0;j<N;j++){
        		map[i][j] = line.charAt(j);
        	}
        }
        int i=0;
        int j=0;
        int count =1;
        boolean flag =true;
        while(flag){
        		switch(map[i][j]){
        		case '>':
        			map[i][j++] = '*';
        			break;
        		case '<':
        			map[i][j--] = '*';
        			break;
        		case '^':
        			map[i--][j] = '*';
        			break;
        		case 'v':
        			map[i++][j] = '*';
        			break;
        		case '.':
        			System.out.println(j+" "+i);
        			flag = false;
        			break;
        		case '*':
        			System.out.println("LOOP");
        			flag =false ;
        			break;
        		}
        	}
        }
    }
}

Measured memory_bytes: 12000
import java.io.*
import java.util.*

fun solve(N: Int, X: Int, m: IntArray){
    var rest = X
    var ans = 0
    rest -= m.sum()
    ans += N
    ans += rest / m.min()!!
    println(ans)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val X = sc.next().toInt()
    val m = IntArray(N)
    for (i in 0 until N) {
        m[i] = sc.next().toInt()
    }
    solve(N, X, m)
}



Measured memory_bytes: 33968
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define sl set<ll>
#define vs vector<string>
#define vl vector<ll>
#define vi vector<int>
#define vpl vector<pair<ll,ll>>
#define pb push_back
#define PI 3.14159265358979323846
#define ll long long
#define ld long double
#define endl "\n"
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define repp(i,a,b) for (ll i = (a); i >= (b); i--)
#define rop(i,a,b)  for(ll i=(a); i>(b); i--)
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define tt long long t; cin>>t; while(t--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
const int maxn=1e5+100;

int main()
{
    IOS;
    string s;
    cin>>s;
    ll n=s.length();
    if(s[n-1]=='s')cout<<s<<"es";
    else cout<<s<<"s";
   
}

Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	int n; cin >> n;
	cout << (n-1) / 2 << endl;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y){return (!y)?x:gcd(y,x%y);}
inline ll lcm(ll x,ll y){return x/gcd(x,y)*y;} 
int n;
ll ans;
int main(){
	scanf("%d",&n); ans=1;
	for (int i=1;i<=n;i++){
		ll x; scanf("%lld",&x);
		ans=lcm(ans,x);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int x, a, b;
    cin >> x >> a >> b;
    
    if (abs(x-a) < abs(x-b))
        cout << "A" << endl;
    else
        cout << "B" << endl;

    return 0;
}

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

using namespace std;

vector<string> V;

bool find(string s){
  sort(V.begin(),V.end());
  return binary_search(V.begin(),V.end(),s);
}

int StoI(string s, int pos){

  string s1 = "", s2 = "";
  
  for(int i = 0; i < pos; i++)
    s1 += s[i];
  
  for(int i = pos; i < s.length(); i++)
    s2 += s[i];

  stringstream ss1(s1), ss2(s2);
  int n1,n2;
  ss1 >> n1;
  ss2 >> n2;
  return n1*n2;
}

string ItoS(int n){
  string out = "";
  if(n == 0) out = "0";

  while(n){
    out += n%10+'0';
    n /= 10;
  }
  reverse(out.begin(),out.end());
  return out;
}

string make(string n){
  int out = 0;

  for(int i = 1; i < n.length(); i++)
     out = max(out,StoI(n,i));

  return ItoS(out);
}

int solve(string n){
  
  int rev = 0;

  while(1){
    
    if(find(n)) return -1;
    else V.push_back(n);

    if(n.length() == 1) return rev;

    n = make(n);
    rev++;
  }
}

int main(){
  int n;
  cin >> n;
  while(n--){
    V.clear();
    string in;
    cin >> in;
    cout << solve(in) << endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 6e18;
const int mod = 1e9 + 7;

signed main() {
    int N, M;
    cin >> N >> M;
    cout << (N == M ? "Yes" : "No") << endl;
}


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

int main()
{
    int n,d,x,t;
    while(scanf("%d%d%d",&n,&d,&x)!=EOF)
    {
        int sum = 0;
        while(n--)
        {
            scanf("%d",&t);
            int flag = 1;
            while(flag<=d)
            {
                flag += t;
                sum++;
            }
        }
        printf("%d\n",sum+x);
    }
}


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

using namespace std;

int main(){
	int n,t,count=0;
	cin>>n>>t;
	vector<int> tt(n);
	for(int i=0;i<n;i++){
    	cin>>tt.at(i);
    }
	for(int j=1;j<n;j++){
    	if(tt[j]-tt[j-1]>=t){
        	count+=t;
        }else{
        	count+=tt[j]-tt[j-1];
        }
    }
	cout<<t+count;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
cm = 1000
p1 = p2 = a[0]
for i in range(1,n):
    #print(i,a[i],p1,p2)
    if(a[i]>=p2):
        p2 = a[i]
    elif(a[i]<p2):
        cm += (cm//p1)*(p2-p1)
        p1 = p2 = a[i]
cm += (cm//p1)*(p2-p1)
print(cm)


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

long Parent(long i) {
    return (long)floor((double)i / 2.0);
}

long Left(long i) {
    return 2 * i;
}

long Right(long i) {
    return (2 * i + 1);
}

int main() {
    int H;
    scanf("%d", &H);
    long A[H];
    for (int i=0; i<H; i++) scanf("%ld", &A[i]);

    for (int i=0; i<H; i++) {
        printf("node %d: key = %ld, ", i + 1, A[i]);
        int p = Parent(i + 1) - 1;
        int r = Right(i + 1) - 1;
        int l = Left(i + 1) - 1;
        if (0 <= p && p < H) printf("parent key = %ld, ", A[p]);
        if (l < H) printf("left key = %ld, ", A[l]);
        if (r < H) printf("right key = %ld, ", A[r]);
        printf("\n");
    }
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
#define mp make_pair


const int MAXN = 100010;

vl fact(MAXN);
vl rfact(MAXN);

ll mod_pow(ll x, ll p, ll M = MOD) {
	ll a = 1;
	while (p) {
		if (p % 2)
			a = a*x%M;
		x = x*x%M;
		p /= 2;
	}
	return a;
}

ll mod_inverse(ll a, ll M = MOD) {
	return mod_pow(a, M - 2, M);
}

void set_fact(ll n, ll M = MOD) {
	fact[0] = fact[1] = rfact[0] = rfact[1] = 1;
	for (ll i = 2; i <= n; i++) {
		fact[i] = i * fact[i - 1] % M;
		rfact[i] = mod_inverse(fact[i], M);
	}
}


int main() {
  int n;
  cin >> n;
  vl a(n);
  rep (i, n) {
    cin >> a[i];
  }
  set_fact(n + 4);
  ll ans = 0;
  vl sum(n + 1);
  rep (i, n) {
    sum[i + 1] = sum[i] + fact[n] * mod_inverse(i + 1) % MOD;
    sum[i + 1] %= MOD;
  }
  rep (i, n) {
    ll temp = 0;
    // i, i - 1, i - 2, .., 0, 1, 2, n - 1 - i
    temp += sum[i + 1] + sum[n - i] - sum[1];
    temp = temp % MOD * a[i] % MOD;
    ans += temp;
    ans %= MOD;
  }
  while (ans < 0) {
    ans = (ans + MOD) % MOD;
  }
  cout << ans << endl;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

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

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,h,w;
  cin >> n >> h >> w;
  VI x(n);
  rep(i,n){
    cin >> x[i];
  }
  int board[w*n+1000];
  memset(board,0,sizeof(board));

  rep(i,n){
    int start = w * i;
    if(i % 2 == 0){// right +
      board[start + x[i]] ++;
      board[start + x[i] + w]--;
    }else{
      board[start - x[i]] ++;
      board[start - x[i] + w] --;
    }
  }

  FOR(i,1, w*n+1000){
    board[i] += board[i-1];
  }

  ll ans = 0;
  rep(i,w*n){
    if(!board[i]) ans += h;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define maxn 100001
#define pb push_back
using namespace std;
typedef long long LL;

int n,m;
int ans[maxn];
int stMult[maxn];
vector<int> adj[maxn];
vector<int> preMult[maxn];
vector<int> sufMult[maxn];
vector<int> children[maxn];

void dfs2(int node, LL upMult) {
	ans[node] = upMult * ( ( stMult[node]-1+m ) % m ) % m;
	int nChild = (int) children[node].size();
	for( int i = 0 ; i < nChild ; i++ ) {
		int to = children[node][i];
		if( i == 0 && i == nChild-1 ) {
			LL newUpMult = (upMult + 1) % m;
			dfs2(to, newUpMult);
		}
		else if( i == 0 ) {
			LL newUpMult = (upMult * sufMult[node][1] % m + 1) % m;
			dfs2(to, newUpMult);
		}
		else if( i == nChild - 1 ) {
			LL newUpMult = (upMult * preMult[node][nChild-2] % m + 1) % m;
			dfs2(to, newUpMult);
		}
		else {
			LL newUpMult = (upMult * preMult[node][i-1]) % m;
			newUpMult = (newUpMult * sufMult[node][i+1]) % m;
			newUpMult = (newUpMult + 1) % m;
			dfs2(to, newUpMult);
		}
	}
}

int dfs(int node, int dad) {
	vector<int> v;
	int allMult = 1;
	for( int i = 0 ; i < (int) adj[node].size() ; i++ ) {
		int to = adj[node][i];
		if( to != dad ) {
			children[node].pb(to);
			int mult = dfs(to, node);
			v.pb(mult);
			allMult = ( (LL) allMult * mult ) % m;
		}
	}
	if(v.size()) {
		int nChild = v.size();
		preMult[node].pb( v[0] );
		for( int i = 1 ; i < nChild ; i++ )
			preMult[node].pb( ( (LL) preMult[node][i-1] * v[i] ) % m );
		sufMult[node].pb( v[nChild-1] );
		for( int i = nChild-2 ; i >= 0 ; i-- )
			sufMult[node].pb( ( (LL) sufMult[node][nChild-i-2] * v[i] ) % m );
		reverse( sufMult[node].begin() , sufMult[node].end() );
	}
	return stMult[node] = (allMult + 1) % m;
}

int main() {
	scanf("%d%d",&n,&m);
	for( int i = 1 ; i < n ; i++ ) {
		int x,y;
		scanf("%d%d",&x,&y);
		adj[x].pb(y);
		adj[y].pb(x);
	}
	dfs(1,0);
	dfs2(1,1);
	for( int i = 1 ; i <= n ; i++ )
		printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 32896