akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, M: int, x: "List[int]", y: "List[int]", z: "List[int]"):
    coef = [1,-1]
    cand = itertools.product(coef,repeat=3)
    sumMax = 0
    for can in cand:
        combined = []
        for i in range(N):
            combined.append(can[0] * x[i] + can[1] * y[i] + can[2] * z[i])
        combined.sort()
        s = sum(combined[:M])
        sumMax = max(sumMax,abs(s))
    print(sumMax)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    z = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        z[i] = int(next(tokens))
    solve(N, M, x, y, z)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
if __name__ == '__main__':
    N = (int)(input())
    A = list(map(int,input().split()))
    print(' '.join(map(str,A)))

    for i in range(1,N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j = j -1
        A[j+1] = v
        print(' '.join(map(str,A)))

Measured memory_bytes: 7724
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        if(a == 1){
            System.out.println("Hello World");
        }else{
            int x = sc.nextInt();
            int y = sc.nextInt();
            System.out.println(x+y);
        }
    }
}


Measured memory_bytes: 21716
#include<stdio.h>
#include<string.h>
#include <iostream>
using namespace std;
#define LEN 100005

typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN; 
    return x;
}

int min(int a, int b) { return a < b ? a : b; }   //クオンタムがキューに格納したプロセス時間より小さければ、クオンタムは返す 

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    
    for(i = 1; i <= n; i++){        //この処理でキューに値を格納
        scanf("%s", Q[i].name);     //キーボード入力された値はメモリに保存、先頭アドレスを渡している(配列を関数に渡す時は先頭アドレスに変換される)
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;
    
    while(head != tail){
        u = dequeue();     //キューの先頭から取り出し
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enqueue(u);    //クオンタムを過ぎてもプロセスが終了していない場合、キューに追加
        else{
            printf("%s %d",u.name, elaps);
            cout << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 13340
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define vi vector<int>
#define ii pair<int, int>
#define ll long long int
#define MAX 200010
#define MOD 1e9+7
#define endl '\n'
using namespace std;

int main()
{
   
	fastio;
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n, x;
	cin >> n >> x;

	int v[n];
	REP(i, 0, n){
		cin >> v[i];
	}

	sort(v, v+n);

	int ans = n;
	int sum = accumulate(v, v+n, 0);
	
	x-=sum;

	ans += floor((double)x/v[0]);

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;
    
    auto arr = readln.chomp.split.map!(to!int).array;
    
    bool ok = arr.all!(x => x % 2 == 1 || x % 3 == 0 || x % 5 == 0);
    
    writeln(ok ? "APPROVED" : "DENIED");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    string ss; cin >> ss;
    bool n = 0, s = 0, e = 0, w = 0;
    rep(i, 0, ss.size()) {
        if (ss[i] == 'W') w = 1;
        if (ss[i] == 'S') s = 1;
        if (ss[i] == 'E') e = 1;
        if (ss[i] == 'N') n = 1;
    }
    (n == s && w == e) ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            char[] s = sc.next().toCharArray();
            char[] t = sc.next().toCharArray();
            int cnt = 0;
            for (int i = 0; i < s.length; i++) {
                if (s[i] != t[i]) cnt++;
            }
            System.out.println(cnt);
        }
    }
}

Measured memory_bytes: 41816
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool ok = 1;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if(a % 2 == 0) {
            if(a % 3 != 0 && a % 5 != 0) {
                ok = 0;
            }
        }
    }
    cout << (ok ? "APPROVED" : "DENIED") << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

vx = [1, -1, 0, 0, 1, 1, -1, -1]
vy = [0, 0, 1, -1, 1, -1, 1, -1]


def dfs(x, y):
    c[y][x] = 0
    for dx, dy in zip(vx, vy):
        nx = x + dx
        ny = y + dy
        if nx < 0 or ny < 0 or nx >= w or ny >= h:
            continue
        if c[ny][nx] == 0:
            continue
        dfs(nx, ny)

while True:
    w, h = map(int, raw_input().split())
    if w == 0:
        break

    c = []
    for _ in range(h):
        c.append(map(int, raw_input().split()))

    cnt = 0

    for y in range(h):
        for x in range(w):
            if c[y][x] == 1:
                cnt += 1
                dfs(x, y)
    print cnt

