akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
    int A,B,N;
    cin >> A >> B >> N;
    for(int i=0;i<N;i++){
        int a,b;
        cin >> a >> b;
        if(b <= A || a >= B){}
        else{
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}


Measured memory_bytes: 3100
#!/usr/local/bin/ruby
a=0
sum=0
def f(x)
   return x*x
end
while line=gets
   d=line.to_i
   for i in 0..(600-2*d)/d
      a=a+d
      sum+=f(a)
   end
   ans=sum*d
   puts "#{ans}"
   a,ans,sum=0,0,0
end

Measured memory_bytes: 6084
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = Integer.parseInt(sc.next());
        int g = Integer.parseInt(sc.next());

        int[] p = new int[d];
        int[] c = new int[d];
        for (int i = 0; i < d; i++) {
            p[i] = Integer.parseInt(sc.next());
            c[i] = Integer.parseInt(sc.next());
        }

        int res = Integer.MAX_VALUE;

        for (int i = 0; i < 1 << d; i++) {
            int count = 0;
            int point = 0;
            for (int j = 0; j < d; j++) {
                if ((1 & i >> j) == 1) {
                    count += p[j];
                    point += c[j] + p[j] * (j + 1) * 100;
                }
            }
            if (point < g) {
                for (int j = d - 1; j >= 0; j--) {
                    if ((1 & i >> j) == 1) {
                        continue;
                    }
                    for (int k = 0; k < p[j]; k++) {
                        if (g <= point) {
                            break;
                        }
                        point += (j + 1) * 100;
                        count++;
                    }
                }
            }
            if (g <= point) {
                res = Math.min(res, count);
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 22608
#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace yspm{
	inline int read()
	{
		int res=0,f=1; char k;
		while(!isdigit(k=getchar())) if(k=='-') f=-1;
		while(isdigit(k)) res=res*10+k-'0',k=getchar();
		return res*f;
	}
	const int N=3e5+10;
	struct node{
		int to,nxt,dis;
	}e[N<<1];
	int head[N],cnt;
	inline void add(int u,int v,int w)
	{
		e[++cnt].dis=w; e[cnt].to=v; e[cnt].nxt=head[u];
		return head[u]=cnt,void();
	}
	int n,m,res[N],maxx,minn;
	inline bool spfa(int st)
	{
		queue<int> q; q.push(st); res[st]=0;
		while(!q.empty())
		{
			int fr=q.front(); q.pop(); 
			for(int i=head[fr];i;i=e[i].nxt)
			{
				int t=e[i].to; 
				if(res[t]!=1e15+10)
				{
					if(res[t]!=res[fr]+e[i].dis) return 0;
				}
				else 
				{
					res[t]=res[fr]+e[i].dis;
					maxx=max(maxx,res[t]);
					minn=min(minn,res[t]);
					if(maxx-minn>1e9) return 0;
					q.push(t);
				}	
			}
		}
		return 1;
	 } 
	signed main()
	{
		n=read(); m=read();
		for(int i=1;i<=n;++i) res[i]=1e15+10;
		for(int i=1;i<=m;++i)
		{
			int l=read(),r=read(),x=read();
			add(l,r,x); add(r,l,-x);
		}
		for(int i=1;i<=n;++i) 
		{
			if(res[i]==1e15+10)
			{
				if(!spfa(i)) return puts("No"),0;
			}
		}puts("Yes");
		return 0;
	}
}
signed main(){return yspm::main();}

Measured memory_bytes: 14080
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		for (int i=1; i<=9; i++) {
			for (int j=1; j<=9; j++) {
				System.out.println(i+"x"+j+"="+i*j);
			}
		}
	}
}


Measured memory_bytes: 25996
import java.util.Scanner;

class  ball{
	boolean red;
	int num;
}

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n,m;
		n=sc.nextInt();
		m=sc.nextInt();
		ball []b=new ball[n];
		b[0]=new ball();
		b[0].red=true;
		b[0].num=1;
		for(int i=1;i<n;i++) {
			b[i]=new ball();
			b[i].num=1;
			b[i].red=false;
		}
		for(int i=0;i<m;i++) {
			int p,q;
			p=sc.nextInt()-1;
			q=sc.nextInt()-1;
			
			if(b[p].red&&b[p].num==1) {
				b[q].red=true;
				b[p].red=false;
			}
			else if(b[p].red==true&&b[p].num>1) {
				b[q].red=true;
				b[p].red=true;
			}
			b[p].num--;
			b[q].num++;
			
           
		}
		int sum=0;
		for(int i=0;i<n;i++) {
			if(b[i].red) {
				sum++;
			}
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 85960
using System;
using System.IO;

namespace abc124c
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var S = Console.ReadLine().ToCharArray();
            var c1 = 0;
            var c2 = 0;

            for (int i = 0; i < S.Length; i++)
            {
                if (i % 2 == 0)
                {
                    if (S[i] == '0')
                    {
                        c1++;
                    }
                    else
                    {
                        c2++;
                    }
                }
                else{
                    if (S[i] == '1')
                    {
                        c1++;
                    }
                    else
                    {
                        c2++;
                    }
                }
            }

            Console.WriteLine(Math.Min(c1, c2));
        }
    }
}


