akhauriyash/Code-Regression huggingface dataset:
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    
    int cnt = 0;
    while(1)
    {
        for (int i = n-1; n >= 0; --i)
        {
            if (h[i] != 0) break;
            h.pop_back();
            --n;
        }
        
        if (n<=0) break;
        ++cnt;
        
        for (int i = n-1; n >= 0; --i)
        {
            if (h[i] == 0)
            {
                break;
            }
            --h[i];
        }
    }
    
    cout << cnt << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int l2[210000];

int main(){
  int N,count1=0,count2=0,count4=0,data;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>data;
    if(data%4==0) count4++;
    else if(data%2==0) count2++;
    else count1++;
  }
  count2%=2;
  if(count4+1>=count1+count2) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e18;
const int inf=2e9;
const ll MOD=1000000007;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};

int main(){
    char a,b;cin>>a>>b;
    string S,T;
    int p=a-'0',q=b-'0';
    rep(i,p)S+=to_string(q);
    rep(i,q)T+=to_string(p);
    cout<<min(S,T)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int main(){
    int n,m;cin>>n>>m;
    int pushes[n];
    fore(i,0,n){
        cin>>pushes[i];
    }
    ll ans = m;
    fore(i,0,n-1){
        ll temp = pushes[i+1] - pushes[i];
        if(temp<=m){
            ans += temp;
        }else{
            ans += m;
        }   
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
main(){
  int w,n;
  while(1){
    scanf("%d",&w);
    if(w==-1) break;

    n=1150;

    while(w>0){

      if(w>30){
	n+=160;
      }
      else if(w>20){
	n+=140;
      }
      else if(w>10){
	n+=125;
      }
      w--;

    }

    printf("%d\n",4280-n);


  }
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<ll> l(100);
    l[0] = 2; l[1] = 1;
    rep(i, 2, 100) l[i] = l[i-1] + l[i-2];
    cout << l[n] << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, l;
    cin >> n >> l;
    int sum = 0;
    int minTaste = 10000;
    bool isPlus = true;
    for(int i=0; i<n; i++){
        sum += (l+i);
        if(minTaste > abs(l+i)){
            minTaste = abs(l+i);
            if(l+i>=0){
                isPlus = true;
            }else{
                isPlus = false;
            }
        }
    }
    if(isPlus){
        cout << sum-minTaste << endl;
    }else{
        cout << sum+minTaste << endl;
    }
    return 0;
}

Measured memory_bytes: 256
s = input()
l = []
for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'T' or s[i] == 'G' or s[i] == 'C':
        l.append(1)
    else:
        l.append(0)
tmp = 0
counter = []
for i in range(len(l)):
    if l[i] == 0:
        counter.append(tmp)
        tmp = 0
    else:
        if i == len(l) - 1:
            tmp += 1
            counter.append(tmp)
        else:
            tmp += 1

print(max(counter))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int n;
vector<string> s;
vector<int> p;
bool hikaku(const int& i, const int& j){
	return (s[i] == s[j]) ? (p[i] > p[j]) : (s[i] < s[j]);
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin >> n;
	s = vector<string>(n);
	p = vector<int>(n); 
	vector<int> ord(n);
	iota(all(ord), 0);

	rep(i,n){
		cin >> s[i] >> p[i];
	}
	sort(all(ord), hikaku);
	rep(i,n){
		cout << ord[i]+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int N;
ll L;
int Doub[40][100005];
vector<ll> x(100005);

void prepare() {
  int index;
  for(int i=0;i<N;++i) {
    index = upper_bound(x.begin(), x.end(), x[i]+L)-x.begin()-1;
    Doub[0][i] = index;
  }
  for(int i=1;i<40;++i) {
    for(int j=0;j<N;++j) {
      Doub[i][j] = Doub[i-1][Doub[i-1][j]];
    }
  }
}

int solve(int a, int b) {
  int ans = 0;
  int two;
  int tmp;
  while(a<b) {
    two = 1;
    tmp = 0;
    while(Doub[tmp+1][a]<b) {
      two *= 2;
      tmp++;
    }
    ans += two;
    a = Doub[tmp][a];
  }
  return ans;
}

int main() {
  cin>>N;
  for(int i=0;i<100005;++i) x[i] = big;
  for(int i=0;i<N;++i) cin>>x[i];
  cin>>L;
  prepare();

  int Q;
  cin>>Q;
  int a, b;
  int ans[Q];
  for(int i=0;i<Q;++i) {
    cin>>a>>b;
    a--;
    b--;
    if(a>b) swap(a, b);
    ans[i] = solve(a, b);
  }
  for(int i=0;i<Q;++i) cout<<ans[i]<<endl;
}



Measured memory_bytes: 20092
use proconio::{fastout, input};
use std::collections::BTreeSet;

#[fastout]
fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
    }

    let abc: BTreeSet<_> = [a, b, c].iter().cloned().collect();
    let ans = if abc.len() == 2 { "Yes" } else { "No" };

    println!("{}", ans);
}


Measured memory_bytes: 2108
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  ll ans=1;
  map<ll,ll> mp;
  mp[0]=3;
  ll N; cin >> N;
  vector<ll> a(N);
  rep(i,N) cin >> a[i];
  rep(i,N){
    ans*=mp[a[i]];
    ans%=MOD;
    mp[a[i]]--; mp[a[i]+1]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7296
a,b,c,d = map(int, input().split())
if a<=c:
  if b<=c:
    answer = 0
  else:
    if d<=b:
      answer = d-c
    else:
      answer = b-c
else:
  if d<=a:
    answer = 0
  else:
    if d<=b:
      answer = d-a
    else:
      answer = b-a
print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define D(...) fprintf(stderr,__VA_ARGS__)
#define int long long
#define LL long long
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef pair<int,int>PII;typedef vector<int>VI;typedef vector<PII>VII;
template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
const int N=100005;
int n,a[N],pw[N],lim[N];
signed main(){
	pw[0]=1;for(int i=1;i<N;++i)if(pw[i-1]>1e15)pw[i]=pw[i-1];else pw[i]=pw[i-1]*2;
	rd(n);
	lim[0]=1;
	rep(i,0,n){
		rd(a[i]);
		if(a[i]>pw[i]){
			puts("-1");
			return 0;
		}
		if(i){
			lim[i]=min((int)1e15,lim[i-1]*2-a[i]);
			if(lim[i]<0){
				puts("-1");
				return 0;
			}
		}
	}
	int mx=0,sum=0;
	per(i,n,0){
		if(a[i]+(mx+1)/2>pw[i]){
			puts("-1");
			return 0;
		}
		mx=min(mx,lim[i])+a[i];
		sum+=mx;
	}
	pt(sum,'\n');
	return 0;
}

Measured memory_bytes: 5936
#include <iostream>//bit DP
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
priority_queue<long>p;
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    long a;cin>>a;
    p.push(a);
  }
  long ans=0;
  if(n%2==0){
    ans+=p.top();
    p.pop();
    for(int j=1;j<=n/2-1;j++){
      ans+=2*p.top();
      p.pop();
    }
  }else{
    ans+=p.top();
    p.pop();
    for(int j=1;j<=n/2-1;j++){
      ans+=2*p.top();
      p.pop();
    }
    ans+=p.top();
  }
  cout<<ans<<endl;
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

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

const ll MOD = 998244353;

vi graph[200007];
int a[200007];
int ans[2000007];

vi v;

void dfs(int i, int pai=-1){

	auto p = lower_bound(all(v), a[i]);
	int idx = distance(v.begin(), p);
	bool ins = false;
	int aux = -1;
	if(p == v.end()){
		v.PB(a[i]);
		ins = true;
	}else{
		aux = v[idx];
		v[idx] = a[i];
	}

	ans[i] = v.size();
	for(auto& k : graph[i]){
		if(k != pai){
			dfs(k, i);
		}
	}

	if(ins) v.pop_back();
	else v[idx] = aux;
}

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

	int n; cin >> n;
	FOR(i, n) cin >> a[i];

	FOR(i, n-1){
		int a, b; cin >> a >> b;
		a--; b--;
		graph[a].PB(b);
		graph[b].PB(a);
	}

	dfs(0);

	FOR(i, n)
		cout << ans[i] << '\n';

 	return 0;
}

Measured memory_bytes: 30384
// ConsoleApplication2.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
	string s[3],S;
	//s[1] = "Sunny";
	//s[2] = "Cloudy";
	//s[3] = "Rainy";
	cin >> S;
	if (S == "Sunny")
	{
		cout << "Cloudy";
	}
	else if (S == "Cloudy")
	{
		cout << "Rainy";
	}
	else if (S == "Rainy")
	{
		cout << "Sunny";
	}
	return 0;
}


//int CalNP(vector <int> a, int pos, int len)
//{
//	int value = a[pos];
//	for (int i = 1; i < len; i++)
//	{
//		value *= a[pos + i];
//	}
//	return value;
//}
// 
//int main()
//{
//	int n;
//	int temp;
//	int N = 0;
//	int P = 0;
//	vector <int> a;
//	cin >> n;
//	for (int i = 0; i < n; i++)
//	{
//		cin >> temp;
//		if (temp < 0)
//		{
//			a.push_back(-1);
//		}
//		else
//		{
//			a.push_back(1);
//		}
//	}
//	for (int len = 1; len <= n; len++)//len
//	{
//		for (int j = 0; (j + len) <= n; j++)
//		{
//			if (CalNP(a, j, len)>0)
//			{
//				P++;
//			}
//			else
//			{
//				N++;
//			}
//		}
//	}
//
//	cout << N<<endl;
//	cout << P;
//}


//int main()
//{
//	int a1, a2, k1, k2, n;
//
//	cin >> a1;
//	cin >> a2;
//	cin >> k1;
//	cin >> k2;
//	cin >> n;
//
//	//先比较k1和k2的大小
//	if (k1 <= k2)
//	{
//		if(k1)
//
//	}
//
//
//	cout << "Hello World!\n";
//}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[100];
const int maxn =2e5+10;
int a[maxn],b[maxn],c[maxn];
#define LL long long
map<int,int>mp;
int main(){
    int n;
    while(~scanf("%d",&n)){
        mp.clear();
        map<int,int>::iterator it;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            b[i] = a[i]+i;
            c[i] = i - a[i];
            it = mp.find(c[i]);
            if(it==mp.end()){
                mp[c[i]]=1;
            }else{
                mp[c[i]]+=1;
            }

        }
        LL ans=0;
        for(int i=1;i<=n;i++){
            it = mp.find(b[i]);
            if(it==mp.end()){
                continue;
            }
            ans+=mp[b[i]];
        }
        printf("%lld\n",ans);

    }
    return 0;
}




