akhauriyash/Code-Regression huggingface dataset:
#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() {
    int n;
    cin >> n;
    vector<int> A(n), B(n), C(n);
    rep(i, n) cin >> A[i];
    rep(i, n) cin >> B[i];
    rep(i, n-1) cin >> C[i];
    rep(i, n) A[i]--;
    int ans = 0;
    rep(i, n) {
        ans += B[A[i]];
        if (i>=1 && A[i]==A[i-1]+1) {
            ans += C[A[i-1]];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		sc.close();

		int x = 0,xMax = 0;
		for(int i=0;i<s.length();i++){
//			char c = s.charAt(i);
//			switch(c){
//			case 'I':{
//				x++;
//				break;
//			}
//			case 'D':{
//				x--;
//				break;
//			}
//			}
			if(s.charAt(i) == 'I') x++;
			else x--;
			xMax = Math.max(xMax, x);
		}
		System.out.println(xMax);

	}

}

Measured memory_bytes: 9680
#include <iostream>
using namespace std;
using ll = long long;

int main(){
        int n,i,cnt=0,ans=0;
        ll h,h_pre=0;
        cin >> n;
        for(i=0;i<n;++i){
                cin >> h;
                if(h<=h_pre) ++cnt;
                else{
                        ans = max(ans,cnt);
                        cnt = 0;
                }
                h_pre = h;
        }
        ans = max(ans, cnt);
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct Edge{
  int u, v, w;
  Edge(){}
  Edge(int _u, int _v, int _w):u{_u}, v{_v}, w{_w}{}
};

vector<Edge> adj;
vector<Edge> solve(int n, int e, int& l, int& r){
//  cout << n << endl;
  vector<Edge> res;
  if(n == 1){
    l = e - 1, r = e;
    res.push_back(Edge(l, e, 0));
    return res;
  }else if(n == 2){
    l = e - 1, r = e;
    res.push_back(Edge(l, e, 0));
    res.push_back(Edge(l, e, 1));
    return res;
  }




  if(n & 1){
    res = solve(n - 1, e, l, r);
    res.push_back(Edge(l, r, n - 1));
  }else{
    int nl, nr;
    res = solve(n / 2, e, l, r);
    l--;
    res.push_back(Edge(l, l + 1, 0));
    res.push_back(Edge(l, l + 1, n / 2));
  }
  return res;
}

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int l;
  cin >> l;
  int nl, nr;
  vector<Edge> res = solve(l, 20, nl, nr);
  cout << nr - nl + 1 << ' ' << res.size() << endl;
  for(auto el : res){
    cout << el.u - nl + 1 << ' ' << el.v - nl + 1 << ' ' << el.w << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>

using namespace std;

#define mp make_pair
#define int long long

vector<int> g;
vector<bool> u;

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin >> n;
	g.resize(n);
	u.assign(n, 0);
	for (int i = 0; i < n; i++)
		cin >> g[i], --g[i];

	int i = 0;
	int ans = 0;
	while (true)
	{
		if (i == 1)
		{
			cout << ans;
			return 0;
		}
		if (u[i])
		{
			cout << -1;
			return 0;
		}
		++ans;
		u[i] = 1;
		i = g[i];
	}
}

Measured memory_bytes: 1024
//他の人の提出は大体において天才的ということですか
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline ll getll() {
	ll A = 0;
	if (ci - cn + 24 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	ll N = getint(), K = getll();
	int A[200000], F[200000];
	rep(i, N) A[i] = getint();
	rep(i, N) F[i] = getint();
	pakuri_sort(N, A);
	pakuri_sort(N, F);

	ll L = -1, R = 1e12;
	while (L + 1 < R) {
		ll M = (L + R) / 2;

		ll kazu = 0;
		rep(i, N) {
			kazu += max(0ll, A[i] - M / F[N - i - 1]);
		}
		if (kazu > K) L = M;
		else R = M;
	}

	printf("%lld", R);


	Would you please return 0;
}

Measured memory_bytes: 2688
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int x,i,n,m,a,b,c;
    while(~scanf("%d %d",&n,&m))
    {
        x=0;
        x=n+m/2;
        printf("%d\n",x);
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
long long N,K,ans=-1000000000000LL;

vector<long long>loop;
bool visited[5000];

void dfs(int state,long long &loop_score,int *P,int *C){
    if(visited[state])return;
    visited[state]=true;
    loop.push_back(C[state]);
    loop_score+=C[state];
    dfs(P[state],loop_score,P,C);
}

int main(){
    cin>>N>>K;
    int P[N],C[N];
    for(auto &i:P){cin>>i;i--;}
    for(auto &i:C)cin>>i;

    for(auto i:P){
        long long loop_score=0LL;
        if(visited[i])continue;
        dfs(i,loop_score,P,C);

        long long score=0LL,score2=-1000000000000LL,len;
        if(loop_score>0LL){
            score+=loop_score*(K/loop.size());
            len=K%loop.size();
            if(len==0LL){
                len=loop.size();
                score-=loop_score;
            }
        }
        else len=min((long long)(loop.size()),K);

        for(int start=0;start<loop.size();start++){
            long long tmp_score=0LL;
            for(int cnt=0,idx=start;cnt<len;cnt++,idx++,idx%=loop.size()){
                tmp_score+=loop[idx];
                score2=max(score2,tmp_score);
            }
        }
        ans=max(ans,score+score2);
        loop.clear();
    }
    cout<<ans<<endl;
    return 0;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in();
  vector<int> t(n);
  cin >> t;

  sort(t);

  vector<int> div;
  int m = t.back();
  for (int i = 1; i * i <= m; ++i) {
    if (m % i == 0) {
      div.pb(m / i);
      if (i * i != m) {
        div.pb(i);
      }
    }
  }

  sort(div);
  // cerr << div << endl;
  int ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    ans += *lower_bound(all(div), t[i]) - t[i];
  }

  cout << ans << endl;
}



Measured memory_bytes: 3384
H, W = map(int, input().split())
S = [input() for _ in range(H)]

ans = [[0 for _ in range(W)] for _ in range(H)]


for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ans[i][j] = "#"
        else:
            if H == 1:
                li = [i]
            elif 0 < i and i < H-1:
                li = [i-1, i, i+1]
            elif i == 0:
                li = [i, i+1]
            else:
                li = [i-1, i]
            if W == 1:
                lj = [j]
            elif 0 < j and j < W-1:
                lj = [j-1, j, j+1]
            elif j == 0:
                lj = [j, j+1]
            else:
                lj = [j-1, j]
            ans[i][j] = str(sum([S[lii][ljj]=="#" for lii in li for ljj in lj]))

for i in range(H):
    s = "".join(ans[i])
    print(s)


Measured memory_bytes: 3188
import math as m
N=int(input())
ans=[0]*N
if N>5:
    for x in range(1,int(m.sqrt(N-5))+1):
        for y in range(1,x+1):
            if x**2+y**2+x*y+x+y+1>N:
                break
            for z in range(1,y+1):
                if x**2+y**2+x*y+x*z+y*z+z**2>N:
                    break
                if len(list(set([x,y,z])))==3:
                    ans[x**2+y**2+x*y+x*z+y*z+z**2-1]+=6
                elif len(list(set([x,y,z])))==2:
                    ans[x**2+y**2+x*y+x*z+y*z+z**2-1]+=3
                elif len(list(set([x,y,z])))==1:
                    ans[x**2+y**2+x*y+x*z+y*z+z**2-1]+=1

for a in ans:
    print(a)


Measured memory_bytes: 9192
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean[] f = new boolean[1000000];
        Arrays.fill(f, true);
        for (int i = 2; i < 1000000; i++)
            if (f[i])
                for (int j = i * 2; j < 1000000; j += i)
                    f[j] = false;
        while (sc.hasNext()){
            int n = sc.nextInt();
            int c = 0;
            for (int i = 2; i <= n; i++)
                c += f[i] ? 1 : 0;
            System.out.println(c);
        }
    }
}



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

