akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  string s;
  cin>>s;
  cout<<(s=="AAA"||s=="BBB"?"No":"Yes")<<endl;



  return 0;
}




Measured memory_bytes: 256
n,q=gets.split.map(&:to_i)
s=gets.chomp
lrs=q.times.map{gets.split.map(&:to_i)}
sum=[0]*(n+1)
(n-1).times do |i|
  sum[i+1]+=1 if s[i]=="A" && s[i+1]=="C"
end
n.times{|i| sum[i+1]+=sum[i]}
lrs.each do |lr|
  puts sum[lr[1]-1]-sum[lr[0]-1]
end


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string base = "CODEFESTIVAL2016";
    string S;
    cin >> S;
    ll count = 0;
    rep(i, S.size()) {
        if(S[i] != base[i]) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

long long int mod = 1e9+7;

long long int fast_power(long long int x, long long int n){
  
  long long int ans = 1;
  long long int tmp = x;
  
  while(n > 0){
    if(n&1 != 0){
      ans *= tmp;
      ans = (ans + mod)%mod;
    }
    tmp = (tmp*tmp + mod)%mod;
    n = (n>>1);
  }
  return ans;
  
}

long long int inverse(long long int x){
  return fast_power(x, mod-2);
}

int main(){
  
  long long int N, K;
  scanf("%lld%lld", &N, &K);
  
  // the answer is (K-1)C(i-1) * ((N-K-1)C(i) + 2*(N-K-1)C(i-1))
  std::vector<long long int> factorial;
  factorial.push_back(1);
  for(long long int i = 1; i <= N; i++){
    factorial.push_back((factorial[i-1]*i+mod)%mod);
  }
  long long int A, B, C, D;
  for(long long int i = 1; i <= K; i++){
    //std::cerr << "i = " << i << std::endl;
    A = 0;
    B = 0;
    C = 0;
    D = 0;
    if(K-1 >= i-1){
      A = (factorial[K-1]*inverse(factorial[i-1])+mod)%mod;
      A = (A*inverse(factorial[K-i])+mod)%mod;
    }
    if(N-K-1 >= 0 && N-K-1 >= i){
      B = (factorial[N-K-1]*inverse(factorial[i])+mod)%mod;
      B = (B*inverse(factorial[N-K-1-i])+mod)%mod;
    }
    if(N-K-1 >= 0 && N-K-1 >= i-1){
      C = (factorial[N-K-1]*inverse(factorial[i-1])+mod)%mod;
      C = (C*inverse(factorial[N-K-i])+mod)%mod;
    }
    if(N-K-1 >= 0 && N-K-1 >= i-2 && i >= 2){
      D = (factorial[N-K-1]*inverse(factorial[i-2])+mod)%mod;
      D = (D*inverse(factorial[N-K-i+1])+mod)%mod;
    }
    else if(N == K && i == 1){
      D = 1;
    }
    //std::cerr << "A = " << A << " B = " << B << " C = " << C << " D =" << D << std::endl;
    std::cout << (A*(B+2*C+D) + mod)%mod << std::endl;
  }
  
  return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << fixed << setprecision(15) << (double)((n + 1) / 2) / n << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<stdlib.h>
#include<stdio.h>
#include<queue>
#include<stack>
#include<string.h>
#include<limits.h>
using namespace std;
typedef unsigned long long ull;

string str;
set<string>se;

int solve(string s){
    if(s.length()>str.length()){
        return 9999999;
    }
    if(se.count(s)){
        return 9999999;
    }
    se.insert(s);
    bool b=true;
    char c=s[0];
    for(int i=1;i<s.length();i++){
        if(s[i]!=c){
            b=false;
            break;
        }
    }
    if(b){
        return 0;
    }
    int mi=9999999;
    string ns='B'+s;
    
    while(ns.length()&&ns[0]=='B'){
        ns=ns.substr(1);
    }
    mi=min(mi,solve(ns));
    ns='W'+s;
    while(ns.length()&&ns[0]=='W'){
        ns=ns.substr(1);
    }
    mi=min(mi,solve(ns));
    ns=s+'B';
    while(ns.length()&&ns[ns.length()-1]=='B'){
        ns=ns.substr(0,ns.length()-1);
    }
    mi=min(mi,solve(ns));
    ns=s+'W';
    while(ns.length()&&ns[ns.length()-1]=='W'){
        ns=ns.substr(0,ns.length()-1);
    }
    mi=min(mi,solve(ns));
    return 1+mi;
}
bool dfs(){
    
    return false;
}
int main(){
    int n,t;
    vector<int>a;
    cin>>n>>t;
    set<int>se;
    int mi=INT_MAX,ma=0;
    int ans=0;
    map<int,int>m;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        mi=min(mi,x);
        if(x-mi>=ma){
            m[x-mi]++;
        }
        ma=max(ma,x-mi);
        a.push_back(x);
        
    }
    cout<<m[ma]<<endl;
}


Measured memory_bytes: 5368
(defun barasu (n &optional (acc 1))
  (cond ((= n acc)
         acc)
        ((< n acc)
         (1- acc))
        (t 
         (barasu (- n acc) (1+ acc)))))      

(defun main (n)
  (let ((p 2)
        (ans-e 0)
        (ans 0))
    ;;
    (loop :named yyy
          :do (cond ((= n 1)
                     (incf ans (barasu ans-e))
                     (return-from yyy))
                    ((= n p)
                     (setf n (/ n p))
                     (incf ans-e))
                    ((> p (sqrt n))
                     (incf ans (barasu ans-e))
                     (incf ans)
                     (return-from yyy))
                    ((= (mod n p) 0)
                     (setf n (/ n p))
                     (incf ans-e))
                    (t
                     (incf ans (barasu ans-e))
                     (setf ans-e 0)
                     (incf p))))
      ;;
      ans))
(let ((n (read)))
  (format t "~A~%" (main n)))


Measured memory_bytes: 24348
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<functional>
#include<math.h>
#include<algorithm>
typedef long long ll;
using namespace std;

map<char,int> miria;

int main(){
  int N;
  cin >> N;
  string tmp;
  cin >> tmp;
  for(int i=0;i<N;i++){
    miria[tmp[i]]++;
  }
  if(miria['R'] > miria['B']){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int ,input().split()))
l = [a[0]]
r = [a[-1]]
def gcd(a, b):
    while a % b:
        a, b = b, a % b
    return b

for i in range(1,n-2):
        l.append(gcd(l[-1],a[i]))
for i in range(2,n-1)[::-1]:
        r.append(gcd(r[-1],a[i]))
r = r[::-1]
ans = []
for i in range(len(l)):
        ans.append(gcd(l[i],r[i]))
ans.append(gcd(l[-1],a[-2]))
ans.append(gcd(r[0],a[1]))

print(max(ans))

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

int main()
{
    long long int n,i;
    cin>>n;
    map<string,long long int> mp;
    for(i=0;i<n;i++)
    {
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }

    map<string,long long int>::iterator it;
    long long int ans=0;
    for(it=mp.begin();it!=mp.end();it++)
    {
        ans+=(it->second*(it->second-1))/2;
    }

    cout<<ans;
}


Measured memory_bytes: 11264
#include<stdio.h>

const int N = 105;

int main()
{
	int a[N][N], r, c, b[N], e[N];
	scanf("%d %d", &r, &c);
	
	for(int i = 0; i < r; i++)
	{
		for(int j = 0; j < c;j++)
		{
			scanf("%d", &a[i][j]);
			b[i] += a[i][j];			
		}
	}
	
	for(int i = 0; i < r; i++)
	{
		for(int j = 0; j < c; j++)
		{
			printf("%d ", a[i][j]);			
		}
		printf("%d\n", b[i]);
	}
	for(int i = 0; i < r; i++)
	{
		for(int j = 0; j < c; j++)
		{
			e[j] += a[i][j];
			if(i == r-1)
			{
				printf("%d ", e[j]);
			}
		}
		e[c] += b[i];
	}
	printf("%d\n", e[c]);
	return 0;
	
}


Measured memory_bytes: 2764
#include <iostream>
#include <string>

using namespace std;

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

        if (b == "A")
cout << "T" << endl;
        else if(b == "T")
cout << "A" << endl;
        else if (b == "C")
cout << "G" << endl;
        else if (b == "G")
cout << "C" << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
M=10**9+7
def inverse(number_inverse,mod_inverse):
    m_inverse=mod_inverse-2
    mod2_inverse=""
    while m_inverse!=0:
        if m_inverse%2==0:
            mod2_inverse="0"+mod2_inverse
        else:
            mod2_inverse="1"+mod2_inverse
        m_inverse=m_inverse//2
    two_inverse=[]
    for i in range(len(mod2_inverse)):
        if mod2_inverse[len(mod2_inverse)-1-i]=="1":
            two_inverse.append(i)
    ret_inverse=1
    for i in two_inverse:
        v_inverse=i
        retsub_inverse=number_inverse
        while v_inverse>0:
            retsub_inverse=retsub_inverse**2
            retsub_inverse=retsub_inverse%mod_inverse
            v_inverse-=1
        ret_inverse*=retsub_inverse
    ret_inverse=ret_inverse%mod_inverse
    return ret_inverse
def comb(n_comb,r_comb,mod_comb):
    ret_comb=0
    if n_comb==0:
        ret_comb=1
    elif r_comb==0:
        ret_comb=1
    else:
        a_comb=1 #分子
        numa_comb=n_comb
        for i in range(r_comb):
            a_comb*=numa_comb
            a_comb%=mod_comb
            numa_comb-=1
        c_comb=1 #r!
        numc_comb=r_comb
        for i in range(r_comb):
            c_comb*=numc_comb
            c_comb%=mod_comb
            numc_comb-=1
        ret_comb=a_comb*inverse(c_comb,mod_comb)
        ret_comb%=mod_comb
    return ret_comb
for p in range(1,k+1):
    if n-k-p+1<0:
        print(0)
    else:
        s1=comb(k-1,p-1,M)
        s2=comb(n-k+1,p,M)
        ans=(s1*s2)%M
        print(ans)


Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> n >> k;
  vvl d = vv(n, 2, 0, ll);
  re(i, n) std::cin >> d[i][0] >> d[i][1];
  sort(all(d));

  for(int i=0;i<n;i++){
    if(k<=d[i][1]){
      std::cout << d[i][0] << '\n';
      return 0;
    }
    k-=d[i][1];
  }
}


