akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    internal class Solution
    {
        public int A, B;

        public void Run()
        {
            var line = Input.ReadIntArray();
            A = line[0];
            B = line[1];

            Console.WriteLine((A * B) % 2 == 0 ? "Even" : "Odd" );
        }
       
    }
    
    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <cstring>
#include<cstdio>
using namespace std;

int ans = -1000000000;
int a[10];
int n, f[100][10], p[100][11];
int max(int ans, int score)
{
	if (ans > score)
		return ans;
	else
		return score;
}
void func(void){
	int score = 0, cnt;
	for (int i = 0; i < n; i++){
		cnt = 0;
		for (int j = 0; j < 10; j++){
			if (a[j] == 1 && f[i][j] == 1)
				cnt++;
		}
			score += p[i][cnt];
	}
	ans = max(ans, score);
}
void dfs(int pos)
{
	if (pos == 10){
		int flag = 0;
		for (int i = 0; i < 10; i++){
			if (a[i] == 1)
				flag = 1;
		}
		if (flag)
		func();
		return;
	}
		a[pos] = 0; dfs(pos + 1);
		a[pos] = 1; dfs(pos + 1);

}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++)
			scanf("%d", &f[i][j]);
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < 11;j++)
		scanf("%d", &p[i][j]);

	dfs(0);
	cout << ans << endl;
	
	return 0;
}

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

struct Dex{
  char word[31];
  int page[1000];
  int n;
} dex[128];

int main(){
  int p, i, j = 0, k, l, tmp, min;
  char w[31];
  while(scanf("%s%d", w, &p) != EOF){
    for(i = 0;i < j;i++) if(strcmp(dex[i].word, w) == 0) break;
    if(i == j){
      strcpy(dex[j++].word, w);
      dex[j - 1].page[0] = p;
      dex[j - 1].n = 1;
    }else
      dex[i].page[dex[i].n++] = p;
  }

  for(i = 0;i < j;i++){
    for(k = 0;k < dex[i].n;k++){
      min = k;
      for(l = k + 1;l < dex[i].n;l++) min = dex[i].page[min] > dex[i].page[l] ? l : min;
      if(min != k){
	tmp = dex[i].page[min];
	dex[i].page[min] = dex[i].page[k];
	dex[i].page[k] = tmp;
      }
    }
  }

  for(i = 0;i < j;i++){
    min = i;
    for(k = i + 1;k < j;k++) if(strcmp(dex[min].word, dex[k].word) > 0) min = k;
    if(min != i){
      dex[127] = dex[min];
      dex[min] = dex[i];
      dex[i] = dex[127];
    }
  }
  for(i = 0;i < j;i++){
    puts(dex[i].word);
    for(k = 0;k < dex[i].n;k++){ 
      if(k != 0) putchar(' ');
      printf("%d", dex[i].page[k]);
    }
    puts("");
  }

  return 0;
}

