akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define ll long long
#define M 100000007
#define fr first
#define sc second
#define endl "\n"
#define vc vector
#define pb push_back
#define pii pair<ll, ll>
#define psi pair<string, ll>
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI 3.14159265
#define r0 return 0
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const char char_max = (char)(((unsigned char) char(-1)) / 2);

int main() {
  fast
    ll n,m;
    cin>>n>>m;
    ll a,sum=0;
    rep(i,0,m) {
        cin>>a;
        sum+=a;
    }
    sum=n-sum;
    if(sum>=0) cout<<sum;
    else cout<<"-1";
}



Measured memory_bytes: 3660
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

cnt = 0

for i in 0..a do
  for j in 0..b do
    for k in 0..c do
      if x == 500 * i + 100 * j + 50 * k
        cnt += 1
      end
    end
  end
end

puts cnt


Measured memory_bytes: 1788
#include <stdio.h>
int main(void){
  int n,m;
  m = 0;
  scanf("%d %d",&n,&m);
  int K[n];
  int A[n][m];
  int count[m];
  int i,j;
  for(i = 0; i < m; i++){
    count[i]=0;
  }
  int c = 0;
  for(i = 0; i < n; i++){
    scanf("%d",&K[i]);
    for(j = 0; j <K[i]; j++){
      scanf("%d",&A[i][j]);
      //printf("%d a %d %d\n",A[i][j],i,K[i]);
      count[A[i][j]-1]++;
    }
    //printf("\n");
  }
  for(i = 0; i < m; i++){
    if(n ==count[i])c++;
  }
  printf("%d",c);
}


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

using ll=long long;
const ll MOD=1e9+7;
deque<int> hoge;
deque<int> piyo;
void decode(ll x){
    hoge.clear();
    int cnt=0;
    while(x){
        if(x&1){
            hoge.push_back(cnt+1);
            cnt=0;
        }
        else{
            cnt++;
        }
        x>>=1;
    }
}
ll encode(const deque<int> &x){
    ll res=0;
    for(int i=x.size()-1;i>=0;i--){
        res<<=(x[i]);
        res+=(1<<(x[i]-1));
    }
    return res;
}
const int SIZE=1e5*2;
int x,y,z;
bool isXYZ(deque<int> &v){
        piyo.clear();
        int sum=0;
        for(int i=v.size()-1;i>=-1;i--){
            if(i==-1 || v[i]+sum>x+y+z){
                for(int j=0;j<=i;j++) piyo.push_front(v.front()),v.pop_front();
                break;
            }
            else sum+=v[i];
        }
        if(sum==x+y+z){
            sum=0;
            int st=0;
            for(int i=0;i<v.size();i++){
                sum+=v[i];
                if(sum==x) st++;
                else if(sum==x+y) st++;
                else if(sum==x+y+z) st++;
            }
            if(st==3) return true;
        }
        return false;
    };
int main(){
    int n;
    cin>>n;
    
    cin>>x>>y>>z;
    vector<vector<ll>> dp(n+1,vector<ll>(SIZE));
    dp[0][0]=1;
    ll res=0;
    vector<ll> tenp(n+1);
    tenp[0]=1;
    for(int i=0;i<n;i++) tenp[i+1]=(tenp[i]*10)%MOD;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<SIZE;j++){
            if(!dp[i][j]) continue;
            decode(j);
            deque<int>& v=hoge;
            ll pat=dp[i][j];
            auto& tmp=v;
            for(int j=1;j<=7;j++){
                tmp.push_back(j);
                if(isXYZ(tmp)){
                    res+=tenp[n-1-i]*pat;
                    res%=MOD;
                }
                else{
                    int tmptmp=encode(tmp);
                    dp[i+1][tmptmp]+=pat;
                    dp[i+1][tmptmp]%=MOD;
                }   
                for(auto &e:piyo) tmp.push_front(e);
                tmp.pop_back();
            }
            dp[i+1][0]+=dp[i][j]*3;
            dp[i+1][0]%=MOD;
        }       
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 65920
import java.util.Scanner;

public class Main {

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

		if ("ABC".equals(n)) {
			System.out.println("ARC");
		} else if ("ARC".equals(n)){
			System.out.println("ABC");
		}
		sc.close();
	}

}


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int k, n;
  cin >> k >> n;
  int nums[n];
  for(int i = 0; i < n; ++i) {
    cin >> nums[i];
  }
  int min_dis = LLONG_MAX;
  for(int i = 0; i < n; ++i) {
    if(i == 0) {
      min_dis = min(min_dis, nums[n-1] - nums[i]);
    } else {
      min_dis = min(min_dis, nums[i-1]+k - nums[i]);
    }
  }
  cout << min_dis;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
  int a,b;
  scanf("%d%d",&a,&b);
  if(2*b>=a){
    printf("%d",0);
    return 0;
  }
  else
  printf("%d",a-2*b);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<list>
using namespace std;
int A[200005];
list<int>::iterator it;
list<int>::reverse_iterator iq;

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++)	{
    	cin >> A[i];
	}
	list<int> c(1,A[0]);
	for(int i=2;i<=n;i++){
		if(i%2==0) c.push_back(A[i-1]);
		else c.push_front(A[i-1]);	
	} 
	if(n%2!=0) {
	   for(it=c.begin();it!=c.end();it++){
			cout << *it<<" ";
		}
	}
	else {
		for(iq=c.rbegin();iq!=c.rend();iq++){
		cout << *iq<<" ";
		}
	}
	return 0;	
}

