akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define N 200000
#define NIL -1
typedef struct Node {
  int parent;
  int left;
  int right;
} node;
void preOrder(int);
void inOrder(int);
void postOrder(int);
node tree[N];
int main() {
  int n, i, j, left, right, node, rooti;
  for (i = 0; i < N; i++) {
    tree[i].parent = NIL;
    tree[i].left = NIL;
    tree[i].right = NIL;
  }
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &node, &left, &right);
    tree[node].left = left;
    tree[node].right = right;
    if (left != NIL) {
      tree[left].parent = node;
    }
    if (right != NIL) {
      tree[right].parent = node;
    }
  }
  for (i = 0; i < n; i++) {
    if( tree[i].parent ==  NIL ) {
      rooti = i;
    }
  }
  printf("Preorder\n");
  preOrder(rooti);
  printf("\nInorder\n");
  inOrder(rooti);
  printf("\nPostorder\n");
  postOrder(rooti);
  printf("\n");
  return 0;
}
void preOrder(int u) {
  if (u == NIL) {
    return; 
  }
  printf(" %d", u);
  preOrder(tree[u].left);
  preOrder(tree[u].right);
}
void inOrder(int u) {
  if (u == NIL) {
    return;
  }
  inOrder(tree[u].left);
  printf(" %d", u);
  inOrder(tree[u].right);
  return;
}
void postOrder(int u) {
  if (u == NIL) {
    return;
  }
  postOrder(tree[u].left);
  postOrder(tree[u].right);
  printf(" %d", u);
  return;
}

Measured memory_bytes: 2960
package main

import (
	"bufio"
	"fmt"
	"os"
)

func isLower(c rune) bool {
	return 'a' <= c && c <= 'z'
}

func isUpper(c rune) bool {
	return 'A' <= c && c <= 'Z'
}

func toLower(c rune) rune {
	return c + 0x20
}

func toUpper(c rune) rune {
	return c - 0x20
}

func convert(s string) string {
	a := make([]rune, len(s))
	for i, c := range s {
		if isUpper(c) {
			a[i] = toLower(c)
		} else if isLower(c) {
			a[i] = toUpper(c)
		} else {
			a[i] = c
		}
	}
	return string(a)
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	fmt.Println(convert(sc.Text()))
}



Measured memory_bytes: 1088
#include <stdio.h>
#define N 100000
typedef struct element {
    struct element *next;
} element;

typedef struct {
    int n;
    element *head;
    element *tail;
} set;

int l[N+1];
set *f[N+1];
int n;

element elements[N+1];

set sets[N];
int next_set = 0;

void initialize(int n) {
    int i;

    for (i = 1; i <= n; i++) {
        f[i] = NULL;
    }
}

void new_pair(int x, int y) {
    set *s = &sets[next_set++];

    f[x] = f[y] = s;

    elements[x].next = &elements[y];
    elements[y].next = NULL;

    s->n = 2;
    s->head = &elements[x];
    s->tail = &elements[y];
}

void merge(set *s1, set *s2) {
    element *e;

    if (s1->n < s2->n) {
        merge(s2, s1);
        return;
    }

    /** s2が小さいのでs1に寄せる */
    for (e = s2->head; e; e = e->next) {
        f[e - elements] = s1;
    }

    s1->n += s2->n;
    s1->tail->next = s2->head;
    s1->tail = s2->tail;
}

void insert(int x, set *s) {
    f[x] = s;
    element *e = &elements[x];
    e->next = s->head;
    s->head = e;
    s->n++;
}

void add_pair(int x, int y) {
    set *f_x, *f_y;

    if ((f_x = f[x])) {
        if ((f_y = f[y])) {
            if (f_x != f_y) {
                merge(f_x, f_y);
            }
        } else {
            insert(y, f_x);
        }
    } else {
        if ((f_y = f[y])) {
            insert(x, f_y);
        } else {
            new_pair(x, y);
        }
    }
}

int movable(int from, int to) {
    if (from == to) {
        return !0;
    }

    return f[from] && f[to] && f[from] == f[to];
}

