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

int main()
{
 	int a,b;
  	cin>>a>>b;
  	int n=0;
  if(a>b)
  {
    n+=a;
    if(a-1>b)
      n+=(a-1);
    else
      n+=b;
  }
  else
  {
    n+=b;
    if(b-1>a)
      n+=b-1;
    else
      n+=a;
  }
  cout<<n;
  
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, m;
int a[100005];

int main(void)
{
	cin >> n >> m;
	int l, r;
	for(int i = 1; i <= m; i++){
		cin >> l >> r;
		a[l]++, a[r+1]--;
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		a[i] += a[i-1];
		if(a[i] >= m) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)
func main() {
	var N,M int
	fmt.Scan(&N,&M)
	Inf := 1 << 62
	//　+-ある数は先頭が変わるので - 1,でシフトする前の段階で1ビット使ってるので -1より 62が最大
	// vertex := make([]int,N)
	a := make([]int,M)
	b := make([]int,M)
	c := make([]int,M)
	for i:= 0; i<M; i++ {
		fmt.Scan(&a[i],&b[i],&c[i])
		c[i] = -c[i]
	}
	// fmt.Println(Inf)
	dist := make([]int,N) //ここにコストをいれる　その地点にいくまでのこすとを考える
	for i:= 0; i<N; i++ {
		dist[i] = Inf//考えうる最大値を考える
	}
	dist[0] = 0 //最初は0にいるので
	for loop := 0; loop < N; loop++ {
		for i:= 0; i<M; i++ {
			if dist[a[i]-1] == Inf {
				continue
			}
			if (dist[b[i]-1] > dist[a[i]-1] + c[i]) {
				//dist[b[i]-1]の行くまでがdist[a[i]-1] + cos　よりもかかるなら最小のほうにする
				dist[b[i]-1] = dist[a[i]-1] + c[i]
			}
		}
	}
	ans := dist[N-1] //最小値が存在する場合はansが答え
	navigate := make([]bool,N)
	for loop := 0; loop < N; loop++ {
		for i:= 0; i<M; i++ {
			if dist[a[i]-1] == Inf {
				continue
			}
			if dist[b[i]-1] > dist[a[i]-1] + c[i] {
				dist[b[i]-1] = dist[a[i]-1] + c[i]
				navigate[b[i]-1] = true
			}
			if navigate[a[i]-1] == true {
				navigate[b[i]-1] = true
			}
		}
	}

	if navigate[N-1]{
		fmt.Println("inf")
	} else {
		fmt.Println(-ans)
	}

}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    n = input()

    if '9' in n:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 62840
import java.io.*;
import java.util.*;
public class Main{
	static void main() throws Exception{
		LinkedList<Integer>ans=new LinkedList<>();
		long n=sc.nextLong();
		while(n>0) {
			n--;
			ans.addFirst((int)(n%26));
			n/=26;
		}
		while(!ans.isEmpty()) {
			pw.print((char)(ans.poll()+'a'));
		}
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
		int tc=1;
//		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

Measured memory_bytes: 32968
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> P;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

/*
int main() {
	ll n; cin >> n;

	string c;

	
	while(n){
		ll r = n % 26;
		string s;
		s = (char)((int)r + 96);

		s += c;

		c = s;

		//cout << r + 96 << endl;

		n /= 26;
	}

	cout << c << endl;
	return 0;
}
*/



ll ll_max(int a, ll b) {
	ll A = (ll)a;
	if (A > b) return A;
	else return b;
}

int main() {
	ll n; cin >> n;
	string ans;

	while (n) {
		n--;
		ans = (char)((int)'a' + n % 26) + ans;
		n /= 26;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
int m[110];

int main(void)
{
    int N, X;
    cin >> N >> X;
    REP(i, N) cin >> m[i];
    ll su = 0;
    ll mi, mv = INF;
    REP(i, N) {
        su += m[i];
        if(m[i] < mv) {
            mv = m[i];
            mi = i;
        }
    }
    ll res;
    res = (X - su) / mv + N;
    cout << res << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

const int N = 310;
int n, m, K, ans;
char s[N], t[N];
int f[N][N][N];

int main() {
	int i, j, k;
	scanf("%s", s+1); n = strlen(s+1);
	m = n >> 1;
	rep(i, 1, n) t[i] = s[n-i+1];
	
	scanf("%d", &K);
	ans = 1;
	rep(i, 1, n-1) {
		rep(j, 1, n-i) 
			rep(k, 0, K) {
				f[i][j][k] = max(f[i-1][j][k], f[i][j-1][k]);
				if(k) f[i][j][k] = max(f[i][j][k], f[i][j][k-1]);
				if(s[i] == t[j]) {
					f[i][j][k] = max(f[i-1][j-1][k]+1, f[i][j][k]);
				} else {
					if(k) f[i][j][k] = max(f[i-1][j-1][k-1]+1, f[i][j][k]);
				}
				//printf("%d %d %d %d\n", i, j, k, f[i][j][k]);
			}
		ans = max(ans, f[i][n-i-1][K]*2+1);
		ans = max(ans, f[i][n-i][K]*2);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 112384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<tuple<long long int,long long int,long long int> > ab;
  int a,b;
  for(int i=0; i<n; i++){
    cin >> a >> b;
    ab.emplace_back(a+b,a,b);
  }
  sort(ab.begin(),ab.end());
  reverse(ab.begin(),ab.end());
  bool tak = true;
  long long int tman=0,aman=0;
  for(int i=0; i<n; i++){
    if(tak){
      tman += get<1>(ab[i]);
    }else{
      aman += get<2>(ab[i]);
    }
    tak = !tak;
  }
  cout << tman-aman << endl;
}

Measured memory_bytes: 4852
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;

int N;
vector<string> S;

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        string tmp;
        cin >> tmp;
        S.push_back(tmp);
    }

    map<string, int> bucket;
    for (int i = 0; i < N; ++i) {
        if (bucket.count(S[i]) == 0) {
            bucket[S[i]] = 1;
        } else {
            bucket[S[i]] += 1;
        }
    }

    int m = 0;
    for (auto itr = bucket.begin(); itr != bucket.end(); ++itr) {
        m = max(m, itr->second);
        // cout << itr->first << endl;
    }

    for (auto itr = bucket.begin(); itr != bucket.end(); ++itr) {
        if (itr->second == m) {
            cout << itr->first << endl;
        }
    }
    return 0;
}

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

int main(){
  int D,G;
  cin>>D>>G;
  G/=100;
  vector<int> p(D+1),c(D+1);
  for(int i=1;i<=D;i++){
    cin>>p.at(i)>>c.at(i);
    c.at(i)/=100;
  }

  vector<int> dp(G+1,10000);
  dp.at(0)=0;
  for(int i=1;i<=D;i++){
    for(int j=G;j>=0;j--){
      for(int k=1;k<p.at(i);k++){
        dp.at(min(G,j+i*k))=min(dp.at(min(G,j+i*k)),dp.at(j)+k);
      }
      dp.at(min(G,j+i*p.at(i)+c.at(i)))=min(dp.at(min(G,j+i*p.at(i)+c.at(i))),dp.at(j)+p.at(i));
    }
  }
  cout<<dp.at(G)<<endl;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int x,y;
    char op;
    
    while(cin>>x>>op>>y,op!='?'){
        switch(op){
            case '+': cout<<x+y<<endl;
                break;
            case '-': cout<<x-y<<endl;
                break;
            case '*': cout<<x*y<<endl;
                break;
            case '/': cout<<x/y<<endl;
                break;
        }
    }
    return 0;
}



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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);

  ll count = 0;
  rep(i, 1, N + 1) {
    if (i % 2 == 1) count++;
  }

  putf(double(count) / double(N), 8);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int A[20];
int B[20];
int C[20];

int main()
{
	int N;
	cin >> N;
	int satisfied = 0;

	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];
	for (int i = 0; i < N - 1; i++) cin >> C[i];

	satisfied = B[A[0] - 1];

	for (int i = 1; i < N; i++) {
		if (A[i] == A[i - 1] + 1) satisfied += C[A[i - 1] - 1];
		satisfied += B[A[i] - 1];
	}

	cout << satisfied << endl;

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct edge{
    int from, to;
    lint cost;
};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

bool bellman_ford(int v, const vector<edge>& es, vector<long long>& cost, int s = 0, int g = -1){
    if(g == -1){
        g = v - 1;
    }

    const long long INF = 1LL << 61;

    cost.resize(v);
    fill(cost.begin(), cost.end(), INF);
    cost[s] = 0;

    for(int i = 0 ; i < v * 2 ; ++i){
        for(auto& e : es){
            if(cost[e.from] < INF && cost[e.from] + e.cost < cost[e.to]){
                if(i >= v - 1 && e.to == g){
                    return false;
                }else if(i >= v - 1){
                    cost[e.to] = -INF;
                }else{
                    cost[e.to] = cost[e.from] + e.cost;
                }
            }
        }
    }

    return true;
}

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

    int n, m;
    cin >> n >> m;

    vector<edge> es;
    for(int i = 0 ; i < m ; ++i){
        int a, b;
        lint c;
        cin >> a >> b >> c;
        es.push_back({a - 1, b - 1, -c});
    }

    vector<lint> cost;

    if(bellman_ford(n, es, cost)){
        cout << -cost[n - 1] << endl;
    }else{
        cout << "inf" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
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; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans=1<<30;
    int ctr=0;
    repi(i,1,n){
        if(s[i]=='E') ctr++;
    }
    chmin(ans,ctr);
    rp(i,n-1){
        if(s[i]=='W') ctr++;
        if(s[i+1]=='E') ctr--;
        chmin(ans,ctr);
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

int main() {
  int num;
  cin >> num;
  if (num == 0) {
    cout << 0 << endl;
  } else if (num == 1) {
    cout << 1 << endl;
  } else if (num == 10) {
    cout << 1 << endl;
  } else if (num == 11) {
    cout << 2 << endl;
  } else if (num == 100) {
    cout << 1 << endl;
  } else if (num == 101) {
    cout << 2 << endl;
  } else if (num == 110) {
    cout << 2 << endl;
  } else if (num == 111) {
    cout << 3 << endl;
  }
}


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

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

    for (int i = 0; i < s.size() - 8; i++)
        cout << s.at(i);
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

string s;

bool vis[26];

int main()
{
	cin >> s;
	if (s.size() == 26)
	{
		string t = s;
		if (!next_permutation(s.begin(),s.end()))
		{
			puts("-1");
			return 0;
		}
		for (int i = 0;i < s.size();i++)
		{
			cout << s[i];
			if (s[i] != t[i])
				break;
		}
		cout << endl;
		return 0;
	}
	for (int i = 0;i < s.size();i++)
		vis[s[i] - 'a'] = 1;
	for (int i = 0;i < 26;i++)
		if (!vis[i])
		{
			s += char(i + 'a');
			cout << s << endl;
			return 0;
		}
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

import math
from functools import reduce

# 標準入力 <int>
N = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0

for a in range(N):
  for b in range(N):
    for c in range(N):
      #print(gcd(a + 1, b + 1, c + 1))
      ans += gcd(a + 1, b + 1, c + 1)

print(ans)


Measured memory_bytes: 69724
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int dp[MAXN];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
		dp[i]=dp[i-1]+1;
		int pw=6;
		for(int j=0;;j++){
			if(pw<=i)
				umin(dp[i],dp[i-pw]+1);
			else
				break;
			pw*=6;
		}
		pw=9;
		for(int j=0;;j++){
			if(pw<=i)
				umin(dp[i],dp[i-pw]+1);
			else
				break;	
			pw*=9;
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define maxn 200007
int n, w;
int value[maxn], wt[maxn];
int main()
{
    cin >> n >> w;
    for (int i = 1; i <= n; i++)
    {
        cin >> wt[i] >> value[i];
    }
    long long int v[n + 1][w + 1];

    for (int i = 0; i <= n; i++)
    {
        v[i][0] = 0;
    }
    for (int i = 0; i <= w; i++)
    {
        v[0][i] = 0;
    }

    for (int item = 1; item <= n; item++)
    {
        for (int weight = 1; weight <= w; weight++)
        {
            if (wt[item] <= weight)
            {
                v[item][weight] = max(v[item - 1][weight - wt[item]] + value[item], v[item - 1][weight]);
            }
            else
            {
                v[item][weight] = v[item - 1][weight];
            }
        }
    }
    cout << v[n][w];
    return 0;
}

Measured memory_bytes: 82496
from collections import deque

n , q = map(int,input().split())
p , t = deque() , deque()
for i in range(n):
    x , y = input().split()
    p.append(x)
    t.append(int(y))
time = 0
temp1 = ""
temp2 = 0

while p:
    temp1 , temp2 = p.popleft() , t.popleft()
    if temp2 <= q :
        time += temp2
        print(temp1,time)
        temp1 , tmep2 = "" , 0
    else:
        time += q
        temp2 -= q
        p.append(temp1)
        t.append(temp2)

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

using namespace std;
typedef long long ll;

int main( void )
{
  ll n, k, c;
  cin >> n >> k >> c;
  
  string s;
  cin >> s;
  
  ll a[k] = {};
  for ( ll i = 0, j = 0; (i < n) and (j < k); i++ ) {
    if ( s[i] == 'o' ) {
      a[j++] = i;
      i += c;
    }
  }
  
  ll b[k] = {};
  for ( ll i = n - 1, j = k - 1; (i >= 0) and (j >= 0); i-- ) {
    if ( s[i] == 'o' ) {
      b[j--] = i;
      i -= c;
    }
  }
  
  for ( ll i = 0; i < k; i++ ) {
    if ( a[i] == b[i] ) {
      cout << (a[i] + 1) << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 4996
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 3e5;
const int mod = 1e9 + 7;
int n, k;
vector<int> G[N]; 
int dp[N][2];
void dfs(int x, int f) {
	dp[x][1] = dp[x][0] = 1;
	int g[2] = {1, 1};
	for (int i: G[x]) {
		if (i == f) continue;
		dfs(i, x); 
		g[0] = (ll)g[0] * dp[i][0] % mod;
		g[1] = (ll)g[1] * (dp[i][1] + dp[i][0]) % mod;
	}
	dp[x][1] = (ll)dp[x][1] * g[0] % mod;
	dp[x][0] = (ll)dp[x][0] * g[1] % mod;
}
int main() {
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs(1, 0);
	cout << (dp[1][0] + dp[1][1]) % mod;
}



Measured memory_bytes: 18432
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int a,b,c;
  cin>>a>>b>>c;
  loop(i,1,500)
    if((a*i)%b==c){
      cout<<"YES"<<endl;
      return 0;
    }
  cout<<"NO"<<endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
 
 
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
int tc;
const int N=3e5+5,M=3e5+5,MOD=1e9+7,OO=1e9;

int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	//file();
 	int n,m;
 	scanf("%d %d",&n,&m);

 	std::vector<int>a(n+1),b(m+1);

 	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
 	for(int i=1;i<=m;i++)scanf("%d",&b[i]);

 	std::vector<std::vector<ll>> dp(n+1,vector<ll>(m+1,0)),sum(n+1,vector<ll>(m+1,0));
 	for(int i=1;i<=n;i++){
 		for(int j=1;j<=m;j++){
 			if(a[i]==b[j])
 				dp[i][j] = 1+sum[i-1][j-1];
 			sum[i][j] = (dp[i][j]+sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+MOD)%MOD;
 			dp[i][j]%=MOD;
 		}
 	}
 	
 	printf("%lld\n",sum[n][m]+1);
}

Measured memory_bytes: 62976
n = int(input())
a = list(map(int, input().split()))
x = 0
for i in range(1, n):
  x = x^a[i]
  
l = [x]
for i in range(n-1):
  x = a[i]^a[i+1]
  l.append(l[i]^x)
print(*l)



Measured memory_bytes: 31636
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<string> w(n);
    map<string, int> z;
    for (int i = 0; i < n; i++){cin >> w[i];z[w[i]] = 0;}
    z[w[0]] = 1;
    for (int i = 0; i < n-1; i++){
        if (z[w[i+1]] || w[i][w[i].size()-1] != w[i+1][0]){
            cout << "No" << endl;
            return 0;
        }else{
            z[w[i+1]] = 1;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3596
import sys
from collections import deque
import copy
def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())
    can_A = V * T
    can_B = W * T
    if A < B:
        B += can_B
        A += can_A
        if A >= B:
            print('YES')
        else:
            print('NO')
    else:
        B -= can_B
        A -= can_A
        if A <= B:
            print('YES')
        else:
            print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9604
#include <stdio.h>

int main(void){
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c);
	if((a==5 && b==5 && c==7)||
		(a==5 && b==7 && c==5) ||
		(a==7 && b==5 && c==5)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	return 0;
}

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

using namespace std;

const int maxn=105;

struct card
{
	char suit;
	int value;
};

card cards[maxn];
card ccards[maxn];
int n;

void bubble()
{
	for(int i=0;i<n;i++){
		for(int j=n-1;j>=i+1;j--){
			if(cards[j].value<cards[j-1].value){
				swap(cards[j],cards[j-1]);
			}
		}
	}
}

void selection()
{
	int minn;
	for(int i=0;i<n;i++){
		minn=i;
		for(int j=i;j<n;j++){
			if(ccards[j].value<ccards[minn].value){
				minn=j;
			}
		}
		swap(ccards[i],ccards[minn]);
	}
}

int isstable()
{
	for(int i=0;i<n;i++){
		if(cards[i].suit!=ccards[i].suit){
			return 0;
		}
	}
	return 1;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf(" %c%d",&cards[i].suit,&cards[i].value);
	}
	for(int i=0;i<n;i++){
		ccards[i]=cards[i];
	}
	bubble();
	selection();
	for(int i=0;i<n;i++){
		if(i!=0){
			printf(" ");
		}
		printf("%c%d",cards[i].suit,cards[i].value);
	}
	cout<<endl;
	printf("Stable\n");
	for(int i=0;i<n;i++){
		if(i!=0){
			printf(" ");
		}
		printf("%c%d",ccards[i].suit,ccards[i].value);
	}
	printf("\n");
	if(isstable()){
		cout<<"Stable"<<endl;
	}else{
		cout<<"Not stable"<<endl;
	}
	return 0;
}
/*
5
H4 C9 S4 D2 C3
*/


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

using namespace std;

const int dirx[] = {0, 1, 0, -1};
const int diry[] = {1, 0, -1, 0};

int h,w,n,i,j,mat[105][105],cnt[100005];

void dfs(int x, int y, int ind, int way){
	cnt[ind]--;
	mat[x][y] = ind;
	int newx, newy;
	newx = x + dirx[way];
	newy = y + diry[way];
	
	if(newx < 0 || newx >= h || newy < 0 || newy >= w || mat[newx][newy] != 0){
		way = (way + 1) % 4;
		newx = x + dirx[way];
		newy = y + diry[way];
	}
	
	if(cnt[ind] == 0)
	ind++;
	
	if(ind == n + 1) return;
	
	dfs(newx, newy, ind, way);
}

int main(){
	scanf("%d%d", &h, &w);
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		cnt[i + 1] = x;
	}
	
	dfs(0, 0, 1, 0);
	
	for(i = 0; i < h; i++){
		for(j = 0; j < w; j++){
			if(j == 0)
			printf("%d", mat[i][j]);
			else
			printf(" %d", mat[i][j]);
		}
		printf("\n");
	}
	printf("\n");
}


Measured memory_bytes: 384
n = int(input())
target = input()
if len(target) % 2 == 1:
    print("No")
else:
    index = len(target) // 2
    str1 = target[:index]
    str2 = target[index:]
    if str1 == str2:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 2940
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int N;
  cin >> N;
  int tmp = 1, ans = 0;
  while(tmp <= N){
    tmp *= 2;
    ans++;
  }
  print(pow(2, ans-1));
}


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

int main(void)
{
    
    long long int N, X, M;
    cin >> N >> X >> M;
    unsigned long long int ans = 0;

    vector<int> la;
    long long int a = X;
    ans += a;
    std::vector<int>::iterator it; 
    for(int i = 1; i < N; ++i)
    {
        long long int at = (a*a)%M;
        it = std::find (la.begin(), la.end(), at); 
        if(it != la.end())
        {
            int ns = it - la.begin();
            int nm = la.size() - ns;
            long long int ss = (N-i)/nm;
            long long int sm = (N-i)%nm;
            for(int k = 0; k < sm; ++k)
            {
                ans += la[k+ns];
            }
            long long int dda = 0;
            for(int k = ns; k < la.size(); ++k)
            {
                dda += la[k];
            }
            ans += dda*ss;
            break;
        }
        ans += at;
        a = at;
        la.push_back(a);
    }

    cout << ans << endl;

    return 0;
}



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

long long int gcd(long long int a, long long int b) {
  if(a < b) gcd(b, a);
  long long int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {

  long long int N;
  cin >> N;
  long long int A[N];
  for (long long int i=0; i<N ; i++){
    cin >> A[i];
  }
  long long int tmp_gcd=A[0];
   for (long long int i=0; i<N ; i++){
     tmp_gcd = gcd(tmp_gcd, A[i]);
   }
   cout << tmp_gcd << endl;

}


Measured memory_bytes: 1024
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var y1 = int.Parse(line[0]);
        var m1 = int.Parse(line[1]);
        var d1 = int.Parse(line[2]);
        line = Console.ReadLine().Trim().Split(' ');
        var y2 = int.Parse(line[0]);
        var m2 = int.Parse(line[1]);
        var d2 = int.Parse(line[2]);
        var ans = getAge(y1, m1, d1, y2, m2, d2);
        Console.WriteLine(ans);
    }
    public static int getAge(int y1, int m1, int d1, int y2, int m2, int d2)
    {
        var ans = -1;
        var yyyy = 2008;
        var bd1 = new DateTime(y1, m1, d1);
        var bd2 = new DateTime(y2, m2, d2);
        var mo = new int[] { 1, 3, 5, 7, 8, 10, 12 };
        foreach (var x in mo)
        {
            for (int i = 1; i <= 31; i++)
            {
                var now = new DateTime(yyyy, x, i);
                var age1 = now.Year - bd1.Year;
                if (bd1 > now.AddYears(-age1)) age1--;
                var age2 = now.Year - bd2.Year;
                if (bd2 > now.AddYears(-age2)) age2--;
                ans = Max(ans, Abs(age1 - age2));
            }
        }
        var mo2 = new int[] { 4, 6, 9, 11 };
        foreach (var x in mo2)
        {
            for (int i = 1; i <= 30; i++)
            {
                var now = new DateTime(yyyy, x, i);
                var age1 = now.Year - bd1.Year;
                if (bd1 > now.AddYears(-age1)) age1--;
                var age2 = now.Year - bd2.Year;
                if (bd2 > now.AddYears(-age2)) age2--;
                ans = Max(ans, Abs(age1 - age2));
            }
        }
        for (int i = 1; i <= 29; i++)
        {
            var now = new DateTime(yyyy, 2, i);
            var age1 = now.Year - bd1.Year;
            if (bd1 > now.AddYears(-age1)) age1--;
            var age2 = now.Year - bd2.Year;
            if (bd2 > now.AddYears(-age2)) age2--;
            ans = Max(ans, Abs(age1 - age2));
        }
        return ans;
    }
}



Measured memory_bytes: 18064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#define INF 100000000
#define EPS 1e-9

using namespace std;

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

int n;

int main() {

	cin >> n;

	ll ans = 100000;

	while (n > 0){
		n--;
		ans *= 1.05;
		if (ans % 1000 != 0){
			ans = (ans / 1000) * 1000 + 1000;
		}
	}

	cout << ans << endl;

	return 0;
}

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

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

using namespace std;

const int INF=1<<29;

int main(){
	for(int n,m,a,b,c;scanf("%d%d%d%d%d",&n,&m,&a,&b,&c),n;){
		a--,b--,c--;
		int wf[100][100];
		rep(u,n)rep(v,n)	wf[u][v]=(u==v?0:INF);
		rep(i,m){
			int s,d,cost;	scanf("%d%d%d",&s,&d,&cost);
			s--,d--;
			wf[s][d]=cost;
		}

		rep(k,n)rep(i,n)rep(j,n)	wf[i][j]=min(wf[i][j],wf[i][k]+wf[k][j]);

		int cmin=INF;
		rep(u,n)	cmin=min(cmin,wf[a][u]+wf[u][b]+wf[u][c]);
		printf("%d\n",cmin);
	}

	return 0;
}

Measured memory_bytes: 796
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#define REP(i, n) for(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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}



int main() {
	int x[4],y[4];
	REP(i,2){
		cin>>x[i]>>y[i];
	}
	x[2]=x[1]-(y[1]-y[0]);
	y[2]=y[1]+(x[1]-x[0]);
	x[3]=x[2]-(y[2]-y[1]);
	y[3]=y[2]+(x[2]-x[1]);
	cout<<x[2]<<" "<<y[2]<<" "<<x[3]<<" "<<y[3];
}


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[]list = new int[N];
    int all=0;
    for(int i=0; i<N; i++){
	  list[i] = sc.nextInt();	
      all += list[i];
}  
    /*System.out.println(all);
    System.out.println(all/4.0/M);
	System.out.println(list[0]);*/

      int count =0;
      for(int j=0; j<N; j++){
        if(list[j] >= all/4.0/M){
         count++;
        }
      }
		if(count >= M){
      System.out.println("Yes");
        }else{
      System.out.println("No");
        }
}
}

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

int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int h,w;
  cin >> h >> w;
  string s[h];
  rep(i,h){
    cin >> s[i];
  }
  rep(i,h){
    cout << s[i] << endl;
    cout << s[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
  double n, m, d;
  
  cin >> n >> m >> d;
  cout << setprecision(10);
  double ans;
  if (d == 0) ans = 1.0 / n;
  else ans = (2 * (n - d)) / (n * n);
  ans *= m - 1;
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 998244353;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

vector<pair<ll,ll>> ap;
int main(){
  ll x,y,a,b,c,ans=0;
  cin>>x>>y>>a>>b>>c;
  ll i1;
  rep(i,0,a){cin>>i1;ap.pb(mp(i1,(ll)0));}
  rep(i,0,b){cin>>i1;ap.pb(mp(i1,(ll)1));}
  rep(i,0,c){cin>>i1;ap.pb(mp(i1,(ll)2));}
  sort(ap.rbegin(),ap.rend());

  ll cntx=0,cnty=0,cntr=0,pos=0;
  while(cntx+cnty+cntr<x+y){
    if(ap[pos].second==0&&cntx<x){ans+=ap[pos].first;pos++;cntx++;}
    else if(ap[pos].second==1&&cnty<y){ans+=ap[pos].first;pos++;cnty++;}
    else if(ap[pos].second==2){
      ans+=ap[pos].first;
      pos++;
      cntr++;
    }
    else pos++;
    //cout<<pos<<endl;
  }
  cout<<ans;
}



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

using namespace std;

#define int long long
typedef pair<int, int> pii;

int n;
int a[50];
int b[50];
vector<pii> g[51];
char mark[51];
char used[51];

bool dfs(int cur, int need){
    if(cur == need) return true;
    used[cur] = true;
    for(auto to: g[cur]){
        if(!mark[to.second]) continue;
        if(!used[to.first]){
            if(dfs(to.first, need)) return true;
        }
    }
    return false;
}

main()
{
    ios_base::sync_with_stdio(false);
    for(int i = 0; i <= 50; i++){
        for(int j = 1; j <= 50; j++){
            g[i].push_back({i%j, j});
        }
    }
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 1; i <= 50; i++) mark[i] = 1;
    for(int i = 0; i < n; i++){
        memset(used, 0, sizeof(used));
        if(!dfs(a[i], b[i])){
            cout << -1 << endl;
            exit(0);
        }
    }
    for(int i = 50; i >= 1; i--){
        mark[i] = false;
        bool ok = false;
        for(int j = 0; j < n; j++){
            memset(used, 0, sizeof(used));
            if(!dfs(a[j], b[j])) ok = true;
        }
        if(ok) mark[i] = true;
    }
    int an = 0;
    for(int i = 1; i <= 50; i++){
        if(mark[i]) an += (1ll << i);
    }
    cout << an << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len, result = 0;
		if(s.length() % 2 != 0) len = s.length() - 1;
		else len = s.length() - 2;
		for(int i = len; i > 1; i -= 2) {
			if(s.substring(0, i / 2).equals(s.substring(i / 2 , i))) {
				result = i;
				break;
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,ans=0;
    cin >> n;
    vector<int> h(n+2);
    for(int i=1;i < n+1;i++)
    {
        cin >> h.at(i);
    }//シミュレートすれば行ける？
    h.at(0)=0;
    h.at(n+1)=0;
    
    while(1){
        bool flag = true;//終了条件 h.at(i)ぜんぶ0

        for(int i=0;i < n+1;i++)
        {
            if(h.at(i)==0){
                continue;
            }else{
                flag = false;
            }
            
            for(int j=i+1;j < n+2;j++)
            {      
                if(h.at(j)!=0){
                    continue;
                }else{
                    ans++;
                    for(int k=i;k < j;k++)
                    {
                        h.at(k)--;
                    }
                    i=-1;
                    break;
                }
            }
        }
        
        if(flag){
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(ll i = 0;i < (n); ++i)
typedef long long ll;
typedef long double la;
using namespace std;

ll f(ll n){
    int ans = 0;
    while(n > 0){
        ans += n%10;
        n /= 10;
    }
    return ans;
}

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i=1;i<=n;i++){
        int num = f(i);
        if(a<=num && num<=b) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int n, a;
  cin >> n;
  cin >> a;
  
  if (n%2 && 0==a) {
    cout << "No" << endl;
    return 0;
  }
  
  int sp = n % 500;
  if (sp > a) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D

n = gets.to_i
arr = []
n.times do
    arr.push gets.to_i
end

maxv=arr[1]-arr[0]
minv = arr[0]
(1..n-1).each do |j|
    maxv = arr[j]-minv if maxv < arr[j]-minv
    minv = arr[j] if minv > arr[j]
end

puts maxv

Measured memory_bytes: 7792
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll n=s.length();
    ll a[n+1][13];
    memset(a,0,sizeof(a));
    a[0][0]=1;
    for(int i=0;i<n;i++){
        if(s[i]=='?'){
            for(int k=0;k<10;k++){
                for(int j=0;j<13;j++){
                    a[i+1][(10*j+k)%13]+=a[i][j];
                    a[i+1][(10*j+k)%13]%=mod;
                }
            }
        }else{
            int k=(s[i]-'0');
            for(int j=0;j<13;j++){
                a[i+1][(10*j+k)%13]+=a[i][j];
                a[i+1][(10*j+k)%13]%=mod;
            }
        }
    }
    cout << a[n][5]<<endl;
    return 0;
}


Measured memory_bytes: 10704
S = input()
N = len(S)

cntRL = []
cntr, cntl = 0, 0
for i, s in enumerate(S):
    if s == 'R':
        if cntl != 0:
            cntRL.append([cntr, cntl, i - 1])
            cntr, cntl = 0, 0
        cntr += 1
    else:
        cntl += 1

cntRL.append([cntr, cntl, i])
ans = [0 for _ in range(N)]
for rcnt, lcnt, idx in cntRL:
    ans[idx-lcnt] = (rcnt+1)//2 + lcnt//2
    ans[idx-lcnt+1] = rcnt//2 + (lcnt+1)//2
print(*ans)

Measured memory_bytes: 52700
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 256
#define EPS 1e-8

using namespace std;
typedef long long ll;

int main()
{
    int n;
    while(cin >> n && n) {
        vector<int> I(n);
        rep(i,n) cin >> I[i];
    
        int S = 0,A = 0,C = 0;
        double H = 100000.0;
        
        rep(s,16) {
            rep(a,16) {
                rep(c,16) {
                    double cnt[500];
                    memset(cnt,0,sizeof(cnt));

                    int res = s;
                    rep(i,n) {
                        res = (a * res + c) % MOD;
                        int t = (I[i] + res) % MOD;
                        cnt[t]++;
                    }

                    double ret = 0.0;
                    rep(i,MOD) {
                        if(cnt[i]) {
                            ret -= cnt[i] / n * log(cnt[i] / (double)n);
                        }
                    }

                    // cout << ret << " "<< EPS << " " << ret + EPS << " " << S << endl;

                    if(ret + EPS < H) {
                        H = ret;
                        S = s;
                        A = a;
                        C = c;
                    }
                }
            }
        }

        cout << S << " " << A << " " << C << endl;
    }

    return 0;
}

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

int gcd(int x, int y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int x;
    cin >> x;
    int i = 0;
    int num = 0;
    while (1) {
        i++;
        num += x;
        if (num % 360 == 0) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3632