akhauriyash/Code-Regression huggingface dataset:
N, M = list(map(int, input().strip().split()))
H = list(map(int, input().strip().split()))
S = set(range(N))

for m in range(M):
  A, B = list(map(int, input().strip().split()))
  if H[A-1] >= H[B-1]:
    S -= set([B-1])
  if H[A-1] <= H[B-1]:
    S -= set([A-1])
  
print(len(S))

Measured memory_bytes: 22592
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define ll long long
#define bit(x,i) (x&(1<<i))
#define pi 3.1415926535897932384626
#define pb push_back
#define pf push_front
#define mt make_tuple
#define ff first
#define ss second
#define debug(x) cout << #x " = " << (x) << endl
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define endl '\n'
#define EPS 1e-9
#define INF 1e18
#define ALL(x) for(int i=0; i<x; i++)
#define fori(a,b,c) for(int a=b; a<c; a++)
#define PRESENT(c,x) ((c).find(x) != (c).end())
#define m0(x) memset((x), 0, sizeof(x))
#define m1(x) memset((x), -1, sizeof(x))

const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, std::less<int>, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> indexed_set;

inline int mod(int n){ return (n%1000000007); }

int gcd(int a, int b){
  if(a == 0 || b == 0) return 0;
  if(b == 1) return b;
  else return gcd(b, a%b);
}

int fpow(int x, unsigned int y, int p){ 
    int res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;
        x = (x*x) % p;   
    } 
    return res; 
} 
const int maxn = 1e5+10;

int32_t main(){
	DESYNC;
    int n, ans = 0, bigg = (int)10e6+10;
    bitset<(int)10e6+10> primes;

    cin>>n;
    vector<int> arr(n);

    for(int &x: arr) cin>>x;

    sort(arr.begin(),arr.end());

    for(int i=1; i<n; i++)
        if(arr[i] == arr[i-1]) primes[arr[i]] = 1;

    arr.resize(unique(arr.begin(),arr.end())-arr.begin());

    for(int i=0; i<(int)arr.size(); i++){
        if(!primes[arr[i]])
            ans++;

        primes[arr[i]] = 1;
        for(int j=arr[i]*2;j<bigg;j+=arr[i])
            primes[j] = 1;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int a,b;
	cin >> a >> b;
	if((a+b)%3==0)cout << "Possible" << endl;
	else if(a%3==0 || b%3==0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int H_MAX = 250;

int a[H_MAX];

void print_node(int index, int H) {
    int id = index + 1;
    cout << "node " << id <<
        ": key = " << a[index];
    int parent_index = id / 2 - 1;
    if (parent_index >= 0) {
        cout << ", parent key = " << a[parent_index];
    }
    int left_index = 2 * id - 1;
    if (left_index < H) {
        cout << ", left key = " << a[left_index];
    }
    int right_index = 2 * id;
    if (right_index < H) {
        cout << ", right key = " << a[right_index];
    }
    cout << ", " << endl;
}

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

    int H;
    cin >> H;
    FOR(i,0,H) { cin >> a[i]; }
    FOR(i,0,H) { print_node(i,H); }

    return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;

    cout << a - (a > b) << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
  static void Main(string[] args)
  {
    string S = Console.ReadLine();
    
    if (S == "Sunny")
    {
      Console.WriteLine("Cloudy");
    }
    if (S == "Cloudy")
    {
      Console.WriteLine("Rainy");
    }
    if (S == "Rainy")
    {
      Console.WriteLine("Sunny");
    }
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    long long a=0;
    long long c[N]={0};
    for(int i=0; i<N; i++){
    cin>>c[i];}
    sort(c,c+N);
    reverse(c,c+N);
    for(int j=K; j<N; j++){
    a+=c[j];}
    cout<<a<<endl;
    }

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define RB rbegin()
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define MD 1000000007
#define PPF pop_front()
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;u.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>u,uc;
map<LL,LL>ww,cc;
LL ar[120005];
LL br[500005];
LL cr[500][500];
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
LL vv[20000001];
void veve(LL n)
{
    LL i,j;
    for(i=1; i<=n; i++)
    {
        if(i%2==1)
        {
            vv[i]=i;
        }
        else
        {
            vv[i]=2;
        }
    }
    for(i=3; i<=sqrt(n); i+=2)
    {
        if(vv[i]==i)
        {
            for(j=i*i; j<=n; j+=2*i)
            {
                if(vv[j]==j)
                {
                    vv[j]=i;
                }
            }
        }
    }
}
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c,str;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    veve(10000000);
    while(tt--)
    {
        UOSMOY;
        cin>>n;
        k=0;
        for(i=1; i<=n; i++)
        {
            if(i==1)
            {
                k+=1;
                continue;
            }
            j=i;
            l=1;
            while(j!=1)
            {
                u[vv[j]]++;
                j/=vv[j];
            }
            for(auto it=u.B;it!=u.E;it++)
            {
                l*=(it->SE+1);
            }
            k+=(l*i);
            u.C;
//            cout<<k<<endl;
        }
        cout<<k<<endl;

    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 81776
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

void ATheNumberOfEvenPairs(std::istream& in, std::ostream& out) {
  llong n, m;

  in >> n >> m;
  llong x = 0;
  if (n > 0)
    x += n * (n - 1) / 2;
  if (m > 0)
    x += m * (m - 1) / 2;
  out << x << endl;
}

int main(int argc, char** argv) { ATheNumberOfEvenPairs(cin, cout); return 0; }


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

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

int main()
{
  int n; cin >> n;
  vector<long long> t(n);
  for (auto itr = t.begin(); itr < t.end(); ++itr)
    cin >> *itr;
  
  long long lcm = 1;
  for (auto itr = t.begin(); itr < t.end(); ++itr)
  	if (lcm > *itr)
      lcm *= *itr / gcd(lcm, *itr);
    else
      lcm *= *itr / gcd(*itr, lcm);
  
  cout << lcm << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var xyxy = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var x1 = xyxy[0];
            var y1 = xyxy[1];
            var x2 = xyxy[2];
            var y2 = xyxy[3];
            var x = x2 - x1;
            var y = y2 - y1;
            Console.WriteLine($"{x2 - y} {y2 + x} {x1 - y} {y1 + x}");
        }
    }
}


Measured memory_bytes: 13396
#include <algorithm>
#include <vector>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <string>
#include <cmath>
#include <numeric>
using namespace std;

constexpr int MOD = 1000000000 + 7;
const long double PI = 3.141592653589793;

using i64 = int64_t;

i64 dp[101][100000 + 1];

signed main() {
  int n, W; cin >> n >> W;
  vector<int> v(n), w(n);
  for (int i = 0; i < n; i++) cin >> v[i] >> w[i];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= W; j++) {
      if (j < w[i]) dp[i + 1][j] = dp[i][j];
      else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
    }
  }

  cout << dp[n][W] << endl;
}


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

