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

int main(int argc, char const *argv[]) {
  int turn, taro_point = 0, hanako_point = 0;
  string taro_card, hanako_card;

  cin >> turn;
  for (int i = 0; i < turn; i++) {
    cin >> taro_card >> hanako_card;

    if (taro_card > hanako_card) {
      taro_point += 3;
    } else if (taro_card < hanako_card) {
      hanako_point += 3;
    } else {
      taro_point++;
      hanako_point++;
    }
  }

  cout << taro_point  << " " << hanako_point<< endl;

  return 0;
}

Measured memory_bytes: 3216
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n;
    cin >> n;
    vs64 a(n), b(n);
    rep (i, n) cin >> a[i] >> b[i];

    s64 ans = 0;
    for (int i = n - 1; i >= 0; --i)
    {
        if ((ans + a[i]) % b[i])
        {
            ans += b[i] - (ans + a[i]) % b[i];
        }
    }

    cout << ans << "\n";
    return 0;
}



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

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    int ans = 1e9;
    rep(p, 101)
    {
        int sum = 0;
        rep(i, n)
        {
            int pp = x[i] - p;
            sum += pp * pp;
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

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

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

    int N;
    cin >> N;

    vector<long long> A(N);
    for (int i=0; i<N; ++i) cin >> A[i];

    vector<long long> acSum(N+1, 0), acXor(N+1, 0);
    for (int i=1; i<=N; ++i) {
        acSum[i] = acSum[i-1] + A[i-1];
        acXor[i] = acXor[i-1] ^ A[i-1];
    }

    long long ans = 1;
    int l=0, r=0;
    while (l < N-1) {
        while (r+1 < N && acSum[r+2] - acSum[l] == (acXor[r+2] ^ acXor[l])) { //ok
            r ++;
            ans ++;
        }
        if (l == r) {
            l ++;
            r ++;
            ans ++;
        } else {
            l ++;
            ans += r - l + 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
//unionfind
struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> p(n);
  rep(i,n){
    cin >> p.at(i);
    p.at(i)--;
  }
  UnionFind u(n);
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    u.unite(x,y);
  }
  vector<vector<int>> v(n);
  int ans=0;
  rep(i,n)
    v.at(u.find(i)).push_back(i);
  rep(i,n){
    set<int> s;
    rep(j,v.at(i).size()){
      s.insert(p.at(v.at(i).at(j)));
      s.insert(v.at(i).at(j));
    }
    ans+=2*v.at(i).size();
    ans-=s.size();
  }
  cout << ans << endl;
}

Measured memory_bytes: 11472
a,b = map(int,input().split(' '))
if a > 0:
    ans = 'Positive'
elif b >= 0:
    ans = 'Zero'
else:
    n = b-a+1
    if n%2 == 0:
        ans = 'Positive'
    else:
        ans = 'Negative'
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <cmath>
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef vector<P> Poly;
#define X real()
#define Y imag()

const double EPS = (1e-10), pi = acos(-1);
double dot(P a, P b){ return a.X*b.X - a.Y*b.Y;}
double cross(P a, P b){ return a.X*b.Y-a.Y*b.X;}

P intersection(L a, L b){
  return a.first + cross(b.second - b.first,a.first-b.first)/
    (-cross(b.second-b.first,a.second-b.first)+cross(b.second-b.first,a.first-b.first))*(a.second-a.first);
}

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return 2;
  if(norm(c) - norm(b) > EPS) return -2;
  return 0;
}

bool is_cross(L a, L b){
  return (ccw(a.first,a.second,b.first)*ccw(a.first,a.second,b.second) < 0 &&
          ccw(b.first,b.second,a.first)*ccw(b.first,b.second,a.second) < 0);
}

bool cmp_arg(P a, P b){ return arg(a) < arg(b);}

int main(){
  int n;
  cin >> n;
  vector<double> S(n);
  for(int i = 0; i < n; ++i) cin >> S[i], S[i] += 0.5;
  Poly x;
  for(int i = 0; i < 5; ++i){
    x.push_back(polar(1.0,4.0*pi*i/5.0));
  }
  Poly star;
  for(int i = 0; i < 5; ++i){
    star.push_back(x[i]);
    for(int j = 0; j < i; ++j){
      L l1 = L(x[i],x[(i+1)%5]), l2 = L(x[j],x[(j+1)%5]);
      if(is_cross(l1,l2)){
        star.push_back(intersection(l1,l2));
      }
    }
  }
  sort(star.begin(),star.end(), cmp_arg);
  double s = 0;
  for(int i = 0; i < 10; ++i){
    s += 0.5*cross(star[i],star[(i+1)%10]);
  }
  for(int i = 0; i < n; ++i){
    double r = sqrt(S[i]/s);
    Poly t = star;
    for(int j = 0; j < 10; ++j) t[j] *= r;
    double xx = -4500, yy = -4500;
    xx += i/10*1000;
    yy += i%10*1000;
    cout << i+1 << endl;
    for(int j = 0; j < 10; ++j) printf("%.9f %.9f\n", t[j].X+xx, t[j].Y+yy);
  }
  return 0;
}



Measured memory_bytes: 3656
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
	double a, b, c, d, e, f;
	double x, y, z;
	while (scanf("%lf", &a) != EOF && scanf("%lf", &b) != EOF && scanf("%lf", &c) != EOF && scanf("%lf", &d) != EOF && scanf("%lf", &e) != EOF && scanf("%lf", &f) != EOF) {
		x = d / a;
		y = b * x-e;
		z = c * x-f;
		z = z / y;
		y = (c - b*z) / a;
		printf("%.3f %.3f\n",y, z);
	}


}


