akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

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


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int r;
    cin >> r;
    cout << r * r << endl;

    return 0;
}


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

signed main(){

  int v,e;
  cin>>v>>e;
  vector<vector<int>> adj(v);
  vector<int> deg(v);
  for(int i=0;i<e;++i){
    int s,t;cin>>s>>t;
    adj[s].emplace_back(t);
    deg[t]++;
  }

  queue<int> que;
  for(int i=0;i<v;++i)if(deg[i]==0)que.emplace(i);
  vector<int> res;
  while(!que.empty()){
    int v = que.front();
    que.pop();
    res.emplace_back(v);
    for(auto nv:adj[v]){
      deg[nv]--;
      if(deg[nv]==0)que.emplace(nv);
    }
  }

  for(auto a:res)cout<< a <<endl;

}


Measured memory_bytes: 3712
function Main(input) {
  const lines = input.split("\n");
  const N = parseInt(lines[0])
  const AList = (lines[1]).split(" ").map(x => parseInt(x))
  let addHeightList = [0]
  for (let i = 0; i < AList.length; i++) {
    if (i == 0) continue
    const sabun = AList[i - 1] + addHeightList[i - 1] - AList[i]
    if (sabun < 0) {
      addHeightList.push(0)
    } else {
      addHeightList.push(sabun)
    }
  }
  const addTotal = addHeightList.reduce((x, y) => x + y )
  console.log(addTotal)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 56800
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
  int N;
  scanf("%d", &N);
  int ans[N + 1];
  fill_n(ans, N + 1, 0);
  for (int i = 1; i <= 100; ++i) {
    for (int j = 1; j <= 100; ++j) {
      for (int k = 1; k <= 100; ++k) {
        if (i * i + j * j + k * k + i * j + j * k + k * i <= N) ++ans[i * i + j * j + k * k + i * j + j * k + k * i];
      }
    }
  }
  for (int i = 1; i <= N; ++i) printf("%d\n", ans[i]);
  return 0;
}

Measured memory_bytes: 1680
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct UnionFind {
    vector<int> data;
    UnionFind(int sz) : data(sz, -1) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
};

int main(void){
  int n, q;
  cin >> n >> q;
  vector<int> com(q), x(q), y(q);
  rep(i, q) cin >> com[i] >> x[i] >> y[i];

  UnionFind uf(n);
  vector<int> ans;
  rep(i, q){
    if(com[i] == 0) uf.unionSet(x[i], y[i]);
    else ans.push_back(uf.findSet(x[i], y[i]));
  }
  rep(i, ans.size()) cout << ans[i] << endl;
  return 0;
}



Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    int a,b;
    cin>>a>>b;
    int s=0;
    int t=0;
    rep(i,b)s=s*10+a;
    rep(i,a)t=t*10+b;
    if(a<b)cout<<s<<endl;
    else cout<<t<<endl;
}

Measured memory_bytes: 256
/**
       ������������    ������������
		Author : Avi J Patel
		University : DA-IICT
       ������������    ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
}
int main()
{
	int n;
	cin>>n;
	vector<pair<int,int>> a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i].ff;
		a[i].ss=i+1;
	}
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++)
	{
		cout<<a[i].ss<<" ";
	}
	return 0;
}












Measured memory_bytes: 1536
#include<bits/stdc++.h>
 
using namespace std;
 
 
int main(){
	int n,W;
	scanf("%d%d",&n,&W);
	long long int i,j,dp[n+1][W+1],w[n+1],v[n+1];

	for(i=1;i<=n;i++)
		scanf("%lld%lld",&w[i],&v[i]);
	for(i=0;i<=n;i++){
		dp[i][0]=0;
	}
	for(i=0;i<=W;i++){
		dp[0][i]=0;
	}

	for(i=1;i<=n;i++){
		for(j=0;j<=W;j++){
			if(w[i]<=j){
				dp[i][j] = max(v[i]+dp[i-1][j-w[i]],dp[i-1][j]);
			}
			else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}

	// for(i=0;i<=n;i++){
	// 	printf("---i %lld---\n",i );
	// 	for(j=0;j<=W;j++){
	// 		printf("%lld ",dp[i][j] );
	// 	}
	// 	printf("\n");
	// }

	printf("%lld\n",dp[n][W] );
	return 0;
}


Measured memory_bytes: 79104
#include<iostream>
#include<queue>
#include<map>
#include<cstdio>
using namespace std;
int main(){
	string s,t;for(int i,n,f;cin>>s,s!="0";){
		queue<string>q;
		map<string,int>d;d[s]=1;
		for(q.push(s);q.size();){
			s=q.front();q.pop();n=s.length();
			for(f=i=0;i<n-1;i++)if(s[i]!=s[i+1]){
				t=s;t[i]=t[i+1]=(char)('r'+'g'+'b'-s[i]-s[i+1]);f++;
				if(!d[t])d[t]=d[s]+1,q.push(t);
			}
			if(!f){printf("%d\n",d[s]-1);goto N;}
		}
		puts("NA");N:;
	}
}

Measured memory_bytes: 0
/*
  NAME : RISHABH SINGH
  INSTITUTION : DELHI TECHNOLOGICAL UNIVERSITY
*/
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int, int>
#define bi __builtin_inf()
#define ll long long
#define mp make_pair
#define ss second
#define pb push_back
#define ff first
#define speed_cubing ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define um unordered_map
#define us unordered_set
#define bp __builtin_popcount
#define ld long double
#define rep(n) for (int i = 0; i < n; i++)
#define pll pair<ll, ll>
#define mx = 1e18;
#define lb(v, val) (lower_bound(v.begin(), v.end(), val) - v.begin())
#define ub(v, val) (upper_bound(v.begin(), v.end(), val) - v.begin())
#define PI 3.1415926535
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
#define sz(v) (int)v.size()
#define endl '\n'
const int N = 1e4;
const int mod = 998244353;
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}


