akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <sstream>
#include <vector>

using namespace std;

int to_i(const string &s) {
    istringstream is(s);
    int n; is >> n;
    return n;
}

string to_s(int n) {
    ostringstream os;
    os << n;
    return os.str();
}

int N;
vector<int> as;
bool input() {
    cin >> N;
    if (N == 0) return false;
    as.clear(); as.resize(N);
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        as[i] = s == "x" ? INT_MIN : to_i(s);
    }
    return true;
}

bool odd(int n) {
    return n % 2 == 1;
}
#define even(x) (!odd(x))

bool check(int x) {
    for (int i = 0; i < as.size(); i++) {
        vector<int> ns;
        if (i - 1 >= 0) ns.push_back(i - 1);
        if (i + 1 < N)  ns.push_back(i + 1);
        for (int j = 0; j < ns.size(); j++) {
            int a = as[i] == INT_MIN ? x : as[i];
            int n = as[ ns[j] ] == INT_MIN ? x : as[ ns[j] ];
            if (odd(i + 1)  && a >= n) return false;
            if (even(i + 1) && a <= n)  return false;
        }
    }
    return true;
}

bool range_check(int x) {
    int start = -1e9, end = 1e9;
    return (start <= x && x <= end);
}

void solve() {
    int ans = INT_MIN;
    for (int i = 0; i < N; i++) {
        if (as[i] == INT_MIN) continue;
        for (int d = -3; d <= 3; d += 2) {
            if (as[i] + d == ans) continue;
            if (check(as[i] + d)) {
                if (ans > INT_MIN) {
                    cout << "ambiguous" << endl;
                    return;
                }
                ans = as[i] + d;
            }
        }
    }
    cout << (ans == INT_MIN ? "none" : to_s(ans)) << endl;
}

int main() {
    while (input()) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1264
#include<cctype>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

int main(){
 while(1){
  char str[1001];
  int n;
  cin >> str;
  if(str[0]=='0') break;
  n=strlen(str);

  int sum=0;
  for(int i=0;i<n;++i){
   sum+=str[i]-'0';
  }
  cout << sum << endl;
 }
 return 0;
}

Measured memory_bytes: 3096
from collections import deque
n = int(input())
'''
old_stack=deque(['a'])
while old_stack:
    s=old_stack.popleft()
    if len(s)==n:
        old_stack.appendleft(s)
        break
    for i in range(ord(max(s))-ord('a')+2):
        old_stack.append(s+chr(ord('a')+i))

for o in old_stack:    
    print(o)
'''
import copy
stack=deque([[0]])
while stack:
    s=stack.popleft()
    if len(s)==n:
        stack.appendleft(s)
        break
    for i in range(max(s)+2):
        news=copy.deepcopy(s)
        news.append(i)
        stack.append(news)

while stack:
    x=''
    s=stack.popleft()
    for i in range(len(s)):
        s[i]=chr(ord('a')+s[i])
    print(''.join(s))

Measured memory_bytes: 28276
n,w = gets.split.map(&:to_i)
dp = Array.new(n){[0]*w}
n.times do |i|
  a,b = gets.split.map(&:to_i)
  if i == 0
    (a..w).each {|j| dp[0][j] = b}
    next
  end
  (0..w).each do |j|
    comp = dp[i-1][j-a]+b
    comp = 0 if j-a < 0
    dp[i][j] = [comp, dp[i-1][j]].max
  end
end

p dp[-1][-1]


Measured memory_bytes: 92512
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int N,M;
    int[] X;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int[] A = new int[100001];
        for(int i=0;i<100001;i++){
            A[i] = 0;
        }
        for(int i=0;i<N;i++){
            A[X[i]]++;
        }
        int[] B = new int[M];
        int[] C = new int[M];
        for(int i=0;i<M;i++){
            B[i] = 0;
            C[i] = 0;
        }
        for(int i=0;i<100001;i++){
            B[i%M] += A[i];
            if(A[i] % 2 == 0){
                C[i%M] += A[i];
            }
            else{
                C[i%M] += A[i] - 1;
            }
        }
        int count = 0;
        for(int i=0;i <= M-i;i++){
            if(i == M-i || i == 0){
                count += B[i]/2;
            }
            else{
                if(B[i] > B[M-i]){
                    count += B[M-i];
                    if(C[i] > B[i] - B[M-i]){
                        count += (B[i] - B[M-i])/2; 
                    }
                    else{
                        count += C[i]/2;
                    }
                }
                else{
                    count += B[i];
                    if(C[M-i] > B[M-i] - B[i]){
                        count += (B[M-i] - B[i])/2;
                    }
                    else{
                        count += C[M-i]/2;
                    }
                }
            }
        }
        sb.Append(count+"\n");
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        M = int.Parse(str[1]);
        X = new int[N];
        str = Console.ReadLine().Split(' ');
        for(int i=0;i<N;i++){
            X[i] = int.Parse(str[i]);
        }
    }    
}