Measured memory_bytes: 3172
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	int n, b, cnt = 1, ans = 0;
	vector<int> a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> b;
		a.push_back(b);
	}

	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		if (a[i] == a[i + 1]) {
			cnt++;
		}
		else {
			if (cnt % 2 != 0) {
				ans++;
			}
			cnt = 1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const ld PI = acos(-1.0);

int32_t main(){
	fast;
	string s;
	cin >> s;
	
	f(i,0,s.length())
		cout << 'x';
}



Measured memory_bytes: 256
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


def main():
    n = I()
    monster = LI()
    ret = 0
    ans = sum(monster)
    savor_lim = LI()
    for i in range(n - 1, -1, -1):
        k = min(savor_lim[i], monster[i + 1])
        monster[i + 1] -= k
        savor_lim[i] -= k
        monster[i] -= min(savor_lim[i], monster[i])
    return ans - sum(monster)



print(main())

Measured memory_bytes: 74980
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int ans;
    if(N>=195){
        ans = 5;
    }else if (N>=189){
        ans = 4;
    }else if (N>=165){
        ans = 3;
    }else if (N>=135){
        ans = 2;
    }else if (N>=105){
        ans = 1;
    }else {
        ans = 0;
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



i64 n, m, a[101010];
i64 lcm(i64 x, i64 y){
	return x / __gcd(x,y) * y;
}
void solve(){
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a,a+n);
	i64 c = a[0]/2;
	bool ok = 1;
	for(int i = 0; i < n; i++){
		i64 lc = lcm(c,a[i]/2);
		if((lc-c) % (c*2) != 0) ok = 0;
		c = lc;
		if(c > m){
			cout << 0 << endl;
			return;
		}
	}
	
	if(!ok){
		cout << 0 << endl;
		return;
	}
	
	cout << 1 + (m-c)/(c*2) << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

//#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
	int A, B, Q;
	cin >> A >> B >> Q;

	vector<ll> s(A), t(B);
	for (int i = 0; i < A; i++)
		cin >> s[i];
	for (int i = 0; i < B; i++)
		cin >> t[i];

	//vector<ll> x(Q);
	for (int i = 0; i < Q; i++) {
		ll x;
		cin >> x;
		int sr = lower_bound(s.begin(), s.end(), x) - s.begin() ;
		int sl = sr - 1;
		int tr = lower_bound(t.begin(), t.end(), x) - t.begin() ;
		int tl = tr - 1;
		/*
		cout << "sr=" << sr << " ";
		cout << "sl=" << sl << " ";
		cout << "tr=" << tr << " ";
		cout << "tl=" << tl << " ";
		cout << endl;
		*/
		ll ans = 1e15;
		if (sl >= 0) {
			if (tl >= 0)
				ans = min(ans, max(abs(x-s[sl]), abs(x-t[tl])));
			if (tr < B)
				ans = min(ans, 2 * min(abs(x - s[sl]), abs(x - t[tr])) + max(abs(x - s[sl]), abs(x - t[tr])));
		}
		if (sr < A) {
			if (tr < B)
				ans = min(ans, max(abs(x - s[sr]), abs(x - t[tr])));
			if (tl >= 0)
				ans = min(ans, 2 * min(abs(x - s[sr]), abs(x - t[tl])) + max(abs(x - s[sr]), abs(x - t[tl])));
		}
		cout << ans << endl;
	}
}


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

#define int long long

using namespace std;



int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;

    int res = 0;

    for(int i = 1 ; i <= N ; i++)
    {
 		int n;
 		cin >> n;
 		if((i&1) && (n&1))res++;   
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 3648
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		Map<Integer,Integer> students = new LinkedHashMap<>();
		for(int i = 0; i < n; i++) {
			students.put(sc.nextInt(),i);
		}
		for(int i = 1; i <= n; i++) {
			System.out.print(students.get(i)+1+ " ");
		}


	}

}