int32_t main(){
   
   speed_cubing 
   
   int n,k;
   cin>>n>>k;

   set<int> s;

   for(int i=0;i<k;i++){
      int d;
      cin>>d;
      for(int i=0;i<d;i++){
         int x;
         cin>>x;
         s.insert(x);
      }
   }

   cout<<n-s.size();
   
    
   return 0;
}


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

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000010;
const int delta = 11353;

int n, a[N];
vector<pii> P, M;

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	//if (n == 1) return cout << (n % 2 == 1?"Second":"First"), 0;
	for (int i = 1; i <= n; i++) cin >> a[i];
	if (n == 1) return cout << (a[1] % 2 == 1?"Second":"First"), 0;
	sort(a + 1, a + n + 1);
	//int mx = 0, mx2 = 0;
	reverse(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++){
		P.pb({i, a[i]});
	}
	sort(all(P));
	int mx = 0;
	reverse(all(P));
	for (auto u:P){
		if (u.S <= mx) continue;
		mx = u.S;
		if (u.F == u.S) return cout << "Second", 0;
		M.pb({u.F, u.S});
	}
	//iassert(0);
	sort(all(M));
	for (int i = 1; i < M.size(); i++){
		if (M[i - 1].F < M[i - 1].S && M[i].F > M[i].S){
			int X = M[i - 1].F, Y = M[i].S;
			if (X == Y){
				if (((M[i - 1].S - Y) % 2 == 1) || ((M[i].F - X) % 2 == 1)) return cout << "First", 0;
				return cout << "Second", 0;
			}
			if (X < Y){
				if (abs(M[i].F - M[i].S) % 2 == 1) cout << "First";
				else cout << "Second";
				return 0;
			}else{
				cout << ((abs(M[i - 1].F - M[i - 1].S) % 2)?"First":"Second");
				return 0;
			}
		}
	}
	if (abs(M.back().F - M.back().S) % 2 == 1) cout << "First";
	else cout << "Second";
	return 0;
}


Measured memory_bytes: 5916
n = int(input())
a = list(map(int, input().split()))

a = sorted([i for i in a if i%2==0])
x = 0
ans = 0
while len(a)!=0 and a[-1]%2==0:
    if a[x] % 2 != 0:
        x += 1
    a[x] = a[x]//2
    ans += 1
print(ans)


Measured memory_bytes: 4152
# 素数を３からN個
N = int(input())

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i] and i%5 == 1]