Measured memory_bytes: 10968
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
 	int A = sc.nextInt();
    int B = sc.nextInt();
    String U = sc.next();

      if(S.equals(U)){
    System.out.print(A-1);
    System.out.println(" " + B);
      }else{
	System.out.print(A);
    System.out.println(" " + (B-1));
      }
      }
}


Measured memory_bytes: 22612
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        decimal l = decimal.Parse(Console.ReadLine());
        decimal ans = l/3 * l/3 * l/3;
 
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11220
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A,B,C,D=map(int, input().split())

#CとDの最小公倍数
LCM=lcm(C,D)
#A未満でCで割れる個数
Ac=(A-1)//C
#範囲内でCで割れる個数
div_C=B//C-Ac
#A未満でDで割れる個数
Ad=(A-1)//D
#範囲内でDで割れる個数
div_D=B//D-Ad
#A未満でLCMで割れる個数
Alcm=(A-1)//LCM
#範囲内でLCMで割れる個数
div_CD=B//LCM-Alcm
#解答
Ans=(B-A+1)-div_C-div_D+div_CD
print(Ans)


Measured memory_bytes: 5372
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(VECTOR) (VECTOR).begin(),(VECTOR).end()

int main(){

	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i ++){
		cin >> A[i];
	}
	int ans = 1;
	int situation = 0;//0:不定,1:非減少,-1:非増加,100:変わり目
	for(int i = 1; i < N; i ++){
		switch(situation){
		case 0:
			if(A[i] > A[i - 1])situation = 1;
			if(A[i] < A[i - 1])situation = -1;
			break;
		case 1:
			if(A[i] < A[i - 1]){
				ans ++;
				situation = 0;
			}
			break;
		case -1:
			if(A[i] > A[i - 1]){
				ans ++;
				situation = 0;
			}
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 256
/*Let's start.............*/
#define   ll                long long
#define   pb                push_back
#define   ff                first
#define   ss                second
#define   srt(v)            sort(v.begin(),v.end())
#define   inf               2000000000000000
#define   mxn               1000009
#define   pi                acos(-1)
#define   MOD               1000000007
#define   db(x)             printf("### VALUE: (%lld) ###\n",(ll)x)
#include  <bits/stdc++.h>
using namespace std;

ll arr[mxn];
int main()
{
    ll n;
    cin >> n;
    ll sum = 0;
    for(ll i = 3; i <= n; i += 3) arr[i] = 1;
    for(ll i = 5;i <= n; i += 5) arr[i] = 1;
    for(ll i = 1;i <= n;i++) if(arr[i] == 0) sum += i;
    cout << sum << endl;
    return 0;
}
/*
".....but the truth is that you can increase it slightly."
Day 27
*/



Measured memory_bytes: 11364
#include<stdio.h>
    int main()
{
    int a,b;
    scanf("%d %d",&a,&b);

    if (a<b){printf("a < b\n");
    }

    if (a>b){
    printf("a > b\n");
    }

    if (a==b){
    printf("a == b\n");
    }

    return 0;
}

Measured memory_bytes: 580
package main

import (
	"fmt"
	"os"
)

func main() {
	m, a := input()
	arr, b, f := toMulBinary(a)
	if !f {
		fmt.Println(0)
		os.Exit(0)
	}
	lcm := arrLCM(arr) * pow(b)
	count := m / lcm
	if count%2 == 0 {
		fmt.Println(count / 2)
	} else {
		fmt.Println(count/2 + 1)
	}
}

func arrLCM(a []int) int {
	n := 1
	for _, v := range a {
		n *= v / dcp(n, v)
	}
	return n
}

func dcp(p, q int) int {
	if q <= 0 {
		return p
	}
	return dcp(q, p%q)
}

func toMulBinary(a []int) ([]int, int, bool) {
	b := includBinary(a[0])
	for i := range a {
		n, f := isXBinary(a[i], b)
		if !f {
			return a, 0, false
		}
		a[i] = n
	}
	return a, b - 1, true
}

func pow(b int) int {
	return 1 << uint32(b)
}

func isXBinary(n, b int) (int, bool) {
	if n%pow(b) != 0 {
		return n, false
	}
	if n%pow(b+1) == 0 {
		return n, false
	}
	return n / pow(b), true
}

func includBinary(n int) int {
	c := 0
	for n != 1 {
		if n%2 == 1 {
			return c
		}
		n /= 2
		c++
	}
	return c
}

func input() (int, []int) {
	var n, m int
	fmt.Scan(&n, &m)
	a := make(map[int]bool, n)
	var t int
	for i := 0; i < n; i++ {
		fmt.Scan(&t)
		a[t] = true
	}
	sa := make([]int, 0, n)
	for i := range a {
		_, ok := a[i]
		if ok {
			sa = append(sa, i)
		}
	}
	return m, sa
}


Measured memory_bytes: 4736
fun MM(x:Int, y:Int):Int{
  if(x>y) return y
  return x
}

fun main(args: Array<String>) {
    val da:Array<Int> = Array(4){
      readLine()!!.toInt()
    }
    println(MM(da[0],da[1])+MM(da[2],da[3]))
}

Measured memory_bytes: 31772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+6;
vector<int> e[maxn];
ll a[maxn];
void dfs(int u,int fa)
{
	a[u]+=a[fa];
	for(int i=0;i<e[u].size();i++)
	{
		int v=e[u][i]; 
		if(v==fa) continue;
		dfs(v,u);
	}
}
int main()
{
    int n,q;cin>>n>>q;
    for(int i=1;i<n;i++)
    {
    	int x,y;cin>>x>>y;
    	e[y].push_back(x);
    	e[x].push_back(y);
	}
	while(q--)
	{
		int x;ll y;cin>>x>>y;
		a[x]+=y;
	}
	dfs(1,0);
	for(int i=1;i<=n;i++) cout<<a[i]<<" ";
	cout<<endl; 
}

Measured memory_bytes: 24320
def bread_cnt(lev):
  return 2**(lev+1) - 2

def patty_cnt(lev):
  return 2**(lev+1) - 1

def burger_cnt(lev):
  return 2**(lev+2) - 3

def solve(n, x):
  return _solve(n, x, 0)
  
def _solve(n, x, p):
  total_s = burger_cnt(n)
  mid = (total_s+1)//2
  
  if x==1:
    return p + (1 if n==0 else 0)
  elif 1 < x and x <= mid:
    reach_mid = 1 if x==mid else 0
    return _solve(n-1, x-1-reach_mid, p+reach_mid)
  elif mid < x and x < total_s:
    return _solve(n-1, x-2-burger_cnt(n-1), p+1+patty_cnt(n-1))
  elif x == total_s:
    return p+patty_cnt(n)

n, x = map(int, input().split(' '))
print(solve(n,x))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	ll n,k;
	cin >> n >> k;
	vector<ll> v(n);
	for(ll &x: v)cin>>x;
	int st = 0;ll sum = 0,prev;
	for(int i = 0;i < k;i++)sum += v[i];
	prev = sum;
	for(int i = k;i < n;i++)
	{
		sum = prev - v[st++] + v[i];
		if(prev < sum )
			cout<<"Yes\n";
		else
			cout<<"No\n";
		prev = sum;
	}
		
}


Measured memory_bytes: 4780
n,m=map(int,input().split())
ans=0
if n==1 and m==1:
    ans=1
elif n==1 or m==1:
    ans=max(n-2,m-2)
elif n==2 or m==2:
    ans=0
else:
    ans=n*m-(n*2+m*2-4)
print(ans)

Measured memory_bytes: 3060
#include "iostream"


using namespace std;

int main() {
	int N,K;
	int d[100] = {0};
	int n[100] = {0};
	int k = 0;

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

		for (int j = 0; j < d[i]; j++) {
			int A;
			cin >> A;
			n[A-1]++;
		}
	}
	
	for (int i = 0; i < N; i++) {
		if (n[i] == 0) {
			k++;
		}
	}
	cout << k << endl;
	return 0;


}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>  // std::greater<T>()