Measured memory_bytes: 73692
#include<stdio.h>

int sum(int *p,int i,int n){
  if(i==n){
    return 0;
  }
  else{
    return p[i]+sum(p,i+1,n);
  }
}

int max(int *p,int i,int n,int m){
  if(i==n){
    return m;
  }
  else{
    int tmp;
    if(p[i]>m){
      tmp=p[i];
    }
    else{
      tmp=m;
    }
    return max(p,i+1,n,tmp);
  }
}

int min(int *p,int i,int n,int m){
  if(i==n){
    return m;
  }
  else{
    int tmp;
    if(p[i]<m){
      tmp=p[i];
    }
    else{
      tmp=m;
    }
    return min(p,i+1,n,tmp);
  }
}

void doit(){
  int n;
  scanf("%d",&n);
  if(n!=0){
    int sc[n];
    int i;
    int ans;
    for(i=0;i<n;i++){
      scanf("%d",&sc[i]);
    }
    ans=(sum(sc,0,n)-max(sc,0,n,0)-min(sc,0,n,1000))/(n-2);
    printf("%d\n",ans);
    doit();
  }
}

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

Measured memory_bytes: 604
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main(){
  ll N;
  cin >> N;
  int dp[100001];
  REP(j,100001)
  {
    dp[j] = 0;
  }
  
  dp[0] = 1;
  for(int i = 0; i < 6; ++i)
  {
    for(int j = 0; j <= N; ++j)
    {
      if(j - (100 + i) >= 0)
      {
        dp[j] = max(dp[j], dp[j - (100 + i)]);
      }
    } 

  }

  cout << dp[N] << endl;

  return 0;    
}



Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    // Here your code !
    int a,b,c;
    int temp;
    scanf("%d%d%d", &a, &b, &c);
    if( a > b ){
        temp = a;
        a = b;
        b = temp;
    }
    if( b > c ){
        temp = b;
        b = c;
        c = temp;
    }
    if( a > b ){
        temp = a;
        a = b;
        b = temp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 596
int pwo(int x,int y)
{
    int i,a;
    a = x;
    if(y == 0)
    {
        return 1;
    }
    for(i = 1 ; i < y ; i++)
    {
        x = x*a;

    }
    return x;
}
#include<stdio.h>

int main(void)
{
    long int n,x,b;
    int k,i,j,a[100];
    scanf("%ld %d",&n,&k);
    i = 1;
    while(n >= pwo(k,i))
    {
        a[i] = n % pwo(k,i);
        
        
        i++;
    }
    printf("%d\n",i);
    
    return 0;
}

Measured memory_bytes: 1712
S = input()
if S == "SUN":
    print(7)
elif S =="MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
else:
    print(1)

Measured memory_bytes: 2940
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int a[101010];
LL rui[101010];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		rui[i] = rui[i - 1] + abs(a[i] - a[i - 1]);
	}
	rui[n + 1] = rui[n] + abs(a[n]);
	for (int i = 1; i < n; i++) {
		cout << rui[i - 1] + rui[n + 1] - rui[i + 1] + abs(a[i - 1] - a[i + 1]) << endl;;
	}
	cout << rui[n - 1] + abs(a[n - 1]) << endl;
	//system("pause");
}

Measured memory_bytes: 2432
n = int(input())
a = list(map(int, input().split())) + [0]
m, s = 1000, 0
for i in range(n):
    if a[i] < a[i+1] and s == 0:
        s = m//a[i]
        m -= a[i]*s
    elif a[i] > a[i+1] and s:
        m += a[i]*s
        s = 0
    
print(m)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m;
    cin >> n >> m;
    vector<int> x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    int sumx = 0, sumy = 0;
    rep(i, n)(sumx += (2 * i - n + 1) * x[i]) %= mod;
    rep(i, m)(sumy += (2 * i - m + 1) * y[i]) %= mod;
    int ans = (sumx * sumy) % mod;
    cout << ans << endl;
}

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

