akhauriyash/Code-Regression huggingface dataset:
s = input()
t = input()
counter = 0
idx = -1
if set(t) <= set(s):
  for i in range(len(t)):
    idx = s.find(t[i],idx+1)
    if idx == -1:
      counter += 1
      idx = s.find(t[i],idx+1)
  print(counter * len(s) +idx +1)
else:
  print(-1)

Measured memory_bytes: 3316
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size() - 1; i ++)
    {
        if(s[i] == 'A' && s[i + 1] == 'C')
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;

    ll S = 0;
    for (char c : to_string(N)) {
        S += c - '0';
    }

    cout << (N % S == 0 ? "Yes" : "No") << endl;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a <= b) cout << a << endl;
    else cout << a - 1 << endl;
    return 0;
}

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

#define TRACE
#ifdef TRACE
#define tr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define tr(...)
#endif

#define ll long long
#define ld long double 
#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (ll)(a.size())
#define all(a) a.begin(), a.end() 
#define fr(i,n) for(i=1;i<=n;i++)
#define rp(i,n) for(i=0;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef pair<ll, ll> ii;
typedef vector<ll> vl;
const ll N = 200010;
ll mod=1e9+7;

ll ffmod(ll x, ll y, ll mod)
{
    ll rt=1;
    while(y)
    {
        if(y&1ll) rt=(rt*x)%mod;
        x=(x*x)%mod, y/=2ll;
    }
    return rt;
}

ll dp[1010][1010];
string s[1010];

int main()
{
    FIO;
    ll i,j,h,w;
    cin>>h>>w;
    rp(i,h) cin>>s[i];
    dp[0][0]=1;
    for(i=0;i<h;i++)
        for(j=0;j<w;j++)
            if((!(i==0 && j==0)) && s[i][j]=='.')
            {
                if(i>0)
                    dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
                if(j>0)
                    dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
            }
    cout<<dp[h-1][w-1]<<endl;
    return 0;
}


Measured memory_bytes: 9216
import bisect

n,v=map(int,input().split( ))
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
C=list(map(int,input().split( )))
D=list(map(int,input().split( )))

AB=[]
for i in range(n):
    for j in range(n):
        AB.append(A[i]+B[j])
CD=[]
for i in range(n):
    for j in range(n):
        CD.append(C[i]+D[j])
AB.sort()
CD.sort()

ans=0
for i in range(n**2):
    target1=v-AB[i]
    #target2=target1+0.2
    l=bisect.bisect_left(CD,target1)
    h=bisect.bisect_right(CD,target1)
    ####

    ans+=h
    ans-=l
print(ans)



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

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

    string str = to_string(n);
    if (str[0] == '7' || str[1] == '7' || str[2] == '7') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    

    return 0;
}

Measured memory_bytes: 3696
def solve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        exit()
    p = list(map(int, input().split()))
    for i in range(110):
        if x - i not in p:
            print(x-i)
            exit()
        if x + i not in p:
            print(x+i)
            exit()


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 200005;

int a[N];
LL f[N][2][3];
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    LL ans = -1e18;
    if (n % 2 == 0) {
        for (int j = 0; j < 1; j++) {
            for (int k = 0; k < 2; k++) {
                f[0][j][k] = -1e18;
            }
        }
        f[0][0][1] = 0;
        for (int i = 1; i <= n + 1; i++) {
            f[i][0][1] = f[i - 1][1][1];
            f[i][0][0] = max(f[i - 1][1][0], f[i - 1][0][1]);
            f[i][1][1] = f[i - 1][0][1] + a[i];
            f[i][1][0] = f[i - 1][0][0] + a[i];
        }
        ans = f[n + 1][0][0];
    } else {
        for (int j = 0; j < 1; j++) {
            for (int k = 0; k < 3; k++) {
                f[0][j][k] = -1e18;
            }
        }
        f[0][0][2] = 0;
        for (int i = 1; i <= n + 1; i++) {
            f[i][0][2] = f[i - 1][1][2];
            f[i][0][1] = max(f[i - 1][1][1], f[i - 1][0][2]);
            f[i][0][0] = max(f[i - 1][1][0], f[i - 1][0][1]);
            f[i][1][2] = f[i - 1][0][2] + a[i];
            f[i][1][1] = f[i - 1][0][1] + a[i];
            f[i][1][0] = f[i - 1][0][0] + a[i];
        }
        ans = f[n + 1][0][0];
    }

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