int main()
{
    int i;
    int m;
    int x, y;
    int r;

    scanf("%d %d", &n, &m);

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

    initialize(n);
    for (i = 1; i <= m; i++) {
        scanf("%d %d", &x, &y);
        add_pair(x, y);
        /* printf("add_pair %d %d\n", x, y); */
        /* debug_print(); */
    }

    r = 0;
    for (i = 1; i <= n; i++) {
        if (movable(i, l[i])) {
            r++;
        }
    }

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


Measured memory_bytes: 3584
#include <iostream>
using namespace std;
 
string s[2000];
int h, w;
typedef struct save
{
    int check = -1;
    int left;
    int up;
    int right;
    int down;
} save_t;
save_t save[2000][2000];
int comp(int x, int y)
{
    int res[4];
    res[0] = 0; res[1] = 0; res[2] = 0; res[3] = 0;
    int i = 0;
    if(y-1 >= 0 && save[x][y-1].check != -1)
    {
        res[0] = save[x][y-1].left+1;
    }
    else
    {
        for (i = y-1; i >= 0; i--)
        {
            if(s[x][i] != '#')
            {
                res[0]++;
            }
            else
            {
                break;
            }
        }
    }
    if(y-1 >= 0 && save[x][y-1].check != -1)
    {
        res[1] = save[x][y-1].right-1;
    }
    else
    {
    for (i = y+1; i < w; i++)
    {
        if(s[x][i] != '#')
        {
            res[1]++;
        }
        else
        {
            break;
        }
    }
    }

    if(x-1 >= 0 && save[x-1][y].check != -1)
    {
        res[2] = save[x-1][y].down-1;
    }
    else
    {
    for (i = x+1; i < h; i++)
    {
        if(s[i][y] != '#')
        {
            res[2]++;
        }
        else
        {
            break;
        }
    }
    }

    if(x-1 >= 0 && save[x-1][y].check != -1)
    {
        res[3] = save[x-1][y].up+1;
    }
    else
    {
        for (i = x-1; i >= 0; i--)
        {
            if(s[i][y] != '#')
            {
                res[3]++;
            }
            else
            {
                break;
            }
        }
    }
 
    save[x][y].check = 1;
    save[x][y].left = res[0];
    save[x][y].up = res[3];
    save[x][y].right = res[1];
    save[x][y].down = res[2];
    return res[0] + res[1] + res[2] + res[3] + 1;
}
 
int main()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        cin >> s[i];
    }
    int ans = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(s[i][j] == '#')
                continue;
            int num = comp(i, j);
            if(num > ans)
            {
                ans = num;
            }
        }
    }
    cout << ans;
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;

int main() {
	cin >> s;
	int ans = 0;
	inc(i, 6) { ans += (s[i] - '0'); }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 55
typedef long long LL;

int c[N][N] = {0};
char s[22];

int main()
{	 
	int i, j, n, p10[10], x, y, p, c2, c5, l, t2 = 0, t5 = 0, ii, jj, ss, d2, d5;
	LL t, ans = 0;
	
	scanf("%d", &n);
	for(i = 1, p10[j = 0] = 1; i < 10; j = i++) p10[i] = p10[j] * 10;
	while(n--){
		scanf("%s", s);
		l = strlen(s);
		for(i = x = y = 0; i < l && s[i] != '.'; i++) x = 10 * x + s[i] - 48;
		if(s[i]){
			for(p = ++i; i < l; i++) y = 10 * y + s[i] - 48;
			t = (LL)x * (LL)p10[d2 = d5 = l - p] + y;
		}
		else t = (LL)x, d2 = d5 = 0;
		c2 = c5 = 0;
		while(t % 2 == 0) t /= 2, c2++;
		while(t % 5 == 0) t /= 5, c5++;
		c2 = c2 - d2 + 9, c5 = c5 - d5 + 9;
		if(c2 > t2) t2 = c2;
		if(c5 > t5) t5 = c5;
		c[c2][c5]++;
	}
	for(i = 0; i <= t2; i++){
		for(j = 0; j <= t5; j++){
			if(!c[i][j]) continue;
			x = 18 - i, y = 18 - j;
			if(x < 0) x = 0;
			if(y < 0) y = 0;
			ss = 0;
			for(ii = x; ii <= t2; ii++){
				for(jj = y; jj <= t5; jj++){
					ss += c[ii][jj];
					if(ii == i && jj == j) ss--;
				}
			}
			ans += (LL)c[i][j] * (LL)ss;
		}
	}
	printf("%lld\n", ans >>= 1);
		
	return 0;
}

Measured memory_bytes: 1692
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	string str;
    	cin>>str;
    	if(str[2]==str[3]&&str[4]==str[5])
    	cout<<"Yes"<<endl;
    	else
    	cout<<"No"<<endl;
    	
    	
    	
    	return 0;
    }

Measured memory_bytes: 3604
#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 r; cin >> r;
	cout << 3 * r * r << endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A_res = 0
B_res = 0
for i in range(N):
    if i % 2 == 1:
        A_res += max(A)
    else:
        B_res += max(A)
    del A[A.index(max(A))]

print(B_res - A_res)

Measured memory_bytes: 38256
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
ll n;
string s;
struct fenwick_tree {
    typedef ll T;
    T n;
    vector<T> bit;

    // 各要素の初期値は 0
    fenwick_tree(T num) : bit(num+1, 0) { n = num; }

    // a_i += w
    void add(T i, T w) {
        for (T x = i; x <= n; x += x & -x) {
            bit[x] += w;
            bit[x]%=MOD;
        }
    }
    // [1, i] の和を計算.
    T sum(T i) {
        T ret = 0;
        for (T x = i; x > 0; x -= x & -x) {
            ret += bit[x];
            ret%=MOD;
        }
        return ret;
    }
    // [left+1, right] の和を計算.
    T sum(T left, T right) {
        return (sum(right) - sum(left)+MOD)%MOD;
    }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>s;
    ll dp[n+1][n+1];//i番目まで見てi番目の数より小さい数字がj個使われている
    memset(dp,0,sizeof dp);
    for(int i=0;i<=n;i++){
        dp[0][i]=1;
    }
    for(ll i=1;i<n;i++){
        fenwick_tree tree(n);
        for(ll j=1;j<=n-i+1;j++){
            //cout<<j<<" "<<dp[i-1][j]<<"\n";
            tree.add(j,dp[i-1][j]);
        }
        for(ll j=1;j<=n-i;j++){
            if(s[i-1]=='<'){
                dp[i][j]=tree.sum(0,j);
            }
            else{
                dp[i][j]=tree.sum(j,n);
            }
        }
    }
    cout << dp[n-1][1] << "\n";
}