using namespace std;
int main() {
	string str;
	int n, a, b;
	cin >> n >> a >> b;
	cin >> str;
	
	int apb = a + b;
	int count = 0;
	int rank = 1;
	for (int i = 0; i < n; i++) {
		if (count < apb) {
			if (str[i] == 'a') {
				cout << "Yes" << endl;
				count++;
			}
			else if (str[i] == 'b' && rank <= b){
				cout << "Yes" << endl;
				count++;
				rank++;
			}
			else
				cout << "No" << endl;
		}else
			cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
  
int main()
{

	int sum=0;
	int n;
	int max;
	int min;
	int i;
	int m;


	while(1)
	{
	scanf("%d",&n);
	if(n==0)
		break;

	max=0;
	min=1000;
	sum=0;

	for(i=0;i<n;i++)
	{
		scanf("%d",&m);
		sum+=m;
		if(m>max)
			max=m;
		if(m<min)
			min=m;
	}

	sum = sum-max-min;

	printf("%d\n",(sum/(n-2)));
	}

	return 0;
}

Measured memory_bytes: 1028
import java.util.Scanner;
class Main{
  			public static void main(String args[]){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int n = sc.nextInt();
        
			switch (n % 10){
	          case 2:System.out.println("hon");
                break;
	          case 4:System.out.println("hon");
                break;
	          case 5:System.out.println("hon");
                break;
	          case 7:System.out.println("hon");
                break;
	          case 9:System.out.println("hon");
	            break;
	          case 0:System.out.println("pon");
                break;
	          case 1:System.out.println("pon");
                break;
	          case 6:System.out.println("pon");
                break;
	          case 8:System.out.println("pon");
	            break;
	          case 3:System.out.println("bon");
                break;
              default:break;
	        }
        }
	}

Measured memory_bytes: 35516
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int[] A = new int[N];
		for(int i = 1; i < N; i++) {
			int a = Integer.parseInt(sc.get()) - 1;
			A[a] += 1;
		}

		StringJoiner joiner = new StringJoiner("\n");
		for (int x : A) {
			joiner.add(String.valueOf(x));
		}
		System.out.println(joiner.toString());
	}
}

class Main {
	public static void main(String... args) {
		var reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
	}
}

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

int main() {
    string S;
    cin >> S;
    const int length = S.length();
    const int interval = length - 1;
    ll sum = 0;
    string tmp = "";

    for (int i = 0; i < (1 << interval); ++i) {
        bitset<10> b(i);
        vector<ll> split;
        tmp += S[0];
        for (int j = 0; j < interval; ++j) {
            if (b.test(j)) {
                split.push_back(atoll(tmp.c_str()));
                tmp = "";
            }
            tmp += S[j+1];
        }
        split.push_back(atoll(tmp.c_str()));
        tmp = "";
        sum += accumulate(split.cbegin(), split.cend(), 0.0);
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

string str;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    cin>>str;
    map<char,int>mp;
    ll sum=0;
    ll num;
    ll len=str.size();
    for(int i=0;i<=len-1;i++)
    {
        char dq=str[i];
        if(mp[dq]==0)
        {
            num=1;
            mp[dq]=1;
            for(int j=i+1;j<len;j++)
            {
                if(str[j]==dq)
                {
                    num++;
                }
            }
            sum+=(num*(num-1))/2;
        }
    }
    ll ans=(len*(len-1))/2+1-sum;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			String line = reader.readLine();
			int x = Integer.parseInt(line);
			System.out.println(x * x * x);
		} catch (IOException e) {
		} catch (NumberFormatException e) {
		}
	}
}

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