int main() {
  int N, D, X;
  cin >> N >> D >> X;

  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    X += (D + A - 1) / A;
  }

  cout << X << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int a,b;
    vector<pair<int,int>> c;

    pair<int,int> buf;
    while(cin >> a >> b){
        if(a == 0 && b == 0){
            break;
        }

        buf.first = a;
        buf.second = b;

        c.push_back(buf);
    }

    for(auto k : c){
        a = k.first;
        b = k.second;

        for (int c = 0; c < a; ++c) {
            for (int d = 0; d < b; ++d) {
                if(c == 0 | c == a - 1 | d == 0 | d == b - 1){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3004
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	odd := 0
	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		odd += a % 2
	}

	if odd%2 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 5504
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main(void)
{
	long a,b;
	cin >> a >> b;
	if(a<0 && b>=0)
		cout << "Zero" << endl;
	else if(a==0 && b>0)
		cout << "Zero" << endl;
	else if(a > 0 && b> 0)
		cout << "Positive" << endl;
	else if(a<0 && b<0){
		a*=-1; b*=-1;
		if( (abs(a-b) + 1) % 2 == 0){
			cout << "Positive" << endl;
		}else{
			cout << "Negative" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#ABC 088 B - Card Game for Two
N = int(input())
card_list = [int(i) for i in input().split()]
alice = 0
bob = 0
for i in range(N):
    if i%2==0:
        m = max(card_list)
        alice += m
        card_list.remove(m)
    if i%2==1:
        m = max(card_list)
        bob += m
        card_list.remove(m)
print(alice-bob)

Measured memory_bytes: 3060
using System;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] s = Console.ReadLine().Split();
			int N = int.Parse(s[0]);
			int T = int.Parse(s[1]);
			int ans = int.MaxValue;
			for (int i = 0; i < N; i++) {
				string[] vs = Console.ReadLine().Split();
				int c = int.Parse(vs[0]);
				int t = int.Parse(vs[1]);
				if (t <= T && c < ans) {
					ans = c;
				}
			}
			if (ans < int.MaxValue) {
				Console.WriteLine(ans);
			} else {
				Console.WriteLine("TLE");
			}
		}
	}
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>

#define M 1046257
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

// 文字列から数値へ変換して key を生成する
long long getKey(char str[]) {
  long long sum =0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) %M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str); // より高速なscanfを使用
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	int P, Q, R;
	cin >> P >> Q >> R;
	int PQ = P + Q;
	int QR = Q + R;
	int PR = P + R;
	cout << min(PQ, min(QR, PR)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int h,n;
    cin>>h>>n;
    ll sum=0;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        sum+=a;
    }
    if(h-sum<=0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC112_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var NT = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NT[0];
            var T = NT[1];
            var minc = 1001;

            for (int i = 0; i < N; i++)
            {
                var ct = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var c = ct[0];
                var t = ct[1];
                if (t <= T && c < minc)
                {
                    minc = c;
                }
            }

            Console.WriteLine(minc == 1001 ? "TLE" : minc.ToString());
        }
    }
}


