akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (n); i++)
typedef pair<int, int> P;

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


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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


int main() {

    ll h, w;
    cin >> h >> w;
    vector<string> a(h+5);
    rep(i, h){
        cin >> a[i];
    }

    // mint dp[1005][1005] = {0};
    vector<vector<mint>> dp(1005,vector<mint>(1005,0));
    dp[0][0] = 1;

    for(ll i = 0; i < h; i++){
        if(a[i+1][0]=='.'){
            dp[i+1][0] += dp[i][0];
        }else{
            dp[i+1][0] = 0;
        }
    }

    for(ll i = 0; i < w; i++){
        if(a[0][i+1]=='.'){
            dp[0][i+1] += dp[0][i];
        }else{
            dp[0][i+1] = 0;
        }
    }

    for(ll i = 0; i < h; i++){
        for(ll j = 0; j < w; j++){
            if(a[i+1][j+1]=='.'){
                dp[i+1][j+1] += dp[i+1][j];
                dp[i+1][j+1] += dp[i][j+1];
            }else{
                dp[i+1][j+1] = 0;
            }
        }
    }

    cout << dp[h-1][w-1] << endl;

    // rep(i,h){
    //     rep(j,w){
    //         cout <<dp[i][j];
    //     }
    //     cout << endl;
    // }
    return 0;
}

Measured memory_bytes: 9216
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;
use std::collections::HashSet;

fn main() {
    let a = input_vector::<usize>();
    let s = a.iter().collect::<HashSet<_>>();
    if s.len() == 2 {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;
const ll INF = 1LL << 60;


int main() {
    int n, i; cin >> n >> i;
    cout << n - i + 1 << endl;

    return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll n, k, sum = 0, x = 0;
	cin >> n >> k;
	vector<ll> v;
	for (int i = 0; i < n; ++i)
		{
			cin >> x;
			v.push_back(x);
		}
	sort(v.begin(), v.end(), greater<ll>());
	for (int i = k; i < n; i++)
		sum += v[i];
	cout << sum << endl;
}

Measured memory_bytes: 2420
#include <stdio.h>

void function0083(int a, int month, int day);

int main()
{
	int year[100],month[100],day[100];
	int ret;
	int i=0;
	int count;
	while(1){
		ret=scanf("%d %d %d", &year[i], &month[i], &day[i]);
		if(ret==EOF){
			break;
		}
		i++;
	}
	count=i;
	for(i=0; i<count; i++){
		function0083(year[i], month[i], day[i]);
	}
	return 0;
}

void function0083(int a, int month, int day)
{
	int year;
	if(a==1989){
		if(month==1){
			if(day>=8){
				year=a-1988;
				printf("heisei %d %d %d\n", year, month, day);
				return;
			}
			else{
				year=a-1925;
				printf("showa %d %d %d\n", year, month, day);
				return;
			}
		}
		else{
			year=a-1988;
			printf("heisei %d %d %d\n", year, month, day);
			return;
		}
	}
	else if(a>1989){
		year=a-1988;
		printf("heisei %d %d %d\n", year, month, day);
		return;
	}
	else if(a==1926){
		if(month==12){
			if(day>=25){
				year=a-1925;
				printf("showa %d %d %d\n", year, month, day);
				return;
			}
			else{
				year=a-1911;
				printf("taisho %d %d %d\n", year, month, day);
				return;
			}
		}
		else{
			year=a-1911;
			printf("taisho %d %d %d\n", year, month, day);
			return;
		}
	}
	else if(a>1926){
		year=a-1925;
		printf("showa %d %d %d\n", year, month, day);
		return;
	}
	else if(a==1912){
		if(month==7){
			if(day>=30){
				year=a-1911;
				printf("taisho %d %d %d\n", year, month, day);
				return;
			}
			else{
				year=a-1867;
				printf("meiji %d %d %d\n", year, month, day);
				return;
			}
		}
		else if(month>7){
			year=a-1911;
			printf("taisho %d %d %d\n", year, month, day);
			return;
		}
		else{
			year=a-1867;
			printf("meiji %d %d %d\n", year, month, day);
			return;
		}
	}
	else if(a>1912){
		year=a-1911;
		printf("taisho %d %d %d\n", year, month, day);
		return;
	}
	else if(a==1868){
		if(month==9){
			if(day>=8){
				year=a-1867;
				printf("meiji %d %d %d\n", year, month, day);
				return;
			}
			else{
				printf("pre-meiji\n");
				return;
			}
		}
		else if(month>9){
			year=a-1867;
			printf("meiji %d %d %d\n", year, month, day);
			return;
		}
		else{
			printf("pre-meiji\n");
			return;
		}
	}
	else if(a>1868){
		year=a-1867;
		printf("meiji %d %d %d\n", year, month, day);
		return;
	}
	else{
		printf("pre-meiji\n");
		return;
	}
	return;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

  function<bool(int, int)> check = [&](int r, int cnt){
    return !(s[r-1] == '1' && s[r] == '0' && cnt == k);
  };

  int ans = 0;
  for(int l=0, r=1, cnt=0; l<n; l++){
    while(r < n && check(r, cnt)){
      if(s[r-1] == '0' && s[r] == '1') cnt++;
      r++;
    }

    ans = max(ans, r-l);

    if(s[l] == '0' && s[l+1] == '1') cnt--;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
	long a, c500 = 0, c5 = 0;
	cin >> a;
	c500 = a / 500;
	a %= 500;
	c5 = a / 5;
	cout << c500 * 1000 + c5 * 5 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>
#include <cstring>
#include <stack>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

main()
{
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		
		if(x % 2 == 1)
		{
			cout << "first";
			return 0;
		}
	}
	
	cout << "second";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int A, B, K; cin >> A >> B >> K;
	int cnt = 0;
	for (int i = min(A, B) + 1; i > 0; --i) {
		if (A % i == 0 && B % i == 0) ++cnt;
		if (cnt == K) {
			cout << i << endl;
			return;
		}
	}
}

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


Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int C = sc.nextInt();
        char[] l;
        String temp = sc.next();
        l = temp.toCharArray();

        if(countDays(l, C) < K) {
            return;
        }
        
        char[] r = new char[l.length];
        for (int i = 0; i < l.length; i++) {
            r[i] = l[N-i-1];
        }
        int[] li = count(l,C);
        int[] ri = count(r,C);
        
        for (int i = 0; i < r.length; i++) {
            
            if(li[i]+ri[N-i-1] < K){
                System.out.println(i+1);
            }
        }
    }
    public static int[] count(char[] c, int C){
        int count = 0;
        int[] arr = new int[c.length];
        for (int i = 1; i < c.length; i++) {
            if(c[i-1] == 'o'){
                count += 1;
                Arrays.fill(arr,i,Math.min(i+C+1,c.length), count);
                i += C;
                
            }else arr[i] = count;
        }
        // for (int i : arr) {
        //     System.out.print(i);
        // }
        // System.out.println(" ");
        return arr;
    }

    public static int countDays(char[] arr, int C){
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] == 'o'){
                count++;
                i += C;
            }
        }
        return count;
    }

}

