akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
using namespace std;

int main(){

  char c1,c2;
  int boll[3]={1,0,0};
  int tmp;

  while(scanf("%c,%c",&c1,&c2) != EOF){
    
    tmp = boll[c1-'A'];
    boll[c1-'A'] = boll[c2-'A'];
    boll[c2-'A'] = tmp;

  }
  
  if(boll[0]==1)
    puts("A");
  else if(boll[1]==1)
    puts("B");
  else
    puts("C");

  return 0;
}

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

import sys


def judge(a, b, c, k):
    while a >= b:
        b *= 2
        k -= 1
    while b >= c:
        c *= 2
        k -= 1
    return k >= 0


def main():
    a, b, c = (int(z) for z in input().split())
    k = int(input())
    if judge(a, b, c, k):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
/*
     ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् |
     उर्वारुकमिव बन्धनान्मृत्योर्मुक्षीय माऽमृतात् ||
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

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

const int N = 200005;
int a[N], vst[N], n, m, k;
vi g[N];

void init(int edge)
{
	for (int i = 2; i <= edge; i++)
	{
		int x; cin >> x;
		g[x].pb(i);
	}
}

void solve()
{
	cin >> n;
	init(n);
	for (int i = 1; i <= n; i++)
		cout << sz(g[i]) << endl;

}

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


	cout << setprecision(9) << fixed;
	clock_t z = clock();
	solve();
	cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

	return 0;
}

Measured memory_bytes: 14684
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int S;
    cin >> S;
    if (S < (int)1e9) {
        cout << "0 0 1 0 0 " << S << endl;
        return 0;
    }
    int xa = (int)1e9;
    int yb = (S + xa - 1) / xa;
    int ya = xa * yb - S;
    int xb = 1;
    cout << "0 0 " << xa << " " << ya << " " << xb << " " << yb << endl;

    return 0;
}

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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;
using Si = set<int>;
using vSi = vector<Si>;
using vvSi = vector<vSi>;

#define fi first
#define se second
#define INF 1e9 + 5
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	int n;
	while(cin >> n) {
		vi a(n), c(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		ll ans = 0;
		for (int i = 0; i < n; ++i) {
			int x;
			cin >> x;
			ans += x;
		}
		for (int i = 0; i < n-1; ++i) {
			cin >> c[i];
		}
		for (int i = 0; i < n-1; ++i) {
			if(a[i] + 1 == a[i+1]) ans += c[a[i]-1];
		}
		cout << ans << '\n';
	}
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, s: str):
    r = s.count("R")
    b = N-r
    if r > b:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(N, s)


if __name__ == '__main__':
    main()


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

int main()
{
    int n;
    cin >> n;
    set<int> s;
    rep(i, n) {
        int d;
        cin >> d;
        s.insert(d);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int h,w,n;
int ans[11];
int a,b;
int dx[]={-1,0,1};
map<pair<int,int>,int>mp;
signed main(){
	cin>>h>>w>>n;
	rep(i,n){
		cin>>a>>b;
		rep(j,3){
			rep(k,3){
				if(a+dx[j]>1&&a+dx[j]<h&&b+dx[k]>1&&b+dx[k]<w){
					mp[{a+dx[j],b+dx[k]}]++;
				}
			}
		}
	}
	for(auto p:mp){
		ans[p.second]++;
	}
	int sum=0;

	for(int i=1;i<=9;i++)sum+=ans[i];
	cout<<(h-2)*(w-2)-sum<<endl;
	for(int i=1;i<=9;i++)cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);

const int MAX=1e5+5;
int h[MAX][3];
ll dp[MAX][4];
int n;

int main(){
    cin >> n;
    ll aux,rta=0;
    for(int i=0;i<n;i++){
        cin >> h[i][0] >> h[i][1] >> h[i][2];
    }
    for(int i=0;i<3;i++){
        dp[0][i]=h[0][i];
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k) continue;
                aux=dp[i-1][k]+h[i][j];
                dp[i][j]=max(aux,dp[i][j]);
            }
        }
    }
    for(int i=0;i<3;i++){
        rta=max(rta,dp[n-1][i]);
    }
    cout << rta << endl;
    return 0;
}


Measured memory_bytes: 7832
import java.io.IOException;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();

		int cnt = 0;
		for (int i = 0; i < 3; i++) {
			if (s[i] == t[i]) {
				cnt++;
			}
		}

		System.out.println(cnt);
	}	
}

Measured memory_bytes: 22100
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
if len(set(v))==1:print(n//2)
else:
    v.extend([0,0])
    voc=Counter(v[::2]).most_common(2)
    vec=Counter(v[1::2]).most_common(2)
    if len(voc)==len(vec)==1:print(0)
    elif voc[0][0]==vec[0][0]:print(n-max(voc[0][1]+vec[1][1],voc[1][1]+vec[0][1]))
    else:print(n-voc[0][1]-vec[0][1])

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

ll a, b, c;

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

	cin >> a >> b >> c;
	if ((a % 2 == 0 || b % 2 == 0) || c % 2 == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	cout << min(a * b, min(b * c, c * a)) << endl;
}



Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

#[macro_use]
extern crate lazy_static;
extern crate num_bigint; // 0.2.2
extern crate num_traits; // 0.2.8
use num_bigint::BigInt;
use num_traits::Pow;

// use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
// use std::convert::TryInto;
use libm::*;
use std::cmp::*;
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::*;
use std::ops::Range;
use std::str::FromStr;
use superslice::*;

use lazy_static::lazy_static;
use std::sync::Mutex;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

lazy_static! {
    static ref PARENTS: Mutex<Vec<usize>> = Mutex::default();
    static ref CHILDS: Mutex<Vec<Vec<usize>>> = Mutex::default();
}

//abc177-A
// #[fastout]
fn main() {
    input![d: i64, t: i64, s: i64];

    if d / s < t || (d / s == t && d % s == 0) {
        println!("Yes")
    } else {
        println!("No")
    }

    // println!("{}", ans);
}

// fn go2(start: usize, plus_val: usize, anss: &mut Vec<usize>, dcc: &Vec<usize>) {
//     let childrens = CHILDS.lock().unwrap()[start].clone();

//     // let mut ans = plus_val;
//     for c in childrens.iter() {
//         go2(*c, plus_val + dcc[start], anss, dcc);
//     }

//     anss[start] = plus_val + dcc[start];
// }

// let mut values = VALUES.lock().unwrap();
// values.extend_from_slice(&[1, 2, 3, 4]);
// assert_eq!(&*values, &[1, 2, 3, 4]);

// -100000000
//  1000000000


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

using namespace std;
int main()
{
    int n,k,d;
    int i = 0;

    cin >> n;
    cin >> k;
    std::vector<int> aa(n,0);
    while(k>i){
        int j = 0;
        int buf;
        cin >> d;
        while(d>j){
            cin >> buf;
            aa[buf-1]++;
            j++;
        }
        i++;
    }
    i = 0;
    int count = 0;
    while(aa.size()>i){
        if(aa[i] == 0){
            count++;
        }
        //cout << aa[i] << endl;
        i++;
    }
    cout << count;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>
#define PI (3.141592653589)
int main(void){
	int a,b,C;
	double S,L,h;
	
	
	scanf("%d %d %d",&a,&b,&C);
	S = a*b*sin(C*PI/180)/2;
	L = a+b+sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(C*PI/180));
	h = 2*S/a;
	
	printf("%6.8lf\n",S);
	printf("%6.8lf\n",L);
	printf("%6.8lf\n",h);
	
	return 0;
}

Measured memory_bytes: 668
import math
N=int(input())
M=int(math.sqrt(N*2-0.25)+0.5)
left = M*(M-1) // 2
sum_=0
for i in range(1,M-(N-left)):
    print(i)
    sum_ += i
for i in range(M-(N-left),M):
    print(i+1)
    sum_ += i+1

Measured memory_bytes: 3408
import java.util.*;

/*
2×N のマス目があります。
上から i 行目、左から j 列目 (1≤i≤2,1≤j≤N) のマスをマス (i,j) と表すことにします。

あなたははじめ、左上のマス (1,1) にいます。 
あなたは、右方向または下方向への移動を繰り返し、右下のマス (2,N) に移動しようとしています。
マス(i,j) には Ai,j 個のアメが置かれています。 
あなたは移動中に通ったマスに置いてあるアメをすべて回収します。
左上および右下のマスにもアメが置かれており、あなたはこれらのマスに置かれているアメも回収します。

移動方法をうまく選んだとき、最大で何個のアメを回収できるでしょうか。
*/
public class Main {
    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int b[] = new int[n];
        int c[] = new int[n];

