akhauriyash/Code-Regression huggingface dataset:
def decodeJ(s):
    return s[-1] + s[:-1]
def decodeC(s):
    return s[1:] + s[0]
def decodeE(s):
    lenS = len(s)
    return s[lenS//2:] + s[:lenS//2] if lenS % 2 == 0 else s[lenS//2+1:] + s[lenS//2] + s[:lenS//2]
def decodeA(s):
    return s[::-1]
def decodeP(s):
    ret = []
    for i in s:
        try:
            ret.append(str((int(i)-1)%10))
        except:
            ret.append(i)
    return ''.join(ret)
def decodeM(s):
    ret = []
    for i in s:
        try:
            ret.append(str((int(i)+1)%10))
        except:
            ret.append(i)
    return ''.join(ret)

N = int(input())
decode = {'J': decodeJ, 'C': decodeC, 'E': decodeE, 'A': decodeA, 'P': decodeP, 'M': decodeM}
for _ in range(N):
    messengers = input()
    message = input()
    for m in messengers[::-1]:
        message = decode[m](message)
    print(message)

Measured memory_bytes: 6748
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int dp[105];
bool bad[105];

int main() {
  int n, m, x;
  scanf("%d%d%d", &n, &m, &x);
  for(int i = 0; i <= n; i++) {
    dp[i] = 1 << 25;
  }
  dp[x] = 0;
  while(m--) {
    int t;
    scanf("%d", &t);
    bad[t] = true;
  }
  for(int i = 1; i <= n; i++) {
    if(bad[i]) {
      dp[i] = min(dp[i], dp[i-1] + 1);
    }
    else {
      dp[i] = min(dp[i], dp[i-1]);
    }
  }
  for(int i = n-1; i >= 0; i--) {
    if(bad[i]) {
      dp[i] = min(dp[i], dp[i+1] + 1);
    }
    else {
      dp[i] = min(dp[i], dp[i+1]);
    }
  }
  printf("%d\n", min(dp[0], dp[n]));
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int x, a, b;
  cin >> x >> a >> b;
  if (b-a<=0) cout << "delicious" << endl;
  else if (b-a <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
p = list(map(int, input().split()))

max_num = max(p)
lst = []
for i in range(max_num+2):
  if i not in p:
    lst.append(i)
tmp = float("inf")
for j in lst:
  if tmp > abs(X-j):
    tmp = abs(X-j)
    ans = j
print(ans)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int>D(N);
  for (int i = 0; i < N; i++) {
    cin >> D.at(i);
  }
  sort(D.begin(),D.end());
  int A = N;
  for (int i = 0; i < N - 1; i++) {
    if (D.at(i) == D.at(i+1)) {
      A--;
    }
  }
  cout << A;
}

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }	//最大公約数(Greatest Common Divisor)
ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }			//最小公倍数(Least Common Multiple)

long long comb(long long m) {
	return (m * (m - 1)) / 2;
}


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

	vector<int> xx(300);
	for (int i = -100; i < 200; i++)	xx[i+100] = i;

	rep(i, 300) {
		rep(j, n) {
			if (xx[i] == p[j])	xx[i] = 999;
		}
	}

	int ansdist=1000;
	int ans;
	rep(i, 300) {
		if (fabs(xx[i] - x) < ansdist) {
			ansdist = fabs(xx[i] - x);
			ans = i;
		}
	}

	cout << xx[ans] << endl;


}

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

using namespace std;

int main()
{
    int A,B;
    cin>>A>>B;
    if(A+B>=A-B&&A+B>=A*B){
        cout<<A+B<<endl;
    }else if(A-B>=A+B&&A-B>=A*B){
        cout<<A-B<<endl;
    }else{
        cout<<A*B<<endl;
    }

    return 0;
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
int h,w;
char a[501][501];
char red[501][501];
char blue[501][501];

signed main(){

    cin >> h >> w;
    rep(i,h) rep(j,w) red[i][j] = '#';
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
            blue[i][j] = a[i][j];   
        }
    }
    for(int i = 1;i < h;i += 2){
        for(int j = 1;j < w-1;j++){
            if(a[i][j] == '.'){
                red[i][j] = '.';
                blue[i][j] = '#';
            }
        }
    }
    for(int i = 2;i < h-1;i += 2){
        int c = 0;
        for(int j = 1;j < w-1;j++){
            if(blue[i][j] == '#')c = 1;
        }
        if(c == 0){
            red[i][1] = '.';
            blue[i][1] = '#';
        }
    }


    rep(i,h){
        rep(j,w){
            cout << red[i][j];  
        }
        cout << endl;
    }
    cout << endl;
    rep(i,h){
        rep(j,w){
            cout << blue[i][j];  
        }
        cout << endl;
    }

    


    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_d
