akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;

	
int main()
{
	string s="No";
	int a,b;cin>>a>>b;
	if((a*b)%2==1)s="Yes";
	cout<<s<<"\n";
}

Measured memory_bytes: 256
input_nums = gets.split.map(&:to_i)
gates = gets.split.map(&:to_i)

n = input_nums[0]
x = input_nums[2]

to_left = 0
(0..x).each do |num|
  to_left += 1 if gates.include?(num)
end

to_right = 0
(x..n).each do |num|
  to_right += 1 if gates.include?(num)
end

if to_left < to_right
  puts to_left
else
  puts to_right
end

Measured memory_bytes: 1788
/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>
 
#define rep(i, n) for(int i = 0; i < n; i++)
 
//const long long INF = 1LL << 60;
const int INF = 1e9;
using ll = long long;

int main()
{
    std::string S;
    std::string T;
    std::cin >> S;
    std::cin >> T;

    int ans = INF;
    rep(i, S.length())
    {
        if( T.length() > S.length() - i )
        {
            break;
        }

        int tmp = 0;
        rep(j, T.length())
        {
            if(S[i+j] != T[j])
            {
                tmp++;
            }
        }

        ans = std::min(ans, tmp);
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
#define all(v) ((v).begin()),((v).end())
#define PI(n) ((double)acos(n))
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file(){
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
#else 
#endif
}
void fast(){
	std::ios_base::sync_with_stdio(0); cin.tie(NULL);
}
int main()
{
	fast();
	int n;
	cin >> n;
	int ans = 0;
	vector<int>v(n+1);
	for (int i = 1; i <= n; i++){
		cin >> v[i];
	}
	for (int i = 1; i <= n; i++){
		if (v[i] == i){
			swap(v[i], v[i + 1]);
			ans++;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){

    int n;
    cin>>n;
    while(n--){

        int x,y,w,h;
        cin>>x>>y>>w>>h;
        int m;
        cin>>m;
        int ans = 0;
        for(int i=0;i<m;i++){
            int X,Y;
            cin>>X>>Y;
            if(x<=X&&X<=x+w&&y<=Y&&Y<=y+h)ans++;

        }
        cout<<ans<<endl;


    }


    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if (x == 1 and y == 1) ans += 400000;
    if (x == 1) ans += 300000;
    else if (x == 2) ans += 200000;
    else if (x == 3) ans += 100000;
    if (y == 1) ans += 300000;
    else if (y == 2) ans += 200000;
    else if (y == 3) ans += 100000;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
const int MAXN=1100;
int main()
{
    ios;
    int x;
    cin>>x;
    if(x==0) printf("1\n");
    else printf("0\n");
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 4/23/2018
 
 9:10-9:23 analysis
 9:24-9:38 1WA
 9:48 2WA
 
 */

const LL Inf=1e18;

LL high(int T, int A) {
  LL good=-1,bad=Inf;
  while(abs(good-bad)>1) {
    LL mid=(good+bad)/2LL;
    LL fx=mid-mid%A;
    (fx<=T?good:bad)=mid;
  }
  return good;
}

LL low(int T, int A) {
  LL good=Inf,bad=-1;
  while(abs(good-bad)>1) {
    LL mid=(good+bad)/2LL;
    LL fx=mid-mid%A;
    (fx>=T?good:bad)=mid;
  }
  return good;
}

// $ g++ -std=c++11 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
vector<LL> solve(int N, vector<LL> A) {
  if(A.back()!=2) return {};
  
  LL l=2,r=2;
  for(int i=N-1; i>=0; --i) {
    LL a=A[i];
    LL k1=(l+a-1)/a,k2=r/a;
//    if(k1==0&&k2==0) return {};
    l=a*k1;
    r=a*(k2+1)-1;
//    dump4(i,A[i],l,r);
    if(l>r) return {};
//    if(l>h) return {};
//    if(l<=-1||l>Inf) return {};
//    if(h<=-1||h>Inf) return {};
  }
  return {l,r};
}

int main() {
  int N; scanf("%d", &N);
  vector<LL> A(N);
  REP(i,N) scanf("%lld", &A[i]);
  vector<LL> res=solve(N,A);
  if(res.empty()) printf("-1\n");
  else printf("%lld %lld\n",res[0],res[1]);
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    set<string> st;
    char pre;
    bool f = true;
    rep(i, 0, n){
        string s;
        cin >> s;
        if(i && s[0] != pre) f = false;
        if(st.count(s)) f = false;
        st.insert(s);
        pre = s[s.size() - 1];
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;

int main() {
   int n,u,v;cin >>n>>u>>v;
   u--;v--;
   vector<vector<int>>g(n);
    for (int i = 0; i < n - 1; ++i) {
        int a,b;cin >>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<ll>du(n,INF);
    queue<ll>que;
    que.push(u);
    du[u]=0;
    ll now;
    while(que.size()){
        ll q=que.front();que.pop();
        now=du[q];
        for(auto e:g[q]){
            if(du[e]>now+1){
                du[e]=now+1;
                que.push(e);
            }
        }
    }
    vector<ll>dv(n,INF);
    que.push(v);
    dv[v]=0;
    while(que.size()) {
        ll q = que.front();
        que.pop();
        now = dv[q];
        for (auto e:g[q]) {
            if (dv[e] > now + 1) {
                dv[e] = now + 1;
                que.push(e);
            }
        }
    }
    ll ans=0;
    for (int i = 0; i < n; ++i) {
        if(du[i]<dv[i])ans=max(ans,dv[i]);
    }
//    for(auto uu:du){
//        cout <<uu<<" ";
//    }
//    for(auto vv:dv){
//        cout <<vv<<" ";
//    }
    cout <<ans-1<<endl;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    //英語文字列のmapをつくる。
    string words = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    map<char, int> KeyEnglish;
    for (int i = 1; i <= 26; i++) {
        KeyEnglish[words.at(i-1)] = i;
    }
    //逆ver
    map<char, int> KeyNumber;
    for (int i = 1; i <= 26; i++) {
        KeyNumber[i] = words.at(i-1);
    }

    string ans;
    for (int i = 0; i < s.size(); i++) {
        if(KeyEnglish.at(s.at(i)) + n > 26) {
            ans += KeyNumber.at(KeyEnglish.at(s.at(i)) + n - 26);
        }
        else {
            ans += KeyNumber.at(KeyEnglish.at(s.at(i)) + n);
        }
    }
    cout << ans;
    //valueからkeyを取得できたらなぁ。もう2つ作るか
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
// 0か1が残ってたら消えるじゃん
int main() {
  std::string s;
  std::cin >> s;
  int ans, w = 0, b = 0;

  for(char c: s) {
    if(c == '0') {
      w++;
    } else {
      b++;
    }
  }
  ans = (w - b) > 0 ? (s.size() + b - w) : (s.size() + w - b);
  std::cout << ans << std::endl;
}

Measured memory_bytes: 512
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int limit = int.Parse(Console.ReadLine());
            int[] heights = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int clearCount = 0;
            for(int i = 0;i < inputs[0];i++)
            {
                if(heights[i] >= inputs[1])
                {
                    clearCount++;
                }
            }

            Console.WriteLine(clearCount);
        }
    }
}

Measured memory_bytes: 19040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
template<typename T, size_t size>
struct BIT {
	T a[size]; int n;
	void init(int _n) { n = _n; memset(a, 0, sizeof(T)*(_n + 1)); }//输入下标范围。
	void erase(int x) { for (int i = x; i <= n; i += i & -i)a[i] = 0; }
	void update(int x, T y) {
		for (int i = x; i <= n; i += i & -i)a[i] += y;
	}
	T query(int x) { T re = 0;  for (int i = x; i; i -= i & -i)re += a[i]; return re; }
};
BIT<int, maxn>bit;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,q;
    cin>>n>>q;
    bit.init(n);
    rep(i,1,q){
        int op,x,y;
        cin>>op>>x>>y;
        if(op)cout<<bit.query(y)-bit.query(x-1)<<endl;
        else bit.update(x,y);
    }

}
/* 

3 5
0 1 1
0 2 2
0 3 3
1 1 2
1 2 2
 */


Measured memory_bytes: 3612
N,M,X = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]
ans = 10**10
for i in range(2**N):
    cost = 0
    rikai = [0 for i in range(M)]
    for j in range(N):
        if i>>j&1:
            cost += A[j][0]
            for k in range(M):
                rikai[k] += A[j][k+1]
    b = True
    for k in range(M):
        if rikai[k] >= X:
            continue
        b = False
    if b:
        ans = min(ans,cost)
print(-1 if ans == 10**10 else ans)
 

Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,q,f1=1,t=0,be;
	string s,s1="",s2=""; 
	char c;
	cin>>s>>n;
	for(int i=0;i<n;i++){
		cin>>q;
		if(q==1){
			t++;
			if(t%2)f1=0;
			else f1=1;
		}
		else if(q==2){
			cin>>be>>c;
			if((be==1&&f1==1)||(be==2&&f1==0))s1+=c;
			else s2+=c;
		}
	}
	if(!f1){
		reverse(s.begin(),s.end());
		reverse(s2.begin(),s2.end());
		cout<<s2<<s<<s1;
	}
	else{
		reverse(s1.begin(),s1.end());
		cout<<s1<<s<<s2;
	}
	return 0;
}

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

class Program {
    static void Main(string[] args) {

        int[] monts = new int[10];
        for (int i = 0; i < 10; i++) {
            monts[i] = Cin.Ni();
        }
        Array.Sort(monts);
        Array.Reverse(monts);
        for (int i = 0; i < 3; i++) {
            Console.WriteLine(monts[i]);
        }                                              
    }
}
public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string Next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return Next();
    }

    public static int Ni() {
        return int.Parse(Next());
    }

    public static long NextLong() {
        return long.Parse(Next());
    }

    public static double NextDouble() {
        return double.Parse(Next());
    }

}

Measured memory_bytes: 9204
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        int ans = 0;
        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == '1') ans++;
        }
        System.out.println(ans);
    }
}

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