using namespace std;

int main() {

  

  int a,b,c;

  cin >> a>>b>>c;

  if(a==b&&b==c){
    cout << "No"<< endl;
   }else if(a==b || b==c || a==c){
    cout << "Yes"<< endl;
    }else{
    cout << "No"<< endl;
}

  

}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
	int c,d,j,i;
	char a[10000];
	while(scanf("%s",&a)==1){
		i=0;
		j=0;
		d=0;
		while(a[d]!='\0'){
			if(a[d]=='O'){
				if(a[d+1]=='I'){
					if(a[d-1]=='J'){
						j++;
					}
					else if(a[d-1]=='I'){
						i++;
					}
				}
			}
			d++;
		}
		printf("%d\n%d\n",j,i);
	}
	return 0;
}


Measured memory_bytes: 1980
#include<stdio.h>

int main(){
  long long int n, m; scanf("%lld %lld", &n, &m);
  long long int tail = 0;
  if(n >= 2 && m >= 2){
    tail = m * n - (m + m + n + n - 4);
  }else if(n == 1 && m == 1){
    tail = 1;
  }else{
    tail = m * n - 2;
  }
  printf("%lld", tail);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll X, Y;
  cin >> X >> Y;
  int counter = 0;
  for(ll i = X; i <= Y; i*=2){
    counter++;
  }
  cout <<counter << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    ll N,sum=0;
    cin>>N;
    vector<ll> v;
    for(ll i=1;i<=N;i++){
        sum+=i;
        v.push_back(i);
        if(N<sum) break;
    }
    for(ll i=0;i<v.size();i++){
        if(sum-N!=v[i]) cout<<v[i]<<endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

ll n, m, cnt, ans, cnt2, ans2;
bool v[2005];
bool vv;
vector<ll> ve[2005];

void dfs(ll p, ll q)
{
    if(v[p]) return;
    if(q == m + 1 && vv) cnt2++;
    else if(q <= m) v[p] = true, cnt++;
    if(q >= m + 1) return;
    if(q >= m && !vv) return;
    for(ll i = 0; i < ve[p].size(); i++)
    {
        dfs(ve[p][i], q + 1);
        if(q == 0) ans2 = max(ans2, cnt2), cnt2 = 0;
    }
}

int main()
{
    cin>>n>>m;
    if(m % 2 == 1) vv = true;
    m /= 2;
    for(ll i = 0; i < n - 1; i++)
    {
        ll t1, t2;
        scanf("%lld%lld", &t1, &t2);
        ve[t1].push_back(t2);
        ve[t2].push_back(t1);
    }
    for(ll i = 1; i <= n; i++)
    {
        cnt = 0;
        for(ll j = 1; j <= n; j++) v[j] = false;
        dfs(i, 0);
        ans = max(ans, cnt + ans2);
        ans2 = 0;
    }
    cout<<n - ans<<endl;
    return 0;
}


Measured memory_bytes: 384
N = int(input())
D = {}

for k in range(2,10**6):
  while N%k<1:
    N//=k
    D[k]=D.get(k,0)+1

a = 0
for i in D.values():
  t = 0
  c = 0
  while t+c<i:
    c+=1
    t+=c
  a+=c

print(a+(N>1))

Measured memory_bytes: 9132
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
  fio();
  ll n, k, s;
  cin >> n >> k >> s;
  vi a(n);
  int m = 1000000000;
  if (s != m) {
    rep (i, k) a[i] = s;
    for (int i = k; i < n; i++) a[i] = m;
  }
  else {
    rep (i, k) a[i] = s;
    for (int i = k; i < n; i++) a[i] = 1;
  }
  rep (i, n) {
    cout << a[i] << " ";
  }
  cout << endl;
}

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

struct info{
    int fi, se;
};

int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
int used[410][410];
int main(){
    int h, w;
    cin >> h >> w;
    string s[410];
    ll sum = 0;
    for(int i = 0; i < h; i++) cin >> s[i];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(used[i][j]) continue;
            queue<info> que;
            que.push((info){i, j});
            used[i][j] = 1;
            ll d = 0, b = 0;
            while(!que.empty()){
                info cur = que.front(); que.pop();
                if(s[cur.fi][cur.se] == '.') d++;
                else b++;
                for(int k = 0; k < 4; k++){
                    int ni = cur.fi + dy[k];
                    int nj = cur.se + dx[k];
                    if(ni >= 0 && nj >= 0 && ni < h && nj < w){
                        if(s[cur.fi][cur.se] != s[ni][nj] && used[ni][nj] == 0){
                            used[ni][nj] = 1;
                            que.push((info){ni, nj});
                        } 
                    }
                }
            }
            sum += b * d;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();
        int n = N;

        int sum = 0;
        while (n > 0) {
            sum += n % 10;
            n /= 10;
        }

        if (N % sum == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
ab = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']*2
n = int(input())
s = input()
ans = ''
for i in s:
    c = ab.index(i)+n
    ans += ab[c]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstring>
#include <map>
#include <set>
#define int long long int
#define cons 1000000007 
using namespace std;


signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    
    int n, i, cnt=0;
    cin>>n;
    int a[n+1], b[n];
    for(i=0;i<=n;i++)
        cin>>a[i];
    for(i=0;i<n;i++){
        cin>>b[i];
    }
    for(i=0;i<n;i++){
        if(a[i]>=b[i]){
            a[i]=a[i]-b[i];
            cnt+=b[i];
        }
        else{
            if(a[i+1]>=b[i]-a[i]){
                cnt+=b[i];
            }
            else{ 
                cnt+=(a[i]+a[i+1]);
            }
            a[i+1] = max((int)0, a[i+1]-(b[i]-a[i]));
            a[i]=0;
        }
    }
    cout<<cnt<<endl;

}




Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

#define INF 999999999
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main(){
	vector< pair<int, int> > a[51], b[8];
	pair<int, int> ins;
	int n, m;
	
	while(1){
		cin >> n;
		if(!n) break;
		REP(i,51)a[i].clear();
		REP(i,8)b[i].clear();
		REP(i,n+1){
			cin >> m;
			REP(j,m){
				cin >> ins.first >> ins.second;
				a[i].push_back(ins);
			}
		}
		REP(i,a[0].size()){
			ins.first = a[0][i].first;
			ins.second = a[0][i].second;
			b[0].push_back(ins);
			b[1].insert(b[1].begin(), ins);
		}
		for(int i=2;i<8;i++){
			REP(j,b[0].size()){
				ins.first = -b[i-2][j].second;
				ins.second = b[i-2][j].first;
				b[i].push_back(ins);
			}
		}
		for(int i=1;i<=n;i++){
			if(b[0].size()==a[i].size()){
				int flag;
				REP(j,8){
					flag=1;
					REP(k,b[0].size()-1){
						int x1 = a[i][k+1].first - a[i][k].first;
						int y1 = a[i][k+1].second - a[i][k].second;
						int x2 = b[j][k+1].first - b[j][k].first;
						int y2 = b[j][k+1].second - b[j][k].second;
						if(x1 != x2 || y1 != y2) flag = 0;
					}
					if(flag){
						cout << i << endl;
						break;
					}
				}
			}
		}
		cout << "+++++" << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

string S;
int A[4];

string dfs(string tmp, int sum) { //返り値:答えのstring or "imp"
    if (tmp.size() == 7) { //終わり
        if (sum == 7) return tmp+"=7";
        else return "imp";
    }
    int i=tmp.size(); //i=1,3,5
    string a = dfs(tmp+"+"+S[i/2+1], sum+A[i/2+1]);
    string b = dfs(tmp+"-"+S[i/2+1], sum-A[i/2+1]);
    if (a == "imp") return b;
    else return a;
}

signed main(void) {
    cin >> S;
    rep(i, 4) {
        A[i] = S[i] - '0';
    }
    cout << dfs(string(1, S[0]), A[0]) << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from itertools import product
"""
-> は @と表記する
"""

variables = set(list("abcdefghijk"))

def formula(S, X, i):
    if S[i] == "T":
        return 1, i+1
    elif S[i] == "F":
        return 0, i+1
    elif S[i] in variables:
        return X[S[i]], i+1
    elif S[i] == "-":
        i += 1
        that, i = formula(S, X, i)
        return (not that), i
    else:
        i += 1
        this, i = formula(S, X, i)
        op = S[i]
        i += 1
        that, i = formula(S, X, i)
        i += 1


        if op == "*":
            return this&that, i
        elif op == "+":
            return this|that, i
        elif op ==  "@":
            return (not this)|that, i
        else:
            raise

S = input()
T, F = 1, 0
while S != "#":
    S = S.replace("->", "@")
    while "--" in S:
        S = S.replace("--", "")
    L, R = S.split("=")
    for v in range(2**11):
        X = {}
        for a, x in zip(list("abcdefghijk"), format(v, "b").zfill(11)):
            X[a] = int(x)
        l, _ = formula(L, X, 0)
        r, _ = formula(R, X, 0)
        if int(l) != int(r):
            print("NO")
            break
    else:
        print("YES")
    S = input()



Measured memory_bytes: 5688
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int d;
	cin >> d;
	switch (d) {
	case 22:
		cout << "Christmas Eve Eve Eve" << endl;
		break;
	case 23:
		cout << "Christmas Eve Eve" << endl;
		break;
	case 24:
		cout << "Christmas Eve" << endl;
		break;
	case 25:
		cout << "Christmas" << endl;
		break;
	}
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N,M;
	long long sum=0;
	cin>>N>>M;
	for (int i=1;i<=M;++i)
	{
		int v;
		scanf("%d",&v);
		sum+=v;
	}
	if (sum>=N) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
main :: IO ()                                                                                                                                         
main = do                                                                                                                                             
  s <- getLine                                                                                                                                        
  let o = length . filter (=='1') $ s                                                                                                                 
      z = length . filter (=='0') $ s                                                                                                                 
  print $ o + z - abs (o - z)

Measured memory_bytes: 7164
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


if __name__ == '__main__':
    n,m,c = map(int, input().split())
    b = [int(i) for i in input().split()]

    count = 0
    for i in range(n):
        num=0
        a = [int(i) for i in input().split()]

        for i in range(m):
            num +=a[i] *b[i]
        if num >c*(-1):
            count+=1
    print(count)


Measured memory_bytes: 5136
#include<iostream>
#include<cstdio>
#define MAX 2000002
using namespace std;

int left(int i){ return 2 * i; }
int right(int i){ return 2 * i + 1; }

int A[MAX], H;

void maxHeapify(int i){
    int largest,tmp;
    int l = left(i);
    int r = right(i);
    
    if(l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    
    if (r <= H && A[r] > A[largest]) largest = r;
    
    if (largest != i){
        tmp = A[i]; A[i] = A[largest]; A[largest] = tmp;
        maxHeapify(largest);
    }
}

void extract(){
    printf("%d\n",A[1]);
    A[1] = A[H];
    H--;
    maxHeapify(1);
    
}

int main(){
    char com[7];
    H = 0;
    while(1){
        scanf("%s",com);
        if(com[0] == 'e' && com[1] == 'n') break;
        else if(com[0] == 'i'){
            H ++;
            scanf("%d",&A[H]);
            int i = H;
            while( i > 1 && A[i] > A[i/2]){
                maxHeapify(i/2);
                i /= 2;
            }

        }
        else{
            extract();
            
        }
        
    }
    
    return 0;
}




Measured memory_bytes: 7044
import sys
readline = sys.stdin.readline


def main():
    X, N = map(int, readline().rstrip().split())
    P = set(map(int, readline().rstrip().split()))

    for i in range(200):
        if X - i not in P:
            print(X - i)
            return
        if X + i not in P:
            print(X + i)
            return


if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))


n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [item-1 for item in a]

seen = [None] * n
c = 0
val = 0
seen[c] = val
val2c = {}
while True:
    val2c[val] = c
    if seen[a[c]] is not None:
        span = val - seen[a[c]] + 1
        init = seen[a[c]]
        break
    c = a[c]
    val += 1
    seen[c] = val

if k<=init:
    ans = val2c[k]
else:
    ans = val2c[(k-init)%span+init]
print(ans+1)

Measured memory_bytes: 126724
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
    int a,b, div;
    int rem;
    cin>>a>>b;

    div = (int)(a/b);
    rem = (int)(a%b);
    double real = (double)a/b;
    printf("%d %d %.5lf\n",div,rem,real);
    return 0;
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int i,j,x; 
  	cin >>i>>j;
  	if((i==1&&j==2)||(i==2&&j==1))x=3;
 	else if((i==1&&j==3)||(i==3&&j==1))x=2;
   	else if((i==2&&j==3)||(i==3&&j==2))x=1;
  	cout << x;
}

Measured memory_bytes: 256
using System;

namespace arc069_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            bool[] sheep = new bool[n + 2];
            bool[,] hoge = new bool[,]
            {
                {true,true },
                {true,false },
                {false,true },
                {false,false },
            };
            bool flag = true;
            for (int i = 0; i < 4; i++)
            {
                sheep[0] = hoge[i,0]; sheep[1] = hoge[i,1];
                for (int j = 2; j < n + 2; j++)
                {
                    sheep[j] = (s[(j - 1) % n] == 'o') == sheep[j - 1] ? sheep[j - 2] : !sheep[j - 2];
                }
                if (sheep[0] == sheep[n] && sheep[1] == sheep[n + 1])
                {
                    flag = false;
                    break;
                }
            }
            if (flag) Console.WriteLine(-1);
            else
            {
                for (int i = 0; i < n; i++) Console.Write(sheep[i] ? "S" : "W");
            }
        }
    }
}

