akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int i,sum=0,n;
   string s;
   cin>>s;
   n=s.length();

   for(i=0;i<n;i++)
   {
    sum=sum+(s[i]-48);
   }
    if(sum%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }


  return 0;
}


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

int N,Q;
int a[100001];
long long x;

int main(){
	scanf("%d%d",&N,&Q);
	for(int i = 0; i < N; i++){
		scanf("%d",&a[i]);
	}
	a[N] = 0;
	for(int i = 0; i < Q; i++){
		scanf("%lld",&x);

		int hd = 0;
		int tl = 0;
		long long sm = a[0];
		
		long long ans = 0;
		while(tl < N){
			if(sm <= x){
				ans += tl - hd + 1;
				tl++;
				sm += a[tl];
			}
			else if(hd < tl){
				sm -= a[hd];
				hd++;
			}
			else{ // hd == tl
				hd++;
				tl++;
				sm = a[hd];
			}
		}
		printf("%lld\n",ans);
	}

	return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

// #include <bits/stdc++.h>
// using namespace std;

const int mod = 1000000007;
// const int mod = 998244353;

struct mint {
  long long x;
  mint(long long x = 0) : x((x%mod+mod)%mod) {}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x -= a.x) < 0) x += mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint operator++() const { return mint(*this) += mint(1);}
  mint operator--() const { return mint(*this) -= mint(1);}
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

/*int main () {
  mint a= mod-1;
  cout << a.pow(2) << endl;
  cout << a.inv() << endl;
  mint b = 123;
  cout << b.inv() << endl;
  return 0;
}*/


mint dp[700][2005];
int main() {
  int n;cin >> n;

  mint a = mint(1);
  rep(i,2005) {
    if(i<3) continue;
    dp[1][i] =  a;
    a+=1;
  }

  orep(i,n/3) orep(j,n) {
    if(j<3*(i+1)) continue;
    dp[i+1][j] += dp[i+1][j-1]+dp[i][j-3];
  }


  mint ans = mint(0);
  orep(i,n/3) ans += dp[i][n]-dp[i][n-1];
  cout << ans << endl;
  return 0;
}


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

#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)

using ll = long long;
#define INF 1e9

int N, K;
string S;

int main(){ 
  cin >> N >> K;
  cin >> S;
  vector<int> retu;
  if(S[0] == '0'){
    retu.push_back(0);
  }
  int cnt = 1;
  REP(i, N){ 
    if(i == N-1){
      retu.push_back(cnt);
      if(S[i] == '0'){
        retu.push_back(0);
      }
      break;
    }
    if(S[i] == S[i+1]){
      cnt++;
    }
    else{
      retu.push_back(cnt);
      cnt = 1;
    }
  }

  if(K *2 >= retu.size()-1){
    cout << N << endl;
    return 0;
  }
  int sum = 0;
  REP(i, 2*K+1){
    sum += retu[i];
  }
  int ans = sum;
  for(int i = 2; i+2*K < retu.size(); i+=2){
    sum -= (retu[i-1] + retu[i-2]);
    sum += (retu[i+2*K] + retu[i+2*K-1]);
    ans = max(ans, sum);
  }
  cout << ans << endl;
  

  return 0;
}



Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a,b,ba,ans;
int main(){
  ll n;
  cin>>n;
  for(ll i=0;i<n;i++){
    string s;
    cin>>s;
    for(ll i=0;i<s.size()-1;i++){
      if(s[i]=='A'&&s[i+1]=='B'){
        ans++;
      }
    }
    if(s[0]=='B'){
      if(s[s.size()-1]=='A'){
        ba++;
      }
      else{
        b++;
      }
    }
    else if(s[s.size()-1]=='A'){
      a++;
    }
  }
  if(ba!=0){
    if(a!=0){
      a--;
      ba++;
    }
    if(b!=0){
      b--;
      ba++;
    }
  }
  cout << ans+min(a,b)+max((ba-1),ll(0));
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define PI 3.1415926535898

int main(){
	double x = 0.0;
	double y = 0.0;
	double angle = 90.0;
	int d, a;
	while(scanf("%d,%d", &d, &a)){
		if(d == 0 && a == 0){
			break;
		}
		x += (double)d*cos(angle*PI/180.0);
		y += (double)d*sin(angle*PI/180.0);
		angle -= (double)a;
	}
	cout << (int)x << endl;
	cout << (int)y << endl;
	return 0;
}

Measured memory_bytes: 0
let n = Int(readLine()!)!
let array = readLine()!.characters.split{$0 == " "}.map{ Int(String($0))! }

var ret = 0
var current = 0
var last = array[0]

for i in 0..<array.count {
  if i != 0 {
    if array[i] <= last {
      current += 1
    } else {
      ret = max(ret, current)
      current = 0
    }
  }
  last = array[i]
}

ret = max(ret, current)

print(ret)

Measured memory_bytes: 7252
N = int(input())

table = [[0] * 10 for _ in range(10)]

for i in range(1, N + 1):
    s = str(i)
    head, tail = int(s[0]), int(s[-1])
    table[head][tail] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += table[i][j] * table[j][i]

print(ans)

Measured memory_bytes: 3064
n,k,s = map(int,input().split())

ans = []

for i in range(k):
    ans.append(s)

for i in range(n-k):
    if s != 10**9:
        ans.append(10**9)
    else:
        ans.append(10**9-1)

ans1 = ""
for i in ans:
    ans1 += str(i)+ " "
print(ans1)

Measured memory_bytes: 7064
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	double r;
	cin>>r;
	cout<<r*2*3.1415926<<endl;
	return 0;
}

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



