akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,h = map(int, input().split())
    a, b = [], []
    for _ in range(n):
        x, y = map(int, input().split())
        a.append(x)
        b.append(y)

    c = max(a)
    res = 0
    b.sort(reverse=True)
    for i in b:
        if i > c:
            h -= i
            res += 1
        if h <= 0:
            print(res)
            exit()
    if h%c == 0:
        print(res+h//c)
    else:
        print(res+h//c+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 11688
#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <cmath>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <sstream>

// short keywords

#define ipow(a,b) (ll)pow(a,b)
#define pi(a,b) pair<ll,ll>(a,b)
#define pis(a,b) pair<ll,string>(a,b)
#define pc(c,d) pair<ll,pair<ll,string>>(c,d)
#define pp(a,b,c) pair<pair<ll,ll>,ll>(pi(a,b),c)
#define ps(a,b,c) pair<string,pair<ll,ll>>(a,pi(b,c))
#define pic(c,d) pair<char,ll>(c,d)

// for loops

#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define mod 1000000007
using namespace std;

// short keywords2
typedef long long ll;
typedef set<ll>::iterator sit;
typedef vector <ll> ::iterator vit;
typedef map<ll,ll>::iterator mit;
typedef multimap<ll,ll>::iterator mmit;

class Task
{
public:
    void solve(istream& in,ostream& out)
    {
        ll n;
        in>>n;
        ll a[n],b[n];
        vector<ll>store;

        rep(i,n)
        {
            in>>a[i]>>b[i];
        }

        ll sum=0;
        rev(i,n-1,0)
        {
            if((a[i]+sum)%b[i]!=0)
            {
                ll k=(a[i]+sum)/b[i]+1;
                sum+=k*b[i]-(a[i]+sum);
        //        out<<i<<" "<<sum<<endl;
            }
        }

        out<<sum<<endl;
    }

    ll c(ll a,ll b)
    {
        ll res=0;
        reps(i,1,15)
        {
            if(a/(ll)pow(b,i)!=0)
            {
                res+=a/(ll)pow(b,i);
            }
            else
            break;
        }

        return res;
    }

    ll gcd(ll a,ll b)
    {
        if(a==0)
        {
           return b;
        }
        else
        {
           return gcd(b%a,a);
        }
    }

    bool isprime(ll n)
    {
        if(n==1 || (n%2==0 && n!=2))
        {
            return false;
        }
        else if(n==2 || n==3)
        {
            return true;
        }
        else
        {
            ll res=0;
            for(ll i=3 ;i<=(ll)sqrt(n) ;i+=2)
            {
                if(n%i==0)
                {
                    res++;
                    break;
                }
            }

            if(res==0)
            {
                return true;
            }
            else
            return false;
        }
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Task solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in,out);
	out.flush();

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dp[110][11000],n,k,sum;
int qpow(int a,int b){
	int ans=1,tmp=a;
	for(;b;b>>=1,tmp=1ll*tmp*tmp%mod)
		if(b&1)ans=1ll*ans*tmp%mod;
	return ans;
}
int main(){
	scanf("%d%d",&n,&k);
	dp[n+1][0]=1,sum=0;
	for(int i=n;i>=1;sum+=(k+sum)/i,--i)
		for(int j=0;j<=sum;++j)if(dp[i+1][j])
			for(int a=0;a<=k;++a)
				if(a>i)dp[i][j]=(dp[i][j]+dp[i+1][j])%mod;
				else dp[i][j+(a+j)/i]=(dp[i][j+(a+j)/i]+dp[i+1][j])%mod;
	int ans=0;
	for(int i=0;i<=sum;++i)
		ans=(ans+1ll*dp[1][i]*i)%mod;
	printf("%d",(1ll*k*qpow(k+1,n)%mod*n%mod*(mod+1)/2%mod-ans+mod)%mod);
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;
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; }

const long long INF = 1LL << 60;

#define MOD 1000000007

int N;

int main(){

    int N; cin >> N;
    int M; cin >> M;

    vector<bool> safe(N+1, true);
    vector<int> dp(N+10, 0);

    int m;
    for(int i = 0; i < M; ++i){
        cin >> m;
        safe[m] = false;
    }

    dp[0] = 0;

    if(safe[1]) dp[1] = 1;
    if(safe[1] && safe[2]) dp[2] = 2;
    if(!safe[1] && safe[2]) dp[2] = 1;

    for(int i = 3; i < N+5; i++){
        if(safe[i]) dp[i] += dp[i-1] %MOD;
        if(safe[i]) dp[i] += dp[i-2] % MOD;
    }

    cout << dp[N] % MOD << endl;
}

Measured memory_bytes: 640
let (n1, n2) = (3, 9)
let n_limit = 100
let mdt = Array.make_matrix n2 n2 0
let path = Array.make n_limit 0
let dx = [| 0; -1; 0; 1 |]
let dy = [| 1; 0; -1; 0 |]
let dir = [| "r"; "u"; "l"; "d" |]

type puzzle = { tbl : int array; space : int; md : int }

let dfs puzzle limit =
  let rec doit depth prev pzl =
    if pzl.md = 0 then true
    else if depth + pzl.md > limit then false
    else begin
      let (sx, sy) = (pzl.space / n1, pzl.space mod n1) in
      let { tbl; md } = pzl in
      let swap tbl i j = let t = tbl.(i) in tbl.(i) <- tbl.(j); tbl.(j) <- t in
      let rec move r =
        if r = 4 then false
        else
          let (tx, ty) = (sx + dx.(r), sy + dy.(r)) in
          if tx < 0 || ty < 0 || tx >= n1 || ty >= n1 then move (r + 1)
          else if max prev r - min prev r = 2 then move (r + 1)
          else begin
            let (space, num) = (tx * n1 + ty, sx * n1 + sy) in
            let md = md - mdt.(space).(tbl.(space) - 1) in
            let md = md + mdt.(num).(tbl.(space) - 1) in
            let tbl = Array.copy tbl in
            swap tbl space num;
            if doit (depth + 1) r { tbl; space; md } then begin
              path.(depth) <- r;
              true
            end else move (r + 1)
          end in
      move 0
    end in
  doit 0 (-n_limit) puzzle

let idastar tbl space =
  let (_, md) =
    Array.fold_left (fun (i, sum) e ->
      (i + 1, if e = n2 then sum else sum + mdt.(i).(e-1)))
      (0, 0) tbl in
  let pzl = { tbl; space; md } in
  let rec doit limit =
    if limit > n_limit then assert false
    else if dfs pzl limit then begin
      let str = ref "" in
      for i = 0 to limit - 1 do
        str := !str ^ dir.(path.(i));
      done;
      !str
    end else doit (limit + 1) in
  doit pzl.md

let () =
  for i = 0 to n2 - 1 do
    for j = 0 to n2 - 1 do
      mdt.(i).(j) <- abs (i / n1 - j / n1) + abs (i mod n1 - j mod n1)
    done
  done;
  let tbl = Array.make n2 0 in
  let rec doit i space =
    if i = n2 then space
    else begin
      let x = Scanf.scanf "%d " (fun i -> i) in
      let (x, space) = if x = 0 then (n2, i) else (x, space) in
      tbl.(i) <- x;
      doit (i + 1) space
    end in
  doit 0 0 |> idastar tbl |> String.length |> Printf.printf "%d\n"

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, k = LI()
a = LI()

check_num = [-1] * n
idx = 0
cnt = 1
while 1:
    idx = a[idx] - 1
    if check_num[idx] != -1:
        s = check_num[idx] - 1
        break
    check_num[idx] = cnt
    cnt += 1
cnt -= 1
if cnt >= k:
    for i in range(n):
        if check_num[i] == k:
            print(i+1)
            break
else:
    x = cnt - s
    y = (k - (s + 1)) % x
    for i in range(n):
        if check_num[i] == s + y + 1:
            print(i+1)
            break

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

int main(){
    int n,k; cin >> n >> k;
    vector<long long> x(n); rep(i,n) cin >> x[i];
    long long ans = 1e18;
    rep(i,n-k+1){
        if(x[i+k-1]-x[i] + min(abs(x[i+k-1]),abs(x[i])) < ans) ans = x[i+k-1]-x[i] + min(abs(x[i+k-1]),abs(x[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : k : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  (r : s : p : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    score :: Maybe RSP -> Int
    score (Just R) = r
    score (Just S) = s
    score (Just P) = p
    score _        = 0
  as <- map unsafeCharToRSP <$> getLine :: IO [RSP]
  let
    (as', as'') = splitAt k as
    bs = map (Just . suc) as' ++ map f (zip as'' bs) :: [Maybe RSP]
      where
        f :: (RSP, Maybe RSP) -> Maybe RSP
        f (a, Just b) | suc a == b = Nothing
        f (a, _)                   = Just . suc $ a
  print . sum . map score $ bs

data RSP = R | S | P deriving Eq

unsafeCharToRSP :: Char -> RSP
unsafeCharToRSP 'r' = R
unsafeCharToRSP 's' = S
unsafeCharToRSP 'p' = P

suc :: RSP -> RSP
suc R = P
suc S = R
suc P = S

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%d", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long
#define float long double 
#define ll long long

const int inf = (int) 1e16;
const int upper = (int) 4e5 + 15;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	int n, m; cin >> n >> m;

	char arr[n + 1][m + 1];
	for (int i = 1; i <= n; i += 1) {
		for (int j = 1; j <= m; j += 1) {
			cin >> arr[i][j];
		}
	}

	int dp[n + 1][m + 1];
	memset(dp, 0, sizeof dp);
	dp[1][1] = 1;

	for (int i = 1; i <= n; i += 1) {
		for (int j = 1; j <= m; j += 1) {
			if (arr[i][j] == '#') continue;
			if (i - 1 >= 1) dp[i][j] += dp[i - 1][j];
			if (j - 1 >= 1) dp[i][j] += dp[i][j - 1];

			dp[i][j] %= M;
		}
	}

	cout << dp[n][m];
 	end_routine();	
}

Measured memory_bytes: 9088
def f12():
    N, M, C=map(int, input().split())
    B = [int(i) for i in input().split()]
    cnt=0
    for i in range(N):
        A=[int(j) for j in input().split()]
        if sum([A[j]*B[j] for j in range(M)])+C > 0:
            cnt += 1
    print(cnt)

def main():
    f12()

main()

Measured memory_bytes: 3060
#! env/bin/local python3
# -*- coding: utf-8 -*-

n = int(input())

restaurants = {}
for i in range(1, n + 1):
    info = input().split()
    restaurants[i] = {
        # 'name': info[0] + str(100 - int(info[1]))
        'name': info[0],
        'score': int(info[1])
    }

# {1: hoge} -> ([1, hoge])
results = sorted(restaurants.items(), key=lambda x: (x[1]['name'], 100 - x[1]['score']))
output = [r[0] for r in results]
print(*output, sep='\n')


Measured memory_bytes: 9132
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int n, d, x;
    cin >> n;
    cin >> d >> x;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    
    int sum = x;
    FOR(i, 1, d) {
        REP(j, n) {
            if(a[j] == 1) sum++;
            if(i%a[j] == 1) sum++;
        }
    }
    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int calc(int N, int a) {

   int amari = 0;
   int count = 0;
   while (amari == 0) {
      amari = N%a;
      N /= a;
      count++;
   }
   return count-1;
}

int main() {
   int N;
   cin >> N;
   int ans = 36;
   for (int i = 0; i < N; i++) {
      int tmp;
      cin >> tmp;
      int tmp2 = calc(tmp, 2);
      if (tmp2 < ans) ans = tmp2;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

// 桁和
int digsum10(int n) {
  int res = 0;
  while (n>0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  vector<int> ans(N-1);
  for (int A=1; A<N; A++) {
    int B = N-A;
    ans[A-1] = digsum10(A)+digsum10(B);
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main(){
		new AOJ1130().doIt();
	}
	
	class AOJ1130{
		
		int w,h;
		char[][] map;
		int sx[] = {1,0,-1,0};
		int sy[] = {0,1,0,-1};
		void dfs(int x,int y){
			map[y][x] = '*';
			for(int i=0;i<4;i++){
				int nx = x+sx[i];
				int ny = y+sy[i];
				if(nx<0||nx>=w||ny<0||ny>=h)continue;
				if(map[ny][nx]=='#'||map[ny][nx]=='*')continue;
				dfs(nx,ny);
			}
		}
		
		void solve(){
			int startx=0,starty=0;
			for(int i=0;i<h;i++)for(int s=0;s<w;s++)if(map[i][s]=='@'){
				startx = s;starty = i;break;
			}
			dfs(startx,starty);
			int cnt = 0;
			for(int i=0;i<h;i++)for(int s=0;s<w;s++)if(map[i][s]=='*')cnt++;
			System.out.println(cnt);
		}
		
		void doIt(){
			while(in.hasNext()){
				w = in.nextInt();
				h = in.nextInt();
				if(w+h==0)break;
				map = new char[h][w];
				for(int i=0;i<h;i++)map[i] = in.next().toCharArray();
				solve();
			}
		}
	}
	
}

Measured memory_bytes: 27412
#include <stdio.h>

#define MAX 1000000

int main(void){
  char p[MAX];
  int n,i,c;
  memset((void *)p,1,MAX);
  p[1] = 0;
  for(n = 2,c = 0;n*n <= MAX;n++){
    if(p[n] == 1){
//      c += 1;
      for(i = n+n;i <= MAX;i += n)
        p[i] = 0;
    }
//    p[n] = c;
  }

  while(scanf("%d",&n) != EOF){
    for(i = 1,c = 0;i <= n;i++)
      if(p[i] == 1)c++;
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 1580
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define f(i,n) for(ll i=0;i<n;i++)
    #define fz for(ll j=i+1;j<n;j++)
    #define f2(i,n) for(ll i=1;i<=n;i++)
    #define endl "\n"
    #define vll vector <ll>
    #define sz(a) (ll)a.size()
    #define mod 1000000007
    #define pb push_back
    #define inf 1e13+5

    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);}
    ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod; b/=2;a=a*a%mod;}return ans;}
    ll inverse(ll a, ll p){return fexp(a, p-2);} 

    
    
    void solve(){
      ll k;cin>>k;
      string s;cin>>s;
      if(sz(s)<=k){
          cout<<s<<endl;
          return;
      }
      f(i,k){
          cout<<s[i];
      }
      cout<<"...";

    }


    int main(){
        ios_base::sync_with_stdio(0) ;
        cin.tie(0) ; cout.tie(0) ;


        ll t;
        t=1;
        // cin>>t;
        while(t--){
            solve();
        }

        
        return 0;
    }

Measured memory_bytes: 3604
#![allow(unused_mut)]

use std::io::{self, BufWriter, Write};
use std::error::Error;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() -> Result<(), Box<dyn Error>> {
    let sout = io::stdout();
    let mut o = BufWriter::new(sout.lock());
  
    input! {
        // input
        n : usize,
        a : [i32; n],
    }

    // operate
    let mut c = 0;
    for (i, v,) in a.iter().enumerate() {
        if i & 1usize == 0usize && v & 1 == 1 {
            c = c + 1;
        };
    };

    let line = format!("{}\n", c);
    o.write(line.as_bytes())?;
    Ok(())
  }


Measured memory_bytes: 2172
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0; i<n; i++) {
      cin >> v[i];
  }
  int m;
  cin >> m;
  vector<int> vc(m);
  for(int i=0; i<m; i++) {
      cin >> vc[i];
  }
  for(int i=0; i<m; i++) {
      if(binary_search(v.begin(),v.end(),vc[i])) {
          continue;
      }
      else {
          cout << 0 << endl;
          return 0;
      }
  }
  cout << 1 << endl;
}


Measured memory_bytes: 4384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
int n;
ll num[200005],f[200005][3],ans=-1e18;
ll b(int a){if(a&1)return 1;return 0;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&num[i]);
	}
	if(n%2==0)
	{
		for(int i=1;i<=n;i++)
		{
			f[i][0]=f[i-1][0]+b(i)*num[i];
			f[i][1]=max(f[i-1][1]+b(i-1)*num[i],f[i-1][0]);
		}
		printf("%lld",f[n][1]);
		
	}
	else
	{
		
		for(int i=1;i<=n;i++)
		{
			f[i][0]=f[i-1][0]+b(i)*num[i];
			f[i][1]=max(f[i-1][1]+b(i-1)*num[i],f[i-1][0]);
			if(i>1)f[i][2]=max(f[i-2][2]+b(i-2)*num[i],f[i-1][1]);
			else f[i][2]=max(f[i-1][2]+b(i-2)*num[i],f[i-1][1]);
//			cout<<f[i][0]<<" "<<f[i][1]<<" "<<f[i][2]<<endl;
		}
		printf("%lld",f[n][2]);
	}
	return 0;
} 

Measured memory_bytes: 10036
import java.util.*;

public class Main {
    public static void main(String[] args){
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int Y = sc.nextInt();
        
        boolean flag = false;
        
        for(int i = 0; i <= N; i++){
            for(int j = 0; j <= (N-i); j++){
                for(int k = 0; k <= (N-i-j) ; k++){
                    int sum = 0;
                    int count = 0;
                     
                    sum = (10000 * i) + (5000 * j) + (1000 * k);
                    count = i + j + k;
                    if(sum == Y && count == N){
                        System.out.println(i + " " + j + " " + k);
                        flag = true; 
                        break;
                    }
                }
                
                if(flag){
                    break;
                }
            }
            
            if(flag){
                break;
            }
        }
        
        if(flag == false){
            System.out.println("-1 -1 -1");
        }
        
    }
    
}


Measured memory_bytes: 27100
#include <iostream>

using namespace std;

int main(){
	
int d[103] = {0};
int n;
int m = 0;
while(cin >> n){
	d[n]++;
	if(d[n] > m) m = d[n];
}
for(int i = 1;i < 101;i++){
	if(d[i] == m) cout << i << endl;
}
}


Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;

int main()
{
	ll n,m,p,ans=0ll;
	scanf("%lld%lld",&n,&m);
	for(p=1;p<=sqrt(m);p++)
	{
		if(!(m%p))
		{
			if(m/p>=n)	ans=max(ans,p);
			if(p>=n)	ans=max(ans,m/p);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
# :::::::::  :::   :::  ::::::::       ::::::::::: ::::    :::  ::::::::  :::    ::: :::::::::: 
# :+:    :+: :+:   :+: :+:    :+:          :+:     :+:+:   :+: :+:    :+: :+:    :+: :+:        
# +:+    +:+  +:+ +:+  +:+    +:+          +:+     :+:+:+  +:+ +:+    +:+ +:+    +:+ +:+        
# +#++:++#:    +#++:   +#+    +:+          +#+     +#+ +:+ +#+ +#+    +:+ +#+    +:+ +#++:++#   
# +#+    +#+    +#+    +#+    +#+          +#+     +#+  +#+#+# +#+    +#+ +#+    +#+ +#+        
# #+#    #+#    #+#    #+#    #+#          #+#     #+#   #+#+# #+#    #+# #+#    #+# #+#        
# ###    ###    ###     ########       ########### ###    ####  ########   ########  ########## 


D = int(input())
if D == 25:
    print("Christmas")
elif D == 24:
    print("Christmas Eve")
elif D == 23:
    print("Christmas Eve Eve")
elif D == 22:
    print("Christmas Eve Eve Eve")

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC156
{
	class A
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
			var attendanceCount = input[0];
			var displayRating = input[1];

			var border = 10;
			if (attendanceCount >= border)
			{
				Console.WriteLine(displayRating);
			}
			else
			{
				Console.WriteLine(displayRating + ( 100 * ( 10 - attendanceCount) ));
			}
		}
	}
}


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

int main() {
   char S[6];

   scanf("%s", S);

   if(S[2] == S[3] && S[4] == S[5]) {
      printf("Yes\n");

   }else {
      printf("No\n");

   }
   return 0;
}


Measured memory_bytes: 1644
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, x, y;
vector<int> ans;
int f(int a, int b){
    int res = b-a;
    int t = abs(a-x) + abs(b-y) + 1;
    return min(res, t);
}
int main(void){
    cin >> n >> x >> y;
    ans.assign(n, 0);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            ans[f(i, j)]++;
        }
    }
    for(int k=1;k<=n-1;k++){
        cout << ans[k] << endl;
    }
    
}


Measured memory_bytes: 256
### classes

class Pt3D
  attr_accessor :x, :y, :z

  def initialize() end
  def initialize(x, y, z) @x = x; @y = y; @z = z end

  def ==(pt) @x == pt.x && @y == pt.y && @z == pt.z end
  def +(pt) Pt3D.new(@x + pt.x, @y + pt.y, @z + pt.z) end
  def -(pt) Pt3D.new(@x - pt.x, @y - pt.y, @z - pt.z) end
  def -@() Pt3D.new(-@x, -@y, -@z) end
  def *(t) Pt3D.new(@x * t, @y * t, @z * t) end
  def /(t) Pt3D.new(@x / t, @y / t, @z / t) end
  def dot(v) @x * v.x + @y * v.y + @z * v.z end
  #def cross(v) @x * v.y - @y * v.x end
  def d2() @x * @x + @y * @y + @z * @z end
  def d() Math.sqrt(d2()) end
  def normalize() self / d() end
  def to_s() "(#{@x}, #{@y}, #{@z})" end
  #def hash() @y * W + @x end
end

### main

loop do
  n = gets.to_i
  break if n == 0

  u, v, w = gets.split.map(&:to_f)

  sphs = []
  n.times do
    xi, yi, zi, ri = gets.split.map(&:to_f)
    sphs << [Pt3D.new(xi, yi, zi), ri, ri * ri]
  end
  
  cp = Pt3D.new(0.0, 0.0, 0.0)
  cv = Pt3D.new(u, v, w).normalize
  #p cv.to_s

  loop do
    crpts = []

    for i in (0...n)
      pt, r, r2 = sphs[i]
      t = cv.dot(pt - cp)
      q = (cv * t) + cp
      qd2 = (pt - q).d2
      
      if qd2 <= r2
        s = t - Math.sqrt(r2 - qd2)
        crpts << [s, i] if s >= 0.0
      end
    end
    #p crpts

    break if crpts.empty?

    s, i = crpts.min
    crpt = cv * s + cp
    pt, r, r2 = sphs[i]

    nv = (crpt - pt).normalize

    # R=F+2(&#8722;F.N)N
    rv = cv + nv * (-2 * cv.dot(nv))

    cp = crpt
    cv = rv
  end

  puts [cp.x, cp.y, cp.z].map{|f| "%.4f" % f}.join(' ')
end

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

int main() {
  string N;
  cin >> N;
  int ans1 = 0, ans2 = (N[0] - '0' - 1) + (9 * (N.size() - 1));
  for (int i = 0; i < N.size(); i++) ans1 += N[i] - '0';
  cout << max(ans1, ans2) << endl;
}

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

    int n, l;
    cin >> n >> l;

    int ans = 0;
    for(int i=1; i<=n; i++){
        ans += l + i - 1;
    }
    if(l >= 0){
        cout << ans - l << endl;
    }
    else if(l + n - 1 < 0){
        cout << ans - ((n - 1) + l) << endl;
    }
    else{
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
LS = len(S)
LT = len(T)
ans = LS

for n in range(1+LS-LT):
  count = 0
  for s,t in zip(S[n:n+LT],T):
    if s!=t:
      count+=1
  ans = min(ans,count)

print(ans)

Measured memory_bytes: 8964
N = int(input())
S = [input() for _ in range(N)]
S.sort()
check = [True]*N
item = ""
item_ = ""
dict_item = {}
cnt = 0

for i in range(N):
  item_ = S[i]
  if item_ != item:
    item = item_
    cnt += 1
print(cnt)

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

int ctoi(const char c) {
  if ('0' <= c && c <= '9') return (c - '0');
  return -1;
}

int main() {
  string N;
  cin >> N;
  ll sum = 0;
  rep(i, N.size()) sum += ctoi(N.at(i));
  string ans = sum % 9 == 0 ? "Yes" : "No";
  cout << ans << endl;
}


Measured memory_bytes: 3752
n = input()
nums_str = input()
num_str_list = nums_str.split(" ")
num_list = list(map(lambda x: int(x), num_str_list))
num_list.sort()

temp = num_list[0]
num_list.pop(0)
for num in num_list:
    temp += num
    temp /= 2

print(temp)


Measured memory_bytes: 3060
def mm(str, max, idx, len)
    return [str] if idx == len

    re = []
    c  = "a"
    max.times do
        s = str.clone
        s[idx] = c
        re += mm(s, max, idx + 1, len)
        c = c.next
    end

    str[idx] = c
    re += mm(str, max + 1, idx + 1, len)
    re
end

n = gets.to_i
str = Array.new(n)
str[0] = "a"

puts mm(str, 1, 1, n).map(&:join)

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

using namespace std;

int main() {
	int n, x;
	while (cin >> n >> x && n) {
		int ways = 0;
		for (int i = 1; i <= n; ++i) {
			for (int j = i+1; j <= n; ++j) {
				for (int k = j+1; k <= n; ++k) {
					if (i + j + k == x) {
						++ways;
					}
				}
			}
		}
		cout << ways << '\n';
	}
}


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

using namespace std;


#define M_DEBUG if(0)

int L_MAX = 2 * 100000;


int main() {
    int n = 0;
	cin >> n;
	assert(1 <= n && n <= L_MAX);

	vector<int> a_list;
	a_list.push_back(-1); // 問題のインデックスと一致させたいので 1 から始める
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		assert(a == 0 || a == 1);
		a_list.push_back(a);
	}

	vector<int> box_list(n + 1, -1); // 問題のインデックスと一致させたいので 1 から始める。そのため一戸余計に確保
	int count = 0;
	// 尻から決めていく 
	for (int i = n ; i > 0; i--) {
		M_DEBUG cout << "i = " << i << endl; 
		int sum_i = 0;
		// box_list[j] = 0/1 で分岐
		for (int j = i + i; j <= n; j += i) {
			M_DEBUG cout << "\tsum[" << i << "] += box_list[" << j << "] : " << box_list[j] << endl;
			sum_i += box_list[j];
		}

		if (sum_i % 2 == a_list[i]) { // box_list[j] = 0 と仮定する√
			box_list[i] = 0;
		} else { // box_list[j] = 1 と仮定する√
			box_list[i] = 1;
			M_DEBUG cout << "\tsum[" << i << "] += box_list[" << i << "] : " << box_list[i] << endl;
			sum_i += box_list[i];
			count++;
		}
		M_DEBUG cout << "\tsum[" << i << "] = " << sum_i << endl;
		M_DEBUG cout << "\ta_list[" << i << "] = " << a_list[i] << endl;

		if (sum_i % 2 != a_list[i]) {
			// いい入れ方が存在しない
			cout << "-1" << endl;
			return 0;
		}
	}

	cout << count << endl;
	if (count > 0) {
		for (int i = 1; i <= n; i++) {
			if (box_list[i] == 1) {
				cout << i << " ";
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 2676
# -*- coding: utf-8 -*-
import sys
import itertools
input = sys.stdin.readline


def main():
    n = int(input())
    towns = []
    for _ in range(n):
        x, y = map(int, input().split())
        towns.append((x, y))

    matrix = [[0] * n for i in range(n)]
    for i in range(n - 1):
        for j in range(i + 1, n):
            l = ((towns[i][0] - towns[j][0]) ** 2 +
                 (towns[i][1] - towns[j][1]) ** 2) ** 0.5
            matrix[i][j] = l
            matrix[j][i] = l

    towns_id = list(range(n))
    all_lengh = []
    for v in itertools.permutations(towns_id):
        l = 0
        for i in range(n-1):
            l += matrix[v[i]][v[i+1]]
        all_lengh.append(l)

    result = sum(all_lengh) / len(all_lengh)
    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4400
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = if N % 2 == 0 { N } else { 2 * N };

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


Measured memory_bytes: 4352
n,a,b = map(int, input().split())
if (b-a)%2==0:
    ans = (b-a)//2
else:
    # ans = min(n-a, b-1)
    # ans = min(ans, min(a-1, n-b) + (b-a-1)//2 + 1)
    ans = min(a-1, n-b) + 1 + (b-a-1)//2
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n , m , dp[N];
vector<vector<int> > v(N);
int calc(int i){
    dp[i] = 0;
    for(int j = 0 ;j < v[i].size() ; j++){
        if(dp[v[i][j]] == -1)
            dp[i] = max(dp[i] , 1 + calc(v[i][j])); 
        else dp[i] = max(dp[i] , 1 + dp[v[i][j]]);
    }
    return dp[i];
}
int main(){
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int x , y;
        cin >> x >> y;
        v[x].push_back(y);
    }
    memset(dp, -1 , sizeof dp);
    int mx = 0;
    for(int i = 1 ; i <= n ; i++){
        if(dp[i] != -1){
            mx = max(dp[i] , mx);
        }else{
            mx = max(mx , calc(i));
        }
    }
    cout<<mx;
    return 0;
}

Measured memory_bytes: 7424
import math
import heapq
import bisect
from collections import defaultdict, Counter, deque
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def update_all(self):
        n = len(self.par)
        for i in range(n):
            self.par[i] = self.find(i)

def main():
    a,b,m = getList()
    anums = getList()
    bnums = getList()
    ans = min(anums) + min(bnums)
    for i in range(m):
        x,y,c = getList()
        tmp = anums[x-1] + bnums[y-1] - c
        if ans > tmp:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

"""
10
203941992 742164984
670850202 743524472
687298546 744891559
676493045 744182895
385467254 742631752
740505911 744926772
425723256 743348462
225362543 742332848
399450535 742706299
563528474 743419738
"""

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

typedef long long ll;

int gcd(int a, int b) {
	//cout << a <<" "<< b << endl;
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

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

	cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,a[200005],w[2][19][200005];
struct O{int x,y;};
vector <O> f; vector <int> e[100005];
struct cmp{
	bool operator()(int a,int b){
		return f[a].x>f[b].x;
	}
};
priority_queue <int,vector<int>,cmp> d;
int Min(int x,int y){return a[x]<a[y]?x:y;}
int get(int o,int l,int r){
	int i=log2(r-l+1);
	return Min(w[o][i][r],w[o][i][l-1+(1<<i)]);
}
int dfs(int o,int l,int r){
	if (l>r) return 0;
	int p=get(o,l,r),q=get(o^1,p+1,r),x=f.size(),y;
	f.push_back({a[p],a[q]});
	y=dfs(o,l,p-1); if (y) e[x].push_back(y);
	y=dfs(o^1,p+1,q-1); if (y) e[x].push_back(y);
	y=dfs(o,q+1,r); if (y) e[x].push_back(y);
	return x;
}
int main(){
	scanf("%d",&n); a[0]=n+3;
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	for (int i=1;i<=n;++i)
		w[0][0][i]=i&1?0:i,w[1][0][i]=i&1?i:0;
	for (int k=0;k<2;++k)
	for (int i=1;i<18;++i)
	for (int j=1<<i;j<=n;++j)
	w[k][i][j]=Min(w[k][i-1][j-(1<<i-1)],w[k][i-1][j]);
	d.push(dfs(1,1,n));
	while (!d.empty()){
		n=d.top(); d.pop();
		printf("%d %d ",f[n].x,f[n].y);
		for (int i=0;i<e[n].size();++i) d.push(e[n][i]);
	}
	puts("");
	return 0;
}

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

namespace V0013{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var stk = new Stack<int>();
            int input;
            while((input = sr.Next<int>()) != int.MinValue){
                if(input == 0) Console.WriteLine(stk.Pop());
                else stk.Push(input);
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T) typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T) Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var result = new T[x];
            for(var i = 0; i < x; ++i){
                result[i] = Next<T>();
            }
            return result;
        }
    }
}

Measured memory_bytes: 10660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,a;
  set<int> s;
  s.clear();
  cin>>n;
  fr(i,n){
    cin>>a;
    if(s.count(a)) s.erase(a);
    else s.insert(a);
  }
  cout<<s.size()<<endl;
}

Measured memory_bytes: 4864
class UnionFind:
    def __init__(self, n: int) -> None:
        self.par = [-1 for i in range(n)]

    def root(self, a):
        if self.par[a] < 0:
            return a
        else:
            self.par[a] = self.root(self.par[a])
            return self.par[a]

    def size(self, a):
        return -self.par[self.root(a)]

    def connect(self, a, b):
        a = self.root(a)
        b = self.root(b)
        if a == b:
            return False

        if self.size(a) < self.size(b):
            a, b = b, a

        self.par[a] = self.par[a] + self.par[b]
        self.par[b] = a

        return True


def main() -> None:
    N, M = map(int, input().split())
    t = [tuple(map(int, input().split())) for _ in range(M)]
    ans = [0 for _ in range(M)]
    ans[-1] = N * (N - 1) // 2
    uni = UnionFind(N)
    for i in reversed(range(1, M)):
        ans[i - 1] = ans[i]
        a = t[i][0] - 1
        b = t[i][1] - 1
        if uni.root(a) != uni.root(b):
            ans[i - 1] = ans[i - 1] - uni.size(a) * uni.size(b)
            uni.connect(a, b)

    for v in ans:
        print(v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23716
n = int(input())
a_ls = list(map(int, input().split()))
num_mul4 = 0
num_even_not4 = 0
num_odd = 0
for i in range(n):
    if a_ls[i] % 4 == 0:
        num_mul4 += 1
    elif a_ls[i] % 2 == 0:
        num_even_not4 += 1
    else:
        num_odd += 1
res = 'No'
if num_even_not4 == 0:
    if num_odd <= num_mul4 + 1:
        res = 'Yes'
else:
    num_odd += 1
    if num_odd <= num_mul4 + 1:
        res = 'Yes'
print(res)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isPossible(x) printf("%s\n",(x) ? "Possible" : "Impossible")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
// #define INF (1<<29)

const long long INF = 1LL<<60;

#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
// const int mod =(int)998244353;
const int mod =(int)1e9+7;

const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(a<0)a=-a;
    if(b<0)b=-b;
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
  if(a<0)a=-a;
  if(b<0)b=-b;
    ll g;g=gcd(a,b);
    return b/g*a;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}
ll RS(ll N,ll P,ll m){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,m);
            return t*t%m;
        }else{
            return N*RS(N,P-1,m)%m;
        }
    }
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first!=b.first){
        return a.first>b.first;
    }else{
        return a.second>b.second;
    }
}

int main() {
    ios::sync_with_stdio(false);
    int N;cin>>N;
    cout<<N+N*N+N*N*N<<endl;
    return 0;
} 


Measured memory_bytes: 3644
//tumi cheye acho tai ami pothe hete jai
//hete hete bohudur bohudur jete chai
//ami_nafi

#include <bits/stdc++.h>
using namespace std;
#define pii pair <int, int>
#define vi vector <int>
#define pb push_back
typedef long long ll;
const int M = 1e6 + 20, MOD = 1e9 + 20;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
   int a, b;
   cin >> a >> b;
   int k = a * b - a - b + 1;
   cout << k << endl;



return 0;
}


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

typedef long long LL;
const int N = 2000005, mod = 1000000007;

#define x first
#define y second

int factor[N], ifactor[N];
void reduce(int &x) { x += x >> 31 & mod; }
int pow(int x, int y, int ans = 1) {
	for (; y; y >>= 1, x = (LL) x * x % mod)
		if (y & 1) ans = (LL) ans * x % mod;
	return ans;
}
void init(int n) {
	factor[0] = 1;
	for (int i = 1; i <= n; ++i)
		factor[i] = (LL) factor[i - 1] * i % mod;
	ifactor[n] = pow(factor[n], mod - 2);
	for (int i = n; i; --i)
		ifactor[i - 1] = (LL) ifactor[i] * i % mod;
}

typedef std::pair<int, int> point;
point operator - (const point &a, const point &b) { return point(a.x - b.x, a.y - b.y); }
int c(point p) { return (LL) factor[p.x + p.y] * ifactor[p.x] % mod * ifactor[p.y] % mod; }

#define y1 dai_ginga_uchu_no_1_variable

int x1, x2, x3, x4, x5, x6;
int y1, y2, y3, y4, y5, y6;

int solve(point A, point B) {
	LL sum = 0;
	for (int i = x3; i <= x4; ++i) {
		// enter
		sum -= (LL) (i + y3) * c(point(i, y3 - 1) - A) % mod * c(B - point(i, y3)) % mod;
		// leave
		sum += (LL) (i + y4 + 1) * c(point(i, y4) - A) % mod * c(B - point(i, y4 + 1)) % mod;
	}
	for (int i = y3; i <= y4; ++i) {
		// enter
		sum -= (LL) (x3 + i) * c(point(x3 - 1, i) - A) % mod * c(B - point(x3, i)) % mod;
		// leave
		sum += (LL) (x4 + i + 1) * c(point(x4, i) - A) % mod * c(B - point(x4 + 1, i)) % mod;
	}
	return sum %= mod, sum + (sum >> 63 & mod);
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	init(2000002);
	std::cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6;
	std::cin >> y1 >> y2 >> y3 >> y4 >> y5 >> y6;
	static point f[4], g[4];
	f[0] = point(x1 - 1, y1 - 1), f[2] = point(x2, y2);
	f[1] = point(x1 - 1, y2), f[3] = point(x2, y1 - 1);
	g[0] = point(x6 + 1, y6 + 1), g[2] = point(x5, y5);
	g[1] = point(x6 + 1, y5), g[3] = point(x5, y6 + 1);
	LL ans = 0;
	for (int i = 0; i < 4; ++i)
		for (int j = 0; j < 4; ++j)
			ans += ((i ^ j) & 1 ? -1 : 1) * solve(f[i], g[j]);
	std::cout << (ans %= mod, ans += ans >> 63 & mod) << '\n';
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,x,y,i,j,ima;
  cin>>n>>x>>y;
  int a[n];
  for(i=0;i<n;i++){
    a[i]=0;
  }
  for(i=1;i<=n-1;i++){
    for(j=i+1;j<=n;j++){
      ima=min(j-i,abs(i-x)+abs(j-y)+1);
      a[ima]++;
    }
  }
  for(i=1;i<=n-1;i++){
    cout<<a[i]<<endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int H = sc.nextInt();
        int W = sc.nextInt();
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int i = 0; i < N; i++)
            a[i] = sc.nextInt();
        sc.close();
        int[][] c = new int[H][W];

        int h = 0;
        int w = 0;
        int count = 0;
        while(count < N){
            while(a[count] > 0){
                c[h][w] = count+1;
                a[count]--;
                w++;
                if(w == W){
                    h++;
                    w = 0;
                }
                
            }
            count++;
        }
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(i%2 == 0)
                    System.out.print(c[i][j]+ " ");
                else
                    System.out.print(c[i][W-j-1]+ " ");
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 34536
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<ll, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
int main() {
	ll cnt = 0;
	int n; cin >> n;
	ll a[100000], b[100000];
	rep(i, n) {
		cin >> a[i] >> b[i];
	}
	per(i, n) {
		ll t = (a[i] + cnt) % b[i];
		if (t == 0)continue;
		else {
			cnt += b[i] - t;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1920
h, n = list(map(int, input().split()))
ab = []
for i in range(n):
    a, b = list(map(int, input().split()))
    ab.append((a, b))
ab.sort(key=lambda ab: (ab[0]/ab[1], -ab[0]), reverse=True)

import sys
sys.setrecursionlimit(100000000)

mem = [-1 for i in range(h)]
def solve(h):
    best = float('inf')
    for a,b in ab:
        if h - a <= 0:
            val = b
        else:
            if mem[h - a] != -1:
                val = b + mem[h - a]
            else:
                mem[h - a] = solve(h - a)
                val = b + mem[h-a]
        if val < best:
            best = val
        else:
            break
    return best

print(solve(h))


Measured memory_bytes: 12532