akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(unused_variables)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};

fn main() {
    input! {
        s: String,
    }
    let ans = if s == "ABC" {"ARC"} else {"ABC"};
    println!("{}", ans);
}


Measured memory_bytes: 2144
import sys
a,b = map(int,input().split())
for x in range(a+1):
    for y in range(a+1):
            if 10000*x + 5000*y + 1000*(a-x-y) > b:
                if a-x-y >= 0:
                    continue
            if 10000*x + 5000*y + 1000*(a-x-y) == b:
                if a-x-y >= 0:
                    print(x,y,a-x-y)
                    sys.exit()
print(-1,-1,-1)

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

int main() {
  int N, ans = 0;
  long long x;
  cin >> N >> x;
  vector<long long>a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < N; i++) {
    if (i == N - 1) {
      if (x == a.at(N - 1)) {
        ans++;
      }
    }
    else if (x >= a.at(i)) {
      ans++;
      x -= a.at(i);
    }
    else {
      break;
    }
  }
  cout << ans;
}

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

int main(void){

  char S,S_small,S_big;

  scanf("%c",&S);
  S_small = tolower(S);
  S_big = toupper(S);

  if(S != S_small) printf("A\n");
  else printf("a\n");
  return 0;
}


Measured memory_bytes: 1644
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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


int main() {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool postal = true;
    for (int i = 0; i < a; i++) {
        if (s[i] < '0' || '9' < s[i]) postal = false;
    } 
    if (s[a] != '-') postal = false;
    for (int i = a+1; i < a+b+1; i++) {
        if (s[i] < '0' || '9' < s[i]) postal = false;
    }
    if (postal) cout << "Yes";
    else cout << "No";
    cout << endl;
}

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

typedef long long int llint;

int main(){
	int N,Q;
	llint A[100001];
	llint S=0;
	for(int i=0;i<100001;i++){
		A[i]=0;
	}

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

	cin >> Q;
	for(int i=0;i<Q;i++){
		int B,C;
		cin >> B >> C;
		S-=A[B]*B;
		S+=A[B]*C;
		A[C]+=A[B];
		A[B]=0;
		cout << S << endl;
	}
	return 0;
}


Measured memory_bytes: 4416
fun main(args: Array<String>) {
    val s = readLine()!!
    val a = s.filterIndexed { index, c -> index % 2 == 0 }.all { it != 'L' }
    val b = s.filterIndexed { index, c -> index % 2 == 1 }.all { it != 'R' }
    println(if(a && b) "Yes" else "No")
}

Measured memory_bytes: 31940
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

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

int par[100005];
int find(int x) {
  return par[x] == x ? x : (par[x] = find(par[x]));
}
bool merge(int x, int y) {
  x = find(x);
  y = find(y);
  if(x == y) return false;
  par[x] = y;
  return true;
}

void solve() {
  int n, m;
  cin >> n >> m;
  for(int i = 1; i <= n; i++) par[i] = i;
  map<int, vector<int>> dp;
  for(int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    while(t--) {
      int now;
      cin >> now;
      dp[now].push_back(i);
    }
  }
  int comps = n;
  for(auto x: dp) {
    vector<int> y = x.second;
    for(int i = 1; i < y.size(); i++) comps -= merge(y[i-1], y[i]);
  }
  if(comps == 1) cout << "YES\n";
  else cout << "NO\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    int a[200005]={0};
    int n;
    cin>>n;
    ll ans=0;
    ll in[n];
    REP(i,n)
    {
        int x;
        cin>>x;
        a[x]++;
        in[i]=x;
    }
    REP(i,200005)
    {
        ans+=(1LL*a[i]*(a[i]-1))/2;
    }
    vector<ll> v;
    REP(i,n)
    {
        if(a[in[i]]!=0)
        v.push_back(ans-(a[in[i]]-1));
    }
    for(auto i:v)
    {
        cout<<i<<"\n";
    }
  }  
  return 0;
}

Measured memory_bytes: 6640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int N = 2e6 + 6;
int A[N];
int vis[N];
int dp[N];
vector<vector<int>> vec;     

int alpha(int i)
{
      if(vis[i])return dp[i];
      int &abs = dp[i];
      if(abs != -1)return abs;
      vis[i] = 1;
      int ans = 0;
      for(auto &it : vec[i])
      {
            ans = max(ans , alpha(it)+1);
      }
      return abs = ans;
}