A = primes(5000) # Aの長さは55を超える
A.pop(0)
print(*A[:N])

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int ans = 0;
		for(int i = 1;i <= n;i++){
			if(String.valueOf(i).length() % 2 == 1){
				ans++;
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int tab[200010];
int n,k;

int cei(int x,int y)
{
    return ((x / y) + (x % y != 0));
}

bool cek(int x)
{
    int cnt = 0;
    for (int i = 1 ; i <= n ; i++)
        cnt += cei(tab[i],x) - 1;
    // cout << cnt << endl;
    return (cnt <= k);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 1 ; i <= n ; i++)
        cin >> tab[i];
    // cout << cek(5) << endl;
    // return 0;
    int l = 1;
    int r = INF;
    while (r - l > 1)
    {
        int mid = (l + r) >> 1;
        // cout << l << " " << r << " " << mid << endl;
        if (cek(mid))
            r = mid;
        else
            l = mid + 1;
    }
    if (cek(l))
    {
        cout << l << endl;
    }
    else
        cout << r << endl;
    return 0;
}

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

#define int long long
#define pb push_back
#define ff first
#define ss second



main(){
	int n;
	cin>>n;
	int count=0;
	int i,j,k=n;
	for(i=2;i<=sqrt(n);i++){
		j=0;
		while(k%i==0){
			j++;
			k = k/i;
		}
		count+=(-1+sqrt(8*j+1))/2;
	}
	if(k>1){
		count++;
	}
	cout<<count;
	return 0;
}

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

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy
# sys.setrecursionlimit(1000000)

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def sumdig(a):
    assert a > 0
    sa = str(a)
    re = 0
    for c in sa:
        re += int(c)
    return re

def main():
    n = int(input())
    res = HUGE
    for a in range(1, n // 2 + 1):
        b = n - a
        res = min(res, sumdig(a) + sumdig(b))
    print(res)

main()


Measured memory_bytes: 3572
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
static const int MAX = 100;
static const int INF = 1000000;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int main(void) {
    int n, i;
    cin >> n;
    int a[n+2], d[n+2], dsum;
    a[0]=0;
    a[n+1]=0;
    for(i=1; i<=n; i++)
        cin >> a[i];
    d[0]=0;
    for(i=1; i<=n; i++) {
        d[i] = d[i-1] + abs(a[i]-a[i-1]);
    }
    dsum = d[n] + abs(a[n]);
    
    
    for(i=1; i<=n; i++) {
        if((a[i-1]<=a[i]&&a[i]<=a[i+1])||(a[i+1]<=a[i]&&a[i]<=a[i-1]))
            cout << dsum << endl;
        else
            cout << dsum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]) << endl;
    }
}