Measured memory_bytes: 13808
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int N,ano = 0;
	cin >> N;
	vector<int> len(N);
	for (int i = 0; i < N; i++) {
		cin >> len.at(i);
	}
	sort(len.begin(),len.end());
	for (int i = 0; i < N - 1; i++) {
		ano += len.at(i);
	}
	if (len.at(N - 1) < ano) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import copy
n=int(input())
s=[int(input())  for i in  range(n)]

Sum=[]
if sum(s)%10 != 0:
  print(sum(s))
  exit()
for i in s:
  c=copy.copy(s)
  c.remove(i)
  baisu=sum(c)
  #print(c)
  if baisu % 10 != 0:
    Sum.append(baisu)

if len(Sum) == 0:
  print(0)
else:
  print(max(Sum))

Measured memory_bytes: 9340
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll n;cin>>n;
  vll p(n+1);
  vvll dp(n,vll(n,MOD));
  rep(i,0,n){
    cin>>p[i]>>p[i+1];
  }
  rep(i,0,n){
    dp[i][i]=0;
  }
  rep(haba,0,n){
    rep(i,0,n-haba){
      int j=i+haba;
      rep(k,i,j){
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i]*p[k+1]*p[j+1]);
      }
    }
  }
  cout<<dp[0][n-1]<<endl;
}



Measured memory_bytes: 3152
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}



#[allow(non_snake_case, unused_variables)]
fn main() {
    input!{
        a: usize,
        b: usize,
    }
    println!("{}", (a-1)*(b-1));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=998244353;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return ((x%mod)*((f(x,y/2)*f(x,y/2))%mod))%mod;
}
int main(){
int N,S;
  cin>>N>>S;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  vector<vector<int64_t>>dp(N+1,vector<int64_t>(1+S,0));
  dp[0][0]=f(2,N);
  int64_t a=f(2,mod-2);
  for(int i=1;i<=N;i++){
  for(int j=0;j<=S;j++){
  if(j<A.at(i-1))
    dp[i][j]=dp[i-1][j];
    else
      dp[i][j]=(a*dp[i-1][j-A.at(i-1)]+dp[i-1][j])%mod;
  
  }
  
  }cout<<dp[N][S]<<endl;
   return 0;
}

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

struct UnionFind{
    vector<int> parent;
    vector<ll> dist;
    UnionFind(int x = 1){
        parent.clear(); parent.resize(x,-1);
        dist.clear(); dist.resize(x,0);
    }
    int find(int x){
        if(parent[x]<0)return x;
        int r = find(parent[x]);
        dist[x]+=dist[ parent[x] ];
        return parent[x]=r;    
    }
    ll depth(int x) { find(x); return dist[x]; }

    bool same(int x,int y) { return (find(x) == find(y)); }

    int size(int x) { return -parent[find(x)]; }

    void unite(int x,int y,ll k=0){
        k+=depth(y);
        k-=depth(x);
        k*=-1;
        x=find(x);
        y=find(y);
        if(x==y)return;
        if(size(x)<size(y)) { swap(x,y); k *= -1;}
        parent[x]+=parent[y];
        parent[y]=x;
        dist[y]=k;
    }
};

