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

using namespace std;

vector<char> a;
char ch;
int n;

int main() {
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> ch;
        a.push_back(ch);
    }
    sort(a.begin(),a.end());
    int dem = 0;
    long long ans = 1;
    for (int i=0; i<n; i++) {
        if (i == n-1 || a[i] != a[i+1]) {
            dem += 2;
            ans = (ans * dem) % int(1e9 + 7);
            dem = 0;
        } else dem++;
    }
    cout << ans - 1;
    return 0;
}

Measured memory_bytes: 512
from math import  pi,cos,sin
r,_x,_y,n=map(int,input().split())
_m=list(map(int,input().split()))
x,y=_x/r,_y/r
m=sum(_m)
t=[0.0]*(n+1)
_t=0
a=[]
for i in range(n):
    _t+=_m[i]/m*2*pi
    t[i+1]=_t
    a.append(int(( 1 + ((sin(t[i])*y-cos(t[i])*x) + (x*cos(t[i+1])-y*sin(t[i+1])) ) / (t[i+1]-t[i]) )*100))
print(*a)

Measured memory_bytes: 8020
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template<class _T> static void getint(_T& a) {
	if (sizeof(_T) > sizeof(int)) {
		scanf("%lld", &a);
	}
	else {
		scanf("%d", &a);
	}
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int N, T;
	get(N, T);

	LLONG max = 0;
	LLONG min = MOD_NUM;
	LLONG maxDiff = 0;
	bool update = false;
	int opecnt = 0;
	for (int i = 0; i < N; i++) {
		LLONG a;
		get(a);

		if (max < a) {
			max = a;
		}
		if (min > a) {
			min = a;
			max = a;
			update = true;
		}
		if (maxDiff < (max - min)) {
			maxDiff = max - min;
			opecnt = 1;
			update = false;
		}
		else if (update && (maxDiff == (max - min))) {
			opecnt++;
			update = false;
		}
	}
	printf("%d\n", opecnt);
}


Measured memory_bytes: 3760
#include <stdio.h>