using namespace std;

int main(){

    int N;
    cin >> N;
    
    vector<double>  A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    double ans = 0.0;
    
    for (int i = 0; i < N; i++) {
        ans += 1/A[i];
    }
    
    cout << fixed;
    cout << setprecision(10) << 1/ans << endl;
    
    
    
    
    
}


Measured memory_bytes: 256
r,c = map(int,input().split())

A = [list(map(int,input().split())) for i in range(r)]
for i in range(r):
    for j in range(c):
        print(A[i][j],end=" ")
    print(sum(A[i]))
for i in range(c):
    ans = 0
    for j in range(r):
        ans += A[j][i]
    print(ans,end=" ")
print(sum(map(sum,A)))



Measured memory_bytes: 6260
#include <bits/stdc++.h>
using namespace std;
string s;
int mt[1 << 26];
int main() {
  fill(mt, mt + (1 << 26), 1E6);
  cin >> s;
  mt[0] = 0;
  const int n = s.size();
  vector<int> dp(n + 1);
  iota(dp.begin(), dp.end(), 0);
  int state = 0;
  for (int i = 1; i <= n; ++i) {
    // cout << "i: " << i  << endl;
    const int cc = s[i - 1] - 'a';
    state ^= (1 << cc);

    for (int k = 0; k < 26; ++k) {
      int ps = state ^ (1 << k);
      dp[i] = min(dp[i], 1 + mt[ps]);
    }
    // cout << dp[i] << endl;
    
    dp[i] = min(dp[i], 1 + mt[state]);
    mt[state] = min(dp[i], mt[state]);

    // cout << dp[i] << endl;
  }

  cout << dp[n] << endl;
}

Measured memory_bytes: 263556
h,w = map(int,input().split())
#mine = [[0 for i in range(w)] for i in range(h)]
mine = []
for i in range(h):
    mine.append(list(input().replace(".","0")))

for i in range(h):
    for j in range(w):
        if mine[i][j] == "#":
            for k in range(i-1,i+2):
                if k > (h-1) or k < 0:
                    continue
                for l in range(j-1,j+2):
                    if l > (w-1) or l < 0:
                        continue
                    elif mine[i][j] == mine[k][l]:
                        continue
                    mine[k][l] = int(mine[k][l])
                    mine[k][l] += 1
for i in mine:
    print("".join(map(str,i)))