Measured memory_bytes: 9728
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
n = len(s)
if n >= 4:
    if s[:4] == 'YAKI':
        print('Yes')
        quit()
print('No')

Measured memory_bytes: 10408
# encoding: utf-8
H, W = map(int, input().split())
s = [list(input()) for i in range(H)]

ans = "Yes"
for y in range(H):
    for x in range(W):
        if s[y][x] == ".": continue
        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            # skip
            if y + dy < 0 or H <= y + dy: continue
            elif x + dx < 0 or W <= x + dx: continue
            # check
            if s[y][x] == s[y + dy][x + dx] == "#": break
            else: continue
        else:
            ans = "No"
        if ans == "No": break
    if ans == "No": break

print(ans)


Measured memory_bytes: 3064
q = int(input())
eps = 1e-8
for _ in range(q):
    xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(int, input().split())
    v1 = complex(xp1 - xp0, yp1 - yp0)
    v2 = complex(xp3 - xp2, yp3 - yp2)
    temp = v1.conjugate() * v2
    dot = temp.real
    cross = temp.imag
    
    if  abs(dot) < eps:
        print("1")
    elif abs(cross) < eps:
        print("2")
    else:
        print("0")



Measured memory_bytes: 5640
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  
  int r;
  cin >> r;
 
  cout << 2 * 3.1415926535 * r << endl;
 
  return 0;
}


Measured memory_bytes: 3792
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

//a^n
LL Pow(LL a, LL n) {
	LL ans = 1;
	while (n > 0) {
		if (n & 1)ans *= a;
		a *= a;
		n >>= 1;
	}
	return ans;
}

VL Hamming() {
	VL ret;
	rep(i2, 21) {
		rep(i3, 14) {
			rep(i5, 10) {
				LL x = Pow(2, i2)*Pow(3, i3)*Pow(5, i5);
				if (x <= 1000000)ret.pb(x);
			}
		}
	}
	sort(all(ret));
	return ret;
}


int main() {
	VL hu = Hamming();

	while (true) {
		LL m, n; cin >> m;
		if (m == 0)break; cin >> n;

		LL ans = 0;
		for (auto aa : hu) {
			if (m <= aa && aa <= n)ans++;
		}
		Cout(ans);
	}
}

/*
2^20 > 10^6
3^13 > 10^6
5^9  > 10^6
*/


Measured memory_bytes: 2992
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, f = 0;    
    while (cin >> n && n){
        int a[4], c[4] = {10, 50, 100, 500};
        int ans[4];
        REP(i,4) cin >> a[i];
        int ma = -1000;
        REP(i,a[0]+1) REP(j,a[1]+1) REP(k,a[2]+1) REP(l,a[3]+1){
            int x = 10*i + 50*j + 100*k + 500*l;
            if (x < n) continue;
            x -= n;
            int res = i+j+k+l;
            int d[4];
            FORR(p,3,0){
                d[p] = x / c[p];
                res -= (x / c[p]);
                x %= c[p];
            }
            if (d[0] > 0 && i > 0) continue;
            if (d[1] > 0 && j > 0) continue;
            if (d[2] > 0 && k > 0) continue;
            if (d[3] > 0 && l > 0) continue;
            if (res > ma){
                ma = res;
                ans[0] = i;
                ans[1] = j;
                ans[2] = k;
                ans[3] = l;
            }
        }
        if (f) cout << endl;
        REP(i,4){
            if (ans[i] == 0) continue;
            printf("%d %d\n", c[i], ans[i]);
        }
        f = 1;
    }
    return 0;
}

Measured memory_bytes: 3220
// D - Handstand
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int solve(int N, int K, string &S){

	S += S[N-1]=='0'? "1":"0";//終端処理用

	vi sumC;//累積和
	sumC.push_back(0);//累積和の差分計算を簡略化するため
	if(S[0] == '0') sumC.push_back(0);//1 から始まるデータを想定して追加

	int count = 0;
	rpz(l, N){
		count++;
		if(S[l] != S[l+1]){
			sumC.push_back(count + sumC[sumC.size()-1]);
			count = 0;
		}
	}

	int n = sumC.size();
	if(n&1) sumC.push_back(sumC[n-1]);//1 で終わるデータを想定して追加
	n = sumC.size();

	int width = K*2 + 1;
	if(width >= n) return N;
	int ans = 1;
	for(int l=0, r=width; r<n; r+=2, l+=2) ans = max(ans, sumC[r]-sumC[l]);//(l.r] 累積和の差分
	return ans;

}