        for (int i = 0; i < n; i++) {
            b[i] = s.nextInt();
        }
        for (int i = 0; i < n; i++) {
            c[i] = s.nextInt();
        }

        int max = 0;
        int temp = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < i; j++) {
                temp += b[j];
            }
            for (int j = i-1; j < n; j++) {
                temp += c[j];
            }
            if (temp >= max) {
                max = temp;
            }
            temp = 0;
        }

        System.out.println(max);
    }
}

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

#define int long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);

const int N = 2e5;
int dp[N][2];
int arr[N];

const int inf = 1e16;
signed main () {
	IOS;
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	 
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif	

	for (int i = 0; i < N; i++) for (int j = 0; j < 2; j++) dp[i][j] = -inf;
	int n; cin >> n;
	for (int i = 1; i <= n; i += 1) {
		cin >> arr[i];
	} 
	dp[2][0] = arr[1] + arr[2], dp[2][1] = -(arr[1] + arr[2]);
	for (int i = 3; i <= n; i += 1) {
		for (int this_flip = 0; this_flip < 2; this_flip++) {
			for (int prev_flip = 0; prev_flip < 2; prev_flip++) {
				if (this_flip) {
					if (prev_flip) {
						dp[i][this_flip] = max(dp[i][this_flip], -arr[i] + (dp[i - 1][prev_flip] + 2 * arr[i - 1]));
					}
					if (!prev_flip) {
						dp[i][this_flip] = max(dp[i][this_flip], -arr[i] + (dp[i - 1][prev_flip] - 2 * arr[i - 1]));
					}
				}
				else {
					dp[i][this_flip] = max(dp[i][this_flip], arr[i] + dp[i - 1][prev_flip]);
				}
			}
		}
	} 
	cout << max(dp[n][0], dp[n][1]);
}	

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