using namespace std;

bool all_zero(vector <int> V)
{
	bool flag = true;
	for (int i = 1; i < V.size(); i++) {
		if (V[0] == 0) {
			if (V[i - 1] != V[i])  flag = false;
		}
		else {
			flag = false;
		}
	}
	return flag;
}

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

	bool ans = true;
	if (all_zero(V)) {
		cout << "Yes" << endl;
		return 0;
	}

	if (n % 3 != 0) {
		cout << "No" << endl;
		return 0;
	}

	vector <int> S;
	int cnt = 0;
	sort(V.begin(), V.end());
	S.push_back(V[0]);
	for (int i = 1; i < n; i++) {
		if (V[i - 1] != V[i]) {
			cnt++;
			S.push_back(V[i]);
		}
	}

	if (cnt == 2) {
		if ((S[0] ^ S[1] ^ S[2]) != 0) {
			ans = false;
		}
		else {
			int s1 = 0, s2 = 0, s3 = 0;
			for (int i = 0; i < n; i++) {
				if (S[0] == V[i])  s1++;
				if (S[1] == V[i])  s2++;
				if (S[2] == V[i])  s3++;
			}
			if (s1 != s2 || s2 != s3)  ans = false;
		}
	}
	else if (cnt == 1) {
		int s1 = 0, s2 = 0;
		for (int i = 0; i < n; i++) {
			if (S[0] == V[i])  s1++;
			if (S[1] == V[i])  s2++;
		}
		if (S[0] != 0 || s2 != 2 * s1)  {
          ans = false;
        }
	}
	else {
		ans = false;
	}

	if (ans)  cout << "Yes" << endl;
	else  cout << "No" << endl;
}


Measured memory_bytes: 1360
#!/usr/bin/env ruby

A, V = gets.chomp.split.map(&:to_i)
B, W = gets.chomp.split.map(&:to_i)
T = gets.chomp.to_i

distance = (A - B).abs
velocity = V - W

if velocity * T >= distance
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 14264
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

cnt = sum(B)

for i in range(len(A)-1):
  if A[i+1] - A[i] == 1:
    cnt += C[A[i+1]-2]

print(cnt)

Measured memory_bytes: 3064
// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <list>
#include <cstdlib>
#include <bitset>
#include <assert.h>
#include <time.h>
#include <iomanip>
// #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
// char buf[(1 << 21) + 1], * p1 = buf, * p2 = buf;
// #define int long long
#define lowbit(x) (x & (-x))
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define pb push_back
typedef unsigned long long ull;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> VI;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define SZ(x) ((int)((x).size()))
#define bug puts("BUG")
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-6;
template <class T>
inline void read(T &x)
{
    int sign = 1;char c = getchar();x = 0;
    while (c > '9' || c < '0'){if (c == '-')sign = -1;c = getchar();}
    while (c >= '0' && c <= '9'){x = x * 10 + c - '0';c = getchar();}
    x *= sign;
}
#ifdef LOCAL
    FILE* _INPUT=freopen("input.txt", "r", stdin);
    // FILE* _OUTPUT=freopen("output.txt", "w", stdout);
#endif
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
int cnt[2019];
int main()
{
    scanf("%s", s);
    int len = strlen(s);
    int cur = 0;
    reverse(s, s + len);
    ++cnt[0];
    int ret = 1;
    for (int i = 0; i < len; ++i)
    {
        cur += (s[i] - '0') * ret;
        ret *= 10;
        ret %= 2019;
        cur %= 2019;
        cnt[cur]++;
    }
    ll res = 0;
    for (int i = 0; i < 2019; ++i)
    {
        res += cnt[i] * (cnt[i] - 1) / 2;
    }
    printf("%lld\n", res);
}

Measured memory_bytes: 3924
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
      	Scanner sc = new Scanner(System.in);
		String S = sc.next();
      	if(S.charAt(0)==S.charAt(1)&&S.charAt(0)==S.charAt(2)) System.out.println("No");	
      	else System.out.println("Yes");
    }
}

Measured memory_bytes: 20820
N = int(input())
A = list(map(int,input().split()))
A.append(-1)
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ret = 0
for i in range(N):
  ret += B[A[i]-1] + C[A[i]-1] if A[i+1] == A[i]+1 else B[A[i]-1]
print(ret)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    ll out=LNF;
    for(int i=0;i<N;i++){
        ll A;
        cin >> A;
        ll cnt=0;
        while(A%2==0){
            cnt++;
            A/=2;
        }
        if(out>cnt)out=cnt;
    }
    cout << out << endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int INF = int(1e9);