int main(){
	int N,K; cin>>N>>K;
	string S; cin>>S;
	cout<< solve(N, K, S) <<endl;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check(int n) {
    for(int i=2;i*i<=n;++i) {
        if(n%i==0)
        return false;
    }
    return true;
}


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    int n,k;
    cin>>n>>k;
    int x;
    int p=0;
    f1(i,n) {
        cin>>x;
        if(x>=k)++p;
    }
    cout<<p<<endl;
    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3560
#include <iostream>
using namespace std;
struct tenboudai{
	int h;
	int value;
};


int main(){
	int n,m;
	tenboudai *t;
	cin >> n >> m;
	t = new tenboudai[n];
	for(int i = 0;i < n;i++){
		cin >> t[i].h;
		t[i].value = 1;
	}
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b;
		if(t[a-1].h < t[b-1].h){
			t[a-1].value = 0;
		}else if(t[a-1].h > t[b-1].h){
			t[b-1].value = 0;
		}else if(t[a-1].h == t[b-1].h){
			t[a-1].value = 0;
			t[b-1].value = 0;
		}
	}
	int counter = 0;
	for(int i = 0;i < n;i++){
		if(t[i].value){
			counter++;
		}
	}
	cout << counter;
	return 0;
}


Measured memory_bytes: 4428
N = int(input())
info =[]
for n in range(N):
    info.append(list(map(int,input().split())))

def chech(Cx,Cy,x,y,h):
    if h > 0:
        H = h + abs(x-Cx) + abs(y-Cy)
        c_list.append(H)
    return 
    
for Cx in range(101):
    for Cy in range(101):
        c_list=[]
        c_list_zero=[]
        for i in info:
            x,y,h=i
            c_=chech(Cx,Cy,x,y,h)

        if len(set(c_list))==1:
            check_zero=True
            for i in info:
                x,y,h=i
                H = c_list[0]
                h_=max(H - (abs(x-Cx) + abs(y-Cy)),0)
                if h_ != h:
                    check_zero=False
                
            if check_zero==True:
                print(Cx,Cy,c_list[0])

Measured memory_bytes: 75044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string result = "Yes";
            for(int i = 0; i < S.Length; i++)
            {
                if (i % 2 == 0)
                {
                    if (S.Substring(i, 1) != "R" && S.Substring(i, 1) != "U" && S.Substring(i, 1) != "D")
                    {
                        result = "No";
                        break;
                    }
                }
                else
                {
                    if (S.Substring(i, 1) != "L" && S.Substring(i, 1) != "U" && S.Substring(i, 1) != "D")
                    {
                        result = "No";
                        break;
                    }
                }
            }
            Console.WriteLine(result);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

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

int main () {
  long long n, m;
  cin >> n >> m;
  vector<long long> y;
  long long p = -1;
  long long sub = (int ) sqrt(m);
  for (long long i = 1; i <= sub; i++) {
    if (m % i == 0) {
      if (m - i * n >= 0) {
        if (p < i) { 
          p = i;  
        }
      } 
         
      // 逆側も議論する．
      long long subsub = m / i;
      if (m - subsub * n >= 0) {
        if (p < subsub) {
          p = subsub;  
        }
      }
    }   
    if (i == sub) {
      i = m;
      if (m - i * n >= 0) {
        p = i;  
      }  
    }
  }  
  cout << p << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
      	sc.nextLine();
        String n = sc.nextLine();
        System.out.println(encrypt(n,i));
        sc.close();
    }
    static char[][] RANGE = {{'a', 'z'}, {'A', 'Z'}};
    static char slide(char c, int key){
        int ret = c + key;
        for(char[] t : RANGE) {
            if(c >= t[0] && c <= t[1]) {
                if(ret < t[0]) ret = t[1] - (t[0] - ret);
                if(ret > t[1]) ret = ret - t[1] + t[0]-1;
                return (char)ret;
            }
        }
        return c;
    }
    static String encrypt(String str, int key){
        StringBuilder sb = new StringBuilder();
        str.chars().forEach(c -> sb.append(slide((char)c, key)));
        return sb.toString();
    }
}