int main(void)
{
	char a[100][101];
	int h,w,i,j;
	scanf("%d%d",&h,&w);
	for(i=0;i<h;i++)scanf("%s",a[i]);
	for(i=-1;i<h+1;i++){
		for(j=-1;j<w+1;j++){
			if(i==-1||i==h||j==-1||j==w)printf("#");
			else printf("%c",a[i][j]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define sec second
using namespace std;
typedef long long ll;
const long long int linf =(ll)9e18;
const int dx[8] = { 0, 0, 1, -1, 1, -1, 1, -1 }, dy[8] = { 1, -1, 0, 0, 1, -1, -1, 1 };

const int N=1005,MOD=(int)1e9+7;
ll n,m,dp[N][N];
char grid[N][N];

bool isvalid(int i,int j){
    return i>=0 && i<n && j>=0 && j<m && grid[i][j]!='#';
}

ll solve(int i,int j){
   if(i==n-1 && j==m-1)return 1;
   ll &ret=dp[i][j];
   if(~ret)return ret;
   ll right=0;
   if(isvalid(i+1,j))right=solve(i+1,j);
   ll down=0;
   if(isvalid(i,j+1))down=solve(i,j+1);
   return ret=(right%MOD + down%MOD)%MOD;
}

int main()
{
    ROCK;
    memset(dp,-1,sizeof dp);
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>grid[i][j];
    cout<<solve(0,0)<<endl;
    return 0;
}

Measured memory_bytes: 12552
#include <iostream>
#include <stdio.h>
#include <string>
#include<algorithm>
using namespace std;
 

int main(){
    long long N,A;
    string inp;
    cin >> inp ;;
    if(inp[0]=='Y'&&inp[1]=='A'&&inp[2]=='K'&&inp[3]=='I'){
        cout <<"Yes"<< endl;
    }else{
        cout <<"No"<< endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
work = [0 for i in range(n)]
count = 0
for i in range(1, n+1):
    if (A[i]-A[i-1])*(A[i+1]-A[i]) < 0:
        work[i-1] = min(abs(A[i+1] - A[i])*2, abs(A[i] - A[i-1])*2)
    count += abs(A[i]-A[i-1])
count += abs(A[n]-0)
for el in work:
    print(count-el)

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{
    gearup;
    ll n; cin >> n;
    string res = "";
    if(n == 0){
        out(0);
        return 0;
    }
    
    while(n != 0){
        ll num = n % -2;
        if(num == -1)num = 1;
        res = (char)('0' + num) + res;
        n = (n-num)/-2;
    }
    out(res);
}

Measured memory_bytes: 3656
#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 x, y, z;
        cin >> x >> y >> z;
        cout << z << " " << x << " " << y << endl;
        return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin>>N;
  vector<long long>A(N);
  vector<long long>sum(N);
  sum.at(0)=0;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    if(i==0){
      sum.at(i)=A.at(i);
    }
    else{
      sum.at(i)=sum.at(i-1)+A.at(i);
    }
  }
  long long ans=2000000000;
  for(int i=0;i<N-1;i++){
    ans=min(ans,abs(sum.at(i)*2-sum.at(N-1)));
  }
  cout<<ans<<endl;
}
  


Measured memory_bytes: 3328
import sys
input = sys.stdin.readline
S = list(input())
T = list(input())
del S[-1]
del T[-1]
l = len(S)
ans = "No"
for i in range(l) :
    a = S[-1]
    del (S[-1])
    S.insert(0,a)
    if S == T :
        ans = "Yes"
        break
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] h = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			string[] vs1 = Console.ReadLine().Split();
			string s = vs1[0];
			string t = vs1[1];
			int[] vs2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int a = vs2[0];
			int b = vs2[1];
			string u = Console.ReadLine();
			if (s == u) {
				a--;
			} else {
				b--;
			}
			Console.WriteLine($"{a} {b}");



			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;

struct RH {
    const int n;
    static constexpr lint mod0 = 1e9 + 7, mod1 = 1e9 + 9;
    static constexpr lint b0 = 12345678, b1 = 87654321;
    V<lint> h0, h1, powb0, powb1;
    template<class Itr> RH(Itr first, Itr last) :
        n(last - first), h0(n + 1), h1(n + 1), powb0(n + 1), powb1(n + 1) {
        powb0[0] = powb1[0] = 1;
        for (int i = 0; i < n; ++i, ++first) {
            h0[i + 1] = (h0[i] * b0 + *first) % mod0;
            h1[i + 1] = (h1[i] * b1 + *first) % mod1;
            powb0[i + 1] = powb0[i] * b0 % mod0;
            powb1[i + 1] = powb1[i] * b1 % mod1;
        }
    }
    pair<lint, lint> get(int l, int r) {
        lint res0 = (h0[r] - h0[l] * powb0[r - l]) % mod0;
        lint res1 = (h1[r] - h1[l] * powb1[r - l]) % mod1;
        if (res0 < 0) res0 += mod0;
        if (res1 < 0) res1 += mod1;
        return {res0, res1};
    }
};

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    RH rh(begin(s), end(s));
    reverse(begin(s), end(s));
    RH rev(begin(s), end(s));
    auto chk = [&](int k) -> bool {
        int t = 2 * k - 2;
        if (n <= t) {
            return rh.get(2 * k - n - 1, k - 1) == rev.get(0, n - k);
        }
        if (rh.get(0, k) != rev.get(n - t - 1, n - k + 1)) return false;
        for (int i = 0; i < n; i += t) {
            int w = min(t, n - i);
            if (rh.get(0, w) != rh.get(i, i + w)) return false;
        }
        return true;
    };
    // cerr << rh.get(0, 3).first << endl;
    // cerr << rev.get(1, 4).first << endl;
    // return 0;
    for (int k = 2; k <= n; ++k) {
        if (chk(k)) return cout << k << "\n", 0;
    }
    assert(false);
    return 0;
}


Measured memory_bytes: 66508
def main():
    S = input()
    N = len(S)
    for i in range(1, N):
        s = S[:-i]
        M = len(s)
        if M % 2:
            continue
        if s[:M//2] == s[M//2:]:
            print(M)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, K;
    string S;
    cin >> N >> K >> S;
    S[K - 1] -= 'A' - 'a';
    cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <map>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N; cin>>N;
  vector<ll> a(N);
  map<ll,ll> cnt;
  ll ans = 0, sum = 0;
  cnt[0LL]++;
  REP(i,N) {
    cin>>a[i];
    sum	+= a[i];
    ll v = cnt[sum]++;
    ans += v;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define lli long long int
using namespace std;


int main(){
    lli n,d,t=0;
    cin>>n>>d;
    lli x,y;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        if(sqrt(abs(x*x+y*y))<=d) t++;
        // cout<<sqrt(abs(x*x+y*y))<<endl;
    }
    cout<<t;
    return 0;
}

Measured memory_bytes: 3696
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main() {
	int N;
	cin >> N;
	double count = 0;
	for (int i = 1; i <= N; i++)
	{
		if (i % 2 == 1)count++;
	}
	printf("%.16f", count / N);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

struct Uni {

    vector<int>par;
    vector<int>size;
    Uni(int n)  {
        par.resize(n); size.resize(n, 1);
        for (int i = 0; i < n; i++)par[i] = i;
    }
    

    int root(int x) {
        if (par[x] == x)return x;
        return par[x] = root(par[x]);
    }
    void ch(long long int x, long long int y) {
        int a = root(x);
        int b = root(y);
        if (a == b)return;
      //  if (size[a] < size[b])swap(a, b);
        par[b] = a;
        size[a] += size[b];
    }

};

int main()
{
    int n, m;
    cin >> n >> m;
    Uni t(n + 2);
    vector<long long int>a(m), b(m);

    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];

    }
    vector<long long int>ans(m);
    ans[m - 1] =(long long int) n * (n - 1) / 2;

    for (int i = m - 1; i >= 1; i--) {
        ans[i - 1] = ans[i];
     //   cout << t.size[a[i]] << " " << t.size[b[i]] << endl;
        if (t.root(a[i]) != t.root(b[i])) {
            
            ans[i - 1] = ans[i] - (long long int)t.size[t.root(a[i])] * t.size[t.root(b[i])];

            
            t.ch(a[i], b[i]);
        }

    }
    for (int i = 0; i < m; i++) {
        cout << ans[i] << endl;
    }


    return 0;

}

Measured memory_bytes: 6436
#include<bits/stdc++.h>
#define REP(i,n) fot(int i=0 ;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(x) x.begin(),x.end()
#define REVERSE(x) reverse(x.begin(),x.end())
typedef long long LL;
const double INF = 1e9;
using namespace std;
int main(){
  int A,B,T;
  cin>>A>>B>>T;
  int ans=T/A*B;
    cout<<ans;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Character {
  string name;
  int v;
  int index;
  Character() {;}
  Character(string name, int v, int index) : name(name), v(v), index(index) {;}
  bool operator<(const Character &rhs) const {
    if (v != rhs.v) { return v > rhs.v; }
    return name < rhs.name;
  }
};

Character character[100010];
Character sorted[100010];
int fav[100010];
bool bfav[100010];
int need[100010];
bool used[100010];
int n, m, k, l;

bool calc(int t) {
  if (t > k || t > m) { return false; }
  MEMSET(used, false);
  REP(i, k - t + 1) {
    if (bfav[sorted[i].index]) {
      used[sorted[i].index] = true;
      t--;
    }
    if (t <= 0) { return true; }
  }
  Character target = sorted[k - t];
  REP(i, m) {
    int index = fav[i];
    if (used[index]) {
      need[i] = l + 1;
      continue;
    }
    need[i] = max(0, target.v - character[index].v);
    if (target.name < character[index].name) {
      need[i]++;
    }
  }
  sort(need, need + m);
  ll sum = 0;
  REP(i, t) {
    sum += need[i];
  }
  return sum <= l;
}

char str[1000];
int main() {
  while (scanf("%d %d %d %d", &n, &m, &k, &l), n|m|k|l) {
    MEMSET(bfav, false);
    map<string, int> mapto;
    REP(i, n) {
      int v;
      scanf("%s %d", str, &v);
      character[i] = Character(str, v, i);
      sorted[i] = character[i];
      mapto[str] = i;
    }
    sort(sorted, sorted + n);
    REP(i, m) {
      scanf("%s", str);
      fav[i] = mapto[str];
      bfav[fav[i]] = true;
    }
    sort(fav, fav + m);
    int left = 0;
    int right = min(m, k) + 1;
    while (left != right) {
      int mid = (left + right) / 2;
      if (calc(mid)) {
        left = mid + 1;
      } else {
        right = mid;
      }
    }
    left--;
    printf("%d\n", left);
  }
}

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

#define ll long long
#define endl "\n"
#define pb push_back
#define mp make_pair

int main(){
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	vector<ll> v = {a*c, a*d, b*c, b*d};
	ll mx = *max_element(v.begin(), v.end());
	cout << mx;
	return 0;
}


Measured memory_bytes: 3644
use std::io::stdin;

#[allow(dead_code)]
fn input_ints() -> Vec<i32> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => st.split_whitespace().map(|s| s.parse().unwrap()).collect(),
        Err(_) => "".split_whitespace().map(|s| s.parse().unwrap()).collect(),
    }
}

#[allow(dead_code)]
fn input_strs() -> Vec<String> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => st.split_whitespace().map(|s| s.to_string()).collect(),
        Err(_) => "".split_whitespace().map(|s| s.to_string()).collect(),
    }
}

