akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

#define K_MAX = 2500;

int main() {
    int X, Y, Z, K, S;
    int sum = 0;
    cin >> K >> S;
    int min = S / 3;
    int count = 0;
    
    for (X=0; X<=K; X++) {
        for (Y=0; Y<=K; Y++) {
            if (S - Y - X > K || Y + X > S) {
                continue;
            }
            count++;
        }
    }

    cout << count;

    return 0; 
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;

int main()
{	
	char s[5];
	scanf("%s",s);
	int len = strlen(s);
	if(len == 2) printf("%s",s);
	else {
		swap(s[0],s[2]);
		printf("%s",s);}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
	int a, b;
	cin >> a >> b;
	rep(i,10000){
		if(floor(i*0.08)==a && floor(i*0.1)==b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb insert
#define mod 998244353
set<ll> pos[30] ;

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s ,t ;
    ll  n , m , i , j ;
    cin >> s >> t ;
    n = s.size() ;
    for (i = 0 ; i< n ; i ++) {
        pos[ s[i]-'a' ] .pb(i) ;
    }
    n = t.size() , m = s.size() ;
    ll ans = 0 , last = 0 ;
    for (i = 0 ; i< n ; i++) {
        ll x = t[i]-'a' ;
        auto y = pos[x].upper_bound(last-1) ;
        if (y==pos[x].end()) {
            ans+= (m-(last)) ;
           // cout << last << ' ' ;
            last = 0;
            y = pos[x].upper_bound(last-1) ; ;
            if (y == pos[x].end()) {
                cout << -1 << endl ;
                return 0 ;
            }
            ans+=(*y-(last)+1) ;
            last = *y +1;
        }
        else {
            ans+= (*y-(last)+1) ;
            last = *y+1 ;
        }
      //  cout<<ans << ' ' << last <<  endl ;

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


Measured memory_bytes: 5200
#include<bits/stdc++.h>
#define   ll          long long int
#define   sz          200010
#define   sc(a)       scanf("%lld",&a)
#define   sc2(a,b)    scanf("%lld %lld",&a,&b)
#define   py          printf("Yes\n")
#define   pn          printf("No\n")
using namespace std;


ll num[sz];



int main()
{

    ll a,b;
    ll x,y;

    cin>>a;

    if(a==2)x=3;
    else if(a==4 || a==6 || a==9 || a==11)x=2;
    else
        x=1;

    cin>>a;

    if(a==2)y=3;
    else if(a==4 || a==6 || a==9 || a==11)y=2;
    else
        y=1;

    if(x==y)py;
    else
        pn;


    return 0;
}



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

int main()
{
  int n;
  bool flag = false;
  cin >> n;
  for(int i = 1; i <=9; ++i)
  {
    if(n % i == 0)
    {
      if(n/i >= 1 && n/i <= 9)
      {
        flag = true;
      }
    }
  }
  if(flag)cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
list_A = list(map(int,input().split()))

from operator import itemgetter
list_b = [list(map(int,input().split(" "))) for m in range(M)]
list_b.sort(key=itemgetter(1),reverse=True)


for b,c in list_b:
  list_A.extend([c]*b)
  if len(list_A) >= 2*N:
    break

list_A.sort(reverse=True)
print(sum(list_A[:N]))

Measured memory_bytes: 34768
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{ 
  int A,B,C;
  cin>>A>>B>>C;
  if(A+B>=C) 
  cout<<"Yes";
  else
  cout<<"No";
  system("pause");
  return 0;
}


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

long long int max_(long long int p[8]) {
	long long int ret = LLONG_MIN;
	for (int i = 0; i < 8; i++) {
		if (ret < p[i]) ret = p[i];
	}
	return ret;
}

int main() {
	int n = 0, m = 0;
	long long int x[1000] = { 0 },
		y[1000] = { 0 },
		z[1000] = { 0 },
		sum[8000] = { 0 };
	long long int ans[8] = {0};
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> z[i];
		sum[i] =          x[i] + y[i] + z[i];
		sum[i + n * 1] =   x[i] + y[i] - z[i];
		sum[i + n * 2] =   x[i] - y[i] + z[i];
		sum[i + n * 3] = - x[i] + y[i] + z[i];
		sum[i + n * 4] =   x[i] - y[i] - z[i];
		sum[i + n * 5] = - x[i] - y[i] + z[i];
		sum[i + n * 6] = - x[i] + y[i] - z[i];
		sum[i + n * 7] = - x[i] - y[i] - z[i];
	}
	sort(sum, sum + n * 1, std::greater<long long int>());
	sort(sum + n * 1, sum + n * 2, std::greater<long long int>());
	sort(sum + n * 2, sum + n * 3, std::greater<long long int>());
	sort(sum + n * 3, sum + n * 4, std::greater<long long int>());
	sort(sum + n * 4, sum + n * 5, std::greater<long long int>());
	sort(sum + n * 5, sum + n * 6, std::greater<long long int>());
	sort(sum + n * 6, sum + n * 7, std::greater<long long int>());
	sort(sum + n * 7, sum + n * 8, std::greater<long long int>());

	for (int i = 0; i < m; i++) {
		ans[0] += sum[i];
		ans[1] += sum[i + n * 1];
		ans[2] += sum[i + n * 2];
		ans[3] += sum[i + n * 3];
		ans[4] += sum[i + n * 4];
		ans[5] += sum[i + n * 5];
		ans[6] += sum[i + n * 6];
		ans[7] += sum[i + n * 7];
	}
	printf("%lld\n", max_(ans));
	
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
using Graph = vector<vector<int>>;
#define rep(i,N) for(int i=0;i<(N);++(i))
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr ll mod = 1000000007;

int main() {
	int N; cin >> N;
	vector<pair<int, int>>vec(N);
	rep(i, N) {
		int a, b; cin >> a >> b;
		vec[i] = make_pair(a, b);
	}
	int ans = 0;
	rep(i, N) {
		ans += vec[i].second - vec[i].first + 1;
	}
	cout << ans << "\n";

	return 0;
}

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

int main(){
	int n;
	string str;
	cin >> n;
	while(n--){
		int ans = 0, out = 0, per = 0;
		while(1){
			cin >> str;
			if(str[1] == 'I'){
				per++;
				if(per > 3){per--;ans++;}
			}
			if(str[1] == 'O'){
				ans += per + 1;
				per = 0;
			}
			if(str[1] == 'U' && ++out == 3)break;
			//cout << per << ans << endl;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N;
vector<int> g[200020];

int dist[200020];
int cost[200020];

void df(int now,int par,int co){
  cost[now]=co;
  for(int i=0;i<g[now].size();i++){
    int nx=g[now][i];
    if(nx==par) continue;
    df(nx,now,co+1);
  }
  return;
}

int dfs(int now,int par){
  int ma=0;
  for(int i=0;i<g[now].size();i++){
    int nx=g[now][i];
    if(nx==par) continue;
    ma=max(ma,dfs(nx,now));
  }
  
  return dist[now]=ma+1;
}

int main(){
  cin>>N;
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  df(0,-1,0);
  int ma=0,mat=0;
  for(int i=0;i<N;i++){
    if(cost[i]>ma){
      ma=cost[i];
      mat=i;
    }
  }

  int z=dfs(mat,-1);

  if(z%3==2) cout<<"Second"<<endl;
  else cout<<"First"<<endl;

  return 0;
}


Measured memory_bytes: 28416
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let n=t.n()
  let a=t.s()
  let ans='Yes'
  if(n%2==0){
    for(let i=0;i<n/2;i++){
      if(a[i] != a[n/2+i]){ans='No';break;}
    }
  }else{
    ans='No'
  }
  t.o(ans)
}
main()

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const vector<int> dy = {-1,0,1,0};
const vector<int> dx = {0,1,0,-1};

int main() {
    int h,w; cin >> h >> w;
    vector<string> grid(h);
    rep(i,h) cin >> grid[i];

    queue<P> q;
    vector<vector<int>> dist(h,vector<int>(w,-1));
    rep(i,h)rep(j,w) {
        if (grid[i][j] == '#') {
            q.push(P(i,j));
            dist[i][j] = 0;
        }
    }
    
    int ans = 0;
    while (!q.empty()) {
        P p = q.front(); q.pop();
        int i = p.first,j = p.second;
        rep(k,4) {
            int y = i + dy[k];
            int x = j + dx[k];
            if (y < 0 || y >= h) continue;
            if (x < 0 || x >= w) continue;
            if (dist[y][x] == -1) {
                dist[y][x] = dist[i][j] + 1;
                ans = max(ans,dist[y][x]);
                q.push(P(y,x));
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 13456
n,m=gets.split.map(&:to_i)
l=gets.split.map(&:to_i)
l.sort!

v=l[0]
count=0
until l[0].nil?
    if l.length>m-1 && l.length!=m
    l.shift(m)
    l.unshift(v)
    
    count+=1
    elsif l.length==m
    l.shift(l.length)
    count+=1

    else
    l.shift(l.length)

    count+=1
    end
end
    
p count

Measured memory_bytes: 31460
import sys
# sys.stdin  = open("input.txt")
s=input()
t=input()
lol=float('inf')
for i in range(len(s)-len(t)+1):
    ch=0
    # print(i)
    for j in range(len(t)):
        # if i+j==(len(s)-1):
        #     print("yey")
        if s[i+j]!=t[j]:
            ch+=1
    lol=min(lol,ch)
print(lol)
        

Measured memory_bytes: 67604
import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)

N, M = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(M)]

indeg = [0 for _ in range(N)]
outdeg = [[] for _ in range(N)]

for x, y in xy:
    x,y = x-1, y-1
    indeg[y] += 1
    outdeg[x].append(y)

heads = []
for i in range(N):
    if not indeg[i]:
        heads.append(i)

dp = [0 for _ in range(N)]
while heads:
    h = heads.pop()
    for c in outdeg[h]:
        dp[c] = max(dp[c], dp[h]+1)
        indeg[c] -= 1
        if indeg[c] == 0:
            heads.append(c)
#        print(h,c,dp)

ans = max(dp)
print(ans)

Measured memory_bytes: 51664
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n, k;
  while(cin >> n >> k, n||k) {
    string a[n];
    REP(i,n) {
      cin >> a[i];
    }
    set<string> se;
    long long comb = (1<<k) - 1;
    while( comb < 1 << n ) {
      vector<int> hoge;
      REP(i,n)
        if (comb >> i & 1)
          hoge.push_back(i);
      sort(ALL(hoge));
      do {
        string s;
        REP(i,k)
          s += a[hoge[i]];
        //    cout << s << endl;
        se.insert(s);
      } while(next_permutation(ALL(hoge)));
      int x = comb&-comb, y = comb+x;
      comb = ((comb & ~y) / x >> 1) | y;
    }
    cout << se.size() << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n,a,b,c;
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        if(c>=a&&c<=b)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(), r = scan.nextInt();
        if (n < 10){
            System.out.println(r + 100*(10-n));
        }else
            System.out.println(r);
    }
}


Measured memory_bytes: 21588
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

r = i()
print(3 * r ** 2)

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


int main()
{
    int N, C;
    int D[31][31] = {};
    int c[1001][1001] = {};
    cin >> N >> C;
    for( int i = 1; i <= C; ++i )
        for( int j = 1; j <= C; ++j ) cin >> D[i][j];
    for( int i = 1; i <= N; ++i )
        for( int j = 1; j <= N; ++j ) cin >> c[i][j];
    

    int num_color[3][31] = {};
    for( int i = 1; i <= N; ++i ){
        for( int j = 1; j <= N; ++j ){
            ++num_color[(i+j)%3][c[i][j]]; 
        }
    }

    int wrongness = 1e+9;
    for( int i = 1; i <= C; ++i ){
        for( int j = 1; j <= C; ++j ){
            for( int k = 1; k <= C; ++k ){
                if( i == j or j == k or k == i ) continue;
                int tmp = 0;
                for( int color = 1; color <= C; ++color ) tmp += D[color][i]*num_color[0][color];
                for( int color = 1; color <= C; ++color ) tmp += D[color][j]*num_color[1][color];
                for( int color = 1; color <= C; ++color ) tmp += D[color][k]*num_color[2][color];
                wrongness = min(wrongness, tmp);
            }
        }
    }
    cout << wrongness << endl;

    return 0;
}

Measured memory_bytes: 4224
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto n = readLong();
    auto a = readLongs();
    long ans = long.max;
    foreach(i; iota(-100, 101)) {
        ans = min(ans, a.map!(x => (x-i)*(x-i)).sum(0L));
    }
    writeln(ans);
}



Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
integer :: n,k,check

read(*,*) n,k

check = n/2
if (mod(n,2) /= 0) then
	check = check +1
end if

if (check >= k) then
	write(*,'(a)') 'YES'
else
	write(*,'(a)') 'NO'
end if

END PROGRAM ATCODER


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  int n = 0;
  cin >> n;
  int num[n];
  for(int i = 0;i <= n - 1;i++)cin >> num[i];
  ll ans = 0;
  ans = 10000000000;
  for(int i = 0;i <= 200;i++){
    ll count = 0;
    for(int j = 0;j <= n - 1;j++)count += pow(max(i - 100,num[j]) - min(i - 100,num[j]),2);
    ans = min(count,ans);
  }
  cout << ans << endl;
  return 0;
}

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

vector<ll> bit2;

void add2(ll i,ll val)
{
  i++;

  for(i;i<=n;i+=i&(-i) )
    bit2[i]+=val;
}

void range_update2(ll l,ll r,ll val)
{
  add2(l,val);
  add2(r+1,-val);
}

ll query2(ll i)
{
  ll ans=0;
  i++;

  for(i;i>0;i-=(i&(-i)))
    ans+=bit2[i];

  return ans;
}

int main()
{ 

fast;

ll k;
cin>>n>>k;

ll a[n];
for(ll i=0;i<n;i++)
cin>>a[i];


for(ll tes=1;tes<=k;tes++)
{
bit2.assign(n+10,0);

for(ll j=0;j<n;j++)
        range_update2(max((ll)0,j-a[j]),min(n-1,a[j]+j),1);

bool f=1;

for(ll j=0;j<n;j++)
    if(a[j]!=query2(j))
    {
        f=0;
        break;
    }

    if(f)
        break;
    else
    {
        for(ll j=0;j<n;j++)
        a[j]=query2(j);
    }
}

for(ll i=0;i<n;i++)
cout<<a[i]<<" ";
}


Measured memory_bytes: 6340
// Template
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<char>> S(n, vector<char>(m));
    rep(i, n) rep(j, m) cin >> S[i][j];
    
    mcf_graph<int, ll> g(2 * n * m + 2);
    int s = 2 * n * m, t = 2 * n * m + 1;
    ll cnt = 0;
    rep(i, n) rep(j, m) {
        g.add_edge(i * m + j + n * m, t, 1, 0);
        if (S[i][j] != 'o') continue;
        ++cnt;
        g.add_edge(s, i * m + j, 1, 0);
        vector<vector<bool>> grid(n, vector<bool>(m, false));
        grid[i][j] = true;
        queue<pair<int, int>> q;
        q.push({i, j});
        while (!q.empty()) {
            auto [x, y] = q.front();
            q.pop();
            g.add_edge(i * m + j, x * m + y + n * m, 1, inf - (x - i) - (y - j));
            if (x + 1 < n && S[x + 1][y] != '#' && !grid[x + 1][y]) {
                q.push({x + 1, y});
                grid[x + 1][y] = true;
            }
            if (y + 1 < m && S[x][y + 1] != '#' && !grid[x][y + 1]) {
                q.push({x, y + 1});
                grid[x][y + 1] = true;
            }
        }
    }
    
    ll x = g.flow(s, t, cnt).second;
    cout << cnt * inf - x << "\n";
}


Measured memory_bytes: 8752
#include <iostream>
#include <vector>

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

using namespace std;

vector<vector <char>> a,b;
int n,m;

bool search(int y,int x){
	for(int i=0;i<m;++i){
		for(int j=0;j<m;++j){
 			if(a[y+i][x+j] != b[i][j])return false;
		}
	}
	return true;
}

int main(){
	bool flag = false;
	cin >> n >> m;
	a.resize(n);
	rep(i,0,n){
		a[i].resize(n);
		rep(j,0,n)cin >> a[i][j];
	}
	b.resize(m);
	rep(i,0,m){
		b[i].resize(m);
		rep(j,0,m)cin >> b[i][j];
	}
	for(int i=0;i<=n-m;++i){
		for(int j=0;j<=n-m;++j){
			flag = search(i,j);
			if(flag)break;
		}
		if(flag)break;
	}
	if(flag)cout << "Yes" << endl;
	else cout << "No" << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    int idx = 0;
    rep(i,N){
        if(A[i]==1){
            idx = i;
            break;
        }
    }

    int l=0;
    ll ans = 0;
    while(1){
        int nxt = l + K - 1;
        ans++;

        cerr << nxt << endl;
        if(nxt>=N-1) break;
        l = nxt;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;

int N,M,Q;
vector<int> a, b, c, d;
ll ans = 0;

void dfs(vector<int> A){
    if (A.size() == N){
             
        ll tmp = 0;
        rep(i,Q){
            if (A[b[i]] - A[a[i]] == c[i]){
                tmp += d[i];
            }
        }
        ans = max(ans, tmp);
        return;
    }

    A.push_back(A.back());
    while (A.back() <= M){
        dfs(A);
        A.back()++;
    }    
}

int main(){
    cin >> N >> M >> Q;
    a= b = c = d = vector<int>(Q);
    rep(i,Q){
       cin >> a[i] >> b[i] >> c[i] >> d[i];
       a[i]--;
       b[i]--;
    }

    for (int i = 1; i <= M; i++){
        dfs(vector<int>(1, i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
int main(){ //AGC023-A
     ll N,result,count;
     vector<ll> A;
     vector<ll> sum;
     cin >> N;
     A.resize(N);
     sum.resize(N + 1);
     sum[0] = 0;
     for(int i = 0; i < N; i++){
          cin >> A[i];
          sum[i+1] = sum[i] + A[i];
     }
     sort(sum.begin(),sum.end());
     result = 0;
     count = 1;
     for(int i = 0; i < N; i++){
          if(sum[i] != sum[i+1]){
               result += count * (count - 1) / 2;
               count = 1;
          }else{
               count++;
          }
     }
     result += count * (count - 1) / 2;
     cout << result << endl;
     return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
 
int main(){
  int i,j,n,u,k,v;
  int data[101][101];
  scanf("%d",&n);
  for( i = 1; i <= n; i++){
    for( j = 1; j <= n; j++){
      data[i][j]=0;
      }
  }
  for(i = 0; i < n; i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      data[u][v]=1;
    }
  }
 
  for(i = 1;i <=n;i++ ){
    for(j = 1; j <=n;j++){
      if(j==n){
    printf("%d",data[i][j]);
      }else{
    printf("%d ",data[i][j]);
      }
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2072
#include <iostream> 
#include<bits/stdc++.h>
using namespace std; 
int main(){
   int n,d,x;
   cin>>n>>d;
   d=(2*d+1);
   if(n%d==0)
        x= n/(d);
    else if(n>d)
        x=(int)(n/d)+1;
    else if((n<=d))
        x=1;
    cout<<x;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define modulo 998244353
#define endl '\n'
using namespace std;
ll fxp(ll a, ll b)
{
    if(b == 0)return 1;
	if(b%2 == 0){
		ll c = fxp(a,b/2);
		return (c*c)%1000000007;
	}
	return (a*fxp(a,b-1))%1000000007;
}
int lcm(int c,int d)
{
    int a=c;
    int b=d;
    int ans;
    if(a>=b)
    {
        while(b!=0)
        { 
            int x=b;
            b=a%b;
            a=x;
        }
        ans = ( c*d)/a;
    }
    else
    {
        while(a!=0)
        {
            int x=a;
            a=b%a;
            b=x;
        }
        ans = ( c*d)/b;  
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int happ[n][3];
    for(int i=0;i<n;i++)
        cin>>happ[i][0]>>happ[i][1]>>happ[i][2];
    ll dp[n][3];
    for(int i=0;i<3;i++)
     dp[n-1][i]=happ[n-1][i];
    for(int i=n-2;i>=0;i--)
    {
        dp[i][0]= happ[i][0]+ max(dp[i+1][1],dp[i+1][2]);
        dp[i][1]= happ[i][1]+ max(dp[i+1][0],dp[i+1][2]);
        dp[i][2]= happ[i][2]+ max(dp[i+1][1],dp[i+1][0]);
    }
    ll t = max(dp[0][1],dp[0][2]);
    ll ans = max(t,dp[0][0]);
    cout<<ans<<endl;
    
    return 0;
}

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

namespace atCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            int dup = 0;
            List<char> chars = new List<char>();

            foreach(char c in input)
            {
                if (chars.Contains(c) == false)
                    chars.Add(c);
                else
                    dup++;

            }

            if (dup == 2 && chars.Count == 2)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

        }

    }
}

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

#define INF 1000000001

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int cnt=0;

int main(){

  int i,n,s[500000];
  
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&s[i]);

  mergeSort(s, 0, n);
  
  for(i=0;i<n;i++){
    if(i)printf(" ");
    printf("%d",s[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}


void mergeSort(int *A, int left, int right){

  int mid;
  
  if(left+1 < right){
    mid = (left+right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);


  }


}

void merge(int *A, int left, int mid, int right){

  int i,j,k,n1,n2,l[500000],r[500000];
  n1 = mid - left;
  n2 = right - mid;
  
  // l = malloc(sizeof(int)*n1);
  // r = malloc(sizeof(int)*n2);

  for(i=0;i<n1;i++)l[i]=A[left+i];
  for(i=0;i<n2;i++)r[i]=A[mid+i];
  l[n1]=INF;r[n2]=INF;
  i=0;j=0;

  for(k=left;k<right;k++){
    cnt++;
    if(l[i]<=r[j]){
      A[k]=l[i];
      i++;
    }
    else{
      A[k]=r[j];
      j++;
    }

  }
  
}



Measured memory_bytes: 5632
#include <iostream>
using namespace std;
   
int F[102][102];
int xg,yg,w,h;
   
   
void DFS(int Y,int X,int c){
  //if(Y < 1 || X < 1)
    //return;
  if(F[Y][X] != c){
    return;
  }
   
  F[Y][X] = -1;
  DFS(Y+1,X  ,c);
  DFS(Y-1  ,X,c);
  DFS(Y,X+1  ,c);
  DFS(Y  ,X-1,c);
}
   
   
int main(){
  int xs,ys,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;
for(int i=0; i<102; i++){
      for(int j=0; j<102; j++){
        F[i][j] = 10;
      }
    }
       F[0][-1] = 0;
    cin >> xs >> ys >> xg >> yg >> n;
   
   
    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;
      if(c == 0)
         c = 1919810;
      if(d == 0){
        for(int j=0;j<4;j++){
          F[x+j][y] = c;
          F[x+j][y+1] = c;
        }
      } else {
        for(int j=0;j<4;j++){
          F[x][y+j] = c;
          F[x+1][y+j] = c;
        }
      }
    }
  DFS(xs,ys,F[xs][ys]);
   
  if(F[xg][yg] == -1){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

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

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	string S;
	cin >> S;
	cout << (S=="ABC"?"ARC":"ABC") << endl;

	return 0;
}


Measured memory_bytes: 3496
#include <iostream>
#include <fstream>
 
#include <vector>
 
using namespace std;
 
int main(){
 
    int X;
 
    string res = "NO";
 
    cin >> X;
 
    //X * t = T
    //t = T/X
 
    if(X == 3 || X == 5 || X == 7)res = "YES";
 
    cout << res << endl;
 
}
 

Measured memory_bytes: 256
var paper = [Int : Int]()
for _ in 0..<Int(readLine()!)! {
    let A = Int(readLine()!)!
    if paper[A] == nil {
        paper[A] = 1
    } else {
        paper[A] = nil
    }
}
print(paper.values.reduce(0){$0+$1})

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

int main() {
  int n; cin >>n;
  int buf=2, max=1;
  int bufsq;
  
  for (int i=1; i<=n; i++){
    if (i*i <= n){
      max = i*i;
    }else{
      break;
    }
  }
  
  cout <<max <<endl;
  
  //cout <<ans <<endl;
  
  //if (ans) cout <<"YES" <<endl;
  //else cout <<"NO" <<endl;
  
}


Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())
    top = list(map(int, input().rstrip().split(' ')))
    bottom = list(map(int, input().rstrip().split(' ')))

    candy=[]
    for i in range(1,N+1):
        candy.append(sum(top[:i]) + sum(bottom[i-1:]))

    print(max(candy))

Measured memory_bytes: 3060
//https://cs.stackexchange.com/questions/84426/find-a-node-with-maximum-distance-from-given-node-in-a-tree
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//#include <ext/rope> //header with rope
//using namespace __gnu_cxx;
//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order tells index pr kon hai..
// order_by_key  tells ki us element se kitne strictly smaller element hai...
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll fact[1000007];
ll mdpower(ll a,ll b)
{
    ll res =1;
    while(b)
    {
        if(b&1) res = (res%mod*a%mod)%mod;
        b/=2;
        a = (a%mod*a%mod)%mod;
    }
    return res;
}
void factorial()
{
    fact[0]=1;
    for(int i=1;i<1000007;i++)
        fact[i] = (fact[i-1]%mod*i%mod)%mod;
}
ll inverse(ll a,ll b)
{
    return mdpower(a,b-2);
}
ll power(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)
            res=(res*a);
        a=(a*a);
        b/=2;
    }
    return res;
}
int main()
{   
    Senky_Bansal
    IIIT_ALLAHABAD


      ll ans=0;
      string s;
      cin>>s;
      stack<char>st;
      st.push(s[0]);
      for(int i=1;i<s.size();i++)
      {
          ll f=0;
          if(st.size()>0){
          if(st.top()=='0' && s[i]=='1')
          {
            ans++;
            f=1;
            st.pop();
          }
          else if(st.top()=='1' && s[i]=='0')
          {
            ans++;
            f=1;
            st.pop();
          }}
          if(f==0)
          st.push(s[i]);
      }
      cout<<ans*2<<endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        long ans = 0;
        for(int i=1;i<=K;i++){
            for(int j=1;j<=K;j++){
                for(int k=1;k<=K;k++){
                    ans += gcd(gcd(i,j),k);
                }
            }
        }
        System.out.println(ans);

    }

}









Measured memory_bytes: 35760
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
using namespace std;
int main(){
	int n,b;
	cin>>n>>b;
	int a[b]={};
	for(int i=0;i<b;i++){
		cin>>a[i];
	}
	int zuida=0;
	for(int i=0;i<b;i++){
		if(a[i]>zuida)zuida=a[i];
	}
	int qita=0;
	bool flag=true;
	for(int i=0;i<b;i++){
		if(zuida==a[i]&&flag==true){
			a[i]=0;
			flag=false;
		}
		qita+=a[i];
	}
	if(qita>=zuida){
		cout<<"0";
	}else cout<<zuida-qita-1;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b && a!=c)|| (a==c && a!=b)|| (b==c && a!=c))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
n,k=map(int,input().split())
li=[]
for i in range (0,n):
  li.append(list(map(int,input().split())))
li.sort()
bought=0
pay=0
t=0
while bought<k:
  pay=pay+(li[t][0])*(li[t][1])
  bought=bought+li[t][1]
  t=t+1
pay=pay-li[t-1][0]*li[t-1][1]
bought=bought-li[t-1][1]
bought_2=k-bought
pay_2=li[t-1][0]*bought_2
pay=pay+pay_2
print(pay)

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

typedef pair<long long, long long> pll;
const long long INF = 1LL<<60;

void chmax(pll &a, pll b) {
  if (a.first < b.first) a.second = max(a.first, b.second), a.first = b.first;
  else a.second = max(a.second, b.first);
}

int main() {
  int N; cin >> N;
  vector<long long> A(1<<N); vector<pll> dp(1<<N);
  for (int bit = 0; bit < (1<<N); ++bit) {
	cin >> A[bit];
	dp[bit] = {A[bit], -INF};
  }
  for (int i = 0; i < N; ++i) 
	for (int bit = 0; bit < (1<<N); ++bit) 
	  if (bit & (1<<i)) 
		chmax(dp[bit], dp[bit^(1<<i)]);
  long long res = -INF;
  for (int bit = 0; bit < (1<<N); ++bit) {
	long long tmp = dp[bit].first + dp[bit].second;
	res = max(res, tmp);
	if (bit) cout << res << endl;
  }
}	

Measured memory_bytes: 9216
/*
     “You just can’t beat the person who won’t give up.”
                                                            */
#include <bits/stdc++.h>
#define ll long long
#define oo 0x3f3f3f3f3f3f3f3fLL
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
const int maxn=2e5+5;
const  double EPS = 1e-9;
const int mod = 1e9+7;

inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}

int main()
{
    ios_base::sync_with_stdio(0);
    File();
    int n;
	cin >> n;
	map<int, int> mp;
	for (int i = 2; i <= n; i++) {
		int x = i;
		for (int d = 2; d * d <= x; d++) {
			while (x % d == 0) {
				mp[d]++;
				x /= d;
			}
		}
		if (x > 1) mp[x]++;
	}

	ll ans = 1;
	for (auto it : mp) {
		ans *= (it.second + 1);
		if (ans > mod) ans %= mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3652
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
	sys.stdin = open(name)

l = list(map(str,input().split()))
a,b = map(int,input().split())
check = input()

if check == l[0]:
    a -= 1
else:
    b -= 1

print(a,b)




Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  int s = 1;
  for(int i = 0; i < 8; i++) {
    if(N == 0 || N == 1) {
      cout << s << endl;
      return 0;
    }
    N /= 2;
    s *= 2;
  }
}


Measured memory_bytes: 384
nn = gets.chomp.to_i

count = Array.new(nn + 1, 0)

(1..100).each do |x|
  (1..100).each do |y|
    (1..100).each do |z|
      m = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
      count[m] ||= 0
      count[m] += 1
    end
  end
end

(1..nn).each do |n|
  puts count[n]
end

Measured memory_bytes: 14852
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

                    int taro =0;
                    int hana =0;
                    String[] temp = new String[2];

                    while((str = br.readLine()) != null){
                        int n = Integer.parseInt(str);
                        for(int i=0;i<n;i++){
                            str = br.readLine();
                            temp = str.split("\\s");
                            
                            if(temp[0].compareTo(temp[1]) == 0){
                                taro++;
                                hana++;
                            }else if(temp[0].compareTo(temp[1]) > 0){
                                taro +=3;
                            }else{
                                hana +=3;
                            }
                        }
                    }

                    System.out.println(taro + " " + hana);

    }
}

Measured memory_bytes: 26860
from collections import Counter

s = input()
a = Counter(s[0:0+3]).values()

for i in range(len(s) - 1):
    for j in (2, 3):
        for v in Counter(s[i:i+j]).values():
            if v >= 2:
                print(i+1, i+j)
                exit()

print(-1, -1)

Measured memory_bytes: 3564
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

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

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000//10^12
#define INFINT 2000000001//2*10^9+1
#define ALL(a) (a).begin(),(a).end()

using namespace std;




int main(void)
{
	//変数の宣言
	int n;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;



	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);


/*	for(i=0;i<n;i++){
//		scanf("%lld",&t[i]);
		scanf_s("%lld",&t[i]);
	}*/
	
	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	ans=100010;
	for(i=0;i<=n;i++){
		temp=0;
		temp1=i;
		temp2=n-i;
		while(temp1!=0){
			temp=temp+temp1%6;
			temp1=temp1/6;
		}
		while(temp2!=0){
			temp=temp+temp2%9;
			temp2=temp2/9;
		}
		ans=min(ans,temp);
	}



	//	printf("計算部分終了\n");

	//出力

	printf("%d",ans);

	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 256
N = str(input())
K = int(input())

dp = [ [ [ 0, 0 ]  for i in range(4) ] for j in range(len(N)+1) ]
dp[0][0][1] = 1

for i in range(1,len(N)+1):
    for j in range(4):
        for k in range(2):
            if k == 0 and j != 0:
                if N[i-1] == "0":
                    dp[i][j][k] = dp[i-1][j-1][0] * 9 + dp[i-1][j][0]
                else:
                    dp[i][j][k] = dp[i-1][j-1][0] * 9 + dp[i-1][j][0] + dp[i-1][j][1] + dp[i-1][j-1][1]*(int(N[i-1])-1)
            if k == 0 and j == 0:
                dp[i][j][k] = dp[i-1][j][0] + dp[i-1][j][1]

            if k == 1 and j != 0:
                if N[i-1] == "0":
                    dp[i][j][k] = dp[i-1][j][1]
                else:
                    dp[i][j][k] = dp[i-1][j-1][1]

print(dp[len(N)][K][0] + dp[len(N)][K][1])

Measured memory_bytes: 38384
n,m=gets.chomp.split.map(&:to_i)
x=gets.chomp.split.map(&:to_i).sort
now=Array.new(n,0)
if n>=m;puts "0";exit;end
if n==1;puts (x.max-x.min).abs;exit;end
dt = []
(x.size-1).times{|ii|dt<< x[ii+1]-x[ii]}
dt.sort!
(n-1).times{dt.pop}
p dt.inject(:+)

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

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

    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for (int i=0; i<n; ++i) {
      cin >> a[i] >> b[i] >> c[i];
    }
    int dpa=0, dpb=0, dpc=0;
    for (int i=0; i<n; ++i) {
      int nxa=a[i]+max(dpb, dpc);
      int nxb=b[i]+max(dpa, dpc);
      int nxc=c[i]+max(dpa, dpb);
      dpa=nxa;
      dpb=nxb;
      dpc=nxc;
    }
    cout << max(dpc, max(dpa, dpb)) << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    lint a, b, X;
    cin >> a >> b >> X;
    lint ret = b / X - (a == 0 ? -1 : (a - 1) / X);
    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    int H,W,A,B;cin>>H>>W>>A>>B;
    for(int i=0;i<B;i++){
        for(int j=0;j<A;j++){
            cout<<1;
        }
        for(int j=A;j<W;j++){
            cout<<0;
        }
        cout<<endl;
    }
    for(int i=B;i<H;i++){
        for(int j=0;j<A;j++){
            cout<<0;
        }
        for(int j=A;j<W;j++){
            cout<<1;
        }
        cout<<endl;
    }
}


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


void RL(int r,int l){
    rep(i,r-1) cout << 0 << " ";
    cout << r/2+r%2 + l/2<< " " << r/2 + l/2 + l%2 << " ";
    rep(i,l-1) cout << 0 << " ";
    
}

int main(){
    
    string s;
    cin >> s;
    int n = s.size();

    vector<int> v;
    v.assign(n,0);

    int cntr = 1;
    int cntl = 0;
    char temp = 'R';
    for(int i = 1;i < n-1;i++){
        if(temp == s[i]){
            if(temp == 'R') {
                cntr++;
            }
            else {
                cntl++;
            }
        }else{
            if(temp == 'L'){
                // cout << cntr << " " << cntl<< endl;
                RL(cntr,cntl);
                cntl = 0;
                cntr = 1;
                temp = 'R';
            }else{
                cntl++;
                temp = 'L';
            }
        }
    }

    if(temp == 'R') RL(cntr,1);
    else RL(cntr,cntl+1);
    cout << endl;
}

Measured memory_bytes: 3792
N, K, Q = map(int, input().split())

P = [K for _ in range(N)]
D = []
for _ in range(Q):
    A = int(input()) - 1
    P[A] += 1

for x in P:
    if Q + 1 <= x:
        print('Yes')
    else:
        print('No')


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

int main() {
  string s;
  cin >> s;
  string ret = "No";
  if (s[2] == s[3] and s[4] == s[5]) ret = "Yes";
  cout << ret << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		sc.close();
		prtln(a + (a * a) + (a * a * a));
	}

	public static <T> void prtln(T t) { System.out.println(t); }
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return true; } return false;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 h,w,m;
  cin >> h >> w >> m;
  vector<int32> hcnt(h), wcnt(w);
  set<pii> obj;
  REP(i,m){
    int32 hi,wi;
    cin >> hi >> wi;
    hi--;wi--;
    hcnt[hi]++;
    wcnt[wi]++;
    obj.insert(pii(hi,wi));
  }
  int32 hmx=0,wmx=0;
  REP(i,h){
    chmax(hmx,hcnt[i]);
  }
  REP(i,w){
    chmax(wmx,wcnt[i]);
  }
  vector<int32> hmxi,wmxj;
  REP(i,h){
    if(hcnt[i] == hmx)hmxi.pb(i);
  }
  REP(j,w){
    if(wcnt[j] == wmx)wmxj.pb(j);
  }
  bool allobj = true;
  if((int64)hmxi.size() * (int64)wmxj.size() <= m){
    for(auto i : hmxi)for(auto j : wmxj){
      if(obj.count(pii(i,j)) == 0)allobj = false;
    }
  }else{
    allobj = false;
  }
  if(allobj){
    ANS(hmx + wmx - 1);
  }else{
    ANS(hmx + wmx);
  }
  return 0;
}

Measured memory_bytes: 35024