akhauriyash/Code-Regression huggingface dataset:
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int dp[114][114514];
int w[114],v[114];
const int max_v=114514;
signed main() {
    int n,m;cin >> n >> m;
    rep(i, n)cin >> w[i] >> v[i];
    // rep(i, n)cin >> v[i];
    rep(i, n+1) {
        rep(j, max_v) dp[i][j]=inf;
    }
    dp[0][0]=0;
    rep(i, n) {
        rep(j,max_v) {
            if(j-v[i]>=0) chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);
            chmin(dp[i+1][j],dp[i][j]);
        }
    }
    int ma = -1;
    rep(i, max_v) {
        if(dp[n][i]<=m) chmax(ma,i);
    }
    // cout << dp[n][11451] << endl;
    cout << ma << endl;
    return 0;
}

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

using namespace std;

#define INF int(1e9)
#define ii pair<int, int>
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define x first
#define y second


int main () {
    ios_base::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;

    if(a!=2 and b!=2)
        cout << 2 << endl;
    if(a!=1 and b!=1)
        cout << 1 << endl;
    if(a!=3 and b!=3)
        cout << 3 << endl;
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  string ans="APPROVED";
  for(int i=0;i<n;i++){
    if(a[i]%2==0 && (a[i]%3!=0 && a[i]%5!=0)) {
      ans="DENIED";
      break;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    count = 0
    count_dict = {}

    for i in range(n):
        input_data = ''.join(sorted(input()))
        if input_data in count_dict:
            count += count_dict[input_data]
            count_dict[input_data] += 1
        else:
            count_dict[input_data] = 1

    print(count)


if __name__ == '__main__' :
    main()

Measured memory_bytes: 17852
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int A,B=0,C=0;
  cin >> A;
  vector<long long int>P(A+1),G(P);
  for(int i=0;i<A+1;i++)cin >> P[i];
  for(int i=0;i<A;i++)cin >> G[i];
  for(int i=0;i<A;i++){
	  if(P[i]+P[i+1]<=G[i]){
		  B+=P[i]+P[i+1];
		  P[i]=0;
		  P[i+1]=0;
	  }else{
		  if(P[i]<=G[i]){
			  B+=G[i];
			  P[i+1]=P[i+1]-G[i]+P[i];
		  }else B+=G[i];
	  }
  }
  cout << B << endl;
}

Measured memory_bytes: 1792
h,n=map(int,input().split())
arr=[]
for _ in range(n):
  arr.append(list(map(int,input().split())))
dp=[10**10]*20001
dp[0]=0
for i in range(20001):
  for j in range(n):
    if i+arr[j][0]>20000:
      continue
    dp[i+arr[j][0]]=min(dp[i+arr[j][0]],dp[i]+arr[j][1])
ans=10**18
for i in range(h,20001):
  ans=min(ans,dp[i])
print(ans)

Measured memory_bytes: 42220
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll min(ll a, ll b)
{
    if(a<b)
        return a;
    else
        return b;
}
int main()
{
    ll n,i,j,k;
    cin>>n>>k;
    ll h[n],dp[n];
    for(i=0;i<n;i++)
    {
        cin>>h[i];
    }
    for(i=0;i<n;i++)
    {
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    for(i=1;i<n;i++)
    {
        for(j=0;j<=k && (i-j>=0);j++)
        {
           dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

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

int n, m;
int c[21];
int dp[21][50001];
const int INF = 100000000;

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    cin >> c[i];
  }
  for(int i = 0; i < m; i++) {
    for(int j = 0; j <= n; j++)
    dp[i][j] = INF;
  }
  dp[0][0] = 0;

  for(int i = 0; i < m; i++) {
    for(int j = 0; j <= n; j++) {
      dp[i+1][j] = dp[i][j];
      if(j >= c[i]) dp[i+1][j] = min(dp[i][j], dp[i+1][j-c[i]] + 1);
      // if(dp[i][j] != INF && dp[i+1][j-c[i]] != INF) {
      //   dp[i+1][j] = min(dp[i][j], dp[i+1][j-c[i]] + 1);
      // } else if(dp[i][j] != INF) {
      //   dp[i+1][j] = dp[i][j];
      // } else{
      //   dp[i+1][j] = INF;
      // }
    }
  }

  if(dp[m][n] != INF) cout << dp[m][n] << endl;
  else cout << -1 << endl;

  return 0;
}


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

using namespace std;

#define REPN(n) for(int _i = 0; _i < (n); _i++)
#define YES_OR_NO(x) (cout << ((x) ? "YES" : "NO") << endl)

void test_case() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max({b * d, b * c, a * d, a * c}) << endl;
}

int main(void) {
  int t = 1;
  // cin >> t;
  while (t--) {
    test_case();
  }
  return 0;
}


Measured memory_bytes: 3656
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""

while True:
    inp = input().strip().split(" ")
    n = int(inp[0]) + 1
    x = int(inp[1])
    cnt = 0
    if n < 2 and x < 1:
        break
    for i in range(1, n-2):
        for j in range(i + 1, n-1):
            for k in range(j + 1, n):
                t = i + j + k
                if t == x:
                    cnt = cnt + 1
                elif t > x:
                    break
    print(cnt)

Measured memory_bytes: 7692
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	for {
		fmt.Scan(&n)
		if n == 0 {
			break
		}
		s := make([]int, n)
		for i := range s {
			fmt.Scan(&s[i])
		}
		fmt.Printf("%f\n", standardDevidation(s))
	}
}

func sum(s []int) int {
	sum := 0
	for _, v := range s {
		sum += v
	}
	return sum
}

func average(s []int) float64 {
	return float64(sum(s)) / float64(len(s))
}

func standardDevidation(s []int) float64 {
	sd := 0.0
	for _, v := range s {
		sd += (float64(v) - average(s)) * (float64(v) - average(s))
	}
	return math.Sqrt(sd / float64(len(s)))
}



Measured memory_bytes: 1256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main(){
  long long n,m;
  cin>>n>>m;
  long long ans;
  if(n==1 && m==1){
    cout<<1<<endl;
  }else if(n==1 || m==1){
    ans = max(n,m)-2;
    cout<<ans<<endl;
  }else if(n==2 || m==2){
    cout<<0<<endl;
  }else{
    ans = (n-2)*(m-2);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import math
N, A, B = map(int, input().split())
all_attack = 0
enemy = [int(input()) for i in range(N)]


def possible_kill_all(attack):
    tmp_enemy = [v-B*attack for v in enemy]
    tmp_needed_attack = 0
    for v in tmp_enemy:
        if v>0:
            tmp_needed_attack += math.ceil(v/(A-B))
    if tmp_needed_attack <= attack:
        return True
    else:
        return False



possible = 10**14
impossible = 0

while possible - impossible > 1:
    M = (possible+impossible)//2
    if possible_kill_all(M):
        possible = M
    else:
        impossible = M

print(possible)



Measured memory_bytes: 243028
#include <iostream>
#include <vector>
using namespace std;
void out_vec(vector<int> vec, int len_vec)
{
    for (int i = 0; i < len_vec; i++)
    {
        cout << vec[i];
        if (i == len_vec - 1)
            cout << "\n";
        else
            cout << " ";
    }
}

void selectionSort(vector<int> vec, int len_vec)
{
    int swap_count = 0;
    for (int i = 0; i < len_vec; i++)
    {
        int min_ind = i;
        for (int j = i; j < len_vec; j++)
        {
            if (vec[min_ind] > vec[j])
            {
                min_ind = j;
            }
        }
        if (i != min_ind)
        {
            swap(vec[i], vec[min_ind]);
            swap_count++;
        }
    }
    out_vec(vec, len_vec);
    cout << swap_count << "\n";
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];
    selectionSort(A, N);
    return 0;
}


Measured memory_bytes: 3152
#include<iostream>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	ll a[n+1]={};
	for(ll i=1;i<=n;i++)
	{
		ll temp;
		cin>>temp;
		a[temp]=i;
	}
	for(ll i=1;i<=n;i++)
	{
		cout<<a[i]<<" ";
	}
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <stdbool.h>

bool is_leap_year(int y);
int get_leap_years(int* a, int b, int c);

int main(void)
{
    int leap_years_list[1000]; //A.D. 0 - A.D. 3000 の間に閏年は高々1000個しかない

    bool first_set = true; //一つ目のセットの前にだけは改行を入れてはいけないので

    while (true) {
        int year_begin, year_end;

        //読み込み
        scanf("%d %d", &year_begin, &year_end);

        //終了判定
        if (year_begin == 0 && year_end == 0) {
            break;
        }

        //閏年を計算する
        int leap_years_count = get_leap_years(leap_years_list, year_begin, year_end);

        //セットとセットの間には空行を入れる
        if (first_set) {
            first_set = false;
        } else {
            putchar('\n'); //putcharは一文字だけ出力する関数です
        }

        //閏年を出力
        if (leap_years_count == 0) {
            puts("NA"); //putsは与えられた文字列を出力した後改行する関数です
        } else {
            for (int i = 0; i < leap_years_count; i++) {
                printf("%d\n", leap_years_list[i]);
            }
        }
        
    }
}

bool is_leap_year(int y)
{
    if (y % 400 == 0) {
        return true; 
    } else if (y % 100 == 0) {
        return false;
    } else {
        return y % 4 == 0;
    }
}

int get_leap_years(int* a, int b, int c)
{
    int i = 0;
    for (int year = b; year <= c; ++year){
        if (is_leap_year(year)) {
            a[i] = year;
            ++i;
        }
    }
    return i;
}

Measured memory_bytes: 1048
N = int(input())
d = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for _ in range(N):
    s = input()
    d[s] += 1
for s in ['AC', 'WA', 'TLE', 'RE']:
    print('{0} x {1}'.format(s, d[s]))


Measured memory_bytes: 9208
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;

int dx[4]={1,0,-1,0},
	dy[4]={0,1,0,-1};
int n,m,i,j,ans,vis[30][30],q[1000][3];
char s[30][30];

int fast(){
	int res=0,fl=1;
	char c=getchar();
	while(c<48||c>57){
		if(c=='-')fl=-1;
		c=getchar();
	}while(c>=48&&c<=57)res=res*10+c-48,c=getchar();
	return res*fl;
}

void write(int x){
	if(x>9)write(x/10);
	putchar(x%10+48);
}

void bfs(int x,int y){
	memset(vis,0,sizeof(vis));
	q[1][0]=x,q[1][1]=y,q[1][2]=0;
	vis[x][y]=1;
	int l=1,r=1;
	while(l<=r){
		for(int i=0;i<4;i++){
			int sx=q[l][0]+dx[i],sy=q[l][1]+dy[i];
			if(sx>=0&&sx<n&&sy>=0&&sy<m&&s[sx][sy]=='.'&&vis[sx][sy]==0){
				q[++r][0]=sx,q[r][1]=sy,q[r][2]=q[l][2]+1;
				vis[sx][sy]=1;
			}
		}l++;
	}ans=max(ans,q[r][2]);
}

int main(){
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%s",s[i]);
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			if(s[i][j]=='.')bfs(i,j);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
from sys import stdin

def main():
    N, L = map(int, input().split())

    apple = [L + i for i in range(N)]
    taste = sum(apple)
    n = float('inf')
    for a in apple:
        if n > abs(a):
            eat = a
            n = abs(a)
    print(taste - eat)

input = lambda: stdin.readline()
main()


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

int main() {
    int n, m;
    cin >> n >> m;
    char a[n][n], b[m][m];
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j];
    for (int i = 0; i < m; i++) for (int j = 0; j < m; j++) cin >> b[i][j];
    bool ans = false;
    for (int i = 0; i <= n - m; i++) for (int j = 0; j <= n - m; j++) {
        bool ok = true;
        for (int ni = 0; ni < m; ni++) for (int nj = 0; nj < m; nj++) {
            if (b[ni][nj] != a[i + ni][j + nj]) ok = false;
        }
        if (ok) {
            ans = true;
            break;
        }
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Control.Monad
import Data.List

take2 []       = []
take2 [x]      = [x]
take2 (x:y:ys) = x : take2 ys

main :: IO ()
main = do
    getLine
    as <- sortBy (\a b -> b `compare` a)
        . fmap read . words <$> getLine :: IO [Int]
    let alice = take2 as
    let bob   = take2 (tail as)
    print $ sum alice - sum bob

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  ll n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a.at(i);
  map<ll, ll> mp;
  rep(i,n) mp[a.at(i)]++;
  ll ans = 0;
  for(auto p : mp) {
    ll key = p.first;
    ll value = p.second;
    if(key>value) ans += value;
    else ans += (value-key); 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=0; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;

int main()
{
  int n ;
  cin >> n ;
  
  while(n%7!=0 && n%4!=0){
    n = n - 7 ;
    if(n<0){
      break ;
    }
    else if(n%4==0 || n%7==0){
      break ;
    }
  }
  
  if(n>=0){
    cout << "Yes"<<endl ;
  }
  else {
    cout <<"No"<<endl ;
  }
      
  

  return 0 ;
}




Measured memory_bytes: 256
function Main(input) {
	const array = input.split("\n").map(c => parseInt(c));
	const n = array[0];
    const k = array[1];
    const x = array[2];
    const y = array[3];
    if ( n <= k ) {
      ans = x * n;
    } else {
      ans = x * k + y * ( n - k );
    }
  	console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#include <queue>
#include<set>
#include<vector>
#include<list>
#include<deque>
#include<map>
#include <stack>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<string>

using namespace std;

int main() {
    priority_queue<int> q[1005];
    int n,t;
    cin>>n>>t;
    int a,b,c;
    while(t--){
        cin>>a;
        if(a==0){
            cin>>b>>c;
            q[b].push(c);
        }
        else if(a==1){
            cin>>b;
            if(!q[b].empty()) cout<<q[b].top()<<endl;
        }
        else{
            cin>>b;
            if(!q[b].empty()) q[b].pop();
        }
    }
    return 0;
}




Measured memory_bytes: 4120
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

string s;

string calc() {
	vector<char>v;
	REP(i, s.size()) {
		if (s[i] == '(')v.emplace_back('(');
		if (s[i] == '[')v.emplace_back('[');
		if (s[i] == ')') {
			if (v.size() == 0)return "no";
			else if (v[v.size()-1] == '(') {
				v.pop_back();
			}
			else {
				return "no";
			}
		}
		if (s[i] == ']') {
			if (v.size() == 0)return "no";
			else if (v[v.size()-1] == '[') {
				v.pop_back();
			}
			else {
				return "no";
			}
		}
	}
	return v.size() == 0 ? "yes" : "no";
}

int main() {
	while (getline(std::cin, s)) {
		if (s == ".")return 0;
		cout << calc() << endl;
	}
}


Measured memory_bytes: 3192
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 1e5 + 5;
const lli INF = 1e18;
int n, m;

vector<pii> g[maxn];

lli val[maxn * 4];
lli lazy[maxn * 4];

void ReadInput()
{
    cin >> n >> m;
    for(int i = 1; i <= m; ++i)
    {
        int L, R, c;
        cin >> L >> R >> c;
        g[L].push_back(pii(R, c));
    }
}

void push(int x)
{
    if(lazy[x] == -1) return;

    if(val[x * 2] > lazy[x])
    {
        val[x * 2] = lazy[x];
        lazy[x * 2] = lazy[x];
    }

    if(val[x * 2 + 1] > lazy[x])
    {
        val[x * 2 + 1] = lazy[x];
        lazy[x * 2 + 1] = lazy[x];
    }

    lazy[x] = -1;
}

void Update(int x, int l, int r, int L, int R, lli nval)
{
    if(L > r || l > R) return;
    if(l >= L && r <= R)
    {
        if(nval < val[x])
        {
            val[x] = nval;
            lazy[x] = nval;
        }
        return;
    }
    push(x);
    int mid = (l + r) / 2;
    Update(x * 2, l, mid, L, R, nval); Update(x * 2 + 1, mid + 1, r, L, R, nval);
}

lli Get(int x, int l, int r, int p)
{
    if(p < l || p > r) return INF;
    if(l == r)
        return val[x];
    push(x);
    int mid = (l + r) / 2;
    return min(Get(x * 2, l, mid, p), Get(x * 2 + 1, mid + 1, r, p));
}

void Solve()
{
    fill(begin(val), end(val), INF);
    fill(begin(lazy), end(lazy), -1);
    Update(1, 1, n, 1, 1, 0);
    for(int i = 1; i < n; ++i)
    {
        lli k = Get(1, 1, n, i);
        for(auto to: g[i])
        {
            int L = i, R = to.first, c = to.second;
            lli nval = k + (lli)c;
            Update(1, 1, n, L + 1, R, nval);
        }
    }

    lli ans = Get(1, 1, n, n);
    if(ans == INF) ans = -1;
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


Measured memory_bytes: 11904
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    ll X;
    in(X);
    ll a = 100;
    ll cnt = 0;
    while (a < X) {
        a += a / 100;
        cnt++;
    }
    cout << cnt << endl;


	return 0;
}


Measured memory_bytes: 3676
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define Vl vector<ll>
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using T = ll;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;


int main(){
   string s, t;
   cin >> s >> t;
   int ss = s.size(), ts = t.size();
   int res = INF;
   rep(i, ss - ts + 1){
       int cnt = 0;
       rep(j, ts){
           if(s[i + j] != t[j])cnt++;
       }
       chmin(res, cnt);
   }
   cout << res << endl;
}


Measured memory_bytes: 3560
import math

def sort(n, pl):
    if n > 1:
        pl_list = []
        for i in range(n):
            tmp = []
            tmp.extend(pl)
            p = tmp.pop(i)
            for l in sort(n-1, tmp):
                l.insert(0, p)
                pl_list.append(l)
        return pl_list
    else:
        return [pl]

def average_len(n, pl):
    pl_list = sort(n, pl)
    ave = 0.0
    for pl in pl_list:
        for i in range(n-1):
            ave += math.sqrt((pl[i][0]-pl[i+1][0])**2+(pl[i][1]-pl[i+1][1])**2)
    ave /= len(pl_list)
    print(ave)

n = int(input())
pl = []
for _ in range(n):
    pl.append([int(i) for i in input().split()])

average_len(n, pl)

Measured memory_bytes: 9204
n, m = map(int, input().split())
red = [False] * n
num = [1] * n
red[0] = True
first = 0
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if red[x]:
        red[y] = True
        num[x] -= 1
        num[y] += 1
        if num[x] == 0:
            red[x] = False
    if not red[x]:
        if num[x] > 0:
            num[y] += 1
            num[x] -= 1
print(red.count(True))

Measured memory_bytes: 4596
mod = 1000000007

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                inv = 0
                if (i < j):
                    inv = (((k + 1) * k) // 2) % mod
                else:
                    inv = ((k * (k - 1)) // 2) % mod
                ans = (ans + inv) % mod

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
N, Q = input().split(' ')
s = input()

f = [0]
for i in range(1,int(N)):
  if (s[i-1]== 'A')&(s[i] == 'C'):
    f.append(f[i-1]+1)
  else :
    f.append(f[i-1])
  
for i in range(int(Q)):
  a,b = map(int,input().split(' '))
  print(f[b-1]-f[a-1])

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;




int main() {
	
	int p, q, r;
	cin >> p >> q >> r;

	int ans = min({ p + q,q + r,r + p });

	
	cout<<ans<<endl;

}


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

using ll=long long;
const ll MOD=1e9+7;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(k),b(k);
    for(int i=0;i<k;i++) cin>>a[i]>>b[i],a[i]--,b[i]--;

    n=n*2;
    vector<int> c(n,-1);
    for(int i=0;i<k;i++) c[a[i]]=b[i],c[b[i]]=a[i];

    auto circleMax=[&](int from,int x,int y){
        int tmpx=x-from,tmpy=y-from;
        if(x<from) tmpx=x+n-from;
        if(y<from) tmpy=y+n-from;
        return tmpx<tmpy ? y : x;
    };
    vector<ll> res(n);   
    // cerr<<circleMax(1,0,7)<<endl;

    // cerr<<"#DP Start"<<endl;
    int half=n/2;
    vector<vector<ll>> dpL(n,vector<ll>(half+1));   
    vector<vector<ll>> dpM(n,vector<ll>(half+1));
    vector<vector<ll>> dpR(n,vector<ll>(half+1));
    for(int i=0;i<n;i++){
        bool b=(c[i]!=-1 && c[i]<i);
        if(b) continue;
        for(int j=0;j<n;j++)for(int k=0;k<=half;k++) dpL[j][k]=dpM[j][k]=dpR[j][k]=0;
        dpL[0][0]=1;
        int cmax=i;
        for(int j=0;j+1<n;j++){
            int id=(i+j+1)%n;
            
            if(c[id]==-1){
                for(int k=0;k+1<=half;k++){    
                    dpL[j+1][k+1]+=dpL[j][k];
                    dpM[j+1][k+1]+=dpM[j][k];
                    dpR[j+1][k+1]+=dpR[j][k];
                }
                for(int k=1;k<=half;k++){
                    dpL[j+1][k-1]+=dpL[j][k]*k;
                    dpM[j+1][k-1]+=dpM[j][k]*k;
                    dpR[j+1][k-1]+=dpR[j][k]*k;
                }
            }
            else{
                cmax=circleMax(i,cmax,c[id]);
                for(int k=0;k<=half;k++){
                    dpL[j+1][k]+=dpL[j][k];
                    dpM[j+1][k]+=dpM[j][k];
                    dpR[j+1][k]+=dpR[j][k];
                }
            }
            if(c[id]==-1 && c[i]==-1 || c[id]==i){
                for(int k=0;k<=half;k++) dpM[j+1][k]+=dpL[j][k];
            }
            if(i<id && circleMax(i,id,cmax)==id){
                dpR[j+1][0]+=dpM[j+1][0];
                dpM[j+1][0]=0;
            }
            for(int k=0;k<=half;k++) dpL[j+1][k]%=MOD,dpM[j+1][k]%=MOD,dpR[j+1][k]%=MOD;
        }
        res[i]=dpR[n-1][0];
    }
    // cerr<<"#DP END"<<endl;
    // for(int i=0;i<n;i++){
    //     cerr<<"$"<<i<<" "<<res[i]<<endl;
    // }
    
    cout<<accumulate(res.begin(),res.end(),0LL)%MOD<<endl;
    return 0;
}

Measured memory_bytes: 4608
#include <stdio.h>
int divisor(int n){
	int i,count=1;
	for (i=1;i<n/2;i++){
		if(n%i==0) count+=1;
	}
	if(count==8) return 1;
	else return 0;
}

int main()
{
	int n,num=0,a,i;
	scanf("%d",&n);
	for (i=1;i<=n;i=i+2){
		a=divisor(i);
		if(a==1) num+=1;
	}
	printf("%d\n",num);
	return 0;
}

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

using namespace std;


int main()
{
    int stones;
    cin>>stones;
    vector<int> stonedet(stones);

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


int dp[stones];
dp[0] = 0;
dp[1] = abs(stonedet[1] - stonedet[0]);

for(int i=2 ; i < stones ; i++)
{
    dp[i] = min(abs(stonedet[i] - stonedet[i-1]) + dp[i-1] , abs(stonedet[i] - stonedet[i-2])+ dp[i-2]);
}

cout<<dp[stones-1];
return 0;
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=1000010;
const ll mod=1e9+7;

int main(){  
  string s;
  cin >> s;
  int n=s.size();
  int ans=0;
  rep(i,n-1){
    if(s[i]!=s[i+1]){ans++;}
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
import math
def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
 
def Koch(n,x1,y1,x2,y2):
    if n == 0:
        plot(x1,y1)
        return
    sx = ( 2 * x1 + x2 ) / 3
    sy = ( 2 * y1 + y2 ) / 3
    tx = ( x1 + 2 * x2 ) / 3
    ty = ( y1 + 2 * y2 ) / 3
    ux = ( tx - sx ) * ( 1 / 2 ) - ( ty - sy ) * ( math.sqrt(3)/2 ) + sx
    uy = ( tx - sx ) * ( math.sqrt(3)/2 ) + ( ty - sy ) * ( 1 / 2 ) + sy
    Koch(n-1, x1,y1, sx,sy)
    Koch(n-1, sx,sy, ux,uy)
    Koch(n-1, ux,uy, tx,ty)
    Koch(n-1, tx,ty, x2,y2)
n=int(input())
Koch(n,0,0,100,0)
plot(100,0)


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

using namespace std;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, vector<long long> L)
{
    sort(L.begin(), L.end());
    long long x = 0;
    for (int i = 0; i < N-1; ++i) {
        x += L[i];
    }
    cout << (L[N-1] < x ? "Yes" : "No") << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long N;
    cin >> N;
    vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        cin >> L[i];
    }
    solve(N, move(L));
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
int H,W,N,i=0,c=0,p;
  scanf("%d",&H);
    scanf("%d",&W);
    scanf("%d",&N);
  if(H<W)p=W;
  else p=H;
  while(1){
  	i+=p;
    c++;
    if(i>=N){
      printf("%d\n",c); 
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int vis[220],n,ans,pp[220];
struct point
{
	int x,y;
} r[110],b[110];
vector<int> g[300];

int check(int now)
{
	for(int i=0; i<g[now].size(); i++)
	{
		if(!vis[g[now][i]])
		{
			vis[g[now][i]]=1;
			if(!pp[g[now][i]]||check(pp[g[now][i]]))
			{
				pp[g[now][i]]=now;
				return 1;
			}
		}
	}
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d%d",&r[i].x,&r[i].y);
	}
	for(int i=1; i<=n; i++)
	{
		scanf("%d%d",&b[i].x,&b[i].y);
	}
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=n; j++)
		{
			if(r[i].x<b[j].x&&r[i].y<b[j].y)
			{
				g[i].push_back(j+n);
			}
		}
	}
	for(int i=1; i<=n; i++)
	{
		memset(vis,0,sizeof(vis));
		if(check(i)) ans++;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

int main(){
    int n;
    cin >> n;
    ll ans = 0;

    for(ll i = 1; i <= n; i++){
        ans += i*(n-i+1);
    }

    for(int i = 0; i < n-1; i++){
        ll a, b;
        cin >> a >> b;
        if(a > b) swap(a,b);
        //ll node_num = a*(n-a+1)+b*(n-b+1);
        ll edge_num = a*(n-b+1);
        //ans += node_num;
        ans -= edge_num;
    }

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    string s, t;
    cin >> s >> t;
    ll ans = 0;
    REP(i, s.size()){
        ans += (s.at(i) != t.at(i));
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll S, W;
    cin >> S >> W;
    if(S <= W){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;       
    }

    return 0;


}

Measured memory_bytes: 3628
counts = {}

for _ in range(int(input())):
    s = input()
    counts[s] = counts.get(s, 0) + 1

words = []
highest_count = 0
#print(counts)

for word, count in counts.items():
    if count > highest_count:
        highest_count = count
        words = [word]
    elif count == highest_count:
        words.append(word)
#print(words)
print("\n".join(sorted(words)))


Measured memory_bytes: 100248
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

long floor_sum(long n, long m, long a, long b)
{
    long ans;
    if (a >= m) ans += (n-1)*n*(a/m)/2;  a %= m;
    if (b >= m) ans += n*(b/m); b %= m;
    long y_max = (a*n+b)/m, x_max = (y_max*m - b);
    if (y_max == 0) return ans;
    ans += (n-(x_max+a-1)/a)*y_max;
    ans += floor_sum(y_max, a, m, (a - x_max%a)%a);
    return ans;
}

void main()
{
	auto T = RD;
	foreach (i; 0..T)
	{
		auto N = RD;
		auto M = RD;
		auto A = RD;
		auto B = RD;
		writeln(floor_sum(N, M, A, B));
	}
	
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 3668
package main

import "fmt"

func main() {
	var x int
	fmt.Scanf("%d", &x)

	money := x
	num500yen := money / 500
	money -= num500yen * 500
	num5yen := money / 5

	happiness := 1000*num500yen + 5*num5yen
	fmt.Printf("%d\n", happiness)
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int GetMaxKouyaku(int, int);

int main()
{
    int N;
    int m;

    cin >> N >> m;

    for(int i = 1; i < N; i++)
    {
        int a;
        cin >> a;
        if(a < m)
        {
            m = GetMaxKouyaku(m, a);
        }
        else
        {
            m = GetMaxKouyaku(a, m);
        }
    }

    cout << m << endl;
    return 0;
}

int GetMaxKouyaku(int Waru, int Amari)
{
    int a = Waru % Amari;
    if(a == 0) return Amari;
    else return GetMaxKouyaku(Amari, a);
}

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

def dfs(s):
  if int(s) > N:
    return 0
  count = 1 if all(s.count(x) > 0 for x in ["7","5","3"]) else 0 

  for i in ["7","5","3"]:
    count += dfs(s+i)

  return count


print(dfs("0"))



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

int sdx[4] = {0, 1, 0, -1};
int sdy[4] = {-1, 0, 1, 0};

struct Edge{
  int src,dst,weight;
  Edge(int src,int dst,int weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator<(const Edge &e, const Edge &f) {
  return (e.weight != f.weight) ? e.weight>f.weight :
    (e.src != f.src) ? e.src<f.src : e.dst<f.src;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
const int INF = 0x7fffffff;
int w,h;
void dijkstra(const Graph &g, int s, vector<int> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF);
  dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q;

  for(Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top();
    Q.pop();
    if(prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    //cout<<"now "<<(e.dst/4)/w<<":"<<(e.dst/4)%w<<endl;
    for(Edges::const_iterator it = g[e.dst].begin(); it != g[e.dst].end(); ++it) {
      if(dist[it->dst] > e.weight + it->weight) {
	dist[it->dst] = e.weight + it->weight;
	Q.push(Edge(it->src, it->dst, e.weight + it->weight));
      }
    }
  }
}

vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for(int u = t; u >= 0; u = prev[u])
    path.push_back(u);
  reverse(path.begin(), path.end());
  return path;
}

/*
 * map[i][j][up] = g[(i*w+j)*4]
 * map[i][j][right] = g[(i*w+j)*4+1]
 * map[i][j][down] = g[(i*w+j)*4+2]
 * map[i][j][left] = g[(i*w+j)*4+3]
 */

int main() {
  while(cin>>w>>h, w||h) {
    Graph g(w*h*4);
    int t;

    for(int i=0; i<h; ++i) {
      for(int j=0; j<w; ++j) {
	cin>>t;
	if(t==4) continue;
	for(int k=0; k<4; ++k) {
	  int tk = (k+t)%4;
	  int nx = j+sdx[tk], ny = i+sdy[tk];
	  if(nx >= 0 && nx < w && ny >= 0 && ny < h )
	  g[(i*w+j)*4+k].push_back( Edge((i*w+j)*4+k, (ny*w+nx)*4+tk%4, 0) );
	}
      }
    }

    int c[4];
    cin>>c[0]>>c[1]>>c[2]>>c[3];

    for(int i=0; i<h; ++i) {
      for(int j=0; j<w; ++j) {
	for(int t=0; t<4; ++t) {
	  for(int k=0; k<4; ++k) {
	    int tk = (k+t)%4;
	    int nx = j+sdx[tk],ny = i+sdy[tk];
	    if(nx >= 0 && nx < w && ny >= 0 && ny < h)
	       g[(i*w+j)*4+k].push_back( Edge((i*w+j)*4+k, (ny*w+nx)*4+tk, c[t]) );
	  }
	}
      }
    }

    vector<int> dist;
    vector<int> prev;
    dijkstra(g, 1, dist, prev);

    int ans = min( dist[dist.size()-2], dist[dist.size()-3] );
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

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

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll ai, ao, at, aj, al, as, az;
    cin >> ai >> ao >> at >> aj >> al >> as >> az;

    ll K = ao + ai/2*2 + al/2*2 + aj/2*2;

    ll K2 = ao;
    if (ai and aj and al) {
        K2 += 3;
        ai--; aj--; al--;
    }
    K2 += ai/2*2 + al/2*2 + aj/2*2;

    cout << max(K, K2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

pair<ll, int> p[100002];
ll x[1002], d[100002];
int main(){
	ll n, T, Q, t1, t2;
	scanf("%lld%lld%lld", &n, &T, &Q);
	for(int i = 0;i < n;i++)scanf("%lld%d", &p[i].fi, &p[i].se);
	for(int i = 0;i < Q;i++)scanf("%lld", &x[i]);
	
	ll f[2] = {0, 0}, tt;
	for(int i = 0;i < n;i++){
		if(p[i].se == 1 && f[0] == 0)f[0] = 1;
		if(p[i].se == 2 && f[0] == 1){
			f[1] = (p[i-1].fi+p[i].fi)/2;
			tt = i-1;
			while(tt != -1 && p[tt].se == 1)d[tt--] = f[1];
			tt = i;
			while(tt < n && p[tt].se == 2)d[tt++] = f[1];
			i = tt;
		}
		if(i == n-1){
			tt = i;
			while(tt != -1 && p[tt].se == 1)d[tt--] = p[i].fi+T;
		}
		if(p[i].se == 2 && f[0] == 0)d[i] = p[i].fi-T;
	}
	
	ll tmp;
	for(int i = 0;i < Q;i++){
		tmp = x[i]-1;
		if(p[tmp].fi < d[tmp])d[tmp] = min(p[tmp].fi+T, d[tmp]);
		if(p[tmp].fi > d[tmp])d[tmp] = max(p[tmp].fi-T, d[tmp]);
		printf("%lld\n", d[tmp]);
	}
	return 0;
}

Measured memory_bytes: 5556
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;

int a, b, h;
int main() {
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x) for(int i=0; i<(int) (x); i++)
#define PI 3.14159265359
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> p;
	p.resize(n);
	rep(i, n)
		cin>>p[i];
	sort(p.begin(), p.end());
	int ans=0;
	rep(i, k)
		ans += p[i];
	cout << ans << endl;
	//////////////////////////////////
	//--------end--------
	//
	return 0;
}


Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class Program
{
    void Calc()
    {
        var sc = new Scanner();
        int n = sc.NextInt(), m = sc.NextInt();
        var points = new int[n];
        var targets = new int[m];
        for (int i = 0; i < m; i++)
        {
            targets[i] = sc.NextInt() - 1;
        }

        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                int a = sc.NextInt() - 1;
                points[targets[i] == a ? j : targets[i]]++;
            }
        }
        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(points[i]);
        }
    }

    static void Main()
    {
        new Program().Calc();
    }

    class Scanner
    {
        string[] s = new string[0];
        int i = 0;
        char[] cs = new char[] { ' ' };

        public string Next()
        {
            if (i < s.Length) return s[i++];
            s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return s[i++];
        }
        public int NextInt() { return int.Parse(Next()); }
        public long NextLong() { return long.Parse(Next()); }
        public double NextDouble() { return double.Parse(Next()); }
    }
}

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
using namespace std;
int main()
{
    ///MUST READ THE POINTS BELOW BEFORE SUBMIT

    ll n, k, arr[200005], i;
    cin >> n >> k;
    for(i = 1; i <= n; i++)
        cin >> arr[i];
    for(i = 1; i <= n; i++)
        arr[i] += arr[i-1];
    for(i = k; i < n; i++){
        if(arr[i]-arr[i-k] < arr[i+1]-arr[i+1-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
    ///MUST READ THE POINTS BELOW BEFORE SUBMIT
}
/**
    1. LOOK SPECIAL CASE N = 1.
    2. LOOK FOR OVERFLOW.
    3. LOOK FOR OUT OF BOUNDS.
**/


Measured memory_bytes: 5164
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 += mod-a.x) >= mod) 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 pow(ll 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, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

  mint is0 = 9;
  is0 = is0.pow(N);
  mint is9 = 9;
  is9 = is9.pow(N);

  mint is09 = 8;
  is09 = is09.pow(N);

  mint all = 10;
  all = all.pow(N);
  // cout << is0 << " " << is9 << " " << is09 << " " << all << endl;
  mint ans = all - (is0 + is9 - is09);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,K;
    cin >> N >> K;
    queue<int> que;
    veci D(10,1);
    REP(i,K) {
        int d; cin >> d;
        D[d] = 0;
    }
    for(int i = 1; i < 10; i++) if(D[i]) que.push(i);
    while(1) {
        int v = que.front();
        que.pop();
        //cout << v << endl;
        if(v >= N) {
            cout << v << endl;
            return 0;
        }
        REP(i,10) if(D[i]) que.push(v*10+i);
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

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

  int h, t = 0, m = 0, s = 0;

  for (int i = 0; i < n; i++){
    cin >> h;

    if (t >= h){
      s++;
    }
    else {
      s = 0;
    }
    m = max(m, s);
    t = h;
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 256