akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF  = 1<<30;


struct item {
  int v, w;
  bool operator<(const item &r) const { return w < r.w; }
  void operator+=(const item &r) { w += r.w, v += r.v; }
};


vector<item> enum_powerset(const vector<item> &is) {
  vector<item> a = {{0, 0}};
  vector<item> c;
  // a.reserve(1<<sz(is));
  c.reserve(1<<sz(is));
  for (auto &i : is) {
    auto b = a;
    for (auto &e : b) e += i;
    merge(all(a), all(b), back_inserter(c));
    swap(a, c);
    c.clear();
  }
  return a;
}


int solve(const vector<item> &is, int W) {
  int n = sz(is);
  auto a = enum_powerset({is.begin(), is.begin() + n/2});
  auto b = enum_powerset({is.begin() + n/2, is.end()});
  reverse(all(a));
 
  int ans = 0;
  int vbmax = -INF;
  auto itr = b.begin();
  for (auto &[va, wa] : a) {
    while (itr != b.end() && wa + itr->w <= W) {
      chmax(vbmax, itr->v);
      ++itr;
    }
    chmax(ans, va + vbmax);
  }
  return ans;
}


int main() {
  int n; cin >> n;
  vector<item> is(n);
  for (auto &[v, w] : is) cin >> v >> w;
  is.insert(is.begin(), {0, 0});

  int q; cin >> q;
  rep(_, q) {
    int v, l; cin >> v >> l;
    vector<item> qi;
    while (v) {
      qi.push_back(is[v]);
      v /= 2;
    }
    cout << solve(qi, l) << '\n';
  }
}


Measured memory_bytes: 7380
import math
n = int(raw_input())

for i in range(n):
    xa,ya,ra,xb,yb,rb = map(float, raw_input().split())
    d = math.sqrt((xa-xb)**2+(ya-yb)**2)
    if ra+rb < d:
        print 0
    elif ra >= rb:
        if d+rb < ra:
            print 2
        else:
            print 1
    elif ra < rb:
        if d+ra < rb:
            print -2
        else:
            print 1

Measured memory_bytes: 4384
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int max = scan.nextInt();
        int range = scan.nextInt();
        int dif = 0, count = 0, sum = 0;
        
	while((sum <= range) && (count < max)){
	    count++;
	    dif = scan.nextInt();
	    sum += dif;
	}
	if(sum <= range){
	    count++;
	}
	/*do{
            count += 1;
	    if (count <= max){
	        dif = scan.nextInt();
	    }
	    sum += dif;
        }while((count <= max) && (sum <= range));*/
	System.out.print(count);
    }
}


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

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

next = 0
visited = [False] * N
cnt = 0
while(True):
    if visited[next]:
        cnt = -1
        break
    if next == 1:
        break
    visited[next] = True
    next = A[next] -1
    cnt += 1
print(cnt)



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

// #parameter{
#ifdef _DEBUG

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

#else

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