Measured memory_bytes: 11488
#include <iostream>
using namespace std;
int main()
{
    int n, T;
    cin >> n >> T;
    int c[n];
    int t[n];
    int ans = 1001;
    for (int i = 0; i < n; i++) {
        cin >> c[i] >> t[i];
        if (t[i] <= T && ans > c[i]) {
            ans = c[i];
        }
    }   
    if (ans <= 1000)
        cout << ans << endl;
    else
        cout << "TLE" << endl;
}


Measured memory_bytes: 256
N = int(input())
w = input()
word = [w]
before = w[-1]
flag = True

for i in range(N-1):
    w = input()
    if w not in word and before == w[0]:
        word.append(w)
        before = w[-1]
    else:
        flag = False
        break

if flag == True:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define ll long long
#define Test int t;cin>>t;while(t--)
#define endl "\n"
#define PI acos(-1)
#define sz(x) (x).size()
#define aa(s) (s).begin(),(s).end()
using namespace std;
const int dx[]={-1,-1,-1,0,0,0,1,1,1};
const int dy[]={-1,0,1,-1,0,1,-1,0,1};
void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll lcm(ll a,ll b){
    return a*b/__gcd(a,b);
}
bool g[101];
int main()
{
    fast();
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    ll d1=h1*60+m1,d2=h2*60+m2-k;
    cout<<d2-d1;
    return 0;
}