int main()
{
    int i = 0;
    string S, T, result;
    cin >> S;
    cin >> T;

    sort(S.begin(), S.end());
    sort(T.begin(), T.end(), greater<char>());

    result = (S < T) ? "Yes" : "No";

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define INF 1e9 + 7

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

    int a,b;
    cin >> a >> b;
    
    cout << max(a+b, max(a-b, a*b)) << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

static const string stations = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

int main(){

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

    int back_dist[101];
    for(int i=0;i<n;i++){
      scanf("%d",back_dist+i);
    }
    string str;
    cin >> str;

    int back_idx = 0;
    for(int i=0;i<str.size();i++){
      int pos = lower_bound(stations.begin(),stations.end(),str[i]) - stations.begin();
      str[i] = stations[(pos - back_dist[back_idx] + stations.size()) % stations.size()];
      back_idx++;
      back_idx %= n;
    }

    cout << str << endl;
  }
}

Measured memory_bytes: 1240
#include<cstdio>
#include<algorithm>
using namespace std;

const int N=100;
int n,m,X,Y,na=-200,nb=200;
int a[N+5],b[N+5];

int main()
{
	scanf("%d %d %d %d",&n,&m,&X,&Y);
	int k;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&k);
		na=max(na,k);
	}
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&k);
		nb=min(nb,k);
	}
	if(nb>na && na<Y && nb>X)
		puts("No War");
	else
		puts("War");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define MAX 2000000

int size, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest, t;
  l = 2*i;
  r = 2*i+1;
  if ( l <= size && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= size && A[r] > A[largest] ) largest = r;
  if ( largest != i ){
    t = A[i]; A[i] = A[largest]; A[largest] = t;
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if ( size < 1 ) return;
  maxv = A[1];
  A[1] = A[size--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  int tmp;
  if ( key < A[i] ) return;
  A[i] = key;
  while ( i > 1 && A[i/2] < A[i] ){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
  }
}

void insert(int key){
  size++;
  A[size] = -1000000001;
  increaseKey(size, key);
}

main(){
  int key;
  char com[20];
  while(1){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &key);
      insert(key);
    } else if ( strcmp(com, "extract") == 0  ){
      printf("%d\n", extract());
    } else break;
  }
  
  return 0;
}


Measured memory_bytes: 5612
open Hashtbl
let n = Scanf.scanf " %d" (+) 0
let ds = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let m = Scanf.scanf " %d" (+) 0
let ts = Array.init m @@ fun _ -> Scanf.scanf " %d" (+) 0
let h = create n
let _ = Array.(iter (fun d -> replace h d @@ try find h d + 1 with _ -> 1) ds;
  iter (fun t -> let c = try find h t - 1 with _ -> -1 in if c < 0 then (print_endline "NO"; exit 0); replace h t c) ts); print_endline "YES"