Measured memory_bytes: 13268
import java.util.*;
// import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
  }

  int n;
  int m;
  int p[];
  String s[];
  int ac[];
  int wa[];

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      n = sc.nextInt();
      m = sc.nextInt();
      p = new int[m];
      s = new String[m];

      for (int i = 0; i < m; i++) {
        p[i] = sc.nextInt() - 1;
        s[i] = sc.next();
      }
      ac = new int[n];
      wa = new int[n];
    } finally {
      sc.close();
    }
  }

  void solve() {
    update();
    int a = good();
    int b = bad();
    System.out.printf("%d %d\n", a, b);
  }

  void update() {
    for (int i = 0; i < m; i++) {
      if (s[i].equals("WA") && ac[p[i]] == 0) wa[p[i]]++;
      if (s[i].equals("AC")) ac[p[i]]++;
    }
  }

  int good() {
    int ans = 0;
    for (int i = 0; i < n; i++) if (ac[i] > 0) ans++;
    return ans;
  }

  int bad() {
    int ans = 0;
    for (int i = 0; i < n; i++) if (ac[i] > 0) ans += wa[i];
    return ans;
  }

}


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

const n,k=parseMap(split(readline()))
const p=parseMap(split(readline()))
const c=parseMap(split(readline()))
function main()
    ans=maximum(c)
    for i in 1:n
        now::Int=i
        score::Vector{Int}=[]
        while true
            now=p[now]
            push!(score,c[now])
            if now==i
                break
            end
        end
        res::Int,len::Int=0,length(score)
        for j in 1:min(k,len)
            res+=score[j]
            ans=max(ans,res)
        end
        if k>len
            res,tmp::Int=(k÷len-1)*sum(score),k-(k÷len-1)*len
            score,len=vcat(score,score),len*2
            ans=max(ans,res)
            for j in 1:min(tmp,len)
                res+=score[j]
                ans=max(ans,res)
            end
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 218516
#include <stdio.h>

int main(){
  long long int x;  scanf("%lld", &x);

  long long int h = 100;

  int i = 1;
  while(1){
    h *= 1.01;
    if(h >= x){
      printf("%d\n", i);
      break;
    }
    i++;
  }
  return 0;
}