const int MOD = int(1e9) + 7;

int n;
LL a, b;
LL s[100005];
int nx[100005][2];
int d[100005];


vector<int> bad;

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> a >> b;
    if (a > b) {
        swap(a, b);
    }
    forn(i, n) {
        cin >> s[i];
    }
    forn(i, n - 1) {
        if (s[i + 1] - s[i] < a) {
            bad.pb(i);
        }
    }
    nx[n - 1][0] = nx[n - 1][1] = n;
    for (int i = n - 2; i >= 0; --i) {
        if (s[i + 1] - s[i] >= a) {
            nx[i][0] = i + 1;
        } else if (i == n - 2 || s[i + 2] - s[i] >= a) {
            nx[i][0] = nx[i + 1][1];
        } else {
            nx[i][0] = INF;
        }
        if (s[i + 1] - s[i] >= b) {
            nx[i][1] = i + 1;
        } else {
            int pos = lower_bound(s, s + n, s[i] + b) - s;
            auto it = lower_bound(bad.begin(), bad.end(), i + 1);
            if (it == bad.end() || *it >= pos - 1) {
                nx[i][1] = nx[pos - 1][0];
            } else {
                nx[i][1] = INF;
            }
        }
    }
    d[0] = 1;
    forn(i, n) forn(j, 2) {
        if (nx[i][j] != INF) {
            d[nx[i][j]] += d[i];
            if (d[nx[i][j]] >= MOD) {
                d[nx[i][j]] -= MOD;
            }
        }
    }
    cout << d[n] << endl;
    return 0;
}


Measured memory_bytes: 2680
using System;
using System.Collections.Generic;
namespace abc151C
{
    class Class
    {
        static void Main(string[] args)
        {
            string[] array = (Console.ReadLine().Split(' '));
            int N = int.Parse(array[0]);
            int M = int.Parse(array[1]);
            var Clear = new bool[N];
            int AC = 0;
            var WAC = new int[N];

            for (int i = 0; i < M; i++)
            {
                array = Console.ReadLine().Split(' ');
                int Num = int.Parse(array[0]) - 1;
                if (array[1] == "WA" && Clear[Num] == false) WAC[Num]++;
                else if(array[1]=="AC"&& Clear[Num]==false)
                {
                    AC++;
                    Clear[Num] = true;
                }
            }
            int WA = 0;
            for(int i = 0; i < N; i++)
            {
                if (Clear[i]) WA += WAC[i];
            }
            Console.WriteLine("{0} {1}",AC,WA);
        }
    }
}

Measured memory_bytes: 17480
#include<iostream>
#include<string.h>
#include<vector>

using namespace std;

#define STA_MAX 52

int main()
{
	//駅順
	string sta = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";	
	int n;					//鍵の数
	int keynum[100];				
	char s[100];				//暗号となる文字列
	char ans[100];				//解読された文字列
	int count=0;

	while(true)
	{
		cin>>n;		//鍵の入力

		if(n==0)	break;

		//鍵内容の入力
		for(int i=0;i<n;i++)
		{
			cin>>keynum[i];
		}

		//暗号の入力
		cin>>s;

		for(int i=0;i<strlen(s);i++)
		{
			for(int j=0;j<sta.size();j++)
			{
				if(sta[j]==s[i])
				{
					if(j-keynum[count]>=0)
					{
						ans[i]=sta[j-keynum[count]];
					}
					else
					{
						ans[i]=sta[(STA_MAX+j)-keynum[count]];
					}
				}
			}
			count++;
			if(count==n)	count=0;
		}

		for(int i=0;i<strlen(s);i++)
		{
			cout<<ans[i];
		}
		cout<<endl;

		count=0;
	}
}

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

#define ll              long long int
#define ull             unsigned long long int
#define pii             pair < int, int>
#define pll             pair < ll, ll>
#define sc              scanf
#define scin(x)         sc("%d",&(x))
#define scln(x)         sc("%lld",&(x))
#define pf              printf
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define mp              make_pair
#define db              double
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define vi              vector< int >
#define vl              vector< ll >
#define vii             vector<vector< int > >
#define vll             vector<vector< ll > >
#define DBG             pf("HI\n")
#define MOD             1000000007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define RUN_CASE(t,T)   for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)         printf("Case %d: ",t)
#define CASEL(t)        printf("Case #%d:\n",t)
#define intlimit        2147483648
#define longlimit       9223372036854775808
#define infinity        (1<<28)
#define gcd(a, b)       __gcd(a,b)
#define lcm(a, b)       ((a)*(b)/gcd(a,b))
#define mx              1234567899
#define PI              2*acos(0.0)
#define rep(i,a,b)      for(__typeof(i) i=a; i<=b; i++)
#define rev(i,a,b)      for(__typeof(i) i=a; i>=b; i--)


using namespace std;

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

vector <ll> graph[100005];
int visited[100005];
ll dist[100005];

