akhauriyash/Code-Regression huggingface dataset:
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int W, a, b;
	int ans = 0;
	cin >> W >> a >> b;

	if (a <= b)
		ans = max(ans, b - (a + W));
	else
		ans = max(ans, a - (b + W));
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    //[0,i)でのM,C,MCの数
    ll M[N+1], C[N+1], MC[N+1];
    M[0] = C[0] = MC[0] = 0;
    rep(i, N){
        M[i+1] = M[i], C[i+1] = C[i], MC[i+1] = MC[i];
        if(S[i] == 'M') M[i+1]++;
        if(S[i] == 'C') C[i+1]++, MC[i+1]+=M[i];
    }
    rep(i, Q){
        int k;
        cin >> k;
        ll ans = 0;
        //j文字目から始める場合
        rep(j, N){
            if(S[j] != 'D') continue;
            ans += MC[min(j+k, N)]-MC[j]-M[j]*(C[min(j+k, N)]-C[j]);
        }
        cout << ans << endl;
    }
}

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

#define endl "\n"
#define f first
#define s second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll M = 998244353;
const int N = 5*1e5+5;
const int K = 3000;
const ll INF = 1e18;
const double EPS = 1e-6;

ll n,a,b,c,d,l1,l2,r1,r2;

int main () {
	faster
	cin>>n>>a>>b>>c>>d;
	ll st = n-1;
	for (int i = 0; i<=st; i++) {
		l1 = a + i*c;
		r1 = a + i*d;
		l2 = b + (st - i)*c;
		r2 = b + (st - i) *d;
		if (l2<l1) {
			swap(l2,l1);
			swap(r2,r1);
		}
		if (l2 <= r1) {
			cout<<"YES";
			//cout<<l1<<' '<<r1<<' '<<l2<<' '<<r2<<endl;
			return 0;
		}
	}
	cout<<"NO";

    return 0;
}


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

typedef struct {
    int num; // Card Number
    char mark; // Card Mark
} Card;

void BubbleSort(Card *);
void SelectionSort(Card *);

int N;

int main(){
    int i,stableflag = 0;
    Card *C,*tmpC;
    scanf("%d",&N);
    C = (Card *)malloc(sizeof(Card) * N);
    tmpC = (Card *)malloc(sizeof(Card) * N);
    
    for (i = 0; i < N; i++) {
        // \n in buffer is ignored by %*c
        scanf("%*c%c %d",&C[i].mark,&C[i].num);
    }
    
#ifdef D
    for (i = 0; i < N; i++) {
        printf("%c%d ",C[i].mark,C[i].num);
    }
#endif
    
    // copy
    for (i = 0; i < N; i++) {
        tmpC[i] = C[i];
    }
    
    // BubbleSort
    BubbleSort(C);
    for (i = 0; i < N; i++) {
        printf("%c%d",C[i].mark,C[i].num);
        if(i == N-1){
            printf("\n");
            break;
        }
        printf(" ");
    }
    
    // BubbleSort is always stable
    printf("Stable\n");
    
    // SelectionSort
    SelectionSort(tmpC);
    for (i = 0; i < N; i++) {
        printf("%c%d",tmpC[i].mark,tmpC[i].num);
        if(i == N-1){
            printf("\n");
            break;
        }
        printf(" ");
    }
    
    // To see if SelectionSorted array is same to BubbleSorted one or not
    for (i = 0; i < N; i++) {
        if (tmpC[i].mark != C[i].mark) {
            stableflag = 1;
            break;
        }
    }
    if (stableflag) {
        printf("Not stable\n");
    }else{
        printf("Stable\n");
    }
    
    free(C);
    return 0;
}


void BubbleSort(Card *C){
    int i = 0, j,flag = 1;
    Card tmp;
    while (flag){
        flag = 0;
        for (j = N-1; j > i; j--) {
            if(C[j-1].num > C[j].num){
                tmp = C[j];
                C[j] = C[j-1];
                C[j-1] = tmp;
                flag = 1;
            }
        }
        i++;
    }
}



void SelectionSort(Card *C){
    int i = 0,j,minj;
    Card tmp;
    
    for (i = 0; i < N; i++) {
        minj = i;
        for (j = i+1; j < N; j++) {
            if (C[j].num < C[minj].num) {
                minj = j;
            }
        }
        if(minj != i){
            tmp = C[minj];
            C[minj] = C[i];
            C[i] = tmp;
        }
    }
}




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