Measured memory_bytes: 22784
s=input()
a=[0]*2019
a[0]+=1
pot=1
v=0
ans=0
for i in range(len(s)-1,-1,-1):
	digit=int(s[i])
	v=(v+digit*pot)%2019
	pot=(pot*10)%2019
	ans+=a[v]
	a[v]+=1

print(ans)



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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    string s;
    cin >> s;

    int n=s.size();

    if(s[0]!='1' or s[n-1]!='0'){
        cout << -1 << endl;
        return;
    }

    rep(i,0,n){
        if(i>=n-i-2) break;
        if(s[i]!=s[n-i-2]) {
            cout << -1 << endl;
            return;
        }
    }

    vector<pair<int,int>> ans;
    int head=1,size=1;
    rep(i,1,n){
        if(s[i]=='1') {
            if(i-1>=0 and s[i-1]=='1'){
                ans.push_back({head,size+1});
                head=size+1;
                ++size;
            }else{
                ans.push_back({head,size+1});
                head=size+1;
                ++size;
                while(size<i+1){
                    ans.push_back({head,size+1});
                    ++size;
                }
            }
        }
    }

    ans.push_back({head,size+1});
    ++size;
    print(size);

    rep(i,0,ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 2372
/*Author : Krishna*/
#include<iostream>
#include<unordered_map>
#include<map>
#include<string>
#include<sstream>
#include<vector>
#include <cmath>
#include <stack>
#include<queue>
#include <unordered_set>
#include <algorithm>
#define ll long long
using namespace std;

vector<int>adj[100005];
vector<bool>vis(100005,false);
void dfs(int i)
{
    if(!vis[i])
    {
        vis[i]=true;
        for(auto v : adj[i])
            dfs(v);
    }
}


void solve()
{

    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
         int x ,y;
         cin>>x>>y;
         
         adj[x].push_back(y);
         adj[y].push_back(x);
    }
    int comp=0;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            comp++;
            dfs(i);
        }
    }
    cout<<comp-1;


}


int main()
{
    int t;
//    cin>>t;
    t =1;
    while(t--)
    {
        solve();
    }
}

/*
 *Check for the edge cases(n=1)?
 *Is there any another approach?
 *check for data types
 *Keep on thinking
 */



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

int main(){
    ll n;
    cin >> n;
    vector<ll> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end());
    for(ll i=0;i<n-1;i++){
        if(vec[i]==vec[i+1]){
            puts("NO");
            return 0;
        }
    }
    puts("YES");

    return 0;
}









Measured memory_bytes: 1792
#include <stdio.h>
#include <malloc.h>
#include <string.h>

void reverse(char *in, char *out)
{
    int i, j = 0;
    int len = strlen(in);
    for (i = len - 1; i >= 0; i--)
    {
        out[j] = in[i];
        j++;
    }
    out[j] = 0;
}

void searchMin(char *in, char *out, int N)
{
    int i;
    char *sub = (char *)calloc(N + 1, sizeof(char));
    char *tmp = (char *)calloc(N + 1, sizeof(char));

    memcpy(sub, in + N, N);

    for (i = N - 1; i >= 0; i--)
    {
        if (sub[i] < *(in + i))
        {
            continue;
        }

        memcpy(tmp, in + i, N);
        if (strcmp(tmp, sub) < 0)
        {
            memcpy(sub, tmp, N);
        }
    }

    memcpy(out, sub, N);

    free(sub);
    free(tmp);
}

