akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <set>
#include <string>

using namespace std;

//dream dreamer erase eraser 
string DREAM = "dream";
string DREAMER = "dreamer";
string ERASE = "erase";
string ERASER = "eraser";

int main() {
  string S;
  cin >> S;
  reverse(S.begin(),S.end());
  
  reverse(DREAM.begin(), DREAM.end());
  reverse(DREAMER.begin(), DREAMER.end());
  reverse(ERASE.begin(), ERASE.end());
  reverse(ERASER.begin(), ERASER.end());
  
  while(S.size() > 4) {
    if(S.substr(0,5)==DREAM || S.substr(0,5)==ERASE) {
      S = S.substr(5);
    } else if(S.substr(0,6)==ERASER) {
      S = S.substr(6);
    } else if(S.substr(0,7)==DREAMER) {
      S = S.substr(7);
    } else {
	    break;
    }
  }
  
  
  if(S.size()==0){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,kk;
int main()
{
    cin>>a>>b>>c;
    if(b>=a)
    {
        cout<<1<<endl;
        exit(0);
    }
    if(c>=b)
    {
        cout<<-1<<endl;
        return 0;
    }
    if((a-b)%(b-c)>=1)kk=1;
    cout<<((a-b)/(b-c)+kk)*2+1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
struct wolf{
	int c[4][8];
};
int c[10][10];
inline bool operator<(const wolf &a,const wolf &b){
	for(int i=0;i<4;i++)for(int j=0;j<8;j++)if(a.c[i][j]!=b.c[i][j])return a.c[i][j]<b.c[i][j];
	return false;
}
int main(){
	int a;scanf("%d",&a);
	while(a--){
		for(int i=0;i<4;i++)for(int j=0;j<7;j++){
			scanf("%d",&c[i][j+1]);
		}
		for(int i=0;i<4;i++)c[i][0]=11+i*10;
		for(int i=0;i<4;i++)for(int j=1;j<8;j++)if(c[i][j]%10==1)c[i][j]=0;
		queue<pair<wolf,int> > Q;
		wolf s;
		for(int i=0;i<4;i++)for(int j=0;j<8;j++)s.c[i][j]=c[i][j];
		Q.push(make_pair(s,0));
		set<wolf>S;
		S.insert(s);
		bool yet=true;
		while(Q.size()){
			wolf at=Q.front().first;
			int cost=Q.front().second;
			Q.pop();
			bool ok=true;
			for(int i=0;i<4;i++)for(int j=0;j<7;j++)if(at.c[i][j]!=11+i*10+j)ok=false;
			if(ok){
				yet=false;
				printf("%d\n",cost);
				break;
			}
			for(int i=0;i<4;i++)for(int j=1;j<8;j++){
				if(!at.c[i][j]&&at.c[i][j-1]&&at.c[i][j-1]%10!=7){
					int row,col;
					for(int k=0;k<4;k++)for(int l=0;l<8;l++)if(at.c[i][j-1]+1==at.c[k][l]){row=k;col=l;}
					at.c[row][col]=0;
					at.c[i][j]=at.c[i][j-1]+1;
					if(!S.count(at)){
						S.insert(at);
						Q.push(make_pair(at,cost+1));
					}
					at.c[i][j]=0;
					at.c[row][col]=at.c[i][j-1]+1;
				}
			}
		}
		if(yet)printf("-1\n");
	}
}

Measured memory_bytes: 13576
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

// template from zscoder

int a[100001];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,l,ptr(-1);
    cin >> n >> l;
    for(int i = 1; i <= n; i++)cin >> a[i];
    for(int i = 1; i < n; i++)
    {
        if(a[i]+a[i+1]>=l)
        {
            ptr = i;
            break;
        }
    }
    if(ptr == -1)
    {
        cout << "Impossible" << endl;
    }
    else
    {
        cout << "Possible" << endl;
        for(int i = 1; i < ptr; i++)
        {
            cout << i << endl;
        }
        for(int i = n-1; i >= ptr; i--)
        {
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10 ** 6)

N = int(input())
A = list(map(int, input().strip().split(" ")))
dp = {i: dict() for i in range(N)}
mod = 10 ** 9 + 7

def f(i, ma, mi):
    if i == N:
        return 1
    if (ma, mi) in dp[i]:
        return dp[i][(ma, mi)]
    if A[i] != ma and A[i] != mi and A[i] != i - ma - mi:
        dp[i][(ma, mi)] = 0
        return 0

    ans = 0
    # iがr, b, gを被って矛盾がないかを見ていく
    if A[i] == ma:
        ans += f(i + 1, ma + 1, mi)
    if A[i] == mi:
        if ma > mi + 1:
            ans += f(i + 1, ma, mi + 1)
        else:
            ans += f(i + 1, mi + 1, ma)
    if A[i] == i - ma - mi:
        ans += f(i + 1, ma, mi)

    dp[i][(ma, mi)] = ans % mod
    return ans % mod

print(f(0, 0, 0) % mod)

Measured memory_bytes: 222268
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i, N) for (int i = 0; i < N; ++i)

using namespace std;

vector<int> merge(const string &s)
{
    vector<int> result;
    char current_color = 0;
    int current_length = 0;
    REP(i, s.length())
    {
        char c = s[i];
        if (current_color == 0)
        {
            if (c == '0')
                result.push_back(0);
            current_color = c;
            current_length = 1;
            continue;
        }

        if (current_color != c)
        {
            result.push_back(current_length);
            current_length = 1;
            current_color = c;
        }
        else
            ++current_length;
    }
    result.push_back(current_length);
    return move(result);
}

int main()
{
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;

    auto xs = merge(s);
    if (xs.size() / 2 <= k)
    {
        cout << n << endl;
        return 0;
    }

    int current = 0;
    REP(i, k * 2 + 1)
        current += xs[i];
    int result = current;
    int l = 0;
    for (int i = k * 2 + 1; i < xs.size(); i += 2)
    {
        int add = (i + 1 >= xs.size()) ? xs[i] : xs[i] + xs[i + 1];
        current = current + add - xs[l] - xs[l + 1];
        result = max(result, current);
        l += 2;
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1020
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var p = o.l();
  var dp = [1-p[0],p[0]];
  for(var i = 1; i < n; i++){
    dp[i+1] = dp[i] * p[i];
    for(var j = i; j > 0; j--){
      dp[j] = dp[j-1] * p[i] + dp[j] * (1 - p[i]);
    }
    dp[0] = dp[j] * (1 - p[i]);
  }
  var ans = 0;
  for(i = (n+1) / 2; i <= n; i++)ans += dp[i];
  return ans;
}

Measured memory_bytes: 21192
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cassert>

using namespace std;

#define TASKNAME ""

void solve(int test_number);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(9);
    cerr.setf(ios::fixed);
    cerr.precision(3);
#ifdef LOCAL
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#else
#endif
    int n = 1;
    for (int i = 0; i < n; i++) {
        solve(i);
    }
}

const int MAX_N = 200005;
const int MOD = 1000000007;


int n, x = 0, y = 1, a[2][MAX_N];

void solve(int test_number) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[0][i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[1][i]);
    }
    sort(a[0], a[0] + n);
    sort(a[1], a[1] + n);
    long long ans = 1;
    int var = 0;
    int i = 0, j = 0;
    while (i < n || j < n) {
        if (i < n) {
            while (j < n && a[y][j] < a[x][i]) {
                var++;
                j++;
            }
        }
        if (var) {
            ans = ans * var % MOD;
            i++;
            var--;
        } else {
            swap(x, y);
            swap(i, j);
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
	a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
	#define cerr if(0)cout
#endif

ll c[10][10];

int32_t main() {
	IAMSPEED
	// set testing to 0 when submitting to judge
	int n; cin >> n;
	FOR(i,1,n) {
		string str = lts(i);
		c[str[0]-'0'][str.back()-'0']++;
	}
	ll ans=0;
	FOR(i,1,9) {
		FOR(j,0,9) {
			ans+=c[i][j]*c[j][i];
		}
	}
	cout << ans;
}


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

using namespace std;

int main() {
	int n; cin >> n;
	int ans = 0;
	for (int a = 1; a < n; a++)
		for (int b = a; b < n; b += a)
			ans++;
	cout << ans << '\n';
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for(int i=1;i<N+1;i++){
    string s = to_string(i);
    if(s.size()%2==1) ans++;
  }
  cout << ans;
}


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

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

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

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

vector<vector<char>> field(10, vector<char>(10));

//oと上下左右で隣接しているところは全てxに変える 
//全てのマスをxに変えるまで何回dfsを行ったかがoの連結数

//現在地(x,y)
void dfs(int x, int y) {
  //今いるところをxに変える

  field[x][y] = 'x';

  //移動する四方向をループ
  for (int i = 0; i < 4; i++) {

    //移動先をnx,nyとする
    int nx = x + dx[i], ny = y + dy[i];

    //nxとnyが地図の範囲内であるかどうかと移動先field[nx][ny]が陸地かどうかを判定
    if (nx >= 0 && nx < 10 && ny >= 0 && ny < 10 && field[nx][ny] == 'o') dfs(nx,ny);

  }
  return;
}

//Sが偶文字列であるかどうか判定
bool hantei(string S) {
	int N = S.size();

	if(N%2) return false;

	else {
		string S1 = S.substr(0,N/2);
		string S2 = S.substr(N/2,N/2);
		if(S1 == S2) return true;
		else return false;
	}
}

int main(){
	string S;
	cin >> S;
	int N = S.size();
	for (int i = 1; i <= N; i++) {
		S.pop_back();
		if(hantei(S)) {
          //cout << S << endl;
			cout << N- i << endl;
			break;
		}
	}
}


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



int main(){
	
	long int d,square,height;
	long int elem,sum;

	while (cin >> d){
		sum = 0;
		elem = 600 / d;
		for (int i = 0; i < elem; i++){
		
			height = (d*i)*(d*i);
			square = height*d;
			sum += square;
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
L = list(map(int,input().split()))
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if len(set((L[i], L[j] , L[k])))!= 3:
        continue
      A = L[i] + L[j] + L[k]
      if 2*max([L[i] , L[j] , L[k]])<A:
        count += 1
        # print(i,j,k)
print(count)

Measured memory_bytes: 69080
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,M=get_i
$ans=0
def dfs(g,visit,p,now)
  visit[p]=1
  if now==N
      $ans+=1
      visit[p]=-1
      return
  end 
  g[p].each do|v|
    dfs(g,visit,v,now+1) if visit[v]==-1
  end
  visit[p]=-1
end
g=Array.new(N){[]}
M.times do|i|
  a,b=get_i.map{|x| x-=1}
  g[a].push(b)
  g[b].push(a)
end
dfs(g,Array.new(N){-1},0,1)
puts $ans

Measured memory_bytes: 14336
N = gets.chomp.to_i

x = []
u = []
N.times do
    a, b = gets.split(' ')
    x << a
    u << b
end

sum = 0
N.times do |i|
    if u[i].eql?('JPY') then
        sum = sum + x[i].to_i
    else
        sum = sum + x[i].to_f * 380000.0
    end
end

print sum

Measured memory_bytes: 1916
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  string s,t;
  ll n,m,idx=-1;
  bool can;
  cin >> s >> t;
  n=s.size();
  m=t.size();
  for(int i=0;i+m-1<n;i++){
    can=true;
    for(int j=0;j<m;j++){
      if(!(s[i+j]=='?'||(s[i+j]==t[j]))){
        can = false;
        break;
      }
    }
    if(can){
      idx=i;
    }
  }
  if(idx==-1){
    cout << "UNRESTORABLE"<<endl;
  }else{
    for(int i=0;i<n;){
      if(i==idx){
        cout << t;
        i+=m;
      }else{
        if(s[i]=='?') s[i] = 'a';
        cout << s[i];
        i++;
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[100][100];
	int b[100];
	int c[100] = {0};
	int n, m, i, j;
	scanf("%d %d", &n, &m);
	for( i = 0;i < n; i++)
	{
		for( j = 0;j < m; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}	
	for( i = 0;i < m;i++)
	{
		scanf("%d", &b[i]);   	
	}
	for( i = 0;i < n;i++)
	{
		for( j = 0;j < m;j++)
		{
			c[i]+=a[i][j]*b[j]; 			
		}			
	}
	for( i = 0;i < n;i++)
	{
		printf("%d\n", c[i]);
	}
	return 0;
 } 


Measured memory_bytes: 2752
#include<utility>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<deque>
#include<stack>
#include<complex>
#include<cmath>
#include<iostream>
#include<set>
#include<map>
#include<sstream>
#include<fstream>
#include<climits>
#include<chrono>
#include<random>
#include<functional>
#include<regex>

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

// ??§????????°INF
const int INF = (1 << 30);
// ?¨±?????????????????
const double EPS = (1e-10);
// 2??????????????????????????????????????????
#define EQ(a,b) (abs((a)-(b)) < EPS)


int main()
{
	int n;
	string o;
	while (true) {
		cin >> n;
		if (n == 0)break;
		int up_or_down = 0;
		bool on = false, l_on = false, r_on = false;
		for (int i = 0; i < n; ++i) {
			cin >> o;
			if (o == "lu") {
				l_on = true;
				if ((!on)&&r_on) {
					on = true;
					++up_or_down;
				}
			}
			else if (o == "ru") {
				r_on = true;
				if ((!on)&&l_on) {
					on = true;
					++up_or_down;
				}
			}
			else if (o == "ld") {
				l_on = false;
				if (on && (!r_on)) {
					on = false;
					++up_or_down;
				}
			}
			else {
				r_on = false;
				if (on && (!l_on)){
					on = false;
					++up_or_down;
				}
			}
		}
		cout << up_or_down << endl;
	}
}

Measured memory_bytes: 1208
def comb(n,r):
  ret=1
  for i in range(n,n-r,-1):
    ret=ret*i
  for i in range(2,r+1):
    ret=ret//i
  return ret

n,a,b=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
cnt=[0]*50
num=[arr[0]]
tmp=arr[0]
pos=0
for i in arr:
  if i==tmp:
    cnt[pos]+=1
  else:
    pos+=1
    cnt[pos]+=1
    tmp=i
    num.append(i)
ave=0
ans=0
if cnt[0]>=a:
  ave=num[0]
  for i in range(a,min(b,cnt[0])+1):
    ans+=comb(cnt[0],i)
else:
  t=0
  pos=0
  for i in range(n):
    t+=cnt[i]
    ave+=num[i]*cnt[i]
    if t>=a:
      ave-=num[i]*(t-a)
      ans=comb(cnt[i],a-(t-cnt[i]))
      break
  ave=ave/a
print(ave)
print(ans)

Measured memory_bytes: 3064
# 単純にbfsによる探索を行う
# 入力、初期設定など
H, W = map(int,input().split())
maze = list(list(input()) for _ in range(H))
INF = -1
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]



def bfs():
    while queue:
        now_row,now_column = queue.pop(0)

        # 上下左右を探索
        # 探索結果が迷路内かつ訪れていないかつ壁でなければvisitedを更新し、そのマスをqueueに追加(いわゆるbfs)
        for i in range(4):
            next_row, next_column = now_row + dy[i] , now_column + dx[i]
            if 0 <= next_row < H and 0 <= next_column < W and \
                    maze[next_row][next_column] != "#" and visited[next_row][next_column] == INF:
                visited[next_row][next_column] = visited[now_row][now_column] + 1
                queue.append([next_row,next_column])


ans = 0
for column in range(W):
    for row in range(H):
        if maze[row][column] == "#":
            continue
        # dequeが使えるかわからないのでリストで代用
        queue = [[row, column]]
        # visitedにはスタートから最短何マスかかるか格納
        visited = [[INF] * W for _ in range(H)]
        visited[row][column] = 0
        bfs()
        tmp_max = 0
        for i in range(H):
            if tmp_max < max(visited[i]):
                tmp_max = max(visited[i])
        if tmp_max > ans:
            ans = tmp_max
print(ans)


Measured memory_bytes: 3188
from collections import Counter
from math import *
N, K = [int(x) for x in input().strip().split()]
x = [int(a) for a in input().strip().split()]
xpos = [0] + [a for a in x if a >= 0]
xneg = [0] + [abs(a) for a in x if a < 0]
xneg.sort()

timemin = 2**64
for i in range(0, min(len(xpos), K + 1)):
    posnum = i
    negnum = K - i
    if negnum >= len(xneg):
        continue
    time = xpos[posnum] * 2 + xneg[negnum]
    if time < timemin:
        timemin = time
for i in range(0, min(len(xneg), K + 1)):
    posnum = K - i
    negnum = i
    if posnum >= len(xpos):
        continue
    time = xneg[negnum] * 2 + xpos[posnum]
    if time < timemin:
        timemin = time

print(timemin)

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

int main()
{
	int r,x,d;
  	cin>>r>>d>>x;
  	int before=r*x-d;
  	cout<<before<<endl;
  	for(int i=1 ; i<10 ; ++i)
    {
	    x=r*before-d;
    	cout<<x<<endl;
      	before=x;
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const ll MOD = 1000000007LL;
/*メモ 
*/
int main(){
    string s;
    std::cin >> s;
    int n=s.size();
    std::vector<bool> a(26,0);
    rep(i,n){
        a[s[i]-'a']=1;
    }
    if(s.size()!=26){
        char c;
        rep(i,26)if(!a[i]){
            c=+'a'+i;
            break;
        }
        std::cout << s+c << std::endl;
        exit(0);
    }
    else{
        if(s=="zyxwvutsrqponmlkjihgfedcba")std::cout << -1 << std::endl;
        else {
            string ss=s;
            next_permutation(all(s));
            rep(i,n){
                if(ss[i]!=s[i]){
                    std::cout << s.substr(0,i+1) << std::endl;
                    exit(0);
                }
            }
            //std::cout << s << std::endl;
        }
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
#define MN 100005
using namespace std;
int n,num,cnt,now[MN],f[MN],head[MN],pre[MN],lst[MN];
struct edge{int to,next;}g[MN<<1];
multiset<int>::iterator it,it2;
void ins(int u,int v){g[++num].next=head[u];head[u]=num;g[num].to=v;}
bool dp(int u,int ff,int mid){
	int tt=0,lef=0;
	for(int i=head[u];i;i=g[i].next)if(g[i].to!=ff)if(!dp(g[i].to,u,mid))return false;
	multiset<int>S;S.clear();
	for(int i=head[u];i;i=g[i].next)if(g[i].to!=ff)S.insert(f[g[i].to]),tt++;
	if(!tt){f[u]=0;return true;}
	while(S.begin()!=S.end()){
		it=S.end();--it;int tmp=(*it);S.erase(it);
		it2=S.upper_bound(mid-tmp-2);
		if(it2!=S.begin()){--it2;S.erase(it2);}
		else {lst[++lef]=tmp;}
	}
	if(u==1){
		if(lef==1)return lst[1]+1<=mid;
		else return lef==0;
	}else {
		if(tt&1){
			if(lef==1){f[u]=lst[lef]+1;return lst[1]+1<=mid;}
			else {f[u]=0;return lef==0;}
		}else {
			if(lef==2){f[u]=lst[2]+1;return f[u]<=mid&&lst[1]+1<=mid;}
			else {f[u]=0;return lef==0;}
		}
	}
}
void calc(int u,int ff){
	int tt=0;
	for(int i=head[u];i;i=g[i].next)if(g[i].to!=ff)calc(g[i].to,u),tt++;
	cnt+=(u==1?(tt+1)/2:tt/2);
}
int main(){
	scanf("%d",&n);int x,y;
	for(int i=1;i<n;i++)scanf("%d%d",&x,&y),ins(x,y),ins(y,x);
	int l=1,r=1e5,ans=1e5;
	while(l<=r){
		int mid=(l+r)>>1;
		if(dp(1,1,mid))ans=mid,r=mid-1;
		else l=mid+1;
	}calc(1,1);printf("%d %d",cnt,ans);
}

Measured memory_bytes: 14592
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader(); 
        int N, D;
        {int[] a = r.ii(); N = a[0]; D = a[1];}   
        println((N-1)/(2*D+1)+1);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  char A,B;
  cin>>A>>B;
  char ans='<';
  if(A>B)
    ans='>';
  if(A==B)
    ans='=';
  cout<<ans;
  }


Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
cand = [A, B, C]
l = []
for i in range(N):
    l.append(int(input()))

def search(i, a, b, c):
    tmp = 0
    if i == N:
        if a > 0 and b > 0 and c > 0:
            return abs(A-a)+abs(B-b)+abs(C-c)
        else:
            return 10**9
    
    ret1 = search(i+1, a, b, c)

    tmp = a
    ret2 = search(i+1, a+l[i], b, c)
    if tmp != 0:
        ret2 += 10
    
    tmp = b
    ret3 = search(i+1, a, b+l[i], c)
    if tmp != 0:
        ret3 += 10

    tmp = c
    ret4 = search(i+1, a, b, c+l[i])
    if tmp != 0:
        ret4 += 10
    
    return min(ret1, ret2, ret3, ret4)

print(search(0, 0, 0, 0))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll H, W;
    cin >> H >> W;
    vector<string> s(H);
    Rep (i, H) {
        cin >> s[i];
    }

    mat dist(H, vec(W, inf));
    dist[0][0] = 0;
    if (s[0][0] == '#') dist[0][0] = 1;
    Rep (i, H) {
        Rep (j, W) {
            if (i+1 < H) {
                if (s[i][j] == '.' and s[i+1][j] == '#') {
                    chmin(dist[i+1][j], dist[i][j] + 1);
                } else {
                    chmin(dist[i+1][j], dist[i][j]);
                }
            }

            if (j+1 < W) {
                if (s[i][j] == '.' and s[i][j+1] == '#') {
                    chmin(dist[i][j+1], dist[i][j] + 1);
                } else {
                    chmin(dist[i][j+1], dist[i][j]);
                }
            }
        }
    }

    cout << dist[H-1][W-1] << endl;
}

Measured memory_bytes: 3740
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	while (cin >> n, n) {
		vector<set<int>> member(n);
		REP(i, n) {
			int m;
			cin >> m;
			REP(j, m) {
				int p;
				cin >> p;
				member[i].insert(p);
			}
		}
		int k;
		cin >> k;
		vector<int> num(k);
		int ans = -1;
		REP(i, k)
			cin >> num[i];
		REP(i, n) {
			bool b = true;
			REP(j, k) {

				if (member[i].find(num[j]) == member[i].end()) {
					b = false;
					break;
				}
			}
			if (b) {
				if (ans == -1)
					ans = i + 1;
				else {
					ans = -1;
					break;

				}

			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3504
#include <iostream>
#include <string>

using namespace std;

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;
  bool result = true;
  for (int i = 0; i < A + B + 1; ++i) {
    if (!((i == A) ? (S[i] == '-') : (('0' <= S[i]) && (S[i] <= '9')))) {
      result = false;
      break;
    }
  }
  
  cout << (result ? "Yes" : "No")  << endl;
  return 0;
}


Measured memory_bytes: 256
#ABC133-D

N = int(input())
A = list(map(int, input().split()))
tot = sum(A)
LE, RE= [-A[0]],[A[-1]]
s = 1
for i in range(N-1):
    LE.append(LE[i]+s*A[i+1])
    RE.append(RE[i]-s*A[-(i+2)])
    s *= -1
ans =[]
for i in range(N):
    s = (-1)**i
    if i == 0:
        ans.append(-LE[N-1])
    elif i == N - 1:
        ans.append(LE[N-2]+A[N-1])
    elif i%2 == 0:
        ans.append(LE[i-1] + A[i] + RE[N-(i+2)])
    else:
        ans.append(-LE[i-1] + A[i] - RE[N-(i+2)])
print(*ans)

Measured memory_bytes: 22464
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

#define maxnum 1000000
bool isprime[maxnum];

void makeprime(){
	REP(i,maxnum){
		if(i%2!=0) isprime[i] = true;
	}
	isprime[1] = false;
	isprime[2] = true;
	for(int i=3;i<sqrt(maxnum);i+=2){
		for(int j=i+2;j<maxnum;j+=2){
			if(j%i==0) isprime[j] = false;
		}
	}
}

int main(){
	int a,d,n;
	makeprime();
	while(1){
		cin >> a >> d >> n;
		if(a==0&&d==0&&n==0) break;
		ll int cnt = 0;
		ll int pos = a;
		while(1){
			if(isprime[pos]){
				cnt++;
			}
			if(cnt==n) break;
			pos+=d;
		}
		cout << pos << endl;
	}
	return 0;
}

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

#define  all(x)          (x).begin(), (x).end()
#define  rall(v)          v.rbegin() , v.rend()
#define  ones(x)          __builtin_popcount(x)
#define  sz(v)           ((int)((v).size())
#define  debug(x)        cout << '>' << #x << ':' << x << endl;
#define  clr(v, d)       memset(v, d, sizeof(v));
#define  rep(i,a,b)      for(ll i=a; i<=b;i++)
#define  fo(i,n)         for(ll i=0;i<n;i++)
#define  rfo(i,n)        for(ll i=n-1;i>=0;i--)
#define  unq(vec)        sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin());
#define  era(v)          sort(v.begin(), v.end());v.erase(unique(v.begin(), v.end()), v.end());
#define  pb              push_back
#define  mp              make_pair
#define  endl            '\n'
#define  fi               first
#define  se               second
#define INF 1001001001

using namespace std;
typedef long long         ll;
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<long long> vll;
typedef vector<double>    vd;
typedef vector<vi >       vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;
typedef pair<int,int>     pii;
typedef vector<pii>       vii;
typedef map<int,int>      mii;
typedef map<ll,ll>        mll;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;}
//ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
//ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
//ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}

const ll MOD = 1e9 + 7;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int X,int Y){return X>Y;}

int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m;cin>>n>>m;
vi paren(n,-1);
vi distanc(n,INF);
vi graph[n];
for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;
    a--;b--;
    graph[a].pb(b);graph[b].pb(a);
}
queue<int>q;
q.push(0);
while(!q.empty()){
    int u = q.front();
    q.pop();
    for(int w : graph[u]){
        if(distanc[w]!=INF){continue;}
        paren[w]=u;
        distanc[w]=distanc[u]+1;
        q.push(w);
    }
}
cout<<"Yes"<<endl;
for(int i=0;i<n;i++){
        if(i==0){continue;}
     int ans= paren[i];
    ans++;
    cout<<ans<<endl;
}
}















Measured memory_bytes: 10540
n, m, v, p = map(int, input().split())
a = sorted(list(map(int, input().split())))
if p >= v:
  print(sum([1 for b in a if b+m >= a[n-p]]))
else:
  s = p-1
  t = sum(a[:(n-p+1)])
  for i in range(n-p+1):
    t -= a[i]
    if a[i]+m >= a[n-p] and (a[i]+m)*(n-p-i) - t >= (v-p-i)*m:
      s += 1
  print(s)

Measured memory_bytes: 63640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return(b);
  }
  else {
    return(gcd(b, a % b));
  }
}

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

int main(void) {
  ll a, b;
  cin >> a >> b;
  std::cout << lcm(a, b) << endl;
  return 0;
}


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

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

    int count=0;
    for (int i = a; i <= b; i++)    {
        if(c%i == 0) count++;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            String str = br.readLine();
            int countW = 0;
            int arrW[] = new int[n];
            int countE = 0;
            int arrE[] = new int[n];
            for (int i = 0; i < n; i++) {
                char ch = str.charAt(i);
                if (ch == 'W') {
                    countW++;
                } else {
                    countE++;
                }
                arrW[i] = countW;
                arrE[i] = countE;
            }
            int min = 0;
            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    min = arrE[n - 1] - arrE[i];
                } else {
                    int tmp = arrW[i - 1] + (arrE[n - 1] - arrE[i]);
                    if (min > tmp) {
                        min = tmp;
                    }
                }
            }
            System.out.println(min);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 29440
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

N, Y = LI()

for x in range(N+1):
    for y in range(N+1-x):
        z = N-x-y
        if (10000*x + 5000*y + 1000*z == Y):
            print(x, y, z)
            quit()

print(-1, -1, -1)

Measured memory_bytes: 41196
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	string s,t,u;
	cin>>s>>t>>u;
	cout<<s[0]<<t[1]<<u[2]<<endl;
	return 0;
}

Measured memory_bytes: 256
object Main {
  def main (args: Array[String]) {
    val num = scala.io.StdIn.readLine.toInt;
    val list = scala.io.StdIn.readLine.split(" ").map(_.toLong).toList;
  
    println(list.min + " " +  list.max + " " + list.sum)
  }
}

Measured memory_bytes: 49424
#include <stdio.h>

int main(){
  long long a,b,k;
  scanf("%lld%lld%lld", &a,&b,&k);
  if(a+b<k){
    printf("0 0");
  }else if(a-k<0){
    printf("%d %lld", 0,b-(k-a));
  }else{
    printf("%lld %lld", a-k,b);
  return 0;
  }
}

Measured memory_bytes: 128
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val a = Array<Int>(n+1, { cin.nextInt() })
    val b = Array<Int>(n, { cin.nextInt() })

    var ans: Long = 0

    for (i in 0..n-1) {
        if (a[i] >= b[i]) {
            ans += b[i]
        } else {
            b[i] -= a[i]
            ans += a[i]
            if (a[i+1] >= b[i]) {
                ans += b[i]
                a[i+1] -= b[i]
            } else {
                ans += a[i+1]
                a[i+1] = 0
            }
        }
    }
    println(ans)
}

Measured memory_bytes: 74572
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,l;
    cin>>n>>l;
    int sum=0,mn=1e9,c=0;
    for (int i=1;i<=n;i++){
        int cost = i+l-1;
        if (abs(cost)<mn)mn=abs(cost),c=cost;
        sum+=cost;
    }
    cout<<sum-c<<endl;
}


Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))
A = [0,]*N
A[0]=B[0]
A[N-1]=B[N-2]
for i in range(1,N-1):
    if B[i] <= B[i-1]:
        A[i]=B[i]
    elif B[i] >= B[i-1]:
        A[i]=B[i-1]
print(sum(A))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int gcd(int a,int b){
	return (b ? gcd(b,a%b) : a);
}
int main(){
	int n,ans = 0; cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				ans += gcd(gcd(i+1,j+1),k+1);
			}
		}
	}
	cout<<ans;
	return 0;	
}