public class Main{

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int y = scanner.nextInt();

		List<Integer> listA = new ArrayList<>();
		listA.add(1);
		listA.add(3);
		listA.add(5);
		listA.add(7);
		listA.add(8);
		listA.add(10);
		listA.add(12);
		List<Integer> listB = new ArrayList<>();
		listB.add(4);
		listB.add(6);
		listB.add(9);
		listB.add(11);
		List<Integer> listC = new ArrayList<>();
		listC.add(2);

		if (listA.contains(x) && listA.contains(y) || listB.contains(x) && listB.contains(y) || listC.contains(x) && listC.contains(y)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 21716
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
d=dict(Counter(D))
p=998244353
#print(d)
maxi=max(d)

ans=1
if D[0]!=0:
  print(0)
else:
  if d[0]!=1:
    print(0)
  else:
    for i in range(1,maxi+1):
      if i not in d:
        print(0)
        exit()
      else:
        s =  (d[i-1]**d[i])%p
        ans = (ans * s)%p
    print(ans)

Measured memory_bytes: 23004
import java.util.Scanner;

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

		int n = sc.nextInt();
		int sum = 0;
		int maxP = 0;
		for (int i = 0; i < n; i++) {
			int p = sc.nextInt();
			sum += p;
			if (p > maxP)
				maxP = p;
		}
		sum -= maxP / 2;
		System.out.println(sum);
		sc.close();
	}
}


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

using namespace std;
int main(){
	long long int N;
	cin >> N;
	long long int memo = pow(3, N);
	long long int ans = 1;
	vector<long long int>D(N);
	for( size_t i = 0; i < N; i++ ){
		cin >> D[i];
		if( D[i] % 2 ){

		} else{
			ans *= 2;
		}
	}
	cout << memo - ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define INF 9223372036854775807
#define M 100000003

signed main()
{
    string s, p;
    cin >> s >> p;

    ull q[s.size() + 1];
    ull h[s.size() + 1];
    q[0] = 1;
    h[0] = 0;
    for (int i = 1; i <= s.size(); i++)
    {
        q[i] = q[i - 1] * M;
        h[i] = h[i - 1] * M + s[i - 1];
    }

    ull ht = 0;

    for (int i = 0; i < p.size(); i++)
        ht = ht * M + p[i];

    for (int i = p.size(); i <= s.size(); i++)
    {
        ull hs = h[i] - h[i - p.size()] * q[p.size()];
        if (hs == ht)
            cout << i - p.size() << endl;
    }
}


Measured memory_bytes: 19724
#include<stdio.h>

int main(void){
  int i,j;
  int m,n;
  int p[20][20],count,maxC;
  
  scanf("%d%d",&m,&n);

  for(i=0;i<m;i++)
    for(j=0;j<n;j++)
      scanf("%d",&p[i][j]);

  maxC=0;
  for(i=0;i<m;i++){
    count=0;

    for(j=0;j<n;j++)
      if(p[i][j])
        count++;

    if(maxC<count)
      maxC=count;
  }
  
  printf("%d\n",maxC);

  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String S = sc.next();

		double rCount = 0;
		double half = (double) N/2;
		for (char c : S.toCharArray()) {
			if(c == 'R') {
				rCount++;
			}

			if(rCount > half) {
				System.out.println("Yes");
				return;
			}
		}

		System.out.println("No");
	}

}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,i,j,k,n,m,t;
string s[1005];
string s1,s2;
int main(){
	scanf("%lld",&n);
	cin>>s1>>s2;
	for(i=0;i<n;i++){
		printf("%c%c",s1[i],s2[i]);
	}

	return 0;
}


Measured memory_bytes: 256
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
typedef unsigned long long UL;

int main()
{
    fast;
    ll n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0||(i%5==0&&i%3==0)) continue;
        else
            sum+=i;
    }
   cout<<sum<<endl;
}




Measured memory_bytes: 3664
freq = {"AC":0, "WA":0, "TLE":0, "RE":0}
for _ in range(int(input())):
    s = input()
    freq[s] += 1