void solve()
{
      int n , m;
      cin >> n >> m;

      vec.resize(n+1);

      mset(dp,-1);

      loop(i,0,m)
      {
            int u ,v;
            cin >> u >> v;
            vec[u].pb(v);
      }

      loop(i,1,n+1)
      {     
            if(!vis[i])
            {
                  alpha(i);
            }
      }

      int ans = 0;

      loop(i,1,n+1)ans = max(ans , dp[i]);

      cout << ans;

}
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);

ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
       

       int t = 1;
       // cin >> t;
       while(t--)solve();
  
}

Measured memory_bytes: 26240
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}



main(){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n){
    cin>>v[i];
  }

  int m=1;
  int ans=0;
  rep(i,n){
    if(v[i]-m<=0){
      m=max(m,v[i]+1);
      continue;
    }
    ans+=v[i]/m;
    if(v[i]%m==0){
      ans--;
      if(i==0) m++;
    }
    //cout<<i<<' '<<m<<' '<<ans<<endl;
  }
  
 
  cout<<ans<<endl;
}



Measured memory_bytes: 1152
k = int(input())
if k % 2 == 0:
    print(-1)
    exit(0)
elif k % 5 == 0:
    print(-1)
    exit(0)    
a = 7 % k
if a == 0:
  print(1)
  exit(0)
for i in range(2, 10000000):
    if (10 * a + 7) % k == 0:
        print(i)
        exit(0)
    a = (10 * a + 7) % k
print(-1)

Measured memory_bytes: 9228
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# (回数、インデックス)をheapで管理

from heapq import heappop, heappush

N,M = map(int,readline().split())
S = [x - ord('0') for x in read().rstrip()]

INF = 10 ** 18
dp_cnt = [INF] * (N+1)
dp_next = [0] * (N+1)

dp_cnt[N] = 0
q = [(0,N)]

for n in range(N-1,-1,-1):
    while True:
        cnt,ind = q[0]
        if ind > n + M:
            heappop(q)
            continue
        break
    cnt += 1
    if S[n] == 1:
        cnt = INF
        ind = 0
    dp_cnt[n] = cnt
    dp_next[n] = ind
    heappush(q, (cnt, n))

if dp_cnt[0] >= INF:
    print(-1)
    exit()

answer = []
append = answer.append
x = 0
while x != N:
    y = dp_next[x]
    append(y-x)
    x = y

print(' '.join(map(str,answer)))

Measured memory_bytes: 19208
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;

string make_str(int i, int j) {
  string ans = "";
  for (auto k = 0; k < N; ++k) {
    ans += "0";
  }
  ans[i] = '1';
  ans[j] = '1';
  ans = "? " + ans;
  return ans;
}

vector<int> V[1000];

int main () {
  cin >> N;
  int cnt = 0;
  for (auto i = 0; i < N; ++i) {
    for (auto j = i+1; j < N; ++j) {
      cout << make_str(i, j) << endl;
      int res;
      cin >> res;
      if (res == 1) {
        V[i].push_back(j);
        cnt++;
        if (cnt == N-1) goto EXIT;
      }
    }
  }
 EXIT:
  cnt = 0;
  cout << "! ";
  for (auto i = 0; i < N; ++i) {
    for (auto x : V[i]) {
      cout << "(" << i << "," << x << ")";
      cnt++;
      if (cnt < N-1) {
        cout << " ";
      } else {
        cout << endl;
      }
    }
  }
}


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

#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define vp vector<P>
#define vb vector<bool>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
const int mod = 1000000007;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

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

const int MAX_V = 1000;
struct edge {int to, cap, rev;};//revはtoからでるrev番目の逆へんを表す
vector< vector<edge> > G;
bool used[MAX_V];

void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size()-1});
}

int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    REP(i, G[v].size()) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t) {
    int flow = 0;
    while (true) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INFTY);
        if (f == 0) return flow;
        flow += f;
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    G.resize(n);
    REP(i, m) {
        int u, v, c;
        cin >> u >> v >> c;
        add_edge(u, v, c);
    }
    int res = max_flow(0, n-1);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}


int main() {
    LL N, K;
    cin >> N >> K;

    VP M;
    FOR(i, 2, N + 1) {
        M.PB(MP(1, i));
    }
    LL r = (N - 1) * (N - 2) / 2 - K;
    if (r < 0) {
        cout << "-1" << endl;
        return 0;
    }
    FOR(i, 2, N + 1) {
        FOR(j, i + 1, N + 1) {
            if (r == 0) break;
            M.PB(MP(i, j));
            r--;
        }
    }

    cout << SZ(M) << endl;
    EACH(m, M) {
        cout << m.first << " " << m.second << endl;
    }
	
    return 0;
}


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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>