fn main() {
    let line = input_strs();
    // let line = input_ints().to_array();
    let x: i32 = (&line[0]).parse().unwrap();
    let op = &line[1];
    let y: i32 = (&line[2]).parse().unwrap();

    if op == "+" {
        println!("{}",x + y);
    }
    else {
        println!("{}",x - y);
    } 
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  int t=A+B+C;
  int m=max({A,B,C});
  if((3*m-t)%2==0){cout<<(3*m-t)/2<<endl;}
  else{cout<<((m+1)*3-t)/2<<endl;}
  
  return 0;  
}

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

int main()
{
  int N, M, C;
  cin >> N >> M >> C;
  
  int s=0;
  
  int B[M];
  for(int k=0; k<M; k++){
        cin >> B[k];
  }
  
  int A[M];
  int i=0;
  while(i<N){
    int S=C;
    for(int j=0; j<M; j++){
      cin >> A[j];
      S += A[j]*B[j];
    }
    if(S>0)
      s=s+1;
    i++;
  }
  cout << s;
  
  return 0;
}


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

int N;

int dfs(string s) {
    ll num;
    if (s.empty()) num = 0; else num = stol(s);
    if (num > N) return 0;
    int ret = 0;
    bool B[] = {false, false, false};
    while (num > 0) {
        int d = num % 10; num /= 10;
        if (d == 3) B[0] = true;
        if (d == 5) B[1] = true;
        if (d == 7) B[2] = true;
    }
    ret = (all_of(begin(B), end(B), [](bool b){return b;})) ? 1 : 0;
    ret += dfs(s + "3");
    ret += dfs(s + "5");
    ret += dfs(s + "7");
    return ret;
}