using namespace std;

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define DESCEND greater<int>()  // sort 降順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから

// func declaration
template <class T> void printVec(vector<T>);


int main() {
    string s, t;
    cin >> s >> t;

    // process
    sort(ALL(s));  // sは一番小さい状態にする
    sort(ALL(t), DESCEND);

    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

// function
template <class T> void printVec(vector<T> vec) {
    // 1要素ずつ、空白・改行なしで出力
    REP(i, vec.size()) {
        cout << vec.at(i);
    }
    cout << endl;
}


Measured memory_bytes: 256
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let _ = lines.next();
    let a_line = lines.next().unwrap().unwrap();
    let splited = a_line.trim().split_whitespace();
    let ds: Vec<i32> = splited.map(|d| d.parse().unwrap()).collect();

    let mut ans = 0;
    for i in 0..ds.len() {
        for j in i + 1..ds.len() {
            ans += ds[i] * ds[j]
        }
    }

    writeln!(&mut writer, "{}", ans).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"3
3 1 2",
            br"11
",
        ),
        (
            br"7
5 0 7 8 3 3 2",
            br"312
",
        ),
    ];

    #[test]
    fn test_b() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;


int main() {

    int bingo[3][3];
    int ans[3][3];

    for(int i=0;i<3;i++){
        
        for(int j=0;j<3;j++){
        
            cin >> bingo[i][j];
            ans[i][j] = 0;
        
        }

    }

    int N;
    cin >> N;
    int b[N];
    
    for(int i=0;i<N;i++){
    
        cin >> b[i];
    
    }
    
    for(int i=0;i<3;i++){
    
        for(int j=0;j<3;j++){
    
            for(int k=0;k<N;k++){
    
                if(b[k]==bingo[i][j]){
    
                    ans[i][j] = 1;
    
                }
    
            }
    
        }
    
    }
    string ANS = "No";
    for(int i=0;i<3;i++){
        if(ans[i][0]&&ans[i][1]&&ans[i][2]) ANS = "Yes";
        if(ans[0][i]&&ans[1][i]&&ans[2][i]) ANS = "Yes";
    }

    if(ans[0][0]&&ans[1][1]&&ans[2][2]) ANS = "Yes";
    if(ans[0][2]&&ans[1][1]&&ans[2][0]) ANS = "Yes";
    
    cout << ANS << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
  int a[1020];
  int n;

  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%d", &a[i]);
  }

  for (int i=0; i<n-1; i++)
      printf("%d ", a[i]);
    printf("%d\n", a[n-1]);
 
  
  for (int i=1; i<n; i++) {
    int v = a[i];
    int j = i-1;

    while (j>=0 && a[j] > v) {
      a[j+1] = a[j];
      j--;
    }

    a[j+1] = v;

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

Measured memory_bytes: 2716
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n;
ll a[3005],dp[3005][3005];
ll pre[3005];
int main(){FAST;
cin>>n;
for(ll i=1;i<=n;++i)cin>>a[i];
for(ll i=1;i<=n;++i){
  pre[i] = pre[i-1]+a[i];
}
for(ll i=1;i<=n;++i){
  dp[i][i] = a[i]; 
}
for(ll len=2;len<=n;++len){
  for(ll i=1,j=i+len-1;j<=n;++i,++j){
    dp[i][j] = max({dp[i][j],pre[j]-pre[i-1]-dp[i][j-1],pre[j]-pre[i-1]-dp[i+1][j]});
  }
}
cout<<2*dp[1][n]-pre[n];
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 49776
# シミュレーション

def main():
    from collections import deque
    from string import ascii_lowercase

    s = []
    for _ in range(3):
        t = input()
        t = deque(ascii_lowercase.index(c) for c in t)
        s.append(t)

    curr = 0
    while True:
        curr = s[curr].popleft()
        if not s[curr]:
            print(ascii_lowercase[curr].upper())
            return


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()


Measured memory_bytes: 3828
A = [[int(i) for i in input().rstrip().split()] for i in range(3)]
n = int(input())
B = [int(input()) for a in range(n)]

for a in A:
    if all(s in B for s in a):
        print("Yes")
        exit()
A = [list(a) for a in zip(*A)]
for a in A:
    if all(s in B for s in a):
        print("Yes")
        exit()
C = [[A[0][0],A[1][1],A[2][2]],[A[0][2],A[1][1],A[2][0]]]
if any(all(s in B for s in c) for c in C):
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main(){

  int H, W;
  cin >> H;
  cin >> W;
  ll maze[H][W];

  vector<string> S;
  string temp;
  REP(i, 0, H) {
    cin >> temp;
    S.push_back(temp);
  }

  REP(i, 0, H) {
    REP(j, 0, W) {
      if ( S[i].substr(j, 1) == "." ) {
        maze[i][j] = 0;
      }
      else {
        maze[i][j] = 1;
      }
    }
  }

  // cout << endl << "-----------" << endl;
  // REP(i, 0, H) {
  //   REP(j, 0, W) {
  //     if (maze[i][j] == 0)
  //       cout << ".";
  //     else
  //       cout << "#";
  //   }
  //   cout << endl;
  // }
  // cout << endl;

  // maze[i][j] -> i*W + j tosuru
  ll d[H*W][H*W];
  REP(s, 0, H*W) {
    REP(e, 0, H*W) {
      if (s == e) {
        d[s][e] = 0;
      }
      else if
        ( (maze[s/W][s%W] == 0) and (maze[e/W][e%W] == 0) and
          ( ( (abs((s/W) - (e/W)) == 1) and ((s%W) == (e%W)) ) or
            ( (abs((s%W) - (e%W)) == 1) and ((s/W) == (e/W)) ) ) )
        {
        d[s][e] = 1;
      }
      else {
        d[s][e] = inf;
      }
    }
  }

  REP(m, 0, H*W) { // midpoint
    REP(s, 0, H*W) { // start
      REP(e, 0, H*W) { // end
        d[s][e] = min(d[s][e], d[s][m] + d[m][e]);
      }
    }
  }

  ll ans = 0;
  ll ans_s, ans_e;
  REP(s, 0, H*W) { // start
    REP(e, 0, H*W) { // end

      // cout << "d"  << "[" <<  s/W << ", " << s%W << "] -> "
      //      << "[" <<  e/W << ", " << e%W << "]" << endl;
      // cout << d[s][e] << endl;;

      if ( d[s][e] == inf )
        continue;
      if ( d[s][e] > ans ) {
        ans = d[s][e];
        ans_s = s;
        ans_e = e;
      }
    }
  }

  // cout << "ans_s: " << "(" <<  ans_s/W << ", " << ans_s%W << ")" << endl;
  // cout << "ans_e: " << "(" <<  ans_e/W << ", " << ans_e%W << ")" << endl;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

int main() {
    char c;
    cin>>A>>c>>B;
    cout<<(c == '+' ? A + B : A - B)<<endl;
}

Measured memory_bytes: 256
N = int(input())
L = []
light = [0]*(N)
light[0] = 1
cnt, now = 0, 0

for i in range(N):
    L.append(int(input()))

for i in range(N):
    now = L[now] - 1
    cnt += 1
    if now == 1:
        print(cnt)
        exit()

print(-1)


Measured memory_bytes: 13760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;

  ll halfN = divceil(N, 2);
  vector<pair<ll, ll>> P(halfN);
  if (N % 2 == 1)
  {
    for (ll i = 0; i < halfN; i++)
    {
      P.at(i).first = C * (2 * i) + (C - D) * (halfN - i - 1);
      chmax(P.at(i).first, 0LL);
      P.at(i).second = D * (2 * i) + (D - C) * (halfN - i - 1);
    }
  }
  else
  {
    for (ll i = 0; i < halfN; i++)
    {
      P.at(i).first = C * (2 * i + 1) + (C - D) * (halfN - i - 1);
      chmax(P.at(i).first, 0LL);
      P.at(i).second = D * (2 * i + 1) + (D - C) * (halfN - i - 1);
    }
  }

  ll X = abs(A - B);
  for (ll i = 0; i < halfN; i++)
  {
    //cerr << P.at(i).first << " " << P.at(i).second << endl;
    if (P.at(i).first <= X && X <= P.at(i).second)
      FINALANS("YES");
  }
  FINALANS("NO");
}

Measured memory_bytes: 4096
use std::io;
use std::str::FromStr;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn divisor(l: i32, u: i32, n: i32) -> i32 {
    let mut count = 0;
    for i in l..u+1 {
        if n % i == 0 {
            count += 1;
        }
    }
    count
}

fn main() {
    from_line!(a: f64);

    println!("{} {}", a * a * PI, 2_f64 * a * PI);
}



Measured memory_bytes: 5056
from collections import Counter
N , K = map(int,input().split())
h = list(int(input()) for _ in range(N))
h.sort()
min = 10 ** 10
for i in range(len(h) - K + 1):
    tmp_min = h[i + K - 1] - h[i]
    if min > tmp_min:
        min = tmp_min
print(min)


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

int main() {
  double N, D;
  cin >> N >> D;
//  cout << N << " " << D << endl;
  
  int result = 0;

//  vector<vector<int>> XY(N ,vector<int>(N));
  for (int i=0; i<N; ++i) {
//    cin >> XY.at(i).at(0) >> XY.at(i).at(1);
    double X, Y;
    cin >> X >> Y;
    double dist = X*X + Y*Y;
//    cout << dist << " " << D*D << endl;
    if (dist <= D*D) {
      result++;
    }
  }
/*  for (int i=0; i<N; ++i) {
    cout << XY.at(i).at(0) << " " << XY.at(i).at(1) << endl;
  }*/
  
 

  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 3780
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<int> G[200010];
int L[2][200010];


void dfs(int T, int V, int cost) {
    //cout << T << " " <<V << " " << cost << endl;
	L[T][V] = cost;
	for (auto to : G[V]){
		if (L[T][to] != INF) continue;
        if (T == 0)
		    dfs(T, to, cost + 1);
        else if (T == 1 && L[1][V] < L[0][V] && L[1][V] + 1 < L[0][to])
            dfs(T, to, cost + 1);
	}
}

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

	int N, u, v;
	cin >> N >> u >> v;
    u--; v--;
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
        a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i, 2) rep(j, 200010) L[i][j] = INF;
	dfs(0, v, 0);
	dfs(1, u, 0);
    int ans = 0;
    rep(i, N) {
        //cout << L[0][i] << " " << L[1][i] << endl;
        if (L[0][i] > L[1][i])
            ans = max(ans, L[0][i] - 1);
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define fr(i,s,e) for(i=s;i<e;i++)

int main() {
    int i,j=0,p=0,q=0;
   int n,m,x;
   cin>>n>>m>>x;
   int a[m];
   fr(i,0,m)
    cin>>a[i];
   fr(i,1,n){
     if(i<x&&i==a[j]){
        p++;
        j++;
     }
     if(i>x&&i==a[j]){
        q++;
        j++;
     }
    }
    cout<<min(p,q);
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

int N;
cin >> N;
vector<string> S(N);
vector<int> A(N);
for (int i=0; i<N; i++){
    cin >> S.at(i);
}

sort(S.begin(), S.end()); //sort abcd...

A.at(0)=0;
for (int i=1; i<N; i++){
    if (S.at(i-1)==S.at(i)){
        A.at(i)=A.at(i-1)+1;
    } else {
        A.at(i)=0;
    }
}
int max=0;
for (int i=0; i<N; i++){
    if (A.at(i)>max){
        max=A.at(i);
    }
}
for (int i=0; i<N; i++){
    if (A.at(i)==max){
    cout << S.at(i) << endl;
   }
}
}

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

int main(){
    long long w,h;
    cin >> w >> h;
    if(w == 1 || h == 1){
        cout << 1 << endl;
        return 0;
    }
    long long ans = (w*h+1)/2;
    cout << ans << endl;
}

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

using namespace std;
using ll = long long int;

constexpr ll Mod = (ll) 1e9 + 7;

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

    ll zero[64] = { }, one[64] = { };

    for (int bit = 0; bit < 64; bit++)
    {
        for (auto &value : A)
        {
            if (((value >> bit) & 1) == 1)
            {
                one[bit]++;
            }
            else
            {
                zero[bit]++;
            }
        }
    }

    ll ans = 0;
    ll mult = 1;
    for (int bit = 0; bit < 63; bit++)
    {
        ll count = (zero[bit] * one[bit]) % Mod;
        ans = (ans + (mult * count) % Mod) % Mod;
        mult = (mult << 1) % Mod;
    }

    cout << ans << endl;
}

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

int main()
{
	int n, r;
	cin >> n >> r;
	
	if (n >= 10)
	{
		cout << r << endl;
	}
	else
	{
		cout << r + 100 * (10 - n) << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
F = int(input())

sum1 = 0
sum2 = 0

if A <= B and A <= C and A <= D:
    sum1 = B+C+D
elif B <= A and B <= C and B <= D:
    sum1 = A+C+D
elif C <= A and C <= B and C <= D:
    sum1 = A+B+D
else:
    sum1 = A+B+C

if E <= F:
    sum2 = F
else:
    sum2 = E
    
print(sum1 + sum2)


Measured memory_bytes: 5588
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  
  int n, m;
  cin >> n >> m;

  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  vec b;

  int sum = 0;
  REP(i, n){
    sum += a[i];
    while(a[i] >= 1){
      b.push_back(a[i] - a[i] / 2);
      a[i] /= 2;
    }
  }

  sort(b.begin(), b.end(), greater<int>());

  for(int i = 0; i < m && i < (int)b.size(); i++){
    sum -= b[i];
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 35812
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

void BGoldenCoins(std::istream& in, std::ostream& out) {
  llong x;
  in >> x;
  llong y = 0;
  y += (x / 500) * 1000;
  x %= 500;
  y += (x / 5) * 5;
  out << y << endl;
}

int main(int argc, char** argv) { BGoldenCoins(cin, cout); return 0; }


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

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

int main()
{
  ll n;
  cin >> n;
  set<string> st;
  rep(i, n)
  {
    string in;
    cin >> in;
    st.insert(in);
  }
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 19224
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    tmp = A[0]
    money = 1000

    for a in A:
        if tmp < a:
            c = money // tmp
            money -= tmp * c
            money += c * a
            tmp = a
        else:
            tmp = min(tmp, a)
    print(money)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9900
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 1000000000000000
#define mod 1000000007
using namespace std;

int main()
{ 

fast;
	ll n,w;
	cin>>n>>w;

	ll wt[n],val[n];
	for(ll i=0;i<n;i++)
		cin>>wt[i]>>val[i];

	ll dp[n+1][100009];
	
	for(ll i=0;i<n+1;i++)
	for(ll j=0;j<100009;j++)
	dp[i][j]=inf;

		for(ll i=0;i<n+1;i++)
			dp[i][0]=0;
		
	for(ll i=1;i<n+1;i++)
	{
		for(ll j=1;j<100001;j++)
		{
		    dp[i][j]=dp[i-1][j];
			if(j>=val[i-1])
				dp[i][j]=min(dp[i][j],dp[i-1][j-val[i-1]]+wt[i-1]);
		}
	}
 ll ans=0;
    
    for(ll i=1;i<n+1;i++)
    {
        for(ll j=i;j<100001;j++)
        {
            if(dp[i][j]<=w)
            ans=max(ans,j);
        }
    }
    cout<<ans<<endl;
}


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

#define FOR(i,a,b) for(size_t i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef pair<ll, ll> pll;
// const ll INF = (ll)1e18;

signed main() {
	string x, y;
	cin >> x >> y;
	cout << (x == y ? "=" : ( x < y ? "<" : ">" )) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 110000
#define ls l,mid,now<<1
#define rs mid+1,r,now<<1|1
int n,tot,cnt,ret;
int head[N],nex[N<<1],to[N<<1];
int deep[N],fa[N],son[N],size[N],top[N],pos[N],bel[N];
int X[N],Y[N],num[N<<2],v0[N<<2],v1[N<<2];
set<int>se[N<<2];
void add(int x,int y)
{
	tot++;
	nex[tot]=head[x];head[x]=tot;
	to[tot]=y;
}
void dfs1(int x,int y)
{
	size[x]=1;
	fa[x]=y;deep[x]=deep[y]+1;
	for(int i=head[x];i;i=nex[i])
		if(to[i]!=y)
		{
			dfs1(to[i],x);
			size[x]+=size[to[i]];
			son[x]=size[to[i]]>size[son[x]] ? to[i] : son[x]; 
		}
}
void dfs2(int x,int y,int tp)
{
	top[x]=tp;
	pos[x]=++cnt;bel[cnt]=x;
	if(son[x])dfs2(son[x],x,tp);
	for(int i=head[x];i;i=nex[i])
		if(to[i]!=y&&to[i]!=son[x])
			dfs2(to[i],x,to[i]);
}
void pushup(int l,int r,int now)
{
	if(l==r)
	{
		v0[now]=(num[now]==0);
		v1[now]=(num[now]==1);
		return;
	}
	if(num[now]==0)v0[now]=v0[now<<1]|v0[now<<1|1];
	else v0[now]=0;

	if(num[now]==0)v1[now]=v1[now<<1]|v1[now<<1|1];
	else if(num[now]==1)v1[now]=v0[now<<1]|v0[now<<1|1];
	else v1[now]=0;
}
void insert(int l,int r,int now,int lq,int rq,int p)
{
	if(lq<=l&&r<=rq)
	{
		se[now].insert(p);
		num[now]++;
		pushup(l,r,now);
		return;
	}
	int mid=(l+r)>>1;
	if(mid>=lq)insert(ls,lq,rq,p);
	if(mid<rq) insert(rs,lq,rq,p);
	pushup(l,r,now);
}
void mark(int x,int y,int p)
{
	while(top[x]!=top[y])
	{
		if(deep[top[x]]<deep[top[y]])swap(x,y);
		insert(1,n,1,pos[top[x]],pos[x],p);
		x=fa[top[x]];
	}
	if(x!=y)
	{
		if(deep[x]<deep[y])swap(x,y);
		insert(1,n,1,pos[y]+1,pos[x],p);
	}
}
void update(int l,int r,int now,int v)
{
	if(num[now])
	{
		ret=*(se[now].begin());
		v=0;
	}
	if(l==r)return;
	int mid=(l+r)>>1;
	if((v==0&&v0[now<<1])||(v==1&&v1[now<<1]))
		update(ls,v);
	else update(rs,v);
}
void del(int l,int r,int now,int lq,int rq,int p)
{
	if(lq<=l&&r<=rq)
	{
		se[now].erase(p);
		num[now]--;
		pushup(l,r,now);
		return;
	}
	int mid=(l+r)>>1;
	if(mid>=lq)del(ls,lq,rq,p);
	if(mid<rq) del(rs,lq,rq,p);
	pushup(l,r,now);	
}
void del(int x,int y,int p)
{
	while(top[x]!=top[y])
	{
		if(deep[top[x]]<deep[top[y]])swap(x,y);
		del(1,n,1,pos[top[x]],pos[x],p);
		x=fa[top[x]];
	}
	if(x!=y)
	{
		if(deep[x]<deep[y])swap(x,y);
		del(1,n,1,pos[y]+1,pos[x],p);
	}	
}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs1(1,0);
	dfs2(1,0,1);
	for(int i=1;i<=n<<2;i++)v0[i]=1;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&X[i],&Y[i]);
		mark(X[i],Y[i],i);
	}
	for(int i=1;i<n;i++)
	{
		if(!v1[1])return puts("NO"),0;
		update(1,n,1,1);
		del(X[ret],Y[ret],ret);
	}
	puts("YES");
	return 0;
}


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

#define SIZE 1010

typedef struct _Cord {
    int x, y;
    int num;
} Cord;

queue<Cord> q;
bool arr[SIZE][SIZE];
int dir[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
int row, column;

bool canMove(int x, int y) {
    return x >= 0 && x < row && y >= 0 && y < column && !arr[x][y];
}

int bfs() {
    int ans = 0;
    while (!q.empty()) {
        Cord cntState = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            int x1 = cntState.x + dir[0][i], y1 = cntState.y + dir[1][i];
            if (!canMove(x1, y1))
                continue;
            arr[x1][y1] = true;
            Cord nextState = {x1, y1, cntState.num + 1};
            ans = max(ans, nextState.num);
            q.push(nextState);
        }
    }
    return ans;
}

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

    cin >> row >> column;
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < column; j++) {
            char ch;
            cin >> ch;
            if (ch == '#') {
                // Black
                arr[i][j] = true;
                q.push({i, j, 0});
            } else {
                // White
                arr[i][j] = false;
            }
        }
    }

    int ans = bfs();
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 13328
/*
 * created   : 2019-07-24 23:31:11
 * accepted  : 2019-07-24 23:31:29
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n;
  cin >> n;
  cout << 3 * n * n << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
/*input
10
*/

#include <bits/stdc++.h>
#include <unistd.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 1e18
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'
#define UQ(x) (x).resize(distance((x).begin(),unique(all((x)))))

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

void solve(){
	ll i,j,k;
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




Measured memory_bytes: 3620
fun main(args: Array<String>) = yorukatsu10e()

fun yorukatsu10e() {
    val (n, m) = readLine()!!.split(' ').map { it.toLong() }
    val aList = readLine()!!.split(' ').map { it.toLong() }

    val counts = aList.map {
        var curr = it
        var count = 0
        while (curr % 2 == 0L) {
            curr /= 2
            count++
        }
        count
    }

    if (counts.distinct().size != 1) return println(0)

    val halved = aList.map { it / 2 }
    val lcm = aList.fold(1L) { acc, l -> lcm(acc, l) }
    val lcmHalved = halved.fold(1L) { acc, l -> lcm(acc, l) }

    val answer = m / lcmHalved - m / lcm

    println(answer)
}

private fun lcm(a: Long, b: Long): Long {
    return a / gcd(a, b) * b
}

private tailrec fun gcd(a: Long, b: Long): Long {
    return if (b == 0L) a else gcd(b, a % b)
}


Measured memory_bytes: 72136
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    int ans = 0;
    rep(i, 1, N + 1) {
        if (i * i > N) break;
        if (N % i == 0) {
            int d1 = i;
            int d2 = N / i;
            if (d1 > 1 && i < d1 - 1) {
                ans += d1 - 1;
                dump(d1 - 1);
            }
            if (d1 != d2 && i < d2 - 1) {
                ans += d2 - 1;
                dump(d2 - 1);
            }
        }
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
H, W = map(int, input().split())
grid = [input() for i in range((H))]
dp = [[0 for i in range(W)] for j in range(H)]
dp[0][0] = 1
m = 10**9 + 7
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            continue
        if i >= 1:
            dp[i][j] += dp[i-1][j]
        if j >= 1:
            dp[i][j] += dp[i][j-1]

        dp[i][j] %= m

print(dp[-1][-1])

Measured memory_bytes: 54236
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int X;
    cin>>X;
    long long int s,r;
    s=0;
    r=0;
    s=X/500;
    s=s*1000;
    if(X%500!=0)
    {
        r=X%500;
        r=r/5;
        r=r*5;
    }
    cout<<r+s;

}

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


int main()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	
	int dp[n];
	dp[0]=0;
	
	for(int i=1;i<n;i++)
	{
		dp[i]=INT_MAX;
		for(int j=1;j<=k;j++)
		{
			if(i-j>=0)
			{
				dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
			}
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
a,b=map(int,raw_input().split())
count=b-a+1
if a<0:
    if a+count-1>=0:
        print "Zero"
    else:
        if count%2==0:
            print "Positive"
        else:
            print "Negative"
else:
    if a==0:
        print "Zero"
    else:
        print "Positive"

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> food(m);
    for (int i = 0; i < n; i++) {
        int k;  cin >> k;
        for (int j = 0; j < k; j++) {
            int num; cin >> num;
            food[num - 1]++;
        }
    }

    int count = 0;
    for (int i = 0; i < m; i++) {
        if (food[i] == n) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
from math import ceil
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
if N % 2 == 0: print(sum(A[:N // 2]) * 2 - A[0])
else: print(sum(A[:ceil(N / 2)]) + sum(A[:N // 2]) - A[0])


Measured memory_bytes: 104312
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
  
using namespace std;

#define pi 3.141592653589793

struct Thread {
	string node;
	int children[1001];
	int dotnum;
};

typedef struct Thread th;

void result(th m[], int cn[], int n)
{
	for(int i = 0; i < m[n].dotnum; i++){
		cout << ".";
	}
	cout << m[n].node << endl;
	if(cn[n] == 0) return;
	for(int i = 0; i < cn[n]; i++){
		result(m, cn, m[n].children[i]);
	}
	return;
}

int main()
{
	int n;
	cin >> n;
	int k[1001], children_num[1001] = {};
	th m[1001];
	for(int i = 0; i < n; i++){
		cin >> k[i] >> m[i].node;
	}
	m[0].dotnum = 0;
	for(int i = 1; i < n; i++){
		int parent = k[i] - 1;
		m[k[i] - 1].children[children_num[parent]] = i;
		children_num[parent]++;
		m[i].dotnum = m[parent].dotnum + 1;
	}
	result(m, children_num, 0);
	return 0;
}

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

int main()
{
  int N;cin>>N;
  double ans=1.0;
  if (N%2 == 0) 
  {
    ans /= 2;
  }
  else 
  {
    ans = N/2+1;
    ans/=N;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n,k;
  cin>>n>>k;
  ll cnt = 0;
  ll ans = 0;
  for(int i = k; i <= n; i+=k){
    cnt++;
  }
  ans+=cnt*cnt*cnt;
  if(k%2==0){
    cnt = 0;
    for(int i = k/2; i <= n; i+=k){
      cnt++;
    }
    ans+=cnt*cnt*cnt;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>
#define MAX_N (100000)

int main(void) {
  int N;
  scanf("%d", &N);
  int H[MAX_N];
  for(int i = 0; i < N; i++) {
    scanf("%d", &H[i]);
  }

  bool flag = true;
  for(int i = N-1; i >= 1; i--) {
    if((H[i] - H[i-1]) >= 0)
      continue;

    if((H[i] - H[i-1]) >= 1) {
      H[i]--;
      continue;
    }

    if((H[i] - H[i-1]) == -1) {
      H[i-1]--;
      continue;
    }    
flag = false;
    break;
  }
  if(flag)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


Measured memory_bytes: 512