Measured memory_bytes: 26708
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool ip/*is_prime*/(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}
vector<pair<ll,ll>> pf/*prime_factorize*/(ll n){vector<pair<ll,ll>> res;for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll ex=0;while(n%a==0){ex++;n/=a;}res.pb({a,ex});}if(n!=1) res.pb({n,1});return res;}
vector<ll> div/*divisor*/(ll n){  vector<ll> res={1};for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll b=n/a;res.pb(b);if(b!=a) res.pb(a);}sort(all(res));return res;}

int main(){
  int x;
  cin>>x;
  int ja=11;
  while(x>=0){
    x-=200;
    ja--;
  }
  cout<<ja<<endl;
}


Measured memory_bytes: 3640
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
N = int(input())
print(str.lower(num2alpha(N)))

Measured memory_bytes: 9168
#include <stdio.h>

int main()
{
	int i, n, cnt = 0;
	
	scanf("%d", &n);
	
	char s[n];
	
	scanf("%s", s);
	
	for(i = 0; i < n; i++){
		if(s[i] == 'R')
			cnt++;
		else
			cnt--;
		
	}
	if(cnt > 0)
		printf("Yes");
	else
		printf("No");

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

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

int main(void){
    int N,K,Q;
    cin>>N>>K>>Q;
    vector<int> A(Q);
    vector<int> count(N);
    rep(i,Q){
        int A;
        cin>>A;
        A--;
        count[A]++;
    }
    rep(i,N){
        if(K-(Q-count[i])>0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int a;
		int ans = 0;

		sc.close();

		if(N==K){
			ans = 1;
		}else{
			ans = (int)(N-1)/(K-1);
			if((N-1)%(K-1)>0)
				ans++;
		}

		System.out.println(ans);
	}
}


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

int h,w;bool c[400][400];bool v[400][400];stack<array<int,3>> s;ll ans;


void bfs(){
  ll bb = 0, ww = 0;
  while(!s.empty()){
    auto p = s.top();s.pop();
    if(p[0] < 0 || p[1] < 0 || p[0] >=w || p[1] >= h || c[p[0]][p[1]] != p[2] || v[p[0]][p[1]]){
      //cout << p[0] << " " << p[1] << " " << p[2] << endl;
      continue;
    }
    v[p[0]][p[1]] = true;
    if(c[p[0]][p[1]]){
      bb++;
    }else{
      ww++;
    }
    rep(i,4){
      s.push({p[0]+fd[i].first, p[1]+fd[i].second, !(p[2])});
    }
  }
  //cout << "------------------" << endl;
  ans += bb * ww;
}

int main(){
  cin>>h>>w;
  rep(i,h){
    string s;cin>>s;
    rep(j,w){
      c[j][i] = (s[j] == '#');
    }
  }
  rep(i,w)rep(j,h)v[i][j] = false;
  
  rep(i,w)rep(j,h){
    if(!v[i][j]){
      s.push({i,j,c[i][j]});
      bfs();
    }
  }
  cout << ans << endl;
}


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

void solve() {
    int n;
    cin >> n;
    long long sum = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a.begin(), a.end());
    long long ans = 0;
    for (auto x : a) {
        ans += abs(x - a[n/2]);
    }
    cout << ans;
}

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


Measured memory_bytes: 3928
#include<stdio.h>

int main(void){

   int t=0,i;
   char s[4];
   scanf("%s",s);

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


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main()
{
	int N;
	ll tt=0,res=0;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int t;
		cin>>t;
		if(t==0)
		{
			res+=tt/2;
			tt=0;
		}
		else
			tt+=t;
	}
	res+=tt/2;
	cout<<res<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    while(true){
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      if(a == 0 && b == 0){
        break;
      }

      for(int j = 0; j < a; j++){
        if(j != 0){
          System.out.print("\n");
        }
        for(int k = 0; k < b; k++){
          System.out.print("#");
        }
      }
      System.out.print("\n\n");
    }
  }

}