void make_graph(ll u, ll v)
{
    graph[u].pb(v);
    visited[v]++;
}

ll DFS(ll u)
{
    if((ll)graph[u].size() == 0)
    {
        dist[u] = 0;
        return 0;
    }
    ll ret = 0;
    if(dist[u]!=-1) return dist[u];
    for(ll i = 0; i < (ll)graph[u].size(); i++ )
    {
        ret = max(ret, DFS(graph[u][i]));
    }
    return dist[u] = ret + 1;
}

int main()
{
    ll n,m,a,b;
    scln(n);
    scln(m);
    for(ll i = 0; i < m; i++)
    {
        scln(a);
        scln(b);
        make_graph(a,b);
    }
    ms(dist,-1);
    for(ll i = 1; i <= n; i++)
    {
        DFS(i);
    }
    ll nim = 0;
    for(ll i = 1; i <= n; i++)
    {
        nim = max(nim, dist[i]);
    }
    pf("%lld\n",nim);
    return 0;
}


Measured memory_bytes: 8960
#include<cstdio>
#include<iostream>
using namespace std;
int main(void)
{
	int n,m;
	scanf("%d %d",&n,&m);
	if(n == 1) printf("%d",m);
	else{
		for(int i = m-n+1;i<n+m;i++)
			printf("%d ",i);
	}
	return 0;	
} 

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

int main(){
  char s;
  string ans;
  cin >> s;
  if( s=='a' || s=='i' || s=='u' || s=='e'|| s=='o'){
    ans="vowel";
  }
  else{
    ans="consonant";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if(x==1)
    {
        if(y==1)
            cout<<1000000;
        else if(y==2)
            cout<<500000;
        else if(y==3)
            cout<<400000;
        else
            cout<<300000;
    }
    else if(x==2)
    {
        if(y==1)
            cout<<500000;
        else if(y==2)
            cout<<400000;
        else if(y==3)
            cout<<300000;
        else
            cout<<200000;
    }
    else if(x==3)
    {
        if(y==1)
            cout<<400000;
        else if(y==2)
            cout<<300000;
        else if(y==3)
            cout<<200000;
        else
            cout<<100000;
    }
    else
    {
        if(y==1)
            cout<<300000;
        else if(y==2)
            cout<<200000;
        else if(y==3)
            cout<<100000;
        else
            cout<<0;
    }
    return 0;
}


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

///    ____ ____ ____ ____ ____
///   ||a |||t |||o |||d |||o ||
///   ||__|||__|||__|||__|||__||
///   |/__\|/__\|/__\|/__\|/__\|
///

using namespace std;

typedef long long ll;

const int N_MAX = 300002;
const int BITS = 19;

int A, B, C;

int n;

struct Person
{
    int a, b, c;
    int nb;
    int nc;
};

bool operator < (const Person &x, const Person &y)
{
    return x.c - x.b < y.c - y.b;
}

Person p[N_MAX];

bool cmpb (const Person &x, const Person &y)
{
    return x.b - x.a < y.b - y.a;
}

bool cmpc (const Person &x, const Person &y)
{
    return x.c - x.a < y.c - y.a;
}

int BIT1[N_MAX];
ll BIT2[N_MAX];

void update (int pos, ll val)
{
    for(int i = pos; i <= n; i += i & -i)
    {
        BIT1[i]++;
        BIT2[i] += val;
    }
}

ll query (int pos)
{
    ll ans = 0;
    for(int i = pos; i >= 1; i -= i & -i)
        ans += BIT2[i];
    return ans;
}

int querykth (int k)
{
    int ans = 0;
    for(int b = BITS; b >= 0; b--)
        if(ans + (1 << b) <= n && BIT1[ans + (1 << b)] < k)
        {
            ans += (1 << b);
            k -= BIT1[ans];
        }
    ans++;
    return ans;
}

ll pref[N_MAX], suff[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> A >> B >> C;
    n = A + B + C;
    for(int i = 1; i <= n; i++)
        cin >> p[i].a >> p[i].b >> p[i].c;
    sort(p + 1, p + n + 1, cmpb);
    for(int i = 1; i <= n; i++)
        p[i].nb = n - i + 1;
    sort(p + 1, p + n + 1, cmpc);
    for(int i = 1; i <= n; i++)
        p[i].nc = n - i + 1;
    sort(p + 1, p + n + 1);
    ll sum = 0;
    for(int i = 1; i <= n; i++)
        sum += p[i].a;
    for(int i = 1; i <= n; i++)
    {
        update(p[i].nb, p[i].b - p[i].a);
        if(i < B)
            continue;
        pref[i] = query(querykth(B));
    }
    memset(BIT1, 0, sizeof(BIT1));
    memset(BIT2, 0, sizeof(BIT2));
    for(int i = n; i >= 1; i--)
    {
        update(p[i].nc, p[i].c - p[i].a);
        if(n - i + 1 < C)
            continue;
        suff[i] = query(querykth(C));
    }
    ll ans = LLONG_MIN;
    for(int i = B; i <= n - C; i++)
        ans = max(ans, sum + pref[i] + suff[i + 1]);
    cout << ans << "\n";
    return 0;
}


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


int N;
int F[101][15];
int P[101][14];
ll one( ll b){
	ll sum=0;
	for (int i=0;i<N;i++){
		ll c = 0;
		for(int j=0;j<10;j++)if((b>>j&1)&&F[i][j])c++;
		sum+=P[i][c];
	}
	return sum;
}

int main(){
	cin >> N;

	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++){
			cin >> F[i][j];
		}
	}

	for(int i=0;i<N;i++){
		for(int j=0;j<11;j++){
			cin >> P[i][j];
		}
	}
	ll ans=-2000000000;
	for(int b=1;b<(1 << 10);b++){
		ans = max(ans,one(b));
	}
	cout << ans << endl;
}


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

