akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9 + 7

N, K = map(int, read().split())

A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

for d in range(K, 0, -1):
    for i in range(2, K // d + 1):
        A[d] -= A[d * i]

answer = sum(d * x for d, x in enumerate(A))
print(answer % MOD)


Measured memory_bytes: 11540
#include<bits/stdc++.h>
using namespace std;
#define MOD int(1e9+7)

int main()
{
    int n,m;cin>>n>>m;
    long long ans=1;
    int i;
    if(abs(n-m)>=2)ans=0;
    else if(n==m)
    {
        for(i=1;i<=n;i++)
        {
            ans=(ans*i)%MOD;
            ans=(ans*i)%MOD;
        }
        ans=(ans*2)%MOD;
    }
    else
    {
        int l = min(m,n);
        for(i=1;i<=l;i++)
        {
            ans=(ans*i)%MOD;
            ans=(ans*i)%MOD;
        }
        ans=(ans*(l+1))%MOD;
    }
    cout<<ans<<endl;
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;




int main() {
	
	int n, x, y;
	cin >> n >> x >> y;
	VI a(n + 2, 0);
	x--; y--;
	REP(i, n) {
		FOR(j, i + 1, n) {
			int cur = (j - i);

			int b = abs(i - x);
			int c = abs(j - y);

			cur = min(cur,b + c + 1);
			a[cur]++;
		}
	}

	REP(i, n - 1)cout << a[i + 1] << endl;

}



Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int n, k;
  scanf("%d %d", &n, &k);
  
  double ans = 0;
  for (int i = 1; i <= n; ++i)
  {
    double p = 1;
    for (int i2 = i; i2 < k; i2 <<= 1) p *= .5;
    ans += p;
  }
  printf("%.16f\n", ans / n);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    int x = x2;
    int y = y2;
    int dx = x2-x1;
    int dy = y2-y1;
    rep(i,0,1){
        swap(dx,dy);
        dx = -dx;
        x += dx;
        y += dy;
        cout<<x<<' '<<y<<' ';
    }
    cout<<"\n";

    return 0;
}

Measured memory_bytes: 888
using System;
using System.Linq;

namespace Sample1
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = int.Parse(Console.ReadLine());
            long[] numbers = Console.ReadLine()
                .Split(' ')
                .Select(x => long.Parse(x))
                .ToArray();
                ;
            long sum = 0;
            for (int i = 0; i < n; i += 1)
            {
                sum += numbers[i];
            }
            Array.Sort(numbers);
            
            Console.WriteLine("{0} {1} {2}",
                numbers[0],
                numbers[n - 1],
                sum);
        }
    }
}

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

