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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'


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


const int MOD = 1000000007;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;

  priority_queue<ll> pq;

  cin >> n >> m;

  for(int i = 0; i < n; i++) {

     int temp;
     cin >> temp;
     pq.push(temp);
  }

  for(int i = 0; i < m; i++) {

     int temp = pq.top();
     temp = temp / 2;
     pq.pop();
     pq.push(temp);
     if(pq.top() == 0) {

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

  ll ans = 0;
  for(int i = 0; i < n; i++) {

      if(pq.top() == 0) {

         break;
      }

      ans +=  pq.top();

      pq.pop();
  }

  cout << ans << endl;

}



Measured memory_bytes: 1400
R={"*":2,"/":2,"+":1,"-":1,"(":0,")":0}
for _ in[0]*int(input()):
 L=[];t=''
 for e in input()[:-1]:
  if e.isdigit():t+=e
  else:
   if t:L+=[t];t=''
   L+=e
 if t:L+=[t]
 P,S=[],[]
 for i in L:
  if"("==i:S+=i
  elif")"==i:
   while"("!=S[-1]:P+=S.pop()
   S.pop()
  elif i in R:
   while S and R[S[-1]]>=R[i]:P+=S.pop()
   S+=i
  else:P+=[i]
 while S:P+=S.pop()
 for x in P:S+=[str(int(eval(S.pop(-2)+x+S.pop())))if x in"+-*/"else x]
 print(*S)


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

int main()
{
    int N, M, point = 0, max = 0;
    cin >> N;
    vector<string> blue(N);
    set<string> ch;
    for (int i = 0; i < N; ++i)
    {
        cin >> blue.at(i);
        ch.insert(blue.at(i));
    }
    cin >> M;
    vector<string> red(M);
    for (int i = 0; i < M; ++i)
    {
        cin >> red.at(i);
        ch.insert(red.at(i));
    }

    for (auto x : ch)
    {
        point = 0; //重要
        for (int i = 0; i < N; ++i)
        {
            if (blue.at(i) == x)
            {
                ++point;
            }
        }
        for (int i = 0; i < M; ++i)
        {
            if (red.at(i) == x)
            {
                --point;
            }
        }
        max = max < point ? point : max;
    }
    cout << max << endl;
}

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

const int N = 200005;
const long double EPS = 1e-9;
const long double PI = acos(-1.);


int n, a[N] , s[N];
int main()
{
    cin >> n;
    for(int i = 2; i <= n; i++){
        scanf("%d", &a[i]);
        s[a[i]] ++;
    }

    for(int i = 1; i <= n ; i++){
        printf("%d\n", s[i]);
    }

    return 0;
}




















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

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

    vector<int> a(N);
    vector<bool> isgot(N);

    rep(i,N){
        cin >> a.at(i);
    }

    int score = 0;
    int isAliceTurn = true;
    rep(i,N){
        // search max element
        int cand = 0;
        int candindex = -1;
        rep(j, N){
            if (isgot.at(j) == false && a.at(j) > cand){
                cand = a.at(j);
                candindex = j;
            }
        }
        if (isAliceTurn){
            score += cand;
            isAliceTurn = false;
        } else {
            score -= cand;
            isAliceTurn = true;
        }
        isgot.at(candindex) = true;
    }
    cout << score << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;

    string S[H];
    int wnum = 0;

    for (int i = 0; i < H; i++) {
        cin >> S[i];
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '.') wnum++;
        }
    }

    int INF = 1 << 30;
    vector<vector<int>> d(H, vector<int>(W, INF));

    queue<pair<int, int>> q;

    d[0][0] = 1;
    q.push({0, 0});

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

    while (!q.empty()) {
        pair<int, int> p = q.front();
        int x = p.first;
        int y = p.second;

        q.pop();

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if (nx >= 0 && nx < H && ny >= 0 && ny < W) {
                if (S[nx][ny] == '.' && d[x][y] + 1 < d[nx][ny]) {
                    d[nx][ny] = d[x][y] + 1;
                    q.push({nx, ny});
                }
            }
        }
    }
  
    if (d[H - 1][W - 1] == INF) {
        // 訪れなかった=ゴール不可能
        cout << -1 << endl;
    } else {
        cout << wnum - d[H - 1][W - 1] << endl;
    }

    return 0;
}

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

char f(char c) {
    if(c == 'b') {
        return 'd';
    }
    if(c == 'd') {
        return 'b';
    }
    if(c == 'p') {
        return 'q';
    }
    if(c == 'q') {
        return 'p';
    }
    return c;
}

string deal(string s) {
    reverse(s.begin(), s.end());

    for(int i = 0; i < s.size(); i++) {
        s[i] = f(s[i]);
    }
    return s;
}