const int INF = 1e9;

int main() {
	int N, K, S; scanf("%d%d%d",&N,&K,&S);
	if(S != INF) for(int i=1; i<=N; i++) {
		if(i <= K) printf("%d ", S);
		else printf("%d ", INF);
	}
	else for(int i=1; i<=N; i++) {
		if(i <= K) printf("%d ", INF);
		else printf("1 ");
	}
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
int gcd(a, b){
	if(a == b){
		return a;
	}
	else if(a > b){
		return b == 0 ? a : gcd(a%b, b);
	}
	else{
		return a == 0 ? b : gcd(b%a, a);
	}
}

int main(void){
	int n;
	long x = 0;
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		for(int j=1; j<=i; j++){
			for(int k=1; k<=j; k++){
				if(i==j && j==k){
					x += gcd(gcd(i, j), k);
				}
				else if(i==j || j==k){
					x += 3*gcd(gcd(i, j), k);
				}
				else{
					x += 6*gcd(gcd(i, j), k);
				}
			}
		}
	}
	printf("%ld\n", x);
	return 0;
}

Measured memory_bytes: 1736
#include <cstdio>

int main() {
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	int coins_per_week = A * 7 + B;
	int weeks = C / coins_per_week;
	int remains = C - weeks * coins_per_week;
	int answer = (remains + A - 1) / A;
	if(answer > 7) answer = 7;
	answer += weeks * 7;
	printf("%d\n", answer);
}


Measured memory_bytes: 2748
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] AC = s.split("");
        boolean ans = true; 
        int cc = 0;
        if(AC[0].equals("A")){
            for(int i = 1; i < AC.length; i++){
                if(AC[i].toUpperCase().equals(AC[i])){
                    if(i == 1 || i == AC.length-1){
                        ans = false;
                    }else{
                        if(AC[i].equals("C")){
                            cc ++;
                        }else{
                            ans = false;
                        }
                    }
                }
            }
        }else{
            ans = false;
        }
        if(cc != 1){
            ans = false;
        }
        if(ans){
            System.out.println("AC");
        }else{
            System.out.println("WA");
        }
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;
const ll INF = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2); return sq*sq; } else { return N*RS(N, P - 1); } } //power(repeat-square,fast)
ll nPr(ll n, ll r) { ll ans = 1; rep(i, r) { ans = ans * (n - i); } return ans; } //permutation
ll nCr(ll n, ll r) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1); bunshi = bunshi * (n - i); } return bunshi / bunbo; } //combination
ll RS(ll N, ll P, ll Mod) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination
priority_queue<int, std::vector<int>, std::greater<int>> p,q;
priority_queue<int> r;
int X,Y,A,B,C;
int main(void) {
  cin >> X >> Y >> A >> B >> C;
  rep(i,A){int x;cin >> x;p.push(x);}
  rep(i,B){int x;cin >> x;q.push(x);}
  rep(i,C){int x;cin >> x;r.push(x);}
  
  while(SZ(p) > X){
    p.pop();
  }
  while(SZ(q) > Y){
    q.pop();
  }

  rep(i,C){
    int a = p.top(); p.pop();
    int b = q.top(); q.pop();
    int c = r.top(); r.pop();
    
    if (a < b){
      if (a < c){
        p.push(c);
        q.push(b);
      }
      else{
        p.push(a);
        q.push(b);
      }
    }
    else{
      if (b < c){
        q.push(c);
        p.push(a);
      }
      else{
        p.push(a);
        q.push(b);
      }
    }
    
  }
  
  ll res = 0;
  rep(i,X){
    res += p.top();
    p.pop();
  }
  rep(i,Y){
    res += q.top();
    q.pop();
  }
  
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	int n;
	sd(n);
	ll ans=0;
	fi(1,n, 1){
		ans+=ceil((n-1)/i);
	}
	cout<<ans;
}

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