Measured memory_bytes: 5760
N=int(input())
A=list(map(int,input().split()))

B={}
for i in range(N):
    if A[i] not in B:
        B[A[i]]=1
    else:
        B[A[i]]+=1

total=0

for k,v in B.items():
    total+=v*(v-1)//2

for i in range(N):
    ans=total
    ans-=B[A[i]]-1
    print(ans)


Measured memory_bytes: 26140
def divisors(n):
    DIVISORS = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            DIVISORS.append(i)
            if i != n**0.5:
                DIVISORS.append(n // i)
    DIVISORS.sort()
    return DIVISORS


n, m = map(int, input().split())

A = divisors(m)

ans = 0
for a in A:
    if m // a >= n:
        ans = a

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>

using namespace std;

double abs( double x , double y){
  if( x - y < 0){ return y - x;}
  else{return x - y;}}

int main(){
  int N; double T,A; cin >> N >> T >> A;
  vector<int> H(N); int ans = 0;
  for(int i = 0; i < N; i++){ cin >> H[i];}
  double min_diff = 1e5;
  for(int i = 0; i < N; i++){
    double m = abs( T - 0.006 * (double)H[i] , A);
    if( m < min_diff){ ans = i+1; min_diff = m;}}
  
  cout << ans << endl;
  
  return 0;}

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var nl = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var n = nl[0];
            var l = nl[1];
            var taste = new int[n].ToList();
            for (var i = 0; i < n; i++)
            {
                taste[i] = l + i;
            }
            if (taste.Contains(0))
            {
                Console.WriteLine(taste.Sum());
                return;
            }
            var min = int.MaxValue;
            var minj = 0;
            for (var i = 0; i < n; i++)
            {
                if (min > Math.Abs(taste[i]))
                {
                    min = Math.Abs(taste[i]);
                    minj = i;
                }
            }
            if (taste[minj] > 0)
            {
                Console.WriteLine(taste.Sum() - Math.Abs(taste[minj]));
            }
            else
            {
                Console.WriteLine(taste.Sum() + Math.Abs(taste[minj]));
            }
        }
    }
}