Measured memory_bytes: 2048
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] T = sc.nextLine().split(" ");
    int K = Integer.parseInt(T[0]);
    int S = Integer.parseInt(T[1]);
    
    int ans = 0;
    for(int i = 0; i <= K; i++){
      for(int j = 0; j <= K; j++){
        int k = S-i-j;
        if(i+j+k == S && k >= 0 && k <= K){
          ans++;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
typedef pair<ll,ll > P;
const int MOD = 1000000007;


int main() {
	ll i, j, k, l, m, n, sum, flag, cc, M, X, H, W, N;
	cc = 0;
	flag = 0;
	char S[100001];
	cin >> N;
	cin >> S;
	ll num[26] = {};
	REP(i, 0, 26) {
		num[i] = 1;
	}
	REP(i, 0, N) {
		num[S[i] - 'a']++;
	}
	ll ans = 1;
	REP(i, 0, 26) {
		ans *= num[i];
		ans %= MOD;
	}
	output(ans - 1);
	
	return 0;
}



Measured memory_bytes: 384
lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(lst[K - 1])

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>

struct node{
  int key;
  struct node *parent,*left,*right;
};

struct node *root,*NIL;

void insert(int k){
  struct node *y=NIL;  //xの親
  struct node *x=root;
  struct node *z;

  z=(struct node*)malloc(sizeof(struct node));

  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
  }

  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key<y->key) y->left=z;
  else y->right=z;
  }

void inorder(struct node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int num,i,k;
  char c[10];

  scanf("%d",&num);

  for(i=0;i<num;i++){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    else{
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
      }
  
  return 0;
}



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

int main()
{
  double a, b, c, d, e, f;

  while (cin >> a >> b >> c >> d >> e >> f){
    double x, y;
    y = (((a * f) - (d * c)) / ((a * e) - (b * d)));
    x = (c - (b * y)) / a;

    printf("%.3f %.3f\n", x, y);
  }

  return 0;
}

Measured memory_bytes: 1240
#[allow(unused)]
use proconio::marker::*;
use proconio::{fastout, input};
#[allow(unused)]
use std::cmp::{max, min, Reverse};
#[allow(unused)]
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

#[fastout]
fn main() {
    input! {
        x: i64,
        n: usize,
        p: [i64; n],
    }

    let mut cur = 200;
    let mut ans = 0;
    for i in 0..=101 {
        if p.iter().all(|&r| r != i) {
            if (i - x).abs() < cur {
                cur = (i - x).abs();
                ans = i;
            }
        }
    }
    println!("{}", ans);
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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;
}

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    vec<ll> a(n);
    REP(i, n) {
        cin >> a[i];
    }

    a.push_back(-INF);
    bool flag = false;
    ll now = 1000;
    ll kabu = 0;
    REP(i, n) {
        if(flag) {
            if(a[i] > a[i + 1]) {
                now += kabu * a[i];
                kabu = 0;
                flag = false;
            }
        } else {
            if(a[i] < a[i + 1]) {
                kabu += now / a[i];
                now -= now / a[i] * a[i];
                flag = true;
            }
        }
    }
    cout << now << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int a,b;
    int count = 0;
    cin >> a >>b;
    if(a > b)
    {
        count += a;
        a-=1;
    }
    else
    {
        count+=b;
        b-=1;
    }
    
    if(a > b)
    {
        count += a;
        a-=1;
    }
    else
    {
        count+=b;
        b-=1;
    }

    cout << count;

}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
p = [True] * (10 ** 6 + 1)
s = list(set(a))
for x in s:
    t = x * 2
    while t <= 10 ** 6:
        p[t] = False
        t += x
ans = 0
for x in a:
    if c[x] == 1 and p[x] == True:
        ans += 1
print(ans)


Measured memory_bytes: 158172
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
 
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 1e4+1;
const ll inf = 1e9+7;

int main() {
	fastio;
	ll a,b,c,k,cont=0;
    cin>>a>>b>>c>>k;
    while(a>=b){
        b*=2;
        cont++;	
    }
    while(c<=b){
        c*=2;
        cont++;
    }
    if(cont<=k) cout<<"Yes\n";
    else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define P pair<ll, ll>
#define VI vector<ll>
#define int long long
using namespace std;

string S, T;

bool check(int x) {
  REP (j, T.size()) {
    if (S[x + j] != '?' && S[x + j] != T[j]) {
      return false;
    }
  }
  return true;
}

void solve() {
  for (int i = (int)(S.size())-(int)(T.size()); i >= 0; i--) {
    if (check(i)) {
      REP (j, T.size()) {
        S[i + j] = T[j];
      }
      for (char c: S) {
        if (c == '?') { cout << 'a'; }
        else { cout << c; }
      }
      cout << endl;
      return;
    }
  }
  cout << "UNRESTORABLE" << endl;
}

signed main() {
  cin >> S;
  cin >> T;

  solve();
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)

# a_1 + ... + a_n = M
# d * (b_1 + ... + b_n) = d * Q
# b_1 + ... + b_n = Q
# 1 + ... + 1 + (Q - (N - 1)) = Q
# a_1 = M / N

sq = Math.sqrt(m).ceil
k = 1
max = 1
1.upto(sq) do |k|
  next if m % k != 0 
    
  max = [k, max].max if k * n <= m
  max = [m / k, max].max if n <= k
end

p max


Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100

void push(int);
int pop(void);
int S[N],top;

int main(){
int x,i,j;
char s[N];

while( scanf("%s", s) != EOF ){
if ( s[0] == '+' ){
i=pop();
j=pop();
push(i+j);
} else if ( s[0] == '-' ){
i=pop();
j=pop();
push(j-i);
} else if ( s[0] == '*' ){
i=pop();
j=pop();
push(i*j);
} else {
push(atoi(s));

}
}
printf("%d\n",pop());
return 0;
}
void push(int x){
if(top==N){
printf("Stack overflow.\n");
return;
exit(2);
}
S[top] = x;
top++;
}
int pop(void){
if(top==0){
printf("Stack is empty.\n");
exit(3);
}
top--;
return S[top];
}



Measured memory_bytes: 2052
a, b, n = gets.chomp.split.map(&:to_f)

# y1 = (a * x1 / b).to_i   # 普通の直線の切り捨てまたは切り上げられる
# y2 = (x2 / b).to_i * a   # bの倍数になった時に固定値が変化する

y1 = (a * n / b).to_i
y2 = (n / b).to_i * a
result = (y1 - y2).to_i

# 一段上がる一つ前
x = (((n / b).to_i * b) - 1).to_f
if x > 0
  y1 = (a * x / b).to_i
  y2 = (x / b).to_i * a
  result = [(y1 - y2).to_i, result].max
end
puts result

Measured memory_bytes: 14392
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, S: "List[str]"):

    A = 0
    count = 0
    for B in range(N):
        # print("***", B)
        flag = True
        # for i in range(N):
        #     print(S[i][B:]+S[i][:B])
        for i in range(N):
            for j in range(i, N):
                # print(i, j, j-B, S[i][j-B], S[j][i-B])
                if S[i][j-B] != S[j][i-B]:
                    flag = False
                    break
            if flag is False:
                break
        if flag:
            count += 1
    print(count*N)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41944
/***********************************************
 *                   _ooOoo_                   *
 *                  o8888888o                  *
 *                  88" . "88                  *
 *                  (| -_- |)                  *
 *                  O\  =  /O                  *
 *               ____/`---'\____               *
 *             .'  \\|     |//  `.             *
 *            /  \\|||  :  |||//  \            *
 *           /  _||||| -:- |||||-  \           *
 *           |   | \\\  -   * |    |           *
 *           | \_|  ''\---/''  |   |           *
 *           \  .-\__  `-`  ___/-. /           *
 *         ___`. .'  /--.--\  `. . __          *
 *      ."" '<  `.___\_<|>_/___.'  >'"".       *
 *     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     *
 *     \  \ `-.   \_ __\ /__ _/   .-` /  /     *
 *======`-.____`-.___\_____/___.-`____.-'======*
 *                   `=---='                   *
 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

             佛祖保佑       永无BUG

   本程序已经经过开光处理，绝无可能再产生bug
 **********************************************/
#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define ll long long
#define INF 0x3f3f3f3f
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
using namespace std;

int main(void)
{
    #ifdef test
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //test

    int N,f=1;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        int a;
        scanf("%d",&a);
        if(a%2==0)
        {
            if(a%3!=0&&a%5!=0)f=0;
        }
    }
    if(f==0)printf("DENIED\n");
    else printf("APPROVED\n");

    #ifdef test
    clockid_t end=clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    printf("\n\n\n\n\n");
    cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位
    cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位
    #endif //test
    return 0;
}


