akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    S[3] = '8';
    cout << S << endl;


    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace abc134_c
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var firstMax = 0;
            var secondMax = 0;
            var aList = new List<int>();
            for (var i = 0; i < n; i++)
            {
                var a = int.Parse(Console.ReadLine());
                aList.Add(a);
                if (firstMax <= a)
                {
                    secondMax = firstMax;
                    firstMax = a;
                    continue;
                }

                if (secondMax < a)
                {
                    secondMax = a;
                }
            }

            foreach (var a in aList)
            {
                if (a == firstMax)
                {
                    Console.WriteLine(secondMax);
                    continue;
                }
                Console.WriteLine(firstMax);
            }
        }
    }
}

Measured memory_bytes: 20052
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 2010
#define prev(x) ((x-1+N)%N)
#define next(x) ((x+1)%N)
typedef long long ll;
 
ll N,A[MAX_N];
ll dp[MAX_N][MAX_N];
 
ll solve(int L,int R,int P){
    if(L == R){
	return (P == 0 ? A[L] : 0);
    }
    if(dp[L][R] >= 0) return dp[L][R];
    ll res = 0;
    if(P == 0){
	res = max(res,solve(prev(L),R,1)+A[L]);
	res = max(res,solve(L,next(R),1)+A[R]);
    }else{
	if(A[L] < A[R]){
	    res = solve(L,next(R),0);
	}else{
	    res = solve(prev(L),R,0);
	}
    }
    return dp[L][R] = res;
}
 