Measured memory_bytes: 9344
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in insert
#define sz(v) v.size()
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 5;
void solve(){
    int n; cin>>n;
    vi v(n);
    int sum1=0;
    for(int i = 0; i < n; i++){
        cin>>v[i];
        sum1+=v[i];
    }
    sum1-=v[0];
    int sum2=v[0];
    int ans=abs(sum1-sum2);
    for(int i = 1; i < n; i++){
        sum1-=v[i];
        sum2+=v[i];
        mina(ans,abs(sum1-sum2));
    }
    cout<<ans;
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a >= 13) {
        cout << b << endl;
    }
    else if (a <= 5) {
        cout << 0 << endl;
    }
    else {
        cout << b / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

vl pow_;
void pow_ini(ll n) {
	pow_.push_back(n);
	rep(j, 62) {
		ll nxt = pow_[j] * pow_[j];
		nxt %= mod;
		pow_.push_back(nxt);
	}
	return;
}

ll pow1(ll k) {
	ll ans = 1;
	rep(ntmp, 62) {
		if ((k >> ntmp) % 2 == 1) {
			ans *= pow_[ntmp];
			ans %= mod;
		}
	}
	return ans;
}

vl fact;
vl fact_inv;

void fact_ini(ll n) {
	fact.push_back(1);
	fact.push_back(1);
	for (ll i = 2; i <= n; i++) {
		ll fact_tmp = fact[i - 1] * i;
		fact_tmp %= mod;
		fact.push_back(fact_tmp);
	}
	fact_inv.resize(n + 1);
	pow_ini(fact[n]);
	fact_inv[n] = pow1(mod - 2);
	for (ll i = n - 1; i >= 0; i--) {
		fact_inv[i] = fact_inv[i + 1] * (i + 1);
		fact_inv[i] %= mod;
	}
}

ll nCm(ll n, ll m) {
	if (fact.size() <= n)
		assert(false);
	if (fact.size() <= m)
		assert(false);
	ll ans = fact[n] * fact_inv[m];
	ans %= mod;
	ans *= fact_inv[n - m];
	ans %= mod;
	return ans;
}

int main() {
	fact_ini(1100000);
	ll N, K;
	cin >> N >> K;

	ll ans = 0;
	K = min(K, N - 1);
	rep(i, K + 1) {
		ll anstmp = nCm(N, i); // empty room
		ll R = N - i;
		anstmp *= nCm(R + i - 1, i);
		anstmp %= mod;
		ans += anstmp;
		ans %= mod;
	}

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

Measured memory_bytes: 19556
import collections
N=int(input())
inarr=[[int(j) for j in input().split()] for i in range(N-1)]
nodes={}
if N == 1:
    print("First")
    exit()

for i,j in inarr:
    if not i in nodes: nodes[i] = [j]
    else: nodes[i].append(j)
    if not j in nodes: nodes[j] = [i]
    else: nodes[j].append(i)

visited = {1}
queue = collections.deque([[1, 0]])
while queue:
    i, d = queue.popleft()
    for node in nodes[i]:
        if not node in visited:
            visited.add(node)
            queue += [[node, d + 1]]

# print("i: {} d: {}".format(i,d))

visited = {i}
queue = collections.deque([[i, 0]])
while queue:
    i, d = queue.popleft()
    for node in nodes[i]:
        if not node in visited:
            visited.add(node)
            queue += [[node, d + 1]]

# print(list(map(str,nodes.values())))
# print("i: {} d: {}".format(i,d))
print('Second' if (d + 1) % 3 == 2 else 'First')


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

using namespace std;

typedef long long ll;

bool notprime[100000 + 501];

int main() {
	notprime[1] = true;
	for (int i = 2; i * i <= 100500; i++) {
		if (!notprime[i]) {
			for (int j = i * 2; j <= 100500; j += i) {
				notprime[j] = true;
			}
		}
	}

	int X;
	cin >> X;

	for (int i = X;; i++) {
		if (!notprime[i]) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 384
N,K,Q = map(int,input().split())
num_list = [0]*N
for i in range(Q):
  j = int(input())
  num_list[j-1]+=1
  
for i in range(N):
  if K-Q+num_list[i]>0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 9912
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

int main(){
  int N,X;
  std::cin >> N >> X;
  std::vector<int> m;
  int temp;
  for(int i=0;i<N;i++){
    std::cin >> temp;
    m.push_back(temp);
  }

  int count=0;
  for(int i=0;i<N;i++){
    X -= m[i];
    count++;
  }
  auto min = std::min_element(m.begin(),m.end());
  while(X >= *min){
    X -= *min;
    count++;
  }
  std::cout << count << std::endl;
  return 0;
}
  
     


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll f[N];
int n,a[N],u,v,i;
vector<int>e[N];
void dfs(int u,int fa){
	if(e[u].size()==1){f[u]=a[u];return;}
	ll su=0,mn,z,y=0;
	for(int v:e[u])if(v!=fa)dfs(v,u),su+=f[v],y=max(y,f[v]);
	if(su-y<y)mn=y,z=y*2-su;else mn=su+1>>1,z=su&1;
	if(a[u]<mn || a[u]>su){
		puts("NO");
		exit(0);
	}
	f[u]=(a[u]-mn)*2+z;
}
int main(){
	scanf("%d",&n);for(i=1;i<=n;++i)scanf("%d",a+i);
	for(i=1;i<n;++i)scanf("%d%d",&u,&v),e[u].push_back(v),e[v].push_back(u);
	if(n==2)return puts(a[1]==a[2]?"YES":"NO"),0;
	for(i=1;e[i].size()==1;++i);dfs(i,0);puts(f[i]?"NO":"YES");
	return 0;
}

Measured memory_bytes: 13568
#include <iostream>
int main() {
	long long N, A[90] = {};
	std::cin >> N;
	A[0] = 2;
	A[1] = 1;
	for (int i = 2; i < N + 1; i++)
		A[i] = A[i - 1] + A[i - 2];
	std::cout << A[N] << std::endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x;
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

int main() {
	ll N, tempN, fN = 0;
	rd(N);
	tempN = N;
	while (1) {
		ll temp = tempN % 10;
		fN += temp;
		if (tempN == 0) break;
		tempN /= 10;
	}
	if (N%fN == 0) wrln("Yes");
	else wrln("No");
	return 0;
}

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

using namespace std;

typedef long long int ll;

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

  ll n, x;
  cin >> n >> x;
  if(x == 1 || x == 2 * n - 1){
    cout << "No" << endl;
  }else if(n == 2 && x == 2){
    cout << "Yes" << endl;
    cout << 1 << endl << 2 << endl << 3 << endl;
  }else{
    vector < ll > ans(2 * n - 1, 0);
    set < ll > s;
    for(int i = 1; i <= 2 * n - 1; i++) s.insert(i);
    if(x != 2){
      ans[n - 2] = x - 1;
      ans[n - 1] = x;
      ans[n] = x + 1;
      ans[n + 1] = x - 2;

      s.erase(x - 1);
      s.erase(x);
      s.erase(x + 1);
      s.erase(x - 2);
    }else{
      ans[n - 2] = 3;
      ans[n - 1] = 2;
      ans[n] = 1;
      ans[n + 1] = 4;

      s.erase(1);
      s.erase(2);
      s.erase(3);
      s.erase(4);
    }

    cout << "Yes" << endl;
    for(int i = 0; i < 2 * n - 1; i++){
      if(ans[i] == 0){
        ans[i] = *s.begin();
        s.erase(s.begin());
      }
      cout << ans[i] << endl;
    }
  }
}


Measured memory_bytes: 12444
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define vpi vector<pair<int,int> > 
#define vpll vector<pair<lli,lli> > 
#define vvi vector<vector<int> >
#define vvll vector<vector<lli> >
#define maxn 500005
#define mod 1000000007
#define inf 10000000000000000



int main()
{
    fastio;
    int n,k;
    cin>>n>>k;
    vi p(n),c(n);
    for(int i=0;i<n;i++)
    cin>>p[i],p[i]--;
    for(int i=0;i<n;i++)
    cin>>c[i];
    bitset<5001> fr;
    lli ans=-1e15;
    for(int i=0;i<n;i++)
    {
        int st=p[i];
        vi cur;cur.pb(st);
        while(st!=i)
        {
            st=p[st];
            cur.pb(st);
        }
        int n1=cur.size();
        lli tot=0,pm=-1e15,pm2=-1e15;
        lli num=k/n1;
        lli rem=k%n1;
        for(int i=0;i<n1;i++)
        {
            if(i<k) tot+=c[cur[i]],ans=max(ans,tot),pm=max(pm,tot);
            if(i<rem) pm2=max(pm2,tot);
        }
        if(num!=0)
        ans=max(ans,num*tot+max(pm2,0ll));
        if(num>=1)
        ans=max(ans,(num-1)*tot+pm);
    }
    cout<<ans<<"\n";
    return 0;
}

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

const int INF = 2e9;

int m, n;
int p[10010];
int c[510], e[510];
int dp[510][10010];
int ans = 0;
int main()
{
  scanf("%d%d", &m, &n);
  for(int i = 1; i <= m; i++)
    scanf("%d", &p[i]);
  
  for(int i = 1; i <= n; i++)
    scanf("%d%d", &c[i], &e[i]);

  sort(p + 1, p + m + 1, greater<int>());
  for(int i = 2; i <= m; i++)
    p[i] += p[i - 1];
  
  for(int i = 0; i <= n; i++)
    for(int j = 0; j <= m; j++)
      dp[i][j] = INF;
  dp[0][0] = 0;

  for(int i = 0; i < n; i++)
    for(int j = 0; j <= m; j++){
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      dp[i + 1][min(j + c[i + 1], m)] = min(dp[i + 1][min(j + c[i + 1], m)], dp[i][j] + e[i + 1]);
    }
  
  for(int i = 0; i <= m; i++)
    ans = max(ans, p[i] - dp[n][i]);
  
  /*
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= m; j++)
      if(dp[i][j] == INF)
	printf("  INF ");
      else
	printf("%5d ", dp[i][j]);
    cout << endl;
  }
  */

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

Measured memory_bytes: 20840
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
	int n, m, l;
	cin >> n >> m >> l;
	vector<vector<int>> a(n, vector<int>(m)), b(m, vector<int>(l));

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < l; ++j) {
			cin >> b[i][j];
		}
	}

	for (int i = 0; i < n; ++i) {
		string ans = "";
		for (int j = 0; j < l; ++j) {
			int sum = 0;
			for (int k = 0; k < m; ++k) {
				sum += a[i][k] * b[k][j];
			}
			ans += to_string(sum) + " ";
		}
		ans.pop_back();
		cout << ans << endl;
	}
}



Measured memory_bytes: 3404
n, t = map(int, input().split())
list_T = list(map(int, input().split()))

list_T.sort()
ans = t

for i in range(1, n):
    if list_T[i] - list_T[i-1] >= t:
        ans += t
    else:
        ans += list_T[i] - list_T[i-1]

print(ans)

Measured memory_bytes: 26836
class UnionFindNode(object):
    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1

    def __str__(self):
        template = "UnionFindNode(group_id: {}, \n\tparent: {}, value: {}, size: {})"
        return template.format(self.group_id_, self.parent_, self.value, self.rank_)

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                unite_root.parent_ = root
                root.rank_ = max(root.rank_, unite_root.rank_ + 1)
            else:
                root.parent_ = unite_root
                unite_root.rank_ = max(root.rank_ + 1, unite_root.rank_)

def main():
    N, M = [int(n) for n in input().split()]
    node_list = [UnionFindNode(i) for i in range(N)]
    for i in range(M):
        X, Y, Z = [int(n) for n in input().split()]
        node_list[X-1].unite(node_list[Y-1])
    gs = set()
    for node in node_list:
        gid = node.find()
        gs.add(gid)
    print(len(gs))
main()

Measured memory_bytes: 39148
#include<bits/stdc++.h>
using namespace std;
#define forn for(int i=0;i<n;i++)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
vector<bool> taken;
int score[(int)1e6];
bool cmp(int a,int b)
{
	return score[a]>score[b];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    int ans=0;
    while(n>0)
    {
    	ans++;
    	n/=k;
	}
	cout<<ans;
}
 


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
const int N_max=51;
const int M_max=N_max*(N_max-1);
vector<int> v[51];
bool isVisited[N_max];
void initialize(){
    REP(i,N_max){
        isVisited[i]=false;
    }
}
void dfs(int v_now){
    isVisited[v_now]=true;
    for(int i:v[v_now]){
        if(!isVisited[i]){
            dfs(i);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    vector<int> A;
    int temp;
    int count;count=0;
    REP(i,N){
        cin>>temp;
        A.push_back(temp);
        if(temp!=(i+1)){
            count++;
        }
    }
    if(count==2){
        print("YES");
    }else if(count==0){
        print("YES");
    }else{
        print("NO");
        
    }
    return 0;
}

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

using namespace std;

int main(){
    int N;
    while(cin >> N && N){
        if(N % 3 == 0) N /= 3;
        double th1 = 2.0 * M_PI / (6.0 * N);
        double th2 = M_PI / 6;
        double r = 1.0 / sqrt(3.0);
        double S = r * r * sin(th1) * sin(th2) / (2.0 * sin(th1 + th2)) * 6 * N;
        printf("%.12f\n", S);
    }
    return 0;
}

Measured memory_bytes: 1212
/*This is the solution from Ling2Feng1, no matter AC or not.*/
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cstdio>
#include<string>
#include<vector>
#include<math.h>
#include<time.h>
#include<utility>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<stdio.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
//#include<conio.h>
//ios::sync_with_stdio(false);
using namespace std;
string s;
int main(){
	cin>>s;
	for(int i=0;i<s.size()-8;i++) cout<<s[i];
	cout<<endl;
	return 0; 
}

Measured memory_bytes: 256
n,k = gets.chomp.split(" ").map(&:to_i)

sum = 0
w = Array.new
n.times { |i|
	w[i] = gets.chomp.to_i
	sum += w[i]
}
max_size = w.max

min = nil
if k == 1
	min = sum
elsif n == k
	min = max_size
else
	left = max_size
	right = sum
	
	while left <= right
		mid = ((left + right) / 2).to_i
		
		truck = 0
		cnt = 0
		w.each { |i|
			if truck + i <= mid
				truck += i
			else
				cnt += 1
				truck = i
				if cnt >= k
					break
				end
			end
		}
		
		if cnt >= k
			left = mid + 1
		else
			right = mid - 1
			min = mid
		end
	end
end

puts min

Measured memory_bytes: 9696
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
int ans=0;
rep(i,4){
    switch(s[i]){
        case '+':
            ans++;
            break;
        case '-':
            ans--;
            break;
        default:
            break;
    }
}
cout<<ans<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

int main(){
	ll n=read(),d=read();
	if(d==1){
		cout<<n*(n-1)/2<<endl;
	}else{
		cout<<d+(n-d-1)*(n-d-2)/2+(n-d-1)*(3)<<endl;
	}
}

Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;

int main(){
	ll n; cin >> n;
	ll w[101]; 
	rep(i, 0, n)cin >> w[i];

	ll minV = 1 << 20;
	rep(t, 0, n) {
		ll s1 = 0;
		ll s2 = 0;
		rep(j, 0, n) {
			if (t <= j) {
				s1 += w[j];
			}
			else {
				s2 += w[j];
			}
		}
		minV = min(abs(s1 - s2), minV);
	}
	cout << minV << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

ll n,m;
#define N (ll)2E5
vector<ll>e[N];
ll dp[N];

ll path(ll pos){
    if(dp[pos]!=-1)return dp[pos];
    if(e[pos].size()==0)return 0;
    ll m=0;
    for(auto x:e[pos]){
        Max(&m,path(x));
    }
    return dp[pos]=m+1;
}
void print(){
    rep(i,0,n-1)cout<<dp[i]<<" ";cout<<endl;
}

int main(){
    cin>>n>>m;
    while(m--){
        ll a,b;cin>>a>>b;
        a--;b--;
        e[a].pb(b);
    }
    memset(dp,-1,sizeof(dp));
    //print();
    ll ans=0;
    rep(i,0,n-1)Max(&ans,path(i));
    //print();
    cout<<ans<<endl;
    return 0;
}






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

map<ll, ll> dp;

ll N;
ll A, B, C, D;

ll rec(ll x)
{
	if(x == 0) return 0;
	if(x == 1) return D;
	if(dp.count(x)) return dp[x];
	ll l2 = (x/2)*2, r2=(x+1)/2*2;
	ll l3 = (x/3)*3, r3=(x+2)/3*3;
	ll l5 = (x/5)*5, r5=(x+4)/5*5;
	
	ll res = 1e18;
	if(x < res/D) res = x*D;
	res = min(res, llabs(l2-x)*D+A+rec(l2/2));
	res = min(res, llabs(r2-x)*D+A+rec(r2/2));
	
	res = min(res, llabs(l3-x)*D+B+rec(l3/3));
	res = min(res, llabs(r3-x)*D+B+rec(r3/3));
	
	res = min(res, llabs(l5-x)*D+C+rec(l5/5));
	res = min(res, llabs(r5-x)*D+C+rec(r5/5));
	
	return dp[x] = res;
}

void solve()
{
	dp.clear();
	cout << rec(N) << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
	int t; cin >> t;
	while(t--){
		cin >> N >> A >> B >> C >> D;
		solve();
	}
	return 0;
}

Measured memory_bytes: 4484
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
typedef long long LL;
const int N=200001;
int n,p[N],fa[N],w[N],s1[N],s0[N];LL ans;
int ask(int x){return fa[x]==x?x:fa[x]=ask(fa[x]);}
struct xint{int s1,s0,id;};
bool operator <(xint a,xint b){
	LL _a=(LL)a.s1*b.s0,_b=(LL)b.s1*a.s0;
	return _a<_b||_a==_b&&a.id<b.id;
}
set<xint> S;
int main(){
	scanf("%d",&n);
	ref(i,2,n)scanf("%d",&p[i]);
	ref(i,1,n)scanf("%d",&w[i]),fa[i]=i;
	ref(i,1,n)s1[i]=w[i],s0[i]=!w[i],S.insert((xint){s1[i],s0[i],i});
	ref(i,2,n){
		xint su=*S.upper_bound((xint){0,1,0});
		if(su.id==1)su=*S.upper_bound(su);
		int u=su.id,v=ask(p[u]);
		xint sv=(xint){s1[v],s0[v],v};
		S.erase(su),S.erase(sv);
		ans+=(LL)s1[v]*s0[u];
		fa[u]=v;s1[v]+=s1[u],s0[v]+=s0[u];
		S.insert((xint){s1[v],s0[v],v});
	}
	cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

const int N = 200005;

int h[N], b[N]; ll tree[3 * N];

void update(int p, int l, int r, int i, ll v) {
  if (i > r || i < l) return;
  if (l >= i && r <= i) {
    tree[p] += v;
    //cout << "P: " << p << " " << tree[p] << endl;
    return;
  }
  int m = (l + r) >> 1;
  update(p * 2, l, m, i, v);
  update(p * 2 + 1, m + 1, r, i, v);
  tree[p] = max(tree[p * 2], tree[p * 2 + 1]);
}

ll query(int p, int l, int r, int i, int j) {
  if (i > r || j < l) return 0;
  if (l >= i && r <= j) return tree[p];
  int m = (l + r) >> 1;
  return max(query(p * 2, l, m, i, j), query(p * 2 + 1, m + 1, r, i, j));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, mx = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    mx = max(mx, h[i]);
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  ll ans = 0;
  //cout << "MX: " << mx << endl;
  for (int i = 0; i < n; i++) {
    ll x = query(1, 1, mx, 1, h[i]);
    //cout << "POS: " << i << " " << "Query: " << x << endl;
    ans = max(ans, x + b[i]);
    update(1, 1, mx, h[i], x + b[i]);
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 6528
ans = ""
S = input()
reversed_S = ""
for i in reversed(range(len(S))):
    reversed_S += S[i]

if S == reversed_S:
    half_S = len(S)//2
    first_half_S = S[:half_S]
    reversed_f_S = ""
    for i in reversed(range(len(first_half_S))):
        reversed_f_S += first_half_S[i]

    second_half_S = S[half_S+1:]
    reversed_s_S = ""
    for i in reversed(range(len(second_half_S))):
        reversed_s_S += second_half_S[i]

    if first_half_S == reversed_f_S and second_half_S == reversed_s_S:
        ans = "Yes"
    else:
        ans = "No"
else:
    ans = "No"

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define tcn cin.tie(0);
#define tct cout.tie(0);
#define pb push_back
#define ll long long
#define fr first
#define se second
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long N = 2e3 + 7;
const ll mod = 1e6 + 7;
ll n , m , a , b , c ,d ;
long double p = 3.141592653589793;
string s;
char ch;
vector<int>v ,v1;
map<int , int>mp;
int main()
{
    TIME tcn tct
    cin >> n;
    ll arr[n];
    for( int i = 1;i < n;i ++ ){
        cin >> a , mp[a] ++;
    }
    for( int i = 1;i < n;i ++ )
        cout << mp[i] << endl;
        cout << 0;
}


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

void Main()
{
    int n;
    cin >> n;
    long ans = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if(i>0){
            if(a[i-1] > a[i]){
                ans += a[i-1] - a[i];
                a[i] = a[i-1];
            }
        }
    }
    
    cout << ans << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


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

int main() {
  int p;
  cin >> p;
  if (p/1000 == p/100%10 || p/100%10 == p/10%10 || p/10%10 == p%10)
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
}


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

#define UP		(0)
#define DOWN	(1)

int main(void)
{
	int c;
	int N;
	int matrix[12][12];
	int x, y;
	int n;
	int direc;
	
	c = 1;
	while (1){
		scanf("%d", &N);
		if (N == 0){
			break;
		}
		
		memset(matrix, -1, sizeof(matrix));
		for (y = 1; y <= N; y++){
			for (x = 1; x <= N; x++){
				matrix[y][x] = 0;
			}
		}
		
		x = y = 1;
		n = 1;
		matrix[y][x] = n;
		direc = UP;
		while (n < N * N){
			if (direc == UP){
				if (matrix[y - 1][x + 1] == 0){
					x++;
					y--;
				}
				else {
					if (matrix[y][x + 1] == 0){
						x++;
					}
					else {
						y++;
					}
					direc = DOWN;
				}
			}
			else {
				if (matrix[y + 1][x - 1] == 0){
					x--;
					y++;
				}
				else {
					if (matrix[y + 1][x] == 0){
						y++;
					}
					else {
						x++;
					}
					direc = UP;
				}
			}
			matrix[y][x] = ++n;
//printf("(%d %x=%d)", x, y, n);
		};
		
		printf("Case %d:\n", c++);
		for (y = 1; y <= N; y++){
			for (x = 1; x <= N; x++){
				printf("%3d", matrix[y][x]);
			}
			printf("\n");
		}
		
	}
	
	return (0);
}

Measured memory_bytes: 616
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;

long long N, A[1 << 19], cnt[1 << 22];
long long ans;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= N; i++) {
		if (i - A[i] >= 0) ans += cnt[i - A[i]];
		if (i + A[i] <= 2000000) cnt[i + A[i]]++;
	}
	for (int i = 0; i <= 2000000; i++) cnt[i] = 0;
	for (int i = N; i >= 1; i--) {
		if (i + A[i] <= 2000000) ans += cnt[i + A[i]];
		if (i - A[i] >= 0) cnt[i - A[i]]++;
	}
	cout << ans / 2LL << endl;
	return 0;
}

Measured memory_bytes: 20716
/*************************************************************************
	> File Name: 1.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Blog: https://blog.csdn.net/Pig_cfbsl 
	> Created Time: 2020/5/2 20:44:09
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
char s[100];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	scanf("%s",s);
	if(s[1]=='R') s[1]='B';
	else s[1]='R';
	printf("%s",s);
	return 0;
}


Measured memory_bytes: 3724
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main() {

	char s[101];

	scanf("%s", s);

	int length = strlen(s);

	for(int i = 0; i < length; i++) {
		s[i] = 'x';
	}

	printf("%s", s);

	return 0;

}


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


int main (void){
        int N;
        long long int a,ans=0;
        scanf("%d",&N);
        for (int i = 0; i < N; i++) {
          scanf("%d",&a);
          ans=ans+a-1;
        }
        printf("%lld",ans);
        return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define	INF 100000000;
using namespace std;
int mp[1001][1001];
int d[1001][1001];
int n,m,s,g1,g2;


int main() {
 


  while(1) {
    cin >> n >> m >> s >> g1 >> g2;
    if(n==0&&m==0&&s==0&&g1==0&&g2==0)break;

    for(int i=0;i<=n;i++) 
      for(int j=0;j<=n;j++)
	if(i == j) mp[i][j] = 0;
	else mp[i][j] = INF;

    for(int i=0;i<m;i++) {
      int b1,b2,c;
      cin >> b1 >> b2 >> c;
      mp[b1][b2] = c;
    }
    for(int k=1;k<=n;k++)
      for(int i=1;i<=n;i++) 
	for(int j=1;j<=n;j++)
	  mp[i][j] = min(mp[i][j] ,mp[i][k]+mp[k][j]);

    long long  ans = INF;
    for(int i=1;i<=n;i++){
      int sum = 0;
      sum = mp[s][i];
      sum += mp[i][g1];
      sum += mp[i][g2];
	if(ans > sum) ans = sum;
    }
    cout << ans << endl;
    
  }
  
  
  return 0;
}

Measured memory_bytes: 5252
#include <stdio.h>

const int money[] = { 500, 100, 50, 10, 5, 1 };
const int size = sizeof( money ) / sizeof( int );

int main ( void )
{
	int x, i, answer = 0;

	while ( 1 ) {
		scanf( "%d", &x );
		if ( x == 0 ) {
			break;
		}

		x = 1000 - x;
		answer = 0;

		for ( i = 0; i < size; ++i ) {
			answer += x / money[i];
			x %= money[i];
		}

		printf( "%d\n", answer );
	}

	return 0;
}

Measured memory_bytes: 600
n = int(input())
w = list(map(int,input().split()))

ans = abs(sum(w))
s1 = 0
s2 = sum(w)
for i in range(n-1):
    s1 += w[i]
    s2 -= w[i]
    m = abs(s2-s1)
    if m <= ans :
        ans = m
print(ans)


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var X = input[0];
            var A = input[1];

            Console.WriteLine(X < A ? 0 : 10);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

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


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());

    combination c(1e5);
    mint ans;
    rep(ri,2) {
        rep(i,n) {
            mint now = c(i,k-1);
            if (ri == 1) now *= -1;
            ans += now*a[i];
        }
        reverse(a.begin(), a.end());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5112
from itertools import product, combinations
S = input()
N = len(S)

cum = 0
for pluses in product((0,1), repeat=N-1):
    sl = S[:]
    for i in range(N-1):
        if pluses[i] == 1:
            sl = sl[:-N+i+1] + '+' + sl[-N+i+1:]
    cum += sum(int(elm) for elm in sl.split('+'))

print(cum)


Measured memory_bytes: 3060
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
S = input()

prev = S[0]
i = 0
count = 0
run_length = []
if S[0] == '0':
    run_length.append(0)
while i < len(S):
    c = S[i]
    if c == prev:
        count += 1
    else:
        run_length.append(count) 
        count = 1
    prev = c
    i += 1
run_length.append(count) 

acc = [0] * (len(run_length) + 1)
acc[0] = 0

for i in range(len(acc) - 1):
    acc[i + 1] = acc[i] + run_length[i]

ans = 0
for i in range(0, len(acc), 2):
    j = 2 * K + 1
    x = 0
    if j + i >= len(acc):
        x = acc[-1] - acc[i]
    else:
        x = acc[j + i] - acc[i]
    ans = max(ans, x)

for i in range(0, len(run_length), 2):
    ans = max(ans, run_length[i])
print(ans)




Measured memory_bytes: 8256
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()
#define pri 1000000007
#define pr pair <ll,ll>

using namespace std;

void masterstroke(){
	
ll n,a;
cin>>n>>a;
ll x=3*n+a;
cout<<x/2<<endl;


	
}

int main() {
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)masterstroke();
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionA(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{
		int N = nextInt();
		char[] s = nextString().toCharArray();

		int rb=0;
		int rw=0;
		for(int i=0;i<N;i++) {
			if(s[i]=='#') {
				rb++;
			}else {
				rw++;
			}
		}

		int lb=0;
		int lw=0;
		int ans =Math.min(rb,rw);
		for(int i=0;i<N;i++) {
			if(s[i]=='.') {
				lw++;
				rw--;
			}else {
				lb++;
				rb--;
			}
			ans=Math.min(ans,lb+rw);
		}

		pw.println(ans);

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 27348
let () =
    let calc1 d c =
        let restv = Array.make 10 (-1) in
        let accv  = Array.make 10 (-1) in
        let rec loop v rest acc =
            if rest = 0 then v, acc else
                if restv.(v) >= 0 then (
                    let cycle = restv.(v) - rest in
                    let acyc  = acc - accv.(v) in
                    restv.(v) <- -1;
                    accv.(v) <- -1;
                    let count = rest / cycle in
                    let rest = rest - count * cycle in
                    let acc =  acc  + count * acyc in
                    loop v rest acc 
                ) else (
                    restv.(v) <- rest;
                    accv.(v) <- acc;
                    let v = v + d in
                    if v >= 10 then loop ((v / 10) + (v mod 10)) (rest - 1) (acc + 2) else
                                    loop v (rest - 1) (acc + 1)
                )
        in
        if c = 1 then d, 0 else
            let v = d * 2 in
            if v >= 10 then loop ((v / 10) + (v mod 10)) (c - 2) 2 else loop v (c - 2) 1 
    in
    let calc2 dc =
        let rec loop cur acc = function
            | [] -> acc
            | (v, s) :: tl ->
                    let v = v + cur in
                    if v >= 10 then loop ((v / 10) + (v mod 10)) (acc + s + 2) tl else loop v (acc + s + 1) tl
        in
        loop 0 (-1)dc
    in
    let main () =
        let m = int_of_string (read_line ()) in
        let dc = Array.init m (fun _ -> Scanf.sscanf (read_line ()) "%d %d" calc1) in
        let r = calc2 (Array.to_list dc) in
        Printf.printf "%d\n" r
    in
    main ()

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

unsigned long long int fact(unsigned long long int n)
{
	if(n==0)
		return 1;
	return n*fact(n-1);
}

int main()
{
	unsigned long long int n;
	while(cin >> n)
		cout << fact(n) << endl;
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{   int a,b,c;
    cin>>a>>b>>c;
    if(a+b<a+c&&a+b<b+c)
        cout<<a+b;
    else if(b+c<a+c)
        cout<<b+c;
    else cout<<a+c;
	return 0;
}



Measured memory_bytes: 3576
#include <stdio.h>
int main() {
	int n, h, m, c = 1;
	scanf("%d %d", &n, &h);
	m = h;
	while(--n) {
		scanf("%d", &h);
		if(h >= m) {
			c++;
			m = h;
		}
	}
	printf("%d", c);
	return 0;
}

Measured memory_bytes: 128
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define mp make_pair
#define ff first
#define ss second
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (ll)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()

using namespace std;

vector<vector<ll> > dp;
vector<vector<char> > arr;
int h,w;

ll fn(int i, int j)
{
	if(i==h-1 && j==w-1)
		return 1;
	else if(arr[i][j]=='#')
	{
		dp[i][j]=0;
		return 0;
	}
	else
	{
		if(dp[i][j]==-1)
			dp[i][j]=(fn(i,j+1)+fn(i+1,j))%mod;
		return dp[i][j]%mod;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h,w;
	cin>>h>>w;
	arr.resize(h,vector<char> (w));
	f(i,0,h)
	{
		f(j,0,w)
			cin>>arr[i][j];
	}
	f(i,0,h)
	{
		vector<ll> v(w,-1);
		dp.pb(v);
	}
	int l=-1;
	rf(i,h-1,0)
	{
		if(arr[i][w-1]!='#')
			dp[i][w-1]=1;
		else
		{
			l=i-1,dp[i][w-1]=0;
			break;
		}
	}
	rf(i,l,0)
		dp[i][w-1]=0;
	l=-1;
	rf(i,w-1,0)
	{
		if(arr[h-1][i]!='#')
			dp[h-1][i]=1;
		else
		{
			l=i-1,dp[h-1][i]=0;
			break;
		}
	}
	rf(i,l,0)
		dp[h-1][i]=0;
	dp[h-1][w-1]=1;
	cout<<fn(0,0)<<"\n";
}

Measured memory_bytes: 9216
# -*- coding: utf-8 -*-
"""
Greedy algorithms - Change Making
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_15_A&lang=jp

"""
import sys


def solve(n):
    ans = 0
    for c in (25, 10, 5, 1):
        q, r = divmod(n, c)
        ans += q
        n = r
    return ans


def main(args):
    n = int(input())
    ans = solve(n)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
int main()
{
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	printf("%6f",w*h/2);
	cout<<" ";
	if(x==w/2&&y==h/2) cout<<"1";
	else cout<<"0";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
long long int dp[100001][3];
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	long long int n,k,r,s,p;
	string t;
	long long int res = 0;
	
	cin >> n >> k;
	cin >> r >> s >> p;
	cin >> t;
 
	memset(dp,0,sizeof(dp));
 
	for(int i=1;i<=k;i++)
	{
		int j = i;
		if(t[i-1]=='r')
		{
			dp[i][2] = p;
		}
		else if(t[i-1]=='s')
		{
			dp[i][0] = r;
		}
		else
		{
			dp[i][1] = s;
		}
		j+=k;
		while(j<=n)
		{
			for(int x=0;x<3;x++)
			{
				if(t[j-1]=='r')
				{
					if(x==2)
					{
						dp[j][2] = max(dp[j][2],max(dp[j-k][0],dp[j-k][1])+p);
					}
					else
					{
						dp[j][0] = max(dp[j][0],max(dp[j-k][1],dp[j-k][2]));
						dp[j][1] = max(dp[j][1],max(dp[j-k][0],dp[j-k][2]));
					}
				}
				else if(t[j-1]=='s')
				{
					if(x==0)
					{
						dp[j][0] = max(dp[j][0],max(dp[j-k][1],dp[j-k][2])+r);
					}
					else
					{
						dp[j][1] = max(dp[j][1],max(dp[j-k][0],dp[j-k][2]));
						dp[j][2] = max(dp[j][2],max(dp[j-k][0],dp[j-k][1]));
					}
				}
				else
				{
					if(x==1)
					{
						dp[j][1] = max(dp[j][1],max(dp[j-k][0],dp[j-k][2])+s);
					}
					else
					{
						dp[j][0] = max(dp[j][0],max(dp[j-k][1],dp[j-k][2]));
						dp[j][2] = max(dp[j][2],max(dp[j-k][0],dp[j-k][1]));
					}
				}
			}
			j+=k;
		}
		//cout << j << '\n';
		res += max(dp[j-k][0],max(dp[j-k][1],dp[j-k][2]));
	}
 
	cout << res << '\n';
 
	return 0;
}

Measured memory_bytes: 2816