Measured memory_bytes: 37744
#include <cstdio>
#include <vector>

using namespace std;

int ceil(int numerator, int denominator)
{
    int quotient = numerator/denominator;
    int remainder = numerator%denominator;

    return (quotient + (remainder != 0));
}

int main()
{
    int no_of_elements, k;
    scanf("%d %d", &no_of_elements, &k);

    int position_1;
    for(int i = 1; i <= no_of_elements; i++)
    {
        int element;
        scanf("%d", &element);

        if(element == 1) position_1 = i;
    }

    int answer = ceil(no_of_elements - 1, k - 1);

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


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

int dp[10001][1<<4] = {}, ng[10001] = {};

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

    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        ng[y] += 1<<x;
    }

    for(int i = 1; i < h; i++){
        // put 1
        for(int xj = 0; xj < 1<<4; xj++){
            int put = 12;
            while(put >= 3){
                if(((put&ng[i-1])==0) && ((xj&put)==0) && ((ng[i]&put)==0)){
                    dp[i][put|ng[i]] = max(dp[i][put|ng[i]], dp[i-1][xj]+1);
                }
                put >>= 1;
            }
        }
        // put 2
        if(ng[i-1] == 0 && ng[i] == 0){
            dp[i][(1<<4)-1] = max(dp[i][(1<<4)-1], dp[i-1][0]+2);
        }
        for(int j = 0; j < 1<<4; j++)   dp[i][0] = max(dp[i][0], dp[i-1][j]);
    }

    int ans = 0;
    for(int j = 0; j < 1<<4; j++)   ans = max(ans, dp[h-1][j]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3788
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a= new int[n];

        for(int i=0;i<n;i++)a[i]=sc.nextInt();

        Arrays.sort(a);

        String ans = "YES";
        for(int i=0;i<n-1;i++){
            if(a[i]==a[i+1]){
                ans="NO";
                break;
            }
        }
        System.out.println(ans);
    }

}




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

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

//ncr
lli ncr(lli left, lli right) {
	right = min(left - right, right);
	lli ans = 1;
	for (lli i = 1; i <= right; i++) {
		ans = ans * (left - right + i) / i;
	}
	return ans;
}

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

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	if (N % 2 == 1) {
		cout << (B[N / 2] - A[N / 2] + 1) << endl;
	}
	else {
		cout << (B[N / 2] - A[N / 2] + B[N / 2 - 1] - A[N / 2 - 1] + 1) << endl;
	}
	return 0;
}



Measured memory_bytes: 4844
N = int(input())
A = list(map(int, input().split()))
box = [0 for _ in range(int(1e5) + 1)]
sA = sum(A)
for a in A:
    box[a] += 1
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    sA = sA - box[B]*B + box[B]*C
    box[C] += box[B]
    box[B] = 0
    print(sA)