Measured memory_bytes: 13120
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= x; i--)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)
typedef unsigned long long ull;
typedef vector<long long> vi;
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
//#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
void print(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}
void print(vi &v)
{
    f(v.size())
    {
        cout << v[i] << " ";
    }
    cout << endl;
}
int32_t main()
{
    int n;
    cin>>n;
    vi v;
        for(int j=1;j*j<=n;j++)
        {
            if(n%j)
            {
                v.pb(n/j);
            }
            else{
                v.pb((n/j)-1);
            }
        }
        fo(i,1,v.size())
        {
            v[i]-=i;
        }
        //print(v);
        int s=accumulate(all(v),0);
        double x=sqrt(n);
        int y;
        if(x==(int)x)
        {
            y=x-1;
        }
        else
        {
            y=x;
        }
        //cout<<x<<endl;
        cout<<s*2-y<<endl;
}

Measured memory_bytes: 3736
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class AAdditionAndSubtractionEasy {
public:
	void solve(istream& in, ostream& out) {
        ll a,b;
        char op;
        in >> a >> op >> b;
        if(op == '+') out << a + b << endl;
        else out << a - b << endl;
	}
};

int main() {
	AAdditionAndSubtractionEasy solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
S = [int(n) for n in list(input())]
n = len(S)
sbox = []

def f(i, box, k):
  if i==n-1:
    box += k
    sbox.append(box)
  else:
    f(i + 1, box+k, S[i+1])
    f(i + 1, box, 10*k + S[i+1])
    
f(0, 0, S[0])
print(sum(sbox))

Measured memory_bytes: 3060
N = input()
d = input().split()
i_1 = 0
i_2 = 0
result = 0
for index_1 in d:
    i_1 += 1
    i_2 = 0
    if i_1 > int(N):
        print('a break')
        break
    for index_2 in d:
        i_2 += 1
        if i_2 > int(N):
            print('b break')
            break
        # print('A:' + index_1 + ' B:' + index_2)
        if i_1 < i_2:
            result += (int(index_1) * int(index_2))
            # print('result:' + str(result))

print(result)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
  int n,t,i,j,dp[100010];
  const int INF=1e9;
  vector<int> m;
  cin >> n;
  m.push_back(1);
  for (t=6;t<=n;t*=6) m.push_back(t);
  for (t=9;t<=n;t*=9) m.push_back(t);
  sort(m.begin(),m.end());
  dp[0]=0;
  dp[1]=1;
  for (i=2;i<=n;i++) dp[i]=INF;
  for (i=2;i<=n;i++){
    for (j=0;j<m.size();j++){
      if (i>=m[j] && dp[i]>dp[i-m[j]]+1) dp[i]=dp[i-m[j]]+1;
    }
  }
  cout << dp[n] << endl;
  return 0;
}

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