Measured memory_bytes: 46592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	int a[105];
	for(ll i=0;i<n;i++) cin>>a[i];
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			ans+=a[i]*a[j];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int main() {
	fast_cin();
	vector<int> a(4);
	for (int i = 0; i < 4; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	vector<int> b = {1, 4, 7, 9};
	if (a == b) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}
}

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

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a*b%2==0)  cout << "Even" << endl;
  else  cout << "Odd" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << x << '\n';
#define int long long 
const int mod = 1e9+7;
vector<pair<int,int>> a;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n,k,s;
    cin>>n>>k>>s;
    vector<int> ans;
    int cur = 0;
    while(ans.size()<n){
        if(k){
            ans.push_back(cur+s);
            cur +=s;
            k--;
        }else if(s+1<=1e9){
            ans.push_back(cur+s+1);
            cur += s+1;
        }else{
            ans.push_back(cur+s-1);
            cur += s-1;
        }
    }
    for(int i=0;i<n;++i){
        if(i==0){
            cout << ans[i] << ' ';
        }else{
            cout << ans[i]-ans[i-1] << ' ';
        }
    }
    cout << '\n';
    return 0;
}

Measured memory_bytes: 2292
def solve(N, D):
    fill = [0] * 24
    fill[0] = 1

    left = False
    for i in range(N):
        if D[i] == 0:
            print(0)
            return 0
        elif D[i] == 12:
            if fill[12] == 1:
                print(0)
                return 0
            else:
                fill[12] = 1
        else:
            if not left:
                if fill[D[i]] == 0:
                    fill[D[i]] = 1
                    left = True
                elif fill[24-D[i]] == 0:
                    fill[24-D[i]] = 1
                    left = False
                else:
                    print(0)
                    return 0
            else:
                if fill[24-D[i]] == 0:
                    fill[24-D[i]] = 1
                    left = False
                elif fill[D[i]] == 0:
                    fill[D[i]] = 1
                    left = True
                else:
                    print(0)
                    return 0

    s = 24
    cnt = 0
    for i in range(1, 24):
        if i == 23:
            if fill[i] == 0:
                cnt += 1
                s = min(s, cnt + 1)
            else:
                s = min(s, cnt + 1)
        else:
            if fill[i] == 0:
                cnt += 1
            else:
                s = min(s, cnt + 1)
                cnt = 0
    print(s)

if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    solve(N, sorted(D))


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

def main():
    N = int(input())
    # N, K = map(int, input().split())
    a = list(map(int, input().split()))
    # s = input().strip()
    ans = 0
    for i in range(N):
        ans += 1/a[i]
    ans = 1/ans
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
from functools import cmp_to_key