int main(){
    int N, M; cin >> N >> M;
    UnionFind T(N);
    rep(i,M){
        int l,r,d; cin >> l >> r >> d; l--; r--;
        if(T.same(l, r)) {
            if(T.dist[l] - T.dist[r] != d) {cout << "No" << endl; return 0;}
        }
        else T.unite(l, r, d);
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 1536
#include<stdio.h>
int main(void){
    int S;
    int h,m,s;
    scanf("%d",&S);
    
    h=S/3600;
    S=S-h*3600;
    m=S/60;
    S=S-m*60;
    s=S;
    
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
    
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
		if(i%k==0)
		{
			cout<<"OK"<<endl;
			return 0;
		}
	cout<<"NG"<<endl;
	return 0;
}


Measured memory_bytes: 3612
/*input
3
10 100 10
*/

//sometimes it's the people who no one imagines anything of 
//who do the things that no one can imagine.

//code author: iamxlr8

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define N 300005
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main() 
{
    off;
    ll n;
    cin>>n;
    vector<ll>v(n);
    for(ll i=0;i<n;i++)
        cin>>v[i];
    ll dp[n][n];
    memset(dp,0,sizeof(dp));
    for(ll i=0;i<n;i++)
        dp[i][i]=v[i];
    for(ll i=n-1;i>=0;i--)
    {
        for(ll j=i+1;j<n;j++)
            dp[i][j]=max(v[i]-dp[i+1][j],v[j]-dp[i][j-1]);
    }
    cout<<dp[0][n-1];
    return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
const int N=2000000+10;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
struct node {
	int to,next,v;
}a[N<<2];
int X[N],Y[N],Z[N],head[N],f[N],dis[N],cnt,INF;
priority_queue<pair<int,int> >q;
set<int> S[N];
void add(int x,int y,int c){
    a[++cnt].to=y;
    a[cnt].next=head[x];
    a[cnt].v=c;
    head[x]=cnt;
}
void dij(int s){
 	q.push({0,s});
	memset(dis,127,sizeof(dis));
    INF=dis[s],dis[s]=0;
	while(!q.empty()){
		int now=q.top().second,z=-q.top().first;
		q.pop();
		if(dis[now]<z)continue;
		for(int i=head[now];i;i=a[i].next){
			int v=a[i].to,w=z+(!S[now].count(a[i].v));
			if(dis[v]>w){
				dis[v]=w,q.push({-w,v});
				S[v].clear();
				S[v].insert(a[i].v);
			}
			else if(dis[v]==w)
				S[v].insert(a[i].v);
		}
    }
}
int main(){
	int n=read(),m=read();
	for(int i=1;i<=m;i++)
		X[i]=read(),Y[i]=read(),Z[i]=read(),add(X[i],Y[i],Z[i]),add(Y[i],X[i],Z[i]);
	dij(1);
	if(dis[n]==INF) puts("-1"),exit(0);
//	for(int i=1;i<=n;i++)
//		cout<<dis[i]<<" ";
//	cout<<dis[6];
	printf("%d",dis[n]);
}


Measured memory_bytes: 128760
n = gets.to_i
h = gets.split.map(&:to_i)
ans = 0
n.times do |i|
    f = true
    i.times do |j|
        if h[j] > h[i]
            f = false
            break
        end
    end
    if f
        ans += 1
    end
end
p ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vl ans(n, 0);
  rep2(i, 1, n) {
    int a;
    cin >> a;
    ans[a - 1]++;
  }
  rep(i, n) cout << ans[i] << endl;
}

Measured memory_bytes: 4844
import java.util.*;

public class Main {
    private class Section {
        int l, r, v;

        public Section(int now, int t, int v) {
            this.l = now;
            this.r = now + t;
            this.v = v;
        }

        public double getMaxV(double t) {
            if (t < l) {
                return v + (l - t);
            } else if (r < t) {
                return v + (t - r);
            } else {
                return v;
            }
        }
    }

    public void main(Scanner sc) {
        int n = sc.nextInt();
        int t[] = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
        }

        Section secs[] = new Section[n + 2];
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            int v = sc.nextInt();
            secs[i] = new Section(sum, t[i - 1], v);
            sum += t[i - 1];
        }

        secs[0] = new Section(0, 0, 0);
        secs[n + 1] = new Section(sum, 0, 0);

        double ans = 0.0;
        for (double now = 0.0; now <= sum - 0.5; now += 0.5) {
            double v1 = secs[0].getMaxV(now);
            double v2 = secs[0].getMaxV(now + 0.5);
            for (int i = 1; i < n + 2; i++) {
                v1 = Math.min(v1, secs[i].getMaxV(now));
                v2 = Math.min(v2, secs[i].getMaxV(now + 0.5));
            }

            ans += (v1 + v2) * 0.25;
        }

        System.out.println(ans);
    }

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


Measured memory_bytes: 24020
#include <stack>
#include <string>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
	stack<int> D;

	string S;

	while (cin >> S)
	{
		if (S == "+" || S == "-" || S == "*")
		{
			int B = D.top();

			D.pop();

			int A = D.top();

			D.pop();

			if (S == "+")
			{
				D.push(A + B);
			}
			if (S == "-")
			{
				D.push(A - B);
			}
			if (S == "*")
			{
				D.push(A * B);
			}
		}
		else
		{
			D.push(atoi(S.c_str()));
		}
	}

	cout << D.top() << endl;

	return 0;
}

Measured memory_bytes: 1200
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def main():
  N = GI()

  l = []

  for color in 'r', 'b':
    for _ in range(N):
      x, y = GIS()
      l.append((x, y, color))

  l.sort()
  rys = [0] * 200
  count = 0
  for x, y, c in l:
    if c == 'r':
      rys[y] = 1
    else:
      found = None
      for i in range(y):
        if rys[i]:
          found = i
      if found is not None:
        rys[found] = 0
        count += 1

  print(count)

main()

Measured memory_bytes: 38896
N = int(input())
mod = 10 ** 9 + 7

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

def factorial(p, n):
    result = 1
    for i in range(1, n + 1):
        result = result * p % mod
    return result

