akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S;
int cnt[3];

int main(){
  cin >> S;
  for (int i = 0; i < S.length(); i++){
    cnt[S[i] - 'a']++;
  }
  sort(cnt, cnt + 3);

  if (cnt[2] - cnt[0] >= 2) NO();
  else YES();

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//hari hari
int main(){
	int n,k;
	cin>>n>>k;
	vector<int>arr(n+1);
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	vector<int>dp(n+1,INT_MAX);
	dp[1]=0;
	for(int i=2;i<=n;i++){
             for(int j=1; (i-j)>0 && j<=k; j++){
                  dp[i] = min(dp[i], dp[i-j]+abs(arr[i]-arr[i-j]));
             }
        }
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 4016
n = int(input())
d, x = map(int, input().split())
#array = []
sum = x
for i in range(n):
    #array.append(int(input()))
    a = int(input())
#    sum += d // a
#    if d % a != 0:
#        sum += 1
    sum += (d - 1) // a + 1
print(sum)


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    set<string> st[5];
    ll n; cin >> n;
    rep(i, n){
        string s; cin >> s;
        if(s[0] == 'M'){
            st[0].insert(s);
        }
        else if(s[0] == 'A'){
            st[1].insert(s);
        }
        else if(s[0] == 'R'){
            st[2].insert(s);
        }
        else if(s[0] == 'C'){
            st[3].insert(s);
        }
        else if(s[0] == 'H'){
            st[4].insert(s);
        }
    }

    ll ans = 0;
    rep(i, 5){
        reps(j, i+1, 5){
            reps(k, j+1, 5){
                ll n1 = st[i].size();
                ll n2 = st[j].size();
                ll n3 = st[k].size();

                ans += n1*n2*n3;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9600
import itertools

n,m= map(int, input().split())
l = [list(map(lambda x:int(x)-1, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))

res = 0
for i in itertools.product(range(2), repeat=n):
  i = list(i)
  flg = 0
  for j in range(m):
    now = 0
    for k in l[j]:
      if i[k] == 1:
        now += 1
    if now % 2 == p[j]:
      continue
    else:
      flg += 1
      break
  if flg == 0:
    res += 1
    
print(res)

Measured memory_bytes: 3064
import java.util.Scanner;

import java.io.*;
import java.lang.Math;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line = reader.readLine();
        char s;
        for(int i=0;i<line.length();i++){
            s = line.charAt(i);
            if(Character.isUpperCase(line.charAt(i))){
                s += 32;
            }
            else if(Character.isLowerCase(line.charAt(i))){
                s -= 32;
            }
            System.out.printf("%c",s);
        }
        System.out.println();
    }
}


Measured memory_bytes: 27852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	ll a,b,k;
	cin >> a >> b >> k;


	a -= k;
	if(a<0){
		b += a;
		a = 0;
	}
	if(b<0) b = 0;
	cout << a << " " << b << endl;

}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    writeln!(o, "{}", solve(n)).unwrap();
}
fn solve(n: usize) -> usize {
    if n == 1 {
        return 0;
    }
    let mut ps: Vec<(usize, usize)> = Vec::new();

    for i in 2..n + 1 {
        let mut j = i;
        for p in ps.iter_mut() {
            while j % p.0 == 0 {
                p.1 += 1;
                j /= p.0;
            }
        }
        if i == j {
            ps.push((i, 1));
        }
    }
    let mut cs = vec![0; 76];
    cs[1] = 1;

    for (_, c) in ps {
        for i in (1..76).rev() {
            for j in 0..c {
                let i_new = i * (j + 2);
                if i_new <= 75 {
                    cs[i_new] += cs[i];
                }
            }
        }
    }
    cs[75]
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


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

int n,M;
vector<int> g[100001];
ll dp[100001],ans[100001];
ll dfs(int v,int p){
    dp[v]=1;
    rep(i,g[v].size())if(g[v][i]!=p){
        dp[v]*=dfs(g[v][i],v)+1;
        dp[v]%=M;
    }
    return dp[v];
}
void dfs2(int v,int p){
    int sz=g[v].size();
    vector<ll> l(sz),r(sz);
    rep(i,sz){
        l[i]=dp[g[v][i]]+1;
        r[i]=l[i];
    }
    rep(i,sz-1) l[i+1]*=l[i],l[i+1]%=M;
    for(int i=sz-2;i>=0;--i) r[i]*=r[i+1],r[i]%=M;
    if(sz>=1)ans[v]=l[sz-1];
    else ans[v]=1;
    rep(i,sz)if(g[v][i]!=p){
        dp[v]=1;
        if(i!=0) dp[v]*=l[i-1],dp[v]%=M;
        if(i+1<sz) dp[v]*=r[i+1],dp[v]%=M;
        dfs2(g[v][i],v);
    }
}
int main(){
    cin>>n>>M;
    int xi,yi;
    rep(i,n-1){
        cin>>xi>>yi;
        --xi,--yi;
        g[xi].pb(yi);
        g[yi].pb(xi);
    }
    dfs(0,-1);
    dfs2(0,-1);
    rep(i,n) cout<<ans[i]%M<<endl;
    return 0;
}


Measured memory_bytes: 19584
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

template < typename Container, typename Value = typename Container::value_type >
std::istream& operator>> (std::istream& is, Container& v) {
  for (auto & x : v) is >> x;
  return is;
}

template < typename Container, typename Value = typename Container::value_type >
std::ostream& operator<< (std::ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template <typename... Args, std::size_t ... Inds>
std::ostream& tuple_output_impl(
  std::ostream& os,
  const std::tuple<Args...>& tuple,
  std::integer_sequence<std::size_t, Inds...>
)
{
  os << "(";
  (void)std::initializer_list<int>{(
    (void)(os << (Inds > 0 ? "," : "") << std::get<Inds>(tuple)), 0
  )...};
  return os << ")";
}
template <typename... Args>
std::ostream& operator<< (std::ostream& os, const std::tuple<Args...>& tuple)
 { return tuple_output_impl(os, tuple, std::index_sequence_for<Args...>()); }

template <typename... Args, std::size_t ... Inds>
std::istream& tuple_input_impl(
  std::istream& is,
  std::tuple<Args...>& tuple,
  std::integer_sequence<std::size_t, Inds...>
)
{
  (void)std::initializer_list<int>{(
    (void)(is >> std::get<Inds>(tuple)), 0
  )...};
  return is;
}
template <typename... Args>
std::istream& operator>> (std::istream& is, std::tuple<Args...>& tuple)
  { return tuple_input_impl(is, tuple, std::index_sequence_for<Args...>()); }

int n, Z, W;
std::vector< int > a;
std::map< std::tuple< int, int, int >, lint > memo;

auto f(int opp, int ckd, int who) {
  // debug(opp, ckd, who);
  assert(0 <= ckd && ckd < n);
  assert(who == 0 || who == 1);
  assert(ckd == 0 || opp == a.at(ckd - 1));
  auto tuple = std::make_tuple(opp, ckd, who);
  auto found = memo.find(tuple);
  if (found != memo.end())
    { return found->second; }
  lint ret;
  if (who == 0) {
    ret = 0LL;
    rep(i, ckd, n - 1)
      { cmx(ret, f(a.at(i), i + 1, 1)); }
    cmx(ret, std::abs(opp - a.back()));
  } else {
    ret = 1LL << 60;
    rep(i, ckd, n - 1)
      { cmn(ret, f(a.at(i), i + 1, 0)); }
    cmn(ret, std::abs(opp - a.back()));
  }
  // debug(tuple, ret);
  memo.emplace(tuple, ret);
  return ret;
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::cin >> n >> Z >> W;
  a.resize(n);
  std::cin >> a;
  auto ret = f(W, 0, 0);
  std::cout << ret << std::endl;
  return 0;
}


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


def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    l = [0 for _ in range(n)]
    for i in range(n-1, -1, -1):
        re_i = i + 1
        res = 0
        for j in range(0, n//re_i):
            re_j = j + 1
            res += l[(re_i * re_j) - 1]
        if res % 2 != a[i]:
            l[i] = 1
    ans = []
    for i in range(len(l)):
        if l[i] == 1:
            ans.append(i + 1)
    print(len(ans))
    if len(ans) == 0:
        sys.exit()
    else:
        print(" ".join(map(str, ans)))
            


if __name__ == '__main__':
    main()

Measured memory_bytes: 80368
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    string s;
    cin>>s;
    int n=0,k=0;
    n+=(s[0]-'0')*10;
    n+=(s[1]-'0');
    k+=(s[2]-'0')*10;
    k+=(s[3]-'0');
    bool y=0,m=0;
    if(k>0&&k<=12)y=1;
    if(n>0&&n<=12)m=1;
    if(y&&m)cout<<"AMBIGUOUS"<<endl;
    else if (y)cout<<"YYMM"<<endl;
    else if (m)cout<<"MMYY"<<endl;
    else cout<<"NA"<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
    int n;
    double x1,x2,x3,y1,y2,y3,A1,B1,C1,A2,B2,C2,X,Y;
    cin>>n;
    for(;n>0;n--){
        scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
        A1=2*(x2-x1);
        B1=2*(y2-y1);
        C1=x1*x1-x2*x2+y1*y1-y2*y2;
        A2=2*(x3-x1);
        B2=2*(y3-y1);
        C2=x1*x1-x3*x3+y1*y1-y3*y3;
        X=(B1*C2-B2*C1)/(A1*B2-A2*B1);
        Y=(C1*A2-C2*A1)/(A1*B2-A2*B1);
        printf("%.3lf %.3lf %.3lf\n",X,Y,hypot(X-x1,Y-y1));
    }
    return 0;
}

Measured memory_bytes: 1292
#include <stdio.h>
int main(void)
{
  int a,b,c;

    scanf("%d %d %d",&a,&b,&c);

//a<b<c
  if(a<=b && b<=c && a<=c){
      printf("%d %d %d\n",a,b,c);
//b<a<c
  }else if(b<=a && a<=c && b<=c){
      printf("%d %d %d\n",b,a,c);
//a<c<b
  }else if(a<=c && c<=b && a<=b){
      printf("%d %d %d\n",a,c,b);
      //b<c<a
  }else if(b<=c && c<=a && b<=a){
      printf("%d %d %d\n",b,c,a);
      //c<a<b
  }else if(c<=a && a<=b && c<=b){
      printf("%d %d %d\n",c,a,b);
      //c<b<a
  }else if(c<=b && b<=a && c<=a){
      printf("%d %d %d\n",c,b,a);
  }

return 0;
}




Measured memory_bytes: 2100
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

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

  vector<string> list;
  int n = s.size();
  rep(i, n){
    string t;
    for (int j = 0; j < k && i+j < n; j++) {
      t += s[i+j];
      list.pb(t);
    }

  }
  sort(all(list));
  list.erase(unique(all(list)), list.end());

  std::cout << list[k-1] << '\n';
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pub(a) push_back(a)
#define mp(a,b) make_pair(a,b)
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for (auto &e: x) cin >> e;

    ll ans = 1e9;
    for (int i = 0; i+k-1 < n; ++i) {
        ll c = min(abs(x[i]), abs(x[i+k-1]));
        c += x[i+k-1] - x[i];
        ans = min(c, ans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
/**
 *    author:  tourist
 *    created: 20.06.2020 15:39:32       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  cout << 360 / __gcd(360, x) << '\n';
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#define ll long long
using namespace std;

int main() {
	char s[10];
	char t[10];
	int ans = 0;

	cin >> s;
	cin >> t;

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

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n;

    for(int i=0;i<2*n;i++)
        cin>>A[i];

    sort(A,A+n*2);

    for(int i=0;i<n;i++)
        sum+=A[i*2];

    cout<<sum;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stack>
#include<string>

using namespace std;


int main()
{
	string S, T;
	cin >> S >> T;

	int num=0;
	int min = 1000;
	for (int i = 0; i <= S.size() - T.size(); i++)
	{

		for (int j = 0; j < T.size(); j++)
		{
			//cout << S[i + j] << "  " << T[j] << endl;

			if (S[i+j] == T[j])
			{

			}
			else
			{
				num++;
				//cout << "num: " << num << endl;
			}
		}

		if (min > num)
		{
			min = num;
		}
		num = 0;
	}

	//cout << num << endl;
	cout << min;


}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

#define N 200001
vector<int> G[N],rG[N],g;
bool u[N];
int n,cmp[N];
  
void add_edge(int x,int y){G[x].push_back(y);rG[y].push_back(x);}
void dfs(int x){u[x]=1;rep(i,G[x].size())if(!u[G[x][i]])dfs(G[x][i]);g.push_back(x);} 
void rdfs(int x,int k){u[x]=1;cmp[x]=k;rep(i,rG[x].size())if(!u[rG[x][i]])rdfs(rG[x][i],k);}
int scc() {
  mem(u);g.clear();rep(i,n)if(!u[i])dfs(i);mem(u);
  int k=0;rrep(i,g.size())if(!u[g[i]])rdfs(g[i],k++);return k;
}

vector<int> v[1111];

void Main() {
  ll m;
  cin >> n >> m;
  rep(i,m) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    add_edge(x,y);
  }
  scc();
  rep(i,n) v[cmp[i]].pb(i);
  rep(i,n) {
    queue<int> que;
    que.push(i);
    ll d[n],p[n];
    fill(d,d+n,MAX);
    memset(p,-1,sizeof(p));
    while(!que.empty()) {
      ll x=que.front();que.pop();
      rep(j,G[x].size()) {
        ll y=G[x][j];
        if(cmp[x]!=cmp[y]) continue;
        if(d[y]==MAX) {
          d[y]=x==i?1:d[x]+1;
          p[y]=x;
          que.push(y);
        }
      }
    }
    g.clear();
    ll x=i;
    if(d[x]==MAX) continue;
    while(1) {
      g.pb(x);
      if(d[x]==1) break;
      x=p[x];
    }
    set<ll> s;
    rep(i,g.size()) s.in(g[i]);
    rep(i,g.size()) {
      ll c=0;
      rep(j,G[g[i]].size()) c+=s.count(G[g[i]][j]);
      if(c!=1) goto next;
    }
    pr(g.size());
    rep(i,g.size()) pr(g[i]+1);
    return;
  next:;
  }
  pr(-1);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 9984
import java.util.*;
import java.io.*;

public class Main{

	public static void main(String[] args) throws IOException {
		int N = readInt(), X = readInt(), min = Integer.MAX_VALUE; for(int i = 1; i<=N; i++) {
			int k = readInt(); X-=k; min = Math.min(k, min);
		}
		println(N + X/min);
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	public void close() throws IOException {
		if (din == null)
			return;
		din.close();
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


Measured memory_bytes: 21076
// atcoder/abc171/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n;
  while (cin >> n) {
    vec<lli> a(n);
    cin >> a;

    map<int, lli> cnt;
    each (i, a) ++cnt[i];

    lli sum = 0;
    each (i, a) sum += i;

    int q;
    cin >> q;
    while (q--) {
      int src, dst;
      cin >> src >> dst;
      sum -= cnt[src] * src;
      sum += cnt[src] * dst;
      cnt[dst] += cnt[src];
      cnt[src] = 0;
      cout << sum << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 10108
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, D = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    for i in range(N):
        for j in range(i+1,N):
            si=S[i]
            sj=S[j]
            dis=0
            for k in range(D):
                dis+=(si[k]-sj[k])**2
            if round(dis**0.5)**2==dis:
                ans+=1
    print(ans)





if __name__ == "__main__":
    main()

Measured memory_bytes: 77508
#include <iostream>

using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int diff = (A + B) - (C + D);
    if (diff > 0) {
        cout << "Left" << endl;
    } else if (diff < 0) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  vector<ll> a(5);
  REP(i, 5) { cin >> a[i]; }

  REP(i, 5) {
    if (a[i] == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
}

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

int main() {
  string str;
  int cnt = 0;
  bool chkOne = false;
  int index = 0;
  
  cin >> str;
  int num = str.size();

  while(index < num){
    if(index == num - 2 && str.at(index) == str.at(index + 1)){
      cnt++;
      break;
    }
    
    if(chkOne && str.at(index) == str.at(index - 1)){
      cnt++;
      index += 2;
      chkOne = false;
    }else{
      cnt++;
      index++;
      chkOne = true;
    }
  }
  
  cout << cnt;
}


Measured memory_bytes: 3768
#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 H, W;
	while (true) {
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		REP(i, H) {
			REP(j, W) {
				if (i % 2 == 0) {
					if (j % 2 == 0) cout << "#";
					else cout << ".";
				} else {
					if (j % 2 != 0) cout << "#";
					else cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}

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



Measured memory_bytes: 3136
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int f(int r,int t,int r2){
	if(r<10){
		return t;
	}else if(t>r2){
		return -1;
		}else{
		priority_queue<int> a;
		int keta=10;
		while(r>keta){
			int b=r/keta,c=r%keta;
			a.push(b*c);
			keta*=10;
		}
		return f(a.top(),t+1,r2);
	}
}
int main(void){
int n;
cin>>n;
for(int k=0;k<n;k++){
int r;
cin>>r;

cout<<f(r,0,r)<<endl;
}

	return 0;
}

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    A--;
    B--;
    C--;
    D--;

    string s; cin >> s;
    ll L = s.size();
    
    // easy
    if(C<D){
        FOR(i, B+1, D){
            if(i+1<L && s[i]=='#' && s[i+1]=='#'){
                p_no();
                return 0;
            }
        }
        FOR(i, A+1, C){
            if(i+1<L && s[i]=='#' && s[i+1]=='#'){
                p_no();
                return 0;
            }
        }
        p_yes();
        return 0;
    }
    else{
        // ふぬけ
        FOR(i, B+1, D){
            if(i+1<L && s[i]=='#' && s[i+1]=='#'){
                p_no();
                return 0;
            }
        }

        // 3スペースがあれば
        bool can_oinuki = false;
        FOR(i, B, D+1){
            if(i-1>=0 && i+1<L && s[i-1]=='.' && s[i]=='.' && s[i+1]=='.'){
                can_oinuki = true;
            }
        }

        // 3スペースはない

        // すぬけ
        if(!can_oinuki){
            // p("おいぬけない");
            p_no();
            return 0;
        }

        // すぬけ
        FOR(i, A+1, C){
            if(i+1<L && s[i]=='#' && s[i+1]=='#'){
                p_no();
                return 0;
            }
        }
        p_yes();
    }
    
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>

using namespace std;
int N;
int t, x, y;
int bt, bx, by;

int main() {
  cin >> N;
  bt = 0;
  bx = 0;
  by = 0;

  for (int i=0; i<N; i++) {
    cin >> t >> x >> y;
    int time = t - bt;
    int dist = abs(x-bx) + abs(y-by);
    if (time < dist || time%2 != dist%2) {
      cout << "No" << endl;
      return 0;
    }
    bt = t;
    bx = x;
    by = y;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
s = list(input())
c = 0
ans = 0
if len(s) == 1 and s[0] == "h":
    print("No")
elif s[-1] != "i":
    print("No")
else:
    for i in range(len(s)):
        if s[i] == "h" and c == 0:
            c = 1
            ans += 1
        elif s[i] == "i" and c == 1:
            c = 0
            ans += 1

    if ans == len(s):
        print("Yes")
    else:
        print("No")


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

bool dp[100010]; // 先手が勝てるかどうか

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

    dp[0] = false; // 0個の時は負け
    for (int i = 1; i <= K; i++) {
        rep(j, N) {
            if (i - a[j] >= 0) dp[i] |= !dp[i - a[j]];
        }
    }

    cout << (dp[K] ? "First" : "Second") << endl;
}

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a<=b&&a<=c){
        if(b<=c) cout << a << " " << b << " " << c << endl;
        else cout << a << " " << c << " " << b << endl;
    }
    else if(b<=a&&b<=c){
        if(a<=c) cout << b << " " << a << " " << c << endl;
        else cout << b << " " << c << " " << a << endl;
    }
    else{
        if(a<=b) cout << c << " " << a << " " << b << endl;
        else cout << c << " " << b << " " << a << endl;
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
 
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
 
void solve(){
 
 
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();

    int n;cin>>n;
    ll s=0;
    repA(i,1,n)if(i%3!=0&&i%5!=0)s+=i;
    cout<<s;
	return 0;
}
 



Measured memory_bytes: 3652
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const ll P = 998244353;
int N, K;
ll fact[5000];

ll ext_gcd(ll a, ll b, ll &x, ll &y){
	if(b == 0){
		x = 1;
		y = 0;
		return a;
	}
	ll nx, ny;
	ll g = ext_gcd(b, a%b, nx, ny);
	x = ny;
	y = nx - a/b *ny;
	return g;
}

ll inv_mod(ll x, ll p){
	ll y,z;
	ext_gcd(x, p, y, z);
	return y>=0 ? y : p+(y%p);
}

ll fact_mod(ll n, ll p, ll &e){
	// n! = a * p^e
	// return = a % p
	if(n == 0){
		e = 0;
		return 1;
	}

	ll na = fact_mod(n/p, p, e);

	e += n/p;
	ll a = na * fact[n%p] % p;

	if((n/p)%2) a = a * (p-1)%p;
	return a;
}

ll comb_mod(ll n, ll m, ll p){
	ll e1,e2,e3;
	ll a1 = fact_mod(n, p, e1);
	ll a2 = fact_mod(m, p, e2);
	ll a3 = fact_mod(n-m, p, e3);

	if(e1 > e2+e3) return 0;
	else return a1*inv_mod(a2*a3%p, p)%p;
}

int main(){
	fact[0] = fact[1] = 1;
	for(int i=2; i<5000; i++) fact[i] = fact[i-1]*i%P;
	cin >> K >> N;

	vector<ll> vec(2*(N+1));
	for(int i=0; i<=N; i++){
		vec[i] = comb_mod(N+K-1-i, N-i, P);
		//cout << i << " " << vec[i] << endl;
	}
	for(int i=2; i<=2*K; i++){
		int l = (i/2)-max(0, i-1-K);
		ll ans = vec[0];
		int sign = 1;
		for(int j=0; j<l; j++){
			ll t = (vec[2*(j+1)]*comb_mod(l, j+1, P))%P;
			//cout << i << " " << j << " " << l << " " << t << endl;
			ans -= sign*t;
			sign *= -1;
			ans += P;
			ans %= P;
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 384
import itertools

n, m = [int(i) for i in input().split()]
s = []
for i in range(m):
    _, *s_ = [int(i) for i in input().split()]
    s.append(s_)
p = [int(i) for i in input().split()]

answer = 0
for i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10 in itertools.product(range(2), range(2), range(2),range(2), range(2), range(2),range(2), range(2),range(2), range(2), range(2)):
    #i_list = [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10]
    i_list = [i10, i9, i8, i7, i6, i5, i4, i3, i2, i1, i0]
    #print(i_list)
    if i_list[n] == 1:
        break

    電気点灯 = 0
    for j in range(m):
        オンになっているスイッチの個数 = 0
        for k in range(len(s[j])):
            if i_list[s[j][k]-1] == 1:
                オンになっているスイッチの個数 += 1
        if オンになっているスイッチの個数 % 2 == p[j]:
            電気点灯 += 1

    if 電気点灯 == m:
        answer += 1

print(answer)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
	int i,j,v,A[20000],k,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}

	for(i=0;i<n;i++){
		v=A[i];
		j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			j--;
			A[j+1]=v;
		}
		for(k=0;k<n-1;k++){
			printf("%d ",A[k]);
		}
		printf("%d",A[n-1]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 608
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();
		int xl = 0;
		int xr = w;
		int yu = h;
		int yd = 0;
		for(int i = 0; i < n; i++){
		    int x = sc.nextInt();
		    int y = sc.nextInt();
		    int a = sc.nextInt();
		    if(a == 1){
		        xl = max(xl, x);
		    }else if(a == 2){
		        xr = min(xr, x);
		    }else if(a == 3){
		        yd = max(yd, y);
		    }else if(a == 4){
		        yu = min(yu, y);
		    }
		}
		// 計算
		int result = 0;
		result = max(0, xr-xl)*max(0, yu-yd);
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 22228
# D - All Your Paths are Different Lengths

L = int(input())
r = 0
while pow(2, r+1) <= L:
    r += 1

N = r + 1 

edge = []
for i in range(N-1): 
    edge.append((i+1, i+2, 0))
    edge.append((i+1, i+2, pow(2, i)))

M = r * 2
remain = L - pow(2, r)

for i in range(N-1)[::-1]:
    if remain < pow(2, i):
        continue
    else:
        edge.append((i+1, N, L-remain))
        M += 1
        remain -= pow(2, i)

print(N, M)
for e in edge:
    print(' '.join(map(str, e)))

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    int a[n+1];
    int b[n+1];
    memset(b, 0, sizeof b);
    vector<int> ans;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=n;i>0;i--){
        /*
        if(i * 2 <= n){
            if(a[i * 2] == 0){
                if(a[i] == 1){
                    ans.push_back(i);
                }
            }else{
                if(a[i] == 0){
                    ans.push_back(i);
                }
            }
        }else{
            if(a[i] == 1){
                ans.push_back(i);
            }
        }
        */
        int sum = 0; 
        int j = 2;
        while(i * j <= n){
            sum += b[i * j];
            j++;
        }
        bool even = ((sum % 2) == 0);
        if(even){
            if(a[i] == 1){
                ans.push_back(i);
                b[i] = 1;
            }
        }else{
            if(a[i] == 0){
                ans.push_back(i);
                b[i] = 1;
            }
        }
    }
    int len = ans.size();
    cout << len << endl;
    for(int a: ans){
        cout << a << " ";
    }
    if(len > 0) cout << endl;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k,a[502],s,p,need;
ll cmp(ll a,ll b){return a%p<b%p;}
signed main()
{
	cin>>n>>k;
	for(ll i=1;i<=n;i++)
		cin>>a[i],s+=a[i];
	for(ll i=1;i<=sqrt(s);i++)
		if(s%i==0){
			p=s/i,need=0;
			sort(a+1,a+n+1,cmp);
			ll tmp[502];
			for(ll j=1;j<=n;j++)
				tmp[j]=a[j];
			ll l=1,r=n;
			while(l<r){
				ll down=tmp[l]%p,up=p-tmp[r]%p;
				ll ss=min(down,up);
				need+=ss,tmp[l]-=ss,tmp[r]+=ss;
				if(tmp[l]%p==0)l++;
				if(tmp[r]%p==0)r--;
			}
			if(need<=k)cout<<p,exit(0);
		}
	for(ll i=sqrt(s);i>0;i--)
		if(s%i==0){
			p=i,need=0;
			sort(a+1,a+n+1,cmp);
			ll tmp[502];
			for(ll j=1;j<=n;j++)
				tmp[j]=a[j];
			ll l=1,r=n;
			while(l<r){
				ll down=tmp[l]%p,up=p-tmp[r]%p;
				ll ss=min(down,up);
				need+=ss,tmp[l]-=ss,tmp[r]+=ss;
				if(tmp[l]%p==0)l++;
				if(tmp[r]%p==0)r--;
			}
			if(need<=k)cout<<p,exit(0);
		}
	return 0;
}

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

P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort()
Q.sort()
P.reverse()
Q.reverse()

P = P[:X]
Q = Q[:Y]

eatable_apple = P+Q+R
eatable_apple.sort()
eatable_apple.reverse()

print(sum(eatable_apple[:X+Y]))

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

using namespace std;

int n,m,tal = 1,ans;
int edges[10][10], vis[10];

void dfs(int src){
	if(tal==n){
		tal--;
		ans++;
		return;
	}
	vis[src] = 1;
	for(int i=1;i<=n;i++){
		if(vis[i]==0 && edges[src][i]){
			vis[i] = 1;
			tal++;
			dfs(i);
			vis[i] = 0; //back-track
		}
	}
	tal--;
	vis[src] = 0; //back-track
}

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    int a,b;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		edges[a][b] = 1;
		edges[b][a] = 1;
	}
	dfs(1);
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  V a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int x[100010] = {};
  for (int i = 0; i < n; i++) {
    if (a[i] != 0) x[a[i]-1]++;
    x[a[i]]++;
    x[a[i]+1]++;
  }
  int ma = -1;
  for (int i = 0; i < 100000; i++) ma = max(ma, x[i]);
  dump(ma);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n,k;
    cin >> n >> k;
    vector <ll> arr(n);
    for (int z=0;z<n;z++){
        cin >> arr[z];
        arr[z]--;
    }
    vector <ll> lol;
    vector <ll> lol1;
    vector <ll> visited(n,false);
    ll u = 0;
    ll start = 0;
    while (true){
        if (visited[u]) {
            start = u;
            break;
        }
        k--;
        lol.push_back(u);
        visited[u] = true;
        u = arr[u];
        if (k == 0){
            cout << u+1 << endl;
            return 0;
        }
    }
    bool ok = false;
    for (int z=0;z<lol.size();z++){
        if (lol[z] == start) ok = true;
        if (ok){
            lol1.push_back(lol[z]);
        }
    }
    cout << lol1[(k)%ll(lol1.size())]+1 << endl;
} 

Measured memory_bytes: 9428
{-# LANGUAGE TupleSections #-}

import qualified Data.ByteString.Char8 as B
import           Data.Maybe (fromJust)
import qualified Data.Map.Strict as M
import           Control.Monad (replicateM)

modT :: Integer
modT = 1000000007

main :: IO ()
main = do
  n <- getInt
  m <- M.fromListWith (+) . fmap ((, 1) . convert) <$> replicateM n getInts
  print . solve $ m

convert :: [Int] -> (Int, Int)
convert [a, b]
  | a == 0 && b == 0 = (0, 0)
  | a == 0 = (0, 1)
  | b == 0 = (1, 0)
  | otherwise = let gcd' = gcd a b
                in if b < 0
                   then (-div a gcd', -div b gcd')
                   else (div a gcd', div b gcd')

solve :: M.Map (Int, Int) Int -> Integer
solve map = let zero = M.findWithDefault 0 (0, 0) map
                ans = solve' . M.delete (0, 0) $ map
            in (fromIntegral zero + ans - 1) `mod` modT

solve' :: M.Map (Int, Int) Int -> Integer
solve' map = go 1 map
  where
    go :: Integer -> M.Map (Int, Int) Int -> Integer
    go acc map = if M.null map
                 then acc
                 else whenNotNull acc map

    whenNotNull :: Integer -> M.Map (Int, Int) Int -> Integer
    whenNotNull acc map =
      let ((a, b), count) = M.elemAt 0 map
          inv = if a > 0
                then (-b, a)
                else (b, -a)
          count' = M.findWithDefault 0 inv map
          ccount = ((2 ^ count `mod` modT) + (2 ^ count' `mod` modT) - 1)
            `mod` modT
          nacc = (ccount * acc) `mod` modT
      in nacc `seq` go nacc . M.delete (a, b) . M.delete inv $ map

getInt = fst . fromJust . B.readInt <$> B.getLine

getInts = fmap (fst . fromJust . B.readInt) . B.words <$> B.getLine


Measured memory_bytes: 94932