akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<limits.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define MAX 1001

vector<vector<int>> init_c(MAX, vector<int>(MAX, -1));
vector<vector<int>> c(MAX, vector<int>(MAX, -1));
string a, b;

int lcs(int i, int j){
    if(i == 0 || j == 0){
        c.at(i).at(j) = 0;

    }else if(c.at(i).at(j) != -1){
        return c.at(i).at(j);

    }else if(a.at(i - 1) == b.at(j - 1)){
        c.at(i).at(j) = lcs(i-1, j-1) + 1;

    }else{
        c.at(i).at(j) = max(lcs(i, j - 1), lcs(i - 1, j));
    }
    // cout << i << " " << j << " " << c.at(i).at(j) << endl;
    
    return c.at(i).at(j);
}

int main(){
    int q; cin >> q;
    rep(i, q){
        c = init_c;
        cin >> a; cin >> b;
        cout << lcs(a.size(), b.size()) << endl;
    }

}



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

    #define ll long long
    #define pb push_back
    

    int main() {
      
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      
      
     ll i,p,q,r;
     cin>>p>>q>>r;
     ll m=max(p,max(q,r));
     if(m==p)i=q+r;
     else if(m==q)i=p+r;
     else i=p+q;
     cout<<i;
     


     
     
      return 0;
    } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s,t;
	cin>>s>>t;
	int res = sz(t);
	for(int i=0;i<sz(s);i++)
	{
		if(i+sz(t)<=sz(s))
		{
			int c = 0;
			for(int j=0;j<sz(t);j++)
				if(s[i+j] != t[j])
					c++;
			res = min(res, c);
		}
	}
	cout<<res<<"\n";
	return 0;
}

Measured memory_bytes: 3660
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var array = new int[n];
            
            for(var i = 0; i < n; i++)
            {
                array[i] = int.Parse(ReadLine());
            }

            var dp = new int[n];
            for(var i = 0; i < n; i++)
            {
                dp[i] = int.MaxValue;
            }

            foreach (var a in array)
            {
                var ok = n - 1;
                var ng = -1;

                while (Abs(ok - ng) > 1)
                {
                    var index = (ok + ng) / 2;
                    if (a <= dp[index])
                    {
                        ok = index;
                    }
                    else
                    {
                        ng = index;
                    }
                }
                dp[ok] = a;
            }

            WriteLine(dp.Count(value => value != int.MaxValue));
        }
    }
}



Measured memory_bytes: 20576
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    s = input()
    n = len(s)
    fac = 1
    cur = 0
    value = [0] * 2019
    value[0] += 1
    for i in range(n):
        add = int(s[n - 1 - i])
        cur = (cur + fac * add) % 2019
        fac = (fac * 10) % 2019
        value[cur] += 1
    ans = 0
    for i in range(2019):
        ans += value[i] * (value[i] - 1) // 2
        
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 27388
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
//#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


//namespace mp = boost::multiprecision;

//using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int size(int n) {
	int count = 0;
	while (n > 0) {
		n /= 10;
		count++;
	}
	return count;
}

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}
int main() {
	int N;
	int ret=scanf("%d", &N);
	int sizeN = size(N);
	string S357 = "357";
	int i = 21;
	int ans = 0;
	while (i < pow(4, sizeN)) {
		deque<char>tmpS;
		vector<int>count(3);
		int tmp = i;
		bool flag = true;
		while (tmp > 0) {
			int ttmp = tmp % 4;
			rep(j, 3) {
				if (ttmp  == j + 1) {
					tmpS.push_front(S357[j]);
					count[j]++;
				}
				else if (ttmp == 0) {
					flag = false;
					break;
				}
			}
			tmp /= 4;
		}
		if (*min_element(all(count)) > 0&&flag) {
			string s = "";
			rep(j, tmpS.size()) {
				s += tmpS[j];
			}
			int aa = stoi(s);
			if (aa <= N) {
				ans++;
			}
		}

		i++;
	}
	cout << ans << endl;

}


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

N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

ans = 0
for i in range(N)[::-1]:
    ans += (B[i] - (ans + A[i]) % B[i]) % B[i]

print(ans)


Measured memory_bytes: 10868
/*
 * abc152c.cpp
 * Copyright (C) 2020 itachi <itachi@itachi-Z510>
 *
 * Distributed under terms of the MIT license.
 */

#include <bits/stdc++.h>

using namespace std;

