akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const int N = 500500;
int n,q,b[N][27];
char s[N];

void update(int pos,int tipo,int val){
    for(;pos<N;pos+=pos&-pos){
        b[pos][tipo]+=val;
    }
}

int soma(int pos,int tipo){
    int ans = 0;
    for(;pos>0;pos-=pos&-pos){
        ans+=b[pos][tipo];
    }
    return ans;
}

signed main(){
    IOS;
    cin >> n;
    for(int i = 1;i<=n;i++){
        cin>>s[i];
        update(i,s[i]-'a',1);
    }
    cin >> q;
    while(q--){
        int type;
        cin >> type;
        if(type == 1){
            int pos;
            char c;
            cin >> pos >> c;
            update(pos,s[pos]-'a',-1);
            s[pos]=c;
            update(pos,s[pos]-'a',1);
        }
        else{
            int l,r,res=0;
            cin >> l >> r;
            rep(i,0,26){
                if(soma(r,i)-soma(l-1,i) > 0) res++;
            }
            cout << res << "\n";
        }
    }
}

Measured memory_bytes: 106240
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M,K=map(int,input().split())
uf=UnionFind(N)

friends=[]
for _ in range(M):
    a,b=map(int,input().split())
    uf.union(a-1,b-1)
    friends.append((a,b))

blocks=[]
for _ in range(K):
    blocks.append(list(map(int,input().split())))

ans=[uf.size(i)-1 for i in range(N)]
for a,b in friends:
    if uf.same(a-1,b-1):
        ans[a-1]-=1
        ans[b-1]-=1
for c,d in blocks:
    if uf.same(c-1,d-1):
        ans[c-1]-=1
        ans[d-1]-=1
print(*ans)



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

#define YES "Yes"
#define NO "No"

#define TSURU 2
#define KAME 4

int main()
{
    int obj_num, leg_num, diff;

    scanf("%d %d", &obj_num, &leg_num);

    diff = leg_num - (obj_num*2);

    if (((diff%2) == 0)&&((0 <= diff)&&((diff/2) <= obj_num)))
    {
        printf("%s", YES);
    } else {
        printf("%s", NO);
    }

    return 0;
}

Measured memory_bytes: 1712
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
mod = 998244353

n,s = map(int,readline().split())
a = list(map(int,readline().split()))
d = np.zeros(3001, np.int64)
d[0] = 1
for i in a:
  dd = [0]*i + list(d)
  d = d*2
  d += dd[:3001]
  d %= mod
print(d[s])

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

using namespace std;

int main()
{
    int a, b, c;

    cin>>a>>b;

    if((a>=1 && a<=9) && (b>=1 && b<=9)){
        cout<<a*b<<endl;
    }
    else
        cout<<"-1"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() 
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int x,count(0);
		cin >> x;
		
		while(x>9)
		{
			int a,b,y(1),max(0);
			for(int i=1;i<7;i++)
			{
				a = x/y;
				b = x%y;
				if(a*b > max){ max=a*b; }
				y*=10;
			}
			x=max;
			count++;
		}
		cout << count << endl;
	}
	return 0 ;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
    ll n,m;
    cin>>n>>m;
    vi edge[n];
    rep(i,m){
        int a,b;cin>>a>>b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> dist(n, -1);
    
    queue<int> que;
    
    dist[0] = 0, que.push(0);

    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : edge[v]) {
            if (dist[nv] == -1) {
                dist[nv] = v+1;
                que.push(nv);
            }
        }
    }
    bool f =true;

    rep(i,n){
        if(dist[i]==-1)f=false;
    }

    if(!f){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    rep(i,n-1){
        cout<<dist[i+1]<<endl; 
    }
    }
}

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

int main(){
  int s[5];
  for(int i=0;i<5;i++){
    cin >> s[i];
  }
  
  int mini = 10;
  for(int i=0;i<5;i++){    
   if(s[i]%10 != 0){
     mini = min(s[i] % 10,mini);
   }
  }
  int sum = 0;
  for(int i=0;i<5;i++){
    if(s[i]%10 == 0){
      sum += s[i];
    }else{
      sum += s[i] + (10 - s[i]%10);
    }
  }
  int ans = sum - 10 + mini;
  cout << ans << endl;
}

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

#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define all(v) (v.begin(),v.end())
#define ll long long

const int N=105;
const int inf=2e9;

int a[N];
int g[N][N];