Measured memory_bytes: 1736
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX/10000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
signed main() {
	double n, k;
	cin >> n >> k;
	double ans = 0;
	REP(i, n) {
		int cnt = 0, num = i;
		while (num < k) {
			num *= 2;
			cnt++;
		}
		ans += 1 / pow(2, cnt);
	}
	printf("%.12Lf\n", ans / n);
	return 0;
}

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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int main(){
    int n,wl;
    cin>>n>>wl;
    vector<int> w(n), v(n);
    rep(i,n) cin>>w[i]>>v[i];
    vector<ll> dp(wl+1);
    dp[0]=0;
    rep(i,n){
        vector<ll> dpt(wl+1);
        for(int j=1;j<=wl;j++){
            if(j-w[i]>=0) dpt[j]=max(dp[j],dp[j-w[i]]+v[i]);
            else dpt[j]=dp[j];
        }
        dp=dpt;
    }

    cout<<dp[wl]<<endl;
    return 0;
}

Measured memory_bytes: 1804
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
 
n, k = map(int, readline().split())
a = np.int32(read().split())
 
a -= 1

b = [0]
t = 0

for i in range(n):
    t = a[t]
    b.append(t)

d = b.index(b[-1]) - 1
r = len(b) - d - 2

if k > n:
    k = (k-d) % r + d

print(b[k]+1)


Measured memory_bytes: 39356
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main()
{
	int n,m;long long sum=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int st=m-i%m,cnt=(n-st)/m+1;
		if((st%m*2)%m==0)sum+=(long long)cnt*cnt;
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

template <class T>
T gcd(T a, T b) {
    if (a < b) {
        T w = a;
        a = b;
        b = w;
    }

    while (b != 0) {
        T w = a % b;
        a = b;
        b = w;
    }

    return a;
}

bool is_pairwise(vector<int>& a) {
    vector<bool> v(*max_element(a.begin(), a.end()) + 1, false);

    for (int i = 0; i < static_cast<int>(a.size()); i++) {
        int b = a[i];
        for (int j = 2; j * j <= b; j++) {
            if (b % j == 0 && v[j]) {
                return false;
            } else if (b % j == 0) {
                v[j] = true;
                while (b % j == 0) {
                    b /= j;
                }
            }
        }

        if (b > 1 && v[b]) {
            return false;
        } else if (b > 1) {
            v[b] = true;
        }
    }

    return true;
}

bool is_setwise(vector<int>& a) {
    int b = a[0];
    for (int i = 1; i < static_cast<int>(a.size()) && b > 1; i++) {
        b = gcd(b, a[i]);
    }

    return b == 1;
}

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

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    if (is_pairwise(a)) {
        cout << "pairwise coprime" << endl;
    } else if (is_setwise(a)) {
        cout << "setwise coprime" << endl;
    } else {
        cout << "not coprime" << endl;
    }
}


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

int main(void){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		string a,b,ans;
		cin >> a;
		cin >> b;
		reverse(a.begin(),a.end());
		reverse(b.begin(),b.end());
		int c=0;
		for(int j=0;j<max(a.size(),b.size());j++){
			string d;
			int e;
			e=c;
			if(a.size()>j)e+=a[j]-'0';
			if(b.size()>j)e+=b[j]-'0';
			c=0;
			if(e>=10)c=1,e-=10;
			d=e+'0';
			ans+=d;
		}
		if(c==1)ans+=c+'0';
		reverse(ans.begin(),ans.end());
		if(ans.size()<=80)cout << ans << endl;
		else cout << "overflow" << endl;
	}
    return 0;
}

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