int main(void)
{
    int N;
    char *S, *U, *S_temp;
    int K;
    int count = 1;

    scanf("%d %d", &N, &K);
    S = (char *)calloc(N + 1, sizeof(char));
    S_temp = (char *)calloc(N + 1, sizeof(char));
    U = (char *)calloc(N * 2 + 1, sizeof(char));
    scanf("%s", S);

    reverse(S, S_temp);

    while (count < K)
    {
        // Uを作成
        memcpy(U, S, N);
        memcpy(U + N, S_temp, N);

        // 最小文字列を検索
        searchMin(U, S_temp, N);
        reverse(S_temp, S);

        if (strcmp(S, S_temp) == 0)
        {
            break;
        }

        count++;
    }

    // Uを作成
    memcpy(U, S, N);
    memcpy(U + N, S_temp, N);

    // 最小文字列を検索
    searchMin(U, S, N);

    printf("%s\n", S);

    free(S);
    free(S_temp);
    free(U);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

using namespace std;

int main (){
  int n;
  cin >> n;
  cout << (n-1)/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;
int x;
void input();

void solve(){
    if(x>=400 && x<=599)cout<<"8\n";
    if(x>=600 && x<=799)cout<<"7\n";
    if(x>=800 && x<=999)cout<<"6\n";
    if(x>=1000 && x<=1199)cout<<"5\n";
    if(x>=1200 && x<=1399)cout<<"4\n";
    if(x>=1400 && x<=1599)cout<<"3\n";
    if(x>=1600 && x<=1799)cout<<"2\n";
    if(x>=1800 && x<=1999)cout<<"1\n";
}

void Clear(){

}

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

    input();
    solve();
    Clear();
}

void input(){
    cin>>x;
}


Measured memory_bytes: 3608
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); 
		long p = 1;
		for(long i = 1; i <= N; i++) {
			p = (p*i)%((int)Math.pow(10, 9)+7);
		}
		System.out.println(p);
	}
}

Measured memory_bytes: 23252
s = input()
r = []
for _ in range(s.count('LR')):
    idx = s.index('LR')+1
    tmp = s[:idx]
    s = s[idx:]
    r.append([tmp, tmp.index('RL'), tmp.count('R'), tmp.count('L')])
r.append([s, s.index('RL'), s.count('R'), s.count('L')])

