akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))

count = 0
minus = 0
total = 0
for i in range(n):
    if a[i] == 0:
        count = i
if count == 0:
    while count < n:
        if a[count] < 0:
            minus += 1
        count += 1
else:
    minus = 0

if minus%2 == 0:
    for i in range(n):
        a[i] = abs(a[i])
    total = sum(a)
else:
    for i in range(n):
        a[i] = abs(a[i])
    total = sum(a) - min(a)*2

print(total)

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

int main() {
  double l,r;
  cin >> l;
  r=l/3;
  r=r*r*r;
  printf("%.8lf",r);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int magic[15][15];
	int i, j;
	int x, y, n;
	while (1) {
		scanf("%d", &n);
		if (!n)
			break;
		memset(magic, 0, sizeof(magic));
		x = n / 2;
		y = n / 2 + 1;
		for (i = 1; i <= n*n; i++) {
			if (!magic[y][x]) {
				magic[y][x] = i;
			}
			else {
				while (1) {
					if (--x < 0)
						x = n-1;
					y = (y+1)%n;
					if (!magic[y][x]) {
						magic[y][x] = i;
						break;
					}
				}
			}
			x = (x+1)%n;
			y = (y+1)%n;
		}
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				printf("% 4d", magic[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 616
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                String s = sc.next();
                int cou = 0;
                boolean ebishu = true;
                if(s.charAt(0) != 'A') ebishu = false;
                for(int i = 2 ; i < s.length() - 1 ; i++){
                        if(s.charAt(i) == 'C'){
                                cou++;
                        }else if(s.charAt(i) >= 97 && s.charAt(i) <= 123){}else{
                                ebishu = false;
                        }
                }
                if(cou != 1) ebishu = false;
                if(s.charAt(s.length() - 1) >= 97 && s.charAt(s.length() - 1) <= 123){}else{
                        ebishu = false;
                }
                if(s.charAt(1) >= 97 && s.charAt(1) <= 123){}else{
                        ebishu = false;
                }
                if(ebishu){
                        System.out.println("AC");
                }else{
                        System.out.println("WA");
                }
        }
}//0=48
 //a=97 a -> +26 = 123
//鶏になれ

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

long long gcd(long long x, long long y) {
    if (x % y == 0) return y;
    else return gcd(y, x%y);
}

int main() {
    long long a, b, c, d; cin >> a >> b >> c >> d;
    long long x, y; x = abs(c-a); y = abs(d-b);
    if (x == 0 || y == 0) {
        cout << 0 << endl;
        return 0;
    }
    long long t = gcd(x, y);
    x /= t; y /= t;
    cout << (x+y-1) * t << endl;
    return 0;
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
S = P[:X] + Q[:Y] + R
S.sort(reverse=True)
ans = sum(S[:X+Y])

print(ans)


Measured memory_bytes: 22720
n=int(input())
ans=[[0]*n for _ in range(n)]
for _ in range(n):
    v,k,*varray= map(int,input().split())
    for i in varray:
        ans[v-1][i-1]=1

for i in range(n):
    print(" ".join(map(str,ans[i])))


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

int main() {
	int a, b;
	cin >> a >> b;
	bool ans = true;
	if (a % 2 == 0 || b % 2 == 0) ans = false;
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int H,W; cin >>H >>W;
  vector<string> a(H);
  rep(i,0,H) cin >>a[i];
  vector<bool> row(H);
  vector<bool> col(W);
  rep(i,0,H) {
    rep(j,0,W) {
      if (a[i][j] == '#') {row[i] = true; col[j] = true;}
    }
  }
  rep(i,0,H) {
    if (row[i]) {
      rep(j,0,W) {
        if (col[j]) cout <<a[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < k; i++) ans += a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int N = sc.nextInt();
        int M = sc.nextInt();
        int C = sc.nextInt();
        int[] B = new int[M];
        for (int i = 0; i < M; i++) {
            B[i] = sc.nextInt();
        }
        int[][] A = new int[N][M];
        int ans = 0;
        for (int i = 0; i < N; i++) {
            int sum = 0;
            for (int j = 0; j < M; j++) {
                A[i][j] = sc.nextInt();
                sum += A[i][j] * B[j];
            }
            sum += C;
            if (sum > 0) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


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

void print(char str[1000], int a, int b){
    int i;
    
    for(i=a; i<=b; i++){
        printf("%c",str[i]);
    }
    printf("\n");
}

void reverse(char str[1000], int a, int b){
    int i;
    char copy[1000];
    
    strcpy(copy,str);
    for(i=0; i<=b-a; i++){
        str[a+i]=copy[b-i];
    }
}

void replace(char str[1000],int a, int b){
    int i;
    char p[1000];
    
    scanf("%s",p);
    for(i=0; i<=b-a; i++){
        str[a+i]=p[i];
    }
}


int main(void){
    char str[1000];
    char order[10];
    int n,i,a,b;
    
    scanf("%s",str);
    scanf("%d",&n);
    
    for(i=0; i<n; i++){
        scanf("%s %d %d",order,&a,&b);
        
        if(strcmp(order,"print") == 0){
            print(str,a,b);
        }
        
        else if(strcmp(order,"reverse") == 0){
            reverse(str,a,b);
        }
        
        else if(strcmp(order,"replace") == 0){
            replace(str,a,b);
        }
    }
    return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
    int m,n,i,j,x,y;
    char a[55][55],ch;
    scanf("%d%d",&n,&m);
    getchar();
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            a[i][j]='0';
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            scanf("%c",&ch);
            if(ch=='#')
            {
                a[i][j]='#';
                for(x=-1;x<=1;x++)
                    for(y=-1;y<=1;y++)
                    {
                        if(i+x>=0&&i+x<n&&j+y>=0&&j+y<m&&a[i+x][j+y]!='#')
                            a[i+x][j+y]++;
                    }
            }

        }
        getchar();
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
            printf("%c",a[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int		main(void)
{
	int k;
	int n;
	scanf("%d", &k);
	scanf("%d", &n);
	int A[n];
	int max = 0;
	int i = 0;
	while (i < n)
	{
		scanf("%d", &A[i]);
		i++;
	}
	i = 1;
	while (i < n)
	{
		if (A[i] - A[i - 1] > max)
			max = A[i] - A[i - 1];
		i++;
	}
	if (k - A[n - 1] + A[0] > max)
		max = k - A[n - 1] + A[0];
	printf("%d", (k - max));
	return (0);
}


Measured memory_bytes: 896
function main(input) {
  const inputs =input.split('\n')
  const [N] = inputs[0].split(' ').map(Number)
  const S = inputs.splice(1)
  const count = {
    'AC': 0,
    'WA': 0,
    'TLE': 0,
    'RE': 0,
  }
  for(let i = 0; i < N; i++) {
    count[S[i]]++
  }
  console.log(`AC x ${count['AC']}
WA x ${count['WA']}
TLE x ${count['TLE']}
RE x ${count['RE']}`
  )
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 38092
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<utility>
#include<string>
#include<map>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}
int lcm(int a, int b){return a*b / gcd(a, b);}


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

    for(int i = 1; i <= 10; i++){
        if(n <= 1000*i){
            cout << 1000*i-n << endl;
            return 0;
        }
    }

}


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

int ans = 0;
string s;

int main()
{
    cin >> s;
    if (s[0] == '1')
        ans++;
    if (s[1] == '1')
        ans++;
    if (s[2] == '1')
        ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define out(a) printf("%d",a)
using namespace std;
int num=0;
char s1[1][10],s2[1][10],c;
bool flag;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
    return s*t;
}
int main()
{
	scanf("%s%s",s1,s2);  
	flag=false;
    for (int i=0;i<strlen(s1[0]);i++)
       num=num*10+s1[0][i]-'0';
    for (int i=0;i<strlen(s2[0]);i++)
       num=num*10+s2[0][i]-'0';
       //printf("%d\n",num);
    for (int i=1;i<=num;i++) {
      if (i*i==num) {
      	flag=true;
      	break;
      }
      if (i*i>num) break;
    }
    if (flag) puts("Yes");
    else puts("No");
	return 0;
}

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

class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int[] a = new int[n+1];
		input = Console.ReadLine().Split(' ');
		long leaves = 0;
		for(int i = 0;i <= n; i++)
		{
			a[i] = int.Parse(input[i]);
			leaves += (long)a[i];
		}

		long[] point = new long[n+1];
		point[0] = 1;
		long allPoints = point[0];
		for(int i = 0;i < n; i++)
		{
			long notLeaf = point[i] - (long)a[i];
			leaves -= (long)a[i];
			if(2*notLeaf<(long)a[i+1])
			{
				Console.WriteLine(-1);
				return;
			}
			point[i+1] = Math.Min(2*notLeaf, leaves);
			allPoints += point[i+1];
		}
		if(point[n]!=(long)a[n]) allPoints = -1;
		Console.WriteLine(allPoints);

	}

}


Measured memory_bytes: 37288
import numpy as np

S = str(input())
S = list(S)
#print(S)
#S = np.array(S).reshape(-1,1)
#print(S)
count = 0
count_w = 0
for id, i in enumerate(S):
    #print(i)
    if str(str(i))==str('W'):
        count += id - count_w
        count_w += 1
print(count)

Measured memory_bytes: 22772
using System;
public class Program {
  public static void Main() {
    int N = int.Parse(Console.ReadLine());
    int res = 0;
    for (int i = 1; i <= N; i+=2) {
      int count = 0;
      for (int j = 1; j <= i; j++) {
        if (i % j == 0) count++;
      }
      if (count == 8) res++;
    }
    Console.WriteLine(res);
  }
}


Measured memory_bytes: 13140
N, A, B = [int(x) for x in input().split()]
S = input()

rank = 0
foreign_rank = 0
for i in S:
    if i == 'a':
        if rank < A + B:
            rank += 1
            print('Yes')
            continue

    if i == 'b':
        if rank < A + B and foreign_rank < B:
            rank += 1
            foreign_rank += 1
            print('Yes')
            continue

    print('No')


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  int64 a,b;
  cin >> n >> a >> b;
  vector<int32> x(n);
  REP(i,n)cin >> x[i];
  int64 ans = 0;
  FOR(i,1,n){
    ans += min(b, a * (x[i] - x[i-1]));
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD_Q 1e9 + 7
#define MOD_A 998244353

 #define int long long


int MIN = I64_MAX;
void solve()
{

  string S;
  cin>>S;

  for (int i = 0; i < S.size() - 2; i++)
  {
    int A,B,C;
    int num;
    A = (int)(S[i] - '0');
    B = (int)(S[i+1] - '0');
    C = (int)(S[i+2] - '0');

    num = 100*A + 10*B + C;

    MIN = min(MIN,abs(num - 753));
    
  }

  cout<<MIN<<endl;
  
  return;
}
 
int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<numeric>
#include<vector>
#include<tuple>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
typedef long long ll;
const int MOD = 1e9 + 7;
ll a[3];
int main(void)
{
	bool flag=false;
	ll mi = 1000000000000000000;
	FOR(i, 0, 3) {
		cin >> a[i];
		if (!(a[i] % 2))flag = true;
	}
	if (flag) {
		cout << 0 << endl;
	}
	else {
		mi = min(mi, a[0] * a[1]);
		mi = min(mi, a[0] * a[2]);
		mi = min(mi, a[2] * a[1]);
		cout << mi << endl;
	}
	return 0;
}


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

const int N = 1e6 + 10;
const int inf = INT_MAX;

#define ll long long
#define FOR(i,a,b) for(int i = a;i <= b;i++)
#define _FOR(i,a,b) for(int i = a;i >= b;i--)

template<typename T> void read(T &x)
{
    x = 0;int f = 1;
    char c = getchar();
    for(;!isdigit(c);c = getchar()) if(c == '-') f = -1;
    for(;isdigit(c);c = getchar()) x = x * 10 + c - '0';
    x *= f;
}

int n,a[N];
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".
    read(n);
    int ans = 0;
	FOR(i,1,n)
	{
		read(a[i]);
		if(i % 2 == 1 && a[i] % 2 == 1) ans++;
	}
	printf("%d\n",ans);
    return 0;
}




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

class B {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int A, B, M;
        int[] a;
        int[] b;
        Input(out A, out B, out M);
        Inputs(out a);
        Inputs(out b);
        int[] x = new int[M];
        int[] y = new int[M];
        int[] c = new int[M];
        int min = 1000000000;
        for(int i = 0; i < M; i++) {
            Input(out x[i], out y[i], out c[i]);
            int cost = a[x[i] - 1] + b[y[i] - 1] - c[i];
            if(cost < min) {
                min = cost;
            }
        }
        int cost2 = a.Min() + b.Min();
        Print(Math.Min(min, cost2));
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void Inputs<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

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

int e[2][4];
int main()
{
  double E[2];
  while (cin >> E[0] >> E[1]){
    for (int i = 0; i < 2; i++){
      if (E[i] >= 1.1)  e[i][0]++;
      else if (E[i] >= 0.6) e[i][1]++;
      else if (E[i] >= 0.2) e[i][2]++;
      else  e[i][3]++;
    }
  }
  for (int i = 0; i < 4; i++){
    cout << e[0][i] << ' ' << e[1][i] << endl;
  }
  return (0);
}

Measured memory_bytes: 1224
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S;
	int K;
	cin >> S >> K;
	char tmp = S[0];
	int N = S.size();
	bool F = false;
	REP(i, N) {
		if (tmp != S[i])F = true;
	}
	if (!F) {
		cout << N * K / 2 << endl;
		return 0;
	}
	int cnt1=0, cnt2=0,i=1;
	while (i < N) {
		if (S[i] == S[i - 1]) {
			i++;
			cnt1++;
		}
		i++;
	}
	S += S;
	N *= 2;
	i = 1;
	while (i < N) {
		if (S[i] == S[i - 1]) {
			i++;
			cnt2++;
		}
		i++;
	}
	cout << cnt1 + (cnt2 - cnt1)*(K - 1) << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll N , M ;
  cin >> N >> M;

  if (N>M) swap(N,M);

  if((M==1)&&(N==1)){cout << 1 << endl; return 0;}
    
  if(N==1){cout << max((ll)(M-2), (ll)0L) << endl;return 0;}
  if(N==2){cout << 0 << endl; return 0;}
  cout << (N-2)*(M-2) << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int m = sc.NextInt();
        int[] h = sc.IntArray();
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i = 0; i < m; i++)
        {
            a[i] = sc.NextInt() - 1;
            b[i] = sc.NextInt() - 1;
        }

        bool[] f = new bool[n];
        for (int i = 0; i < m; i++)
        {
            if (h[a[i]] <= h[b[i]]) f[a[i]] = true;
            if (h[a[i]] >= h[b[i]]) f[b[i]] = true;
        }

        Console.WriteLine(f.Count(bo => !bo));
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll pow5(ll a){return a*a*a*a*a;}

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

    ll X; cin >> X;

    for (ll i = 0;i < 10005;i++){
        ll A5 = pow5(i);
        if(A5 < X){
            ll diff = X-A5;
            ll low = 0, high = 10005; // [low, high)
            while(high-low != 1){
                ll mid = (low+high)/2;
                if(pow5(mid) <= diff) low = mid;
                else high = mid;
            }
            if(pow5(low) == diff){
                cout << i << " " << -low << endl;
                return 0;
            }
        }else{
            ll diff = A5-X;
            ll low = 0, high = 10005; // [low, high)
            while(high-low != 1){
                ll mid = (low+high)/2;
                if(pow5(mid) <= diff) low = mid;
                else high = mid;
            }
            if(pow5(low) == diff){
                cout << i << " " << low << endl;
                return 0;
            }
        }
    }

    return 0;

}

Measured memory_bytes: 3532
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vvi G(n);
    rep(i, n-1) {
        int a;
        cin >> a;
        --a;
        G[a].push_back(i+1);
    }
    function<int(int)> dfs = [&](int now) {
        vi gh;
        for(int ne:G[now]) {
            gh.push_back(dfs(ne));
        }
        sort(rall(gh));
        rep(i, gh.size()) gh[i] += i+1;
        if(gh.empty()) gh.push_back(0);
        return *max_element(all(gh));
    };
    
    cout << dfs(0) << endl;
}

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

int main(){
  int n;
  vector<p> v;
  cin >> n;
  for(int i = 0; i < n; i++){
    ll a, b;
    cin >> a >> b;
    v.push_back(p(a, b));
  }
  sort(v.begin(), v.end());
  ll min_s = v[n-1].second + v[n-1].first;
  cout << min_s << endl;
  return 0;
}


Measured memory_bytes: 2420
#include <iostream>

using namespace std;

int main() {
	int n;
	int suretu[100];
	int key;
	int i;

	cin >> n;

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

	for (int j = 1; j < n; j++) {
		for (int k = 0; k < n; k++) {
			if (k != 0) {
				cout << " " << flush;
			}
			cout << suretu[k] << flush;
		}
		cout << endl;
		key = suretu[j];
		i = j - 1;
		while (i >= 0 && suretu[i] > key) {
			suretu[i+1] = suretu[i];
			i--;
		}
		suretu[i+1] = key;
	}

	for (int k = 0; k < n; k++) {
		if (k != 0) {
			cout << " " << flush;
		}
		cout << suretu[k] << flush;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1160
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N):
    all_time = 0
    for c, s, f in CSF[i:]:
        if all_time < s:
            all_time = s
        if all_time % f != 0:
            all_time += f - (all_time % f)
        all_time += c
    print(all_time)


Measured memory_bytes: 3316
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[6][6];
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int N,M,K;
    cin>>N>>M>>K;
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        char g;
        cin>>g;
        a[i][j]=g=='#';
      }
    }
    int tot=0;
    for(int i=0;i<(1<<N);i++){
      for(int j=0;j<(1<<M);j++){
        int cur=0;
        for(int ii=0;ii<N;ii++){
          for(int jj=0;jj<M;jj++){
            if(a[ii][jj] && (i&(1<<ii)) && (j&(1<<jj)))cur++;
          }
        }
      if(cur==K)tot++;
      }
    }
    cout<<tot;
}

Measured memory_bytes: 3616
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<Integer> nums = new ArrayList<>();
        for(int i = 0;i < n;i++) {
            nums.add(sc.nextInt());
        }
        int r = 0;
        for(int i = 1;i < n - 1;i++){
            int p1 = nums.get(i - 1);
            int p2 = nums.get(i);
            int p3 = nums.get(i + 1);
            if(p1 > p2 && p2 > p3){
                r++;
            }else if(p3 > p2 && p2 > p1){
                r++;
            }
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

score = 0
before = N

for i in range(N):

    x = A[i] - 1
    score += B[x]

    if before + 1 == x:
        score += C[before]

    before = x

print(score)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main () {

  ll N, K, S;
  cin >> N;
  cin >> K;
  cin >> S;

  ll num_10_9 = 1000000000;

  if (S == num_10_9) {
    // num_10_9 (= S) ga K ko, and else, 1
    REP(i, 0, N) {
      ll ele;
      if (i < K) {
        ele = S;
      }
      else {
        ele = 1;
      }
      cout << ele << " ";
    }
    cout << endl;
  }
  else { // S ga K ko, and else, 1000000000
    REP(i, 0, N) {
      ll ele;
      if (i < K) {
        ele = S;
      }
      else {
        ele = num_10_9;
      }
      cout << ele << " ";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1280
maxn = 100000

n , q = map(int, input().split())

par = [0] * n
rank = [0] * n

#初期化
for i in range(n):
    par[i] = i
    rank[i] = 0

#判定(一番上野根を求める)
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
#結合
def unite(x , y):
    rx = find(x)
    ry = find(y)
    
    if rx == ry:
        return
    
    if rank[rx] < rank[ry]:
        par[rx] = ry
    elif rank[rx] > rank[ry]:
        par[ry] = rx
    else:
        par[ry] = x
        rank[rx] += 1      

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

for i in range(q):
    p,a,b = map(int, input().split())
    if p == 0:
        unite(a,b)
    if p == 1:
        print(1 if same(a,b) else 0)


Measured memory_bytes: 6032
using System;

namespace ABC121_D___XOR_World
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            
            var digit = 1;
            long result = 0;
            while(digit < 1000)
            {
                result += ((countBinary1(AB[1],digit)-countBinary1(AB[0]-1,digit)) % 2) * (long)Math.Pow(2,digit-1);
                digit++;
            }
            Console.WriteLine(result);
        }

        static long countBinary1(long number,int digit)
        {
            long a = (long)(number/Math.Pow(2,digit)) * (long)Math.Pow(2,digit-1);
            long b = Math.Max(number % (long)Math.Pow(2,digit) - (long)Math.Pow(2,digit-1) + 1,0);
            return a+b;
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;


//input
ll n,k;
vector<ll>a;

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<ll>divisor(ll n){
    vector<ll>ret;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
        }
    }
    sort(ret.begin(),ret.end());
    return ret;
}

bool solve(ll x){
    vector<ll>rem;
    rep(i,n){
        rem.push_back(a[i]%x);
    }
    ll s = accumulate(rem.begin(),rem.end(),0);
    if(s%x!=0)return false;
    sort(rem.begin(),rem.end());
    ll res = 0;
    rep(i,n-s/x){
        res += rem[i];
    }
    if(res<=k)return true;
    else return false;
}

int main(){
    cin >> n >> k;
    a.resize(n);
    rep(i,n)cin>>a[i];
    ll S = accumulate(a.begin(),a.end(),0);
    auto div = divisor(S);
    reverse(div.begin(),div.end());
    rep(i,div.size()){
        if(solve(div[i])){
            cout << div[i] << endl;
            return  0;
        }

    }

    return 0;
}


Measured memory_bytes: 3600
k, n = input().split(" ")
k, n = int(k), int(n)
a = input().split(" ")
a = list(map(int, a))

kyori = [0] * n
for i in range(n):
    if (i != n - 1):
        kyori[i] = a[i + 1] - a[i]
    elif (i == n - 1):
        kyori[i] = k - a[n - 1] + a[0]
ans = sum(kyori) - max(kyori)
print(ans)


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

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s=="SUN")    cout<<"7"<<endl;
    else if(s=="MON")cout<<"6"<<endl;
    else if(s=="TUE")cout<<"5"<<endl;
    else if(s=="WED")cout<<"4"<<endl;
    else if(s=="THU")cout<<"3"<<endl;
    else if(s=="FRI")cout<<"2"<<endl;
    else if(s=="SAT")cout<<"1"<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[n+1];
    dp[0]=0;
    dp[1]=0;
    dp[2] = abs(a[1]-a[0]);
    for(int i=3;i<=n;i++){
        dp[i] = min(dp[i-1]+abs(a[i-2]-a[i-1]) , dp[i-2]+abs(a[i-3]-a[i-1]) );
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//Qの条件をみたすかみたさないか。
//2^50
//全探索、10^9*50
//むりなんですが･･･。
//DP?
//DFS使った全探索か。
ll N,M,Q,ans=0,sum=0;
vector<ll> Z(11),A(55),B(55),C(55),D(55);
void dfs(ll d, ll p){
  for(int i=p; i<=M; i++){
    Z[d]=i;
    if(d<N-1) dfs(d+1,i);
    if(d==N-1){//Aがでそろったら判定
      sum=0;
      for(int j=0; j<Q; j++) if(Z[B[j]-1]-Z[A[j]-1]==C[j]) sum+=D[j];
      ans=max(ans,sum);  
    }
  }
}
int main(){
  ll a,b,c,d; cin>>N>>M>>Q;
  for(int i=0; i<Q; i++) cin>>A[i]>>B[i]>>C[i]>>D[i];
  dfs(0,1);//深さと最初の数
  cout<<ans<<endl;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  double total = 0;
  double x[n];
  string u[n];

  for( int i = 0; i < n; i++ ) {
    cin >> x[i] >> u[i];
    if( u[i] == "JPY" )
      total += x[i];
    else
      total += x[i] * 380000;
  }
  cout << total << endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    
    int ans = 0;
    bool flg = false;
    int tmp = 1;
    for(int i=0;i<n;i++){
        if(a[i]==tmp){
            flg = true;
            tmp++;
        } else {
            ans++;
        }
    }
    
    if(flg){
        cout << ans << endl;
    } else {
        cout << "-1" << endl;
    }
    //return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
  int i,j,k,l,a,b,c,d=0,n=0;
  int num[2000000];
  scanf("%d",&n);
  char ord[12];

  for(i=0;i<n;i++){
    scanf("%s %d",ord,&b);
    if(ord[0]=='i'){
      num[i]=b;
    }else if(ord[6]=='F'){
      i-=2;
      n-=2;
    }else if(ord[6]=='L'){
      i--;
      n--;
      d++;
    }else{
      i--;
      n--;
      l=0;
    
    for(j=i;j>=0;j--){
      if(l>0)break;
      if(b==num[j]){
	k=i-j;
	a=0;
	l++;
	while(k!=a++){
	  num[j+a-l]=num[j+a];
	}
	i--;
	n--;
      }
    }
  }
  }
  for(i=0;i<n-d;i++){
    if(i==n-d-1){
      printf("%d\n",num[n-1-i]);
    }else{
      printf("%d ",num[n-1-i]);
    }
  }
  return 0;
}



Measured memory_bytes: 5636
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int n, d;
int q;
const int N = 5e5 + 1;
ll a[N];
ll val[N];
int ok[N];
ll mi[N];

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> d;
  ll now = d;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    val[i] = now;
    now = min(now, abs(now-a[i]));
  }

  mi[n-1] = 1;
  for(int i = n - 2; i >= 0; i--) {
    mi[i] = mi[i+1];
    if(abs(a[i+1] - mi[i]) < mi[i]) mi[i] = mi[i] + a[i+1];
  }

  cin >> q;
  int i;
  while(q--) {
    cin >> i; i--;
    cout << (mi[i] != 0 && mi[i] <= val[i] ? "YES" : "NO") << "\n";
  }

  return 0;
}


Measured memory_bytes: 15616
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-27 15:01:13
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

template <class T>
class CumulativeSum {
 public:
  CumulativeSum(const std::vector<T>& vec) : vec_(vec) { Build(); }

  // return sum of [left, right]
  T Get(int left, int right) {
    return sum_[right + 1] - sum_[left];    
  }

 private:
  std::vector<T> vec_;
  std::vector<T> sum_;

  void Build() {
    sum_.assign(vec_.size() + 1, static_cast<T>(0));
    for (size_t i = 0; i < vec_.size(); ++i) {
      sum_[i + 1] = sum_[i] + vec_[i];
    }
  }
};

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

  int n; cin >> n;
  vector<int64> a(n); cin >> a;
  CumulativeSum<int64> cs(a);

  int64 ans = 1e18;

  for (int i = 0; i < n - 1; ++i) {
    ans = min(ans, abs(cs.Get(0, i) - cs.Get(i + 1, n - 1)));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long int

ll ans=0;
int n,m,lst[26];
int nxt[26][100001];
char s[100002],t[100002];

int main(void)
{
	int p=0,c;
	memset(nxt,-1,sizeof(nxt));
	memset(lst,-1,sizeof(lst));
	scanf("%s %s",s+1,t+1);
	n=strlen(s+1);
	m=strlen(t+1);
	for(int i=1;i<=n;i++){
		c=s[i]-'a';
		for(int j=lst[c];j<i;j++)
			nxt[c][j]=i;
		lst[c]=i;
	}
	for(int i=1;i<=n;i++){
		c=s[i]-'a';
		if(lst[c]!=-1){
			for(int j=lst[c];j<=n;j++)
				nxt[c][j]=i;
			lst[c]=-1;
		}
	}
	
	for(int i=1;i<=m;i++){
		c=t[i]-'a';
		if(nxt[c][p]==-1){
			printf("-1\n");
			return 0;
		}
		if(nxt[c][p]<=p)
			ans+=nxt[c][p]+n-p;
		else ans+=nxt[c][p]-p;
		p=nxt[c][p];
	}
	printf("%lld\n",ans);
	return 0;
}
/*
aa
a
*/

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

lint mod = 1e9 + 7;

lint powmod(lint x, lint n){
  lint ret = 1;
  while(n > 0){
    if(n&1) ret *= x, ret %= mod, n -= 1;
    else x *= x, x %= mod, n >>= 1;
  }
  return ret;
}

vector<lint> fact;
vector<lint> revfact;

void setfact(int n){
  fact.resize(n+1); revfact.resize(n+1);
  fact[0] = 1;
  rep(i, n) fact[i+1] = fact[i] * (i+1) % mod;
  
  revfact[n] = powmod(fact[n], mod-2);
  for(int i=n-1; i>=0; i--) revfact[i] = revfact[i+1] * (i+1) % mod;
}

lint getC(int n, int r){
  return fact[n] * revfact[r] % mod * revfact[n-r] % mod;
}

int main(){
    int n;
    lint a, b, c;
    scanf("%d%lld%lld%lld", &n, &a, &b, &c);
    setfact(200010);
    lint ans = 0;
    lint m = powmod(a+b, mod-2);
    rep(i, n){
        ans = (ans + getC(n+i-1, i) * ((powmod(a, n)*powmod(b, i)%mod + powmod(a, i)*powmod(b, n)%mod) % mod) % mod * powmod(m, n+i) % mod * (n+i) % mod) % mod;
    }
    printf("%lld\n", ans * 100 % mod * powmod(100-c, mod-2) % mod);
}

Measured memory_bytes: 3328
let rec lower_bound l r p =
  if r <= 1 + l
  then r
  else let m = (l + r) / 2 in
       if p m
       then lower_bound l m p
       else lower_bound m r p

let () = Scanf.scanf "%d\n" @@ fun n ->
  let x = lower_bound 0 n @@ fun x -> n <= x * (x + 1) / 2 in
  ignore @@ Array.fold_left (fun n x ->
    if n < x then n
    else (Printf.printf "%d\n" x; n - x)) n @@ Array.init x (fun i -> x - i)


Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

class UnionFind{
public:
  vector<int> par;
  vector<int> rank;
  vector<int> sz;
  int N;

  UnionFind(int n){N = n;}

  //初期化
  void init(){
    for(int i=0;i<N;i++){
      par.push_back(i);
      rank.push_back(0);
      sz.push_back(1);
    }
  }

  //木の根を求める
  int find(int x){
    if(par[x]==x) return x;
    else{
      par[x]=find(par[x]);
      return par[x];
    }
  }

  //xとyの集合の併合
  void unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じ集合にあるか
  bool same(int x, int y){
    return find(x) == find(y);
  }

  //xの木のサイズ
  int size(int x){
    return sz[find(x)];
  }
};

//==================================================
int main(){
  int N,M;
  cin >> N >> M;

  int K[N];
  vector<int> use;
  vector<int> L[N];
  for(int i=0;i<N;i++){
    cin >> K[i];
    for(int j=0;j<K[i];j++){
      int l;
      cin >> l;
      use.push_back(l - 1);
      L[i].push_back(l-1);
    }
  }


  UnionFind uf = UnionFind(M);
  uf.init();
  for(int i=0;i<N;i++){
    for(int j=0;j<L[i].size()-1;j++){
      uf.unite(L[i][j], L[i][j+1]);
    }
  }

  bool isok = true;
  for(int i=1;i<use.size();i++){
    if(!uf.same(use[i], use[i-1])){
      isok = false;
      break;
    }
  }

  if(isok) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 8056
import bisect

n,k = map(int,input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]

a.sort()
f.sort(reverse=True)

af = [[0 for i in range(3)] for j in range(n)]

for i in range(n):
    af[i][0] = a[i]*f[i]
    af[i][1] = a[i]
    af[i][2] = f[i]
    
af.sort(reverse=True)

if k == 0:
    print(af[0][0])
    exit()

low = -1
high = af[0][0]+1
tmp = 0

while low+1 < high:
    tmp = 0
    mid = (low + high) //2
    #print(mid)
    
    for i in range(n):
        tmp += max(0,af[i][1] - mid // af[i][2])
    #print(tmp)
    
    if tmp <= k:
        high = mid
    else:
        low = mid
        
if tmp > k:
    print(mid+1)
else:
    print(mid)


Measured memory_bytes: 123468
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int cnt[101010];
bool isac[101010];

int n, m;
int p;
string s;

int main(){
    cin >> n >> m;
    REP(i, m){
        cin >> p >> s;
        if(s == "WA" && !isac[p])cnt[p]++;
        else isac[p] = true;
    }
    int ac = 0, pe = 0;
    for(int i = 1;i <= n;i++){
        if(isac[i]){
            ac++;
            pe += cnt[i];
        }
    }
    cout << ac << " " << pe << endl;
}

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

using namespace std;









const int INF = 10E8 + 5;

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

	vector<int> h(n);
	vector<int> dp(n, INF);
	for(int &i : h){
		cin >> i;
	}
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j: {i + 1, i + 2}){
			if(j < n){
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
			}
		}
	}
	cout << dp[n - 1];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,m; cin>>n>>m;
	vvi g(n,vi());
	rep(i,0,m){
		int a,b; cin>>a>>b;
		g[a-1].push_back(b);
		g[b-1].push_back(a);
	}
	rep(i,0,n){
		cout<<g[i].size()<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define INF 10000000000

int main(){

    //cout << (int)'0' << (int)'9' << endl;
    int a, b; cin >> a >> b;
    string s; cin >> s;
    bool flag = true;

    for(int i = 0; i < a; i++){
        if(s[i] < '0' || '9' < s[i]) flag = false;
    }

    if(s[a] != '-') flag = false;

    for(int i = a + 1; i < a + b; i++){
        if(s[i] < '0' || '9' < s[i]) flag = false;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256