akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() { return numeric_limits<long long>::min(); }
ll mal() { return numeric_limits<long long>::max(); }

#define R3(i, a, b) for (long long i = (a); i < (b); ++i)
#define R2(i, b) for (long long i = 0; i < (b); ++i)
#define R1(b) for (long long i = 0; i < (b); ++i)
#define RR(i, a, b) for (long long i = a; i > b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

istringstream lcin;
void rl()
{
    string s;
    getline(cin, s);
    lcin = istringstream(s);
}
// build: ctrl + f9

// run: shift + f10
// debug: shift + f9
// sanitize: shift + f11

int main(int , char **)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    double R;
    cin >> R;
    double circ = 2.0*M_PI*R; 
    cout << fixed << setprecision(20) << circ << endl;
}

Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll q,i;
    string s;
    cin>>s;
    deque<char> dq;
    for(i=0;i<sz(s);i++) dq.push_back(s[i]);
    cin>>q;
    ll t,f;
    char c;
    int state = 1;
    while(q--)
    {
        cin>>t;
        if(t==1) state*=-1;
        else
        {
            cin>>f;
            cin>>c;
            if(state==1)
            {
                if(f==1) dq.push_front(c);
                else dq.push_back(c);
            }
            else
            {
                if(f==1) dq.push_back(c);
                else dq.push_front(c);
            }
        }
    }
    if(state == 1) 
    {
        for(i=0;i<sz(dq);i++) cout<<dq[i];
    }
    else
    {
        for(i=sz(dq)-1;i>=0;i--) cout<<dq[i];
    }
}

