akhauriyash/Code-Regression huggingface dataset:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


n=l()[0]
A=l()
A=[0]+A+[0]
ans=0
for i in range(1,n+2):
    ans+=abs(A[i]-A[i-1])
for i in range(1,n+1):
    print(ans-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i-1]-A[i+1]))



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

bool visited[51];
vector<vector<bool>>graph(51,vector<bool>(51));

void dfs(int v,int n) {
	int i;
	for (i = 2; i <= n; ++i) {
		if (visited[i])continue;
		if (graph[v][i] != true)continue;
		visited[i] = true;
		dfs(i,n);
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	int ans = 0;
	bool bridge;
	vector<int>a(m), b(m);
	for (int i = 0; i < m; ++i) {
		cin >> a[i]>> b[i];
		graph[a[i]][b[i]] =graph[b[i]][a[i]]= true;
	}
		for (int i = 0; i < m; ++i) {
			for (int j = 1; j<= n; ++j)visited[j] = false;
			graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
			visited[1] = true;
			dfs(1, n);
			bridge = false;
			for (int j = 1; j <= n; ++j) {
				if (visited[j] == false)bridge = true;
			}
			if (bridge)++ans;
			graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()

def main():
  n,m,k = map(int, input().split())
  a = tuple(map(int, input().split()))
  b = tuple(map(int, input().split()))
  sa = [0] * (n+1)
  sb = [0] * (m+1)
  for i in range(n):
    sa[i+1] = sa[i] + a[i]
  for i in range(m):
    sb[i+1] = sb[i] + b[i]
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

if __name__ == '__main__':
    main()

Measured memory_bytes: 66176
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        String S = sc.next();
        String ans = solve(N, K, S);

        System.out.println(ans);
    }

    private static String solve(int N, int K, String S) {
        char[] sarray = S.toCharArray();

        sarray[K-1] = (char)(sarray[K-1] - ('A' - 'a'));

        return new String(sarray);
    }
}


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

using namespace std;

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans = a+b+c+d;
  cin>>a>>b>>c>>d;
  ans = max(ans, a+b+c+d);
  cout << ans << endl;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s[0] == s[1]) {
    cout << "Bad" << endl;
  } else if (s[1] == s[2]) {
    cout << "Bad" << endl;
  } else if (s[2] == s[3]) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
}

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

using namespace std;

typedef long long ll;

int n;
ll m, v, p;
ll a[100010];
ll pref[100010];
int ans;