// ━━━━━━神兽出没━━━━━━
//      ┏┓       ┏┓
//     ┏┛┻━━━━━━━┛┻┓
//     ┃           ┃
//     ┃     ━     ┃
//     ????━????   ┃
//     ┃           ┃
//     ┃    ┻      ┃
//     ┃           ┃
//     ┗━┓       ┏━┛
//       ┃       ┃
//       ┃       ┃
//       ┃       ┗━━━┓
//       ┃           ┣┓
//       ┃           ┏┛
//       ┗┓┓┏━━━━━┳┓┏┛
//        ┃┫┫     ┃┫┫
//        ┗┻┛     ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s1,s2;
  cin>>s1;
  cin>>s2;
  int m=s1.size();
  int n=s2.size();
   vector<vector<int>> dp(m+1,vector<int>(n+1,0));
  for(int i=1;i<=m;i++)
  {
    for(int j=1;j<=n;j++)
    {
        if(s1[i-1]==s2[j-1])
          dp[i][j]=1+dp[i-1][j-1];
        else
          dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
  }
   string s;
    int i=m,j=n;
    while(i>0&&j>0)
    {
        if(s1[i-1]==s2[j-1])
        {
            s+=s1[i-1];
            i--;j--;
        }
        else if(dp[i][j-1]>=dp[i-1][j])
               j--;
        else 
            i--;
    }
     reverse(s.begin(),s.end());
    cout<<s;
}

Measured memory_bytes: 38648
use std::io::*;
use std::str::FromStr;

/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {    
    let x: i32 = read();
    let y: i32 = read();
    let cs =[0,300000,200000,100000];
    let mut sum: i32 = 0;
    if x==1 && y==1{
	sum = 1000000;
    }else {
	if x<4 {
	    sum += cs[x as usize];
	}
	if y<4 {
	    sum += cs[y as usize];
	}
    }
    println!("{}",sum);
}


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

using namespace std;

vector<int> adj[100100];
int n, m;
int dp[100100];

int cal(int u) {
	if (!dp[u]) {
		for (int v : adj[u]) {
			dp[u] = max(dp[u], cal(v));
		}
		dp[u]++;
	}
	return dp[u];
}