using namespace std;

double euc(pair<int, int> p1, pair<int, int> p2) {
    return sqrt((p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second));
}

int main(){

    int N;
    cin >> N;
    vector<pair<int, int>> p(N);
    for(int i = 0; i < N; i++) cin >> p.at(i).first >> p.at(i).second;

    double ave_dist = 0.;
    std::vector<int> v(N);
    iota(v.begin(), v.end(), 0);
    do {
        for(int i = 0; i < N - 1; i++) {
            ave_dist += euc(p.at(v.at(i)), p.at(v.at(i + 1)));
        }
    } while(next_permutation(v.begin(), v.end()));

    double factrial = 1;
    for(int i = 1; i <= N; i++) factrial *= i;

    cout << fixed << setprecision(6) << ave_dist / factrial << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <algorithm>
 
using namespace std;
 
bitset<10000> cookie[10];
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
    int R, C;
	while(cin >> R >> C && R > 0)
	{
		int i, j;
		for (i = 0; i < R; ++i)
		{
			for (j = 0; j < C; ++j)
			{
				bool upwards;
				cin >> upwards;
				cookie[i][j] = upwards;
			}
		}
 
		// 在横向一共有2^R种变换
		int permute_r = 1 << R;
		int result = 0;
		for (i = 0; i < permute_r ; ++i)
		{
			// 完成当前的变换
			for (j = 0; j < R; ++j)
			{
				// 这一行是否应当翻个面
				if (i & (1 << j))
				{
					cookie[j].flip();
				}
			}
			
 
			// 对每一列分别算出朝上和朝下的煎饼个数，取其最大值
			int possible_answer = 0;
			for (j = 0; j < C; ++j)
			{
				int up_cookie_count = 0;
				for (int k = 0; k < R; ++k)
				{
					if (cookie[k][j])
					{
						++up_cookie_count;
					}
				}
				possible_answer += max(up_cookie_count, R - up_cookie_count);
			}
			// 结果取最大值
			result = max(result, possible_answer);
			
			// 复原
			for (j = 0; j < R; ++j)
			{
				if (i & (1 << j))
				{
					cookie[j].flip();
				}
			}
		}
		cout << result << endl;
	}
 
    return 0;
}