#endif

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

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

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

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

	int r, D, x;
	scanf("%d %d %d", &r, &D, &x);
	for (int i = 1; i <= 10; i++) {
		x = r * x - D;
		printf("%d\n", x);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define ll long long
    #define ld long double
    using namespace std;
     
    int main()
    {
        int n;
        cin>>n;
        ll a[n],b[n];
        for(int  i = 0; i < n; i++) cin>>a[i]>>b[i];

        ll x = a[0],y = b[0];
        for(int i = 1; i < n; i++)
        {
            ll q  = max(ceil((ld) x/ a[i]) , ceil((ld) y/ b[i]));

            x = a[i]*q ; y = b[i]*q;
        }

        cout<<x+y<<"\n";
      return 0;
    }

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

int main (){
    string s1,s2;cin>>s1>>s2;
	if(s1==s2) {
		cout<<"Yes"<<endl;
		return 0;
	}
	int sz=(int)s1.size();
	for(int i=0;i<sz;i++){
	   char ss=s1[sz-1];
	   auto it = s1.end();
	   it--;
	   s1.erase(it);
	   s1=ss+s1;
	   if(s1==s2) { cout<<"Yes"<<endl;return 0;}
	}
	cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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 T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


bool check(int H,int W,vector<int> &alph){
  // H,W がともに偶数のときは4つの塊のみ
  // H,W の片方が偶数のときは4つの塊の他に2つの塊が偶数のやつ/2個存在
  // H,W がともに奇数のときは2つの塊がH/2+W/2個、1つが1個ある
  int not2 = 0;
  int not4 = 0;
  rep(i, alph.size()){
    if (alph[i]%2 != 0) not2++;
    else if (alph[i]%4 != 0) not4++;
  }
  if (H%2 == 0 && W%2 == 0){
    if (not2 > 0) return false;
    if (not4 > 0) return false;
    return true;
  }else if (H%2 == 0 || W%2 == 0){
    if (not2 > 0) return false;
    if (H%2==0 && not4 > H/2) return false;
    if (W%2==0 && not4 > W/2) return false;
    return true;
  }else{
    if (not2 > 1) return false;
    if (not4 > H/2+W/2) return false;
    return true;
  }
}

int main() {
  int H,W; cin >>H >>W;
  vector<int> alph(26);
  rep(i, H){
    string s; cin >>s;
    rep(j, W) alph[s[j]-'a']++;
  }
  cout <<(check(H,W,alph) ? "Yes" : "No") <<endl;
}


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

struct UnionFind {
  vector<int> par;

  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void merge(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }

  bool is_same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

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

  UnionFind tree(N);
  for (int i = 0; i < M; i++) {
    int x, y; cin >> x >> y; x--; y--;
    tree.merge(x, y);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int root = tree.root(P[i]);
    if (tree.is_same(root, i)) ans++;
  }

  cout << ans << endl;

}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
 
class Program
{
    static void Main()
    {
        var nq = ReadLine().Split().Select(int.Parse).ToArray();
        var n = nq[0];
        var q = nq[1];
        var c = 1;
        for (int i = 1; i < n; i <<= 1)
        {
            c = i;
        }
        c <<= 1;
 
        var s = new SegTree(c);
        for (int i = 0; i < q; i++)
        {
            var line = ReadLine().Split().Select(int.Parse).ToArray();
            if (line[0] == 0) s.Update(line[1], line[2]);
            else WriteLine(s.Query(line[1], line[2] + 1));
        }
    }
}
 
public class SegTree
{
    int[] buffer;
    int N;
 
    public SegTree(int cap)
    {
        buffer = new int[cap * 2 - 1];
        for (int i = 0; i < buffer.Length; i++)
        {
            buffer[i] = int.MaxValue;
        }
        N = cap;
    }
 
    public void Update(int index, int value)
    {
        index += N - 1;
        buffer[index] = value;
        while (index > 0)
        {
            index = (index - 1) / 2;
            buffer[index] = Math.Min(buffer[index * 2 + 1], buffer[index * 2 + 2]);
        }
    }
 
    public int Query(int l, int r)
    {
        var y = int.MaxValue;
        l += N - 1;
        r += N - 1;
        while (l < r)
        {
            if ((l & 1) == 0)
            {
                y = Math.Min(y, buffer[l]);
            }
            if ((r & 1) == 0)
            {
                y = Math.Min(y, buffer[r - 1]);
            }
            l /= 2;
            r = (r - 1) / 2;
        }
        return y;
    }
}


Measured memory_bytes: 23040
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> a;
    for (int i = 0; i < h; ++i) {
        string tmp;
        cin >> tmp;
        if (tmp.find("#") != string::npos)
            a.push_back(tmp);
    }

    vector<int> ignore_columns;
    for (int col = 0; col < w; ++col) {
        bool only_white = true;
        for (int row = 0; row < a.size(); ++row) {
            if (a[row][col] == '#') {
                only_white = false;
                break;
            }
        }
        if (!only_white)
            ignore_columns.push_back(col);
    }

    for (int i = 0; i < a.size(); ++i) {
        for (int j = 0; j < w; ++j) {
            if (find(ignore_columns.begin(), ignore_columns.end(), j) !=
                ignore_columns.end())
                cout << a[i][j];
        }
        cout << '\n';
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	 static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
	 static int divisors(long x) {
		    long limit = x;
		    int numberOfDivisors = 0;

		    if (x == 1) return 1;

		    for (int i = 1; i < limit; ++i) {
		        if (x % i == 0) {
		            limit = x / i;
		            if (limit != i) {
		                numberOfDivisors++;
		            }
		            numberOfDivisors++;
		        }
		    }

		    return numberOfDivisors;
		} 
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		int k = s.nextInt();
		String x = s.next();
		if(x.length()<=k) {
			for(int i=0;i<x.length();i++) {
				System.out.print(x.charAt(i));
			}
		}
		if(x.length()>k) {
			for(int i=0;i<k;i++) {
				System.out.print(x.charAt(i));
			}
			System.out.println("...");
		}
	}
}

Measured memory_bytes: 32848
#include <stdio.h>
#include <stdlib.h>

int compar(const int *val1,const int *val2){
    return *val1-*val2;
}
int main(void){
    int map[4]={0},i;
    for(i=0;i<4;i++)
        scanf("%d",&map[i]);
    qsort(map,4,sizeof(int),(int(*)(const void *,const void *))compar);
   if(map[0] == map[1] && map[2] == map[3])
       printf("yes\n");
   else
       printf("no\n");
   return 0;
}

Measured memory_bytes: 584
#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vec(i) vector<i>
#define all(c) c.begin(), c.end()
#define FOR(i, s, e) for(int i=s; i<e; i++)
#define mod 1000000007LL
#define endl "\n"

template <typename T> void print(T v);
template <typename T> void print(vector<T> a);

void solve()
{
    ll a, b, c, d;
    cin>>a>>b>>c>>d;

    print(max(a*c, max(a*d, max(b*c, b*d))));
}

int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t=1;
while(t--)solve();
return 0;
}
template <typename T>
void print(T v){
    cout<<v<<"\n";
}
template <typename T>
void print(vector<T> a){
    FOR(i, 0, a.size()){
        cout<<a[i]<<" ";
    }cout<<"\n";
}

Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<cmath>

