akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int Mod = 1e9+7;

const int Nmax = 4004;
int ans=0, n, m, k, i, j, d[Nmax][Nmax], sum[Nmax][Nmax];

int main()
{
   // freopen("input", "r", stdin);
   // freopen("output", "w", stdout);

    scanf("%d%d%d", &n, &m, &k);

    d[0][0] = 1;
    for(i=0; i<=n; ++i) sum[0][i] = 1;

    for(i=1; i<=n+m; ++i) /// lungimea secventei
        for(j=0; j<=n; ++j) /// suma secventei
        {
            d[i][j] = sum[i-1][j] - (j>=k ? sum[i-1][j-k] : 0);
            if(d[i][j]<0) d[i][j] += Mod;

            sum[i][j] = (j ? sum[i][j-1] : 0) + d[i][j];
            if(sum[i][j]>=Mod) sum[i][j] -= Mod;
        }


    for(i=n%(k-1); i<=n; i+=k-1) /// suma secventei
        for(j=1; j<=n+m; ++j) /// lungimea secventei
            if( (m-j*(k-1)+i-1) >= 0 && (m-j*(k-1)+i-1) % (k-1) == 0 )
            {
                ans += d[j][i] - d[j-1][i]; /// nu pot avea 0 pe ultima pozitie
                if(ans>=Mod) ans -= Mod;
                else if(ans<0) ans += Mod;
            }


    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 94720
from collections import defaultdict
H,W,N=map(int,input().split())

allcase=(H-2)*(W-2)

abset=set()
for _ in range(N):
  a,b=map(int,input().split())
  abset.add((a-1,b-1))
#print(abset)

memo=defaultdict(int)
for a,b in abset:
  for j in range(-2,1):
    if a+j<0 or H-2<=a+j:
      continue    
    for k in range(-2,1):
      if b+k<0 or W-2<=b+k:
        continue
      memo[(a+j,b+k)]+=1
#print(memo)  

case_list=[0]*10
for v in memo.values():
  case_list[v]+=1
case_list[0]=allcase-sum(case_list[1:])
#print(case_list)

for i in range(10):
  print(case_list[i])

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

int main(int argc, char const *argv[]) {
    int n, k;
    cin >> n >> k;
    vector<int> sunuke(n);

    for (size_t i = 0; i < k; i++) {
        int d;
        cin >> d;
        for (size_t j = 0; j < d; j++) {
            int a;
            cin >> a;
            if (sunuke[a-1] == 0) {
                sunuke[a-1] = 1;
            }
        }
    }

    int sum = 0;
    for (size_t i = 0; i < n; i++) {
        sum += sunuke[i];
    }

    cout << n - sum << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <stack> 
#include <map>
#include <queue>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
#define pb 					push_back
#define FAST_IO          ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
template<typename T,typename S>
ostream& operator <<(ostream& os, pair<T, S> input) {
	os<<"("<<input.first<<", "<<input.second<<")";
	return os;
}
template<typename T>
ostream& operator <<(ostream& os, vector<T> input) {
	for(auto t: input)
		os << t <<" ";
	return os;
}
template<typename T>
ostream& operator <<(ostream& os, set<T> input) {
	for(auto t: input)
		os << t <<" ";
	return os;
}





void solve(int x, int d) {
	for(int i=1; i<=7e3; i++) {
		long long a = i;
		long long b = a - d;
		long long A = a*a*a*a*a;
		long long B = b*b*b*b*b;
		// cout <<A << "\n";
		if(A-B==x) {
			cout << a << " " << b << "\n";
			exit(0);
		}
	}
}

int main() {	
	int x;
	cin >> x;
	for(int i=1; i*i<=x; i++) {
		if(x%i!=0)
			continue;
		int a = i;
		int b = x/i;
		solve(x, a);
		solve(x, b);

	}
	return 0;
}














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

using namespace std;

int main(){
    string s;
    cin>>s;
    int i;
    for(i=0;i<8;i++){
         s.pop_back();
    }
    
    cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
record = [1] * N
for i in range(M):
    a, b = map(int, input().split())
    if H[a - 1] <= H[b - 1]:
        record[a - 1] = 0
    if H[a - 1] >= H[b - 1]:
        record[b - 1] = 0

print(sum(record))

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

int f(int _i)
{
	return _i*_i;
}

int main()
{
	int d;
	while(cin >> d){
		int S = 0;

		for(int i=1;i<600/d;++i){
			S += f(d*i)*d;
		}

		cout << S << endl;

	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
 
bool IsCoffeeLike( const std::string & str )
{
  if ( str.size() != 6 )
  {
    return false;
  }
  
  return ( str[2] == str[3] && str[4] == str[5] );
}
 
int main( void )
{
  std::string str;
  std::cin >> str;
  
  std::cout << ( IsCoffeeLike(str) ? "Yes" : "No" ) << std::endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    if(T.startsWith(S)) {
    	String is_one = T.substring(S.length());
    	if(is_one.length() == 1) {
    		System.out.println("Yes");
    	}else {
    		System.out.println("No");
    	}
    }else {
    	System.out.println("No");
    }
    
  }
}

Measured memory_bytes: 35620
#include<iostream>
#include<string>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
    string str;
    cin>>str;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string d,h;
        int a,b;
        cin>>d>>a>>b;
        if(d=="print"){
            cout<<str.substr(a,b-a+1)<<endl;
        }else if(d=="reverse"){
            string temp= str.substr(a,b-a+1);
            reverse(temp.begin(),temp.end());
            str = str.replace(a,b-a+1,temp);
        }else if(d=="replace"){
            cin>>h;
            str = str.replace(a,b-a+1,h);
        }
    }
    return 0;
    
}


Measured memory_bytes: 3200
import java.util.*;
 
class Main {
    public static void main(String[] args) {
 		Scanner sc = new Scanner(System.in);
		int intKazu = sc.nextInt();
     	int intAshi = sc.nextInt();

// intKazu 3
// intAshi 6,8,10,12
// intKazu 5
// intAshi 10,12,14,16,18,20
	
		int OKflag = 0;
        for(int i=0;i<(intKazu+1);i++){
			if ( ((intKazu * 2) + (i *2)) == intAshi ) {
			OKflag = 1;
			}
        }
    
  
		if ( OKflag == 1 ) {
	        System.out.println("Yes"); 
		} else {
	        System.out.println("No");
		}
	}
}

Measured memory_bytes: 35812
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const ll maxn=1e9+7;
bool vis[8];
int main(){
    int n,x;
    cin>>n;
    for(int i=0;i<8;i++) vis[i]=0;
    int cnt=0;
    for(int i=0;i<n;i++){
        cin>>x;
        if(x>=3200) cnt++;
        else vis[x/400]=1;
    }
    int ans=0;
    for(int i=0;i<8;i++) ans+=vis[i];
    if(ans==0){
        ans=1;
        cnt--;
    }
    cout<<ans<<" "<<ans+cnt<<endl;
    return 0;
}


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

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<int,int> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

int dp[6000][11];
int T(int n, int x){
	int &m = dp[n][x];
	if(m != -1)
		return m;
	if(n == 1 && (x == 1 || x == 2 || x == 3 || x==7 || x== 8|| x ==9 || x ==0)){
		m = 2;
		return 2;
		}
	if(n == 1 && (x == 4|| x == 6)){
		m = 3;
		return 3;
	}
	if(x == 0){
		m = ((T(n-1,4))%mod + T(n-1,6)%mod)%mod;
		return m;
	}
	if(x == 1){
		m = (T(n-1,6)%mod + T(n-1,8)%mod)%mod;
		return m;
	}
	if(x == 2){
		m = (T(n-1,7)%mod + T(n-1,9)%mod)%mod;
		return m;
	}
	if(x == 3){
		m = (T(n-1,4)%mod + T(n-1,8)%mod)%mod;
		return m;
	}
	if(x == 4){
		m = ((T(n-1,0)%mod + T(n-1,9)%mod)%mod + T(n-1,3)%mod)%mod;
		return m;
	}
	//~ if(x == 5)
		//~ return T(n-1,4) + T(n-1,8);
	if(x == 6){
		m = ((T(n-1,1)%mod + T(n-1,7)%mod) %mod + T(n-1,0)%mod)%mod;
		return m;
	}
	if(x == 7){
		m = (T(n-1,2)%mod + T(n-1,6)%mod)%mod;
		return m;
	}
	if(x == 8){
		m = (T(n-1,1)%mod + T(n-1,3)%mod)%mod;
		return m;
	}
	
	m = (T(n-1,4)%mod + T(n-1,2)%mod)%mod;
	return m;
	
}

int main(){
	int x, y; cin>> x >> y;
	cout<< x + (y/2);
	return 0;
}


Measured memory_bytes: 256
n,k = gets.split.map(&:to_i)
R,S,P = gets.split.map(&:to_i)
t = gets.strip

win = {
  'r' => 'p',
  's' => 'r',
  'p' => 's',
}
points = {
  'r' => R,
  's' => S,
  'p' => P,
}

total = 0

pattern = t.chars
result = []

pattern.each.with_index do |rsp, i|
  if i+1 > k && pattern[i-k] == rsp && result[i-k]
    result[i] = false
    next
  end
  total += points[win[rsp]]
  result[i] = true
end

puts total


Measured memory_bytes: 9544
#include<stdio.h>
int main()
{
    int a,b,s;
    char c;

        scanf("%d %c %d",&a,&c,&b);
        if(c=='+'){
            s=a+b;
            printf("%d\n",s);
        }
        else if(c=='-'){
            s=a-b;
            printf("%d\n",s);
        }


    return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
//vvi(n, vector<int>(m, -1))
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a) (a).begin(), (a).end()
#define out(x) cout << (x) << endl;

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	int a, b, c;
  cin >> a >> b >> c >> x >> y;

  f = a*x + b*y;
  if(x >= y){
    f = min(f, c*y*2 + a*(x-y));
  }else{
    f = min(f, c*x*2 + b*(y-x));
  }
  f = min(f, 2*c*max(x, y));
  out(f);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T> void dbg(T x) { cout << x << "\n"; }
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }

static int cnt1[2018], cnt2[2018];

int main() {
    int n;
    while (cin >> n) {
        memset(cnt1, 0, sizeof(cnt1));
        memset(cnt2, 0, sizeof(cnt2));
        rep(c, 1001) rep(d, 1001) {
            int x = n - c - d;
            if (0 <= x&&x <= 2000) cnt1[x]++;
        }
        rep(a, 1001) rep(b, 1001) {
            cnt2[a + b]++;
        }

        ll ans = 0;
        rep(i, 2001) ans += cnt1[i] * cnt2[i];
        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int c[1000006];
vector<int> V;
set<int> S;
multiset<int> T;

int N, A[200005];

int dp[200005];

int num[1000006];

int main(void) {
	cin >> N;
	int Am = 0;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		V.push_back(A[i]);
		S.insert(A[i]);
		T.insert(A[i]);
		Am = max(Am, A[i]);
		num[A[i]]++;
	}

	//sort(V.begin(), V.end());

	

	for(auto y: V){
		if (c[y] >= 1) { c[y] = 2; }
		else if (c[y] >= 0) { c[y]++;
		for (long long int j = y*2; j <= Am; j+=y) {
			c[(int) j] = -1;
		}
		}
	}

	for (int i = 1; i <= N;i++) {
		if (T.count(A[i]) >= 2) { continue; }
		else { if (c[A[i]] == 1) { int x = 1; } }
	}

	int ans = 0;

	for (int i = 1; i <= N; i++) {
		//if (T.count(A[i]) >= 2) { continue; }
		if (c[A[i]] == 1) { ans++; }
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 30292
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
using namespace std;
 
 
 
/*void SieveOfEratosthenes(int n) 
{ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 

    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++) 
    if (prime[p]) 
        cout << p << " "; 
} */

int main() 
{ 
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust";
    else cout<<"win";
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int main () {
  int N, M;
  cin >> N >> M;

  int ans = 1900*M + 100*(N-M);
  rep(i,M) ans *= 2;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100000
int parent(int i){return i/2;
}
int left(int i){return 2*i;
}
int right(int i){return 2*i+1;
}
int main()
{
	int H,i,A[MAX+1];
	cin>>H;
	for(int i=1;i<=H;i++)
	cin>>A[i];
	for(int i=1;i<=H;i++)
	{
		cout<<"node "<<i<<": key = "<<A[i]<<", ";
	    if(parent(i)>=1)cout<<"parent key = "<<A[parent(i)]<<", ";
	    if(left(i)<=H)cout<<"left key = "<<A[left(i)]<<", ";
	    if(right(i)<=H)cout<<"right key = "<<A[right(i)]<<", ";
	    cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class CRally {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        vi X(n);
        in >> X;
        int sum = accumulate(all(X), 0), p = (int) round((double) sum / n), res = 0;
        trav(x, X) {
            int d = x - p;
            res += d * d;
        }
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    CRally solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(){
  
  int m,f,r;


  while(1){
    cin >> m >> f >> r;

    if(m==-1 && f==-1 && r==-1){
      break;
    }else{
      int mark=0;
      char grade=0;
      
      if(m==-1 || f==-1 ){
        grade = 'F';
      }

      if(m!=-1){
        mark += m;
      }
      if(f!=-1){
        mark += f;
      }

      if(grade == 0){
        if(mark >= 80){
          grade = 'A';
        }else if(mark >= 65){
          grade = 'B';
        }else if(mark >= 50){
          grade = 'C';
        }else if(mark >=30){
          if(r >= 50){
            grade = 'C';
          }else{
            grade = 'D';
          }
        }else{
          grade = 'F';
        }
      }
    
      cout << grade << endl;
    }
  }
}

Measured memory_bytes: 1156
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

const ll mod=1e9+7;

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int h,w;
    cin >> h >> w;
    vector<vector<char>> arr(h,vector<char>(w));
    vector<vector<ll>> dp(h,vector<ll>(w));
    F0R(i,h)
    {
        F0R(j,w)
            cin >> arr[i][j];
    }
    dp[0][0]=1;
    FOR(t,1,w+h-1)
    {
        F0R(i,t+1)
        {
            int j=t-i;
            // cout << i << ", " << j << endl;
            if(j<w && i<h && arr[i][j]!='#')
            {
                if(i-1>=0)
                    dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
                if(j-1>=0)
                    dp[i][j]=(dp[i][j-1]+dp[i][j])%mod;
            }
        }
    }
    cout << dp[h-1][w-1] << endl;

    return 0;
}


Measured memory_bytes: 9088
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int mod = 1e9+7;

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


Measured memory_bytes: 512
#include<stdio.h>

#define min(a,b) ((a)<(b)?(a):(b))

/*int solve(int kai,long now){
	if(kai>=ans)return 0;
	if(now>n)return 0;
	if(n-now>=0&&n-now<6){
		if(ans>kai+n-now)ans=kai+n-now;
		return 0;
	}else {
		if(n-now>=0&&ans>kai+n-now)ans=kai+n-now;
		printf("%ld\n",ans);
		if(n-now>=59049)solve(kai+1,now+59049);
		if(n-now>=46656)solve(kai+1,now+46656);
		if(n-now>=7776)solve(kai+1,now+7776);
		if(n-now>=6561)solve(kai+1,now+6561);
		if(n-now>=1296)solve(kai+1,now+1296);
		if(n-now>=729)solve(kai+1,now+729);
		if(n-now>=216)solve(kai+1,now+216);
		if(n-now>=81)solve(kai+1,now+81);
		if(n-now>=36)solve(kai+1,now+36);
		if(n-now>=9)solve(kai+1,now+9);
		if(n-now>=6)solve(kai+1,now+6);
		//solve(kai+1,now+2799366);
		//solve(kai+1,now+531441);
		return 0;
	}
}*/

int ru(int a,int b){
	int r=1,i;
	for(i=0;i<b;i++)r=r*a;
	return r;
}

int main(){
	int n;
	scanf("%d",&n);
	int dp[100001],i,j;
	for(i=0;i<6;i++)dp[i]=i;
	//solve(0,0);
	for(i=6;i<=n;i++){
		for(j=0;ru(6,j)<=i;j++)dp[i]=min(dp[i-1]+1,dp[i-ru(6,j)]+1);
		for(j=0;ru(9,j)<=i;j++)dp[i]=min(dp[i-1]+1,min(dp[i-ru(9,j)]+1,dp[i]));
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
typedef long long ll;

int main(){
    double a,b,c,x,ans;
    while(scanf("%lf%lf%lf",&a,&b,&x)==3){
        if(a*b/2.0<=x/a){
            c=2.0*x/(a*a)-b;
            ans=atan((b-c)/a);
            ans=ans/pi*180.0;
        }
        else{
            c=2.0*x/(a*b);
            ans=atan(b/c);
            ans=ans/pi*180.0;
        }
        printf("%.10lf\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d", $N, $M);
for($i = 1; $i <= $N; $i++){
    $c[$i] = 0;
}
for($i = 0; $i < $M; $i++){
    fscanf(STDIN, "%d%d", $a, $b);
    $c[$a]++;
    $c[$b]++;
}
for($i = 1; $i <= $N; $i++){
    echo $c[$i],"\n";
}


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

int main(){
   long long K, N;
   cin >> K >> N;
   vector<long long> A(N);
   for (int i=0; i<N; i++){
      cin >> A.at(i);
   }
   vector<long long> d(N-1);
   for (int i=1; i<N; i++){
      d.at(i-1) = A.at(i)-A.at(i-1);
   }
   sort(d.begin(), d.end());
   int L = K-A.at(N-1)+A.at(0);
   int max = d.at(N-2);
   if (L > max)
      cout << accumulate(d.begin(), d.end(), 0) << endl;
   else
      cout << accumulate(d.begin(), d.end(), 0)-max+L << endl;

}



Measured memory_bytes: 3328
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
a = 0
ans = 0

for x1 in range(0, N):
  for x2 in range(x1+1, N):
    for i in range(0, D):
      a += (X[x1][i]-X[x2][i])**2
    if math.sqrt(a).is_integer():
      ans += 1
    a = 0
print(ans)

Measured memory_bytes: 3064
var
  n:ansistring;
  i:longint;
begin
  readln(n);
  for i:=1 to length(n) do
    begin
      if n[i]=n[i+1] then
        begin
          writeln(i,' ',i+1);exit;
        end;
      if n[i]=n[i+2] then
        begin
          writeln(i,' ',i+2);exit;
        end;
    end;
  writeln('-1 -1');
end.

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

int n, m;
int maxx;
vector<vector<int>> in(100000);
//vector<vector<int>> out(100000);
int mem[233333];

int dfs(int k)
{
    if (mem[k] != -1)
        return mem[k];
    int ans = 0;
    if (in[k].begin() != in[k].end())
    {
        for (auto it = in [k].begin(); it != in[k].end(); ++it)
        {
            ans = max(ans, dfs(*it));
        }
        mem[k] = ans + 1;
    }
    return mem[k];
}

int main()
{
    fill(mem, mem + 233333, -1);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
    {
        int a, b;
        cin >> a >> b;
        in[b].push_back(a);
        //out[a].push_back(b);
    }
    for (int i = 1; i <= n; i++)
    {
        maxx = max(maxx, dfs(i));
    }
    cout << maxx;
    return 0;
}

Measured memory_bytes: 11136
import copy

h, w = map(int, input().split())
maze = []
for i in range(h):
    maze.append(list(input()))

max_steps = 0

for i in range(h):
    for j in range(w):
        maze_search = copy.deepcopy(maze)
        if maze_search[i][j] == "#":
            continue
        
        maze_search[i][j] = 0
        numbered_area = [[i, j]]
        step_num = 0
        
        while True:
            
            if not numbered_area:
                if step_num - 1 > max_steps:
                    max_steps = step_num - 1
                break

            step_num += 1
            
            numbered_area_new = []
            for point in numbered_area:
                if point[0] < h - 1 and maze_search[point[0] + 1][point[1]] == ".":
                    maze_search[point[0] + 1][point[1]] = step_num
                    numbered_area_new.append([point[0] + 1, point[1]])
                
                if point[0] > 0 and maze_search[point[0] - 1][point[1]] == ".":
                    maze_search[point[0] - 1][point[1]] = step_num
                    numbered_area_new.append([point[0] - 1, point[1]])
                
                if point[1] < w - 1 and maze_search[point[0]][point[1] + 1] == ".":
                    maze_search[point[0]][point[1] + 1] = step_num
                    numbered_area_new.append([point[0], point[1] + 1])
                
                if point[1] > 0 and maze_search[point[0]][point[1] - 1] == ".":
                    maze_search[point[0]][point[1] - 1] = step_num
                    numbered_area_new.append([point[0], point[1] - 1])
            
            numbered_area = copy.deepcopy(numbered_area_new)
                
print(max_steps)

Measured memory_bytes: 3444
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.UnsupportedEncodingException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc146_b solver = new abc146_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc146_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            String S = in.next();
            byte[] asciiCodes = new byte[S.length()];

            try {
                asciiCodes = S.getBytes("US-ASCII");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            for (int i = 0; i < asciiCodes.length; i++) {
                //System.out.println("asciiCodes[" + i + "]:" + asciiCodes[i]);
                asciiCodes[i] = (byte) (asciiCodes[i] + N <= 90 ? (asciiCodes[i] + N) : (65 + ((asciiCodes[i] + N) - 90) - 1));
                //System.out.println("asciiCodes[" + i + "]:" + asciiCodes[i]);
            }
            try {
                out.println(new String(asciiCodes, "US-ASCII"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }

    }
}



Measured memory_bytes: 24020
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
const int mo = 1e9 + 7;
using namespace std;
typedef long long ll;

const int MAXN = 2e5 + 10;
ll fact[MAXN], factinv[MAXN];
inline ll fpm(ll a, ll b = mo - 2)
{
	ll res = 1;
	while (b)
	{
		if (b & 1) res = res * a % mo;
		a = a * a % mo;
		b >>= 1;
	}
	return res;
}
inline void pre()
{
	fact[0] = factinv[0] = 1;
	for (register int i = 1; i < MAXN; ++i) 
	{
		fact[i] = fact[i - 1] * i % mo;
		factinv[i] = fpm(fact[i]);
	}
}
int h, w, a, b;
inline ll C(int a, int b)
{
	if (a - b < 0 || b < 0) return 0;
	return fact[a] * factinv[a - b] % mo * factinv[b] % mo;
}
template <class T>
inline void _read(T &x)
{
	x = 0;
	char t = getchar();
	while (!isdigit(t)) t = getchar();
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
int main()
{
	_read(h), _read(w), _read(a), _read(b);
	pre();
    ll ans = 0;
 
    for (register int i = b + 1; i <= w; ++i)
        ans = (ans + C(i - 1 + h - a - 1, h - a - 1) * C(w - i + a - 1, w - i) % mo) % mo;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3328
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int N;
	cin>>N;
	vector <int > a(N);
	int k;

	cin>>k;
	int b=k/2;
	for(int i=0;i<N;i++)
		cin>>a[i];
	sort(a.begin(),a.end());
	/*for(int i=0;i<N;i++)
		cout<<a[i]<<" ";*/
		int s=0;
	for(int i=0;i<N;i++)
	{
		if(a[i]>b)
			s+=2*(k-a[i]);
		else
			s+=2*a[i];
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 10000

int main(void){
  int i,num,j,k;
  int n,ice[N][10],icetype;

  for(i=0;;i++){
    scanf("%d",&n);
    if(n==0)
      break;
    for(j=0;j<10;j++)
      ice[i][j]=0;
    for(j=0;j<n;j++){
      scanf("%d",&icetype);
      ice[i][icetype]++;
    }
  }
  num=i;
  for(i=0;i<num;i++){
    for(j=0;j<10;j++){
      for(k=0;k<ice[i][j];k++){
        printf("*");
      }
      if(ice[i][j]==0)
        printf("-");
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

ll gcd(ll x, ll y) {
    if (x < y) swap(x, y);
    while(y > 0) {
        ll tmp = x % y;
        x = y;
        y = tmp;
    }
    return x;
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

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

    if (s[0] != t[0]) {
        cout << -1 << endl;
        return 0;
    }
    ll l = lcm(n, m);
    ll l2 = lcm(l / n, l / m);
    for (int i = 1; i < n; i++) {
        ll x = i * (l / n);
        if (x % l2 == 0) {
            if (x <= (m - 1) * (l / m)) {
                if (s[i] != t[x / (l / m)]) {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    for (int i = 1; i < m; i++) {
        ll x = i * (l / m);
        if (x % l2 == 0) {
            if (x <= (n - 1) * (l / n)) {
                if (t[i] != s[x / (l / n)]) {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    cout << l << endl;
    return 0;
}


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

#define ul unsigned long int
#define ull unsigned long long
#define li long long int


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

  if (a<b)
    cout << "a < b" << endl;
  else if (a>b)
    cout << "a > b" << endl;
  else
    cout << "a == b" << endl;

  return 0;
}



Measured memory_bytes: 3076
package main

import "fmt"

func main() {
	var s string
	fmt.Scanln(&s)
	ans := 7
	switch s {
	case "MON":
		ans = 6
	case "TUE":
		ans = 5
	case "WED":
		ans = 4
	case "THU":
		ans = 3
	case "FRI":
		ans = 2
	case "SAT":
		ans = 1
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
use std::io::{BufRead, Write};
use std::io;
use std::collections::HashSet;

// Each node is represented as an `usize`, for a shorter implementation.
#[derive(Copy, Clone, Debug)]
struct Edge {
    node: usize,
    cost: usize,
}

fn shortest_path(adjacency: &Vec<Vec<Edge>>, top: usize) -> Vec<usize> {
    let mut visited: HashSet<usize> = HashSet::new();
    let mut queue: Vec<usize> = vec![top];
    let mut result: Vec<usize> = vec![0; adjacency.len()];
    visited.insert(top);
    while let Some(x) = queue.pop() {
        for y in &adjacency[x] {
            if visited.insert(y.node) {
                result[y.node] = result[x] + y.cost;
                queue.push(y.node);
            }
        }
    }
    result
}

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().unwrap();
    let mut adjacency = vec![Vec::<Edge>::new(); n];
    for _ in 0..n - 1 {
        s.clear();
        input.read_line(&mut s).unwrap();
        let (a, b, c): (usize, usize, usize) = {
            let mut split = s.split_whitespace();
            let a = split.next().unwrap().parse().unwrap();
            let b = split.next().unwrap().parse().unwrap();
            let c = split.next().unwrap().parse().unwrap();
            (a, b, c)
        };
        adjacency[b - 1].push(Edge {
            node: a - 1,
            cost: c,
        });
        adjacency[a - 1].push(Edge {
            node: b - 1,
            cost: c,
        });
    }
    s.clear();
    input.read_line(&mut s).unwrap();
    let (q, k): (usize, usize) = {
        let mut split = s.split_whitespace();
        let a = split.next().unwrap().parse().unwrap();
        let b = split.next().unwrap().parse().unwrap();
        (a, b)
    };
    let cost = shortest_path(&adjacency, k - 1);
    for _ in 0..q {
        s.clear();
        input.read_line(&mut s).unwrap();
        let (x, y): (usize, usize) = {
            let mut split = s.split_whitespace();
            let a = split.next().unwrap().parse().unwrap();
            let b = split.next().unwrap().parse().unwrap();
            (a, b)
        };
        writeln!(output, "{}", cost[x - 1] + cost[y - 1]).unwrap();
    }
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5\n",
            "3
2
4\n",
        );
    }
    #[test]
    fn case2() {
        test(
            "7
1 2 1
1 3 3
1 4 5
1 5 7
1 6 9
1 7 11
3 2
1 3
4 5
6 7\n",
            "5
14
22\n",
        );
    }
    #[test]
    fn case3() {
        test(
            "10
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
6 7 1000000000
7 8 1000000000
8 9 1000000000
9 10 1000000000
1 1
9 10\n",
            "17000000000\n",
        );
    }
}


Measured memory_bytes: 22780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	int sl = s.size(), tl = t.size();
	if (sl == tl) {
		if (s == t) {
			cout << "EQUAL\n";
		}
		else if (s < t) {
			cout << "LESS\n";
		}
		else {
			cout << "GREATER\n";
		}
	}
	else {
		if (sl < tl) {
			cout << "LESS\n";
		}
		else {
			cout << "GREATER\n";
		}
	}

	return 0;
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
          int kingaku = int.Parse(Console.ReadLine());
          int gohyaku = kingaku / 500;
          int go = (kingaku % 500) / 5;
          	Console.WriteLine((gohyaku * 1000) + (go * 5));
          
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, ans=1e18;
ll vv[222222], ps[222222];

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; int i;
	for(i=1 ; i<=n ; i++) cin>>vv[i];
	for(i=1 ; i<=n ; i++) ps[i]=ps[i-1]+vv[i];
	for(i=1 ; i<=n-1 ; i++) ans=min(ans,abs(2*ps[i]-ps[n]));
	cout<<ans; return 0;
}

Measured memory_bytes: 3456
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
count=[[0]*26 for _ in range(n)]
ans=0
for i in range(n):
    for j in range(10):
        count[i][ord(s[i][j])-ord("a")]+=1
for i in range(n):
    count[i]=tuple(count[i])
for i in dict(Counter(count)).values():
    for j in range(i):
        ans+=j
print(ans)

Measured memory_bytes: 155652
N, C, K = map(int, input().split())
T = [0]*N
cnt = 1
bus = 1
for i in range(N):
    T[i] = int(input())
T.sort()
tmp = T[0]+K
for i in range(1, N):
    if(cnt == 0):
        bus += 1
        cnt = 1
        tmp = T[i]+K
        continue
        
    if(T[i] <= tmp and cnt < C):
        cnt += 1
        if(cnt == C):
            cnt = 0
    else:
        cnt = 1
        bus += 1
        tmp = T[i]+K
print(bus)

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

int main(){
    string S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;    
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
 int n;
 long ans;
 scanf("%d",&n);
 ans=0;
 for(int i=1;i<=n;i++){
     if( i%3!=0 && i%5!=0){
         ans+=i;
     }
 }
 printf("%ld",ans);
 return 0;
}

Measured memory_bytes: 1696
h,w=map(int,input().split())
a=[]
allwhite_row=[]
allwhite_column=list(set([i for i in range(w)]))
for i in range(h):
    row=input()

    whitecolumn_index=row.find('.',0)
    whitecolumn=[]
    while(whitecolumn_index != -1):
        whitecolumn.append(whitecolumn_index)
        whitecolumn_index = row.find('.',whitecolumn_index+1)

    allwhite_column = list(set(allwhite_column) & set(whitecolumn))

    if(list(row).count('.')==w):
        allwhite_row.append(i)

    a.append(row)

for i in range(h):
    if(i not in allwhite_row):
        ans_i=[]
        for j in range(w):
            if(j not in allwhite_column):
                ans_i.append(a[i][j])
        print(''.join(ans_i))


Measured memory_bytes: 3316
/*
    Author : Pranav_Raut.
*/

#include<bits/stdc++.h>
using namespace std;
#define input(arr,n) for(ll i=0;i<n;i++){cin>>arr[i];}
typedef long long int ll;
ll MOD = 1000000007;
ll MAXN = 100005;


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        /* JUST CODE TILL YOU CRACK IT !!! */
        ll n,w;
        cin>>n>>w;
        ll wi[n], vi[n];
        ll arr[n][w+1];
        for(ll i=0;i<n;i++)
        {
            cin>>wi[i]>>vi[i];
            arr[i][0] = 0;
        }
        for(ll i=0;i<n;i++)
        {
            for(ll j=1;j<=w;j++)
            {
                ll a = 0;
                ll b = 0;
                if(wi[i]<=j)
                {
                    a += vi[i];
                }
                if(i-1>=0)
                {
                    b = arr[i-1][j];
                }
                if(i-1>=0 && j-wi[i]>=0)
                {
                    a += arr[i-1][j-wi[i]];
                }
                arr[i][j] = max(a,b);
            }
        }
        cout<<arr[n-1][w]<<endl;
    }
    return 0;
}


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

typedef long long ll;
bool used[500][500];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<vector<ll>> a(n, vector<ll>(n));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            cin >> a[i][j];
        }
    }
    vector<vector<ll>> dist = a;
    for(int k = 0; k < n; ++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(a[i][j] != dist[i][j]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    
    ll res = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(i == j)          continue;
            if(used[i][j])      continue;
            
            bool flag = true;
            for(int k = 0; k < n; ++k){
                if(k == i || k == j)    continue;
                
                if(dist[i][j] == dist[i][k] + dist[k][j]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                res += dist[i][j];
            }
            used[i][j] = used[j][i] = true;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {
	int N;
	long[] A;
	long result = 0;

	Main() throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		N = Integer.parseInt(in.readLine());
		A = new long[N];
		String[] tokens = in.readLine().split(" ");
		for (int i = 0; i < N; ++i) {
			A[i] = Integer.parseInt(tokens[i]);
		}
		in.close();
		calc();
	}

	void calc() {
		int minusCount = 0;
		long minAbs = Long.MAX_VALUE;
		long absSum = 0;
		for (int i = 0; i < N; ++i) {
			if (A[i] < 0) {
				++minusCount;
			}
			long absVal = Math.abs(A[i]);
			if (minAbs > absVal) {
				minAbs = absVal;
			}
			absSum += absVal;
		}
		if (minusCount % 2 == 0) {
			this.result = absSum;
		} else {
			this.result = absSum - minAbs*2;
		}
	}

	public static void main(String[] args) throws IOException {
		Main ins = new Main();
		System.out.println(ins.result);
	}

}

Measured memory_bytes: 50552
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
   int a, b;
   cin >> a;
   cin >> b;

   int d = a / b;
   int r = a % b;
   double f = double(a) / double(b);
   
   cout << d;
   cout << " ";
   cout << r;
   cout << " ";
   std::cout << fixed << setprecision(5) << f;
   
   cout << endl;
}


Measured memory_bytes: 3268
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int N; 
string S;
vector<ll> d, m, dm;

ll solve(const int k) 
{
  ll ret = 0;
  for(int i = 1; i <= N; i++) {
    if(S[i-1] == 'C') {
      int pos = max(0, i-k);
      ll work = dm[i] - dm[pos];
      ll work2 =  ((m[i]-m[pos]) * d[pos]);
      ret += (work-work2);
      //      cout << i << " " << work << " " << work2 << " " << ret << endl;
    }
  }
  return ret;
}

int main() {
  cin>>N>>S;
  d = vector<ll>(N+1, 0);
  m = vector<ll>(N+1, 0);
  dm = vector<ll>(N+1, 0);
  for(int i = 0; i < N; i++) {
    m[i+1] = m[i];
    d[i+1] = d[i];
    dm[i+1] = dm[i];
    switch (S[i]) {
    case 'D': d[i+1] ++; break;
    case 'M': m[i+1] ++ ; dm[i+1] += d[i]; break;
    }
  }
  int Q; cin>>Q;
  while(--Q >= 0) {
    int k; cin>>k;
    ll ans = solve(k);
    //    cout << "Answer=";
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 24836
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    long long R, G, B, N;
    cin >> R >> G >> B >> N;
    long long ans = 0;
    for(int r=0; r<=N; r++){
        for(int g=0; g<=N; g++){
            int tmp = N-(r*R+g*G);
            if(tmp < 0) continue;
            if(tmp % B == 0) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int A,B;
int D[100001],E[100001];
int main() {
	cin>>A>>B;
	int R=0;
	for(int i = 0; i<A; i++)cin>>D[ i ];
	for(int j = 0; j<B; j++)cin>>E[ j ];

	int S = 0;
	int k;
	for(int i = 0; i<B; i++){
		S = 0;
		k = 0;
		for(int j = 0; j<A; j++){
			if(E[ i+k ]==D[ j ]){
				S += 1;
				k += 1;
			}
		}
		R = max(R, S);
	}
	cout<<R<<endl;
	return 0;
}



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

int main() {
  int N, i, j=1;
  int a[200000];
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (i = 0; i < N; i++) {
    if (a[i] == j)
      j++;
  }
  if (j != 1)
    cout << N - j + 1 << endl;
  else
    cout << "-1" << endl;
}

Measured memory_bytes: 1024
/*
    to amy
    https://atcoder.jp/contests/abc131/tasks/abc131_c
*/

#include <bits/stdc++.h>

using namespace std;

#define MAX 100010
#define pb push_back

typedef long long ll;
typedef vector<int> vi;

vi v;

ll gcd(ll a, ll b){ return b==0? a: gcd(b, a%b);}
ll lcm(ll a, ll b){ return a*(b/gcd(a,b));}

ll f(ll x,ll c,ll d){
    ll res = x;
    res -= x/c;
    res -= x/d;
    res += x/lcm(c,d);
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,d;
    while(cin>>a>>b>>c>>d){
        cout<<f(b,c,d) - f(a-1,c,d)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
	"strings"
)

const BufSize = 200100
var read = bufio.NewReaderSize(os.Stdin, BufSize)

func readLine() string {
	var buf []byte
	l,_,_ := read.ReadLine()
	buf = append(buf,l...)
	return string(buf)
}

func readInt(r ...*int64) {
	l := strings.Fields(readLine())
	for i,v := range l {
		*r[i],_ = strconv.ParseInt(v,10,64)
	}
	return
}
func readIntArray() []int64 {
	l := strings.Fields(readLine())
	ret := make([]int64,len(l))
	for i,v := range l {
		ret[i],_ = strconv.ParseInt(v,10,64)
	}
	return ret
}

func main() {
    var n int64
    readInt(&n)
    fmt.Println(n*n*n)
}

Measured memory_bytes: 640
package main

import (
  "fmt"
  "strings"
)

func main() {
  var input string
  var count int
  fmt.Scanf("%s", &input)

  inputArray := strings.Split(input, "")
  for i := 0; i < len(inputArray); i++ {
      if inputArray[i] == "o" {
        count += 1
      }
  }
  sum := 700 + 100 * count
  fmt.Println(sum)
}


Measured memory_bytes: 640