Measured memory_bytes: 3028
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  priority_queue<int> q;
  rep(i, n){
    cin >> a[i];
    q.push(a[i]);
  }
  rep(i, m){
    int qmax=q.top();
    q.pop();
    q.push(qmax/2);
  }
  ll ans=0;
  while(!q.empty()){
    int p=q.top();
    q.pop();
    ans+=p;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1276
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;


void main() {
    int n, m;
    scan(n, m);
    auto cnt = new int[](n);
    auto red = new bool[](n);
    cnt[] = 1;
    red[0] = 1;

    foreach (i ; 0 .. m) {
        int xi, yi;
        scan(xi, yi);
        xi--, yi--;
        if (red[xi]) {
            red[yi] = 1;
            if (cnt[xi] - 1 == 0) red[xi] = 0;
        }
        cnt[xi]--;
        cnt[yi]++;
    }

    auto ans = iota(n).count!(i => red[i] && cnt[i] > 0);
    writeln(ans);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
#define bada 1000000000000000000

int gcd(int a, int b)
{
    if(b)
        return gcd(b,a%b);
    return a;
}
int lcm(int a,int b)
{
    return (a*b)/gcd(a,b);
}
int main ()
{
    int x;
    cin>>x;
    cout<<lcm(x,360)/x<<endl;
}



Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    
    if(x+r<=W && x-r>=0 && y+r<=H && y-r>=0) {printf("Yes\n");}
    else {printf("No\n");}
    
    return 0;
    
}



Measured memory_bytes: 2104
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>


/* ---------- Namespace ---------- */

using namespace std;


/* ---------- Type Abbreviation ---------- */

template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

using ll = long long;
using PL = P<ll, ll>;
using PS = P<string, ll>;

using VI = V<int>;
using VVI = V<VI>;
using VL = V<ll>;
using VVL = V<VL>;
using VS = V<string>;
using VB = V<bool>;
using VVB = V<VB>;
using VPL = V<PL>;
using VPS = V<PS>;

#define fst first
#define snd second


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)