print("AC x", freq["AC"])
print("WA x", freq["WA"])
print("TLE x", freq["TLE"])
print("RE x", freq["RE"])


Measured memory_bytes: 9116
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N;
vec c;
int pre[202020], dp[202020];

signed main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    c.pb(tmp);
  }

  UNIQUE(c);
  N = c.size();

  mm(pre);

  dp[0] = 1;
  for (int i = 1; i <= N; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= MOD;

    if (pre[c[i - 1]] != -1) {
      dp[i] += dp[pre[c[i - 1]]];
      dp[i] %= MOD;
    }

    pre[c[i - 1]] = i;
  }

  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 5104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	init(5555);
	int n,a,b,c; cin>>n>>a>>b>>c; int res=0;
	for(int x=0;x<=n;x++)
	{
		for(int y=0;y<=n;y++)
		{
			int aleft = a - x;
			int bleft = b;
			int cleft = c - x - 3*y;
			if(aleft<0||bleft<0||cleft<0) continue;
			if(bleft%2!=0) continue;
			if(bleft==0&&cleft>0) continue;
			int ans = (bleft>0?choose(cleft+bleft/2 -1, cleft):1);
			ans = mult(ans, choose(bleft/2+aleft,aleft));
			ans = mult(ans, choose(bleft/2+aleft+x,x));
			ans = mult(ans, choose(bleft/2+aleft+x+y,y));
			res=add(res,ans);
		}
	}
	cout<<res<<'\n';
}


Measured memory_bytes: 384
// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue> 
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl
 
const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001 
  
// stores smallest prime factor for every number 
ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;
 

 
int main(){
    ll n,x,t; cin>>n>>x>>t;
    if(n%x==0){
        cout<<(n/x)*t<<endl;
    }else{
        cout<<(n/x + 1)*t<<endl;
    }
    
    return 0;
}

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

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

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());

  int ans= 0;
  for(int i=0; i<K; i++){
    ans+= data.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
  int n, cnt=0, cnt2=0; 
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
    if(a.at(i) % 4 == 0)cnt++;
    else if(a.at(i) % 2 == 0)cnt2++;
  }
  if(cnt2==0)cnt2++;
  if((cnt*2+1)+cnt2-1 >= n)cout << "Yes";
  else cout << "No";
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    ll k;
    cin >> n;
    cin >> k;
    vector<vector<int>> next(60, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        cin >> next[0][i];
        next[0][i]--;
    }

    for (int i = 0; i < 59; ++i) {
        for (int j = 0; j < n; ++j) {
            next[i+1][j] = next[i][next[i][j]];
        }
    }

    int res = 0;
    for (int i = 0; i < 60; ++i) {
        if (k & 1) res = next[i][res];
        k >>= 1;
    }

    cout << res + 1 << endl;
}

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

int countStr(string objStr, string str) {
  int cnt = 0;
  int index = 0;
  while (1) {
    int pos = objStr.find(str, index);
    if (pos == string::npos) return cnt;
    cnt++;
    index = pos + str.size();
  }
}

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  for (int i = 0; i < n; i++) cin >> S.at(i);
  vector<int> cnt(26, 0);
  vector<string> alp = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
  "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
  for (int i = 0; i < 26; i++) {
    int tmp = 50;
    for (int j = 0; j < n; j++) {
      tmp = min(tmp, countStr(S.at(j), alp.at(i)));
    }
    cnt.at(i) = tmp;
  }
  string ans = "";
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < cnt.at(i); j++) {
      ans = ans + alp.at(i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import collections
from math import gcd
def main():
    n=int(input())
    c=collections.Counter()
    mod=10**9+7
    for _ in range(n):
        a,b=map(int,input().split())
        g=abs(gcd(a,b))
        if g==0:
            g=1
        a//=g
        b//=g
        c[(a,b)]+=1
    ans=1
    s=set()
    for i,j in c:
        if (i,j)==(0,0):
            continue
        if (i,j) not in s:
            s.add((i,j))
            s.add((-i,-j))
            s.add((-j,i))
            s.add((j,-i))
            ans*=(pow(2,c[(i,j)]+c[(-i,-j)],mod)+pow(2,c[(j,-i)]+c[(-j,i)],mod)-1)%mod
    print((ans-1+c[(0,0)])%mod)

if __name__ == "__main__":
    main()


Measured memory_bytes: 183956
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int answer = 0;
    long n = sc.nextLong();
    long div = 2;
    long limit = (long)Math.sqrt(n) + 1;
    while(div <= limit){
      int divCnt = 0;
      while(n % div == 0){
        divCnt++;
        n /= div;
      }
      answer += countNumber(divCnt);
      if(div == 2){
        div++;
      } else {
        div += 2;
      }
    }
    if(n != 1){
      answer++;
    }
    System.out.println(answer);
  }
  static int countNumber(int n){
    int ret = 0;
    int counter = 1;
    while(counter <= n){
      n -= counter;
      ret++;
      counter++;
    }
    return ret;
  }
}