Measured memory_bytes: 20884
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int a, b;
    cin >> a >> b;
    if (a == 1 && b == 1) {
        cout << "Draw" << endl;
    } else if (a == 1 || b == 1) {
        if (a == 1) {
            cout << "Alice" << endl;
        } else {
            cout << "Bob" << endl;
        }
    } else {
        if (a > b) {
            cout << "Alice" << endl;
        } else if (b > a) {
            cout << "Bob" << endl;
        } else {
            cout << "Draw" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 888
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	vector<string> arr = {
		"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"
	};
	string s;
	cin >> s;
	cout << 7 - (find(arr.begin(), arr.end(), s) - arr.begin()) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
class Dice{
    public:
    int a[7],n;
    
    Dice(){}
    
    void roll_E(){   //東のとき
        roll(1,4,6,3);
    };   
    
    void roll_W(){  //西のとき
        roll(1,3,6,4);
    };
    
    
    void roll_S(){   //南のとき
        roll(1,5,6,2);
    };
    void roll_N(){  //北のとき
        roll(1,2,6,5);
    };
    
    void roll_H(){      //横回り
        roll(2,3,5,4);
    }
    
    
    void roll(int i, int j, int k, int l){    //転がったときの値の移動
       n = a[i], a[i] = a[j], a[j] = a[k], a[k] = a[l], a[l] = n; 
    }
    
    void way(char m){  //方角を判断
        if(m == 'E') roll_E();
        else if(m == 'W') roll_W();
        else if(m == 'S') roll_S();
        else if(m == 'N') roll_N();
        else if(m == 'H') roll_H();
    }
};
    
    
    


bool equal( Dice c1, Dice c2 ){    //等しいとき
    for(int i = 1; i <= 6; i++){
        if(c1.a[i] != c2.a[i]) return false;    //一致してなかったらfalse
    }
    return true;
}

    
bool compare( Dice c1, Dice c2 ){   //比較  false==0,true==1
    for(int i = 1; i <= 6; i++){   //a[i] == b[i]をする
        //if(a[1] == b[1]) break;
        //if(c1.a[i] != c2.a[i]) return false;   //とりあえず、true == １なので１と出させる
        for(int j = 0; j < 4; j++){    //右面と同じことして回す
            //cout << "i,j,b[1]"  << i << " "<< j << " " << c2.a[1] << endl;;
            if( equal(c1,c2) ) return true;   //一致したら
            c1.roll_H();
                
        }
        if(i%2 == 0) c1.roll_W();
        else c1.roll_N();
    }
            
    return false;
}

int n;
Dice d[101];

bool judge(){    //判定、二つのサイコロを比較する関数しかないのでiとｊで回す
    for(int i = 0; i <= n-1;i++){
        
        for(int j = i+1; j < n;j++) {
            if(compare( d[i], d[j])) return false;
        
        }
        return true;
    }
}


int main(void){
    // Your code here!
    //int n;
    
    cin >> n;
    for(int j = 0; j < n; j++){
        for(int i = 1; i <= 6; i++){    //各面に値を入力
            cin >> d[j].a[i];
        }
    }
    
    
    if( judge() ) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 3100
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<cstring>
#include<map>
#include<sstream>
 
using namespace std;
 
int main(){
 
long N;
long K;
  
cin>>N>>K;
  
long H[N];
  for(int i = 0; i < N; i++)
    cin>>H[i];
  
sort(H,H+N);
  
long count = 0;
  
for(int i = 0; i < N - K; i++){
  count += H[i];
}
  cout << count << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<stdint.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long int
using namespace std;

vector<int>adj[300000];
vector<int>val(300000,0);

void dfs(int x,int pre){
	for(int i=0;i<adj[x].size();i++){
		int y=adj[x][i];
		if(y!=pre){
			val[y]+=val[x];
			dfs(y,x);
		}
	}
}

int32_t main(){
	int n,q,x,y;
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	for(int i=0;i<q;i++){
		cin>>x>>y;
		val[x]+=y;
	}
	dfs(1,0);
	for(int i=1;i<=n;i++){
		cout<<val[i]<<" ";
	}
}


Measured memory_bytes: 30464
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;

	int cnt = 0;

	for(int i = 1; i < b - a; ++i){
		cnt += i;
	}

	cout << cnt-a << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
long long n,a,ans,f,x=1e9+7; 
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) 
	{
		cin>>a;
		if(a<0) f++;
		ans+=abs(a);
		x=min(x,abs(a));
	}
	if(f%2==0) cout<<ans;
	else cout<<ans-x*2;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
m=[]
a=[]
r=[]
c=[]
h=[]
for i in range(n):
    k=input()
    if k[0]=="M":
        m.append(k)
    elif k[0]=="A":
        a.append(k)
    elif k[0]=="R":
        r.append(k)
    elif k[0]=="C":
        c.append(k)
    elif k[0]=="H":
        h.append(k)
s=0
s=s+len(m)*len(a)*len(r)+len(m)*len(a)*len(c)+len(m)*len(a)*len(h)+len(m)*len(r)*len(c)+len(m)*len(r)*len(h)+len(m)*len(c)*len(h)+len(a)*len(r)*len(c)+len(a)*len(r)*len(h)+len(a)*len(c)*len(h)+len(r)*len(c)*len(h)
print(s)

Measured memory_bytes: 9972
n = int(input())
p = list(map(int, input().split()))

swap_idx = []
for i in range(n):
    if p[i] != i+1:
        swap_idx.append(i)

if len(swap_idx) == 2 or len(swap_idx) == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,a,b) for(i=a;i<=b;i++)
#define pb push_back;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  ll m,n,i,j,k,p=1000000007,count=0,flag=0,temp1=0,temp2=0;
  string s;
        
          cin>>s;
        n=s.length();
for(i=0;i<n;i++)
{
  if(s[i]!=s[n-1-i])
  {
    flag=1; 
    break;
  }
}
if(flag==0)
{
        for(i=0;i<=(n-3)/2;i++)
        {
          if(s[i]!=s[((n-3)/2)-i])
          {
            flag=1;
            break;
          }
        }
  }
        if(flag==0)
        {
          for(i=(n+1)/2;i<n;i++)
          {
            if(s[i]!=s[((3*n-1)/2)-i])
              {
                flag=1;
                break;
               }
           }
        }
           if(flag)cout<<"No"<<endl;
           else cout<<"Yes"<<endl;



return 0; 
 
 
}

Measured memory_bytes: 256
def bitadd(a,w,bit): #aにwを加える(1-origin)
 
    x = a
    while x <= (len(bit)-1):
        bit[x] += w
        x += x & (-1 * x)
 
def bitsum(a,bit): #ind 1～aまでの和を求める
 
    ret = 0
    x = a
    while x > 0:
        ret += bit[x]
        x -= x & (-1 * x)
    return ret


def updiv(a,b):
    if a % b == 0:
        return a//b
    else:
        return a//b +1

def want(x):

    lis = []
    for i in a:
        if i >= x:
            lis.append(1)
        else:
            lis.append(-1)

    slis = [0]
    for i in lis:
        slis.append(slis[-1] + i)

    #座圧する(1-Originにすべき)
    dic = {}
    nlis = []
    for i in slis:
        if i not in dic:
            dic[i] = None
            nlis.append(i)
    nlis.sort()
    for i in range(len(nlis)):
        dic[nlis[i]] = i+1

    #print (x,dic)
    
    ans = 0
    BIT = [0] * (len(nlis) + 1)

    for i in slis:
        j = dic[i]

        ans += bitsum(j,BIT)
        bitadd(j,1,BIT)
        
    #print (x,ans,slis)
    return ans
    

N = int(input())

a = list(map(int,input().split()))

l = 1
r = max(a) + 1

while r-l != 1:

    m = (l+r) // 2

    mnum = want(m)

    if mnum >= updiv((N**2+N)//2,2):
        l = m
    else:
        r = m

print (l)


Measured memory_bytes: 129468
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 200001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n;
  int p[MAX];
  scanf("%d", &n);

  rep(i, 0, n) scanf("%d", &p[i]);

  int cnt = 1;
  int min = p[0];
  rep(i, 1, n) {
    if (p[i] < min) cnt++;
    min = min(min, p[i]);
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 896
import java.util.*;
class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        long sum = 0;
        for(int i = 0;i<n;i++){
            a[i] = sc.nextInt();
            sum+=a[i];
        }
        long ans = sum;
        long tmpA = 0,tmpB = sum;
        for(int i =0;i<n;i++){
            tmpA += a[i];
            tmpB -= a[i];
            ans = Math.min(Math.abs(tmpA-tmpB),ans);
        }
        System.out.println(ans);
    }
}


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

using namespace std;

vector<pair<int, int> > V;

bool comp(pair<int, int> p1, pair<int, int> p2)
{
    if(p1.second < p2.second) return true;
    else if(p1.second == p2.second){
        return p1.first > p2.first;
    }
    return false;
}

set<pair<int, int> > x;
set<pair<int, int> > y;
set<pair<int, int> > lft;
set<pair<int, int> > rght;

int l1, r1;

void dlt(int l, int r)
{
    x.erase(x.lower_bound(make_pair(l, -1)));
    y.erase(y.lower_bound(make_pair(r, -1)));
}

int query()
{
    //cout << x.size() << " " << y.size() << endl;
    set<pair<int, int> > ::iterator it1 = x.end();
    it1--;
    pair<int, int> p1 = *it1;
    set<pair<int, int> > ::iterator it2 = y.begin();
    pair<int, int> p2 = *it2;

    int l2 = p1.first, r2 = p2.first;
    int ans = 0;
    if(r1 >= l1) ans += (r1-l1+1);
    if(r2 >= l2) ans += (r2-l2+1);
    return ans;
}

int n;

void dlt(set<pair<int,int> > &S, int x)
{
    S.erase(S.lower_bound(make_pair(x, -1)));
}

int findMax(set<pair<int, int> > &S)
{
    set<pair<int, int> > ::iterator it = S.end();
    it--;
    pair<int, int> p = *it;
    return p.first;
}

int findMin(set<pair<int, int> > &S)
{
    set<pair<int, int> > ::iterator it = S.begin();
    pair<int, int> p = *it;
    return p.first;
}

int calc()
{
    int ans = 0;
    for(int i=0; i<n; i++){
        int l = V[i].first, r = V[i].second;
        int cur = r-l+1;
        dlt(lft, l);
        dlt(rght, r);
        int maxs = findMax(lft);
        int mins = findMin(rght);
        if(maxs <= mins) cur += mins-maxs+1;
        ans = max(ans, cur);
        lft.insert(make_pair(l, i));
        rght.insert(make_pair(r, i));
    }
    return ans;
}

int main()
{
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        int l, r;
        scanf("%d %d", &l, &r);
        V.push_back(make_pair(l, r));
        lft.insert(make_pair(l, i));
        rght.insert(make_pair(r, i));
    }
    sort(V.begin(), V.end(), comp);
    int ans = 0;
    l1 = V[0].first, r1 = V[0].second;
    for(int i=1; i<V.size(); i++){
        int l = V[i].first, r = V[i].second;
        x.insert(make_pair(l, i));
        y.insert(make_pair(r, i));
        ans = max(ans, r-l+1);
    }
    ans = max(ans, query());
    for(int i=1; i<n-1; i++){
        int l = V[i].first, r = V[i].second;
        l1 = max(l1, l);
        r1 = min(r1, r);
        dlt(l, r);
        int cur = query();
        ans = max(ans, cur);
    }
    ans = max(ans, calc());
    cout << ans;
}