int main() {
  int N,M,X;
  cin >> N >> M >> X ;
  vector<int> C(N);
  vector<vector<int>> A(N);
  for(int i=0;i<N;i++){
    cin >> C[i];
    for(int j=0;j<M;j++){
      int tmp;
      cin >> tmp;
      A[i].push_back(tmp);
    }
  }
  vector<int> cost;
  vector<int> p(M);
  for(int i=0;i<pow(2,N);i++){
    int tmpcost = 0;
    for(int k=0;k<N;k++){
      tmpcost += (i >> k & 1)*C[k];
    }
    for(int j=0;j<M;j++){
      p[j] = 0;
      for(int k=0;k<N;k++){
        p[j] += (i >> k & 1)*A[k][j];
      }
    }
    bool ok = true;
    for(int j=0;j<M;j++){
      if(p[j] < X){
        ok = false;
        break;
      }
    }
    if(ok) cost.push_back(tmpcost);
  }
  if(cost.size() == 0){
    cout << -1 << endl;
  }else {
    sort(cost.begin(), cost.end());
    cout << cost[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 3196
#pragma region GNUC
//以下を参考にした
//https://yukicoder.me/wiki/auto_vectorization
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#pragma endregion

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;
#pragma region Math
// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}

// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}

template<class T>
T pow(T x,int n){
	T mul = x;
	T ans = (T)1;
	while(n){
		if(n&1){
			ans *= mul;
		}
		mul *= mul;
		n >>= 1;
	}
	return ans;
}
#pragma endregion //math

void solve(){
	int A,B,C;
	cin >> A >> B >> C;
	cout << (A+B)*C/2 ;
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}


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

int dp[101][10001];
int main()
{
	int N, W;
	int v[101], w[101];

	cin >> N >> W;
	REP(i, 0, N) cin >> v[i] >> w[i];
	REP(i, 0, 101) REP(j, 0, 10001) dp[i][j] = 0;

	REP(i, 0, N) {
		REP(j, 0, W + 1) {
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if (j + w[i] <= W) dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
		}
	}

	int ans = -1;
	REP(j, 0, W + 1) ans = max(ans, dp[N][j]);
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7040
#include "bits/stdc++.h"
using namespace std;

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (C >= B) {
		cout << 0 << endl;
	}
	else {
		cout << max(0,min(B, D) - max(A, C)) << endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

void probD() {
	int N; cin >> N;
	vi vec(N);
	rep(i, N) cin >> vec[i];
	sort(ALL(vec),greater<int>());
	
	ll ans = -vec[0];
	for (int i = 0; i < N; i++) {
		int label = i / 2;
		ans += vec[label];
	}

	cout << ans << endl;
}

int main() {
	probD();
}

Measured memory_bytes: 4048
#include <iostream>
#include <cstdio>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>

using namespace std;

int main()
{
    int a,b;
    char op;
    while(op != '?'){
        cin >> a >> op >> b;
        switch(op){
            case '+':
                cout << a+b << endl;
                break;
            case '-':
                cout << a-b << endl;
                break;
            case '*':
                cout << a*b << endl;
                break;
            case '/':
                cout << a/b << endl;
                break;
            default:
                break;
        }
    }
}

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int n;
    cin >> n;
    map<ll, ll> dictl;
    map<ll, ll> dictr;
    ll ans = 0;
    rep(i, n) {
        ll a;
        cin >> a;
        ll l = i + a;
        ll r = i - a;
        ans += dictr[l];
        ans += dictl[r];
        dictl[l]++;
        dictr[r]++;
    }
    out(ans);

    return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int a, b, x;
  cin >> a >> b >> x;
  string ans;
  if(a<=x && x<=a+b) ans = "YES";
  else ans = "NO";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int k, n;
    cin >> k >> n;
    vector<int> vec(n);
    for(int i = 0; i <n; i++){
        int x;
        cin >> x;
        vec[i] = x;
    }
    vector<int> diff;
    
    for(int i =0;i<n-1;i++){
        diff.push_back(vec[i+1] - vec[i]);
    }
    int len = vec.size();
    diff.push_back(k-(vec[len-1]-vec[0]));
    
    int maxi = INT_MIN;
    int sum = 0;
    for(int i = 0;i < diff.size(); i++){
        sum += diff[i];
         maxi = max(maxi, diff[i]);
        
    }
    cout << sum - maxi;
}









Measured memory_bytes: 2168
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    a.sortDescending()
    val k = a[m - 1]
    val sum = a.sum()
    if (4 * k * m >= sum) {
        println("Yes")
    } else {
        println("No")
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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

int N, Q;
int const INF = INT_MAX;
/*
AOJ DSL2_A
Range Minimum Query (RMQ)
数列 A = {a0,a1 ,...,an-1} に対し、次の２つの操作を行うプログラムを作成せよ。
update(i,x): aiをxに変更する。
find(s,t): as,as+1,...,atの最小値を出力する。
ただし、ai (i=0,1,...,n−1)は、231-1で初期化されているものとする。
入力
n q
com0 x0 y0
com1 x1 y1
...
comq−1 xq−1 yq−1
制約
1≤n≤100000
1≤q≤100000
comiが0のとき、0≤xi<n, 0≤yi<231−1
comiが1のとき、0≤xi<n, 0≤yi<n
入力例 1
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
出力例 1
1
2
*/
struct SegmentTree {
private:
    int n;
    vector<int> node;

public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1; while (n < sz) n *= 2;
        node.resize(2 * n - 1, INF);
        for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }

    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2 * x + 1], node[2 * x + 2]);
        }
    }

    int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b) return node[k];

        int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
};

int main() {
    cin >> N >> Q;
    SegmentTree seg(vector<int>(N, INF));
    for (int i = 0; i < Q; i++) {
        int c, x, y; cin >> c >> x >> y;
        if (c == 0) seg.update(x, y);
        else cout << seg.getmin(x, y + 1) << endl;
    }
}