Measured memory_bytes: 42864
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    set<int> s;
    rep(i, n){
        int a;
        cin >> a;
        s.insert(a);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
n, m = map(int, raw_input().split())
mat = [([0] * n) for i in range(n)]
for i in range(m):
  a, b = map(int, raw_input().split())
  mat[a-1][b-1] = 1
  mat[b-1][a-1] = 1
for i in range(n):
  mat[i][i] = 1

visit = [False] * n
color = [-1] * n

def f(i):
  r = [1, 0]
  next_list = [i]
  color[i] = 0
  while next_list:
    i = next_list.pop(0)
    visit[i] = True
    for j in range(n):
      if mat[i][j] == 0:
        if color[i] == color[j]:
          print(-1)
          sys.exit()
          break
        else:
          if color[j] == -1:
            color[j] = 1 - color[i]
            r[color[j]] += 1
            next_list.append(j)
  return r

def dou(k):
    return (k*(k-1))//2
ans = []
for i in range(n):
  if not visit[i]:
    ans.append(f(i))

r=sorted(ans, reverse=True)
for i in range(1, len(ans)):
    if r[0][0]>r[0][1]:
        r[0][0] += min(r[i][0],r[i][1])
        r[0][1] += max(r[i][0],r[i][1])
    else:
        r[0][0] += max(r[i][0],r[i][1])
        r[0][1] += min(r[i][0],r[i][1])
print(dou(r[0][0]) + dou(r[0][1]))


Measured memory_bytes: 16260
#include<iostream>
    using namespace std;
    int main()
    {
      int a,b,c;
      std::cin >> a >> b >> c;

      if (b-a == 0 && c-a == 0 && b-c == 0) {
        std::cout << 1 << '\n';
      }
       else if (b-a != 0 && c-a != 0 && b-c != 0) {
        std::cout << 3 << '\n';
       }
       else{
        std::cout << 2 << '\n';
       }

        return 0;
    }


Measured memory_bytes: 256
#include<iostream>

using namespace std;

bool isSame(string tmp,string s,int n){
    int i;
    bool flag = true;

    for( i=0;i<n;i++ ){
        if( s[i] == '\0' ){
            break;
        }
        if( tmp[i] != s[i] ){
            //cout << i << "," << tmp << "," << s[i] << endl;
            return false;
        }
    }

    return true;
}

bool isResult(string tmp,string s,string t,int n){
    int i;
    string tmp2;
    string tmp3;

    tmp2 = tmp + t;

    for( i=0;i<n;i++ ){
        tmp3[i] = tmp2[i];
    }

    //cout << "tmp:" << tmp << endl;

    if( isSame(tmp2,s,n) ){
        return true;
    }else{
        return false;
    }

}

int main(){
    int n;
    int i,j;
    string s,t,tmp;
    cin >> n;
    cin >> s;
    cin >> t;

    for( i=0;i<=n;i++ ){
        tmp = "";
        //cout << tmp + s + t << endl;
        for( j=0;j<i;j++ ){
            //cout << "tmpにs[j]を代入 j:" << j << "s[j]:" << s[j] << endl;
            tmp += s[j];
        }

        //cout << tmp << endl;

        tmp[i] = '\0';
        if( isResult(tmp,s,t,n) ){
            //cout << tmp + t << endl;
            cout << (tmp + t).length() << endl;
            break;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
  vector<int >mon(n+1,0),hero(n,0);
  for(int i=0;i<n+1;i++){
  	cin>>mon[i];
  }
  for(int i=0;i<n;i++)cin>>hero[i];
  long long num=0;
  for(int i=0,change;i<n;i++){
  	change=min(mon[i],hero[i]);
  	num+=change;
  	change = min(mon[i+1],hero[i]-change);
  	num+=change;
  	mon[i+1]-=change;
    
      
  }
  cout<<num;
}

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

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

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

    if(k <= a) {
        cout << k << endl;
        return 0;
    }else if (k <= a + b){
        cout << a << endl;
    }else  {
        cout << a - (k-a-b) << endl;
    }
    return 0;
}


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

int calc(int i, int c, const vector<int>& v, const vector<int>& w, vector<vector<int> >& ans){
  if(i <= -1 || c < 0){
    return 0;
  }else if(c == 0){
    ans[i][c] = 0;
  }else if(ans[i][c] >= 0){
    return ans[i][c];
  }else if(c - w[i] < 0){
    ans[i][c] = calc(i-1, c, v, w, ans);
  }else{
    ans[i][c] = max(
      v[i] + calc(i-1, c - w[i], v, w, ans),
      calc(i-1, c, v, w, ans)
    );
  }
  return ans[i][c];
}

int main(){
  int n,c;
  cin >> n >> c;
  vector<int> v(n),w(n);
  for(int i = 0; i < n; i++)
    cin >> v[i] >> w[i];
  vector<vector<int> > ans(n, vector<int>(c+1, -1));
  cout << calc(n-1, c, v, w, ans) << endl;
  return 0;
}

Measured memory_bytes: 6764
#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;

typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vii;
typedef pair<int, int> pi;
typedef map<int, int> mi;
#define fi first
#define se second
#define be begin()
#define ed end()
#define sz size()
#define cl clear()
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define lb(v, x) lower_bound(v.begin(), v.end(), x)
#define lbi(v, x) (lb(v, x) - v.begin())
#define tp(x, y) int x, y; tie(x, y)
#define mp make_pair
#define mt make_tuple
#define fc(x) for(int x = 1, _end = ri(); x <= _end; x++)
void uni(vi &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }

db rd() { db x; cin >> x; return x; }
ll ri() { ll x; cin >> x; return x; }
string rs() { string s; cin >> s; return s; }
pi rpi() { pi x; cin >> x.fi >> x.se; return x; }
vi rvi(int n, int f = 0) { vi v(n + f); for (int i = f; i < v.size(); i++) cin >> v[i]; return v; }
vii rvii(int n, int m, int f = 0) { vii v(n + f, vi(n + f)); for (int i = f; i < v.size(); i++) for (int j = f; j < v[0].size(); j++) cin >> v[i][j]; return v; }
void pr() {}; template <class T, class ...U> void pr(T x, U ...y) { cout << x << ' ', pr(y...); }
void prl() { cout << '\n'; }; template <class T, class ...U> void prl(T x, U ...y) { cout << x << ' ', prl(y...); }
void pr(const vi &v, int f = 0) { for (int i = f; i < v.size(); i++) cout << v[i] << ' '; }
void prl(const vi &v, int f = 0) { pr(v, f); cout << '\n'; }
void pr(const pi &x) { cout << x.fi << ' ' << x.se; };
void prl(const pi &x) { pr(x); cout << '\n'; }

#define rep(i, l, r) for (int i = l; i < r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

const int N = 2e5 + 5, M = 1e9 + 7;

int main() {
  auto s = rs();
  int n = s.sz;
  if (s[0] == s[n-1]) puts(n % 2 == 0 ? "First" : "Second");
  else puts(n % 2 == 0 ? "Second" : "First");
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	string s; cin >> s;
	VI a(s.length() + 1); 
	ll ans = 0, len = 1;
	REP(i, s.length()) {
		if (s[i] == '<') {
			a[i + 1] = len;
			ans += len;
			len++;
		}
		else
			len = 1;
	}
	len = 1;
	for(int i = s.length() - 1;i >= 0;i--) {
		if (s[i] == '>') {
			if (i != 0) {
				if (a[i] < len)
					ans += len - a[i];
			}
			else
				ans += len;
			len++;
		}
		else
			len = 1;
	}
	cout << ans;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] NM = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int N = NM[0];
            int[] M = new int[NM[1]];

            for (int i = 0; i < N; i++)
            {
                int[] vs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                for (int j = 1; j <= vs[0]; j++)
                {
                    M[vs[j] - 1]++;
                }
            }
            int cnt = 0;
            for (int i = 0; i < M.Length; i++)
            {
                if (M[i] == N)
                    cnt++;
            }
            Console.WriteLine(cnt);
        }
    }
}