Measured memory_bytes: 35732
#include <cstdio>
#include <cstring>
using namespace std;
int n;
int k[10010];
int main()
{
	while(1)
	{
		memset(k,0,sizeof(k));
		scanf("%d",&n);
		if(n==0)break;
		bool flag=true;
		int cnt=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&k[i]);
			if(k[i]>1)flag=false;
			if(k[i]>0)cnt++;
		}
		if(flag)printf("NA\n");
		else printf("%d\n",cnt+1);
	}
	return 0;
}

Measured memory_bytes: 1084
n, m = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
b = []
for _ in range(m):
    b.append(int(input()))
for i in range(n):
    c = 0
    for j in range(m):
        c += A[i][j] * b[j]
    print(c)


Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
int main() {
	
	string S;
	cin >> S;
	long long ans = 0,cnt=0;
	for (long long i = 0; i < S.size(); i++) {
		if (S[i] == 'W') {
			ans += i - cnt;
			cnt++;
		}
	}
	cout <<ans<< endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

const ll INF=100000000;

int H,W,K;
string S[1005];

int choco[15][1005];
int B[15];

int Pow(int a,int b){
    int res=1;
    for(int i=0;i<b;++i)res*=a;
    return res;
}

int calc_choco(int x,int y,int pline_x,int pline_y){
    int cnt;
    if(pline_y==0){
        if(pline_x==0)cnt=choco[y-1][x-1];
        else cnt=choco[y-1][x-1]-choco[y-1][pline_x-1];
    }
    else if(pline_x==0)cnt=choco[y-1][x-1]-choco[pline_y-1][x-1];
    else cnt=choco[y-1][x-1]-choco[pline_y-1][x-1]-choco[y-1][pline_x-1]+choco[pline_y-1][pline_x-1];
    return cnt;
}

int calc(int b){
    int res=0;
    vector<int> line_y;
    int pline_x=0;
    int pline_y=0;
    for(int i=1;i<H;++i){
        if((b&B[i])==B[i])line_y.push_back(i);
    }
    line_y.push_back(H);
    for(int x=1;x<=W;++x){
        pline_y=0;
        int cnt;
        for(auto y:line_y){
            cnt=calc_choco(x,y,pline_x,pline_y);
            if(cnt>K){
                pline_x=x-1;
                res++;
            }
            if(x==W){
                if(calc_choco(x,y,pline_x,pline_y)>K)return INF;
            }
            pline_y=y;
        }
    }
    return line_y.size()+res-1;
}

int main(){
    for(int i=0;i<15;++i)B[i]=Pow(2,i);
    int ans=10000005;
    cin>>H>>W>>K;
    for(int i=0;i<H;++i)cin>>S[i];
    for(int y=0;y<H;++y){
        for(int x=0;x<W;++x){
            int c=S[y][x]-'0';
            if(y==0){
                if(x==0)choco[y][x]=c;
                else choco[y][x]=choco[y][x-1]+c;
            }
            else {
                if(x==0)choco[y][x]=choco[y-1][x]+c;
                else choco[y][x]=choco[y-1][x]+(choco[y][x-1]-choco[y-1][x-1])+c;
            }
        }
    }
    if(choco[H-1][W-1]<=K)cout<<0<<endl;
    else{
        for(int i=2;i<=B[H]-1;++i)ans=min(ans,calc(i));
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100
#define INFINITY (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

static int n;
static int M[MAX][MAX];

static int prim()
{
    int d[MAX], p[MAX], color[MAX];

    for (int i = 0; i < n; i++) {
        d[i] = INFINITY;
        p[i] = -1;
        color[i] = WHITE;
    }

    d[0] = 0;

    while (1) {
        int minv = INFINITY;
        int u = -1;

        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }

        if (u == -1)
            break;

        color[u] = BLACK;

        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFINITY) {
                if (d[v] > M[u][v]) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }

    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] != -1)
            sum += M[i][p[i]];
    }

    return sum;
}

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int e;
            scanf("%d", &e);
            M[i][j] = (e == -1) ? INFINITY : e;
        }
    }

    printf("%d\n", prim());
    return 0;
}


