akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	private static class Stack {

		private int [] data;
		private int top;

		// ????????????Stack stack = new Stack(?????????????????????);???
		public Stack(int stackSize) {
			this.data = new int[stackSize];
			this.top = 0;
		}

		// ?????????????????????????????????????????????
		// ????????????
		// stack.push(?????????);
		public void push(int pushData) {
			this.data[this.top] = pushData;
			this.top++;
		}

		// ??????????????????????????????????????????????????????
		// ????????????
		// int data = stack.pop();
		public int pop() {
			this.top--;
			int popData = this.data[this.top];

			return popData;
		}
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] formula = br.readLine().split(" ");

		Stack stack = new Stack(100);

		for(int i = 0; i < formula.length; i++) {
			if(!formula[i].equals("+") && !formula[i].equals("-") && !formula[i].equals("*")) {
				stack.push(Integer.parseInt(formula[i]));
			} else {
				if(formula[i].equals("+")) {
					int popNum1 = stack.pop();
					int popNum2 = stack.pop();

					int formulaResult = popNum2 + popNum1;

					stack.push(formulaResult);
				} else if(formula[i].equals("-")) {
					int popNum1 = stack.pop();
					int popNum2 = stack.pop();

					int formulaResult = popNum2 - popNum1;

					stack.push(formulaResult);
				} else if(formula[i].equals("*")) {
					int popNum1 = stack.pop();
					int popNum2 = stack.pop();

					int formulaResult = popNum2 * popNum1;

					stack.push(formulaResult);
				}
			}
		}
		System.out.println(stack.pop());
	}
}

Measured memory_bytes: 24472
<?php
$s = strrev(trim(fgets(STDIN)));
$divide = ['dream', 'dreamer', 'erase', 'eraser'];
foreach ($divide as $k => $v) {
    $divide[$k] = strrev($v);
}
$can = true;
for ($i = 0; $i < strlen($s);) {
    $can2 = false;
    foreach ($divide as $v) {
        if (strpos($s, $v, $i) === $i) {
            $can2 = true;
            $i += strlen($v);
        }
    }
    if (! $can2) {
        $can = false;
        break;
    }
}
echo $can ? 'YES' : 'NO';
?>

Measured memory_bytes: 16392
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 13:40:00 2020