int main() {
    cin >> N;
    cout << dfs("") << endl;
}

Measured memory_bytes: 256
num = int(input())
category = {"AC": 0, "WA": 0, "TLE":0, "RE": 0}

for i in range(num):
  word = input()
  category[word] += 1

print("AC x " + str(category["AC"]))
print("WA x " + str(category["WA"]))
print("TLE x " + str(category["TLE"]))
print("RE x " + str(category["RE"]))

Measured memory_bytes: 9172
a, b, c, d = map(int, list(input()))

for i in range(1<<3):
    num = [a, b, c, d]
    for j in range(3):
        if i>>j & 1 != 1:  # 1桁目==1 がTrueではなかった場合
            num[j+1] *= -1
    ans = sum(num)
    if ans == 7:
        for k, n in enumerate(num):
            if n >= 0 and k > 0:
                print('+', n, sep='', end='')
            else:
                print(n, sep='', end='')
        else:
            print('=7', sep='')
        break

Measured memory_bytes: 8984
#include<stdio.h>

int main()
{

int m[10];
int i=0,c=0,ca=0;

for(c=0;c<10;c++){
	scanf("%d",&m[c]);
}


for(c=0;c<10;c++){
for(i=0;i<9;i++)
{
if(m[i]<m[i+1])
{
ca=m[i];
m[i]=m[i+1];
m[i+1]=ca;
}
}
}
printf("%d\n",m[0]);
printf("%d\n",m[1]);
printf("%d\n",m[2]);


return 0;

}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  vector<vector<char>> s(n,vector<char>(n));
  int i,j;
  rep(i,n)rep(j,n)cin>>s[i][j];
  vector<vector<int>> move(n);
  rep(i,n)
  {
    rep(j,n)
    {
      if(s[i][j]=='1')
      {
        move[i].emplace_back(j);
      }
    }
  }
  vector<int> color(n,-1);
  color[0]=0;
  queue<int> q;
  queue<int> q2;
  q.push(0);
  bool ok=true;
  while(!q.empty())
  {
    while(!q.empty())
    {
      int now=q.front();
      q.pop();
      rep(i,move[now].size())
      {
        if(color[move[now][i]]==-1)
        {
          color[move[now][i]]=(1-color[now]);
          q2.push(move[now][i]);
        }
        else if(color[move[now][i]]==color[now])
        {
          ok=false;
        }
      }
    }
    while(!q2.empty())
    {
      q.push(q2.front());
      q2.pop();
    }
  }
  if(!ok)cout<<-1<<endl;
  else
  {
    int ans=0;
    for(i=0;i<n;i++)
    {
      int dis=1;
      vector<int> mind(n,-1);
      mind[i]=0;
      q.push(i);
      while(!q.empty())
      {
        while(!q.empty())
        {
          int now=q.front();
          q.pop();
          rep(j,move[now].size())
          {
            if(mind[move[now][j]]==-1)
            {
              mind[move[now][j]]=dis+1;
              q2.push(move[now][j]);
            }
          }
        }
        while(!q2.empty())
        {
          q.push(q2.front());
          q2.pop();
        }
        dis++;
      }
      rep(j,n)ans=max(ans,mind[j]);
    }
    cout<<ans<<endl;
  }
}



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

using namespace std;

class dice 
{
private:
	
public:
	dice();
	dice(int array[]);
	void assign(int array[]);
	void turnE();
	void turnN();
	void turnS();
	void turnW();
	void command(string com);
	int findRightThroughtTopAndFront(int top, int front);
	int num[7];
};

int isSame(dice* dic1, dice* dic2);
dice::dice()
{

}
dice::dice(int array[])
{
	int i;
	for (i = 0; i < 6; i++)
		num[i + 1] = array[i];
}

void dice::assign(int array[])
{
	int i;
	for (i = 0; i < 6; i++)
		num[i + 1] = array[i];
}

void dice::command(string com)
{
	int len = com.length();
	int i;
	char ch;
	for (i = 0; i < len; i++)
	{
		ch = com.at(i);
		if (ch == 'E')
		{
			turnE();
			continue;
		}
		if (ch == 'N')
		{
			turnN();
			continue;
		}
		if (ch == 'W')
		{
			turnW();
			continue;
		}
		if (ch == 'S')
		{
			turnS();
			continue;
		}
	}
}