Measured memory_bytes: 70656
# coding: utf-8
N,M,V,P=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
A_wa=[A[0]]

for i in range(1,N):
    A_wa.append(A_wa[i-1]+A[i])
A_wa.append(0)
def bin_isOK(index):
    if A[index]+M < A[N-P]:
        return False
    # print("index:{}".format(index))
    # print("f1:{}".format((A[index]+M)*(N-P-index+1) - (A_wa[N-P] - A_wa[index-1])))
    # print("f2:{}".format(V*M-M*(P-1+index)))
    if (A[index]+M)*(N-P-index+1) - (A_wa[N-P] - A_wa[index-1]) >= V*M-M*(P-1+index):
        return True
    else:
        return False


def binary_search():
    ng = -1
    ok = N-P

    while abs(ok - ng) >1:
        # print("!")
        mid = (ok + ng)//2

        if bin_isOK(mid):
            ok = mid
        else:
            ng = mid
    
    return ok

# print(A)
# print(A_wa)
# print(A[N-P])

print(N-binary_search())

Measured memory_bytes: 14964
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, M;
  cin >> N >> M;
  ll sum = 0;
  for (ll i = 0; i < M; ++i) {
    ll a;
    cin >> a;
    sum += a;
  }
  ll temp = -1;
  cout << max(temp, N - sum) << endl;
}


Measured memory_bytes: 3636
import std.stdio, std.conv, std.string, std.range, std.array, std.algorithm;
import std.bigint;

void main()
{
  int n = readln().chomp().to!int;

  while (n--){
    BigInt a = readln().chomp().to!BigInt;
    BigInt b = readln().chomp().to!BigInt;
    if ((a + b).to!string.length > 80){
      writeln("overflow");
    } else {
      writeln(a + b);
    }
  }
}

Measured memory_bytes: 2456
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
double ax[110];
double ay[110];
double bx[110];
double by[110];
double ev[500];
double x[500];
double y[500];
double z[500];
double EPS=1e-9;
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		int sz=0;
		for(int i=0;i<a;i++){
			scanf("%lf%lf",ax+i,ay+i);
			ev[sz++]=ax[i]+EPS;
			ev[sz++]=ax[i]-EPS;
		}
		ax[a]=ax[0];
		ay[a]=ay[0];
		for(int i=0;i<b;i++){
			scanf("%lf%lf",bx+i,by+i);
			ev[sz++]=bx[i]-EPS;
			ev[sz++]=bx[i]+EPS;
		}
		bx[b]=bx[0];
		by[b]=by[0];
		std::sort(ev,ev+sz);
		for(int i=0;i<sz;i++){
			x[i]=ev[i];
			double L=-999999999;
			double R=999999999;
			vector<double> ps;
			for(int j=0;j<a;j++){
				if(min(ax[j],ax[j+1])-EPS<x[i]&&x[i]<EPS+max(ax[j],ax[j+1])){
					if(min(ax[j],ax[j+1])+EPS>max(ax[j],ax[j+1])){
						ps.push_back(ay[j]);
						ps.push_back(ay[j+1]);
						continue;
					}
					double M=ay[j]+(ay[j+1]-ay[j])*(x[i]-ax[j])/(ax[j+1]-ax[j]);
					ps.push_back(M);
				}
			}
			std::sort(ps.begin(),ps.end());
			if(ps.size()==0)ps.push_back(0);
			y[i]=ps[ps.size()-1]-ps[0];
			L=-999999999;
			R=999999999;
			ps.clear();
			for(int j=0;j<b;j++){
				if(min(bx[j],bx[j+1])-EPS<x[i]&&x[i]<EPS+max(bx[j],bx[j+1])){
					if(min(bx[j],bx[j+1])+EPS>max(bx[j],bx[j+1])){
						ps.push_back(by[j]);
						ps.push_back(by[j+1]);
						continue;
					}
					double M=by[j]+(by[j+1]-by[j])*(x[i]-bx[j])/(bx[j+1]-bx[j]);
		//			printf("%d: %f\n",j,M);
					ps.push_back(M);
				}
			}
			std::sort(ps.begin(),ps.end());
			
			if(ps.size()==0)ps.push_back(0);
			z[i]=ps[ps.size()-1]-ps[0];
			
		}
		double V=0;
		for(int i=1;i<sz;i++){
			if(x[i]<x[i-1]+EPS)continue;
			V+=(x[i]-x[i-1])*(y[i]*z[i]+y[i-1]*z[i-1]+(y[i]+y[i-1])*(z[i]+z[i-1]))/6;
	//		printf("%f %f %f %f\n",x[i],y[i],z[i],(x[i]-x[i-1])*(y[i]*z[i]+y[i-1]*z[i-1]+(y[i]+y[i-1])*(z[i]+z[i-1]))/6);
		}
		printf("%.12f\n",V);
	}
}

Measured memory_bytes: 1136
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define vi vector<int>
#define usi unordered_set<int> 
#define si set<int>
#define umii unordered_map<int, int> 
#define mii map<int, int>
#define all(a) a.begin(), a.end()
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define mod (int)(1e9+7)
#define INF INT_MAX
 
 