Measured memory_bytes: 4148
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    printf("%d %d %d\n", x, y, z);
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define esp 1e-6
using namespace std;
long long  read(){
	long long x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,m;
int k;
int num[1100][1100];

int main(){
	n=read();m=read();k=read();
	for (int i=0;i<=n;i++){
		for (int j=0;j<=m;j++){
			if (i*m+j*n-2*i*j==k){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    S = input().rstrip()
    K = int(input())
    if len(set(S)) == 1:
        ans = len(S)*K //2 
        print(ans)
        return
    CNT = 1
    ans = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            CNT += 1
        else:
            ans += CNT//2
            CNT = 1
    ans += CNT//2

    if S[0] != S[len(S)-1]:
        print(ans*K)
    else:
        ans2 = 0
        CNT = 1
        SS = S + S
        for i in range(len(SS)-1):
            if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans2 += CNT//2
                CNT = 1
        ans2 += CNT//2
        # print(ans*(K-1))
        print(ans*K + (ans2-ans*2)*(K-1))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9248
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n) ;i++)

using namespace std;
using p=pair<int,int>;
typedef long long ll;
const double pi=3.1415926535;

int main(void) {
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double n=m/60;
  double x=(60*h+m)/720;
  double c = 2*pi*n;
  double d = 2*pi*x;
  double w = fabs(c-d);
  double ans;
  double r=cos(w);
  ans=a*a+b*b-2*a*b*r;
  double s=sqrt(ans);
  cout << setprecision(20) << s << endl;
  

  return 0;

}



Measured memory_bytes: 4112
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]


N, M = map(int, input().split())
Un = WeightedUnionFind(N+1)

ans = "Yes"
for _ in range(M):
    l, r, w = map(int, input().split())
    if Un.same(l, r):
        if Un.diff(l, r) != w:
            ans = "No"
            break
    else:
        Un.union(l, r, w)
print(ans)


Measured memory_bytes: 10212
use proconio::input;
use proconio::marker::Chars;

#[allow(dead_code)]
fn dump(a: &Vec<bool>) -> String {
    a.iter().map(|&c| if c { 'W' } else { 'R' } ).collect()
}

#[allow(dead_code)]
fn type_of<T>(_: T) -> &'static str {
    std::any::type_name::<T>()
}

fn main() {
    input!{
        _: usize,
        a: Chars,
    }
    let mut a = a.iter().map(|&c| c == 'W').collect::<Vec<bool>>();

    let mut itr = a.iter_mut();
    let mut ans = 0usize;
    while let Some(c) = itr.by_ref().skip_while(|c| !**c).next() {
        if let Some(s) = itr.rfind(|s| !**s) {
            std::mem::swap(c, s);
            ans += 1;
        }
    }
    println!("{}", ans);


}


Measured memory_bytes: 3296
import collections

N = int(input())
a = list(int(i) for i in input().split())

b = a[::2]
c = a[1::2]

b_ =collections.Counter(b)
c_ =collections.Counter(c)

baa = b_.most_common()
caa = c_.most_common()

baa.append([0,0])
caa.append([0,0])

if baa[0][0] != caa[0][0]:
    print(N - baa[0][1] - caa[0][1])
else:
    print(min(N - baa[0][1] - caa[1][1],N - caa[0][1] - baa[1][1]))

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

int main(){
  double a, b, C;
  cin >> a >> b >> C;
  double theta = M_PI*C/180;
  double c = sqrt(a*a + b*b -2*a*b*cos(theta));
  double h = b * sin(theta); 
  double S = a*h/2;
  printf("%0.8f\n", S);
  printf("%0.8f\n", a+b+c);
  printf("%0.8f\n", h);

  return 0;
}

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

int main() {
	int w, h, n;
	cin >> w >> h >> n; 
	int w1 = 0, w2 = w, h1 = 0, h2 = h; 
	for(int i = 0; i < n; i++){
		int x, y, a; 
		cin >> x >> y >> a; 
		if(a == 1) w1 = max(w1, x);
		else if(a == 2) w2 = min(w2, x);
		else if(a == 3) h1 = max(h1, y);
		else if(a == 4) h2 = min(h2, y);
	}
	cout << max(w2 - w1, 0) * max(h2 - h1, 0) << endl; 
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private final byte MASK_RIGHT = 0x0F;//右4bit数値化用マスク
	private int[][] paper = new int[10][10];//都合の良い方眼紙

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

	private void execute() throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 128);
		String sLine;
		while ((sLine = reader.readLine()) != null) {
			droppingInk(sLine.charAt(0) & MASK_RIGHT, sLine.charAt(2) & MASK_RIGHT, sLine.charAt(4) & MASK_RIGHT);
		}
		calcResult();
	}

	/**
	 *都合の良い滴下
	 */
	private void droppingInk(int x, int y, int size) {
		sinking(x, y - 1);
		sinking(x - 1, y);
		sinking(x, y);
		sinking(x + 1, y);
		sinking(x, y + 1);
		if (size == 1) {
			return;
		}

		sinking(x - 1, y - 1);
		sinking(x + 1, y - 1);
		sinking(x - 1, y + 1);
		sinking(x + 1, y + 1);
		if (size == 2) {
			return;
		}

		sinking(x, y - 2);
		sinking(x - 2, y);
		sinking(x + 2, y);
		sinking(x, y + 2);
	}

	/**
	 * 床は汚さないようにする
	 */
	private void sinking(int x, int y) {
		if (x >= 0 && x < 10 && y >= 0 && y < 10) {
			paper[x][y]++;
		}
	}

	/**
	 *紙の染みを数え、損害を報告する
	 */
	private void calcResult() {
		int white = 0;//綺麗な部分
		int max = 0;//一番ひどい汚れ
		for (int[] row : paper) {
			for (int colum : row) {
				if (colum == 0) {
					white++;
				} else if (colum > max) {
					max = colum;
				}
			}
		}
		System.out.println(white);
		System.out.println(max);
	}
}