int main() {
	cin >> n >> m;
	while (m--) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
	}
	
	int ans = 0;
	for (int i = 1; i <= n; i++) ans = max(ans, cal(i));
	cout << ans - 1 << '\n';
}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    ll a[100000];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int arr[100000] = {};
    int cnt4 = 0, cnt2 = 0, cnt0 = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] % 4 == 0)
        {
            arr[i] = 2;
            cnt4++;
        }
        else if (a[i] % 2 == 0)
        {
            arr[i] = 1;
            cnt2++;
        }
        else
        {
            cnt0++;
        }
    }

    if (n % 2 && cnt4 >= cnt0 - 1)
        cout << "Yes" << endl;
    else if (cnt4 >= cnt0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/

/*==================================================*/
/*function*/

/*==================================================*/

int main() {

    int A, B, K;
    cin>>A>>B>>K;

    set<int> st;
    vector<int> ansv;

    for(int i = A; i <= A+K-1 && i <= B ; i++){
        if(st.find(i) != st.end()) continue;
        st.insert(i);
        ansv.push_back(i);
    }

    for(int i = B; i >= B-K+1 && i >= A ; i--){
        if(st.find(i) != st.end()) continue;
        st.insert(i);
        ansv.push_back(i);
    }

    sort(ansv.begin(), ansv.end());

    for(int e : ansv){
        cout<<e<<endl;
    }

    return 0;
}


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

ll gcd ( ll x, ll y ) { return y ? gcd(y,x%y) : x;}

vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    for ( ll i = 2; i*i <= n; ++i ) {
        if ( n % i ) continue;
        res.emplace_back(i, 0);
        while (n%i ==0 ){
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

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

    ll g = gcd(a, b);

    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int > pi;
typedef vector<ll> vi;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define FOR(a ,b) for(int i = a; i < b; i++) 
#define e "\n"


int main(){
	int n;
	cin >> n;
	vector<int> dp(3,0);
	for(int day = 0 ; day < n ;day++){
		vector<int> new_dp (3,0);
		vector<int> c(3);
		for(int &x : c) cin >> x;
		
		for(int i = 0 ; i < 3;i++){
			for(int j = 0;j < 3;j++){
				if(i != j){
					new_dp[j] = max(new_dp[j], dp[i]+c[j]);
				}
			}
		}
		dp = new_dp;
	}
	cout << max(dp[0], max(dp[1],dp[2])) << e;
}


Measured memory_bytes: 256
import os

import cmath
import math
import sys

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

A, B, H, M = list(map(int, sys.stdin.buffer.readline().split()))

h = A * cmath.rect(1, (H / 12 + M / 60 / 12) * math.pi * 2)
m = B * cmath.rect(1, (M / 60) * math.pi * 2)
print(abs(h - m))


Measured memory_bytes: 9468
"use strict";

function find(num, ary, l, r) {
  const p = Math.floor((r + l) / 2);

  if (r - l === 0) {
    if (ary[p] < num) {
      return p + 1;
    } else {
      return p;
    }
  } else if (r - l === 1) {
    if (num <= ary[l]) {
      return l;
    } else if (ary[l] < num && num <= ary[r]) {
      return r;
    } else if (ary[r] < num) {
      return r + 1;
    }
  }

  if (num < ary[p]) {
    return find(num, ary, l, p - 1);
  } else if (ary[p] < num) {
    return find(num, ary, p + 1, r);
  } else {
    return p;
  }
}

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split("\n");

const firstLine = input[0].split(" ").map((val) => parseInt(val, 10));

const N = firstLine[0];
const Q = firstLine[1];

const S = input[1];

const indexes = [];

for (let i = 0; i < N; i++) {
  if (S[i] !== "A") {
    continue;
  }

  if (S[i + 1] === "C") {
    indexes.push(i);
  }
}

for (let i = 2; i < Q + 2; i++) {
  const line = input[i].split(" ").map((val) => parseInt(val, 10));
  const l = line[0] - 1;
  const r = line[1] - 1;

  let firstIndex = -1;
  let lastIndex = -1;

  firstIndex = find(l, indexes, 0, indexes.length);
  lastIndex = find(r, indexes, 0, indexes.length);

  // console.log(firstIndex, lastIndex);

  if (firstIndex === -1 || lastIndex === -1) {
    console.log(0);
  } else {
    console.log(lastIndex - firstIndex);
  }
}


Measured memory_bytes: 33272
#include <iostream>
#include <cctype>

int main() {
  char a;
  int cnt[26] = {0};
  while (std::cin >> a) {
    if (std::isalpha(a)) {
      if (std::isupper(a)) {
        a = std::tolower(a);
      }
      int num = a - 'a';
      cnt[num]++;
    }
  }
  for (int i = 0; i < 26; i++) {
    a = 'a' + i;
    std::cout << a << " : " << cnt[i] << "\n";
  }
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m,a[10010];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a[i];
		n-=a[i];
		if(n<0){cout<<-1;return 0;}
	}
	cout<<n;
    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main() {
  char A, B;
  scanf("%c %c", &A, &B);
  if(A > B) {
    printf(">\n");
  } else if(A < B) {
    printf("<\n");
  } else {
    printf("=\n");
  }
  
  return 0;
}

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

typedef long long ll;
const ll mod=1e9+7;
const int N=200000;

void Run()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
ll a[N],b[N];
int main()
{
    Run();
    int n,x;
    cin>>x>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=0;i<110;i++)
    {
        if(b[x-i]==0)
        {
            cout<<x-i;
            break;
        }
        else if(b[x+i]==0)
        {
            cout<<x+i;
            break;
        }
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

long long a, b, c, x, y, s, t;

int main(){

    cin >> a >> b >> c >> x >> y;

    if(2*c >= (a+b)){
        cout << (a*x) + (b*y);
        return 0; 
    }

    s = min(x, y);
    if(s == x){
        t = t + (x*2*c);
        if(c*2 < b){
            t = t + (y-x)*c*2;
        } else{
            t = t + (y-x)*b;
        }
    }else if(s == y){
        t = t + (y*2*c);
        if(c*2 < a){
            t = t + (x-y)*c*2;
        } else{
            t = t + (x-y)*a;
        }
    }

    cout << t;

    







}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;

bool solve(vint a, int b){
	set<int>	s, ss;
	s.insert(0);
	for(auto t : a){
		ss.clear();
		for(auto u : s){
			ss.insert(u+t);
			ss.insert(u-t);
		}
		s = ss;
	}
	return s.count(b);
}
int main(){
	string s;
	int x, y;
	cin >> s; cin >> x >> y;
	vint X, Y;
	bool f = true;
	int start = 0;
	while(start < s.size() && s[start] == 'F'){
		x--;
		start++;
	}
	for(int i = start;i < s.size();i++){
		int d = 0;
		while(s[i] == 'F'){
			d++;
			i++;
			if(i == s.size())	break;
		}
		if(d > 0) {if(f)	X.push_back(d); else Y.push_back(d);}
		f = !f;
	}
	bool ans = solve(X, x) && solve(Y, y);
	if(ans)	cout << "Yes" << endl;	else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int kaijou(int n){
    if(n==1) return 1;
    return n+kaijou(n-1);
}

int main(void)
{
    int a,b,c,d,i,j,k,n,x[10];

    cin >> a;
  
    cout << kaijou(a);
    return 0;
}

Measured memory_bytes: 256
import math
x = int(input())
b = 0
ans = []
while True:
    n = x - b**5
    if n < 0:
        break
    a = int(math.pow(n, 1/5))
    if a**5 == n:
       ans.append(a)
       ans.append(-b)
       break
    b += 1

if len(ans) != 0:
    print(*ans)
else:
    b = 0
    while True:
        n = x + b**5
        a = int(math.pow(n, 1/5))
        if a**5 == n:
           ans.append(a)
           ans.append(b)
           break
        b += 1
    print(*ans)

Measured memory_bytes: 9476
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll n,k,ans,t;
int main()
{
	scanf("%lld%lld",&n,&k);
	if(k==1)
	{
		printf("%lld\n",n*n*n);
	}
	else if(k==2)
	{
		ll ans=(n+1)/2;
		printf("%lld\n",ans*ans*ans+(n-ans)*(n-ans)*(n-ans));
	}
	else if(k&1)
	{
		ll ans=n/k;
		printf("%lld\n",ans*ans*ans);
	}
	else
	{
		ll ans=n/k;
		if(n>=k/2)t=n-k/2,t=t/k+1;else t=0;
		printf("%lld\n",ans*ans*ans+t*t*t);
	}
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long n = in.nextLong();
		System.out.println(solve(n));
		in.close();
	}

	private static long solve(long n) {
		long r = (long) (Math.pow(n, 0.5) + 1);
		for (; r > 1; r--)
			if (n % r == 0)
				return n / r + r - 2;
		return n - 1;
	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <unordered_map>
using namespace std;

string characters[38];

void init() {
	for(int i = 0; i < 26; ++i) {
		characters[i] = 'a' + i;
	}
	characters[26] = "ld";
	characters[27] = "mb";
	characters[28] = "mp";
	characters[29] = "nc";
	characters[30] = "nd";
	characters[31] = "ng";
	characters[32] = "nt";
	characters[33] = "nw";
	characters[34] = "ps";
	characters[35] = "qu";
	characters[36] = "cw";
	characters[37] = "ts";
}

string get_char(int &idx, const string &word) {
	if(idx + 1 < word.size()) {
		const string tmp = word.substr(idx, 2);
		if(find(begin(characters), end(characters), word.substr(idx, 2)) != end(characters)) {
			idx += 2;
			return tmp;
		}
	}

	return idx < word.size() ? string(1, word[idx++]) : "";
}

void calc_input(unordered_map<string, unordered_map<string, int>> &cnt) {
	string sentence;
	getline(cin, sentence);

	istringstream iss(sentence);
	for(string word; iss >> word;) {
		int idx = 0;
		string current = get_char(idx, word);
		string next;

		for(string next; (next = get_char(idx, word)) != "";) {
			++cnt[current][next];
			current = move(next);
		}
	}
}

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

	init();

	int n;
	cin >> n;
	cin.ignore();

	unordered_map<string, unordered_map<string, int>> cnt;
	while(n--) calc_input(cnt);

	for(const auto &character : characters) {
		int max_cnt = 0;
		string max_char = "a";
		const auto &c_cnt = cnt[character];

		for(const auto &target : characters) {
			if(c_cnt.count(target) && max_cnt < c_cnt.at(target)) {
				max_cnt = c_cnt.at(target);
				max_char = target;
			}

		}

		cout << character << " " << max_char << " " << max_cnt << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1316
#include <iostream>
#include <string>

using namespace std;

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

    string s;
    cin >> s;

    bool flag = true;
    for (int i = a + 1; i < c && flag; i++) {
        if (s[i - 1] == '#' && s[i] == '#') {
            flag = false;
        }
    }

    for (int i = b + 1; i < d && flag; i++) {
        if (s[i - 1] == '#' && s[i] == '#') {
            flag = false;
        }
    }

    if (c > d) {
        bool f = false;
        for (int i = b; i <= d; i++) {
            if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
                f = true;
                break;
            }
        }

        if (!f) {
            flag = false;
        }
    }

    cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var N = IO.RLong;
            var A = IO.RSLong;

            var cum = new long[N + 1];
            for (int i = 0; i < N; i++)
            {
                cum[i + 1] = cum[i] + A[i];
            }

            var ans = long.MaxValue;
            for (int i = 0; i < N; i++)
            {
                ans = Min(ans, Abs(cum[i] - (cum[N] - cum[i])));
            }
            WriteLine(ans);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 44420
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

bool solve(const int n, const int a)
{
  int value = n;
  int c  = (n / 500);
  value -=  c * 500;
  return value <= a;
}


int main()
{
  int n, a;
  cin >> n >> a;
  solve(n, a) ? cout << "Yes\n" : cout << "No\n";
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXSZ=3000;
const int MAXLEN=3000;
const int MOD=1000000007;

int sz,len;

int dp1[MAXLEN+1][MAXLEN+1]; // dp1[i][j] = #ways to reach height j in i steps up/down (never going below 1 or above sz)
int dp2[MAXLEN+1][MAXLEN+1]; // dp2[i][j] = #ways to reach height j in i steps up/down (never going below 0 or above sz-1)
int dp3[MAXLEN+1]; // dp3[i] = sum of dp2[i][*]
int C[MAXLEN+1][MAXLEN+1];
int p2[MAXLEN+1];

ll ways[MAXLEN+1];

inline void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }
void run() {
	scanf("%d%d",&sz,&len); --len;

	memset(dp1,0,sizeof(dp1)); dp1[0][0]=1; REP(i,len) REPE(j,sz) { if(j-1>=1) inc(dp1[i+1][j-1],dp1[i][j]); if(j+1<=sz-1) inc(dp1[i+1][j+1],dp1[i][j]); }
	memset(dp2,0,sizeof(dp2)); dp2[0][0]=1; REP(i,len) REPE(j,sz) { if(j-1>=0) inc(dp2[i+1][j-1],dp2[i][j]); if(j+1<=sz-1) inc(dp2[i+1][j+1],dp2[i][j]); }
	memset(dp3,0,sizeof(dp3)); REPE(i,len) REPE(j,sz) inc(dp3[i],dp2[i][j]);
	memset(C,0,sizeof(C)); REPE(i,len) { C[i][0]=C[i][i]=1; FOR(j,1,i) { inc(C[i][j],C[i-1][j-1]); inc(C[i][j],C[i-1][j]); } }
	p2[0]=1; REP(i,len) p2[i+1]=(ll)2*p2[i]%MOD;

	ll ret=0;
	memset(ways,0,sizeof(ways));
	REPE(downlen,len) REPE(mxdown,min(sz-1,downlen)) {
		ways[downlen]+=dp1[downlen][mxdown];
		ways[downlen]%=MOD;
	}
	REPE(nhor,len) REPE(downlen,len-nhor) {
		int uplen=len-nhor-downlen;
		ll cur=(ll)p2[nhor]*C[len][nhor]%MOD*ways[downlen]%MOD*dp3[uplen]%MOD;
		//printf("nhor=%d downlen=%d uplen=%d -> %lld\n",nhor,downlen,uplen,cur);
		ret+=cur; ret%=MOD;
	}
	ret%=MOD;
	printf("%lld\n",ret*4%MOD);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 105856