/* ---------- container ---------- */

#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define GSORT(c) sort(ALL(c), greater<decltype((c).front())>())
#define SZ(x) (LL((x).size()))


/* ---------- repetition ---------- */

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)

#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// Usual REP runs from 0 to n-1 (R: n to 0)
// Natural REP runs from 1 to n (R: n to 1)


/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = 3.14159265358979;
// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};


/* ---------- Short Functions ---------- */

template <typename T>
T square(T a) {
    return a * a;
}


/* ---------- Debug ---------- */
#define GET_VAR_NAME(variable) #variable

#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;
#define testP(p) cout << GET_VAR_NAME(p) << " = (" << (p).fst << ", " << (p).snd << ")" << endl;


/* ^^^^^^^^^^^^^^^ Settting Part ^^^^^^^^^^^^^^^ */

/* ---------- Variances ---------- */


/* ---------- Functions ---------- */


/* ---------- Main Function ---------- */

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

    ll N;
    cin >> N;

    VL A(N), B(N);
    REP(i, N) {
        cin >> A[i] >> B[i];
    }

    ll ans = 0;
    RREP(i, N - 1) {
        A[i] += ans;
        ll push_num;
        if (A[i] > 0) {
            push_num = B[i] - ((A[i] - 1) % B[i] + 1);
        } else {
            push_num = 0;
        }
        ans += push_num;
    }

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

Measured memory_bytes: 1792