T = []
for  i, j, R, L in r:
    tmp = [0]*len(i)
    if len(i) % 2 == 0:
        tmp[j], tmp[j+1] = len(i) // 2, len(i) // 2
    else:
        if R > L:
            if (R-1) % 2 ==0:
                tmp[j] = -(-len(i) // 2)
                tmp[j+1] = len(i) // 2
            else:
                tmp[j] = len(i) // 2
                tmp[j+1] = -(-len(i) // 2)
        else:
            if (L-1) % 2 ==0:
                tmp[j] = len(i) // 2
                tmp[j+1] = -(-len(i) // 2)
            else:
                tmp[j] = -(-len(i) // 2)
                tmp[j+1] = len(i) // 2
    T += tmp
print(*T)

Measured memory_bytes: 14868
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); i++)
using namespace std;
using ll = long long;

int N;

int flog(int i, vector<int> &dp, vector<int> &h){
    if(i==0){
        return 0;
    }
    
    if(dp[i] !=-1){
        return dp[i];
    }

    if(i==1){
        dp[i] = flog(i-1 , dp ,h) + abs(h[i]-h[i-1]);
    }else{
        dp[i] = min(abs(h[i]-h[i-2])+flog(i-2, dp ,h), abs(h[i]-h[i-1]) + flog(i-1, dp ,h));    
    }
    //cout << "dp[" << i <<"]" << dp[i] << endl;

    return dp[i];
}


int main(){
    cin >> N;
    vector<int> dp(N,-1);
    vector<int> h(N);
    
    rep(i,N){
        int x; cin >> x;
        h[i] = x;
    }

    int ans = flog(N-1, dp ,h);
    cout << ans << endl;
}


Measured memory_bytes: 11932
//	-*- mode: C++ -*-
//	How many ways?
//
//		Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
//
//		You should select three integers from 1 to n without duplication.
//		A total sum of the three integers is x.
//		For example, there are two combinations for n = 5 and x = 9.
//
//		1 + 3 + 5 = 9
//		2 + 3 + 4 = 9
//	Input
//		The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.
//
//		The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.
//
//	Constraints
//		3 ≤ n ≤ 100
//		0 ≤ x ≤ 300
//	Output
//		For each dataset, print the number of combinations in a line.
//
//	Sample Input
//		5 9
//		0 0
//	Sample Output
//		2

#include <iostream>
#include <vector>
#include <utility>

int	main(int	argc,
		 char*	argv[])
{
	unsigned int	n	{0};
	unsigned int	x	{0};

	std::vector<std::pair<unsigned int, unsigned int>> p;

	while(true){
		std::cin >> n >> x;

		if((n == 0) && (x == 0)){
			break;
		}

		p.push_back(std::make_pair(n, x));
	}

	for(auto s : p){
		unsigned int	count	{0};

		for(unsigned int i = s.first; i > 2; i--){
			for(unsigned int j = i - 1; j > 1; j--){
				for(unsigned int k = j - 1; k > 0; k--){
					if((i + j + k) == s.second){
						count++;
					}
				}
			}
		}
			std::cout << count << '\n';
	}

    return 0;
}



Measured memory_bytes: 3068
N, M = map(int, input().split())
C = []
for _ in range(N):
    a, b = map(int, input().split())
    C.append((a, b))
C.sort()
ans = 0
for a, b in C:
    ans += a * min(b, M)
    M -= min(b, M)
    if M == 0:
        break
print(ans)


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

int main(){
  std::map<string,int> b;
    
  int n,m,i,max = 0;
  string s,in[110];
  
  cin >> n;
  for(i = 0 ; i < n ; i++){
    cin >> s;
    in[i] = s;
    b[s]++;
  }
  

  cin >> m;
  for(i = 0 ; i < m ; i++){
    cin >> s;
    b[s]--;
  }
  
  for(string x : in)	if( max < b[x] ) max = b[x];
  
  cout << max << endl;  
}

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

int main(void){
	string s;
	
	cin >> s;
	
	long long ans = 0;
	for(int i=0; i<s.size(); i++){
		if(s[i] == 'g') ans++;
		else ans--;
	}

	cout << ans / 2 << endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int N;
    cin >> N;
    int ans = 0;
    vector<int> num(N);
    rep(i, N) {
        int p;
        cin >> p;
        num[i] = p;
    }
    rep(i, N) {
        if (num[i] == i+1) {
            ans++;
            if (i != N-1) {
                swap(num[i], num[i+1]);
            }
        }
    }
    cout << ans << endl;
 }

Measured memory_bytes: 640
#include <iostream>
#include <stack>

int main()
{
    std::stack<int> cars;

    int in_car;
    while (std::cin >> in_car) {
        if (in_car == 0) {
            std::cout << cars.top() << std::endl;
            cars.pop();
        } else {
            cars.push(in_car);
        }
    }

    return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

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

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

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

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

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


void Main()
{
    int n;cin>>n;
    LL r1=1,r2=1;

    REP(i,n){
        LL t,a;cin>>t>>a;

        LL t1 = (r1+t-1)/t;
        LL t2 = (r2+a-1)/a;

        r1 = t*max(t1,t2);
        r2 = a*max(t1,t2);
    }
    cout<<r1+r2<<endl;
	return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

int main(){
    int N, M, A, B;
    cin >> N >> M;
    vector<int> edge[N+1];
    rep(i, M){
        cin >> A >> B;
        edge[A].push_back(B);
        edge[B].push_back(A);
    }
    bool used[N+1];
    fill_n(used, N+1, false);
    int L = 1, R = edge[L][0];
    used[L] = true, used[R] = true;
    vector<int> vecl, vecr;
    vecl.push_back(L);
    vecr.push_back(R);
    int i = 0;
    while(true){
        int l = vecl[i];
        int p = 0;
        rep(k, edge[l].size()){
            if(!used[edge[l][k]]){
                p = edge[l][k];
                break;
            }
        }
        if(p){
            vecl.push_back(p);
            used[p] = true;
            i++;
        }
        else break;
    }
    int j = 0;
    while(true){
        int r = vecr[j];
        int p = 0;
        rep(k, edge[r].size()){
            if(!used[edge[r][k]]){
                p = edge[r][k];
                break;
            }
        }
        if(p){
            vecr.push_back(p);
            used[p] = true;
            j++;
        }
        else break;
    }
    cout << vecl.size() + vecr.size() << endl;
    for(int i = vecl.size()-1; i >= 0; i--){
        cout << vecl[i] << ' ';
    }
    rep(i, vecr.size()){
        cout << vecr[i] << ' ';
    }
}

Measured memory_bytes: 6904
N, W = map(int, input().split())
v = [0] * N
w = [0] * N
for i in range(N):
    v[i], w[i] = list(map(int, input().split()))

INF = float('inf')
dp = [[INF] * (sum(v)+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(sum(v)+1):
        if j - v[i] >= 0:
            dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i])
        else:
            dp[i+1][j] = dp[i][j]

#for i in dp:
    #print(i)
ans = 0
cnt = -1
for i in dp[-1]:
    cnt += 1
    if i <= W:
        ans = cnt
print(ans)



Measured memory_bytes: 13880
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    // dp[i]:i番目の足場に着くまでの最小のコスト
    vector<lint> dp(n, 0);
    dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]),
                    dp[i - 1] + abs(h[i - 1] - h[i]));
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 2e5 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	FIO
	string s, t; cin >> s >> t;
	ll n = s.length(); ll m = t.length();
	ll dp[n + 1][m + 1] = {};
	for (ll i = 1; i <= n; i++) {
		for (ll j = 1; j <= m; j++) {
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = 1 + dp[i - 1][j - 1];
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	string ans;
	ll i = n, j = m;
	while (i >= 1 && j >= 1) {
		if (s[i - 1] == t[j - 1]) {
			ans = s[i - 1] + ans; i--, j--;
		}
		else {
			if (dp[i - 1][j] >= dp[i][j - 1]) {
				--i;
			}
			else {
				--j;
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 73972
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main() {

  ll n;
  cin >> n;
  ll ans = n;
  for(ll i = 1; i <= sqrt(n); i++){
    if(n % i == 0){
          ans = min(ans, i + (n / i) - 2);
    }
  }
  cout << ans << endl;

}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, m, a[1000], b[1000], MOD = 1e9 + 7;

int main() {
	cin >> n >> m;
	inc(i, n) { cin >> a[i]; }
	inc(i, m) { cin >> b[i]; }
	
	set<LL> sh, sw;
	inc(i, n) { sh.insert(a[i]); }
	inc(i, m) { sw.insert(b[i]); }
	
	LL ans = 1, ch = 0, cw = 0;
	dec1(i, n * m) {
		int csh = sh.count(i);
		int csw = sw.count(i);
		
		if(csh == 1 && csw == 0) { (ans *= cw) %= MOD; }
		if(csh == 0 && csw == 1) { (ans *= ch) %= MOD; }
		if(csh == 0 && csw == 0) { (ans *= ch * cw - (n * m - i)) %= MOD; }
		
		ch += csh;
		cw += csw;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
  char c1,c2,c3,c4;
  cin >> c1>>c2>>c3>>c4;
  if(c1==c2||c2==c3||c3==c4){
    cout <<"Bad";
  }
  else{
    cout <<"Good";
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int dp[n],h[n];
	for(int i=0;i<n;i++){
		dp[i]=0;
		cin>>h[i];
	}
	for(int i=1;i<n;i++){
		int mini=INT_MAX;
		for(int j=i-1;j>=i-k && j>=0;j--){ 
			mini=min(mini,dp[j]+abs(h[i]-h[j]));
		}
		dp[i]=mini;
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> H(N);
    vector<int> A(M);
    vector<int> B(M);
    vector<bool> ans(N,true);
    for(int i = 0; i < N; i++){
        cin >> H.at(i);
    }
    for (int i = 0; i < M; i++){
        cin >> A.at(i) >> B.at(i);
        if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) ans.at(B.at(i) - 1) = false;
        else if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1)) ans.at(A.at(i) - 1) = false;
        else {
            ans.at(A.at(i) - 1) = false;
            ans.at(B.at(i) - 1) = false;
        }
    }
    int ANS = 0;
    for (int i = 0; i < N; i++){
        if (ans.at(i)) ANS++;
    }
    cout << ANS << endl;
}

Measured memory_bytes: 4512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long int;

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

  vector<ll> A(N, 0);
  vector<ll> B(N, 0);
  rep(i, N) cin >> A[i];
  B = A;

  ll ans = 0;
  for (int i = 0; i < A.size() - 1; i++) {
    if (B[i] > B[i + 1]) {
      ans += B[i] - B[i + 1];
      B[i + 1] += B[i] - B[i + 1];
    }
  }
  cout << ans;
}

Measured memory_bytes: 6344
import numpy as np
def F(x,y):
    count = 1
    if x<=y:
        while y >= 10:
            y = y/10
            count += 1
        return count
    else :
        while x >= 10:
            x = x/10
            count += 1
        return count
#print F(1,13)
N = input()
min = 10**10
index = np.zeros(2)
for i in range(np.sqrt(N).astype(np.int32)):
    if N%(i+1) == 0:
       if min > F(i+1,N/(i+1)):
           min = F(i+1,N/(i+1))
           index[0] = i+1
           index[1] = N/(i+1)
       #print i+1, N/(i+1),F(i+1,N/(i+1)), min

print min

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

int main(){
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    bool check = false;
    for (ll i = 0; i <= N-1; i++) {
        ll l = A - i * D + (N-1-i) * C;
        ll r = A - i * C + (N-1-i) * D;
        if (l <= B && B <= r) {
            check = true;
            break;
        }
    }
    if (check) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        int[] b = new int[n + 1];
        for(int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }

        countingSort(a, b, n, 10000);

        StringBuilder sb = new StringBuilder();
        for(int i = 1; i <= n; i++) {
            if(i != 1) sb.append(" ");
            sb.append(b[i]);
        }
        System.out.println(sb);
 
        sc.close();
    }

    private static void countingSort(int[] a, int[] b, int n, int k) {
        int[] c = new int[k + 1];
        for(int i = 0; i <= k; i++) {
            c[i] = 0;
        }

        for(int j = 1; j <= n; j++) {
            c[a[j]]++;
        }

        for(int i = 1; i <= k; i++) {
            c[i] = c[i] + c[i - 1];
        }

        for(int j = n; j > 0; j--) {
            b[c[a[j]]] = a[j];
            c[a[j]]--;
        }
    }
}


Measured memory_bytes: 516400
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

int A, B;

int main(){
  cin >> A >> B;
  cout << A * B << endl;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		int count = 0;

		for (int i = 1; i < S.length(); i++) {
			if (S.charAt(0) == 'W') {
				if (S.charAt(i) == 'W' && S.charAt(i - 1) == 'B') count++;
			}
			else {
				if (S.charAt(i) == 'B' && S.charAt(i - 1) == 'W') count++;
			}
		}

		System.out.println(S.charAt(0) == S.charAt(S.length() - 1) ? count * 2 : count * 2 + 1);
 	}
}

Measured memory_bytes: 25532
### B

N, M = list(map(int , input().split()))

A = []

for n in range(N):
	A.append(list(map(int , input().split())))
	A[n].pop(0)


c = 0
Count = 0
for m in range(M):
	for n in range(N):
		if m+1 in A[n]:
			c += 1
#			print(str(n) + " likes " + str(m+1))
	if c == N:
		Count += 1
#	print("Count = " + str(Count))
	c = 0

print(Count)


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

int main()
{
    int n;
    cin>>n;
    int x,i,c=0;
    vector<int>v;
    for(i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    c=n/2;
    cout<<v[c]-v[c-1]<<endl;
    return 0;
}



Measured memory_bytes: 892
def check(a):
    for i in a:
        if i%2:
            return True
    return False

n,p = map(int, input().split())
a = list(map(int,input().split()))
if check(a):
    print(2**(n-1))
elif p==0:
    print(2**n)
else:
    print(0)

Measured memory_bytes: 3064
#include <stdio.h>

int Ans[110];
int main()
{
    int a,n,k,i,j,d;

    scanf("%d %d",&n ,&k);
    int ans = 0;

    for(i=0;i<k;i++)
    {
        scanf("%d",&d);

        for(j=0;j<d;j++)
        {
            scanf("%d",&a);
            Ans[a]++;
        }
    }

    for(i=1;i<=n;i++)
    {
        ans += (1000-Ans[i])/1000;
    }

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

    return 0;

}

Measured memory_bytes: 1696
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using ull = unsigned long long;
using namespace std;

int gcd(int a, int b) { return (b == 0 ? a : gcd(b,a%b) ); }

int main(){
  int n; cin >> n;
  vector<int> a(n); rep(i,n) cin >> a[i];
  int count = a[0];
  rep(i,n) if(i) count = gcd(count,a[i]);
  if(count > 1) { cout << "not coprime" << endl; return 0; }
  vector<bool> check(1001001,false);
  rep(i,n){
    for(int j = 2; j*j <= a[i]; j++){
      if(a[i] % j) continue;
      while(a[i] % j == 0) a[i] /= j;
      if(check[j]) { cout << "setwise coprime" << endl; return 0; }
      else check[j] = true;
    }
    if(a[i] > 1){
      if(check[a[i]]) { cout << "setwise coprime" << endl; return 0; }
      else check[a[i]] = true;
    }
  }
  cout << "pairwise coprime" << endl;
  return 0;
}



Measured memory_bytes: 7212
#include <stdio.h>
const int N = 10000;
int main ()
{
	int a[N]={0}, n, max=-1000005, min=1000005;
	long long sum = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)	
	{
		scanf("%d", &a[i]);
		if(a[i] > max)
		{
			max = a[i];
		}
		if(a[i] < min)
		{
			min = a[i];
		}
		sum += a[i];
		
	}
	printf("%d %d %lld\n", min, max, sum);
	return 0; 
} 


Measured memory_bytes: 2796