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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



int main(){
  char a;
  cin >> a;
  if('a'<=a && a<='z') cout << 'a' << endl;
  else cout << 'A' << endl;
}

Measured memory_bytes: 3568
import java.util.*;

final class Point {
	int x;
	int y;

	Point(int x, int y) {
		this.x = x;
		this.y = y;
	}
}

final class Cost implements Comparable<Cost> {
	Point vertex;
	int cost;

	Cost(Point vertex, int cost) {
		this.vertex = vertex;
		this.cost = cost;
	}

	@Override
	public int compareTo(Cost o) {
		return Comparator.comparingInt((Cost c) -> c.cost).compare(this, o);
	}
}

final class Solver {
	static final Solver INSTANCE = new Solver();
	private int H;
	private int W;
	private BitSet[] table;

	void solve(Scanner sc) {
		this.H = sc.nextInt();
		this.W = sc.nextInt();
		table = new BitSet[H];
		for (int i = 0; i < H; i++) {
			BitSet bits = table[i] = new BitSet(W);
			String S = sc.next();
			char[] chars = S.toCharArray();
			for (int j = 0; j < chars.length; j++) {
				bits.set(j, chars[j] == '.');
			}
		}
		System.out.println(dijkstra() + (table[0].get(0) ? 0 : 1));
	}