Measured memory_bytes: 16852
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define all(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*
2d pointer array
int **dp;
in main function
int row,col;
dp=new int*[n];
rep(i,n)dp[i]=new int[m]
*/
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  string s;
  cin>>s;
  if(s=="Sunny")cout<<"Cloudy";
  else if(s=="Cloudy")cout<<"Rainy";
  else if(s=="Rainy")cout<<"Sunny";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int n, res;
string s;
int main() {
    DAU
    cin >> n >> s;
    s = '$' + s;
    for (int i = 1; i <= n - 2; ++i)
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
            ++res;
    cout << res;
    PLEC
}


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

using namespace std;
using ll = long long;
#define int ll

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

const ll LLINF = (1LL<<60);

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }

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

  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    string s, t;
    cin >> s >> t;

    int ans = LLINF;
    function<void(int,int,string)> dfs = [&](int idx, int cost, string str) {
      if(idx == n || str == t) { chmin(ans, cost); return; }
      // idx番目をstr[idx]->t[idx]にもっていくのにかかるコスト
      int diff = t[idx]-str[idx];
      if(diff<0) diff += 10;
      // [idx, i] を回転させる
      FOR(i, idx, str.size()) {
        str[i] = ((str[i]-'0') + diff)%10 + '0';
        dfs(idx+1, cost+(diff==0?0:1), str);
      }
    };

    dfs(0, 0, s);
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3208
N = int(input())
yamas = [int(j) for j in input().split()]
highest = 0
mountains = 0

for i in range(N):
    if yamas[0] >= highest:
        mountains += 1
        highest = yamas[0]
        yamas = yamas[1:]
    else:
        yamas = yamas[1:]

print(mountains)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//split??????????????§????????????????§£????????£??\
		String[] lines = sc.nextLine().split(" ");
		int num1 = Integer.parseInt(lines[0]);
		int num2 = Integer.parseInt(lines[1]);
		int num3 = Integer.parseInt(lines[2]);
		//???????????£??\??????result?????£?¨????
		String result;

		//????????¶??????????????????????????£??\???
		if(num1 < num2 && num2 < num3){
			result = "Yes";
		} else {
			result = "No";
		}

		//???????????¨??????
		System.out.println(result);

	}
}

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

using namespace std;

typedef long long ll;

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