//int n = int.Parse(Console.ReadLine());
//int[] N = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int  MOD = 1e9 + 7 , N = 1e5 + 2  , M = 1e2 + 2 ;
ll mem[N][M][2];
string s ;
int D ;
ll solve(int idx , int sum , int flag){
    if(idx == s.size()){
        return (sum == 0);
    }
    int dig = s[idx] - '0' ;
    if(flag)
        dig = 9 ;
    ll &ret = mem[idx][sum][flag] ;
    if(~ret)
        return ret ;
    ret = 0 ;
    for(int i = 0 ; i<= dig ; ++i){
        bool ok = flag ;
        if(i < dig)
            ok = 1 ;
        ret+=(solve(idx + 1 , (sum+i) % D  , ok))%MOD ;
    }
    return ret % MOD;

}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(mem , -1 , sizeof mem);
    cin >> s >> D ;
    cout << (solve(0 , 0 , 0) - 1 + MOD)% MOD;

    return 0;
}


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


void solve(long long A, long long B){
    int n = ceil(((double)B - A) / (A - 1)) + 1;
    cout << n << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in f(string s, char c){
  bool k=1;
  forv(i,s)
    if(s[i]!=c)
      k=0;
  if(k)
    return 0;
  string t(sz(s)-1,c+1);
  forv(i,t){
    if(s[i]==c || s[i+1]==c)
      t[i]=c;
    else
      t[i]=c+1;
  }
  return 1+f(t,c);
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin>>s;
  in bst=1e9;
  for(char c='a';c<='z';++c)
    bst=min(bst,f(s,c));
  cout<<bst<<endl;
  return 0;
}


Measured memory_bytes: 764
def search(s:list, target:int) -> int:
    left=0
    right=len(s)
    while left < right:
        mid = int((left+right)/2)
        if s[mid] == target:
            return mid
        if target > s[mid]:
            left=mid+1
        elif target < s[mid]:
            right=mid
    return -1

n=int(input())
s=list(map(int, input().split()))
q=int(input())
t=list(map(int, input().split()))

ans=0
for _t in t:
    if search(s, _t) != -1:
        ans+=1

print(ans)


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

#define int long long

bool comp(pair<int,int> p1,pair<int,int> p2){
	if(p1.second != p2.second) return p1.second > p2.second;
	else return p1.first > p2.first;
}

signed main(){
	int n,m;
	cin>>n>>m;
	int arr[n];
	for(int i = 0;i < n;i++) cin>>arr[i];
	sort(arr,arr+n);
	vector<pair<int,int> > vp(m);
	for(int i = 0;i < m;i++){
		cin>>vp[i].first>>vp[i].second;
	}
	sort(vp.begin(),vp.end(),comp);
	
	int j = 0;
	for(int i = 0;i < m;i++){
		int oldJ = j;
		for(;j < min(oldJ + vp[i].first,n); j++){
			if(arr[j] <= vp[i].second) arr[j] = vp[i].second;
			else break;
		}
	}
	
	int sum = 0;
	for(int i = 0;i < n;i++){
		// cout<<arr[i]<<" ";
		sum += arr[i];
	}
	// cout<<endl;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<vector<int>> data(3, vector<int>(N));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < N; j++) {
      cin >> data.at(i).at(j);
    }
  }
  int ans = 0;
  int idx0 = data.at(0).at(0)-1;
  ans += data.at(1).at(idx0);
  int idx;
  for(int i = 1; i < N; i++){
    idx = data.at(0).at(i)-1;
    if(idx0 == idx-1){
      ans += data.at(1).at(idx);
      ans += data.at(2).at(idx0);
    }
    else ans += data.at(1).at(idx);
    idx0 = idx;
  }
  cout << ans << endl;
}

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

