akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
#define rep(i, a, n) for(int i = a; i < n; i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int d[3][210];
int r[110], n;


bool f(int c){
    vector<P> sc(n);
    int score[3][210] = {};
    rep(i, 0, 3){
        vector<int> tmp(n);
        rep(j, 0, n){
            tmp[j] = d[i][j];
        }
        sort(tmp.begin(), tmp.end());
        reverse(tmp.begin(), tmp.end());
        int now = -1;
        int rank = -1;
        rep(j, 0, n){
            if(tmp[j] != now){
                now = tmp[j];
                rank = j;
            }
            score[i][tmp[j]] = r[rank];
        }
        // rep(j, 0, 100){
        //     cout << score[i][j] << " ";
        // }
        // cout << endl;
    }
    vector<P> sum(n);
    rep(i, 0, n){
        sum[i].se = i;
        rep(j, 0, 3){
            sum[i].fi -= score[j][d[j][i]];
        }
    }
    sort(sum.begin(), sum.end());
    // rep(i, 0, n){
    //     cout << sum[i].se << " " << sum[i].fi << " " << endl;
    // }
    // cout << endl;
    rep(i, 0, 8){
        if(sum[i].se == 0) return true;
    }
    return false;
}


int main(){
    cin >> n;
    rep(i, 0, n) cin >> r[i];
    rep(i, 0, n){
        rep(j, 0, 3){
            cin >> d[j][i];
        }
    }

    rep(i, 0, 100){
        rep(j, 0, 3){
            d[j][0] += i;
            if(d[j][0] >  201) continue;
            if(f(j)){
                cout << i << endl;
                return 0;
            }
            d[j][0] -= i;
            // if(i == 3) return 0;
            // cout << endl;
        }
    }
    cout << "Saiko" << endl;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*
橋判定はO(N+M)でできるらしいが、面倒
*/

bool b[60];
vector<int> vec[60];
//vec[i]:頂点i(+1)の隣接頂点
void dfs(int v){
    b[v]=true;
    for(int i:vec[v]){
        if(!b[i]) dfs(i);
    }
    return;
}


void solve(){
    int n, m;
    cin>> n >> m;
    vector<pair<int,int>> vp;
    rep(i,m){
        int tmp1,tmp2;
        cin >> tmp1 >> tmp2;
        vp.emplace_back(make_pair(tmp1-1,tmp2-1));
        //vec[tmp1-1].emplace_back(tmp2-1);
    }
    int ans = 0;
    rep(i,m){
        rep(j,m){
            if(i!=j){
                int t1,t2;
                t1 = vp[j].first;
                t2 = vp[j].second;
                vec[t1].emplace_back(t2);
                vec[t2].emplace_back(t1);
            }
        }
        rep(i,n){
            b[i]=false;
        }
        dfs(0);
        bool allvisited=true;
        rep(i,n){
            if(b[i]==false) allvisited = false; 
        }
        if(!allvisited) ans++;
        allvisited = true;


        rep(k,n){
            vec[k].clear();
        }
        
    }

    cout << ans << endl;

}

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll M = 1000000007;


int main()
{

  ll r,c;
  cin>>r>>c;
  char arr[r][c];
  ll arr1[r][c];
  for(int i=0;i<r;i++)
  {
    for(int j=0;j<c;j++)
    {
      cin>>arr[i][j];
    }
  }
    ll count1=0;
    ll count2=0;
    for(int j=0;j<c;j++)
    {
      if((arr[0][j]=='.') && (count1==0))
      {
          arr1[0][j]=1;
      }
      else if(arr[0][j]=='#')
      { arr1[0][j]=0;
        count1++;
      }
      else if((arr[0][j]=='.') && (count1>0))
      {
          arr1[0][j]=0;
      }

    }

    for(ll i=0;i<r;i++)
    {
      if((arr[i][0]=='.') && (count2==0))
      {
          arr1[i][0]=1;
      }
      else if(arr[i][0]=='#')
      {  arr1[i][0]=0;
        count2++;
      }
      else if((arr[i][0]=='.') && (count2>0))
      {
          arr1[i][0]=0;
      }
    }

    for(ll i=1;i<r;i++)
    {
      for(ll j=1;j<c;j++)
      { 
        if(arr[i][j]=='#')
        {   
           arr1[i][j]=0;
         }

        else if( (arr[i-1][j]=='#') && (arr[i][j-1]!='#'))
        {
          arr1[i][j]= 0 + arr1[i][j-1];
        }
        else if( (arr[i-1][j]!='#') && (arr[i][j-1]=='#'))
        {
          arr1[i][j]=arr1[i-1][j]+ 0;
        }
        else if( (arr[i-1][j]=='#') && (arr[i][j-1]=='#'))
        {
          arr1[i][j]=0;
        }
        else
        {
          arr1[i][j]=(arr1[i-1][j] + arr1[i][j-1])%M;
        }
      }
    }


    cout<<arr1[r-1][c-1]%M<<endl;
    //for(int i=0;i<r;i++)
    //{
    //  for(int j=0;j<c;j++)
    //  {
    //    cout<<arr1[i][j];
    //  }
    //  cout<<endl;
  //  }
  return 0;
}


Measured memory_bytes: 12336
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int f[N];
int main(){
	int n,s,x;scanf("%d",&n),s=sqrt(n);
	for(int i=1;i<=s;i++)for(int j=1;j<=s;j++)for(int k=1;k<=s;k++){
		x=i*(i+j+k)+j*(j+k)+k*k;
		if(x<N)f[x]++;
	}
	for(int i=1;i<=n;i++)printf("%d\n",f[i]);
	return 0;
}

Measured memory_bytes: 3792
///বিসমিল্লাহির_রহমানির_রহীম
#include<bits/stdc++.h>
#define     pie                          acos(-1)
#define     N                            2000005
#define     ESP                          1e-9
#define     pii                          pair<int,int>
#define     vi                           vector<int>
#define     vl                           vector<ll>
#define     pb                           push_back
#define     pp                           pop_back
#define     ff                           first
#define     ss                           second
#define     nl                           "\n"
#define     MOD                          1000000007
#define     sp                           " "
#define     CLR(a)                       memset(a,0,sizeof(a))
#define     SET(a)                       memset(a,-1,sizeof(a))
#define     mk                           make_pair
#define     ALL(x)                       x.begin(),x.end()
using namespace std;
int dx[]={0,0,1,-1,-1,-1,1,1};
int dy[]={1,-1,0,0,-1,1,1,-1};
typedef long long ll;
typedef long double ld;
int main(){
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(10);
    cin.tie(nullptr);  cout.tie(nullptr);
    // freopen ("output.txt","w",stdout);
    // freopen ("input.txt","r",stdin);
    int n;
    string s;
    int k;
    cin>>n>>s>>k;
    for(int i=0;i<n;i++){
        if(s[k-1]!=s[i]) s[i]='*';
    }
    cout<<s<<endl;


    return 0;
}


Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A;
    std::vector<int64_t> S;
    int64_t sum = 0;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);

        sum += t;
        S.push_back(sum);
    }

    int64_t ans = INT64_MAX;

    for (int64_t i = 0; i < N - 1; ++i) {
        auto sunu = S[i];
        auto kuma = S[N-1] - S[i];
        auto diff = std::abs(sunu - kuma);
        ans = std::min(ans, diff);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3564
import sys
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
f=sorted(list(map(int,input().split())),reverse=True)
h,l=max(a[i]*f[i] for i in range(n))+1,0

if sum(a)<=k: print(0);sys.exit()

while h-l>1:
    m=(h+l)//2
    practice=sum(max(0,a[i]-m//f[i]) for i in range(n))
    if practice<=k: h=m
    else: l=m
print(h)

Measured memory_bytes: 121036
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main()
{
	int N, X;
	cin >>N >>X;
	vector<int> cities(N);
	rep(i,N){
		cin >>cities.at(i);
	}
	cities.push_back(X);

	sort(cities.begin(),cities.end());

	vector<int> dicities(N);
	rep(i,N){
		dicities.at(i) = cities.at(i+1)-cities.at(i);
	}

	int D=dicities.at(0);
	rep(i,N){
		D = gcd(D,dicities.at(i));
	}

	cout <<D <<endl;
	
}

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

using namespace std;
#define ll long long int
ll n,ara[3005],dp[3005][3005][2];
bool vis[3005][3005][2];
ll func(ll l, ll r, ll turn)
{
    if(l>r) return 0;
    if(vis[l][r][turn]) return dp[l][r][turn];
    vis[l][r][turn]=true;
    if(!turn)
    {
        ll p1=ara[l]+func(l+1,r,1-turn);
        ll p2=ara[r]+func(l,r-1,1-turn);
        return dp[l][r][turn]=max(p1,p2);
    }
    else
    {
        ll p1=-ara[l]+func(l+1,r,1-turn);
        ll p2=-ara[r]+func(l,r-1,1-turn);
        return dp[l][r][turn]=min(p1,p2);
    }
}

int main()
{
    ll i,j;
    cin>>n;
    for(i=1; i<=n; i++) cin>>ara[i];
    ll ans=func(1,n,0);
    cout<<ans<<endl;
    return 0;


}




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

using namespace std;
int t[100001]={};
int main()
{
long d;
cin>>d;
for(int i=0;i<d;i++)
{long x;
cin>>x;
t[x]++;
if(x>0)
t[x-1]++;
t[x+1]++;
    
}
sort(t,t+100001);
reverse(t,t+100001);
cout<<t[0]<<endl;
return 0;
}
//bbgg

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

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

    int ans = 0;

    string s, t;

    cin >> s >> t;

    for (int i = 0; i < 3; i++) {

        if (s[i] == t[i]) ans++;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define pb push_back
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ini(a, i) memset(a, i, sizeof(a))
#define forf(i,a,b) for(int i=a;i<b;i++)
#define forb(i,a,b) for(int i=b-1;i>=a;i--)
#define debug(ar, n) for(int i=0 ; i<n ; ++i) cout<<ar[i]<<' ';cout<<endl;
const int MAX_VALUE = LONG_MAX;
const int MIN_VALUE = LONG_MIN;
const ull U_MAX_VALUE = ULLONG_MAX;
typedef pair<int, int> pi;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}


ll mod_power(ll x, ull y, ll p)
{
	ll res = 1;
	x = x % p;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll find_no_of_bits(ll n)
{
	ll bits = 0;
	while (n)
	{
		n /= 2;
		bits++;
	}
	return bits;
}

void solve()
{
	ll n;
	cin >> n;
	ll dp[n][3];
	for (ll i = 0; i < n; i++)
	{
		cin >> dp[i][0] >> dp[i][1] >> dp[i][2];
	}
	for (ll i = 0; i < n; i++)
	{
		if (i > 0)
		{
			dp[i][0] = max(dp[i - 1][1] + dp[i][0], dp[i - 1][2] + dp[i][0]);
			dp[i][1] = max(dp[i - 1][0] + dp[i][1], dp[i - 1][2] + dp[i][1]);
			dp[i][2] = max(dp[i - 1][0] + dp[i][2], dp[i - 1][1] + dp[i][2]);
		}
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}
signed main()
{

	fast_io;
	// ll t = 1;
	// cin >> t;
	// while (t--)
	// {
		solve();
		cout << "\n";
	// }

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

int main()
{
        ll MOD = 1000000007;

        ll N, M; cin >> N >> M;
        if (abs(N-M) > 1) {
                cout << 0 << endl;
        }
        else {
                if (N == M) {
                        ll ans = 1;
                        for (int i = 0; i < N; ++i) {
                                ans = ans * (i+1) % MOD;
                        }
                        ans = ans * ans % MOD;
                        ans = ans * 2 % MOD;
                        cout << ans << endl;
                }
                else {
                        ll ans1 = 1;
                        for (int i = 0; i < N; ++i) {
                                ans1 = ans1 * (i+1) % MOD;
                        }
                        ll ans2 = 1;
                        for (int i = 0; i < M; ++i) {
                                ans2 = ans2 * (i+1) % MOD;
                        }
                        ans1 = ans1 * ans2 % MOD;
                        cout << ans1 << endl;
                }
        }
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll h, w;

    cin >> h >> w;

    if (h == 1 || w == 1){
      cout << 1 << endl;
    } else {
      cout << setprecision(30) << ceil(h*w/2.0) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int H, N;
	scanf("%d %d", &H, &N);

	int A[100000];
	int i;
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	int sum = 0;
	for (i = 0; i < N; i++) {
		sum += A[i];
	}

	if (sum >= H) {
		printf("Yes");
	}
	else {
		printf("No");
	}

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF() { return std::numeric_limits<T>::max() / 16; }
std::mt19937 mt{std::random_device{}()};
int main()
{
    int N;
    std::cin >> N;
    std::vector<ll> a(N);
    for (int i = 0; i < N; i++) { std::cin >> a[i]; }
    auto f = [&](bool p) {
        ll sum = 0, ans = 0;
        for (int i = 0; i < N; i++) {
            sum += a[i];
            if (p and (sum <= 0)) {
                ans += (1LL - sum), sum = 1;
            } else if (not p and (sum >= 0)) {
                ans += (sum + 1LL), sum = -1;
            }
            p = not p;
        }
        return ans;
    };
    std::cout << std::min(f(true), f(false)) << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define YES "YES"
#define Yes "Yes"
#define NO "NO"
#define No "No"
#define YESNO OUT(three(solve(),YES,NO))
#define YesNo OUT(three(solve(),Yes,No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<ppr, Vppr, greater<ppr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,1,1,-1,-1,0 }, dy[] = { 1,0,-1,0,1,-1,1,-1,0 };
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 4010;
const int SIZE3 = 305;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
ut N, M, K, X, L, Y, H, W, Q, D,T;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], nums[SIZE], maps[SIZE2][SIZE2], answer = zero;
LL A[SIZE],B[SIZE];
LL parent[SIZE];
LL solve() {
	cin >> N;
	string s;
	cin >> s;
	LL now = 0;
	REP(i, s.size()) {
		if (s[i] == '#') now++;
		A[i] = now;
	}
	now = 0;
	RREP(i, s.size()) {
		if (s[i] != '#') now++;
		B[i] = now;

	}
	LL minium = INF;
	REP(i, N+1) {
		if (i == 0) minium = B[i];
		else MN(minium, A[i-1] + B[i]);
	}
	cout << minium << endl;
	return 0;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	solve();
	//	cin >> N;
	return 0;
}


Measured memory_bytes: 22420
# B - ROT N
N = int(input())
S = str(input())
def caesar(s, n):
    ns = []
    for ch in s:
        # A - Z
        if ('A' <= ch and ch <= 'Z'):
            ns.append(chr((ord(ch) - ord('A') + n) % 26 + ord('A')))
        # no change for other characters
        else:
            ns.append(ch)
    return "".join(ns)

result = caesar(S, N)
print(result)

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

int main(void){
    ll x;
    cin>>x;
    ll ans=x/11;
    ll d=x%11;
    ans*=2;
    if (d==0) ;
    else if (d<=6) ans++;
    else ans+=2;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
const int maxn=105;
char s[maxn]; char f[maxn]; char g[maxn];

bool check(char *a,int len)
{
	for(int i=1,j=len;i<=j;i++,j--)
	{
		if(a[i]!=a[j]) return false;
	}
	return true;
}
int main(void)
{
	scanf("%s",s+1);
	int len1=strlen(s+1);
	int len2=0; int len3=0;
	for(int i=1;i<=(len1-1)/2;i++)
	{
		f[++len2]=s[i];
	}
	for(int i=(len1+3)/2;i<=len1;i++)
	{
		g[++len3]=s[i];
	}
	if(check(s,len1)&&check(f,len2)&&check(g,len3)) printf("Yes\n");
	else printf("No\n");
	return 0;
	
}

Measured memory_bytes: 256
o = input()
e = input()

if len(o) - len(e) == 1:
    for i in range(len(o)-1):
        print(o[i]+e[i] ,end="")
    else:
        print(o[len(o)-1])
else:
    for j in range(len(o)):
        print(o[j]+e[j] ,end="" )

Measured memory_bytes: 38384
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll n;
    cin>>n;
    if(n==2){
        cout<<"1\n";
        return;
    }
    ll ans=2,d1,d2;
    for(ll i=2;i*i<=n;i++){
        if(n%i){
            continue;
        }
        d1=min(i,n/i);
        d2=max(i,n/i);
        while((d2%d1)==0){
            d2/=d1;
        }
        if((d2%d1)==1){
            ++ans;
        }
    }
    --n;
    for(ll i=2;i*i<=n;i++){
        if(n%i){
            continue;
        }
        ans+=2;
        d1=i,d2=n/i;
        if(d1==d2){
            --ans;
        }
    }
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 384
n, m = list(map(int, input().split()))
pyi = []
for i in range(m):
    tmp = list(map(int, input().split()))
    pyi.append([tmp[0], tmp[1], i])
pyi = sorted(pyi, key = lambda x:x[1])
count_n = [0]*n
for i in range(m):
    count_n[pyi[i][0]-1] += 1
    pyi[i].append(count_n[pyi[i][0]-1])
pyi = sorted(pyi, key = lambda x:x[2])
for i in range(m):
    print(str(pyi[i][0]).rjust(6, "0") + str(pyi[i][-1]).rjust(6, "0"))

Measured memory_bytes: 32888
import math
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

def check_order(k):
    res = 0
    for _ in range(n):
        if len(k) == 1:
            break
        s = k[0]
        c = 0
        for i in k:
            if s >= i:
                 c += 1
        k.pop(0)
        res += math.factorial(len(k)) * (c-1)
    return res

p_order = check_order(p)
q_order = check_order(q)

print(abs(p_order-q_order))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;

int main() {
  int n;
  int64 A, B;
  scanf("%d%lld%lld", &n, &A, &B);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int64 ret = 0;
  for (int i = 1; i < n; ++i) {
    ret += min((a[i] - a[i - 1]) * A, B);
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 640
import math,itertools
def distance(i,j):
	return math.sqrt(math.pow(i[0]-j[0],2)+math.pow(i[1]-j[1],2))
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
city = []
for i in range(n):
	city.append([int(p) for p in input().split(' ')])
# print(n,city)

dists = [distance(c[0],c[1]) for c in itertools.combinations(city,2)]
t = math.factorial(n)/2*(n-1)/combinations_count(n,2)
# print(t)
res = sum([d*t for d in dists])/(math.factorial(n)/2)
print(res)

Measured memory_bytes: 3064
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		
		System.out.println(a*b/2);
		
		
	}

}


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

using namespace std;

int main(){
  int n; cin >> n;
  vector<pair<int,int>> a(n);
  int m=0; //配列a(n)の要素の最大値
  for(int i=0;i<n;i++){
    cin >> a[i].second;
    a[i].first=i;
    m=max(m,a[i].second);
  }
  int count=0;
  for(int i=0;i<n;i++){
    if(a[i].second==m){
      count++;
    }
  }
  int M=0; //配列a(n)の要素のうち、mの次の最大値
  for(int i=0;i<n;i++){
    if(a[i].second!=m){
      M=max(M,a[i].second);
    }
  }
  if(count>=2){ //もし最大値をとる要素が２つ以上あれば、最大値mを出力
    for(int i=0;i<n;i++){
      cout << m << endl;
    }
  }
  else{ //最大値をとる要素が１つのみならば、Mを出力
    for(int i=0;i<n;i++){
      if(a[i].second==m){
        cout << M << endl;
      }
      else{
        cout << m << endl;
      }
    }
  }
  
}


Measured memory_bytes: 3200
# include <iostream>
# include <cstdio>
# include <cmath>
# include <cstring>
# include <string>
# include <cstdlib>
# include <algorithm>
# include <stack>
# include <queue>
# include <vector>
# define maxx (50000)
# define Pi (3.14159265358979)
# define inf (2147483647)
using namespace std;
int n,m=1;
char a[110][110];
char b[110][110];
bool p=1;
int main() {
	int n,m;
	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			cin>>a[i][j];
			b[i][j]='0';
		}
	}
	for(int i=1; i<=n; i++) { //ÅÐ¶Ï
		for(int j=1; j<=m; j++) {
			if(a[i][j]=='#') {
				b[i][j]='#';
				if(a[i-1][j]!='#')b[i-1][j]++;
				if(a[i][j-1]!='#')b[i][j-1]++;
				if(a[i][j+1]!='#')b[i][j+1]++;
				if(a[i+1][j]!='#')b[i+1][j]++;
				if(a[i-1][j-1]!='#')b[i-1][j-1]++;
				if(a[i-1][j+1]!='#')b[i-1][j+1]++;
				if(a[i+1][j-1]!='#')b[i+1][j-1]++;
				if(a[i+1][j+1]!='#')b[i+1][j+1]++;
			}

		}
	}
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			cout<<b[i][j];
		}
		cout<<endl;
	}
	return 0;
}

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

int main()
{
  	int n, m;
  cin >> n >> m;
  while(m--)
  {
    int a;
    cin >> a;
    n-=a;
  }
  if(n<0)cout << -1;
  else cout << n;
}

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

using namespace std;

int main()
{
	int H, W, D;
	cin >> H >> W >> D;

	vector<pair<int, int>> v(H * W);
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			int A;
			cin >> A;
			v[A - 1] = make_pair(i, j);
		}
	}

	auto mp = [&](int x, int y) {
		return abs(v[x].first - v[y].first) + abs(v[x].second - v[y].second);
	};

	vector<int> ans(H * W, 0);

	for (int i = D; i < H * W; ++i) {
		ans[i] = ans[i - D] + mp(i - D, i);
	}

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int L, R;
		cin >> L >> R;
		--L;
		--R;
		cout << ans[R] - ans[L] << endl;
	}
}


Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
using namespace std;
int main(void){
    const long long int mod=1000000007;
    long long int n,m,comb=1;
    cin>>n>>m;
    if(abs(n-m)>1){cout<<0;return 0;}
    for(int i=1;i<=n;i++){
        comb*=i;
        comb%=mod;
    }
    for(int i=1;i<=m;i++){
        comb*=i;
        comb%=mod;
    }
    
    if(abs(n-m)==1){cout<<comb;return 0;}
    if(abs(n-m)==0){cout<<(comb*2)%mod;return 0;}
    
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

string s, t;

void solve() {
    int same_c = 0;
    int start = -1;
    repr(i, s.length()) {
        int temp = i;
        repr(j, t.length()) {
            if (temp >= 0 && (s[temp] == t[j] || s[temp] == '?')) {
                same_c++;
                temp--;
            } else {
                same_c = 0;
                break;
            }
        }
        if (same_c == t.length()) {
            start = temp+1;
            break;
        }
    }
    if (start == -1) cout << "UNRESTORABLE" << endl;
    else {
        rep(i, start) {
            if (s[i] == '?') cout << 'a';
            else cout << s[i];
        }
        for (int j = start; j < start + t.length(); ++j) {
            cout << t[j - start];
        }
        for (int i = start + t.length(); i < s.length(); ++i) {
            if (s[i] == '?') cout << 'a';
            else cout << s[i];
        }
    }
}

int main() {
    cin >> s >> t;
    solve();
    return 0;
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll res;set<int>s;int a[N],pos[N],n;
typedef set<int>::iterator IT;
IT itl,itr,it;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]),pos[a[i]]=i;
	s.insert(0),s.insert(n+1),s.insert(pos[n]);
	fd(i,n-1,1){
		itr=s.lower_bound(pos[i]),itl=itr,--itl;
		if(itl!=s.begin()){
			it=itl,--it;
			res+=1ll*i*((*itr)-pos[i])*((*itl)-(*it));
		}
		if(itr!=--s.end()){
			it=itr,++it;
			res+=1ll*i*((*it)-(*itr))*(pos[i]-(*itl));
		}
		s.insert(pos[i]);
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	map<string, int> mp;
	rep(i, n) {
		string s;
		cin >> s;
		mp[s]++;
	}
	int m;
	cin >> m;
	rep(i, m) {
		string s;
		cin >> s;
		mp[s]--;
	}
	int ans = 0;
	for (auto c : mp) {
		chmax(ans, c.second);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> v(n);
  for(int i=0; i<n; i++) cin >> v[i];
  
  bool ok = true;
  int max = v[0]-1;
  if(max<0) max = 0;
  for(int i=1; i<n; i++) {
    if(max<v[i]) v[i]--;
    if(max>v[i]) {ok = false; break;}
    if(v[i]>max) max = v[i];
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;

    auto sub = [&](const string& S) {
        int cur = 0, last = -c - 1;
        vector<int> res(n + 1, 0); // 各マスを区切る線に注目
        for (int i = 0; i < n; i++) {
            if (i - last > c && S[i] == 'o')
                ++cur, last = i;
            res[i + 1] = cur;
        }
        return res;
    };

    const auto& left = sub(s);
    string t = s;
    reverse(t.begin(), t.end());
    const auto& right = sub(t);
    for (int i = 0; i < n; i++) {
        if (s[i] == 'x')
            continue;
        if (left[i] + right[n - i - 1] < k)
            cout << i + 1 << endl;
    }
}

Measured memory_bytes: 5256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();

            int ans = 1;

            while ((ans << 1) <= n)
                ans = ans << 1;

            out.println(ans);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 22996
from collections import Counter


def main():
    r"""
    数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶ

        各 i=1,2...,n-2 について、ai=ai+2
        数列に現れる数はちょうど 2種類偶数長の数列

    v1,v2,...,vnが与えられます
    要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。
    書き換える要素の数は最小でいくつになるか求めてください。

    2 <= n <= 10^5, nは偶数
    1 <= vi <= 10^5, viは整数
    """
    n = int(input())
    *v, = map(int, input().split())

    ans = f(n, v)
    assert ans == simple(n, v)
    print(ans)


def simple(n, v):
    # most_commonを事前に使い短くする
    # 1種類しかないならば存在しない種類を0個で足して条件分岐を潰す
    c1 = Counter(v[::2]).most_common() + [(0, 0)]
    c2 = Counter(v[1::2]).most_common() + [(0, 0)]

    if c1[0][0] == c2[0][0]:
        n_no_change = max(c1[0][1] + c2[1][1],
                          c1[1][1] + c2[0][1])
        return n - n_no_change
    else:
        return n - c1[0][1] - c2[0][1]

def f(n, v):
    """
    3 1 3 2:
        3種類
        a1=a3, a2 != a4
    """
    ans = float("inf")
    v_idx_even = []
    v_idx_odd = []
    for i, x in enumerate(v):
        if i % 2 == 0:
            v_idx_even.append(x)
        else:
            v_idx_odd.append(x)

    ve = Counter(v_idx_even)
    vo = Counter(v_idx_odd)

    if len(ve) == 1 and len(vo) == 1:
        # 両方1種類
        ans = 0
        if ve.most_common()[0][0] == vo.most_common()[0][0]:
            ans = n // 2

    elif len(ve) == 1 or len(vo) == 1:
        # 片方1種類
        idx = 0
        if ve.most_common()[0][0] == vo.most_common()[0][0]:
            idx = 1
        if len(ve) == 1:
            ans = n // 2 - vo.most_common()[idx][1]
        else:
            ans = n // 2 - ve.most_common()[idx][1]

    else:
        # 両方2種類以上
        if ve.most_common()[0][0] != vo.most_common()[0][0]:
            ans = n - ve.most_common()[0][1] - vo.most_common()[0][1]
        else:
            ans = n - \
                max(ve.most_common()[0][1] + vo.most_common()[1][1],
                    ve.most_common()[1][1] + vo.most_common()[0][1])

    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 20676
/*=======================
Author    : Shounak Dey
Filename  : d.cpp
=======================	*/

#include<bits/stdc++.h>

using namespace std;

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

#define PB push_back
#define MK make_pair 
#define SZ(a) (int)(sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define read(n) scanf("%d",&n)
#define readl(n) scanf("%lld",&n)
#define readul(n) scanf("%llu",&n);


#define SORTV(a) sort(a.begin(),a.end())
#define TEST int Test;cin >> Test;while(Test--)
#define gcd(a,b) __gcd(a,b)
#define ffs(a) __builtin_ffs(a) // find first set
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)


#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

vector<string> split(const string& s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c))
		v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

int main()
{
	fast_io;
	ll x;
	cin >> x;
	auto isPrime = [](ll x){
	    if(x==1)
	        return 0;
	    ll curr=2;
	    while((curr*curr)<=x){
	        if((x%curr)==0)
	            return 0;
	        curr ++;
	    }
	    return 1;
	};
	while(1){
	    if(isPrime(x)){
	        cout << x << endl;
	        return 0;
	    }
	    x++;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	int res = (int)1 << 60;
	for (int i = 0; i + K - 1 < N; i++) {
		res = min(res, A[i + K - 1] - A[i]);
	}
	cout << res << endl;
}

Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Debug.Trace
import Data.Functor
import qualified Data.Sequence as S
import Data.Foldable

main :: IO()
main = do
  n <- readLn :: IO Int
  cs <- B.getContents :: IO B.ByteString
  B.putStrLn . B.unwords $ solve''' cs
 
insertC = B.pack "insert"
deleteC = B.pack "delete"
deleteLastC = B.pack "deleteLast"
deleteFirstC = B.pack "deleteFirst"

data Dll a = Dll !Int [a] deriving (Show) 
emptyDll :: Dll a
emptyDll = Dll 0 []
dllToList :: Dll a -> [a]
dllToList (Dll n vs) = take n vs
insertDll :: a -> Dll a -> Dll a
insertDll !v (Dll n vs) = let newn = n + 1 in newn `seq` Dll newn (v:vs)
deleteDll :: (Eq a) => a -> Dll a -> Dll a
deleteDll !v (Dll n vs) = if Data.List.elem v validVs
                          then Dll (n - 1) $ delete v validVs
                          else Dll n validVs
  where
    validVs = take n vs
    delete _ [] = []
    delete !v (b:bcc) = if v == b
                        then bcc
                        else b:(delete v bcc)
deleteLast :: Dll a -> Dll a
deleteLast (Dll n vs) = let newn = n - 1 in newn `seq` Dll newn vs
deleteFirst :: Dll a -> Dll a
deleteFirst (Dll n vs) = let newn = n - 1 in newn `seq` Dll newn $ tail vs

solve''' :: B.ByteString -> [B.ByteString]
solve''' = dllToList . Data.Foldable.foldl' func emptyDll . B.lines
  where
    func :: Dll B.ByteString -> B.ByteString ->Dll B.ByteString
    func acc cs
      | command == insertC = {-# SCC insertDll #-} insertDll val acc
      | command == deleteC = {-# SCC deleteDll #-} deleteDll val acc
      | command == deleteLastC = {-# SCC deleteLastDll #-} deleteLast acc
      | command == deleteFirstC = {-# SCC deleteFirstDll #-} deleteFirst acc
        where
          (command:c) = B.words cs
          (val:_) = c
          delete _ [] = []
          delete !v (b:bcc) = if v == b
                              then bcc
                              else b:(delete v bcc)



Measured memory_bytes: 199156
from math import sqrt
n = int(input())


def calc_f(a, b):
    return max(len(str(a)), len(str(b)))


ans = 10 ** 10
for i in range(1, int(sqrt(n)) + 1):
    if n % i != 0:
        continue
    j = n // i
    ans = min(ans, calc_f(i, j))

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
int main(){
    long long n,k;
    scanf("%lld %lld",&n,&k);
    if(k==1){
        printf("%d\n",0);
        return 0;
    }
    long long tmp=0;
    n=n%k;
    while(1){
        tmp=n;
        n=llabs(n-k);
        if(tmp<=n){
            printf("%lld\n",tmp);
            return 0;
        }

    }
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] A = new int[M];
    int[] B = new int[M];
    for (int i = 0; i < M; i++) {
      // 0 origin
      A[i] = sc.nextInt()-1;
      B[i] = sc.nextInt()-1;
    }
    
    // union-find
    int[] par = new int[N];
    for (int i = 0; i < N; i++) {
      par[i] = i;
    }
    int[] size = new int[N];
    Arrays.fill(size, 1);
    
    long[] ans = new long[M];
    ans[M-1] = (long) N*(N-1)/2;
    for (int i = M-2; i >= 0; i--) {
      if (root(par, A[i+1]) == root(par, B[i+1])) {
        ans[i] = ans[i+1];
      } else {
        ans[i] = ans[i+1] - (long)size[root(par,A[i+1])]*size[root(par,B[i+1])];
        unite(par, size, A[i+1], B[i+1]);
      }
    }

    for (int i = 0; i < M; i++) {
      System.out.println(ans[i]);
    }
  }
  
  private static int root(int[] par, int x) {
    if (par[x] == x) {
      return x;
    }
    par[x] = root(par, par[x]);
    return par[x];
  }
  
  private static void unite(int[] par, int[] size, int x, int y) {
    x = root(par, x);
    y = root(par, y);
    if (x == y) {
      return;
    }
    if (x > y) {
      int tmp = x;
      x = y;
      y = tmp;
    }
    par[x] = y;
    size[y] += size[x];
  }
}

Measured memory_bytes: 98616
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//STANDARD DATA TYPES
#define ll long long
#define llu unsigned long long
#define ld long double
//ADV DATA TYPES
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
//C ++ DS
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define all(x) x.begin(),x.end()

//priority_queue < pii, vector < pii >, greater < pii > > pq;
//lower_bound(v.begin(),v.end(),20);//for any sorted container
//CONSTANTS
#define MOD (int)(1e9+7)
#define INF 0x3f3f3f3f
#define MAXN (int)(1e5+1)
//MOD OPERATIONS
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
//DEBUG
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
int main()
{
	fastio;
	int n;cin>>n;
	vector<vi> match(n,vi(n));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
			cin>>match[i][j];
	}
	//dp[i][mask] represent number of ways to match subset women(mask) with upto 0 to i men
	//for i+1 iterate over masks then jth women 
	//if jth women can pair with ith men
	//dp[i+1][mask^(1<<j)]+=dp[i][mask]
	//else dp[i+1][mask]+=dp[i][mask]//dont pair ith men(note if we iterate mask big to small then this will be first update of dp[i+1][mask])
	vector<int> dp(1<<n);
	dp[0]=1;
	for(int i=0;i<n;i++)//ith men
	{
		for(int mask=(1<<n)-1;mask>=0;mask--)
		{
			if(dp[mask]==0)continue;
			for(int j=0;j<n;j++)
			{
				if(match[i][j] && !(mask&(1<<j)))
				{
					dp[mask^(1<<j)]=addmod(dp[mask^(1<<j)],dp[mask]);
				}
			}
		}
	}  
	cout<<dp[(1<<n)-1]<<endl;
}


Measured memory_bytes: 8576
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var S = Console.ReadLine();
            var Q = int.Parse(Console.ReadLine());

            var flag = true;
            var ll = new LinkedList<char>();
            ll.AddLast('*');

            for (int i = 0; i < Q; i++)
            {
                var input = Console.ReadLine();
                if (input[0] == '1')
                {
                    if (flag)
                    {
                        flag = false;
                    }
                    else
                    {
                        flag = true;
                    }
                    continue;
                }
                var q = input.Split().ToArray();
                if (flag)
                {
                    if (q[1] == "1")
                    {
                        ll.AddFirst(char.Parse(q[2]));
                    }
                    else
                    {
                        ll.AddLast(char.Parse(q[2]));
                    }
                }
                else
                {
                    if (q[1] == "1")
                    {
                        ll.AddLast(char.Parse(q[2]));
                    }
                    else
                    {
                        ll.AddFirst(char.Parse(q[2]));
                    }
                }
            }

            var str = new string(ll.ToArray()).Replace("*", S);
            Console.WriteLine(flag ? str : new string(str.Reverse().ToArray()));
        }
    }
}


Measured memory_bytes: 34092
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    string A;
    cin >> A;
    vector<ll> bucket(30);
    for(int i = 0; i < 30; i++){
        bucket[i] = 0;
    }
    for(ll i = 0; i < A.size();i++){
        bucket[A[i] - 'a']++;
    }
    ll count = 0;
    for(int l = 0; l < 29; l++){
        for(int r = l + 1; r < 30; r++){
            count += bucket[l] * bucket[r];
        }
    }
    cout << count + 1ll << endl;
}


Measured memory_bytes: 640