int main() {
  int N;
  ll _gcd;
  
  cin >> N;
  
  ll a, b;
  cin >> a >> b;
  _gcd = gcd(a, b);
  
  for (int i = 0; i < N - 2; i++) {
    ll in;
    
    cin >> in;
    
    _gcd = gcd(_gcd, in);
  }
  
  cout << _gcd << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long LL;
const int N = 5e5;
LL d[N+1];
LL dist[N+1];
LL mex[N+1];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n; cin >> n >> dist[0];
	for(int i = 1; i <= n; i++)
	{
		cin >> d[i];
		if(dist[i-1] >= d[i])
			dist[i] = dist[i-1]-d[i];
		else if(d[i]-dist[i-1] < dist[i-1])
			dist[i] = d[i]-dist[i-1];
		else
			dist[i] = dist[i-1];
	}
	mex[n] = 1;
	for(int i = n-1; i >= 1; i--)
	{
		//Suppose I am currently on mex[i+1]
		//If d[i] would move me, then it would move me
		//into a spot where I lose (since all less than me are losses)
		//so, I would have to be at mex[i+1]+d[i]
		//If I started at d[i]-mex[i+1] then moved to mex[i+1],
		//then I wouldn't move if I just started at mex[i+1]
		if(d[i+1] > mex[i+1] && d[i+1]-mex[i+1] >= mex[i+1]) //I wouldnt move
			mex[i] = mex[i+1];
		else
			mex[i] = mex[i+1]+d[i+1];
	}
	// for(int i = 1; i <= n; i++)
	// 	cout<<mex[i]<<endl;f
	int Q; cin >> Q;
	while(Q--)
	{
		int q; cin >> q;
		cout<<(mex[q] <= dist[q-1] ? "YES" : "NO")<<'\n';
	}

	cout<<flush;
	return 0;
}

Measured memory_bytes: 13696
#include <stdio.h>

int main(){

  int a,b,c;

  while(1){
    scanf("%d%d%d",&a,&b,&c);
    if(a+b+c==-3) break;

    if(a==-1 || b==-1){
      printf("F\n");
    }
    else if(a+b>=80){
      printf("A\n");
    }
    else if(a+b>=65){
      printf("B\n");
    }
    else if(a+b>=50){
      printf("C\n");
    }
    else if(a+b>=30){
      if(c>=50){
	printf("C\n");
      }else{
	printf("D\n");
      }
    }else{
      printf("F\n");
    }
  }


  return 0; 
}



Measured memory_bytes: 2620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>

using namespace std;

using P = pair<int, int>;
using i64 = int64_t;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;