char c[100];
int main() {
    int n;
    cin >> n;
    int mi = INT_MAX;
    int count = 0;
    for (int i=0;i<n;i++) {
        int m;
        cin >> m;
        if (m<mi) {
            count++;
            mi = m;
        }
    }
    cout << count << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<pair<int, int> > vec;
    REP2(i, 1, n){
        int a; cin >> a;
        vec.push_back(make_pair(a, i));
    }
    // pairのfirstでソート＝生徒の存在数順
    sort(vec.begin(), vec.end());

    // sort済みvecのsecondが出席番号
    rep(i, n){
        if(i == n - 1){
            cout << vec[i].second;
        }else{
            cout << vec[i].second << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 1780
a,b,c,d = gets.chomp.split("").map(&:to_i)
pred = 10*a + b
last = 10*c + d
if last > 0 and last <= 12
  if pred > 0 and pred <= 12
    puts "AMBIGUOUS"
  else
    puts "YYMM"
  end
elsif pred > 0 and pred <= 12
  if last > 12 or last == 0
    puts "MMYY"
  elsif last > 0 and last <= 12
    puts "AMBIGUOUS"
  end
else
  puts "NA"
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,A,B,i,j,ans,l,r,f[5010],mx,a[5010];
int main(){
	scanf("%lld%lld%lld",&n,&A,&B);
	ans=1e18;
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);mx=0;
		f[i]=1e18;l=r=0;
		for(j=i-1;j;j--){
			if(a[j]<a[i]&&a[j]>mx)f[i]=min(f[i],f[j]+l*B+r*A);
			if(a[j]>a[i])r++;
			 else l++,mx=max(mx,a[j]);
		}
		if(mx==0)f[i]=r*A;
		for(j=i+1;j<=n;j++)mx=max(mx,a[j]);
		if(mx<a[i])ans=min(ans,f[i]+B*(n-i));
		//printf("%lld\n",f[i]);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 3920
class Dice
  def initialize(n, s, e, w, t, b)
    $north = n
    $south = s
    $east = e
    $west = w
    $top = t
    $bottom = b
  end

  def move_north
    north = $north
    south = $south
    top = $top
    bottom = $bottom
    $north = top
    $top = south
    $bottom = north
    $south = bottom
  end

  def move_south
    north = $north
    south = $south
    top = $top
    bottom = $bottom
    $south = top
    $bottom = south
    $north = bottom
    $top = north
  end

  def move_east
    top = $top
    bottom = $bottom
    east = $east
    west = $west
    $east = top
    $bottom = east
    $west = bottom
    $top = west
  end

  def move_west
    top = $top
    bottom = $bottom
    east = $east
    west = $west
    $west = top
    $bottom = west
    $east = bottom
    $top = east
  end

  def execute_orders(orders)
    length = orders.length
    for i in 0...length
      if orders[i] == "N"
        move_north
      elsif orders[i] == "S"
        move_south
      elsif orders[i] == "E"
        move_east
      elsif orders[i] == "W"
        move_west
      else
        puts "error!"
      end
    end
  end

  def find_south_by_ne(order_n, order_e)
    "e = #{order_e}"
    loop do
      tmp = execute_orders(["N", "S", "E", "W"].sample)
      if $top == order_n && $south == order_e
        break
      end
    end
    return $east
  end
end

dice_number = gets.chomp.split.map(&:to_i)
t = dice_number[0]
s = dice_number[1]
e = dice_number[2]
w = dice_number[3]
n = dice_number[4]
b = dice_number[5]
num = gets.chomp.to_i
answers = []
num.times do
  input_ne = gets.chomp.split.map(&:to_i)
  order_n = input_ne[0]
  order_e = input_ne[1]
  dice = Dice.new(n, s, e, w, t, b)
  answers << dice.find_south_by_ne(order_n, order_e)
end
answers.each do |i|
  puts i
end

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,n,x;
    set<int>st;
    cin >> n;
    for(i=0;i<n;i++)cin >> x,st.insert(x);
    if(st.SZ == n)cout << "YES";
    else cout << "NO";
    return 0;
}


Measured memory_bytes: 9600
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	for a := 0; ; a++ {
		rest := n - 4*a
		if rest < 0 {
			fmt.Println("No")
			return
		}
		if rest%7 == 0 {
			fmt.Println("Yes")
			return
		}
	}
}


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

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define ALL(v) v.begin(), v.end()

const int MAX = 1e9;
ll S;

void solve() {
    ll lo = 0, hi = 2e9; // (x-1)^2 < S /\ S <= x^2なるxを求める
    while (hi - lo > 1) {
        ll mid = (hi+lo)/2;
        if (mid*mid >= S) hi = mid;
        else lo = mid;
    }

    ll x = hi, w = x, y = 1, z = x*w-S;
    if (z > x) {
        w--;
        z = x*w-S;
    }
    cout << "0 0 " << x << " " << y << " " << z << " " << w << endl;
}

int main() {
    cin >> S;
    solve();
}

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

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

vector<pair<PII, int>> go(int L, int k)
{
	if (L < k)
	{
		vector<pair<PII, int>> res;
		REP(i, L)
			res.push_back(MP(MP(1, 2), i));

		return res;
	}

	int md = L%k;
	if (md)
	{
		auto list = go(L - md, k);
		int last = list.back().first.second;

		REP(i, md)
			list.push_back(MP(MP(1, last), L - i - 1));

		return list;
	}

	auto list = go(L / k, k);
	int last = list.back().first.second;
	list.push_back(MP(MP(last, last + 1), 0));
	REP(i, k - 1)
		list.push_back(MP(MP(last, last + 1), (i + 1)*L / k));

	return list;
}

vector<pair<PII, int>> go(int L)
{
	FORQ(k, 2, 65)
	{
		auto res = go(L, k);
		if (res.back().first.second < 21 && res.size() < 61)
			return res;
	}

	return{};
}

int main()
{
	int L;
	scanf("%d", &L);

	auto list = go(L);

	printf("%d %d\n", list.back().first.second, list.size());
	for (const auto& p : list)
		printf("%d %d %d\n", p.first.first, p.first.second, p.second);

	return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    unsigned long long int n,m; cin >> n >> m;
    int c=0;
    while(n--){
        unsigned long long int a,b; cin >>a >>b;
        if(((a*a)+(b*b))<=(m*m))
            c++;
    } 
    cout << c;
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	long long ret=0;
	for(int i=0;i<a;i++){
		ret+=b[i]/2;
		b[i]%=2;
		if(i<a-1&&b[i]&&b[i+1]){
			ret++;
			b[i]--;b[i+1]--;
		}
	}
	printf("%lld\n",ret);
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int ans = 0;
  while (true) {
    int maxi = *max_element(all(h));
    if (maxi == 0) break;
    rep(i, n) if (h[i] == maxi) {
      for (int j = i; j < n && h[j] == maxi; ++j) {
        h[j]--;
      }
      break;
    }
    ++ans;
  }
  out(ans);
}


Measured memory_bytes: 3600
import numpy as np

N = int(input())
H = np.array(input().split(), dtype=np.int32)

def myfunc(left, right):
    if right<left:
        return 0
    idx = left+H[left:right+1].argmin()
    m = H[idx]
    H[left:right+1]-=m
    return m+myfunc(left, idx-1)+myfunc(idx+1, right)

print(myfunc(0, N-1))

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

int main(){
int N; int i=0; long co=0;
cin >> N;
vector<long> a(N+1); vector<long> b(N);
while(i<N+1){
cin >> a.at(i++);
}
i=0;
while(i<N){
cin >> b.at(i++);
}

int che=0; long by,an;
for(int j=N; j>=1; j--){
    by = b.at(j-1);
    an = a.at(j);
    if(by>=an){
        co+=an;
        by-=an;
    }else{
        co+=by;
        che++;
    }
    if(che==0){
        if(by >= a.at(j-1)){
            co += a.at(j-1);
            a.at(j-1)=0;
        }else{
            co += by;
            a.at(j-1) -= by;
        }
    }
    che = 0;
}
cout << co << endl;
return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  sort(ALL(a));
  int mm = n/2, ml = n/2-1, mr = n/2+1;
  ll ans = 0;
  rep(i, n){
    if(i != mm && i != ml){
      ans += (ll)abs(a.at(i) - a.at(mm)) * 2;
    }
  }
  ans += abs(a.at(mm) - a.at(ml));

  ll add = 0;
  if(n % 2 != 0){
    rep(i, n){
      if(i != mm && i != mr){
        add += (ll)abs(a.at(i) - a.at(mm)) * 2;
      }
    }
    add += abs(a.at(mm) - a.at(mr));
  }
  ans = max(ans, add);
  cout << ans << endl;

  return 0;
}

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



int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int i,t;
    cin>>t;
    vector<int> v;

    for(i=0; i<t; i++){
        int n;
        cin>>n;
        v.push_back(n);
    }

    int val=1,c=0;
    for(i=0; i<t; i++){
        if(v[i]==val){
            val++;
            c++;
        }
    }

    int r = t - c;
    if(r==t) cout<<"-1\n";
    else cout<<r<<"\n";
    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
  string s;
  cin >>s;
  int L=s.length();
  int res=0;
  int x,y,z=0;
  for(int i=0;i<L;++i){
    if(s[i]=='A'){
      x=i;
      break;
    }
  }
  for(int i=L-1;i>-1; --i){
    if(s[i]=='Z'){
      y=i;
      break;
    }
  }
  cout << y-x+1<<endl;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10 ** 6)