int main(){
    cin >> N;
    for(int i = 0 ; i < N ; i++){
	cin >> A[i];
    }
    memset(dp,-1,sizeof(dp));
    ll res = 0;
    for(int i = 0 ; i < N ; i++){
	res = max(res,solve(prev(i),next(i),1)+A[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 34768
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main (void){
	int n,a;
	cin >> n;
	vector<int>v1;
	for(int i=0;i<n;i++){
		cin >>a;
		v1.push_back(a);
	}
	sort(v1.begin(),v1.end());
	cout << v1[n/2]-v1[n/2-1] <<endl ;
	return 0;
}

Measured memory_bytes: 892
import java.util.Scanner


fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val p = scn.nextInt()
	val s = scn.next().toCharArray().map{Integer.parseInt(it.toString())}
	var ans = 0L
	if (p==2 || p==5){
		s.forEachIndexed {i, d -> if (d%p==0) ans += i+1 }
	}else {
		val map = mutableMapOf<Int, Long>()
		var crt = s.last()%p
		var k = 1
		map[crt] = 1
		for (i in s.lastIndex-1 downTo 0){
			k = (k*10)%p
			crt = (k*s[i]+crt)%p
			map[crt] = map.getOrElse(crt){0} + 1
		}
		map.values.forEach { ans += it*(it-1)/2 }
		if (map.containsKey(0)){
			ans += map[0]!!
		}
	}
	print(ans)
}

Measured memory_bytes: 42048
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= n; i+=2) {
            int count = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) {
                    count++;
                }
            }
            if (count == 8) {
                ans++;
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 23252
#include<stdio.h>
int main(){
  int i,a,b,c[5]={};
  for(i=0;i<3;i++){
    scanf("%d %d",&a,&b);
    c[a]++;
    c[b]++;
  }
  a=0;
  for(i=1;i<5;i++)a+=c[i]%2;
  printf("%s\n",a-2?"NO":"YES");
  return 0;
}


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

int dist(int a, int b) {
  if (a - b >= 0)
    return a - b;
  else
    return b - a;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 2);
  for (int i = 0; i < N; i++)
    cin >> A.at(i + 1);
  A.at(0) = 0;
  A.at(N + 1) = 0;
  
  int sum = 0;
  for (int i = 0; i < N + 1; i++) 
    sum += dist(A.at(i),A.at(i + 1));
 
  for (int i = 0; i < N; i++) {
    cout << sum - dist(A.at(i),A.at(i + 1)) - dist(A.at(i + 1),A.at(i + 2)) + dist(A.at(i),A.at(i + 2)) << endl; 
  }
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define pb push_back
#define mb make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod = 1e9+7;
vector<ll> adj[100010];
ll v[100010];
ll dp[100010][2];
void dfs(ll i , ll p ){
	dp[i][0]=1;
	dp[i][1]=1;
	for(auto u:adj[i]){
		if(u!=p){
			dfs(u,i);
			dp[i][0] *= (dp[u][0]+dp[u][1]);
			dp[i][0]%=mod;
			dp[i][1] *= (dp[u][0]);
			dp[i][1]%=mod;
		}
	}
	
}
int main(){
	IOS;
	ll n; cin >> n;
	for(ll i = 1 ; i <= n; i++)
		v[i]=0,adj[i].clear();
	memset(dp,0,sizeof(dp));
	for(ll i = 0 ; i < n-1; i++){
		ll a,b; cin >> a >> b;
		adj[a].pb(b),adj[b].pb(a);
	}
	dfs(1,0);
	cout << (dp[1][0]+dp[1][1])%mod << endl;
	return 0;
}




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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a; cin>>n>>a;
    cout<<n*n-a<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            var sum = 700;
            foreach (var item in S)
            {
                if (item == 'o')
                    sum += 100;
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<ll, ll>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (ll i = begin; i < n; i++)
#define repe(i, begin, n) for (ll i = begin; i <= n; i++)
#define repr(i, begin, n) for (ll i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (ll i = begin; i >= end; i--)

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

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

const ll inf = 1000000007;
const ll MOD = 1000000007;
const long long INF = 1000000000000000007;

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

ll N, K;
ll A[201010];

bool can(ll l) {
  ll cnt = 0;
  rep(i, 0, N) { cnt += (A[i] + l - 1) / l - 1; }
  return cnt <= K;
}

int main() {
  //
  cin >> N >> K;
  rep(i, 0, N) { cin >> A[i]; }

  ll high = INF;
  ll low = 1;

  if (can(1)) {
    cout << 1;
    return 0;
  }

  while (high - low > 1) {
    ll mid = (high + low) / 2;
    if (can(mid)) {
      high = mid;
    } else {
      low = mid;
    }
  }

  cout << high;
}


Measured memory_bytes: 5192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            int count = Integer.parseInt(br.readLine().split(" ")[0]);
            List<String> inputStringList = new ArrayList<>();
            for (int i = 0; i < count; i++) {
                inputStringList.add(br.readLine());
            }

            for (int i = 0; i < count; i++) {
                for (int j = 0; j < 2; j++) {
                    System.out.println(inputStringList.get(i));
                }
            }
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 21972
r=[0]*3
r[0],r[1],r[2],n=map(int, input().split())
ct=0
r=sorted(r)

for i in range(n//r[2]+1):
    for j in range(min(n//r[1]+1, n-r[2]*i+1)):
        if (n-(i*r[2]+j*r[1]))%r[0]==0 and 0<=(n-(i*r[2]+j*r[1]))<=n+1:
            ct+=1
print(ct)

Measured memory_bytes: 40684
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n, ans = INF;
	string s;
	cin >> n >> s;
	int CmpE[n] = {}, CmpW[n] = {};
	for (int i = 0; i < n; i++) {
		if (s[i] == 'E') {
			CmpE[i] = 1;
		} else {
			CmpW[i] = 1;
		}
	}
	for (int i = 0; i < n - 1; i++) {
		CmpE[i + 1] += CmpE[i];
		CmpW[i + 1] += CmpW[i];
	}
	for (int i = 0; i < n; i++) {
		if (i) {
			ans = min(ans, CmpW[i - 1] + CmpE[n - 1] - CmpE[i]);
		} else {
			ans = min(ans, CmpE[n - 1] - CmpE[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5380
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007;
#define pi 3.14159265358979323846264
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
int a, b, c, d;
int main() {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    printf("%d\n", max(a*b, c*d));
    return 0;
}

Measured memory_bytes: 764
red = list()
blue = list()
n = int(raw_input())

for i in range(0,n):
    red.append(map(int,raw_input().split()))
for i in range(0,n):
    blue.append(map(int, raw_input().split()))

red = sorted(red, key=lambda x:x[1], reverse=True)
blue = sorted(blue, key=lambda x:x[0])

c = int()
for r in red:
    for b in blue:
        if r[0]<b[0] and r[1]<b[1]:
            blue.remove(b)
            c+=1
            break
print c

Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main(){
  vector<int> a;
  int N;
  cin>>N;

  for(int i=0;i<N;i++){
    int temp=0;
    cin >> temp;
    a.push_back(temp);
  }
  sort(a.begin(),a.end(),greater<int>());
  
  int alice=0,bob=0;
  int i=0;
  for(auto it=a.begin();it!=a.end();it++){
    if(i%2==0) alice+=(*it);
    else bob+=(*it);
    i++;
  }
  cout << alice-bob<<endl;

  return 0;
}



Measured memory_bytes: 256
data class Node(val id: Int, val edges: List<Int>, var discoveredTime: Int = 0, var finishedTime: Int = 0, var visited: Boolean = false)

fun main(args: Array<String>) {
    val nodeList = List(readLine()?.toInt() ?: 0) {
        val input = readLine()?.split(" ".toRegex())?.map(String::toInt) ?: listOf()
        Node(input[0], input.subList(2, 2 + input[1]))
    }
    val dfs = Dfs(nodeList)
    dfs.print()
}
class Dfs(private val nodes: List<Node>) {
    init {
        dfs()
    }

    private var time = 0

    fun print() {
        println(
            nodes.joinToString("\n") { node ->
                "${node.id} ${node.discoveredTime} ${node.finishedTime}"
            }
        )
    }

    private fun dfs() {
        nodes.forEach { edgeNode ->
                if (!edgeNode.visited) {
                    visit(edgeNode)
                }
            }
    }

    private fun visit(node: Node) {
        node.visited = true
        node.discoveredTime = ++time
        nodes.filter { node.edges.contains(it.id) }
            .forEach { edgeNode ->
                if (!edgeNode.visited) {
                    visit(edgeNode)
                }
            }
        node.finishedTime = ++time
    }
}


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

int main()
{
    string N;
    cin >> N;
    int NI = stoi(N);
    if (NI >= 1000)
    {

        int temp;
        temp = 1 + (NI % 1000);
        ostringstream sout;
        sout << setfill('0') << setw(3) << temp;
        string s = sout.str();
        cout << "ABD" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 256
N = int(input())
list_a = list(map(int,input().split()))
list_a.sort(reverse=True)
alice = 0; bob = 0
for i in range(len(list_a)):
    if i % 2 == 0:
        alice += list_a[i]
    else:
        bob += list_a[i]
print(alice-bob)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

int main(){FIN;
	ll h,w,k; cin>>h>>w>>k;
	char t[h][w];
	fore(i,0,h){
		fore(j,0,w){
			cin>>t[i][j];
		}
	}
	ll res=h*w+1;
	fore(m,0,(1<<(h-1))){
		vector<vector<ll>> v;
		vector<ll> vv;
		fore(i,0,h){
			vv.pb(i);
			if(((1<<i)&m)||i==h-1)v.pb(vv),vv.clear();
		}
		/*for(auto i:v){
			for(auto j:i)cout<<j<<" "; cout<<"\n";
		}*/
		ll tot[h];
		mset(tot,0);
		ll resp=0,br=0;
		fore(i,0,w){
			fore(j,0,SZ(v)){
				fore(k,0,SZ(v[j])){
					tot[j]+=t[v[j][k]][i]=='1';
				}
			}
			ll maxi=0;
			fore(i,0,h)maxi=max(maxi,tot[i]);
			if(maxi>k){
				resp++;
				mset(tot,0);
				fore(j,0,SZ(v)){
					fore(k,0,SZ(v[j])){
						tot[j]+=t[v[j][k]][i]=='1';
					}
				}
			}
			maxi=0;
			fore(i,0,h)maxi=max(maxi,tot[i]);
			if(maxi>k){
				br++; break;
			}
			//fore(i,0,h)cout<<tot[i]<<" "; cout<<"\n";
		}
		if(br)continue;
		resp+=__builtin_popcount(m);
		//if(resp==3)cout<<m<<"\n";
		res=min(res,resp);
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		List<Integer> list = new ArrayList<>();

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();

		System.out.println(k>=e-a?"Yay!":":(");

	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000001
#define mod 998244353
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 1000001;
const ll M = 1;

struct point {
    ll x, y;
};

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    else if(n & 1)
        return fast_exp(x, n - 1) * x % mod;
    else
    {
        ll tmp = fast_exp(x, n >> 1);
        return tmp * tmp % mod;
    }
}

bool c(string s)
{
    ll n = s.size();
    for(int i = 0; i < n / 2; i++)
    {
        if(s[i] != s[n - i - 1]) return false;
    }
    return true;
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m = 0, ans = INF, x, y, k, v;
        cin >> n >> m >> k;
        bool a[n][m];
        char c;
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                cin >> c;
                a[i][j] = c - '0';
            }
        }
        for(ll i = 0; i < (1ll << (n - 1)); i++)
        {
            ll tmp;
            x = __builtin_popcountll(i);
            tmp = x;
            ll b[++x][m] = {};
            y = 0;
            for(ll j = 0; j < n; j++)
            {
                for(int s = 0; s < m; s++)
                {
                    b[y][s] += a[j][s];
                }
                if(i & (1ll << j)) y++;
            }
            /*cout << x << "\n";
            for(ll j = 0; j < x; j++)
            {
                for(int s = 0; s < m; s++)
                {
                    cout << b[j][s] << " ";
                }
                cout << "\n";
            }
            //cout << "\n";*/
            for(int s = 0; s < m; s++)
            {
                y = 0;
                for(int j = 0; j < x; j++)
                {
                    if(s > 0)
                        b[j][s] += b[j][s - 1];
                    y = max(y, b[j][s]);
                }
                if(y > k)
                {
                    y = 0;
                    for(int j = 0; j < x; j++)
                    {
                        if(s > 0)
                            b[j][s] -= b[j][s - 1];
                        y = max(y, b[j][s]);
                    }
                    tmp++;
                    if(y > k) tmp = INF;
                }
            }
            ans = min(ans, tmp);
        }
        cout << ans << "\n";
    }
    return 0;
}


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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define dbg(x) cout<<#x<<"="<<x<<endl

#define fi first
#define se second

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

ll gcd(ll a,ll b){
  return b?gcd(b,a%b):a;
}

ll extgcd(ll a,ll b,ll& x,ll &y){
  ll d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}

ll mod_inverse(ll a,ll m){ 
  ll x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}

PA linear_congruence(const vector<PA>& A){
  ll x=0,m=1;

  ll N=A.size();
  for(ll i=0;i<N;i++){
    ll a=m%A[i].se,b=A[i].fi-x,d=gcd(A[i].se,a);
    b%=A[i].se;
    if(b<0)b+=A[i].se;
    if(b%d!=0)return PA(0,-1);
    ll t=((b/d)*mod_inverse(a/d,A[i].se/d))%(A[i].se/d);
    x=x+m*t;
    m*=A[i].se/d;
    x%=m;
    if(x<0)x+=m;
  }

  return PA(x%m,m);
}

int main(){

  int N;
  cin>>N;
  vector<int> P(N);
  vector<int> Q(N);
  vector<int> tmp(N);
  vector<bool> vis(N,false);

  rep(i,N){
    cin>>tmp[i];
    tmp[i]--;
    P[tmp[i]]=i;
  }
  rep(i,N){
    cin>>tmp[i];
    tmp[i]--;
    Q[i]=tmp[i];
  }

  bool ok=true;
  vector<PA> ps;
  rep(i,N){
    if(vis[i])continue;
    int v=i;
    vector<int> vs;
    while(!vis[v]){
      vs.push_back(v);
      vis[v]=true;
      v=Q[v];
    }
    vector<int> pos;
    rep(j,vs.size()){
      pos.push_back(P[vs[j]]);
    }
    int M=vs.size();
    ll b=0;
    while(pos!=vs&&b<M){
      vector<int> tmpp;
      tmpp.push_back(pos.back());
      rep(j,M-1)tmpp.push_back(pos[j]);
      pos=tmpp;
      b++;
    }
    if(b==M){
      cout<<-1<<endl;
      return 0;
    }
    if(M>1)ps.push_back(PA(b,M));
  }

  PA res=linear_congruence(ps);

  if(res.se==-1){
    cout<<-1<<endl;
    return 0;
  }

  if(res.fi<0)res.fi+=res.se;

  cout<<res.fi<<endl;

  return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
  int n,q;cin>>n>>q;vector<pair<int,pair<int,int>>> p;
  rep(i,n){
    int s,t,x;cin>>s>>t>>x;
    p.push_back(make_pair(s-x,make_pair(1,x)));
    p.push_back(make_pair(t-x,make_pair(0,x)));
  }
  sort(p.begin(),p.end());
  int d[210000];rep(i,q)cin>>d[i];
  int ans[210000];
  set<int> st;int j = 0;
  rep(i,q){
    while(d[i] >= p[j].first){
      if(j >= p.size())break;
      if(p[j].second.first)st.insert(p[j].second.second);
      else st.erase(p[j].second.second);
      j++;
    }
    ans[i] = (st.empty()? -1 : *st.begin());
  }
  rep(i,q)cout << ans[i] << endl;
}


Measured memory_bytes: 16876
Scanf.scanf "%d %d %d" (fun n m r ->
    let next_permutation list =
        let rec phase3 taddr = function
            | _  :: tl when tl == taddr -> []
            | hd :: tl                  -> hd :: phase3 taddr tl
            | []                        -> [] in

        let rec phase2 h2 taddr = function
            | h1 :: tl when h1 > h2 -> let lis = phase3 taddr tl in
                                       h1, h2 :: lis
            | h1 :: tl              -> let hh, lis = phase2 h2 taddr tl in
                                       hh, h1 :: lis
            | _                     -> failwith "??" in

        let rec phase1 list = function
            | h1 :: h2 :: tl when h1 > h2  -> let hh, lis = phase2 h2   tl list in
                                              List.rev_append tl (hh :: lis)
            | _  :: tl                     -> phase1 list tl
            | _                            -> list in

        let rev_list = List.rev list in
        phase1 rev_list rev_list
    in
    let ri = Array.init r (fun _ -> Scanf.scanf " %d" (fun r -> r - 1)) in
    let nei = Array.make n [] in
    for i = 1 to m do
        Scanf.scanf " %d %d %d" (fun a b c ->
            let a = a - 1 in
            let b = b - 1 in
            nei.(a) <- (c, b) :: nei.(a);
            nei.(b) <- (c, a) :: nei.(b);
        )
    done;
    let module S = Set.Make (struct type t = int * int let compare = compare end) in
    let dijkstra s g =
        let d = Array.make n max_int in
        d.(s) <- 0;
        let rec loop set =
            if S.is_empty set then () else
                let ((dd, cur) as m) = S.min_elt set in
                let set = S.remove m set in
                let set = List.fold_left (fun set (nc, nv) ->
                    if d.(nv) <= nc + dd then set else (
                        d.(nv) <- nc + dd;
                        S.add (nc + dd, nv) set
                    )
                ) set nei.(cur)
                in
                loop set
        in
        loop (S.singleton (0, s));
        d.(g)
    in
    let dist = Array.make_matrix r r max_int in
    for i = 0 to r - 1 do
        dist.(i).(i) <- 0;
        for j = i + 1 to r - 1 do
            let c = dijkstra ri.(i) ri.(j) in
            dist.(i).(j) <- c;
            dist.(j).(i) <- c;
        done
    done;
    let rec iota a = if a < 0 then [] else a :: iota (a - 1) in
    let rec fact a = if a = 0 then 1  else a *  fact (a - 1) in

    let calc l =
        match l with
        | [] -> 0
        | hd :: tl ->
                let rec loop prev sum = function
                    | [] -> sum
                    | x :: xs -> loop x (sum + dist.(prev).(x)) xs
                in
                loop hd 0 tl
    in

    let rec loop i lis acc =
        if i = 0 then acc else
            loop (i - 1) (next_permutation lis) (min acc (calc lis))
    in
    loop (fact r) (iota (r - 1)) max_int |> Printf.printf "%d\n"
)

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<int> h(n);
	for(auto &x:h) cin >> x;
	vector<int> dp(n, 1000000001);
	dp[0] = 0; dp[1] = abs(h[1]-h[0]);
	//cout << dp[1] << "\n";
	for(int i=2;i<n;i++){
		for(auto x: {i-1, i-2}){
			dp[i] = min(dp[x]+abs(h[i]-h[x]), dp[i]);
		}
	//	cout << dp[i] << "\n";
	}
	cout << dp[n-1] << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int h,w;
   cin >> h >> w;
   string s[h];
   rep(i,h) cin >> s[i];
 
   rep(i,w+2) cout << "#";
   cout << endl;
   rep(i,h){
      cout << "#" << s[i] << "#" << endl;
   } 
   rep(i,w+2) cout << "#";
   cout << endl;

   return 0;
}

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

int main(){
  long long N;
  cin >> N;
  int A[2][N];
  int dp[2][N];
  for(int i=0; i<2; i++){
    for(int j=0; j<N; j++){
      cin >> A[i][j];
      if(j==0) dp[i][j]=A[i][j];
      else dp[i][j]=A[i][j]+dp[i][j-1];
    }
  }
  int ans=0;
  for(int i=0; i<N; i++){
    if(i==0) ans=max(ans,dp[0][0]+dp[1][N-1]);
    else ans=max(ans,dp[0][i]+(dp[1][N-1]-dp[1][i-1]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int i,j,s,minj,x,y=0;
  int a[100]={};


  scanf("%d",&s);
  for(i=0;i<s;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<s;i++){
    minj=i;
    for(j=i;j<s;j++){
      if(a[minj]>a[j]){
	minj=j;
      }
    }
    
    if(minj!=i){
      x=a[minj];
      a[minj]=a[i];
      a[i]=x;
      y++;
    }
  }

  for(i=0;i<s;i++){
    printf("%d",a[i]);
    if(i==s-1)puts("");
    else printf(" ");
  }
  printf("%d\n",y);
    
  return 0 ;
}



Measured memory_bytes: 2100
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <vector>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <sstream>
#include <complex>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <limits>
#include <numeric>
#include <cmath>
#include <functional>
#include <queue>
#include <cstring>

using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;

#define FORE(k,a,b) for(int k=(a); k <= (int)(b); ++k)
#define FOR(k,a,b) for(int k=(a); k < (int) (b); ++k)

#define pb push_back
#define mp make_pair
#define sfi(a) scanf("%d",&a)
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<uint> uvi;
typedef vector<uvi> uvvi;
typedef vector<vd> vvd;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
typedef vector<vii> vvii;
typedef pair<uint,uint> uu;
typedef map<string, int> msi;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define FOR_IT(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define contains(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

int main(){

    int str[5],test;

    sfi(test);
    while(test--){

            scanf("%d%d%d",&str[0],&str[1],&str[2]);


        sort(str,str+3);

        if(str[2]*str[2]==(str[0]*str[0])+(str[1]*str[1]))
            puts("YES");
        else
            puts("NO");
    }




return 0;
}

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

int main(){
    ll n;
    cin>>n;
    vector<string>ss(n);
    rep(i,n)cin>>ss[i];
    vector<ll>c(5,0);
    rep(i,n){
        if(ss[i][0]=='M')c[0]+=1;
        else if(ss[i][0]=='A')c[1]+=1;
        else if(ss[i][0]=='R')c[2]+=1;
        else if(ss[i][0]=='C')c[3]+=1;
        else if(ss[i][0]=='H')c[4]+=1;
    }
    ll cnt=0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                cnt+=c[i]*c[k]*c[j];
            }
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr if(true)cerr
void print(){cout<<endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {cout<<a<<" ";print(args...);}
lli llipowerp(lli x, lli y, lli p=LLONG_MAX)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
inline void printvec(vector<T> inp){
    for(auto it:inp) cout<<it<<" ";
    cout << endl;
}
//---------------------------------------------------------------------------------
lld nthRoot(lli A, lli N)
{
    // intially guessing a random number between
    // 0 and 9
    lld xPre = rand() % 10;

    //  smaller eps, denotes more accuracy
    lld eps = 1e-3;

    // initializing difference between two
    // roots by INT_MAX
    lld delX = INT_MAX;

    //  xK denotes current value of x
    lld xK;

    //  loop untill we reach desired accuracy
    while (delX > eps)
    {
        //  calculating current value from previous
        // value by newton's method
        xK = ((N - 1.0) * xPre +
              (lld)A / pow(xPre, N - 1)) /
             (lld)N;
        delX = abs(xK - xPre);
        xPre = xK;
    }

    return xK;
}
int main(){
    
    int n;
    cin>>n;
    vector<lli> a(n);
    fori(n) cin>>a[i];
    map<lli,lli> diff;
    map<lli,lli> sums;
    fori(n){
        diff[i-a[i]]++;
        sums[i+a[i]]++;

    }
    lli ans=0;
    for(auto it:diff){
        ans+=it.S*sums[it.F];
    }
    cout<<ans<<endl;

}


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

int main(){
	int n;
	while( scanf("%d", &n ), n ){
		int zero=0;
		for( int i=5; i<=n; i+=5 ){
			int k=i;
			while( k%5==0 ){
				k/=5;
				zero++;
			}
		}
		printf("%d\n", zero);
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
Dict = {}
ans = 0
tmp_list = []
for i in range(n):
    tmp = list(input())
    tmp_list.append(tmp)
tmp_list.reverse()
for i in range(n):
    tmp = tmp_list[i]
    tmp = sorted(tmp)
    tmp = ''.join(tmp)
    if tmp not in Dict.keys():
        Dict[tmp] = 1
    else:
        ans += Dict[tmp]
        Dict[tmp] += 1
print(ans)

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

using namespace std;

int n;
int a[111], cnt[111];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d",&n);
	int x;
	for(int i = 1; i <= n; ++i) scanf("%d",&x), ++cnt[x];
	for(int i = 100; i >= 1; --i){
		if (cnt[i]){
			for(int j = i / 2 + 1; j <= i; ++j){
				if (cnt[j] < 2){
					printf("Impossible");
					return 0;
				}
				cnt[j] -= 2;
			}
			if (i % 2 == 0){
				if (!cnt[i / 2]){
					printf("Impossible");
					return 0;					
				}
				--cnt[i / 2];
			}
			for(int j = i / 2 + i % 2; j >= 1; --j) if (cnt[j]){
				printf("Impossible");
				return 0;
			}
			break;
		}
	}
	printf("Possible");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector< vector<int> > jobs(m);
  for(int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if(a > m) continue;
    jobs[m-a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for(int i = m-1; i >= 0; --i) {
    for(int b : jobs[i]) {
      q.push(b);
    }
    if(!q.empty()) {
      ans += q.top();
      q.pop();
    }
    // ans += *max_element(jobs[i].begin(), jobs[i].end());
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5504
import unittest


class TestA(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([5, 7, 9]), 'win')

    def test_2(self):
        self.assertEqual(think([13, 7, 2]), 'bust')


def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    return read_int(3)


def read_int(n):
    return read_type(int, n)


def read_float(n):
    return read_type(float, n)


def read_type(t, n):
    return list(map(lambda x: t(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    a1, a2, a3 = data
    if a1 + a2 + a3 < 22:
        return 'win'
    return 'bust'


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 6336
x1,y1,x2,y2=map(int,input().split())
w=x2-x1
h=y2-y1
x3=x2-(y2-y1)
y3=y2+(x2-x1)
x4=x3-(x2-x1)
y4=y3-(y2-y1)
print(x3,y3,x4,y4)


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

int main(){
    string s1,s2;
    cin>>s1>>s2;
    if (s1.size()+1==s2.size()){
        for (int i=0;i<s1.size();++i){
            if (s1[i]!=s2[i]){
                cout<<"No";
                return 0;
            }
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer K,X;
        K = sc.nextInt();
        X = sc.nextInt();
        if (500* K >= X)
           System.out.println("Yes");
        else
           System.out.println( "No");
    }
}


Measured memory_bytes: 21844
def head(str)
  str[0, 1]
end
 
def checkWrong(value)
  return (head(value[0]) == "0" && value[0].size > 1) || (head(value[1]) == "0" && value[1].size > 1) || (head(value[2]) == "0" && value[2].size > 1)
end

def calc(value, replacement)
  value.each{
    |v| v.gsub!("X", replacement) 
  }
  return true   if  value[0].to_i + value[1].to_i == value[2].to_i
end

def solve(input)
  for replacement in 0..9
      value = input.chomp.scan(/[^(\+=)]+/)
      #値が決定した後に異常値でないかチェックする
      if  calc(value, replacement.to_s) && !checkWrong(value)
        return replacement.to_s
      end
  end
  return nil
end

#main loop
while input = gets
  if  (x = solve(input)) != nil
    puts x
  else
    puts "NA"
  end
end
 
#for test : X5+5=1X X+X=X X5+X5=10

Measured memory_bytes: 6220
n, l = map(int, input().split())
taste = [i for i in range(l, l + n)]
SUM = sum(taste)
diff = 10 ** 3
idx = 0
for j in range(len(taste)):
    diff_n = abs(taste[j])
    if diff_n < diff:
        idx = j
        diff = diff_n
        if diff == 0:
            print(SUM)
            exit(0)
print(SUM-taste[idx])

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

int main() {
  int A,B,C;
  cin >>A >>B >>C;
  
  if(A>B){
    if(C>B){
      if(A>C){
        cout <<"Yes" <<endl;
        return 0;
      }
    }
  }
  else{
    if(C>A){
      if(B>C){
        cout <<"Yes" <<endl;
        return 0;
      }
    }
  }
  cout <<"No" <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    int x[h][w];
    vector<int> a,b,c,d;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>x[i][j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(x[i][j]&1){
                if(i!=h-1){
                    x[i+1][j]++;
                    a.pb(i+1);
                    b.pb(j+1);
                    c.pb(i+2);
                    d.pb(j+1);
                }
                else if(i==h-1&&j!=w-1){
                    x[i][j+1]++;
                    a.pb(i+1);
                    b.pb(j+1);
                    c.pb(i+1);
                    d.pb(j+2);
                }
            }
        }
    }
    ll n=a.size();
    cout << n<<endl;
    for(int i=0;i<n;i++){
        cout << a[i]<<" "<<b[i]<<" "<<c[i]<<" "<<d[i]<<endl;
    }
    
    return 0;
}

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

int main() {

	long res = 1;

	int N;
	string S;
	cin >> N >> S;
    int doko;
    

	int check[26];
    
    for (int j = 1; j<= 26; j++) check[j] = 0;

	for (int i = 1; i <= N; i++) {
        doko = S[i - 1] - 'a' + 1;
        check[doko] = check[doko] + 1 ;
    }

	for (int k = 1; k <= 26; k++) {

		res = res * (check[k] + 1);
        res = res % 1000000007;
	}
  res-- ;
	cout << res << endl;

}

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

int cnt;
string now;

int main(){
	ios::sync_with_stdio(false);
	cin>>now;
	for (;cnt < now.length();cnt ++)if (now[cnt] == 'C')break;
	for (register int i = now.length() - 1;i > cnt;i --)if (now[i] == 'F'){
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

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

double MM = sqrt(3.0)/2.0; 

void f(int n, double a1, double a2, double b1, double b2){
	if(n == 0) return;
	double c1=(b1-a1)/3.0, c2=(b2-a2)/3.0;
	double top1 = 0.5*c1-MM*c2, top2=MM*c1+0.5*c2;
	double s1 = c1+a1, s2 = c2+a2;
	
	f(n-1, a1, a2, s1, s2);
	cout << s1 << " "<< s2 << endl;
	f(n-1, s1, s2, s1+top1, s2+top2);
	cout << s1+top1 << " "<< s2+top2 << endl;
	f(n-1, s1+top1, s2+top2, s1+c1, s2+c2);
	cout << s1+c1 << " "<< s2+c2 << endl;
	f(n-1, s1+c1, s2+c2, b1, b2);
}


int main(){
	int n;
	cin >> n;
	cout << 0 << " "<< 0<<endl;
	f(n, 0, 0, 100, 0);
	cout << 100 << " "<< 0<<endl;
	return 0;
}

Measured memory_bytes: 1252
n = int(input())

"""
def hor(matrix,y):
    res = [True]*9
    s = set()
    out = set()
    for i in matrix[y]:
        if i in s:
            out.add(i)
        s.add(i)
    for ind,i in enumerate(matrix[y]):
        if i in out:
            res[ind] = False
"""
def so(seq):
    res = [False]*9
    s = set()
    out = set()
    for i in seq:
        if i in s:
            out.add(i)
        s.add(i)
    for ind,i in enumerate(seq):
        if i in out:
            res[ind] = True
    return res

for num in range(n):
    matrix = [list(map(int, input().split())) for _ in range(9)]
    part = []
    for i in range(9):
        t = []
        for j in range(9):
            t.append(matrix[j][i])
        part.append(t)
    section = []
    for i in range(3):
        for j in range(3):
            t = []
            for k in range(3):
                for l in range(3):
                    t.append(matrix[i*3 + k][j*3 + l])
            section.append(t)   
        
    cor = [[False]*9 for _ in range(9)]

    for i in range(9):
        for ind,j in enumerate(so(matrix[i])):
            cor[i][ind] = cor[i][ind] or j
        for ind,j in enumerate(so(part[i])):
            cor[ind][i] = cor[ind][i] or j
        for ind,j in enumerate(so(section[i])):
            x = i % 3
            y = i // 3
            px = ind % 3
            py = ind // 3
            cor[y*3 + py][x*3 + px] = cor[y*3 + py][x*3 + px] or j
    for i,j in zip(cor, matrix):
        for k,l in zip(i,j):
            if k: t = '*'
            else: t = ' '
            print(f'{t}{l}',end='')
        print()
    if num != n-1: print()





Measured memory_bytes: 5648
#include <iostream>
#include <string>

using namespace std;

int main () {
	int N;
    string S;
    cin >> N;
    cin >> S;
    if (N%2 != 0 || S.length() %2 != 0) {
    	cout << "No" << endl;
    }
    else {
    	string a = S.substr (0,S.length()/2);
        string b = S.substr (S.length()/2);
        if (a.compare(b) != 0) {
        	cout << "No" << endl;
        }
        else {
        	cout << "Yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
w,h,n=map(int,input().split())
A1=[0]
A2=[w]
A3=[0]
A4=[h]
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    A1.append(x)
  elif a==2:
    A2.append(x)
  elif a==3:
    A3.append(y)
  else:
    A4.append(y)
if min(A2)>max(A1) and min(A4)>max(A3):
  print((min(A2)-max(A1))*(min(A4)-max(A3)))
else:
  print(0)


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

const long long INF = 1e18 + 10;

int main() {

    int n, max_w; scanf("%d%d", &n, &max_w);

    vector <long long> v(n), w(n);
    for (int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    vector <vector <long long> > dp(n + 1, vector <long long> (max_w + 1, -INF));

    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= max_w; j++) {
            if (dp[i][j] != -INF) {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);

                if (j + w[i] <= max_w) {
                    dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
                }
            }
        }
    }

    long long result = *max_element(dp[n].begin(), dp[n].end());

    cout << result;

    return 0;
}

Measured memory_bytes: 80256
fn main() {
    let r = std::io::stdin();
    let mut sc = Scanner::new(r.lock());
    let v = sc.read_line();

    let h : usize = v[0].parse().unwrap();
    let a : usize = v[1].parse().unwrap();

    let mut ans = h / a;
    if h % a != 0 {
        ans += 1;
    }
    println!("{}", ans);
}

pub struct Scanner<R: std::io::Read> (std::io::BufReader<R>);

impl<R: std::io::Read> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner (std::io::BufReader::new(r))
    }

    pub fn read_line(&mut self) -> Vec<String> {
        use std::io::BufRead;
        let mut line = String::new();
        self.0
            .read_line(&mut line)
            .unwrap();

        line.split_whitespace()
            .map(|b| b.to_string())
            .collect::<Vec<String>>()
    }
}

Measured memory_bytes: 4352
import scala.io.StdIn.readLine

object Main{
  def main(args: Array[String]): Unit = {
    val a = readLine.split(" ").map(_.toInt)
    var f = "No"
    if(a(0) < a(1) && a(1) < a(2)) {
      f = "Yes"
    }
    printf("%s\n", f)
  }
}

Measured memory_bytes: 43788
n  = int(input())
li = list(map(int,input().split()))
ok = set()
ng = set()
mul = set()

ans = 0

for i in li:
    if i not in ok:
        ok.add(i)
    else:
        ng.add(i)

for i in ok:
    for j in range(2,10**6):
        if i*j > 10**6:
            break
        else:
            mul.add(i*j)

for i in ok:
    if i not in mul:
        if i not in ng:
            ans+=1

print(ans)

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

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

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N;
    cin >> N;

    vector<i64> A(N);
    rep(i,0,N) cin >> A[i];

    vector<i64> l(N),r(N);
    l[0]=A[0];
    rep(i,1,N){
        l[i]=gcd(l[i-1],A[i]);
    }

    r[N-1]=A[N-1];
    for(i64 i=N-2; i>=0; --i){
        r[i]=gcd(r[i+1],A[i]);
    }

    i64 ans=0;
    rep(i,0,N){
        if(i==0) chmax(ans,r[i+1]);
        else if(i==N-1) chmax(ans,l[i-1]);
        else chmax(ans,gcd(l[i-1],r[i+1]));
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val mod = 998244353L

    class BulkCombination(n: Int, val mod: Long = 998244353L) {

        private val factorial = LongArray(n + 1) { 1 }
        private val inverse = LongArray(n + 1) { 1 }
        private val factorialInverse = LongArray(n + 1) { 1 }

        init {
            for (i in 2..n) {
                factorial[i] = (factorial[i - 1] * i.toLong() % mod)
                inverse[i] = (mod - inverse[mod.toInt() % i] * (mod / i.toLong()) % mod)
                factorialInverse[i] = (factorialInverse[i - 1] * inverse[i] % mod)
            }
        }

        fun nCm(n: Int, m: Int): Long {
            return factorial[n] * (factorialInverse[m] * factorialInverse[n - m] % mod) % mod
        }

        fun nHm(n: Int, m: Int): Long {
            return nCm(n + m - 1, m)
        }
    }

    val (n, m, k) = readLine()!!.split(' ').map(String::toLong)
    val c = BulkCombination(n.toInt() - 1)
    val mo = LongArray(n.toInt() + 1) { 1 }
    mo[1] = m - 1
    for (i in 2..n.toInt()) {
        mo[i] = (mo[i - 1] * (m - 1)) % mod
    }
    var ans = 0L
    for (i in 0..k.toInt()) {
        var temp = m
        temp *= mo[n.toInt() - 1 - i]
        temp %= mod
        temp *= (c.nCm(n.toInt() - 1, i)) % mod
        temp %= mod
        ans += temp
        ans %= mod
    }
    println(ans)
}

Measured memory_bytes: 43040
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
void trace(int n, int arr[]){for(int i = 0; i < n; i++){cout << i << " " << arr[i] << endl;} cout << endl << endl;}
int main()
{
    Hello
    int n;
    cin >> n;
    ll arr[n + 5], sum = 0, freq[100005] = {};
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        sum += arr[i];
        freq[arr[i]]++;
    }
    int q;
    cin >> q;
    while(q--){
        int a, b;
        cin >> a >> b;
        sum -= (freq[a] * a);
        sum += (freq[a] * b);
        freq[b] += freq[a];
        freq[a] = 0;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 5024