int const MAXN = 50;

int x[MAXN], y[MAXN], N;


int main() {
  std::cin >> N;
  double cx = 0.0, cy = 0.0;
  for(int i = 0; i < N; ++i) {
    std::cin >> x[i] >> y[i];
    cx += x[i]; cy += y[i];
  }
  cx /= N; cy /= N;
  double ans2;
  for(double lr=0.1; lr > 1e-9; lr*=0.999) {
    int mI = 0;
    double dx = x[mI] - cx, dy = y[mI] - cy;
    double mD2 = dx*dx + dy*dy;
    for(int i = 1; i < N; ++i) {
      dx = x[i] - cx; dy = y[i] - cy;
      double d2 = dx*dx + dy*dy;
      if(d2 > mD2) { mI = i; mD2 = d2; }
    }
    cx += (x[mI]-cx)*lr;
    cy += (y[mI]-cy)*lr;
    ans2 = mD2;
  }
  std::cout << std::setprecision(10) << std::fixed << std::sqrt(ans2) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{	char s;
    int sum = 0;
    for(int i=0; i<5; i++){
        scanf("%c", &s);
        if(s == '+')
            sum++;
        else if(s == '-')
            sum--;
    }printf("%d\n", sum);
    return 0;
}

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

int main(){
int A,B,C,X;
  cin>>A>>B>>C>>X;
  
  int ans=0;
  for(int i=0; i<=A; i++){
   for(int j=0; j<=B; j++){
    for(int k=0; k<=C; k++){
     if(500*i+100*j+50*k==X){
      ans++;
     }
    }
   }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define ll long long
#define int long long
using namespace std;
const int maxn = 500010, inf = 1e9 + 233;

template<typename T>
inline void read(T &k)
{
	int f = 1; k = 0; char c = getchar();
	while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
	while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
	k *= f;
}

signed main()
{
	int K, A, B;
	read(K); read(A); read(B);
	if (B - A <= 2) printf("%lld\n", 1 + K);
	else
	{
		if (K + 1 <= A) printf("%lld\n", 1 + K);
		else
		{
			K -= A - 1;
			int ans = A;
			if (K & 1) K--, ans++;
			ans += K / 2 * (B - A);
			printf("%lld\n", ans);
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
  int n, k, q; cin >> n >> k >> q;
  for (int i = 0; i < q; i++) {
    int t; cin >> t;
    a[t]++;
  }
  for (int i = 1; i <= n; i++) {
    if (q - a[i] >= k) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
mint dp[61][2][2][2];
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    ll l, r; cin >> l >> r;
    dp[60][0][0][0] = 1;
    for (int i = 59; i >= 0; i--) {
        bool lb = l>>i & 1, rb = r>>i & 1;
      rep(a,2)rep(b,2)rep(c,2){
        mint pre = dp[i+1][a][b][c];
        rep(x,2)rep(y,2){
          int na = a, nb = b, nc = c;
          if (x && !y)continue;
          if (!c && x != y)continue;
          if (x && y)nc = 1;
          if (lb && !a && !x)continue;
          if (!lb && x)na = 1;
          if (!rb && y && !b)continue;
          if (rb && !y)nb = 1;
          dp[i][na][nb][nc] += pre;
        }
      }
    }
    mint ans;
    rep(i,2)rep(j,2)rep(k,2) ans += dp[0][i][j][k];
    cout << ans.x << endl;
}




Measured memory_bytes: 256
N = int( input())
A = list( map( int, input().split()))
L = [0] * N

for a in A:
  L[ a - 1 ] += 1

s = 0
for i in range( N ):
  l = L[ i ]
  if l > 0:
    s += ( l - 1 ) * l // 2

for i in range( N ):
  print( s - ( L[ A[ i ] - 1 ] - 1 ))

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

using ll = long long;
using ull = unsigned long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define bzero(p, n) memset(p, 0, n)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

struct pair_ii_hash {
    inline size_t operator()(const pair<int,int> & p) const{
        const auto a = hash<int>()(p.first);
        const auto b = hash<int>()(p.second);
        return a ^ (b << 1);
    }
};

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N, M; cin >>N >>M;
    vector<pair<int, int>> PY(M);
    vector<int> PY_sorted_i(M);
    rep(i, M) {
        cin >> PY[i].first >> PY[i].second;
    }
    iota(all(PY_sorted_i), 0);
    sort(all(PY_sorted_i), [&](int a, int b) { return PY[a] < PY[b]; });

    //map<pair<int, int>, int> x_map;
    unordered_map<pair<int, int>, int, pair_ii_hash> x_map;
    int P_prev = -1;
    int x;
    rep(i, M) {
        const pair<int, int>& py = PY[PY_sorted_i[i]];
        //cout << FMT2(py.first, py.second) << endl;
        if (py.first != P_prev) {
            x = 1;
        } else {
            x++;
        }
        x_map.emplace(py, x);
        P_prev = py.first;
    }

    rep(i, M) {
        //printf("%06d%06d\n", PY[i].first, x_map[PY[i]]);
        cout << setw(6) << setfill('0') << PY[i].first  << setw(6) << setfill('0') << x_map[PY[i]] << endl;
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)

int M = 1000005;

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

  vector<int> Ai(N);
  vector<int> nums(M+1);
  rep(i,N){
    cin >> Ai.at(i);
  }

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

  for(int a : Ai){
    if(nums.at(a) != 0){
      nums.at(a) = 2;
      continue;
    }
    for(int i = a; i < M; i+=a){
      nums.at(i) = 1;
    }
  }

  int ans = 0;

  for(int a : Ai){
    if(nums.at(a)==1) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 8020
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

int main() {
    
    
    int n,i,j;
    
    cin>>n;
    
    vector<int> v;
    
    v.push_back(1);
    
    int t = 6;
    
    while( t <= n ){
        v.push_back(t);
        t *= 6;
    }
    
    t = 9;
    while( t <= n ){
        v.push_back(t);
        t *= 9;
    }
    
    sort(v.begin(),v.end());
    
    int s = v.size();
    
    int dp[n+1];
    
    for(i=0;i<=n;i++) dp[i] = INT_MAX;
    
    dp[0] = 0;
    for(i=1;i<=n;i++){
        for(j=0;v[j]<=i;j++){
            dp[i] = min(dp[i],dp[i-v[j]]+1);
        }
    }
    
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	var n, sum int64
	_, _ = fmt.Scanf("%d", &n)
	mountens := readInt64Slice()
	isSee := true
	for key, val := range mountens {
		if key == 0 {
			sum++
			continue
		}
		for i := 0; i < key; i++ {
			if mountens[i] > val {
				isSee = false
				break
			}
		}
		if isSee {
			sum++
		}
		isSee = true
	}
	fmt.Println(sum)
}

func readInt64Slice() []int64 {
	line := readStringSlice()
	slice := make([]int64, 0, len(line))
	for _, tmp := range line {
		val, err := strconv.ParseInt(tmp, 10, 64)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		slice = append(slice, val)
	}
	return slice
}
func readFloat64Slice() []float64 {
	line := readStringSlice()
	slice := make([]float64, 0, len(line))
	for _, tmp := range line {
		val, err := strconv.ParseFloat(tmp, 64)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		slice = append(slice, val)

	}
	return slice
}
func readString() string {
	s, _, _ := in.ReadLine()
	return string(s)
}
func readStringSlice() []string {
	line := readString()
	s := strings.Split(line, " ")
	return s
}
func dump(value ...interface{}) {
	for _, v := range value {
		fmt.Printf("%#v\n", v)
	}
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;
#define N 3030
int i,l,n;
long long v[N],a[N][N][2],x,y,z,t;
int main()
{
    cin >> n;
    for (i = 0; i < n; ++i)
        cin >> v[i];
    if (n == 1){
        cout << v[0];
        return 0;
    }
    for (i = 0; i < n; ++i)
        a[i][i][n & 1] = v[i];
    for (l = 1; l < n; ++l){
        for (i = 0; i + l < n; ++i){
            if ((n - l) & 1){
                x = v[i] + a[i + 1][i + l][1];
                y = a[i + 1][i + l][0];
                z = v[i + l] + a[i][i + l - 1][1];
                t = a[i][i + l - 1][0];
                if (x > z){
                    a[i][i + l][0] = y;
                    a[i][i + l][1] = x;
                }
                else{
                    a[i][i + l][0] = t;
                    a[i][i + l][1] = z;
                }
            }
            else{
                x = v[i] + a[i + 1][i + l][0];
                y = a[i + 1][i + l][1];
                z = v[i + l] + a[i][i + l - 1][0];
                t = a[i][i + l - 1][1];
                if (x > z){
                    a[i][i + l][1] = y;
                    a[i][i + l][0] = x;
                }
                else{
                    a[i][i + l][1] = t;
                    a[i][i + l][0] = z;
                }
            }
        }
    }
    cout << a[0][n - 1][1] - a[0][n - 1][0];
    return 0;
}


Measured memory_bytes: 143616
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int n, m;
	cin >> n >> m;
	int a[50], b[50], c[50], d[50];
	rep(i, n) cin >> a[i] >> b[i];
	rep(i, m) cin >> c[i] >> d[i];
	rep(i, n){
		int min_dist = abs(a[i] - c[0]) + abs(b[i] - d[0]), cnt = 1;

		for(int j = 1; j < m; ++j){
			int man_dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if(min_dist > man_dist){
				min_dist = man_dist;
				cnt = j + 1;
			}
		}
		cout << cnt << endl;
	}
}


Measured memory_bytes: 256
N,K,S=map(int,input().split())
l=[]
if S==10**9:
    buf=[S]*K
    l.extend(buf)
    buf=[1]*(N-K)
    l.extend(buf)
else:
    buf = [S] * K
    l.extend(buf)
    buf = [10**9] * (N - K)
    l.extend(buf)
print(*l,sep=" ")

Measured memory_bytes: 47036
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int max = 0;
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for (int left = 0; left <= n && left <= k; left++) {
            for (int right = 0; left + right <= n && left + right <= k; right++) {
                for (int i = 0; i < left; i++) {
                    queue.add(arr[i]);
                }
                for (int i = 0; i < right; i++) {
                    queue.add(arr[n - i - 1]);
                }
                for (int i = 0; i < k - left - right && queue.size() > 0 && queue.peek() < 0; i++) {
                    queue.poll();
                }
                int sum = 0;
                while (queue.size() > 0) {
                    sum += queue.poll();
                }
                max = Math.max(max, sum);
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 37404
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
 
const int N = (int)5e5 + 5;
const int inf = (int)1e9 + 7;
 
vector<int> t[4 * N];
int n, q, a[N], b[N];
 
void build(int v, int tl, int tr) {
	if (tl == tr) {
		t[v].push_back(b[tl]);
	} else {
		int tm = tl + tr >> 1;
		build(2 * v, tl, tm);
		build(2 * v + 1, tm + 1, tr);
		merge(t[2 * v].begin(), t[2 * v].end(), t[2 * v + 1].begin(), t[2 * v + 1].end(), back_inserter(t[v]));
	}
}
 
int query(int v, int tl, int tr, int l, int r, int up) {
	if (l > r) return 0LL;
	if (l == tl && r == tr) {
		auto let = upper_bound(t[v].begin(), t[v].end(), up);
		return (int)(t[v].end() - let);
	} else {
		int tm = tl + tr >> 1;
		return query(2 * v, tl, tm, l, min(tm, r), up) + query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, up);
	}
}
				
int32_t main() {
	fast_cin();  
 
	cin >> n >> q;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	map<int, int> last;
	for (int i = n; i >= 1; i--) {
		if (last.find(a[i]) != last.end()) {
			b[i] = last[a[i]];
			last[a[i]] = i;
		} else {
			b[i] = inf;
			last[a[i]] = i;
		}
	}
	// for (int i = 1; i <= n; i++)
	// 	cout << b[i] << " ";
	// cout << endl; 
	build(1, 1, n);
	while (q--) {
		int l, r; cin >> l >> r;
		int ans = query(1, 1, n, l, r, r);
		cout << ans << endl;
	}
	return 0;

}
	

Measured memory_bytes: 192060
n, m = map(int, input().split())
mat = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    mat[a].append(b)
    mat[b].append(a)

ans = 0
def dfs(visited, current):
    global ans
    if len(visited) == n:
        ans += 1
        return
    for nex in mat[current]:
        if nex not in visited:
            _vi = visited[:]
            _vi.append(nex)
            dfs(_vi, nex)

dfs([0], 0)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
deque<char> Q;
int rev;
int main()
{
	string s;
	cin >> s;
	for(auto v : s) Q.push_back(v);
	int q;
	cin >> q;
	while(q--)
	{
		int op, typ;
		cin >> op;
		if(op == 1) rev ^= 1;
		else
		{
			cin >> typ >> s;
			--typ;
			typ ^= rev;
			if(typ == 0) Q.push_front(s[0]);
			else Q.push_back(s[0]);
		}
	}
	if(rev) reverse(Q.begin(), Q.end());
	while(!Q.empty())
	{
		printf("%c", Q.front());
		Q.pop_front();
	}
	return 0;
}

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

int main(){
    long n;
    cin >> n;
    vector<long> ss(n+1, 0);
    for (long i = 0; i < n-1; i++)
    {
        long s = i + 1;
        long b;
        cin >> b;
        ss[b] ++;
    }
    for (long i = 1; i<= n; i++)
        cout << ss[i] << "\n";
    return 0;
}

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

int main() {
  int n, i;
  cin >> n;
  
  vector<int> h(n);
  for(i = 0; i < n; i++){
    cin >> h.at(i);
  }
  
  int keep = h.at(0);
  bool ans = true;
  for(i = 1; i < n; i++){
    if(keep > h.at(i) + 1) ans = false;
    keep = max(keep, h.at(i));
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll A;
	cin >> A;
	string B;
	cin >> B;
	ll S = 0;
	ll F = 0;
	bool found = false;
	for (int i = 0; i < (int) B.size(); i++) {
		if (!found) {
			if (B[i] != '.') {
				S*=10LL;
				S += B[i] - '0';
			} else {
				found = true;
			}
		} else {
			F*=10LL;
			F += B[i] - '0';
		}
	}
	cout << A * (100LL*S + F) / 100LL << endl;
}



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

int main()
{
	int n;
	cin >> n;
	string s1,s2;
	cin >> s1 >> s2;
	for(int i = 0; i < n; i++){
		cout << s1[i] << s2[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;


int main(){
    int H,W,h,w;cin>>H>>W>>h>>w;
    
    if(H%h==0&&W%w==0)printf("No\n");
    else{
        int big=999999937;
        int small=(big/(h*w-1)+1)*(-1);
        
        printf("Yes\n");
        for(int i=0;i<=H-1;i++){
            for(int j=0;j<=W-1;j++){
                if(i%h==0&&j%w==0)printf("%d",big);
                else printf("%d",small);
                if(j!=W-1)printf(" ");
            }
            printf("\n");
        }
        
    }
    
    return 0;
}




Measured memory_bytes: 2816
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double p[10];
double q[10];
double f(double x){
	double ret=0;
	for(int i=0;i<6;i++){
		ret+=max(x*p[i],(1-x)*q[i]);
	}
	return ret;
}
int main(){
	for(int i=0;i<6;i++){
		int t;scanf("%d",&t);
		p[i]=0.01*t;
	}
	for(int i=0;i<6;i++){
		int t;scanf("%d",&t);
		q[i]=0.01*t;
	}
	double ret=1;
	double left=0;
	double right=1;
	for(int i=0;i<100;i++){
		double m1=left*2/3+right/3;
		double m2=left/3+right*2/3;
		double L=f(m1);
		double R=f(m2);
		if(L>R){
			left=m1;
		}else{
			right=m2;
		}
		ret=min(ret,min(L,R));
	}
	printf("%.12f\n",ret);
}

Measured memory_bytes: 128
double p;
drawKoch(int level, double x1, double y1, double x2, double y2){
	if(level==0){printf("%f %f\n",x2,y2);return;}
	double x_first=(x1*2+x2)/3,x_second=(x1+x2*2)/3,y_first=(y1*2+y2)/3,y_second=(y1+y2*2)/3;
	double x_third=(x_second-x_first)*cos(p/3)-(y_second-y_first)*sin(p/3)+x_first;
	double y_third=(x_second-x_first)*sin(p/3)+(y_second-y_first)*cos(p/3)+y_first;
	drawKoch(level-1,x1,y1,x_first,y_first);
	drawKoch(level-1,x_first,y_first,x_third,y_third);
	drawKoch(level-1,x_third,y_third,x_second,y_second);
	drawKoch(level-1,x_second,y_second,x2,y2);
}
main(n){p=atan2(1,0)*2;scanf("%d",&n);puts("0 0");drawKoch(n,0,0,100,0);exit(0);}

Measured memory_bytes: 648
import java.util.Scanner;


public class Main {
	
	int w, h;
	char[][] map;
	
	int count;
	
	void dfs(int x, int y) {
		int[] dx = new int[]{0, 0, -1, 1};
		int[] dy = new int[]{1, -1, 0, 0};
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (0 <= nx && nx < w && 0 <= ny && ny < h && map[ny][nx] == '.') {
				map[ny][nx] = '#';
				count++;
				dfs(nx, ny);
			}
		}
	}
	
	int solve() {
		count = 1;
		for (int y = 0; y < h; y++) {
			for (int x = 0; x < w; x++) {
				if (map[y][x] == '@') {
					dfs(x, y);
				}
			}
		}
		return count;
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		String output = "";
		while (sc.hasNext()) {
			w = sc.nextInt();
			h = sc.nextInt();
			if (w == 0 && h == 0) {
				break;
			} else {
				sc.skip("\n");
				map = new char[h][];
				for (int i = 0; i < h; i++) {
					String row = sc.nextLine();
					map[i] = row.toCharArray();
				}
				output += solve() + "\n";
			}
		}
		sc.close();
		System.out.print(output);
	}

	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 37024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    int n,m;
    cin>>n>>m;
    int ans = n*(n-1)/2 + m*(m-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int S[100000],T[100000],c,b,i,j,mid,count=0;
  double left,right;
  
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&c);
  for(i=0;i<c;i++){
    scanf("%d",&T[i]);
  }

  
  
 
  for(i=0;i<c;i++){
    right=b;
    left=0;

    
    while(left<=right){
      mid=(left+right)/2;
      
      if(S[mid]==T[i]){
        count++;
        break;
      }
     else if (T[i] > S[mid]) {
      left = mid+1; 
    } else {
      right = mid-1; 
     }
  }
  }

  
  printf("%d\n",count);

  

  return 0;
}



Measured memory_bytes: 2324
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmpintU(const void *a, const void *b) { return *(char *)a - *(char *)b; }
int cmpintD(const void *a, const void *b) { return *(char *)b - *(char *)a; }
int main() {
	char s[101], t[101];
	scanf("%s%s", s, t);
	qsort(s, strlen(s), sizeof(char), cmpintU);
	qsort(t, strlen(t), sizeof(char), cmpintD);
	if (strcmp(s, t) < 0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int i,j,minj,temp,count,N;
  int A[100];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj])minj=j;
    }
        temp=A[i];
        A[i]=A[minj];
        A[minj]=temp;
        if(i!=minj)count++;
    }
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
printf("\n%d\n",count);
return 0;
}



Measured memory_bytes: 2044
a, b, h, m = gets.split(" ").map(&:to_i)

rm = Rational(m, 60)
rh = Rational(h, 12) + rm / 12

sinh = Math.sin(rh.to_f * 2 * Math::PI) * a
cosh = Math.cos(rh.to_f * 2 * Math::PI) * a
sinm = Math.sin(rm.to_f * 2 * Math::PI) * b
cosm = Math.cos(rm.to_f * 2 * Math::PI) * b

puts Math.hypot((sinh - sinm), (cosh - cosm))


Measured memory_bytes: 14688
s = input()
if int(s) < 10: print(s); exit()

ans = -1
for i in range(len(s)):
    t = s[:i]
    NINE = (len(s)-len(t))
    SUB = 0
    t+= '9' * NINE
    if int(s) < int(t): SUB = int('1' + '0' * NINE)
    t = max(int(t) - SUB, 0)
    ans = max(ans, sum(int(c) for c in str(t)))
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;


public class Main {
	public static int partition(int[] arr, int p, int r) {
		int x = arr[r];
		int i = p - 1;
		for (int j = p; j < r; j++) {
			if (arr[j] <= x) {
				int a = arr[++i];
				arr[i] = arr[j];
				arr[j] = a;
			}
		}
		int a = arr[i + 1];
		arr[i + 1] = arr[r];
		arr[r] = a;
		return i + 1;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int index = partition(arr, 0, n - 1);
		for (int i = 0; i < n; i++) {
			if (i == index) {
				System.out.print("[" + arr[i] + "] ");
			} else if (i == n - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		}
	}
}


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

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

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var N int

	var sdn []int

	fmt.Scanf("%d", &N)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	dn := scanner.Text()
	dn = strings.TrimSpace(dn)

	dnn := strings.Fields(dn)

	for j := range dnn {
		var iparam int
		iparam, _ = strconv.Atoi(dnn[j])
		sdn = append(sdn, iparam)
	}

	sum := 0

	for i := 0; i < (N - 1); i++ {
      for k := i+1; k < N; k++ {
			sum += sdn[i] * sdn[k]
		}
	}

	fmt.Printf("%d\n", sum)
}


Measured memory_bytes: 640
W,H,N = map(int,input().split())
X1 = W
X2 = 0
Y1 = H
Y2 = 0
for _ in range(N):
    x,y,a = map(int,input().split())
    if a==1:
        X2 = max(X2,x)
    elif a==2:
        X1 = min(X1,x)
    elif a==3:
        Y2 = max(Y2,y)
    elif a==4:
        Y1 = min(Y1,y)
if X2>=X1 and Y2>=Y1:
    ans = 0
elif X2>=X1 and Y2<Y1:
    ans = 0
elif X2<X1 and Y2>=Y1:
    ans = 0
elif X2<X1 and Y2<Y1:
    ans = (X1-X2)*(Y1-Y2)
print(ans)

Measured memory_bytes: 38256
import math,fractions
A,B,C,D=map(int,input().split())
E=C*D//fractions.gcd(C,D)

ac=(A-1)//C
ad=(A-1)//D
bc=B//C
bd=B//D
ae=(A-1)//E
be=B//E

s= bc-ac
t= bd-ad
u= be-ae

print(B-A+1 - s -t +u)


Measured memory_bytes: 5176
package main

import (
	"fmt"
	"math"
)

func stdinput() (int, int) {
	var A, B int
	fmt.Scan(&A, &B)
	return A, B
}
func main() {
	a, b := stdinput()
	aMin := int(math.Ceil(float64(a) * 100.0 / 8.0))
	aMax := (a + 1) * 100 / 8
	bMin := b * 10
	bMax := (b + 1) * 10
	if aMin >= bMax {
		fmt.Println(-1)
	} else if aMax <= bMin {
		fmt.Println(-1)
	} else if aMin < bMin {
		fmt.Println(bMin)
	} else {
		fmt.Println(aMin)
	}

}

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

int main() {
  
  int a;
  cin >> a;
  
  if(a==7 || a==5 || a==3) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  if(n == m) cout << "Yes" << endk;
  else cout << "No" << endk;
  return 0;
}


Measured memory_bytes: 3636
//सत्यान्न प्रमदितव्यम्  ||
//Still, Taking my time to perfect the beats
//And I still got love for the streets, it's the A-D-D-U
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define nt _int128
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debugged cout<<"debugged\n";
#define inf 0x3f3f3f3f
#define LINF  0x3f3f3f3f3f3f3f3fll
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end() 
 
const ll mod = 999983;
#define mx 1000005
const ll mxi = 105;

using namespace __gnu_pbds;
#define ordered_set tree<pair<ll, ll>, null_type,less<pair<ll, ll>>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    fast_as_levi;
    ll a,b;
    cin>>a>>b;
    cout<<a*b;
}

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

int N;
int m[16][16];
int m2[16][16];
int maxi = 0;

void f(int I, int ANS)
{
    if (I == N) {
        rep(i, N) {
            rep(j, N) {
                if (m[i][j] == 1 && m[j][j] == -2) {
                    goto lend;
                } else if (m[i][j] == 0 && m[j][j] == -1) {
                    goto lend;
                }
            }
        }
        if (ANS > maxi) maxi = ANS;
    lend:
        do { } while (0);
        
    } else {
        f(I+1, ANS);
        rep(i, 16) m[I][i] = -2;
        f(I+1, ANS - 1);
        rep(i, 16) m[I][i] = m2[I][i];
    }
}

int main()
{
    cin >> N;
    rep(i, N) {
        rep(j, N) {
            m[i][j] = -1;
            m2[i][j] = -1;
        }
    }
    rep(i, N) {
        int A;
        cin >> A;
        rep(j, A) {
            int x, y;
            cin >> x >> y;
            m[i][x - 1] = y;
            m2[i][x - 1] = y;
        }
    }
    f(0, N);

    cout << maxi << endl;
    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll p = 0;
  REP(i, n) {
    if (s[i] == '1') {
      p++;
    }
  }

  if (p == 0) {
    REP(i, n) { cout << 1 << endl; }
    return 0;
  }

  // p >= 1
  vector<ll> f(p + 1, 0);
  // p以下になる
  FOR(i, 1, p + 1) {
    ll t = i;
    ll c = 0;
    REP(j, 20) {
      if ((1LL << j) & t) {
        c++;
      }
    }
    f[i] = 1 + f[t % c];
  }

  ll x1 = 0, power2p = 1;
  vector<ll> ans(n, 0);

  // x % p+1
  IREP(i, n) {
    if (s[i] == '1') {
      (x1 += power2p) %= p + 1;
    }
    (power2p *= 2) %= p + 1;
  }

  ll c = 1;
  IREP(i, n) {
    if (s[i] == '0') {
      ll idx = (x1 + c) % (p + 1);
      ans[i] = f[idx] + 1;
    }
    (c *= 2) %= p + 1;
  }

  if (p == 1) {
    REP(i, n) { cout << ans[i] << endl; }
    return 0;
  }

  // x % p-1
  ll x2 = 0;
  c = 1;
  ll power2n = 1;
  IREP(i, n) {
    if (s[i] == '1') {
      (x2 += power2n) %= p - 1;
    }
    (power2n *= 2) %= p - 1;
  }
  IREP(i, n) {
    if (s[i] == '1') {
      ll idx = (x2 - c + p - 1) % (p - 1);
      ans[i] = f[idx] + 1;
    }
    (c *= 2) %= p - 1;
  }

  REP(i, n) { cout << ans[i] << endl; }
}

Measured memory_bytes: 5860
n=int(input())
a=1
b=1
for i in range(n):
    ti,ai=map(int,input().split())
#    m=max(int((a-1)/ti)+1,int((b-1)/ai)+1)
    m=max(int((a-1)//ti)+1,int((b-1)//ai)+1)
    a=m*ti
    b=m*ai
print(a+b)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
/*cout <<setprecision(11)<<ret<<endl;で、数字部分を計11桁表示*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//Shift+Command+bでデバッグ
//その後ターミナルで./a.outを実行
//入力を貼り付ける

//////////////////
//  A
/*int main(void){
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;

    int ret=(m2-m1)+(h2-h1)*60-k;
    cout<<ret<<endl;
    return 0;
}*/
//////////////////
//  B
int main(void){
    string t;cin>>t;
    for(int i=0;i<t.length()-1;i++){
        if(t[i]=='?'){
            //if(t[i+1]=='D') cout<<'P';
            //else cout<<'D';
            cout<<'D';
        }else{
            cout<<t[i];
        }
    }
    if(t[t.length()-1]=='?') cout<<'D'<<endl;
    else cout<<t[t.length()-1]<<endl;

    return 0;
}
//////////////////
//  C
/*int main(void){

    return 0;
}*/
//////////////////
//  D
/*int main(void){

    return 0;
}*/
//////////////////
//  E
/*int main(void){

    return 0;
}*/
//////////////////
//  F
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 3488