Measured memory_bytes: 2088
N, K, Q = [int(x) for x in input().split(' ')]
points = [0 for x in range(N)]
 
for q in range(Q):
  index = int(input())-1
  points[index] += 1
 
for n in range(N):
  print('Yes' if (Q-points[n]) < K else 'No')

Measured memory_bytes: 4672
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define mp make_pair

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;

class TaskB {
 public:
  int innerSolve(int n, const vector<int>& a) {
    int res = 0;
    for (int i = 0; i < n; ++i) {
      if (((n - 1) & i) == i) {
        res ^= a[i];
      }
    }
    return res;
  }

  void solveOne(istream &in, ostream &out) {
    int n;
    string s;
    in >> n;
    in >> s;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
      a[i] = s[i] - '1';
    }
    bool anyOnes = false;
    for (int x : a) if (x == 1) anyOnes = true;
    if (anyOnes) {
      for (int i = 0; i < n; ++i) if (a[i] == 2) a[i] = 0;
      out << innerSolve(n, a) << "\n";
    } else {
      for (int i = 0; i < n; ++i) if (a[i] == 2) a[i] = 1;
      out << 2 * innerSolve(n, a) << "\n";
    }
  }

  void solve(std::istream &in, std::ostream &out) {
    int nt;
    nt = 1;
    for (int it = 0; it < nt; ++it) {
      solveOne(in, out);
    }
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskB solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 5276
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
ll a[100000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    ll sum=0;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        sum+=a[i];
    }
    ll ans[n];
    for (int i = 0; i < n; i++)
        ans[i]=0;
    ll sumd=0;
    for(int i=1;i<n;i=i+2){
        sumd+=2*a[i];
    }
    ans[0]=sum-sumd;
    for(int i=0;i<n;i++){
        cout << ans[i] <<" ";
        if(i==n-1)break;
        int temp=ans[i]/2;
        ans[i+1]=2*(a[i]-temp);
    }
     cout << "\n";
}

Measured memory_bytes: 2944
from bisect import bisect_left,bisect

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

a.sort()
ai=max(a)


#if ai%2==0:
#    ai2=ai//2+1
#else:
#    ai2=ai//2
ai2=ai/2

jj=bisect(a,ai2)

if jj+1<n:
    if abs(a[jj]-ai2)>abs(a[jj+1]-ai2):
        jj=jj+1
if jj-1>=0:
    if abs(a[jj]-ai2)>abs(a[jj-1]-ai2):
        jj=jj-1
    
if jj==n-1:
    jj=jj-1
    
aj=a[jj]

print(ai,aj)



Measured memory_bytes: 20136
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int ans;
  if(n % 2 == 0) {
    ans = n;
  } else {
    ans = n * 2;
  }
  cout << ans << endl;

  return 0;
}


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