Measured memory_bytes: 3648
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int ln;
  string s,t,u,v;
  char c;
  while(cin>>s&&s[0]!='-'){
    cin>>t>>u;
    i=0;
    j=1;
    k=0;
    c=t[0];
    v="";
    ln=t.length();
    while(j<ln+1){
      if(u[k]==c){
	c=s[i];
	i++;
	k++;      
      }else{
	v+=c;
	c=t[j];
	j++;
      }
    }
    cout<<v<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <cctype>
using namespace std;

map<string, int> atom;
string s;
int idx;

int number(){
  int ret = 0;
  while(isdigit(s[idx])){
    ret *= 10;
    ret += s[idx++] - '0';
  }
  return ret;
}

int Atom(){
  string res = "";
  res += s[idx++];
  if(islower(s[idx])) res += s[idx++];
  //cout << "res = " << res << endl;
  if(atom.find(res) == atom.end()) throw "";
  return atom[res];
}

int Molecule(){
  int ret = 0;
  int m;
  while(idx < s.size() && s[idx] != ')'){
    if(s[idx] == '('){
      idx++;
      m = Molecule();

      idx++;
      ret += m * number();
    }
    else{
      m = Atom();
      if(isdigit(s[idx])){
	ret += m * number();
      }
      else ret += m;
    }
  }
  return ret;
}

int main(){
  string name;
  int w;
  while(cin >> name){
    if(name == "END_OF_FIRST_PART") break;
    cin >> w;
    atom[name] = w;
  }
  
  while(cin >> s){
    if(s == "0") break;
    idx = 0;
    try{
      cout << Molecule() << endl;
    }
    catch(const char* c){
      cout << "UNKNOWN" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1296
x=$<.map &:to_i
n=x[0]
h={}
begin
    i=1;while i<=n
    raise if (x[i]^i)%2>0
    u=x[i];v=i;h[u]=1
    while i<u
        i+=1
        raise if x[i]!=i
        i+=1
        raise if (x[i]^i)%2>0
        if u<x[i];u=x[i];h[u]=1
        elsif v==x[i];v+=2;v+=2 while h[v]
        else;raise
        end
    end
    i+=1;end
    puts :Yes
rescue
    puts :No
end

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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

ll dp[310][100010];
ll dp1[310][100010];
int a[310];

int main(){
  int n;
  cin >> n;
  int sum = 0;
  REP(i,n) {
    cin >> a[i+1];
    sum += a[i+1];
  }

  dp[0][0] = 1LL;
  dp1[0][0] = 1LL;

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= sum; j++) {
      dp[i][j] += dp[i-1][j] * 2LL;
      dp[i][j] %= MOD1;
      dp1[i][j] += dp1[i-1][j];
      dp1[i][j] %= MOD1;

      if (j >= a[i]) {
        dp[i][j] += dp[i-1][j-a[i]];
        dp[i][j] %= MOD1;
        dp1[i][j] += dp1[i-1][j-a[i]];
        dp1[i][j] %= MOD1;
      }
    }
  }

  ll ans = 1LL;
  REP(i,n) {
    ans *= 3LL;
    ans %= MOD1;
  }

  for (int i = (sum + 1) / 2; i <= sum; i++) {
    ans -= dp[n][i] * 3;
    while (ans < 0) ans += MOD1;
    ans %= MOD1;
  }

  if (sum % 2 == 0) {
    ans += dp1[n][sum/2] * 3;
    ans %= MOD1;
  }

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


Measured memory_bytes: 472448
N, P = map(int, input().split())
S = [int(i) for i in input()]
from collections import Counter
def solve(S,N,P):
    if P==2 or P==5:
        ans = 0
        for i in range(N):
            if S[i]%P==0:
                ans += i+1
        return ans
    cum = [0]*(N+1)
    mods = [0]*N
    mods[0] = 1
    for i in range(1,N):
        mods[i] = mods[i-1]*10%P
    for i in range(N):
        cum[i+1] = (cum[i]+S[N-1-i]*mods[i])%P
    c = Counter(cum)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2
    return ans
print(solve(S,N,P))

Measured memory_bytes: 21108
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
    int x,y,z,h,g;
int main()
{
    cin>>x>>y>>z;
    h=x-z;
    while(h-z>0)
    {
        if(h-y-z<0)break;
        else h=h-y-z;
        g++;
    }
    cout<<g<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;



int main(void) {
    int l;
    cin >> l;

    if (l % 3 == 0) {
        cout << l / 3 * l / 3 * l / 3 << endl;
        return 0;
    }

    double k = l;
    double ans = k / 3 * k / 3 * k / 3;
    printd(ans);
    return 0;
}


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

int main() {
	int a, b, i;
	cin >> a >> b;
	for(i = 0; i < 10100; i++) {
		if (i * 8 / 100 == a && i * 10 / 100 == b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    int n, s[1000];

    while(1){
        cin >> n;
        if(n == 0) break;    
        
        for(int i = 0; i < n; i++){
            cin >> s[i];
        }
        double sum = 0;
        for(int i = 0; i < n; i++){
            sum += s[i];
        }
        double ave = sum / n;
        
        double S = 0;
        for(int i = 0; i < n; i++){
            S += pow((s[i] - ave), 2);
        }
        
        printf("%1f\n", sqrt(S/n));
    }
    return 0;
}


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

int main()
{
    int N, count=0;
    cin >> N;
    vector<int> data(N);

    for (int i = 0; i < N; i++)
    {
            cin >> data.at(i);
    }

    for (int i = 0; i < N-2; i++){
        //cout << data.at(i)<<data.at(i+1)<<data.at(i+2)<<endl;
        if (data.at(i) < data.at(i + 1) && data.at(i+1) < data.at(i + 2))
            count++;
        else if (data.at(i) > data.at(i + 1) && data.at(i + 1) > data.at(i + 2))
            count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int A = 0;
  int B = 0;
  int C = 0;
  int h, m, s;
  int sh, sm, ss;
  int i;

  for(i = 0; i < 3; i++){
    scanf("%d %d %d %d %d %d",&h ,&m, &s, &sh, &sm, &ss);
    A =((sh * 3600) + (sm * 60) + ss) - ((h * 3600) + (m * 60) + s);
    B = A / 3600;
    C = (A % 3600) / 60;
    A -= ((B * 3600) + (C * 60));
    printf("%d %d %d\n", B, C, A);

  }


  /*
  for (i = 0; i < n; i++){
  scanf("%d", &a[i]);
  }
  */

  return (0);
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int main() {
  int a,b,c,d;
  int res=0;
  cin >> a >> b >> c >> d;
  if(a < c){
    if(b > c){
      if(b > d){
        res=d-c;
      }else{
        res=b-c; 
      }
    }else{
      res = 0;
    }
  }else{
    if(d > a){
      if(d > b){
        res=b-a;
      }else{
        res=d-a;
      }
    }else{
      res = 0;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
using LL = int_fast64_t;
const int MAXN = 1e5+7;
int n;
LL m,dp[MAXN],f[MAXN];
vector<int> G[MAXN];
vector<LL> pre[MAXN],suf[MAXN];
LL dfs(int u, int par){
    dp[u] = 1;
    for(int v : G[u]) if(v!=par) dp[u] = (dp[u]*dfs(v,u))%m;
    return dp[u] + 1;
}
void solve(int u, int par, int pos){
    LL fp = (pos?pre[par][pos-1]:1) * (pos==(int)suf[par].size()-1?1:suf[par][pos+1]) % m;
    f[u] = dp[u] * (fp+1) % m;
    for(int i = 0; i < (int)G[u].size(); i++){
        if(G[u][i]==par){
            pre[u].emplace_back(1);
            suf[u].emplace_back(1);
            continue;
        }
        pre[u].emplace_back(dp[G[u][i]]+1);
        suf[u].emplace_back(dp[G[u][i]]+1);
    }
    pre[u].emplace_back(fp+1);
    suf[u].emplace_back(fp+1);
    for(int i = 1; i < (int)pre[u].size(); i++) pre[u][i] = pre[u][i] * pre[u][i-1] % m;
    for(int i = suf[u].size()-2; i >= 0; i--) suf[u][i] = suf[u][i] * suf[u][i+1] % m;
    for(int i = 0; i < (int)G[u].size(); i++) if(G[u][i]!=par) solve(G[u][i],u,i);
}
int main(){
    ____();
    cin >> n >> m;
    for(int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    dfs(1,0);
    f[1] = dp[1];
    for(int i = 0; i < (int)G[1].size(); i++){
        pre[1].emplace_back(dp[G[1][i]]+1);
        suf[1].emplace_back(dp[G[1][i]]+1);
    }
    for(int i = 1; i < (int)G[1].size(); i++) pre[1][i] = pre[1][i] * pre[1][i-1] % m;
    for(int i = G[1].size()-2; i >= 0; i--) suf[1][i] = suf[1][i] * suf[1][i+1] % m;
    for(int i = 0; i < (int)G[1].size(); i++) solve(G[1][i],1,i);
    for(int i = 1; i <= n; i++) cout << f[i] << endl;
    return 0;
}

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

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

const int N = 2e5 + 5;

int n, q;
ll dp[N];
vector <int> adj[N];

void dfs(int v, int p = -1) {
	for (auto u : adj[v])
		if(u ^ p) {
			dp[u] += dp[v];
			dfs(u, v);
		}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	for (int i = 0; i < q; i++) {
		int v, val;
		cin >> v >> val;
		v--;
		dp[v] += val;
	}
	dfs(0);
	for (int i = 0; i < n; i++)
		cout << dp[i] << " ";
	cout << "\n";
}


Measured memory_bytes: 24320
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N;
long A[1<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	reverse(A,A+N);
	vector<pair<long,long> >S;
	for(int i=1;i<N-1;i++)
	{
		if(A[i]>=0)
		{
			S.push_back(make_pair(A[N-1],A[i]));
			A[N-1]-=A[i];
		}
		else
		{
			S.push_back(make_pair(A[0],A[i]));
			A[0]-=A[i];
		}
	}
	S.push_back(make_pair(A[0],A[N-1]));
	A[0]-=A[N-1];
	cout<<A[0]<<endl;
	for(pair<int,int>p:S)
	{
		cout<<p.first<<" "<<p.second<<endl;
	}
}

Measured memory_bytes: 4336
#!/usr/bin/env python3


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())


class dsu(UnionFind):
    def __init__(self, n):
        super().__init__(n)
        self.merge = self.union
        self.leader = self.find

    def groups(self):
        result = [self.members(r) for r in self.roots()]

        return result


def main():
    n, q = list(map(int, input().split()))

    dsu_ = dsu(n)

    for i in range(q):
        t, u, v = list(map(int, input().split()))
        if t == 1:
            if dsu_.leader(u) == dsu_.leader(v):
                print(1)
            else:
                print(0)
        elif t == 0:
            dsu_.merge(u, v)


if __name__ == "__main__":
    main()


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

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        Console.WriteLine(Console.ReadLine().Split().Select(long.Parse).OrderByDescending(x => x).Where((_, index) => index % 2 == 1).Take(n).Sum());
    }
}

Measured memory_bytes: 49556
// at_abc141d.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<queue>
using namespace std;
typedef long long ll;
#define FOR(i,a) for(int i=0;i<a;i++)
int main()
{
    priority_queue<int>pq;
    int n, k;cin >> n >> k;
    FOR(i, n) {
        int temp;cin >> temp;
        pq.push(temp);
    }
    FOR(a, k) {
        int temp = pq.top();
        pq.pop();
        pq.push(temp / 2);
    }
    ll sum = 0;
    while(!pq.empty()) {
        sum += pq.top();
        pq.pop();
    }
    cout << sum << "\n";
}



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

const int N = 2010;

int h, w;
char board[N][N];
int g[N][N];

int L[N], R[N];

int calc(vector<int> a) {
    vector<int> st;
    for (int i = 0; i < int(a.size()); i++) {
        while (!st.empty() && a[i] <= a[st.back()]) {
            st.pop_back();
        }
        L[i] = (st.empty() ? 0 : st.back() + 1);
        st.push_back(i);
    }

    st.clear();
    for (int i = int(a.size()) - 1; i >= 0; i--) {
        while (!st.empty() && a[i] <= a[st.back()]) {
            st.pop_back();
        }
        R[i] = (st.empty() ? int(a.size()) - 1 : st.back() - 1);
        st.push_back(i);
    }

    int res = 0;
    for (int i = 0; i < int(a.size()); i++) {
        res = max(res, a[i] * (R[i] - L[i] + 2));
    }

    return res;
}

int main() {
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; i++) {
        scanf("%s", board[i]);
    }
    for (int i = 0; i < h - 1; i++) {
        for (int j = 0; j < w; j++) {
            g[i][j] = (board[i][j] != board[i + 1][j]);
        }
    }

    vector<int> f(h - 1);
    int ans = w;
    for (int j = w - 1; j >= 0; j--) {
        vector<int> nf(h - 1);
        for (int i = 0; i < h - 1; i++) {
            nf[i] = 1;
            if (j < w - 1 && g[i][j] == g[i][j + 1]) {
                nf[i] += f[i];
            }
        }
        swap(f, nf);
        ans = max(ans, calc(f));
    }

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


Measured memory_bytes: 19968
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    string s;cin>>s;
    LL n = SIZE(s);

    LL result = 0;
    REP(i,n){
        result += s[i]-'0';
    }
    if(result%9 == 0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3744
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public int[] A;
        public void Run()
        {
            N = Input.ReadInt();
            A = Input.ReadIntArray();
            Array.Sort(A);
            Console.WriteLine(A[A.Length-1] - A[0]);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 11348
#include <stdio.h>
#include <math.h>

int check(int x)
{
	if(x<2)return 0;
	if(x==2)return 1;
	if(x%2==0)return 0;
	for(int i=3;i<=sqrt(x);i+=2){
		if(x%i==0)return 0;
	}
	return 1;
}
int main(void)
{
	int a,b,n;
	int count;
	
	while(1){
		scanf("%d %d %d",&a,&b,&n);
		if(a==0&&b==0&&n==0)break;
		count=0;
		int y=a;
		if(check(y)==1)count++;
		while(1){
			if(count==n){
				printf("%d\n",y);
				break;
			}
			y+=b;
			if(check(y)==1)count++;
		}
	}
	
	return 0;
}


Measured memory_bytes: 2724
N = gets.to_i
as = gets.chomp.split.map(&:to_i)

evens = as.select.with_index { |e, i| (i+1).even? }
odds = as.select.with_index { |e, i| (i+1).odd? }

if N.even?
  puts((evens.reverse + odds).join(' '))
else
  puts((odds.reverse + evens).join(' '))
end

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

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

vector<pair<ll,int> >res;

vector<pair<ll,int> > factorize(ll n){
        for(ll i=2;i*i<=n;i++){
                if(n%i)continue;
                res.emplace_back(i,0);
                while(n%i==0){
                        n/=i;
                        res.back().second++;
                }
        }
        if(n!=1)res.emplace_back(n,1);
        return res;
}

int main(){
        ll n;
        cin>>n;
        factorize(n);
        cout<<n<<":";
        for(int i=0;i<res.size();i++){
                for(int j=0;j<res[i].second;j++){
                        cout<<" "<<res[i].first;
                }
        }
        cout<<endl;
        return 0;
}




Measured memory_bytes: 3136
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nk = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nk[0]);
        int k = Integer.parseInt(nk[1]);

        if (n == 1) {
            System.out.println(k);
        } else {
            int answer = k;
            for (int i = 1; i < n; i++) {
                answer *= (k - 1);
            }
            System.out.println(answer);
        }
    }
}


Measured memory_bytes: 22228
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = LS()
    if a[1][0] == "+":
        print(int("".join(a[0])) + int("".join(a[2])))
    else:
        print(int("".join(a[0])) - int("".join(a[2])))
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 38512
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    val M = LongArray(N + 1)
    A.forEach { M[it] += 1L }
    fun c2(x: Long) = x * (x - 1) / 2
    var total = M.sumByLong { c2(it) }
    val ans = LongArray(N)
    A.forEachIndexed { index, a ->
        ans[index] = total - c2(M[a]) + c2(M[a] - 1)
    }
    println(ans.joinToString("\n"))
}
inline fun LongArray.sumByLong(selector: (Long) -> Long): Long {
    var sum = 0L
    for (element in this) sum += selector(element)
    return sum
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 99356
# -*- coding: utf-8 -*-
"""
D - Blue and Red Balls
https://atcoder.jp/contests/abc132/tasks/abc132_d

"""
import sys


F = [1]
for i in range(1, 2001):
    F.append(F[-1] * i)

def solve(n, k):
    MOD = 10**9 + 7
    ans = []
    for i in range(1, k+1):
        blue = F[k-1] // (F[i-1] * F[k-1-i+1])
        red = F[n-k+1] // (F[i] * F[n-k+1-i])
        ans.append(blue * red % MOD)
    return ans


def main(args):
    n, k = map(int, input().split())
    ans = solve(n, k)
    print(*ans, sep='\n')


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


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

int main() {
  long long int H;
  cin >> H;
//count:攻撃数 num:敵数
  long long int count = 0, num = 1;
  while(H!=0) {
      H /= 2; 
      count += num;
      num *= 2; 
  }

  cout << count << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int N;
std::string S;
int right_cou, left_cou;
int want_to;
bool flag = true;

int main()
{
	in >> N >> S;

	auto S_ = S;
	while (flag)
	{
		flag = false;
		rep(i, S_.length())
		{
			if (S_[i] == '('&&S_[i + 1] == ')')
			{
				S_.erase(i, 2);
				flag = true;
			}
		}
	}
	rep(i, S_.length())
	{
		if (S_[i] == ')') { right_cou++; }
		else { left_cou++; }
	}
	rep(i, right_cou) { S = "(" + S; }
	rep(i, left_cou) { S += ")"; }

	out << S << std::endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    import numpy as np
    c = np.concatenate
    n = int(input())
    ss = [list(input()) for _ in [0]*n]
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    d = {j: i for i, j in enumerate(alphabet)}
    s = np.array([[d[i] for i in j] for j in ss], dtype=np.int8)
    cnt = 0
    for a in range(n):
        for i in range(n):
            ia_n = (i+a) % n
            if not (c([s[i, i+a:n], s[i, :a]]) == c([s[i:n-a, ia_n], s[n-a:n, ia_n]])).all():
                break
        else:
            cnt += 1
    print(n*cnt)


main()

Measured memory_bytes: 13960
#include<cstdio>
#include<set>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
struct Edge {
    int to,next,val;
    Edge(){}
    Edge(int to,int next,int val):to(to),next(next),val(val){}
    bool operator < (const Edge& rhs)const{
        return val>rhs.val;
    }
}edge[N*2];
int tot,head[N];
void addEdge(int from,int to,int val) {
    edge[tot].next=head[from];
    edge[tot].to=to;
    edge[tot].val=val;
    head[from]=tot++;
}
bool vis[N];
int dis[N];
int SPFA(int s,int e) {
    memset(vis,false,sizeof(vis));
    memset(dis,INF,sizeof(dis));
    dis[s]=0;
 
    priority_queue<Edge> Q;
    Q.push(Edge(s,0,0));
    while (!Q.empty()) {
        Edge temp=Q.top();
        Q.pop();
        if(vis[temp.to])
            continue;
        vis[temp.to]=true;
 
        for(int i=head[temp.to]; i!=-1; i=edge[i].next) {
            if(dis[edge[i].to]>dis[temp.to]+edge[i].val) {
                dis[edge[i].to]=dis[temp.to]+edge[i].val;
                Q.push(Edge(edge[i].to,0,dis[edge[i].to]));
            }
        }
    }
    if(dis[e]!=INF)
        return dis[e]/2;
    return -1;
}
map<int,int> mp[N];
int allPoint;
int getPoint(int x,int y) {
    if (!mp[x][y])
        mp[x][y]=++allPoint;
    return mp[x][y];
}
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    allPoint=n;
    for (int i=1; i<=m; i++) {
        int x,y,w;
        scanf("%d%d%d",&x,&y,&w);
 
        int newX=getPoint(x,w);
        int newY=getPoint(y,w);
 
        addEdge(x,newX,1);
        addEdge(newX,x,1);
        addEdge(newX,newY,0);
        addEdge(newY,newX,0);
        addEdge(y,newY,1);
        addEdge(newY,y,1);
    }
    int res=SPFA(1,n);
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 94196
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<cmath>
#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=1e6+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	char s[maxn];
	scanf("%s",s+1);
	int i,len=strlen(s+1),dp[maxn][2]={0};
	//dp[i][0]表示直接用钱支付这部分，dp[i][1]表示要找钱 
	s[0]='0';dp[len+1][1]=1;
	for(i=len;i>=0;i--)
	{
		int num=s[i]-'0';
		dp[i][0]=min(dp[i+1][0]+num,dp[i+1][1]+num+1);
		dp[i][1]=min(dp[i+1][0]+10-num,dp[i+1][1]+10-num-1);
	}
	printf("%d\n",min(dp[0][0],dp[0][1]));
}

Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while(true){
			int n = stdIn.nextInt();
			int m = stdIn.nextInt();
			if(n==0&&m==0){
				return;
			}
			int r = stdIn.nextInt();
			int[][] r_rec = new int[r][4];
			for(int i=0;i<r;i++){
				for(int j=0;j<4;j++){
					
					r_rec[i][j] = stdIn.nextInt();
				}
			}
			int q = stdIn.nextInt();
			for(int i=0;i<q;i++){
				int[] hear = new int[3];		// hear = question
				for(int j=0;j<3;j++){
					hear[j] = stdIn.nextInt();
				}
				
				
				int time = 0;
				int progress = 0;
				// 一つずつレコード走査
				for(int j=0;j<r;j++){
					// 対象学生のレーコドだけ処理
					if(r_rec[j][2]!=hear[2]){
						continue;
					}
					// ログアウトはスタート時刻として除外
					if(r_rec[j][3]==0){
						continue;
					}
					// 個々PCのログインとログアウトを関連づけて時間を算出
					int start = r_rec[j][0];
					int stop = 0;
					for(int k=j+1;k<r;k++){
						// 対象学生の一致確認と同PCのログインログアウト関連付け確認
						if((r_rec[k][2]==hear[2])&&(r_rec[j][1]==r_rec[k][1])){
							stop = r_rec[k][0];
							break;
						}
					}
//					System.out.println();
//					System.out.print(start+" "+stop+" -> ");
					// 進捗時間が範囲終了を越えた場合は終了
					if(progress>=hear[1]){
						break;
					}
					// 今回の開始時間が範囲の終了時間を越えてれば終了
					if(hear[1]<=start){
						break;
					}
					// 計算進捗時間が今回の終了時間より大きければ除外
					if(progress>=stop){
						continue;
					}
					// 今回の終了時間が範囲のスタート時間より下回ってるのは除外
					if(stop<=hear[0]){
						continue;
					}
					// 範囲外のスタート時刻を範囲内に収める
					if(start<hear[0]){
						start = hear[0];
					}
					// 計算進捗時間までは重複するので削る
					if(start<progress){
						start = progress;
					}
					// 範囲外のストップ時刻を範囲に収める
					if(stop>hear[1]){
						stop = hear[1];
					}
//					System.out.println(start+" "+stop+" -> "+(stop-start));
					time += stop-start;
					progress = stop;
				}
//				System.out.println();
//				System.out.print("time = ");
				System.out.println(time);
			}
		}
	}
}

Measured memory_bytes: 13000
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


A = LI()
A.sort()

print(A[0] * A[1] // 2)


Measured memory_bytes: 2940
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    (0..$i).map(|_| $e.get::<$t>()).collect::<Vec<$t>>()
  };
  ($e:expr => $row:expr, $col:expr; $t:ty) => {
    (0..$i).map(|_| scan!($e => $col; $t)).collect::<Vec<$t>>()
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

trait Writable {
  fn write(&self, sep: &'static str) -> String;
}

impl<T: ToString> Writable for Vec<T> {
  fn write(&self, sep: &'static str) -> String {
    self.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep)
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let (_, s) = scan!(sc; i32, String);
  let mut x = 0;
  let mut ans = 0;
  for c in s.chars() {
    match c {
      'I' => {
        x += 1;
        ans = max(ans, x);
      },
      'D' => {
        x -= 1;
      },
      _ => unreachable!()
    }
  }
  println!("{}", ans);
}

fn max<T: Ord>(a: T, b: T) -> T {
  if a > b { a } else { b }
}


Measured memory_bytes: 4352
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

const Nmax = 10^6

function main()
  N = readint()[1]
  A = readint()

  A = sort(A)
  kusi = Vector{Bool}(undef, Nmax)
  kusi .= false

  cout = 0
  for i in 1:N-1
    a = A[i]
    kusi[a] && continue
    
    a < A[i+1] && (cout += 1)
    for j in a:a:Nmax
      kusi[j]=true
    end
  end
  
  kusi[A[end]] || (cout += 1)
  println(cout)
  
end

main()

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

int main (){
 int c[6];
	cin>>c[0]>>c[1]>>c[2]>>c[3]>>c[4]>>c[5];
		if(c[0]+c[1]*5+c[2]*10+c[3]*50+c[4]*100+c[5]*500>=1000){cout<<"1"<<endl;
		}
		else{cout<<"0"<<endl;
		}
return 0;
}

Measured memory_bytes: 1156
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD = 1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,prev = 0,next = 0;
	string s[10000],t,a[10000],z[10000];
	cin >> n;
	for(int i = 0;i < n;i++) {
		cin >> s[i];
		a[i] = s[i];
		z[i] = s[i];
		for(int j = 0;j < s[i].length();j++){
			if(s[i][j] == '?') {
				a[i][j] = 'a';
				z[i][j] = 'z';
			}
			else{
				a[i][j] = s[i][j];
				z[i][j] = s[i][j];
			}
		}
	}
	cin >> t;
	for(int i = 0;i < n;i++){
		if(z[i] < t) prev++;
		if(a[i] > t) next++;
	}
	for(int i = prev + 1;i <= n - next + 1;i++) cout << (i != prev + 1 ? " " : "") << i;
	cout << endl;
	return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	ll n;
	std::vector<ll>  a(5);

	ll mina = -1;
	std::cin >> n;
	for (int i = 0; i < 5; i++) {
		std::cin >> a[i];
		if ((mina < 0) || (mina > a[i])) mina = a[i];
	}

	ll tmpn = (n + mina - 1) / mina;

	ll sumk = 4 + tmpn;
	std::cout << sumk << std::endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def can_reach(s, p, q):
	for i in range(p, q):
		if s[i] == '#' and s[i+1] == '#':
			return False
	return True

def main():
	_, a, b, c, d = map(lambda i: int(i)-1, input().strip().split())
	s = input().strip()
	if a < c < b < d:
		if can_reach(s, a, c) and can_reach(s, b, d):
			print('Yes')
		else:
			print('No')
	elif a < b < c < d:
		if can_reach(s, a, c) and can_reach(s, b, d):
			print('Yes')
		else:
			print('No')
	else:
		if can_reach(s, a, c) and can_reach(s, b, d):
			for i in range(b-1, d):
				if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.':
					print('Yes')
					return
		print('No')

if __name__ == '__main__':
	main()


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

int main(void){
    int s,i=1;
    cin>>s;
    vector<int> a;
    a.push_back(s);
    while(true){
        if(a[i-1]%2==1)
            a.push_back(3*a[i-1]+1);
        else
            a.push_back(a[i-1]/2);

        for(int j=0;j<i;j++){
            if(a[j]==a[i]){
                cout<<i+1<<endl;
                return 0;
            }
        }
        i++;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int a,b;
  cin >> a >> b;
  
  vector<int>abc = {1,3,1,2,1,2,1,1,2,1,2,1};
  
  if(abc[a - 1] == abc[b - 1])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Main().main();
    }

    public void main() {
        Scanner scanner = new Scanner(System.in);

        int sNum = Integer.parseInt(scanner.nextLine());
        String[] sLine = scanner.nextLine().split(" ", sNum);
        int[] s = new int[sNum+1];
        for (int i = 0; i < sNum; i++) {
            s[i] = Integer.parseInt(sLine[i]);
        }

        int tNum = Integer.parseInt(scanner.nextLine());
        String[] tLine = scanner.nextLine().split(" ", tNum);

        int result = 0;
        for (int i = 0; i < tNum; i++) {
            int t = Integer.parseInt(tLine[i]);
            if (this.linearSearch(t, s, sNum)) {
                result++;
            }
        }
        System.out.println(result);
    }

    private boolean linearSearch(int key, int[] arr, int arrSize) {
        arr[arrSize] = key;
        int i = 0;
        while (arr[i] != key) {
            i++;
        }
        return i != arrSize;
    }
}



Measured memory_bytes: 30780
import scala.io.StdIn._
import scala.math._

object Main extends App with StdInHelper {
  val n = readInt
  val i = n % 10
  i match {
    case 2 | 4 | 5 | 7 | 9 => println("hon")
    case 0 | 1 | 6 | 8     => println("pon")
    case 3                 => println("bon")
  }
}

trait StdInHelper {
  def readInts = readLine.split(" ").map(_.toInt)
  def readLongs = readLine.split(" ").map(_.toLong)
}


Measured memory_bytes: 54656
package main

import(
	"bufio"
	"os"
	"strings"
	"fmt"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	str := strings.Split(sc.Text(), " ")
	a,_ := strconv.Atoi(str[0])
	b,_ := strconv.Atoi(str[1])
	c,_ := strconv.Atoi(str[2])
	flag := 0
	if(c > a + b) {
		flag = b * 2 + a + 1
	} else {
		flag = c + b
	}
	fmt.Printf(strconv.Itoa(flag))
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

vector<int> divisor(int n)
{
    vector<int> value;
    FOR(i, 1, pow(n, 0.5) + 1)
    {
        if (i <= sqrt(n))
        {
            if (n % i == 0)
            {
                value.push_back(i);
                if (i * i != n)
                {
                    value.push_back(n / i);
                }
            }
        }
    }
    return value;
}

ll M = 1000000007;
typedef pair<int, int> P;
int main()
{
    vector<bool> pripri(1e5,false);//0 origin
    FOR(i, 1, 1e5 + 1)
    {
        if (i % 2 == 1)
        {
            if (divisor(i).size() ==2 && divisor((i + 1) / 2).size() == 2)
            {
                //cout<<i<<endl;
                pripri[i-1] = true;
            }
            
        }
    }
    vector<int>acc(1e5+1,0);//1 origin 0は計算用
    int sum=0;
    rep(i,1e5){
        if(pripri[i]){
            sum++;
        }
        acc[i+1]=sum;
    }
    int q;
    cin>>q;
    rep(i,q){
        int l,r;
        cin>>l>>r;
        cout<<acc[r]-acc[l-1]<<endl;
    }
}


Measured memory_bytes: 1280
#include <iostream>
#include <map>
#define ll long long
using namespace std;
int main () {
  ll n,tot=0; cin >> n;
  ll arr[n]; for (ll i=0; i<n; i++) {cin >> arr[i];tot+=arr[i];}
  map <ll,ll>m;
  for (ll i=0; i<n; i++) m[arr[i]]++;
  ll q; cin >> q;
  for (ll i=0; i<q; i++) {
    ll b,c; cin >> b >> c;
    tot -= m[b]*b;
    tot -= m[c]*c;
    m[c] += m[b];
    tot += m[c]*c;
    m.erase(b);
    cout << tot << endl;
  }
}

Measured memory_bytes: 7860
h,w,a,b = map(int, input().split())
if h == 1:
    S = "1"*a+"0"*(w-a)
    print(S)
elif w == 1:
    S = [1]*b+[0]*(h-b)
    for s in S:
        print(s)
elif h >= 2 and w >= 2:
    # if b*w != a*h:
    #     print("No")
    #     exit()
    # else:
    for i in range(h):
        # print(a,i)
        if i < b:
            S = "1"*a + "0"*(w-a)
        else:
            S = "0"*a + "1"*(w-a)
        print(S)

Measured memory_bytes: 3956
//#include<stdio.h>
//#include<stdlib.h>
#include<bits/stdc++.h>
//#define Min(a,b,c) min((a),min((b),(c)))
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-11
#define MEM(x) memset(x,0,sizeof(x))
//#define N 200005
#define M
#define pi 3.14159265359
using namespace std;
typedef long long LL;
vector<int> v[100005];
int visit[100005];
deque<int> q;
void dfs(int n){
	for(vector<int>::iterator it=v[n].begin();it!=v[n].end();it++){
		if(!visit[*it])
		{
			q.push_front(*it);
			visit[*it]=1;
			dfs(*it);
			break;
		}
	}
}
void dfs2(int n){
	for(vector<int>::iterator it=v[n].begin();it!=v[n].end();it++){
		if(!visit[*it])
		{
			q.push_back(*it);
			visit[*it]=1;
			dfs2(*it);
			break;
		}
	}
}
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		v[a].pb(b);
		v[b].pb(a);
	}
	q.pb(1);
	q.pb(v[1][0]);
	visit[1]=1;
	visit[v[1][0]]=1;
	dfs(q.front());
	dfs2(q.back());
	printf("%d\n",q.size());
	while(!q.empty()){
		printf("%d",q.front());
		q.pop_front();
		if(q.size()==0)
		printf("\n");
		else
		printf(" ");
	}
}

/*90 110
180 220
270 330
360 440
450 550
540 660
630 770
*/

Measured memory_bytes: 7040