ll ek(int s,int t){
    ll ans=0;
    while(1){
        queue<int>q;
        q.push(s);
        vector<int>pre(t+1,-1);
        vector<int>vis(t+1,0);
        vis[s]=1;
        while(!q.empty()){
            int u=q.front();
            q.pop();
            //vis[u]=0;
            //cout<<"u"<<u<<endl;
            for(int i=0;i<=t;++i){
                if(!vis[i]&&g[u][i]>0){
                    vis[i]=1;
                    pre[i]=u;
                    q.push(i);
                }
            }
        }
        if(pre[t]==-1) break;
        int tmp=inf;
        for(int i=t;i!=s;i=pre[i]){
            tmp=min(tmp,g[pre[i]][i]);
        }
        for(int i=t;i!=s;i=pre[i]){
            g[pre[i]][i]-=tmp;
            g[i][pre[i]]+=tmp;
        }
        ans+=tmp;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(0);
    //freopen("in.txt","r",stdin);
    int n,s,t;
    ll ans=0;
    cin>>n;
    s=0;
    t=n+1;
    rep(i,1,n+1){
        cin>>a[i];
        if(a[i]>0) ans+=a[i];
    }
    memset(g,0,sizeof(g));
    rep(i,1,n+1){
        if(a[i]<=0){
            g[s][i]=-a[i];
            g[i][s]=0;
        }
        else if(a[i]>0){
            g[i][t]=a[i];
            g[t][i]=0;
        }
        for(int j=i*2;j<=n;j+=i){
            g[i][j]=inf;
            g[j][i]=0;
        }
    }
    ll tmp=ek(s,t);
    cout<<ans-tmp;
    return 0;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T>
T vec_min(V<T> v){return *min_element(ALL(v));}

template<typename T>
T vec_max(V<T> v){return *max_element(ALL(v));}

int main(){
    int N,M,X,Y;
    cin>>N>>M>>X>>Y;
    Vi x(N),y(M);
    REP(i,N) cin>>x[i];
    REP(i,M) cin>>y[i];
    x.pb(X);
    y.pb(Y);

    int x_max = vec_max(x);
    int y_min = vec_min(y);

    if(x_max<y_min){
        cout<<"No War"<<endl;
    }else{
        cout<<"War"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
K = int(input())
A = list(map(int,input().split()))
M,m = 2,2
A = reversed(A)
for i in A:
    M = (M//i)*i+(i-1)
    m = math.ceil(m/i)*i
    if m > M:
        print(-1)
        exit()
print(m,M)

Measured memory_bytes: 15020
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
int V,E;
vector<int> g[100100];
int dep[100100],low[100100],ord[100100];
int cnt = 0;
void dfs(int v,int p,int d){
    dep[v] = d;
    ord[v] = cnt++;
    low[v] = ord[v];
    for(int i=0;i<g[v].size();i++){
        if(g[v][i]==p)continue;
        int ch = g[v][i];
        if(ord[ch]==-1){
            dfs(ch,v,d+1);
            low[v] = min(low[v],low[ch]);
        }else{
            low[v] = min(low[v],ord[ch]);
        }
    }
}
int main(){
    scanf("%d %d",&V,&E);
    vector<P> es(E);
    for(int i=0;i<E;i++){
        int s,t;
        scanf("%d %d",&s,&t);
        s--;t--;
        g[s].pb(t);
        g[t].pb(s);
        if(s>t)swap(s,t);
        es[i]=P(s,t);
    }
    memset(ord,-1,sizeof(ord));
    dfs(0,-1,0);
    vector<P> ans;
    for(int i=0;i<E;i++){
        int s = es[i].fi,t = es[i].sec;
        if(dep[s]>dep[t])swap(s,t);
        if(ord[s]<low[t])ans.pb(es[i]);  
    }
    sort(all(ans));
    cout << ans.size() << endl;
   // for(int i=0;i<ans.size();i++)printf("%d %d\n",ans[i].fi,ans[i].sec);
    return 0;
}

Measured memory_bytes: 2944
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int N;

void dfs(const string& S, int v, int k) {
  if (k ==  N) {
    cout << S << endl;
    return;
  }

  ++k;
  for (int i = 0; i <= v; ++i) {
    char c = 'a' + i;
    dfs(S + c, v, k);
  }
  ++v;
  char c = 'a' + v;
  dfs(S + c, v, k);
}

int main() {
  cin >> N;
  dfs("a", 0, 1);
}


Measured memory_bytes: 1536
using System;
using System.Linq;
using System.Collections.Generic;

namespace Atcoder
{
    class Program2
    {
        public static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());
            if (s == 1||s==2)
            {
                Console.WriteLine(4);
                return;
            }
            int n = s;
            int count = 1;
            while (n != 1)
            {
                if (n % 2 == 0)
                {
                    n = n / 2;
                    count++;
                }
                else
                {
                    n = 3 * n + 1;
                    count++;
                }
            }
            Console.WriteLine(count + 1);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define pb push_back
#define long long long
#define pll pair < long , long >
#define vll vector < pll >
#define ml map < long , long >
#define mll map < pll , long >
#define x first
#define y second
#define vl vector < long >
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
long n,t[105],v[105],i,curv,s=0,g[20005],p[105]={0},j,ans=0,c=0,cc=0,h[20005];
int main()
{
    io
    cin>>n;
    for(i=1;i<=n;++i)
    cin>>t[i],s+=t[i],p[i]=(i?p[i-1]:0)+t[i];
    for(i=0;i<=s;++i)
    g[i]=1e9;
    v[0]=0;
    for(i=1;i<=n;++i)
    cin>>v[i];
    v[n+1]=0;
    p[0]=0;
    p[n+1]=p[n];
    for(i=0;i<=s;++i)
    {
        for(j=0;j<=n;++j)
        {
            if(i>=p[j] && i<=p[j+1])
            g[i]=min(g[i],v[j+1]),h[i]=v[j+1];
            long vv=min(v[j],v[j+1]);
            if(i>=p[j])
            g[i]=min(g[i],vv+i-p[j]);
            if(i<p[j])
            g[i]=min(g[i],vv+p[j]-i);
        }
    }
    for(i=0;i<=s;++i)
    {
        ans+=g[i];
        if(g[i+1]<g[i]) c--;
        else if(g[i+1]>g[i]) c++;
        else if(g[i]!=h[i]) cc++;
    }
    double tt=ans,gg=c,ggg=cc;
    cout<<fixed<<setprecision(15)<<tt+gg/2+ggg/4;
    return 0;
}


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

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  string s;
  int dx = x2 - x1;
  int dy = y2 - y1;
  for(int i=0; i<dy; ++i) s += 'U';
  for(int i=0; i<dx; ++i) s += 'R';
  for(int i=0; i<dy; ++i) s += 'D';
  for(int i=0; i<dx+1; ++i) s += 'L';
  for(int i=0; i<dy+1; ++i) s += 'U';
  for(int i=0; i<dx+1; ++i) s += 'R';
  s += "DR";
  for(int i=0; i<dy+1; ++i) s += 'D';
  for(int i=0; i<dx+1; ++i) s += 'L';
  s += 'U';
  cout << s << endl;
}

Measured memory_bytes: 3632
/* An ACEASH Source code  */
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double

#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>

#define vvi vector< vector < int > >
#define vvl vector< vector < ll > >

#define pii pair< int , int >
#define pll pair< ll , ll >

#define vpl vector< pll >
#define vpi vector< pii >

#define MOD 1000000007

#define mp make_pair
#define pb push_back

#define sare(v) (v).begin(),(v).end()

#define F first
#define S second

#define tez  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ld pie = 3.1415926535897932384626 ;

int main()
{
    int x,ans;
    cin>>x;
    if(x) ans=0;
    else ans=1;
    cout<<ans<<"\n";
    return 0;
}




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

int main()
{
	int A, B, X;

	cin >> A; 
	cin >> B;

	if (A >= B) {
		X = A;
		if ((A - 1) >= B) {
			X = X + (A - 1);
		}
		else {
			X = X + B;
		}
	}
	else {
		X = B;
		if ((B - 1) >= A) {
			X = X + (B - 1);
		}
		else {
			X = X + A;
		}
	}

    cout << X << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
		}
		sc.close();

		int mod = 1000000007;
		int m2 = 1000000008 / 2;
		Arrays.sort(c);
		long ans = 0;
		long base = 0;
		long d = 1;
		long time = power(2, n, mod);
		long total = time;
		for (int i = 0; i < n; i++) {
			base = base * 2 + d;
			base %= mod;
			if (i != 0) {
				d *= 2;
				d %= mod;
			}
			time *= m2;
			time %= mod;
			long val = base * time % mod;
			val = val * c[n - 1 - i] % mod * total % mod;
			ans += val;
			ans %= mod;
		}
		System.out.println(ans);
	}

	static long power(long x, long n, int m) {
		if (n == 0) {
			return 1;
		}
		long val = power(x, n / 2, m);
		val = val * val % m;
		if (n % 2 == 1) {
			val = val * x % m;
		}
		return val;
	}
}


Measured memory_bytes: 65072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
ll cnt = 0;
void insertionSort(ll A[], ll N, ll G){
    rep(i,G,N){
        ll v = A[i];
        ll j = i - G;
        while(j >= 0 && A[j] > v){
            A[j+G] = A[j];
            j -= G;
            cnt++; 
        }
        A[j+G] = v;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[1000010];
    rep(i,0,N) cin >> A[i];
    vector<ll> G;
    ll M = 0;
    ll v = 1;
    while(v <= N){
        G.push_back(v);
        v = 3 * v + 1;
        M++;
    }
    sort(G.begin(), G.end(), greater<ll>());
    print(M);
    printa(G, M);
    rep(i,0,M){
        insertionSort(A, N, G[i]);
    }
    print(cnt);
    rep(i,0,N) print(A[i]);


}


Measured memory_bytes: 10880
package main

import (
	"fmt"
	"math"
	"sort"
)

type Entry struct {
	prime int64
	count int64
}

type Entries []Entry

func (es Entries) Len() int {
	return len(es)
}

func (es Entries) Less(i, j int) bool {
	return es[i].count > es[j].count
}

func (es Entries) Swap(i, j int) {
	es[i], es[j] = es[j], es[i]
}

func main() {
	var n, p int64
	fmt.Scanf("%d %d\n", &n, &p)

	primeLimit := int64(math.Sqrt(float64(p)))
	allPrimes := listPrimes(primeLimit)
	entries := countPrimes(p, allPrimes)

	sort.Sort(Entries(entries))

	factor := int64(1)
	for _, e := range entries {
		if e.count >= n {
			// v := e.prime * (e.count / n)
			v := int64(math.Pow(float64(e.prime), float64(e.count/n)))
			factor *= v
		}
	}

	fmt.Println(factor)
}

func countPrimes(n int64, allPrimes []int64) []Entry {
	es := []Entry{}

	for _, p := range allPrimes {
		if p*p > n {
			break
		}
		cnt := int64(0)
		for n%p == 0 {
			cnt += 1
			n /= p
		}
		if cnt > 0 {
			es = append(es, Entry{p, cnt})
		}
	}
	if n > 1 {
		es = append(es, Entry{n, 1})
	}

	return es
}

func listPrimes(limit int64) []int64 {
	ns := make([]int64, limit-1)
	for i := int64(2); i <= limit; i++ {
		ns[i-2] = i
	}

	divided := make([]bool, limit+1)

	ps := make([]int64, 0)
	for _, n := range ns {
		if divided[n] {
			continue
		}
		ps = append(ps, n)
		for i := n; i < int64(len(divided)); i += n {
			divided[i] = true
		}
	}

	return ps
}


Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	LL n, d;
	cin >> n >> d;
	V<LL> x(n), y(n);
	REP(i, n) {
		cin >> x[i] >> y[i];
	}

	int ans = 0;
	REP(i, n) {
		LL tmp = x[i] * x[i] + y[i] * y[i];
		if (tmp <= d * d) {
			ans++;
		}
	}
	col(ans);
	return 0;
}

Measured memory_bytes: 6348
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int s[]=new int[n];
        for(int i=0;i<n;i++) s[i]=sc.nextInt();
        int q=sc.nextInt();
        int cnt=0;
        if(n<10){
            for(int i=0;i<q;i++){
                int t=sc.nextInt();
                for(int j=0;j<n;j++){
                    if(t==s[j]){
                        cnt++;
                        break;
                    }
                }
            }
        }else{
            for(int j=0;j<q;j++){
                int t=sc.nextInt();
                if(t>s[n/2]){
                    for(int k=n/2+1;k<n;k++){
                        if(t==s[k]){
                            cnt++;
                            break;
                        }
                    }
                }else{
                    for(int k=0;k<=n/2;k++){
                        if(t==s[k]){
                            cnt++;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 69396
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int[] dy = { -1, -1, -1, 0, 0, 1, 1, 1 };
		int[] dx = { -1, 0, 1, -1, 1, -1, 0, 1 };
		char[][] map = new char[8][8];
		for (int i = 0; i < 8; i++)
			map[i] = scanner.next().toCharArray();
		while (true) {
			boolean flag = false;
			for (int i = 0; i < 2; i++) {
				char my, en;
				if (i == 0) {
					my = 'o';
					en = 'x';
				} else {
					my = 'x';
					en = 'o';
				}
				int cnt = 0;
				int cx = 0, cy = 0, dr = 0;
				for (int y = 0; y < 8; y++)
					for (int x = 0; x < 8; x++) {
						int hy = i == 0 ? y : 7 - y;
						int hx = i == 0 ? x : 7 - x;
						if (map[hy][hx] != '.')
							continue;
						int cc = 0;
						int cdr = 0;
						for (int j = 0; j < 8; j++) {
							int c = 0;
							while (true) {
								int ny = hy + dy[j] * (c + 1);
								int nx = hx + dx[j] * (c + 1);
								if (nx < 0 || 8 <= nx || ny < 0 || 8 <= ny)
									break;
								if (map[ny][nx] == en) {
									c++;
									continue;
								} else if (map[ny][nx] == my && c != 0) {
									cc += c;
									cdr |= (1 << j);
								}
								break;

							}
						}
						if (cc <= cnt)
							continue;
						cx = hx;
						cy = hy;
						dr = cdr;
						cnt = cc;
					}
				if (cnt > 0) {
					flag = true;
					map[cy][cx] = my;
					for (int j = 0; j < 8; j++) {
						if ((dr & (1 << j)) != 0) {
							for (int k = 1; true; k++) {
								int nx = cx + dx[j] * k;
								int ny = cy + dy[j] * k;
								if (map[ny][nx] == my)
									break;
								map[ny][nx] = my;
							}
						}
					}
				}

			}
			if (!flag)
				break;

		}
		for (int i = 0; i < 8; i++)
			System.out.println(String.valueOf(map[i]));
	}
}

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

using namespace std;

typedef long long int ll;

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

  int n;
  cin >> n;
  vector < int > a (n + 2);
  for (int i = 1; i <= n; i++) cin >> a[i];
  a[0] = 200;
  a[n + 1] = 0;

  ll cash = 1000, stock = 0;
  for (int i = 1; i <= n; i++) {
    // buy.
    if (a[i] <= a[i - 1] && a[i] < a[i + 1]) {
      ll stk = cash / a[i];
      stock += stk;
      cash -= stk * a[i];
    }
    //sell
    if (a[i] >= a[i - 1] && a[i] > a[i + 1]) {
      cash += stock * a[i];
      stock = 0;
    }
  }

  cash += stock * a[n];

  cout << cash << '\n';
}


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

int main()
{
  ll n;
  string s;
  
  ll b=0, w =0;
  cin >> n >> s;
  
  for (int i=0; i<n; i++) {
    if (s[i] == '#')
      b++;
    else
      w++;
  }
  ll ans = min(b,w);
  ll lb=0, lw=0;
  
  for (int i=0; i<n; i++) {
    if (s[i] == '#')
    {
      lb++;
      b--;
    }
    else {
      lw++;
      w--;
    }
    ans = min(lb+w, ans);
  }
  cout << ans << endl;
  return 0;
}
  

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

int main() {
  int H,W;
  cin >> H >> W;
  for(int i=0; i<=W+1; i++){
    if(i == W+1){
      cout << "#" << endl;
    }
    else{
    cout << "#";
    }
  }
  for(int i=0; i<H; i++){
    string S;
    cin >> S;
    cout << "#" << S << "#" << endl;
  }
    for(int i=0; i<=W+1; i++){
    if(i == W+1){
      cout << "#" << endl;
    }
    else{
    cout << "#";
    }
  }
}


Measured memory_bytes: 3560
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);i--)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n,k;
  cin >> n >> k;
  
  cout << max(0LL,n-k+1) << endl;

  return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
	int x[3];
	for (int i = 0; i < 3; i++)cin >> x[i];
	sort(x, x + 3);
	cout << x[0] << ' '<< x[1] << ' ' << x[2] << endl;
}


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

int dp[2][10001];
int v[100], w[100];

int main() {
  int N, W;
  cin >> N >> W;
  for (int i = 0; i < N; i++) cin >> v[i] >> w[i];
  for (int i = 1; i <= N; i++) {
    int cur = i % 2, ref = 1 ^ cur;
    for (int j = 0; j <= W; j++) {
      dp[cur][j] = dp[ref][j];
      if (j >= w[i - 1])
        dp[cur][j] = max(dp[cur][j], dp[cur][j - w[i - 1]] + v[i - 1]);
    }
  }
  cout << dp[N % 2][W] << endl;
}



Measured memory_bytes: 3184
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int N;
	vector<int> member(100002, 0);
	cin >> N;
	REP(i, 0, N) {
		int a, b;
		cin >> a >> b;
		member[a-1]++;
		member[b]--;
	}
	REP(i, 0, 100001) member[i + 1] += member[i];

	int ans = 0;
	REP(i, 0, 100002) {
		if (member[i] >= i) ans = max(ans, i);
	}

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

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

set<int> st;
int a[21];
int main(){
    int n,q,mi;
    cin>>n;
    rep(i,n) cin>>a[i];
    rep(i,1<<20){
        int sum=0;
        rep(j,20)if((i>>j)&1) sum+=a[j];
        st.insert(sum);
    }
    cin>>q;
    rep(i,q){
        cin>>mi;
        if(st.count(mi)>0) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3128
#include<stdio.h>
int main(void)
{
  int x, y, a, X, Y;

  while(scanf("%d %d", &x, &y)!=EOF)
    {
  if (y > x)
    {
      a=x;
      x=y;
      y=a;
    }

  X=x;
  Y=y;
  x=x%y;

  while (x!=0)
    {
      a=x;
      x=y;
      y=a;
      x=x%y;
    }
  a=X/y*Y;
  printf("%d %d\n",y,a);

    }
  return 0;

}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,h,w;
    cin>>n>>h>>w;
    if(n<h || n<w)
        cout<<"0\n";
    else
    {
        int x=(n-h+1)*(n-w+1);
    cout<<x<<"\n";
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int cnt[30]={0};
bool flag=false;
bool v[30]={0};
int res=-1;
void find(int x)
{
	if(x==13)
	{
		int a=24;
		for(int i=0;i<24;i++)
			for(int j=i+1;j<24;j++)
				if(v[i]&&v[j])
					a=min(a,min(j-i,24-j+i));
		res=max(a,res);
		return;
	}
	if(cnt[x]==2) 
	{
		v[x]=v[24-x]=1;
		find(x+1);
	}
	else if(cnt[x]==1)
	{
		v[x]=1;
		find(x+1);
		v[x]=0;
		if(x)
		{
			v[24-x]=1;
			find(x+1);
			v[24-x]=0;
		}
	}
	else find(x+1);
}
int main()
{
	int n,m;
	scanf("%d",&n);
	cnt[0]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&m);
		cnt[m]++;
		if(cnt[m]>2) flag=true;
	}
	if(flag||cnt[0]>1||cnt[12]>1)
	{
		cout<<0;
		return 0;
	}
	else
	{
		find(0);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define wzh(x) cerr<<#x<<' '<<x<<endl
int n;
char a[N];
LL pm(LL x,LL y,LL z){
	LL q=1;
	while(y){
		if(y&1)q=q*x%z;
		x=x*x%z;
		y>>=1;
	}
	return q;
}
int f[N][2];
int s[N][2];
void gao(int x){
	if(!x){
		cout<<1<<'\n';
		return ;
	}
	int ans=1;
	while(x){
		x%=__builtin_popcount(x);
		//cout<<x<<endl;
		ans++;
	}
	cout<<ans<<'\n';
	return ;
}
int main() {
  ios::sync_with_stdio(false);
//111 001 010
  cin>>n>>a+1;int sz=0,pos;
  for(int i=1;i<=n;i++){
  	sz+=a[i]=='1';
  	if(a[i]=='1')pos=i;
  }
 	//sz+1 or sz-1
  if(sz==0){
  	for(int i=1;i<=n;i++){
  		cout<<1<<'\n';
  	}
  	return 0;
  }
  if(sz==1){
  	int x=pm(2,n-pos+1,2);
  	for(int i=1;i<=n;i++){
  		if(a[i]=='1')cout<<0<<'\n';
  		else{
  			gao((x+pm(2,n-i,2))%2);
  		}
  	}
    return 0;
  }
  for(int i=1;i<=n;i++){
  	f[i][0]=(a[i]-'0')*pm(2,n-i,sz-1);
  	s[i][0]=(s[i-1][0]+f[i][0])%(sz-1);
  	f[i][1]=(a[i]-'0')*pm(2,n-i,sz+1);
  	s[i][1]=(s[i-1][1]+f[i][1])%(sz+1);
  }
  LL pre=0;
  for(int i=1;i<=n;i++){
  	pre=(pre+(a[i]-'0')*pm(2,n-i,sz+1))%(sz+1);
  	if(i==n)pre=(pre+pm(2,n-i,sz+1))%(sz+1);
  	//cout<<i<<' '<<pre<<endl;
  }
  //cout<<pre<<endl;
 	for(int i=1;i<=n;i++){
 		if(a[i]=='1'){
 			//sz-1
 			int go=(s[n][0]-pm(2,n-i,sz-1)+sz-1)%(sz-1);
 			gao(go);
 		}else{
 			int go=(s[n][1]+pm(2,n-i,sz+1))%(sz+1);
 			gao(go);
 		}
 	}
 	return 0;
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int a,b,t;
  cin >> a >> b >> t;
  cout << t/a*b << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile

INF = float("inf")


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    N = readi()
    x = readi(N, 3)
    dp = arr(N + 1, 3)
    for i in range(N):
        for j in range(3):
            dp[i + 1][j] = max(
                dp[i + 1][j], dp[i][(j + 1) % 3] + x[i][j], dp[i][(j + 2) % 3] + x[i][j]
            )
    print(max(dp[N]))


if __name__ == "__main__":
    main()


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

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

    int n, ans = 1;
    cin >> n;

    for (int i = 2; i < 10; i++) {
        if (ans * 2 > n)
            break;
        ans *= 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

constexpr int MOD = 998244353;
struct mint
{
	int v;
	mint():v(0){}
	mint(int v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(int k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(int n, int k) {
		if(n-k<k) k=n-k;
		mint num(1), dom(1);
		for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; }
		return num/dom;
	}
};
std::istream& operator>>(std::istream&i,mint&a){ int t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


signed main() {
	int n;
	std::cin >> n;
	std::vector<int> d(n);
	std::map<int,int> map;
	int max = 0;
	rep(i,n) {
		int x;
		std::cin >> x;
		d[i] = x;
		map[x]++;
		max = std::max(max,x);
	}
	if(d[0]!=0) {
		print(0);
		return 0;
	}
	if(map[0]!=1) {
		print(0);
		return 0;
	}
	mint sum = 1;
	for(int i=1;i<=max;i++) {
		sum *= mint(map[i-1]).pow(map[i]);
	}
	print(sum);

	return 0;
}


Measured memory_bytes: 7296
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>

using namespace std;
typedef long long LL;
const int maxn = 1000005;
const int mod = 1e9+7;

LL dp[maxn],s[maxn],ans;int n;
int main()
{
	#ifdef Amberframe
		freopen("arc071f.in","r",stdin);
		freopen("arc071f.out","w",stdout);
	#endif
	
	scanf("%d",&n);
	dp[0]=s[0]=1;ans=1;
	for (int i=1;i<=n;i++) {
		dp[i]=((i>=3?s[i-3]:0)+dp[i-1])%mod;
		s[i]=(s[i-1]+dp[i])%mod;
	}
	LL w=(LL)(n-1)*(n-1)%mod;
	for (int i=1;i<=n;i++) {
		if (i>=4) ans=(ans+s[i-4])%mod;
		if (i==n) {
			ans=(ans+dp[i-1]*(n-1))%mod;
		}
		else if (i==n-1) {
			ans=(ans+dp[i-1]*(n-1))%mod;
			ans=(ans+dp[i-1]*w)%mod;
		}
		else {
			ans=(ans+dp[i-1]*(LL)(i+1))%mod;
			ans=(ans+dp[i-1]*w)%mod;
		}
	}
	printf("%lld",ans);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int H,W;
    while(true){
        cin >> H >> W;
        if(H==0 && W==0) break;
        for(int h=1;h<=H;h++){
            for(int w=1;w<=W;w++){
                cout << (((h+w)%2)?'.':'#');
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3084
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
L = sorted(iil())

if 2*L[-1] < sum(L):
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b;
int main()
{
    cin>>a>>b;
    if(a==b)return puts("1"),0;
    int r,k;
    for(r=60;(a&(1LL<<r))==(b&(1LL<<r));r--);
    a&=(1LL<<(r+1))-1;b&=(1LL<<(r+1))-1;
    ll ans=(1LL<<r+1)-a;
    for(k=r-1;k>=0&&!(b&(1LL<<k));k--);
    if(a>(1LL<<k+1))ans-=a-(1LL<<k+1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_num(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
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; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)


int a, b, c, d, e, f;

int main() {
	cin >> a >> b >> c >> d >> e >> f;
	c += b * 100;
	f += e * 100;
	if (a<d) cout << (f>c ? d - a + 1 : d - a) << endl;
	else if (a>d) cout << (f<c ? a - d + 1 : a - d) << endl;
	else cout << (f == c ? 0 : 1) << endl;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define int long long 
#define ld long long double
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int cPF(int x) 
{ 
    int re = 0; 
    if (x % 2 == 0) 
	{ 
        re++; 
        while (x % 2 == 0) 
            x = x / 2; 
    } 
    for (int i = 3; i <= sqrt(x); i = i + 2) 
	{ 
        if (x % i == 0) 
		{ 
            re++; 
            while (x % i == 0) 
                x = x / i; 
        } 
    }  
    if (x > 2) 
        re++; 
    return re; 
} 
int countCommonPrimeFactors(int a, int b) 
{ 
    int gc = __gcd(a, b); 
    return cPF(gc); 
}
int32_t main() 
{
	FAST
	int a,b;
	cin>>a>>b;
	cout<<countCommonPrimeFactors(a, b)+1; 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool OperationFA( int *an , int n ){
	bool ret = true;
	int *cn = new int[n];
	
	for(int i = 0; i < n; i++){
		int mode = 0;
		for(int j = 0; j < n; j++){
			if( an[j] == an[i] ) mode++;
		}
		cn[i] = mode;
	}
	for(int i = 0; i < n; i++){
		if( an[i] != cn[i] ) ret = false;
		an[i] = cn[i];
	}
	delete []cn;
	return ret;
}
int main(void){
	while( true ){
		int n;
		int cnt = 0;
		int *an;

		cin >> n;
		if( n == 0 ) break;
		an = new int[n];

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

		while ( true ){
			if( OperationFA( an, n ) ) break;
			cnt++;
		}

		cout << cnt << '\n';
		cout << an[0];
		for(int i = 1; i < n; i++){
			cout << ' ' << an[i];
		}
		cout << '\n';
		delete []an;
	}
	return 0;
}

Measured memory_bytes: 0
/*input
5
1 2 3 4 5


*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 998244353;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

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


template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
    int x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

  string str;
  cin >> str;
  int o = count(all(str), 'o');
  if (o + (15 - str.size()) >= 8) cout << "YES" << endl;
  else cout << "NO" << endl;


  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
char a[2][3];
int main()
{
	int i, j;
	for(i = 1; i <= 2; i++)
	{
    	for(j = 1; j <= 3; j++)
    	{
			scanf(" %c", &a[i][j]);
	    }
	}
    if( a[1][1]==a[2][3] && a[1][3]==a[2][1] && a[1][2]==a[2][2])
    	printf("YES\n");
	else
 	    printf("NO\n");
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
const int dx[]={1,0,-1,0,1,-1,-1,1}; 
const int dy[]={0,1,0,-1,1,1,-1,-1}; 
const int INF = 1e9; 
const long long LINF = 1e18; 
const double EPS = 1e-8; 
#define pb push_back 
#define mk make_pair 
#define fr first 
#define sc second 
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); ++i) 
#define rep(i,j) reps(i,0,j) 
#define all(a) (a).begin(),(a).end() 
#define MOD 1000000007 
typedef pair<int,int> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;

int main(){
    string s;
    cin >> s;
    
    bool flg = true;
    rep(i,s.size()){
        //cout << "HOGE " << i << endl;
        if(s[i] != 'd' && s[i] != 'e'){
            flg = false;
            break;
        }
        if(i+4 >= s.size()){
            flg = false;
            break;
        }
        
        string f;
        f = "#####";
        reps(j,i,i+5){
            f[j-i] = s[j];
            if(j == i+4){
                i = j+1;
                break;
            }
        }
        if(f != "dream" && f != "erase"){
            flg = false;
            break;
        }
        //cout <<"idx : "<< i << endl;
        //cout << f << endl;
        
        
        
        if(f == "dream" && s[i] == 'e' && s[i+1] == 'r' && s[i+2] == 'a'){
            --i;
            continue;
            
        }
        else if(f == "dream" && s[i] == 'e' && s[i+1] == 'r'){
            --i;
            i += 2;
            continue;
        }
        else if(f == "erase" && s[i] == 'r'){
            --i;
            ++i;
            continue;
        }
        else{
            --i;
            continue;
        }
    }
    
    
    flg?puts("YES"):puts("NO");
    
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
  int a = 0;
  int b = 0;
  scanf("%d",&a);
  scanf("%d",&b);
  if (a == 1){
    a = 14;
  }
  if (b == 1){
    b = 14;
  }
  if (a < b){
    printf("Bob");
  }else if(a > b){
    printf("Alice");
  }else{
    printf("Draw");
  }
  return 0;
}
	

Measured memory_bytes: 128