akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LL long long
#define Rg register
#define RI register int
#define RC register char
#define ed puts("") 
#define Pair pair<int,int>
#define space putchar(' ')
using namespace std;   
template <typename tp> inline void read(tp & x) 
{	
    x=0;
    RI f=1; 
    RC c=getchar();  
    while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();} 
    while(c>='0' && c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();} 
 	x*=f;
} 	
    	
template <typename Tp> inline void print(Tp x)  
{							  	
    if(x<0) x=-x,putchar('-');  
    if(x>9) print(x/10);      
    putchar(x%10+'0');		  	
}	

const int maxn=1e6+10;
char s[maxn];
int ans;
char last;
bool vis[maxn];
int flag;

int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	flag=1;//上一个长度 
	for(RI i=1;i<=len;++i)
	{
		if(s[i]==s[i+1] && flag==1 && i==len-1) 
		{
			++ans;
			break;
		}
		if(s[i]==s[i+1]&&flag==1) 
			++ans,flag=2;
		else if(s[i]!=s[i+1] && flag==2) 
			++ans,flag=1,++i;
		else if(s[i]!=s[i+1] && flag==1) 
			++ans;
		else if(s[i]==s[i+1] && flag==2) 
			++i,++ans,flag=1;
	}
	print(ans);	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

	return 0;
}

Measured memory_bytes: 4036
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val aa = 1.until(n + 1).map {
        val a = readLine()?.toInt() ?: return
        A(
            it,
            0.until(a).map {
                val (x, y) = readLine()?.split(" ")?.map(String::toInt) ?: return
                Testimony(x, y == 0)
            }
        )
    }
    val candidates = mutableListOf<BooleanArray>()
    generateCandidates(booleanArrayOf(), n, 0, candidates)

    val count = candidates.map { liars ->
        if (verify(aa, liars)) {
            liars.count { !it }
        } else {
            0
        }
    }.max()
    println(count.toString())
}

data class Testimony(val number: Int, val liar: Boolean)
data class A(
    val number: Int,
    val testimony: List<Testimony>
)

fun verify(aa: List<A>, liars: BooleanArray): Boolean {
    aa.flatMap {
        val liar = liars[it.number - 1]
        if (liar) {
            emptyList()
        } else {
            it.testimony
        }
    }.forEach {
        if (liars[it.number - 1] != it.liar) {
            return false
        }
    }
    return true
}

tailrec fun generateCandidates(array: BooleanArray, n: Int, index: Int, candidates: MutableList<BooleanArray>) {
    if (index == n) {
        candidates.add(array)
    } else {
        generateCandidates(array + booleanArrayOf(true), n, index + 1, candidates)
        generateCandidates(array + booleanArrayOf(false), n, index + 1, candidates)
    }
}


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


