akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define S second
#define F first
#define int long long

typedef long long ll;

const int maxn = 3e5+10;
const ll INF = 1e18;

ll mod;
vector<ll> g[maxn], pre[maxn], suf[maxn];
ll f[maxn], dp[maxn], d[maxn];
int par[maxn], pos[maxn];

void dfs(int v)
{
    f[v] = 1;

    for(auto u : g[v])
        if(u != par[v])
        {
            par[u] = v;
            dfs(u);
            pos[u] = pre[v].size();
            (f[v] *= (f[u]+1)) %= mod;
            if(pre[v].empty())
                pre[v].push_back((f[u]+1) % mod);
            else
                pre[v].push_back((pre[v].back() * (f[u]+1)) % mod);
        }

    if(g[v].size())
        for(int i = g[v].size()-1; i >= 0; i--)
        {
            int u = g[v][i];
            if(u != par[v])
            {
                if(suf[v].empty())
                    suf[v].push_back((f[u]+1) % mod);
                else
                    suf[v].push_back((suf[v].back() * (f[u]+1)) % mod);
            }
        }
    reverse(suf[v].begin(), suf[v].end());
}

void dfs_get_dp(int v)
{
    d[v] = 1;
    if(v != 1)
    {
        d[v] = d[par[v]];
        if(pos[v] >= 1)
            (d[v] *= pre[par[v]][pos[v]-1]) %= mod;
        if(pos[v] < pre[par[v]].size()-1)
            (d[v] *= suf[par[v]][pos[v]+1]) %= mod;
        (d[v] += 1) %= mod;
    }
    for(auto u : g[v])
        if(u != par[v])
            dfs_get_dp(u);
}

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

    int n; cin>> n >> mod;
    for(int i = 1; i < n; i++)
    {
        int u, v; cin>> u >> v;
        g[v].push_back(u);
        g[u].push_back(v);
    }

    dfs(1);
    dfs_get_dp(1);

    for(int v = 1; v <= n; v++)
    {
        cout<< (d[v] * f[v]) % mod <<"\n";
    }
}





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

int main() {
	int a, b, c;
	while (cin >> a >> b, a | b) {
		cin >> c;
		vector<vector<int>>s(a);
		for (int k = 0; k < a; k++) {
			vector<int>p(b);
			s[k] = p;
		}
		map<vector<int>, bool>d;
		for (int e = 0; e < c; e++) {
			vector<int>f(2);
			int z, q;
			cin >> z >> q;
			z--; q--;
			f[0] = z;
			f[1] = q;
			d[f];
			d[f] = true;
		}
		for (int g = 0; g < a; g++) {
			for (int h = 0; h < b; h++) {
				vector<int>i(2);
				i[0] = g; i[1] = h;
				d[i];
				if (d[i]) { s[g][h] = 0; }
				else {
					if (g&&h)s[g][h] = s[g - 1][h] + s[g][h - 1];
					else if (g)s[g][h] = s[g - 1][h];
					else if (h)s[g][h] = s[g][h - 1];
					else s[g][h] = 1;
				}
			}
		}
		cout << s[a - 1][b - 1] << endl;
	}
}

Measured memory_bytes: 3164
#include<cstdio>
#include<cstring>
using namespace std;
char s[11];
bool flag;
int main()
{
	scanf("%s",s);
	flag=true;
	for (int i=0;i<strlen(s);i++)
		if (s[i]!=s[strlen(s)-i-1])
		{
			flag=false;
			break;
		}
	if (flag)printf("Yes");
	else printf("No");
}

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

const int MAX_N = 1e3+100;
typedef long long LL;
typedef vector<LL> VLL;
int N,K;
LL sum[MAX_N];
int bit[70];

int main(){
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0);
	LL x;
	while(cin >> N >> K){
		memset(sum, 0, sizeof sum);
		for(int i = 1; i <= N; ++i) {
			cin >> x;
			sum[i] += x + sum[i-1]; 
		}
		VLL v;
		for(int i = 1; i <= N; ++i){
			for(int j = i; j <= N; ++j){
				v.push_back(sum[j] - sum[i-1]);
			}
		}
		LL ans = 0;
		memset(bit, 0, sizeof bit);
		for(int i = 40; i >= 0; --i){
			int k = 0;
			ans += (1LL << i);
			for(int j = 0; j < v.size(); ++j){
				if((v[j]&ans) == ans) ++k;
			}
			if(k < K) ans -= (1LL << i);
		}
		cout << ans << endl;
	}
	return 0;
} 

Measured memory_bytes: 6512
class Dice:
    def __init__(self, num):
        self.state = {}
        for i in range(1,6+1):
            self.state[i] = num[i-1]

        self.reversed_state = {}
        for key,val in zip(self.state.keys(), self.state.values()):
            self.reversed_state[val] = key
        
    def search_side(self, x,y):
        a = self.reversed_state[x]
        b = self.reversed_state[y]
        if str(a)+str(b) in '12651':
            side = self.state[3]
        elif str(b)+str(a) in '12651':
            side = self.state[4]
        elif str(a)+str(b) in '13641':
            side = self.state[5]
        elif str(b)+str(a) in '13641':
            side = self.state[2]
        elif str(a)+str(b) in '23542':
            side = self.state[1]
        elif str(b)+str(a) in '23542':
            side = self.state[6]
        else:
            side = None
        return side
        