void dice::turnE()
{
	int temp;
	temp = num[6];
	num[6] = num[3];
	num[3] = num[1];
	num[1] = num[4];
	num[4] = temp;
}

void dice::turnN()
{
	int temp;
	temp = num[6];
	num[6] = num[5];
	num[5] = num[1];
	num[1] = num[2];
	num[2] = temp;
}

void dice::turnS()
{
	int temp;
	temp = num[6];
	num[6] = num[2];
	num[2] = num[1];
	num[1] = num[5];
	num[5] = temp;
}

void dice::turnW()
{
	int temp;
	temp = num[6];
	num[6] = num[4];
	num[4] = num[1];
	num[1] = num[3];
	num[3] = temp;
}

int dice::findRightThroughtTopAndFront(int top, int front)
{
	int i;
	// find front
	for (i = 1; i < 7 && num[i] != front; i++);
	if (i == 1)
		turnS();
	else if (i == 3)
	{
		turnW();
		turnS();
	}
	else if (i == 4)
	{
		turnE();
		turnS();
	}
	else if (i == 5)
	{
		turnS();
		turnS();
	}
	else if (i == 6)
	{
		turnN();
	}
	// now let the front to front
	if (i == 7)
		return -1;

	for (i = 1; i < 7 && num[i] != top; i++);
	if (i == 4)
	{
		turnE();
	}
	else if (i == 6)
	{
		turnE();
		turnE();
	}
	else if (i == 3)
	{
		turnW();
	}

	if (i == 7)
		return -1;

	return num[3];
}

int main(void)
{
	int array[6];
	int n;
	int i, j;
	cin >> n;
	dice *dices = new dice[n];
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 6; j++)
			cin >> array[j];
		(dices + i)->assign(array);
	}
	
	int flag = 0;
	for (i = 0; i < n - 1; i++)
	{
		if (isSame((dices + i), (dices + i + 1)) == 1)
			flag = 1;
	}

	for (i = 0; i < n - 1; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			if (isSame((dices + i), (dices + j)) == 1)
				flag = 1;
		}
	}

	if (flag == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;

}

int isSame(dice* dic1, dice* dic2)	// Same return 1, else return 0;
{
	int flag = 0;
	int front = dic1->num[2];
	int top = dic1->num[1];
	int rightFind = dic2->findRightThroughtTopAndFront(top, front);
	if (rightFind == dic1->num[3])
	{
		front = dic1->num[6];
		top = dic1->num[5];
		rightFind = dic2->findRightThroughtTopAndFront(top, front);
		if (rightFind == dic1->num[4])
		{
			front = dic1->num[3];
			top = dic1->num[1];
			rightFind = dic2->findRightThroughtTopAndFront(top, front);
			if (rightFind == dic1->num[5])
				flag = 1;
		}
	}
	return flag;
}


Measured memory_bytes: 3128
#include <cstdio>
#include <algorithm>

int n;
int A[16][16];

long long int dp[1<<16];
long long int dp2[2][1<<16];

void conv(long long int *r, const long long int *a){
  for(int x = 0; x < (1 << n); x++) r[x] = 0;
  for(int x = 0; x < (1 << n); x++){
    int z = ~x & ((1 << n) - 1);
    for(int y = z; y; y = (y-1) & z){
      r[x^y] = std::max(r[x^y], a[x] + a[y]);
    }
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      scanf("%d", &A[i][j]);
    }
  }
  for(int x = 0; x < (1<<n); x++){
    dp[x] = dp[x&(x-1)];
    int i = __builtin_ctz(x);
    for(int y = x&(x-1); y; y &= y-1){
      int j = __builtin_ctz(y);
      dp[x] += A[i][j];
    }
    dp2[0][x] = dp[x];
  }

  for(int i = 0; i < 4; i++){
    bool b = i&1;
    conv(dp2[!b], dp2[b]);
  }
  long long int ans = dp2[0][(1<<n)-1];
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>
#include <utility>
#include <tuple>
using namespace std;
using Int = long long;

int main()
{
    int X, A, B;
    cin >> X >> A >> B;
    cout << (X - A) % B << endl;
    return 0;
}


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

using namespace std;

//#define int long long

pair<int, int> pos[300 * 300 + 10];
int n, m, d;
int q;
int vec[300 * 300 + 10];
int p[300 * 300 + 10];
char used[300 * 300 + 10];
vector<vector<int>> pref;

main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m >> d;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            int x;
            cin >> x;
            pos[x] = {i, j};
        }
    }
    for(int i = 1; i <= n * m; i++){
        if(used[i]) continue;
        int j = i;
        vector<int> cur;
        cur.push_back(0);
        p[j] = 0;
        used[j] = true;
        vec[j] = pref.size();
        int c = 1;
        int px = pos[j].first, py = pos[j].second;
        while(j + d <= n * m){
            j += d;
            used[j] = true;
            p[j] = c++;
            vec[j] = pref.size();
            int tx = pos[j].first, ty = pos[j].second;
            cur.push_back(abs(px - tx) + abs(py - ty) + cur.back());
            px = tx;
            py = ty;
        }
        pref.push_back(cur);
    }
    cin >> q;
    for(int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        int an = pref[vec[r]][p[r]] - pref[vec[l]][p[l]];
        cout << an << '\n';
    }
}