// rm -r -f test;oj dl http://agc004.contest.atcoder.jp/tasks/agc004_c

Measured memory_bytes: 1408
N = int(input())


ans = ""
divide = 1

if N == 0:
    ans = "0"
else:
    while N != 0:
        if N%(divide*2) == 0:
            ans = "0" + ans
        else:
            ans = "1" + ans
            N -= divide
        divide *= -2
    

print(ans)
    

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

int sumd(int x) {
    int res = 0;
    while (x != 0) {
        res += x % 10;
        x /= 10;
    }
    return res;
}

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

    if (n % sumd(n) == 0)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <map>
#include <vector>
struct edge {long long from, to, cost;};

edge es[20000];
long long d[1100];
int over[1252];
int n,m;

using namespace std;
int main(){
  scanf("%d%d",&n,&m);
  for(int i=0;i<m;i++){
    long long a,b,c;
    scanf("%lld%lld%lld", &a,&b,&c);
    es[i].from = a-1;
    es[i].to = b-1;
    es[i].cost =  c;
  }
  for(int i = 0; i < n; i++)d[i] = -10000000000000;
  d[0] = 0;
  for(int k=0;k<=2*n;k++){
    for(int i=0;i<m;i++){
      if(d[es[i].from] != -10000000000000 && d[es[i].to] < d[es[i].from] + es[i].cost){
        d[es[i].to] = d[es[i].from] + es[i].cost;
        if(k == 2*n){
          over[es[i].to] = 1;
        }
      }
    }
  }
  if(over[n-1])printf("inf\n");
  else printf("%lld\n", d[n-1]);
}


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