Measured memory_bytes: 14748
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc062.contest.atcoder.jp/tasks/arc062_b>
問題文============================================================
 シカのAtCoDeerくんは友達のTopCoDeerくんとあるゲームをして対戦しています。
 このゲームは N ターンからなります。各ターンではそれぞれのプレイヤーはじゃんけんのグーかパーを出します。
 ただし、各プレイヤーは次の条件を満たす必要があります。
 
 (※) 各ターンの後で、(今までにパーを出した回数)≦(今までにグーを出した回数)　を満たす
 
 このゲームでの各プレイヤーの得点は、(勝ったターンの数) − (負けたターンの数) です。
 AtCoDeerくんは特殊能力を持っているので、
 ゲームが始まる前にTopCoDeerくんの出す N ターンの手を全て知ることが出来ました。
 AtCoDeerくんの各ターンでの手を決めて、AtCoDeerくんの得点を最大化してください。
 TopCoDeerくんの出す手の情報は文字列 s で与えられます。
 s の i(1≦i≦N) 文字目が gのときは i ターン目でTopCoDeerくんがグーを出すことを、
 pのときはパーを出すことを表します。
=================================================================

解説=============================================================

 良く考えれば　gpgpgp...と交互に出すのが最適だとわかる
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    int ans = 0;
    for(int i = 0; i < (int)s.length();i++){
        if(i%2 == 0){
            if(s[i] == 'p') ans--;
        }else{
            if(s[i] == 'g') ans++;
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
size = int(input())
array =  list(map(int, input().split()))
dp = [0]* size
dp[1]=  dp[0] + abs(array[1] - array[0]) 
for i in range(2,size):
	dp[i] = min(
	dp[i-1] + abs(array[i] - array[i-1]),
	dp[i-2] + abs( array[i] - array[i-2] )
	)
print(dp[-1])
		


Measured memory_bytes: 13928
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => { content += buf; })
process.stdin.on('end', () => {
  const [a, b, c] = content.split(' ').map(n => parseInt(n, 10));
  console.log(a < b && b < c ? 'Yes' : 'No');
});


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

int main() {
  ll x, y;
  cin >> x >> y;

  ll ans;
  if (x % y == 0) {
    // xの倍数はすべてyの倍数となってしまう。
    ans = -1;
  } else {
    ans = x;
  }

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


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

namespace AtTest.ABC_140
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] aArray = ReadInts();
            int[] bArray = ReadInts();
            int[] cArray = ReadInts();
            int res = 0;
            for(int i = 0; i < n; i++)
            {
                res += bArray[aArray[i] - 1];
                if (i > 0 && aArray[i] == aArray[i - 1] + 1)
                {
                    res += cArray[aArray[i - 1] - 1];
                }
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll K, X, Y;
vector<l_l> ans;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> K>> X >> Y;
    if((!(K & 1)) && (abs(X + Y) & 1)) {
        cout << -1 << endl;
        return 0;
    }
    ll Z = X + Y;
    Y = X - Y;
    X = Z;
    ll x = 0;
    ll y = 0;
    while(x != X || y != Y) {
        ll dx = X - x;
        ll dy = Y - y;
        dx = abs(dx);
        dy = abs(dy);
        ll nowdx, nowdy;
        if(dx == K && dy <= K) {
            nowdx = K;
            nowdy = dy;
        } else if(dy == K && dx <= K) {
            nowdx = dx;
            nowdy = dy;
        } else if(dx >= dy && dx >= K) {
            nowdx = K;
            nowdy = dy - K;
            chmin(nowdy, K);
            if((abs(nowdx + nowdy) % 2 == 1)) {
                nowdy--;
            }
        } else if(dy >= dx && dy >= K) {
            nowdy = K;
            nowdx = dx - K;
            chmin(nowdx, K);
            if((abs(nowdx + nowdy) % 2 == 1)) {
                nowdx--;
            }
        } else {
            nowdx = K;
            nowdy = dy - K;
            if((abs(nowdx + nowdy) % 2 == 1)) {
                nowdy++;
            }
        }
        if(X - x != dx) {
            nowdx *= -1;
        }
        if(Y - y != dy) {
            nowdy *= -1;
        }
        x += nowdx;
        y += nowdy;
        ans.push_back({x, y});
        //cerr << x << " " << y << endl;
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++) {
        int x = (ans[i].first + ans[i].second) / 2;
        int y = (ans[i].first - ans[i].second) / 2;
        cout << x << " " << y << endl;
    }
    return 0;
}


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


int main()
{
    string s;
    cin >> s;
    int ans = 1;
    if(s == "SSS") ans = 0;
    if(s == "SRR" || s == "RRS") ans = 2;
    if(s == "RRR") ans = 3;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3616
N, K = gets.split.map(&:to_i)
P = gets.split.map { |a| (a.to_f + 1) / 2 }
cusum = [0]
max_sum = 0

N.times do |i|
  cusum.push(cusum[i] + P[i])
end

(N - K + 1).times do |j|
  max_sum = [max_sum, cusum[j + K] - cusum[j]].max
end

p max_sum

Measured memory_bytes: 20356
#include <bits/stdc++.h>
#define N 100001
#define INF 1e9
using namespace std;
typedef pair<int,int> P;
int n,m,A[N],Sum[20][N];


int cost(int idx,int i){return Sum[i][n]-(Sum[i][idx+Sum[i][n]]-Sum[i][idx]);}

int mem[1<<20],used[1<<20];
int dfs(int sta,int idx){
  if(sta==(1<<m)-1)return 0;
  if(used[sta]++) return mem[sta];
  int &res=mem[sta]=INF;
  for(int i=0;i<m;i++){
    if((sta>>i)&1)continue;
    res=min(res,cost(idx,i)+dfs(sta|(1<<i),idx+Sum[i][n]));
  }
  return res;
}

int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>A[i],A[i]--;

  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
      Sum[i][j+1]+=Sum[i][j]+(A[j]==i);
  cout <<dfs(0,0)<<endl;
}

Measured memory_bytes: 19404
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

void solve() {
    int n;
    string s = "";
    string cor_ans = "";
    char c;
    int cnt=0, st = 0;
    cin >> n;
    for (int i =0; i < n; ++i) {
        cin >> c;
        if (c == '(') {
            ++st;
        } else if (c == ')') {
            --st;
        }
        if (st < 0) {
            ++cnt;
            st = 0;
        }
        s += c;
    }
    for (; st > 0; --st) {
        s += ')';
    }
    for (; cnt > 0; --cnt) {
        cor_ans += '(';
    }
    cor_ans += s;
    cout << cor_ans;
}

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


Measured memory_bytes: 3012
#include <stdio.h>
int main()
{
    int d,n,x,sum=0,count,result,c,swap;
    scanf("%d%d",&n,&x);
    int a[n];
    for(d=0;d<n;d++){
        scanf("%d",&a[d]);
     sum=sum+a[d];
    }
    result=x-sum;
    for (c = 0 ; c < ( n - 1 ); c++)
  {
    for (d = 0 ; d < n - c - 1; d++)
    {
      if (a[d] > a[d+1])
      {
        swap   = a[d];
        a[d]   = a[d+1];
        a[d+1] = swap;
      }
    }

  }
     count=result/a[0];
    printf("%d\n",count+n);
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstdlib>
inline int getint() {
	register char ch;
	while(!isdigit(ch=getchar()));
	register int x=ch^'0';
	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
	return x;
}
const int N=100001;
std::vector<int> e[N];
inline void add_edge(const int &u,const int &v) {
	e[u].push_back(v);
	e[v].push_back(u);
}
inline bool dfs(const int &x,const int &par) {
	int ret=0;
	for(unsigned i=0;i<e[x].size();i++) {
		const int &y=e[x][i];
		if(y==par) continue;
		ret+=dfs(y,x);
		if(ret==2) {
			puts("First");
			exit(0);
		}
	}
	return !ret;
}
int main() {
	const int n=getint();
	for(register int i=1;i<n;i++) {
		add_edge(getint(),getint());
	}
	puts(dfs(1,0)?"First":"Second");
	return 0;
}

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

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

    string S;
    cin >> S;

    bool alldif = true;
    for(size_t i = 0; i < S.size(); ++i){
        for(size_t j = 0; j < S.size(); ++j){
            if(i != j && S[i] == S[j]){
                alldif = false;
                break;
            }
        }
        if(!alldif){
            break;
        }
    }
    cout << (alldif ? "yes" : "no") << endl;

    return 0;
}

Measured memory_bytes: 256
/*input
2
ip cc
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	int a,b;
	cin>>a>>b;
	if(a%2==b%2) cout<<(a+b)/2<<'\n';
	else cout<<"IMPOSSIBLE";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{   int n;
    scanf("%d",&n);
    int a[n],nodd=0,neven=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]%2==0)neven++;
        else nodd++;
    }
        neven+=nodd/2;
        nodd=nodd%2;
        
    while(neven>1){
        neven=(neven+1)/2;
    }
    if(nodd+neven==1)printf("YES");
    else printf("NO");
    
    

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[2000005];
ll k;
ll vis[2000005],step[2000005];
ll r1,r2;
int st;
void dfs(int now,ll s) {
	if(vis[now]) {
		st=now;
		r2=s-step[now];
		r1=step[now];
		return;
	}
	vis[now]++;
	step[now]=s;
	dfs(a[now],s+1);
}
void solve(int now,ll rem) {
	if(rem==0) {
		cout<<now;
		return;
	}
	solve(a[now],rem-1);
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>k;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	dfs(1,0);
	if(k>=r1) {
		k=(k-r1)%r2;
		solve(st,k);
	} else solve(1,k);
	return 0;
}

Measured memory_bytes: 7480
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <list>
using namespace::std;


int main(){
	long int q, h, s, d; cin >> q >> h >> s >> d;
	long int n; cin >> n;

	long int ans = 0;

	ans += n/2*min({8*q, 4*h, 2*s, d});
	n = n%2;

	ans += n*min({4*q, 2*h, s});
	n = n-1;

	cout << ans;


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

public class Main{



  public static OutputStream out=new BufferedOutputStream(System.out);
  static Scanner sc=new Scanner(System.in);
  static long mod=1000000007l;
  static int INF=10000000;
  static int[] rr=new int[]{1, 0, -1, 0};                                 //rook row move
  static int[] rc=new int[]{0, 1, 0, -1};                                 //rook col move

  //nl-->neew line; //l-->line;  //arp-->array print;  //arpnl-->array print new line
  public static void nl(Object o) throws IOException{out.write((o+"\n").getBytes()); }
  public static void l(Object o) throws IOException{out.write((o+"").getBytes());}
  public static void arp(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+" ").getBytes()); out.write(("\n").getBytes());}
  public static void arpnl(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+"\n").getBytes());}
  public static void scanl(long[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextLong();}
  public static void scani(int[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextInt();}
  public static void scan2D(int[][] a,int n,int m) {for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=sc.nextInt();}
  //static variables

  //


  public static void main(String[] args) throws IOException{
    long sttm=System.currentTimeMillis();
    long mod=100000l;

    long a=sc.nextLong(), b=sc.nextLong();
    long c=sc.nextLong(), d=sc.nextLong();
    long ans=Math.max(a*c, Math.max(a*d, Math.max(b*c, b*d)));
    nl(ans);

    out.flush();
  }

}

class Pair{
  int x; int y;
  Pair(int x,int y){
    this.x=x;
    this.y=y;
  }
}


Measured memory_bytes: 38588
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N =  int(sys.stdin.readline())
print(N ** 3)

Measured memory_bytes: 66028
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){ 
  int n,m;
  cin>>n>>m;
  n--;m--;
  cout<<n*m<<endl;
  return 0;
}




Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    string s; cin >> s;
    rep(i,0,s.length()) if(i % 2 == 0) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = LIST()

if sum(A) > N:
    print(-1)
else:
    print(N - sum(A))


Measured memory_bytes: 11392
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int n;
int gcd(int e,int f)
{
	if(f==0) return e;
	else return gcd(f,e%f);
}
int main()
{
	cin>>n;
	vector<int>x;
	int a;
	cin>>a;
	x.pb(a);
	for(int i=0;i<n;i++)
	{
		cin>>a;
		x.pb(a);
	}
	sort(x.begin(),x.end());
	int c[n];
	for(int i=0;i<n;i++)
	c[i]=x[i+1]-x[i];
	int ch=c[0];
	for(int i=1;i<n;i++)
	ch=gcd(max(ch,c[i]),min(ch,c[i]));
	cout<<ch;
	return 0;
} 

Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
	if(2*c>=b-a+1){
    for(int i=a;i<=b;i++) cout<<i<<"\n";
  }
  else{
    for(int i=a;i<a+c;i++) cout<<i<<"\n";
    for(int i=b-c+1;i<=b;i++) cout<<i<<"\n";
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	lli n, a, b, c, d, ans;
	scanf("%lld%lld%lld", &n, &a, &b);
	if(a==0) ans = 0;
	c= n/(a+b);
	d = n%(a+b);
	if(0<=d && d<a) ans = c*a+d;
	if(a<d && d<a+b) ans = c*a+a;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;
using ll = long long;

void ABC073D()
{
	int N, M, R;
	cin >> N >> M >> R;
	vector<int>ri(R);
	for (auto& x : ri)
		cin >> x;
	transform(ri.cbegin(), ri.cend(), ri.begin(), [](int x) {return x - 1; });
	sort(ri.begin(), ri.end());

	struct Edge	{
		int to;
		int dist;
	};

	vector<vector<Edge> > graph(N);
	for (int i = 0; i < M; ++i)
	{
		int A, B, C;
		cin >> A >> B >> C;
		graph[A-1].push_back(Edge{ B-1, C });
		graph[B-1].push_back(Edge{ A-1, C });
	}

	vector<vector<ll> > distR(R, vector<ll>(R));
	for (int i = 0; i < R; ++i)
	{
		priority_queue<pair<ll, int> > qu;
		vector<ll> dVec(N,1000000000000);
		ll d = 0;
		dVec[ri[i]] = 0;
		qu.push(make_pair(d, ri[i]));
		while (!qu.empty())
		{
			auto p = qu.top();
			qu.pop();
			ll theDist = p.first;
			int theVertex = p.second;
			for (auto& x : graph[theVertex])
			{
				int to = x.to;
				ll newDist = theDist + x.dist;
				if (newDist < dVec[to])
				{
					dVec[to] = newDist;
					qu.push(make_pair(newDist, to));
				}
			}
		}
		for (int j = 0; j < i; ++j)
		{
			distR[i][j] = dVec[ri[j]];
			distR[j][i] = dVec[ri[j]];
		}
		distR[i][i] = 0;
	}

	ll minDist = 1000000000000;

	vector<int> v(R);
	for (int i = 0; i < R; ++i)
		v[i] = i;
	do
	{
		ll d = 0;
		for (int i = 1; i < R; ++i)
			d += distR[v[i]][v[i - 1]];
		minDist = min(minDist, d);
	} while (next_permutation(v.begin(), v.end()));
	cout << minDist << endl;
}

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

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

int a1,a2,a3,m1,m2,m3;
int count,x,y,z,sx,sy,sz;

long long int lcm(int a,int b){
	long long int xx,yy,zz;
	if(a>b){xx=a;yy=b;}else{xx=b;yy=a;}
	while(yy>0){
		zz=xx%yy;
		xx=yy;
		yy=zz;
	}
	return xx*(a/xx)*(b/xx);
}

int main(){
	while(scanf("%d %d %d %d %d %d",&a1,&m1,&a2,&m2,&a3,&m3)*a1*m1){
		count=0;x=1;y=1;z=1;sx=0;sy=0;sz=0;
		while(sx*sy*sz==0){
			count++;
			x=(x*a1)%m1;
			y=(y*a2)%m2;
			z=(z*a3)%m3;
			if(sx==0 && x==1)sx=count;
			if(sy==0 && y==1)sy=count;
			if(sz==0 && z==1)sz=count;
		}

		printf("%lld\n",lcm(sx,lcm(sy,sz)));
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
template<typename T> 
struct BIT2D{
  vector<vector<T> > bit;
  int n,m;
  //1-indexed
  BIT2D(){init(-1,-1);}
  BIT2D(int n_,int m_){init(n_,m_);}
  void init(int n_,int m_){
    n=n_;
    m=m_;
    for(vector<T> &v:bit) v.clear();
    bit.clear();
    bit.resize(n+1,vector<T>(m+1));
  }
  T sum(int i,int j){
    T s=0;
    for(int x=i;x>0;x-=(x&-x))
      for(int y=j;y>0;y-=(y&-y))
	s+=bit[x][y];
    return s;
  }
  void add(int i,int j,T a){
    if(i==0||j==0) return;
    for(int x=i;x<=n;x+=(x&-x))
      for(int y=j;y<=m;y+=(y&-y))
	bit[x][y]+=a;
  }
  // (x1,x2] * (y1,y2];
  T sum(int x1,int y1,int x2,int y2){
    return sum(x1,y1)-sum(x1,y2)-sum(x2,y1)+sum(x2,y2);
  }
};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int h,w,t,q;
  cin>>h>>w>>t>>q;
  BIT2D<int> beet(h+100,w+100);
  BIT2D<int> ushi(h+100,w+100);
  typedef pair<int,int> P;
  typedef pair<int,P> PP;
  queue<PP> qq; 
  for(int i=0;i<q;i++){
    int a,c,x1,y1;
    cin>>a>>c>>x1>>y1;
    while(!qq.empty()&&qq.front().first<=a){
      P p=qq.front().second;qq.pop();
      int x=p.first,y=p.second;
      assert(beet.sum(x-1,y-1,x,y)==1);
      beet.add(x,y,-1);
      assert(ushi.sum(x-1,y-1,x,y)==0);
      ushi.add(x,y,1);
    }
    if(c==0){
      assert(beet.sum(x1-1,y1-1,x1,y1)==0);
      beet.add(x1,y1,1);
      qq.push(PP(a+t,P(x1,y1)));
    }
    if(c==1){
      if(ushi.sum(x1-1,y1-1,x1,y1)==0) continue;
      ushi.add(x1,y1,-1);
    }
    if(c==2){
      int x2,y2;
      cin>>x2>>y2;
      x1--;y1--;
      cout<<ushi.sum(x1,y1,x2,y2)<<" "<<beet.sum(x1,y1,x2,y2)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 38752
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
int main(){
	char ch[110];scanf("%s",ch);
	int n=strlen(ch);for(int i=0;i<n;i++) if(ch[i]=='7') return printf("Yes\n"),0;
	printf("No\n");
}

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

int main(){
  int n;
  int count = 0;
  cin >> n;
  vector<int> d(n);
  for (int tsumugi = 0; tsumugi < n; tsumugi++)
    cin >> d[tsumugi];
  
  for (int kaori = 1; kaori <= 100; kaori++){
    for (int matsuri = 0; matsuri < n; matsuri++){
      if (d[matsuri] == kaori){
        count++;
        matsuri += 100;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll N, M;
vector<ll> g[MAX*2];

int main(void) {
    ll i, j;
    cin >> N >> M;
    
    for(i=0; i<M; i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    
    for(i=0; i<g[0].size(); i++) {
        ll u=g[0][i];
        for(j=0; j<g[u].size(); j++) {
            if(g[u][j]==N-1) {
                puts("POSSIBLE");
                return 0;
            }
        }
    }
    
    puts("IMPOSSIBLE");
    
    
    
}


Measured memory_bytes: 12776
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int x; cin >> x;

    int m = x / 100;

    REP(i, m + 1) {
        int n = x - i * 100;

        if (5 * i >= n) {
            cout << 1 << endl;
            return 0;
        }
    }

    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int main(void) {

	int N, result = 100000;
	cin >> N;

	for (int i = 0; i <= N; i++) {
		int res = 0;

		int t = i;

		while (t != 0) {
			res += t % 6;
			t /= 6;
		}

		t = N - i;


		while (t != 0) {
			res += t % 9;
			t /= 9;
		}

		CHMIN(result,res);

	}

	cout << result << endl;

	return 0;
}


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

		// 整数の入力
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[][] sk = new int[10][10];
		int[] k = new int[m];
		int[] p = new int[m];

		for(int i=0;i<m;i++){
			int k2 = sc.nextInt();
			k[i] = k2;
			for(int j=0;j<k2;j++){
				sk[i][j]=sc.nextInt();
			}
		}

		for(int s=0;s<m;s++){
			p[s]=sc.nextInt();
		}

		int num = (int)(Math.pow(2,n));
		int[] sw = new int[n];
		int ans = 0;

		for(int t=0;t<num;t++){
			int nnn = t;
			for(int u=0;u<n;u++){	//スイッチのオンオフ
				sw[u]=nnn%2;
				nnn/=2;
			}
			boolean flg = true;
			for(int v=0;v<m;v++){	//電球
				int count = 0;
				for(int w=0;w<k[v];w++){	//対応スイッチ
					count += sw[sk[v][w]-1];
				}
				if(count%2!=p[v]){
					flg=false;
					break;
				}
			}
			if(flg)ans++;
		}

		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include<stdio.h>

#include<stdlib.h>
int main()
{
 int a,b;
scanf("%d%d",&a,&b);


 if(b%a==0)
 {
   printf("%d\n",(a+b));
 }
 else
     {
          printf("%d\n",(b-a));
     }

 return 0 ;
}




Measured memory_bytes: 128
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))



# n = II()
# p = tuple(MI())
# q = tuple(MI())

# l = list(permutations(list(range(1,n+1))))
# print(abs(l.index(p)-l.index(q)))
def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a%b)
 
def lcm(a, b):
	return a // gcd(a, b) * b
 
N, M = MI()
A = LI()
A = [a//2 for a in A]


while A[0] % 2 == 0:
	for i in range(N):
		if A[i] % 2 != 0:
			print(0)
			exit()
		A[i] //= 2
	M //= 2

 
for i in range(N):
	if A[i] % 2 == 0:
		print(0)
		exit()
 
tmp_lcm = 1
for i in range(N):
	tmp_lcm = lcm(tmp_lcm, A[i])
	if M < tmp_lcm:
		print(0)
		exit()
 
print((M // tmp_lcm + 1) // 2)

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const
      noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const
      noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const
      noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const
      noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const
      noexcept {
    return x == p.x;
  }
  constexpr bool operator!=(const ModInt &p) const
      noexcept {
    return x != p.x;
  }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while(n) {
      if(n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(
      ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is,
                                       ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

vector<ModInt<>> sum(100010);

ll inv(ll x) {
  ll res = 1;
  ll N = (long long)(1e9 + 7);
  ll k = N - 2;
  ll y = x;
  while(k) {
    if(k & 1) res = (res * y) % N;
    y = (y % N * (y % N)) % N;
    k /= 2;
  }
  return res;
}

int main(void) {
  long long n;
  cin >> n;
  vector<long long> x(n + 1);
  ModInt<> ans = 0;
  ModInt<> kaijo = 1;
  for(int i = 1; i <= n - 1; i++) kaijo = kaijo * i;
  for(int i = 0; i < n; i++) cin >> x[i + 1];
  for(int i = 0; i < n; i++)
    sum[i + 1] = (sum[i] + x[i + 1]);

  for(long long p = 1; p <= n - 1; p++) {
    ModInt<> tmp = inv(n - p) * (x[n] - x[p]);
    ans = ans + tmp;
  }
  for(long long p = 1; p <= n - 2; p++) {
    ModInt<> tmp = inv(p * (p + 1));
    ModInt<> tmp1 = sum[n - 1] - sum[p];
    ModInt<> tmp2 = sum[n - 1 - p];
    ModInt<> tmp3 = tmp1 - tmp2;
    ModInt<> tmp4 = tmp * tmp3;
    ans = ans + tmp4;
  }
  ans = ans * kaijo;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC048B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
            long a = input[0];
            long b = input[1];
            long x = input[2];

            var a_count = f(a - 1, x);
            var b_count = f(b, x);

            Console.WriteLine(b_count - a_count);
        }

        static long f(long n, long x)
        {
            if (n == -1)
            {
                return 0;
            }

            return n / x + 1;
        }
    }
}


Measured memory_bytes: 13396
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if b < a:
        a,b = b,a
    if a <= c <= b:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    s = input()
    a = list(set(list(s)))
    k = II()
    for i in a:
        if s[k] != i:
            s = s.replace(i, "*")
    print(s)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39152