int main(void){
    int a, b;
    int result;

    cin >> a >> b;

    if(a >= 13){
        result = b;
    } else if(a <= 12 && a >= 6){
        result = b / 2;
    } else {
        result = 0;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<bitset>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::bitset;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;

//#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

lli N, M;
lli a, b, vis, ans;
vector<lli> gph[50];
queue<int> bfs;
bitset<50> flag;

int main(){
	cin.tie(0);
	std::ios::sync_with_stdio(false);
	cin >> N >> M;
	for(lli i = 0; i< M; i++){
		cin >> a >> b;
		gph[a-1].push_back(b-1);
		gph[b-1].push_back(a-1);
	}

	for(int i = 0; i < N; i++){
		for(auto j : gph[i]){
			if(j < i) continue;
			flag &= 0;
			vis = 0;
			bfs.push(i);
			flag.set(i);
			vis++;
			while(bfs.size() > 0){
				a = bfs.front();bfs.pop();
				for(auto k : gph[a]){
					if( (a==i && k==j) || (a==j && k==i) || flag[k]) continue;
					bfs.push(k);
					flag.set(k);
					vis++;
				}
			}
			if(vis < N) ans++;
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll sz = ((ll)1 << 22);
ll dp[sz];
ll g[22][22];
ll mod = 1e9+7;

int main() {
    ll n;
    cin >> n;
    for(ll i = 0 ; i < n  ;i++){
        for(ll j = 0 ; j < n ; j++)
        cin >> g[i][j];
    }

    dp[0] = 1;
    for(ll mask= 0 ; mask < (1 << n)-1 ; mask++)
    {
        ll i = __builtin_popcount(mask);
        for(ll j = 0 ; j < (n) ; j++)
        {
            if(g[i][j] && !(mask & ((ll)1<< j)))
            {
                ll new_mask = (mask^((ll)1 << j));
                dp[new_mask]+= dp[mask];
                if(dp[new_mask] >= mod)
                dp[new_mask] -= mod;
            }
        }
    }

    cout << dp[((ll)1 << n)-1];




    

}


Measured memory_bytes: 19944
import sys
import itertools

def extend_gcd(a, b):
    if b == 0:
        return (1, 0, a)
    else:
        (a1, b1, g) = extend_gcd(b, a % b)
        return (b1, a1 - (a // b) * b1, g)
    
    
if __name__ == '__main__':
    line = sys.stdin.readline()
    a,b = line.split()
    a,b = int(a), int(b)
    
    (x, y, g) = extend_gcd(a, b)
    
    
    sys.stdout.write(str(x) + ' '  + str(y) +  '\n')
    
        

Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 9223372036854775807;
ll ans = 0;

int main()
{
ll n;
cin >> n;
ll d[n][n] = {};
rep(i, n)rep(j,n)
{
    cin >> d[i][j];
    ans+=d[i][j];
}
bool a[n][n]={};

//cout << ans<< endl;
ll temp=0;
for (int k = 0; k < n; k++)
    for (int i = 0; i < n-1; i++)
        for (int j = i+1; j < n; j++){
            //d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            if(d[i][j]> d[i][k] + d[k][j]){
                cout << -1 << endl;
                return 0;
            }
            if(d[i][j]== d[i][k] + d[k][j]&&k!=j&&k!=i){
                a[i][j]=1;
               // cout <<k+1<<' '<<i+1<<' '<<j+1<<' '<< d[i][j]<< endl;
            }
        }



rep(i,n)rep(j,i){
    if(a[j][i]==0)temp+=d[i][j];
}
cout << temp<< endl;
return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

vector<vector<int>> G;
vector<bool> vis;
vector<int> ans;
void bfs(){
    queue<int> q;
    q.push(1);
    vis[1]=1;
    while(!q.empty()){
        auto u=q.front();
        q.pop();
        for(auto to:G[u]){
            if(!vis[to]){
                vis[to]=1;
                ans[to]=u;
                q.push(to);
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin>>n>>m;
    G.resize(n+1);
    vis.resize(n+1);
    ans.resize(n+1);
    forn(i,m){
        int x,y;
        cin>>x>>y;
        G[x].pb(y);
        G[y].pb(x);
    }
    bfs();
    cout<<"Yes\n";
    for(int i=2;i<=n;i++) cout<<ans[i]<<endl;
    return 0;
}



Measured memory_bytes: 10280
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e18+18
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod 1000000007
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=1000001;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
void power(ll a[][50],ll b[][50],ll n)
{
   ll i,k,j,p;
   ll c[50][50]={};
   memset(c,0,sizeof(c));
   
   for(i=0;i<n;i++)
   {
   	for(j=0;j<n;j++)
   	{
   		for(k=0;k<n;k++)
   		{
   			c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod;
   		}
   	}
   }
   for(i=0;i<n;i++)
   {
   	for(j=0;j<n;j++)
   		a[i][j]=c[i][j];
   }

}
void matriix(ll a[][50],ll n,ll k)
{
	ll r[50][50]={},i,j;
	memset(r,0,sizeof(r));
	for(i=0;i<n;i++)
		r[i][i]=1;
	while(k)
	{
        if(k%2)
        {
        	k--;
        	power(r,a,n);
        }
        k=k/2;
        power(a,a,n);
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
			a[i][j]=r[i][j];
	}
}
int main()
{
   
   ll i,j,k,l,m,n;
   cin>>n>>k;
   ll a[n][50];
   for(i=0;i<n;i++)
   {
   	for(j=0;j<n;j++)
   		cin>>a[i][j];
   }
   matriix(a,n,k);
   l=0;
   for(i=0;i<n;i++)
   {
   	for(j=0;j<n;j++)
   		l=(l+a[i][j])%mod;
   }
   cout<<l;
   
}

Measured memory_bytes: 3660
#include <stdio.h>

#define N 10000

int n,A[N];
int rec(int, int);

int main() {
  int i,q,M[N];

  scanf("%d" ,&n);
  for(i=0; i<n; i++) {
    scanf("%d" ,&A[i]);
  }
  scanf("%d" ,&q);
  for(i=0; i<q; i++) {
    scanf("%d" ,&M[i]);
  }
  for(i=0; i<q; i++) {
    if(rec(0,M[i]) == 1) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int rec(int s,int m){
  if(A[s]==m) return 1;
  if(s+1==n) return 0;
  if(rec(s+1,m-A[s]) || rec(s+1,m)) return 1;
  return 0;
}

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

int main() {
 int N, X;
 cin >> N >> X;
  
  vector<int> vec(N);
  for(int i = 0; i < N; i++) {
   cin >> vec.at(i);
  }
  
  int res = 114514;
  for(int i = 0; i < N; i++) {
    if(res > vec.at(i)) {
      res = vec.at(i);
    }
  }
  
  int sum = 0;
  for(int i = 0; i < N; i++) {
    sum += vec.at(i);
  }
  int amari;
  amari = X - sum;
  
  cout << N + amari / res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define qwq(x) cout<<"# "<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define f(x,y) g[(x)][(y)+52]
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=200005;
int fa[N][20],mx[N][20],d[N],anc[N],f[N],g[N],h[N];
int n,a,b;
vi e[N];

void pre(int u){
	anc[u]=anc[fa[u][0]];
	if(u>anc[u])anc[u]=u;
	mx[u][0]=u;
	rep(j,1,19){
		fa[u][j]=fa[fa[u][j-1]][j-1];
		mx[u][j]=max(mx[u][j-1],mx[fa[u][j-1]][j-1]);
	}
	for(auto v:e[u])
		if(v!=fa[u][0])
			fa[v][0]=u,d[v]=d[u]+1,pre(v);
}

void dfs(int u){
	if(anc[u]==u){
		f[u]=f[fa[u][0]]+1;
		for(auto v:e[u])
			if(v!=fa[u][0])
				f[u]+=h[v];
	}
	else if(anc[u]==fa[u][0]){
		f[u]=f[fa[u][0]];
		f[u]+=g[u]-h[u];
	}
	else f[u]=f[fa[u][0]];
	for(auto v:e[u])
		if(v!=fa[u][0])dfs(v);
}

int main(){
	read(n);
	rep(i,1,n-1){
		read(a),read(b);
		e[a].pb(b),e[b].pb(a);
	}
	d[1]=1,pre(1);
	rep(u,2,n)if(anc[u]!=u){
		int p=u,H=0;
		per(j,19,0)
			if(d[fa[p][j]]>d[anc[u]])
				H=max(H,mx[p][j]),p=fa[p][j];
		g[p]++;
		H=max(H,p);
		if(H<anc[fa[anc[u]][0]])
			h[p]++;
	}
	f[0]=-1,dfs(1);
	rep(i,2,n)printf("%d ",f[i]);
	return 0;
}

Measured memory_bytes: 57088
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
bool yes[100010];
int siz[100010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi(),x,y;
	yes[1]=1;for(int i=1;i<=n;++i)siz[i]=1;
	while(m--){
		x=gi(),y=gi();
		if(!siz[x])continue;
		--siz[x],++siz[y];
		yes[y]|=yes[x];
		if(!siz[x])yes[x]=0;
	}
	int ans=0;for(int i=1;i<=n;++i)ans+=yes[i];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
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 Return(ans) { cout << (ans) << endl; return 0; }
#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 T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; 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 A(N); cin >> A;

    int ans = 0;
    map<int, int> cnt;
    REP(i, N){
        ans += cnt[i - A[i]];
        cnt[i + A[i]] += 1;
    }
    Out(ans);

    return 0;
}


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

int main() {
    
    int i;
    int h, n, a, all = 0;

    scanf("%d%d", &h, &n);
    for(i = 0; i < n; i++) {
        scanf("%d", &a);
        all += a;
    }

    if(h <= all) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


N, K = MI()
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
print(len(Base_10_to_n(N, K)))

Measured memory_bytes: 38256
from collections import Counter

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

v1 = Counter(v[::2])
v2 = Counter(v[1::2])
v1 = v1.most_common()
v2 = v2.most_common()

no_change = 0
no_change1 = 0
no_change2 = 0

no_change1 += v1[0][1]
for i in v2:
    if i[0] != v1[0][0]:
        no_change1 += i[1]
        break

no_change2 += v2[0][1]
for i in v1:
    if i[0] != v2[0][0]:
        no_change2 += i[1]
        break

no_change = max(no_change1, no_change2)

print(n-no_change)


Measured memory_bytes: 18656
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

using Graph = vector<vector<int>>;
using pint = pair<int, int>;

int N, M;
Graph G;
int s, t;

long long solve(){
    vector<vector<long long>> dist(N, vector<long long>(3, -1));
    dist[s][0] = 0;
    queue<pint> que;
    que.push({s, 0});
    while(!que.empty()) {
        pint cur = que.front(); que.pop();
        int v = cur.first;
        int parity = cur.second;
        for (auto nv:G[v]) {
            int np = (parity + 1) % 3;
            if (dist[nv][np] == -1) {
                dist[nv][np] = dist[v][parity] + 1;
                que.push({nv, np});
            }

        }
    }
    if (dist[t][0] == -1) return -1;
    else return dist[t][0] / 3;
}

int main(){
    cin >> N >> M;
    G.assign(N, vector<int>());
    for (int i = 0; i < M; ++i) {
        int u, v; cin >> u >> v; --u, --v;
        G[u].push_back(v);
    }
    cin >> s >> t;
    --s, --t;
    cout << solve() << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define int ll
using pii = pair<int, int>;

int32_t main()
{
    int N, X, T; cin >> N >> X >> T;
    int round = N/X + 1 - (N%X == 0? 1 : 0);
    cout << round * T << '\n';
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long
const int maxn=1e6+10;
const ll mod=998244353;
using namespace std;

ll f[maxn]; 
ll tree[maxn];
int n,a[maxn];
ll lowbit(int x)
{
	return x & -x;
}
void add(int x,int k)
{
	while(x<=n)
	{
		tree[x]+=k;x+=lowbit(x);
	}
}
ll sum(int x)
{
	ll ans=0;
	while(x>=1)
	{ 
		ans+=tree[x];x-=lowbit(x);
	}
	return ans;
}
int main()
{
	ll ans=0,ans1=0;
	scanf("%d",&n);
	f[1]=1;
	for(int i=2;i<=n;i++) f[i]=f[i-1]*i%mod,f[i]%=mod;
	for(int i=1;i<=n;i++)  add(i,1);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		ll w=(f[n-i]*(sum(a[i]-1)%mod))%mod;
		ans+=w,ans%=mod;
		add(a[i],-1);
	}
	memset(tree,0,sizeof(tree));
	for(int i=1;i<=n;i++)  add(i,1);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		ll w=(f[n-i]*(sum(a[i]-1)%mod))%mod;
		ans1+=w,ans1%=mod;
		add(a[i],-1);
	}
	printf("%lld\n",abs(ans-ans1));
	return 0;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
#define MAXN 100100
using namespace std;
typedef vector<int> vi;
typedef set<int> se;
typedef pair<int,int> pii;
inline int mod(int n, int m){
int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

int resto[MAXN];
int dp[MAXN][14];
string s;
int n;
int solve(int id,int r){
	if(id==n){
		if(r==5)return 1;
		return 0;
	}
	if(dp[id][r]!=-1)return dp[id][r];
	int mul = resto[n-1-id];
	if(s[id]!='?'){
		return dp[id][r]=mod(solve(id+1,mod(r+(s[id]-'0')*mul,13)),M);
	}else{
		int ans =0;
		for(int i =0;i<10;i++){
			ans=mod(ans+solve(id+1,mod(r+i*mul,13)),M);
		}
		return dp[id][r]=mod(ans,M);
	}
}

int32_t main(){
    fastio;
 	cin>>s;
 	n = s.size();
	 int a = 1;
	 for(int i=0;i<(int)s.size()+10;i++){
	  resto[i]=a;	 
	  a=a*10;
	  a=a%13;
	 }
	 memset(dp,-1,sizeof(dp));
	 cout<<mod(solve(0,0),M)<<endl;   
}

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

int main() {
  int n, d;
  cin >> n >> d;
  
  ll a, b;
  int cnt = 0;
  for(int i=0; i<n; i++) {
    cin >> a >> b;
    if(sqrt(a*a+b*b)<=d) cnt++;
  }
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3640
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

const MOD: usize = 1_000_000_007;

fn main() {
    let input = read_vec::<usize>();
    let (n, m) = (input[0], input[1]);

    let mut aa = vec![false; n+2];
    for _ in 0..m {
        let a = read::<usize>();
        aa[a] = true;
    }

    let mut dp = vec![0usize; n+2];
    dp[0] = 1;

    for i in 0..n {
        if !aa[i+1] {
            dp[i+1] += dp[i];
            dp[i+1] %= MOD;    
        }
        if !aa[i+2] {
            dp[i+2] += dp[i];
            dp[i+2] %= MOD;
        }
    }

    println!("{:?}", dp[n]);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define fi first
#define se second
#define vi vector< int > 
#define pii pair<int,int>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin >> n;
	vector<int> v(n+1),vis(1000009);
	for (int i = 0;i < n; i++) cin >> v[i];
	sort(v.begin(),v.begin() + n);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (vis[v[i]]) continue;
		if (v[i+1] != v[i])
		ans++;
		for (int j = v[i]; j <= 1000000; j += v[i]) vis[j] = 1;
	}
	cout << ans;
}

Measured memory_bytes: 7936
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int h,H,r,c,t,s;
int seq[1000],n,p,pot[12];
char fl[100][101],dmg[256];
int dp[1001][1<<12];

bool solve()
{
	rep(i,n+1)rep(j,1<<p)dp[i][j]=0;
	dp[0][(1<<p)-1]=h;
	rep(i,n)for(int j=(1<<p)-1;j>=0;j--)if(dp[i][j]>0)
	{
		rep(k,p)if(j&1<<k)
		dp[i][j^1<<k]=max(dp[i][j^1<<k],min(H,dp[i][j]+pot[k]));
		dp[i+1][j]=max(dp[i+1][j],dp[i][j]-seq[i]);
	}
	rep(i,1<<p)if(dp[n][i]>0)return 1;
	return 0;
}
int main()
{
	while(scanf("%d%d",&h,&H),h)
	{
		scanf("%d%d",&r,&c);
		rep(i,r)scanf("%s",fl+i);
		
		char a; int b;
		scanf("%d",&t);
		rep(i,t)scanf(" %c%d",&a,&b),dmg[a]=b;
		
		int y=0,x=0; n=0;
		scanf("%d",&s);
		rep(i,s)
		{
			scanf(" %c%d",&a,&b);
			rep(j,b)
			{
				if(a=='U')y--; if(a=='R')x++;
				if(a=='D')y++; if(a=='L')x--;
				seq[n++]=dmg[fl[y][x]];
			}
		}
		
		scanf("%d",&p);
		rep(i,p)scanf("%d",pot+i);
		
		puts(solve()?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 16000
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//ここまでテンプレ
int main(){
	int N,C;
	cin>>N>>C;
	int D[SIZE][SIZE]={};
	int c[SIZE][SIZE]={};
	int TC[SIZE][SIZE]={};
	for(int i=0;i<C;i++)
		for(int j=0;j<C;j++)
			cin>>D[i][j];
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			cin>>c[i][j];
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			TC[(i+j)%3][c[i][j]-1]++;
		}
	}
	int mini=INF;
	for(int i=0;i<C;i++){
		for(int j=0;j<C;j++){
			for(int k=0;k<C;k++){
				if(i==j || j==k || k==i)
					continue;
				int temp=0;
				for(int l=0;l<C;l++)
					temp+=D[l][i]*TC[0][l]+D[l][j]*TC[1][l]+D[l][k]*TC[2][l];
				mini=min(mini,temp);
			}
		}
	}
	cout<<mini<<endl;
	return 0;
}

Measured memory_bytes: 13184
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int a, b, k;
  cin >> a >> b >> k;

  for(int i = 0; i < k; i++){
    if(i % 2 == 0){
      if(a % 2 == 1) a--;
      b += a / 2;
      a -= a / 2;
    }
    else{
      if(b % 2 == 1) b--;
      a += b / 2;
      b -= b / 2;
    }
  }

  cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 504
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pr;
const double pi=acos(-1);
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define Rep(i,u) for(int i=head[u];i;i=Next[i])
#define clr(a) memset(a,0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define pq priority_queue
#define pqb priority_queue <int, vector<int>, less<int> >
#define pqs priority_queue <int, vector<int>, greater<int> >
#define vec vector
ld eps=1e-9;
ll pp=1000000007;
ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;}
ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;}
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
//void add(int x,int y,int z){ v[++e]=y; next[e]=head[x]; head[x]=e; cost[e]=z; }
int dx[5]={0,-1,1,0,0},dy[5]={0,0,0,-1,1};
ll read(){ ll ans=0; char last=' ',ch=getchar();
while(ch<'0' || ch>'9')last=ch,ch=getchar();
while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
if(last=='-')ans=-ans; return ans;
}
int a[200];
int main(){
	int n=read(),ans=0;
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=2;i<=n;i++) 
		if (a[i]==a[i-1]) a[i]=-1,ans++;
	printf("%d",ans);
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<vector<int>> a(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) cin >> a[i][j];
  }
  int n;
  cin >> n;
  unordered_set<int> called;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    called.insert(b);
  }
  vector<vector<bool>> flag(3, vector<bool>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      flag[i][j] = called.find(a[i][j]) != called.end();
    }
  }
  string ans = "No";
  for (int i = 0; i < 3; i++) {
    bool ok = true;
    for (int j = 0; j < 3; j++) {
      if (flag[i][j]) continue;
      ok = false;
      break;
    }
    if (ok) {ans = "Yes"; break;}
  }
  for (int j = 0; j < 3; j++) {
    bool ok = true;
    for (int i = 0; i < 3; i++) {
      if (flag[i][j]) continue;
      ok = false;
      break;
    }
    if (ok) {ans = "Yes"; break;}
  }
  bool ok = true;
  for (int i = 0; i < 3; i++) {
    if (flag[i][i]) continue;
    ok = false;
    break;
  }
  if (ok) ans = "Yes";
  ok = true;
  for (int i = 0; i < 3; i++) {
    if (flag[i][2-i]) continue;
    ok = false;
    break;
  }
  if (ok) ans = "Yes";
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=10000;i++)
	{
		double x,y;
		x=i*0.08;
		y=i*0.1;
		if(int(x)==a&&int(y)==b)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0; 
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
import numpy as np
n=int(input())
a=np.array([int(j) for j in input().split()],dtype=np.int64)
ans=0
mod=10**9+7
for i in range(61):
    b=(a>>i)&1
    c=np.count_nonzero(b)
    ans+=(2**i)*c*(n-c)
    ans%=mod
print(ans)

Measured memory_bytes: 48756
inp = input()
N,M = inp.split()
N,M = int(N), int(M)

CorrectAnswer = [0] * N
Penalties     = [0] * N

p = []
S = []
for i in range(M):
    inp = input()
    x,y = inp.split()
    x   = int(x)
#     p.append(x)
#     S.append(y)
    
    #checking 1st timers?
    if CorrectAnswer[x-1] == 1:
        pass
        #         CorrectAnswer[x-1] = 1
    else:
        if y == 'AC':
            CorrectAnswer[x-1] = 1
        else:
            Penalties[x-1] += 1

penalties = 0
for i in range(N):
    penalties += CorrectAnswer[i] * Penalties[i]
print(sum(CorrectAnswer), penalties)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void printString(long long n) 
{ 
    char str[1000000]; // To store result (Excel column name) 
    int i = 0; // To store current index in str which is result 
  
    while (n > 0) { 
        // Find remainder 
        int rem = n % 26; 
  
        // If remainder is 0, then a 'Z' must be there in output 
        if (rem == 0) { 
            str[i++] = 'z'; 
            n = (n / 26) - 1; 
        } 
        else // If remainder is non-zero 
        { 
            str[i++] = (rem - 1) + 'a'; 
            n = n / 26; 
        } 
    } 
    str[i] = '\0'; 
  
    // Reverse the string and print result 
    reverse(str, str + strlen(str)); 
    
    cout << str << endl; 
  
    return; 
} 
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
  long long n;
  cin>>n;
  printString(n);
  
  
 
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
    A--, B--, C--, D--;
    string S; cin >> S;
    function<bool(int, int)> ok = [&](int from, int to) {
        if (from == to) return true;
        if (from > to) return false;
        if (from+1 < N && S[from+1] == '.') return ok(from+1, to);
        if (from+2 < N && S[from+2] == '.') return ok(from+2, to);
        return false;
    };
    auto cross = [&](int x, int y) {
        for (int i = x-1; i < y; i++) {
            if (0 <= i && i+2 < N && S[i] == '.' && S[i+1] == '.' && S[i+2] == '.') {
                return true;
            }
        }
        return false;
    };
    bool ans;
    if (D < C) {
        ans = ok(A, C) && ok(B, D) && cross(B, D);
    } else {
        ans = ok(A, C) && ok(B, D);
    }
    cout << (ans ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 9604
from collections import deque

n, m = map(int, input().split())
rooms = [[] for i in range(n + 1)]

for i in range(m):
    a, b = map(int, input().split())
    rooms[a].append(b)
    rooms[b].append(a)

q = deque()
q.append(1)
paths = [-1]*(n + 1)
paths[1] = 0

while q:
    rnum = q.popleft()
    for i in rooms[rnum]:
        if paths[i] == -1:
            paths[i] = rnum
            q.append(i)
print("Yes")
for i in paths[2:]:
    print(i)

Measured memory_bytes: 35112
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int s[]=new int[13];
		int h[]=new int[13];
		int c[]=new int[13];
		int d[]=new int[13];
		for(int i=0;i<13;i++) {
			s[i]=0;
			h[i]=0;
			c[i]=0;
			d[i]=0;
		}
		String chara;
		int num;
		for(int i=0;i<n;i++) {
			chara = scan.next();
			num=scan.nextInt()-1;
			if(chara.equals("S"))s[num]=1;
			if(chara.equals("H"))h[num]=1;
			if(chara.equals("C"))c[num]=1;
			if(chara.equals("D"))d[num]=1;
		}

		for(int i=0;i<13;i++) if(s[i]==0) System.out.println("S "+(i+1));
		for(int i=0;i<13;i++) if(h[i]==0) System.out.println("H "+(i+1));
		for(int i=0;i<13;i++) if(c[i]==0) System.out.println("C "+(i+1));
		for(int i=0;i<13;i++) if(d[i]==0) System.out.println("D "+(i+1));

		scan.close();
	}

}


Measured memory_bytes: 26288
n, k = gets.strip.split.map(&:to_i)

array = {}

n.times do
    a, b = gets.strip.split.map(&:to_i)
    array[a] = 0 unless array.key?(a)
    array[a] += b
end

array = array.sort

count = 0
array.each do |key, value|
    if count + value >= k
        puts key
        break
    end
    count += value
end

Measured memory_bytes: 9992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    string s;
    int ans = 0;
    cin >> s;
    char tmp = s[0];
    for (int i = 1; i < s.length(); i++)
    {
        if (s[i] != tmp)
        {
            ans++;
            tmp = s[i];
        }
    }
    int an = 0;
    tmp = s[s.length() - 1];
    for (int i = s.length() - 2; i >= 0; i--)
    {
        if (s[i] != tmp)
        {
            an++;
            tmp = s[i];
        }
    }
    cout << min(ans, an) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int H, N;
  cin >> H >> N;
  int sum = 0;
  rep(i,N) {
    int t;
    cin >> t;
    sum += t;
  }
  if (sum >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;cin>>s;
    fore(i,0,(int)s.size()-1,2){
        if(s[i]!='h'||s[i+1]!='i'){
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
s = input()
K = int(input())

expi = len(s)
expn = 1
for i in range(1, len(s) + 1):
    if s[i-1] == "1":
        continue
    expi = i
    expn = s[i-1]
    break

if expi <= K:
    print(expn)
else:
    print(s[K-1])


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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

typedef long long ll;
typedef pair<int, int> P;

int main(){
  int n, x[10], y[10];
  
  cin >> n;
  rep(i, n){
    cin >> x[i] >> y[i];
  }
  
  int sum = 0;
  double dis = 0;
  rep(i, n - 1){
    rep2(j, i + 1, n){
      debug2(i, j);
      int xd = x[i] - x[j];
      int yd = y[i] - y[j];
      dis += sqrt((double)(xd * xd + yd * yd));
    }
  }
  
  printf("%lf", dis / (double)n * (double)2);
  
  return 0;
}


Measured memory_bytes: 256
from heapq import heapify, heappop, heappush
N,M = map(int, input().split())
AB = []
for i in range(N):
    a,b = map(int, input().split())
    AB.append((a,-b))
AB.sort()

Q = []
ans = 0
i = 0

for day in range(M):
    while i<N and AB[i][0] == day+1:
        heappush(Q, AB[i][1])
        i+=1
    if Q:
        ans -= heappop(Q)
print(ans)

Measured memory_bytes: 17660
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int h,w,ch,cw,dh,dw;
    cin>>h>>w>>ch>>cw>>dh>>dw;
    --ch;--cw;--dh;--dw;
    vector<string> s(h);
    rep(i,h)cin>>s[i];
    constexpr int dx[]={-1,1,0,0};
    constexpr int dy[]={0,0,-1,1};
    deque<pair<int,int>> q;
    int d[h][w];
    bool done[h][w]={};
    rep(i,h)rep(j,w)d[i][j]=-1;
    d[ch][cw]=0;
    q.push_back({ch,cw});
    while(q.size()){
        int x=q.front().first;
        int y=q.front().second;
        q.pop_front();
        if(done[x][y])continue;
        done[x][y]=true;
        rep(i,4){
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(nx<0||h<=nx||ny<0||w<=ny||s[nx][ny]=='#')continue;
            if(d[nx][ny]==-1||d[x][y]<d[nx][ny]){
                d[nx][ny]=d[x][y];
                q.push_front({nx,ny});
            }
        }
        for(int i=-2;i<=2;++i){
            int nx=x+i;
            for(int j=-2;j<=2;++j){
                int ny=y+j;
                if(nx<0||h<=nx||ny<0||w<=ny||s[nx][ny]=='#'||d[nx][ny]!=-1)continue;
                d[nx][ny]=d[x][y]+1;
                q.push_back({nx,ny});
            }
        }
    }
    cout<<d[dh][dw]<<"\n";
}


Measured memory_bytes: 10396
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  ULL n;
  cin >> n;
  ULL sum = (1 + n) * n / 2;
  for(int i = 1; i <= n / 3; i++) {
    sum -= 3 * i;
  }
  for(int i = 1; i <= n / 5; i++) {
    sum -= 5 * i;
  }for(int i = 1; i <= n / 15; i++) {
    sum += 15 * i;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3596
n,k = map(int,input().split())
p_list = list(map(int,input().split()))
ruiseki = []
a = 0
for i in range(n):
  a += p_list[i]
  ruiseki.append(a)
res = -1
val_list = []
for m in range(n-k):
  val = ruiseki[k+m] - ruiseki[m]
  val_list.append(val)
if n ==k :
  	print((sum(p_list) + k)/2)
else:
	print((max(val_list)+k)/ 2) 

Measured memory_bytes: 25604
h, w = gets.split.map(&:to_i)
a = h.times.map{gets.chomp}.select{|v|v.index("#")}
b = w.times.select{|i| a.map{|v|v[i]}.include?("#")}
puts a.map{|v| b.map{|i|v[i]}.join}.join("\n")

Measured memory_bytes: 2172
#include <iostream>
using namespace std;
int main()
{
int x1,x2,x3,x4,x5;
cin>>x1;
cin>>x2;
cin>>x3;
cin>>x4;
cin>>x5;
if (x1==0)cout<<1<<endl;
else if (x2==0)cout<<2<<endl;
else if (x3==0)cout<<3<<endl;
else if (x4==0)cout<<4<<endl;
else if (x5==0)cout<<5<<endl;
return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
 
using namespace std;
 
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
 
const int MAXN = 500100, MAXK = 30;
const ll MOD = 998244353;
const int INF = 1e8;
const ld PI = asin(1) * 2;
 
void setIO () {
    FAST_IO;
}
 
void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
 
 
 
int main() {
	setIO();
 
    int n;
    cin >> n;
    if (n/100 == 7 || (n/10)%10 == 7 || n%10 == 7) cout << "Yes";
    else cout << "No";
 
	return 0;
}
 

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {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;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(1);
    ull n;
    ull a,b;
    cin >>n>>a>>b;
    if (b<a) swap(a,b);
    if ((b-a)%2==0) cout << (b-a)/2;
    else if (a-1 <= n-b){
        cout << a+(b-a)/2;
    }else
        cout << n-b+1 + (n-(a-b+1+n))/2;
    

    return 0;
}



Measured memory_bytes: 256
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64_t
#endif


const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

map <int, int> maps;
int a[MAXN];


int pref[MAXN];

 main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt (), m = readInt();
    for (int i = 1; i <= n; i++) {
    	i[a] = readInt();
    }
	maps[0] = 1;
	int ans = 0;
	/// a === b (mod m)
	/// a - b == 0
    for (int i = 1; i <= n; i++) {
    	pref[i] = pref[i - 1] + a[i];
    	pref[i] %= m;
    	ans += maps[pref[i]];
    	maps[pref[i]]++;        
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 9088