signed main()
{
    
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int n; cin >> n;
    vector<int> dp(3, 0);
    
    for (int day=0; day<n; day++) {
        vector<int> new_dp(3, 0);
        vector<int> c(3);
        for (int i=0; i<3; i++)
            cin >> c[i];

        for (int i=0; i<3; i++) {
            for (int j=0; j<3; j++) {
                if (i!=j) {
                    new_dp[j] = max(new_dp[j], dp[i]+c[j]);
                }
            }
        }  
        dp = new_dp;  
    }
    int res= 0;
    res=max(res, dp[0]);
    res=max(res, dp[1]);
    res=max(res, dp[2]);
    cout << res;
    return 0;
}

Measured memory_bytes: 256
def inTriangle?(p)
  x1, y1, x2, y2, x3, y3, x, y = p
  va = [x1 - x, y1 - y]
  vb = [x2 - x, y2 - y]
  vc = [x3 - x, y3 - y]

  s = [[va, vb], [vb, vc], [vc, va]].map{ |a, b| triangleArea(a,b) }
  if s.all?{ |x| x < 0 } || s.all?{ |x| x >= 0 }
    true
  else
    false
  end
end

def triangleArea(a, b)
  (a[0] * b[1] - a[1] * b[0])/2.0
end

if __FILE__ == $0
  loop do
    input = gets
    break if input.nil?
    points = input.split.map(&:to_f)
    puts (inTriangle?(points) ? "YES" : "NO")
  end
end

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

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1]<<endl;
}


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