bool judge(int kA, int kB, int kC, int kX){
    if (kX == 500*kA + 100*kB + 50*kC){
        return true;
    }else{
        return false;
    }
}

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    
    int count = 0;
    
    int max[3];
    max[0] = X / 500;
    max[1] = X / 100;
    max[2] = X / 50;
    A = min(A, max[0]);
    B = min(B, max[1]);
    C = min(C, max[2]);
    bool flag;
    
    for(int a = 0; a <= A; a++){
        for(int b = 0; b <= B; b++){
            for (int c = 0; c <= C; c++){
                flag = judge(a, b, c, X);
                if (flag){
                    count++;
                }
            }
        }
    }
    
    cout << count << endl;
}

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

int main() {
        int s;
        int s1;
        int s2;
        int s3;
        int result;

        cin >> s;

        s1 = s / 100;
        s2 = (s - (s1 * 100)) / 10;
        s3 = (s - (s1 * 100) - s2 * 10);

        result = s1 + s2 + s3;

        cout << result << endl;
}


Measured memory_bytes: 256
//#include "stdafx.h"
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
int ans,r,d,q,n,x,a[101],c;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin >>n>>d>>x;
	for(int i=0;i<n;i++)cin>>a[i];

	for(int i=0;i<n;i++){
		r=1;q=a[i];
		while(q<=d){
			q=(a[i]*r)+1;
			r++;
		}
		if(a[i]<=d)
		ans+=r-2;
	}
	cout<<n+ans+x<<"\n";
	return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
#include<string.h>
int main(void){
    int n, p[100][2], u[2];
    char s[100][11], t[11];
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%s %d", s[i], &p[i][0]);
        p[i][1]=i+1;
    }
    
    for(int i=1;i<n;i++){
        for(int j=1;j<n;j++){
            if(strcmp(s[j-1], s[j])>0){
                strcpy(t, s[j-1]);
                strcpy(s[j-1], s[j]);
                strcpy(s[j], t);
                u[0]=p[j-1][0];
                u[1]=p[j-1][1];
                p[j-1][0]=p[j][0];
                p[j-1][1]=p[j][1];
                p[j][0]=u[0];
                p[j][1]=u[1];
            }
        }
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<n;j++){
            if(strcmp(s[j-1], s[j])==0){
                if(p[j-1][0]<p[j][0]){
                    strcpy(t, s[j-1]);
                    strcpy(s[j-1], s[j]);
                    strcpy(s[j], t);
                    u[0]=p[j-1][0];
                    u[1]=p[j-1][1];
                    p[j-1][0]=p[j][0];
                    p[j-1][1]=p[j][1];
                    p[j][0]=u[0];
                    p[j][1]=u[1];
                }   
            }
        }
    }


    
    for(int i=0; i<n; i++){
        printf("%d\n", p[i][1]);
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		int cost = 0;
		if(a <= b) {
			cost = a;
		} else {
			cost = b;
		}
		if(c <= d) {
			cost = cost + c;
		} else {
			cost = cost + d;
		}
		System.out.println(cost);
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main()
{
	unsigned long n, d, area;

	while (scanf("%d", &d) == 1)
	{
        n = (600 / d) - 1;

		area = d * d * d * ((n * (n + 1) * (2*n + 1)) / 6);

		printf("%lu\n", area);
	}

	return(0);
}

Measured memory_bytes: 600
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

typedef long long int ll;
typedef pair<ll,ll> pll;

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}

signed main(){
	IOS
	string s;	cin >> s;
	char c;
	int q;	cin >> q;
	deque<char> que;
	rep(i,SZ(s))	que.pb(s[i]);
	bool rev = 0;
	while(q--){
		int op;	cin >> op;
		if(op == 1)	rev ^= 1;
		else{
			int where;
			cin >> where >> c;
			if(rev){
				if(where == 1)	que.pb(c);
				else			que.pf(c);
			}
			else{
				if(where == 1)	que.pf(c);
				else			que.pb(c);
			}
		}
	}
	if(rev){
		while(!que.empty()){
			cout << que.back();
			que.pop_back();
		}
	}
	else{
		while(!que.empty()){
			cout << que.front();
			que.pop_front();
		}
	}
}