#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    int ans = INT_MAX;
    for (int i = 0; i <= (int)(a.size()) - (int)(b.size()); ++i) {
        int d = 0;
        for (int j = 0; j < b.size(); ++j) {
            if (a[j + i] != b[j]) ++d;
        }
        ans = min(ans, d);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;

typedef long long ll;

int main() {
	ll q, ans = 0; cin >> q;
	priority_queue<ll> s;
	priority_queue<ll, vector<ll>, greater<>> l;
	for (ll _ = 0; _ < q; ++_) {
		ll t; cin >> t;
		if (t == 1) {
			ll a, b; cin >> a >> b;
			ans += b;
			s.push(a); l.push(a);
			ll x = s.top(); s.pop();
			ll y = l.top(); l.pop();
			if (x > y) {
				ans += x - y;
				swap(x, y);
			}
			s.push(x);
			l.push(y);
		}
		else {
			cout << s.top() << " " << ans << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 4588
#include <iostream>

using namespace std;

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

    for (int i = 0; i < k; i++) {
        if (i % 2 == 0) {
            b += a / 2;
            a /= 2;
        } else {
            a += b / 2;
            b /= 2;
        }
    }

    cout << a << " " << b << endl;
}


Measured memory_bytes: 3560
class Main{
  public static void main(String []args){
    Scanner x=new Scanner(System.in);
    String table="abcdefghijklmnopqrstuvwxyz";
    loop:while(x.hasNext()){
      String s=x.nextLine();
      int c=0;
      for(;c<table.length();c++){
        char []p=s.toCharArray();
        int i=0;
        for(;i<s.length();i++)
          if(table.indexOf(p[i])!=-1)p[i]=table.charAt( (table.indexOf(p[i])+c)%table.length() );
        String r=new String(p);
        if(r.indexOf("the")!=-1||r.indexOf("this")!=-1||r.indexOf("that")!=-1){
          System.out.println(r);
          continue loop;
        }
      }
    }
  }
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
int main() {
	int n;
	string ans;
	cin >> n;
	if (n % 10 == 9 || (n >= 90 && n <= 99)) { ans = "Yes"; }
	else { ans = "No"; }
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	final int INF = Integer.MAX_VALUE/2;
	int[][] cost = new int[10][10];
	int[][] d = new int[10][10];
	
	void warshall_floyd() {
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				d[i][j] = cost[i][j];
		for (int i = 0; i < 10; i++)
			d[i][i] = 0;
		
		for (int k = 0; k < 10; k++)
			for (int i = 0; i < 10; i++)
				for (int j = 0; j < 10; j++)
					d[i][j] = Math.min(d[i][j], d[i][k]+d[k][j]);
	}
	
	void run() {
		while (true) {
			int n = sc.nextInt();
			if (n == 0) break;
			for (int i = 0; i < 10; i++)
				for (int j = 0; j < 10; j++)
					cost[i][j] = INF;
			
			for (int i = 0; i < n; i++) {
				int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
				cost[a][b] = c;
				cost[b][a] = c;
			}
			warshall_floyd();
			int res = INF, num = 0;
			for (int i = 0; i < 10; i++) {
				if (d[i][0] == INF) break;
				int sum = 0;
				for (int j = 0; j < 10; j++) {
					if (d[i][j] == INF) break;
					sum += d[i][j];
				}
				if (res > sum) {
					res = sum;
					num = i;
				}
			}
			out.printf("%d %d\n", num, res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 19924
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 998244353;
constexpr int inf = 3e18;

int N,X[1005],Y[1005];
void solve(int x,int y){
	for(int i=31;i>=0;i--){
		if(x>0&&y>0){
			cout<<'R';x-=1ll<<i;y-=1ll<<i;
		}else if(x>0){
			cout<<'U';x-=1ll<<i;y+=1ll<<i;
		}else if(y>0){
			cout<<'D';x+=1ll<<i;y-=1ll<<i;
		}else {
			cout<<'L';x+=1ll<<i;y+=1ll<<i;
		}
	}
}
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N;
	rep(i,N){
		cin>>X[i]>>Y[i];
		if(i&&(X[i]+Y[i]+(1ll<<31))%2!=(X[i-1]+Y[i-1]+(1ll<<31))%2){
			cout<<-1<<endl;return 0;
		}
	}
	cout<<32+((X[0]+Y[0]+(1ll<<31))%2==0)<<endl;
	rep(i,32)cout<<(1ll<<(31ll-i))<<" ";
	if((X[0]+Y[0]+(1ll<<31))%2==0)cout<<1;
	cout<<endl;
	rep(i,N){
		if((X[0]+Y[0]+(1ll<<31))&1){
			solve(X[i]+Y[i],X[i]-Y[i]);
			cout<<endl;
		}else {
			solve(X[i]+Y[i]+1,X[i]-Y[i]+1);
			cout<<'L'<<endl;
		}
	}
}


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

int main(){
	int h,w;
	scanf("%d%d",&h,&w);
	char grid[h+5][w+5];
	for(int i=0;i<h;i++)scanf("%s",grid[i]);
	int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
	queue<pair<int,int> > q;
	int ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(grid[i][j]=='#')continue;
			int dist[h][w];
			for(int k=0;k<h;k++){
				for(int l=0;l<w;l++){
					dist[k][l]=1000000010;
				}
			}
			dist[i][j]=0;
			q.push(make_pair(i,j));
			while(!q.empty()){
				int x=q.front().first,y=q.front().second;
				//printf("%d %d\n",x,y);
				q.pop();
				for(int k=0;k<4;k++){
					int nx=x+dx[k],ny=y+dy[k];
					if(0<=nx&&nx<h&&0<=ny&&ny<w&&grid[nx][ny]=='.'&&dist[nx][ny]>dist[x][y]+1){
						dist[nx][ny]=dist[x][y]+1;
						q.push(make_pair(nx,ny));
					}
				}
			}
			for(int k=0;k<h;k++){
				for(int l=0;l<w;l++){
					if(dist[k][l]<1000000010)ans=max(ans,dist[k][l]);
				}
			}
			//printf("%d\n",ans);
		}
	}
	printf("%d",ans);
}


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in();
  int valleys[n+1];
  int total_rain = 0;
  for(int i = 1; i < n+1; ++i) {
    cin >> valleys[i];
    total_rain += valleys[i];
  }
  int first_mt = total_rain;
  for(int i = 2; i < n+1; i+=2) {
    first_mt -= 2 * valleys[i];
  }
  cout << first_mt << " ";
  int current = first_mt;
  for(int i = 1; i < n; ++i) {
    int tmp = 2 * valleys[i] - current;
    if(i == n-1) {
      COUTB(tmp);
    } else {
      COUTS(tmp);
      current = tmp;
    }
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 2048
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int N  =sc.nextInt();
        String ans;
        
        if(N<=999){
            ans = "ABC";
        }else{
            ans = "ABD";
        }
        
        System.out.println(ans);
    }
}


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

int main()
{
    vector<int> abc(3);
    rep(i,3) cin >> abc[i];
    sort(abc.begin(),abc.end());
    if(abc[0] == abc[1] && abc[0] != abc[2])
        cout << "Yes" << endl;
    else if(abc[1] == abc[2] && abc[0] != abc[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
class Node:
    parent = ""
    sibling = ""
    depth = ""
    height = ""

    def __init__(self, left, right):
        self.left = left
        self.right = right

        if self.right == -1 and self.left == -1:
            self.degree = 0
            self.type = 'leaf'
        elif self.right == -1 or self.left == -1:
            self.degree = 1
            self.type = 'internal node'
        else:
            self.degree = 2
            self.type = 'internal node'


def add_parent_node_and_depth(nodes, parent_node_no, node_no, depth):
    nodes[node_no].parent = parent_node_no
    nodes[node_no].depth = depth

    left_node_no = nodes[node_no].left
    right_node_no = nodes[node_no].right

    left_height, right_height = 0, 0
    if left_node_no != -1:
        left_height = add_parent_node_and_depth(nodes, node_no, left_node_no, depth+1)
        nodes[left_node_no].sibling = right_node_no
    if right_node_no != -1:
        right_height = add_parent_node_and_depth(nodes, node_no, right_node_no, depth+1)
        nodes[right_node_no].sibling = left_node_no

    if left_node_no == -1 and right_node_no == -1:
        nodes[node_no].height = 0
    else:
        nodes[node_no].height = max(left_height, right_height) + 1
    return nodes[node_no].height


def main():
    n = int(input())
    nodes = {}
    for i in range(n):
        node_no, left, right = [int(x) for x in input().split()]
        nodes[node_no] = Node(left, right)

    lefts = [nodes[x].left for x in nodes]
    rights = [nodes[x].right for x in nodes]
    root_no = list(set(nodes.keys()) - set(lefts + rights))[0]

    nodes[root_no].type = 'root'
    nodes[root_no].sibling = -1
    add_parent_node_and_depth(nodes, -1, root_no, 0)

    for i in range(n):
        node = nodes[i]
        print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(
            i, node.parent, node.sibling, node.degree, node.depth, node.height, node.type
        ))

    return

main()


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int INF = 1000000007;

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

  string S, T;
  cin >> S >> T;
  int N = S.size();
  int A[26] = {}, B[26] = {};
  rep(i, N){
    A[S[i] - 'a']++;
    B[T[i] - 'a']++;
    if(A[S[i] - 'a'] != B[T[i] - 'a']){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 916
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18 + 100;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	

	int n,x;

	cin >> n >> x;
	vector<int> data(n);

	rep(i, 0, n) {
		
		int a;
		cin >>a;
		data[i] = abs(x - a);

	}
	int ans = data[0];
	rep(i,1, n) {

		ans = gcd(ans, data[i]);


	}

	cout << ans << endl;



	
	
}
	

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

using namespace std;

vector<int> v[100010];
queue<int> q;

int maxim,x,y,i,nod,n,m,vecin,grad[100010],dp[100010];

int main()
{
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>x>>y;
        v[y].push_back(x);
        grad[x]++;
    }

    for(i=1;i<=n;i++)
    {
        if(grad[i]==0)
        {
            q.push(i);
            dp[i]=0;
        }
    }

    while(!q.empty())
    {
        nod=q.front();

        for(i=0;i<v[nod].size();i++)
        {
            vecin=v[nod][i];
            grad[vecin]--;


            dp[vecin]=max(dp[vecin],dp[nod]+1);
            if(grad[vecin]==0)q.push(vecin);
        }
        q.pop();
    }

    for(i=1;i<=n;i++)
    {
        if(dp[i]>maxim)maxim=dp[i];
    }

    cout<<maxim;
    return 0;
}


Measured memory_bytes: 6528
# not found suitable BinarySearch module

def binary_search(a, x, lo=0, hi=None):
    """Return True if list a in item x, assuming a is sorted.
    """
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x:
            lo = mid+1
        elif a[mid] > x:
            hi = mid
        else:
            return True
    return False

same_num_count = 0
firstlist_num = int(input())
sorted_firstlist = sorted(set(input().split()))
secondlist_num = int(input())
secondlist = set(input().split())

for n in secondlist:
    if binary_search(sorted_firstlist, n):
        same_num_count += 1
print(same_num_count)


Measured memory_bytes: 14832
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=5e5+5,M=5e3+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
ll a[N],s1[N],s2[N],all,n,m;
int main(){

	read(n,m);
	read(a[1]);
	rep(i,2,n){
		read(a[i]);
		if(a[i]>a[i-1]){
			all+=a[i]-a[i-1];
			s1[a[i-1]+1]+=a[i-1]+1;
			s1[a[i]+1]-=a[i-1]+1;
			s2[a[i-1]+1]++;
			s2[a[i]+1]--;
		}else{
			all+=m+a[i]-a[i-1];
			s1[a[i-1]+1]+=a[i-1]+1;
			s2[a[i-1]+1]++;
			s1[1]+=a[i-1]+1-m;
			s2[1]++;
			s1[a[i]+1]-=a[i-1]+1-m;
			s2[a[i]+1]--;
		}
	}
	rep(i,1,m)s1[i]+=s1[i-1],s2[i]+=s2[i-1];
	ll ans=0;rep(i,1,m)gmax(ans,1ll*i*s2[i]-s1[i]);
	cout<<all-ans;
}

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

 int main() {
     string words[4] = {"dream", "dreamer", "erase", "eraser"};;
     string S;
     cin >> S;

     reverse(S.begin(), S.end());
     for (int i=0; i<4; i++) reverse(words[i].begin(), words[i].end());

     bool div1 = true;
     for (int i=0; i<S.size();) {
         bool div2 = false;
         for (int j=0; j<4; j++) {
             string w = words[j];
             if (S.substr(i, w.size()) == w) {  // Sのi番目からi+w[j]まで抜き出して比較
                 i += w.size(); // prefixなのでここで更新可能
                 div2 = true;   // 4単語いずれかで割り切れるならtrueになる
             }
         }
         if (!div2) {
             div1 = false;  //どの単語でも割れなかった時点でfalse
             break;
         } 
     } 
     if (div1) cout << "YES" << endl;
     else cout << "NO" << endl; 
 }

Measured memory_bytes: 512
fun main(args: Array<String>)
{
    val (n, a, b) = readNInts()

    println(if (n*a < b) n*a else b)
}


// Read an integer
// Usage: val a = readInt()
private fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
private fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
private fun readString() = readLine()!!


Measured memory_bytes: 37944
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>adj[100100];
ll vis1[100100];
ll vis2[100100];
ll dist1[100100];
ll dist2[100100];
int main()
{
    ll n,u,v;
    cin>>n>>u>>v;
    ll a,b;
    for(ll i=1;i<n;i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    queue<ll>q1;
    queue<ll>q2;
    q1.push(u);
    q2.push(v);
    dist1[u]=0;
    dist2[v]=0;
    vis1[u]=1;
    vis2[v]=1;
    while(!q1.empty())
    {
        ll x=q1.front();
        q1.pop();
        for(ll i:adj[x])
        {
            if(vis1[i]==0)
            {
                dist1[i]=dist1[x]+1;
                vis1[i]=1;
                q1.push(i);
            }
        }
    }
    while(!q2.empty())
    {
        ll x=q2.front();
        q2.pop();
        for(ll i:adj[x])
        {
            if(vis2[i]==0)
            {
                dist2[i]=dist2[x]+1;
                vis2[i]=1;
                q2.push(i);
            }
        }
    }
    ll maxi=0;
    for(ll i=1;i<=n;i++)
    {
        if(dist1[i]<dist2[i])
            maxi=max(maxi,dist2[i]-1);
    }
    cout<<maxi;
}

Measured memory_bytes: 9600
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void){
  int n;scanf("%d",&n);
  vector<ll> a(n);for(int i = 0;i < n;i++)scanf("%lld",&a[i]);
  ll ans = INT_MAX;
  for (int i = 0; i < n; ++i)
  {
    ll c = 0;
    while(a[i] %2 == 0){
      a[i] /= 2;
      c++;
    }
    ans = min(ans,c);
  }
  printf("%lld\n",ans);
}


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

ll mpow(ll x, ll n){ //x^n(mod mo) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mo;
        x = x*x % mo;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll n,ll k){
    ll g,l;    
    /*if(k > n){
        k = k - n;
    }*/
    g=n;
    l=k;
    ll a = 1;
    ll b = 1;
    rep(i,l){
        a *= g;
        a %= mo;
        b *= (i+1);
        b %= mo;
        g--;
    }
    return (a*mpow(b,mo-2)) % mo;

}


int main(){
    ll N,K;
    cin >> N >> K;

    for(ll i = 1;i<=K;i++){
        cout << (comb(N-K+1,i)*comb(K-1,i-1))%mo << endl;;
    }
}

Measured memory_bytes: 256
/**
* Author: Luis Alberto Herrera Gomez
* Tags: 
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ii;

int main()
{
    int A, P;

    cin >> A >> P;

    cout << (A * 3 + P) / 2 << "\n";

    return 0;
}


Measured memory_bytes: 256
n=int(input())
de=[[0,0,0]]
for i in range(n):
  de.append(list(map(int,input().split())))
flag=0
for i in range(n):
  interval=de[i+1][0]-de[i][0]
  distance=abs(de[i+1][1]-de[i][1])+abs(de[i+1][2]-de[i][2])
  if interval<distance:
    flag=1
    break
  elif (interval-distance)%2==0:
    continue
  else:
    flag=1
    break
if flag==1:
  print("No")
else:
  print("Yes")
    

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

int main()
{
  int r, g, b;
  cin >> r >> g >> b;
  
  int rgb = (r * 100) + (g * 10) + b;
  
  if(rgb % 4 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

import sys, math
sys.setrecursionlimit(300000)


def solve(H: int, W: int, N: int):
    ret = min(math.ceil(N / H), math.ceil(N / W))
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(H, W, N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t A, B;

    std::cin >> A >> B;

    std::cout << (A*B) << std::endl;

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s.size()%2)return puts("No"),0;
	for(int i=0;i<s.size();i+=2)if(s[i]!='h')return puts("No"),0;
	for(int i=1;i<s.size();i+=2)if(s[i]!='i')return puts("No"),0;
	puts("Yes");
}

Measured memory_bytes: 256
using System;
class rect{
    public static void Main(){
        String[] str = Console.ReadLine().Split(' ');
        int W = int.Parse(str[0]);
        int H = int.Parse(str[1]);
        int x = int.Parse(str[2]);
        int y = int.Parse(str[3]);
        int r = int.Parse(str[4]);
        if((x-r)>=0 && (y-r)>=0 && (x+r)<=W && (y+r)<=H){
            Console.WriteLine("Yes");
        }
        else{
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 17944
def dijkstra(matrix, s):
    INF = 200000
    n = len(matrix)
    state, d, p = [False] * n, [INF] * n, [-1] * n
    d[s] = 0
    while True:
        mincost = INF
        for i in range(n):
            if not state[i] and d[i] < mincost:
                mincost = d[i]
                u = i
        if mincost == INF:
            break
        state[u] = True
        for v in range(n):
            if not state[v] and matrix[u][v] != -1:
                if d[u] + matrix[u][v] < d[v]:
                    d[v] = d[u] + matrix[u][v]
                    p[v] = u
    return d


def main():
    n = int(input())
    m = [[-1] * n for _ in range(n)]
    for _ in range(n):
        u, k, *vc = map(int, input().split())
        for v, c in zip(vc[::2], vc[1::2]):
            m[u][v] = c
    dist = dijkstra(m, 0)
    for i, d in enumerate(dist):
        print(i, d)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5744