n, m = map(int, input().split())
e = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    e[a-1].append(b-1)

c = [0] * n
ans = []
def search_path(p, temp):
    c[p] = 1
    for x in e[p]:
        if x in temp:
            print(-99999)
            exit()
        else:
            search_path(x, temp + [x])


t = 1
for i in range(n):
    if c[i] == 0:
        ans = search_path(i, [i])

print(-1)


Measured memory_bytes: 7924
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort(reverse=True)

if n % 2 == 0:
    res = 0
    for i in range(n//2-1):
        res += a[i] * 2
    res += a[n//2-1]
    res -= a[n//2]
    for i in range(n//2+1, n):
        res -= a[i] * 2
    print(res)
else:
    res1 = 0
    for i in range(n//2-1):
        res1 += a[i] * 2
    res1 += a[n//2-1] + a[n//2]
    for i in range(n//2+1, n):
        res1 -= a[i] * 2
    
    res2 = 0
    for i in range(n//2):
        res2 += a[i] * 2
    res2 -= a[n//2] + a[n//2+1]
    for i in range(n//2+2, n):
        res2 -= a[i] * 2
    print(max(res1, res2))


Measured memory_bytes: 7512
//have fun
#include <bits/stdc++.h>
using namespace std;
#define mod 		998244353
#define ll 		long long
#define mp 		make_pair
#define pb 		push_back
#define forn(i,n) 	for(int i=0;i<n;i++)
#define for1(i,n) 	for(int i=1;i<n;i++)
#define ford(i,n) 	for(int i=n-1;i>=0;i--)
#define vi 		vector<int>
#define vl 		vector<ll>
#define pii 		pair<int,int>
#define pll 		pair<ll,ll>
#define vpi 		vector<pair<int,int> >
#define vpl		vector<pair<ll,ll> >
#define vvi 		vector<vector<int> >
#define vvl 		vector<vector<ll> >
#define ull 		unsigned long long
#define IOS 		ios_base::sync_with_stdio(false);
#define PI 		3.1415926535897932384626
#define ff 		first
#define ss 		second
#define char2Int(c) 	(c-'0')
#define FOREACH(i,t) 	for (auto i=t.begin(); i!=t.end(); i++)
#define clr(a,x) 	memset(a,x,sizeof(a)) //set elements of array to some value
#define all(x)		(x).begin(),(x).end()//cout<<"Case #"<<zzz<<": ";
void solve()
{
    int x,n;cin>>x>>n;set<int> p;forn(i,n){int x;cin>>x;p.insert(x);}
    int ans=x;
    while(p.find(ans)!=p.end())++ans;
    int curr=ans-x;
    int ptr=x;
    while(p.find(ptr)!=p.end())--ptr;
    if(curr<x-ptr)cout<<ans<<endl;
    else cout<<ptr<<endl;
}
int main()
{
    IOS;cin.tie(NULL);
    int zz=1;
    for(int zzz=1;zzz<=zz;zzz++)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3664
#include<stdio.h>
#define MAX 2000000
int A[MAX];
int H;

void swap(int *a,int *b){
  int tmp=*a;
  *a=*b;*b=tmp;
}
void maxHeapify(int i){
  int l = 2*i;
  int r = 2*i+1;
  int largest;
  
  if(l <= H && A[l] > A[i])largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest])largest = r;

  if(largest != i){
    swap(&A[i],&A[largest]); 
    maxHeapify(largest); 
  }
}
void Insert(int x){
  int i;
  i=H;
  A[i]=x;
  while(i>=2&&A[i/2]<A[i]){
    swap(&A[i],&A[i/2]);
    i=i/2;
  }
}
int extract(void){
  int maxv;
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(1);

  return maxv;
}

int main(){
  char com[10];
  int i,key;

  while(1){
    scanf("%s",com);
    if(com[0]=='i'){
      H++;
      scanf("%d",&key);
      Insert(key);
    }
    else if(com[1]=='x') printf("%d\n",extract());
    else break;
  }
  return 0;
}





Measured memory_bytes: 5604
s = input()
ans = 0

def plus_in(num, i):
  if i < len(s):
    plus_in(num + s[i], i + 1)
    plus_in(num + "+" + s[i], i + 1)
  else:
    nums = map(int, num.split("+"))
    sum_nums = sum(nums)
    global ans
    ans += sum_nums


plus_in(s[0], 1)
print(ans)


Measured memory_bytes: 2940
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 200005
#define MM (1<<18)
#define ML 19
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int L[ML][MN],R[ML][MN],f[MM],g[MM],x[MN];
bool vis[MM];
int n,v,j,val;
int main()
{
	n=in();v=in();
	for (int i=1;i<=n;++i) x[i]=in();
	for (j=0,val=v;;val>>=1,++j){
		L[j][0]=L[j][1]=1;
		R[j][n]=R[j][n+1]=n;
		for (int i=2;i<=n;++i)
		if (x[i]-x[i-1]>val) L[j][i]=i;else L[j][i]=L[j][i-1];
		for (int i=n-1;i;--i)
		if (x[i+1]-x[i]>val) R[j][i]=i;else R[j][i]=R[j][i+1];
		if (!val) break;
	}for (int i=0;i<(1<<j);++i) f[i]=0,g[i]=n+1;
	for (int i=0;i<(1<<j);++i){
		for (int k=0;k<j;++k) if (!(i&(1<<k))){
			f[(i|(1<<k))]=max(f[i|(1<<k)],R[k+1][f[i]+1]);
			g[(i|(1<<k))]=min(g[i|(1<<k)],L[k+1][g[i]-1]);
		}
	}
	for (int i=0;i<(1<<j);++i)
	if (R[0][f[i]+1]>=g[((1<<j)-1)^i]-1) vis[R[0][f[i]+1]]=1;
	for (int i=1;i<=n;++i) puts(vis[R[0][i]]?"Possible":"Impossible");
	return 0;
}

Measured memory_bytes: 34816
module Main where
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import qualified Data.Vector.Generic           as VG
import qualified Data.Vector.Generic.Mutable   as VGM
import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List                      ( unfoldr )
import           Data.Map.Strict                ( Map )
import qualified Data.Map.Strict               as Map
import           Data.IntMap                    ( IntMap )
import qualified Data.IntMap                   as IntMap
import           Data.HashMap.Strict            ( HashMap )
import qualified Data.HashMap.Strict           as HashMap
import           Data.Maybe

main :: IO ()
main = do
  n <- readLn :: IO Int
  bss <- V.replicateM n getLine
  let m = Map.fromListWith (+) $ V.toList $ V.zip bss $ V.replicate n (1::Int)
  putStrLn $ "AC x " ++ show (fromMaybe 0 (m Map.!? "AC"))
  putStrLn $ "WA x " ++ show (fromMaybe 0 (m Map.!? "WA"))
  putStrLn $ "TLE x " ++ show (fromMaybe 0 (m Map.!? "TLE"))
  putStrLn $ "RE x " ++ show (fromMaybe 0 (m Map.!? "RE"))


Measured memory_bytes: 27396
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#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 ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  int a;
  cin >> a;
  if(a<30)
cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int A,B;cin>>A>>B;
	cout<<max(A+B,max(A-B,A*B))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    if (A+B >= C) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n, t = 0;
    cin >> n;
    int a[n + 1];
    FOR(i, 1, n)
    {
        cin >> a[i];
        if(a[i] != i) t++;
    }
    if(t > 2) cout << "NO";
    else
    {
        cout << "YES";
    }
    return 0;
}


Measured memory_bytes: 256
const main = (input) => {
  var N = input[0].split(" ")[0];
  var K = input[0].split(" ")[1];
  var Q = input[0].split(" ")[2];

  var map = {};
  for(var i=1;i<=Q;i++){
    var x = input[i];
    map[x] = (map[x]||0) + 1;
  }
  for(var i=1;i<=N;i++){
    console.log(Q-(map[i]||0)<K?"Yes":"No");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 30512
N = int(input())
b = list(map(int,input().split()))

ans = []
while len(b):
    memo = -1
    for key,val in enumerate(b):
        if key+1==val:
            memo = key
    if memo != -1:
        ans.append(b.pop(memo))
    else:
        break

if len(b):
    print(-1)
else:
    ans.reverse()
    for a in ans:
        print(a)

Measured memory_bytes: 63832
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

struct UnionFind {
  vector<int> par;//parent

  vector<int>nodes;

  UnionFind(int N): par(N), nodes(N)
  {
    for(int i = 0; i < N; i++){
      par[i] = i;
      nodes[i] = 1;
    }
  }

  int root(int x) {//find the root and path compression
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    nodes[ry] += nodes[rx];
    par[rx] = ry;
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n, m; cin >> n >> m;
  UnionFind U(n);
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    U.unite(a, b);
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    ans = max(ans, U.nodes[i]);
  }
  cout << ans << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 4816
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    return arr

N=int(input())

ls=factorization(N)

cnt=0

for l in ls:
    cc=0
    for i in range(1,l[1]+1):
        cc+=i
        if cc<=l[1]:
            cnt+=1
        else:
            break

print(cnt)

Measured memory_bytes: 63176
#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 n, a, t;
 
int main(){
    cin >> n;
 
    vector<long long> v;
 
    for(int i = 0; i < 3*n; i++){
        cin >> a;
        v.push_back(a);
    }
 
    sort(v.begin(), v.end());
 
    for(int i = n; i < 3*n; i = i + 2){
        t = t + v[i];
    }
 
    cout << t;
 
 
 
 
 
}

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

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

int main() {
	
	string s;
	cin >> s;
	int a = INT_MAX, z = INT_MIN;
	for (int i=0; i<s.size(); i++) {
		if (s[i] == 'A') a = min(a, i);
		if (s[i] == 'Z') z = max(z, i);
	}
	cout << z - a + 1 << endl;
	
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> a;
  std::vector<std::pair<int, int>> bc;
  for (int i = 0; i < n; i++) {
  	int temp;
    std::cin >> temp;
    a.push_back(temp);
  }
  for (int i = 0; i < m; i++) {
  	int b, c;
    std::cin >> b >> c;
    bc.emplace_back(std::make_pair(b, c));
  }
  std::sort(a.begin(), a.end());
  std::sort(bc.begin(), bc.end(), [](
    const std::pair<int, int>& a, const std::pair<int, int>& b){
    	return (a.second < b.second);
  });
  long long ans = 0;
  for (int i = n - 1, j = m - 1, sum = 0; sum < n; sum++) {
  	if (j >= 0 && a[i] < bc[j].second) {
      ans += bc[j].second;
      bc[j].first--;
      if (bc[j].first == 0) {
      	j--;
      }
    } else {
      ans += a[i--];
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 1784
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

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

const int N = 404;

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

int n,m;
string s[N];

pii dfs(int x, int y) {
  char ch = s[x][y];
  s[x][y] = '$';
  pii res = mp(0,0);
  if(ch == '#') res.FF++;
  else res.SS++;
  rep(i,0,4) {
    int a = x + dx[i];
    int b = y + dy[i];
    if(a < 0 || a >= n) continue;
    if(b < 0 || b >= m) continue;
    if(s[a][b] == '$' || s[a][b] == ch) continue;
    pii tmp = dfs(a, b);
    res.FF += tmp.FF;
    res.SS += tmp.SS;
  }
  return res;
}

int main() {
  S2(n,m);
  rep(i,0,n) {
    cin >> s[i];
  }
  LL ans = 0;
  rep(i,0,n) rep(j,0,m) if(s[i][j] != '$') {
    pii p = dfs(i, j);
    ans += p.FF * 1LL * p.SS;
  }
  cout << ans << "\n";
  return 0;
}


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

using namespace std;

const int N = 1005;
const int MOD = 1e9 + 7;

char g[N][N];
int n, m, f[N][N];

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", g[i] + 1);
  }
  f[n][m] = 1;
  for (int i = n; i > 0; --i) {
    for (int j = m; j > 0; --j) {
      if (i == n and j == m) continue;
      if (g[i][j] == '#') continue;
      f[i][j] = f[i + 1][j] + f[i][j + 1];
      if (f[i][j] >= MOD) f[i][j] -= MOD;
    }
  }
  cout << f[1][1] << endl;
  return 0;
}



Measured memory_bytes: 5120
#include <iostream>
#include <cstdlib>

using namespace std;

typedef long long ll;

int N;
ll A, B, h[101000];

int main(){
  cin >> N >> A >> B;

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

  ll l = 0, r = 1e9;
  while(r - l > 1){
    ll m = (r + l) / 2;
    ll x = 0;
    for(int i = 0; i < N; i++){
      ll z = max(0LL, h[i]-B*m);
      x += (z + A-B-1) / (A-B);
    }
    x = max(x, m);
    if(x <= m){
      r = m;
    }
    else{
      l = m;
    }
  }
  cout << l+1 << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
int euclid(int x,int y){
    if(x < y){
        const int a = x;
        x = y;
        y = a;
    }
    int b = 100000;
        while(b){
            b = x % y;
            x = y;
            y = b;
            if(b == 0) break;
        }
        return x;
}

signed main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    //ここからa以上b以下でのcの倍数を求める
    int e = (a - 1) / c;
    int f = b / c;
    int sumc = f - e;
    //ここからa以上b以下のdの倍数を求める
    int g = (a - 1) / d;
    int h = b / d;
    int sumd = 0;
        sumd = h - g;
    //ここからa以上b以下のc,dのgclの倍数を求める
    int ceu = c,deu = d;
    int gcdcd = euclid(ceu,deu);
    c /= gcdcd;
    d /= gcdcd;
    int gclcd = c * d * gcdcd;
    int i = (a - 1) / gclcd;
    int j = b / gclcd;
    int sumcd = 0;
    sumcd = j - i;
    int revsum = b - a + 1;
    int alt = sumc + sumd - sumcd;
    revsum -= alt;
    cout << revsum << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  DPpractice
//
//  Created by abhishek kumar on 20/04/20.
//  Copyright © 2020 abhishek kumar. All rights reserved.
//

#include <iostream>
#include<vector>
using namespace std;
typedef long long int ll;
const long long int N=1000;
const int INF=1e9 + 5;
ll n,k,m,temp,arr[N+1][N+1],dp[N+1][N+1],visited[N+1][N+1];


int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c;
    cin>>n;
    vector<vector<ll>> vacation(n,vector<ll>(3,0));
    vector<vector<ll>> dp(n,vector<ll>(3,0));
    for(auto i=0;i<n;i++)
    {
            cin>>a>>b>>c;
            vacation[i][0]=a; vacation[i][1]=b; vacation[i][2]=c;
        if(i==0)
        {
             dp[i][0]=a; dp[i][1]=b; dp[i][2]=c;
        }
    }
    
    
    
    
    for(auto i=1;i<n;i++)
    {
        for(auto j=0;j<=2;j++)
        {
            if(j==0)
                dp[i][j]=vacation[i][j] + max(dp[i-1][1],dp[i-1][2]);
            else if(j==1)
                dp[i][j]=vacation[i][j]+max(dp[i-1][0],dp[i-1][2]);
            else
                dp[i][j]=vacation[i][j]+max(dp[i-1][0],dp[i-1][1]);
        }
    }
    
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    
  
    return 0;
        
}

Measured memory_bytes: 11264
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    const n = chunk.toString()
        .split("\n")
        .filter(x => x !== "0 0" && x !== "")
        .map(x => x.split(" ")); // [[3, 4], [5, 6], [3, 3] ...]

    const ans = n.map(x => makeOneAns(Number(x[0]), Number(x[1])));
    ans.forEach(x => {
        x.forEach((y, i) => {
            console.log(y)

        });
    });
});


function makeOneAns(height, width) {
    let ans = []
    for (let i = 0; i < height; i++) {
        if (i % 2 === 0) {
            ans.push(makeEvenLine(width));
        } else {
            ans.push(makeOddLine(width));
        }
    }
    ans.push("")
    return ans
}

function makeOddLine(num) {
    let ans = "";
    for (let i = 0; i < num; i++) {
        if (i % 2 === 0) {
            ans = ans + "."
        } else {
            ans = ans + "#"
        }
    }
    return ans;
}

function makeEvenLine(num) {
    let ans = "";
    for (let i = 0; i < num; i++) {
        if (i % 2 !== 0) {
            ans = ans + "."
        } else {
            ans = ans + "#"
        }
    }
    return ans;
}


Measured memory_bytes: 21060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int ans=0;
    for(int i=1; i<=n; i+=2){
        int count=0;
        for(int j=1; j<=n; j+=2){
            if(i%j==0) count++;
        }
        if(count==8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
int main(){
  int a,b;
  int result = 0;
  cin>>a>>b;
  result = a+b;
  result = max(result, a-b);
  result = max(result, a*b);
  log(result);

}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[]){
    
    int debt=100000;
    int n, m=0;
    
    scanf("%d", &n);
    
    for(int i=0; i<n; i++){
        debt += debt*0.05;
        m = debt % 1000;
        if(m != 0){
            debt -= m;
            debt += 1000;
        }
    }
    
    printf("%d\n", debt);
    
    return 0;
}

Measured memory_bytes: 1016
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
using namespace std;
typedef long long int ll;
const int MOD = 1000000007;
 
int main(){
int ans;
int n, k, x, y;
cin >> n;
cin >> k;
cin >> x;
cin >> y;
if(n <= k){
    ans = x * n;
}
else{
    ans = x * k + y *(n - k);
}

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

Measured memory_bytes: 764
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
suf = 0
for i in range (n):
  suf += b[i]
  if i >= 1 and a[i - 1]  + 1 == a[i]:
    suf += c[a[i - 1] - 1]
print(suf)


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

int main(void){
  int N;
  cin >> N;
  double ans = 0;
  const double bi = 380000.0;
  for(int i=0; i<N; i++){
    double tmp;
    string tmpS;
    cin >> tmp >> tmpS;
    if(tmpS == "JPY") ans += tmp;
    else ans += tmp*bi;
  }
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2000000000;

int n, k;
vector<int> w;

bool isOK(int P) {
  int cnt = 1, space = P;
  for (int i = 0; i < n; i++) {
    if (space - w[i] < 0) {
      space = P;
      cnt ++;
      if (cnt > k) {
        return false;
      }
      i--;
    }
    else {
      space -= w[i];
    }
  }
  return true;
}

int binarySearch() {
  int left = 0, right = MAX;
  while (right - left >1) {
    int mid = (left + right) / 2;
    if (isOK(mid)) {
      right = mid;
    }
    else {
      left = mid;
    }
  }
  return right;
}

int main() {
  cin >> n >> k;
  w.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  cout << binarySearch() << endl;
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;

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

int main() {
  
  ll n;
  cin >> n;
  vl p(n);
  unordered_map<ll, ll> mp;
  set<ll> s;
  rep(i, n) {
    cin >> p[i];
    mp[p[i]] = i; //値 => INDEX
    s.insert(p[i]);
  }
  
  //memo: setで降順で取得したい => rbegin()を使う
  set<ll> idx;
  ll ans = 0;
  while(!s.empty()) {
    ll now = *s.rbegin(); //最大から取得
    s.erase(now);
    
    ll i = mp[now];
    vl l(2, -1), r(2, n);
    {
      auto itr = idx.lower_bound(i);
      rep(j, 2) { //r
        if(itr == idx.end()) break;
        r[j] = *itr;
        itr++;  //インクリメントすることで，「その次に右にある，より値が大きい要素のインデックス」を取得できる
      }
    }
    {
      auto itr = idx.lower_bound(i);
      rep(j, 2) { //l
        if(itr == idx.begin()) break;
        itr--;  //左の場合は，最初にデクリメント．これができるのは，idxには検索地より大きい値しか無いという仮定のため
        l[j] = *itr;
      }
    }
    
    ll l1 = i - l[0], l2 = l[0] - l[1];
    ll r1 = r[0] - i, r2 = r[1] - r[0];
    ans += (l1 * r2 + l2 * r1) * now;
    
    idx.insert(i);
  }
  cout << ans << '\n';
  
  return 0;
}

Measured memory_bytes: 11812
import math
import sys
import itertools
# import numpy as np

def main():
  n,q = map(int, input().split())
  process = [input().split() for _ in range(n)]
  

  total_time = 0

  while len(process) > 0:
    time = int(process[0][1])

    if time <= q:
      total_time += time
      print(process[0][0], total_time)
    else:
      total_time += q
      process.append([process[0][0], str(time - q)])

    process.pop(0)

if __name__ == '__main__':
  main()


Measured memory_bytes: 17184
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        	String input = br.readLine();
        	int[][] sum = new int[4][13];
        	for (int i = 0; i < Integer.parseInt(input); i++)
        	{
            	String[] card = br.readLine().split(" ");
            		int k = Integer.parseInt(card[1]) - 1;
            		if (card[0].equals("S"))
            			sum[0][k] = 1;
            		if (card[0].equals("H"))
            			sum[1][k] = 1;
            		if (card[0].equals("C"))
            			sum[2][k] = 1;
            		if (card[0].equals("D"))
            			sum[3][k] = 1;
        	}
        	for (int i = 0; i < 4; i++)
        	{
        		for (int j = 0; j < 13; j++)
        		{
        			if (sum[i][j] != 1)
        			{
        				if (i == 0)
        					System.out.println("S " + (j + 1));
        				if (i == 1)
        					System.out.println("H " + (j + 1));
        				if (i == 2)
        					System.out.println("C " + (j + 1));
        				if (i == 3)
        					System.out.println("D " + (j + 1));
        			}
        		}
        	}
        	
        	
	}

}

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

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

  for(int j = 0; j < n; j++){
    for(int i = b.size() - 1; i >= 0; i--){
      if(b[i] == i + 1){
        ans.push_back(b[i]);
        b.erase(b.begin() + i);

        break;
      }
    }
  }
  reverse(ans.begin(), ans.end());
  if(ans.size() != n) cout << -1 << endl;
  else rep(i, n) cout << ans[i] << endl;

  return 0;
}


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

int getcnt(vector<int>& a, vector<int>& b, int pos) {
    int left = lower_bound(a.begin(), a.end(), pos) - a.begin();
    int right = lower_bound(b.begin(), b.end(), pos) - b.begin();
    int right2 = b.size() - right;
    int left2 = a.size() - left;
    return left*right2 + right*left2;
}

int main() {
    int n;
    string in;
    cin >> n >> in;
    vector<int> red, green, blue;
    for(int i=0;i<n;i++) {
        if(in[i] == 'R') red.push_back(i);
        else if(in[i] == 'G') green.push_back(i);
        else blue.push_back(i);
    }
    long long res = 0;
    for(int i=0;i<n;i++) {
        if(in[i] == 'R') {
            res += getcnt(green, blue,i);
        }
        else if(in[i] == 'G') {
            res += getcnt(red, blue,i);
        }
        else {
            res += getcnt(red, green,i);
        }
        for(int j=1;;j++) {
            int left = i-j;
            int right = i+j;
            if(left<0 || right>= n) break;
            if(in[i] != in[left] && in[i] != in[right] && in[left] != in[right]) res--;
        }
    }
    printf("%lld\n",res);
}


Measured memory_bytes: 3732
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;
int cnt = 0;
ll n;
vector<string> p;

void dfs(ll a) {
    if(a <= n) {
        cnt++;
        p.pb(to_string(a));


    if(a * 10 + 3 <= n) dfs(a * 10 + 3);
    if(a * 10 + 5 <= n) dfs(a * 10 + 5);
    if(a * 10 + 7 <= n) dfs(a * 10 + 7);
    }   
}


int main(){
    cin >> n;
    int ans = 0;
    dfs(0);
    for(int i = 0;i < cnt;i++){
        int si = p[i].size();
        string s = p[i];
        bool ok3 = false, ok5 = false, ok7 = false;
        for(int j = 0;j < si;j++){
            if(s[j] == '3') ok3 = true;
            if(s[j] == '5') ok5 = true;
            if(s[j] == '7') ok7 = true;
        }
        if(ok3 && ok5 && ok7) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1916