Measured memory_bytes: 976
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars
    }
    let mut count = 0;
    let le = s.len();
    for i in 0..le/2 {
        if s[i] != s[le - i - 1] {
            count += 1;
        }

    }
    println!("{}", count);
}


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



int main(){
	int N;
	cin>>N;
	string S;
	cin>>S;
	
	int S_white[N+2];
	S_white[0]=0;
	
	for(int i=0;i<N;i++){
		S_white[i+1]=S_white[i];
		if(S[i]=='.')S_white[i+1]++;
	}
	S_white[N+1]=S_white[N];
	int mini = 9999999;
	
	for(int i=1;i<=N+1;i++){
		int a = 0;
		a+=i-1-S_white[i-1];
		a+=S_white[N+1]-S_white[i-1];
		mini=min(a,mini);
	}
	
	cout<<mini<<endl;
	
		
	
	return 0;
}


Measured memory_bytes: 1412
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,m,p;
  std::cin>>n>>m>>p;
  
  struct Edge{ll from,to,cost;};

  std::vector<Edge> es(m);

  std::vector<ll> d(n);

  rep(i,0,m){
    ll a,b,c;
    std::cin>>a>>b>>c;
    a--;b--;
    es[i]=Edge{a,b,p-c};
  }

  rep(i,0,n)d[i]=LLONG_MAX;

  ll ans=0;

  d[0]=0;
  ll count=0;
  ll temp=0;
  while(1){
    count++;
    bool update=false;
    rep(i,0,m){
      Edge e=es[i];
      if(d[e.from]!= LLONG_MAX&&d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
        update=true;
      }
    }

    if(!update){
      break;
    }

    if(count==n+1){
      temp= -d[n-1];
    }else if(count%(n+1)==0){
      if(temp<-d[n-1]){
        ans=-1;
      }
      break;
    }
  }

  if(ans!=-1){
    if(d[n-1]>0){
      std::cout<<0;
    }else{
      std::cout<<-d[n-1];
    }
  }else{
    std::cout<<-1;
  }

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

int mainsolve(){

	ll k,n;
	cin >> k >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];

	ll maxd = (k - a[n-1]) + a[0];
	assert(maxd >= 0);
	rep(i,n-1){
		maxd = max(maxd, a[i+1] - a[i]);
	}

	cout << k - maxd << endl;
	return 0;

	
}

int main(){

	return mainsolve();
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int INF = 1145141919;
vector <vector<int>> d(15,vector <int>(15,-1));
vector <vector<int>> dp(1<<15,vector <int>(15,-1));
int V,E;
int rec(int S, int now){
    if(dp[S][now]!=-1) return dp[S][now];
    if(S==(1<<V)-1&&now==0) return 0;
    int r=INF;
    for(int next=0;next<V;next++){
        if(d[now][next]!=-1 && !(S & (1<<next)))
        r = min(r, rec(S|(1<<next), next)+d[now][next]);
    }
    dp[S][now]=r;
    return r;
}
int main(void){
    cin>>V>>E;
    for(int i=0;i<E;i++){
        int a,b; cin>>a>>b; cin>>d[a][b];
    }
    int ans = rec(0,0);
    if(ans==INF) cout<<-1<<endl;
    else cout<<ans<<endl;
}



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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int A, B, C, D, E, F;
  scanf("%d %d %d %d %d %d", &A, &B, &C, &D, &E, &F);
  int ans_warter = -1, ans_sugar = -1;
  for (int op1 = 0; 100 * A * op1 <= F; ++op1) {
    for (int op2 = 0; 100 * A * op1 + 100 * B * op2 <= F; ++op2) {
      if (op1 + op2 == 0) { continue; }
      int water = 100 * A * op1 + 100 * B * op2;
      if (water > F) { continue; }
      int sugar_possible = E * (A * op1 + B * op2);
      int rest = min(F - water, sugar_possible);
      for (int op3 = 0; op3 * C <= rest; ++op3) {
        for (int op4 = 0; op3 * C + op4 * D <= rest; ++op4) {
          int sugar = op3 * C + op4 * D;
          if (water + sugar > F) { continue; }
          // fprintf(stderr, "DEBUG: op1=%d, op2=%d, op3=%d, op4=%d, rest=%d, water=%d, sugar=%d\n", op1, op2, op3, op4, rest, water, sugar);
          if (ans_warter == -1) {
            // fprintf(stderr, "DEBUG: op1=%d, op2=%d, op3=%d, op4=%d, rest=%d, water=%d, sugar=%d\n", op1, op2, op3, op4, rest, water, sugar);
            ans_warter = water;
            ans_sugar = sugar;
          }
          else if (sugar * (ans_warter + ans_sugar) > ans_sugar * (water + sugar)) {
            // fprintf(stderr, "DEBUG: op1=%d, op2=%d, op3=%d, op4=%d\n", op1, op2, op3, op4);
            ans_sugar = sugar;
            ans_warter = water;
          }
        }
      }
    }
  }
  printf("%d %d\n", ans_sugar + ans_warter, ans_sugar);
  return 0;
}