ans = factorial(10, N) - 2 * factorial(9, N) + factorial(8, N)
ans = ans % mod

while True:
    if ans > 0:
        break
    ans += mod

print(ans)


Measured memory_bytes: 9052
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
//	cout<<n%27<<endl;
	int x=ceil(double(n)/1.08);
	if((int)(x*1.08)==n)
		cout<<x<<endl;
	else if((int)((x-1)*1.08)==n)
		cout<<x-1<<endl;
	else if((int)((x-2)*1.08)==n)
		cout<<x-2<<endl;
	else
		cout<<":("<<endl;
	return 0;
}

Measured memory_bytes: 256
@1=map$-=$_-2,@0=1..<>+2;--$0[-1];map$\+=$'*($$_[$N=$$_[$`]]-($$_[$P=${1-$_}[$`]]=$N))*($`-$P),/	/,0for`tr ' ' '
'|nl|sort -nk2`;print

Measured memory_bytes: 42236
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main(){
	int k;
	cin >> k;
	long long int ans=0;
	int n;
	int m;
	for (int i = 1; i < k+1; ++i)
	{
		for (int j = 1; j < k+1 ;++j)
		{
			for (int t = 1; t < k+1; ++t)
			{
				n = gcd(i,j);
				m = gcd(n,t);
				ans = ans + m;

			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cassert>

using namespace std;

#define TASKNAME ""

void solve(int test_number);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(9);
    cerr.setf(ios::fixed);
    cerr.precision(3);
#ifdef LOCAL
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#else
#endif
    int n = 1;
    for (int i = 0; i < n; i++) {
        solve(i);
    }
}

const int MAX_N = 100005;

int cnt[32];
int n, a[MAX_N];

void solve(int test_number) {
    int xor_all = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        xor_all ^= a[i];
        int first_bit = (a[i] & -a[i]);
        cnt[__builtin_popcount(first_bit | (first_bit - 1)) - 1]++;
    }
    int flip = 0, ans = 0;
    for (int i = 31; i >= 0; i--) {
        int b = ((xor_all & (1 << i))? 1: 0);
        if (b ^ flip) {
            if (!cnt[i]) {
                cout << "-1" << endl;
                return;
            }
            flip ^= 1;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int n; cin >> n;
    vector<ll> b(n-1);
    rep(i,n-1)cin >> b[i];
    vector<ll> a(n,0);
    ll ans = 0;
    rep(i,n-1){
        if(i == 0){
            a[i] = b[i];
            ans += a[i];
            continue;
        }
        a[i] = min(b[i-1],b[i]);
        // cout << "i=" << i << " " << a[i] << endl;
        ans += a[i];
    }
    a[n-1] = b[n-2];
    ans += a[n-1];
    // rep(i,n)cout << a[i] << " ";
    // cout << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC088
{
    class ProblemA
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine().ToString();
            string input2 = Console.ReadLine().ToString();

            int n = int.Parse(input1);
            int a = int.Parse(input2);
            if (n % 500 <= a)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return true; } return false;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 h,w,k;
  cin >> h >> w >> k;
  vector<string> c(h);
  REP(i,h)cin >> c[i];
  int32 ans = 0;
  for(int32 mask = 0; mask < (1<<(h+w)); ++mask){
    vector<string> d = c;
    REP(i,h){
      if(mask >> i & 1){
        REP(j,w)d[i][j] = '*';
      }
    }
    REP(j,w){
      if(mask >> (h+j) & 1){
        REP(i,h)d[i][j] = '*';
      }
    }
    int32 cnt = 0;
    REP(i,h)REP(j,w)if(d[i][j] == '#')++cnt;
    if(cnt == k)++ans;
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int vist[100005];
int Q(int n){
	long long x = 2,ans = 1;
	while(n>0){
		if(n&1)		ans = ans*x%1000000007;
		x = x*x%1000000007;
		n/=2;
	}
	return ans;
}
void Init(int n){
	for(int i = 0; i <= n-1; i++)
		vist[i]	= 0;
}
int main()
{
	int n,m,F;
	while(scanf("%d",&n)!=EOF){
		Init(n);
		F = true;
		for(int i = 0; i < n; i++){
			scanf("%d",&m);
			vist[m]++;		if(m>n-1)	F = false;
		}
		if(n%2!=0){
			for(int i = 0; i <= n-1; i++){
				if(i==0&&vist[i]!=1)		F = false;	
				if(i!=0&&i%2==0&&vist[i]!=2)		F = false;
				if(i%2!=0&&vist[i]!=0)		F = false;	
			}
			if(F){
				int c = Q((n-1)/2);
				printf("%d\n",c%1000000007);
			}
			else	printf("0\n");
		}
		
		else{
			for(int i = 1; i <= n-1; i++){
				if(i%2!=0&&vist[i]!=2)		F = false;
				if(i%2==0&&vist[i]!=0)		F = false;
			}
			if(F){
				int c = Q(n/2);
				printf("%d\n",c%1000000007);
			}
			else	printf("0\n");
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,x,i;
	cin>>n;
	map<int,int>m;
	for(i=1;i<n;i++)
	{
		cin>>x;
		m[x]++;
	}
	for(i=1;i<=n;i++)
	{
		cout<<m[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 12972
def main():
        
    N,C = map(int, input().split())

    #　各時間各チャンネルで録画機が動いてるかどうか
    R = [[0]*(10**5) for _ in range(C)]

    for _ in range(N):
        s,t,c = map(int, input().split())
        #チャンネルｃをｓからｔまで録画、ｓの0.5秒前から録画機を使うのでs-1始まりにする
        R[c-1][s-1:t] = [1] * (t-(s-1))

    ans = 0
    for t in range(10**5):
        cnt = 0
        #時刻ごとにそれぞれのチャンネルで録画機を使ってるかどうか数え上げる
        for ch in range(C):
            if R[ch][t] == 1: cnt += 1

        ans = max(ans, cnt)

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 26612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> C)
{
    ll dp[200010];
    dp[0] = 1;
    ll left[200010];

    for (int i = 0; i < 200010; i++)
    {
        left[i] = -1;
    }
    left[C[0]] = 0;
    for (int i = 1; i < N; i++)
    {
        dp[i] = dp[i - 1];
        int c = C[i];

        if (left[c] >= 0 && left[c] < i - 1)
        {
            dp[i] = (dp[i - 1] + dp[left[c]]) % MOD;
        }
        left[c] = i;
    }

    cout << dp[N - 1] << endl;
}

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


Measured memory_bytes: 4992
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	int res = 0;
	rep(i, n) {
		int x; cin >> x;
		res += x - 1;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) int __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

struct UnionFind{
    int n;
    vi p,r;
    UnionFind(int N):n(N){
        p.resize(n);
    	iota(all(p),0);
        r.resize(n);
        fill(all(r),0);
    }
    void unite(int a, int b){
        int c=root(a),d=root(b); 
        if(c!=d) {
            if(r[c]<r[d]){
                p[c]=d;
            }else{
                p[d]=c;
                if(r[c]==r[d])r[c]++;
            }
        }
    }
    int root(int a){return p[a]=(p[a]==a?a:root(p[a]));}
    bool same(int a, int b){return root(a)==root(b);}
};

struct Kruskal{
    using Edge=pair<int,pair<int,int>>;
    vector<Edge> edge;
	int n;
	Kruskal(){}
	Kruskal(int N):n(N){ edge.resize(n); }
    void add(int C,int S,int T){
		edge.eb(C,mp(S,T));
	}
    void remove(int C,int S,int T){
		edge.erase(find(all(edge),mp(C,mp(S,T))));
	}
	pair<int,vector<Edge>> calcMST(){
		int ans=0;
		vector<Edge> ret;
		sort(all(edge),[](Edge a,Edge b){return a.fs<b.fs;});

		UnionFind uf(n);		
		for(auto e:edge){
			if(!uf.same(e.sc.fs, e.sc.sc)){
				ret.pb(e);
				ans+=e.fs;
				uf.unite(e.sc.fs, e.sc.sc);
				if(ret.size()==n-1){
					break;
				}
			}
		}
		return mp(ans,ret);
	}

};

int main(){
	int n,m;
	while(cin>>n>>m){
		Kruskal kr(n);
		rep(i,m){
			dcl(s,d,c);
			kr.add(c,s-1,d-1);
		}
		auto mst=kr.calcMST();
		int cost=mst.fs;
		int ans=0,anscost=0;

		for(auto e:mst.sc){
			kr.remove(e.fs, e.sc.fs, e.sc.sc);
			int cur=kr.calcMST().fs;
			if(cur != cost || cur==-1){
				ans++;
				anscost+=e.fs;
			}
			kr.add(e.fs, e.sc.fs, e.sc.sc);
		}
		cout<<ans<<" "<<anscost<<endl;
	}
	return 0;
}



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

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

using namespace std;

using ll = long long int;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q, tmp, l, r;
  vector<int> m;
  m.emplace_back(0);
  string s;
  cin >> n >> q;
  cin >> s;
  for (int i = 1; i < s.size(); ++i)
  {
    if (s[i] == 'C' && s[i - 1] == 'A')
      ++tmp;
    m.emplace_back(tmp);
  }
  rep(i, q)
  {
    cin >> l >> r;
    cout << m[r - 1] - m[l - 1] << endl;
  }
}

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

int a[1001][1001];

int main(){
	int n, d;
	cin >> n >> d;
	
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= d; j++){
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		for (int x = n; x > i; x--){
			if (x != i){
				int t = 0;
				for (int j = 1; j <= d; j++){
					t += abs(a[i][j] - a[x][j]) * abs(a[i][j] - a[x][j]);
				}
				for (int j = 1; j <= t; j++){
					if (j * j == t) ans++;
				}
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    vector<ll> sum(n+1);
    rep(i,n) sum[i+1] = sum[i] + a[i];
    ll ok = 0, ng = 1e6;
    while(ng - ok > 1){
        ll mid = (ok + ng) / 2;
        ll total = 0;
        rep(i,n){
            int it = lower_bound(a.begin(), a.end(), mid-a[i]) - a.begin();
            total += n - it;
        }
        if(total >= m) ok = mid;
        else ng = mid;
    }
    ll ans = 0, cnt = 0;
    rep(i,n){
        int it = lower_bound(a.begin(), a.end(), ok-a[i]) - a.begin();
        cnt += n - it;
        ans += a[i] * (n - it) + sum[n] - sum[it];
    }
    ans -= (cnt - m) * ok;
    cout << ans << endl;
	return 0;
}

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

int main(){
	int n,k;
	char s[52];
	cin>>n>>k;
	cin>>s;
	for(int i=0;i<n;i++){
		if(i+1==k){
			printf("%c",s[i]+('a'-'A'));
		}
		else{
			cout<<s[i];
		}
	}
	cout<<endl;
	return(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
using namespace std;
int main(void){
    int n,a[100];
    double avg=0,s,ans;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        avg+=a[i];
    }
    avg/=n;
    s=abs(a[0]-avg);
    ans=0;
    for(int i=1;i<n;i++){
        if(s>abs(a[i]-avg)){
            s=abs(a[i]-avg);
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int monthNum[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	string dayName[7] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};
	int month, day, passDay=0;
	
	while (1) {
		cin >> month >> day;
		if (month == 0) break;
		
		for (int i=0; i<month; i++)
			passDay += monthNum[i];
		passDay += day-1;
		
		cout << dayName[passDay % 7] << endl;
		passDay = 0;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i] % 2 == 0) b.pb(a[i]);
    }
    int ans = 0;
    for (auto ai : b) {
        do{
            ans++;
            ai /= 2;
        }while(ai % 2 == 0);
    }
    pr(ans);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> tmp(n),a;
    for (int i = 0; i < n; i++) {
        cin >> tmp[i];
        if (tmp[i] % 2 == 0) a.push_back(tmp[i]);
    }

    for (int i = 0; i < a.size(); i++) {
        if (!(a[i] % 3 == 0 || a[i] % 5 == 0)) {
            cout << "DENIED";
            return 0;
        }
    }
    cout << "APPROVED";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if (a == b)
		cout << "Draw";
	else
	{
		if (a == 1)
			cout << "Alice";
		else if (b == 1)
			cout << "Bob";
		else if (b > a)
			cout << "Bob";
		else
			cout << "Alice";

	}
}


Measured memory_bytes: 3624
// Author: Tyler Wang

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(12);
  std::cerr.precision(12);
  std::mt19937 rng((std::uint_fast32_t)std::chrono::high_resolution_clock::now()
                       .time_since_epoch()
                       .count());
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  vector<int> dp(n, 2e9);
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= k; ++j) {
      if (i + j < n) {
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
      }
    }
  }
  cout << dp[n - 1] << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  string s; cin >> s;
  unordered_map<char, int> U;

  for (char c: s) U[c]+=1;

  bool ok = true;
  for (const auto &e : U) {
    if (e.second & 1) {
      ok = false;
      break;
    }
  }

  puts(ok ? "Yes" : "No");

  return 0;
}



Measured memory_bytes: 256
import math
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True
N = int(input())
while True:
    if is_prime(N):
        print(N)
        exit()
    N += 1


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define INF 1e15
vector< pair< long long int,long long int > >arr;
void debug(long long int a,long long int b)
{
	printf("a-%lld\nb-%lld\n",a,b);
}
int main()
{
   long long int i,j,k,ans=0,w,a=0,b,sum=0,n;
   scanf("%lld%lld",&n,&w);
   for(i=1;i<=n;i++)
   {
   	scanf("%lld%lld",&a,&b);
    arr.push_back(make_pair(a,b));
    sum+=b;
   } 
   long long int dp[n+1][sum+1]={0};
   //debug(sum,arr.size());
   a=0;
   for(i=1;i<=sum;i++)
   {
     if(arr[0].second>=i)
      dp[0][i]=arr[0].first;
    else
      dp[0][i]=INF;
   }
   for(i=1;i<n;i++)
    for(j=0;j<=sum;j++)
    {
      dp[i][j]=min(dp[i-1][j],arr[i].first+dp[i-1][max(a,j-arr[i].second)]);
    }
    //printf("ok");
    for(i=sum;i>=0;i--)
    {
      if(dp[n-1][i]<=w)
      {
        ans=i;
        break;
      }
    }
   printf("%lld\n",ans);
}


Measured memory_bytes: 79104
import Control.Applicative
import Control.Monad
import Data.List


main = do
    [h, w] <- map read . words <$> getLine
    lines <- replicateM h getLine
    mapM_ putStrLn $ solve lines

solve :: [String] -> [String]
solve = compressCol . compressRow

compressRow :: [String] -> [String]
compressRow = filter $ any (== '#')

compressCol :: [String] -> [String]
compressCol = transpose . compressRow . transpose


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
const int inf = 1e9;

string str, st = "MARCH";
int a[5];
int dfs(int s, int c, int u){
	if(s == 5){
		//if(u != 0)printf("%d\n", c);
		if(c == 3)return u;
		else return 0;
	}
	int ans = 0;
	ans += dfs(s+1, c+1, u*a[s]);
	ans += dfs(s+1, c, u);
	return ans;
}

signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,n){
		cin >> str;
		rep(j,5)if(str[0] == st[j])a[j]++;
	}
	//rep(i,5)printf("%lld\n", a[i]);
	int ans = dfs(0, 0, 1);
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

using V = vector<LL>;
using VV = vector<V>;

constexpr int mod = 1e9 + 7;
int main() {
	string S;
	cin >> S;
	LL ret = 0;
	int N = S.size();
	VV prev_link(N, V(26));
	VV next_link(N, V(26));
	V lp(26, -1), ln(26, -1);

	{
		for(int i:range(N)){
			prev_link[i] = lp;
			lp[S[i] - 'a'] = i;
		}
	}
	{
		for (int ri : range(N)) {
			const int i = N - 1 - ri;
			next_link[i] = ln;
			ln[S[i] - 'a'] = i;
		}
	}
	VV dp(N, V(N, 0));
	for(int i:range(26)) {
		if (ln[i] >= 0 && lp[i] >= 0) {
			dp[ln[i]][lp[i]]++;
			ret++;
		}
	}
	for (int l : range(N)) {
		for (int rr : range(N)) {
			const int r = N - 1 - rr;
			if (l >= r)continue;
			ret += dp[l][r];
			for (int i : range(26)) {
				int nl = next_link[l][i];
				int nr = prev_link[r][i];
				if (nl >= 0 && nr >= 0 && nl < nr) {
					(dp[nl][nr] += dp[l][r]) %= mod;
				}
				if (nl == -1 && nr == -1)continue;
				int p = max(nl, nr);
				if (l < p&&p < r) {
					ret += dp[l][r];
				}
			}
		}
	}
	cout << ret%mod << endl;
	return 0;
}



Measured memory_bytes: 35064
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
 
using int64 = int64_t;
 
constexpr int64 MOD = 1000000007;
 
string S, T;
int Q;
 
int main() {
    cin >> S >> T >> Q;
 
    int sa[101010], ta[101010];
    fill(sa, sa+101010, 0);
    fill(ta, ta+101010, 0);
 
    sa[1] = (S[0] == 'A') ? 1 : 0;
    for (int j = 2; j <= S.size(); ++j) {
        sa[j] = sa[j-1] + (S[j-1] == 'A' ? 1 : 0);
    }
 
    ta[1] = (T[0] == 'A') ? 1 : 0;
    for (int j = 2; j <= T.size(); ++j) {
        ta[j] = ta[j-1] + (T[j-1] == 'A' ? 1 : 0);
    }
 
    for (int j = 0; j < Q; ++j) {
        int w, x, y, z;
        cin >> w >> x >> y >> z; --w; --x; --y; --z;
 
        int a1 = sa[x+1] - sa[w];
        int b1 = (x-w+1) - a1;
 
        int a2 = ta[z+1] - ta[y];
        int b2 = (z-y+1) - a2;
 
        if ((a1 + 2 * b1) % 3 == (a2 + 2 * b2) % 3) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;
vvint adj;
int n,m;
int ans;
vector <bool> vis;

bool check(int s){
	for(int u : adj[s]){
		if(!vis[u]) return false;
	}
	return true;
}

void all_paths(int s){
	if(check(s)){
		bool flag = 0;
		for(int i = 0;i < n;++i){
			if(!vis[i]){
				flag = 1;
				break;
			}
		}
		if(!flag) ++ans;
		return;
	}
	else{
		for(int u : adj[s]){
			if(!vis[u]){
				vis[u] = 1;
				all_paths(u);
				vis[u] = 0;
			}
		}
	}
	return;
}

void solve(){
	cin >> n >> m;
	adj = vvint(n,vector <int> (n));
	vis = vector <bool> (n,0);
	for(int i = 0;i < m;++i){
		int u,v;
		cin >> u >> v;
		--u,--v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vis[0] = 1;
	all_paths(0);
	cout << ans << newl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 3676
#include<stdio.h>
#define N 10

int main(){
  int i;
  double a, sum;

  while(scanf("%lf", &a) != EOF){
    sum = a;

    for(i=2; i<=N; i++){
      if((i%2) == 0)
	a *= 2.0;
      else
	a /= 3.0;

      sum += a;
    }

    printf("%0.8f\n", sum);
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
using namespace std;


int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,n,m,k;
    ll t;
 string s;
 cin>>s;
 if(s[2]==s[3] && s[4]==s[5])
 {
     cout<<"Yes";
 }
 else
     cout<<"No";
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  long n,f,z,fz;
  scanf("%ld",&n);
  f=n/3;
  z=n/5;
  fz=n/15;
  printf("%ld",(n*(n+1)-f*(f+1)*3-z*(z+1)*5+fz*(fz+1)*15)>>1);
  return(0);
}


Measured memory_bytes: 1720
//****** @mdazmat9 **********
    #include<bits/stdc++.h>
    using namespace std;
    #define int long long
    #define UB upper_bound
    #define LB lower_bound
    #define BS binary_search
    #define EB emplace_back
    #define endl "\n"
    #define MOD 1000000007
    #define F first
    #define S second
    #define ALL(a) (a).begin(),(a).end()
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
    int fast_pow(int x, int y, int p);
   
    void solve() {
      int n;cin>>n;
      int a[n];
      map<int,int> mp;
      for(int i=0;i<n;i++){
        cin>>a[i];
        int num=a[i];
        int count=0;
        for(int j=2;j*j<=num;j++){
           count=0;
          while(num%j==0){
            count++;
            num/=j;
          }
          mp[j]=max(mp[j],count);
        }
        if(num!=1)
          mp[num]=max(mp[num],(int)1);
      }
    
      int lcm=1;
      for(auto x:mp){
        //cout<<x.F<<" "<<x.S<<endl;
        int temp=fast_pow(x.F, x.S, MOD);
        lcm=(lcm*temp)%MOD;
      }
      //cout<<lcm<<endl;
      int ans=0;
      for(int i=0;i<n;i++){
        int temp=fast_pow(a[i],  MOD-2, MOD);
        temp=(lcm*temp)%MOD;
        ans+=temp;
        ans%=MOD;
      }
      cout<<ans<<endl;
      
    }
     
    int32_t main()
    {
    IOS;
    int test=1;
    // cin>>test;
    while(test--){
    solve();
    }
    return 0;
    }
    int fast_pow(int x, int y, int p)
    {
    int res = 1;
    x = x % p;
    while (y > 0)
    {
    if (y & 1)
    res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
    }
    return res;
    }

Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 100000

int partition(int *, int, int);

int A[MAX];
int n;

int main(){
  int i, j;
  int q;
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  
  q = partition(&A[0], 0, n-1);
  for(i=0; i<n-1; i++){
    if(i == q){
      printf("[%d] ", A[i]);
    } else{
      printf("%d ", A[i]);
    }
  }
  printf("%d\n", A[i]);
  return 0;
}

int partition(int *A, int p, int r){
  int i, j;
  int x, tmp;
  x = A[r];

  i = p-1;
  for(j=p; j<r; j++){
    if(A[j] <= x){
      i = i + 1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;

  
  return i+1;
}



Measured memory_bytes: 2244
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] str = Console.ReadLine().Split(' ');
            long A = long.Parse(str[0]);
            long B = long.Parse(str[1]);
            long X = long.Parse(str[2]);
            long ans = 0;

            if (A != 0) { 
               ans = ((B / X) - ((A-1) / X));
            }
            else
            {
                ans = (B / X) + 1;
            }
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 13140