Measured memory_bytes: 3536
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s,t,tmp;
	cin>>s>>t;
	rep(i,s.size()){
		tmp=s[s.size()-1]+s.substr(0,s.size()-1);
		if(tmp==t)break;
		s=tmp;
	}
	cout<<((tmp==t)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, k] <- getIntList
    let m = f k 1
    let s = sum $ map (\i -> 2 ^ (m - (f k i))) [1..n]
    print $ (fromIntegral s) / ((fromIntegral 2 ^ m) * (fromIntegral n))

f k x | k <= x = 0
      | otherwise = 1 + (f k (2 * x))

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define R(i,n) for(int i=0;i<n;i++)
main(){int n,a=1e9,c[2][20];cin>>n;R(i,n)cin>>c[0][i];R(i,n)cin>>c[1][i];vector<vector<int>>p(1<<n,vector<int>(51,1e9));p[0][0]=0;R(B,1<<n){int o=0,d[n];R(i,n)if(!(B&1<<i))d[i]=o++;R(i,n){int k=abs(i-n+o);R(j,c[k%2][i]+1)p[B|1<<i][c[k%2][i]]=min(p[B|1<<i][c[k%2][i]],p[B][j]+d[i]);}}R(i,51)a=min(a,p[(1<<n)-1][i]);cout<<(a>1e8?-1:a);}

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