int main() {
  int a, b, c, d, e, f, g;
  cin >> a;
  b = a % 2;
  c = a - b;
  d = c / 10;
  e = d % 2;
  f = d - e;
  g = f / 10;
  cout << b + e + g << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

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

ans = []
counter = 0
if N == 1:
    print(0)
    exit()
for i in range(N-1):
    ans.append(counter)
    if H[i] >= H[i+1]:
        counter += 1
    else:
        counter = 0
    ans.append(counter)
print(max(ans))


Measured memory_bytes: 14168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,l,q,a,b,m=1,c=1;
    cin>>n;
    vector<int> x(n);
    for(auto& i:x) cin>>i;
    cin>>l>>q;
    while(c*2<n){
        ++m;
        c*=2;
    }
    vector<vector<int>> g(m,vector<int>(n));
    fr(i,n) g[0][i]=upper_bound(x.begin(),x.end(),x[i]+l)-x.begin()-1;
    fr(i,m-1) fr(j,n) g[i+1][j]=g[i][g[i][j]];
    fr(i,q){
        cin>>a>>b;
        --a;--b;
        if(a>b) swap(a,b);
        int ka=m,C=c,ans=1;
        while(C){
            --ka;
            if(g[ka][a]<b){
                a=g[ka][a];
                ans+=C;
            }
            C/=2;
           }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 7928
#include <iostream>
#include <string>
#include <vector>
using namespace std;
   
int main(void){
	int K , N , A , B , C , D;
	cin >> K >> N;
	
	for(int i=1 ; i<=N ; i++){
		cin >> A;
		if(i==1) {
          D = A;
          B = A;
        }
		else {
			if((A-B)>C) C=A-B;
			B = A;
		}
	}
	
	if((K-A+D)>C) C=K-A+D;
		
	cout << K-C << endl;

    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    print(n**3)
    return

#B
def B():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    ans = sum(b)
    for i in range(n-1):
        x = a[i]
        y = a[i+1]
        if y == x+1:
            ans += c[x-1]
    print(ans)
    return

#C
def C():
    n = I()
    b = LI()
    b.append(float("inf"))
    a = [min(b[i],b[i-1]) for i in range(n)]
    print(sum(a))
    return

#D
def D():
    n,k = LI()
    a = S()
    ans = 0
    for i in range(n-1):
        if a[i] == a[i+1]:
            ans += 1
    print(min(n-1,ans+2*k))
    return

#E
def E():
    def add(i):
        while i <= n:
            bit[i] += 1
            i += i&-i

    def sum(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i&-i
        return res

    n = I()
    p = LI()
    r = [0]*n
    bit = [0]*(n+1)
    for i in range(n)[::-1]:
        r[i] = (n-i-1)-sum(p[i])
        add(p[i])
    print(r)
    l = [0]*n
    bit = [0]*(n+1)
    for i in range(n):
        l[i] = i-sum(p[i])
        add(p[i])
    print(l)

    return

#F
def F():
    n = I()
    s = LI()
    s.sort()
    s = s[::-1]
    m = 1<<n
    f = [-1]*m
    f[0] = 0
    for i in range(n):
        k = 0
        l = 0
        for j in range(1<<i):
            while f[k] != i:
                k += 1
            while f[l] >= i or s[k] <= s[l]:
                l += 1
                if l == m:
                    print("No")
                    return
            f[l] = i+1
            k += 1
        for j in range(m):
            if f[j] >= 0:
                f[j] = i+1
    print("Yes")
    return

#Solve
if __name__ == "__main__":
    F()


Measured memory_bytes: 97736
#define R(i,n)for(int i=0;i<=n;i++)
s;main(a,b,c,x){scanf("%d%d%d%d",&a,&b,&c,&x);R(i,a)R(j,b)R(k,c)if(x/50==10*i+2*j+k)s++;printf("%d",s);}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        sc.close();
        int j = 0;
        for (int i = x - k + 1; i <= x + k - 1; i++) {
            System.out.print(i + " ");
        }
        System.out.println();
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
long long int a = 0;
long long int r[10] = {1, 11, 112, 1124, 11248, 112496, 1124992, 11249984, 112499968, 1124999936};
string s;
int main(){
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        a += r[s.size() - i - 1] * (1 << i) * (s[i] - '0');
    }
    cout << a << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;

    vector<vector<int>> honest(n), unkind(n);
    for(int i=0; i<n; i++){
        int a;
        cin >> a;

        for(int j=0; j<a; j++){
            int x, y;
            cin >> x >> y;
            x -= 1;
            if(y == 1) honest[i].push_back(x);
            if(y == 0) unkind[i].push_back(x);
        }
    }

    int ans = 0;
    for(int bit=1; bit<(1<<n); bit++){
        set<int> people;
        for(int i=0; i<n; i++){
            if((bit>>i) & 1){
                people.insert(i);
                //cout << i << " ";
            }
        }
        //cout << endl;

        bool flag = true;
        for(int i=0; i<n; i++){
            if(people.find(i) != people.end()){
                for(int h : honest[i]) if(people.find(h) == people.end()) flag = false;
                for(int u : unkind[i]) if(people.find(u) != people.end()) flag = false;
            }
        }
        if(flag == true) ans = max(ans, (int)people.size());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int cc(string s,int i);
int main(){
	int a,b,n=0;
	string s;
	cin>>a;
	cin>>s;
	for(int i=1;i<a;i++){
		b=cc(s,i);
		n=max(n,b);
	}
	cout<<n;
	return 0;
}
int cc(string s,int i){
	string s1=s.substr(0,i);
	string s2=s.substr(i);
	char a='a';
	int n1[26],n2[26];
	int t=0;
	int n=0;
	memset(n1,0,sizeof(n1));
	memset(n2,0,sizeof(n2));
	for(int j=0;j<26;j++){
		n1[j]=count(s1.begin(),s1.end(),a);
		n2[j]=count(s2.begin(),s2.end(),a);
		a++;
	}
	for(int j=0;j<26;j++){
		if(n1[j]>0&&n2[j]>0){
			
			n++;
		}
	}
	return n;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n,t;
    cin>>n>>t;
    vector<ll> a(n);
    ll sum=0;
    ll mx=0;
    for(auto &I:a){
        cin>>I;
        mx=max(mx,I);
        sum+=I;
        cout<<max((t-sum+2*mx)/mx,1LL)<<endl;
    }
    
    
    return 0;
}



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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

struct Date
{
    int year,month,day;

    Date(){}
    Date(string s)
    {
        year=atoi(s.substr(0,4).c_str());
        month=atoi(s.substr(5,2).c_str());
        day=atoi(s.substr(8,2).c_str());
    }

    int releasedAfter(Date b)
    {
        if(year>b.year) return 1;
        else if(year==b.year)
        {
            if(month>b.month) return 1;
            else if(month==b.month)
            {
                if(day>=b.day) return 1;
            }
        }
        return 0;
    }

    int releasedBefore(Date b)
    {
        if(year<b.year) return 1;
        else if(year==b.year)
        {
            if(month<b.month) return 1;
            else if(month==b.month)
            {
                if(day<=b.day) return 1;
            }
        }
        return 0;
    }
};

struct Book
{
    string title,author;
    Date date;

    Book(){}
    Book(string a, string b, Date c)
    {
        title=a;
        author=b;
        date=c;
    }

    int searchString(string q, string s)
    {
        int Q=q.size(), S=s.size();

        rep(i,S-Q+1)
        {
            if(s.substr(i,Q)==q) return 1;
        }
        return 0;
    }

    int includeTitle(string q)
    {
        return searchString(q,title);
    }
    int includeAuthor(string q)
    {
        return searchString(q,author);
    }
    int releasedBefore(Date q)
    {
        return date.releasedBefore(q);
    }
    int releasedAfter(Date q)
    {
        return date.releasedAfter(q);
    }
};

int main()
{
    int n;
    cin >>n;

    vector<Book> b(n);
    rep(i,n)
    {
        string x,y,z;
        cin >>x >>y >>z;
        b[i]=Book(x,y,Date(z));
    }

    int Q;
    cin >>Q;
    rep(q,Q)
    {
        string t,a,from,to;
        cin >>t >>a >>from >>to;

        vector<int> ok(n,1);
        rep(i,n)
        {
            if(t!="*") ok[i]&=b[i].includeTitle(t);
            if(a!="*") ok[i]&=b[i].includeAuthor(a);
            if(from!="*") ok[i]&=b[i].releasedAfter(Date(from));
            if(to!="*") ok[i]&=b[i].releasedBefore(Date(to));
        }

        if(q) printf("\n");
        rep(i,n) if(ok[i]) cout << b[i].title << endl;
    }

    return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int a,b;
    cin>>a>>b;
    if (a>0&&b>0) {
        cout<<"Positive"<<endl;
    } else if ( (a<=0&&0<=b) || (a>=0&&b<=0) ) {
        cout<<"Zero"<<endl;
    } else if (a<0&&b<0) {
        long long int tmp=abs(b)-abs(a);
        if (tmp%2==0) {
            cout<<"Negative"<<endl;
        } else {
            cout<<"Positive"<<endl;
        }
    }
}

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++)
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;

int N;
vector<int> A;
map<int, int> X;

bool solve(int room){
    int rem = N - room;
    int least = 0;
    if(rem == 0){
        if(X[room-1] == N) return true;
        else return false;
    }

    if(rem < room) least = room - rem;
    for(int i = least; i < room; i++){
        if(X[room-1] == i && X[room] == N-i){
            return true;
        }
    }
    return false;
}

int main(){
    int large = 0;
    cin >> N;
    REP(i,N){
        int a;
        cin >> a;
        //A.push_back(a);
        chmax(large, a);
        X[a]++;
    }

    //sort(A.rbegin(), A.rend());

    //int first = A[0];

    bool valid = solve(large);
    if(valid) goto success;

    valid = solve(large+1);
    if(valid) goto success;

    cout << "No" << endl;
    return 0;

success:
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 4992
def main():
    a, b, c = map(int, input().split())
    k = int(input())

    count = 0
    while True:
        if a < b:
            if b < c:
                break
            else:
                c *= 2
                count += 1
        else:
            b *= 2
            count += 1
    print('Yes' if count <= k else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9120
s = input()
n = len(s)

list = ["dream", "dreamer", "erase", "eraser"]

s = s[::-1]

while True:
    if s.startswith(list[0][::-1]):
        n -= 5
        s = s[5:]
    elif s.startswith(list[1][::-1]):
        n -= 7
        s = s[7:]
    elif s.startswith(list[2][::-1]):
        n -= 5
        s = s[5:]
    elif s.startswith(list[3][::-1]):
        n -= 6
        s = s[6:]
    else:
        break

if s == "":
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9312
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,X,Y; cin >> A >> B >> C >> X >> Y;
    int sum = 0;
    if(A+B > 2*C){
        int p = min(X,Y);
        sum += 2*C * p;
        X-=p; Y-=p;
        if(X != 0){
            if(X*A < 2*C*X) sum += X*A;
            else sum += 2*C*X;
        }else{
            if(Y*B < 2*C*Y) sum += Y*B;
            else sum += 2*C*Y;
        }
    }else{
        sum += A*X+B*Y;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Here your code !
    char buf[100];
    int a;
    int b;
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf, "%d %d",&a,&b);
    if ((a<=8) && (b<=8)) {
        printf("Yay!");
    } else  {
        printf(":(");
    }
    //printf("%d\n",a);
    //printf("%d\n",b);

}

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

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

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

    int q;
    cin>>q;
    multimap<string, int> mp;
    rep(i, q) {
        int c;
        cin>>c;
        if (c == 0) {
            string k;
            cin>>k;
            int x;
            cin>>x;
            mp.emplace(k, x);
        }
        else if (c == 1) {
            string k;
            cin>>k;
            auto p = mp.equal_range(k);
            for (auto it = p.first; it != p.second; ++it) {
                cout<<(*it).second<<endl;
            }
        }
        else if (c == 2) {
            string k;
            cin>>k;
            mp.erase(k);
        }
        else {
            string l, r;
            cin>>l>>r;
            auto it = mp.lower_bound(l);
            auto cl = mp.upper_bound(r);
            for (; it != cl; it = next(it, 1)) {
                if ((*it).second == 0) continue;
                cout<<(*it).first<<" "<<(*it).second<<endl;
            }
        }
    }
}


Measured memory_bytes: 24932
#include <stdio.h>
#include <algorithm>
#define mod 1000000007
typedef long long ll;

ll  mul(ll a, ll b) {
  a *= b, a %= mod;
  return a;
}

ll rev(ll a) {
  ll now = mod - 2, ans = 1;
  while(now) {
    if(now & 1) ans = mul(ans, a);
    a = mul(a, a), now >>= 1;
  }
  return ans;
}

int main(void) {
  ll i, j, k, n, ans;
  scanf("%lld%lld", &n, &k);
  ll fact[n + 1];
  fact[0] = 1;
  for(i = 1; i <= n; ++i) fact[i] = mul(fact[i - 1], i);
  for(i = 1; i <= k; ++i) {
    if(n - k - i + 1 < 0) {
      printf("0\n");
      continue;
    }
    ans = mul(fact[n - k + 1], mul(rev(fact[i]), rev(fact[n - k - i + 1])));
    ans = mul(ans, fact[k - 1]);
    ans = mul(ans, mul(rev(fact[k - i]), rev(fact[i - 1])));
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

using namespace std;
using ll = long long;

void Main() {
	string s, t; cin >> s >> t;
	int res = 0;
	REP(i, 3) {
		if (s[i] == t[i]) ++res;
	}
	cout << res << endl;
}

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


Measured memory_bytes: 764
package main

import (
	"fmt"
)

type graph struct {
	path []int
	height int
	// flag bool // pathに存在するもので自分より高いものがあればtrue
}
func main() {
	var N,M int
	fmt.Scan(&N,&M)
	graphs := make([]graph,N)
	for i:= 0; i<N; i++ {
		var h int
		fmt.Scan(&h)
		graphs[i].height = h
		graphs[i].path = []int{}
		// graphs[i].flag = false
	}
	for i:= 0; i<M; i++ {
		var a,b int
		fmt.Scan(&a,&b)
		graphs[a-1].path = append(graphs[a-1].path,b-1)
		graphs[b-1].path = append(graphs[b-1].path,a-1)
	}
	count := 0
	for i:=0; i<N; i++ {
		paths := graphs[i].path
		height := graphs[i].height
		bestHeight := true // 一番高いのならtrue
		for _,value := range paths {
			if height <= graphs[value].height {
				bestHeight = false
				break
			}
		}
		if bestHeight {
			// fmt.Println(graphs[i],"ベスト")
			count ++
		}
	}
	fmt.Println(count)
}


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

int main(void){
    int n;
    cin>>n;
    int x[100000] = {};
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a>0) x[a-1] ++;
        if(a<99999) x[a+1] ++;
        x[a] ++;
    }
    int ans=0;
    for(int i=0;i<100000;i++){
        ans = max(ans,x[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
def main():
    k, s = map(int, input().split())
    ans = 0
    for x in range(k + 1):
        for y in range(k + 1):
            z = s - x - y
            if z >= 0 and z <= k:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
N = str(input())

doN = len(N)-2
strN = list(str(N))
minv = 20000000000

for i in range(doN):
    judN=strN[i]+strN[i+1]+strN[i+2]
    minv = min(minv,abs(753-int(judN)))
print(minv)


Measured memory_bytes: 2940
#include <iostream>
#include<cstring>
#include<string>
#include <stdio.h>
using namespace std;

int main(){
    string w,t;
    int count = 0; 
    cin>>w;
    cin>>t;
    for(int i=0;i<w.size();i++) {
    if('A'<=w[i]&&w[i]<='Z') w[i]+='a'-'A';
    }
    while(t!="END_OF_TEXT"){
      for(int i = 0;i < t.size();i++){
        if('A'<=t[i]&&t[i]<='Z') t[i]+='a'-'A';
      }
      if(w == t){
          count++;
      }
      cin>>t;
    }
    std::cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3204
s = input()
k = int(input())

a = sorted(set(s))[:5]
if len(s) >= 2:
  b = sorted(set([s[i:i+2] for i in range(len(s)-1)]))[:5]
  a.extend(b)
if len(s) >= 3:
  c = sorted(set([s[i:i+3] for i in range(len(s)-2)]))[:5]
  a.extend(c)
if len(s) >= 4:
  d = sorted(set([s[i:i+4] for i in range(len(s)-3)]))[:5]
  a.extend(d)
if len(s) >= 5:
  e = sorted(set([s[i:i+5] for i in range(len(s)-4)]))[:5]
  a.extend(e)

print(sorted(a)[k-1])

Measured memory_bytes: 3512
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	set<int> s;
	int a;
	REP(i, 3) {
		cin >> a;
		s.insert(a);
	}
	cout << s.size() << endl;
	return 0;
}


Measured memory_bytes: 256
S = input()
N=len(S)+1
SS = '>'+S+'<'
a = [-1]*(N+2)
for i in range(N+1):
    if SS[i] == '>' and SS[i+1]=='<':
        a[i+1]=0
b = a[1:-1]
c = a[1:-1]

for i in range(N-1):
    if S[i] == '<' and b[i]>=0 :
        b[i+1] = b[i] +1


for i in range(N-2,-1,-1):
    if S[i] == '>' and c[i+1]>=0:
        c[i] = c[i+1] +1

ans = 0
for bb,cc in zip(b,c):
    ans += max(bb,cc) 

print(ans)



Measured memory_bytes: 37264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
#define SIZE 200005
#define M 1000000007
ll power(ll a,ll b){
	if(b==0)
		return 1;
	ll p=power(a,b/2);
	p=(p*p)%M;
	if(b%2==0){
		return p;
	}
	else{
		return (p*a)%M;
	}
}
ll arr[SIZE];
int main(){
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll N;
	cin>>N;
	for(ll i=1;i<=N;++i){
		cin>>arr[i];
	}
	sort(arr+1,arr+N+1,greater<ll>());
	ll ans=0;
	for(ll i=1;i<=N;++i){
		ans=(ans+(arr[i]*(i+1))%M)%M;
	}
	ans=(ans*power(4,N-1))%M;
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
from sys import stdin

def main():

    input = stdin.readline

    K = int(input())

    if (K % 2 == 0) or (K % 5 == 0):
        print("-1")
        return

    seven_len = 0

    for i in range(10 ** 7):

        seven_len = (seven_len * 10 + 7) % K
        if seven_len == 0:
            print(i+1)
            return


    print("-1")


if __name__ == "__main__":
    main()

Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std ;
 
// #define int long long
#define endl '\n'

#define IOS ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
 
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vp vector<pii>
#define vs vector<string>
#define all(v) v.begin(),v.end()

#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define ff  first
#define ss  second
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
 
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
     
#define pi 3.14159265358979323846264338327950L
#define MOD 1000000007

int32_t main(){

   
    int n,m,ans=0;
    cin>>n>>m;
    
    vi days(m,0);
    while(m--)
    {
      int x;
      cin>>x;
      ans+=x;
    }
    cout<<max((n-ans),-1);



  return 0;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
int32_t main()
{  lli n,m,i,k,j,c=0,v1=0,v2=0;
   cin>>n>>m>>k;
   lli a[n+5];
   lli b[m+5];
   for(i=1;i<=n;i++)
    { cin>>a[i];
      if(i!=1) a[i]+=a[i-1];
      if(k>=a[i]) v1=i;
    }
   for(i=1;i<=m;i++)
    { cin>>b[i];
      if(i!=1) b[i]+=b[i-1];
      if(k>=b[i]) v2=i;
    }
   i=1;  j=m;
   c=max(v1,v2);
   while(i<=n && j>=1)
   {  if(a[i]+b[j] <=k)
       {   c=max(c,i+j);
           i++;
       }
       else
         j--;
   }
   cout<<c<<"\n";
   return 0;
}//main


Measured memory_bytes: 6668
h,w=map(int,input().split())
char={}
for _ in range(h):
  s=input()
  for c in s:
    if c not in char:
      char[c]=1
    else:
      char[c]+=1
cnt4=(h//2)*(w//2)
cnt2=0
cnt1=0
if h%2==1 and w%2==1:
  cnt1=1
  cnt2=h//2+w//2
elif h%2==1:
  cnt2=w//2
elif w%2==1:
  cnt2=h//2
flag=True
for _ in range(cnt4):
  for c in char.keys():
    if char[c]>=4:
      char[c]-=4
      if char[c]==0:
        del char[c]
      break
  else:
    flag=False
for _ in range(cnt2):
  for c in char.keys():
    if char[c]>=2:
      char[c]-=2
      if char[c]==0:
        del char[c]
      break
  else:
    flag=False
for _ in range(cnt1):
  for c in char.keys():
    if char[c]>=1:
      char[c]-=1
      if char[c]==0:
        del char[c]
      break
  else:
    flag=False
if flag==True:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
int a[]={0,0,0,0,0,0,0,0,0,0};
int b;
while(cin>>b){
if(b==0){
cout<<a[0]<<endl;
for(int i=0;i<9;i++){
a[i]=a[i+1];}}
else{
for(int i=0;i<9;i++){
a[9-i]=a[8-i];}
a[0]=b;}}}

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

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}

const ll mod = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1;i <= n;i += 2){
        int cnt = 0;
        for (int j = 1;j <= i;j++){
            if (i % j == 0) cnt++;
            if (cnt > 8) break;
        }
        if (cnt == 8) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;

class Main
{
	public static void main (String[] args) throws IOException
	{
		String S;
		int time,h,m,s;
		
		Scanner in = new Scanner(System.in);
		
		S = in.nextLine();
		
		time = Integer.parseInt(S);
		
		h = time / 3600;
		m = (time - h * 3600) / 60;
		s = (time - h * 3600) % 60;
		
		System.out.println(h + ":"  + m + ":" + s);
	}
}

Measured memory_bytes: 17316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int H;
  cin >> H;
  int W;
  cin >> W;

  vector<string> pict(H);
for (int i = 0; i < H; i++) {
  cin >> pict.at(i);
}
  
  for (int i = 0; i < H+2; i++){
  
      if ( i == 0 || i == H+1){
      	for(int j=0; j < W+2; j++){
        	if ( j < W+1){
        	cout << "#";
        	}
        	else{
          	cout << "#" << endl;
        	}
        }
      }
      else{
      	for(int j=0; j < 3; j++){
        	if (j == 0){
         	 cout << "#";
        	}
        	else if(j == 2){
         	 cout << "#" << endl;
        	}
        	else{
          	cout << pict.at(i-1);
        	}
        }
      }  
 }
}

Measured memory_bytes: 256
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n,a,b = gi
puts min a*n,b


Measured memory_bytes: 2300
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import heapq
    from collections import defaultdict

    n, m, s = map(int, readline().split())
    s_max = 0

    edge = defaultdict(list)
    for _ in range(m):
        u, v, a, b = map(int, readline().split())
        u, v = u - 1, v - 1
        edge[u].append((v, a, b))
        edge[v].append((u, a, b))
        s_max += a

    exchange = [[0] * 2 for _ in range(n)]
    for i in range(n):
        c, d = map(int, readline().split())
        exchange[i][0], exchange[i][1] = c, d

    s_start = min(s, s_max)

    hq = []
    heapq.heappush(hq, (0, s_start, 0))
    dist = [[INF] * (s_max + 1) for _ in range(n)]

    while hq:
        cost, s_cur, u = heapq.heappop(hq)

        s_rate, s_time = exchange[u][0], exchange[u][1]
        s_next = s_cur + s_rate
        s_next = min(s_next, s_max)
        if cost + s_time < dist[u][s_next]:
            heapq.heappush(hq, (cost + s_time, s_next, u))
            dist[u][s_next] = cost + s_time

        for v, a, b in edge[u]:
            if s_cur >= a and cost + b < dist[v][s_cur - a]:
                heapq.heappush(hq, (cost + b, s_cur - a, v))
                dist[v][s_cur - a] = cost + b

    for i in range(1, n):
        print(min(dist[i]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 101756