int main(int argc, char **argv) {
    int n;
    cin >> n;

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

    sort(vec.begin(), vec.end(), greater<int>());
    i64 ans{0};
    for (int i = 0; i < n; ++i) {
        for (int j=i+1; j<n; ++j) {
            for (int k=j+1; k<n; ++k) {
                if (vec[i] < vec[j]+vec[k])
                    ++ans;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){

int n,m,q;
int lef[200003];
int rig[200003];
int a[100003];
int b[100003];
int dat[503][503];

cin >> n >> m >>q;

for(int i = 1 ; i < m + 1 ; i++){
	cin >> lef[i] >> rig[i];
	dat[lef[i]][rig[i]]++;
}

for(int i = 1 ; i < q + 1 ; i++){
	cin >> a[i] >> b[i];
}

for(int i = 1 ; i < 502 ; i++){
	for(int j = 1; j < 502 ; j++){
		
		dat[i+1][j]=dat[i+1][j]+dat[i][j];
		
	}
}

for(int i = 1 ; i < 502 ; i++){
	for(int j = 1; j < 502 ; j++){
		
		dat[i][j+1]=dat[i][j+1]+dat[i][j];
		
	}
}

for(int i = 1; i < q+1 ; i++){

	cout << dat[b[i]][b[i]]-dat[a[i]-1][b[i]] << endl;
	
}





}

Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	ll n;
	cin >> n;
	if (n % 2 ==0) {
		cout << n << endl;
	} else {
		cout << n *2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/b;
    printf("%d %d %f",d,r,f);
 
return 0;
}

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

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

    sort(a.begin(), a.end());
    long long tmp = -1;
    for(auto x:a){
        if(tmp == x){
            cout << "NO" << endl;
            return 0;
        }
        else{
            tmp = x;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc075/tasks/abc075_a

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    A, B, C = map(int, input().split())
    ans = 0
    if A == B:
        ans = C
    elif B == C:
        ans = A
    else:
        ans = B
    print(ans)


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


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	string s;
	cin >> s;

	int ans = 0;
	for (int ii = 0; ii < n-1; ++ii){
		if (s[ii] == s[ii+1]){
			ans++;
		}
	}

	cout << min(n-1, ans + 2*k) << "\n";

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int a,b,c; 
int main()
{
	cin>>a>>b>>c;
	cout<<a+b+c+max(a,max(b,c))*9;
}

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

const int DIM = 2e3 + 5;
const int MOD = 1e9 + 7;

int dp[DIM][DIM], fct[DIM * DIM], inv[DIM * DIM];

int lgput( int x, int n ) {
    if( n == 0 )
        return 1;
    
    int y = lgput( x, n / 2 );
    y = ( 1LL * y * y ) % MOD;
    
    if( n % 2 == 1 )
        y = ( y * 1LL * x ) % MOD;
    
    return y;
}

inline int comb( int n, int k ) {
    return ( ( ( 1LL * fct[n] * inv[k] ) % MOD ) * inv[n - k] ) % MOD;
}

int main( void ) {
    
    int n, k;
    cin >> n >> k;
    
    if( k == 1 )
        cout << "1\n";
    else {
        fct[0] = inv[0] = 1;
        for( int i = 1; i <= n * k; i ++ )
            fct[i] = ( 1LL * fct[i - 1] * i ) % MOD;
        
        inv[n * k] = lgput( fct[n * k], MOD - 2 );
        for( int i = n * k - 1; i >= 1; i -- )
            inv[i] = ( 1LL * inv[i + 1] * (i + 1) ) % MOD;
        
        for( int i = 0; i <= n; i ++ ) {
        for( int j = i; j <= n; j ++ ) {
            if( i <= 1 && j <= 1 )
                dp[i][j] = 1;
            else {
                if( i != 0 )
                    dp[i][j] = dp[i - 1][j];
                
                if( i != j )
                    dp[i][j] = ( dp[i][j] + ( 1LL * dp[i][j - 1] * comb( i + j * (k - 1) - 1, k - 2 ) ) % MOD ) % MOD;
            }
        } }

        for( int i = 1; i <= n; i ++ )
            dp[n][n] = ( 1LL * dp[n][n] * i ) % MOD;
        cout << dp[n][n] << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 47360
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    void ng(){
        cout<<0<<endl;
        return;
    }

    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;
    }

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        const ll MOD=1e9+7;
        ll n;
        cin>>n;
        vl A(n);
        map<ll,ll> m;
        rep(i,n){
            cin>>A[i];
            m[A[i]]++;
        }
        if(n%2==1){
            if(m[0]!=1){
                ng();
                return 0;
            }
            rep(i,n/2){
                if(m[(i+1)*2]!=2){
                    ng();
                    return 0;
                }
            }
        }else{
            rep(i,n/2){
                if(m[i*2+1]!=2){
                    ng();
                    return 0;
                }
            }
        }
        cout<<modpow(2,n/2,MOD)<<endl;
    }

Measured memory_bytes: 7932
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

public class FootPrint
{

    public long First { get; set; }
    public FootPrint(long t)
    {
        First = t;
    }
}
public class AtCoder
{

    public static void Main()
    {
        //入力を保持する
        var N = int.Parse(Console.ReadLine());
        var As = Console.ReadLine().Split().Select(e => BigInteger.Parse(e)).ToArray();
        //Array.Sort(As);
        foreach (var a in As)
        {
            if (a == 0)
            {
                Console.WriteLine(0);
                return;
            }
        }
        BigInteger ans = 1;
        for (int i = 0; i < N; i++)
        {
            BigInteger work = ans * As[i];
            if ((work > 1000000000000000000) || (work < 0))
            {
                ans = -1;
                break;
            }
            ans = ans * As[i];
        }
        Console.WriteLine(ans);
    }
}


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

using namespace std;

int main() {
	string s;

	cin >> s;

	int len = s.size();
	int p = 0;

	for (int i = 0; i < len; i++) {
		if (s.at(i) == 'p') {
			p++;
		}
	}

	int myp = len / 2;


	cout << myp - p << endl;

	return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = sc.nextInt();
		int[] arr = new int[N];
		long ans = 0;
		boolean can = true;
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
			if (i == 0) {
				if (arr[i] != 0) can = false;
			} else {
				if (arr[i] > arr[i-1] + 1) can = false;
				if (arr[i] == arr[i-1] + 1) ans++;
				else ans += arr[i];
			}
			
		}
		System.out.println(can ? ans : -1);
	}
}


Measured memory_bytes: 87436
import java.util.Scanner;

public class Main {
    private static double[] p;
    private static double[] q;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        p = new double[n+1];
        q = new double[n+1];
        for (int i = 1; i <= n; i++) {
            p[i] = in.nextDouble();
        }
        for (int i = 0; i <= n; i++) {
            q[i] = in.nextDouble();
        }
        System.out.println(minimumCost());
    }

    private static double minimumCost() {
        int n = p.length - 1;
        double[][] weight = new double[n+2][n+1];
        double[][] cost = new double[n+2][n+1];

        for (int i = 1; i <= n + 1; i++) {
            weight[i][i-1] = q[i-1];
            cost[i][i-1] = q[i-1];
        }

        for (int size = 1; size <= n; size++) {
            for (int i = 1; i <= n - size + 1; i++) {
                int j = i + size - 1;
                cost[i][j] = Double.MAX_VALUE;
                weight[i][j] = weight[i][j-1] + p[j] + q[j];
                for (int r = i; r <= j; r++) {
                    double testCost = cost[i][r-1] + cost[r + 1][j] + weight[i][j];
                    if (testCost < cost[i][j]) {
                        cost[i][j] = testCost;
                    }
                }
            }
        }
        return cost[1][n];
    }
}



Measured memory_bytes: 45224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N,M;cin>>N>>M;
    ll d[N][N];
    REP(i,N){
        REP(j,N)d[i][j]=INF;
        d[i][i]=0;
    }
    int a,b;ll c;
    REP(i,M){
        scanf("%d %d %d",&a ,&b ,&c);
        a--;b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    ll d1[N][N];
    REP(i,N)REP(j,N)d1[i][j]=d[i][j];
    REP(k,N)REP(i,N)REP(j,N)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    int res=0;
    REP(i,N)REP(j,N){
        if(i<j && d1[i][j]!=INF && d[i][j]<d1[i][j])res++;
    }
    cout<<res<<endl;
    return 0;
}

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

int main(){
    int n,m,ans=0;cin>>n>>m;vector<int> M(m);
    for(int i=0;i<n;i++){
        int k;cin>>k;
        for(int j=0;j<k;j++){
            int a;cin>>a;
            M.at(a-1)++;
        }
    }
    for(int i=0;i<m;i++){
        if(M.at(i)==n){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    for(int i=0;i<s.size();i++)
    {
        char ch=s[i];
        for(int j=0;j<n;j++)
        {
            if(ch!='Z')
                ch++;
            else
                ch='A';
        }
        s[i]=ch;
    }
    cout<<s<<endl;
    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> s(N);
  for(int i = 0; i < N; i++){
    cin >> s.at(i);
  }
  int t = 0;
  for(int i = 0; i < N; i++){
    if(s.at(i) >= K){
      t++;
    }
  }
  cout << t << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
vector<vector<int> > d; 
ll power(ll a,int n){
  if(n==0)
    return 1;
  if((n%2)==0)
    return (power((a*a)%mod,n/2))%mod;
  else
    return (a*(power((a*a)%mod,n/2))%mod)%mod;    
}
void bfs(int s,vector<vector<int> >& g,vector<bool>& vis){
     queue<pii> q;
     q.push(mp(s,0));
     while(!q.empty()){
        pii a=q.front();
        q.pop();
        vis[a.ff]=true;
        d[s][a.ff]=a.ss;
        for(int i=0;i<g[a.ff].size();i++){
           if(!vis[g[a.ff][i]]){
              q.push(mp(g[a.ff][i],(a.ss)+1));
              vis[g[a.ff][i]]=true;
           }
        }
     }
}
int main(){
FASTIO
int n,x,y;
cin>>n>>x>>y;
vector<vector<int> > g(n);
for(int i=0;i<n-1;i++){
   g[i].pb(i+1);
   g[i+1].pb(i);
}
g[x-1].pb(y-1);
g[y-1].pb(x-1);
d.resize(n,vector<int>(n));
for(int i=0;i<n;i++){
   vector<bool> vis(n);
   bfs(i,g,vis);
}
vector<int> ans(n);
for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
       if((d[i][j]>0)&&(d[i][j]<n))
         ans[d[i][j]-1]++;
    }
}
for(int i=0;i<n-1;i++){
   cout<<((ans[i])/2)<<"\n";
}
return 0;
}

Measured memory_bytes: 16128
def main():
    N,M=map(int,input().split())
    H=list(map(int,input().split()))
    OK=[True]*N
    for m in range(M):
        a,b=map(int, input().split())
        if H[a-1] <= H[b-1]: OK[a-1] = False
        if H[b-1] <= H[a-1]: OK[b-1] = False
    print(OK.count(True))

if __name__=='__main__':
    main()

Measured memory_bytes: 20072
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int R=sc.nextInt();
		int G=sc.nextInt();
		int B=sc.nextInt();
		int N=sc.nextInt();
		long ans=0;
		for(int i=0; i<=3000; i++) {
			for(int j=0; j<=3000; j++) {
				int rest=N-R*i-G*j;
				if(rest>=0&& rest%B==0) {
					ans++;
				}
			}
		}
		pl(ans);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0) u += m;
    //cout << u << endl;
    return u;
}

ll paty_counter(ll level, ll x){
    ll size = pow(2, level+2) - 3;
    ll pmi = pow(2, level) - 1;
    if(x == 0){
        return 0;
    }else if(level == 0){    
        return 1;
    }else{
        if(x <= (size - 1)/2){
            return paty_counter(level-1, x-1);
        }else{
            return pmi + 1 + paty_counter(level-1, x - pow(2, level+1) + 3 - 2);
        }
    }

}
 
using namespace std;
using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
static ll x;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
        x ++;
    }
}

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

    ll ten = 1;
    ll nine = 1;
    ll eight = 1;
    REP(i, n){
        ten *= 10;
        nine *= 9;
        eight *= 8;
        ten %= MOD;
        nine %= MOD;
        eight %= MOD;
    }
    cout << (ten + eight - 2 * nine % MOD + MOD)%MOD << endl;
}



Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#define N 1001
int lcs();
char c1[N],c2[N];
int c[N][N];
int main()
{
  int i,j;
  int l[N],n;
  
  scanf("%d",&n);
  
  for(i=0; i<n; i++){
      scanf("%s",c1);
      scanf("%s",c2);
      l[i] = lcs();
  }

  for(i=0; i<n; i++){
    printf("%d\n",l[i]);
  }
  
  return 0;
}