signed main()
{
  int a, b, c;
  int sum = 0;
  bool flag = false;

  cin >> a >> b >> c;

  for (int i = 1; i < a * b; i++) {
    if (sum % b == c) {
      flag = true;
    }
    sum = i * a;
  }

  if (flag) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return (0);
}

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

using namespace std;

typedef long long ll;
const int MAXN = 1e5 + 100;
vector<int> G[MAXN];
ll dp[MAXN], suf[MAXN], pre[MAXN], pro[MAXN];
int n, MOD;

void dfs(int nod, int fa) {
	dp[nod] = 1;
	int len = G[nod].size();
	for (int i = 0; i < len; i++) {
		int son = G[nod][i];
		if (fa != son) {
			dfs(son, nod);
			dp[nod] = dp[nod] * (dp[son] + 1) % MOD;
		}
	}
}

void sch(int nod, int fa) {
	int len = G[nod].size(), m = 0;
	
	pre[0] = 1;
	for (int i = 0; i < len; i++) {
		int son = G[nod][i];
		if (son == fa) continue;
		m++;
		pre[m] = pre[m - 1] * (dp[son] + 1) % MOD;
	}
	
	suf[m + 1] = 1;
	for (int i = len - 1; i >= 0; i--) {
		int son = G[nod][i];
		if (son == fa) continue;
		suf[m] = suf[m + 1] * (dp[son] + 1) % MOD;
		m--;
	}
	
	m = 0;
	for (int i = 0; i < len; i++) {
		int son = G[nod][i];
		if (son == fa) continue;
		m++;
		pro[son] = (pro[nod] * pre[m - 1] % MOD * suf[m + 1] + 1) % MOD;
	}
	
	for (int i = 0; i < len; i++) {
		int son = G[nod][i];
		if (son == fa) continue;
		sch(son, nod);
	}
}

