akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    vector<int> v(5);
    for(auto& i : v) cin >> i;
    sort(all(v), [](auto a, auto b){return (10 - a%10)%10 < (10 - b%10)%10;});
    int ans = 0;
    REP(i, 4){
        ans += v[i] + (10 - v[i]%10) % 10;
    }
    ans += v.back();
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
int main() {
    ll n, i, j, k;
    cin >> n;
    vector<ll> a(n);
    for (i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<ll> s(n + 1);
    map<ll, ll> mp;
    s[0] = 0;
    mp[0]++;
    for (i = 1; i <= n; i++) {
        s[i] = s[i - 1] + a[i - 1];
        mp[s[i]]++;
    }
    ll ret = 0;
    for (pair<ll, ll> p : mp) {
        ll num = p.second;
        ret += num * (num - 1) / 2;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 15872
#include <stdio.h>

int main()
{
    int h, w;
    int y, x;
    while(1) {
        scanf("%d%d", &h, &w);
        if(h==0 && w==0) break;
        for(y=0; y<h; y++) {
            for(x=0; x<w; x++) {
                putchar('#');
            }
            putchar('\n');
        }
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 572
class SegmentTreeMax():
  def __init__(self,n,init):
    self.offset=2**((n-1).bit_length())
    self.tree=[init]*(2*self.offset)
    self.init=init
  def update(self,pos,val):
    pos+=self.offset
    self.tree[pos]=val
    while pos>1:
      pos=pos//2
      self.tree[pos]=max(self.tree[2*pos],self.tree[2*pos+1])
  def query(self,l,r):
    l+=self.offset
    r+=self.offset
    ret=self.init
    while l<=r:
      ret=max(ret,self.tree[r])
      r=(r-1)//2
      ret=max(ret,self.tree[l])
      l=(l+1)//2
    return ret

n=int(input())
h=list(map(int,input().split()))
a=list(map(int,input().split()))
st=SegmentTreeMax(max(h)+1,0)
for i in range(n):
  val=a[i]+st.query(0,h[i]-1)
  st.update(h[i],val)
print(max(st.tree))

Measured memory_bytes: 115800
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9+7;
ll MOD = 998244353;

int n;
vector<int> e[100005];
int df[100005];
int ds[100005];
bool vf[100005];
bool vs[100005];

void fdfs(int x, int d) {
    df[x] = d;
    vf[x] = true;
    for (int i = 0; i < (int)e[x].size(); i++) {
        if (vf[e[x][i]]) continue;
        fdfs(e[x][i], d+1);
    }
}

void sdfs(int x, int d) {
    ds[x] = d;
    vs[x] = true;
    for (int i = 0; i < (int)e[x].size(); i++) {
        if (vs[e[x][i]]) continue;
        sdfs(e[x][i], d+1);
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    fdfs(1, 0);
    sdfs(n, 0);
    int f, s;
    f = s = 0;
    for (int i = 1; i <= n; i++) {
        if (df[i] <= ds[i]) f++;
        else s++;
    }
    dump(f > s ? "Fennec" : "Snuke");
    return 0;  
}

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

const int maxa=100003;
int n, q;
long long cnt[maxa+3], ans=0;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	memset(cnt,0,sizeof cnt);
	for (int i=0;i<n;i++){
		int a;
		cin >> a;
		cnt[a]++;
		ans+=a;
	}
	cin >> q;
	while (q--){
		int b, c;
		cin >> b >> c;
		ans-=b*cnt[b];
		ans+=c*cnt[b];
		cnt[c]+=cnt[b];
		cnt[b]=0;
		cout << ans << "\n";
	}
}

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

int main(){ 
  string s;
  cin >> s;
  if(s=="Sunny"){
    cout << "Cloudy" << endl;
  }else if(s=="Cloudy"){
    cout << "Rainy" << endl;
  }else{
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
long long MIN(long long a, long long b){
    return a<b?a:b;
}
int main()
{   int h,w,k;
    scanf("%d%d%d",&h,&w,&k);
    char s[h][w+1];
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    int a[300][300]={0},cat=1,map[h];
    for(int i=0;i<h;i++){
        map[i]=0;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
               map[i]++; 
            }
        }
    }
    for(int i=0;i<h;i++){
        if(map[i]>0){
            int flag=0,x=0;
            for(int j=0;j<w;j++){
                if(s[i][j]=='#'&&flag==0){
                    while(x<=j){
                        a[i][x]=k;
                        x++;
                    }
                    flag=1;
                }
                if(s[i][j]=='#'){
                    a[i][j]=k;
                    x=j+1;
                    while(s[i][x]=='.'){
                        a[i][x]=k;
                        x++;
                    }
                    k--;
                }
            }
        }
    }
    int up=0,down=0;
    for(int i=0;i<h;i++){
        if(map[i]==0){
            up++;
        }else if(up>0){
            down=i-1;
            while(up>0){
                for(int j=0;j<w;j++){
                    a[down][j]=a[down+1][j];
                }
                down--;
                up--;
            }
            
        }
        if(i==h-1&&up>0){
            while(up>0){
                for(int j=0;j<w;j++){
                a[i-up+1][j]=a[i-up][j];
                }
                up--;
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            printf("%d ",a[i][j]);
        }
        printf("\n");
    }
    return 0;
}


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

#define int long long
typedef pair<int, int> P;

int N;
int A[100000];

signed main() {   
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
        --A[i];
    }

    int ans = 0;
    for(int i = 0; i < N; ++i) {
        int j = A[i];
        if(i == A[j]) {
            ++ans;
            A[j] = -1;
        }
    }

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

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

class UF{
	vector<int> prsz;// parent & size
	public:
	UF(int n): prsz(n, -1){}
	int operator[](int v){return prsz[v] < 0? v: prsz[v]=operator[](prsz[v]);}//root
	bool operator()(int v, int u){//unite
		v = operator[](v); u = operator[](u);
		if(v == u) return false;
		if(size(v) < size(u)) swap(v, u);
		prsz[v] += prsz[u];
		prsz[u] = v;
		return true;
	}
	int size(int x){return -prsz[operator[](x)];}
};

int main(){
	int N, M; cin>>N>>M;
	UF uf(N);
	rep(i, M){
		int a,b; cin>>a>>b;
		uf(a-1, b-1); // unite(a,b)
	}
	int ans = 0;
	rep(i, N) ans = max(ans, uf.size(i));
	cout<< ans <<endl;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll n, m, p, ac, wa;
    string s;
    ll cnt_ac[100005], cnt_wa[100005];
    m0(cnt_ac);
    m0(cnt_wa);
    cin >> n >> m;

    for(ll i = 0; i < m; i++) {
        cin >> p >> s;
        if(s == "AC") {
            cnt_ac[p] = 1;
        } else {
            if(cnt_ac[p] == 0) {
                cnt_wa[p]++;
            }
        }
    }

    ac = 0, wa = 0;
    for(ll i = 1; i <= n; i++) {
        if(cnt_ac[i] == 1) {
            ac++;
            wa += cnt_wa[i];
        }
    }

    cout << ac << " " << wa << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> A;
	A.resize(N);
	vector<int> counter(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		counter[A[i]]++;
	}

	int kind = 0;
	for (int i = 1; i <= N; i++) {
		if (counter[i] > 0)
			kind++;
	}

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

	int ans = 0;

	if (kind > K) {
		for (int i = N - K; i >= 1; i--) {
			if (counter[i] == 0)
				break;
			else
				ans += counter[i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        an:[i64;n],
    }
    let mut minv = an[0];
    let mut ans = std::i64::MIN;
    for j in 1..n {
        ans = max(ans,an[j]-minv);
        minv = min(minv, an[j]);
    }
    println!("{}",ans);
}



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

c = []
c.append(k - a[-1] + a[0])
for i in range(len(a)-1):
    c.append(a[i+1] - a[i])

longest = sorted(c, reverse=True)[0]

print(k-longest)


Measured memory_bytes: 26436
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rev(x) reverse(x,x+strlen(x))
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int N=1e6+10;
ll a,b,c,d,ans,e,p;
ll gcd(ll m,ll n)
{
    if(m%n==0) return n;
    return gcd(n,m%n);
}
int main(){
    cin>>a>>b>>c>>d;
    e=c*d/gcd(c,d);

    if(a%c==0) p=a;
    else       p=(a/c+1)*c;
    if(p<=b)
    ans+=(b-p)/c+1;

    if(a%d==0) p=a;
    else       p=(a/d+1)*d;
    if(p<=b)
    ans+=(b-p)/d+1;

    if(a%e==0) p=a;
    else       p=(a/e+1)*e;
    if(p<=b)
    ans-=(b-p)/e+1;

    cout<<b-a+1-ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int func(vector<vector<int>> &data, vector<bool> &bit, int ans, int N, int M, int X, int n) {
    if (n == 0) {
        int sum = 0;
        int know;
        bool check = true;
        for (int i = 1; i < M + 1; i++) {
            know = 0;
            for (int j = 0; j < N; j++) {
                if (bit.at(j)) {
                    know += data.at(j).at(i);
                }
            }
            if (know < X) {
                check = false;
                break;
            }
        }
        if (check) {
            for (int i = 0; i < N; i++) {
                if (bit.at(i)) {
                    sum += data.at(i).at(0);
                }
            }
            ans = min(ans, sum);
        }
        return ans;
    }
    int sumt, sumf;
    bit.at(N - n) = true;
    sumt = func(data, bit, ans, N, M, X, n - 1);
    bit.at(N - n) = false;
    sumf = func(data, bit, ans, N, M, X, n - 1);
    ans = min({ans, sumt, sumf});
    return ans;
}

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<vector<int>> data(N, vector<int>(M + 1));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M + 1; j++) {
            cin >> data.at(i).at(j);
        }
    }
    vector<bool> bit(N, false);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += data.at(i).at(0);
    }
    ans++;
    int money = func(data, bit, ans, N, M, X, N);
    if (money == ans) {
        money = -1;
    }
    cout << money << endl;
}

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

int main() {
	// your code goes here
	
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	
	long int n;
	cin>>n;
	
	long int arr[n];
	
	for(long int i=0;i<n;i++)
	{
	    cin >> arr[i];
	}
	
	sort(arr,arr+n);
	
	long int k;
	 k=arr[((n-1)/2)+1]-arr[(n-1)/2];
	
	cout<< k<<endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    long long int a,b,x,i,cnt=0;
    cin>>a>>b>>x;
    if(a % x == 0){
        cout << b / x - a / x + 1 << endl;
    }
    else{
        cout << b / x - a / x << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define  Rep(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) Rep(i,0,n) 
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
 
int main()
{
    map<char,string> s;
    cin>>s['a']>>s['b']>>s['c'];
    char now='a';
    for(;;){
        if(s[now].size()==0) { cout<<(char)(now+'A'-'a')<<endl; return 0; }
        char tmp=s[now][0];
        s[now]=s[now].substr(1);
        now=tmp;
    }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val a = (1..3).map{
        readLine()!!.split(" ").map{it.toInt()}
    }
    val n = readLine()!!.toInt()
    var b = Array(n) {
        readLine()!!.toInt()
    }
    var bingo = Array(9) {false}
    bingo[0] = (0..2).map{a[it][it] in b}.all{it}
    bingo[1] = (0..2).map{a[it][2-it] in b}.all{it}
    for (i in 2..4)
        bingo[i] = (0..2).map{a[i-2][it] in b}.all{it}
    for (i in 5..7)
        bingo[i] = (0..2).map{a[it][i-5] in b}.all{it}
    println(if (bingo.any{it}) "Yes" else "No")
}


Measured memory_bytes: 37908
#include <iostream>
#include <sstream>
using namespace std;
string dunction(int x){
    string ans;
    stringstream bruh;
    bruh << x;
    return bruh.str();
}




int main(){
    int n, count;
    count = 0;
    cin >> n;
    string bruh;
    for (int x = 1; x <= n; x++){
        bruh = dunction(x);
        if (bruh.size() % 2 == 1)
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
import sys, os
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
qs = [0]*N
for i in range(N):
    s, t, x = map(int, readline().split())
    qs[i] = (s-x, t-x, x)
qs.sort()

b = builders.StringBuilder(Q*11)
que = []
D = [int(readline()) for i in range(Q)]
j = 0
for d in D:
    while j < N and qs[j][0] <= d:
        s, t, x = qs[j]
        heappush(que, (x, t))
        j += 1
    while que and que[0][1] <= d:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())

Measured memory_bytes: 120784
package main

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

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a, b, n := scanInt(), scanInt(), scanInt()

	ans := 0
	if n < b-1 {
		ans = n
	} else {
		ans = b - 1
	}
	fmt.Println(ans*a/b - ans/b*a)
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
int N, Y;

int main()
{
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= N - i; j++)
        {
            int k = N - i - j;
            if (10000 * i + 5000 * j + 1000 * k == Y)
            {
                res10000 = i;
                res5000 = j;
                res1000 = k;
            }
        }
    }
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}


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

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

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> k(M);
	vector<vector<int>> s(M);
	vector<int> p(M);
	for(int i=0;i<M;i++){
		cin >> k.at(i);
		for(int j=0;j<k.at(i);j++){
			int x;
			cin >> x;
			x--;
			s.at(i).push_back(x);
		}
	}
	for(int i=0;i<M;i++)	cin >> p.at(i);
	
	int ans=0;
	for(int bit=0;bit<(1<<N);bit++){
		bool flag=true;
		for(int i=0;i<M;i++){
			int count=0;
			for(int j=0;j<k.at(i);j++){
				if(bit & (1<<s.at(i).at(j))){
					count++;
				}
			}
			if(count%2 !=p.at(i))	flag=false;
		}
		if(flag)	ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
blue = [input() for i in range(N)]
M = int(input())
red = [input() for i in range(M)]
blue_dict = {}
red_dict = {}
for s in blue:
    if s not in blue_dict:
        blue_dict[s] = 1
    else:
        blue_dict[s] += 1

for t in red:
    if t not in red_dict:
        red_dict[t] = 1
    else:
        red_dict[t] += 1

ans = 0
for key in blue_dict:
    if key in red_dict:
        ans = max(ans, blue_dict[key] - red_dict[key])
    else:
        ans = max(ans, blue_dict[key])
print(ans)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[]ss = S.toCharArray();
 
    int cou = 0;
    for(int i=0; i<4; i++){ 
        if(ss[i]==('+')){
        cou++;
        }
    }
    int mai =4-cou;
    int ans = cou-mai;
		System.out.println(ans); 
}
}

Measured memory_bytes: 22740
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0 ; i < n ; i++ ){
            a[i] = sc.nextInt();
        }
        sc.close();
        long s = 1000;
        long kab = 0;
        for(int i = 0 ; i < n - 1 ; i++){
            if(a[i] <= a[i + 1]){
                kab = s / a[i];
                s -= kab * a[i];
                s += a[i + 1] * kab;
                kab = 0;
            }
        }
        System.out.println(s);
    }
}

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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;

ll op(ll a, ll b) {
    return max(a, b);
}

ll e() {
    return (ll)(0);
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n,k;
    cin >> n >> k;
    segtree<ll,op,e> seg(300001);
    rep(i,n){
        ll a;
        cin >> a;
        ll p = seg.prod(max(a-k,(ll)0),min(a+k+1,(ll)300001));
        seg.set(a,p+1);
    }
    print(seg.all_prod());
    return 0;
}

Measured memory_bytes: 13792
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD = 1000000007;
#define INF (1e9)
#define print(x) cout << x << endl;

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


int main()
{
    ll N;
    cin >> N;
    print(N/3);
    return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

long long gcd(long long m, long long n) {

  if (m < n)
    std::swap(m, n);

  long long tmp;
  while (m % n != 0) {
    tmp = n;
    n = m % n;
    m = tmp;
  }

  return n;
}

int main() {

  int N, X;
  cin >> N >> X;

  int ans = 0;
  REP(i, N) {
    int x;
    cin >> x;

    if (ans == 0) {
      ans = abs(X - x);
    } else {
      ans = gcd(ans, abs(X - x));
    }
  }

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


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define PrintArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;
#define PrintPairs(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i].fi <<"," << cont[__i].se<<")";} cout<<endl;
#define Print(v) cout<<v<<endl;
#define PDBG() cout<<"Line:"<<__LINE__<<endl;
#define PrintArray2D(cont, fh, th, fw, tw) for(int __i=fh;__i<th;++__i){for(int __j=fw;__j<tw;++__j) {cout<<cont[__i][__j]<<" ";} cout<<endl;}cout<<endl;
#define Resize2D(cont,H,W,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W,V);
#define Resize3D(cont,H,W,D,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W);for(int i=0;i<H;++i)for(int j=0;j<W;++j)cont[i][j].resize(D,V);
/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 * priority_queue<int,vector<int>, greater<int>> Q;
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
/*
struct PairComp{
    int operator()(P l, P r) const {
        return l.fi==r.fi?l.se<r.se:l.fi<r.fi;
    }
};*/
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
int main() {
    cout.precision(15);
    cout << fixed;
    string s;
    cin >> s;
    if (s[0]>='a' && s[0]<='z') {
        cout<<"a"<<endl;
    } else {
        cout<<"A"<<endl;
    }

}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include<cstring>
#define max(x,y) x>y?x:y
using namespace std;
int a[2][105];
int f[2][105];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<=1;i++)
        for(int j=1;j<=n;j++)
            cin>>a[i][j];
    f[0][1]=a[0][1];
    f[1][1]=a[0][1]+a[1][1];
    for(int i=2;i<=n;i++)
    {
        f[0][i]=f[0][i-1]+a[0][i];
    }

    for(int i=2;i<=n;i++)
    {
        if(f[0][i]>f[1][i-1])
            f[1][i]=f[0][i]+a[1][i];
        else
             f[1][i]=f[1][i-1]+a[1][i];
       // f[1][i]=max(,)+a[1][i];

    }
   // for(int i=0;i<=1;i++)
  //  {
   //     for(int j=1;j<=n;j++)
    //        cout<<f[i][j]<<" ";
    //    cout<<endl;

   // }


     cout<<f[1][n]<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
d = []
for i in range(n):
  a = list(map(int, input().split()))
  d.append(a)
total = 0
for i in d:
  if i[0] == i[1]:
    total += 1
  else:
    total = 0
  
  if total == 3:
    print("Yes")
    exit()

print("No")
    


Measured memory_bytes: 9148
#include<stdio.h>
int count;
void bfs(char (*sz) [101],int r,int c,int n,int m,char k){
	if(r<0||r>=n||c<0||c>=m)return ;
	if(sz[r][c]=='.'||sz[r][c]!=k)return ;
	sz[r][c]='.';
	for(int dr=-1;dr<=1;dr++)
	for(int dc=-1;dc<=1;dc++){
		if((dr!=0||dc!=0)&&dr*dc==0)bfs(sz,dr+r,dc+c,n,m,k);
	}
	return;
}
int main(){
	char sz[101][101];
	int a,b;
	while(scanf("%d%d",&a,&b)==2&&a*b){
		count=0;
		getchar();
		for(int i=0;i<a;i++)
		scanf("%s",sz[i]);
		
		for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(sz[i][j]=='@'||sz[i][j]=='#'||sz[i][j]=='*')
			{
			bfs(sz,i,j,a,b,sz[i][j]);
			count++;
		}
		}
		}
		printf("%d\n",count);
	}
	return 0;
} 

Measured memory_bytes: 1980
#include<stdio.h>

int main(void)
{
        int a,b;
        scanf("%d %d",&a,&b);
        if (a<b){
            printf("a < b\n");
        }else if(a>b){
            printf("a > b\n");
        }else if(a==b){
            printf("a == b\n");
        }
        return 0;
}

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



int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];

    map<ll, ll> m;
    rep(i, n){
        m[a[i]-1]++;
        m[a[i]]++;
        m[a[i]+1]++;
    }

    ll res = -1;
    for(auto it : m){
        res = max(res, it.second);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 6912
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.00000001
using namespace std;

struct Info{
	double r;
};

double*** dp;

void func(char buf[300]){

	double length;
	int tmp;

	int index;

	tmp = 0;
	for(index = 0;buf[index] != ' ' && buf[index] != '\0'; index++){
		tmp = 10*tmp + buf[index] - '0';
	}

	length = (double)tmp;

	Info info[15];
	int info_index = 0;

	while(buf[index] != '\0'){

		tmp = 0;
		for(++index;buf[index] != ' ' && buf[index] != '\0';index++){
			tmp = 10*tmp + buf[index] - '0';
		}
		info[info_index].r = (double)tmp;
		info_index++;
	}

	double sum = 0;

	for(int i = 0; i < info_index; i++){
		sum += info[i].r;
	}

	if(length > 2*sum+EPS){
		printf("OK\n");
		return;
	}

	double distance[info_index][info_index];

	for(int i = 0; i < info_index;i++){
		for(int k = 0; k < info_index; k++){
			if(i != k){
				distance[i][k] = sqrt((info[i].r+info[k].r)*(info[i].r+info[k].r)-(info[i].r-info[k].r)*(info[i].r-info[k].r)); //i??????k???
			}
		}
	}

	int limit = pow(2,info_index);


	double minimum = 4000.0;



	for(int i = 0; i < info_index; i++){
		for(int k = 0; k < info_index;k++){
			for(int p = 0; p < limit; p++)dp[i][k][p] = 3000.0;
		}
	}

	int next_state;

	for(int i = 0; i < info_index;i++){
		next_state = pow(2,i);

		dp[0][i][next_state] = info[i].r;
	}

	for(int i = 1; i <= info_index-1; i++){
		for(int k = 0; k < info_index; k++){
			for(int state = 0; state < limit; state++){
				if(dp[i-1][k][state] < 2000.0){
					for(int a = 0; a < info_index; a++){
						if(state & (1 << a)){
							//Do nothing
						}else{
							next_state = state + pow(2,a);
							if(i != info_index-1){
								dp[i][a][next_state] = min(dp[i][a][next_state],dp[i-1][k][state]+distance[k][a]);
							}else{
								dp[i][a][next_state] = min(dp[i][a][next_state],dp[i-1][k][state]+distance[k][a]+info[a].r);
							}
						}
					}
				}
			}
		}
	}

	for(int i = 0; i < info_index; i++){
		minimum = min(minimum,dp[info_index-1][i][limit-1]);
	}

	if(minimum < length || fabs(minimum-length) < EPS){
		printf("OK\n");
	}else{
		printf("NA\n");
	}

}

int main(){

	dp = new double**[12];

	for(int i = 0; i < 12; i++){
		dp[i] = new double*[12];
		for(int k = 0; k < 12; k++){
			dp[i][k] = new double[4096];
		}
	}


	char buf[300];
	int index;
	char ch;

	while(true){
		index = 0;
		ch = getchar();

		if(ch == '\n' || ch == '\0' || ch == EOF)break;

		while(ch != '\n' && ch != '\0' && ch != EOF){
			buf[index++] = ch;
			ch = getchar();
		}
		buf[index] = '\0';
		func(buf);
	}

	return 0;
}

Measured memory_bytes: 7840
# coding:utf-8

import sys
from collections import defaultdict

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

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


n, k, l = LI()

# UnionFind
class UnionFind:
    # 負: ルートで値は木の深さを表す
    # 正: 子で値は次のノードを表す
    def __init__(self, size: int) -> None:
        self.nodes = [-1] * size  # 初期状態では全てのノードがルート

    def find(self, x: int) -> int:
        if self.nodes[x] < 0:
            return x
        else:
            self.nodes[x] = self.find(self.nodes[x])
            return self.nodes[x]

    def unite(self, x: int, y: int) -> None:
        root_x, root_y = self.find(x), self.find(y)
        if root_x != root_y:
            if self.nodes[root_x] != self.nodes[root_y]:  # グラフの高さが異なる場合
                # 木のランクが高い方のルートに併合させる
                # 併合後にランクの変動はない
                if self.nodes[root_x] < self.nodes[root_y]:
                    self.nodes[root_y] = root_x
                else:
                    self.nodes[root_x] = root_y
            else:
                # ランクが等しい木同士を併合させるので
                # 併合後は木のランクが1つ上がる
                self.nodes[root_x] += -1
                self.nodes[root_y] = root_x


ufa = UnionFind(n)
ufb = UnionFind(n)

for _ in range(k):
    a, b = LI_()
    ufa.unite(a, b)
for _ in range(l):
    a, b = LI_()
    ufb.unite(a, b)

cnt = defaultdict(int)
keys = []
for i in range(n):
    key = (ufa.find(i), ufb.find(i))
    cnt[key] += 1
    keys.append(key)

print(*[cnt[key] for key in keys])


Measured memory_bytes: 43420
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let bs = reads int
    let xs =
        Seq.zip bs (Seq.initInfinite (fun x -> x + 1))
        |> Seq.sortBy fst
        |> Seq.map snd
    String.Join(" ", xs)
    |> printfn "%s"
    0

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

int main(){
  int N; cin >> N;
  vector<long long>H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  bool flag = true;
  for(int i=N-1;i>0;i--){
    if(H.at(i-1) == H.at(i) + 1) H.at(i-1)--;
    else if(H.at(i-1) > H.at(i)){
      flag = false;
      break;
    }
    if(H.at(i-1) == 0){
      flag = false;
      break;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 1152
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
char buf[1000001];
int main(){
	int m,n;
	while(scanf("%d%d",&n,&m),n){
		scanf("%s",buf);
		vector<int> v;
		int len=0,p=0;
		while(p<m){
			while(buf[p]=='O')p++;
			while(p+2<m&&buf[p+1]=='O'&&buf[p+2]=='I')p+=2,len++;
			if(len>0)v.push_back(len);
			len=0; p++;
		}
		int ans=0;
		rep(i,v.size()){
			if(v[i]>=n)ans+=v[i]-n+1;
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

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

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = [0] * N

for i in range(N - 1, -1, -1):
    tmp_sum = 0
    for j in range((i + 1) * 2 - 1, N, i + 1):
        tmp_sum += B[j]
        tmp_sum %= 2
    B[i] = tmp_sum ^ A[i]

print(sum(B))
print(*[i + 1 for i, b in enumerate(B) if b == 1])

Measured memory_bytes: 17644
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    string s,S,t; cin>>s>>t;
    int a=s.size();
    int k=0;
    for(int i=0;i<100;i++){
        S[0]=s[a-1];
        for(int j=0;j<a-1;j++){
            S[j+1]=s[j];
        }
        for(int j=0;j<a;j++){
            if(S[j]==t[j]){
                k++;
            }
            s[j]=S[j];
        }
        if(k==a){
            cout<<"Yes"<<endl;
            return 0;
        }
        k=0;
    }
    cout<<"No"<<endl;
}


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

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {
    string s;
    cin >> s;
    string ans = (s[0] == '9' || s[1] == '9')? "Yes" : "No";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
 
#include<algorithm>
#define str(a) to_string(a)
#define int long long
#define pb push_back
 
int32_t main()
{
    int n; cin >> n;
    int vec[n][3];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++)
            cin >> vec[i][j];
    }
    int dp[n][3];
    dp[0][0] = vec[0][0];    dp[0][1] = vec[0][1];    dp[0][2] = vec[0][2];
    for (int i = 1; i < n; i++) {
            dp[i][0] = vec[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
            dp[i][1] = vec[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
            dp[i][2] = vec[i][2] + max(dp[i - 1][1], dp[i - 1][0]);
        }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;
    }
 
 
 

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int)1e9+7, M = (int)1e5+6;

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	vector<ll> a(n);
	ll ans = 0;

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

	for (int i = 0; i < n; ++i)
	{
		for (int j = i+1; j < n; ++j)
		{
			if(a[i] == a[j])
				continue;
			for (int k = j+1; k < n; ++k)
			{
				if(a[i] == a[k] || a[j] == a[k])
					continue;

				if(((a[i]+a[j]) > a[k]) && (a[i]+a[k] > a[j]) && (a[j]+a[k] > a[i]))
					ans++;
			}
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3628
N = gets.chomp
warn N.size
carry = 0
count = 0
N.size.times{|i|
    d = N[-i-1].to_i + carry
    if d >= 6 || d == 5 && i < N.size - 1 && N[-i-2].to_i >= 5
        carry = 1
        count += 10 - d
    else
        carry = 0
        count += d
    end
}
if carry > 0
    count += 1
end
puts count

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

using namespace std;

int main(){
  int N,D,X;cin>>N>>D>>X;
  vector<int>A(N);
  for(int i;i < N;i++)
    cin>>A[i];
  
  int eat = 0;
  for(int i = 0;i < N; i++){
    int j = 0;
    while(j*A[i] < D){
      eat++;
      j++;
    }
   }
    cout<<eat+X<<endl;
  }



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		char[] str = sc.next().toCharArray();

		int count = 0;
		int tmpCount = 0;

		for(int i = 0; i < str.length; i++){
			if((i % 2 == 0 && str[i] == '0') ||( i % 2 == 1 && str[i] == '1')){
				count++;
			}
		}

		for(int i = 0; i < str.length; i++){
			if((i % 2 == 1 && str[i] == '0') ||( i % 2 == 0 && str[i] == '1')){
				tmpCount++;
			}
		}

		System.out.println(Math.min(count, tmpCount));

	}

}

Measured memory_bytes: 26420
#include<iostream>
#include<cstdio>
//#include<cmath>
//#include<algorithm>
//#include<cstring>
//#include<map>
using namespace std;
inline int read()
{
    int p=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){p=p*10+c-'0';c=getchar();}
    return f*p;}
int main()
{
	int xx,yy,ti,N;
	N=read();
	for(int i=1;i<=N;i++)
	   {
	   	ti=read();
	   	xx=read();
	   	yy=read();
	   	int s=xx+yy;
	   	if(s>ti){cout<<"No";return 0;}
	   	if(!(s%2)&&ti%2){cout<<"No";return 0;}
		if(s%2&&!(ti%2)){cout<<"No";return 0;}
	   }
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <iterator>

using namespace std;

typedef long long ll;
#define mems(p) memset(p,0,sizeof(p))
#define mp make_pair

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll a[200001];

int main() {
	ll n,k;
	cin>>n>>k;
	int curr = 1;
	vector<int> path;
	path.push_back(curr);
	set<int> pathSet;
	pathSet.insert(curr);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i+1];
	}
	ll idx = 0;
	for (int i = 0; i < n; ++i)
	{
		if (pathSet.find(a[curr]) == pathSet.end()) {
			path.push_back(a[curr]);
			pathSet.insert(a[curr]);
			curr = a[curr];
		} else {
			for (ll j = 0;j<(ll)path.size();++j) {
				if (path[j] == a[curr]) {
					idx=j;
					break;
				}
			}
			break;
		}
	}
	if (k < path.size()) {
		cout << path[k] << endl;
		return 0;
	}
	ll tem = (ll) path.size();
	tem = tem - idx;
	cout << path[(k-idx)%tem + idx] << endl;
}

Measured memory_bytes: 14572
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

pair<ll,ll> d[1000100];

int main() {
  rep(i,0,1000100)d[i] = mp(-1,-1);
  ll h,w;
  cin>>h>>w;
  vector<ll> vh;
  vector<ll> vw;
  rep(i,0,h){
    ll a;
    cin>>a;
    a--;
    if(d[a].fi!=-1){
      cout << 0 << endl;
      return 0;
    }
    d[a].fi = i;
  }
  rep(i,0,w){
    ll a;
    cin>>a;
    a--;
    if(d[a].se!=-1){
      cout << 0 << endl;
      return 0;
    }
    d[a].se = i;
  }
  ll ans1 = 1;
  ll c = 0;
  ll c0 = 0;
  ll ch = 0;
  ll cw = 0;
  per(i,0,h*w){
    ll a = i;
    if(d[i].fi!=-1&&d[i].se!=-1){
      ch++;
      cw++;
    }
    else if(d[i].se!=-1){
      ans1 *= ch;
      cw++;
      ans1 %= MOD;
    }
    else if(d[i].fi!=-1){
      ans1 *= cw;
      ch++;
      ans1 %= MOD;
    }
    else{
      ll b = ch*cw;
      ll e = b-c;
      if(e<=0){
        cout << 0 << endl;
        return 0;
      }
      ans1 *= e;
      ans1 %= MOD;
    }
    c++;
  }
  cout << ans1%MOD << endl;
  return 0;
}

Measured memory_bytes: 15872
x = input().split()
y = input().split()
z = [0, 1, 2]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
            break
        if x[j] == y[z[j]]:
            order[j] = 1 
            if x[j] == x[-j-1]:
                order[j] = 2 
    else:
        if 2 in order or (i < 3) == sum(order) % 2:
            print('Yes')
            break
    z = [z[2], z[0], z[1]]
    if i == 2:
        z = [z[0], z[2], z[1]]
else:
    print('No')

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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

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

void solve()
{
    int n;
    in(n);
    int ans = 0;
    rep1(i, n)
    {
        int flag = 0;
        rep1(j, n)
        {
            if (i % 2 == 1 && i % j == 0)
            {
                flag++;
            }
        }
        if (flag == 8)
        {
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
double a;
main()
{
    while(cin>>a)
    {
        if(a<=48)cout<<"light fly"<<endl;
        else if(a<=51)cout<<"fly"<<endl;
        else if(a<=54)cout<<"bantam"<<endl;
        else if(a<=57)cout<<"feather"<<endl;
        else if(a<=60)cout<<"light"<<endl;
        else if(a<=64)cout<<"light welter"<<endl;
        else if(a<=69)cout<<"welter"<<endl;
        else if(a<=75)cout<<"light middle"<<endl;
        else if(a<=81)cout<<"middle"<<endl;
        else if(a<=91)cout<<"light heavy"<<endl;
        else cout<<"heavy"<<endl;
    }
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


// distance,count
map<int,int> bfs(const  vector<vector<int>> &g,const int &st) {
    vector<int> cost(g.size(),INF);
    // pos,depth
    queue<pair<int,int>> q;
    q.emplace(st,0);
    while(!q.empty()) {
        auto now = q.front();q.pop();
        if(chmin(cost[now.first],now.second)) {
            for(const auto &it: g[now.first]) q.emplace(it,now.second+1);
        }
    }

    map<int,int> ret;
    REP(i,cost.size()) {
        if (cost[i] != INF && i > st) {
            if(ret.count(cost[i]) == 0) ret[cost[i]] = 0;
            // if(cost[i] == 1) cerr << "i: " << st << " j: " << i << "is cost 1" << endl;
            ret[cost[i]]++;
        }
    }
    return ret;
}
void solve() {
    int N,X,Y;
    cin >> N >> X >> Y;
    vector<vector<int>> g(N,vector<int>());
    REP(i,N-1) {
        g[i].push_back(i+1);
        if(i+1 < N) g[i+1].push_back(i);
    }
    --X; --Y;
    g[X].push_back(Y);
    g[Y].push_back(X);

    vector<int> ans(N,0);
    REP(i,N-1) {
        auto p = bfs(g,i);
        for(const auto &it: p) ans[it.first] += it.second;
    }

    FOR(i,1,N) cout << ans[i] << endl;
}



int main() {
    solve();
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	int A, B;
	cin >> A >> B >> N;
	int x = min(B - 1, N);
	int ans = (A * x / B) - A * (x / B);

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

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

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0)){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using ll=long long; 
using ld=long double; 
using namespace std;
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout); 
  #endif
  int n; cin>>n; vector<int>a(n); for(int i=0;i<=n-1;i++) cin>>a[i]; 
  ll s=0; if(n==1){ cout<<0<<"\n"; return 0 ; }
  ll k=a[0]; 
  for(int i=1;i<=n-1;i++)
  {
    if(k<=a[i]) k=a[i]; 
    else{ s+=(k-a[i]); }
  }
  cout<<s<<"\n"; 
  return 0; 
}

Measured memory_bytes: 3984