num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))

dice1 = Dice(num1)
dice2 = Dice(num2)


pairs = [(1,2), (2,6),(6,5),(5,1), (1,3),(3,6),(6,4),(4,1), (2,3),(3,5),(5,4),(4,2)]
pairs = [(dice1.state[a], dice1.state[b]) for (a,b) in pairs]

ans = 'Yes'
for x,y in pairs:
    side1 = dice1.search_side(x,y)
    side2 = dice2.search_side(x,y)
    if side1!=side2:
        ans = 'No'
        break
print(ans)


Measured memory_bytes: 5612
import java.io.PrintWriter
val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun println(value: Any) { pw.println(value) }

fun func() {
    val (N, K) = listOfInt()
    var ans = if (K > 1) N - K else 0
    println("${ans}")
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 36128
from collections import Counter

n = int(input())
sss = [input() for _ in range(n)]
d = {s[1:]: 0 for s in sss}
flags = [1 << (i * 18) for i in range(26)]

trie_chr = [-1]
trie_children = [{}]
trie_counter = [0]
trie_fin = [0]
s_fin_node = []
l = 1

for s in sss:
    node = 0
    trie_counter[node] += 1
    for i in range(len(s) - 1, 0, -1):
        c = ord(s[i]) - 97
        if c in trie_children[node]:
            node = trie_children[node][c]
            trie_counter[node] += 1
        else:
            trie_chr.append(c)
            trie_children.append({})
            trie_fin.append(0)
            trie_children[node][c] = l
            trie_counter.append(1)
            node = l
            l += 1
    trie_fin[node] += 1
    s_fin_node.append(node)

trie_flags = [0] * l

for s in sss:
    cnt = Counter(s)
    flag = 0
    for c in cnt:
        flag |= flags[ord(c) - 97]
    node = 0
    if len(s) > 1 and trie_fin[node] > 0:
        trie_flags[node] += flag

    for i in range(len(s) - 1, 1, -1):
        c = s[i]
        k = ord(c) - 97
        cnt[c] -= 1
        if cnt[c] == 0:
            flag ^= flags[k]

        node = trie_children[node][k]
        # print(s, i, node, trie_counter[node])
        if trie_counter[node] == 1:
            break
        if trie_fin[node] > 0:
            trie_flags[node] += flag
            # print('add', s, i)

# print([chr(c) if c >= 0 else -1 for c in trie_chr])
# print(trie_counter)
# print(trie_fin)
# print(trie_flags)
# print(s_fin_node)

ans = 0
mask = (1 << 18) - 1
for i, s in enumerate(sss):
    cnt = (trie_flags[s_fin_node[i]] >> ((ord(s[0]) - 97) * 18)) & mask
    ans += cnt

print(ans)


Measured memory_bytes: 318800
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main() 
{
	char c;
	cin >> c;
	cout << (char)(c + 1) << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

#import
#import math
#import numpy as np
N = int(input())
#= input()
#= map(int, input().split())
A = list(map(int, input().split()))
#= [input(), input()]
#= [list(map(int, input().split())) for _ in range(N)]
#= [int(input()) for _ in range(N)]
#= {i:[] for i in range(N)}

dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = 0

for key in dic:
    if dic[key] != key:
        if dic[key] > key:
            ans += dic[key] - key
        else:
            ans += dic[key]

print(ans)

Measured memory_bytes: 21668
#include <stdio.h>

int main(){
  int n,i;
  int maxv;
  int minv;
  scanf("%d",&n);
  int r[n];
  for(i = 0; i < n; i++){
    scanf("%d",&r[i]);
  }
  maxv = r[1] - r[0];
  minv = r[0];
  for(i = 1; i < n; i++){
    if(maxv < r[i] - minv){
      maxv = r[i] - minv;
    }
    if(minv > r[i]){
      minv = r[i];
    }
  }
  printf("%d\n",maxv);
  return 0;
}



Measured memory_bytes: 2544
n,t=map(int,input().split())
a=list(map(int,input().split()))
b=[]
m=a[0]
for i in range(1,n):
  b.append(a[i]-m)
  m=min(m,a[i])
x=max(b)
ct=0
for i in range(len(b)):
  if b[i]==x:
    ct+=1
print(ct)

Measured memory_bytes: 15020
s=input()

if s[-1] == '2' or s[-1] == '4' or s[-1] == '5' or s[-1] == '7' or s[-1] == '9':
    print('hon')
elif s[-1] == '0' or s[-1] == '1' or s[-1] == '6' or s[-1] == '8':
    print('pon')
elif s[-1] == '3':
    print('bon')

Measured memory_bytes: 9124
while(True):
	n,l,r = map(int, input().split())
	if (n+l+r)==0:break
	a = list(int(input()) for i in range(n))
	count = 0
	for year in range(l,r+1):
		var = n
		for i in range(n):
			if year%a[i]==0:
				var = i
				break
		if var%2==0:
			count += 1
	print(count)


Measured memory_bytes: 5604
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    double x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    double a=x1-x2;
    double b=y1-y2;
    double c=a*a+b*b;
    double d=sqrt(c);
    cout<<fixed<<d<<endl;
    
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main() {
  int a, b;
  char str[20];
  bool postal = true;
  scanf("%d %d", &a, &b);
  scanf("%s", str);

  if(str[a] != '-') {
    postal = false;
  }

  for(int i = 0; str[i] != '\0'; i++) {
    if(i != a) {
      if(str[i] < '0' || str[i] > '9') {
        postal = false;
        break;
      }
    }
  }

  (postal) ? puts("Yes") : puts("No");
  return 0;
}

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

//bool hantei(string &s, string &p, int &i, bool &judge){
  //string t;
  
  //for(int j=0;j<s.size();j++){
    //if(i+j<=s.size()-1){
      //t.at(j)=s.at(i+j);
    //}
    //else
      //int
      //if(i+j==s.size())
        //j=0;
      //t.at(j)=s.at(j)
  //}
//}

int main()
{
  string s, p, t;
  int i;
  bool judge=0;
 
  cin >> s >> p;
  
  t = s + s;
  
  for(i=0;i<s.size();i++){
    if(t.substr(i, p.size())==p)
      judge=1;
  }
  
  if(judge==1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  //if((i+p.size()-1)>(s.size()-1)){
    
  //else{
    //if(p == s.substr(i, p.size()))
      //judge=1;
  //}
  
  //cout << p << endl;
  
  return 0;
}



Measured memory_bytes: 3160
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n, k;
	cin >> n >> k;
	int h[100001];
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}

	int result[100001];
	result[n - 1] = 0;
	result[n - 2] = abs(h[n - 1] - h[n - 2]);
	for(int i = n - 3; i >= 0; i--){
		result[i] = result[i + 1] + abs(h[i + 1] - h[i]);
		for(int j = 2; i + j < n && j <= k; j++){
			result[i] = min(result[i], result[i + j] + abs(h[i + j] - h[i]));
		}
	}
	cout << result[0] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  string O,E;
  cin >> O >> E;
  int n = O.size();
  int m = E.size();
  string ans = "";
  rep(i,n){
    ans.push_back(O[i]);
    if (i == n-1 && m < n){
      cout << ans << endl;
      return 0;
    }
    ans.push_back(E[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


class Program {

	const long mod = 1000000007;
	//public static int[] max;

	static void Main(string[] args) {

		char[] cs = new char[] { ' ', ',' };
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = vals[0];
		//string res="";

		//int y = vals[0];
		//int x = vals[1];


		int res = vals[0] + vals[1];

		if (res >= 10) { Console.WriteLine("error"); return; }
		Console.WriteLine(res);


		return;
	}



	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryl(string[] str) {
		long[] nums = new long[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}



	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
		return re;
	}

}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int ans,b;
int main(){
  int n,d;
  cin>>n>>d;
  vector<vector<int>>v(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>v[i][j];
    }
  }
  ans = 0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      b=0;
      for(int k=0;k<d;k++){
        int a=abs(v[i][k]-v[j][k]);
        b+=a*a;
      }
      bool flag = false;
     for(int x=0;x<=b;x++) {
       if(b==x*x){
         flag=true; 
       }
     }
     if(flag)ans++;
    }
    
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
//#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define M_PI 3.14159265358979323846
template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
	while (*sdbg != ',')cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
	os << "["; for (auto& vv : V) os << vv << ","; os << "]";
	return os;
}

ostream& operator<<(ostream& os, vector<bool> V) {
	os << "[";
	REP(i, 26) {
		if (V[i]) {
			os << (char)('a' + i) <<",";
		}
	}
	os << "]";
	return os;
}
template<class L, class R> ostream& operator<<(ostream& os, map<L,R> V) {
	os << "["; for (auto& vv : V) os << vv << ","; os << "]";
	return os;
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.st << "," << P.nd << ")";
}


#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#endif

template<typename Out>
void split(const std::string &s, char delim, Out result) {
	std::stringstream ss(s);
	std::string item;
	while (std::getline(ss, item, delim)) {
		*(result++) = item;
	}
}

std::vector<std::string> split(const std::string &s, char delim) {
	std::vector<std::string> elems;
	split(s, delim, std::back_inserter(elems));
	return elems;
}

void trim(string & s) {
	int idx = 0;
	int n = s.size();
	REP(i, n) {
		if (s[i] != ' ' && s[i] != '\t') {
			s = s.substr(i);
			break;
		}
	}
	while (!s.empty()) {
		if (s.back() == ' ' || s.back() == '\t') {
			s.pop_back();
		}
		else {
			break;
		}
	}
}



int32_t main(int32_t argc, char ** argv) {
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	string res;
	unordered_map<int, int> m;
	int h = 0;
	int nonEmpty = 0;
	int lastRes = INT_MAX;
	for (char c : s) {
		int off = c - 'a';
		h ^= 1 << off;
		if (h & (1 << off)) {
			nonEmpty++;
		}
		else {
			nonEmpty--;
		}
		if (nonEmpty <= 1) {
			m[h] = 1;
			lastRes = 1;
			continue;
		}
	nxt:;
		lastRes = INT_MAX;
		if (m.count(h)) {
			lastRes = m[h] + 1;
		}
		REP(i, 26) {
			h ^= 1 << i;
			if (m.count(h)) {
				int v = m[h];
				mini(lastRes, v + 1);
				h ^= 1 << i;
				if (m.count(h)) {
					mini(m[h], v + 1);
				}
				else {
					m[h] = v + 1;
				}
				h ^= 1 << i;
			}
			h ^= 1 << i;
		}
	}
	cout << lastRes;
}

Measured memory_bytes: 8668
n, w = [int(i) for i in input().split()]
a = [[int(n) for n in input().split()] for i in range(n)]

sv = {}
for ww, vv in a:
    added = {}
    for k, v in sv.items():
        added[ww+k] = vv+v
    for k, v in added.items():
        if (k <= w) and (k not in sv or v > sv[k]):
            sv[k] = v

    if (ww <= w) and (ww not in sv or vv > sv[ww]):
        sv[ww] = vv

print(max(sv.values()))

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))

typedef long long lint;
typedef pair<int, int> pii;

struct Cake {
	int w, d;
	
	Cake(int _w, int _d) : w(_w), d(_d) {}
	
	int area() { return w * d; }
		
	vector<Cake> cut_in(int s) {
		vector<Cake> res;
		
		int cnt = 0;
		while (1) {
			if (cnt % 2 == 0) {
				if (s <= w) break;
				s -= w;
				cnt++;
			} else {
				if (s <= d) break;
				s -= d;
				cnt++;
			}
		}
		
		if (cnt % 2 == 0) {
			res.push_back(Cake(s, d));
			res.push_back(Cake(w - s, d));
		} else {
			res.push_back(Cake(w, s));
			res.push_back(Cake(w, d - s));
		}
		
		if (res[0].area() > res[1].area()) swap(res[0], res[1]);
		return res;
	}
};

int n, w, d;

void solve() {
	vector<Cake> vc;
	vc.push_back(Cake(w,d));
	
	for_(i,0,n) {
		int p, s; cin >> p >> s;
		--p;
		
		int c_size = (int)vc.size();
		vector<Cake> sub;
		for_(j,0,c_size) if (j != p) sub.push_back(vc[j]);
		
		vector<Cake> cuts = vc[p].cut_in(s);
		sub.push_back(cuts[0]);
		sub.push_back(cuts[1]);
		
		vc = sub;
	}
	
	vector<int> ans;
	for_(i,0,n + 1) ans.push_back(vc[i].area());
	sort(allof(ans));
	for_(i,0,n + 1) {
		if (i < n) cout << ans[i] << " ";
		else cout << ans[i] << endl;
	}
}

int main() {
	while (cin >> n >> w >> d) {
		if (n == 0 && w == 0 && d == 0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 1220
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  long n,ii,jj;
  vector<long> l;
  cin >> n;
  l.resize(n);

  for(ii=0;ii<n;ii++){
    cin >> l[ii];
  }

  long sum;
  bool flg = true;
  for(ii=0;ii<n;ii++){
    sum = 0;
    for(jj=0;jj<n;jj++){
      if(jj != ii){
	sum += l[jj];
      }
    }
    if(l[ii] >= sum){
      flg = false;
    }
  }
  if(flg){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


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


int main(void) {

  ll n, ga, gb, sa, sb, ba, bb;
  cin >> n;
  cin >> ga >> sa >> ba;
  cin >> gb >> sb >> bb;
  

  ll d = 0;
  ll p = gb - ga, q = sb - sa, r = bb - ba;
  ll g = ga, s = sa, b = ba;
  vector<ll> pq(n + 2, 0);
  //gx+sy+bz<=nのもとでpx+qy+rzを最大化
  for (ll i = 1; i <= n; i++) {
    if (i - g >= 0) pq[i] = max(0LL, pq[i-g] + p);
    if (i - s >= 0) pq[i] = max(pq[i], pq[i-s] + q);
  }
  for (ll z = 0; b*z <= n; z++) {
    d = max(d, r*z + pq[n-b*z]);
  }
  
  n += d;

  d = 0;
  p = ga - gb; q = sa - sb; r = ba - bb;
  g = gb; s = sb; b = bb;
  vector<ll> qp(n + 2, 0);
  for (ll i = 1; i <= n; i++) {
    if (i - g >= 0) qp[i] = max(0LL, qp[i-g] + p);
    if (i - s >= 0) qp[i] = max(qp[i], qp[i-s] + q);
  }
  for (ll z = 0; b*z <= n; z++) {
    d = max(d, r*z + qp[n-b*z]);
  }
  

  cout << n + d << endl;

  return 0;

}

  
      
    


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

int main() {
  long long a, b, c, d; cin >> a >> b >> c >> d;
  long long sub = max(a*c, max(a*d, max(b*c, b*d)));
  if (a * b <= 0 || c * d <= 0) sub = max(sub, 0ll);
  cout << sub;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
bool vis[2000005];

int main(void) {
	int n, m; cin >> n >> m;
	vector<vector<int>> v(n+1);
	for(int i=0;i<m;i++) {
		int a, b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	vector<int> ans;
	queue<int> Q;
	for(int i=1;i<=n;i++) {
		if(!vis[i]) {
			vis[i] = true;
			Q.push(i);
			int cmp = 1;
			while(!Q.empty()) {
				int f = Q.front(); Q.pop();
				for(int j : v[f]) {
					if(!vis[j]) {
						vis[j] = true;
						Q.push(j);
						cmp++;
					}
				}
			}
			ans.pb(cmp);
		}
	}
	int maxi = 0;
	for(int i : ans) maxi = max(maxi, i);
	cout << maxi << endl;
	return 0;
}



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

int main() {
  long long N;
  cin >> N;

  long long ans = 1000000010000;
  for (long long i = 1; i * i <= N; i++) {
    long long j = N / i;
    if (i * j != N) continue;
    ans = min(ans, i + j - 2);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		double xa,xb,ya,yb,ra,rb;
		scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&ra,&xb,&yb,&rb);
		double l;
		if(ra>rb){
			l=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
			if(l<(ra-rb))printf("2");
			else if(l>=(ra-rb)&&l<=(ra+rb))printf("1");
			else printf("0");}
		else{
			l=sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya));
			if(l<(rb-ra))printf("-2");
			else if(l>=(rb-ra)&&l<=(ra+rb))printf("1");
			else printf("0");}
		printf("\n");}
	return 0;}


Measured memory_bytes: 2612
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,ans,ans1,ans2,ans3,ans4;
	cin>>a>>b;
	ans1=a+b;
	ans2=a-b;
	ans3=a*b;
	ans4=max(ans1,ans2);
	ans=max(ans4,ans3);
	cout<<ans<<endl;
	return 0;
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main () {
    ll N;
    cin >> N;
    vector <int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    vector<int> count(N);
    for(int i = 0; i < N; i++){
        count[A[i] - 1] = i + 1;
    }
    for(int i = 0; i < N; i++){
        cout << count[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



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

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string ac="AC",wa="WA";
  ll n,m;cin>>n>>m;
  vector<ll>flag(n),cnt(n);
  ll a=0,w=0;
  rep(i,m){
    ll num;
    string r;
    cin>>num>>r;
    num--;
    if(flag[num])continue;
    if(r==wa){
      w++;
      cnt[num]++;
    }
    else {
      flag[num]++;
      a++;
    }
  }
  rep(i,n){
    if(flag[i]==0){
      w-=cnt[i];
    }
  }


  cout<<a<<" "<<w<<endl;


  return 0;

}


Measured memory_bytes: 1792
import sys

man = int(input())
s = str(input())

if 1 >= man and man <= 100:
    print('No')
    sys.exit()

str = s[0:man]

r_val = str.count('R')
b_val = str.count('B')

if r_val > b_val:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size();
const int INF=INT_MAX;
int main(){
  ll k,ans;cin>>k;
  ll x=k/2;
  if(k%2==0){
    ans=x*x;
  }
  else{
    ans=x*(k-x);
  }
  cout<<ans<<endl;
}

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

int main()
{
    int k;
    vector<int> abc(3);
    cin >> abc[0] >> abc[1] >> abc[2] >> k;
    int sum,max,index;
    for(int i = 0; i < k; i++){
        max = 0;
        for(int j = 0; j < 3; j++){
            sum = 0;
            for(int h = 0; h < 3; h++){
                if(j == h){
                    sum += abc[h]*2;
                }else{
                    sum += abc[h];
                }
            }
            if(max < sum){
                max = sum;
                index = j;
            }
        }
        abc[index] *= 2;
    }
    cout << abc[0]+abc[1]+abc[2] << endl;
}

Measured memory_bytes: 256
S = []
for i in range(int(input())):
    S.append(input())
C0,C1,C2,C3=0,0,0,0
for s in S:
    if s == "AC":
        C0+=1
    elif s == "WA":
        C1+=1
    elif s == "TLE":
        C2+=1
    else:
        C3+=1
print("AC x  "+str(C0))
print("WA x "+str(C1))
print("TLE x "+str(+C2))
print("RE x "+str(C3))

Measured memory_bytes: 16204
#include <bits/stdc++.h>
int main() {
    for (std::string s : (std::string[1]){"\0"}) {
          if (s.clear(),0){}
          for (std::string in : (std::string[1]){"\0"}) {
             if (std::cin >> in, 0) {}
             for (char c : in) {
                if (c == '0') {
                  if (s+='0',0) {}
                }
                if (c == '1') {
                  if (s+='1',0){}
                }
                if (c == 'B') {
                  if (s.size()) {
                    if (s.pop_back(),0) {}
                  }
                }
             }
          }
          if (std::cout << s,0){}
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll N, M, Q;
ll ans;
ll A[100];
ll B[100];
ll C[100];
ll D[100];

void dfs(int idx, vector<ll>& X){
    if(idx == N){
        ll tmp = 0;
        REP(i,Q){
            ll a, b, c, d;
            a = A[i], b = B[i], c = C[i], d = D[i];
            if(X[b] - X[a] == c)
                tmp += d;
        }
        chmax(ans, tmp);
    }
    else{
        ll m = X[idx-1];
        for(int t = m; t <= M; t++){
            X[idx] = t;
            dfs(idx+1, X);
        }
    }
}

int main(){
    cin >> N >> M >> Q;
    REP(i,Q){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--;
        A[i] = a;
        B[i] = b;
        C[i] = c;
        D[i] = d;
    }

    vector<ll> X(N);
    X[0] = 1;
    ans = -1;
    dfs(1, X);

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


Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,ans=999999;
int w[2001],s[2001];
int main(){
  scanf("%d",&n);s[0]=0;
  for(int i=1;i<=n;i++)
  {
    scanf("%d",&w[i]);s[i]=s[i-1]+w[i];
  }
  for(int i=1;i<=n-1;i++){
    int t=abs(s[i]-s[n]+s[i]);
    ans=min(ans,t);
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

map <ll,ll> a;
int main() {
	ll n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		a[x]+=y;
	}
	ll sum=0,ans=0;
    for(auto itr = a.begin(); itr != a.end(); ++itr) {
        ll val =  itr->second ;
        ll now= itr->first;
        if(sum+val<k){
        	ans+=val*now;
        	sum+=val;
        }
        else{
        	ans+=(k-sum)*now;
        	break;
        }
    }	
    cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 6528
n = int(input())
nums = list(map(int, input().split()))

num_count = {}
for num in nums:
    num_count[num] = num_count.get(num, 0) + 1

total = 0
for num, ele in num_count.items():
    total += (ele * (ele - 1)) // 2

ans = []

for num in nums:
    ans.append(total - num_count[num] + 1)
print("\n".join(list(map(str, ans))))


Measured memory_bytes: 38972
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int S; cin >> S;
    int L=S/100;
    int R=S%100;
    
    if (1<=L && L<=12){
        if (1<=R && R<=12) cout << "AMBIGUOUS";
        else cout << "MMYY";
    }else{
        if (1<=R && R<=12) cout << "YYMM";
        else cout << "NA";
    }
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi a(n), b(n), f(n + 1, 1);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) f[i + 1] = f[i] * (i + 1);
	auto calc = [&](vi v){
		int res = 0;
		rep(i, n){
			res += f[n - 1 - i] * (v[i] - 1);
			for(int j = i + 1; j < n; j++) if(v[j] > v[i]) v[j]--;
		}
		return res;
	};
	cout << abs(calc(a) - calc(b)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;

long int MOD = 1000000007;

long int gyaku(long int a){
	int bits[33]={0};
	long int beki[33];
	long int bi=MOD-2;
	beki[0]=a;
	rep(i,32){
		beki[i+1] = (beki[i] * beki[i])%MOD;
	}
	rep(i,32){
		bits[i]=bi%2;
		bi = (bi-bits[i])/2;
	}
	long int ret=1;
	rep(i,32){
		if(bits[i]==1){
			ret = (ret * beki[i])%MOD;
		}
	}
	return ret%MOD;
}

long int bikkuri(long int a){
	return (a==1 || a==0)? 1:((bikkuri(a-1)*a)%MOD);
}

int main (){
	long int AAA,BBB,CCC,KKK;
	cin >> AAA >> BBB >>CCC >> KKK;

	if(KKK%2==0){
		cout << AAA-BBB <<endl;
	}
	else {
		cout << BBB-AAA <<endl;
	}
	return 0;
}


Measured memory_bytes: 256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    ll n, m ,k;
    cin>>n>>m>>k;
    vector<ll> fst(n), snd(m);
    for(int i = 0; i < n; i++)
        cin>>fst[i];
    for(int i = 0; i < m; i++)
        cin>>snd[i];
    ll ans = -1, f = 0, s = 0, cnt = 0;
    for(int i = 0; i < n; i++){
        if(cnt + fst[i]> k)
            break;
        ++f;
        cnt += fst[i];
    }
    for(int i = 0; i < m; i++){
        if(cnt + snd[i]> k)
            break;
        ++s;
        cnt += snd[i];
    }
    // cout<<s;
    ans = max(ans, f+s);
    for(int i = f-1; i>=0 ; i--){
        cnt -= fst[i];
        while(s < m && cnt+snd[s] <= k){
            cnt += snd[s];
            ++s;
            ans = max(i+s, ans);
        }
    }
    cout<<ans;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  int min=1000;
  for(int i=0; i<N-2; i++){
    string suji;
    suji.push_back(S.at(i));
    suji.push_back(S.at(i+1));
    suji.push_back(S.at(i+2));
    int number = stoi(suji); //文字列から数字
    if(abs(753-number)<min) min=abs(753-number);
  }
  cout<<min<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 222222;
ll a[N];
int n;

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    map<ll, ll> cnt;
    for(int i = 0; i <= n; i++) {
        cnt[a[i]]++;
    }
    ll ans = 0;
    for(p : cnt) {
        ll c = p.second - 1;
        ans += c * (c + 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N, K;
    string S;
    cin >> N >> K >> S;
    S[K-1] = S[K-1] - 'A' + 'a';
    _PR(S);

    return 0;
}

/*



*/

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

void nn(string& str){
    for(int i=0; i < str.size(); i++)
        if('A' <= str[i] && str[i] <= 'Z')
            str[i] = str[i] - 'A' + 'a';
}

int main(){
    string W,str;
    int cnt = 0;
    cin >> W;
    nn(W);
    
    while(true){
        cin >> str;
        if(str == "END_OF_TEXT") break;
        nn(str);
        if(str == W)
            cnt++;
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
#define all(i) i.begin(),i.end()
#define debug(i) std::cout << i << "\n"

using ll = long long;
using P = std::pair<int, int>;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;


int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
    int n,d;
    std::cin>>n>>d;
    int x[11][11]={0};
    rep(i,0,n){
        rep(j,0,d){
            std::cin>>x[i][j];
        }
    }
    int ans=0;
    rep(i,0,n){
        rep(j,i+1,n){
            int temp=0;
            rep(k,0,d){
                temp+=(int)pow(x[i][k]-x[j][k],2);
            }
            int cnt=1;
            while ((cnt*cnt)<=temp)
            {
                if((cnt*cnt)==temp){
                    ans++;
                    break;
                }
                cnt++;
            }
        }
    }
    std::cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int min(int a, int b)
{
    return a <= b ? a : b;
}

int main()
{
    int N;
    scanf("%d", &N);

    int dp[N+1];
    dp[0] = 0;
    for (int n = 1; n < N+1; ++n)
    {
        dp[n] = dp[n-1] + 1;
        int power = 6;
        while (power <= n)
        {
            dp[n] = min(dp[n], dp[n-power]+1);
            power *= 6;
        }
        power = 9;
        while (power <= n)
        {
            dp[n] = min(dp[n], dp[n-power]+1);
            power *= 9;
        }
    }

    printf("%d", dp[N]);

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i=0,j=0,k=0,x=0,y=0,count=0;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0 && y==0){
            break;
        }
        for(i=1;i<x;i++){
            for(j=i;j<x;j++){
                for(k=i; k<=x; k++){
                    if(i+j+k==y && i!=j && i!=k && j!=k && i<j && j<k){
                        //printf("%d %d %d\n",i,j,k);
                        count++;
                    }
                }
            }
        }
        printf("%d\n",count);
        count = 0;
    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define N 1000005
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1){
        c -= b;
        if(c<=0){
            cout<<"Yes";
            return 0;
        }
        a -= d;
        if(a<=0){
        cout<<"No";
        return 0;
        }
    }
 
    
    return 0;
}

Measured memory_bytes: 3652
import copy

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

tmp = 0
ans = 0
for i in range(N-1,0,-1):
    if H[i] <= H[i-1]:
        tmp += 1
        if tmp > ans:
            ans = copy.copy(tmp)
    else:
        tmp = 0

print(ans)


Measured memory_bytes: 14764
#include <iostream>
#include <list>
#include <string>
#include <tuple>
using namespace std;
using ll = long long;

ll f(ll n,ll x) {
	if (n == -1)return 0;
	return n / x + 1;
}

int main()
{
	ll a, b, x, cnt = 0;
	cin >> a >> b >> x;
	cnt = f(b, x) - f(a-1, x);
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset>
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fio ios_base::sync_with_stdio(false)
#define li long long int
#define ll int
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%lld",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 100000000000000005
#define MINN -10000000000000000
#define INTMAX 1000001000
#define pii pair<ll,ll> 
#define pdd pair<double,double>
#define pic pair<int,char>
#define N 5005
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
using namespace std;
li a[16][16];li n,inf=10000000000000000;li A[1<<16];li sum[1<<16];
void pre(){
    li i,j,k,c;
for(i=(1<<n)-1;i>=0;i--){c=0;
A[i]=inf;
    for(j=0;j<n;j++){
        for(k=j+1;k<n;k++){
if(((1<<j)&i) && ((1<<k)&i)){c=c+a[j][k];}
        }
    }
    sum[i]=c;
}    
}

li ff(li i){
    if(i==0) return(0);
    if(A[i]!=inf) return(A[i]);
li j;li ans=-10000000000000000;
for(j=i;j>0;j=((j-1)&i))
{
ans=max(ans,sum[j]+ff(i^j));
}
A[i]=ans;return(A[i]);
}

int main(){li i,j;readl(n);
for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            readl(a[i][j]);
        }
    }
pre();
li ans=ff((1<<n)-1);cout<<ans;    
}

Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}
int main() {
    int n;
    cin >> n;
    /*
    for(int i = 3;i <= n;i+=3) {
        cout << i;
        //if(i != n)
            cout << " ";
    }
    */
    call(n);
    //cout << endl;
}


Measured memory_bytes: 3120
#include<stdio.h>

int main()
{
  int n,m,i,l,j,k,q;
  int M[102],MM[102][102];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&M[i],&m);
  }
  M[n]=m;
  for(i=1;i<n+1;i++)MM[i][i]=0;

  for(l=2;l<n+1;l++){
    for(i=1;i<n-l+2;i++){
      j=i+l-1;
      MM[i][j]=10000000000;
      for(k=i;k<=j-1;k++){
	q=(MM[i][k]+MM[k+1][j]+M[i-1]*M[k]*M[j]);
        if(MM[i][j]>q){
	  MM[i][j]=q;
	}
      }
    }
  }
  printf("%d\n",MM[1][n]);
  return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
#define int long long
#define dd second
#define mp make_pair
#define pb push_back
#define ff first
#define dd second
#define pp pair<int,int>
using namespace std;

void wyp(int x)
{
    for(int i = 0; i < 26; ++i) cout << (x >> i & 1);
    cout << endl;
}

main()
{
    ios_base::sync_with_stdio(false);
    int ans = 0;
    string s; cin >> s;
    int ileinnych = 0;
    for(auto &i:s) if(i != 'x') ileinnych++;
    if(ileinnych ==0)
    {
        cout << 0 << endl; exit(0);
    }
    int ind = 0;
    int ile = 0;
    for(ind = 0; ind < s.size(); ++ind)
    {
        if(s[ind] != 'x') ile++;
        if(ile == (ileinnych)/2+1) break;
    }
    //cout << " ind " << ind << " " << ileinnych << endl;
    int l = ind-1; int p = ind+1;
    if((ileinnych & 1) == 0)
    {
        p = l = ind; l--;
        while(s[l] == 'x')l--;
    }
    //cout << l << ' ' << p << endl;
    while(l >= 0 and p < s.size())
    {
        if(s[l] != s[p])
        {
            if(s[l] == 'x')
            {
                ans++; l--; continue;
            }
            if(s[p] == 'x')
            {
                ans++; p++; continue;
            }
            cout << -1 << endl; exit(0);
        }
        l--; p++;
    }
   // cout << l << " " << p << " " << ans << " " << s.size() <<  endl;
    if(l >= 0 and s[l] != 'x')
    {
        cout << -1 << endl; exit(0);
    }
    if(p < s.size() and s[p] != 'x')
    {
        cout << -1 << endl; exit(0);
    }
   // cout << "jest" << endl;
    while(l >= 0 or p < s.size())
    {
        ans++;
        l--; p++;
    }
    //cout <<
    cout << ans << endl;
}



Measured memory_bytes: 512
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n, k = map(int, input().split())

ans1 = 0
ans2 = 0
for i in range(1, n+1):
    num = 0
    score = i
    if (i >= k):
        ans1 += 1
    else:
        while True:
            score *= 2
            num += 1
            if (score >= k):
                break
        ans2 += (0.5)**num
print((ans1+ans2)/n)



Measured memory_bytes: 9320
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 };
int alp[30];

long long ans = 1;
int main() {
	int n;
	cin >> n;
	string h;
	cin >> h;
	for (int i = 0; i < h.length(); ++i) {
		++alp[h[i] - 'a'];
	}
	for (int i = 0; i < 30; ++i) {
		ans *= (alp[i] + 1);
		ans %= MOD;
	}
	cout << ans - 1 << endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int count=0;
  int arr[n];
  for(int i=0;i<n;i++)
  {cin>>arr[i];
     if(arr[i]>=k)
        count++;
  }
  cout<<count<<endl;
  return 0;
}
  

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
string S;
int a=0;
  
cin >> S;
  
  for(int i=0;i<4;++i)
  {
  if(S[i]=='+') ++a;
  else if(S[i]=='-') --a;
  }

cout << a << endl;

return 0;
}

Measured memory_bytes: 256
import heapq
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
p=p[-1*x:]
q=list(map(int,input().split()))
q.sort()
pq=p
pq.extend(q[-1*y:])
r=list(map(lambda x:-1*int(x),input().split()))
heapq.heapify(pq)
heapq.heapify(r)
while(len(r)>0):
    max_r=-1*heapq.heappop(r)
    min_pq=heapq.heappop(pq)
#    print(max_r,min_pq)
#    print(pq)
#    print(r)
    if(min_pq < max_r):
        heapq.heappush(pq,max_r)
    else:
        heapq.heappush(pq,min_pq)
        break
print(sum(pq))

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

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h,vector<int>(w));
  rep(i,h) rep(j,w) cin >> a[i][j];

  vector<pair<P,P>> res;
  rep(i,h) rep(j,w-1) {
    if (a[i][j] % 2 != 0) {
      a[i][j+1]++;
      a[i][j]--;
      res.push_back({{i+1,j+1},{i+1,j+2}});
    }
  }
  rep(i,h-1) {
    if (a[i][w-1] % 2 != 0) {
      a[i+1][w-1]++;
      a[i][w-1]--;
      res.push_back({{i+1,w},{i+2,w}});
    }
  }
  cout << res.size() << endl;
  for (auto e : res) {
    cout << e.first.first << " " << e.first.second << " ";
    cout << e.second.first << " " << e.second.second << endl;
  }
  return 0;
} 

Measured memory_bytes: 5232
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int l,a,b,c,d;
	cin >> l >> a >> b >> c >> d;
	int _a = a%c==0?a/c:a/c+1;
	int _b = b%d==0?b/d:b/d+1;
	cout << l-(max(_a,_b)) << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
 
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("./input.txt","r",stdin);
    //freopen("./output.txt","w",stdout);
    string a;
    cin>>a;
    if((a[0]==a[1])||(a[1]==a[2])||(a[2]==a[3]))
        cout<<"Bad";
    else
        cout<<"Good";
}

Measured memory_bytes: 256