int main() {
    string s;

    cin >> s;
    
    if(s == deal(s)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

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


class A
{
	public static void Main ()
	{
	
		string s = Console.ReadLine ();
		int n = int.Parse (Console.ReadLine ());
		int pram1 = 0;
		int pram2 = 0;

		for (int i=0; i<n; i++) {
			string[] op = Console.ReadLine ().Split (' ');
			pram1 = int.Parse(op[1]);
			pram2 = int.Parse (op [2]) + 1 - pram1;

			switch (op[0]) {
			case "print":
				Console.WriteLine (s.Substring (pram1, pram2));
				break;

			case "reverse":
				char[] sort = s.Substring (pram1, pram2).ToCharArray();
				Array.Reverse (sort);
				s = s.Remove (pram1, pram2);
				s = s.Insert (pram1, new string(sort));
				break;

			case "replace":
				s = s.Remove (pram1, pram2);
				s = s.Insert (pram1, op[3]);
				break;
			}
		}
	}
}

Measured memory_bytes: 9172
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<(*i)<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 998244353;//1000000007;
constexpr ld EPS = 1e-11;



int main() {
    
    int ans=0;
    ll n,d;

    cin>>n>>d;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        if(a*a+b*b<=d*d){
            ans++;
        }
    }
    fin(ans);
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string s;
ll n ;
int main()
{
    cin >> s ;
    n = s.size();
    for (int i = 0 ; i < n ;i++)
    {
        if (i%2 == 0)
        {
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D')
            {
                //cout <<i << endl;
                cout <<"No";
                return 0;
            }
        }
        if (i%2 == 1)
        {
            if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D')
            {
                //cout <<i << endl;
                cout <<"No";
                return 0;
            }
        }
    }
    cout <<"Yes";
    return 0;
}


Measured memory_bytes: 256
/*
* @author:  codancer
* @createTime:  time
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef pair<int,int> pii;
int main(){
	long long a,b;
	cin>>a>>b;
	if(a==1||b==1){
		cout<<1<<endl;
		return 0;
	}
	long long ans=(a*b+1)/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
gets.to_i.times do
    a,b = gets.split.map(&:to_i)
    c = (Math.sqrt(a*b)+Float::EPSILON).floor
    if c*c == a*b
        if a == b
            puts c*2-2
        else
            puts c*2-3
        end
    elsif (c+1)*c < a*b
        puts c*2-1
    else
        puts c*2-2
    end
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
 
#define ll long long 
# define skorost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 

using namespace std ;
 
ll z , o , ans ;

ll N = 1e4 + 15820 ;

int main(){ skorost ;

	int a[3] ;

	for( int i = 0 ; i < 3 ; i ++ ){

		cin >> a[i] ;

	}

	sort(a,a+3);

	if( a[0] == 5 && a[1] == 5 && a[2] == 7 ){

		cout << "YES"<< endl ;

	}

	else{

		cout << "NO" << endl;

	}

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
     
    int counter[26];
    for(int i=0;i<26;i++){
        counter[i]=0;
    }
     
    char ch;
    while(cin>>ch){
        int num = tolower(ch) - 'a';
        counter[num]++;
    }
     
    for(int i=0;i<26;i++){
        ch = i + 'a';
        cout << ch << " : " << counter[i] << endl;
    }
 
}

Measured memory_bytes: 1144
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val a = Array.fill(n)(sc.nextInt).distinct

  val ans = a.reduceOption(gcd)

  ans match {
    case Some(e) => println(e)
    case None => println(a(0))
  }

  def gcd(a: Int, b: Int): Int = {
    if(b > a) gcd(b, a) else if(b == 0) a else gcd(b, a % b)
  }
}


Measured memory_bytes: 53972
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 110;
const ll INF = 1e16;

int n;
int f[MAXN][5][2];
int cnt[MAXN];
ll p[MAXN][10];

ll getProfit(ll mask) {
  ll profit = 0;
  for (int i=0;i<n;i++) {
    cnt[i] = 0;
  }
  for (int i=0;i<10;i++) {
    if ((mask >> i) & 1) {
      int day = i / 2;
      int m = i % 2;
      for (int j=0;j<n;j++) {
        if (f[j][day][m] > 0) {
          cnt[j]++;
        }
      }
    }
  }
  for (int i=0;i<n;i++) {
    profit += p[i][cnt[i]];
  }
  return profit;
}

void solve() {
  ll maxProfit = -INF;
  for (ll i=1;i<(1<<10);i++) {
    maxProfit = max(maxProfit, getProfit(i));
  }
  cout << maxProfit << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    for (int j=0;j<5;j++) {
      for (int k=0;k<2;k++) {
        cin >> f[i][j][k];
      }
    }
  }
  for (int i=0;i<n;i++) {
    for (int j=0;j<11;j++) {
      cin >> p[i][j];
    }
  }
  solve();
}


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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());            
            var a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

            var max = a.Max();
            var min = a.Min();

            Console.WriteLine(max - min);
        }
    }
}


Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    int t,n,c;
    string s;
    cin>>n;
    cin>>s;
    //cout<<s.size()<<"n";
    if(s.size()<=n)cout<<s;
    else{
            for(int i=0;i<n;i++)cout<<s[i];
            cout<<"...";
    }
}


Measured memory_bytes: 3648
#include <stdio.h>
int main(void)
{
  int N,K,tall,i;
  int num=0;
  scanf("%d %d",&N,&K);
  for(i=0;i<N;i++){
    scanf("%d",&tall);
    if(tall>=K) num++;
  }
  printf("%d",num);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int n, l;
    cin >> n >> l;

    int min = 1000, index = -1;

    for (int i = 0; i < n; i++)
    {
        if (abs(l + i) < min)
        {
            min = abs(l + i);
            index = i;
        }
    }

    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        if (i != index)
        {
            sum += l + i;
        }
    }

    cout << sum << endl;
    return 0;
}


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

typedef long long ll;

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

	int N, A, B, C;
	cin >> N >> A >> B >> C;

	vector<int> l(N);

	for(int i = 0; i < N; i++) {
		cin >> l[i];
	}

	int min = 10000000;

	for(int a = 1; a < (1 << N); a++) {
		int ca = -10;

		vector<int> X;
		int x = 0;

		for(int i = 0; i < N; i++) {
			if(a & (1 << i)) {
				X.push_back(l[i]);
			} else {
				x += l[i];
				ca += 10;
			}
		}

		ca += abs(A - x);

		if(X.size() >= N) continue;

		for(int b = 1; b < (1 << X.size()); b++) {
			int cb = -10;

			vector<int> Y;
			int y = 0;

			for(int i = 0; i < X.size(); i++) {
				if(b & (1 << i)) {
					Y.push_back(X[i]);
				} else {
					y += X[i];
					cb += 10;
				}
			}

			cb += abs(B - y);

			if(Y.size() >= X.size()) continue;

			for(int c = 1; c < (1 << Y.size()); c++) {
				int cc = -10;

				int z = 0;

				for(int i = 0; i < Y.size(); i++) {
					if(c & (1 << i)) {
						z += Y[i];
						cc += 10;
					}
				}

				cc += abs(C - z);

				if(ca + cb + cc < min) {
					min = ca + cb + cc;
				}
			}
		}
	}

	cout << min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
using namespace std;

#define ll long long

int main(){
    int s,a[100000];
    cin >> s;
    a[0] = s;
    for(int i = 1; i < 100000; i++){
        if(a[i-1]%2) a[i] = 3 * a[i-1] + 1;
        else a[i] = a[i-1] / 2;
        for(int j = 0; j < i; j++){
            if(a[i] == a[j]){
                cout << i + 1 << endl;
                return 0;
            }
        } 
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct edge{int to,cost;};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<vector<edge>> g(n);
    vector<int> l(m),r(m),d(m);
    rep(i,m){
        cin>>l[i]>>r[i]>>d[i];
        l[i]--,r[i]--;
        g[l[i]].push_back({r[i],d[i]});
        g[r[i]].push_back({l[i],-d[i]});
    }
    vector<int> ans(n,-INF);
    int id=0;
    auto bfs=[&](int v){
        queue<int> que;
        que.push(v);
        ans[v]=0;
        while(!que.empty()){
            int from=que.front();
            que.pop();
            for(auto to:g[from]){
                if(ans[to.to]!=-INF) continue;
                ans[to.to]=ans[from]+to.cost;
                que.push(to.to);
            }
        }
    };
    rep(i,n){
        if(ans[i]==-INF){
            bfs(i);
        }
    }
    rep(i,m){
        if(ans[r[i]]-ans[l[i]]!=d[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 11776
import java.util.*;

public class Main{
	public static void main(String args[]){
	  Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      String s = sc.next();
      if(a < 3200){
        System.out.println("red");
      }else{
        System.out.println(s);
      }
	}
}


Measured memory_bytes: 21844
/**
 *    author:  math2do
 *    created: 21.11.2019 21:8:3
**/

#include <bits/stdc++.h>

using namespace std;

vector <vector <double>> dp;

const double eps = (double) 1e-12;

double solve(int idx, int n, int head, vector <double> &prob) {
  if (idx == n) {
    int tail = n - head;
    if (head > tail) return 1.0;
    else return 0;
  }
  if ((dp[idx][head] + 1.0) > eps) return dp[idx][head];  
  double ans = 0.0;
  //..head
  head++;
  double h = solve(idx + 1, n, head, prob);
  ans = ans + h * prob[idx];

  //..tail
  head--;
  double t = solve(idx + 1, n, head, prob);
  ans = ans + t * (1 - prob[idx]);
  return dp[idx][head] = ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(17);
  #ifdef LOCAL
    freopen("coins.in", "rt", stdin);
  #endif
  int n;
  cin >> n;
  vector <double> prob(n);
  for (int i = 0; i < n; i++) {
    cin >> prob[i];
  }
  dp.resize(n);
  for (int i = 0; i < n; i++) {
    dp[i].resize(n + 1);
    fill(dp[i].begin(), dp[i].end(), -1.0);
  } 

  int head = 0;
  double ans = solve(0, n, head, prob);
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 70912
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int X = Integer.parseInt(scan.next());
		if(X == 7 || X == 5 || X == 3) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}


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

int main(){
  int x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int dx = x1-x2, dy = y1-y2;

  int x3 = x2+dy, y3 = y2-dx, x4 = x1+dy, y4 = y1-dx;

  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_Registration_167
    {
        // https://atcoder.jp/contests/abc167/tasks/abc167_a
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string s = Console.ReadLine();
            string t = Console.ReadLine();
            string result;
            s = s + t.Substring(t.Length - 1, 1);

            if ( s == t )
            {
                result = "Yes";
                Console.WriteLine(result);
            }
            else
            {
                result = "No";
                Console.WriteLine(result);
            }
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25848
import math
n, m = map(int, input().split())

N = math.factorial(n)
M = math.factorial(m)
INF = 10**9 + 7

if abs(n-m) > 1:
    print(0)
elif abs(n-m) == 1:
    print(N*M%INF)
else:
    print(2*N*M%INF)

Measured memory_bytes: 5324
#include<cstdio>
#include<iostream>
#include<cmath>
#include<stack>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k;
int h[100005];
int dp[100005];

int main()
{
memset(dp, 0x3f ,sizeof dp);
scanf("%d %d",&n,&k);
for( int i = 1 ; i <= n ; i++) scanf("%d",&h[i]);
dp[1] = 0;
for( int i = 1 ; i <= n ; i++)
{
	for(int j = 1 ; j <= k; j++)
	dp[i+j] = min(dp[i+j],dp[i]+abs(h[i] - h[i+j]));
}
printf("%d",dp[n]);

	return 0;
}




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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
	fastio;

	int n;
	cin >> n;
	int a[n + 1];
	for(int i = 1; i <= n; ++i) cin >> a[i];
	int cnt = 0, curr = 1;
	while(curr != 2) {
		if(cnt == n) {
			cnt = -1;
			break;
		}
		curr = a[curr];
		++cnt;
	}
	cout << cnt;

	return 0;
}

/*
Simulate the process
* There are N buttons in total
* So if 2 doesn't come in the first N iterations, it will never come
*/


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

using namespace std;

int n;
int a[10004];
int b[10004];

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    long long need = 0, tot = 0;
    for (int i = 0; i < n; ++i) need += max(0, (b[i] - a[i] + 1) / 2), tot += b[i] - a[i];
    cout << (need > tot ? "No" : "Yes") << endl;
}


Measured memory_bytes: 384
class UnionFind

  attr_accessor :nodes, :sizes

  def initialize(num)
    self.nodes = []
    self.sizes = []

    num.times do |n|
      self.nodes[n] = n
      self.sizes[n] = 1
    end
  end

  def root(i)
    # Loop up the chain until reaching root
    while nodes[i] != i do
      # path compression for future lookups
      nodes[i] = nodes[nodes[i]]
      i = nodes[i]
    end
    i
  end

  def union(i, j)
    rooti = root i
    rootj = root j

    # already connected
    return if rooti == rootj

    # root smaller to root of larger
    if sizes[i] < sizes[j]
      nodes[rooti] = rootj
      sizes[rootj] += sizes[rooti]
    else
      nodes[rootj] = rooti
      sizes[rooti] += sizes[rootj]
    end
  end

  def connected?(i, j)
    root(i) == root(j)
  end

end

N, M = gets.split.map &:to_i
ABs = $<.map{|s|
  s.split.map &:to_i
}
uf = UnionFind.new(N+1)

ABs.each{|a, b|
  uf.union(a, b)
}
p (1..N).map{|i|
  uf.root(i)
}.uniq.count - 1

Measured memory_bytes: 24460
def main():
    N=int(input())
    A=[]
    B=[]
    for _ in range(N):
        a,b=map(int,input().split())
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    if N%2==0:
        a_t=(A[N//2]+A[N//2-1])/2
        b_t=(B[N//2]+B[N//2-1])/2
        print(int((b_t-a_t)//0.5+1))
    else:
        a_t=A[N//2]
        b_t=B[N//2]
        print(int((b_t-a_t)//1+1))
main()


Measured memory_bytes: 25556
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin>>s;
  int64_t a,b;
  a=0,b=0;
  bool flag=false;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='A'){
      if(a==0){
        a=i;
      }
    }
    if(s.at(i)=='Z'){
      b=i;
    }
  }
  if(s.at(0)=='A'){
    a=0;
  }
  cout<<b-a+1<<endl;
}

Measured memory_bytes: 640
n = (int)(input())

max_count = 0
word_dict = {}
for i in range(n):
    s = input()
    if s in word_dict:
        word_dict[s] += 1
    else:
        word_dict[s] = 1
    if max_count < word_dict[s]:
         max_count = word_dict[s]

#print("{}".format(word_dict))

ret_dict = []
for k, v in word_dict.items():
    if v == max_count:
        ret_dict.append(k)
ret_dict.sort()

for ret in ret_dict:
    print("{}".format(ret))


Measured memory_bytes: 32096
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;

int n;
int a[N],b[N],c[N];
int dp[3][N];

int main()
{
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",a+i,b+i,c+i);
	for(int i=1;i<=n;i++)
	{
		dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
		dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
		dp[2][i]=max(dp[0][i-1],dp[1][i-1])+c[i];
	}
	printf("%d\n",max(max(dp[0][n],dp[1][n]),dp[2][n]));
	
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define N 100005
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
using namespace std;
deque<pair<int,long long> > dq;
int k,x,m,rx[N];

int main(){
    scanf("%d%d",&x,&k);
    for(int i=1;i<=k;i++) scanf("%d",&rx[i]);
    scanf("%d",&m);
    dq.push_back(mp(0,0LL));dq.push_back(mp(x,x*1LL));
    long long add = 0;int pos=0;
    while(m--){
        int t,a;scanf("%d%d",&t,&a);
        while(pos<k&&t>rx[pos+1]){
            pos++;
            add += (pos%2==1) ? rx[pos-1]-rx[pos]:rx[pos]-rx[pos-1];
            
            while(!dq.empty()&&dq.front().y+add <= 0) dq.pop_front();
            if(dq.empty()) dq.push_back(mp(0,-add)),dq.push_back(mp(x,-add));
            else if(!dq.empty()&&dq.front().x > dq.front().y+add)
                dq.push_front(mp(dq.front().x - (dq.front().y+add),-add)); 
            if(dq.front().x!=0) dq.push_front(mp(0,-add));

            while(!dq.empty()&&dq.back().y+add >= x) dq.pop_back();
            if(dq.empty()) dq.push_back(mp(0,x-add)),dq.push_back(mp(x,x-add));
            else if(!dq.empty()&&dq.back().x + x - (dq.back().y+add) <x)
                dq.push_back(mp(dq.back().x + x - (dq.back().y+add),x-add));
            if(dq.back().x!=x) dq.push_back(mp(x,x-add));
        }
        
        long long now=0;
        int l=0,r=dq.size();
        while(l+1<r){
            int mid=(l+r)>>1;
            if(dq[mid].x <= a) l=mid;
            else r = mid;
        }
        
        if(dq[l].x==a) now=dq[l].y+add;
        else now=dq[l].y+ add + (dq[l+1].y-dq[l].y)/(dq[l+1].x-dq[l].x)*(a-dq[l].x);
        if(pos%2==1) now+=t-rx[pos];
        else now-=t-rx[pos];
        
        printf("%lld\n",min(max(0LL,now),x*1LL));
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

ll inq(ll x, ll y, ll mod)
{
    if (y == 0) return 1 % mod;
    ll l = inq(x, y / 2, mod);
    if (y % 2) return l * l % mod * x % mod;
    return l * l % mod;
}

ll gcdex(ll a, ll b, ll &x, ll &y)
{
    // Solves the equation ax + by = gcd(a, b)
    // returns gcd(a, b)
    // save x and y in given values
    //
    // Correctness tested on random tests.
    //
    if (a == 0)
    {
        x = 0, y = 1;
        return b;
    }
    ll x1, y1;
    ll g = gcdex(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return g;
}

pair<ll, ll> crt(vector<ll> r, vector<ll> m)
{
    // Finds such x, that x mod m[i] = r[i] for each i
    // if such x does not exist returns {0, 0}
    //
    // Correctness tested on random tests.
    //
    int n = r.size();
    for (int i = 0; i < n; i++) r[i] %= m[i];
    ll r0 = 0, m0 = 1;
    for (int i = 0; i < n; i++)
    {
        ll r1 = r[i], m1 = m[i];
        if (m0 < m1)
        {
            swap(m0, m1);
            swap(r0, r1);
        }
        if (m0 % m1 == 0)
        {
            if (r0 % m1 != r1) return {0, 0};
            continue;
        }
        ll x, y;
        ll g = gcdex(m0, m1, x, y);
        ll u = m1 / g;
        if ((r0 - r1) % g != 0)
            return {0, 0};
        ll z = (r1 - r0) / g % u * x % u;
        r0 += z * m0;
        m0 *= u;
        if (r0 < 0) r0 += m0;
    }
    return {r0, m0};
}

const int K = 12;

ll solve(ll a, ll m)
{
    if (m == 1) return K;
    ll phi = m;
    ll z = m;
    for (int i = 2; i * i <= z; i++)
    {
        if (z % i == 0)
        {
            phi /= i;
            phi *= (i - 1);
            while (z % i == 0)
            {
                z /= i;
            }
        }
    }
    if (z > 1)
    {
        phi = phi / z * (z - 1);
    }
    ll g = __gcd(m, phi);
    ll y = solve(a, g);
    vector<ll> R = {y, inq(a, y, m)};
    vector<ll> M = {phi, m};
    pair<ll, ll> ze = crt(R, M);
    while (ze.first < K) ze.first += ze.second;
    return ze.first;
}

int main()
{
    int q;
    cin >> q;
    while (q--)
    {
        ll a, m;
        cin >> a >> m;
        ll r = solve(a, m);
        cout << r << "\n";
        //cout << r % m << " " << inq(a, r, m) << "\n";
    }
}


Measured memory_bytes: 3636
use proconio::*;
use std::cmp::*;
use std::vec::Vec;

fn calc(x: i64) -> i64 {
    if x % 4 == 0 {
        return x
    } else if x % 4 == 1 {
        return 1
    } else if x % 4 == 2 {
        return x + 1
    } else {
        return 0
    }
}
fn main() {
    input! {
        a: i64,
        b: i64,
    }
    let res = calc(b) ^ calc(a - 1);
    println!("{}", res);
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
const int MX = 1e5 + 10, MD = 1e9 + 7;
long long n, m, a[MX], ans, tmp, mx, t1, t2, ind, res;
int main(){
    ios::sync_with_stdio(0) ; cin.tie(0) ;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] > mx){
            mx = a[i];
            ind = i;
        }
    }
    ans = mx + 1;
    if(mx % 2 == 0){
        t1 = mx / 2;
        for(int i = 0; i < n; i++){
            if(ind == i)continue;
            if(abs(a[i] - t1) < ans){
                ans = abs(a[i] - t1);
                res = a[i];
            }
        }
    }
    else{
        t1 = mx / 2;
        t2 = mx / 2 + 1;
        for(int i = 0; i < n; i++){
            if(ind == i)continue;
            if(abs(a[i] - t1) < ans){
                ans = abs(a[i] - t1);
                res = a[i];
            }
            else if(abs(a[i] - t2) < ans){
                ans = abs(a[i] - t2);
                res = a[i];
            }
        }
    }
    cout << mx << " " << res;

}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
 
 
 
int main()
{
    fast;
    lli n;
    cin>>n;
    string s;
    cin>>s;
    lli cnt=0;
    for(int i=0; i<n; i++){
        while(i<n-1 && s[i]==s[i+1]) i++;
        cnt++;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
#define ld long double
//最大公約数　最小公倍数はa*b/GCD(a,b)
int64_t GCD(int64_t a,int64_t b){
    return b == 0 ? a : GCD(b, a % b);
}
int64_t LCM(int64_t a,int64_t b){
    if(a%b==0){
        return a;
    }
    if(b%a==0){
        return b;
    }
    return a/GCD(a,b)*b;
}
int64_t count_not_div(int64_t n,int64_t a,int64_t b,int64_t c){
    return (n-(n/a+n/b-n/c));
}
int main(){
    int64_t a,b,c,d;
    cin>>a>>b>>c>>d;
    int64_t lcm = LCM(c,d);
    cout<<count_not_div(b,c,d,lcm)-count_not_div(a-1,c,d,lcm)<<endl;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {

    static class Node {
        int x, y;
        char ch;
        Node(int x, int y, char ch) {
            this.x = x;
            this.y = y;
            this.ch = ch;
        }
    }
    static int n;
    static Node[] a;

    private static long process1() {
        Map<Integer, List<Node>> M = new HashMap();
        for (int i = 0; i < n; i++) {
            int tem = a[i].x + a[i].y;
            if (a[i].ch != 'U' && a[i].ch != 'R') continue;
            if (M.containsKey(tem) == false) {
                List<Node> list = new ArrayList();
                M.put(tem, list);
            }
            List<Node> list = M.get(tem);
            list.add(a[i]);
        }
        long ans = Long.MAX_VALUE;
        for (List<Node> list : M.values()) {
            Collections.sort(list, (a, b) -> (a.x - b.x));
            for (int i = 1; i < list.size(); i++) {
                if (list.get(i - 1).ch != 'R' || list.get(i).ch != 'U') continue;
                ans = Math.min(ans, (list.get(i).x - list.get(i - 1).x) * 10L);
            }
        }
        return ans;
    }

    private static long process2() {
        Map<Integer, List<Node>> M = new HashMap();
        for (int i = 0; i < n; i++) {
            int tem = a[i].x;
            if (a[i].ch != 'U' && a[i].ch != 'D') continue;
            if (M.containsKey(tem) == false) {
                List<Node> list = new ArrayList();
                M.put(tem, list);
            }
            List<Node> list = M.get(tem);
            list.add(a[i]);
        }
        long ans = Long.MAX_VALUE;
        for (List<Node> list : M.values()) {
            Collections.sort(list, (a, b) -> (a.y - b.y));
            for (int i = 1; i < list.size(); i++) {
                if (list.get(i - 1).ch != 'U' || list.get(i).ch != 'D') continue;
                ans = Math.min(ans, (list.get(i).y - list.get(i - 1).y) * 5L);
            }
        }
        return ans;
    }

    private static void rotate() {
        for (int i = 0; i < n; i++) {
            int nx = a[i].y, ny = -a[i].x;
            char nch;
            if (a[i].ch == 'U') nch = 'R';
            else if (a[i].ch == 'R') nch = 'D';
            else if (a[i].ch == 'D') nch = 'L';
            else nch = 'U';
            a[i].x = nx;
            a[i].y = ny;
            a[i].ch = nch;
        }
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        a = new Node[n];
        for (int i = 0; i < n; i++) {
            int x = scan.nextInt();
            int y = scan.nextInt();
            char ch = scan.next().charAt(0);
            a[i] = new Node(x, y, ch);
        }
        long ans = Long.MAX_VALUE;
        for (int k = 0; k < 4; k++) {
            ans = Math.min(ans, process1());
            rotate();
        }
        ans = Math.min(ans, process2());
        rotate();
        ans = Math.min(ans, process2());
        if (ans == Long.MAX_VALUE) System.out.println("SAFE");
        else System.out.println(ans);
    }
}


Measured memory_bytes: 107276
//  PDF 解法2.横に切って、その後縦に切る
import java.util.*;

public class Main {

    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;

        if (s.equals("SUN"))
            ans = 7;
        else if (s.equals("MON"))
            ans = 6;
        else if (s.equals("TUE"))
            ans = 5;
        else if (s.equals("WED"))
            ans = 4;
        else if (s.equals("THU"))
            ans = 3;
        else if (s.equals("FRI"))
            ans = 2;
        else if (s.equals("SAT"))
            ans = 1;

        System.out.println(ans);

    }
}

Measured memory_bytes: 21332
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn main() {
  input! {
    k: usize,
    a: usize, b:usize
  };

  for x in a..b + 1 {
    if x % k == 0 {
      println!("OK");
      std::process::exit(0);
    }
  }
  println!("NG");
}


Measured memory_bytes: 2156
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}


int main(){
    int n,k;
    cin>>n>>k;
    set<int> d;
    rep(i,0,k) {int t;cin>>t; d.insert(t);};
    rep(i,n,100000){
        int t=i,found=0;
        while(t){
            if(d.find(t%10)!=d.end()) {found=1;break;}
            t/=10;
        }
        if(found) continue;
        cout<<i<<endl; break;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
   int a;
    vector < long long> b;
    cin >> a;
    int B;
    for (int i=0; i<a;i++){
        cin >> B;
        b.push_back(B);
    }
    int f=0,g=0;
    while (f != 1){
        for (int i=0; i<a;i++){
            if(b[i]%2!=0){
                f=1;
                
            }
        }
        
        if(f==0){
            g++;
            for (int i=0; i<a;i++){
                b[i] = b[i]/2;
                
            }
        }
    }
    cout << g <<endl;
    
    
return 0;
}

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

int main() {
  int A, B, C, D, E, F;
  double N;
  cin >> A >> B >> C >> D >> E >> F;
  N = E / 100.0;
  vector<int> x;
  for (int i = 0; 100 * A * i <= F; i++) {
    for (int j = 0; 100 * B * j <= F; j++) {
      int tmp = 100 * A * i + 100 * B * j;
      if (tmp > F) continue;
      x.push_back(tmp);
    }
  }
  vector<int> y;
  for (int i = 0; C * i <= F; i++) {
    for (int j = 0; D * j <= F; j++) {
      int tmp = C * i + D * j;
      if (tmp > F) continue;
      y.push_back(tmp);
    }
  }
  double mx = 0.0;
  int w = 100 * A, s = 0;
  for (int i = 0; i < x.size(); i++) {
    for (int j = 0; j < y.size(); j++) {
      if (x[i] + y[j] > F || x[i] + y[j] == 0) continue;
      double tmp = double(y[j]) / double(x[i]);
      if (N >= tmp) {
        if (mx < tmp) {
          mx = tmp;
          w  = x[i] + y[j];
          s  = y[j];
        }
      }
    }
  }
  cout << w << " " << s << endl;
}

Measured memory_bytes: 1400
n,p = map(int,input().split())	
a = list(map(int,input().split()))
ass = 0
g = 0
k = 0

for i in range(n):
    if a[i] % 2 == 0:
        g += 1
    else:
        k += 1
        


if p == 0:
    rr = 1
    tt = 1
    jj = 1
    for i in range(g):
        rr = rr * (g-i)
        tt = tt * (i+1)
        if tt != 0:
            jj += rr //tt
    jkl = 1
    rr = 1
    tt = 1
    for i in range(k//2):
        rr = rr *(k-2*i)*(k-2*i-1)
        
        tt = tt * (2*i+1) * (2*i+2)

        if tt != 0:
            jkl += rr//tt
    ass += jj*jkl
else:
    rr = 1
    tt = 1
    jkl = 1
    for i in range(g):
        rr = rr * (g-i)
        tt = tt * (i+1)
        if tt != 0:
            jkl += rr //tt
    
    rr = 1
    tt = 1
    jj = 0
    if k % 2 == 1:
        u = k//2+1
    else:
        u = k//2
    for i in range(u):
        if i == 0:
            rr = k
            tt = 1
        else:
            rr = rr*(k-2*i)*(k-2*i+1)
            tt = tt*(2*i)*(2*i+1)
        jj += rr//tt
    ass += jj*jkl
print(int(ass))

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  for (int i = a; i <= b; i++)
  {
    if (c % i == 0)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<vector<int>> v;
  rep(i,N-1){
    int a, b;
    cin >> a >> b;
    if(a > b) swap(a,b);
    v.push_back({a,b});
  }

  ll ret = 0;
  for(int i=N; i>0; i--){
    ret += (ll)i * (i+1) / 2;
  }

  rep(i,v.size()){
    ll a = v[i][0];
    ll b = v[i][1];

    ll tmp = a * (N+1-b);
    ret -= tmp;
  }

  cout << ret << endl;
  
  return 0;
}



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

int main(void){
  int N; cin >> N;
  int D, X;
  cin >> D >> X;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  int ans = 0;
  for(int a_idx = 0; a_idx < N; a_idx++){
    for(int day = 1; day <= D; day+=A[a_idx]){
      ans++;
    }
  }
  cout << ans + X << endl;
}


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

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N; cin >> N;
	string s = "";
	ll temp = 1;
	while (N>0) {
		if (N % 26 == 0)s += 'z';
		else s += 'a' + (N % 26) -1;
		if (N % 26 == 0) {
			N /= 26;
			N--;
		}
		else N /= 26;
		//if (N % 26 == 0) N--;
	}
	reverse(s.begin(), s.end());
	cout << s << endl;
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main(void)
{
    int i, j, k, l, m, n;
    cin >> n >> m >> l;
    int A[n][m], B[m][l];
      
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            cin >> A[i][j];
        }
    }
    for(i = 0; i < m; i++){
        for(j = 0; j < l; j++){
        cin >> B[i][j];
        }
    }
    for(i = 0; i < n; i++){
        long int multip;
        for(j = 0; j < l; j++){
            multip = 0;
            for(k = 0; k < m; k++){
            multip += A[i][k] * B[k][j];
            }
            if(j == l-1) break;
            cout << multip << ' ';
        }
        cout << multip << endl;
    }
}


Measured memory_bytes: 3192
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int Cin()
{
    int n;
    cin >> n;
    return n;
}

int main()
{
    string S, T, U;
    int A, B;
    cin >> S >> T >> A >> B >> U;
    if (U == S) --A;
    else --B;
    cout << A << ' ' << B << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
  int n,i,frame=0;
  int *a;
  double average=0.0,temp,dist=101.0;
  
  scanf("%d",&n);
  a=(int*)calloc(n, sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    average+=a[i];
  }
  average=average/n;
  
  for(i=0;i<n;i++){
    temp=a[i]-average;
    if(temp<0){
      temp=0-temp;
    }
    
    if(dist>temp){
      dist=temp;
      frame=i;
    }
  }
  
  printf("%d",frame);
  free(a);
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> jobs[m];
  
  rep(i,n){
    int a,b;
    cin >> a >> b;
    if(a>m)continue;
    jobs[m-a].push_back(b);
  }
  priority_queue<int> p;
  ll ans = 0;
  for(int i=m-1;i>=0;i--){
    for(int j : jobs[i]){
      p.push(j);
    }
    if(!p.empty()){
      ans += p.top();
      p.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5504
def dfs(start,path):
    res = 0
    path.append(start)
    if len(path) == N:
        res += 1
        return res
    for i in graph[start]:
        if i not in path:
            res += dfs(i,path)
            path.pop()
    return res

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
print(dfs(0,[]))

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

int main(){
    int a,b; cin>>a>>b;
    int ans=0;
    for(int i=a;i<=b;i++){
        string s=to_string(i);
        if(s[0]==s[4]&&s[1]==s[3]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, k) = readIntegerList()
    val dList = readIntegerList().toSet()

    var ans = n
    while (true) {
        var f = true
        for (c in ans.toString()) {
            if (dList.contains(c - '0')) {
                f = false
            }
        }

        if (f) {
            out.println(ans)
            return
        }

        ans++
    }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 41980
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while (a>0 || c>0 ) {
    c-= b;
    if ( c<=0 ) {
      cout << "Yes" << endl;
      break;
    }
    a-= d;
    if ( a<=0  ) {
      cout << "No" << endl;
      break;
    }
  }
}

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

int main() {
  string s;
  cin >> s;
  string y = s.substr(0, 4);
  string m = s.substr(5, 2);
  string d = s.substr(8, 2);
  int Y = stoi(y);
  int M = stoi(m);
  int D = stoi(d);
  if(Y <= 2019 && M <= 4 && D <= 30) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}

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

int main()
{
    float N;
    cin >> N;
    int ans1 = floor(N / 1.08);
    int ans2 = ceil(N / 1.08);
    if (floor(ans1 * 1.08) == N)
        cout << ans1 << endl;
    else if (floor(ans2 * 1.08) == N)
        cout << ans2 << endl;
    else
        cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 384