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

    // define
# define loop(i,a,n) for(int i=a;i<n;++i)
# define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0);
# define ll long long int 
# define endl '\n'
# define mp make_pair
# define mt make_tuple
# define pb push_back
# define eb emplace_back
# define in insert
# define rev(i,a,n) for(int i=n-1;i>=a;--i)
# define test int t; cin>>t; while(t--)

/* debug */
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _itRS(_ss); err(_itRS, args); }

void err(istream_iterator<string> itRS) {}
template<typename T, typename... Args>
void err(istream_iterator<string> itRS, T a, Args... args) {
    cerr << *itRS << " = " << a << endl;
    err(++itRS, args...);
}


const int MOD=1000000007;
ll power(ll x, unsigned ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
}

int T[10001];
int main()
{
    fast
    ll h;
    cin>>h;
    ll sum=0;
    ll state=1;
   while(h!=0)
   {
       h=h/2;
       
       sum=sum+state;
       state=state*2;
   }
   cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> p(n),q(n),buf(n);
    ll P=0,Q=0;
    rep(i,0,n){
        cin>>p[i];
        P+=p[i]*pow(10,n-i-1);
        buf[i]=i+1;
    }
    rep(i,0,n){
        cin>>q[i];
        Q+=q[i]*pow(10,n-i-1);
    }
    ll ansp=0,ansq=0;
    if(P!=Q){
        ll num=0;
        do {
            ll B=0;
            rep(i,0,n) B+=buf[i]*pow(10,n-i-1);
            if(B==Q)ansq=num;
            else if(B==P) ansp=num;
            num++;    
        } while (next_permutation(buf.begin(), buf.end()));
    }
    cout<<abs(ansp-ansq)<<endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ans = 0;
        int n = sc.nextInt();
        int k = sc.nextInt();
        int h;
        for(int i = 0; i < n; i++) {
            h = Integer.parseInt(sc.next());
            if(h >= k) ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 45360
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    A2IN(ll, A, ll, B, N);
    SORT(A);
    SORT(B);
    ll i = (N - 1) / 2;
    ll ans;
    if (N % 2 == 0)
    {
        ans = (B[i + 1] + B[i]) - (A[i + 1] + A[i]) + 1;
    }
    else
    {
        ans = B[i] - A[i] + 1;
    }
    OUT(ans);
}

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

using namespace std;

int main() {
    int q;
    cin >> q;
    vector<pair<int, int>> query(q);
    for(int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;
        query[i] = {l, r};
    }
    vector<int> dp(100001, 0);
    auto is_prime = [](int n)
    {
        if(n == 2) return true;
        if(n < 2) return  false;
        if(n == 3) return true;
        if(n % 2 == 0) return false;
        if(n % 3 == 0) return false;
        for(int i = 3; i * i <= n; i += 2)
        {
            if(n % i == 0)
            {
                return false;
            }
        }
        return true;
    };
    //累積和を求める
    for(int i = 0; i <= 100000; i++)
    {
        if(is_prime(i))
        {
            //iが素数
            int t = (i + 1) / 2;
            if(is_prime(t))
            {
                dp[i] = dp[i - 1] + 1;
            }else{
                dp[i] = dp[i - 1];
            }
        }else{
            dp[i] = dp[i - 1];
        }
    }
    for(auto e : query)
    {
        cout << dp[e.second] - dp[e.first - 1] << endl;
    }
    return 0;
}


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

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

int main() {
	string S;
	cin >> S;
	int a[3] = {};
	for (auto c : S) {
		if (c == 'a')a[0] = 1;
		if (c == 'b')a[1] = 1;
		if (c == 'c')a[2] = 1;
	}
	int sum = a[0] + a[1] + a[2];
	if (sum == 3)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int INF=(1e9);
const int maxn=(1e5)+10;
int n,s[maxn],mn,pos;
char S[maxn];
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%s",S+1); n=strlen(S+1);
	for (char ch='a';ch<='z';ch++) {
		mn=INF;
		for (int i=1;i<=n;i++) {
			s[i]=s[i-1]+(S[i]==ch);
			if (2*s[i]-i>mn) {
				printf("%d %d\n",pos+1,i); return 0;
			}
			if (mn>2*s[i-1]-(i-1)) mn=2*s[i-1]-(i-1),pos=i-1;
		}
	} printf("-1 -1\n");
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main() {
  int n,t_p=0,h_p=0;
  string taro,hanako;
  cin>>n;
  while (n!=0){
    cin>>taro>>hanako;
    if(taro==hanako){t_p++;h_p++;}
    else taro>hanako? t_p+=3 : h_p+=3;
    n--;
  }
  cout<<t_p<<" "<<h_p<<endl;
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>

using namespace std;
 int main(){
    int N;
    cin >> N;
    int a = 1;
    int b = 1;
    int c = 1;
    // a, b, cは正整数
    // a * b < N となる組み合わせを探せば良い
    // a, bが定まればcは一意に定まる
    long long count = 0;
    for (a = 1; a < N; a++) {
        count += (N-1) / a;
    }
    cout << count << endl;
 }


Measured memory_bytes: 3668
#include "bits/stdc++.h"
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long int;

ll mpow(ll a, ll n, ll mod)
{
	ll r = 1;
	while (n) {
		if (n&1) r = r*a%mod;
		a = a*a%mod;
		n >>= 1;
	}
	return r;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	string s; cin >> s;
	if (s.back() == 's') s += 'e';
	s += 's';
	cout << s;
}

Measured memory_bytes: 3660
n, m = map(int, input().split())
a = [int(x) for x in input().split()]

total = sum(a)
a.sort()
a = a[::-1]
count=0
for i in range(m):
    if a[i] < total * 1/(4*m):
        break
    count+=1

if count == m:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9136
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
    int main(){
    string N;
    cin >> N;
    if(N[0]=='9' || N[1]=='9'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	vector<int> a1, a2;
	int t, i;
	ios::sync_with_stdio(false);
	cin >> t;
	while(t --)
	{
		int x;
		bool flg = 1;
		a1.push_back(0);
		a2.push_back(0);
		for(i = 0; i < 10; i ++)
		{
			cin >> x;
			if(a1.back() < x)	a1.push_back(x);
			else if(a2.back() < x) 	a2.push_back(x);
			else
			{
				flg = 0;
				break;
			}
		}
		for( i ++; i < 10; i ++)	cin >> x;
		flg ? cout << "YES" << endl : cout << "NO" << endl;
		a1.clear();
		a2.clear();
	}
	return 0;
} 


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;
 
const int Inf = 1000000007;
//const int mod = 998244353;//1000000007;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

long long X;
set <long long> S;

void Solve()
{	
	cin >> X;
	for(long long i = -300; i <= 300; i++)
	{
		S.insert(i * i * i * i * i + X);
	}
	for(long long i = -300; i <= 300; i++)
	{
		if(S.count(i * i * i * i * i) == true)
		{
			cout << i << " ";
			for(long long j = -300; j <= 300; j++)
			{
				if(j * j * j * j * j == i * i * i * i * i - X)
				{
					cout << j;
					return;
				}
			}
		}
	}
}
 
int main()
{
	Fastio();
	Solve();
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)

P tree[55];
int A[55],B[55],indexA[55],indexB[55];
int n;

bool fir = true;
void Postorder(int i=A[0]){
	if(~tree[i].first)Postorder(tree[i].first);
	if(~tree[i].second)Postorder(tree[i].second);
	cout << (fir?"":" ") << i;
	fir = false;
}

void make_tree(int l=0,int r=n,int p=A[0]){
	int left,right,indl=1000,indr=1000;
	FOR(i,l,indexB[p]){
		if(indl>indexA[B[i]]){
			indl = indexA[B[i]];
			left = B[i];
		}
	}
	FOR(i,indexB[p]+1,r){
		if(indr>indexA[B[i]]){
			indr = indexA[B[i]];
			right = B[i];
		}
	}
	if(indl!=1000)tree[p].first = left;
	if(indr!=1000)tree[p].second = right;
	if(indl!=1000)make_tree(l,indexB[p],left);
	if(indr!=1000)make_tree(indexB[p]+1,r,right);
}


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

	FOR(i,0,55) tree[i].first=tree[i].second=-1;
	memset(A,-1,sizeof(A));
	memset(B,-1,sizeof(B));
	memset(indexA,-1,sizeof(indexA));
	memset(indexB,-1,sizeof(indexB));

	cin >> n;
	FOR(i,0,n){
		cin >> A[i];
		indexA[A[i]] = i;
	}
	FOR(i,0,n){
		cin >> B[i];
		indexB[B[i]] = i;
	}
	make_tree();
	Postorder();
	cout << '\n';

}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }


void func(long long X, long long K, long long D){
    X = abs(X);
    ll Q = X / D;
    ll R = X % D;
    ll remain_k = K - Q;

    if (remain_k < 0) {
        cout << X - K * D << endl;
    } else if (remain_k % 2 == 0) {
        cout << R << endl;
    } else {
        cout << D - R << endl;
    }
}

int main(){
    // cout << fixed << setprecision(5);

    long long X;
    scanf("%lld",&X);
    long long K;
    scanf("%lld",&K);
    long long D;
    scanf("%lld",&D);
    func(X, K, D);
    return 0;
}

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

int main(){
  std::string ch;
  char CH[1200];

  std::getline(std::cin, ch);

  for(int i=0; i<ch.size(); i++){
    if(ch[i] >= 'a' && 'z' >= ch[i]){ch[i] -= 32;}
    else if(ch[i] >= 'A' && 'Z' >= ch[i]){ch[i] += 32;}
  }
  std::cout << ch << std::endl;

  return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  int n;
  cin>>n;
  nvec(long,a,n);
  sort(all(a));
  bool b = count_lt(a,0)%2;
  FOR(i,n){
    a[i]=abs(a[i]);
  }
  cout<<SUM(a)-min_e(a)*2*b;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int fact[1000001];

int modpow(int x, int k) {
  int a = 1;
  while (k > 0) {
    if (k & 1) a = (1LL*a*x) % MOD;
    x = (1LL*x*x) % MOD;
    k >>= 1;
  }
  return a;
}

int inv(int x) {
  return modpow(x, MOD-2);
}

int nCr(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  return (1LL * fact[n] * inv((1LL*fact[k]*fact[n-k]) % MOD)) % MOD;
}

void calc_fact() {
  fact[0] = 1;
  for (int i=1; i<=1000000; i++) {
    fact[i] = (1LL*i*fact[i-1]) % MOD;
  }
}

int N;
int A[200000];
int C[200000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  calc_fact();
  cin >> N;
  N++;
  rep(i, N) {
    cin >> A[i];
    A[i]--;
    C[A[i]]++;
  }
  int ty = -1;
  rep(i, N-1) {
    if (C[i] > 1) {
      ty = i;
      break;
    }
  }
  vector<int> xs;
  rep(i, N) {
    if (ty == A[i]) xs.pb(i);
  }
  int l = xs[0], r = xs[1];
  int s = N-(r-l+1);
  for (int k=1; k<=N; k++) {
    int all = nCr(N, k);
    int sub = nCr(s, k-1);
    all += (MOD-sub)%MOD;
    all %= MOD;
    cout << all << "\n";
  }
  return 0;
}


Measured memory_bytes: 11392
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

struct P {
  int num;
  string s;
};
bool operator<(const P&a, const P&b) {
  return a.num != b.num ? a.num > b.num : a.s < b.s;
}
int main() {
  int n;
  while(cin>>n, n) {
    cin.ignore();
    map<string, int> mp;
    REP(i,n) {
      string line;
      getline(cin,line);
      stringstream ss(line);
      string s;
      while(ss>>s) {
        mp[s]++;
      }
    }
    char c; cin >> c;
    vector<P> v;
    FOR(it, mp) {
      if (it->first[0] == c) {
        v.push_back((P){it->second, it->first});
      }
    }
    sort(ALL(v));
    if(v.size() == 0) {
      cout << "NA" << endl;
    } else {
      REP(i,min((int)v.size(),5)) {
        if (i) cout << " ";
        cout << v[i].s;
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 952
import re

n, q = map(int, input().split())
s = input()
count = [0] * len(s)
for ind, char in enumerate(s[1:], 1):
    if char == 'C' and s[ind-1] == 'A':
        count[ind] = count[ind-1] + 1
    else:
        count[ind] = count[ind-1]

# print(count)
answer = []

for _ in range(q):
    l, r = map(int, input().split()) 
    answer.append(count[r-1] - count[l-1])

for ans in answer:
    print(ans)


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

long long exp(long long a,long long b) {
  if(b==1) {
    return a;
  }
  else if(b>1){
    long long c=a;
    for(long long i=0;i<b-1;i++) {
      c=a*c;
      if(i==b-2) {
        return c;
        break;
      }
    }
  }
  else if(b<-1) {
    cout<<"1"<<"/";
    long long c=a;
    for(long long i=0;i<abs(b)-1;i++) {
      c=a*c;
      if(i==abs(b)-2) {
        return c;
        break;
      }      
    }
  }
  else if(b==-1) {
    cout<<"1"<<"/";
    return a;
  }
}
int main() {
  int n;
  cin>>n;
  for(int i=n;i>0;i--) {
    for(int j=1;j<sqrt(n)+1;j++) {
      for(int k=2;k<10;k++) {
        if(i==exp(j,k)) {
          for(int m=0;m<n;m++) {
            vector<int>vec(1000);
            vec.at(m)=i;
            if(m==n-1) {
              sort(vec.begin(), vec.end());
              reverse(vec.begin(), vec.end());
              cout<<vec.at(0)<<endl;
              goto end;
              break;
            }
          }
        }
      }
    }
  }
  end:
  return 0;
}

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

int main(){
  
  int N;
  scanf("%d", &N);
  
  if(N == 0){
    printf("%d\n", 2);
    return 0;
  }
  if(N == 1){
    printf("%d\n", 1);
    return 0;
  }
  else{
    int64_t ans = 0, tmp2 = 2, tmp1 = 1;
    for(int i = 1; i < N; i++){
      ans = tmp2 + tmp1;
      tmp2 = tmp1;
      tmp1 = ans;
    }
  
    printf("%ld\n", ans);
  }
  return 0;
}

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

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

int main() {
    ll n;
    cin >> n;
    vector<ll> num;
    num.push_back(1);
    num.push_back(n);
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            num.push_back(i);
        }
    }
    ll ans = 1e18;
    for (auto nn: num) {
        ans = min(ans, nn - 1 + (n / nn) - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys
import numpy as np

import itertools

def solve(N: int, P: "List[int]", Q: "List[int]"):
    num = [i for i in range(1,N+1)]
    c=1
    a=b=0
    for p in itertools.permutations(num):
        if list(p)==P:
            a=c
        if list(p)==Q:
            b=c
        c+=1

    print(abs(a-b))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    Q = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P, Q)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12408
/**
 *    author:  tesnik      
**/
#include <bits/stdc++.h>
 
using namespace std;

const int MOD = 1e9 + 7;
int n, a, b;
long long iv[200002];

long long C(int n, int k) {
  long long ans = 1;
  for (int i = 1; i <= k; i++) {
    ans = ans * (n - i + 1) % MOD * iv[i] % MOD;
  }
  return ans;
}

long long powMod(long long b, int p) {
  long long r = 1;
  for (; p; b = b * b % MOD, p /= 2) {
    if (p & 1) {
      r = r * b % MOD;
    }
  }
  return r;
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  iv[1] = 1;
  for (int i = 2; i <= 200000; i++) {
    iv[i] = MOD - MOD / i * iv[MOD % i] % MOD;
  }
  cin >> n >> a >> b;
  long long ans = powMod(2, n);
  cout << (ans + 2 * MOD - C(n, a) - C(n, b) + MOD - 1) % MOD;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include<vector>

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    string s[h];
    REP(i,h) cin >> s[i];
    //cout << s[0] << endl;;
    bool hi[h];
    bool wi[w];
    REP(i,h) hi[i] = true;
    REP(i,w) wi[i] = true;
    REP(i,h){
        bool f= true;
        REP(j,w) if(s[i][j] == '#') f=false;
        //REP(j,w) if(s[i][j] == '#') cout << s[i][j] << i << j<<endl;
        if(f) hi[i] = false;
    }
    REP(i,w){
        bool f=true;
        REP(j,h) if(s[j][i] =='#') f=false;
        if(f) wi[i] = false;
    }
    REP(i,h){
        if(hi[i]){
            REP(j,w) if(wi[j]) cout <<  s[i][j]; 
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cstdlib>
using namespace std;

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define INIT(a) memset(a,0,sizeof(a))
#define pb push_back
#define sz size()
#define INF (1<<25)
#define V 300
typedef pair<int,int> P;

struct edge{
  int from,to,cost,cap,rev;
};

vector<edge> G[V];

void AddEdge(int s,int g,int c,int p){
  G[s].pb((edge){s,g,c,p,(int)G[g].sz});
  G[g].pb((edge){g,s,-c,0,(int)G[s].sz-1});
}

int d[V];
int h[V],pv[V],pe[V];
int v;
bool use[V];

int MinCostFlow(int s,int t,int f){
  int res = 0;
  fill(h,h+v,0);
  while(f>0){
    fill(d,d+v,INF);
    memset(use,0,sizeof(use));
    d[s] = 0;

    while(true){
      int u = -1;
      rep(i,v){
	if(!use[i] && (u<0 || d[u] > d[i]))u = i;
      } 

      if(u<0 || d[u] == INF)break;
      use[u] = true;

      rep(i,G[u].sz){
	edge &e = G[u][i];
	if(e.cap>0 && d[e.to] > d[u] + e.cost + h[u] - h[e.to]){
	  d[e.to] = d[u] + e.cost + h[u] - h[e.to];
	  pv[e.to] = u; pe[e.to] = i;
	}
      }	  
    }

    if(d[t]==INF)return -1;
    rep(u,v)h[u] += d[u];

    int x = f;
    for(int u=t;u!=s;u=pv[u])x = min(x,G[pv[u]][pe[u]].cap);
    f -= x;
    res += x*h[t];
    for(int u=t;u!=s;u=pv[u]){
      edge &e = G[pv[u]][pe[u]];
      e.cap -= x; G[u][e.rev].cap += x;
    }
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  int p[110];
  for(int i=0;i<n;i++)cin >> p[i];

  v = 2*n+2;
  for(int i=0;i<n;i++){
    AddEdge(0,i+1,0,1);
    AddEdge(i+n+1,v-1,0,1);
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(p[i]!=j+1){
	AddEdge(p[i],j+n+1,p[i]*abs(i-j),1);
      }
    }
  }

  cout << MinCostFlow(0,v-1,n) << endl;
}

Measured memory_bytes: 1764
lst=[]
for i in range(3):
    a=map(int,input().split())
    for j in a:
        lst.append(j)
for i in range(lst[0]+1):
    a,d=i,lst[0]-i
    b=lst[3]-lst[0]+a
    c=lst[6]-lst[0]+a
    e=lst[1]-lst[0]+d
    f=lst[2]-lst[0]+d
    if lst[4]==b+e and lst[5]==b+f and lst[7]==c+e and lst[8]==c+f:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 9220
#include <iostream>
#include<stdio.h>
#include<string>
using namespace std;
int main(void){
    int x,b;
    scanf("%d",&x);
    b=x/100;
    std::string str = std::string(b, '3');
    std::cout << "ai1333";
    std::cout << str << std::endl; 
    return 0;
}



Measured memory_bytes: 3268
#include<stdio.h>

int main(void){
    int n,sum=0,x=10,tmp;
    scanf("%d",&n);
    tmp=n;
    while(10*n>=x){
        sum+=(n%x)/(x/10);
        n-=n%x;
        x*=10;
    }
    if (sum==0) return 0;
    if(tmp%sum==0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int sort(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}

int main(void){
    int n,x,ans=0;
    scanf("%d%d",&n,&x);
    int a[n];
    for (int i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    qsort (a,n,sizeof(int),sort);
    for (int i=0; i<n; i++){
        if (a[i]<=x){
            x-=a[i];
            ans++;
        } else {
            break;
        }
    }
    if (ans==n && x>0){
        ans--;
    }
    printf("%d\n",ans);
	return 0 ;
}

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

int main() {

  int q;
  cin >> q;
  
  while (0 < q) {
    
    string X, Y;
    cin >> X >> Y;

    int x = X.size();
    int y = Y.size();

    // X_0 ... X_i と Y_0 ... Y_j に対するLCSの長さ
    vector<vector<int>> dp(x+1, vector<int>(y+1));

    int answer = 0;

    for (int i = 0; i < x; i++) {
      for (int j = 0; j < y; j++) {
        if (X[i] == Y[j]) {
          // 同じ文字列の場合は、
          // X_0 ... X_i と Y_0 ... Y_j に対するLCSに1加える
          dp[i+1][j+1] = dp[i][j] + 1;
        } else {
          // 違う場合は、
          // X_0 ... X_i と Y_0 ... Y_j+1 に対するLCSと
          // X_0 ... X_i+1 と Y_0 ... Y_j に対するLCSで
          // 大きい方
          dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        }
        answer = max(answer, dp[i+1][j+1]);
      }
    }

    cout << answer << endl;

    q--;
  }

  return 0;

}


Measured memory_bytes: 6880
fun main(args: Array<String>) {
    var n= readLine()!!.toInt()

    readLine()!!.split(" ").map(String::toInt)
    .sorted().reversed().let{
        var a = 0
        var b = 0
        for((i,x) in it.withIndex()){
            if(i%2==0) a+=x
            else b+=x
        }
        println(a-b)
    }
}



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

int main(){
  int N,L;
  cin>>N>>L;
  int V[N+100];
  int total=0;
  int minabs=400;
    
  for(int i=1;i<N+1;i++){
    V[i]=L+i-1;
  }
  
  for(int i=1;i<N+1;i++){
    total=total+V[i];
  }
  
  for(int i=1;i<N+1;i++){
    minabs=min(minabs,abs(V[i]));
  }
  
  if (total>0){
  cout<<total-minabs;
  return 0;
  }
  cout<<total+minabs<<endl;
  return 0;
}

               



  


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

const int INF = 1e9;

int main(){
  int n,m,k;
  scanf("%d%d%d",&n,&m,&k);
  
  vector< vector<edge> > g(n);
  rep(i,m){
    int a,b,l;
    cin >> a >> b >> l; a--; b--;
    g[a].push_back(edge(l,b));
    g[b].push_back(edge(l,a));
  }

  vector<int> d(n,INF);
  priority_queue< edge, vector<edge>, greater<edge> > q;
  rep(i,k){
    int s; cin >> s; s--;
    d[s] = 0;
    q.push(edge(0,s));
  }

  while(q.size()){
    edge x = q.top(); q.pop();
    int c = x.first, v = x.second;
    
    for(edge e : g[v]){
      int nc = c + e.first;
      int u = e.second;
      
      if(d[u] > nc){
	d[u] = nc;
	q.push( edge(nc, u) );
      }
    }
  }
  
  int ans = 0;
  rep(a,n){
    for(edge e : g[a]){
      int l = e.first, b = e.second;
      
      int A = min(d[a], d[b]), B = max(d[a], d[b]);
      if(A+l < B){
	ans = max(ans, A+l);
      }else{
	ans = max(ans, (A+B+l+1)/2);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6064
#include <stdio.h>
int main (void)
{
int m,d;
int i,k;
int count =0;
scanf("%d",&m);
scanf("%d",&d);
 
for(i=2;i<=m;i++)
for(k=22;k<=d;k++)
if((k/10)>=2&&(k%10)>=2)
if((k/10)*(k%10)==i)
count ++;

printf("%d",count);

return 0;
}

Measured memory_bytes: 128
n, m, p = gets.split.map(&:to_i)
ds = (1..m).map{ gets.to_i }.sort
ds << ds.shift + n until p < ds[0] 

a = n - (ds[0] - p)
b = ds[-1] - p 

min = [a, b].min
ds.each_cons(2){|x, y|
    cost = x - p + (n - (y - x)) 
    min = cost if cost < min 
    cost = (p + n - y) + (n - (y - x)) 
    min = cost if cost < min 
}

p min * 100 

Measured memory_bytes: 6308
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,p[100005];
vector<int>v[100005];
int vv[100005];
void bfs(int x)
{
    queue<int>q;
    q.push(x);
    while(!q.empty())
    {
        int now=q.front();q.pop();
        for(int i=0;i<v[now].size();i++)
        {
            vv[v[now][i]]--;
            p[v[now][i]]=now;
            if(vv[v[now][i]]==0) q.push(v[now][i]);
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n-1+m;i++)
    {
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        vv[y]++;
    }
    for(int i=1;i<=n;i++)
        if(vv[i]==0) {bfs(i);break;}
    for(int i=1;i<=n;i++) printf("%d\n",p[i]);
}


Measured memory_bytes: 7040
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
void okuri() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3;
	}
	else {
		ci += 8;
		tmp = *(ll*)ci;
		ci += 4 + __builtin_ctzll((tmp & ma0) ^ ma0) >> 3;
	}
}

int A[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint(), K = getint();

	int p = 0;
	for (; p < N; p++) {
		A[p + 1] = A[p] + getint();
		if (A[p + 1] > K) break;
	}
	for (int q = p + 1; q < N; q++) okuri();

	while (A[p] > K) p--;
	ll kotae = p;

	rep1(i, M) {
		K -= getint();
		if (K < 0) break;
		while (A[p] > K) p--;
		if (kotae < i + p) kotae = i + p;
	}

	printf("%d\n", kotae);

	Would you please return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	if(__builtin_popcount(n)==1)
		return cout<<"No"<<endl, 0;
	cout<<"Yes"<<endl;
	for(int i=3;i<=n;i+=2)
		cout<<i-1<<' '<<i<<'\n'<<i<<' '<<1<<'\n'<<1<<' '<<i-1+n<<'\n'<<i-1+n<<' '<<i+n<<'\n';
	cout<<n+1<<' '<<2<<'\n';
	if(n%2==0){
		int x = n&-n;
		cout<<x+1<<' '<<n<<'\n';
		cout<<n-x+n<<' '<<2*n<<'\n';
	}
}


Measured memory_bytes: 2304
from itertools import product

N, M = map(int, input().split())
connected = []  # 二次元リスト
for _ in range(M):
    # それぞれの行の1つ目の入力は、その後に続く値の個数
    connected.append(list(map(int, input().split())))
mod = list(map(int, input().split()))
ans = 0

for is_on_li in product([False, True], repeat=N):
    is_ok = True
    for light_idx in range(M):
        on_cnt = 0
        for i in range(1, len(connected[light_idx])):
            sw_idx = connected[light_idx][i] - 1
            if is_on_li[sw_idx]:
                on_cnt += 1
        if on_cnt % 2 != mod[light_idx]:
            is_ok = False
    if is_ok:
        ans += 1
print(ans)


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int answer = 0;
  while(true){
    a -= b;
    answer += c;
    if(a <= 0){
      break;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f(ll x){
	return (x-1)*x/2;
}
int main(){
	string s;
	cin>>s;
	s=">"+s;
	ll lc=0,rc=0;
	ll ans=0;
	for(int i=1;i<s.size();i++){
		if(s[i]=='>'){
			rc++;
			if(s[i-1]=='<')ans+=f(lc);
		}else{
			if(s[i-1]=='>'){
				ans+=max(rc,lc)+f(rc);
				lc=0;
				rc=0;
			}
			lc++;
		}
	}
	if(s[s.size()-1]=='<')ans+=f(lc+1);
	else {
		ans+=max(rc,lc)+f(rc);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4308
import           Data.List
import           Control.Applicative
import           Control.Monad
import           Control.Monad.State

gacha :: Ord a => [a] -> [a] -> [(a, a)]
gacha [] _  = []
gacha _  [] = []
gacha (x : xs) (y : ys) | x == y    = (x, y) : gacha xs ys
                        | x < y     = gacha xs (y : ys)
                        | otherwise = gacha (x : xs) ys

binarySearch :: Ord a => a -> [a] -> Bool
binarySearch a []  = False
binarySearch a [t] = a == t
binarySearch a xs | head l == a = True
                  | head r == a = True
                  | head r > a  = binarySearch a l
                  | otherwise   = binarySearch a r
 where
  sz     = div (length xs) 2
  (l, r) = splitAt sz xs

main = do
  n <- readLn
  s <- take n . map (read :: String -> Int) . words <$> getLine
  q <- readLn
  t <- take q . map (read :: String -> Int) . words <$> getLine
  print $ length $ gacha s (sort t)



Measured memory_bytes: 93228
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
cnt=-2
for i in range(n):
    ans+=b[a[i]-1]
    if cnt+1==a[i]:
        ans+=c[a[i]-2]
    cnt=a[i]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
#define endl cout << "\n"
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    map<int, int> m;
    vector<char> v;
    string s;
    cin >> s;
    for(int i=0; i<s.size(); ++i){
    	if(s[i]=='0') v.push_back('0');
    	else if(s[i]=='1') v.push_back('1');
    	else if(s[i]=='B'){
    		if(!v.empty()) v.pop_back();
    		else continue;
    	}
    }

    for(auto i: v) cout << i;
    	endl;
    bye;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int a,b,c,n,ijk[1000][3],r[1000],ans[300];
    while(cin>>a>>b>>c,a||b||c){cin>>n;
    fill(ans,ans+a+b+c,2);
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++)
            cin>>ijk[i][j],ijk[i][j]--;
        cin>>r[i];
        if(r[i]==1)
            for(int j=0;j<3;j++)
                ans[ijk[i][j]]=1;
    }
    for(int i=0;i<n;i++)
        if(r[i]==0)
            if(ans[ijk[i][0]]==1){
                if(ans[ijk[i][1]]==1)
                    ans[ijk[i][2]]=0;
                else if(ans[ijk[i][2]]==1)
                    ans[ijk[i][1]]=0;
            }
            else
                if(ans[ijk[i][1]]==1&&ans[ijk[i][2]]==1)
                    ans[ijk[i][0]]=0;
    for(int i=0;i<a+b+c;i++)
        cout<<ans[i]<<endl;}
}



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

long long dp[51][51][2501];

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

    int n, a;
    cin >> n >> a;
    vector<int> X(n);
    REP(i, n) cin >> X[i];

    dp[0][0][0] = 1;   //何も選ばない場合の数
    REP(i, n) REP(j, n) REP(k, 2500){
        if(dp[i][j][k]){
            dp[i + 1][j][k] += dp[i][j][k];   //選ばないとき
            dp[i + 1][j + 1][k + X[i]] += dp[i][j][k];   //選ぶとき
        }
    }

    long long ans = 0;
    for(int i = 1; i <= n; i++){
        ans += dp[n][i][i * a];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 48128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

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

int n;
string train;

string rev(string s) {
	return string(s.rbegin(), s.rend());
}

int solve(string train) {
	set<string> s;
	int length = train.size();
	repa(i,1,length-1) {
		string f = train.substr(0, i);
		string b = train.substr(i);
		
		s.insert(f + b);
		s.insert(b + f);
		s.insert(rev(f) + b);
		s.insert(b + rev(f));
		s.insert(f + rev(b));
		s.insert(rev(b) + f);
		s.insert(rev(f) + rev(b));
		s.insert(rev(b) + rev(f));
	}
	return (int)s.size();
}

int main() {
	cin >> n;
	rep(i,n) {
		cin >> train;
		cout << solve(train) << endl;
	}
}

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

const int N = 1e5+5;
ll s[N], t[N], near2s[N], neartot[N];


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b,q;
    cin>>a>>b>>q;
    for(int i = 0; i< a; i++)cin>>s[i];
    for(int i = 0; i< b; i++)cin>>t[i];
    

    for(int i = 0; i< q; i++){
        ll x;
        cin>>x;
        int n = lower_bound(s, s+a, x) - s;
        int m = lower_bound(t, t+b, x) - t;
        ll ans = 1e11+5;
        if(n<a||m<b){
            ll rn,rm;
            if(n<a) rn = s[n];
            else rn = 1e11+5;
            if(m<b) rm = t[m];
            else rm = 1e11+5;

            if(rn>=rm){
                ll temp = rm - x;
                ll nextstep = min(n>0?t[m] - s[n-1]:(ll)1e11, n<a?s[n]- t[m]:(ll)1e11);
                ans = min(ans, temp+ nextstep);
            }else{
                ll temp = rn - x;
                ll nextstep = min(m>0?s[n] - t[m-1]:(ll)1e11, m<b?t[m]- s[n]:(ll)1e11);
                ans = min(ans, temp+ nextstep);
            }
        }
        
        
        if(n>0||m>0){
            ll lefn,lefm;
            if(n>0) lefn = s[n-1];
            else lefn = -1;
            if(m>0) lefm = t[m-1];
            else lefm = -1;
            
            
            if(lefn<lefm) {
                ll temp = x - lefm;
                ll nextstep = min(n<a?s[n] - t[m-1]:(ll)1e11, n>0? t[m-1] - s[n-1]:(ll)1e11 );
                ans = min(ans, temp+ nextstep);
            }
            else{
                ll temp = x - lefn;
                ll nextstep = min(m<b?t[m] - s[n-1]:(ll)1e11, m>0? s[n-1] - t[m-1]:(ll)1e11 );
                ans = min(ans, temp+ nextstep);
            }
            
        }
        cout<<ans<<endl;
    }
    
    return 0;
}


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

int main() {
    ll H, N; cin >> H >> N;
    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        ll a; cin >> a;
        sum += a;
    }
    string mes;
    if (sum >= H) mes = "Yes";
    else mes = "No";
    cout << mes << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	
	// for prime mod
	mint inv() const { return pow(mod-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) const { return mint(*this) /= a;}
};

mint F[1001001];

mint nCr(ll n, ll r){
	return F[n] / (F[n-r]*F[r]);
}

int main()
{
	ll N, M;
	cin >> N >> M;
	
	F[0] = 1;
	for(int i = 1; i < 1001001; i++){
		F[i] = F[i-1] * i;
	}

	mint sum = 0;
	for(ll k = 0; k <= N; k++){
		sum += nCr(M, k) * nCr(N, k) * F[k] *  nCr(M-k, N-k) * F[N-k] * nCr(M-k, N-k) * F[N-k] * (k % 2 == 0 ? 1 : -1);
	}
	mint ans = sum;
	cout << ans.x << endl;
	
	return 0;
}


Measured memory_bytes: 11448
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] t = new long[n];
		for(int i = 0 ; i < n ; i++) t[i] = sc.nextLong();
		long ans = 1;
		for(int i = 0 ; i < n ; i++) {
			ans = ans / gcd(ans, t[i]) * t[i];
		}
		System.out.println(ans);
	}

	static long gcd(long x, long y) {
		if(x < y) {
			long w = x;
			x = y;
			y = w;
		}
		if(y == 0) return x;
		return gcd(y, x % y);
	}

}


Measured memory_bytes: 21204
import sys
input = sys.stdin.readline

n = int(input())
hito = list(map(int,input().split()))
ans = 0
for i in range(1, n):
    if hito[i-1] > hito[i]:
        ans += hito[i-1] - hito[i]
        hito[i] = hito[i-1]
print(ans)

Measured memory_bytes: 31416
for i in range(int(input())):
    N,A,B,C,D=map(int,input().split())
    memo={}
    memo[0]=0
    memo[1]=D
    def dfs(num):
        global A,B,C,D
        if num in memo:
            return memo[num]
        res=D*num
        for i in range(-1,2):
            nv=num+i
            if nv%2==0:
                res=min(res,D*abs(i)+A*(nv//2!=0)+dfs(nv//2))
        for i in range(-2,3):
            nv=num+i
            if nv%3==0:
                res=min(res,D*abs(i)+B*(nv//3!=0)+dfs(nv//3))
        for i in range(-4,5):
            nv=num+i
            if nv%5==0:
                res=min(res,D*abs(i)+C*(nv//5!=0)+dfs(nv//5))
        memo[num]=0
        memo[num]=res
        return memo[num]

    print(dfs(N))

Measured memory_bytes: 85108
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

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

	double total = 0;
	vector<double> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		total += A[i];
	}

	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] >= total / (double)(4 * M)) {
			cnt++;
		}
	}

	cout << ((cnt >= M) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3716
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] Q = new ArrayList[n];
		for(int i = 0; i < n; i++) Q[i] = new ArrayList<Integer>();
		for(int i = 0; i < q; i++){
			str = br.readLine().split(" ");
			int op = Integer.parseInt(str[0]);
			if(op == 0){
				int t = Integer.parseInt(str[1]);
				int x = Integer.parseInt(str[2]);
				Q[t].add(x);
			}else if(op == 1){
				int t = Integer.parseInt(str[1]);
				if(Q[t].isEmpty()) continue;
				System.out.println(Q[t].get(0));
			}else{
				int t = Integer.parseInt(str[1]);
				if(Q[t].isEmpty()) continue;
				Q[t].remove(0);
			}
		}
	}
}



Measured memory_bytes: 70180
#include <cstdio>
#include <cstdlib>
#include <cstring>

const int table[] = { 0, 1, 2, 3, 5, 7, 8, 9 };

int main(){
	while(true){
		int n;
		scanf("%d", &n);
		if(n == 0){ break; }
		long long answer = 0, e = 1;
		while(n != 0){
			int m = n % 8;
			answer += e * table[m];
			e *= 10;
			n /= 8;
		}
		printf("%lld\n", answer);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 500005
#define MX 1048576
#define MOD 1000000007
using namespace std;
using LL = long long;
int n,in[M];
LL pw[M];
vector<int> pos[MX];
int find_nxt(int p,int num) {
    auto it = upper_bound(pos[num].begin(), pos[num].end(), p);
    if (it==pos[num].end()) return n+1;
    return *it;
}
int find_cnt(int p1,int p2,int num) {
    auto it1 = upper_bound(pos[num].begin(), pos[num].end(), p1);
    auto it2 = lower_bound(pos[num].begin(), pos[num].end(), p2) - 1;
    if (it1<=it2) return it2-it1+1;
    return 0;
}
int main()
{
    pw[0] = 1;
    REP(i,1,M-1) pw[i] = (pw[i-1]*2) % MOD;
    
    while (~scanf("%d",&n)) {
        REP(i,0,MX-1) pos[i].clear();
        REP(i,1,n) scanf("%d", &in[i]);
        REP(i,2,n) in[i] ^= in[i-1];
        REP(i,1,n) pos[in[i]].push_back(i);

        //REP(i,1,n) printf("%d ",in[i]); puts("");

        LL ans = 0;
        REP(i,1,MX-1) if (in[n]==0 || in[n]==i) {
            LL frsum = 0;
            LL frdp = 0;
            LL dp = 0;

            REP(j,0,(int)pos[i].size()-1) {
                int fri = j==0 ? 0 : pos[i][j-1];
                int c0 = find_cnt(fri, pos[i][j], 0);
                
                frdp = (frdp + frsum * c0) % MOD;
                dp = (frdp + 1) % MOD;
                frsum = (frsum + dp) % MOD;
            }
           
            if (in[n]==0) {
                ans += frsum;
                ans %= MOD;
            } else {
                ans += dp;
                ans %= MOD;
            }
        }

        if (in[n]==0) {
            int len = 0;
            REP(i,1,n-1) if(in[i]==0) len++;
            ans += pw[len];
            ans %= MOD;
        }


        printf("%lld\n", ans);
    }
    return 0;
}







Measured memory_bytes: 40308