typedef long long ll;

int main() {
  int N, ans = 0;
  cin >> N;
  vi A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ans += A[i] - 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
typedef long long LL;
using namespace std;
LL a , b , c , d , n;
int main()
{
	while(~scanf("%lld%lld%lld%lld%lld" , &n , &a , &b , &c , &d)){
		bool flag = 0;
		for(LL i = 2;i <= n - 1;i++){
			LL res = a - d * (i - 1);
			LL tmp = a - c * (i - 1);
			LL res_ = b - d * (n - i);
			LL tmp_ = b - c * (n - i);
			bool ok = 1;
			if(res > tmp_ || res_ > tmp) ok = 0;
			if(ok) flag = 1;
			if(flag) break;
		}
		if(flag) printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 256
chomp($nn=<>);
($n,$m,$x) = split/ /,$nn;
chomp($nnn=<>);
@a=split/ /,$nnn;
%hash= map { $_ => 1 } @a;

$right=0;
for($i=$x;$i<=$n;$i++){
	if(exists($hash{$i})){
    	$right++;
    }
}
$left=0;
for($i=$x;$i>=1;$i--){
	if(exists($hash{$i})){
    	$left++;
    }
}
if($left>=$right){
	print $right;
}else{
	print $left;
}

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

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

  int ac_total = 0, wa_total = 0;
  vector<int> wa_counts(N, 0);
  vector<bool> passed(N, false);

  for (int i = 0; i < M; i++) {
    int pi;
    string si;
    cin >> pi >> si;

    if (passed[pi - 1]) {
      continue;
    }

    if (si == "WA") {
      wa_counts[pi - 1]++;
    }

    if (si == "AC") {
      ac_total++;
      wa_total += wa_counts[pi - 1];
      passed[pi - 1] = true;
    }
  }

  printf("%d %d\n", ac_total, wa_total);
}

Measured memory_bytes: 640
N=gets.to_i
as=N.times.map{gets.split.map(&:to_i)}
as.sort!{|a,b|(a[2]<=>b[2])*(-1)}
as=as.transpose
xs,ys,hs=as[0],as[1],as[2]
for y in 0..100
    for x in 0..100
        height=hs[0]+(xs[0]-x).abs+(ys[0]-y).abs
        judge=true
        for i in 1..xs.size-1
            if height!=hs[i]+(xs[i]-x).abs+(ys[i]-y).abs && hs[i]!=0
                judge=false
                break
            end
        end
        if judge
            for i in 1..xs.size-1
                if hs[i]!=[height-(xs[i]-x).abs-(ys[i]-y).abs,0].max
                    judge=false
                    break
                end
            end
        end
        if judge
            puts [x,y,height].join(" ")
            exit 0
        end
    end
end


Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int h, w;
vector<vector<int>> c(10, vector<int>(10, 0));

int main() {
    cin >> h >> w;
    rep(i, 0, 10) {
        rep(j, 0, 10) {
            cin >> c[i][j];
        }
    };
    
    rep(i, 0, 10) {
        rep(j, 0, 10) {
            rep(k, 0, 10) {
                c[j][k] = min(c[j][k], c[j][i]+c[i][k]);
            }
        }
    }

    int ans = 0;
    rep(i, 0, h) {
        rep(i, 0, w) {
            int a;
            cin >> a;
            if(abs(a) == 1) continue;
            else ans += c[a][1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using P1 = pair<int, P>;
#define FOR(t, a, b) for (int t = (a); t < (b); ++t)
#define REP(t, n) FOR(t, 0, n)

int main()
{
    string s;
    int ans = 0;
    cin >> s;
    REP(i, 4)
    {
        if (s[i] == '+')
        {
            ans++;
        }
        else
        {
            ans--;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
def countInRangeUtil(pos, cnt, tight, num): 

	# Last position 
	if pos == len(num):
		if cnt == K: 
			return 1
		return 0
	if dp[pos][cnt][tight] != -1: 
		return dp[pos][cnt][tight] 

	ans = 0
	limit = 9 if tight else num[pos] 

	for dig in range(limit + 1): 
		currCnt = cnt 
		if dig != 0: 
			currCnt += 1

		currTight = tight 

		if dig < num[pos]: 
			currTight = 1

		# Next recursive call 
		ans += countInRangeUtil(pos + 1, currCnt, currTight, num) 

	dp[pos][cnt][tight] = ans 
	return dp[pos][cnt][tight] 
def countInRange(x): 
	global dp, K, M 

	num = [] 
	while x: 
		num.append(x % 10) 
		x //= 10

	num.reverse()
	dp = [[[-1, -1] for i in range(M)] for j in range(M)] 
	return countInRangeUtil(0, 0, 0, num) 


dp = [] 
M = 101
K = 0

L = 1
R = int(input())
K = int(input())
print(countInRange(R) - countInRange(L - 1)) 





Measured memory_bytes: 5108
fn main() {
    // N
    let n = read_line::<u32>();
    solve(n);
}

fn solve(n: u32) {
    let ans = (0..n)
            // 桁数が奇数
            .filter(|d| {
            (((d + 1) as f64).log10() as u32) % 2 == 0
        })
        .count();
    println!("{}", ans);
}

#[allow(dead_code)]
fn read_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

Measured memory_bytes: 4352
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000003;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const vector<pll> dir={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}
inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 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,class L>ostream& operator << (ostream& os, pair<T,L>& p){os << p.first << " " << p.second;return os;}

int main(){
  ll l,n,s=0;
  cin>>n>>l;
  vector<ll> a(n);
  rep(i,0,n) a[i]=l+i;
  rep(i,0,n) s+=a[i];
  if(a[0]>-1) cout<<s-a[0];
  else if(a[n-1]<0) cout<<s-a[n-1];
  else cout<<s;
}


Measured memory_bytes: 256
#include<cstdio>
long long n,ans;
void dfs(long long a,int f){
  if(a>n) return;
  if(f==7)++ans;
  a*=10;
  dfs(a+3,f|1);
  dfs(a+5,f|2);
  dfs(a+7,f|4);
}
int main(){
  scanf("%lld",&n);
  dfs(0,0);
  printf("%lld\n",ans);
  return 0;
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const ll INF=1e10; // 期待値の最大値はおよそ(500*250/2)*500*250<1e10
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int w,h;cin>>w>>h && w|h;){
		vs grid(h);
		rep(i,h) cin>>grid[i];
		
		vvl stair(h,vl(w,INF)),spring(h,vl(w,INF));
		queue<tuple<int,int,ll>> q;
		rep(i,h) rep(j,w) if(grid[i][j]=='g') q.emplace(i,j,0);
		while(q.size()){
			int i,j; ll d; tie(i,j,d)=q.front(); q.pop();
			if(0<=i && i<h && 0<=j && j<w && strchr(".sg",grid[i][j]) && stair[i][j]==INF){
				stair[i][j]=d;
				rep(k,4) q.emplace(i+"\xff\x1\0\0"[k],j+"\0\0\xff\x1"[k],d+1);
			}
		}
		rep(i,h) rep(j,w) if(grid[i][j]=='*') q.emplace(i,j,0);
		while(q.size()){
			int i,j; ll d; tie(i,j,d)=q.front(); q.pop();
			if(0<=i && i<h && 0<=j && j<w && strchr(".sg*",grid[i][j]) && spring[i][j]==INF){
				spring[i][j]=d;
				rep(k,4) q.emplace(i+"\xff\x1\0\0"[k],j+"\0\0\xff\x1"[k],d+1);
			}
		}
		
		vl st,sp;
		rep(i,h) rep(j,w) if(strchr(".s",grid[i][j])){
			st.push_back(stair[i][j]);
			sp.push_back(spring[i][j]);
		}
		
		int n=st.size();
		vi is(n); iota(all(is),0);
		sort(all(is),[&](int i,int j){return st[i]-sp[i]<st[j]-sp[j];});
		
		int si=-1,sj=-1;
		rep(i,h) rep(j,w) if(grid[i][j]=='s') si=i,sj=j;
		
		double res=stair[si][sj];
		ll sum1=0,sum2=accumulate(all(sp),0ll),cnt=0;
		for(int i:is){
			sum1+=st[i],sum2-=sp[i],cnt++;
			res=min(res,spring[si][sj]+double(sum1+sum2)/cnt);
		}
		printf("%.10f\n",res);
	}
}

Measured memory_bytes: 10572
h,w,k=map(int,input().split())
table=[]
for i in range(h):
  row=str(input())
  table.append(row)

ans = 0
for maskR in range(1 << h):
    for maskC in range(1 << w):
        black = 0
        for i in range(h):
            for j in range(w):
                if ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 and table[i][j] == '#': 
                    black = black + 1
        if black == k: 
            ans = ans + 1
print(ans)

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}


/*{
  }*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

//constexpr int mod = 1e9+7;
//constexpr int inf = 1<<30;

signed main(){
  string s;
  cin >> s;
  int n = sz(s);

  int ans = 0;
  rep(i, 0, n/2){
    if(s[i] != s[n-1-i]) ans++;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

class EDGE {
public:
    int no;
    int nord1;
    int nord2;
    int value;
    EDGE(int a, int b, int c, int d) : no(a), nord1(b), nord2(c), value(d) {}
};

bool operator< (const EDGE &edge1, const EDGE &edge2) {
    return edge1.value > edge2.value;
}

bool operator> (const EDGE &edge1, const EDGE &edge2) {
    return edge1.value < edge2.value;
}

int main() {
    int V, E; // V: 頂点の数 E: 辺の数
    cin >> V >> E;
    UnionFind uf(V);
//    bool is_in[V]; // 頂点が木としてつながってるかどうか
//    for (int i = 0; i < V; i++) is_in[i] = false;
    multiset<EDGE, greater<EDGE> > edge_set;
    for (int i = 0; i < E; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        EDGE edge(i, a, b, c);
        edge_set.insert(edge);
    }
    int ans = 0;
    multiset<EDGE>::iterator it = edge_set.begin();
    for (; it != edge_set.end(); it++) {
        if (uf.unionSet((*it).nord1, (*it).nord2)) {
//            printf("%d-%d edge is added\n", (*it).nord1, (*it).nord2);
            ans += (*it).value;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    vector<vector<int>> bingo(3, vector<int>(3));
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> bingo[i][j];
        }
    }
    int n;
    cin >> n;
    for (int k = 0; k < n; ++k) {
        int a;
        cin >> a;
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (bingo[i][j] == a) {
                    bingo[i][j] = 0;
                }
            }
        }
    }
    if (bingo[0][0] == bingo[0][1] && bingo[0][1] == bingo[0][2]) cout << "Yes" << endl;
    else if (bingo[1][0] == bingo[1][1] && bingo[1][1] == bingo[1][2]) cout << "Yes" << endl;
    else if (bingo[2][0] == bingo[2][1] && bingo[2][1] == bingo[2][2]) cout << "Yes" << endl;
    else if (bingo[0][0] == bingo[1][0] && bingo[1][0] == bingo[2][0]) cout << "Yes" << endl;
    else if (bingo[0][1] == bingo[1][1] && bingo[1][1] == bingo[2][1]) cout << "Yes" << endl;
    else if (bingo[0][2] == bingo[1][2] && bingo[1][2] == bingo[2][2]) cout << "Yes" << endl;
    else if (bingo[0][0] == bingo[1][1] && bingo[1][1] == bingo[2][2]) cout << "Yes" << endl;
    else if (bingo[0][2] == bingo[1][1] && bingo[1][1] == bingo[2][0]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define db double
const db eps = 1e-6;
int sgn(db a, db b = 0) {
	a -= b;
	return (a > eps) - (a < -eps);
}

struct poi {
	db x, y;
	void r() { cin >> x; cin >> y; }
	void w() { cout << x << ' ' << y << '\n'; }
	poi operator -(poi p) {
		return {x - p.x, y - p.y};
	}
	poi operator +(poi p) {
		return {x + p.x, y + p.y};
	}
	poi operator *(db d) {
		return {x * d, y * d};
	}
	db dot(poi p) {
		return x * p.x + y * p.y;
	}
	db cross(poi p) {
		return x * p.y - y * p.x;
	}
	db len2() { return x * x + y * y; }
	poi proj(poi p, poi q) {
		db s = (*this - p).dot(q - p) / (q - p).len2();
		return p + (q - p) * s;
	}
};

int ccw(poi a, poi b, poi c) {
	poi u = b - a, v = c - a;
	if(u.cross(v) > eps) return 1;
	if(u.cross(v) < -eps) return -1;
	if(u.dot(v) < -eps) return -2;
	if(u.len2() + eps < v.len2()) return 2;
	return 0;
}

int main() {
	ios :: sync_with_stdio(false);

	int T; cin >> T;
	while(T --) {
		poi p0, p1, p2, p3; p0.r(); p1.r(); p2.r(); p3.r();
		if(!sgn((p1 - p0).cross(p3 - p2)))
			cout << "2\n";
		else if(!sgn((p1 - p0).dot(p3 - p2)))
				cout << "1\n";
		else
				cout << "0\n";
	}

	return 0;
}

Measured memory_bytes: 3276
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

int main() {
  vector<int> deg(4, 0);
  for (int i = 0; i < 3; ++i) {
    int a, b;
    scanf("%d %d", &a, &b), --a, --b;
    ++deg[a];
    ++deg[b];
  }
  bool ok = *max_element(deg.begin(), deg.end()) <= 2;
  if (ok) printf("YES\n");
  else printf("NO\n");
  return 0;
}


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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
#define int long long

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 ll a,b,c,s,t,i,j,k,x,y,z;
 ll A,B,C,S,T,X,Y,Z;

 ll count;

 long double pi=3.14159265358979323846;

 string N,M;

unsigned long long D;

signed main(){

	cin>>N>>M;

	cout<<M<<N;
	


	return 0;

}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  int N, K;
  vector<ll> input;
  Tmp(int N, int K)
  : N(N)
  , K(K)
  , input(N)
  {}

  ll operator() () {
    boost::sort(input);

    ll res = K;
    for (int i = 0; i < N; ++i) {
      auto j = minus(i);
      auto d = diff(i, j);
      chmin(res, d);
    }
    return res;
  }

  ll diff(int k, int n) {
    auto a = input[k];
    auto b = input[n];
    auto d = b - a;
    if (d < 0) {
      d += K;
    }
    return d % K;
  }

  int minus(int n) {
    auto k = n-1;
    if (k < 0) { k += N; }
    return k;
  }
};

void solve(void)
{
  int K, N; cin >> K >> N;
  Tmp t(N, K);
  for (int i = 0; i < N; ++i) {
    cin >> t.input[i];
  }
  auto ans = t();
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 1792
//ABC 162 D
#include <bits/stdc++.h>
using namespace std;

int main(){
   int n;
   string s,s1;
   cin >> n; //n=n*100; 
   cin >> s;
   	/*for (int i=0;i<100;i++)
	{
		s=s+s1;
	}
	*/
   int r[n+1], g[n+1], b[n+1];
   
   for (int i=0; i<=n; i++){
   	  r[i]=g[i]=b[i]=0;
   }
   
   for (int i=n-1; i>=0; i--){    //一开始错写成了 i<=0 
   	   if (s[i]=='R')
   	      r[i]=r[i+1]+1;
   	   else
   	   	  r[i]=r[i+1];
   	   
   	   if (s[i]=='G')
   	      g[i]=g[i+1]+1;
   	   else
   	   	  g[i]=g[i+1];
   	   
   	   if (s[i]=='B')
   	      b[i]=b[i+1]+1;
   	   else
   	   	  b[i]=b[i+1];
   }
   
   long long ans=0;      //注意：不能 int , 否则 两个WA 
   
   for(int i=0; i<=n-4; i++){
   	 for(int j=i+1; j<=n-2; j++){
   	 	if (s[i]!=s[j]){
   	 	   int k=j+(j-i);
           if (s[i]!='B' && s[j]!='B'){
           	  ans += b[j+1];
           	  if (k<=n-1 && s[k]=='B') ans--;
           }
           
           if (s[i]!='G' && s[j]!='G'){
           	  ans += g[j+1];
           	  if (k<=n-1 && s[k]=='G') ans--;
           }
           
           if (s[i]!='R' && s[j]!='R'){
           	  ans += r[j+1];
           	  if (k<=n-1 && s[k]=='R') ans--;
           }
   	 	}
   	 }
   }
   
   cout << ans << endl;
   return 0;
} 

Measured memory_bytes: 3644
def resolve():
    N = int(input())
    A = [int(input()) for i in range(N)]
    d = {}
    for a in A:
        if not a in d:
            d[a] = 1
        else:
            d[a] += 1
    res = 0
    for v in d.values():
        if v % 2 != 0:
            res += 1
    print(res)

if '__main__' == __name__:
    resolve()

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        int tmp = 500 * i + 100 * j + 50 * k;
        if (tmp == x) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

const int INF = 2e9 + 3;
const int N = 1e5 + 3;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

const double PI = acos(-1);


void solve() {
    int s;
    cin >> s;
    vector<int> dp(s + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < s; i++) {
        for (int j = 3; j <= s; j++) {
            if (i + j <= s)
                dp[i + j] = (dp[i + j] + dp[i]) % MOD;
        }
    }
    cout << dp[s];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    t = 1;
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

const int MAXN = 51;
int n;
int a[MAXN];


void solve() {
    sc(n);
    sca(a, n);
    int diff = 0;
    fo(i, n) if (a[i] != i+1) diff++;
    if (diff <= 2) printf("YES");
    else printf("NO");
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    vector<ll> A;
    cin >> N;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A.pb(a);
    }
    asort(A);
    for (int i = 1; i < N; i++) {
        if(A[i-1] == A[i]){
            cout << "NO" << endl;
            exit(0);
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 5284
(function() {
    'use strict';

    var koch = function() {
        var cos60 = Math.cos(60.0 * Math.PI / 180.0);
        var sin60 = Math.sin(60.0 * Math.PI / 180.0);

        function inner(n, p1x, p1y, p2x, p2y) {
            if (n == 0)
                return;
            var sx = (2 * p1x + p2x) / 3;
            var sy = (2 * p1y + p2y) / 3;

            var tx = (p1x + 2 * p2x) / 3;
            var ty = (p1y + 2 * p2y) / 3;

            var dx = tx - sx;
            var dy = ty - sy;
            var ux = sx + dx * cos60 - dy * sin60;
            var uy = sy + dx * sin60 + dy * cos60;

            inner(n - 1, p1x, p1y, sx, sy);
            console.log(sx + " " + sy);
            inner(n - 1, sx, sy, ux, uy);
            console.log(ux + " " + uy);
            inner(n - 1, ux, uy, tx, ty);
            console.log(tx + " " + ty);
            inner(n - 1, tx, ty, p2x, p2y);
        }
        return inner;
    };

    var fs = require('fs');
    var contents = fs.readFileSync('/dev/stdin', 'utf-8');
    var n = parseInt(contents.trim());

    var kochFunc = koch();
    console.log(0.00000 + " " + 0.0000);
    kochFunc(n, 0, 0, 100.0, 0);
    console.log(100.00000000 + " " + 0.00000000);
})();

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

int main(){
  int64_t N, K, Q;
  cin >> N >> K >> Q;
  vector<int64_t> A(Q);
  for(int i = 0; i < Q; i++){
    cin >> A.at(i);
  }
  vector<int64_t> P(N, K - Q);
  for(int i = 0; i < Q; i++){
    P.at(A.at(i) - 1)++;
  }
  for(int i = 0; i < N; i++){
    if(P.at(i) > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
	int N, K;
	string S;
	vector<int> ar, ruisekiwa;
	cin >> N >> K >> S;
	int cnt = 1;
	char bef = S[0];
	for (int i = 1; i < N; i++) {
		if (S[i] == bef)cnt++;
		else ar.push_back(cnt), cnt = 1, bef = S[i];
	}
	ar.push_back(cnt);

	//calc_ruisekiwa
	ruisekiwa.resize(ar.size() + 1);
	int ans = 0;
	if (S[0] != S.back()) {

		if (S[0] == '0')reverse(ar.begin(), ar.end());
		ruisekiwa[0] = 0;
		for (int i = 1; i < ruisekiwa.size(); i++) {
			ruisekiwa[i] = ruisekiwa[i - 1] + ar[i - 1];
		}

		ans = (ruisekiwa[ar.size()] - ruisekiwa[max((int)ar.size() - 2 * K, 0)]);
		for (int i = 0; 2 * K + 1 + i <= ar.size() ; i += 2) {
			ans = max(ans, ruisekiwa[2 * K + 1 + i] - ruisekiwa[i]);
		}
		
	}
	else {

		ruisekiwa[0] = 0;
		for (int i = 1; i < ruisekiwa.size(); i++) {
			ruisekiwa[i] = ruisekiwa[i - 1] + ar[i - 1];
		}

		if (S[0] == '0') {
			ans = max(ruisekiwa[min(2 * K, (int)ar.size())] - ruisekiwa[0], 
				ruisekiwa[ar.size()] - ruisekiwa[max((int)ar.size() - 2 * K, 0)]);
			for (int i = 0; i + 2 * K + 2 <= ar.size(); i += 2) {
				ans = max(ans, ruisekiwa[i + 2 * K + 2] - ruisekiwa[i + 1]);
			}
		}
		else {
			if (2 * K + 1 >= ar.size()) {
				ans = ruisekiwa[ar.size()] - ruisekiwa[0];
			}
			else {
				for (int i = 0; 2 * K + 1 + i <= ar.size(); i += 2) {
					ans = max(ans, ruisekiwa[2 * K + 1 + i] - ruisekiwa[i]);
				}
			}

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

Measured memory_bytes: 1272
N = int(input())
a = list(map(int, input().split()))
cnt = 0
while True:
    dfrag = 0
    for i in range(N):
        if a[i]%2 == 0:
            a[i] = a[i]//2
            dfrag = 1
            cnt += 1
    if dfrag == 0:
        break
print(cnt)

Measured memory_bytes: 4148
using System;
using System.Linq;

public class Program
{
    static void Main()
    {

        int n = int.Parse(Console.ReadLine());
        int[] x = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        double sum = 0;
        for(int i = 0;i<x.Length;i++)
        {
            sum += x[i];
        }
        int ave = (int)Math.Round(sum / x.Length,MidpointRounding.AwayFromZero);
        int ans = 0;
        for(int i = 0;i<x.Length;i++)
        {
            ans += (int)Math.Pow(x[i] - ave, 2);
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
DBG = true
n = gets.to_i
b = Array.new(3000002,0)
for i in 1..1000000
  if b[n] == 1
    puts "#{i}"
    exit
  end
  b[n] = 1
  if n%2 == 0
    n /= 2
  else
    n = 3*n+1
  end
end


Measured memory_bytes: 25212
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)
        a[i]=-1;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        if(a[x-1]==-1 || a[x-1]==y)
            a[x-1]=y;
        else
        {
            cout<<"-1"<<endl;
            return 0;
        }
    }
    if(a[0]==0 && n>1)
        cout<<"-1"<<endl;
    else if(a[0]==0 && n==1)
        cout<<"0"<<endl;
    else{
        if(a[0]==-1 && n>1)
            a[0]=1;
        else if(a[0]==-1 && n==1)
            a[0]=0; 
        
        for(int i=0;i<n;i++)
        {
            if(a[i]==-1)
                cout<<"0";
            else
                cout<<a[i];
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;


int main(){

    int n;
    cin >> n;
    string s;
    cin >> s;

    int cnt = 1;
    for (int i=0; i < n-1; i++){
        if (s[i] != s[i+1]) cnt++;
    }

    cout << cnt << endl;

}





//              g++ -std=c++1z

Measured memory_bytes: 1144
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef vector < int > vint;
typedef pair < int, int > pii;
typedef pair < int, bool > pib;
typedef unsigned long long ull;

#define PB push_back
#define MP make_pair
#define RANGE(V) V.begin(), V.end()
#define FOR(i,n) for(int i=0;i<n;++i)
#define FORN(i,n) for(int i=1;i<=n;++i)
#define debug(x) cerr<<#x<<":"<<x<<"\n";
#define FORS(i,n) for(int i=0;i<n.length();++i)
const int INF = INT_MAX;
const int MAX = 10000001;
const int M = 1000000007;
int mod{ 1000000007 };
int op(int a,int b, int m) {
	if (m == 0) return a * b;
	if (m == 1) return a + b;
	if (m == 2) return a / b;
	if (m == 3) return a - b;
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("input.txt", "r", stdin);
	int item;
	vint v(8);
	FOR(i, 3) {
		cin >> item;
		v[item]++;
	}
	if (v[5] == 2 && v[7] == 1) cout << "YES";
	else cout << "NO";
	return 0;	
}






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

int main() {
  int N;
  cin >> N;
  vector<long long> X(N),Y(N);
  for (int i=0; i<N; i++) {
    cin >> X[i] >> Y[i];
  }
  if (N <= 2) {
    cout << 1 << endl;
    return 0;
  }
  int ans = N;
  int term;
  long long p,q;
  for (int i=0; i<N-1; i++) {
    for (int j=i+1; j<N; j++) {
      term = N;
      p = X[i] - X[j];
      q = Y[i] - Y[j];
      for (int k=0; k<N; k++) {
        for (int l=0; l<N; l++) {
          if (k == l) {
            continue;
          }
          if (p == X[k] - X[l] && q == Y[k] - Y[l]) {
            term--;
            break;
          }
        }
      }
      ans = min(ans,term);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256