def f(a, b):
    if a[0] == b[0]:
        ap = a[1] + a[2] * 20
        bp = b[1] + b[2] * 20
        if ap == bp:
            return a[3] > b[3]
        return ap < bp
    return a[0] > b[0]


while True:
    M, T, P, R = map(int, input().split())
    if not M:
        break
    fail = [[0 for i in range(P)] for j in range(T)]
    # [-solved, time, -team]
    res = [[0, 0, -i] for i in range(T)]
    
    for r in range(R):
        m, t, p, j = map(int, input().split())
        t -= 1
        p -= 1
        if j:
            fail[t][p] += 1
        else:
            res[t][0] -= 1
            res[t][1] += fail[t][p] * 20 + m
    res = sorted(res)
    for i, r in enumerate(res[:-1]):
        if r[0] == res[i + 1][0] and r[1] == res[i + 1][1]:
            print(-r[2] + 1, end='=')
        else:
            print(-r[2] + 1, end=',')
    print(-res[-1][2] + 1)

Measured memory_bytes: 6768
N, K = map(int, input().split())
mylist =   [0] + list(map(int,input().split()))
#print(mylist)
flag_list = [float('INF') for n in range(N+1)]
#print(flag_list)
myseries = []

myflag = 0
mypos = 1
mycnt = 0 
while myflag == 0:
    if flag_list[mypos] == float('INF'):
        flag_list[mypos] = mycnt
        #print(mypos)
        myseries.append(mypos)
        mypos = mylist[mypos]
        mycnt += 1
    else:
        myflag = 1
        mystart = flag_list[mypos]
        mylen = mycnt-mystart
#print(flag_list)
#print(myseries)
#print(mystart, mylen)

if K < mystart:
    print(myseries[K])
else:
    print(myseries[(K-mystart)%mylen + mystart])

Measured memory_bytes: 32224
from collections import Counter
mod=998244353
def solve():
    n = int(input())
    D = list(map(int, input().split()))
    if D[0] != 0 or 0 in D[1:]:
        return 0
    C = Counter(D)
    ans = 1
    for i in range(1, max(C) + 1):
        ans = ans * (C[i - 1] ** C[i]) % mod
    return ans
print(solve())