Measured memory_bytes: 13152
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int count = 0;
    while(b <= a)
    {
        count++;
        b *= 2;
    }

    while(c <= b)
    {
        count++;
        c *= 2;
    }

    Print(a);
    Print(b);
    Print(c);
    Print(k);
    Print(count);


    if(count <= k)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int a[3], d; cin >> a[0] >> a[1] >> a[2] >> d;
	
	if(abs(a[1] - a[0]) <= d and abs(a[2] - a[1]) <= d) cout << "Yes" << endl;
	else if(abs(a[0] - a[2]) <= d) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
using Weight = long long int;
struct Edge {
	int src, dst;
	Weight weight;
	int tate;
	Edge(int src_, int dst_, Weight weight_,bool a) :
		src(src_), dst(dst_), weight(weight_),tate(a) { }
	Edge(int src, int dst, Weight weight) :
		src(src), dst(dst), weight(weight) { }
	Edge() :src(0), dst(0), weight(0) {

	}
};
struct Node {
	int x;
	int y;
	int id;
};
struct aa {
	int id;
	int tate;
	Weight time;
};
class Compare {
public:
	//aa?????????????????¶
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};
Weight getans(vector<vector<Edge>>&g, const bool startswitch,int s,int t) {
	priority_queue<aa,vector<aa>,Compare>que;
	que.push(aa{ 0,true,0 });
	if (startswitch) {
		que.push(aa{ 0,false,1 });
	}
	vector<vector<Weight>>memo(g.size(), vector<Weight>(2,1e18));

	while (!que.empty()) {
		aa atop(que.top());
		if (atop.id == t)return atop.time;
		que.pop();
		if (atop.id) {
			if (memo[atop.id][!atop.tate]>atop.time+1) {
				memo[atop.id][!atop.tate] = atop.time + 1;
				que.push(aa{ atop.id,!atop.tate,atop.time + 1 });
			}
		}
		for (auto e : g[atop.id]) {
			if (e.tate != atop.tate)continue;
			const Weight nexttime = atop.time + e.weight;
			if (memo[e.dst][e.tate] > nexttime) {
				memo[e.dst][e.tate] = nexttime;
				que.push(aa{ e.dst,e.tate,nexttime });
			}
		}
	}
	return -1;
}
int main() {
	int M, N, K; cin >> M >> N >> K;
	vector<Node>ps;
	bool startswitch = false;
	int id = 0;
	ps.push_back(Node{ 0,0,id++ });
	for (int i = 0; i < K; ++i) {
		int x, y; cin >> x >> y; x--; y--;
		if (x == 0 && y == 0) {
			startswitch = true;
		}
		else if (x == M-1&&y == N-1) {

		}
		else {
			ps.push_back(Node{ x,y,id++ });
		}
	}
	ps.push_back(Node{ M-1,N-1,id });
	vector<vector<Edge>>g(K + 2);
	sort(ps.begin(), ps.end(), [](const Node&l, const Node&r) {
		return l.x == r.x ? l.y < r.y : l.x < r.x;
	});
	for (int i = 0; i < ps.size() - 1; ++i) {
		Node l = ps[i];
		Node r = ps[i + 1];
		if (l.x == r.x) {
			g[l.id].push_back(Edge(l.id, r.id, r.y - l.y, true));
			g[r.id].push_back(Edge(r.id, l.id, r.y - l.y, true));
		}
	}
	sort(ps.begin(), ps.end(), [](const Node&l, const Node&r) {
		return l.y == r.y ? l.x < r.x : l.y < r.y;
	});
	for (int i = 0; i < ps.size() - 1; ++i) {
		Node l = ps[i];
		Node r = ps[i + 1];
		if (l.y == r.y) {
			g[l.id].push_back(Edge(l.id, r.id, r.x - l.x, false));
			g[r.id].push_back(Edge(r.id, l.id, r.x - l.x, false));
		}
	}
	long long int ans = getans(g,startswitch,0,id);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 44588
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long lint;

const lint INF = 1001001001001001001;

class Point {
	public:
	int x, y, id;
	Point(int x = 0, int y = 0, int id = 0) : x(x), y(y), id(id){}
	Point operator - (Point p){ return Point (x - p.x, y - p.y);}
};

int cross(Point a, Point b)
{
	return (a.x * b.y - a.y * b.x);
}

Point p;

bool sortT(Point a, Point b)
{
	return (cross(a - p, b - p) > 0);
}

vector<Point> normalize(vector<Point> &v)
{
	int pt = 0;
	for (int i = 1; i < v.size(); i++){
		if (v[pt].y > v[i].y || (v[pt].y == v[i].y && v[pt].x > v[i].x)){
			pt = i;
		}
	}
	swap(v[pt], v[0]);
	p = v[0];
	sort(v.begin() + 1, v.end(), sortT);
	return (v);
}

int area(Point a, Point b, Point c)
{
	return (abs(cross(c - a, b - a)));
}

lint dp[41][41][41][41];
int prev[41][41][41][41];

int main()
{
	int N, Q;
	
	scanf("%d", &N);
	
	vector<Point> v;
	for (int i = 0; i < N; i++){
		Point t;
		t.id = i;
		scanf("%d %d", &t.x, &t.y);
		v.push_back(t);
	}
	
	for (int i = 0; i <= N; i++) for (int j = 0; j <= N; j++) for (int k = 0; k <= N; k++) for (int l = 0; l <= N; l++)
		dp[i][j][k][l] = INF;
	
	for (int i = 0; i < N; i++){
		vector<Point> v2;
		for (int j = 0; j < N; j++){
			if (v[i].x < v[j].x || (v[i].x == v[j].x && v[i].y < v[j].y)){
				v2.push_back(v[j]);
			}
		}
		
		p = v[i];
		sort(v2.begin(), v2.end(), sortT);
		
		for (int j = 0; j < v2.size(); j++){
			for (int k = j + 1; k < v2.size(); k++){
				dp[3][i][v2[j].id][v2[k].id] = area(v[i], v2[j], v2[k]);
			}
		}
		
		for (int j = 4; j <= N; j++){
			for (int k = 0; k < v2.size(); k++){
				for (int l = k + 1; l < v2.size(); l++){
					for (int m = 0; m < k; m++){
						if (cross(v2[k] - v2[m], v2[l] - v2[m]) > 0 && dp[j][i][v2[k].id][v2[l].id] > dp[j - 1][i][v2[m].id][v2[k].id] + area(v[i], v2[k], v2[l])){
							dp[j][i][v2[k].id][v2[l].id] = dp[j - 1][i][v2[m].id][v2[k].id] + area(v[i], v2[k], v2[l]);
							prev[j][i][v2[k].id][v2[l].id] = v2[m].id;
						}
					}
				}
			}
		}
	}
	
	scanf("%d", &Q);
	
	for (int i = 0; i < Q; i++){
		int num;
		scanf("%d", &num);
		
		int piv1, piv2, piv3;
		lint ans = INF;
		for (int j = 0; j < N; j++) for (int k = 0; k < N; k++) for (int l = 0; l < N; l++){
			if (dp[num][j][k][l] < ans){
				ans = dp[num][j][k][l];
				piv1 = j; piv2 = k; piv3 = l;
			}
		}
		
		if (ans == INF) printf("NA\n");
		else {
			vector<Point> res;
			while (num != 3){
				res.push_back(v[piv3]);
				int t = prev[num][piv1][piv2][piv3];
				num--;
				piv3 = piv2;
				piv2 = t;
			}
			res.push_back(v[piv3]); res.push_back(v[piv2]); res.push_back(v[piv1]);
			res = normalize(res);
			for (int i = 0; i < res.size(); i++) printf("%d%c", res[i].id + 1, " \n"[i == res.size() - 1]);
		}
	}
	
	return (0);
}

Measured memory_bytes: 28896
;;;; q
(defstruct queue (entrance nil) (exit nil))

(defun enqueue (item queue)
  (let ((cell (list item)))
    (if (queue-entrance queue)
        (setf (cdr (queue-entrance queue)) cell)
        (setf (queue-exit queue) cell))
    (setf (queue-entrance queue) cell)))

(defun dequeue (queue)
  (when (queue-exit queue)
    (prog1 (pop (queue-exit queue))
      (unless (queue-exit queue)
        (setf (queue-entrance queue) nil)))))

;;;; main
(let* ((h (read))
       (w (read))
       (s (make-array (list h w) :initial-element nil))
       (e (make-array (list h w) :initial-element nil))
       (num 0)
       (ans 0))
  ;;
  (loop :for i :from 0 :to (1- h)
        :for l := (read-line)
        :do (loop :for j :from 0 :to (1- w)
                  :do (when (char= (aref l j) #\.)
                        (setf (aref s i j) t)
                        (incf num))))
  ;
  (loop :for i :from 0 :to (1- h)
        :do (loop :for j :from 0 :to (1- w)
                  :do (loop :for (di . dj) :in '((0 . -1) (0 . 1) (1 . 0) (-1 . 0))
                            :if (and (<= 0 (+ i di) (1- h)) (<= 0 (+ j dj) (1- w)) (aref s (+ i di) (+ j dj)))
                            :do (push (cons (+ i di) (+ j dj)) (aref e i j)))))
  ;
  (loop :for si :from 0 :to (1- h)
        :do (loop :for sj :from 0 :to (1- w)
                  :if (aref s si sj)
                  :do (let ((q (make-queue))
                            (chk (make-array (list h w) :initial-element nil))
                            (cnt 0))
                        (enqueue (list* si sj 0) q)
                        (loop :while (queue-exit q)
                              :for (i j . p) := (dequeue q)
                              :do (unless (aref chk i j)
                                    (setf (aref chk i j) t)
                                    (incf cnt)
                                    (when (= cnt num)
                                      (setf ans (max ans p))
                                      (return))
                                    (loop :for (y . x) :in (aref e i j)
                                          :if (not (aref chk y x))
                                          :do (enqueue (list* y x (1+ p)) q)))))))
  ;
  (format t "~A~%" ans))


Measured memory_bytes: 40624
n, k = map(int, input().split())
a = list(map(int, input().split()))

cnt1 = 0
cnt2 = 0
mod = 10**9+7
for i in range(0, n):
    for j in range(i+1, n):
        if a[i] > a[j]:
            cnt1 += 1
        elif a[i] < a[j]:
            cnt2 += 1
print(((k*(k+1)//2 % mod) * cnt1 % mod + ((k-1)*k//2 % mod)*cnt2 % mod) % mod)


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>

#define rep(i,n)	for(int i = 0;i < n;i++)
#define rep2(i,n)	for(int i = 1;i <= n;i++)
#define each(i,x)	for(auto & i : x)

using namespace std;

int main()
{
	int p = 1;
	int n;
	cin >> n;
	while(n)
	{
		vector<int> xa;
		vector<int> ya;
		rep(i,n)
		{
			int x,y;
			cin >> x >> y;
			xa.push_back(x);
			ya.push_back(y);
		}
		double s = 0;
		rep(i,n)
		{
			s += xa[i]*ya[(i+1)%n]-xa[(i+1)%n]*ya[i];
		}
		printf("%d %.1lf\n",p,abs(s)/2.0);
		cin >> n;
		p++;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n; cin >> n;
    cout << n * n * n << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <cmath>

int main(void)
{
    int N;
    std::cin >> N;
    long sum = std::pow(3,N);
    int gunsuu_sum = 1;

    for(int i=0;i<N;i++){
        int a;
        std::cin >> a;
        if(a%2 == 0) gunsuu_sum*=2;
    }

    std::cout<<sum-gunsuu_sum<<std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    s+='_';//番兵

    char pc=s[0];
    int i=0;
    int k=0;
    bool extra=false;
    for (int j = 1; j < s.length(); j++) {
      if(pc==s[j]){
        continue;
      }
      int len=j-i;
      if(extra){
        k+=len/3*2+len%3;
        extra=len%3==0;
      }else{
        k+=len/3*2+(len%3>0);
        extra=len%3==2;
      }
      i=j;
      pc=s[j];
    }
    
    cout << k << endl;
    return 0;
}


Measured memory_bytes: 644
from collections import Counter
from functools import reduce


def factor(n):
    res = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            res.append(i)
            n //= i
    if n > 1:
        return res + [n]
    else:
        return res


N = int(input())
MOD = 10 ** 9 + 7
factors = reduce(lambda x, y: x + y, [factor(i) for i in range(1, N + 1)])
ans = 1
for v in Counter(factors).values():
    ans *= v + 1
    ans %= MOD
print(ans)


Measured memory_bytes: 3680
program sample
	implicit none
    integer(8) :: N,i,count,average,sum1
    integer(8),allocatable :: x(:),a(:),b(:)
    real(8) :: count2,average2
    
    read(*,*) N
    
    allocate(x(N))
    allocate(b(N))
    
    
    read(*,*) x
    
    !write(*,*) x
    
    count =0
    count2=0
    do i=1,N
    	b(i) = x(i)-x(1)
        count = count +x(i)
        count2= count2 +real(x(i))
    end do
    
    average = count / N
    average2 = count2 /N
    
    sum1= 0
    if (maxval(b) ==minval(b)) then
    	write(*,*) 0
    else if (abs(average2-average) >= abs(average2-average-1) ) then
    	do i=1,N
        	sum1= sum1 + (x(i)-average-1)**2
        end do
        write(*,*) sum1
    else
    	do i=1,N
        	sum1 = sum1 + (x(i)-average) **2
    	end do
    	write(*,*) sum1
    end if
    
	deallocate(x)
    stop
end program sample

Measured memory_bytes: 256
n, k = map(int, raw_input().split())
h = map(int, raw_input().split())
INF = 2 ** 32
dp = [INF for i in xrange(n)]
dp[0] = 0
for i in xrange(n):
    for j in xrange(k+1):
        if i - j >= 0:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
print dp[n-1]
        


Measured memory_bytes: 42348
import sys

N, Q = map(int, input().split())

S = str(input())

ruisekiwa = [0]
for i in range(len(S)):
    if S[i] == 'C' and S[i-1] == 'A':
        ruisekiwa.append(ruisekiwa[-1]+1)
    else:
        ruisekiwa.append(ruisekiwa[-1])

# print(ruisekiwa)
for line in sys.stdin.readlines():
    l, r = map(int, line.strip().split())
    print(ruisekiwa[r]-ruisekiwa[l])


Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    for(int i = 0; i < n; i++){
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

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

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

int main() {
    int N;
    cin >> N;
    vector<P> X(N);
    for (int i = 0; i < N; i++) {
        ll x, l;
        cin >> x >> l;
        X[i] = P(x, l);
    }
    sort(X.begin(), X.end());

    int toRemove = 0;
    ll last = INT32_MIN;
    for (int i = 0; i < N; i++) {
        if (X[i].first - X[i].second < last) {
            toRemove++;
            last = min(last, X[i].first + X[i].second);
        } else {
            last = X[i].first + X[i].second;
        }
    }

    cout << N - toRemove << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int main()
{
	int n;
	long long a;
	long long la;
	cin>>n;
	int t=0;
	int f=0;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(i!=0&&f==0)
			if(a>la)
			{
				f=1;
			}
			else if(a<la)
			{
				f=2;
			}
		if(f==1&&a<la)
		{
			f=0;
			t++;
		}
		if(f==2&&a>la)
		{
			f=0;
			t++;
		}
		la=a;
	}
	cout<<t+1<<endl;
	return 0;
}

Measured memory_bytes: 256
function main(arg) {    
 	arg = arg.trim().split('\n');
 	var n = Number(arg[0]),
  		cut = arg[1].split('');
 
  	console.log(cut.map(function(str) {
      var num = str.charCodeAt() + n;
      if (num > 90) {
        num -= 26;
      }
      return String.fromCharCode(num)
    }).join(''));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;

ll mp[50][26];
int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  REP(i, n) { cin >> s[i]; }
  map<char, ll> cnt;
  REP(i, n) {
    REP(j, s[i].length()) { mp[i][s[i][j] - 'a']++; }
  }

  REP(j, 26) { cnt['a' + j] = mp[0][j]; }
  REP(i, n) {
    REP(j, 26) { cnt['a' + j] = min(cnt['a' + j], mp[i][j]); }
  }

  string ans = "";
  REP(i, 26) { ans.append(cnt['a' + i], 'a' + i); }

  cout << ans;

  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 a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();

		int sub = b - a;

		if (k * 2 > sub) {
			for (int i = a; i < b + 1; i++) {
				System.out.println(i);
			}

		} else {

			for (int i = a; i < a + k; i++) {
				System.out.println(i);
			}

			for (int i = b - k + 1; i < b + 1; i++) {
				System.out.println(i);
			}
		}

		sc.close();

	}
}


Measured memory_bytes: 23764
/*
 * Code be weshen zyk :'(
 * I won't surrender quietly
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <bits/stdc++.h>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define S second
#define F first
#define pb push_back

using ii = pair<int, int>;
using ll = long long;
using db = long double;

const int N = 50, K = 205, MOD = 998244353;
const ll MX = 1e15;
const int blkSz = 320;
int sz[N + 1];
int n, x, d;
ll m[N + 1], p[N + 1];
ll dp[N * N * N + 1];
int main() {
//#ifdef ONLINE_JUDGE
//	ios_base::sync_with_stdio(0);
//	cin.tie(0);
//#endif

	cin >> n >> x >> d;
	cin >> m[1];
	sz[1] = 1;
	for (int i = 2; i <= n; i++) {
		cin >> m[i] >> p[i];
		sz[i] = 1;
	}

	for (int i = n; i >= 1; --i) {
		sz[p[i]] += sz[i];
		m[p[i]] += m[i];
	}

	int ord[n + 1];
	iota(ord + 1, ord + n + 1, 1);

	sort(ord + 1, ord + n + 1, [](int i, int j) {
		///cost / doughnut
		///m[i] / sz[i] < m[j] / sz[j];
			return 1ll * m[i] * sz[j] < 1ll * m[j] * sz[i];
		});
	fill(dp + 1, dp + N * N * N + 1, x + 1);
	int limit[n + 1];
	fill(limit + 1, limit + n + 1, d);
	limit[1] = (1 << 30);
	for (int i = 1; i <= n; i++) {
		for (int bag = N * N * N; bag >= 0; --bag)
			for (int take = 0;
					bag - take * sz[i] >= 0 && take <= min(N, limit[i]); take++)
				dp[bag] = min(dp[bag], dp[bag - take * sz[i]] + m[i] * take);
	}
	int ans = 0;
	for (int take = 0; take <= N * N * N; take++)
		if (dp[take] <= x) {
			int pLimit[n + 1];
			int tmp = take;
			int lft = x - dp[take];
			int cur = take;
			for (int j = 1; j <= n; j++) {
				int howMuch = lft / m[ord[j]];
				howMuch = max(0, min(howMuch, (limit[ord[j]] - 50)));
				cur += howMuch * sz[ord[j]];
				lft = lft - m[ord[j]] * howMuch;
			}
			ans = max(ans, cur);
		}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 1280
import sys

input = sys.stdin.readline

n = int(input())
h_list = list(map(int, input().split()))

tmp = 0
flag = False

for h in h_list:

    if tmp == 0:
        tmp = h
        continue

    if tmp > h:
        if tmp - 2 >= h:
            print("No")
            exit(0)
        tmp = h
        if flag:
            print("No")
            exit(0)
        else:
            flag = True
    elif tmp < h:
        tmp = h
        flag = False

print("Yes")


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    unordered_map<int,int>mp;
    int n;cin >>n;
    for (int i = 0; i < n; ++i) {
        int a;cin>>a;
        mp[a]=1-mp[a];
    }
    int ans=0;
    for(auto p:mp){
        if(p.second>0){
            ans++;
        }
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 7132
require 'set'
S = gets.chomp.chars
K = gets.to_i

set = Set.new
(0...(S.size)).each do |i|
  (i...([i + 5, S.size].min)).each do |j|
    set.add(S[i..j].join(''))
  end
end
puts set.to_a.sort[K - 1]


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

using namespace std;

using ll = long long;

constexpr ll MOD = 1e9 + 7;

ll N, X;
vector<ll> s;
vector<vector<ll>> memo;

ll Rec(int idx, ll x) {
    if (idx == N) return x;
    if (memo[idx][x] != -1) return memo[idx][x];

    ll &res = memo[idx][x];
    res = Rec(idx + 1, x % s[idx]) % MOD;
    (res += Rec(idx + 1, x) * (N - idx - 1)) %= MOD;

    return res;
}

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

    cin >> N >> X;
    s.resize(N);
    for (auto &s_i : s) cin >> s_i;
    sort(s.begin(), s.end(), greater<ll>());

    memo.resize(N, vector<ll>(X + 1, -1));
    cout << Rec(0, X) << endl;

    return 0;
}


Measured memory_bytes: 157824
#include<stdio.h>
int main()
{
    int n,n1,n2,n3;
    while(~scanf("%d",&n))
    {
        n1=n%100%10;
        n2=n%100/10;
        n3=n/100;
        if(n1==n3)
        {
            printf("Yes\n");
        }
        else
            printf("No\n");
    }
}


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

using namespace std;
using ll = long long int;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n;
    cin >> n;

    ll v[] = {101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381,1451,1471,1481,1511,1531,1571,1601,1621,1721,1741,1801,1811,1831,1861,1871,1901,1931,1951,2011,2081,2111,2131,2141,2161,2221,2251,2281,2311,2341,2351,2371,2381,2411,2441,2521,2531,2551,2591};
    for(ll i=0; i<n; i++)
        cout << v[i] << ' ';
    cout << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  
  int ans = 0;
  while(true){
    bool odd = false;
    for(int i = 0; i < n; i++){
      if(a[i] % 2 == 1){
        odd = true;
      }
    }
    if(odd) break;
    ans++;
    for(int i = 0; i < n; i++){
      a[i] /= 2;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
  {
  int a,b,c,x,y;
  scanf("%d%d%d",&a,&b,&c);
  x=a;
  a=b;
  b=x;
  y=a;
  a=c;
  c=y;
  printf("%d %d %d",a,b,c);
  }

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


ll N,K,ma=-1;
vector<ll> A(200010);


bool C(ll x){

    ll num = 0;
    rep(i,N){
        if(A[i] % x) num += (A[i]/x);
        else num += ((A[i]/x)-1);
    }
    return num <= K;
}


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

    rep(i,N){
        cin >> A[i];
        ma = max(ma,A[i]);
    }

    ll ok = 1, ng = ma+1;

    while(ok <= ng){
        ll mid = (ng+ok) / 2;
        if(C(mid)) ng = mid-1;
        else ok = mid+1;
    }
    
    cout << ok << endl;
}

Measured memory_bytes: 4696
#include <iostream>
#include <sstream>

int main() {
    int H, W;
    std::stringstream ss;
    while (std::cin >> H >> W) {
        if (H == 0 && W == 0) break;
        else {
            for (int i=0;i<H;i++) {
                for (int j=0;j<W;j++)
                    ss << "#";
                ss << "\n";
            }
            ss << "\n";
        }
    }

    std::cout << ss.str();
    
    return 0;
}


Measured memory_bytes: 3292
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
int a[100010];
int maxIndex;
int main(){ _;
  int n;cin>>n;
  REP(i,n){
    cin>>a[i];
    if(a[i]>a[maxIndex]){
      maxIndex=i;
    }
  }
  int mindistance=1e9+10;
  int mindistanceIndex;
  REP(i,n){
    if(i==maxIndex)continue;
    int distance=a[maxIndex]-min(a[i],a[maxIndex]-a[i]);
    if(mindistance>distance){
      mindistance=distance;
      mindistanceIndex=i;
    }
  }
  cout<<a[maxIndex]<<" "<<a[mindistanceIndex]<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <deque>
using namespace std;

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

    deque<char> ans;
    bool reverse = false;

    // 初期化
    for (auto c : s)
    {
        ans.emplace_back(c);
    }
    

    // クエリー実行
    for (size_t i = 0; i < q; i++)
    {
        int type;
        cin >> type;

        if (type == 1) {
            // 反転させる
            reverse = !reverse;
            continue;
        } else if (type == 2) {
            int fi;
            cin >> fi;

            char c;
            cin >> c;

            if (reverse) {
                if (fi == 1) {
                    ans.emplace_back(c);
                } else if (fi == 2) {
                    ans.emplace_front(c);
                }
            } else {
                if (fi == 1) {
                    ans.emplace_front(c);
                } else if (fi == 2) {
                    ans.emplace_back(c);
                }
            }
        }
    }


    // 出力する
    if (reverse)
    {
        while (!ans.empty())
        {
            char c = ans.back();
            ans.pop_back();
            cout << c;
        }
    }
    else
    {
        while (!ans.empty())
        {
            char c = ans.front();
            ans.pop_front();
            cout << c;
        }
    }
}

Measured memory_bytes: 960
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }

    public static long Gcd(long a, long b)
    {
	if (a < b){ return Gcd(b, a); }
	while (b != 0)
	{
	    var r = a % b;
	    a = b;
	    b = r;
	}
	return a;
    }
}

class Program
{
    static int checkChar(string s, long L, long i)
    {
	int n = s.Length;
	long a = L / n;
	if (i % a == 0)
	{
	    return (int) s[(int)(i/a)];
	}
	else
	{
	    return -1;
	}
    }

    static bool check(string s, string t, long L)
    {
	int m = t.Length;
	for (int i = 0; i < m; i++)
	{
	    long a = (int) (L / m);
	    int c = checkChar(s, L, i*a);
	    if (c > 0 && c != (int) t[i])
		return false;
	}
	return true;
    }
    
    public static void Main()
    {
	var tmp = ReadLongArray();
	long n = tmp[0], m = tmp[1];
	long g = n * m / Gcd(n, m);

	string s = ReadLine();
	string t = ReadLine();

	WriteLine(check(s, t, g) ? g : -1);
    }
}


Measured memory_bytes: 13364
#include <stdio.h>

#define N 50

int main(void) {
	int n,r;
	int c[N];
	int deck_A[N],deck_B[N],deck_C[N];
	int i,j,k;
	int len;
	int last;

	// input the number of cards n and the number of operations r
	while (scanf("%d%d",&n,&r) != EOF) {
		// input each operation c
		for (i = 0;i != r;++i) {
			scanf("%d",&c[i]);
		}
		// init the deck
		for (i = 0;i != n;++i) {
			deck_C[i] = i;
		}
		// riffle shuffle
		for (i = 0;i != r;++i) {
			// divide cards into deck A and deck B
			// deck A consists of the top half, and deck B of the bottom half
			len = n/2;
			for (j = 0;j != len;++j) {
				deck_B[j] = deck_C[j];
			}
			for (k = 0;j != n;++k,++j) {
				deck_A[k] = deck_C[j];
			}
			// operate
			len = n/2 - n/2%c[i];
			// j is index of deck A and B,k is index of deck C
			for (j = 0,k = 0;j != len;++j) {
				deck_C[k] = deck_A[j];
				deck_C[k + c[i]] = deck_B[j];
				k += (j + 1)%c[i] == 0 ? 1 + c[i] : 1;
			}
			len = (1 + n)/2;
			last = j;
			for (;j != len;++j,++k) {
				deck_C[k] = deck_A[j];
			}
			len = n/2;
			for (j = last;j != len;++j,++k) {
				deck_C[k] = deck_B[j];
			}
		}
		printf("%d\n",deck_C[n - 1]);
	}
	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

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

using namespace std;
typedef long long int64;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int a,b;
  cin>>a>>b;
  if(a<=8&&b<=8){
    cout<<"Yay!"<<endl;
  }else{
    cout<<":("<<endl;
  }



  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <queue>
#include <vector>

#define MAXSIZE 100000

using namespace std;

void calculate(vector<long long int>& lunlun_num)
{
  queue<long long int> lunlun_temp;
  for (int i = 1; i <= 9; i++){
    lunlun_temp.push(i);
    lunlun_num.push_back(i);
  }
  int count = 9;
  while (count <= MAXSIZE){
    long long int temp = lunlun_temp.front(), num = temp * 10 + temp % 10;
    lunlun_temp.pop();
    if (temp % 10 != 0){
      lunlun_temp.push(num - 1);
      lunlun_num.push_back(num - 1);
      count++;
    }
    lunlun_temp.push(num);
    lunlun_num.push_back(num);
    count++;
    if (temp % 10 != 9){
      lunlun_temp.push(num + 1);
      lunlun_num.push_back(num + 1);
      count++;
    }
  }
}

void getans(vector<long long int>& lunlun_num)
{
  int index;
  cin >> index;
  cout << lunlun_num[index - 1] << '\n';
}

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<long long int> lunlun_num;
  calculate(lunlun_num);
  getans(lunlun_num);
  return 0;
}


Measured memory_bytes: 4552
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  string s; cin >> s;
  int ans = 0;
  for(int i = 0; i < s.size(); i++) {
    int j = s.size() - 1 - i;
    if(s[i] != s[j]) {
      ans++;
      s[i] = s[j];
    }
  }

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


Measured memory_bytes: 256