@author: NEC-PCuser
"""
def fibonatch(a, N):
    #d[i][j]: iからjへの最短距離
    n1, n2 = 1, 1
    if N == 0:
        return 1
    elif N == 1:
        return 1
    else:
        for i in range(N - 1):
            if a[i] == 1:
                n1 = 0
            if a[i + 1] == 1:
                n2 = 0
            n1, n2 = n1 + n2, n1
        return (n1) % 1000000007



if __name__ == "__main__":
    N, M = map(int, input().split())
    a = [0] * N
    for i in range(M):
        a[int(input()) - 1] = 1
    
    print(fibonatch(a, N))


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

int main(){
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  for(int i = 0; i < N; ++i){
    cin >> P[i];
  }
  for(int i = 0; i < N; ++i){
    cin >> Q[i];
  }
  vector<int> I(N);
  iota(I.begin(), I.end(), 1);
  int a = -1, b = -1, t = 1;
  do{
    if(I == P) a = t;
    if(I == Q) b = t;
    ++t;
  }while(next_permutation(I.begin(), I.end()));
  cout << abs(a-b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	long long n,i,ans,sum=0;
	cin>>n;
	for(i=sqrt(n);i>0;i--)
		if(n%i==0)
		{
			ans=n/i;
			break;
		}
	while(ans)
	{
		sum++;
		ans/=10;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 305
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	int A, P;
	scanf("%d %d", &A, &P);
	P += A * 3;
	printf("%d\n", P >> 1);
	return 0;
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

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

const int INF = 100000000;
const ll LINF = 1e18+5;

int main() {
    ll X;
    cin >> X;
    bool dameflag = false;
    while(1) {
        dameflag = false;
        REP(i, 2, (ll)sqrt(X)+1) {
            if(X%i==0) {
                dameflag = true;
                break;
            }
        }
        if(!dameflag) {
            cout << X << endl;
            return 0;
        }
        X++;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 10000005;
ll bs[MX], res;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	for (int i = 1; i < MX; i++)
		for (int j = i; j < MX; j += i)
			bs[j]++;

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++)
		res += i * bs[i];

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 81748
K = int(input())
L = [False]*K
X = 7
ans = 0
R = 0
while not L[0]:
    ans += 1
    X %= K
    R = (R+X)%K
    X *= 10
    if L[R]:
        ans = -1
        break
    L[R] = True
    

print(ans)


Measured memory_bytes: 16580
numbers = [0]*2019
numbers[0] = 1
s = input()
t = 0
mod = 2019
u = 1
for i in range(1, len(s) + 1):
    t = (t + int(s[-i]) * u )% mod
    numbers[t] += 1
    u = 10*u%mod
ans = 0
for n in numbers:
    ans += n*(n-1)/2
print(int(ans))


Measured memory_bytes: 9220
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+10;
int n,m,cnt,root=1,rt=1,ans,fa[N],head[N],a[N],f[N];
struct edge{ int to,from; }e[N*2];
void insert(int x,int y)
{
	e[++cnt].to=y,e[cnt].from=head[x],head[x]=cnt;
	e[++cnt].to=x,e[cnt].from=head[y],head[y]=cnt;
}
int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]); }
void dfs(int x,int y){ a[x]=y; for (int i=head[x];i;i=e[i].from) if (e[i].to!=fa[x]) fa[e[i].to]=x,dfs(e[i].to,-y),a[x]+=a[e[i].to]; }
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=1,x,y;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		if (find(x)!=find(y)) fa[fa[x]]=fa[y]; else{ root=x,rt=y; continue; }
		insert(x,y);
	}
	fa[root]=cnt=0,dfs(root,1);
	if (n==m)
	{
		for (int i=rt;i;i=fa[i]) f[++cnt]=a[i];
		if (cnt&1)
		{
			if (a[root]&1){ printf("-1"); return 0; }
			for (int i=rt;i;i=fa[i]) a[i]-=a[root]/2;
		}
		else 
		{
			if (a[root]){ printf("-1"); return 0; }
			sort(f+1,f+cnt+1);
			for (int i=rt;i;i=fa[i]) a[i]-=f[cnt/2];
		}
	}
	else if (a[root]){ printf("-1"); return 0; }
	for (int i=1;i<=n;i++) ans+=abs(a[i]); printf("%d",ans);
}

Measured memory_bytes: 8064
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)

    divisors.sort()
    return divisors

n = int(input())
a = (max(make_divisors(n)))
b = n//a
print(a+b-2)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MAX = 390624; //44444444(5)
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    int m;
    cin >> m;
    vector<vector<int>> R(n, vector<int>(n, 0));
    for (int i = 0; i < m; i++){
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      if (x < y){
        R[x][y] = 1;
      } else {
        R[y][x] = -1;
      }
    }
    vector<long long> C(n);
    C[0] = 1;
    for (int i = 1; i < n - 1; i++){
      C[i] = C[i - 1] * 5;
    }
    C[n - 1] = 0;
    vector<long long> dp(MAX + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < n; i++){
      for (int j = i + 1; j < n; j++){
        vector<long long> dp2(MAX + 1, 0);
        for (int k = 0; k <= MAX; k++){
          if (R[i][j] >= 0 && k + C[i] <= MAX){
            dp2[k + C[i]] += dp[k];
          }
          if (R[i][j] <= 0 && k + C[j] <= MAX){
            dp2[k + C[j]] += dp[k];
          }
        }
        swap(dp, dp2);
      }
    }
    long long p = 0;
    for (int i = 0; i < n - 1; i++){
      p += C[i] * ((n - 1) / 2);
    }
    cout << dp[p] << endl;
  }
}


Measured memory_bytes: 8892
#include<bits/stdc++.h>
using namespace std;
// V:k<=447, E:n<=10^5
int main(){
  int N,k,n;
  cin>>N;
  for(k=2;k<=447;++k){
    if((k*(k-1))/2==N)break;
  }
  if((k*(k-1))/2!=N){
    cout<<"No";
    return 0;
  }
  vector<vector<int>> v(k);
  vector<bool> l(N,false);
  cout<<"Yes"<<endl<<k<<endl;
  n=1;
  while(n<=N){
    for(int i=0;i<k-1;++i){
      for(int j=i+1;j<k;j++){
        v[i].push_back(n);
        v[j].push_back(n);
        
        n++;
      }
    }
  }
  for(int i=0;i<k;i++){
    cout<<k-1;
    for(int j=0;j<k-1;j++){
      cout<<" "<<v[i][j];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 2304
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int[][] roads = new int[3][2];
        for (int i=0; i<3; i++) {
            for (int j=0; j<2; j++) {
                roads[i][j] = scan.nextInt();
            }
        }
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(roads[0][0]);
        list.add(roads[0][1]);
        int rest = 0;
        outer:
        for (int i=1; i<3; i++) {
            for (int j=0; j<2; j++) {
                if (roads[i][j] == list.get(0)) {
                    if (j==0)
                        list.add(0, roads[i][1]);
                    else
                        list.add(0, roads[i][0]);
                    if (i==1) 
                        rest = 2;
                    else
                        rest = 1;
                    break outer;
                }
                if (roads[i][j] == list.get(1)) {
                    if (j==0)
                        list.add(roads[i][1]);
                    else
                        list.add(roads[i][0]);
                    if (i==1) 
                        rest = 2;
                    else
                        rest = 1;
                    break outer;
                }
            }
        }
        if (roads[rest][0]==list.get(0) || roads[rest][0]==list.get(2) || roads[rest][1]==list.get(0) || roads[rest][1]==list.get(2))
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		String result;
		result = (N==M) ? "Yes" : "No";
		System.out.println(result);
	}
}


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

using namespace std;

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));

#define debug(x) std::cout << #x << ": " << x << endl
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

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

//mt19937 mrand(random_device{}());
//const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

//------------------------------------------------------------------------//
int T;
const int maxn = 2e4+5;
int n;
typedef pair<pii, ll> Block;

#define w X.X
#define s X.Y
#define v Y

void solve()
{
   cin >> n;
   vector<Block> bs(n);
   int maxspw = 0;
   for(auto &bi:bs) cin >> bi.w >> bi.s >> bi.v, maxspw = max(maxspw, bi.s+bi.w);
   std::function<bool(pair<pii, ll>&, pair<pii, ll>&)> cmp = [&](pair<pii, ll>& a, pair<pii, ll>& b)
   {
     return a.s - b.w < b.s - a.w;
   };
   sort(all(bs), cmp);

   vector<ll> dp(maxspw+1, 0ll);
   ll ans = 0ll;
   //i : from if choose x must choose y, judge from y to x
   //j : from big update to small update that no current i updated will be used this round
   rep(i, 0, n)
   repinv(si, bs[i].w, bs[i].s+bs[i].w+1) //cur all weight
   {
     //si = for nxt to carry
     dp[si] = max(dp[si], dp[si-bs[i].w]+bs[i].v); //last carried = si-bs[i].w
     //cout << si << ' '; debug(dp[si]);
     ans = max(ans, dp[si]);
   }
   cout << ans << endl;
   return;
}


signed main()
{
  fastIO();
  //cin >> T;
  T = 1;
  while(T--) solve();
  return 0;
}


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

int main(){
   int a,b; cin >> a >> b;
   int s=min(a,b); int B=max(a,b);
   int ans=0;
   rep(i,B) ans+=s*pow(10,i);
   cout << ans << endl;
return 0;
}


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

int sort(int *a, int *b, int *c)
{
    int maxi = max({*a, *b, *c}), mini = min({*a, *b, *c});
    int midi = *a + *b + *c - maxi - mini;
    *a = mini; *b = midi; *c = maxi;
    if(*a == *c) return 0;
    else if(*a == *b) return 1;
    else if(*b == *c) return 2;
    else return -1;
}

int main()
{
    int a, b, c, ans = 0;
    cin >> a >> b >> c;
    sort(&a, &b, &c);
    ans += ((c-a) / 2) + ((c-b) / 2);
    if((c-a) % 2 == 0) a = c;
    else a = c - 1;
    if((c-b) % 2 == 0) b = c;
    else b = c - 1;
    cout << ans + sort(&a, &b, &c) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
//memset(ar,-1,sizeof(ar));
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
#define MAX 1000005
#define mod 1000000007



int main()
{
 //O_O ;
   ll a,b,c,k;
   cin>>a>>b>>c>>k;
   if(k>a){
 ll ans=a;
  k=k-a;
k-=b;
 if(k>-1)
 {

     cout<<ans-k<<nn;
 }
 else{
    cout<<ans<<nn;
 }
   }
   else
    cout<<k<<nn;

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    if(N == 0){
        cout << N << endl;
        return 0;
    }
    string s;
    while(N != 1){
        if(N > 0){
            if(N % -2 == 0){
                s += '0';
                N /= -2;
            }
            else{
                s += '1';
                N = (N - 1) / -2;
            }
        }
        else{
            if(N % -2 == 0){
                s += '0';
                N /= -2;
            }
            else{
                s+= '1';
                N = N / -2 + 1;
            }
        }
    }
    s += '1';
    reverse(s.begin(), s.end());
    cout << s << endl;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
a_img = N.times.map { gets.chomp }
b_img = M.times.map { gets.chomp }

ret = 0.upto(N - M).any? do |i|
  0.upto(N - M).any? do |j|
    a_img[i, M].map { |s| s[j, M] } == b_img
  end
end

if ret == true
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 2044
#include "bits/stdc++.h"
#include "sstream"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int N=1e5+1;
int main() {
    quick
long long a,b; cin>>a>>b;
cout<<a*b/__gcd(a,b);
}

Measured memory_bytes: 256
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef unsigned long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	ll ans = 0;
	ll curr = 1;
	ll H;
	scll(H);
	while (H) {
		ans += curr;
		H >>= 1LL;
		curr <<= 1LL;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
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;}


int main(){
  ll n ; cin>> n ;
  vector<P> A(n) ;
  rep(i,n){
      cin>> A[i].fi ;
      A[i].se = i ;
  }
  vector<P> B(n) ;
  rep(i,n){
      cin>> B[i].fi ;
      B[i].se= i ;
  }
  sort(A.begin(),A.end()) ;
  sort(B.begin(),B.end()) ;
  bool ok=1 ;
  rep(i,n){
      if(A[i].fi>B[i].fi) ok=0 ;
  }
  bool ko=0 ;
  // swapしたらどれも満たさないことを確認
  rep(i,n-1){
      if(A[i+1].fi<=B[i].fi
       && A[i].fi <=B[i+1].fi) ko=1  ;
  }
  //loop確認
  ll loop=0 ;
  ll st = 0 ;
  vector<ll> C(n) ; rep(i,n)  C[A[i].se]= B[i].se ;
  vector<ll> cnt(n) ;
  // rep(i,n) cout<< C[i]<<endl ;
  rep(i,n-1){
    cnt[st]++ ;
    if(cnt[C[st]]!=0) break ;
    st = C[st] ;
    loop ++ ;
  }
  
  if(loop<n-1) ko=1 ;
  if(ok==1 &&ko==1) cout<< "Yes" <<endl ;
  else cout<< "No"<<endl ;
  
 return 0 ; 
}
// 5 1 10 100 1000 10000 50000 5 50 500 5000


Measured memory_bytes: 7976
N=int(input())
A1=list(map(int, input().split()))
A2=list(map(int, input().split()))

B1=[0]
for i in A1:
    B1.append(i+B1[-1])
B2=[0]
for i in reversed(A2):
    B2.insert(0, i+B2[0])
B2.insert(0,0)
B2.pop(len(B2)-1)
C=[B1[i]+B2[i] for i in range(len(B1))]
print(max(C))


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll v; gi(v);
	ll ans = (v/500)*1000; v %= 500;
	ans += (v/5)*5;
	print(ans);
}


Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    if(a > 0)cout<<"Positive";
    else if(a == 0||(a < 0 && b > 0))cout<<"Zero";
    else if((abs(b)-abs(a))%2 != 0)cout<<"Positive";
    else cout<<"Negative";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 100000000
#define MAX 100001
#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

struct edge{int to, cost;};
vector<edge> G[100000];

signed main(){ INIT;
    VAR(int, x, a, b);
    OUTL((x - a) % b);
RET;}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
const int maxn = 20 + 10;
int A[maxn], B[maxn], C[maxn];
int main(void)
{
	int n; cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> A[i];
	int s = 0;
	for (int i = 1; i <= n; ++i)
		cin >> B[i], s += B[i];
	for (int i = 2; i <= n; ++i)
		cin >> C[i];
	for (int i = 2; i <= n; ++i) {
		if (A[i] == A[i - 1] + 1)
			s += C[A[i]];
	}
	cout << s << endl;
	return 0;
}

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

int main(void)
{
    
    int N;
    cin >> N;
    
    int i,A[N];
    int j[2] = { 1 , 0 };
    int check = -1;
    for(i=0;i<N;i++) cin >> A[i];
    
    sort( A , A + N);
    
    if(N==1) cout << j[0] << endl;
    else{
        i = 0;
        do{
            if( A[i] == A[i+1] ){
                j[0]++;
                i++;
            }
            else{
                j[1] = j[1] + j[0]%2;
                i++;
                j[0] = 1;
                check = 1;
            }
        }while(i<N-1);
        j[1] = j[1] + j[0]%2;
        
        if(check == -1){
            cout << N%2 << endl;
        }
        else{
            cout << j[1] << endl;
        }
    }
}


Measured memory_bytes: 640
#!/usr/bin/perl -w

$n=<>;
@line=split(/ /,<>);
$ava=0;
for($i=0;$i<$n;$i++){
    $ava+=$line[$i];
}
$ava/=$n;
my $thum=0;
for($i=0;$i<$n;$i++){
    if(abs($ava-$line[$thum])>abs($ava-$line[$i])){
        $thum=$i;
    }
}
print $thum;

Measured memory_bytes: 512
#include <iostream>
#define mod 1000000007
using namespace std;
int main() {
	int m,n;
	cin>>m>>n;
	int arr[m][n];
	for(int i=0;i<m;i++)
	{
	    for(int j=0;j<n;j++)
	    {
	        char x;
	        cin>>x;
	        if(x=='#')
	            arr[i][j]=0;
	        else
	            arr[i][j]=1;
	    }  
	}
	 int dp[m][n];
	 for(int i=0;i<m;i++)
	 {
	     for(int j=0;j<n;j++)
	     {
	         
	         if(arr[i][j]==0)
	            dp[i][j]=0;
	         else
	         {
	             if(i==0 && j==0)
	                dp[i][j]=1;
	             else if(i==0 && j>0)
	                dp[i][j]=dp[i][j-1];
	             else if(j==0 && i>0)
	                dp[i][j]=dp[i-1][j];
	             else 
	                dp[i][j]=dp[i-1][j]%mod+dp[i][j-1]%mod;
	         }
	     }
	 }
	 
	 cout<<dp[m-1][n-1]%mod;
	return 0;
}

Measured memory_bytes: 11408
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;

bool judge(int x){
  if(0<x && x<13)return 1;
  else return 0;
}

int main(){
  string s;cin >> s;
  int a = stoi(s.substr(0,2));
  int b = stoi(s.substr(2,2));
  if(judge(a)==1){
    if(judge(b))cout << "AMBIGUOUS";
    else cout << "MMYY";
  }
  else{
    if(judge(b))cout << "YYMM";
    else cout << "NA";
  }
}
    

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

int combination(int n, int r) {
  if ( r * 2 > n ) r = n - r;
  int dividend = 1;
  int divisor  = 1;
  for ( int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

signed main() {
  int N, P;
  cin >> N >> P;
  
  vector<int> A(N);
  int odd = 0;
  int even = 0;
  for( int i = 0; i < N; i++ ){
    cin >> A.at(i);
    if( A.at(i) % 2 == 1 ) odd++;
    else even++;
  }
  
  int ans = 1;
  int oddkumi = 0;
  //偶数のビスケットをどれだけ食べるか
  for( int i = 0; i < even; i++ ){
    ans *= 2;
  }
  if( P == 0 ){
    //奇数のビスケットをどれだけ食べるか(偶数個)
    for( int i = 0; i <= odd; i+=2 ){
      oddkumi += combination(odd, i);
    }
    if( oddkumi > 0 ) cout << oddkumi * ans << endl;
    else cout << ans << endl;
  }else{
    //奇数のビスケットをどれだけ食べるか(奇数個)
    for( int i = 1; i <= odd; i+=2 ){
      oddkumi += combination(odd, i);
    }
    if( oddkumi > 0 ) cout << oddkumi * ans << endl;
    else cout << 0 << endl;
  }
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,len;
int a[200005];
vector<pair<int,int> >now;//(char,len)
bool ok(int x){
	now.clear();len=0;
	for(int i=1;i<=n;i++){
		if(a[i]>len){
			now.push_back(make_pair(1,a[i]-len));
		}else{
			int Char;
			while(len>=a[i]){
				len-=now.back().second;
				Char=now.back().first;
				now.pop_back();
			}
			if(Char<x){
				if(len!=a[i]-1){
					now.push_back(make_pair(Char,a[i]-1-len));
				}
				now.push_back(make_pair(Char+1,1));
			}else{
				while(now.size()&&now.back().first==x)len-=now.back().second,now.pop_back();
				if(!now.size())return false;
				Char=now.back().first;int tmp=now.back().second;
				now.pop_back();
				if(tmp>1)now.push_back(make_pair(Char,tmp-1));
				now.push_back(make_pair(Char+1,1));
				if(len<a[i])now.push_back(make_pair(1,a[i]-len));
			}
		}
		len=a[i];
	}
	return true;
}
int main(){
//	freopen("data.txt","r",stdin);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	int L=0,R=n+5;
	while(R-L>1){
		int mid=(L+R)/2;
		if(ok(mid))R=mid;
		else L=mid;
	}
	cout<<R<<endl;
	return 0;
}

Measured memory_bytes: 3188
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String str = in.next();
            int a = Character.getNumericValue(str.charAt(0));
            int b = Character.getNumericValue(str.charAt(1));
            int c = Character.getNumericValue(str.charAt(2));
            int d = Character.getNumericValue(str.charAt(3));
            String op1, op2, op3;


            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    for (int k = 0; k < 2; k++) {
                        int ans = 0;
                        if (i % 2 == 1) {
                            ans += (a + b);
                            op1 = "+";
                        } else {
                            ans += (a - b);
                            op1 = "-";
                        }

                        if (j % 2 == 1) {
                            ans += c;
                            op2 = "+";
                        } else {
                            ans -= c;
                            op2 = "-";
                        }

                        if (k % 2 == 1) {
                            ans += d;
                            op3 = "+";
                        } else {
                            ans -= d;
                            op3 = "-";
                        }

                        if (ans == 7) {
                            out.print(a + op1 + b + op2 + c + op3 + d + "=7");
                            return;
                        }
                    }
                }
            }


        }

    }
}



Measured memory_bytes: 23380
#include <iostream>

using namespace std;

int main(){

    int a, b, c;
    cin >> a >> b >> c;

    if(a>b) cout << "a > b" << endl;
    else if (a<b) cout << "a < b" << endl;
    else cout << "a == b" << endl; 

    return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<math.h>

using namespace std;

int bubbleSort(int A[], int N){
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++){
    flag = 0;
    for (int j = N-1; j > i; j--){
        if (A[j] < A[j-1]) {
          swap(A[j], A[j-1]);
          flag = 1;
        }
    }
  }
  sw = A[0];
  return sw;
}

void diff(int A[], int minval, int N) {
  for (int i = 0; i < N; i++){
    A[i] -= minval;
  }
}

long double nabe(int A[], int N) {
  long double mean, sum = 0.0;
  double j;
  mean = double(A[0] + A[1])*pow(2.0, double(-N+1));
  sum = mean;
  for (int i = 0; i < N - 2 ; i++){
    j = double(N - 2 - i);
    sum += A[i+2]*pow(2.0, (-j));
    // cout << A[N - 1 - i]*pow(2.0, (-j)) << endl;
  }
  return sum;
}


int main() {
  int sw, A[50], N;
  long double sum;
  cin >> N;
  for (int i = 0; i < N ; i++) cin >> A[i];
  if (N == 2) {
    cout << double(A[0] + A[1])/2.0 << "\n";
  } else {
    sw = bubbleSort(A, N);
    diff(A, sw, N);
    sum = nabe(A, N);
    sum += sw;
    cout << sum << "\n";
  }
  return 0;
}


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

int A, B, C, X, Y;

int main()
{
    scanf("%d%d%d%d%d", &A, &B, &C, &X, &Y);
    int ans = 0;

    // all by self
    ans = X * A + Y * B;

    // 2a + c = 2X
    int c = 2 * X;
    int b = std::max(0, Y - X);
    ans = std::min(ans, b * B + c * C);

    c = 2 * Y;
    int a = std::max(0, X - Y);
    ans = std::min(ans, a * A + c * C);

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
#print(A)
A.sort()
B.sort()
C.sort()
#print(A)
import bisect

ans=0
for i in range(N):
    cnt=bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i]))
    ans+=cnt
print(ans)

Measured memory_bytes: 104280
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=2e5+5,A=26;
vector<int> w[A];
int cnt[A],tak[A];
int t[N];
int get(int i){
    int res=0;
    for(;i>=0;i=(i&(i+1))-1)res+=t[i];
    return res;
}
void add(int i,int x){for(;i<N;i|=i+1)t[i]+=x;}
int get(int l,int r){return get(r)-get(l-1);}//[l..r]
int32_t main(){
    string s;
    cin>>s;
    int n=sz(s);
    forn(i,n)cnt[s[i]-'a']++;
    int co=0;
    forn(i,A)co+=cnt[i]&1;
    if(co>1)cout<<"-1\n";
    else{
        int sl=n/2,sr=n/2;
        if(n&1){
            int cl=count(s.begin(),s.begin()+sl,s[sl]);
            int cr=cnt[s[sl]-'a']-cl;
            if(cl>=cr)sl++;
            else sr++;
        }
        int ans=0;
        string s1,s2,s3,s4;
        forn(i,sl){
            int c=s[i]-'a';
            tak[c]++;
            if(tak[c]*2>cnt[c])s2+=s[i];
            else s1+=s[i],ans+=sz(s2);
        }
        memset(tak,0,sizeof tak);
        forn(i,sr){
            int c=s[n-i-1]-'a';
            tak[c]++;
            if(tak[c]*2>cnt[c])s3+=s[n-i-1];
            else s4+=s[n-i-1],ans+=sz(s3);
        }
        reverse(s3.begin(), s3.end());
        reverse(s2.begin(), s2.end());
        string tl=s1+s3,tr=s4+s2;
        ans+=sz(s2)*sz(s3);
        if(sz(tl)<sz(tr))swap(tl,tr);
        if(sz(tl)>sz(tr)){
            forn(j,A)if(cnt[j]&1)tr+=((char)(j+'a'));
        }
        forn(i,sz(tr))w[tr[i]-'a'].pb(i);
        memset(tak,0,sizeof tak);
        forn(i,sz(tl)){
            int c=tl[i]-'a';
            int val=w[c][tak[c]];
            ans+=get(val,sz(tr));
            add(val,1);
            tak[c]++;
        }
        cout<<ans<<'\n';
    }
    return 0;
}

Measured memory_bytes: 5980
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAX(X,Y) ((X)>(Y)?(X):(Y))

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


Measured memory_bytes: 892
#include<iostream>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;

int main(void) {
	int w, h, n;
	int o, p, q, r;
	int x[101], y[101], a[101];

	cin >> w >> h >> n;
	o = 0;
	p = w;
	q = 0;
	r = h;

	FOR(i, 1, n) {
		cin >> x[i] >> y[i] >> a[i];
	}
	FOR(i, 1, n) {
		if (a[i] == 1) {
			o = max(o, x[i]);
		}
		else if (a[i] == 2) {
			p = min(p, x[i]);
		}
		else if (a[i] == 3) {
			q = max(q, y[i]);
		}
		else {
			r = min(r, y[i]);
		}
	}
	if ((p-o<=0)||(r-q<=0)) {
		cout << 0 << endl;
	}
	else {
		cout << (p - o)*(r - q) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
using ll = long long int;
using namespace std;
double pi = 3.141592653589793238;

#define FOR(i,N) for(int i=0;i<N;i++)
#define pb(x) push_back(x)

int main() {
	int N;
	string s;
	cin >> N >> s;
	int cnt = 0;
	FOR(i, 10) {
		FOR(j, 10) {
			FOR(k, 10) {
				int flag = 0;
				for (int a = 0; a < N; a++) {
					if (flag == 0) {
						if (s[a] == '0' + i)flag++;
					}
					else if (flag == 1) {
						if (s[a] == '0' + j)flag++;
					}else if (flag == 2) {
						if (s[a] == '0' + k)flag++;
					}
				}
				if (flag == 3)cnt++;
			}
		}
	}
	cout << cnt;
}

Measured memory_bytes: 256
n,k,c=map(int,input().split())
s=input()
l=len(s)
cand=[]
for i in range(l):
    if s[i]=='o':
        cand.append(i+1)
cnt1=[0]*(n+c+2)
cnt2=[0]*(n+c+2)        

for i in range(l):
    if s[i]=='o':
        cnt1[i+1]=max(cnt1[i],cnt1[i-c]+1)
    else:
        cnt1[i+1]=cnt1[i]
for i in range(l-1,-1,-1):
    if s[i]=='o':
        cnt2[i+1]=max(cnt2[i+2],cnt2[i+c+2]+1)
    else:
        cnt2[i+1]=cnt2[i+2]
ans=[]
for i in range(len(cand)):##嘘に見える
    tmp=cand[i]
    if cnt1[tmp-1]+cnt2[tmp+1]<k:
        print(tmp)


Measured memory_bytes: 56416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	string s; cin >> s;
	int n = s.size();
	vector<int> ans(n,0);
	int even = 0;
	int odd = 0;
	bool iseven = true;
	rep(i,n){
		if(s[i] == 'R'){
			if(iseven) even++;
			else odd++;
			iseven = !iseven;
		}else{
			if(iseven){
				ans[i] += even;
				ans[i-1] += odd;
			}else{
				ans[i] += odd;
				ans[i-1] += even;
			}
			even = 0;
			odd = 0;
			iseven = true;
		}
	}
	for(int i=n-1; i>=0; i--){
		if(s[i] == 'L'){
			if(iseven) even++;
			else odd++;
			iseven = !iseven;
		}else{
			if(iseven){
				ans[i] += even;
				ans[i+1] += odd;
			}else{
				ans[i] += odd;
				ans[i+1] += even;
			}
			even = 0;
			odd = 0;
			iseven = true;
		}
	}
	rep(i,n) cout << ans[i] << ' ';
}



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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

vvi g;
int n;
vi par,vis; 
vii r,b;

int augment(int v)
{
    if(vis[v])
        return 0;
    vis[v] = 1;
    for(int u : g[v])
        if(par[u] == -1 || augment(par[u]))
        {
            par[u] = v;
            return 1;
        }
    return 0;
}

int mcbm(int left) 
{
    int ans = 0;
    par = vi(2*n, -1);
    for(int i = 0; i < left; i++)
    {
        vis = vi(left, 0);
        ans += augment(i);
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    while(cin >> n)
    {
        r = vii(n);
        for(int i = 0; i < n; i++)
            cin >> r[i].first >> r[i].second;
        b = vii(n);
        for(int i = 0; i < n; i++)
            cin >> b[i].first >> b[i].second;
        g = vvi(2*n);
        for(int i = 0; i < (int)r.size(); i++)
            for(int j = 0; j < (int)b.size(); j++)
                if(r[i].first < b[j].first && r[i].second < b[j].second)
                    g[i].push_back(j+n);
        cout << mcbm(n) << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
cnt=c
ans=0
for i in range(n):
  a=list(map(int,input().split()))
  for j in range(m):
    cnt+=b[j]*a[j]
  if cnt>0:
    ans+=1
  cnt=c
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define dump(x) cout << #x << " = " << (x) << endl

int main() {
  string S;
  cin >> S;
  int n = S.length();
  bool good = true;
  rep(i, n) {
    if (i % 2 == 0 & S[i] == 'L') {
      good = false;
      break;
    } else if (i % 2 == 1 & S[i] == 'R') {
      good = false;
      break;
    } else {
      continue;
    }
  }
  if (good) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pot ( int a, int b ){
	if ( b == 0 ) return 1;
	int c = pot ( a, b/2);
	c *= c;
	if ( b % 2 ) c *= a;
	return c;
}
int main(){
	int n;
	scanf("%d", &n);
	int ans = 0;
	
	//znajdźmy pierwszą parzystą liczbę
	
	int np = 1;
	for(int i = 0; i < n; i ++ ){
		int a;
		scanf("%d", &a);
		
		//to ma być pierwsza parzysta
		int p; //ile parzystych tu może być
		if ( a % 2 ) p = 2;
		else p = 1;
		
		int v = np * p * ( pot ( 3, (n - i - 1) ) );
		//printf("v %d\n", v);
		ans += v;
		
		if ( a % 2 == 0 ) np *= 2; //do teraz ciągle nieparzyste
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    int n;
    cin >> n;
    string s;
    cin >> s;
    char before = '0';
    int cnt = 0;
    for (auto c : s) {
        if (c == before) continue;
        cnt++;
        before = c;
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

int main()
{
    long long int n,m,c,b[100],i,j,z,s,count=0;
    cin>>n>>m>>c;
    for(i=0;i<m;++i){

        cin>>b[i];

    }
    for (i=1;i<=n;++i){

        s=0;
        for (j=0;j<m;++j){

           cin>>z;
           s+=(b[j]*z);

        }
        s+=c;
        if (s>0)++count;

    }

    cout<<count<<endl;
    return 0;

}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] a = new int[3];
		a[0] = scan.nextInt();
		a[1] = scan.nextInt();
		a[2] = scan.nextInt();
		Arrays.sort(a);
		int price = a[0] + a[1];
		System.out.println(price);
	}
}

Measured memory_bytes: 21844