typedef long long ll;
typedef unsigned long long llu;
typedef long double ldo;
#define forz(iter,n)	for(ll iter=0;iter<n;++iter)
#define rep(iter,s,e)	for(ll iter=s;iter<e;++iter)
#define urep(iter,s,e)	for(ll iter=s;iter>=e;--iter)
#define MOD				(ll)1000000007
#define pp				pair<ll,ll>
#define vii				vector<int>
#define vll				vector<ll>
#define vpp				vector<pp>
#define vss				vector<string>
#define take(A,n)		{forz(iter,n)cin>>A[iter];}
#define pb				push_back
#define pob				pop_back
#define eb				emplace_back
#define pf				push_front
#define pof				pop_front
#define mkp				make_pair
#define all(a)			a.begin(),a.end()
#define ff				first
#define ss				second
#define lcm(a,b)		(a*b)/__gcd(a,b)
#define bs(v,x)			binary_search(all(v),x)
#define ub(v,x)			upper_bound(all(v),x)
#define lb(v,x)			lower_bound(all(v),x)
#define zoom			ios_base::sync_with_stdio(false);cin.tie(NULL);
template <class C> void setmin(C &a,C b){if(a>b)a=b;}
template <class C> void setmax(C &a,C b){if(a<b)a=b;}
template <class C> void printv(vector<C> vec,string end=" "){for(auto const&iter:vec)cout<<iter<<end;if(end!="\n")cout<<endl;}
template <class C> void printv(set<C> setc,string end=" "){for(auto const&iter:setc)cout<<iter<<end;if(end!="\n")cout<<endl;}
template <class C> void print(C A[],ll n,string end=" "){forz(iter,n)cout<<A[iter]<<end;if(end!="\n")cout<<endl;}
//for(auto const&x:mp)

class Solution
{
	public:
	void SolutionFunc()
	{
		ll n;
		cin>>n;
		cout<<(n-1)/2<<endl;
	}
};
int main()
{
	zoom;
	Solution ob;
	ll t=1;
	// cin>>t;
	forz(t1,t)
	{
		// cout<<"Case #"<<t1+1<<": ";
		ob.SolutionFunc();
	}
	return 0;
}

Measured memory_bytes: 256
N = gets.strip.to_i
W = gets.strip.split(' ').map(&:to_i)
c = nil
0.upto(N-2).each do |n|
  s1 = W[0..n]
  s2 = W[n+1..(W.size - 1)]
  sub = (s1.inject(&:+) - s2.inject(&:+)).abs
  c = sub if c == nil || c > sub
end
puts c

Measured memory_bytes: 1788
c = [list(map(int,input().split())) for i in range(3)]
for i in range(-101,101):
  for j in range(-101,101):
    for k in range(-101,101):
      a = [i,j,k]
      b = [c[0][0] - a[0] ,c[1][1] - a[1], c[2][2] - a[2]]
      flag = 0
      for x in range(3):
        for y in range(3):
          if a[x]+b[y] != c[x][y]:
            flag = 1
      if flag == 0:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 46636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main()
{
  int q;
  cin >> q;
  
  for(int i = 0; i < q; i++){
    ll a, b;
    cin >> a >> b;

    if(a > b) swap(a, b);
    
    if(a == b){
      cout << 2*min(a, b) - 2 << endl;  
    }else if(a+1 == b){
      cout << 2*min(a, b) - 2 << endl;
    }else{
      ll c = sqrt(a * b);
      if(c * c == a * b){
        if(a == c){
          cout << 2*c - 2 << endl;
        }else{
          cout << 2*c - 3 << endl;
        }
      }else if(c * (c+1) >= a * b){
        cout << 2*c - 2 << endl;
      }else{
        cout << 2*c - 1 << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define INF 9223372036854775807
const ll mod=1e9+7;


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

    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=min(k,a)-max(0ll,(k-a-b));
    cout<<ans;


    return 0;
}


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


h, w = map(int, input().split())

MAZE = ["#" * (w + 2)]
for _ in range(h):
    s = "#" + input().strip() + "#"
    MAZE.append(s)
MAZE.append("#" * (w + 2))

I = [-1, 0, 0, 1]
J = [0, -1, 1, 0]
def bfs(r, c):
    DISTANCES = {}
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            DISTANCES[(i, j)] = -1
    DISTANCES[(r, c)] = 0
    Q = [(r, c)]
    while Q:
        i, j = Q.pop(0)
        for k in range(4):
            if MAZE[i + I[k]][j + J[k]] == "." and DISTANCES[(i + I[k], j + J[k])] == -1:
                DISTANCES[(i + I[k], j + J[k])] = DISTANCES[(i, j)] + 1
                Q.append((i + I[k], j + J[k]))
    return max(DISTANCES.values())

BFS = []
for r in range(1, h + 1):
    for c in range(1, w + 1):
        if MAZE[r][c] == ".":
            BFS.append(bfs(r, c))

print(max(BFS))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define N 200005
ll mod=1000000007;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(x) x.begin(),x.end()
#define lb lower_bound
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}

vector<ll> g[100001];
bool visited[100001]={0};
ll col[100001];
bool flag=0;
ll depth[100001]={0};

void dfs1(ll x){
    visited[x]=1;
    for(int i=0;i<g[x].size();i++){
        if(visited[g[x][i]]==0){
            col[g[x][i]]=!col[x];
            dfs1(g[x][i]);
        }
        else{
            ll x1=col[x];
            ll x2=!col[g[x][i]];
            if(x1!=x2){
                flag=1;
            }
        }
    }
}

int main(){
    fast;
    
    ll n;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    
    ll cnt=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i][j]=='1'){
                g[i+1].pb(j+1);
                g[j+1].pb(i+1);
            }
        }
    }

    
    for(int i=1;i<=n*n;i++){
        col[i]=-1;
    }
    col[1]=1;
    dfs1(1);
    ll max1=0;
    if(flag){
        cout<<"-1"<<endl;
    }
    else{
        for(int i=1;i<=n;i++){
            queue<ll> q;
            visited[i]=1;
            q.push(i);
            while(!q.empty()){
                ll x=q.front();
                q.pop();
                for(int i=0;i<g[x].size();i++){
                    if(visited[g[x][i]]==0){
                        visited[g[x][i]]=1;
                        depth[g[x][i]]=depth[x]+1;
                        q.push(g[x][i]);
                    }
                }
            } 
            for(int i=1;i<=n;i++){
                max1=max(max1,depth[i]);
            }
            for(int i=1;i<=n;i++){
                visited[i]=0;
                depth[i]=0;
            }
        }
      
        cout<<max1+1<<endl;
        
    }
    return 0;
}


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