int main() {
	cin >> n >> MOD;
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	
	dfs(1, -1);
	pro[1] = 1;
	sch(1, -1);
	
	for (int i = 1; i <= n; i++) {
		cout << dp[i] * pro[i] % MOD << endl;
	}
	
	return 0;
}


Measured memory_bytes: 16148
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int a,b,c,k,i;
    cin>>a>>b>>c>>k;
    int x[3]={a,b,c};
    
    sort(x,x+3);
    
    for(i=1;i<=k;++i)
      {
          x[2]=x[2]*2;
      }
      int sum=x[0]+x[1]+x[2];
    cout<<sum;
    
   
         
}

Measured memory_bytes: 256
from sys import setrecursionlimit
setrecursionlimit(10**8)


def count_water(h_array):
    # print(h_array)
    water = 0
    if len(h_array) == 1:
        water = h_array[0]
        # print(h_array, water)
        return water
    min_h = min(h_array)
    water = min_h
    new_h_array = []
    for h in h_array:
        if h != min_h:
            new_h_array.append(h - min_h)
        else:
            if len(new_h_array) != 0:
                water += count_water(new_h_array)
                new_h_array = []
    else:
        if len(new_h_array) != 0:
            water += count_water(new_h_array)        
    # print(h_array, water)
    return water


N = int(input())
h_array = list(map(int, input().split()))
print(count_water(h_array))

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define i64 long long int
#define ui64 unsigned long long int
#define eps (1e-6)
#define xx first
#define yy second
#define ln 17
#define off 2

#define sq(x) ((x)*(x))

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace __gnu_pbds;
using namespace std ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int,int> pii;

#define log 20
#define mod 998244353LL
#define INF 1000000000000000000LL
#define maxn 300005

int main()
{
    int an ;

    scanf("%d",&an) ;

    int ans = 0 ;

    long double x = 0.0 , y= 0.0;
    long double ang = an ;

    for(int i=1; ; i++)
    {
        x += ( cos( (PI*i*an)/180.0 ) ) ;
        y += ( sin( (PI*i*an)/180.0 ) ) ;

        if( abs(x) < eps && abs(y) < eps )
        {
            ans = i ;
            break ;
        }
    }

    printf("%d\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 4152