int main() {
    scanf("%d%lld%lld%lld", &n, &m, &v, &p);
    for (int i = 0; i < n; i++)
        scanf("%lld", &a[i]);
    sort(a, a + n);
    reverse(a, a + n);
    for (int i = 0; i < n; i++)
        pref[i + 1] = pref[i] + a[i];
    ans = p;
    for (int i = p; i < n; i++) {
        if (a[i] + m < a[p - 1]) break;
        ll cur = v - (n - (i - p + 1));
        if (cur <= 0) {
            ans++;
            continue;
        }
        if (cur * m <= (i - p + 1) * (a[i] + m) - (pref[i] - pref[p - 1]))
            ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int n,m,xs,ys,xt,yt,ans[10005][10005];
int yi[10]={0,0,0,1,-1};
int xi[10]={0,1,-1,0,0};
int ym[30]={-2,-2,-2,-2,-2,-1,0,1,2,2,2,2,2,1,0,-1,1,-1,-1,1};
int xm[30]={-2,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,1,1,-1,-1};
char a[1005][1005];
struct node{int x,y,w;node(){}node(int X,int Y,int W){x=X;y=Y;w=W;}
bool operator<(const node o)const{return w>o.w;}};
inline bool chcek(int xx,int yy,int ww)
{
	if(a[xx][yy]=='#'||xx<1||xx>n||yy<1||yy>m||ans[xx][yy]<=ww)
		return 0;
	return 1;
}
void bfs()
{
	priority_queue<node> q;
	node now;
	q.push(node(xs,ys,0));
	while(q.size())
	{
		now=q.top();
		q.pop();
		if(ans[now.x][now.y]<now.w)
			continue;
		ans[now.x][now.y]=now.w;
		for(int i=1;i<=4;i++)
			if(chcek(now.x+xi[i],now.y+yi[i],now.w))
				q.push(node(now.x+xi[i],now.y+yi[i],now.w));
		for(int i=1;i<=20;i++)
			if(chcek(now.x+xm[i],now.y+ym[i],now.w+1))
				q.push(node(now.x+xm[i],now.y+ym[i],now.w+1));
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d",&xs,&ys);
	scanf("%d%d",&xt,&yt);
	for(int i=1;i<=n;i++)
		scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			ans[i][j]=0x3f3f3f3f;
	ans[xs][ys]=0;
	bfs();
	if(ans[xt][yt]==0x3f3f3f3f)
		printf("-1");
	else
		printf("%d",ans[xt][yt]);
}


Measured memory_bytes: 13320
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int n;
  cin >> n;
  vint A(n);
  vint B(n);
  rep(i,n) cin >> A[i];
  rep(i,n) cin >> B[i];
  vint ans(n);
  rep(i,n){
    rep(j,n){
      if(j < i){
        ans[i] += A[j];
      }
      if(j == i){
        ans[i] += A[j] + B[j];
      }
      if(i < j){
        ans[i] += B[j];
      }
    }
  }
  int ANS = 0;
  rep(i,n) ANS = max(ANS,ans[i]);
  cout << ANS << endl;
}

Measured memory_bytes: 256
#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; }

// ---- ----

int n, m[1200][1200];
string s[1200], t[300];

int main() {
	cin >> n;
	inc(i, n) { cin >> t[i]; }
	
	inc(i, n) {
	inc(j, n) {
		s[2 * i + 0] += t[i][j];
		s[2 * i + 0] += '.';
		s[2 * i + 1] = string(n * 2, '.');
	}
	}
	
	inc(i, 2 * n) { s[i] += s[i]; s[2 * n + i] += s[i]; }
	
	inc(i, 4 * n) {
	inc(j, 4 * n) {
		inc(k, 4 * n) {
			if(
				inID(i - k, 0, 4 * n) &&
				inID(j + k, 0, 4 * n) &&
				inID(i + k, 0, 4 * n) &&
				inID(j - k, 0, 4 * n) &&
				s[i - k][j + k] == s[i + k][j - k]
			) {
				m[i][j] = k;
			} else {
				break;
			}
		}
	}
	}
	
	
	int ans = 0;
	inc(a, n) {
	inc(b, n) {
		int i = 2 * a;
		int j = 2 * b;
		
		bool f = true;
		inc(k, 2 * n) {
			if(min(k, 2 * n - 1 - k) <= m[i + k][j + k]) { } else { f = false; break; }
		}
		if(f) { ans++; }
	}
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 7808
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

ll calc ( ll n ) {
    ll ans = 0;

    while ( n > 0 ) {
        ans += n%10;
        n /= 10;
    }

    return ans;
}

pair<double, ll> insert ( int n, char digit[16] ) {
    ll tmp = 0;
    rep(i, n) tmp = tmp*10ll + digit[i];

    return mp((double)tmp / calc(tmp), tmp);
}

int main()
{
    ll k;
    cin >> k;

    set<pair<double, ll>> s;
    rep(i, 17) {
        char digit[20];

        rep(j, i+1) {
            rep(k, j) {
                reep(l, 0, j) digit[l] = 0;
                reep(l, j+1, i) digit[l] = 9;

                rep(l, 10) {
                    rep(m, 10) {
                        digit[0] = l;
                        digit[k] = m;

                        if ( digit[0] == 0 ) digit[0] = 1;
                        auto p = insert(i, digit);
                        s.insert(p);
                    }
                }
            }
        }
    }

    int cnt = 0;
    ll max_val = 0;
    for( auto& p : s ) {
        if ( max_val < p.sc ) {
            cout << p.sc << endl;
            max_val = p.sc;
            
            ++cnt;
            if ( cnt == k ) break;
        }            
    }
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N;
    cin >> N;
    vl A(N), B(N), C(N);
    rep(i, N){
        cin >> A[i];
    }
    sort(all(A));
    rep(i, N){
        cin >> B[i];
    }
    sort(all(B));
    rep(i, N){
        cin >> C[i];
    }
    sort(all(C));

    ll ans = 0;
    //中段を決めると全て決まる
    rep(i, N){
        ll a = lower_bound(all(A), B[i]) - A.begin();
        ll c = N - (upper_bound(all(C), B[i]) - C.begin());
        ans += a * c;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2688
import java.util.*;
class Main {
	public static void main (String[] args) throws java.lang.Exception {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int a = sc.nextInt();
			String d = sc.next();
			int b = sc.nextInt();
			if(d.equals("?")) break;
			if(d.equals("+")) System.out.println(a + b);
			if(d.equals("-")) System.out.println(a - b);
			if(d.equals("*")) System.out.println(a * b);
			if(d.equals("/")) System.out.println(a / b);
		}
	}
}

Measured memory_bytes: 26272
K = int(input())
d = [1,2,3,4,5,6,7,8,9]

if K <= 9:
  print(K)
  exit()

cnt = 9
while cnt < K:
  _ = d.pop(0)
  matsubi = _%10
  
  if matsubi == 0:
    d.append(_*10+matsubi)
    cnt += 1
    if cnt == K:
      print(d[-1])
      exit()
    d.append(_*10+matsubi+1)
    cnt += 1
    if cnt == K:
      print(d[-1])
      exit()
    
  elif matsubi == 9:
    d.append(_*10+matsubi-1)
    cnt += 1
    if cnt == K:
      print(d[-1])
      exit()

    d.append(_*10+matsubi)
    cnt += 1
    if cnt == K:
      print(d[-1])
      exit()
  else:
    d.append(_*10+matsubi-1)
    cnt += 1
    if cnt == K:
      print(d[-1])
      exit()

    d.append(_*10+matsubi)
    cnt += 1
    if cnt == K:
      print(d[-1])
      exit()

    d.append(_*10+matsubi+1)
    cnt += 1
    if cnt == K:
      print(d[-1])
      exit()

Measured memory_bytes: 5900
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count =0;
    for(int i=1;i<=n;i++){
      String h = Integer.toString(i);
      int l = h.length();
      if(l%2!=0){
        count++;
      }
    }
    System.out.println(count);
  }
}
 

Measured memory_bytes: 28244
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m,l = readline() |> split |> parseMap
	g = zeros(Int,n,n)
	d = 10^12*ones(Int,n,n)
	e = 10^12*ones(Int,n,n)
	for i in 1:n
		d[i,i] = 0
	end
	for i in 1:m
		a,b,c = readline() |> split |> parseMap
		g[a,b] = c
		g[b,a] = c
		d[a,b] = c
		d[b,a] = c
	end
	for k in 1:n
		for i in 1:n
			for j in 1:n
				d[i,j] = min(d[i,j], d[i,k] + d[k,j])
			end
		end
	end
	for i in 1:n
		for j in 1:n
			if d[i,j] <=l
				e[i,j] = 1
			end
		end
	end
	for k in 1:n
		for i in 1:n
			for j in 1:n
				e[i,j] = min(e[i,j], e[i,k] + e[k,j])
			end
		end
	end
	q = readline() |> parseInt
	for i in 1:q
		s,t = readline() |> split |> parseMap
		println(e[s,t]<10^11?e[s,t]-1:-1)
	end
end

main()

Measured memory_bytes: 160248
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#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()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvi = vector<vector<int> >;
using vvll =  vector<vector<ll> >;
const int maxR = 3005;

const ll inf = 1LL << 60;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int R,C,K;cin >>R>>C>>K;
    //vvll board1(R+1,vector<ll>(C+1,0)), board2(R+1,vector<ll>(C+1,0)),board3(R+1,vector<ll>(C+1,0));
    vector<vector<vector<ll> > > board(4,vector<vector<ll> >(maxR, vector<ll>(maxR,0)));
    vvll item(R,vector<ll>(C,0));
    REP(i,K){
        int r,c; ll v;
        cin >> r>>c>>v;
        r--;c--;
        item[r][c] = v;
    }
    REP(i,R){
        REP(j,C){
            board[0][i+1][j+1] = max({board[0][i+1][j+1],board[0][i+1][j],board[0][i][j+1], board[1][i][j+1],board[2][i][j+1],board[3][i][j+1]});
            FOR(k,1,4){
                if(item[i][j] == 0){ //itemとる余地無し
                    board[k][i+1][j+1] = max(board[k][i+1][j+1], board[k][i+1][j]);
                }
                else{
                    if(k == 1){
                        board[k][i+1][j+1] = max({board[k][i+1][j+1], board[k][i+1][j], board[k-1][i+1][j] + item[i][j], board[0][i][j+1] + item[i][j], board[1][i][j+1] + item[i][j], board[2][i][j+1] + item[i][j] , board[3][i][j+1] + item[i][j]});
                    }
                    else{
                        board[k][i+1][j+1] = max({board[k][i+1][j+1], board[k][i+1][j], board[k-1][i+1][j] + item[i][j]});
                    }
                }
            }
        }
    }

    ll ans = 0;
    REP(i,4){
        ans = max(ans,board[i][R][C]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 356428
n,m=map(int,input().split())
ans=[0]*m
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
  k=l[i][0]
  for j in range(1,k+1):
    ans[l[i][j]-1]+=1
cnt=0
for aa in ans:
  if aa==n:
    cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c) <= d){
    cout << "Yes" << endl;
  }else if((abs(a-b)<=d)&&(abs(b-c) <= d)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x1,x2,x3,X,Y;
	cin>>x1>>x2>>x3>>X>>Y;
	 int price=0,big=0,maxx;
	 
	 if(X>Y)  maxx=X;
	 else  maxx=Y;
	 
	
	
	 if((x1+x2)/2>=x3)
	   {
	   if(X>Y)  big=Y;
	   else  big=X;
	   price=2*big*x3+price;
	   if(X>Y)  price=price+(X-Y)*x1;
	   else  price=price+(Y-X)*x2;
	   }
	
	if((x1+x2)/2<x3)
	price=x1*X+x2*Y;
	
	if(x3*2*maxx<price)
	price=x3*2*maxx;

	cout<<price<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll MAXD = 1000000000000000000;


struct SegmentTree
{
    int n;
    vector<ll> data;
    SegmentTree(){};

    void init(int n_)
    {
        n = 1;
        while (n < n_) n <<= 1; 
        data.assign(n << 1, MAXD);
    }

    // void build(const vector<ll> &v)
    // {
    //     init(v.size());
    //     rep(i, 0, v.size()) data[i] = v[i];
    //     rrep(i, v.size(), 1) data[i] = min(data[2 * i], data[2 * i + 1]);
    // }

    void set(int k, ll x)
    {
        k += n;
        data[k] = min(x, data[k]);
        while (k >>= 1)
            data[k] = min(data[2 * k], data[2 * k + 1]);
    }

    ll query(int a, int b)
    {
        ll vl = MAXD, vr = MAXD;
        for (int l = a+n, r = b+n; l < r; l >>= 1, r >>= 1)
        {
            if (l&1) vl = min(vl, data[l++]);
            if (r&1) vr = min(vr, data[--r]);
        }
        return min(vl, vr);
    }
};



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

    vector<pll> edge[n];
    rep(i, 0, m)
    {
        ll l, r, c;
        cin >> l >> r >> c;
        --l, --r;
        edge[l].emplace_back(r, c);
    }

    SegmentTree st;
    st.init(n);
    st.set(0, 0);
    // st.init(10);
    // cout << st.query(0, 1) << endl;

    rep(i, 0, n)
    {
        ll nowd = st.query(i, n);
        // cout << i << ' ' << nowd << endl;
        for (pll r_c: edge[i])
        {
            ll next, cost;
            tie(next, cost) = r_c;
            // cout << "   " << next << ' ' << cost+nowd << endl;
            st.set(next, cost+nowd);
        }
    }
    ll res = st.query(n-1, n);
    if (res == MAXD)
        cout << -1 << endl;
    else
        cout << res << endl;
    return 0;
}

Measured memory_bytes: 7680
from collections import deque

def solve():
    n,a,b,c,d = map(int,input().split())
    s = input()
    # aからcに到達可能か
    flag1 = True
    # bからcに到達可能か
    flag2 = True
    # 反転しているとき、到達可能な範囲に...は存在するか
    flag3 = False
    cnt = 0
    for i in range(a-1,c):
        if s[i]=='#':
            cnt+=1
        else:
            cnt=0
        if cnt>=2:
            flag1 = False
    cnt=0
    for i in range(b-1,d):
        if s[i]=='#':
            cnt+=1
        else:
            cnt=0
        if cnt>=2:
            flag2 = False
    l = max(a,b)
    r = min(c,d)
    if r<n and s[r]!='#':
        r+=1
    if l-2>=0 and s[l-2]!='#':
        l-=1
    for i in range(l-1,r):
        if s[i]=='.':
            cnt+=1
        else:
            cnt=0
        if cnt>=3:
            flag3 = True

    if flag1 and flag2:
        if c<d:
            print('Yes')
        else:
            if flag3:
                print('Yes')
            else:
                print('No')
    else:
        print('No')
        
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3828
import java.lang.Math.max
import java.lang.Math.min


fun main(args:Array<String>):Unit{
    val n = readLine()!!.toInt()
    val trampoline = Array(n){
        Trampoline(it * 10, readLine()!!.toInt())
    }
    val maxRight = Array(n){0}
    maxRight[0] = trampoline[0].maxRightPos()
    for (i in 1 until n){
        maxRight[i] = max(maxRight[i - 1], trampoline[i].maxRightPos())
    }
    val minLeft = Array(n){n * 10}
    minLeft[n - 1] = trampoline[n - 1].minLeftPos()
    for (i in 2 .. n){
        minLeft[n - i] = min(minLeft[n - i + 1], trampoline[n - i].minLeftPos())
    }
    var forward = 0
    var prevPos = 0
    while (forward < n - 1){
        forward = maxRight[forward] / 10
        if (prevPos == forward){
            break
        }
        prevPos = forward
    }
    var backward = n - 1
    while (backward > 0){
        backward = (minLeft[backward] + 9) / 10
        if (prevPos == backward){
            break
        }
        prevPos = backward
    }
    println(if (forward >= n - 1 && backward <= 0) "yes" else "no")
}
class Trampoline(val position:Int, val length:Int){
    fun maxRightPos():Int = position + length
    fun minLeftPos():Int = position - length
}


Measured memory_bytes: 78748
#include <bits/stdc++.h>
#define A string N;
#define B cin >> N;
#define C if((N[0]==N[1] && N[1]==N[2]) || (N[1]==N[2] && N[2]==N[3]))cout << "Yes" << endl;
#define D else cout << "No" << endl;
using namespace std;
int main(){
  A B C D
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int A,B,C,D;
  scanf("%d %d %d %d",&A ,&B ,&C ,&D);
  do{
    C=C-B;
    A=A-D;
  }while((C>0)&&(A>0));
  if(C<=0){
    printf("Yes");
  }
  else{
   	printf("No");
  }
  return 0;
}

Measured memory_bytes: 1728
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int dp[3333];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, T, S; cin >> N >> T >> S;
  int A[N], B[N];
  FOR(i,0,N) cin >> A[i] >> B[i];
  int ans = 0;
  FOR(i,0,N) {
    for(int j = T; j - B[i] >= 0; j--) {
      if(j > S && j - B[i] < S) continue;
      dp[j] = max(dp[j], dp[j-B[i]] + A[i]);
      ans = max(ans, dp[j]);
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

int main(){
	string S;
	cin>>S;
	int p=0,ans=0;
	REP(i,(int)S.length()){
		char h=S[i];
		if (p>0){
			p--;
			if (h=='g'){
				ans++;
			}
		}else{
			if (h=='p'){
				ans--;
			}
			p++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

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

	vector<int> a(n);
	vector<int> b(n);

	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}

	for (int i = 0; i < n; i++)
	{
		cin >> b.at(i);
	}

	int s = 0;
	for (int i = 0; i < n; i++)
	{
		int s0 = accumulate(a.begin(), a.begin() + i + 1, 0);
		int s1 = accumulate(b.begin() + i, b.end(), 0);


		s = max(s, s0 + s1);
	}

	cout << s << endl;
}

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

int main(){
    int n;
    cin >> n;
    int A[n], B[n];
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    B[0] = 0;    B[1] = abs(A[1] - A[0]);
    for(int i = 2; i < n; i++){
        int one = abs(A[i] - A[i-1]), two = abs(A[i] - A[i-2]);
        B[i] = min(B[i-1] + one, B[i-2] + two);
    }
    cout << B[n-1];
}



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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	long long x, d, k;
	cin >> x >> k >> d;
	x = abs(x);
	long long div = x / d;
	if (k >= div)
	{
		k -= div;
		x -= div * d;
		k %= 2;
	}
	cout << abs(x - k * d);
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
using namespace std;
int ans[8000]={0};
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    a=min(a,b);
    for(int i=0;i<=a;i++)
        for(int j=0;j<=a;j++)
            ans[i+j]++;
    int wans=0;
    for(int i=0;i<=a;i++)
        wans=wans+ans[b-i];
    printf("%d\n",wans);
    return 0;
}


Measured memory_bytes: 256
/* this is a test */

using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC170C
{
    class Program
    {
        static void Main(string[] args)
        {
            var XN = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var X = XN[0];
            var N = XN[1];

            if (N == 0)
            {
                Console.WriteLine(X);
                return;
            }

            var pSet = new HashSet<int>(Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x));

            /*if (pSet.Count == 100)
            {
                Console.WriteLine(0);
                return;
            }*/

            var a = 0;
            for (var i = X; i <= 101; i++)
            {
                if (!pSet.Contains(i))
                {
                    a = i;
                    break;
                }
            }

            var b = 0;
            for (var i = X; i >= 0; i--)
            {
                if (!pSet.Contains(i))
                {
                    b = i;
                    break;
                }
            }

            if (Math.Abs(X - a) < Math.Abs(X - b))
                Console.WriteLine(a);
            else
                Console.WriteLine(b);

        }
    }
}


Measured memory_bytes: 20492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

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

    vector<ll> f[2], b[2];
    f[0].push_back(A[0]), f[1].push_back(A[1]);
    b[0].push_back(A[N - 1]), b[1].push_back(A[N - 2]);
    for (int i = 2; i + 1 < N; i += 2)
        f[0].push_back(f[0].back() + A[i]),
            f[1].push_back(max(f[1].back(), f[0][f[0].size() - 2]) + A[i + 1]);
    for (int i = N - 3; i - 1 >= 0; i -= 2)
        b[0].push_back(b[0].back() + A[i]),
            b[1].push_back(max(b[1].back(), b[0][b[0].size() - 2]) + A[i - 1]);

    if (N % 2 == 0) {
        cout << max(f[0].back(), f[1].back()) << endl;
    } else if (N == 3) {
        cout << max({A[0], A[1], A[2]}) << endl;
    } else {
        ll ans =
            max(max({A[0], A[1], A[2]}) + b[0][(N - 5) / 2], max({A[0], A[1]}) + b[1][(N - 5) / 2]);
        for (int i = 0; (i + 1) * 2 + 3 < N; i++) {
            ll x;
            int j = (N - 7) / 2 - i;
            int k = (i + 1) * 2;
            x = max({f[0][i] + b[0][j] + max({A[k], A[k + 1], A[k + 2]}),
                     f[1][i] + b[0][j] + max(A[k + 1], A[k + 2]),
                     f[0][i] + b[1][j] + max(A[k], A[k + 1]), f[1][i] + b[1][j] + A[k + 1]});
            ans = max(ans, x);
        }
        ll x = max(max({A[N - 1], A[N - 2], A[N - 3]}) + f[0][f[0].size() - 2],
                   max(A[N - 1], A[N - 2]) + f[1][f[1].size() - 2]);
        ans = max(ans, x);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 8768
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cmath>
#include <iomanip>
#include <cstdio>
using namespace std;

typedef long long ll;

const int maxn = 1e5+5;
int N,M;
int fa[maxn];
int size[maxn];
ll ans[maxn];
int l[maxn];
int r[maxn];

int find(int x)
{
    return fa[x]==x ? x:fa[x]= find(fa[x]); //这里一开始写错了，写成了x = find。。
}

void join(int a, int b)
{
    a = find(a), b = find(b);
    if(a != b)
    {
        size[a] += size[b];
        size[b] = 0;
       fa[b] = a;
    }
}
int main(){
	cin>>N>>M;

	for(int i=0;i<maxn;i++)
		fa[i] = i,size[i]=1;
	 memset(ans, 0, sizeof(ans));
		
	for(int i=1;i<=M;i++)
		scanf("%d%d", &l[i], &r[i]);
	ll cnt = N;
	ans[M+1] = cnt*(cnt-1)/2;
	for(int i = M;i>=2;i--){
		int x = find(l[i]);
		int y = find(r[i]);
		if(x!=y){
			ans[i] = ans[i+1]-size[x]*size[y];
			join(l[i],r[i]);
		}
		else 
			ans[i] = ans[i+1];
	}
	
	for(int i=2;i<=M+1;i++)
		  printf("%lld\n", ans[i]);
	
	return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<math.h>
#include<set>
#include<iomanip>
#include<stdio.h>
#include<deque>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#define M 1000000007
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a;
	string s;
	cin>>a>>s;
	if(a>=3200)
		cout<<s<<endl;
	else
		cout<<"red"<<endl;
}

Measured memory_bytes: 256
class PriorityQueue
  attr_accessor :data

  def initialize(arr=[])
    @data = arr
  end

  def push(e)
    @data.push(e)

    current_index = @data.size-1
    parent_index = parent(current_index)

    while current_index > 0 && @data[parent_index] > @data[current_index]
      @data[current_index] = @data[parent_index]
      @data[parent_index] = e
      current_index = parent_index
      parent_index = parent(current_index)
    end
  end

  def pop
    ret = @data.first
    last = @data.last
    current_index = 0

    while have_child?(current_index)
      li = left_child_index(current_index)
      ri = right_child_index(current_index)

      ni = li
      ni = ri if ri < @data.size && @data[ri] < @data[li]

      break if @data[ni] >= last

      @data[current_index] = @data[ni]
      current_index = ni
    end
    @data[current_index] = last
    @data.pop

    ret
  end

  def size
    @data.length
  end

  def parent(index)
    (index-1)/2
  end

  def left_child_index(index)
    2*index+1
  end

  def right_child_index(index)
    2*index+2
  end

  def have_child?(index)
    left_child_index(index) < @data.size
  end
end

n, m = gets.strip.split.map(&:to_i)
ab = readlines.map {|line| line.strip.split.map(&:to_i) }.group_by(&:first)

q = PriorityQueue.new

(1..m).reverse_each do |d|
  next unless ab[d]
  ab[d].each do |c_ab|
    q.push(c_ab.last)
    q.pop if q.size > (m-d+1)
  end
end

p q.data.inject(0, :+)



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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) {
	if (b == 0) return a;
	else return GCD(b, a % b); 
}
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }
template<class T>
inline T upper(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (i % 3 != 0 && i % 5 != 0) ans += i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624
//2018.10.19 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register LL
#define LL long long
#define inf 0x3f3f3f3f3f3f3f
#define eps 1e-15
inline LL read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline LL _abs(const res &x){
    return x>0?x:-x;
}
inline LL _max(const res &x,const res &y){
    return x>y?x:y;
}
inline LL _min(const res &x,const res &y){
    return x<y?x:y;
}
const int N=2e5+10;
namespace MAIN{
    LL n,x;
    LL a[N],sum[N];
    LL ans=inf;
    inline void MAIN(){
        n=read(),x=read();
        for(res i=1;i<=n;i++)a[i]=read(),sum[i]=sum[i-1]+a[i];
        for(res k=1;k<=n;k++){
            res tot=0;
            for(res i=n;i>=1;i-=k){
                tot+=(sum[i]-sum[_max(0,i-k)])*(i==n?5:2*((n-i)/k)+3);
                if(tot+(k+n)*x>=ans)break;
            }
            ans=_min(ans,tot+(k+n)*x);
        }
        printf("%lld\n",ans);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 3328
#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;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int h,w,n; cin>>h>>w>>n;
	int m = max(h,w);
	cout<<(n+m-1)/m<<'\n';
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int bounceArray[101];

int main()
{
	int length, checkPoint, Counter = 0;
	cin >> length >> checkPoint;
	for (int i = 0; i < length; ++i)
	{
		cin >> bounceArray[i + 1];
		bounceArray[i + 1] += bounceArray[i]; 
	}
	for (int i = 0; i < length + 1; ++i)
		if (bounceArray[i] <= checkPoint)
			++Counter;
	cout << Counter;
}

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

using namespace std; 

int main(){ 
  int n,m;
  cin>>n>>m;
  int a[50];
  int b[50];
  for (int i=0;i<m;i++){
    cin>>a[i]>>b[i];
  }
  int c[50]={0};
  for(int i=0;i<m;i++){
    c[a[i]-1]+=1;
    c[b[i]-1]+=1;
  }
  for (int i=0;i<n;i++){
    cout<<c[i]<<endl;
  }
}

Measured memory_bytes: 256
/*  ex4_3
    person_A  */
#include<stdio.h>
#include<math.h>
//プロトタイプ宣言
//西からindex番目の木の高さを返す
int rec(int index);
//見えている木の部分の高さから、雪が積もった高さを返す
int heightSnow(int heightA,int heightB);

int main(void){
    int heightA,heightB;
    //木の高さa,bの入力
    scanf("%d %d",&heightA,&heightB);
    //答えの出力
    printf("%d\n",heightSnow(heightA,heightB));
    return 0;
}

//関数の定義
int rec(int index){
    if(index==1){
        return 1;
    }
    else{
        return rec(index-1)+index;
    }
}

int heightSnow(int heightA,int heightB){
    return rec(heightB-heightA)-heightB;
}


Measured memory_bytes: 128
from itertools import accumulate
N = int(input())
an = list(map(int, input().split()))
res = [0] + an
res = list(accumulate(res))
ans = 10e+9
for i in range(1, N):
    ans = min(ans, abs(res[i] - (res[-1]-res[i])))
print(ans)


Measured memory_bytes: 88528
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int N=1e5+15;
vector<int>g[N];
int n,m,d[N];

void dfs(int v) {
	if(d[v]!=-1)return;
	d[v]=0;
	for(int i:g[v]) {
		dfs(i);
		d[v]=max(d[v],d[i]+1);
	}
}

int main(){FIN;
	mset(d,-1);
	cin>>n>>m;
	fore(i,0,m) {
		int x,y;
		cin>>x>>y;x--,y--;
		g[x].pb(y);
	}
	fore(i,0,n)dfs(i);
	int res=0;
	//fore(i,0,n)cout<<d[i]<<" ";cout<<endl;
	fore(i,0,n)res=max(res,d[i]);
	cout<<res<<endl;
}	

Measured memory_bytes: 8192
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO
import Data.Function

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  as <- VU.unfoldrN n (BS.readInt . BS.dropWhile (<'-')) <$> BS.getLine
  bs <- VU.unfoldrN m (BS.readInt . BS.dropWhile (<'-')) <$> BS.getLine
  let asum = fromIntegral $ VU.sum as :: Int64
      bsum = fromIntegral $ VU.sum bs
  print $ asum * bsum



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

int main() {
    int N;
    cin >> N;
    int odd = (N + 1) / 2;
    double ans = (double) odd / N; 
    cout << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second




int main() {
	int n, k, s = 1;
	cin >> n >> k;
	for (int i = 0;i < n;i++) {
		if (s * 2 <= s + k) {
			s *= 2;
		}
		else s += k;
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll modd=10e9;

int main(){
  ll n;
  cin >> n;
  vector<ll>a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }
  
  ll count=0;
  ll c2=0;
  ll c5=0;
  long double all=1;
  ll ans=1;
   bool judge=true;
  for(int i=0; i<n; i++){
    ll j=0;
    ans*=a[i];
    while(a[i]%10==0){
      a[i]/=10;
      j++;
      count++;
    }
    if(a[i]!=1) judge=false;
    if(a[i]==2)c2++;
    if(a[i]==5)c5++;
    all*=a[i];
    while(all>=10){
      all/=10;
      count++;
    }
  }
  
  if(c2>0 && c5>0 && c2==c5)judge=true;
  if(count>=18 && judge==false) cout << -1 << endl;
  else cout << ans << endl;
  
}
  
  
  


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

int main()
{
	int64_t n, a, b;
	string s;
	cin >> n >> a >> b >> s;

	int64_t x = 0, y = 0;

	for (auto &&c : s)
	{
		if (c == 'a')
		{
			if (x < a + b)
			{
				cout << "Yes" << endl;
				x++;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else if (c == 'b')
		{
			if (x < a + b && y < b)
			{
				cout << "Yes" << endl;
				x++;
				y++;
			}
			else
			{
				cout << "No" << endl;
			}
		}
		else if (c == 'c')
		{
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a > 9 || b > 9) System.out.println("-1");
        else System.out.println(a * b);
    }
}

Measured memory_bytes: 35848
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

bo = ['a','e','i','u','o']

while True:
    N = inp()
    if N == 0:
        break
    else:
        codes = ['']*N
        for i in range(N):
            S = input()
            flag = True
            for s in S:
                if flag:
                    codes[i] = codes[i] + s
                    flag = False
                if s in bo:
                    flag = True

        for k in range(1,60):
            koho = set()
            for code in codes:
                koho.add(code[:k])

            if len(koho) == N:
                print(k)
                break
        else:
            print(-1)



Measured memory_bytes: 7160
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
max_h=0
max_w=0
flag=True
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            if i>max_h:
                max_h=i
            elif i<max_h:
                flag=False
            if j>max_w:
                max_w=j
            elif j<max_w:
                flag=False
print("Possible" if flag==True else 'Impossible')

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

int main(){
  int N;
  cin >> N;
  vector<int> ans(N+1);
  for(int i = 1; i <= 100; i++){
    for(int j = 1; j <= 100; j++){
      for(int k = 1; k <= 100; k++){
        int v = i * i + j * j + k * k + i * j + j * k + i * k;
        if(v > N) continue;
        ans[v]++;
      }
    }
  }
  for(int i = 1; i <= N; i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 3424
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B = LI()

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

Ad = make_divisors(A)
Bd = make_divisors(B)
# c = list(Ad.intersection(Bd))
c = list(set(Ad) & set(Bd))

def is_prime_custom(n):
    # custom
    if n == 1: return True

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

count = 0
for i in c:
    if is_prime_custom(i):
        count += 1
print(count)

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> count(m);
  for (int i = 0; i < n; i++) {
    int k; cin >> k;
    vector<int> ai(k);
    for (int j = 0; j < k; j++) cin >> ai.at(j);
    for (int a : ai) count.at(a-1) += 1;
  }
  int ans = 0;
  for (int c : count) if (c == n) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {


    int n;cin>>n;
    if(n%2==0)
    	cout<<n/2<<endl;
    else
    	cout<<(n/2)+1<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する

int main() {
    int n;
    cin >> n;
    map<int,int> m;
    REP(i,0,n){
        int d;
        cin >> d;
        if(m.find(d) == m.end()) {
            m.insert(pair<int,int>(d, 1));
        }else{
            m[d]++;
        }
    }
    int M;
    cin >> M;
    REP(i,0,M){
        int t;
        cin >> t;
        if(m.find(t) == m.end()){
            cout << "NO" << endl;
            return 0;
        }else if(m[t] == 0){
            cout << "NO" << endl;
            return 0;
        }else{
            m[t]--;
        }
    }
    cout<< "YES" << endl;
    return 0;
}


Measured memory_bytes: 9600