bool isPrime(int n) {
    for (int j = 2; j <= int(sqrt(n)); j++) {
        if (n % j == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        int num;
        cin >> num;
        if (isPrime(num)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3076
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
using namespace std;
#define maxn 100010
typedef long long ll;


int n,m,k;


int main()
{
  int a,b,c;
  while(cin>>a>>b>>c)
  {



  int ans=0;
  ans=a*100+b*10+c;
  if(ans%4==0)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;


  }



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main(){
  ll H,N;
  cin >> H >> N;
  vector<ll> A(N),B(N);
  for(int i = 0; i < N; i++){
    cin >> A[i] >> B[i];
  }
  vector< vector<ll> > dp(N+1, vector<ll>(H+1, INF));
  dp[0][0] = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j <= H; j++){
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
      dp[i+1][min(j+A[i],H)] = min(dp[i+1][min(j+A[i], H)], dp[i+1][j] + B[i]);
    }
  }
  cout << dp[N][H] << endl;
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)

typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int ans = INF;
  rep(i, s.size()-t.size()+1) {
    int sum = 0;
    rep(j, t.size()) {
      if (s[i+j] != t[j])
        sum++;
    }
    chmin(ans, sum);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
// 髙橋君とカード
#include <iostream>
using namespace std;

int N,A;
int x[60];
long long dp[60][60][2600];

int main(){
    cin>>N>>A;
    for(int i=1;i<=N;i++){
        cin>>x[i];
    }
    dp[0][0][0]=1;
    for(int i=1;i<=N;i++){
        for(int k=0;k<=i;k++){
            for(int s=0;s<2600;s++){
                if(s<x[i]) dp[i][k][s]=dp[i-1][k][s];
                else if(k) dp[i][k][s]=dp[i-1][k][s]+dp[i-1][k-1][s-x[i]];
            }
        }
    }
    long long ans=0;
    for(int i=1;i<=N;i++){
        ans+=dp[N][i][A*i];
    }
    cout<<ans;
}

Measured memory_bytes: 61696
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define REP(i,n) for(int i=0; i<(n); ++i)
int main()
{
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> row(h), column(w);
  set<pair<int, int>> bomb;
  REP(i,m){
    int a,b;
    cin >> a >> b;
    --a; --b;
    ++row[a]; ++column[b];
    bomb.emplace(a,b);
  }
  int mh = 0, mw = 0 ; 
  vector<int> max_row, max_column;
  REP(i, h) mh = max(row[i], mh);
  REP(i, w) mw = max(column[i], mw);
  REP(i, h) if(mh == row[i]) max_row.push_back(i);
  REP(j, w) if(mw == column[j]) max_column.push_back(j);
  int ans = mh + mw;
  int faul = 0;
  for(int i:max_row) for(int j:max_column){
      if(bomb.count(P(i,j))) continue;
      cout << ans << endl;
      return 0;
  }
  --ans;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 23872
s = input()
#Aの海をかき分けてBCが進む

r = list(reversed(list(s)))
r = ['X'] + r + ['X']
#print(r)
BC_cnt = 0
A_cnt = 0
cnt = 0
for i in range(1, len(s) + 1):
    if r[i] == 'A':
        cnt += BC_cnt
        #print(BC_cnt, A_cnt)
    elif r[i] == 'C' and r[i + 1] == 'B':
        BC_cnt += 1
    elif r[i - 1] == 'C' and r[i] == 'B':
        pass
    else:
        BC_cnt = 0
print(cnt)


Measured memory_bytes: 63088