Measured memory_bytes: 19828
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {   
    ll n, m; cin >> n >> m;
    UnionFind uf(n);
    rep(i, m){
        int a, b; cin >> a >> b; a--; b--;
        uf.merge(a, b);
    }
    int one = uf.size(0), two = uf.size(1);
    int big = one>=two ? 0 : 1;
    int small = big==0 ? 1 : 0;
    for(int i=2; i<n; i++){
        if(!uf.issame(big, i) && !uf.issame(small, i))uf.merge(big, i);
    }
    ll res = n*(n-1)/2 - ((ll)uf.size(0)*uf.size(1)) - m;
    //cout << uf.size(0) << " " << uf.size(1) << ln;
    cout << res << ln;
}



Measured memory_bytes: 640
from math import atan2,pi

a,b,x = map(int,input().split())
S = x/a #平面の面積

if a*b == S:
    ans = 0
elif S <= a*b/2:
    a = S/(b/2)
    ans = atan2(b,a)*180/pi
else:
    S = a*b-S
    a,b = b,a
    a = S/(b/2)
    ans = 90-atan2(b,a)*180/pi
print(ans)

Measured memory_bytes: 3064
x, n = map(int,input().split())
p_l = list(map(int,input().split()))

if x not in p_l:
    print(x)
    exit()

for i in range(1,100):
    if (x - i) not in p_l:
        print(x-i)
        break
    elif (x + i) not in p_l:
        print(x+i)
        break 



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

using namespace std;

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

  int n;
  int64_t d;
  cin >> n >> d;

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int64_t x, y;
    cin >> x >> y;
    int64_t dist = x * x + y * y;
    if (dist <= d * d) {
      ++cnt;
    }
  }

  cout << cnt << '\n';

  return 0;
}


Measured memory_bytes: 3656
import java.util.*;
import java.io.*;

public class Main{

	public static void main(String[] args) throws IOException {
		if(readInt() == 1) {
			println("Hello World");
		}
		else {
			println(readInt() + readInt());
		}
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


Measured memory_bytes: 22228
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

int main(){
	string arr[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
	string s;
	cin >> s;
	rep(i, 7) {
		if(s == arr[i]) {
			cout << 7 - i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3596