akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
Created on Sat May 30 18:26:16 2020

@author: Tofu
"""
import math 
def clock(A,B,H,M):
    
    #print(N)
    #print(A,B,H,M)
    #print(string)
    short_hand = H*360/12+M*360/(60*12)
    long_hand = M*360/60
    #print(short_hand,long_hand)
    diff1 = short_hand - long_hand
    diff2 = 360 - diff1
    if diff1 > diff2:
        diff = diff2
    else:
        diff = diff1
    
    #print(diff)
    rad = math.radians(diff)
    #'{:.025f}'.format(rad)
    #print(rad)
    
    #format(rad,'.30g')
    cos = math.cos(rad)
    #print(cos)
    #format(cos,'.30g')
    C = math.sqrt(A*A+B*B-2*A*B*cos)
    #format(C,'.30g')
    
    #print(C)
    return C
if __name__ == '__main__':
    A,B,H,M = input().split()
    A = float(A)
    B = float(B)
    H = float(H)
    M = float(M)
    ans = clock(A,B,H,M)
    print(ans)
    

Measured memory_bytes: 9364
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
   int n,m; cin >> n >> m;
   vector<int> a(n);
   vector<int> b(n);
   rep(i,n) cin >> a[i] >> b[i];
    vector<int> c(m);
    vector<int> d(m);
    rep(i,m) cin >> c[i] >> d[i];

    for (int i = 0; i < n; ++i) {
        int distance;
        int MIN = INFINITY;
        int num = 0;
        for (int j = 0; j < m; ++j) {
            distance = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(distance < MIN){
                MIN = distance;
                num = j + 1;
            }
        }
        print(num);
    }
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<vector<int>> A(2, vector<int>(N + 5));
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < N; ++j) {
      scanf("%d", &A[i][j]);
    }
  }
  for (int i = 1; i < N; ++i) {
    A[0][i] += A[0][i - 1];
    A[1][i] += A[1][i - 1];
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int sum = A[0][i] + A[1][N - 1];
    if (i > 0) { sum -= A[1][i - 1]; };
    ans = max(ans, sum);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  map<pair<int, int>, int> mp;
  rep2(i, 1, n+1){
    pair<int, int> now;
    string si = to_string(i);
    now.first = si.front() - '0';
    now.second = i % 10;
    mp[now]++;
  }
  ll ans = 0;
  rep(i, 10){
    rep(j, 10){
      ans += mp[make_pair(i, j)] * mp[make_pair(j, i)];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ALDS1_8_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Node root = null;

            for (int i = 0; i < n; i++)
            {
                string[] tmpLine = Console.ReadLine()
                                          .Split()
                                          .ToArray();

                if (tmpLine[0] == "insert")
                {
                    Node tmpNode = new Node(int.Parse(tmpLine[1]));

                    if (root == null)
                    {
                        root = tmpNode;
                    }
                    else
                    {
                        root.Insert(tmpNode);
                    }
                }
                else if (tmpLine[0] == "print")
                {
                    if (root != null)
                    {
                        root.InorderPrint();
                        Console.WriteLine();
                        root.PreorderPrint();
                        Console.WriteLine();
                    }
                }
            }

            //Console.ReadLine();
        }
    }

    class Node
    {
        public int val;
        public Node parent;
        public Node left;
        public Node right;

        public Node(int val)
        {
            this.val = val;
        }

        public void Insert(Node target)
        {
            if (target.val < this.val)
            {
                if (this.left == null)
                {
                    this.left = target;
                    target.parent = this;
                }
                else
                {
                    this.left.Insert(target);
                }
            }
            else
            {
                if (this.right == null)
                {
                    this.right = target;
                    target.parent = this;
                }
                else
                {
                    this.right.Insert(target);
                }
            }
        }

        public void PreorderPrint()
        {
            Console.Write(string.Format(" {0}", this.val));

            if (this.left != null)
            {
                this.left.PreorderPrint();
            }

            if (this.right != null)
            {
                this.right.PreorderPrint();
            }
        }

        public void InorderPrint()
        {
            if (this.left != null)
            {
                this.left.InorderPrint();
            }

            Console.Write(string.Format(" {0}", this.val));

            if (this.right != null)
            {
                this.right.InorderPrint();
            }
        }
    }
}



Measured memory_bytes: 45808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni();
        int[] x = nia(n);

        int l = ni();
        int q = ni();
        int[] a = new int[q];
        int[] b = new int[q];
        for (int i = 0; i < q; i++) {
            a[i] = ni() - 1;
            b[i] = ni() - 1;
        }

        int[][] dp = new int[n][20];
        int can = 0;
        for (int i = 0; i < n; i++) {
            while (can < n - 1 && x[can + 1] - x[i] <= l) can++;
            dp[i][0] = can;
        }
        for (int i = 1; i < 20; i++) {
            for (int j = 0; j < n; j++) {
                dp[j][i] = dp[dp[j][i - 1]][i - 1];
            }
        }

        for (int i = 0; i < q; i++) {
            if (a[i] > b[i]) {
                int tmp = a[i];
                a[i] = b[i];
                b[i] = tmp;
            }

            int high = 100000;
            int low = 0;
            while (high - low > 1) {
                int mid = (high + low) / 2;
                int now = a[i];
                int t = 0;
                int tmp = mid;
                while (tmp > 0) {
                    if (tmp % 2 == 1) {
                        now = dp[now][t];
                    }
                    tmp >>= 1;
                    t++;
                }
                if (now >= b[i]) {
                    high = mid;
                } else {
                    low = mid;
                }
            }

            out.println(high);
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 42300
#include<bits/stdc++.h>
using namespace std;
int main()
{string s;cin>>s;
 int a=count(s.begin(),s.end(),'A'),b=count(s.begin(),s.end(),'B');
 if(a==0 || b==0)cout<<"No";
 else cout<<"Yes";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];

    sort(all(A));
    reverse(all(A));

    ll res = A[0];
    int cnt = 1;
    for (ll i = 1; ; i++) {
        if (cnt >= n - 1) {
            break;
        }
        res += A[i];
        cnt++;
        if (cnt >= n - 1) {
            break;
        }
        res += A[i];
        cnt++;
        if (cnt >= n - 1) {
            break;
        }
    }

    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll k, n;

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

    vector<ll> h(n);
    vector<ll> d(n);
    
    cin >> h[0];
    // cout << n  << "," << h[0] << endl;
    for(int i = 1; i < n; i++) {
        cin >> h[i];
        d[i] = h[i] - h[i-1];
    }
    d[0] = (h[0] + k) - h[n-1];
    
    ll m = -1;
    ll mi = -1;
    REP(i,n) {
        // cout << h[i] << " " << d[i] << endl;
        if(m < d[i]) {
            m = d[i];
            mi = i;
        }
    }
    
    cout << k - m << endl;

}

 

Measured memory_bytes: 3328
import java.util.Scanner;

/**
 * A - +-x
 * 整数 A, Bがあります。
 * A+B,  A−B,  A×B の中で最大の数を出力してください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        int a = sc.nextInt();
        int b = sc.nextInt();

        int addition = ( a + b );       // 加算
        int subtraction = ( a - b );    // 減算
        int multiplication = ( a * b ); // 乗算
        int max = addition;

        if( subtraction > addition ) max = subtraction;
        if( multiplication > addition ) max = multiplication;
        System.out.println( max );
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
#include<stack>
#include<queue>
using namespace std;

typedef long long ll;

bool isprime(int x) {
	if (x < 2) return false;
	else if (x == 2) return true;
	if (x % 2 == 0) return false;
	for (int i = 3; i * i <= x; i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

int main(){
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (isprime(x)) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

typedef vector<int> vec;
typedef vector<vec> mat;

const int INF = 1 << 28;
int N, M, L, K, A, H;

void solve() {
    vec lf(L); for (auto &i : lf) cin >> i;
    lf.push_back(A);
    lf.push_back(H);

    mat wfroid(N, vec(N, INF));
    for (int i = 0; i < N; i++) wfroid[i][i] = 0;
    for (int i = 0; i < K; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        wfroid[x][y] = wfroid[y][x] = z;
    }

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            for (int k = 0; k < N; k++) wfroid[j][k] = min(wfroid[j][k], wfroid[j][i] + wfroid[i][k]);

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            if (wfroid[i][j] > M) wfroid[i][j] = INF;

    for (int i = 0; i < lf.size(); i++)
        for (int j = 0; j < lf.size(); j++)
            for (int k = 0; k < lf.size(); k++)
                wfroid[lf[j]][lf[k]] = min(wfroid[lf[j]][lf[k]], wfroid[lf[j]][lf[i]] + wfroid[lf[i]][lf[k]]);

    if (wfroid[A][H] == INF) cout << "Help!" << endl;
    else cout << wfroid[A][H] + max(0, (wfroid[A][H] - M)) << endl;
}

int main() {
    while (cin >> N >> M >> L >> K >> A >> H, N || M || L || K || A || H) solve();

    return 0;
}

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

int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int wa=0;
    for(int i=0;i<n;i++) wa+=a[i];
    int waf=0;
    int sa=100000000;
    for(int i=0;i<n;i++) {
        waf+=a[i];
        int wab=wa-waf;
        sa=min(sa, abs(waf-wab));
    }

    cout<<sa<<endl;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < 26; i++) {
        string a = s;
        a += 'a' + i;
        if (a == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int N;
  cin >> N;
  ll A[N];
  ll Num[N+10] = {0};
  for (int i = 1; i < N; ++i) {
    cin >> A[i];
    ++Num[A[i]-1];
  }
  for (int i = 0; i < N; ++i) {
    // printf("%lld\n", Num[i]);
    cout << Num[i] << endl;
  }
}


Measured memory_bytes: 6748
def num_packs(p)
  i = 0
  @k.times do
    s = 0
    loop do
      break if i == @n
      break if s + @w[i] > p
      s += @w[i]
      i += 1
    end
    break if i == @n
  end
  i
end

def bsearch(min, max)
  return min if min == max

  half = (max - min) / 2 + min
  if num_packs(half) < @n
    bsearch(half+1, max)
  else
    bsearch(min, half)
  end
end


@n, @k = gets.split.map(&:to_i)
@w = []
max = 0
@n.times do
  w = gets.to_i
  max = [max, w].max
  @w << w
end
p_min, p_max = 0, max
while num_packs(p_max) < @n
  p_min = p_max
  p_max = p_max * 2
end
puts bsearch(p_min, p_max)


Measured memory_bytes: 8904
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator
const int MxN = 101;
int ar[101];
void solve() {
    int n;cin>>n;
    int res=0;
    for(int i=0;i<n;i++) {
        cin >> ar[i];
        res += ar[i];
    }
    if(res%10 == 0) {
        sort(ar, ar+n);
        for(int i=0;i<n;i++) 
            if(ar[i]%10 != 0) {
                res -= ar[i];
                goto q;
            }
        res = 0;
    }
    q:
    cout<<res<<endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
def north(d):
	d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]
	
def south(d):
	d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]
	
def east(d):
	d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]
	
def west(d):
	d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]

F = {'N': north, 'S': south, 'W': west, 'E': east}

d, os = list(map(int, input().split())), input()

for o in os:
	F[o](d)

print(d[0])

Measured memory_bytes: 7776
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    unsigned long long N;
    unsigned long long A;
    unsigned long long B;
    cin >> N >> A >> B ;
    if ((B-A)%2 == 0){
        cout << (B-A)/2;
    }else{
        if((N-A)>(B-1)){
            cout << (B-1+A-1+1)/2;
        }else{
            cout << (N-A+N-B+1)/2;
        }
    }
}

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


int main(){
  int n,k;
  cin >> n >> k;
  vector<int> l(n);
  for(int i=0;i<n;++i) cin >> l[i];

  sort(l.rbegin(),l.rend());
  int ans=0;
  for(int i=0;i<k;++i) ans+=l[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

set<string> s;
bool ok;
ll ans;
int main() {
	ll n;
	cin >> n;
	REP(i, n) {
		string a;
		cin >> a;
		if (a == "E869120")ans++;
	}
	cout << ans << endl;
}




Measured memory_bytes: 3200
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    val x = sc.next().toLong()
    val l = (0 until n).map { sc.next().toLong() }
    println(problem130b(n, x, l))
}

fun problem130b(n: Long, x: Long, l: List<Long>): Int {
    var d = 1L
    var count = 1
    (1..n.toInt()).forEach { i ->
        d = (d - 1) + l[i - 1]
        if (d <= x) {
            count++
        }
        d++
    }
    return count
}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	string s ;
	cin >> s ;
	int q ;
	cin >> q ;
	string s1 = "" ;//前
	int rev = 0 ;
	rep(i,q){
		int t ;
		cin >> t ;
		if(t==1){
			swap(s1,s);
			rev = 1 - rev; 
		} else {
			int f ;
			cin >> f ;
			char c ;
			cin >> c ;
			if( f == 1){
				s1.push_back(c);
			} else {
				s.push_back(c);
			}
		}
	}
	if(rev%2==0){
		rSORT(s1);
	} else {
		rSORT(s1);
	}
	cout << s1 << s << endl;
}


Measured memory_bytes: 960
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int r, D, x;
    cin >> r >> D >> x;
    for (int i = 0; i < 10; i++){
        x = r * x - D; 
        cout << x << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int k[3] = { 0, 0, 0 };
    for (char c : s) {
        ++k[c - 'a'];
    }
    if (abs(k[0] - k[1]) > 1 || abs(k[1] - k[2]) > 1 || abs(k[0] - k[2]) > 1) {
        cout << "NO";
    } else {
        cout << "YES";
    }
    return 0;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-

N = int(input().strip())
T_list = [int(input().strip()) for _ in range(N)]
#-----

def gcd(a,b):
    if b == 0: 
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return (a * b) // gcd(a, b)


ans = T_list[0]
for i in T_list[1:]:
    ans = lcm(ans, i)

print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		no1();
	}

	static void no1() {
		try (Scanner sc = new Scanner(System.in)) {
			String t = sc.next();

			int a = Integer.parseInt(t.substring(0, 1));
			int b = Integer.parseInt(t.substring(1, 2));
			int c = Integer.parseInt(t.substring(2, 3));

			System.out.println(a + b + c);
		}
	}
}


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

using namespace std;

inline int read(){
    int AK = 1, IOI = 0;
    char ch = 0;
    while (ch < '0' || ch > '9'){
        AK = ch=='-'?-1:1;
        ch = getchar();
    }
    while (ch <= '9' && ch >= '0'){
        IOI *= 10;
        IOI += ch - 48;
        ch = getchar();
    }
    return AK * IOI;
}
int n;
inline int abs(int x){
    return x < 0 ? -x : x;
}
int a[1000001];
int b[1000001];

inline bool check(int x){
    for (int i = 1; i <= n * 2 - 1; i ++){
        b[i] = a[i] < x ? 0 : 1;
    }
    int Away_1 = 0x7f7f7f7f;
    int Away_0 = 0x7f7f7f7f;
    for (int i = 1; i <= n * 2 - 1; i ++){
        if (b[i] == b[i - 1]){
            if (b[i] == 1)
                Away_1 = std::min (Away_1, abs(i - n) + abs(i - 1 - n));
            else{
                Away_0 = std::min (Away_0, abs(i - n) + abs(i - 1 - n));
            }
        } 
    }
    if (Away_1 == Away_0 && Away_1 == 0x7f7f7f7f){
        return 1;
    }
    return Away_1 < Away_0;
}
int main(){
//    freopen("pyramid.in", "r", stdin);
//    freopen("pyramid.out", "w", stdout);
    n = read();
    int Min = 0x7f7f7f7f;
    int Max = 0;
    for (int i = 1; i <= n * 2 - 1; i ++){
        a[i] = read();
        Min = std::min (Min, a[i]);
        Max = std::max (Max, a[i]);
    }
    int left = Min, right = Max;
    int answer = 0;
    while (left <= right){
        int middle = (left + right) >> 1;
        if (check(middle)){
            answer = middle;
            left = middle + 1;
        } else{
            right = middle - 1;
        }
    }
    printf("%d", answer);
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
using namespace std;


int main() {
  int n,x;
  cin>>n>>x;
  vector<int> a(n);
  frn(i,n) cin>>a[i];
  int ans = n, s = accumulate(a.begin(), a.end(), 0);
  x -= s;
  ans += x /(*min_element(a.begin(), a.end()));
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	int N, X, T;
	cin >> N >> X >> T;

	N = (N + (X - 1)) / X;

	cout << N * T << endl;

}

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

int main(){
  int N,M;cin >> N >> M;
  ll K;cin >> K;
  vector<ll> A(N+1,0);
  vector<ll> B(M+1,0);
  for(int i=0;i<N;i++){
    ll a;cin >> a;
    A[i+1] = A[i] + a;
  }
  for(int i=0;i<M;i++){
    ll b;cin >> b;
    B[i+1] = B[i] + b;
  }
  int X=0,Y=0;
  for(int i=0;i<=N;i++){
    if(A[i]<=K){
      X = i;
    }else{
      break;
    }
  }
  for(int i=0;i<=M;i++){
    if(A[X]+B[i]<=K){
      Y = i;
    }else{
      break;
    }
  }
  int sum = X + Y;
  while(X>=0){
    for(int i=Y;i<=M;i++){
      if(A[X]+B[i]<=K){
        Y = i;
      }else{
        break;
      }
    }
    sum = max(sum,X+Y);
    X --;
  }
  cout << sum << endl;
}

Measured memory_bytes: 6420
from collections import Counter

n,a = map(int,input().split())
input_list = [int(num)-a for num in input().split()]

ans = Counter([0,input_list[0]])
for i in input_list[1:]:
    temp = Counter()
    for key,value in ans.items():
        temp[i+key] += value
    ans += temp

print (ans[0]-1)

Measured memory_bytes: 3572
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n: u64 = read_as_vec()[0];
    let s = read_as_string().chars().collect::<Vec<char>>();

    let mut r_v: Vec<usize> = vec![];
    let mut g_v: Vec<usize> = vec![];
    let mut b_v_bools = vec![false;4000];
    let mut b_num: usize = 0;
    for i in 0..s.len(){
        if s[i] == 'R'{
            r_v.push(i);
        }else if s[i] == 'G'{
            g_v.push(i);
        }else{
            b_v_bools[i] = true;
            b_num += 1;
        }
    }

    let mut ans: usize = r_v.len() * g_v.len() * b_num;
    for r_pos in &r_v{
        for g_pos in &g_v{
            let (former, later) = (
                cmp::min(*r_pos, *g_pos),
                cmp::max(*r_pos, *g_pos)
            );

            if former > (later - former) && b_v_bools[former - (later - former)]{
                ans -= 1;
            }

            if (later-former)%2 == 0 && b_v_bools[former+(later-former)/2]{
                ans -= 1;
            }

            if later + (later - former) < b_v_bools.len() && b_v_bools[later + (later - former)]{
                ans -= 1;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}
ll dp[3001][3001];
void solve(){
    string a, b;
    cin >> a >> b;
    ll n = sz(a), m = sz(b);
    foa(i, 0, n){
        foa(j, 0, m){
            if(a[i] == b[j]){
                dp[i + 1][j + 1] = max(dp[i+1][j+1] , dp[i - 1+1][j - 1+1] + 1);
            }
            else{
                dp[i+1][j+1] = max(dp[i+1][j+1], max(dp[i-1+1][j+1], dp[i+1][j - 1+1]));
            }
        }
    }
    string ans = "";
    ll i = n - 1, j = m - 1;
    while(i >= 0 && j >= 0){
        if(dp[i+1][j+1] == dp[i - 1+1][j+1])i--;
        else if(dp[i+1][j+1] == dp[i+1][j - 1+1])j--;
        else if(dp[i+1][j+1] - 1 == dp[i - 1+1][j - 1+1]){
            ans += a[i - 1+1];
            i--, j--;
        }
    }
    reverse(all(ans));
    ANS;

}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 74076
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums []int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

type Point struct {
	h, w int
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	h, w, m := nextInt(), nextInt(), nextInt()

	sh, sw := make([]int, h), make([]int, w)
	set := map[Point]bool{}
	for i := 0; i < m; i++ {
		hi, wi := nextInt()-1, nextInt()-1
		sh[hi]++
		sw[wi]++
		set[Point{hi, wi}] = true
	}

	// 行，列ごとの最大の爆破数
	shmax, swmax := max(sh), max(sw)
	// 爆破対象に選ぶとshmax/swmaxだけ爆破できるような座標
	hmax, wmax := make([]int, 0), make([]int, 0)
	for i := 0; i < h; i++ {
		if shmax == sh[i] {
			hmax = append(hmax, i)
		}
	}
	for i := 0; i < w; i++ {
		if swmax == sw[i] {
			wmax = append(wmax, i)
		}
	}

	ans := shmax + swmax
	for i := range hmax {
		for j := range wmax {
			// 爆破数を最大化でき，爆弾と重ならないマスが存在すればOK
			if !set[Point{hmax[i], wmax[j]}] {
				puts(ans)
				return
			}
		}
	}
	// 爆弾と重なるマスしかない場合
	puts(ans - 1)
}


Measured memory_bytes: 48624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJHelloWorld1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);
            if (a < b && b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 17940
#include <iostream>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    ll n;   cin >> n;
    ll ans = 0;
    for(ll i = 1; i*i <= n; i++){
        if(n%i == 0){
            ans = i+n/i-2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <math.h>

#define sfd(type, fn)	type fn(P a
#define isfd(type, fn)	inline sfd(type, fn)
#define fd(type, fn)    type fn(P a, P b
#define ifd(type, fn)   inline fd(type, fn)
 
typedef double frac;
 
typedef struct { frac x, y; } Point, P;
 
ifd(frac, cross))   { return (a.x * b.y - a.y * b.x);  }
ifd(frac, dot))     { return (a.x * b.x + a.y * b.y);  }
ifd(P, plus))       { return (P){a.x + b.x, a.y + b.y};}
ifd(P, minus))      { return (P){a.x - b.x, a.y - b.y};}
isfd(P, multi),int x){ return (P){a.x * x, a.y * x};   }
isfd(P, sq))		{ return (P){a.x * a.x, a.y * a.y};}
isfd(frac, scalar))	{ return (a.x + a.y);			   }
isfd(frac, norm))   { return (a.x * a.x + a.y * a.y);  }

fd(int, ccw), P c){
    b = minus(b, a), c = minus(c, a);
    if (cross(b, c) > 0) return +1;          // ccw
    if (cross(b, c) < 0) return -1;          // cw
    if (dot(b, c) < 0)    return +2;         // c-a-b
    if (norm(b) < norm(c)) return -2;  // a-b-c
    return 0;
}
fd(int, in_tri), P c, P p){ return (ccw(a, b, p) == ccw(b, c, p) && ccw(b, c, p) == ccw(c, a, p)); }
 
int input_p(P *p) { return scanf("%lf %lf", &p->x, &p->y); }

int main(void)
{
    P ps[4];
    int n, i;

    scanf("%d", &n);
    for (i = 0; i < n; i++){
        int pt;
        for (pt = 0; pt < 3; pt++) input_p(ps + pt);
        {
        	P a = multi(minus(ps[1], ps[0]), 2);
        	P b = multi(minus(ps[2], ps[0]), 2);
        	frac c = scalar(sq(ps[0])) - scalar(sq(ps[1]));
        	frac d = scalar(sq(ps[0])) - scalar(sq(ps[2]));
        	frac x = (a.y * d - b.y * c) / cross(a, b);
        	frac y = (c * b.x - d * a.x) / cross(a, b);
        	frac r = sqrt(pow(fabs(x - ps[0].x), 2) + pow(fabs(y - ps[0].y), 2));

        	printf("%.3lf %.3lf %.3lf\n", x, y, r);
        }
    }
 
    return (0);
}

Measured memory_bytes: 664
def GCD(y,x):
    if y>x:
        p,q=y,x
    else:
        p,q=x,y
    if p%q==0:
        return q
    else:
        return GCD(q,p%q)

ans1=0
ans2=0
ans3=0
K=int(input())
for i in range(1,K+1):
    for j in range(i+1,K+1):
        for l in range(j+1,K+1):
            ans1+=GCD(GCD(i,j),l)

for i in range(1,K+1):
    for j in range(i+1,K+1):
        ans2+=GCD(i,j)

for i in range(1,K+1):
    ans3+=i
print(ans1*6+ans2*6+ans3)

Measured memory_bytes: 9228
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def divisors(n):
    S,T=[],[]
    for i in range(1,int(n**.5)+1):
        if n%i==0:
            S.append(i)
            T.append(n//i)
    T.reverse()
    return S+T if S[-1]!=T[0] else S+T[1:]

def resolve():
    n,m=map(int,input().split())
    D=divisors(m)
    ans=0
    for d in D:
        if(d*n<=m):
            ans=max(d,ans)
    print(ans)
resolve()

Measured memory_bytes: 38640
import sys
from collections import deque

n = int(sys.stdin.readline())
G = [[] for _ in range(n+1)]
G_order = []
for i in range(n-1):
    a,b = map(lambda x:int(x)-1, sys.stdin.readline().split())
    G[a].append(b)
    G_order.append(b)

que = deque([0])
C = [0]*(n+1)
while que:
    nw = que.popleft()
    c = 1
    for nx in G[nw]:
        if c==C[nw]:
            c+=1
        C[nx] = c
        c += 1
        que.append(nx)

print(max(C))
for i in G_order:
    print(C[i])

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  REP(i, m){
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  vector<int> dx(m-1);
  REP(i,m-1){
    dx[i] = x[i+1] - x[i];
  }
  sort(dx.begin(), dx.end());

  ll ans = 0;
  REP(i,m-n){
    ans += dx[i];
  }

  cout << ans << endl;


  return 0;
}

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

int main() {
	int n,sumsum=0;
	cin>>n;
	vector<long>vec(n);
	for(int i=0;i<n;i++){
		long a;
		cin>>a;
		vec.at(i)=a;
	}
	sort(vec.begin(),vec.end());
	int sum=1;
	if(n==1){
	      cout<<1<<endl;	
	}
	else{
	for(int i=0;i<n-1;i++){
		
		if(vec.at(i)==vec.at(i+1)){
			sum++;
			if(i==n-2){
				if(sum%2==1){
					sumsum++;
				}
			}
		}
		else{
			if(sum%2==1){
				sumsum++;
				if(i==n-2){
					sumsum++;
				}
			}
			sum=1;
		}
	}
	cout<<sumsum<<endl;
	return 0;
	}
}

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;

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll mn=b+a*(n-1),mx=a+b*(n-1);
    cout<<max(0LL,mx-mn+1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int main(void){
  int h,w,a,b;
  scanf("%d %d %d %d",&h,&w,&a,&b);
  FOR(h){
    FORJ(w){
      PRC('0'+(i<b)^(j<a));
    }
    PRS("");
  }
  return 0;
}


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


int main(void){
    int n,k;
    cin >> n >> k;
    vector<int> h;
    rep(i,n){
        int x;
        cin >> x;
        h.push_back(x);
    }
    int mn=1000000009;
    sort(h.begin(),h.end());
    int num = 0;
    rep(i,n-k+1){
        num = h[k+i-1]-h[i];
        mn = min(mn,num);
    }
    cout << mn <<endl;
    return 0;
}








































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

#define int long long

using namespace std;



const int MAXN = 2000 + 23, MXNK = MAXN * MAXN + 23, D = 1000 * 1000 * 1000 + 7;











int n, k, f[MXNK], ivf[MXNK], dp[MAXN][MAXN];

int inv(int x) {
	int ret = 1;
	for (int y = D - 2; y; (y >>= 1), (x = x * x % D)) if (y & 1) ret = ret * x % D;
	return ret;
}
int ent(int x, int y) { return f[y] * ivf[y - x] % D * ivf[x] % D; }




int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	f[0] = 1;
	for (int i = 1; i < MXNK; i++) f[i] = f[i - 1] * i % D;
	ivf[MXNK - 1] = inv(f[MXNK - 1]);
	for (int i = MXNK - 2; ~i; i--) ivf[i] = ivf[i + 1] * (i + 1) % D;
	cin >> n >> k;
	if (k == 1) return cout << 1, 0;
	dp[n][n] = 1;
	for (int i = n; ~i; i--) for (int j = i; ~j; j--) {
		if (j < i) dp[i][j] = (dp[i][j] + ent(k - 2, n * k - i - j * (k - 1) - 1) * dp[i][j + 1]) % D;
		if (i < n) dp[i][j] = (dp[i + 1][j] + dp[i][j]) % D;
	}
	cout << dp[0][0] * f[n] % D;
	return 0;
}

Measured memory_bytes: 94720
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;


ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll num_bg(int n){
  if(n==0)return 1;
  return 2*num_bg(n-1)+3;
}
ll num_pt(int n){
  if(n==0)return 1;
  return 2*num_pt(n-1)+1;
}

ll ans(ll N, ll K){
  if(N>1){
    ll bg = num_bg(N-1);
    if(K==1){
      return 0;
    }else if(K<2+bg){
      return ans(N-1, K-1);
    }else if(K==2+bg){
      return ans(N-1, K-2)+1;
    }else if(K<3+2*bg){
      return ans(N-1, K-2-bg)+num_pt(N-1)+1;
    }else{
      return ans(N-1, K-3-bg)+num_pt(N-1)+1;
    }
  }
  if(N==1){
    ll result[]={0,1,2,3,3};
    //cout <<K <<" "<< result[K-1] << endl;
    return result[K-1];
  }
}

/******************************************
** A main function is start from here  ****
*******************************************/
int main(){
  ll N, K;
  cin >> N >> K;
  //cout << num_bg(N) << " " << num_pt(N)<<endl;
  cout << ans(N,K);
  return 0;
}


Measured memory_bytes: 256
n=input()
a=map(int, raw_input().split())
a.sort()
cur = 1
if n % 2 == 1:
    if a[0] != 0:
        print 0
        exit(0)
    n -= 1
    a = a[1:]
    cur += 1
    
for i in xrange(n / 2):
    if a[i * 2] != cur or a[i * 2 + 1] != cur:
        print 0
        exit(0)
    cur += 2
print pow(2, n / 2, 1000000007)

Measured memory_bytes: 11328
def main():
    line = input()

    for ch in line:
        if   65 <= ord(ch) <= 90:
            ch = chr(ord(ch)+32)
        elif 97 <= ord(ch) <= 122:
            ch = chr(ord(ch)-32)

        print(ch, end='')
    print()

if __name__ == '__main__':
    main()



Measured memory_bytes: 5720
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const int MAX = 100000;
static const int NIL = -1;
using namespace std;


int main() {

    int w,h,n; cin >> w >> h >> n;
    int xl = 0, yl = 0, xr = w, yr = h;
    int x,y,a;

    rep(i,n){
        cin >> x >> y >> a;
        if(a == 1)xl = max(xl,x);
        if(a == 2)xr = min(xr,x);
        if(a == 3)yl = max(yl,y);
        if(a == 4)yr = min(yr,y);
    }

    if((xr-xl)<0 || (yr-yl)<0) cout << 0;
    else cout << (xr-xl)*(yr-yl);


    return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 


int32_t main()
{
	IOS
	string s1,s2;cin>>s1>>s2;
	int n1=s1.length(),n2=s2.length();
	s1='$'+s1;
	s2='$'+s2;
	//Note 3000 * 3000 dp possible 
	vector<vector<int>>dp(n1+1,vector<int>(n2+1));
	pair<int,int> par[n1+1][n2+1];
	
	//Note dp[0][0] = 0 && dp[1...n1][0]=0  && dp[0][1...n2]=0 , base cases
	par[1][1]={0,0};
	for(int i=1;i<=n1;i++)
	{
		for(int j=1;j<=n2;j++)
		{
			if(s1[i]==s2[j])
			{
				dp[i][j]=dp[i-1][j-1] + 1 ;
				par[i][j]={i-1,j-1};
			}
			else
			{
				if( dp[i-1][j] > dp[i][j-1])
				{
					 dp[i][j]=dp[i-1][j];
					 par[i][j]={i-1,j};
				}
				else
				{
					dp[i][j]=dp[i][j-1];
					par[i][j]={i,j-1};
				}
			}
		}
	}
	string ans;
	pair<int,int>crnt={n1,n2};
	while( crnt.first != 0 && crnt.second != 0 )
	{
		if( par[crnt.first ][ crnt.second ].first == crnt.first -1 && par[crnt.first ][ crnt.second ].second== crnt.second -1  ) ans+=s1[crnt.first];
		crnt=par[ crnt.first ][ crnt.second ];
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}
		


Measured memory_bytes: 211456
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    T = [tuple(sorted(iss())) for _ in range(N)]
    S = collections.Counter(T)
    print(sum(v*(v-1)//2 for v in S.values()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 26328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <list>
using namespace std;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int ans = min(B, D) - max(A, C);
    if (ans <= 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	long long mi=1000000, ma=-1000000, sum=0;
	for (int i=0; i < n; i++) {
		long long a;
		scanf("%lld", &a);
		ma = max(a, ma);
		mi = min(a, mi);
		sum = sum + a;
	}
	printf("%lld %lld %lld\n", mi, ma, sum);
}


Measured memory_bytes: 2752
#include <stdio.h>

int main()
{
    int N;
    int M;
    int K;
    int A;
    int i;
    int j;
    int type[30];
    int count;

    scanf("%d %d", &N, &M);
    for(i = 0; i < M; i++) {
        type[i] = 0;
    }

    for(i = 0; i < N; i++) {
        scanf("%d", &K);
        for(j = 0; j < K; j++) {
            scanf("%d", &A);
            type[A-1] += 1;
        }
    }

    count = 0;
    for(i = 0; i < M; i++) {
        if(type[i] == N) {
            count += 1;
        }
    }
    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 128
s = list(input())
ans = 0
halfidx = int((len(s)/2))
ary  = s[0:halfidx]
rary = list(reversed(s))[0:halfidx]
for i in range(0,halfidx):
    if (ary[i] != rary[i]):
        ans = ans + 1
print(ans)

Measured memory_bytes: 9120
import sys
sys.setrecursionlimit(500000)
N=int(input())
A=[int(input())-1 for _ in range(N)]
result=[False]*N
def next(k):
	newlight=A[k]
	if k==1:
		return(1)
	elif result[k]:
		return(0)
	else:
		result[k]=True
		return(next(newlight))
if not next(0):
	print(-1)
else:print(sum(result))

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

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

typedef long long ll;

ll INF = 100000000000000;
ll MOD = 1e9+7;

int main(){
   ll N;cin >> N;
   vector<vector<ll>> PLAY(N,vector<ll>(3));
   for(ll i = 0;i < N;i++){
       cin >> PLAY[i][0] >> PLAY[i][1] >> PLAY[i][2];
   }
   ll dp[100010][3];
   for(int i = 0;i < 100010;i++){
       for(int j = 0;j < 3;j++){
           dp[i][j] = 0;
       }
   }
   for(ll i = 0;i < N;i++){
       for(ll j = 0;j < 3;j++){
           for(ll k = 0;k < 3;k++){
               if(j != k){
                   dp[i+1][j] = max(dp[i][k] + PLAY[i][j],dp[i+1][j]);
               }
           }
       }
   }
   ll ans = 0;
   ans = max({dp[N][0],dp[N][1],dp[N][2]});
   cout << ans << endl;
}


Measured memory_bytes: 8064
import java.math.BigInteger;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int N=cin.nextInt();
			if(N==0){
				break;
			}
			BigInteger[] a = new BigInteger[4001];
			for(int i = 0; i < a.length;i++){
				a[i]=new BigInteger("0");
			}
			long max=-1;
			TreeSet<Integer> t = new TreeSet<Integer>();
			int[] b = new int[4001];
			int count=0;
			for(int i = 0; i <N;i++){
				int sha = cin.nextInt();
				long tan = cin.nextInt();
				long suu = cin.nextInt();
				a[sha]=a[sha].add(new BigInteger(tan*suu +""));
				if(t.contains(sha)){
					
				}
				else{
					b[count++]=sha;
					t.add(sha);
				}
			}
			boolean f = false;
			for(int i = 0; i <count;i++){
				//System.out.println("   "+b[i]);
				if(a[b[i]].compareTo(new BigInteger("1000000"))>=0){
					System.out.println(b[i]);
					f=true;
				}
			}
			/*
			for(int i = 1;i<=4000;i++){
				if(a[i].compareTo(new BigInteger("1000000"))>=0){
					System.out.println(i);
					f=true;
				}
			}*/
			
			if(!f){
				System.out.println("NA");
			}
		}

	}

}

Measured memory_bytes: 13000