Measured memory_bytes: 784
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    vector<int> ans(n, 0);
    rep(i, n) {
        if (s[i] == 'R') ++cnt;
        else {
            ans[i] += cnt / 2;
            ans[i-1] += cnt - cnt / 2;
            cnt = 0;
        }
    }
    cnt = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == 'L') ++cnt;
        else {
            ans[i] += cnt / 2;
            ans[i+1] += cnt - cnt / 2;
            cnt = 0;
        }
    }
    rep(i, n) {
        if (i >= 1) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3816
S = input()
list = ['A', 'C', 'G', 'T']

max_length = 0
for i in range(len(S)):
  if S[i] in list:
    for j in range(i, len(S)):
      s = S[j]
      if s not in list:
        break
      else:
        str = S[i:j+1]
        if len(str) > max_length:
          max_length = len(str)

print(max_length)

Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

int main() {
  int n;
  cin >> n;
  int a, b;
  cin >> a >> b;
  if ((b - a) & 1) {
    cout << "Borys" << endl;
  } else {
    cout << "Alice" << endl;
  }
}

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

int main(void) {
  string str;
  long n,blue,red,w,a;
  
  getline(cin, str);
  istringstream s(str);
  s >> n >> blue >> red;
  
  if(blue == 0 && red == 0){
    cout << 0 << endl;
  }
  
  else{
    if((blue + red) <= n){
      w = n / (blue + red);
      a = n % (blue + red);
      if(a>blue){
        w++;
        a = 0;
      }
      cout << w * blue + a << endl;
    }
    else{
      if(n>=blue){
        cout << blue << endl;
      }
      else {
        cout << n << endl;
      }
    }
  } 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

int main(){
    int x, t;
    cin >> x >> t;
    if(x - t > 0){
        cout << x - t << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

char toLowerCase(char c){
  if(isLowerCase(c)){
    return c;
  }else{
    return c+'a'-'A';
  }
}
char toUpperCase(char c){
  if(isLowerCase(c)){
    return c-('a'-'A');
  }else{
    return c;
  }
}
ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
void func(vector<int>& l, int depth, int idx){
  ;
}
int main() {
  int n;cin>>n;
  int ans=10-n/200;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3640
N,Y=map(int,input().split())
A=[]
for i in range(Y//10000+1):
    for j in range((Y-i*10000)//5000+1):
        c1=(Y-10000*i-5000*j)//1000
        c2=N-i-j
        if c1==c2:
            A=[i,j,c1]
            break
        if c1!=c2:
            continue
if len(A)==0:
    print("-1 -1 -1")
else:
    A[2]=int(A[2])
    print(str(A[0])+" "+str(A[1])+" "+str(A[2]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	int x,a,b;
	cin >> x >> a >> b;
	if(a>=b)
		cout << "delicious" << endl;
	else{
		if(b-a>x)
			cout << "dangerous" << endl;
		else
			cout << "safe" << endl;
	}
}

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

int main(void){
  int n; scanf("%d",&n);
  int b[n-1];
  rep(i,n-1) scanf("%d",&b[i]);
  int sum = 0;
  sum = b[0];
  for(int i = 0; i < n-2; i++){
    sum += min(b[i],b[i+1]);
  }
  sum += b[n-2];
  printf("%d",sum);
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 40;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};



int main()
{
  int n; cin >> n;
  vector<vector<ll>> vec(10, vector<ll>(10, 0));
  for(int i = 1; i <= n; ++i) {
    string s = to_string(i);
    if(s.back() == '0') continue;
    ++vec[s.front()-'0'][s.back()-'0'];
  }
  ll ans = 0;
  for(int i = 1; i <= 9; ++i) {
    for(int j = 1; j <= 9; ++j) {
      ans += vec[i][j]*vec[j][i];
    }
  }
  cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i,n){
        int x;
        cin >> x;
        a[x] = i+1;
    }
    rep(i,n){
        if(i>0) cout << " ";
        cout << a[i+1];
    }
    cout << endl;
    
    return 0;
} 

Measured memory_bytes: 1152
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	bool leap[3001];
	for (int i = 0; i < 3001; i++) {
		int y = i;
		if (y % 4 != 0) { leap[i] = false; }
		else if(y%100!=0){
			leap[i] = true;
		}
		else if (y % 400 != 0) {
			leap[i] = false;
		}
		else {
			leap[i] = true;
		}
	}
	int a, b;
	bool first = true;
	while (cin >> a >> b) {
		bool ever = false;
		if (a == 0 && b == 0) { break; }
		if (!first) { cout << endl; }
		for (int i = a; i <= b; i++) {
			if (leap[i]) { ever = true; cout << i << endl; }
		}
		if (!ever)
		{
			cout << "NA" << endl;
		}first = false;
	}
	return 0;
}


Measured memory_bytes: 3172
def main():
    n = input()
    aa = map(int, raw_input().split())
    length = sum(aa)
    s = 0
    for i, a in enumerate(aa):
        s += a
        if s >= length / 2.0:
            break
    if s == length / 2.0:
        print 0
        return
    print min(s * 2 - length, length  - (s - aa[i]) * 2)


main()


Measured memory_bytes: 19992
#include<iostream>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < 10; i++) {
    if (n % i == 0 && n / i < 10) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define int long long
#define ll long long
using namespace std;
int a,n,p[100010];
signed main(){
    cin>>a>>n;
    rep(i,n)cin>>p[i];
    sort(p,p+n);
    int j=0,ans=0,res=110;
    rep(i,110){
        if(p[j]==i){
            j++;
            continue;
        }
        else if (res>abs(i-a))
            {
                ans=i;
                res=abs(i-a);
            }
            
    }
    cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;


int main() {
    int l, r;
    cin >> l >> r;
    r++;
    constexpr int M = 35000;
    vector<bool> is_prime(M+1, true);
    vector<int> prime;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= M; ++i) {
        if(is_prime[i]) prime.emplace_back(i);
        for (auto &&j : prime){
            if(i*j > M) break;
            is_prime[i*j] = false;
            if(i % j == 0) break;
        }
    }
    vector<int> ans(r-l), remain(r-l);
    for (int i = 0; i < r-l; ++i) {
        remain[i] = l+i;
    }
    for (auto &&p : prime) {
        int j = l+(p-l%p)%p;
        while(j < r){
            while(remain[j-l]%p == 0){
                ans[j-l]++;
                remain[j-l] /= p;
            }
            j += p;
        }
    }
    int ret = 0;
    for (int i = 0; i < r - l; ++i) {
        if(remain[i] != 1) ans[i]++;
        ret += is_prime[ans[i]];
    }
    cout << ret << "\n";
    return 0;
}


Measured memory_bytes: 10772
N=int(input())
S=input()
list1=[0]*N
for i in reversed(range(N)):
    if i==N-1 and S[i]==".":
        list1[i]+=1
    elif i==N-1:
        list1[i]=0
    elif S[i]==".":
        list1[i]=list1[i+1]+1
    else:
        list1[i]=list1[i+1]   
list2=[]
for i in range(N+1):
    if i==0:
        tmp=N-list1[0]
    elif i==N:
        tmp=list1[0]
    else:
        tmp=i-list1[0]+2*list1[i]
    list2.append(tmp)
print(min(list2))

Measured memory_bytes: 19304
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  int n, m; cin >> n >> m;
  vector<string> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  bool flag = false;
  rep(i, n-m+1) rep(j, n-m+1) {
    bool equal = true;
    rep(k, m) rep(l, m) {
      if(b[k][l] != a[i+k][j+l]) equal = false;
    }
    if(equal) {
      flag = true;
      break;
    }
  }
  cout << (flag ? "Yes" : "No") << '\n';
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")

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

	char c;
	cin >> c;

	string s = { 'a','i','u','e','o' };
	rep(i, 5)
	{
		if (c == s[i])
		{
			cout << "vowel";
			break;
		}
		if (i == 4)
		{
			cout << "consonant";
		}
	}
	cout << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n,k;
vector<int> d;

void input(){
    cin >> n >> k;
    d.resize(k);
    for(int i=0;i<k;i++) cin >> d[i];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    vector<int> num = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    vector<int> canuse;
    set_difference(num.begin(), num.end(), d.begin(), d.end(), back_inserter(canuse));
    sort(canuse.begin(), canuse.end());
    // for(auto e:canuse) cout << e << endl;
    string ans = "a";
    for(int i=n;i<=10*n;i++){
        string tmp = to_string(i);
        int cnt = 0;
        for(auto s:tmp){
            if(binary_search(canuse.begin(), canuse.end(), int(s-'0'))){
                cnt++;
            }
        }
        if(cnt == tmp.size()){
            ans = tmp;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n, a, b, tmp; cin >> n;
  bool flag = true;
  for (int i=1; i<10; ++i) {
    if(((n/i)<10) && (n%i)==0) {
      a = i;
    } else continue;
    if((b/a)<10 && (b%a)==0) {
      cout << "Yes" << endl;
      flag = false;
      break;
    }
  }
  if (flag) cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

long N, Q;
string s;
vector<pair<char, char>> Qs;

// -1: 左から落ちる
// 0: 落ちない
// 1: 右から落ちる
long is_down(long pos) {
  if (pos == -1) return -1;
  if (pos == N) return 1;
  for (auto it: Qs) {
    if (s[pos] == it.first) {
      pos += it.second;
      if (pos == -1) return -1;
      if (pos == N) return 1;
    }
  }
  return 0;
}

// left は落ちること保証, right は落ちないこと保証
long search_left_down(long left, long right) {
  long middle = (left + right) / 2;
  //cerr << "search_left_down: left=" << left << ", right=" << right << ", middle=" << middle << endl;
  if (middle == left) return left;
  //cerr << "------- test" << endl;
  bool middle_left_down = is_down(middle) == -1;
  if (middle_left_down) return search_left_down(middle, right);
  else return search_left_down(left, middle);
}

// left は落ちないこと保証, right は落ちること保証
long search_right_down(long left, long right) {
  //cerr << "search_right_down: left=" << left << ", right=" << right << endl;
  long middle = (left + right) / 2;
  if (middle == left) return right;
  bool middle_right_down = is_down(middle) == 1;
  if (middle_right_down) return search_right_down(left, middle);
  else return search_right_down(middle, right);
}

int main(void) {
  cin >> N >> Q;
  cin >> s;
  rep(i, Q) {
    char t, d;
    cin >> t >> d;
    char move = d == 'L' ? -1 : 1;
    Qs.push_back(pair<char, char>(t, move));
  }

  bool ml_left_down = is_down(0) == -1;
  bool mr_left_down = is_down(N-1) == -1;

  bool ml_right_down = is_down(0) == 1;
  bool mr_right_down = is_down(N-1) == 1;

  //cerr << "is_down(0): " << is_down(0) << ", is_down(N-1): " << is_down(N-1) << endl;

  long left_down;
  if (not ml_left_down) left_down = -1;
  else if (mr_left_down) left_down = N-1;
  else left_down = search_left_down(0, N-1);
  //cerr << "search_left_down(0, N-1): " << search_left_down(0, N-1) << endl;

  long right_down;
  if (not mr_right_down) right_down = N;
  else if (ml_right_down) right_down = 0;
  else right_down = search_right_down(0, N-1);

  //cerr << "left_down: " << left_down << ", right_down: " << right_down << endl;

  cout << (right_down - left_down - 1) << endl;
  return 0;
}


Measured memory_bytes: 1024
K = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
ans = a[K-1]
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int n,v[5005];
ll a,b,f[5005];
int main()
{
	scanf("%d%lld%lld",&n,&a,&b);
	for(int i=1;i<=n+1;i++)
	{
		f[i]=1000000000000000000;
		if(i<=n)scanf("%d",&v[i]);
		else v[i]=n+1;
		ll sum=0;
		int maxx=0;
		for(int j=i-1;j>=1;j--)
		{
			if(v[j]>v[i])sum+=a;
			else if(v[j]>maxx)
			{
				f[i]=min(f[i],f[j]+sum);
				sum+=b;
			}
			else sum+=b;
		}
		f[i]=min(f[i],sum);
	}
	printf("%lld\n",f[n+1]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const int MOD = 1e9 + 7;

#define MAX 1100
#define int long long

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


    int N;
    int temp[MAX] = {};
    int ans = 1;
    cin>>N;

    for(int i = 2; i <= N; i++){
        int x = i;
        
        for(int j = 2; j*j <= x; j++){
            while(x%j == 0){
                temp[j]++;
                x /= j;
            }
        }
        temp[x]++;
    }
    
    for(int i = 2; i <= N; i++){
        ans *= temp[i]+1;
        ans %= MOD;
        // cout<<i<<" "<<temp[i]<<endl;
    }

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


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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>; 

int gcd(int a,int b){//ユーグリッド
    if(a%b == 0) return b;

    return(gcd(b,a%b));
}

int main(){
    int a,b; cin>>a>>b;
    if(a<b) {
        int t = a;
        a = b;
        b = t;
    }
    int g = gcd(a,b);
    cout<<(ll)a*b/g<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
 
ll go(ll n,ll arr[])
{
    ll aa[n];
    ll i;
    aa[0] = 0;
    aa[1] = abs(arr[1]-arr[0]);
    //cout << aa[0] << " " << aa[1] << endl;
    
    for(i=2;i<n;i++)
    {
        aa[i] = min(abs(arr[i]-arr[i-1])+aa[i-1],abs(arr[i]-arr[i-2])+aa[i-2]);
        //cout << aa[i] << endl;
    }
    return aa[n-1];
}
 
int main(void){
    // Your code here!
    ll n,i;
    
    cin >> n;
    
    ll arr[n];
    
    for(i=0;i<n;i++)
    {
        cin >> arr[i];
    }
    
    ll ans = go(n,arr);
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++) 
using namespace std;
queue<int>q;
int nedge=0,p[1000010],nex[1000010],head[1000010],rp[1000010];
int dist[200010],vis[200010],n,m,s,t,g,l;
inline void addedge(int x,int y){
	p[++nedge]=y;nex[nedge]=head[x];head[x]=nedge;
}
inline void spfa()
{
	memset(dist,0x3f,sizeof dist);
	dist[1]=0;q.push(1);vis[1]=1;
	while(!q.empty())
	{
		int now=q.front();q.pop();
		for(int k=head[now];k;k=nex[k])
		if(dist[p[k]]>dist[now]+1)
		{
			dist[p[k]]=dist[now]+1;
			if(!vis[p[k]]){vis[p[k]]=1;q.push(p[k]);}
		}
		vis[now]=0;
	}
}
int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x,y;cin>>x>>y;
		addedge(x,y);
	}
	spfa();
	if(dist[n]>2)puts("IMPOSSIBLE");
	else puts("POSSIBLE");
}

Measured memory_bytes: 10368
from bisect import bisect

def solve(N, A, B, H, total, M):
    class Solver:
        def __init__(self, N, A, B, H, total):
            self.N = N
            self.B = B
            self.BA = A-B
            self.H = H
            self.len = idiv(total, B)

        def __getitem__(self, k):
            Bk = self.B * k
            cnt = 0
            for i in range(self.N):
                h = H[i] - Bk
                if h < 0:
                    continue
                cnt += idiv(h, self.BA)
                if cnt > k:
                    return -1
            #print("[%d]"%k, cnt, k)
            return 1 if cnt <= k else -1

        def __len__(self):
            return self.len

    k0 = idiv(total, (B*N+A))
    s = Solver(N, A, B, H, total)
    k = bisect(s, 0, k0, idiv(M, B))
    print(k)

def main():
    input = open(0).readline
    N, A, B = map(int, input().split())
    H = [0]*N
    M = 0
    total = 0
    for i in range(N):
        h = int(input())
        H[i] = h
        M = max(M, h)
        total += h
    solve(N, A, B, H, total, M)

def idiv(x, y):
    if x <= 0:
        return 0
    q, r = divmod(x, y)
    return q + (1 if r > 0 else 0)



main()


Measured memory_bytes: 7028
N = input()
K = int(input())
L = len(N)
"""
dp[i][j][k]：Nを頭からi桁まで見たとき、残りの使える0以外の個数がj個で、そこまでの値がNのi-1桁目までより小さい/同じ（小さいとk=1）時のi桁目までのとりうる個数
"""
dp = [[[0 for _ in range(2)] for _ in range(K+1)] for _ in range(L+1)]
dp[0][K][0] = 1

for i in range(L):
    digit = int(N[i])
    for num_rest_non_zero in range(K+1):
        for flag_less in range(2):
            """
            ・先頭はN[0]以下の値で決める
            ・もし現時点でNより小さいなら、次のi桁目は0以外の数字を使える個数に余裕があれば、
            i桁目に1~9まで使うこともできるし、0を使うこともできる
            ・既に0以外を使える個数がなくなって（使い切って）いれば、0をあてるしかない
            ・i-1桁目までがNと一致している（flag_less = 0）であれば、nのi桁目以下の値からしか選べない
            """

            # 先頭はN[0]以下の値しか選べない
            if i == 0:
                d = digit
            elif num_rest_non_zero == 0:
                d = 0
            elif flag_less == 1:
                d = 9
            else:
                d = digit

            for num in range(d+1):
                
                if flag_less == 0 and num == digit:
                    flag_less_nxt = 0
                else:
                    flag_less_nxt = 1

                # 0以外を使う場合
                if num != 0:
                    dp[i+1][num_rest_non_zero-1][flag_less_nxt] += dp[i][num_rest_non_zero][flag_less]
                else:
                    # i桁目に0をあてるので残数が減らない
                    dp[i+1][num_rest_non_zero][flag_less_nxt] += dp[i][num_rest_non_zero][flag_less]


print(sum(dp[L][0]))
#print(dp)

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

int main() {
	int n;
	cin>>n;
	set<string> st;
 	for (int i=0; i<n; i++) {
		string s;
		cin>>s;
		st.insert(s);
	}
	cout << st.size();
	return 0; 	
}

Measured memory_bytes: 19124
#include<iostream>

using std::cout;
using std::endl;
using std::cin;


void checkMaxMin(long& max, long& min, long& input) {
    if (input > max) {
        max = input;
    }
    if (input < min) {
        min = input;
    }
    return;
}


int main(void) {
    long n;
    cin >> n;
    long sum = 0;
    long max;
    long min;

    long input;
    for (long i = 0; i < n; i++) {
        cin >> input;
        sum += input;
        if (i == 0) {
            max = input;
            min = input;
        } else {
            checkMaxMin(max, min, input);
        }
    }

    cout << min << " " << max << " " << sum << endl;

    return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 505;
int n, a[N];
int main(){
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n * 2; i++) cin >> a[i];
	sort(a + 1, a + 2 * n + 1);
	for (int i = n * 2; i; i -= 2) {
		ans += a[i - 1];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 6700417
#define h2 (N-1)
using namespace std;
int H[N];

int CtoN(char c){
  if(c == 'A') return 1;
  if(c == 'C') return 2;
  if(c == 'G') return 3;
  return 4;
}

int StoN(char str[]){
  int n = strlen(str);
  int res = 0;
  for(int i=0;i<n;i++)
    res = res*5 + CtoN(str[i]);
  return res;
}



void Insert(char str[],int i){
  int k = StoN(str);
  int hash = k%N;
  while(H[hash] != 0) hash = (hash + k%h2)%N;
  H[hash] = i;
}

char S[1000001][11];
bool Find(char str[]){
  int k = StoN(str);
  int hash = k%N;
  while(H[hash]){
    if(strcmp(str,S[H[hash]]) == 0) return 1;
    hash = (hash+k%h2)%N;
  }
  return 0;
}

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

  for(int i=1;i<=n;i++){
    char q[11]; 
    scanf("%s %s",q,S[i]);
    if(q[0] == 'i') Insert(S[i],i);
    else printf("%s\n",(Find(S[i])? "yes":"no"));
  }
  
  return 0;
}

Measured memory_bytes: 37604
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;


int main(){
    string s;
    cin >> s;
    ll n=s.length();
    ll ans=0;
    rep(i,n){
        if(s[i]=='o') ans++;
    }
    if(ans+15-n>=8) cout << "YES" << endl;
    else cout << "NO" << endl;
}



Measured memory_bytes: 3596
#include <iostream>
    #include <queue>
    #include <vector>
    #include <string>
    using namespace std;
     
    const long long INF = 1e18;
    const int di[] = {-1, 0, 1, 0};
    const int dj[] = {0, -1, 0, 1};
     
    int main() {
      int h, w, k;
      cin >> h >> w >> k;
      int si, sj, ti, tj;
      cin >> si >> sj >> ti >> tj;
      --si; --sj; --ti; --tj;
      vector<string> g(h);
      for (int i = 0; i < h; ++i) cin >> g[i];
     
      auto toId = [&](int i, int j, int v) {
        return (i*w+j)*4 + v;
      };
      auto modCeilK = [&](long long x) {
        return (x + k - 1) / k * k;
      };
     
      vector<long long> dist(h*w*4, INF);
      priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
      auto push = [&](int i, int j, int v, long long x) {
        int id = toId(i, j, v);
        if (dist[id] <= x) return;
        dist[id] = x;
        q.emplace(x,id);
      };
      for (int v = 0; v < 4; ++v) push(si, sj, v, 0);
      while (!q.empty()) {
        long long d = q.top().first;
        int id = q.top().second;
        q.pop();
        if (dist[id] != d) continue;
        int i = id / w / 4;
        int j = id /4 % w;
        int v = id % 4;
        for (int nv = 0; nv < 4; ++nv) {
          push(i, j, nv, modCeilK(d));
          int ni = i+di[v], nj = j+dj[v];
          if (0 <= ni && ni < h && 0 <= nj && nj < w) {
            if (g[ni][nj] == '.') {
              push(ni, nj, v, d+1);
            }
          } 
        }
      }
     
      long long ans = INF;
      for (int v = 0; v < 4; ++v) ans = min(ans, dist[toId(ti, tj, v)]);
      if (ans == INF) cout << -1 << endl;
      else {
        ans = modCeilK(ans)/k;
        cout << ans << endl;
      }
      return 0;
    }

Measured memory_bytes: 44036
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
#define ull unsigned long long
#define MOD 10007
int main()
{
    ull dp[1005][8] = { 0 };
    int n;
    int responsible[1005] = { 0 };
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        char c;
        cin >> c;
        if (c == 'J')responsible[i] = 4;
        else if (c == 'O')responsible[i] = 2;
        else responsible[i] = 1;
    }
    int s = 4 | responsible[0];
    for (int i = 1; i<8; i++){
        if (s == (i&s))dp[0][i] = 1;
    }
    for (int i = 1; i < n; i++){
        for (int j = 1; j < 8; j++){
            if (responsible[i] & j){
                for (int k = 1; k < 8; k++){
                    if (k&j) dp[i][j] = (dp[i][j] + dp[i - 1][k]) % MOD;
                }
            }
        }
    }
    int ans = 0;
    for (int i = 1; i < 8; i++)ans = (ans + dp[n-1][i]) % MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 3176
def readinput():
    s=input()
    return s

def main(s):
    count=0
    t=['0','1']
    for i in range(len(s)):
        if s[i]==t[i%2]:
            count+=1
    return min(count,len(s)-count)

if __name__=='__main__':
    s=readinput()
    ans=main(s)
    print(ans)


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

int main() {
  
  int N, M;
  cin >> N >> M;
  vector<int> vec1(M), vec2(M);
  rep(i, M){
  cin >> vec1.at(i) >> vec2.at(i);
  }
  vector<int> vecsum(N);
  rep(i, N){
  vecsum.at(i) = 0;
  }
  rep(i, N){
  	rep(k, M){
      if(vec1.at(k) == i + 1 || vec2.at(k) == i + 1){
  		vecsum.at(i) += 1;
  	  }
    }
  }
  rep(i, N){
  cout << vecsum.at(i) << endl;
  }
}

Measured memory_bytes: 3484
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)
#define _popcnt __builtin_popcount

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

	int A[3][3], N, B;
	REP(i, 3) REP(j, 3) cin >> A[i][j];
	bool check[3][3] = {};
	cin >> N;
	REP(_, N){
		cin >> B;
		REP(i, 3) REP(j, 3){
			if(A[i][j] == B) check[i][j] |= 1;
		}
	}
	REP(i, 3) REP(j, 3) cerr << check[i][j] << endl;
	bool yes = 0;
	REP(i, 3){
		bool ok = 1;
		REP(j, 2) if(!(check[i][j] and check[i][j+1])) ok &= 0;
		yes |= ok;
	}
	REP(j, 3){
		bool ok = 1;
		REP(i, 2) if(!(check[i][j] and check[i+1][j])) ok &= 0;
		yes |= ok;
	}
	yes |= ((check[0][0] and check[1][1]) and (check[1][1] and check[2][2]));
	yes |= ((check[0][2] and check[1][1]) and (check[1][1] and check[2][0]));
	if(yes) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

s = list(input())
t = list(input())

s.sort()
t.sort(reverse = True)

S = str()
T = str()

for x in s:
	S += x

for y in t:
	T += y

if sorted([S, T])[0] == S and S != T:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int inf = 0x3f3f3f3f;
char ss[maxn];
int main() {

    scanf("%s", ss + 1);
    int ans = inf;
    int len = strlen(ss + 1);
    for (int i = 1; i <= len; i++) {
        if (ss[i] != ss[i + 1])
            ans = min(ans, max(i, len - i));
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 384
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		// 計算
		String result = "A";
		if(abs(x-a) > abs(x-b)) result = "B";
		
		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 21716
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll dp[100007][2];

int main(){
  string S;
  dp[0][0]=1;
  cin >> S;
  rep(i,S.size()){
    int C=ctoi(S[i]);
    rep(j,2){
      rep(k,2){
        if(!j&&C<k){
          continue;
        }
        ll X = dp[i][j];
        if(k){
          X*=2;
        }
        dp[i+1][j|(C>k)]+=X;
        dp[i+1][j|(C>k)]%=MOD;
      }
    }
  }
  cout << (dp[S.size()][0]+dp[S.size()][1])%MOD << endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp  make_pair
#define pb  push_back
#define INF 1e9+5
void c_p_c(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void solve(){
    int n,k;
    cin>>n>>k;
    int h[n];
    vector <int> dp(n,INF);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    cout<<dp[n-1]<<endl;
}
int32_t main(){
    c_p_c();
    int t;
    t=1;
    //cin>>t;
    while(t--){
       solve(); 
    }
	return 0;
}


Measured memory_bytes: 4752
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1

template<typename F>
struct FixPoint : F {
  FixPoint(F&& f) :F(forward<F>(f)) {}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f) {
  return FixPoint<F>{forward<F>(f)};
}

// http://nocotan.github.io/%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0/2017/01/23/lis-copy.html
int lis(const vector<int>& ns) {

  vector<int> dp(ns.size(), INT32_MAX);

  F0R(i, ns.size()) {
    *lower_bound(dp.begin(), dp.end(), ns[i]) = ns[i];
  }

  return lower_bound(dp.begin(), dp.end(), INT32_MAX) - dp.begin();
}

// 数値一つごとに呼び出す、計算のレジュームが可能なLIS、Undo対応版
pair<int, int> lisc(vector<int>& dp, int n) {
  pair<int, int> result;
  auto it = lower_bound(dp.begin(), dp.end(), n);
  auto prev = *it;
  *it = n;

  return { it - dp.begin(), prev };
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

#if 0
  // debug lis test
  cout << lis({ 1, 2, 5, 3, 4 }) << newl;
  return 0;
#endif

  int N;
  cin >> N;
  vector<int> a(N);
  F0R(i, N) {
    cin >> a[i];
  }
  vector<vector<int>> G(N, vector<int>());
  F0R(i, N - 1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  vector<int> results(N);
  vector<int> dp(N, INT32_MAX);
  MFP([&](auto dfs, int v, int p)->void {

    auto undo = lisc(dp, a[v]);
    results[v] = lower_bound(dp.begin(), dp.end(), INT32_MAX) - dp.begin();

    for (auto e : G[v]) {
      if (e == p) continue;
      dfs(e, v);
    }
    
    dp[undo.first] = undo.second;
  })(0, -1);

  F0R(i, N) {
    cout << results[i] << newl;
  }
}
#endif


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    string S; cin >> S;
    REP(i,3){
        if(S[i] == '1'){
            cout << '9';
        }else if(S[i] == '9'){
            cout << '1';
        }else{
            cout << S[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3604
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::HashMap;
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::usize;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_cols<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    // 23:54:50
    let v = read_cols::<i32>();
    let a = v[1];
    let b = v[2];

    if (b - a) % 2 == 0 {
        println!("Alice");
    } else {
        println!("Borys");
    }
}


Measured memory_bytes: 4352
#include <vector>
#include <queue>
#include <functional>
#include <utility>

using namespace std;

//  E[i]: vertexes which can be reased from i
//  W[i]: their weight
template<class T>
vector<T> dijkstra(vector<vector<int>> E, vector<vector<T>> W, int s, T inf)
{
    int n = (int)E.size();

    vector<T> D(n, inf);
    typedef pair<T,int> P;
    priority_queue<P,vector<P>,greater<P>> Q;

    D[s] = T();
    Q.push(make_pair(D[s], s));

    while (!Q.empty())
    {
        T d = Q.top().first;
        int p = Q.top().second;
        Q.pop();
        if (d > D[p])
            continue;
        for (int i=0; i<(int)E[p].size(); i++)
        {
            int t = E[p][i];
            if (d+W[p][i] < D[t])
                D[t] = d+W[p][i],
                Q.push(make_pair(D[t], t));
        }
    }
    return D;
}


#include <iostream>
#include <string>

int main()
{
    int H, W;
    cin>>H>>W;
    int Ch, Cw;
    cin>>Ch>>Cw;
    Ch--, Cw--;
    int Dh, Dw;
    cin>>Dh>>Dw;
    Dh--, Dw--;
    vector<string> S(H);
    for (string &s: S)
        cin>>s;

    vector<vector<int>> E(W*H);
    vector<vector<int>> WW(W*H);
    for (int y1=0; y1<H; y1++)
    for (int x1=0; x1<W; x1++)
        if (S[y1][x1]=='.')
            for (int y2=y1-2; y2<=y1+2; y2++)
            for (int x2=x1-2; x2<=x1+2; x2++)
                if (0<=x2 && x2<W && 0<=y2 && y2<H)
                    if (S[y2][x2]=='.')
                    {
                        int p1 = y1*W+x1;
                        int p2 = y2*W+x2;
                        int d = abs(x1-x2)+abs(y1-y2)<=1 ? 0 : 1;
                        E[p1].push_back(p2);
                        WW[p1].push_back(d);
                    }
    int oo = W*H;
    vector<int> D = dijkstra(E, WW, Ch*W+Cw, oo);
    int ans = D[Dh*W+Dw];
    if (ans>=W*H)
        ans = -1;
    cout<<ans<<endl;       
}


Measured memory_bytes: 247832