Measured memory_bytes: 6832
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int d[100000];
    int x;
    cin >> x;
    d[0]=2;
    int n=1;
    for(int i=2;i<100004;i++ ){
        bool flag=0;
        for(int j=0;j<n;j++){
            if(i%d[j] == 0)flag=1;
        }
        if(!flag){
            d[n]=i;
            n++;
            if(i>=x)break;
        }
        
    }
    if(x==2)cout << 2 << endl;
else cout << d[n-1] << endl;

}

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

int main (){
  int n;
  cin >> n;
  vector <int> a(n); 
  vector <int> b(n-1);
  for (int i = 0;i<n;i++){
    cin >> b[i];    
  }
  a[0] = b[0];
  a[n-1] = b[n-2];
  int count = a[n-1] + a[0];
  for (int j = 1;j<n-1;j++){
    a[j] = min(b[j-1],b[j]);
    count += a[j];
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
const int N = 10101;
int main() {
	int n;
	cin >> n;
	V a(n);
	rep(i, n) {
		cin >> a[i];
	}
	VE<VE<bool>> dp(n + 1, VE<bool>(N, false));
	dp[0][0] = true;
	rep(i, n) rep(j, N) {
		if (dp[i][j]) {
			dp[i + 1][j + a[i]] = true;
			dp[i + 1][j] = true;
		}
	}
	int ans = 0;
	rep(i, N) {
		if (dp[n][i] && i % 10 != 0) chmax(ans, i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
 
#define lb push_back
typedef long long ll;
using namespace std;
const int maxn = 1e6+5;
map<int,int> w;
int main()
{
    int n, k, a; cin >> n >> k;
    for(int i = 1; i <= k; i++) {
        cin >> a;
        w[a] = 1;
    }
    for(int i = n; i <= 100000; i++) {
        a = i;
        int flag1 = 0;
        while(a) {
            int b = a%10;
            if(w[b]) {
                flag1 = 1;
                break;
            }
            a /=10;
        }
        if(!flag1) {
            cout << i << endl;
            return 0;
        }
    }
 
}

Measured memory_bytes: 256
s = int(input())
if s<=10**9:
	print(0,0,1,0,0,s)
elif 10**18>s>10**9:
    q,r = divmod(s,10**9)
    print(10**9,0,r,q+1,0,1)
else:
    print(0,0,10**9,0,0,10**9)

Measured memory_bytes: 3060
#include <iostream>
#include <tuple>
#include <cstdint>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <cctype>
#include <utility>
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

#define ll long long
#define ld long double

#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)
#define all(x) begin(x), end(x)
#define rall(x) end(x), begin(x)

#define endl '\n'
constexpr ll MOD = 1000000007;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    ll ex = 0;
    while (N % a == 0) {++ex, N /= a;}
    res.push_back({a, ex});
  }

  if (N != 1) res.push_back({N, 1});
  return res;
}

ll solve(ll N) {
  auto primes = prime_factorize(N);
  ll res = 0;
  for (auto elm : primes) {
    res += (ll)floor(0.5*(-1+sqrt(8.0*elm.second+1)));
  }
  return res;
}

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

  ll N;
  cin >> N;

  auto ans = solve(N);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(ll i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	ll l,r; cin >> l >> r;
	ll mx = min(l+2019,r);
	ll ans = 2019;
	rep2(i,l,mx)rep2(j,i+1,mx+1){
		ans = min(ans,(i*j)%2019);
	}
	out(ans);
}




Measured memory_bytes: 256
//22
#include<iostream>

using namespace std;

#define MAX 1299709

int main(){
  static bool cmp[MAX+1]={true,true};
  for(int i=2;i<=MAX;i++){
    if(!cmp[i]){
      for(int j=2;j*i<=MAX;j++){
	cmp[i*j]=true;
      }
    }
  }
  for(int n;cin>>n,n;){
    if(!cmp[n]){
      cout<<0<<endl;
    }else{
      int f=n,l=n;
      while(cmp[f]){
	f--;
      }
      while(cmp[l]){
	l++;
      }
      cout<<l-f<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
#include <vector>
#define REP(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
  ll h,w,n;
  cin>>h>>w>>n;
  ll a[n];
  REP(i,n){
    cin>>a[i];
  }
  
  ll c[h][w];
  ll b[n];
  b[0] = 1;
  for(int i=1;i<n;i++){
    b[i] = b[i-1]+a[i-1];
  }
  
  REP(i,h){
    REP(j,w){
      c[i][j] = 0;
    }
  }
      
  
  REP(i,h){
    REP(j,w){
      ll num = 0;
      if(i%2==0){
        num = i*w+j+1;
      }else{
        num = i*w+w-j;
      }
      
      REP(k,n){
        if(b[k]>num){
          if(j!=0){
            cout<<" ";
          }
          cout<<k;
          break;
        }else if(k==n-1){
          if(j!=0){
            cout<<" ";
          }
          cout<<k+1;
        }
      }
    }
    cout<<endl;
  }
  
  return 0;
}

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

int main() {
  vector<string> abc(3);
  char winner;
  for(int i = 0; i < 3; i++){
    cin >> abc.at(i);
  }

  int turn = 0, next_turn;
  for(;1;){
    
    if(abc.at(turn).size() != 0){
//      cout << abc.at(turn);
      next_turn = abc.at(turn).at(0) - 'a';
//      cout << next_turn << endl;
      abc.at(turn).erase(abc.at(turn).begin());
//      cout << abc.at(turn) << endl;
      turn = next_turn;
      
    }else{
      winner = 'A' + turn;
      
      break;
    }
    
  }
  
  
  cout << winner << endl;
}




Measured memory_bytes: 256
#include <iostream>


using namespace std;
int main(void){
    int K,S;
    cin>>K>>S;
    int res=0;
    for(int i=0;i<=K;i++){
        for(int j=0;j<=K;j++){
            if(S-i-j>=0 && S-i-j<=K)res++;
        }
    }
    printf("%d",res);
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        char carr[]=sc.nextLine().toCharArray();
        int n=carr.length;
        if(carr[n-1]=='s')
        System.out.println(new String(carr)+"es");
        else
        System.out.println(new String(carr)+"s");
    }
}

Measured memory_bytes: 38516
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	long s = read.to!long;
	
	long u1 = 1_000_000_000;
	long v1 = 1;
	long u2 = (u1 - s % u1) % u1;
	long v2 = (s + u1 - 1) / u1;
	
	long x1 = 0;
	long y1 = 0;
	long x2 = x1 + u1;
	long y2 = y1 + v1;
	long x3 = x1 + u2;
	long y3 = y1 + v2;
	
	[x1, y1, x2, y2, x3, y3].map!(to!string).array.join(" ").writeln;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;;
    cin >> s;

    if(s=="SAT")
	cout << 1 << endl;
    else if(s=="SUN")
	cout << 7 << endl;
    else if(s=="MON")
	cout << 6 << endl;
    else if(s=="TUE")
	cout << 5 << endl;
    else if(s=="WED")
	cout << 4 << endl;
    else if(s=="THU")
	cout << 3 << endl;
    else if(s=="FRI")
	cout << 2 << endl;
}



Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

m,d = inp
ans = 0
(1..m).each do |mi|
  (1..d).each do |di|
    if((di/10) >1 and (di%10) >1 and (di/10)*(di%10) == mi)
      ans += 1 
    end
  end
end
p ans

Measured memory_bytes: 1788
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let mut dp = vec![n+10; n+10];
    let mut edges = vec![1];

    for &k in [6, 9].iter() {
        let mut base = k;
        loop {
            edges.push(base);
            base *= k;
            if base >= dp.len() {
                break;
            }
        }
    }

    dp[0] = 0;
    for i in 1..dp.len() {
        for &e in edges.iter() {
            if i >= e {
                dp[i] = min(dp[i], dp[i-e]+1);
            }
        }
    }

    println!("{}", dp[n]);
}


Measured memory_bytes: 4352
#include<iostream>
int main()
{
  int age = 0;
  std::cin >> age;
  switch(age){
    case 1:
      std::cout << "Hello World" << std::endl;
      break;
    case 2:
      int a,b;
      std::cin >> a >> b;
      std::cout << a + b << std::endl;
      break;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>
#include <cassert>
using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n){
        cin >> a[i];
    }
    vector<int> b(n);
    b[n-1] = 1;
    for(int i=n-2;i>=0;i--){
        if(a[i]>=a[i+1]){
            b[i] = b[i+1]+1;
        }else{
            b[i] = 1;
        }
    }
    cout << *max_element(b.begin(),b.end()) -1<< endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>
using namespace std;

int main()
{
    long long k, a, b;
    cin >> k >> a >> b;
    if (b - a <= 2 || k <= a)
    {
        cout << k + 1 << endl;
    }
    else
    {
        long long ans = 0;
        k += 1;
        k -= a;
        k -= 2;
        ans += b;
        if (k % 2 == 0)
        {
            ans += k / 2 * (b - a);
        }
        else
        {
            ans += k / 2 * (b - a) + 1;
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
    ll n, k;
    cin >> n >> k;
    vector<int> nx(n);
    for(int i = 0; i < n; i++){
        cin >> nx[i];
        nx[i]--;
    }
    vector<int> ord(n, -1), s;
    int u = 0;
    while(ord[u] == -1){
        ord[u] = s.size();
        s.push_back(u);
        u = nx[u];
    }
    int loop = s.size() - ord[u];
    if(k <= ord[u]){
        cout << s[k]+1 << endl;
    } else {
        cout << s[(k-ord[u]) % loop + ord[u]]+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 5864
x,y = map(int,input().split())
minimum = 10000000
table = [i for i in range(y,y+x)]

table1 = list(filter(lambda x: x>=0,table)) + [1000000000]
table2 = list(filter(lambda x: x<0,table))[::-1] + [-1000000]

if table1[0] > table2[0] * -1:
    print(sum(table) - table2[0])
else:
    print(sum(table) - table1[0])




Measured memory_bytes: 3060
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
a,b = [list(i) for i in zip(*l)]
j = 0
p = 0

while m > 0:
    if b[j] <= m:
        p += a[j] * b[j]
        m -= b[j]
        j += 1
    else:
        p += a[j] * m
        m = 0

print(p)

Measured memory_bytes: 35616
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int64;
const int64 INF = 1LL << 58;
typedef pair< int64, int > Pi;
 
struct edge
{
  int to, cost;
};
 
vector< edge > g[100001];
int64 dp[100001][10];
 
int main()
{
  int N, M, R, Q;
  cin >> N >> M >> R >> Q;
 
 
  for(int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    g[b].push_back((edge) {a, c});
  }
 
  fill_n(*dp, 100001 * 10, INF);
  priority_queue< Pi, vector< Pi >, greater< Pi > > que[11];
  for(int i = 1; i <= N; i++) {
    que[i % R].emplace(0, i);
    dp[i][i % R] = 0;
  }
  for(int i = 0; i < R; i++) {
    while(!que[i].empty()) {
      auto p = que[i].top();
      que[i].pop();
      if(p.first > dp[p.second][i]) continue;
      for(auto &e : g[p.second]) {
        if(p.first + e.cost >= dp[e.to][i]) continue;
        dp[e.to][i] = p.first + e.cost;
        que[i].emplace(dp[e.to][i], e.to);
      }
    }
  }
 
  int64 ret = 0;
  while(Q--) {
    int64 X, Y, Z;
    cin >> X >> Y >> Z;
    int64 cost = 0;
    for(int i = 0; i < R; i++) {
      cost = max(cost, Z - dp[X][i] - dp[Y][i]);
    }
    ret += cost;
  }
  cout << ret << endl;
}

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


int main()
{
    string S;
    cin >> S;


    long ans = 0, numB = 0;
    for( int i = 0; i < (int) S.size(); ++i ){
        if( S[i] == 'B' ) ++numB;
        if( S[i] == 'W' ) ans += numB;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

// Author:: Subash Singha Roy
// Institution:: Jalpaiguri Government Engineering College

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (int)(1e9+7)
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=a-1;i>=b;i--)
#define tc(t) int t;cin >>t;while(t--)
#define pb(i) push_back(i)
#define rr return 0
#define mp make_pair
#define pr  pair <ll,ll> 
#define ff first
#define ss second
#define inf 999999999999999999
ll mult(ll a,ll b, ll p=mod){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=mod){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = mod) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = mod) {return fpow(a, p - 2, p);}
bool sa(const pair<int,int> &a,const pair<int,int> &b){return (a.second<b.second);}
bool fd(const pair<int,int> &a,const pair<int,int> &b){return (a.first>b.first);}
bool sd(const pair<int,int> &a,const pair<int,int> &b){return (a.second>b.second);}

int main(){
fio
ll n;
cin>>n;
ll h[n+5];
fr(i,0,n){
    cin>>h[i];
}
ll dp[n+5][3];
dp[0][0]=0;
dp[0][1]=0;
dp[1][0]=abs(h[0]-h[1]);
dp[1][1]=inf;
fr(i,2,n){
    dp[i][0]=min(dp[i-1][0],dp[i-1][1])+(abs)(h[i]-h[i-1]);
    dp[i][1]=min(dp[i-2][1],dp[i-2][0])+(abs)(h[i]-h[i-2]);
}
cout<<min(dp[n-1][1],dp[n-1][0]);
rr;}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    ll n,d;
    cin >> n >> d;

    ll sum=0;
    ll x, y;
    REP(i,n){
        cin >> x >> y;
        if (x*x + y*y <= d*d)sum++;
    }
    cout << sum << endl;

}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	string a,b,c;
	cin>>n>>a>>b>>c;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==b[i]&&b[i]==c[i])ans+=0;
		else if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i])ans+=2;
		else ans+=1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
# include <bits/stdc++.h>
using namespace std;
int main() {
    string N;
    std::cin >> N;
    int sum=0;
    int M=N.length();
    for (int i = 0; i < M; i++) {
        sum+=(int)N[i]-'0';
    }
    if(M>1){
        if(N[0]-'0'==1 && N[1]-'0'==0){
            sum+=9;
        }
    }
    std::cout << sum << std::endl;
    return 0;
}



Measured memory_bytes: 256