	int dijkstra() {
		int[][] cost = new int[H][W];
		int[] infs = new int[W];
		Arrays.fill(infs, Integer.MAX_VALUE);
		for (int[] ints : cost) {
			System.arraycopy(infs, 0, ints, 0, W);
		}

		PriorityQueue<Cost> costs = new PriorityQueue<>();
		costs.add(new Cost(new Point(0, 0), 0));

		while (!costs.isEmpty()) {
			Cost c = costs.remove();
			if (c.cost > cost[c.vertex.y][c.vertex.x]) continue;
			boolean from = table[c.vertex.y].get(c.vertex.x);
			down: {
				if (c.vertex.y == H - 1) {
					break down;
				}
				int u = c.cost + (!table[c.vertex.y + 1].get(c.vertex.x) && from ? 1 : 0);
				if (cost[c.vertex.y + 1][c.vertex.x] > u) {
					cost[c.vertex.y + 1][c.vertex.x] = u;
					costs.add(new Cost(new Point(c.vertex.x, c.vertex.y + 1), u));
				}
			}
			right: {
				if (c.vertex.x == W - 1) {
					break right;
				}
				int r = c.cost + (!table[c.vertex.y].get(c.vertex.x + 1) && from ? 1 : 0);
				if (cost[c.vertex.y][c.vertex.x + 1] > r) {
					cost[c.vertex.y][c.vertex.x + 1] = r;
					costs.add(new Cost(new Point(c.vertex.x + 1, c.vertex.y), r));
				}
			}

		}
		return cost[H - 1][W - 1];
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 29812
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 10010010010001;

int main(){
    int N;
    cin >> N;
    int ans = N;
    for(int i=0;i<=N;i++){
        int cc = 0;
        int t = i;
        while(t > 0){
            cc += t%6;
            t /= 6;
        }
        t = N-i;
        while(t > 0){
            cc += t%9;
            t /= 9;
        }
        if(ans > cc) ans = cc;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N; cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    ll m = 1000, s = 0;
    vector<int> buy,sell;
    REP(i,N-1) {
        if (A[i] < A[i+1]) {
            s += m / A[i];
            m -= (m / A[i]) * A[i];
        } else if (A[i] > A[i+1]) {
            m += s * A[i];
            s = 0;
        }
        // cerr << m << " " << s << endl;
    }

    m += A[N-1] * s;

    OUT(m)


    return 0;
}

Measured memory_bytes: 3644
# 1. 入出力 (二次元配列)

N, C = map(int, input().split())

D = [ list(map(int, input().split())) for _ in range(C) ]
col = [ list(map(int, input().split())) for _ in range(N) ]

ans = 1 << 60
info = [ [0 for j in range(C)] for i in range(3) ]

for i in range(N):
    for j in range(N):
        mod = (i + j) % 3
        info[mod][ col[i][j] - 1 ] += 1

for i in range(C):
    for j in range(C):
        for k in range(C):
            if i == j or j == k or k == i:
                continue

            temp = 0
            lst = [i, j, k]

            for x in range(3):
                for y in range(C):
                    temp += D[y][ lst[x] ] * info[x][y]

            ans = min(ans, temp)
            # print(lst, temp)

print(ans)

Measured memory_bytes: 5620
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
#include <string>

#include <vector>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#define N 10
using namespace std;

int main(int argc, char const *argv[]) {
    int n;
    long long k;
    cin >> n >> k;
    int a[n];
    
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
        a[i]--;
    }

    int memo[n];
    int root[n];
    memset(memo, -1, sizeof(memo));

    int now = 0;
    int c = 0;
    while (true) {
        root[c] = now;
        if (k - c == 0) {
            cout << now + 1 << endl;
            return 0;
        }
        if (memo[now] >= 0) {
            c -= memo[now];
            k -= memo[now];
            break;
        } else {
            memo[now] = c;
            c ++;
            now = a[now];
        }
    }

    int res = k % c;
    cout << root[memo[now] + res] + 1 << endl;
    return 0;
}

Measured memory_bytes: 5816
N = int(input())
S = input()
cnt = 0

if N%2 != 0:
  print("No")
  exit()
  
for i in range(N//2):
  if S[i] == S[N//2+i]:
    cnt += 1
if cnt == N//2:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>

int main() {
	std::string s[3]; for (int i = 0; i < 3; i++)std::cin >> s[i];
	for (auto& str : s) {
		str[0] = toupper(str[0]);
		std::cout << str[0];
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;


class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        sc.nextLine();

        int[][] list = new int[N][M+1];

        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= M; j++) {
                list[i][j] = sc.nextInt();
            }
            sc.nextLine();
        }

        int okane = 0;
        int ans = Integer.MAX_VALUE;
        
        for (int i = 0; i < Math.pow(2, N); i++) {
            int[] abi = new int[M];
            String bit = Integer.toBinaryString(i);

            for (int j = bit.length()-1; j >= 0 ;  j--) {
                if (bit.charAt(j) == '1') {
                    okane += list[bit.length()-1-j][0];
                    for (int k = 0; k < M; k++) {
                        abi[k] += list[bit.length()-1-j][k+1];
                    }
                }
            }

            if (check(abi,X) && okane <= ans) { ans = id(okane);; }
            okane = 0;

        }
        if(ans == Integer.MAX_VALUE) {ans = -1;}
        System.out.println(ans);
    }

    static int id(int i) {
        return i;
    } 

    static boolean check (int[] k,int x) {
        for (int i = 0; i < k.length; i++) {
            if (k[i] < x) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 38332
#include<cstdio>
#include<iostream>
using namespace std;
int n,a[109],b[109],ans=0;
int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>a[i];
		b[1]=a[1];
		if(i>1) b[i]=min(a[i-1],a[i]);
	}
	b[n]=a[n-1];
	for(int i=1;i<=n;i++){
		ans+=b[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#include <sstream>
#include <complex>
#define BIT(nr) (1ULL << (nr))
#define int long long
#define ll long long
#define double complex<long double>
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	
#define LL_HALFMAX 9223372036854775807 / 2	
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

using namespace std;


signed main() {
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;

	rep(i, 10) rep(j, 10) rep(k, 10)
	{
		vector<bool> f(3, false);
		rep(l, N) {
			if (S[l] - '0' == i && !f[0]) {
				f[0] = true;
				continue;
			}
			if (S[l] - '0' == j && f[0] && !f[1]) {
				f[1] = true;
				continue;

			}
			if (S[l] - '0' == k && f[1]) {
				f[2] = true;
				continue;

			}
		}
		if (f[2]) {
			ans++;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 384
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"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var s = o.a(1);
  var n = s.length;
  for(var i = 0; i < n; i++){
    if(i%2){
      if(s[i] === "R")return "No";
    }else{
      if(s[i] === "L")return "No";
    }
  }
  return "Yes";
}

Measured memory_bytes: 7372
/*https://atcoder.jp/contests/agc027/tasks/agc027_a*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	long long a[n], x;
	cin >> x;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		if (x < a[i])
		{
			cout << count;
			return 0;
		}
		x -= a[i], count++;
	}
	if (x == 0)
		cout << count;
	else
		cout << n - 1;
}

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

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

using namespace std;

using uint=unsigned int;
using ll=long long;

uint xor128(){
	static uint d[]={1145141919,1919810893,810893364,364114514};
	uint t=d[0]^(d[0]<<11);
	REP(i,3)
		d[i]=d[i+1];
	return d[3]=d[3]^(d[3]>>19)^(t^(t>>8));
}

struct Node{
	Node *l,*r;
	uint pri;
	int s,v,mn;
} buf[200000];

using NP=Node*;

NP newNode(int v){
	static int c=0;
	buf[c]=Node{NULL,NULL,xor128(),1,v,v};
	return &buf[c++];
}

const int inf=1145141919;

inline int Mini(NP x){
	return x?x->mn:inf;
}

inline int Size(NP x){
	return x?x->s:0;
}

inline NP Update(NP x){
	x->s=Size(x->l)+Size(x->r)+1;
	x->mn=min({x->v,Mini(x->l),Mini(x->r)});
	return x;
}

inline NP LinkL(NP x,NP l){
	x->l=l;
	return Update(x);
}

inline NP LinkR(NP x,NP r){
	x->r=r;
	return Update(x);
}

inline NP CutL(NP x){
	x->l=NULL;
	return Update(x);
}

inline NP CutR(NP x){
	x->r=NULL;
	return Update(x);
}

inline NP Merge(NP a,NP b){
	if(!a)
		return b;
	else if(!b)
		return a;
	else if(a->pri>b->pri)
		return LinkR(a,Merge(a->r,b));
	else
		return LinkL(b,Merge(a,b->l));
}

using Res=Node;

inline Res Split(NP x,int k){
	if(k<=0)
		return Res{NULL,x};
	else if(x->s<=k)
		return Res{x,NULL};
	else if(k<=Size(x->l)){
		Res s=Split(x->l,k);
		return Res{s.l,Merge(s.r,CutL(x))};
	}else{
		Res s=Split(x->r,k-Size(x->l)-1);
		return Res{Merge(CutR(x),s.l),s.r};
	}
}

inline void Set(NP x,int k,int v){
	int ls=Size(x->l);
	if(k<ls)
		Set(x->l,k,v);
	else if(k==ls)
		x->v=v;
	else
		Set(x->r,k-ls-1,v);
	Update(x);
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

NP t[200000];

int main(){
	int n=read(),q=read();
	REP(i,n)
		t[i]=newNode(read());
	while(n>1){
		int k=n/2;
		REP(i,k)
			t[i]=Merge(t[i*2],t[i*2+1]);
		if(k*2<n)
			t[k]=t[k*2];
		n=(n+1)/2;
	}
	NP root=t[0];
	REP(_,q){
		int x=read(),y=read(),z=read();
		if(x==0){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y-1);
			Res s3=Split(s2.r,1);
			root=Merge(Merge(s1.l,s3.l),Merge(s2.l,s3.r));
		}else if(x==1){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y);
			printf("%d\n",Mini(s2.l));
			root=Merge(s1.l,Merge(s2.l,s2.r));
		}else if(x==2){
			Set(root,y,z);
		}
	}
}

Measured memory_bytes: 11048
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	rep(i, N) cin >> A.at(i);
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	ll count = A.at(0);
	ll M = N / 2;
	if (N % 2 == 0) {
		rep(i, M - 1) { count += A.at(i + 1) * 2; }
	} else {
		rep(i, M - 1) { count += A.at(i + 1) * 2; }
		count += A.at(M);
	}
	cout << count << endl;
}

Measured memory_bytes: 4848
//
// Created by Myabu on 2020/01/27.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    string S_1;
    string S_2;
    string S_3;
    cin>>S_1;
    cin>>S_2;
    cin>>S_3;

    cout<<S_1[0]<<S_2[1]<<S_3[2]<<endl;




    return 0;
}

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

main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,p;
 while(cin>>n){
        j=0;
 for(i=1;i<=n;i++){
    cin>>k;
    if(k%2==1&&i%2==1)j++;
 }
cout<<j<<endl;
 }


    return 0;

}


Measured memory_bytes: 3584
n,q = map(int,input().split())

P = [i for i in range(n)]
def root(x):
    path_to_root = []
    while P[x] != x:
        path_to_root.append(x)
        x = P[x]
    for node in path_to_root:
        P[node] = x
    return x
def is_same_set(x,y):
    if root(x) == root(y):
        return 1
    else: return 0
def unite(x,y):
    P[root(x)] = root(y)

for i in range(q):
    com,x,y = map(int,input().split())
    if com == 0:
        unite(x,y)
    if com == 1:
        print(is_same_set(x,y))


Measured memory_bytes: 5976
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
  int H, A;
	cin >> H >> A;
	cout << dup(H, A) << endl;
  
  return 0;
}

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

typedef long long ll;
const ll mod = 1e9 + 7;
ll res = 1;
ll mul[2][52];

int main() {
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    for (int pos = 0; pos < n; pos++) {
        if (s1[pos] == s2[pos]) {
            if (pos == 0) {
                res *= 3;
            } else if (s1[pos - 1] == s2[pos - 1]) {
                res *= 2;
            }
        } else {
            if (pos == 0) {
                res *= 6;
            } else if (s1[pos - 1] == s2[pos - 1]) {
                res *= 2;
            } else {
                res *= 3;
            }
            pos++;
        }
        res %= mod;
    }
    cout << res % mod << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(raw_input())
s = []
for _ in xrange(n):
    s.append(int(raw_input()))
mx = sum(s)
if mx % 10 != 0:
    print mx
else:
    s.sort()
    for idx in xrange(len(s)):
        if s[idx] % 10 != 0:
            print mx - s[idx]
            break
    else:
        print "0"


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

# define C continue;

# define ll long long
# define ld long double

# define pb push_back
# define I insert
# define PQ priority_queue

# define vi vector < int >
# define vll vector < ll >
# define vc vector < char >
# define vb vector < bool >
# define vs vector < string >

# define vvi vector < vector < int > >
# define vvll vector < vector < ll > >
# define vvc vector < vector < char > >
# define vvb vector < vector < bool > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >

# define vpii vector < pair < int , int > >
# define vpll vector < pll >

# define F first
# define S second

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .
/// Start using lower bound !!

int n , m ;

const int N = 1e5 + 10 ;
pii v[N] ;

void read ()
{
    cin >> n >> m ;

    for ( int i=0 ; i < n ; i ++ )
        cin >> v[i].F >> v[i].S ;
}

ll dp[N] ;

void solve ( int test_case )
{
    read () ;
    int &w = m ;

    for ( int i=0 ; i < n ; i ++ )
    {
        for ( int j = max ( 0 , w - v[i].F ) ; j > -1 ; j -- )
        {
            if ( j == 0 || dp[j] > 0 )
                dp[j + v[i].F] = max ( dp[j + v[i].F] , dp[j] + v[i].S ) ;
        }
    }

    ll ans = 0 ;

    for ( int i=0 ; i <= m ; i ++ )
        ans = max ( ans , dp[i] )  ;

    cout << ans ; line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0;
}


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

int main() {
    long long N;
    cin >> N;
    long long m = 1001001001001001001;
    for(int i=0; i<5; ++i) {
        long long a;
        cin >> a;
        m = min(m, a);
    }
    cout << 4 + N / m + (N % m ? 1 : 0) << endl;
}

Measured memory_bytes: 256
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var values = o.getArray(0)
    var A = values[0]
    var B = values[1]

    return Math.ceil((B - 1) / (A - 1));
}

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

constexpr int MAX_H = 50;
constexpr int MAX_W = 50;

int H, W;
char grid[MAX_H][MAX_W + 1];

//#define OCTAS
#ifdef OCTAS
constexpr int dh[]{-1, -1, -1, 0, 0, +1, +1, +1};
constexpr int dw[]{-1, 0, +1, -1, +1, -1, 0, +1};
#else
constexpr int dh[]{-1, 0, 0, +1};
constexpr int dw[]{0, -1, +1, 0};
#endif

bool draw(int h, int w) {
  for (int i{}; i < sizeof(dh) / sizeof(int); ++i) {
    int nh = h + dh[i];
    if (nh < 0 || nh >= H)
      continue;
    int nw = w + dw[i];
    if (nw < 0 || nw >= W)
      continue;
    if (grid[nh][nw] == '#') {
      return true;
    }
  }

  return false;
}

int main() {
  scanf("%d%d", &H, &W);
  for (int h{}; h < H; ++h) {
    scanf("%s", &grid[h][0]);
  }

  bool judge{true};
  for (int h{}; h < H; ++h) {
    for (int w{}; w < W; ++w) {
      if (grid[h][w] == '.') {
        continue;
      }
      if (!(judge = draw(h, w))) {
        judge = false;
        goto END;
      }
    }
  }
END:
  printf("%s\n", judge ? "Yes" : "No");
  return 0;
}


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

using namespace std;

int main(){

	int a,b;
	char name[20];

	for(int i=0; i < 9; i++){
		scanf("%s %d %d",name,&a,&b);
		printf("%s %d %d\n",name,a+b,200*a+300*b);
	}

    return 0;
}

Measured memory_bytes: 2708
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int a,b;
   cin >> a >> b;
   if((a+b)%2==1){
       cout << (a+b)/2+1 << endl;
       
   }else{
       cout << (a+b)/2 << endl;
   }
    return 0;
    
}


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

int h1[20010],h2[20010],n,tt1,tt2;
char s1[5010],s2[5010];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline int abs1(int x) { return (x>0)?x:-x; }

inline void pre_gao()
{
	tt1=tt2=0;
	if (s1[1]!=s2[1]) h1[++tt1]=0;
	for (int i=1;i<=5009;i++) h1[++tt1]=0;
	for (int i=1;i<=n;i++) if (s1[i]!=s1[i+1]) h1[++tt1]=i;
	for (int i=1;i<=5010;i++) h1[++tt1]=n;
	h2[++tt2]=0;
	for (int i=1;i<=n;i++) if (s2[i]!=s2[i+1]) h2[++tt2]=i;
}

int main()
{
	n=rd();
	scanf("%s%s",s1+1,s2+1);
	pre_gao();
	int ans=inf;
	for (int i=1;i+tt2-1<=tt1;i+=2)
	{
		int res=0;
		for (int j=1;j<=tt2;j++) res+=abs1(h1[i+j-1]-h2[j]);
		for (int j=1;j<i;j++) res+=abs1(h1[j]);
		for (int j=i+tt2;j<=tt1;j++) res+=abs1(h1[j]-n);
		ans=min(ans,res);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  int N,M,sum=0;
  cin >> N;
  int T[N];
  for(int i=0;i<N;i++){
    cin >> T[i];
    sum += T[i];
  }
  cin >> M;
  for(int i=0;i<M;i++){
    int P,X;
    cin >> P >> X;
    cout << sum-T[P-1]+X << endl;
  }
}

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

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  if(s[k - 1] == 'A') s[k - 1] = 'a';
  else if(s[k - 1] == 'B') s[k - 1] = 'b';
  else s[k - 1] = 'c';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
n,q=gets.split.map &:to_i
A=n.times.map{[]}
q.times{
a=gets.split.map &:to_i
if a[0]==0
A[a[1]]<<a[2]
elsif a[0]==1
puts A[a[1]][0] if A[a[1]][0]
else
A[a[1]].shift
end
}


Measured memory_bytes: 9232
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const int INF = 1001001001;
int N,M;
vector<vector<bool>> graph;
vector<bool> reached;

int dfs(int v){
    bool all_reached = true;
    for(int i=0;i<N;i++){
        if(reached[i] == false) all_reached = false;
    }
    if(all_reached) return 1;

    int ret = 0;
    for(int i=0;i<N;i++){
        if(graph[v][i] == false) continue;
        if(reached[i]) continue;

        reached[i] = true;
        ret += dfs(i);
        reached[i] = false;
    }
    return ret;
}

int main(){
    cin >> N >> M;
    graph   = vector<vector<bool>>(N,vector<bool>(N,false));
    reached = vector<bool>(N);
    int x,y;
    for(int i=0;i<M;i++){
        cin >> x >> y;
        x--;y--;
        graph[x][y] = graph[y][x] = true;
    }
    reached[0] = true;
    cout << dfs(0) << endl;
}


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

namespace ABC126 {
  class ProblemB {
    static void Main(string[] args) {
      int n = Input.num;
      int foo = 0;
      if (n % 100 >= 1 && n % 100 <= 12) {
        foo += 1;
      }
      if (n / 100 >= 1 && n / 100 <= 12) {
        foo += 2;
      }

      switch (foo) {
        case 0:
          System.Console.WriteLine("NA");
          break;
        case 1:
          System.Console.WriteLine("YYMM");
          break;
        case 2:
          System.Console.WriteLine("MMYY");
          break;
        case 3:
          System.Console.WriteLine("AMBIGUOUS");
          break;
        default:
          break;
      }
    }
  }
  public class Input {
    public static string str => System.Console.ReadLine();
    public static string[] strs => str.Split(' ');
    public static char[] charArr => str.ToCharArray();
    public static int num => int.Parse(str);
    public static int[] nums => Array.ConvertAll(strs, int.Parse);
    public static long numL => long.Parse(str);
    public static long[] numLs => Array.ConvertAll(strs, long.Parse);
  }
}

Measured memory_bytes: 11092
#include <stdio.h>
 
int main( void )
{
	int N, Q ;
	scanf("%d %d", &N, &Q ) ;
	char s[100000+1];
	scanf("%s", s ) ;
	int C[100000]={};
	int c = 0 ;
	for( int n = 1 ; s[n] ; n++ ) {
		if( s[n-1] == 'A' && s[n] == 'C' ) c++ ;
		C[n] = c ;
	}
	for( int q = 0 ; q < Q ; q++ ) {
		int l, r ;
		scanf("%d %d", &l, &r ) ;
		l-- ;
		r-- ;
		printf("%d\n", C[r]-C[l] ) ;
	}
	return 0 ;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	int n,m,p;
	string s;
	vector<int> pv;
	vector<string> sv;
	cin >> n >> m;
	vector<int> waTimes(n,0);
	vector<bool> isAc(n, false);
	rep(i,m) {
		cin >> p >> s;
		if(s == "WA" && isAc[p-1] == false) {
			waTimes[p-1]++;
		}
		if(s == "AC" && isAc[p-1] == false) {
			isAc[p-1] = true;
		}
	}
	int acTimesSum = 0;
	int waTimesSum = 0;
	rep(i,n) {
		if(isAc[i] == true) {
			acTimesSum++;
			waTimesSum += waTimes[i];
		}
	}
	cout << acTimesSum << " " << waTimesSum << endl;

  return 0;
}


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

int const N = 1e7 + 1;
int ar[N];

void sieve()
{
	for (int i = 0; i < N; ++i)
		ar[i] = 1;

	for (int i = 2; i < N; i++)
		for (int j = i; j < N; j += i)
			ar[j]++;
}

int main()
{
	sieve();

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

	long long res = 0;
	for (int i = 1; i <= n; ++i)
		res += 1LL * i * ar[i];
	cout << res << '\n';
	return 0;
}

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

using namespace std;

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

	int N;
	cin >> N;
	vector<int>A(N);

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

	int ans = 0;
	
	for (int i = 0; i < N; i++) {
		ans += A[i] - 1;
	}

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

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int N,S=0,i=0;
  char n[20]={'\0'};
  scanf("%d",&N);
  sprintf(n,"%d",N);
  while(n[i]!='\0'){
    S+=(n[i]-48);
    i++;
  }
  if(N%S==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


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

import static java.lang.Integer.parseInt;

/**
 * Sum of Integers II
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n, s;
			n = parseInt(line.substring(0, line.indexOf(' ')));
			s = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((n | s) == 0) return;

			long[][][] dp = new long[101][n + 1][s + 1];

			dp[0][0][0] = 1;
			dp[0][1][0] = 1;

			for (int i = 1; i <= 100; i++) {
				for (int j = 1; j <= n; j++) {
					for (int k = i; k <= s; k++) {
						for (int l = 0; l < i; l++) {
							dp[i][j][k] += dp[l][j - 1][k - i];
						}
					}
				}
			}

			long ans = 0;

			for (int i = 0; i <= 100; i++) {
				ans += dp[i][n][s];
			}

			System.out.println(ans);
		}
	}
}

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

int main() {
	int H, W;
	for (int a = 0; ; a++) {
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		for (int i = 0; i < W; i++) {
			cout << '#';
		}
		cout << endl;
		for (int i = 1; i < H - 1; i++) {
			cout << '#';
			for (int j = 1; j < W - 1; j++) {
				cout << '.';
			}
			cout << '#' << endl;
		}
		for (int i = 0; i < W; i++) {
			cout << '#';
		}
		cout << endl << endl;
	}
}


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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int32_t main() {
    //ios::sync_with_stdio(false); cin.tie(nullptr);

    string s;
    cin >> s;

    int ans = 0, len = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A' or s[i] == 'T' or s[i] == 'G' or s[i] == 'C') {
            len++;
        } else {
            ans = max(ans, len);
            len = 0;
        }
    }

    cout << max(ans, len) << "\n";
    return 0;
}


Measured memory_bytes: 256
N, K =map(int, input().split())
mod = 10**9 + 7
A = int(-(N+1)*(N+2)*(2*N+3)/6)%mod
B = int((N+1)*(N+1)*(N+2)/2)%mod
C = N+1
a = int(-(K-1)*K*(2*K-1)/6)%mod
b = int((N+1)*(K-1)*K/2)%mod
c = K-1
print((A+B+C-a-b-c)%mod)

Measured memory_bytes: 9188
#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>
using namespace std;

void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main()
{
	fast();

	char a[4]; 
	int sum = 0;
	for (int i = 0; i < 3; i++)
	{
		cin >> a[i];
		if (a[i] == 'o')
			sum+= 100;

	}
	cout << 700 + sum << endl;
}



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

#define MAX_N 52
#define M 1000000007

using namespace std;

int main(void)
{
    int N;
    string S[2];
    cin >> N;
    cin >> S[0] >> S[1];
    long long answer = 1;
    for (int i = N - 1; i >= 0; i--) {
        if (S[0][i] == S[1][i]) {
            if (i == 0) {
                answer = (answer * 3) % M;
            } else if (S[0][i-1] == S[1][i-1]) {
                answer = (answer * 2) % M;
            } else {
                // answer = (answer * 1) % M;
            }
        } else {
            if (i == 1) {
                answer = (answer * 6) % M;
            } else if (S[0][i-2] == S[1][i-2]) {
                answer = (answer * 2) % M;
            } else {
                answer = (answer * 3) % M;
            }
            i--;
        }
    }
    cout << answer << endl;
    return 0;
}


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		400010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];

//
int main(){
	int r; cin >> r;

	cout << r*r << endl;




	return 0;
}




Measured memory_bytes: 256
H, W, K = map(int,input().split())
C = []
for _ in range(H):
    C.append(list(input()))

ans = 0

for i in range(2 ** H):
    for j in range(2 ** W):
        cnt = 0
        for k in range(H):
            for l in range(W):
                if i & 1 << k and j & 1 << l and C[k][l] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1

print(ans)

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

const double PI = acos(-1);
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll a, b;
	cin >>a >>b;
	
	auto f=[](ll z){
		VL rt;
		for(ll i=1; i*i<=z; i++){
			if(z%i) continue;
			rt.push_back(i);
			if(i*i != z) rt.push_back(z/i);
		}
		sort(all(rt));
		return rt;
	};
	auto g=[](ll z){
		for(ll i=2; i*i<=z; i++){
			if(z%i ==0) return false;
		}
		return true;
	};

	auto ya = f(a);
	auto yb = f(b);
	int ans = 0;
	for(auto x: ya){
		if(binary_search(all(yb), x) && g(x)) ans++;
	}
	cout << ans <<"\n";
	return 0;
	
}


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

int main() {
  int N, v[1000];
  double ans;
  cin >> N;
  for(int i=0; i<N; ++i) cin >> v[i];
  sort(v, v+N);
  ans = v[0];
  for(int i=1; i<N; ++i)
    ans = (ans+v[i])/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
h.reverse()
count=1
for i in range(0,n-1):
    if h[i]<h[i+1]:
        h[i+1]=h[i+1]-1
    if h[i]>=h[i+1]:
        count+=1
if count==n:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum = sum + a[i];
        }
        double ave = sum * 1.0 / n;
        double sa = Math.abs(a[0] - ave);
        int check = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            double sasa = Math.abs(a[i] - ave);
            if (sa == sasa)
                count++;
            if (sa > sasa) {
                sa = sasa;
                check = i;
            }
        }
        for (int i = 0; i < n; i++) {

        }
        if (count == n) {
            System.out.println(0);
        } else {
            System.out.println(check);
        }
    }
}

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

int main(){
    char number[1001];
    while(1){
        scanf("%s",number);
        if(number[0]=='0')break;
        int sum = 0;
        for(int i = 0;number[i]!='\0';i++){
            int a = number[i]-'0';
            sum+=a;
        }
        printf("%d\n",sum);
    }
    return 0;
}


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




int main() {
  
  int N,M;
  cin>>N>>M;
  vector<string> vec_a(N);
  vector<string> vec_b(M);

  
  for (int i=0;i<N;i++){
    cin>>vec_a.at(i);
  }
  
  for (int i=0;i<M;i++){
    cin>>vec_b.at(i);
  }
  
  string answer="No";
  bool flag=false;
  
  
  for (int i=0;i<N-M+1;i++){
    

    for (int j=0;j<N-M+1;j++){

      bool match=true;
      
      for (int k=0;k<M;k++){

        for (int l=0;l<M;l++){
          if (vec_a.at(i+k).at(j+l)!=vec_b.at(k).at(l)){
            match=false;
          }
          if (match==false){
            break;
          }
        }
        if (match==false){
          break;
        }
      }
      
      if (match){
        answer="Yes";
        flag=true;
      }
      if (flag){
        break;
      }
    }
    if (flag){
      break;
    }
    
  }
  
  cout<<answer<<endl;
      

}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    string S;
    cin >> N;
    vector<unsigned long long> A(N);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    unsigned long long ans=1, prev=1;

    rep(i,N){
        ans *= A[i];
        if(ans > 1000000000000000000){
            cout << -1 << endl;
            return 0;
        }
        if(prev > ans){
            cout << -1 << endl;
            return 0;
        }
        prev = ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,k;
	cin >> n >> k;
	int cnt = 0;
	int x = 0, z;
	while(n){
		z = n%k;
		x += x*pow(10, cnt);
		n /= k;
		cnt++;
	}
	cout << cnt << '\n';
	return 0;
}



Measured memory_bytes: 256
# Aizu Problem 0073: Surface Area of Quadrangular Pyramid
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    x = int(input())
    h = int(input())
    if x == h == 0:
        break
    h_x = math.sqrt(h**2 + x**2 / 4)
    A = x**2 + 2 * x * h_x
    print("%.6f" % A)

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

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

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; }

int main() {
    int h, a;
    int r;
    cin >> h >> a;

    r = h / a;
    if (h % a != 0)
        r++;
    cout << r << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
   int N;
   int C[500];
   int S[500];
   int F[500];
   int ans[500]={0,};
   
   scanf("%d",&N);
   int n;
   for(n=0;n<N-1;n++){
   	scanf("%d %d %d",&C[n],&S[n],&F[n]);
   }

   for(n=0;n<N-1;n++){
   	int k=n;
   	   int time=0;
   while(k<N-1){
   	 if(time>=S[k]&&(time+S[k])%F[k]==0){
   	 	//ans[n+1]=time;
   	 	time+=C[k];
   	 	k++;
   	 	
   	 }else{
   	 	if(time<S[k]){
   	 	time=S[k];
   	 	}else{
   	 		time+=F[k]-(time+S[k])%F[k];
   	 		
   	 	}
   	 }
   }
   ans[n]=time;
   }

   for(n=0;n<N-1;n++){

   	printf("%d\n",ans[n]);
   }
   printf("0\n");
   
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define debug(x) cout << x << endl
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const LL INF64 = 1e18;

const int N = 1e5 + 5;

int n, k;
string s;

vector<pair<int, int> > consecone;
vector<pair<int, int> > conseczero;

int main() {
	fastio;
	cin >> n >> k;
	cin >> s;
	int one = 0;
	int now = 0;
	int zero = 0;
	int i = 0;
	int j = 0;
	while (i < n) {
		if (s[i] - '0' == 0) {
			while (i < n && s[i] - '0' == 0)
				i++;
			now++;
		} else {
			while (i < n && s[i] - '0' == 1)
				i++;
		}
		while (now > k && j < i) {
			if (s[j] - '0' == 0) {
				now--;
				while (s[j] - '0' == 0) {
					j++;
				}
			} else {
				while (s[j] - '0' == 1)
					j++;
			}
		}
		// cout << i << " " <<  j << endl;
		if (now <= k) 
			one = max(one, i - j);
	}
	// cout << endl;
	// now = i = j = 0;
	// while (i < n) {
	// 	if (s[i] - '0' == 1) {
	// 		while (i < n && s[i] - '0' == 1)
	// 			i++;
	// 		now++;
	// 	} else {
	// 		while (i < n && s[i] - '0' == 0)
	// 			i++;
	// 	}
	// 	while (now > k && j < i) {
	// 		if (s[j] - '0' == 1) {
	// 			now--;
	// 			while (s[j] - '0' == 1) {
	// 				j++;
	// 			}
	// 		} else {
	// 			while (s[j] - '0' == 0)
	// 				j++;
	// 		}
	// 	}
	// 	cout << i << " " << j << endl;
	// 	if (now <= k) 
	// 		zero = max(zero, i - j);
	// }
	// cout << max(zero, one) << endl;
	cout << one << endl;
	return 0;
}
		

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

static const ll MAX = 100001;

int n;
int h[MAX];
int arr[MAX];

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    cin >> n;
    fill(arr, arr+MAX, 0);
    int res = 0;
    rep(i, n){
        cin >> h[i];
        if(i>0){
            if(h[i]<=h[i-1]){
                arr[i] = arr[i-1]+1;
                res = max(arr[i], res);
            }
        }
    }
    
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BProductMax {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int res = a * c;
        res = max(res, a * d);
        res = max(res, b * c);
        res = max(res, b * d);
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BProductMax solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3564
from collections import deque


def bellman_ford(start: int, goal: int, graph: list) -> list:
    '''bellman-ford法: 始点startから終点goalへの最小コストを求める
    重み付きグラフgraphは隣接リストで与えられる
    辺のコストは負でも良い
    負閉路検出: 始点startから終点goal上のパスに負閉路があるときは[-1]を返す
    計算量: O(|E||V|)
    '''
    INF = float("inf")
    n = len(graph)

    # スタートからゴールに到着可能かどうか判定する
    is_reachable = [False] * n
    is_reachable[start] = True
    q = deque([start])
    while q:
        pos = q.popleft()
        for next_pos, _ in graph[pos]:
            if is_reachable[next_pos]:
                continue
            is_reachable[next_pos] = True
            q.append(next_pos)

    # 逆辺で構築したグラフでゴールからスタートに到着可能かどうか判定する
    reverse_graph = [[] for i in range(n)]
    for pos, edge in enumerate(graph):
        for next_pos, cost in edge:
            reverse_graph[next_pos].append((pos, cost))

    is_rev_reachable = [False] * n
    is_rev_reachable[goal] = True
    q = deque([goal])
    while q:
        pos = q.popleft()
        for next_pos, _ in reverse_graph[pos]:
            if is_rev_reachable[next_pos]:
                continue
            is_rev_reachable[next_pos] = True
            q.append(next_pos)            

    need = [False] * n
    for i in range(n):
        need[i] = is_reachable[i] and is_rev_reachable[i]

    distance = [INF] * n
    distance[start] = 0
    for _ in range(n):
        is_updated = False
        for pos, edge in enumerate(graph):
            for next_pos, cost in edge:
                if not need[pos]:
                    continue
                if distance[pos] != INF and distance[pos] + cost < distance[next_pos]:
                    distance[next_pos] = distance[pos] + cost
                    is_updated = True
        if not is_updated:
            return distance[goal]
    # 負閉路が存在する
    return -INF


n, m, p = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

graph = [[] for i in range(n)]
for i in range(m):
    a, b, c = info[i]
    graph[a - 1].append((b - 1, -(c - p)))
ans = bellman_ford(0, n-1, graph)
if ans == -float("inf"):
    print(-1)
else:
    print(max(-ans, 0))


Measured memory_bytes: 54488