inline
int gcd(int x, int y) {
	if (x % y == 0) return y;
	else return gcd(y, x % y);
}

int main() {
	int n, k, g; cin >> n >> k >> g;
	int maxi = g;
	n--;
	while (n--) {
		int a; cin >> a;
		g = gcd(g, a);
		maxi = max(maxi, a);
	}
	cout << ((k % g == 0 && k <= maxi) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
	return 0;
}


Measured memory_bytes: 3576
<?php
$n = trim(fgets(STDIN));

for ($i = 0; $i < $n; $i++) {
	$snake = trim(fgets(STDIN));
	if (preg_match("/^>'(=+)#\\1~$/", $snake)) {
		echo "A\n";
	} else if (preg_match("/^>\^(Q=)+~~$/", $snake)) {
		echo "B\n";
	} else {
		echo "NA\n";
	}
}

Measured memory_bytes: 6768
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
#define MP make_pair
#define PB push_back
#define F_d first
#define S_d second
#define LARGE 100000000
#define MOD 100000
#define LL long long

int K, A, B;
LL ans = 1;
bool tmp = false;
int main() {
	cin >> K >> A >> B;
	for (int i = 1; i <= K; i++) {
		if (tmp) {
			ans += B; tmp = false;
//			cout << "buy" << endl;
		}
		else if (i < K && A + 1 < B && ans >= A) {
			ans -= A; tmp = true;
//			cout << "sell" << endl;
		}
		else {
			ans++;
//			cout << "hit" << endl;
		}
	}
	cout << ans << endl;
	return 0;
}



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

ll time(int n) {
  ll ans = 1;
  do {
    ans *= n;
    ans %= 1000000007;
  } while (--n);
  return ans;
}

int main(void) {
  int N;
	cin >> N;

  cout << time(N) << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>

long p[100000];

int argmax(int l, int r){
  int nowmax=p[l];
  int maxindex=l;
  for(int i=l+1;i<=r;i++){
    if(p[i]>nowmax){
      maxindex=i;
      nowmax=p[i];
    }
  }
  return maxindex;
}

int ascending(int l, int r){
  for(int i=l;i<=r-1;i++){
    if(p[i]>p[i+1]) return 0;
  }
  return 1;
}

int descending(int l, int r){
  for(int i=l;i<=r-1;i++){
    if(p[i]<p[i+1]) return 0;
  }
  return 1;
}

long firstsum(int l, int r, int n){
  int i,imax;
  long ans;
  if(l==n && r==n) return 0;
  if(l!=n) imax=l;
  else imax=l+1;
  for(i=l+1;i<=r;i++){
    if(i!=n && p[i]>p[imax]) imax=i;
  }
  if(imax<n){
    ans=p[imax]*(imax-l+1)*(r-n+1)+firstsum(imax+1,r,n);
  }else{
    ans=p[imax]*(n-l+1)*(r-imax+1)+firstsum(l,imax-1,n);
  }
  return ans;
}

long secondsum(int l, int r){
  long ans=0;
  int imax,i,j;
  int ll[100000];
  int rr[100000];

  if(r-l<1) return 0;
  if(ascending(l,r)){
    for(i=l;i<=r-1;i++){
      ans+=p[i]*(i-l+1);
    }
    return ans;
  }
  if(descending(l,r)){
    for(i=r;i>=l+1;i--){
      ans+=p[i]*(r-i+1);
    }
    return ans;
  }
  imax=argmax(l,r);
  
  if(imax==l)
    ans=secondsum(imax+1,r)+firstsum(l,r,imax);
  else if(imax==r)
    ans=secondsum(l,imax-1)+firstsum(l,r,imax);
  else
    ans=secondsum(l,imax-1)+secondsum(imax+1,r)+firstsum(l,r,imax);
  return ans;
}

int main()
{
  int n;
  scanf("%d", &n);
  for(int i=0;i<n;i++) scanf("%d", &p[i]);
  printf("%ld\n",secondsum(0,n-1));  
  return 0;
}

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

int main(){
  int n,k;cin>>n>>k;
  vector<int>a(n,0);
  rep(i,n){
    cin>>a[i];
    if(i>=k){
      if(a[i-k]<a[i])cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 4004
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let (n, m) = read_touple::<usize>();
    let mut a: Vec<usize> = read_vec();
    a.sort_by(|a, b| b.cmp(&a));
    let sum = a.iter().fold(0, |acc, &x| acc + x);
    let mut ans = true;
    for i in 0..m {
      if sum > 4 * m * a[i] {
         ans = false;
         break;
      }
    }

    if ans {
       println!("Yes");
    } else {
      println!("No");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define mod (ll)1000000007
using namespace std;

int main()
{
    int n;
    cin>>n;

    pair<double,double> a[n];

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

    int ix[n];
    for(int i =0;i < n; i++){
        ix[i] = i;
    }
    double f = 1.0;

    for(int i =2; i <= n; i++)
        f*=i;

    long double ans = 0.0;
    do{

        for(int i =0; i < n-1; i++){
            ans += sqrt((a[ix[i]].first-a[ix[i+1]].first)*(a[ix[i]].first-a[ix[i+1]].first) + (a[ix[i]].second - a[ix[i+1]].second)*(a[ix[i]].second - a[ix[i+1]].second));
        }

    }while(next_permutation(ix,ix+n));

    ans/=f;
    cout<<setprecision(15);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;
static const long k10E7 = 1000000007;

int main()
{
    long l, r;
    cin >> l >> r;

    bool end = false;
    int result = 0;

    if(!end){
        if ((r - l) >= 672){
            result = 0;
            end = true;
        }
    }

    if(!end){
        long start = l % 2019;
        long end = r % 2019;
        result = 2019;
        for(int i = start; i < end; i++){
            for(int j = i + 1; j <= end; j++){
                result = min(result, (i * j) % 2019);
            }
        }
    }

    cout << result << endl;

    return 0;
}


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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for (int i = 0; i < N; i++) cin >> S[i];

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

  string ans = "";

  for (int i = 0; i < N; i++) ans += S[i];

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N;
    int A[200000];
    int l[200000];
    int r[200000];
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    l[0] = A[0];
    for(int i = 1; i < N; i++) l[i] = max(l[i-1], A[i]);
    r[N-1] = A[N-1];
    for(int i = N-2; i >= 0; i--) r[i] = max(r[i+1], A[i]);
    cout << r[1] << endl;
    for(int i = 1; i < N-1; i++){
        cout << max(l[i-1], r[i+1]) << endl;
    }
    cout << l[N-2] << endl;
}

Measured memory_bytes: 3968
#include <iostream>

using namespace std;

int main() {
  while (1) {
    int x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      break;
    }

    if (x <= y) {
      cout << x << " " << y << endl;
    } else {
      cout << y << " " << x << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3040
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32


def solve(A: int, B: int):
    if(1 <= A <= 9 and 1 <= B <= 9):
        print(A*B)
    else:
        print(-1)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf LLONG_MAX

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    

    ll test=1;
    //cin>>test;
    while(test--)
    {
        ll n;
        cin>>n;

        map<string,ll> mp;
        string str;
        ll ans=0;
        for(ll i=0;i<n;i++)
        {
            cin>>str;
            if(mp[str]==0)
            {
                ans++;
                mp[str]=1;
            }
        }

        cout<<ans;
    }
}

Measured memory_bytes: 19252
#define _CRT_SECURE_NO_WARINGS
#include<iostream>
#include<iomanip>
#include<map>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<fstream>
#include<map>
#include<unordered_map>
using namespace std;
typedef int me;
typedef long long ll;
typedef unsigned long long ull;
#define andrew  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define sz(v)(int)(v.size())
#define all(v) v.begin(),v.end()
#define PI 3.1415926535
#define sin(i) (long double)sin(i*PI/180.0);
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }
void the_end() {
#ifndef ONLINE_JUDGE;
    system("pause");
#endif
}
int dy8[] = { 0,0,1,-1,1,-1,-1,1 };
int dx8[] = { 1,-1,0,0,1,-1,1,-1 };
int id8[] = { 0, 1,2,3,4, 5,6, 7 };
// you can be specialist 
// soon will be (Cyain)
ll n;
vector<ll>v;
map<int, ll>m;
ll solve(int i)
{
    if (i == 0)
        return 0;
    if (i == 1) {
        return abs(v[i] - v[i - 1]);
    }
    if (m.find(i) != m.end())
        return m[i];
    return m[i] = min(solve(i - 1) + abs(v[i] - v[i - 1]), solve(i - 2) + abs(v[i] - v[i - 2]));
}
int main()
{
    andrew;
    cin >> n;
    v.resize(n);
    for (int i = 0; i < n; i++)cin >> v[i];
    cout << solve(n-1)<< endl;
    the_end();
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main(int argc, char **argv)
{
	ll N; cin >> N;
	auto dp = make_vec<ll>(N+1, 4, 4, 4);
	dp[0][3][3][3] = 1;

	REP(n, N)
	{
		REP(a, 4)
		{
			REP(b, 4)
			{
				REP(c, 4)
				{
					REP(d, 4)
					{
						if (b == 0 && c == 2 && d == 1) continue;
						if (b == 0 && c == 1 && d == 2) continue;
						if (b == 2 && c == 0 && d == 1) continue;
						if (a == 0 && c == 2 && d == 1) continue;
						if (a == 0 && b == 2 && d == 1) continue;
						(dp[n+1][b][c][d] += dp[n][a][b][c]) %= MOD;
					}
				}
			}
		}
	}

	ll res{0};
	REP(a, 4)REP(b, 4)REP(c, 4)
		(res += dp[N][a][b][c]) %= MOD;

	std::cout << res << std::endl; 
}


Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vit vector<lint>::iterator
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define mod 1000000007
#define graph_set(n) struct edge{int to,int cost;} vector<edge> G((n))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define range(x,y) ((x) >= 0 && (x) < h && (y) >= 0 && (y) < w)
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
#define fin return 0
#define input(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
typedef vector<long long> vi;
typedef vector<pair<long long, long long>> vp;
typedef vector<vector<long long>> vvi;
typedef pair<long long, long long> pi;
typedef long long lint;
typedef long long ll;
lint qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = (ll)1e19;

int r[100], l[100];
int a, b;

#define MAX 9223372036854775807
/*********************** */

int main() {
	int a,b;cin >>  a >> b;
	if((a+b)%2==0){
	 cout << (a+b)/2 << endl;
	}else{
	cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

setrecursionlimit(10**6)

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

def answer(b):
  print("Yes" if b else "No")
  exit()

N = read()
a = reads()

d = Counter(a)
keys = list(d.keys())
keys.sort()

if len(keys) > 3:
  answer(False)

if len(keys) == 1:
  answer(keys[0] == 0)
elif len(keys) == 2:
  if keys[0] != 0:
    answer(False)
  v = keys[1]
  answer(d[0] * 2 == d[v])
else:
  assert len(keys) == 3
  v, w, x = keys
  if v ^ w == x and d[v] == d[w] == d[x]:
    answer(True)
  else:
    answer(False)



Measured memory_bytes: 14708
#include<iostream>
#include<vector>
#include <cmath>
#include <map>

using namespace std;


int main() {
	long long n;
	cin >> n;
	map<long long, long long> appear;
	map<long long, long long> ansers;
	vector<long long> a(n);

	for (long long i = 0; i < n; i++) {
		cin >> a[i];
		appear[a[i]] += 1;
	}
	for (long long i = 0; i < n; i++) {
		long long count = 0;

		if (ansers.count(appear[a[i]]) == 0) {
			appear[a[i]] -= 1;

			for (auto itr = appear.begin(); itr != appear.end(); itr++) {
				long long tmp = itr->second;
				count += tmp * (tmp - 1) / 2;
			}
			appear[a[i]] += 1;
			ansers[appear[a[i]]] = count;

		}
		else {
			count = ansers[appear[a[i]]];
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	char s[4];
	rep(i,4){
		cin>>s[i];
	}
	int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
	if(a+b+c+d==7){
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
	}
	else if(a+b+c-d==7){
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
	}
	else if(a+b-c+d==7){
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
	}
	else if(a+b-c-d==7){
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
	}
	else if(a-b+c+d==7){
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
	}
	else if(a-b+c-d==7){
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
	}
	else if(a-b-c+d==7){
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
	}
	else{
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";
	}
	re 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		int ans = 0;

		for (int i = 1; i <= N; ++i) {

			int n = i;
			int sum = 0;

			while (n > 0) {

				sum = sum + n % 10;
				n = n / 10;
			}

			if (A <= sum && sum <= B) {

				ans = ans + i;
			}

		}

		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int main()
{
	int t;
	t=1;
	while(t--)
	{
          int n;
          cin>>n;
          while(n--)
          {
          	cout<<"ACL";
          }
	}
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b)-1; i>=(a); i--)
#define debug(x) cout << #x << " => " << x << endl
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

const int MAX_N = 7 + 100000;
///----------------------------------------------
vi G[MAX_N];
int col[MAX_N];
queue<int> que;
int main() {

    ///freopen ( "xx.in" , "r" , stdin );

    ///read
    int n; cin>>n;
    rep(i,0,n) {
        int a,b; scanf("%d%d",&a,&b);
        G[a].pb(b);
        G[b].pb(a);
    }

    ///
    memset(col,-1,sizeof(col));  col[1]=1; col[n]=2;
    que.push(1); que.push(n);
    for (; !que.empty(); que.pop()) {
        int u=que.front();
        rep(i,0,sz(G[u])) {
            int v=G[u][i];
            if (~col[v]) continue;
            col[v]=col[u];
            que.push(v);
        }
    }

    ///
    int num1=0;
    rep(i,1,n) if (col[i]==1) num1++;
    int num2=n-num1;
    puts(num1>num2 ? "Fennec" : "Snuke");

}


Measured memory_bytes: 6272
"""
N, Q = map(int, input().split())
nodes = [0 for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    nodes[b] = a

counter = [0 for _ in range(N+1)]
for _ in range(Q):
    p, x = map(int, input().split())
    counter[p] += x

for i in range(1, N+1):
    counter[i] += counter[nodes[i]]

print(' '.join(map(str, counter[1:])))
"""
from collections import deque
N, Q = map(int, input().split())
counter = [0 for _ in range(N+1)]
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    counter[p] += x

que = deque()
que.append(1)
checked = [False for _ in range(N+1)]

while(que):
    v = que.pop()
    checked[v] = True
    for u in graph[v]:
        if checked[u]:
            continue
        counter[u] += counter[v]
        que.append(u)

print(' '.join(map(str, counter[1:])))

Measured memory_bytes: 135672
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	for _, x := range s {
		if x == ',' {
			x = ' '
		}
		fmt.Printf("%c", x)
	}
	fmt.Println()
}

func Min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func Max(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

llong N, M;
vector<vector<int> > s;
vector<int> p;

int solve(int now, vector<int> v) {
	if (now == N) {
		int check = 1;
		for (int i = 0; i < M; i++) {
			int sum = 0;
			for (auto x : s[i])
				sum += v[x-1];
			if (sum%2 != p[i])
				check = 0;
		}

		return check;
	}

	int res = solve(now+1, v);
	v[now] = 1;
	res += solve(now+1, v);

	return res;
}

int main() {
	cin >> N >> M;
	s.resize(M);
	p.resize(M);

	int k;
	for (int i = 0; i < M; i++) {
		cin >> k;
		s[i].resize(k);
		for (int j = 0; j < k; j++)
			cin >> s[i][j];
		sort(ALL(s[i]));
	}
	for (int i = 0; i < M; i++)
		cin >> p[i];

	vector<int> v(N, 0);
	cout << solve(0, v) << endl;
}

Measured memory_bytes: 256
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (true) {

			String data = sc.nextLine();
			if ( data.equals("0") ) break;

			int sum = 0;
			for (int i=0; i < data.length(); i++) {
				sum += Integer.parseInt( data.substring(i, i+1) );
			}

			sb.append(sum + "\n");

		}

		System.out.print(sb);
	}

}

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

int main(){
  string s,t;
  cin >> s >> t;
  int dif = 100000;
  for(int i = 0; i <= s.size() - t.size(); i++){
    int count = 0;
    for(int j = i; j < i + t.size(); j++){
      if(s[j] != t[j - i]) count++;
    }
    dif = min(count, dif);
  }
  cout << dif << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

const int INF = 1e8;

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

signed main(){
    int w, h;
    while(1){
        cin >> w >> h;
        if(w + h == 0) break;
        int wally[30][30];
        int wallx[30][30];
        rep(i, 0, 2*h - 1){
            if(i % 2 == 0){
                rep(j, 0, w - 1){
                    cin >> wally[i / 2][j];
                }
            }else{
                rep(j, 0, w){
                    cin >> wallx[i / 2][j];
                }
            }
        }
        queue<P> q;
        int y = 0, x = 0;
        q.push(P(y, x));
        int d[31][31];
        rep(i, 0, 31) rep(j, 0, 31) d[i][j] = INF;
        d[0][0] = 1;

        while(q.size()){
            P now = q.front(); q.pop();
            if(now. first == h - 1 && now . second == w - 1) break;
            rep(i, 0, 4){
                int ny = now. first + dy[i];
                int nx = now. second + dx[i];
                if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
                if(d[ny][nx] != INF) continue;
                if(i == 0 && wallx[now. first][nx]) continue;
                if(i == 1 && wallx[ny][nx]) continue;
                if(i == 2 && wally[ny][now. second]) continue;
                if(i == 3 && wally[ny][nx]) continue;
                d[ny][nx] = d[now. first][now. second] + 1;
                q.push(P(ny, nx));   
            }
        }
        cout << (d[h - 1][w - 1] == INF ? 0 : d[h - 1][w - 1]) << endl;
    }
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    for (int i = 0; i < N; i++)
    {
        cin >> P[i];
    }

    vector<int> Q(N, numeric_limits<int>::max());
    Q[0] = P[0];
    for (int i = 1; i < N; i++)
    {
        Q[i] = min(Q[i - 1], P[i]);
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (P[i] <= Q[i])
            ans++;
    }
    cout << ans << endl;

    return 0;
}

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

typedef vector<int> vi; 
typedef pair<int,int> p;
typedef long long ll;
#define F first 
#define S second 
#define PB push_back 
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define pmod 1000000007
#define INF 1000000000000000000
#define pi atan(1)*4
#define modi 1000000

ll n;
vector<ll> f(10010, 0);

ll rep(ll x, ll y, ll z){
	
	ll res = x*x + y*y + z*z + x*y + y*z + z*x;

	if(res > 10009) return 0;
	
	return res;
	
}

void solve(){
	
	cin >> n;
	
	for(ll i = 1; i <= n; i++){
		cout << f[i] << endl;
	}
	
}

int main(){
	
	ifstream fin ("text.in");
    ofstream fout ("text.out");   
	
	ll t = 1;
	
	for(ll i = 1; i <= 200; i++){
		
		for(ll i2 = 1; i2 <= 200; i2++){
			
			for(ll i3 = 1; i3 <= 200; i3++){
				
				f[rep(i,i2,i3)]++;
				
			}			
		}
	}	
		
	while(t--) solve();
	
	return 0;
}

Measured memory_bytes: 3632
arr = input().split()
arr = list(map(int, arr))
w = arr[0]
h = arr[1]
n = arr[2]

x = []
y = []
a = []
for i in range(n):
    arr = input().split()
    arr = list(map(int, arr))
    x.append(arr[0])
    y.append(arr[1])
    a.append(arr[2])

x1,x2 = 0,w
y1,y2 = h,0

for i in range(n):
    if a[i] == 1:
        if x1 <= x[i]:
            x1 = x[i]
    elif a[i] == 2:
        if x2 >= x[i]:
            x2 = x[i]
    elif a[i] == 3:
        if y2 <= y[i]:
            y2 = y[i]
    elif a[i] == 4:
        if y1 >= y[i]:
            y1 = y[i]           

if x1 <= x2 and y1 >= y2:
    print((x2-x1) * (y1-y2))
else:
    print(0)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int x,k;
    cin>>x>>k;
    cout<<max(0,x-k);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll n,k;
    cin >>n >> k;
    vector<ll> arr(n);
    for(ll i=0;i<n;i++)
    {
        cin >> arr[i];
    }
    sort(arr.begin(),arr.end());
    ll sum=0;
    for(ll i=0;i<k;i++)
    {
        sum += arr[i];
    }
    cout << sum<<"\n";
}


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

int main()
{
    int a,b,c,x,y;
    int ans = 0;
    cin >> a >> b >> c >> x >> y;
    if(a+b < 2*c)
    {
        ans = a*x+b*y;
    }
    else
    {
        int minNum = min(x,y);
        int maxNum = max(x,y);
        if(x < y)
        {
            ans += b*(y-x);
        }
        else
        {
            ans += a*(x-y);
        }
        
        ans += minNum*2*c;
        ans = min(maxNum*2*c, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n=gets.to_i
v=[*1..n]
array=v.permutation.to_a
array.sort!
first=gets.split.map(&:to_i)
second=gets.split.map(&:to_i)
i_f=array.index(first)
i_s=array.index(second)
p (i_f-i_s).abs

Measured memory_bytes: 20600
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

ll d[5];

int main(void)
{
    ll n;
    cin >> n ;

    rep(i, 5) cin >> d[i];
    ll min_num = *min_element(d, d+5);

    cout << (ll)((n + min_num - 1)/min_num + 4) << endl;
   

    
    return 0;
}

Measured memory_bytes: 256
// 長方形の面積と周の長さ
public class Hello {
    public static void Main(){
        // 1行に複数の入力値がある場合の例
        string [] inputs = System.Console.ReadLine().Split(' ');
        int a = int.Parse(inputs[0]);
        int b = int.Parse(inputs[1]);
        int c = (a * b);
        int d = (a + b) * 2;
        System.Console.WriteLine(c + " " + d);
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int H,W;
string S[2005];
int A[2005][2005],B[2005][2005];

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

    cin >> H >> W;

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

    for (int i = 0;i < H;i++){
        int sum = 0;
        int from = 0;
        int j = 0;
        while(j < W){
            if(S[i][j] == '#'){
                for (int k = from;k < j;k++){
                    A[i][k] = sum;
                }
                sum = 0;
                from = j+1;
            }else{
                sum++;
            }
            j++;
        }
        for (int k = from;k < j;k++){
            A[i][k] = sum;
        }
    }

    for (int i = 0;i < W;i++){
        int sum = 0;
        int from = 0;
        int j = 0;
        while(j < H){
            if(S[j][i] == '#'){
                for (int k = from;k < j;k++){
                    B[k][i] = sum;
                }
                sum = 0;
                from = j+1;
            }else{
                sum++;
            }
            j++;
        }
        for (int k = from;k < j;k++){
            B[k][i] = sum;
        }
    }

    int ans = 0;

    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            ans = max(ans,A[i][j]+B[i][j]-1);
        }
    }

    cout << ans << endl;

    return 0;

}

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

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	
	int c=a+b;
	int d=a-b;
	int e=a*b;
	
	printf("%d\n",max(c,max(d,e)));
	return 0;
}

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

const int N = 10 * 1000 + 20, inf = 1e9;
int dp[N], a[N], b[N], n, h;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  	cin >> h >> n;
  	for (int i = 0; i < n; i++)
      	cin >> a[i] >> b[i];
 	for (int i = 1; i <= h; i++) {
		dp[i] = inf;
      	for (int j = 0; j < n; j++) {
          	if (i - a[j] <= 0)
				dp[i] = min(dp[i], b[j]);
         	else
              	dp[i] = min(dp[i], b[j] + dp[i - a[j]]);
        }
    }
    return cout << dp[h] << "\n", 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef vector<vi> vii;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  LL a[2], b[2];
  forn(i,2) cin>>a[i];
  forn(j,2) cin>>b[j];
  LL an = -1e18 + 5;
  forn(i,2) forn(j,2) an = max(an, a[i]*b[j]);
  cout<<an<<endl;


  return 0;
}

Measured memory_bytes: 3648
use std::io::*;
use std::str::FromStr;

fn main(){
    let d: usize = read();
    let g: i64 = read();

    let mut p: Vec<i64> = vec![1;d];
    let mut c: Vec<i64> = vec![1;d];
    let mut sum: Vec<i64> = vec![0;d];

    for i in 0..d {
        p[i] = read();
        c[i] = read();
        sum[i] = p[i] * 100 * ((i+1) as i64) + c[i];
    }

    let mut ans: i64 = 1 << 32;
    for i in 0..(1<<d) {
        let mut now = 0;
        let mut mai = 0;
        for j in 0..d {
            if i & (1<<j) != 0 {
                now += sum[j];
                mai += p[j];
            }
        }
        if now >= g {
            ans = std::cmp::min(ans, mai);
        } else {
            for j in 0..d {
                if i & (1<<j) == 0 && now + sum[j] >= g {
                    let po = std::cmp::min(p[j],
                        (g-now) / (100*(j+1) as i64) + 
                        if (g-now) % (100*(j+1) as i64) != 0 {1} else {0});
                    ans = std::cmp::min(ans, mai + po);
                }
            }
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int a,p;
	int ans=0;
	cin >>a>>p;
	ans=(a*3+p)/2;
	cout<<ans<<endl;
}

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

using namespace std;

long long n, v[20][20], dp[(1 << 16)], cost[(1 << 16)];

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      cin >> v[i][j];
  }
  for (int mask = 0; mask < (1 << n); mask++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (mask & (1 << i) && mask & (1 << j))
          cost[mask] += v[i][j];
  for (int mask = 0; mask < (1 << n); mask++) {
    dp[mask] = cost[mask] / 2;
    for (int mask1 = mask; mask1 > 0; mask1 = (mask1 - 1) & mask) /// mersi Google
      dp[mask] = max(dp[mask], dp[mask1] + dp[mask ^ mask1]);
  }
  cout << dp[(1 << n) - 1];
	return 0;
}


Measured memory_bytes: 1280