Measured memory_bytes: 256
import math

x = int(input())

max_pow = 1
for i in range(1, math.ceil(math.sqrt(x))):
    for p in range(2, 9):
        i_p = i**p
        if i_p > x:  break
        if i_p > max_pow: max_pow = i_p
            
print(max_pow)

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

struct st { int x, y, cnt; };
int H, W;
int vs[1000][1000];
queue<st> que;
int ans;
int dx[] = { 0, 0, 1, -1 };
int dy[] = { 1, -1, 0, 0 };

int main()
{
  cin >> H >> W;
  rep(i, H) rep(j, W) {
    char c;
    cin >> c;
    if (c == '#') {
      que.push({i, j, 0});
      vs[i][j] = 1;
    }
  }

  while (!que.empty()) {
    int x = que.front().x, y = que.front().y, cnt = que.front().cnt; que.pop();
    ans = max(ans, cnt);
    rep(i, 4) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || ny < 0 || nx >= H || ny >= W || vs[nx][ny]) continue;
      que.push({nx, ny, cnt+1});
      vs[nx][ny] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16272
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll> rui(n + 1, 0); // 累積mod
    for (ll i = 0; i < n; i++)
    {
        rui[i + 1] = (rui[i] + a[i]) % m;
    }
    map<ll, ll> mp;
    for(auto t: rui){
        mp[t]++;
    }
    ll ans = 0;
    for(auto p : mp){
        ans += ((p.second) * (p.second - 1) / 2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    k = ni()

    m = 0
    for i in range(10 ** 6 + 1):
        tmp = 7 * pow(10, i, k)
        m = (m + tmp) % k
        if m == 0:
            print(i + 1)
            exit(0)

    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11260
#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<n; i++)
#define INF 999999999
#define llong long long
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <utility>
#include <stdio.h>
#include <math.h>
using namespace std;

int main() {
	string s;
	int ans=INF;
	cin >> s;
	REP(i, s.size() - 2) {
		int x;
		x = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + s[i + 2] - '0';
		ans = ans > abs(x - 753) ? abs(x - 753) : ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int A, B;
    int ans;
    
    scanf("%d %d", &A, &B);
    if(B%A == 0){
	ans = A+B;
    }
    else{
	ans = B-A;
    }

    printf("%d", ans);

    return 0;
}


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

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

    vector<int> problem(3);
    for(int i=0; i<n; i++){
        int p;
        cin >> p;
        if(p <= a) problem[0] += 1;
        if(a+1 <= p && p <= b) problem[1] += 1;
        if(b+1 <= p) problem[2] += 1;
    }
    sort(problem.begin(),problem.end());
    cout << problem[0] << endl;
    return 0;
}

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

int main()
{
    int n;
    int sum = 0;
    int max = 0;
    cin >> n;
    int p;
    for (int i = 0; i < n; i++)
    {
        cin >> p;
        sum += p;
        if (p > max)
            max = p;
    }
    cout << sum - max / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
function Main(input) {
  const args = input.split(' ');
  const A = parseInt(args[0]);
  const B = parseInt(args[1]);
  if( (A * B) % 2 === 0 ) {
    console.log('No');
  } else {
    console.log('Yes');
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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


int main()
{
    int a,b,c,d;

    cin >> a >> b >> c >> d;

    while(true)
    {
        c -= b;
        if(c <= 0)
        {
            cout << "Yes";
            break;
        }

        a -= d;

        if(a <= 0)
        {
            cout << "No";
            break;
        }
            

        
    }
    

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];

  vector<ll> dp(n, INF);
  dp[0] = 0;

  repI(i, 1, n) {
    chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    if (i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }

  cout << dp[n-1] << endl;


  return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;



public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");

		int d = Integer.parseInt(tmpArray[0]);
		int g = Integer.parseInt(tmpArray[1]);


		int problem[] = new int[d];
		int bonus[] = new int[d];

		PriorityQueue<Integer> pq = new PriorityQueue<>();
		ProblemSet pset[] = new ProblemSet[d];
		for(int i = 0; i < d; i++){
			tmpArray = br.readLine().split(" ");

			problem[i] = Integer.parseInt(tmpArray[0]);
			bonus[i] = Integer.parseInt(tmpArray[1]);

			pset[i] = new ProblemSet((i + 1)*100, problem[i], bonus[i]);
		}

//		Arrays.sort(pset);
//
//		for(int i = 0; i < d; i++){
//			System.out.println(pset[i].point+" "+ pset[i].ave);
//		}

		//各ビットが1のとき、その問題はコンプしたことにする

		int minNum = Integer.MAX_VALUE;
		for(int i = 0; i < Math.pow(2, d); i++){
			boolean comp[] = new boolean[d];
			int bit = 1;
			for(int j = 0; j < d; j++){
				if((int)(bit & i) != 0){
					comp[j] = true;
				}

				bit <<= 1;
			}

			//debug
//			for(int j = 0; j < d; j++){
//				if(comp[j])System.out.println("comp "+(j + 1)*100);
//			}

			int tmpNum = 0;
			int tmpScore = 0;
			for(int j = 0; j < d; j++){
				if(comp[j]){
					tmpNum += problem[j];
					tmpScore += problem[j] * 100 * (j + 1) + bonus[j];
				}
			}

			//コンプ以外の問題は点数が高い順に
			for(int j = d - 1; j >= 0 && tmpScore < g ; j--){
				if(comp[j]){
					continue;
				}
				for(int k = 0; k < problem[j] - 1; k++){
					tmpNum++;
					tmpScore += (j + 1)*100;

					if(tmpScore >= g){
						break;
					}
				}
			}
//			System.out.println("tmpNum:" + tmpNum +" tmpScore: "+tmpScore);
			if(tmpScore >= g){
				minNum = Math.min(minNum, tmpNum);
			}
		}

		System.out.println(minNum);
	}

}

class ProblemSet implements Comparable<ProblemSet>{
	int num;
	int bonus;
	int point;
	double ave;

	ProblemSet (int point, int num, int bonus){
		this.point = point;
		this.num = num;
		this.bonus = bonus;

		ave = ((double)point * num + bonus)/num;
	}

	@Override
	public int compareTo(ProblemSet p) {
		// TODO 自動生成されたメソッド・スタブ

		if(this.ave > p.ave){
			return -1;
		}
		else if(this.ave == p.ave){
			return 0;
		}
		else {
			return 1;
		}
	}


}

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

const long long INF = 1LL << 60; // これはなに？

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() {
	int N; cin >> N;
	vector<vector<long long>> a(N, vector<long long>(3));
	for(int i = 0; i < N; ++i){
		for(int k = 0; k < 3; ++k) {
			cin >> a[i][k];
		}
	}

	vector<vector<long long>> dp(100010, vector<long long>(3));
	for(int i = 0; i < 100010; ++i) {
		for(int k = 0; k < 3; ++k) {
			dp[i][k] = 0;
		}
	}

	// ここがdpテーブルへの格納部分。
	for(int i = 0; i < N; ++i) {
		for(int m = 0; m < 3; ++m) {
			for(int k = 0; k < 3; ++k) {
				if(m == k) continue;
				chmax(dp[i + 1][m], dp[i][k] + a[i][m]);
			}
		}
	}

	// 最後にdpの最後の値を見て、a, b, cどの値が大きかったかを確認する。
	long long res = 0;
	for(int i = 0; i < 3; ++i) {
		chmax(res, dp[N][i]);
	}
	cout << res << endl;
}

Measured memory_bytes: 11136
#include <iostream>

using namespace std;

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

    int res_x = -1, res_y = -1, res_z = -1;
    for (int i = 0; 10000 * i <= y; i++) {
        for (int j = 0; 10000 * i + 5000 * j <= y; j++) {
            int k = (y - 10000 * i - 5000 * j) / 1000;

            if (i + j + k == n) {
                res_x = i;
                res_y = j;
                res_z = k;
                goto out;
            }
        }
    }

out:
    cout << res_x << " " << res_y << " " << res_z << endl;
}


Measured memory_bytes: 256
import itertools
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
from math import factorial

sys.setrecursionlimit(4100000)
from functools import lru_cache

INF = 1 << 60
MOD = 10 ** 9 + 7

#Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ここから書き始める
n = int(input())
ab = [()] * n
for i in range(n):
    a, b = map(int, input().split())
    ab[i] = (b, a)
ab.sort()
# print(ab_sorted)
time = 0
yes = True
# print("ab", ab)
for i in ab:
    time += i[1]
    # print("time =", time)
    if time > i[0]:
        yes = False
        break
if yes:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 31516
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n,k;
	string s;

	cin>>n;
	cin>>s;
	cin>>k;
	rep(i,n){
		if(s[i]!=s[k-1])s[i]='*';
	}
	cout<<s<<endl;
	return 0;

}


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

int main(){
    string S,S1;
    int N;
    cin >> S;
    S1 = S;
    N = S.size();
    reverse(S1.begin(),S1.end());
    bool flag = true;
    if(S != S1){
        flag = false;   
    }else{
        for(int i = 0;i < (N-1)/2;i++){
            if(S[i] != S[(N+1)/2+i]){
                flag = false;
            }
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256