int main(){
  while(1){
    int n,x;
    cin>>n>>x;
    if(n == 0 && x == 0) break;
    int ans = 0;
    for(int a = 1; a <= n ; a++)
      for(int b = a + 1; b <= n ; b++)
	for(int c = b + 1; c <= n ; c++){
	  if(a + b + c != x) continue;
	  ans++;
	}
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3084
/*
* welcome to my code!
* ------------------------------------------
* author : lynmisakura(twitter : @andoreiji11)
*/

#include<bits/stdc++.h>
using namespace std;

using ll = long long;

#define REP(i,n) for(int i = 0;i < n;i++)
#define all(x) x.begin(),x.end()
#define dup(x,y) (x + y - 1)/y
#define sz(v) (int)v.size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

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

    int64_t N;cin >> N;
    vector<int64_t> a(N);
    REP(i,N)cin >> a[i];
    sort(a.rbegin(),a.rend());

    int64_t ans = 0;
    REP(i,N-1) ans += a[(i+1)/2];

    cout << ans << '\n';

}


Measured memory_bytes: 4720
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

template <class T> struct FenwickTree {
   vector<T> node;
   FenwickTree(int n) : node(n,0) {}
   void add(int idx, T val) {
      while (idx < node.size()) {
         node[idx] += val;
         idx += idx & -idx;
      }
   }
   T sum(int idx) {
      T ret = 0;
      while (idx > 0) {
         ret += node[idx];
         idx -= idx & -idx;
      }
      return ret;
   }
};

int main() {

   int n,q; cin >> n >> q;
   FenwickTree<int> inst(100010);
   REP(i,q){
      int com,x,y;
      cin >> com >> x >> y;
      if(com == 0) {
         inst.add(x,y);
      } else {
         cout << inst.sum(y) - (x>0 ? inst.sum(x-1) : 0) << endl;
      }
   }

   return 0;
}

Measured memory_bytes: 3072
#include <cstdio>

template <int N, typename T, T M>
struct factorial_mod {
    T mod[N + 1];
    T inv_mod[N + 1];

    constexpr factorial_mod() : mod(), inv_mod() {
        mod[0] = 1;
        for (int i = 0; i < N; ++i) {
            mod[i + 1] = (mod[i] * (i + 1)) % M;
        }
        inv_mod[N] = power(mod[N], M - 2);
        for (int i = N - 1; i >= 0; --i) {
            inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
        }
    }

    constexpr T power(T a, T b) const {
        T r = 1;
        while (b > 0) {
            if ((b & 1) != 0) r = (r * a) % M;
            a = (a * a) % M;
            b >>= 1;
        }
        return r;
    }

    constexpr T comb(T n, T r) const {
        if (r < 0 || r > n || n < 0) return 0;
        return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
    }
};

constexpr factorial_mod<1000000, long long, 1000000007> fmod;

int main() {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    if ((x + y) % 3 != 0) {
        puts("0");
        return 0;
    }
    long long n = (x + y) / 3;
    x -= n;
    y -= n;
    if (x < 0 || y < 0) {
        puts("0");
        return 0;
    }
    printf("%lld\n", fmod.comb(n, x));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  string A, B, C;
  cin >> A >> B >> C;
  if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    CIN(A);CIN(B);
    Possible(A%3 == 0||B%3==0||(A+B)%3==0);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
class Dice2{
public:
    Dice2(){
        number = new int[6];
        relative = new int[55];
        relative[31] = relative[43] = relative[24] = relative[12] = 0;
        relative[3] = relative[20] = relative[52] = relative[35] = 1;
        relative[1] = relative[40] = relative[54] = relative[15] = 2;
        relative[4] = relative[10] = relative[51] = relative[45] = 3;
        relative[2] = relative[30] = relative[53] = relative[25] = 4;
        relative[21] = relative[42] = relative[34] = relative[13] = 5;
    };
    ~Dice2(){
        delete[] number;
        delete[] relative;
    };
 
    void setNumber(int index,int num){
        number[index] = num;
    };
 
    int returnRight(int top,int front){
        int top_index,front_index;
        for(int i = 0; i < 6; i++){
            if(number[i] == top)
                top_index = i;
            if(number[i] == front)
                front_index = i;
        }
        return number[relative[10*top_index+front_index]];
    }
private:
    int* number;
    int* relative;
};
 
int main(){
    Dice2 dice2;
    int x,q,top,front;
    for(int i = 0; i < 6; i++){
        scanf("%d",&x);
        dice2.setNumber(i,x);
    }
    scanf("%d",&q);
    for(int i = 0; i < q; i++){
        scanf("%d %d",&top,&front);
        printf("%d\n",dice2.returnRight(top,front));
    }
}


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

namespace diverta_D
{
    class Program
    {
        static void Main(string[] args)
        { 
            var n = long.Parse(Console.ReadLine());
            long otpt = 0;
            var z = Math.Sqrt((n));
            long m = (long)(Math.Ceiling(z));
            bool finish = false;
            int i = 0;
            do
            {
                i++;
                if (n%i==0)
                {
                    if (n / i > m)
                    {
                        otpt = otpt + n/i-1;
                    }
                }
                if (i > m)
                {
                    finish = true;
                }
            }
            while (finish == false) ;
            Console.WriteLine(Convert.ToString(otpt));
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,d;
signed main(){
	cin>>n>>d;
	int D=2*d+1;
	cout<<(n-1)/D+1<<endl;	
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{
  string s;
  cin >> s;
  int size = s.size();
  int cnt = 0;
  for (int i = 0; i < size; i++)
  {
    if (s[i] == '1')
    {
      cnt++;
    }
  }
  cout << 2 * min(cnt, size - cnt) << "\n";
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;
/* -- template -- */

int main(){
    int N, K; cin >> N >> K;
    string S;cin >> S;
    int dp[100001];
    dp[0] = 0;
    bool zeroflg = false;
    for(int i = 0; i < N; ++i){
        dp[i] = dp[((i - 1 < 0) ? 0 : i - 1)];
        if(S[i] == '0' && !zeroflg){
            zeroflg = true;
            ++dp[i];
        }
        if(S[i] == '1'){
            zeroflg = false;
        }
    }
    int l = 0, r = 1;
    int maxv = 1;
    while(r < N){
        if(dp[r] - ((l - 1 < 0) ? 0 : dp[l - 1]) + ((S[l] == '0' && l != 0) ? 1 : 0) <= K){
            maxv = max(maxv, r - l + 1);
            ++r;
        }else{
            ++l;
        }
        if(r == l)++r;
    }
    cout << maxv << endl;
}
/*
5
1
00101
*/


Measured memory_bytes: 896
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int k,x; cin >>k >>x;
  printf("%s",k*500>=x?"Yes":"No");
}

/// confirm df==0 ///


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

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

typedef long long ll;

int main() {
    string s;cin>>s;
    rep(i,3)if(s[i+1]==s[i]){
        cout<<"Bad"<<endl;
        return 0;
    }
    cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 256
A,B,C,X,Y=map(int,input().split())
price=0
if A+B>C+C:
    minXY=min(X,Y)
    price+=minXY*C*2
    X-=minXY
    Y-=minXY
if A>C+C:
    price+=X*2*C
    X=0
else:
    price+=A*X
    X=0
if B>C+C:
    price+=Y*2*C
    Y=0
else:
    price+=B*Y
    Y=0
print(price)

Measured memory_bytes: 3064
// I - Coins
#include <bits/stdc++.h>
using namespace std;
using dl = double;

int main(){
	int N; cin>>N;
	int C = (N+1)/2;
	vector<dl> dp(N+2);
	dp[1] = 1.;
	for(int lv=1; lv<=N; lv++){
		dl p; cin>>p;
		dl f = p, b = 1.-f;
		int e = max(1, lv-C+2);
		for(int i=lv+1; i>=e; i--) dp[i] = b*dp[i] + f*dp[i-1];
	}
	dl a = 0; for(int i=N+1; i>C; i--) a += dp[i];
	printf("%.10g\n",a);
}

Measured memory_bytes: 256
#include<stdio.h> 
int main()
{
	int a, b;
    scanf("%d%d", &a, &b);
    if(a>b)
    {
    	printf("a > b\n");	
	}
	else if(a<b)
	{
		printf("a < b\n");
	}
	else if(a==b)
	{
		printf("a == b\n");
	}
	
	return 0;	
}


Measured memory_bytes: 2020
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let mut k = io.read::<usize>();
    let f = |x: i64| -> i64 {
        let mut xx = x;
        let mut ret = 0;
        while xx > 0 {
            ret += xx % 10;
            xx /= 10;
        }
        ret
    };

    let mut dp = vec![999; k as usize];
    dp[1] = 1;
    let mut q = VecDeque::new();
    q.push_back(1usize);
    while let Some(qq) = q.pop_front() {
        let mut u = (qq * 10) % k;
        if dp[u] > dp[qq] {
            dp[u] = dp[qq];
            q.push_back(u);
        }
        u = (qq + 1) % k;
        if dp[u] > dp[qq] + 1 {
            dp[u] = dp[qq] + 1;
            q.push_back(u);
        }
    }
    io.writeln(dp[0]);
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 2772
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(input[0], 10);
	//出力
	console.log('%d',1110-a);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

int main(){
	int n,ans = 1;
	cin >> n;
	vector<int> v(n);
	
	for(int i=0;i<n;++i) cin >> v[i];

	for(int i=1;i<n;++i){
		bool ok = true;
		for(int j=i-1;j>=0;--j){
			//cout << v[i] << ' ' << v[j] << '\n';
			if(v[i] < v[j]) ok = false;
		}

		if(ok) ++ans;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double pi = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

int main(){
    int a,b;
    cin >> a >> b;
    cout << a + b/2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		boolean ans=true;
//		S.replace('o', 'n');
		int[] countlist = new int[27];
		int[] Tcountlist = new int[27];
		char[] chlist = new char[27];
		char[] tailist = new char[27];
		for(int num=0;num<27;num++) {
			countlist[num]=0;
			Tcountlist[num]=0;
			chlist[num]=100;
			tailist[num]=100;
		}


		for(int index=0;index<S.length();index++) {
			//System.out.println(S.charAt(index)-'a');
			countlist[S.charAt(index)-'a']++;
			if(countlist[S.charAt(index)-'a']==1) {//aの数
				tailist[S.charAt(index)-'a']=T.charAt(index);//aの対応
			} else {
				if(tailist[S.charAt(index)-'a']!=T.charAt(index)) {//aの対応が今の対応と違う
					ans=false;
				}
			}
//			System.out.println(String.valueOf(tailist[S.charAt(index)-'a']));
			//System.out.println(String.valueOf(tailist[S.charAt(index)-'a'])+"  "+String.valueOf((chlist[T.charAt(index)-'a'])));
		}
		for(int index=0;index<S.length();index++) {
			//System.out.println(T.charAt(index)-'a');
			Tcountlist[T.charAt(index)-'a']++;
			if(Tcountlist[T.charAt(index)-'a']==1) {//bの数
				chlist[T.charAt(index)-'a']=S.charAt(index);//bの対応
			} else {
				if(chlist[T.charAt(index)-'a']!=S.charAt(index)) {//bの対応が今の対応と違う.
					ans=false;
				}
			}
//			System.out.println(String.valueOf(chlist[T.charAt(index)-'a']));
		}

		if(ans) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


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

int main() {
  string  S;
  cin >> S;
  int size=S.size();
  if(S.at(size-1) =='s'){
    cout << S + "es" <<endl;
  }
  if(S.at(size-1) !='s'){
    cout << S + 's' <<endl;
  }
}




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

using namespace std;

int n;
int sec[10010];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>sec[i];
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int tmp;
        cin>>tmp;
        ans+=max(0,sec[i]-tmp);
    }
    cout<<ans<<'\n';
}

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

bool compare_by_b(pair<string, int> a, pair<string, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first > b.first;
    }
}

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<string> S(N);
    rep(i, N) cin >> S[i];
    // vector<pair<string, int>> scount;
    // set<string> stemp;
    map<string, int> ms;
    rep(i, N) {
        string ns = S[i];
        if (ms.count(ns)) {
            ms[ns] += 1;
        } else {
            ms[ns] = 1;
        }
    }
    vector<pair<string, int>> scount;
    for (auto x: ms) {
        scount.push_back(x);
    }
    sort(scount.begin(), scount.end());
    // cout << scount[0].first << " " << scount[1].first << endl;
    sort(scount.rbegin(), scount.rend(), compare_by_b);
    int max_count = scount[0].second;
    for (auto x: scount) {
        if (x.second == max_count) {
            cout << x.first << endl;
        } else {
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 30704
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>

using namespace std;

int main()
{
	int a, b;
	cin >> a >>b;
	
	int apb = a+b;
	int amb = a - b;
	int acb = a*b;
	
	int t = max(apb, amb);
	int t2 = max(t, acb);
	
	cout << t2 <<endl;
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
keta=[0]*60
for i in A:
    for j in range(60):
        keta[j]+=((i>>j)&1)

ans_l=[0]*N
for i in range(N):
    for j in range(60):
        if(keta[j]%2!=(A[i]>>j)&1):
            ans_l[i]+=(1<<j)

print(*ans_l)
            

            
    
    

Measured memory_bytes: 98824
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(int argc,char* argv[]){
    int n,ans=1;
    vector<string> data;
    string str;

    cin>>n;

    for(int i=0;i<n;i++){
        cin>>str;
        data.push_back(str);
    }
    sort(data.begin(),data.end());
    for(int i=1;i<n;i++){
        if(data[i]!=data[i-1]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int K;
  cin>>K;
  deque<P> dq;
  dq.push_front(P(1*10%K, 0));
  dq.push_back(P((1+1)%K,1));
  bool flag[K+1]={};
  P edge;
  while(true){
    edge = dq.front();
    if(edge.first==0) break;
    dq.pop_front();
    if(flag[edge.first]==0){
      flag[edge.first]=true;
      dq.push_front(P((edge.first*10)%K,edge.second));
      dq.push_back(P((edge.first+1)%K,edge.second+1));
    }
  }
  cout<<edge.second+1<<endl;
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  scanf("%d",&n);
  int nc=n;
  int sum=0;
  while(nc>0)
  {
    sum+=nc%10;
    nc/=10;
  }
  if(n%sum==0)
    printf("Yes");
  else printf("No");
  return 0;
}


Measured memory_bytes: 256
def parent(i)
  ( i / 2 ).ceil
end

def right(i)
  2 * i + 1
end

def left(i)
  2 * i
end

n = gets.to_i
heap = gets.split.map(&:to_i)
heap.each_with_index do |x, i|
  i = i + 1
  print "node #{i}: key = #{x}, "
  if parent(i) >= 1
    print "parent key = #{heap[parent(i) - 1]}, "
  end
  if left(i) <= n
    print "left key = #{heap[left(i) - 1]}, "
  end
  if right(i) <= n
    print "right key = #{heap[right(i) - 1]}, "
  end
  puts ""
end


Measured memory_bytes: 6868
/*
 *  NIKHILESH CHAMARTHI @ nikki371  ==> CSE(2015-19)
 *  VIT UNIVERSITY, VELLORE
*/

#pragma GCC optimize("O3")
#include "bits/stdc++.h"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x7fffffff
#define INFL 0x7fffffffffffffffLL
#define inrep int tc79;cin>>tc79;while(tc79--)
#define si(x) x = scanInt()
#define sll(x) x = scanLong()
#define nl putc_unlocked('\n', stdout);
#define cppio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

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

inline int scanInt(){
	 int n = 0,sign=1;
	 char ch = getchar_unlocked();
	 while(ch < '0' || ch > '9'){
		  if(ch == '-') sign = -1;
		  ch = getchar_unlocked();
	 }
	 while(ch >= '0' && ch <= '9'){
		  n = (n<<1)+(n<<3)+(int)(ch-'0');
		  ch = getchar_unlocked();
	 }
	 return n*sign;
}
inline ll scanLong(){
	 ll n = 0,sign = 1;
	 char ch = getchar_unlocked();
	 while(ch < '0' || ch > '9'){
		  if(ch == '-') sign = -1;
		  ch = getchar_unlocked();
	 }
	 while(ch >= '0' && ch <= '9'){
		  n = (n<<1)+(n<<3)+(ll)(ch-'0');
		  ch = getchar_unlocked();
	 }
	 return n*sign;
}
int getString(char *start) {
    char *data = start, ccc = 0;
    while (!(ccc > ' ' && ccc <= '~')) ccc = getc_unlocked(stdin);
    while (ccc > ' ' && ccc <= '~') {
        *data++ = ccc;
        ccc = getc_unlocked(stdin);
    }
    *data = 0;
    return data - start;
}
template <class type> void print(type a) {
    if (a < 0) {
        putc_unlocked('-', stdout);
        a = -a;
    }
    if (a == 0) {
        putc_unlocked('0', stdout);
    } else {
        char result[20];
        int resSize = 0;
        while (a > 0) {
            result[resSize++] = '0' + a % 10;
            a /= 10;
        }
        while (--resSize >= 0) putc_unlocked(result[resSize], stdout);
    }
    putc_unlocked('\n', stdout);
}
void printString(const char *str) {
    while (*str) putc_unlocked(*str++, stdout);
    putc_unlocked('\n', stdout);
}

// SOLUTION

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b) cout << c;
	else if(a == c) cout << b;
	else cout << a;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}


const double inf = 1e18;
const double eps = 1e-12;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int xs,ys,xt,yt;cin >> xs >> ys >> xt >> yt;
	int n;cin >> n;
	vector<int> x(n),y(n),r(n);
	rep(i,n) cin >> x.at(i) >> y.at(i) >> r.at(i);
	vector<vector<double>> g(n + 2,vector<double>(n + 2,inf));
	rep(i,n){
		double t = sqrt(pow(xs - x.at(i), 2) + pow(ys - y.at(i), 2)) - r.at(i);
		if(t < 0) t = 0;
		g[0][i + 1] = t;
		g[i + 1][0] = t;
		t = sqrt(pow(xt - x.at(i), 2) + pow(yt - y.at(i), 2)) - r.at(i);
		if(t < 0) t = 0;
		g[n + 1][i + 1] = t;
		g[i + 1][n + 1] = t;
	}
	rep(i,n){
		for(int j = i + 1; j < n; j++){
			double t = sqrt(pow(x.at(i) - x.at(j), 2) + pow(y.at(i) - y.at(j), 2)) - r.at(i) - r.at(j);
			if(t < 0) t = 0;
			g[i + 1][j + 1] = t;
			g[j + 1][i + 1] = t;
		}
	}
	vector<double> dist(n + 2,inf);
	dist[n + 1] = sqrt(pow(xs - xt, 2) + pow(ys - yt, 2));
	dist.at(0) = 0;
	priority_queue<pair<double,int>, vector<pair<double,int>>, greater<pair<double,int>>> pq;
	pq.push(mp(0,0));
	while(!pq.empty()){
		double k = pq.top().first;
		int cur = pq.top().second;
		pq.pop();
		if(dist[cur] < k - eps) continue;
		rep(i,n + 2){
			if(k + g[cur][i] < dist[i] - eps){
				dist[i] = k + g[cur][i];
				pq.push(mp(dist[i],i));
			}
		}
	}
	cout << setprecision(20) << fixed << dist.at(n + 1) << endl;
}


Measured memory_bytes: 13808
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	
	// a graph structure based on adjacent graph
	public static class graph{
		public int v_num; // the number of vertices
		public List<List<Integer>> adj_table;
		
		public graph(int _v_num) {
			v_num = _v_num;
			adj_table = new ArrayList<List<Integer>>();
			for(int i = 0; i < v_num; i++) {
				adj_table.add(new ArrayList<Integer>());
			}
		}
		
		
		//src and dst is always 1-kara
		public void insert_edge(int src, int dst) {
			adj_table.get(src-1).add(dst);
		}
		
		// 1-kara
		public List<Integer> get_adj_nodes(int i){
			return adj_table.get(i-1); 
		}
	}
	
	public static int clock = 0;
	
	
	public static void _dfs(graph g, int current, int[] b, int []f) {
		clock++;
		b[current] = clock;
		List<Integer> adj_list = g.get_adj_nodes(current);
		for(int i = 0; i < adj_list.size(); i++) {
			if(b[adj_list.get(i)] == 0)
				_dfs(g, adj_list.get(i), b, f);
		}
		clock++;
		f[current] = clock;
	
	}
	
	public static void dfs(graph g) {
		int [] b = new int[g.v_num+1];
		int [] f = new int[g.v_num+1];
		int component_count = 0;
		for(int i = 1; i <= g.v_num; i++) {
			if(b[i] == 0) {
				_dfs(g, i, b, f);
				component_count++;
			}
		}

		for(int i = 1; i <= g.v_num; i++) {
			System.out.println(i + " "+ b[i]+" "+f[i]);
		}
	}
	
	public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		graph g = new graph(n);
		
		int src_id,  list_len; 
		for(int i = 0; i< n; i++) {
			src_id = cin.nextInt();
			list_len = cin.nextInt();
			while(list_len > 0) {
				g.insert_edge(src_id, cin.nextInt());
				list_len--;
			}
		}
		
		dfs(g);
		
		
		cin.close();
		
		
	}
}

Measured memory_bytes: 28604
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    ll x;
    cin >> x;
    ll res = 100;
    ll ans = 0;
	while(res < x) {
		ll rem = res / 100;
		res += rem;
		ans ++;
		//cout << res << endl;
	}
	cout << ans;
    return (0);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int main() {
	LL n;
	cin >> n;
	LL ans = n - 1;
	for (LL i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			ans = min(ans, i + n / i - 2);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int count = 0;
		int button = 1;
		int[] b = new int[n]; // 押されたボタン判定用
		while (true) {
			b[button - 1] = 1;
			button = a[button - 1];
			count++;

			if (button == 2) {
				System.out.println(count);
				break;
			}

			if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			}
		}



		sc.close();
	}

}


Measured memory_bytes: 50704
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

int main(){
    long long int a,b,i,res = 0,x;
    scanf("%lld %lld %lld",&a,&b,&x);
    res = b/x;
    res -= a/x;
    if(a%x == 0)
        res++;
    
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(ll n, vector<ll> a) {
  deque<ll> v;
  REP(i,n) {
    if (i & 1) v.push_front(a[i]);
    else v.push_back(a[i]);
  }
  if (n & 1) reverse(ALL(v));
  REP(i,n) {
    cout << v[i] << " \n"[i == n - 1];
  }
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll n;
	scanf("%lld", &n);
	vector<ll> a(n-1+1);
	for (int i = 0 ; i <= n-1 ; i++) {
	  scanf("%lld", &a[i]);
	}
	solve(n, a);
	return 0;
}


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

using namespace std;

const int maxn = 1e5+100;

int n, h[maxn], dp[maxn];

int solve(int x){
    if(dp[x]!=-1)return dp[x];
    if(x>n)return 0x3f3f3f3f;
    if(x==n)return 0;
    int case1 = abs(h[x+1]-h[x])+solve(x+1);
    int case2 = abs(h[x+2]-h[x])+solve(x+2);
    return dp[x]=min(case1, case2);
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n;

    for(int i=1; i<=n; i++)cin >> h[i];

    memset(dp, -1, sizeof dp);

    cout << solve(1) << endl;
}


Measured memory_bytes: 4224
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <forward_list>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cstdint>
#include <iomanip>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

map<pair<string,string>,ll> K[2];
int N;
string S,R[2];

int main(void) {
    cin >> N;
    cin >> S;
    for(int i = 1;i <= S.length()/2;i++)
        R[1].push_back(S[S.length()-i]);
    for(int i = 0;i < S.length()/2;i++)
        R[0].push_back(S[i]);
    for(unsigned long i = 0;i < pow(2,N);i++) {
        for(int l = 0;l < 2;l++) {
            unsigned long t = i;
            string s[2];
            for(int j = 0;j < N;j++) {
                if(t & (unsigned long)0b1)
                    s[0].push_back(R[l][j]);
                t = t >> 1;
            }
            t = ~i;
            for(int j = 0;j < N;j++) {
                if(t & (unsigned long)0b1)
                    s[1].push_back(R[l][j]);
                t = t >> 1;
            }
            K[l][make_pair(s[0], s[1])]++;
        }
    }
    ll ret = 0;
    for(auto& z:K[0]) {
        ret += z.second * K[1][z.first];
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 108288
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n;
  vector<long long> v, x;
  cin >> n;
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    x.push_back(a);
  }
  v = x;
  sort(v.begin(), v.end());
  long long a = v[v.size()/2 -1];
  long long b = v[v.size()/2];
  for (auto it = x.begin();it != x.end();it++) {
    if (*it <= a) {
      cout << b << endl;
    } else {
      cout << a << endl;
    }
  }
  return(0);
}


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

using namespace std;

const int N = 105;

int res[N][N];
int loc[N * N][2];

int main() {
  int h, w;
  scanf("%d %d", &h, &w);
  int now = 0;
  for (int i = 0; i < h; ++i) {
    int j = i % 2 ? w - 1 : 0;
    int g = i % 2 ? -1 : 1;
    for (int k = 0; k < w; ++k, j += g) {
      loc[now][0] = i;
      loc[now++][1] = j;
    }
  }
  now = 0;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    while (x--) {
      res[loc[now][0]][loc[now][1]] = i;
      ++now;
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      printf("%d%c", res[i][j], j == w - 1 ? '\n' : ' ');
    }
  }
  return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
int main (void){
int N,i,j,k=0;
scanf("%d",&N);
int p[N+1];
for(i=0;i<N;i++){
scanf("%d",&p[i]);
}
for(j=0;j<N;j++){
if(p[j]>j+1){k++;}
}
if(k<=1){
printf("YES");
}else{
printf("NO");
}
return 0;
}

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

int main() {
	int l1, l2;
	cin >> l1 >> l2;
	vector<string> g(l1);
	rep(i,l1) cin >> g[i];
	vector<string> v(l2);
	rep(i,l2) cin >> v[i];
	rep(i,l1) {
		rep(j,l1) {
			if (i + l2 - 1 >= l1 || j + l2 - 1 >= l1) continue;
			bool b = true;
			rep(x,l2) {
				rep(y,l2) {
					if (g[i+x][j+y] != v[x][y]) b = false;
				}
			}
			if (b) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>

int A[2000001],B[2000001],n;

void CountingSort() {
  int i,j,k=10000;
  int C[k];

  for(i=0;i<k;i++){
    C[i] = 0;
  }

  for(j=1;j<=n;j++){
    C[A[j]]++;
  }

  for(i=1;i<=k;i++){
    C[i] = C[i] + C[i-1];
  }

  for(j=n;j>0;j--){
    B[C[A[j]]] = A[j];
    //printf("%d\n",C[A[j]]);
    C[A[j]]--;
      }
}

int main() {
  int i;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }

  CountingSort();

  for(i=1;i<=n;i++){
    if(i==1) printf("%d",B[i]);
    else printf(" %d",B[i]);
  }

  printf("\n");

  return 0;
}
  
  



Measured memory_bytes: 17460
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf = 0x3f3f3f3f;
const int maxn = 100000;
int A[maxn];
int n;
int main()
{
  cin >> n;
  ll ans1 = 1;
  ll ans2 = 1;
  for (int i = 0; i < n; i++)
  {
    ans1 *= 3;
    cin >> A[i];
    if (A[i] & 1)
    {
      ans2 *= 1LL;
    }
    else
    {
      ans2 *=  2LL;
    }
  }
  cout << (ans1 - ans2) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
	string s;cin>>s;
	sort(s.begin(),s.end());
	if(s=="abc")cout<<"Yes";
	else cout<<"No";
	
}

Measured memory_bytes: 256
import numpy as np
from itertools import product
n, m, x = [int(x) for x in input().split()]
a = np.stack([np.array(input().split(), dtype=int) for _ in range(n)])
tot = np.sum(a, axis=0)
if min(tot[1:]) < x:
    print(-1)
    exit(0)
cost = tot[0]
whole = np.array(list(product([0,1],repeat=n)), dtype=bool)[1:-1]
for flag in whole:
    sel = a[flag]
    tot = np.sum(a[flag], axis=0)
    if min(tot[1:]) >= x and tot[0] < cost:
        cost = tot[0]
print(cost)


Measured memory_bytes: 27528
from sys import stdin
from copy import deepcopy


n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
for i, list in enumerate(data):
    list[1] = int(list[1])
    list.append(i+1)

sortdata = sorted(data, key=lambda x: (x[0], -x[1]))

for i, list in enumerate(sortdata):
    print(list[2])


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

int n, ans = 0;
vector<int> s(100010);

void binarySearch(vector<int> A, int key){
    int left = 0, right = n;
    while(left < right){
        int mid = (left+right)/2;
        if(A[mid] == key){
            ans++;
            break;
        }
        else if(A[mid] > key) right = mid;
        else if(A[mid] < key) left = mid+1;
    }
    
}

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

    for(int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    cin >> q;
    vector<int> t(q);
    for(int j = 0; j < q; j++)
    {
        cin >> t[j];
        binarySearch(s, t[j]);
    }
    cout << ans << endl;

    return 0;   
    
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int N = 1e4+5;
const int M = 1e4;
const int INF = 0x3f3f3f3f;

int main() {
	int n,a,b;
	scanf("%d",&n); 
	scanf("%d%d",&a,&b);
	
	for(int i = a;i <= b;++i){
		if(i % n == 0){
			printf("OK\n");
			return 0;
		}
	}
	printf("NG\n");
    return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
  cin >> N;
  vector<int> buka(N);
  for(int i = 0; i < N-1; i++){
  	int a;
    cin >> a;
    buka.at(a-1) ++;
  }
  for(int i = 0; i < N; i++){
  	cout << buka.at(i) << endl;
  }
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
  
  int N, num = 0 , now = 1 ;
  cin >> N;
  vector<int> next(N);
  
  for (int i = 0 ; i < N ; i++)
    cin >> next.at(i);
  
  while (true){
     
    if (now == 2){
      cout << num << endl;
      break;
    }
    else if (num > N){
      cout << -1 << endl;
      break;
    }
    
    else{
      now = next.at(now - 1);
      num ++;
    }
    
    
  }
}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int a[100001];
	scan(N);
	rep(i,N) scan(a[i]);
	sort(a,a+N);
	if(a[0]+1>=a[N-1]){
		int small=0,big=0;
		rep(i,N){
			if(a[i]==a[0]) small++;
			else big++;
		}
		if(big==0){
			if(a[0]==N-1||N>=a[0]*2) prin("Yes");
			else prin("No");
		}
		else{
			if(a[N-1]>small&&N>=small+(a[N-1]-small)*2) prin("Yes");
			else prin("No");
		}
	}
	else prin("No");
	return 0;
}


Measured memory_bytes: 640