int lcs()
{
  int m,n;
  int i,j;  
  m = strlen(c1);
  n = strlen(c2);

  for(i=1; i<=m; i++){
    c[i][0] = 0;
  }
  for(j=0; j<=n; j++){
    c[0][j] = 0;
  }

  for(i=1; i<=m; i++){
    for(j=1; j<=n; j++){
      if(c1[i-1]==c2[j-1]){
	c[i][j] = c[i-1][j-1]+1;
      }
      else if(c[i-1][j]>=c[i][j-1]){
	c[i][j] = c[i-1][j];
      }
      else{
	c[i][j] = c[i][j-1];
      }
    }
  }

  return c[m][n];
}
      

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

int main()
{
	string s;
	cin >> s;
	long long ans = 0;
	for (int i = 0; i < (1 << s.size() - 1); i++)
	{
		long long last = -1;
		long long sum = 0;
		for (int j = 0; j < s.size(); j++)
		{
			if (i & (1 << j))
			{
				long long cnt = 0;
				for (int k = last + 1; k <= j; k++)
				{
					cnt = cnt * 10 + (long long)(s[k] - '0');
				}
				sum += cnt;
				last = j;
			}
		}
		long long cnt = 0;
		for(int j = last + 1; j < s.size(); j++)
		{
			cnt = cnt * 10 + (long long)(s[j] - '0');
		}
		sum += cnt;
		ans += sum;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>

int main(void)
{
    int A,B,K;
    scanf("%d %d",&A, &B);

    K = A+B;

    if(K%2 == 0){
        printf("%d\n",K/2);
    } else {
        printf("IMPOSSIBLE\n");
    }



    return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))

S = []
for i in range(N):
    p, si = i, [0]
    ps = set()
    while P[p] not in ps:
        p = P[p]
        ps.add(p)
        si.append(si[-1] + C[p])
    si = si[1:]
    S.append(si)


ans = -float('inf')
for i in range(N):
    for j in range(len(S[i])):
        if K - j - 1 < 0:
            continue

        if S[i][-1] > 0:
            roop = (K - j - 1) // len(S[i])
            ans = max(ans, S[i][-1] * roop + S[i][j])
        else:
            ans = max(ans, S[i][j])

print(ans)


Measured memory_bytes: 280416