int main(void){
    int n;
    cin >> n;
    vector<int> l(n+1),r(n+1);
    for(int i=1;i<=n;i++){
        int a,b;
        cin >> a >>b;
        l[i]=a,r[i]=b;
    }
    sort(l.rbegin(),l.rend());
    sort(r.begin(),r.end());
    ll ans=0;
    for(int i=0;i<=n;i++){
        if(l[i]>r[i]){
            ans+=2*(l[i]-r[i]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
n = getN()

works = []
for i in range(n):
    works.append(getList())

works.sort(key=lambda x: x[1])

ans = "Yes"
tmp = 0
for w in works:
    tmp += w[0]
    # print(tmp,w[0], w[1])
    if tmp > w[1]:
        ans = "No"

print(ans)
# print(works)

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  int ans = 0;
  rep(i,n) {
    if (p.at(i) != i + 1) ans++;
  }
  if (ans <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;

void main() {
  const tmp = readln.split.to!(int[]);
  const N = tmp[0];
  const X = tmp[1];
  const Ls = readln.split.to!(int[]);
  
  int p = 0;
  int cnt;
  foreach (i; 0..N+1) {
    if (p > X) break;
    p += Ls[i];
    cnt++;
  }
  writeln(cnt);
}


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

constexpr int inf = 1e9;

int main() {
    int n; cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0; i < n - 1; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int k, rt; cin >> k;
    vector<int> mini(n, -inf), maxi(n, inf);
    for(int i = 0; i < k; ++i) {
        cin >> rt;
        rt--;
        cin >> mini[rt];
        maxi[rt] = mini[rt];
    }

    function<void(int, int)> calc_range = [&] (int v, int p) {
        for(auto const to : g[v]) {
            if(to == p) continue;
            calc_range(to, v);
            mini[v] = max(mini[v], mini[to] - 1);
            maxi[v] = min(maxi[v], maxi[to] + 1);
        }
    };
    calc_range(rt, -1);
    vector<int> ans(n);
    function<bool(int, int, int)> solve = [&] (int v, int p, int prev_val) {
        int cur_val = inf;
        if(mini[v] <= prev_val + 1 && prev_val + 1 <= maxi[v]) {
            cur_val = prev_val + 1;
        }
        if(mini[v] <= prev_val - 1 && prev_val - 1 <= maxi[v]) {
            cur_val = prev_val - 1;
        }

        if(cur_val == inf) return false;
        ans[v] = cur_val;
        bool res = true;
        for(auto const to : g[v]) {
            if(to == p) continue;
            res &= solve(to, v, cur_val);
        }
        return res;
    };

    if(!solve(rt, -1, mini[rt] + 1)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        for(auto const& v : ans) {
            cout << v << endl;
        }
    }
}


Measured memory_bytes: 16896
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll x = 0;
int func(ll m)
{
	if (x > ((m * (m+1)) /2))
		return 1;
	if (x <= (((m-1) * m) / 2))
		return -1;
	return 0;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> x;
	ll l, r, mid;
	l = 0;
	r = x;
	while(l <= r)
	{
		mid = (l+r)/2;
		if(func(mid) == 0)
		{
			break;
		}
		else if (func(mid) == 1)
		{
			l = mid + 1;
		}
		else
		{
			r = mid - 1;
		}
	}
	cout << mid << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
build, floors, rooms = (4, 3, 10)

buildings = [[[0 for i in range(rooms)] for j in range(floors)] for k in range(build)]


for k in range(n):
    b, f, r, v = map(int, input().split())

    buildings[b-1][f-1][r-1] = buildings[b-1][f-1][r-1] + v


for n in buildings[0]:
    print("", *n, sep=" ")
print("#" * 20)
for o in buildings[1]:
    print("", *o, sep=" ")
print("#" * 20)
for p in buildings[2]:
    print("", *p, sep=" ")
print("#" * 20)
for q in buildings[3]:
    print("", *q, sep=" ")



Measured memory_bytes: 5624
#include<iostream>
#include<vector>
#include<string>
#include<cmath>

int main(){
    int N, T, A;
    std::cin >> N >> T >> A;
    int optInd = 0;
    double diff = 10000000.0;
    for(int i = 0; i < N; i++){
        int h;
        std::cin >> h;
        double temp = T - h * 0.006;
        if(std::fabs(temp - A) < diff){
            diff = std::fabs(temp - A);
            optInd = i + 1; // to 1 origin
        }
    }

    std::cout << optInd << std::endl;
    return 0;
}


Measured memory_bytes: 256
// ABC137A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
	int A, B;
	cin >> A >> B;
	int plus = A + B;
	int minus = A - B;
	int multiply = A * B;
	int ans = plus;
	ans = max(ans, minus);
	ans = max(ans, multiply);

	cout << ans << endl;
}

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

for o in range(N):
    A[o] -= (o + 1)

A.sort()

b = A[len(A) // 2]
c = A[len(A) // 2 - 1]

tmp1, tmp2 = 0, 0

for a in A:
    tmp1 += abs(a - b)
    tmp2 += abs(a - c)

print(min(tmp1, tmp2))


Measured memory_bytes: 26128
X,Y,N=map(int,input().split())
max_X=X
max_Y=Y
current_min_x=0
current_min_y=0
current_max_x=X
current_max_y=Y
xy=[list(map(int,input().split())) for _ in range(N)]
for x,y,a in xy:
  n=0
  if a==1:
    current_min_x=max(current_min_x, x)
  elif a==2:
    current_max_x=min(current_max_x, x)
  elif a==3:
    current_min_y=max(current_min_y, y)
  elif a==4:
    current_max_y=min(current_max_y, y)
result=(current_max_x-current_min_x)*(current_max_y-current_min_y)
print(max(current_max_x-current_min_x,0)*max(current_max_y-current_min_y,0))

Measured memory_bytes: 9224
#include <iostream>
#include <cmath>
typedef long long ll;
using namespace std;

const ll MOD = 1e9+7;

bool isPrime(int n) {
    if(n==1) return false;
    else if(n==2) return true;
    else if(n%2==0) return false;

    int m = sqrt(n)+1;
    for(int i=3; i<=m; i+=2) if(n%i==0) return false;
    return true;
}

int main() {
    int n;
    cin >> n;
    ll ans=1;
    for(int i=2; i<=n; i++) {
        int cnt=0;
        for(int j=1; j<=n; j++) {
            if(i>j) continue;
            if(!isPrime(i)) continue;
            int a=i, b=j;
            while(b%a==0) {
                b/=a;
                cnt++;
            }
        }
        ans = (ans*(cnt+1))%MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            long ans = 0;
            ArrayList<Integer> a = new ArrayList<>();
            ArrayList<Integer> diff = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                a.add(in.nextInt());
            }
            Collections.sort(a);
            for (int i = 1; i < m; i++) {
                diff.add(a.get(i) - a.get(i - 1));
            }
            Collections.sort(diff);
            for (int i = 0; i < m && i < m - n; i++) {
                ans += diff.get(i);
            }
            out.println(ans);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 42920
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;





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

    string s;
    cin >> s;
    int n = s.length()-1;
    ll ans = 0;
    ll tmp = 0;
    ll res = 0;
    rep(i,1<<n){
        tmp = 0;
        rep(j,s.length()){
            if(j){
                if(i>>j-1&1){
                    tmp += ans;
                    ans = 0;
                    ans += (s[j]-'0');
                }else{
                    ans = ans*10+(s[j]-'0');
                }
            }else{
                ans += (s[j]-'0');
            }
        }
        ans += tmp;
        res += ans;
        ans = 0;
    }
    cout << res << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int r,d,x;
    cin >> r >> d >> x;
    rep(i,10)
    {
        x=x*r-d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
p_array = gets.chomp.split(' ').map(&:to_i)
a_array = (1..n).to_a

cnt = 0
0.upto(n - 1) do |i|
  cnt += 1 if p_array[i] != a_array[i]
end

if cnt <= 2
  puts 'YES'
else
  puts 'NO'
end


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

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
  ll N = inputValue();
  ll ans = N * (N-1) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#pragma GCC optimize("inline")
#pragma once
#include<bits/stdc++.h>
#define q register
typedef long long ll;
using namespace std;
string s;
ll tag1,tag2,tot;
bool ans;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    for(q ll i=0;i<s.length();i++){
        if((s[i]=='C')&&(!ans)){
            tot=tag1=i;
			ans=true;  
        }
        if(s[i]=='F'){
            tag2=i;   
            if(ans){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <set>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n;
vector<int> v(100002,0);

int main(void){
    cin >> n;
    REP(i,n){
        int a;
        cin >> a;
        v[a]++;
        v[a+1]++;
        v[a+2]++;
    }
    int res = 0;
    REP(i,v.size()){
        res = max(v[i],res);
    }
    //put(mp.size());
    put(res);
    return 0;
}


Measured memory_bytes: 640
def dfs(s, n):
    if int(s) > n:
        return 0
    if all(s.count(c) > 0 for c in '753'):
        result = 1
    else:
        result = 0
    for c in '753':
        result += dfs(s + c, n)

    return result


def main():
    n = int(input())
    print(dfs('0', n))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9120
#include <iomanip>
#include <iostream>
#include <cmath>

using namespace std;

int main(){
	int n;
	cout << fixed << setprecision(5);
	while(cin >> n && n){
		double input, sum = 0.0, sum2 = 0.0;
		for(int i = 0; i < n; i++){
			cin >> input;
			sum += input;
			sum2 += input*input;
		}
		double mean = sum/n;
		cout << sqrt(sum2/n - mean*mean) << endl;
	}
	return 0;
}

Measured memory_bytes: 3264
#include<iostream>
using namespace std;

void insertSort(int A[100],int N){
  int j,key;


  for(int k=0;k<N-1;k++)cout<<A[k]<<' ';
  cout<<A[N-1]<<endl;

  for(int i=1;i<N;i++){
   key=A[i];
    j=i-1;
    while(j>=0 && A[j]>key){
      A[j+1]=A[j];
      j--;}
    A[j+1]=key;
    for(int k=0;k<N-1;k++)cout<<A[k]<<' ';
    cout<<A[N-1]<<endl;}
}

int main(){
  int N,A[100];
  cin>>N;
  for(int i=0;i<N;i++)cin>>A[i];
  insertSort(A,N);
}

Measured memory_bytes: 1160
#include <string.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define ll long long
#define inf 0x3f3f3f3f
#define ms(x,a) memset(x,a,sizeof(x))
#define sd(x) scanf("%d",&x)
#define sdd(x,y) scanf("%d%d",&x,&y)
#define sddd(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld%lld",&x,&y)
#define slll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define sf(x) scanf("%lf",&x)
#define sff(x,y) scanf("%lf%lf",&x,&y)
#define sfff(x,y,z) scanf("%lf%lf%lf",&x,&y,&z)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define repp(i,n,a) for(int i=n;i>=a;i--)
#define pd(x) printf("%d\n",x)
#define pdd(x,y) printf("%d%d\n",x,y)
#define pddd(x,y,z) printf("%d%d%d\n",x,y,z)
#define pl(x) printf("%lld\n",x)
#define pll(x,y) printf("%lld%lld\n",x,y)
#define plll(x,y,z) printf("%lld%lld%lld\n",x,y,z)
#define debug() printf("***\n")
using namespace std;
const int maxn=1e5+10;
int n,m;
int a[maxn];
int main() {
	while(sd(n)!=EOF) {
		rep(i,1,n){
			sd(a[i]);
		}
		int flag=0;
		a[1]--;
		rep(i,2,n-1){
			if(a[i]-1<=a[i+1]&&a[i]-1>=a[i-1])a[i]--;
		}
		rep(i,2,n){
			if(a[i]<a[i-1])flag=1;
		}
		if(flag)printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}



Measured memory_bytes: 640
n, k = map(int, input().split())
*h, = map(int, input().split())

dp = [float("inf")]*n
dp[0] = 0

for i in range(1, n):
    if i == 1:
        dp[1] = dp[0] + abs(h[0]-h[1])
        continue

    dp[i] = min([dp[i-j] + abs(h[i-j]-h[i]) for j in range(1, k+1)])

print(dp[n-1])


Measured memory_bytes: 58336
for i in range(3000):
    k=input().split()
    a=int(k[0])
    b=int(k[1])
    if a==0 and b==0:
        break
    else:
        if a<b:
            print(str(a)+" "+str(b))
        else:
            print(str(b)+" "+str(a))


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

int main()
{
    long long int flag = 0,i;
    char s[13],t[13];
    cin>>s;
    cin>>t;
    for(i=0;i<3;i++)
    {
        if(s[i]==t[i])
        {
            flag++;
        }
    }
    cout<<flag<<endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
k = 1
yes_n = (k * (k+1)) // 2
flag = False
while N >= yes_n:
    if N == yes_n:
        flag = True
        break
    k += 1
    yes_n = (k * (k+1)) // 2
if flag:
    ans = []
    max_n = 1
    for i in range(k+1):
        tmp = []
        for j in range(i):
            tmp += [ans[j][i-1]]
        for j in range(k-i):
            tmp += [str(max_n)]
            max_n += 1
        ans += [tmp]
    print('Yes')
    print(k+1)
    for a in ans:
        print(k, ' '.join(a))
else:
    print('No')

Measured memory_bytes: 78224