Measured memory_bytes: 19936
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=0;
    if(k>0){
        if(k<a){
            cout<<k<<endl;
            return 0;
        }
        ans+=a;
        k-=a;
    }
    if(k>0){
        k-=b;
    }
    if(k>0){
        ans-=k;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 1000000005
#define NIL -1
ll mod = 1e9+7;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dp[201010];
int main(){
    int n; cin >> n;
    ll x[n], y[n];
    ll b, e;
    for(int i = 0; i < n; i++){
        cin >> x[i];
        y[i] = x[i];
    }
    sort(y, y + n);
    b = y[n/2-1];
    e = y[n/2];
    for(int i = 0; i < n; i++){
        if(x[i] <= b){
            cout << e << endl;
        } else if(x[i] >= e){
            cout << b << endl;
        }
    }
}


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


int main() {

    string n;
    cin >> n;
    if (n[0] == '9' || n[1] == '9') cout << "Yes" <<endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
M=int(input())
c=[]
d=[]
for i in range(0,M):
    D,C=map(int,input().split())
    c.append(C)
    d.append(D)

s=sum(c[i]*d[i] for i in range(0,M))
digit=sum(c)
if s%9==0:
    print(digit-1+s//9-1)
else:
    print(digit-1+s//9)

Measured memory_bytes: 72024
import java.util.*
fun main(arg: Array<String>) {
    val N = nextInt()
    val V = listOfDouble()
    var Q = PriorityQueue<Double>(N, Comparator { a, b ->  a.compareTo(b) })
    Q.addAll(V)
    for (n in 1..N - 1) {
        val v1 = Q.poll()
        val v2 = Q.poll()
        Q.add((v1 + v2) / 2)
    }
    println(Q.peek())
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfDouble() = listOfString().map { java.lang.Double.parseDouble(it) }

Measured memory_bytes: 37560
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

int main() 
{
	fast;
	ll N,x; cin>>N; ll arr[200000],visited[200000];
	for(ll i = 1 ; i <= N; i++) cin>>arr[i];
	for(ll i = 1 ; i <= N; i++) visited[i] = 0;
	x = 1; ll ans = 0;
	while(x != 2)
	{
		if(visited[x] == 1)
		{
			ans = -1;
			break;
		}
		else ans++;
		visited[x] = 1;
		x = arr[x];
	}
	cout << ans << endl;
 	return 0;	
}

Measured memory_bytes: 3072
#include<iostream>
#include<cstring>
using namespace std;
string s;
int main(){
    int n,m;
    cin>>n>>m>>s;
    int i;
    for(i=0;i<n;i++)
        if(s[i]>'9'||s[i]<'0'){
            cout<<"No"<<endl;
            return 0;
        }
    if(s[n]!='-'){
        cout<<"No"<<endl;
        return 0;
    }
    for(i=n+1;i<n+m;i++)
        if(s[i]>'9'||s[i]<'0'){
            cout<<"No"<<endl;
            return 0;
        }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;


int main(void){
  int n,i;
  ll x,l,left[100005];
  vector<P> right;
  
  cin >> n;
  for (i=0;i<n;i++){
    cin >> x >> l;
    right.push_back(P(x+l,i));
    left[i]=x-l;
  }
  
  sort(right.begin(),right.end());
  
  int ans=1,t,p;
  t=0;
  p=right[0].first;
  while (1){
    while (t<n && left[right[t].second]<p) t++;
    if (t==n) break;
    ans++;
    p=right[t].first;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2932
s = str(input())

year = ''
for i in range(4):
    y = s[i]
    flag1 = True
    if y == '0':
        if len(year) == 0:
            flag1 = False
        if flag1:
            year += y
    else:
        year += y
year = int(year)

month = ''
for i in range(5, 7):
    m = s[i]
    if i == 5 and m == '0':
        continue
    else:
        month += m
month = int(month)


if year < 2019:
    answer = 'Heisei'

elif year == 2019 and month <= 4:
    answer = 'Heisei'

else:
    answer = 'TBD'

print(answer)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0)
typedef pair<int,int> ii;
typedef long long int ll;
typedef vector<int> vi;
int n;
vector<vector<int>> v;
vector<vector<int>> dp;
//dp[i][l] -> maior fecilidade que dá pra chegar ali
// dp[i][l] = max(dp[i-1][(l+1)%3] + v[i-1][l] , dp[i-1][(l+2)%3] + v[i-1][l])
int solve(int i, int l){
	if(i == 1){
		return v[0][l];
	}
	if(i < n && dp[i][l] != -1) return dp[i][l];
	int ret = 0;
	ret = max(solve(i-1,(l+1)%3) + v[i-1][l] , solve(i-1,(l+2)%3) + v[i-1][l]);
	if(i < n)dp[i][l] = ret;
	return ret;
}

int main(){
	fast;
	cin >> n;
	v.resize(n);
	dp.resize(n);
	for(int i = 0 ; i < n ; i++){
		dp[i].resize(3,-1);
		v[i].resize(3);
	}
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < 3 ; j++){
			cin >> v[i][j];
		}
	}
	if(n == 1){
		cout << max(v[0][0],max(v[0][1],v[0][2])) << endl;
		return 0;
	}
	cout << max(solve(n,0),max(solve(n,1),solve(n,2))) << endl;





	return 0;
}

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

signed main() {
  ll num = 0;
  ll n, m;
  cin >> n >> m;

  if (n == m) {
    if (n == 1) num = 1;
    else if (n == 2) num = 0;
  } else if (n == 1 || m == 1) {
    num = max(n, m) - 2;
  } else {
    num = max((ll)0, (n - 2) * (m - 2));
  }

  if (n == m && n == 1) num = 1;
  else if (n == m && n == 2) num = 0;
  // else if (n == m && n >= 3) num = (n - 2) * (m - 2);
  else if (n == 1 || m == 1) num = max(n, m) - 2;
  else num = (n - 2) * (m - 2);

  cout << num << endl;
}


Measured memory_bytes: 3560
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <complex>
#include <iostream>
#include <vector>
#include <utility>
#define EPS (1e-10)
#define X real()
#define Y imag()
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;

double dot(P a, P b){
  return a.X*b.X + a.Y*b.Y;
}

double cross(P a, P b){
  return a.X*b.Y - a.Y*b.X;
}

P intersection(L a, L b){
  //??´???a??¨??´???b?????????
  return a.first + cross(b.second-b.first,a.first-b.first)/(-cross(b.second-b.first,a.second-b.first)+cross(b.second-b.first,a.first-b.first))*(a.second-a.first);
}

  
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if( cross(b,c) > EPS ) return +1;
  if( cross(b,c) < -EPS ) return -1;
  if( dot(b,c) < 0 ) return +2;
  if( abs(b-a) + EPS < abs(c-a) ) return -2;
  return 0;
}

bool is_cross(L a, L b){
  if(ccw(a.first,a.second,b.first)*ccw(a.first,a.second,b.second) <= 0 &&
     ccw(b.first,b.second,a.first)*ccw(b.first,b.second,a.second) <= 0) return true;
  return false;
}

int main(){
  double W, H;
  int N;
  while(cin >> W >> H >> N, W){
    vector<L> V;
    double x, y;
    vector<double> S;
    S.push_back(0);
    for(int i = 0; i < 2*N; ++i){
      cin >> x >> y;
      L tmp;
      if(abs(x) > EPS && abs(W-x) > EPS){
	tmp = L(P(0, W*y/x), P(W*y/(W-x), 0));
	S.push_back(W*y/(W-x));
      }else if(abs(x) > EPS){
	tmp = L(P(0, y), P(H, y));
	S.push_back(H);
      }else{
	tmp = L(P(y, 0), P(y, H));
	S.push_back(y);
      }
      V.push_back(tmp);
      if((abs(cross(tmp.first-tmp.second, P(H,0))) > EPS) && is_cross(tmp,L(P(0,H),P(H,H)))){
	S.push_back(intersection(tmp,L(P(0,H),P(H,H))).X);
      }
    }
    for(int i = 0; i < 2*N; ++i){
      for(int j = 0; j < i; ++j){
	if((abs(cross(V[j].first-V[j].second, V[i].first-V[i].second)) > EPS) && is_cross(V[i],V[j]))
	  S.push_back(intersection(V[i],V[j]).X);
      }
    }
    S.push_back(H);
    sort(S.begin(), S.end());
    int k = (int)S.size();
    double ans = 0;
    for(int i = 1; i < k; ++i){
      double s_r = S[i], s_l = S[i-1];
      L l_r = L(P(s_r,0),P(s_r,H)), l_l = L(P(s_l,0),P(s_l,H));
      vector<double> T_l, T_r;
      if(s_r > H + EPS) break;
      for(int j = 0; j < 2*N; ++j){
	//??°??¢????????´
	if((abs(cross(V[j].first-V[j].second, P(0,H))) > EPS) && is_cross(V[j],l_r)){
	  T_r.push_back(min(intersection(V[j],l_r).Y, H) );
	}else if(V[j].second.X < s_r && V[j].first.X < s_r){
	  T_r.push_back(0);
	}else if(abs(V[j].first.X - s_r) < EPS && abs(V[j].second.X - s_r) < EPS){
	  T_r.push_back(H);
	}else{
	  T_r.push_back(H);
	}
	//??°??¢????????´
	if((abs(cross(V[j].first-V[j].second, P(0,H))) > EPS) && is_cross(V[j],l_l)){
	  T_l.push_back(min(intersection(V[j],l_l).Y, H));
	}else if(V[j].second.X < s_l && V[j].first.X < s_l){
	  T_l.push_back(0);
	}else if(abs(V[j].first.X - s_l) < EPS && abs(V[j].second.X - s_l) < EPS){
	  T_l.push_back(0);
	}else{
	  T_l.push_back(H);
	}
      }
      sort(T_l.begin(), T_l.end());
      sort(T_r.begin(), T_r.end());
      ans += (T_l[N]-T_l[N-1]+T_r[N]-T_r[N-1])*(s_r-s_l)/2.0;
    }
    printf("%.11f\n", ans/H/H);
  }
  return 0;
}

Measured memory_bytes: 3440
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String X = sc.next();
		int one = 0;
		for (int i = 0; i < X.length(); i++) {
			if (X.charAt(i) == '1') {
				one++;
			}
		}
		long sum = 0;
		long sum2 = 0;
		long temp = 1;
		long odd[] = new long[N];
		long a[] = new long[N];
		for (int i = 0; i < X.length(); i++) {
			if (one > 1) {
				odd[i] = temp;
				temp = (temp * 2) % (one - 1);
			}
		}
		temp = 1;
		for (int i = 0; i < X.length(); i++) {
			a[i] = temp;
			temp = (temp * 2) % (one + 1);
		}
		for (int i = X.length()-1; i >=0; i--) {
			if (X.charAt(i)=='1') {
				if (one>1) {
					sum =(sum + odd[N-i-1])%(one-1);
				}
				sum2 =(sum2 + a[N-i-1])%(one+1);
			}
		}
		int result[] = new int[N];
		for (int i = X.length()-1; i >=0; i--) {
			if (one==0 &&i!=N-1) {
				result[i]=0;
			} else if (one ==0) {
				result[i]=1;
			} else if (one==1&&X.charAt(i)=='1') {
				result[i]=0;
			} else if (X.charAt(i)=='1'){
				long t = (sum-odd[N-i-1]+one-1)%(one-1);
				result[i]=Main.changeT(t)+1;
			} else {
				long t = (sum2+a[N-i-1])%(one+1);
				result[i]=Main.changeT(t)+1;
			}
		}
		for (int i = 0; i < X.length(); i++) {
			System.out.println(result[i]);
		}
	}

	public static int changeT (long a) {
		int count =0;
		while(a>0) {
			int one=0;
			long temp =a;
			while (temp>0) {
				if (temp%2==1) {
					one ++;
				}
				temp = temp/2;
			}
			a = a%one;
			count ++;
		}
		return count;
	}
}

Measured memory_bytes: 59220
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include <math.h>

int main() {
  int a, b;

  cin >> a >> b;

  if (a >= b) {
    for (int j = 0; j < a; j++) {
      cout << b;
    }
  } else {
    for (int j = 0; j < b; j++) {
      cout << a;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pub push_back
#define pob pop_back
#define M 1000000007
#define pii pair<ll,ll>
#define mp make_pair
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    ll h,w,a,b,p;
    cin>>h>>w;
    cin>>a>>b;
    p=a*w+h*b;
    p-=a*b;
    p=h*w-p;
    cout<<p;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	if(y==0) return x;
	return gcd(y,x%y);	
}

ll lcm(ll x, ll y) {
	ll z=gcd(x,y);
	return x/z*y;
}

int main()
{
	string s;
	cin >> s;
	cout << (s>"2019/04/30"?"TBD\n":"Heisei\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;

string N;
int K;

ll dp[110][2][4];

ll rec(int i = 0, bool smaller = false, int k = K) {
    if (k == 0) return 1;
    if (i >= N.size()) return 0;

    ll &ret = dp[i][(int)smaller][k];
    if (ret > 0) return ret;
    ret = 0;

    if (smaller) {
        ret += rec(i + 1, true, k);            // 次の桁が0の時
        ret += rec(i + 1, true, k - 1) * 9LL;  // 次の桁が0以外の時
    } else {
        if (N[i] == '0') {  // 次の桁が0しかありえない時
            ret += rec(i + 1, false, k);
        } else {
            ret += rec(i + 1, true, k);                     // 次の桁が0の時
            ret += rec(i + 1, true, k - 1) * (N[i] - '1');  // 次の桁が0でもN[i]でも無い時
            ret += rec(i + 1, false, k - 1);                // 次の桁がN[i]の時
        }
    }
    return ret;
}

int main() {
    cin >> N;
    cin >> K;
    cout << rec() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() 
{
	int n;
	cin >> n;
	int x = 200001, ans = 0;
	rep(i, 0, n) {
		int p;
		cin >> p;
		if (p <= x) {
			ans++;
			x = p;
		}
	}
		cout << ans << endl;
}




Measured memory_bytes: 3632
n=int(input())
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
c=list(map(int,input().split()))
c.sort(reverse=1)
print(sum(c)-c[0])
d=[-1]*n
d[0]=c[0]
Q=[0]
visited={0}
ind=1
while Q:
  P=[]
  for i in Q:
    for j in edge[i]:
      if j in visited:continue
      visited.add(j)
      d[j]=c[ind]
      ind+=1
      P.append(j)
  Q=P
print(*d)

Measured memory_bytes: 6548
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    int data[8] = {0};
    double a, b;
    while (cin >> a >> b) {
        if (a >= 1.1) {
            data[0]++;
        } else if (a >= 0.6) {
            data[2]++;
        } else if (a >= 0.2) {
            data[4]++;
        } else {
            data[6]++;
        }
        if (b >= 1.1) {
            data[1]++;
        } else if (b >= 0.6) {
            data[3]++;
        } else if (b >= 0.2) {
            data[5]++;
        } else {
            data[7]++;
        }
    }
    for (int i = 0; i < 8; i++) {
        if (i%2) {
            cout << data[i] << endl;
        } else {
            cout << data[i] << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 3188
S = input()
L = []

for i in range(4):
  T = "n"
  for j in range(len(L)):
    if S[i] == L[j][0]:
      L[j][1] +=1
      T = "y"
  if T == "n":
    L.append([S[i],1])
    
if len(L) == 2:
  if L[0][1] == L[1][1]:
    print("Yes")
  else:
    print("No")
else:
  print("No")

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

int main(){
    int n,a=0,c=1;
    cin>>n;
    int v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
    }

    while(n>0){
        if(v[a] == 2){
            break;
        }else {
            a=v[a]-1;
            c++;
        }
        n--;
    }
    if(n==0){
        cout<<-1<<endl;
    }else{
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	long N, Q;
	string S;

	cin >> N >> Q;
	cin >> S;

	vector<tuple<char, int>> T;

	for( long long i = 0; i < Q; i++ ){
		char t, d;
		cin >> t >> d;
		T.push_back(make_tuple(t, d=='R'?1:-1));
	}

	long long L = -1;
	long long R = N;
	while(R-L>1){
		int M = (L+R)/2;
		int cur = M;
		bool ok = false;

		for(int i = 0; i < T.size(); i++){
			if(S[cur] == get<0>(T[i])) cur+= get<1>(T[i]);
			if(cur == N ) break;
			if(cur == -1) {
				ok = true;
				break;
			}
		}
		if(ok) L = M;
		else R = M;
	}
	int LL = L;

	L = -1; R = N;
	while(R-L>1){
		int M=(L+R)/2;
		int cur=M;
		bool ok = false;

		for(int i = 0; i < T.size(); i++){
			if(S[cur] == get<0>(T[i])) cur+= get<1>(T[i]);
			if(cur == -1 ) break;
			if(cur == N) {
				ok = true;
				break;
			}
		}
		if(ok) R=M;
		else L=M;
	}

	int RR = R;
	if(LL>=RR) cout<<0<<endl;
	else cout << RR-LL-1<<endl;

	return 0;
}


Measured memory_bytes: 2680
/*
  AOJ 1518
  Title:Last One
  @kankichi573
*/
#include <stdio.h>
int conv(char c)
{
  if(isdigit(c))
    return(c-'0');
  if(isupper(c))
    return(c-'A'+10);
  if(islower(c))
    return(c-'a'+36);
}
int count_bits(int n)
{
  int ret=0;

  while(n)
    {
      ret += (n & 1);
      n >>= 1;
    }
  return(ret);
}
int count_bits_N(char * s,int radix)
{
  int ret=0;

  while(1)
    {
      ret += conv(*s);
      s++;
      if(!*s)	break;
      ret *= radix;
    }
  //printf("ret=%d\n",ret);
  return(count_bits(ret));
}
main()
{
  int n,p,i;
  char m[10];
  int cnt;
    
  scanf("%d",&n);
  for(i=0,cnt=0;i<n;i++)
    {
      scanf("%d %s",&p,m);
      cnt ^= count_bits_N(m,p);
    }
  printf("%s\n",(cnt)?"win":"lose");
  
  return(0);
}

Measured memory_bytes: 584
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18

int N,M,Q;
vector<vector<int>> sum;
int buildsum(vector<int> L, vector<int> R){
    sum = vector<vector<int>>(N+1,vector<int>(N+1,0));
    for(int i=0;i<M;i++){
        sum[L[i]][R[i]]++;
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            sum[i][j] += sum[i - 1][j];
			sum[i][j] += sum[i][j - 1];
			sum[i][j] -= sum[i - 1][j - 1];
        }
    }
}

int getsum(int p, int q){
    int ans = sum[q][q]-sum[q][p-1]-sum[p-1][q] + sum[p-1][p-1];
    return ans;
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> Q;
    vector<int> L(M);
    vector<int> R(M);
    
    for(int i=0;i<M;i++){
        cin >> L[i] >> R[i];
    }
    vector<int> p(Q);
    vector<int> q(Q);
    for(int i=0;i<Q;i++){
        cin >> p[i] >> q[i];
    }
    buildsum(L,R);
    for(int i=0;i<Q;i++){
        int ans = getsum(p[i],q[i]);
        cout << ans  << endl;
    }
    return 0;
}

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


int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> edge(N+1, vector<int>(N+1, 0));
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        edge[a][b] = 1;
        edge[b][a] = 1;
    }
    int cnt = 0;
    for (int i = 1; i < N; i++) {
        for (int j = i+1; j <= N; j++) {
            if (edge[i][j] == 0) continue;
            edge[i][j] = 0;
            queue<int> q;
            q.push(i);
            vector<bool> check(N+1, false);
            check[i] = true;
            while (!q.empty()) {
                int now = q.front();
                q.pop();
                check[now] = true;
                if (now == j) {
                    cnt++;
                    break;
                }
                for (int k = 1; k <= N; k++) {
                    if (edge[now][k] == 1 && !check[k]) {
                        q.push(k);
                    }
                }
            }
            edge[i][j] = 1;
        }
    }
    cout << M-cnt << "\n";
}

Measured memory_bytes: 256
module Main (main) where

import Control.Monad
import qualified Data.ByteString.Char8 as C8
import Data.Bool

main :: IO ()
main = do
  [[s1],[s2],[s3]] <- replicateM 3 readStrings
  print . showAnswer $ solve (s1,s2,s3)

type Input  = (String, String, String)
type Output = String

solve :: Input -> Output
solve (s1,s2,s3) = [s1!!0, s2!!1, s3!!2]

showAnswer :: Output -> Answer
showAnswer = String

-- utils
readStrings :: IO [String]
readStrings = map C8.unpack . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

Measured memory_bytes: 380
A,B=map(int,input().split())

n = 0
for i in range(A,B+1):
    s = str(i)
    recursive = True
    for j in range(len(s)//2):
        if s[j] != s[len(s)-1-j]:
            recursive = False
            break
    if recursive:
        n += 1

print(n)

Measured memory_bytes: 73316
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define REP(i,n) for (int i = 0; i < n; ++ i)
#define FOR(i,a,b) for (int i = a; i <= b; ++ i)
#define FORD(i,b,a) for (int i = b; i >= a; -- i)
#define debug(x) cerr << #x << ": " << x << "\n"
#define task ""
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> li;
typedef vector<int> vi;

const int N = 705;
int n, m, bal;
bool hasEdge[N][N];
int color[N], f[N];
vi v;

void dfs(int u) {
	//cerr << "dfs " << u << color[u] << "\n";
	bal += color[u];
	FOR(v, 1, n) if (v != u && hasEdge[u][v] == 0) {
		if (color[v] == 0) {
			color[v] = - color[u];
			dfs(v);
		} else if (color[v] == color[u]) {
			cout << "-1";
			exit(0);
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	//freopen(task".inp", "r", stdin);
	//freopen(task".out", "w", stdout);
	cin >> n >> m;
	REP(i, m) {
		int u, v;
		cin >> u >> v;
		hasEdge[u][v] = hasEdge[v][u] = 1;
	}	
	int s = 0;
	FOR(u, 1, n) if (color[u] == 0) {
		color[u] = -1;
		bal = 0;
		dfs(u);
		//cerr << "----------\n";
		s += abs(bal);
		v.pb(abs(bal));
	}
	f[0] = 1;
	int tmp = 0;
	REP(j, (int) v.size()) {
		FORD(i, s/2, v[j]) f[i] |= f[i - v[j]];
	}
	FOR(i, 1, s/2) if (f[i]) tmp = i;
	//FOR(i, 0, s/2) cerr << f[i] << " "; cerr << "\n";
	int dif = s - 2 * tmp;
	int x = (n - dif) / 2;
	int y = (n + dif) / 2;
	//cerr << x << " " << y << "\n";
	cout << 1LL * x * (x - 1) / 2 + 1LL * y * (y - 1) / 2;
}

Measured memory_bytes: 768
N,Q = map(int,input().split())
S = input()
lr_list = [list(map(int, input().split())) for i in range(Q)]

ac_list  = [0]*N
cnt = 0
for i in range(N-1):
    if i < len(S) and S[i:i+2] == "AC":
        cnt += 1
    ac_list[i+1] = cnt
        
for lr in lr_list:
    print(ac_list[lr[1]-1] - ac_list[lr[0]-1])

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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

const ll MRINF = 5000000000000000;

int main() {

  int N, H, W;
  cin >> N >> H >> W;

  cout << (N-H+1) * (N-W+1)  << endl;



}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3628
n = gets.to_i
now = gets.split.map(&:to_i)
pass = gets.split.map(&:to_i)
ans = 0
sum = 0
check = 0
change = []
for i in 0..n-1
  if now[i] < pass[i]
    sum += pass[i] - now[i]
    ans += 1
  else
    check += now[i] - pass[i]
    change.push(now[i] - pass[i])
  end
end
change.sort!
if change.length == 0 || sum > check
  puts -1
  exit
end
while sum > 0
  sum -= change[-1]
  ans += 1
  change.delete_at(-1)
end
puts ans


Measured memory_bytes: 16308
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int time;
} P;

int head, tail, n;
P Q[LEN];

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

int min(int a, int b){
  return a < b ? a : b;
}

int main(){
  int q, a;
  int i, elaps = 0;
  scanf("%d %d", &n, &q);

  for (i=1; i<=n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].time);
  }

  head = 1;
  tail = n + 1;

  while (head != tail){
    P u = dequeue();
    a = min(u.time, q);
    u.time -= a;
    elaps += a;
    if (u.time > 0){
      enqueue(u);
    } else {
      printf("%s %d\n", u.name, elaps);
    }
  }

  return 0;
}



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

def binary_search_int(ok, ng, test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ok


N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
F = list(map(int, input().split()))
F.sort(reverse=True)

def max2(x,y):
    return x if x > y else y

def test(x):
    temp = K
    for a, f in zip(A, F):
        temp -= max2((a - x//f), 0)
        if temp < 0:
            return False
    return True

print(binary_search_int(A[-1]**2 + 100, -1,test))


Measured memory_bytes: 105408
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int n,k;
signed main()
{
	cin>>n>>k;
	if(k==1){
		cout<<0;
	}else{
		cout<<n-(k-1)-1<<endl;
	}
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define FOREACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIGN(x) (((x)>0)?1:(((x)<0)?-1:0))
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; }
typedef long long ll;
#define vv(t) vector< t > 
#define CHC(mp, x) if(mp.end() != mp.find(x))
#define CHCV(mp, x) if(mp.end() != find(ALL(mp), x))
template<typename T>
inline T lcm(T a, T b) {return a / __gcd(a, b) * b;}
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C);

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

void Main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), std::move(B), std::move(C));
}

void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    sort(ALL(A));
    sort(ALL(B));
    sort(ALL(C));
    vv(ll) memo(N);
    //Bの上に乗るAの個数をmemoする
    REP(i, N){
        auto it=lower_bound(ALL(A), B[i]);
        memo[i] = it-A.begin();
    }
    FOR(i, N, 1){
        memo[i]+=memo[i-1];
    }
    ll cnt=0;
    REP(i, N){
        auto it=lower_bound(ALL(B), C[i]);
        if(it!=B.begin()){
            cnt+=memo[it-B.begin()-1];
        }
    }
    cout << cnt << el;
}



Measured memory_bytes: 3328