Measured memory_bytes: 976
import java.util.Scanner;

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

    void solve(Scanner sc) {
        char[] s = sc.next().toCharArray();
        
        char preC = s[0];
        int count = 0;
        for (char c : s) {
            if (c != preC) {
                count++;
            }
            preC = c;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 28196
#include <stdio.h>
#include <stdlib.h>

int get_num,fukuro_num;
int price[1000];

int qsort_comp(const void* x,const void* y) {
	int* a=(int*)x;
	int* b=(int*)y;
	if(*a<*b)return 1;
	if(*a>*b)return -1;
	return 0;
}

int main(void) {
	int i;
	int result;
	while(1) {
		scanf("%d%d",&get_num,&fukuro_num);
		if(get_num==0 && fukuro_num==0)break;
		for(i=0;i<get_num;i++)scanf("%d",&price[i]);
		qsort(price,get_num,sizeof(int),qsort_comp);
		for(i=0,result=0;i<get_num;i++) {
			if((i+1)%fukuro_num!=0)result+=price[i];
		}
		printf("%d\n",result);
	}
	return 0;
}

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

#define ll long long

int n, m, k, x, y, tmp, cnt, ans[100001], lbl[100001];
bool done[100001];
std::vector<int> a[100001], b[100001], group;
std::queue<int> idx;

void solve() {
    std::cin >> n >> m >> k;
    for (int i=0; i<m; ++i) {
        std::cin >> x >> y;
        a[x].push_back(y);
        a[y].push_back(x);
    }

    cnt = 0;
    for (int i=0; i<100001; ++i) {
        done[i] = 0;
        ans[i] = 0;
    }
    for (int i=1; i<n+1; ++i) {
        group.clear();
        if (done[i] == true)
            continue;
        done[i] = true;
        group.push_back(i);
        for (int p : a[i]) {
            idx.push(p);
            done[p] = true;
            group.push_back(p);
        }
        while (!idx.empty()) {
            tmp = idx.front();
            idx.pop();
            for (int p : a[tmp]) {
                if (done[p] == true)
                    continue;
                idx.push(p);
                done[p] = true;
                group.push_back(p);
            }
        }
        for (int s : group) {
            ans[s] = group.size();
            lbl[s] = cnt;
        }
        ++cnt;
    }

    for (int i=0; i<k; ++i) {
        std::cin >> x >> y;
        if (lbl[x] == lbl[y]) {
            b[x].push_back(y);
            b[y].push_back(x);
        }
    }

    for (int i=1; i<n+1; ++i)
        std::cout << ans[i] - a[i].size() - b[i].size() - 1 << " ";
    std::cout << std::endl;
}

int main() {
    std::ios_base::sync_with_stdio(0);
    solve();
    return 0;
}


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


int main(){
    int64_t a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int64_t mincost = 999999999999999;
    int64_t cost = 0;
    for(int i = 0; i <= max(x, y); i++){
        cost = 2*c*i + a*max(x-i, (int64_t)0) + b*max(y-i, (int64_t)0);
        if(cost < mincost){
            mincost = cost;
        }
    }
    
    cout << mincost << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <iomanip>
using namespace std;
int n;
int summ;
int cnt[3]={0};
vector<vector<vector<double>>>dp;
double eval(int a,int b,int c)
{
  if(dp[a][b][c]!=-1)
  {
    return dp[a][b][c];
  }
  else
  {
    double res=0;
    if(a>0){res+=(eval(a-1,b,c)+n/(a+b+c+0.0))*a;}
    if(b>0){res+=(eval(a+1,b-1,c)+n/(a+b+c+0.0))*b;}
    if(c>0){res+=(eval(a,b+1,c-1)+n/(a+b+c+0.0))*c;}
    res=res/(a+b+c);
    dp[a][b][c]=res;
    //cout<<"dp"<<a<<b<<c<<endl;
    //cout<<res<<endl<<endl;
    return res;
  }
}
int main()
{
  ios::sync_with_stdio(false);
  std::cout<<fixed<<setprecision(10);

  //int n;
  cin>>n;

  for(int i=0;i<n;i++)
  {
    int tmp;
    cin>>tmp;
    cnt[tmp-1]++;
  }
  summ=cnt[0]+cnt[1]*2+cnt[2]*3;
  dp=vector<vector<vector<double>>>(n+1,vector<vector<double>>(cnt[1]+cnt[2]+1,vector<double>(cnt[2]+1,-1)));
  dp[0][0][0]=0.0;
  eval(n,0,0);
  eval(cnt[0],cnt[1]+cnt[2],0);

  cout<<eval(cnt[0],cnt[1],cnt[2])<<endl;
  return 0;

}


Measured memory_bytes: 216960
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define TT pair<long long, long long>
#define ordered_set tree<TT, null_type, less<TT>, rb_tree_tag, tree_order_statistics_node_update>
#define fo(i,n)   for(i=0;i<n;i++)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define mp make_pair
#define For(m) for(auto it = m.begin();it!=m.end();it++)
#define fi first
#define se second
typedef long long ll;
typedef long double mytype;
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //priority_queue <int, vector<int>, greater<int> > pq;
    //cout << fixed << setprecision(9) <<ans<<endl;
    //ordered_set os;//os.order_of_key();//os.find_by_order();
    ll l,r,count,n,m,sum=0,ans=0,i,j,k,tt,t,x,y,z,c,a[200005]={},b[200005]={};
    string ss[2000];
    set<ll> s;
    vector<ll> v;
    map<ll,ll> ma;
    cin>>n>>m;
    fo(i,n)
    cin>>ss[i+1];
    fo(i,n)
    ss[i+1].insert(0,"a");
    ll dp[2000][2000]={};
    dp[1][1]=1;
    ll mod=1e9 + 7;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(i==1 && j==1)
            continue;
            if(ss[i][j]=='#')
            continue;
            dp[i][j]=dp[i-1][j]+dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n][m]<<endl;
}

Measured memory_bytes: 33536
#include<iostream>
using namespace std;
int main()
{
    int N;
	double A,m;
    m=0.0;
	cin>>N;
	for(int t=1;t<=N;t++)
	{
		cin>>A;
		m+=1.0/A;		
	} 
	cout<<1.0/m;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
fn main() {
    input! {
        n: i64,
        aa: [i64; n as usize],
    }

    let mut subs = HashMap::new();

    for (id, tall) in aa.iter().cloned().enumerate() {
        let id_sub_tall = id as i64 - tall;
        *subs.entry(id_sub_tall).or_insert(0) += 1i64;
    }

    let mut count = 0;
    // id + tall = other_id - other_tall (id < other_id)
    for (id, tall) in aa.into_iter().enumerate() {
        let id_add_tall = id as i64 + tall;
        count += *subs.get(&id_add_tall).unwrap_or(&0);
    }

    println!("{}", count);

}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n-1);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  for(int i=0;i<n;i++){
    cin >> b.at(i);
  }
  for(int i=0;i<n-1;i++){
    cin >> c.at(i);
  }
  //ここまで入力
  int sum=0;
  for(int i=0;i<n;i++){
    sum += b.at(a.at(i)-1);
    if(i==0){
      continue;
    }else{
      if(a.at(i)-1 == a.at(i-1)){
        sum += c.at(a.at(i-1)-1);
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 2e5 + 5;

int n,a[N],cnt[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=2;i<=n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		cout<<cnt[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 5152
#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;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    vll vec(3);
    REP(i, 3) cin >> vec.at(i);
    sort(ALL(vec));
    reverse(ALL(vec));
    ll n;
    cin >> n;
    ll ans = accumulate(ALL(vec), 0) - vec.at(0) + vec.at(0) * pow(2, n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;cin>>n;
  vector<int>stick(n);
  int tate=0;int yoko=0;
  for(int i=0;i<n;i++)cin>>stick[i];
  sort(stick.begin(),stick.end(),greater<int>());
  //for(int i=0;i<n;i++)cout<<stick[i]<<endl;
  for(int i=0;i<n-1;i++){
    int cnt=1;
    while(i!=n&&stick[i]==stick[i+1]){
      i++;
      cnt++;
    }
    //cout<<stick[i]<<endl;
    if(cnt>=4&&tate==0&&yoko==0){
      tate=stick[i];
      yoko=stick[i];
      break;
    }else if(cnt>=2){
      if(tate!=0){
	yoko=stick[i];
	break;
      }else{
	tate=stick[i];
      }
    }
  }
  cout<<(ll)tate*yoko<<endl;
  return 0;
}

Measured memory_bytes: 640
def palin(s):
  n=len(s)
  if s==s[::-1]:
    return 1
  else:
    return 0
s=raw_input()
n=len(s)
if palin(s)+palin(s[0:(n-1)/2])+palin(s[(n+3)/2 -1:])==3:
  print "Yes"
else:
  print "No"


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

count_0 = 0
count_minus = 0

abs_a = a

for i in range(n):
    if a[i] < 0:
        count_minus += 1
        abs_a[i] = -1*a[i]
    elif a[i] == 0:
        count_0 += 1

abs_a.sort()
a_sum = sum(abs_a)

if count_minus % 2 == 1 and count_0 == 0:
    print(a_sum - abs_a[0]*2)
else:
    print(a_sum)


Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
const int mxN=20;
int n,m;
int masksum[1<<mxN], edge[mxN][mxN], dp[1<<mxN][mxN], summ;
signed main()
{
    //freopen(file".inp","r",stdin);
    //freopen(file".out","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    memset(dp,-1,sizeof(dp));
	for(int i=1;i<=m;i++)
	{
		int u,v,w;
		cin>>u>>v>>w; u--, v--;
		edge[u][v]=edge[v][u]=w;
		summ+=w;
		for(int j=0;j<(1<<n);j++)
			if((j>>u&1) and (j>>v&1))
				masksum[j]+=w;// cout<<masksum[j]<<endl;
	}
	dp[1][0]=0;
	for(int i=1;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		{
			if(~dp[i][j]) 
			{	
				for(int k=0;k<n;k++)
					if(!(i>>k&1) and edge[j][k]) 
						dp[i|(1<<k)][k]=max(dp[i|(1<<k)][k],dp[i][j]+edge[j][k]);
				for(int kk=((1<<n)-1)^i,k=kk;k;k=(k-1)&kk)
					dp[i|k][j]=max(dp[i|k][j],dp[i][j]+masksum[k|(1<<j)]);
			}	
		}
	}
		
	cout<<summ-dp[(1<<n)-1][n-1];
}


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

using namespace std;

typedef long long ll;

void pv(vector <int> &v) {
    for(int i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve() {
	
}

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

    ll n;
    cin >> n;
    vector <int> a(n, 0);
    vector <int> b(n, 0);
    
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    
    reverse(b.begin(),b.end());
    // pv(b);
    int prob = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] == b[i]) prob++;
    }
    int c = -1;
    int l = INT_MAX;
    int r = INT_MIN;
    for(int i = 0; i < n; i++) {
        if(a[i] == b[i]) {
            c = a[i];
            l = i;
            break;
        }
    }
    for(int i = n-1; i >= 0; i--) {
        if(a[i] == b[i]) {
            r = i;
            break;
        }
    }

    int toSwap = (r-l+1);
    if(toSwap == 0 || prob == 0) {
        cout << "Yes" << endl;
        pv(b);
        return 0;
    }
    int l0 = l;
    int r0 = r;
    int avail = 0;
    for(int i = 0; i < l; i++) {
        if(a[i] != c && b[i] != c) avail++;
    }
    for(int i = r+1; i < n; i++) {
        if(a[i] != c && b[i] != c) avail++;
    }
    if(avail < toSwap) {
        cout << "No" << endl;
        return 0;
    }
    else cout << "Yes" << endl;

    int i = 0;
    int j = r0+1;

    while(l <= r) {
        if(i < l0 && a[i] != c && b[i] != c) {
            swap(b[i], b[l]);
            l++;
        }
        i++;
        if(i == n) break;
    }
    // if(j < n) {
        while(l <= r) {
            if(j < n && a[j] != c && b[j] != c) {
                swap(b[j], b[l]);
                l++;
            }
            j++;
            // if(j == n) break;
        }
    // }


    // while(l <= r) {
    //     if(i < l0 && a[i] != c && b[i] != c) {
    //         swap(b[i], b[l]);
    //         l++;
    //         i++;
    //         continue;
    //     }
    //     else if(i == l0 && a[j] != c && b[j] != c && j < n) {
    //         swap(b[j], b[l]);
    //         l++;
    //         j++;
    //         continue;
    //     }
    //     i++;
    //     if(i == l0) j++;
    // }
    pv(b);
    


    
    return 0;
}

Measured memory_bytes: 4788
# Aizu Problem ALDS_1_4_B: Binary Search
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


_ = input()
S = set([int(_) for _ in input().split()])
_ = input()
T = set([int(_) for _ in input().split()])
print(len(S.intersection(T)))

Measured memory_bytes: 21372
import cmath
n=int(input())
l=[None for i in range(n)]
for i in range(n):
    a,b=map(int,input().split())
    c=complex(a,b)
    l[i]=[cmath.phase(c),c]
l.sort(key=lambda x:x[0])
res=0
for i in range(n):
    c=l[i][1]
    for j in range(1,n):
        cc=c+l[(i+j)%n][1]
        if abs(cc)<abs(c):
            break
        c=cc
    res=max(res,abs(c))
print(res)

Measured memory_bytes: 39408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )

#define INF 1000000000

void swap(int* x, int *y)
{
	int t;

	t = *x;
	*x = *y;
	*y = t;
}

int binary_search(int p[], int n, int key)
{
	int left, right, middle;

	left = 0;
	right = n-1;


	while (left <= right)
	{
		middle = (left + right) / 2;

		if (p[middle] == key)
			return middle;
		else if (p[middle] > key)
		{
			right = middle - 1;
		}
		else if (p[middle] < key)
		{
			left = middle + 1;
		}
	}

	return -1;

}

void bubble_sort(int p[], int n)
{
	int i, j;

	for (i = 0; i < n-1; i++)
	{
		for (j = 0; j < n - i - 1; j++)
		{
			if (p[j] > p[j + 1])
				swap(&p[i], &p[i + 1]);
		}
	}
}

int main()
{
	int n;
	int num;
	int min = INF, max = -INF;
	long long int sum = 0;

	scanf("%d", &n);

	int i, j;

	for (i = 0; i < n; i++)
	{
		scanf("%d", &num);

		if (num < min)
			min = num;

		if (num > max)
			max = num;

		sum += num;
	}

	printf("%d %d %lld\n", min, max, sum);
}


Measured memory_bytes: 2144
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):number|number[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
let [a,b] = t.c(2)
  t.o(a=='9'||b=='9'?'Yes':'No')
}
main()

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
const ull MOD = 1000000007;
const int MAX_N = 100000;
ull fact[MAX_N + 1];
int main(){
    fact[0] = 0;
    fact[1] = 1;
    for (int i = 2; i < MAX_N + 1; i++){
        fact[i] = (fact[i - 1] * i) % MOD;
    }
    while (1){
        int N, R;
        ull num = 0;
        cin >> N;
        if (N == 0) break;
        int ans = 0;
        vector<int> word(N);
        for (int i = 0; i < N; i++) word[i] = i;
        word.push_back(0);
        cin >> R;
        vector<int> s(2*R+1, 0);
        for (int i = 0; i < R; i++){
            cin >> s[i] >> s[i+R];
            s[i]--; s[i+R]--;
            word[s[i]] ^= word[s[i+R]];
            word[s[i+R]] ^= word[s[i]];
            word[s[i]] ^= word[s[i+R]];
        }
        sort(s.begin(), s.end());
        s.erase(unique(s.begin(), s.end()), s.end());
        s.push_back(N);
        for (int i = 0, R = s.size() - 1; i < R; i++){
            ull tmp = fact[N - s[i] - 1], tmp2 = 0;
            tmp *= word[s[i]];
            tmp = tmp % MOD;
            for (int j = i; j < R; j++){
                word[s[j]] -= (word[s[j]] > word[s[i]] ? 1 : 0);
                if (s[j] + 1 != s[j + 1]){
                    word[s[j] + 1] -= (word[s[j] + 1] > word[s[i]] ? 1 : 0);
                }
            }
            for (int j = s[i] + 1; j < s[i + 1]; j++){
                tmp2 += fact[N - j - 1];
                tmp2 = tmp2 % MOD;
            }
            for (int j = i + 1; j < R; j++){
                word[s[j]] -= (word[s[j]] > word[s[i] + 1] ? s[i+1] - s[i] - 1 : 0);
                if (s[j] + 1 != s[j + 1]){
                    word[s[j] + 1] -= (word[s[j] + 1] > word[s[i] + 1] ? s[i+1] - s[i] - 1 : 0);
                }
            }
            tmp2 *= word[s[i] + 1] % MOD;
            tmp += tmp2;
            tmp += ans;
            ans = tmp % MOD;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2784
n = int(input())

if n == 1:
    print(0)
    exit()

def factorization(n):
    seq = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            seq.append([i, cnt])

    if temp!=1:
        seq.append([temp, 1])

    if seq==[]:
        seq.append([n, 1])

    return seq

so = factorization(n)

ans = 0
for i in range(len(so)):
    j = 1
    mun = so[i][1]
    while mun >= j:
        if mun - j >= 0:
            ans += 1
            mun -= j
            j += 1

print(ans)

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

int main() {
	
	//vector<int> a(n);
	//cout << "test" << endl;

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	//string ans="YES";


	int n,d;
	cin >> n >> d;
	
	int ans=0;
	
	int di;//d:int
	double dd;//d:double
	
	vector<vector<int>> a(n, vector<int>(d));
	
	rep(i,n){
		rep(j,d){
			cin >> a[i][j];
		}
	}
	//cout << "test" << endl;
	
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			int dis=0;
			for(int k=0;k<d;k++){
				int dif=a[i][k]-a[j][k];
				dis+=dif*dif;
			}
			di=sqrt(dis);
			dd=sqrt(dis);
			if((double)di==dd) ans++;
		}
	}
	
	
	cout << ans << "\n";
	
	
	return 0;

    }

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

#define I inline void 

using namespace std ; 

using ll = long long ; 
using ld = long double ; 

const int N = 2e6 + 7 ; 

// How interesting!

int n , m , k ; 

int col[N] , row[N] ; 

vector<pair<int,int>>ed ; 
map<pair<int,int>,int> mp ;

int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	//freopen("in.in", "r" , stdin) ;
	cin >> n >> m >> k ; 
	for(int i = 0 ;i < k ;i++){
		int u , v; 
		cin >> u >> v; 	
		ed.push_back({u,v}) ;
		row[u]++;
		col[v]++;
		mp[{u,v}] = 1; 
	}	

	std::vector<int> vecr , vecc ; 

	int mxr = 0 , mxc = 0 ; 

	for(int i =1 ;i <= n;i++){
		if(row[i] == mxr){
			vecr.push_back(i) ; 
		}
		else if(row[i] > mxr)vecr = {i} , mxr = row[i] ; 
	}
	for(int i = 1;i <= m ;i++){
		if(col[i] == mxc){
			vecc.push_back(i) ; 
		}
		else if(col[i] > mxc)vecc = {i} , mxc = col[i]; 
	}
	int ans = 0 ;
	for(auto u : vecr){
		for(auto v : vecc){
			int k = mp[{u,v}] ; 
			ans = max(row[u] + col[v] - k , ans ) ; 
			if(!k){
				cout<< ans ; 
				return 0 ; 
			}
		}
	}

	cout<< ans ; 

	return 0 ; 
}

Measured memory_bytes: 30976
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
char s[110];
long long k,ans;
int l,cnt,cn;
long long dis[10000];

int main()
{
	scanf("%s%lld",s+1,&k);
	l=strlen(s+1);
	for(int i=1;i<=l;++i)
	{
		char ch=s[i];
		cn=1;
		while(s[i]==s[i+1]) ++cn,++i;
		dis[++cnt]=cn;
	}
	if(cnt==1)
	{
		cout<<(k*l>>1);
	}
	else 
	{
		if(s[1]==s[l])
		{
			ans+=(dis[1]>>1)+(dis[cnt]>>1);
			for(int i=2;i<cnt;++i)
			ans+=(dis[i]>>1)*k;
			ans+=((dis[1]+dis[cnt])>>1)*(k-1);
			cout<<ans;
		}
		else
		{
			for(int i=1;i<=cnt;++i)
			ans+=(dis[i]>>1);
			ans*=k;
			cout<<ans;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
int main(){
    int a,b; cin >> a >> b;
    if(max(a,b) > min(a,b)){
        cout << max(a,b)*2 -1 << endl;
    } else {
        cout << max(a,b)*2 << endl;
    }
}



Measured memory_bytes: 256
// clang-format

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;

void solve(std::vector<long long> M, std::vector<long long> D) {
  if(M[0] != M[1])cout << 1 << endl;
  else cout << 0 << endl;
}

int main() {
  int a;
  std::vector<long long> M(2);
  std::vector<long long> D(2);
  for (int i = 0; i < 2; i++) {
    scanf("%lld", &M[i]);
    scanf("%lld", &D[i]);
  }
  solve(std::move(M), std::move(D));
  return 0;
}


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

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

typedef long long ll;

int main() {
  int n;
  cin >> n;

  string ret = "No";
  for(int i=1; i<10; i++){
    if(n%i == 0 && n/i <10){
      ret = "Yes";
      break;
    }
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define N             (int)(1e6+5)
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    int a,b,h; cin>>a>>b>>h;
    double t=(a+b)*h;
    t/=2;
    cout<<t;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

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

#define ll long long

ll get(ll a, ll b, ll c){
	ll mini, maxi;
	mini = min(a, min(b, c));
	maxi = max(a, max(b , c));
	return maxi - mini;
}

int main(){
    ll i,j,h,w,mini,a,b,c;
    scanf("%lld %lld", &h, &w);
    if(h % 3 == 0 || w % 3 == 0){
    	printf("0\n");
    	return 0;
    }
    mini = min(h, w);
    if(h % 3 == 1){
    	a = (h / 3) * w;
    	b = (2 * (h / 3) + 1) * (w / 2);
    	c = (2 * (h / 3) + 1) * (w - w / 2);
    	mini = min(mini, get(a,b,c));

    	a = (h / 3 + 1) * w;
    	b = (2 * (h / 3)) * (w / 2);
    	c = (2 * (h / 3)) * (w - w / 2);
    	mini = min(mini, get(a,b,c));
    }

    else if(h % 3 == 2){
    	a = (h / 3) * w;
    	b = (2 * (h / 3) + 2) * (w / 2);
    	c = (2 * (h / 3) + 2) * (w - w / 2);
    	mini = min(mini, get(a,b,c));

    	a = (h / 3 + 2) * w;
    	b = (2 * (h / 3)) * (w / 2);
    	c = (2 * (h / 3)) * (w - w / 2);
    	mini = min(mini, get(a,b,c));

    	a = (h / 3 + 1) * w;
    	b = (2 * (h / 3) + 1) * (w / 2);
    	c = (2 * (h / 3) + 1) * (w - w / 2);
    	mini = min(mini, get(a,b,c));
    }

    swap(h, w);
    if(h % 3 == 1){
    	a = (h / 3) * w;
    	b = (2 * (h / 3) + 1) * (w / 2);
    	c = (2 * (h / 3) + 1) * (w - w / 2);
    	mini = min(mini, get(a,b,c));

    	a = (h / 3 + 1) * w;
    	b = (2 * (h / 3)) * (w / 2);
    	c = (2 * (h / 3)) * (w - w / 2);
    	mini = min(mini, get(a,b,c));
    }

    else if(h % 3 == 2){
    	a = (h / 3) * w;
    	b = (2 * (h / 3) + 2) * (w / 2);
    	c = (2 * (h / 3) + 2) * (w - w / 2);
    	mini = min(mini, get(a,b,c));

    	a = (h / 3 + 2) * w;
    	b = (2 * (h / 3)) * (w / 2);
    	c = (2 * (h / 3)) * (w - w / 2);
    	mini = min(mini, get(a,b,c));

    	a = (h / 3 + 1) * w;
    	b = (2 * (h / 3) + 1) * (w / 2);
    	c = (2 * (h / 3) + 1) * (w - w / 2);
    	mini = min(mini, get(a,b,c));
    }
    printf("%lld\n", mini);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main() {
	int n, x;
	while (1) {
		cin >> n;
		if (n == 0) break;
		vi d(n);
		rep(i, 0, n) {
			cin >> d[i];
		}
		cin >> x;
		int cnt = 0, l = 0, r = n - 1;
		while (l<=r) {
			cnt++;
			int mid = (l + r) / 2;
			if (d[mid] > x) {
				r = mid - 1;
			}
			else if (d[mid] < x) {
				l = mid + 1;
			}
			else{
				break;
			}
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <cmath>
#include <string> 
#include <cstdint>
#include <cstring>
#include <queue> 
#include <climits>
#include <unordered_map>
//https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
 
using namespace std;
typedef long long ll;
std::unordered_map<ll, std::vector<pair<pair<ll,ll>,ll> > > connection;
ll N, M;
int result = 0;

int main()
{
    cin >> N >> M;
    ll* a = new ll[M];
    ll* b = new ll[M];
    ll* c = new ll[M];
    bool* result = new bool[M];

    for(ll i = 0; i < M; i ++){
        cin >> a[i] >> b[i] >> c[i];
        result[i] = false;
        a[i] --;
        b[i] --;
        connection[a[i]].push_back(make_pair(make_pair(i, b[i]), c[i]));
        connection[b[i]].push_back(make_pair(make_pair(i, a[i]), c[i]));
    }

    for(ll i = 0; i < N; i ++){

        //ダイクストラ
        priority_queue<pair<ll,ll> >pq;
        // weight[v]に始点sからvまでの最短コストを保存する
        ll weight[N];
        // 訪問状態を記録
        bool searched[N];
        //
        ll parent[N];
        for(ll i = 0; i < N; i ++){
            searched[i] = false;
            weight[i] = LLONG_MAX;
        }

        pq.push(make_pair(0, i));

        // priority_queue dicstra
        while(!pq.empty()){
            pair<ll,ll> first = pq.top();
            pq.pop();
            ll node = first.second;
            ll u = -first.first;
            //cout << node << "/" << u << endl;
            searched[node] = true;

            for(pair<pair<ll,ll>,ll> target : connection[node]){
                ll targetNode = target.first.second;
                ll targetCost = target.second;
                if(searched[targetNode]) continue;
                if(targetCost + u < weight[targetNode]){
                    //cout << i << "/" << node << ":" << targetCost << "," << u << endl;
                    parent[targetNode] = target.first.first;
                    weight[targetNode] = targetCost + u;
                    pair<ll,ll> newPair = make_pair(weight[targetNode] * -1, targetNode);
                    pq.push(newPair);
                }
            }
        }

        for(ll n = 0; n < N; n ++){
            if(n == i) continue;
            result[parent[n]] = true;
        }
    }

    ll answer = 0;
    for(ll i = 0; i < M; i ++){
        if(result[i] == false){
            answer ++;
        }
    }
    cout << answer;

    return 0;
}

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

int main() {
    string str;
    int n;
    cin >> n >> str;
    if(str.length() <= n) {
        cout << str << endl;
    }
    else {
        for(int i = 0;i < n;i ++) {
            cout << str[i];
        }
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    vec D(N); cin >> D;
    int M; cin >> M;
    vec T(M); cin >> T;

    map<int, int> cD, cT;
    for(int x: D) cD[x] += 1;
    for(int x: T) cT[x] += 1;
    bool f = true;
    for(auto p: cT){
        if(cD[p.f] < p.s) f = false;
    }
    Ans(f, "YES", "NO");

    return 0;
}


Measured memory_bytes: 28416
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
ll mod=1e18;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}
long modInverse(long a) {return powmod(a, mod-2);}
ll my_rand(){ll a=rand();ll b=rand();return (a*RAND_MAX+1)+b;}
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()


int main(){
    ios::sync_with_stdio(false);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0);
    cout.tie(0);
    map<string,int>m;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<m.size()<<endl;
    return 0;
    }


Measured memory_bytes: 19232
import java.util.Scanner;


//Print a Rectangle
//
//たてH cm よこ W cm の長方形を描くプログラムを作成して下さい。
//
//1 cm × 1cm の長方形を '#'で表します。
//Input
//
//入力は複数のデータセットから構成されています。各データセットの形式は以下のとおりです：
//
//H W
//
//H, W がともに 0 のとき、入力の終わりとします。
//Output
//
//各データセットについて、H × W 個の '#' で描かれた長方形を出力して下さい。
//
//各データセットの後に、１つの空行を入れて下さい。
//Constraints
//
//H, W ? 300
//Sample Input
//
//3 4
//5 6
//2 2
//0 0
//
//Sample Output
//
//####
//####
//####
//
//######
//######
//######
//######
//######
//
//##
//##


public class Main {
    public static void main(String[] args) {

    	/*Scanner = テキスト入力を扱うためのクラス
		 *キーボードからの入力を受けつける場合は
		 *System.inを使って下記のように記述
		 */
		Scanner scan = new Scanner(System.in);

		//forループ文用に変数準備
		int i;
		int j;

		/*while文で無限ループ設定
		 * if文でbreakをかける
		 * 求められている通りになったがコードが無駄に多いように思える
		 * 後程修正を行えるか試す
		 */

		while(true){
			int H = scan.nextInt();
			int W = scan.nextInt();
			if(H == 0 && W == 0 || H > 300 || W > 300)break;
			for(j = 0; j < H; j++){
				for(i = 0; i < W; i++){
					System.out.print("#");
				}
			System.out.println();
			}
			System.out.println();
		}
    }
}

Measured memory_bytes: 26824
#include<bits/stdc++.h>
using namespace std;
int main(){int h,w,s;cin>>h>>w>>s;
           int a=0;
           vector<char>g(h*w);
       for(int i=0;i<h*w;i++)cin>>g.at(i);
 int f=(1<<h),q=(1<<w);for(;f>0;f--)
 {for(;q>0;q--){int j=0;for(int i=0;i<h*w;i++)
     if(((q/(1<<(i%w)))%2)&&((f/(1<<(i/w)))%2)&&(g.at(i)=='#'))
     {j++;}if(j==s)a++;}q=(1<<w);}cout<<a<<endl;}

Measured memory_bytes: 3636
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
temp = a[0]
l = 1
e = 0
ans = n
b = 0
for i in 1..n-1
  if temp^a[i] == temp+a[i]
    l += 1
    ans += l-1
  else
    loop do
      temp ^= a[i-l]
      l -= 1
      if temp^a[i] == temp+a[i]
        ans += l
        l += 1
        break
      end
    end
  end
  temp ^= a[i]
end
p ans

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

using namespace std;

const int MAXN = 505;
const int mod = 1e9 + 7;

int n, x;
int a[MAXN];
int comb[MAXN][MAXN];

int g[MAXN];
int f[MAXN][MAXN][MAXN];

int mul(int x, int y) {
  return 1LL * x * y % mod;
}

void add(int &x, int y) {
  x += y;
  if(x >= mod) x -= mod;
  if(x < 0) x += mod;
}

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

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

  for(int i = 0; i < MAXN; ++i) {
    comb[i][0] = 1;
    for(int j = 1; j <= i; ++j) {
      add(comb[i][j] = comb[i - 1][j], comb[i - 1][j - 1]);
    }
  }

  /***
    f(i, k, sum), numbers with value >= i, has chosen k numbers, and acquired sum of sum
  ***/

  f[x + 1][0][0] = 1;
  for(int i = x + 1; i > 0; --i) {
    for(int k = 0; k <= x + 1; ++k) {
      for(int sum = 0; sum <= x; ++sum) {
        if(!f[i][k][sum]) continue;
        int way = sum + k - i * k;
        if(k == 0) way = 0;
        for(int t = 0; t < a[i]; ++t) {
          f[i][k][sum] = mul(f[i][k][sum], way);
        }
        int val = i - 1;
        for(int c = 0; k + c <= x + 1 && sum + c * val <= x; ++c) {

          add(f[i - 1][k + c][sum + c * val], mul(f[i][k][sum], comb[k + c][c]));
        }
      }
    }
  }


  for(int blocked = x; blocked >= 0; --blocked) {
    g[blocked] = f[0][blocked + 1][x - blocked];
    for(int j = blocked + 1; j <= x; ++j) {
      add(g[blocked], -mul(g[j], comb[j][blocked]));
    }
  }

  cout << g[0] << endl;


  return 0;
}


Measured memory_bytes: 502272
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a[100]= {1,3,5,7,8,10,12};
    int b[100]= {4,6,9,11};
    int n,m,k,i,h,l;
    scanf("%d %d",&n,&m);
    k=0;h=0;l=0;
    for(i=0; i<7; i++)
    {
        if(n==a[i])
            k++;
        if(m==a[i])
            k++;
    }
    for(i=0; i<4; i++)
    {
        if(n==b[i])
            h++;
        if(m==b[i])
            h++;
    }
    if(n==2&&m==2)
        l++;
    if(k>1||h>1||l>0)
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<math.h>
using namespace std;

int main(){
	int x,y;
	double theta=0;
	double sum_x=0;
	double sum_y=0;
	char c;
	
	while(cin >>x>> c >> y){
		if(x==0&&y==0) break;
		sum_y += x*cos(theta*M_PI/180);
		sum_x += x*sin(theta*M_PI/180);
		theta += y;
	}
	cout << (int)sum_x<<endl;
	cout <<(int)sum_y<<endl;

}

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

using namespace std;

int main(){
    int a = 0, b = 0, x = 0;
    
    cin >> x;
    cin >> a;
    cin >> b;
    
    x = x - a;
    x = x % b;
    cout << x << endl;
    
    return 0;
}

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

priority_queue<double> q;

double n, v;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> v;
		q.push(-v);
	}
	while (1) {
		double a = -q.top(); q.pop();
		double b = -q.top(); q.pop();
		q.push(-(a + b) / 2);
		if (q.size() == 1) { break; }
	}
	cout << -q.top() << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque
D1 = {i:chr(i+96) for i in range(1,27)}
D2 = {val:key for key,val in D1.items()}

N = int(input())
heap = deque([(D1[1],1)])
A = []
while heap:
    a,n = heap.popleft()
    if n<N:
        imax = 0
        for i in range(len(a)):
            imax = max(imax,D2[a[i]])
        for i in range(1,min(imax+1,26)+1):
            heap.append((a+D1[i],n+1))
    if n==N:
        A.append(a)
A = sorted(list(set(A)))
for i in range(len(A)):
    print(A[i])

Measured memory_bytes: 110300
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}


int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  int y=*max_element(A.begin(),A.end());

  vector<bool>ok(10000000,true);

  for(int i=0;i<N;i++){
   int x=A[i];
   if(i<N-1&&A[i]==A[i+1]){ok[A[i]]=false;continue;}
   for(int j=x+x;j<=y;j+=x){
     ok[j]=false;
   }
  }

  int cnt=0;
  for(int i=0;i<N;i++){
    if(ok[A[i]]){cnt++;}
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 5352
//This disgusting code is wriiten by Juruo D0zingbear
//Please don't hack me! 0v0 <3
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}

// cf IO: I64d
// atcoder IO: ｌｌｄ
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int Maxn=200005;
string s;
int nxt[Maxn][27];
int dp[Maxn];
vector<pair<int,int> > pre[Maxn];
int main(){
	cin>>s;
	int n=s.length();
	for (int i=0;i<26;i++) nxt[n][i]=-1;
	for (int i=s.length()-1;i>=0;i--){
		for (int j=0;j<26;j++){
			nxt[i][j]=nxt[i+1][j];
		}
		nxt[i][s[i]-'a']=i;
	}
	//cout<<nxt[0][0]<<endl;
	for (int i=0;i<=n+1;i++) dp[i]=1e9;
	dp[n+1]=0;
	for (int i=n;i>=0;i--){
		for (int j=0;j<26;j++){
			int Nxt=nxt[i][j]+1;
			if (!Nxt) Nxt=n+1;
			if (dp[Nxt]+1<dp[i]){
				dp[i]=dp[Nxt]+1;
			}
		}
	//	cout<<dp[i]<<endl;
	}
	int now=0;
	string ans;
	while (1){
	//	cout<<now<<endl;
	//	cout<<now<<endl;
		for (int i=0;i<26;i++){
			
		//	cout<<dp[nxt[now][i]+1]<<endl;
			if (nxt[now][i]==-1){
				ans+=(char)(i+'a');
				cout<<ans<<endl;
				return 0;
			}
			if (dp[nxt[now][i]+1]==dp[now]-1){
				ans+=(char)(i+'a');
				now=nxt[now][i]+1;
				break;
			//	cout<<nxt[now][i]<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 27140
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e5+5;
ll inf=1e15;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        ll need=0;
        ll ar[n];
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
        }
        for(int i=1;i<n;i++)
        {
            if(ar[i]<ar[i-1])
            {
                need+=ar[i-1]-ar[i];
            }
            ar[i]=max(ar[i],ar[i-1]);
        }
        cout<<need<<endl;
    }

    return 0;
}

Measured memory_bytes: 5208
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int n;

vector<vector<int> >v;
vector<int >deg;

int dp[maxn];
int ans;

void dfs(int x,int prev)
{
	for(int i=0;i<v[x].size();i++)
	{
		int son=v[x][i];
		if(son!=prev)
		{
			dfs(son,x);
		}
	}
	vector<int>tmp;
	int sum=0;
	for(int i=0;i<v[x].size();i++)
	{
		int son=v[x][i];
		if(son!=prev)
		{
			tmp.push_back(dp[son]);
			sum+=dp[son];
		}
	}
	//dp[x]有可能为0 
	int add=0;
	for(int i=0;i<tmp.size();i++)
	{
		if(!tmp[i])add++;
		dp[x]=sum+max(add-1,0); //add-1可能<0 
	}
}

int main()
{
	ios::sync_with_stdio(0);
	
	cin>>n;v.resize(n+1);deg.resize(n+1);
	for(int i=1;i<n;i++)
	{
		int a,b;cin>>a>>b;
		v[a].push_back(b);v[b].push_back(a);
		deg[a]++;deg[b]++;
	}
	
	int ma=0,root=-1;
	for(int i=0;i<n;i++)
	{
		if(deg[i]>ma)
		{
			ma=deg[i];
			root=i;
		}
	}
	if(ma<=2)
	{
		cout<<"1\n";return 0;
	}
	
	dfs(root,-1);
	cout<<dp[root];
	return 0;
}

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

vector<bool> primes;
const int MAXV = 1e5;

// j - i = Aj + Ai　です。
// 上記を式変形すると以下の様になります
// Ai + i = Aj - j 　

int main()
{
    int n;
    cin >> n;
    vector<int> list(n);
    for (int i = 0; i < n; i++) {
        cin >> list[i];
    }
    ll ans = 0;
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        int p = i - list[i];
        int a = i + list[i];
        ans += m[p];
        m[a]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21052