akhauriyash/Code-Regression huggingface dataset:
/*input
10 4 8
*/

//sometimes it's the people who no one imagines anything of 
//who do the things that no one can imagine.

//code author: iamxlr8

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define all(c) c.begin(),c.end()
#define mod 1000000007
#define inf 1000000000000000001
#define F first
#define S second
#define dbg(x) cout << #x << " = " << x << '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

void solve()
{
    ll n,x,y;
    cin>>n>>x>>y;
    ll dist[n]={0};
    // vector<pair<ll,ll>> v[n];
    for(ll i=1;i<=x;i++)
    {
        // cout<<i<<endl;
        for(ll j=i+1;j<=n;j++)
        {
            // cout<<j<<" ";
            if(j<=x)
            {
                dist[j-i]++;
                // v[j-i].push_back({i,j});
            }
            else if(x<j&&j<y)
            {
                dist[x-i+min(y-j+1,j-x)]++;
                // v[x-i+min(y-j+1,j-x)].push_back({i,j});
            }
            else if(j>=y)
            {
                dist[x-i+1+j-y]++;
                // v[x-i+1+j-y].push_back({i,j});
            }
        }
        // cout<<endl;
    }
    for(ll i=x+1;i<=y;i++)
    {
        for(ll j=i+1;j<=n;j++)
        {
            if(j<=y)
            {
                dist[min(j-i,i-x+1+y-j)]++;
                // v[min(j-i,i-x+1+y-j)].push_back({i,j});
            }
            else
            {
                dist[j-y+min(y-i,i-x+1)]++;
                // v[j-y+min(y-i,i-x+1)].push_back({i,j});
            }
        }
    }
    for(ll i=y+1;i<=n-1;i++)
    {
        for(ll j=i+1;j<=n;j++)
        {
            dist[j-i]++;
            // v[j-i].push_back({i,j});
        }
    }
    for(ll i=1;i<=n-1;i++)
    {
        // for(auto p:v[i])
        //     cout<<p.F<<" "<<p.S<<"  ---->   ";
        cout<<dist[i]<<"\n";
    }
}

int main() 
{
    off;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
        solve();
    }
    return 0;
}

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


int main() {

	int n;
	cin >> n;

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

	int ma = 0;
	for (int i = 0; i < n; i++) {
		
		ma = max(ma, a[i]);
	}

	int mi = 1100000000;
	for (int i = 0; i < n; i++) {

		mi = min(mi, a[i]);
	}

	cout << ma - mi << endl;



	return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int i = scanner.nextInt();
		
		scanner.close();
		
		if (i == 0) {
			System.out.println("1");
		} else {
			System.out.println("0");
		}
	}

}


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

int main(){
  int n;
  cin>>n;
  
  int arr[n];
  for(int i =0;i<n;i++)
    cin>>arr[i];
  
  map<int,int> m;
  for(int i =0;i<n;i++)
    m[arr[i]]++;
  
  int cnt =0;
  for(auto it = m.begin();it!=m.end();it++){
    if(it->first > it->second)
      cnt+=it->second;
    else if(it->first < it->second)
      cnt+=(it->second - it->first);
  }
  
  cout<<cnt;
  return 0;
}
  
  

Measured memory_bytes: 5120
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string s[8];
  int i,j;
  for(i=0;i<8;i++){
    cin >> s[i];
  }
  cout << "90" << endl;
  for(i=0;i<8;i++){
    for(j=7;j>=0;j--){
      cout << s[j][i];
    }
    cout << endl;
  }
  cout << "180" << endl;
  for(i=7;i>=0;i--){
    for(j=7;j>=0;j--){
      cout << s[i][j];
    }
    cout << endl;
  }
  cout << "270" << endl;
  for(i=7;i>=0;i--){
    for(j=0;j<8;j++){
      cout << s[j][i];
    }
    cout << endl;
  }
  return 0;
}

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

int main()
{
	int A, B;
	int max;
	cin >> A >> B;
	int a1, a2, a3;
	
	a1 = A + B;
	a3 = A * B;

	if (B < 0) {
		a2 = A - (B);
	}
	else {
		a2 = A - B;
	}
	
	if (a1 > a2) {
		if (a1 > a3) {
			max = a1;
		}
		else {
			max = a3;
		}
	}
	else if (a2 > a3) {
		max = a2;
		
	}
	else {
		max = a3;
	}

	cout << max;
	
	

}

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

int main()
{
    int a, b;

    cin >> a >> b;
    if (a + b == 15)
    {
        cout << "+" << endl;
    }
    else if (a * b == 15)
    {
        cout << "*" << endl;
    }
    else
    {
        cout << "x" << endl;
    }

    return 0;
}

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

int main()
{
    int N, sum=0;
    cin >> N;
    vector<int> p(N);
    vector<int> tmp(N);

    for (int i = 0; i < N; i++){
        cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    for (int i = 0; i < N; i++){
        if(i==N-1){
            sum += p.at(i) / 2;
        }
        else{
            sum += p.at(i);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 636
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll N, place[10] = {}, nextPlace[30000][10] = {}, ans = 0, box = 0;
string S;

int main() {
	cin >> N;
	cin >> S;
	for (int i = sz(S) - 1; i >= 0; i--) {
		rep(j, 10) {
			if (place[j] != 0)nextPlace[i][j] = place[j];
		}
		place[S[i] - '0'] = i;
	}
	rep(i, 10) {
		if (nextPlace[0][i] != 0 || S[0] - '0' == i) {
			if (S[0] - '0' == i) {
				box = 0;
			}
			else {
				box = nextPlace[0][i];
			}
			rep(j, 10) {
				if (nextPlace[box][j] != 0) {
					rep(k, 10) {
						if (nextPlace[nextPlace[box][j]][k] != 0)ans++;
					}
				}
			}

		}
	}
	cout << ans << endl;
	return 0;
}

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

#define       pb                 push_back
#define       mx                 200005
#define       MOD                1000000007
#define 	  optimize           ios::sync_with_stdio(0);cin.tie(0);
#define 	  inf                0x3f3f3f3f
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);

using namespace std;

typedef       long long int      ll;
typedef       vector<int> 	     vi;

int main()
{
    int a, b, cn=0;

    cin >> a >> b;

    if(b==1)
    {
        cout << 0 << endl;
        return 0;
    }

    int ans=0;

    ans += a;
    cn++;

    while(1)
    {
        if(ans>=b) break;

        ans += (a-1);
        cn++;
    }

    cout << cn << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	list<int> LIST;

	int Q;
	scanf("%d",&Q);

	int command,tmp;

	auto it = LIST.begin();

	for(int loop = 0; loop < Q; loop++){
		scanf("%d",&command);

		switch(command){
		case 0:
			scanf("%d",&tmp);
			it = LIST.insert(it,tmp);
			break;
		case 1:
			scanf("%d",&tmp);
			if(tmp > 0){

				for(int i = 0; i < tmp; i++){
					it++;
				}

			}else{

				for(int i = 0; i < abs(tmp); i++){
					it--;
				}

			}
			break;
		case 2:
			it = LIST.erase(it);
			break;
		}
	}

	it = LIST.begin();

	while(it != LIST.end()){
		printf("%d\n",*it);
		it++;
	}

	return 0;
}



Measured memory_bytes: 18760
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void) {

	int read = 0;

	string s;
	string d = "dream";
	string dr = "dreamer";
	string e = "erase";
	string er = "eraser";

	cin >> s;

//	cout << s.size()<<"\n";

	while (1) {
		if (equal(s.begin() + read, s.begin() + read + 5, d.begin()) == true) {

			if (equal(s.begin() + read, s.begin() + read + 7, dr.begin()) == true) {
				if (equal(s.begin() + read + 5, s.begin() + read + 10, e.begin()) == true) {
				//	cout << "trued\n";
					read += 5;
				}
				else {
				//	cout << "truedr\n";
					read += 7;
				}
			}
			else {
				//cout << "trued\n";
				read += 5;
			}
		}
		else if (equal(s.begin() + read, s.begin() + read + 5, e.begin()) == true) {

			if (equal(s.begin() + read, s.begin() + read + 6, er.begin()) == true) {
				//cout << "trueer\n";
				read += 6;
			}
			else {
				//cout << "truee\n";
				read += 5;
			}
		}
		else {
			cout << "NO\n";
			break;
		}

		if (read >= s.size()) {
			cout << "YES\n";
			break;
		}
	}
	

//	cout << s;

	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;
#define NNN_MAX 100010
typedef pair<int,int> P;

int max(int a,int b){
	if (a>b) return a;
	return b;
}

int min(int a,int b){
	if (a>b) return b;
	return a;
}

int abs(int a,int b){
	if(a>b) return a-b;
	return b-a;
}

int main (){
	//隣項和S、飛隣項和をとる、S-抜いた点の前後+飛ばした距離をたすこの和を取ればいい
	int NNN;
	cin >> NNN ;
	int a[NNN+2];
	a[NNN+1] =0;
	a[0]=0;
	rep(i,NNN){
		cin >> a[i+1];
	}

	int ichi[NNN+2];
	int allkyori=0;
	
	rep(i,NNN+1){
		ichi[i] = abs(a[i],a[i+1]);
		allkyori += ichi[i];
	}
	
	//抜いた項を考える
	int ni[NNN];

	Rep(i,1,NNN+1){
		ni[i] = abs(a[i-1],a[i+1]);
	}
	long int ans = 0;
	
	Rep(i,1,NNN+1){
		ans =0;
		ans = ans + allkyori;
		ans = ans - ichi[i] - ichi[i-1];
		ans = ans + ni[i];
		cout << ans << endl;
	}
	return 0;
}

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

int main(){

    int cnt=0;
    string s,t;
    cin>>s>>t;

    for(int i=0;i<3;i++){
        if(s.at(i)==t.at(i)) cnt++;
    }
    
    cout<<cnt<<endl;


    return 0;
}

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

int main () {
  int N;
  cin >> N;
  
  int data[N], count = 0;
  for (int i = 0; i < N; i++) {
    cin >> data[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i < j) {
        count += data[i]*data[j];
      }
    }
  }
  cout << count << endl;
}

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

using namespace std;

int main(){
    long long n, k, ans = 0;
    cin >> n >> k;
    for(long long i = 0; i < k; ++i){
        long long tmp; cin >> tmp;
        ans += tmp;
    }
    if(ans >= n)cout << "Yes";
    else cout << "No";


    return 0;
}


Measured memory_bytes: 256
fun main (args:Array<String>){
    val numOfTakoyaki = readLine()!!.toInt()
    val goodTaste = readLine()!!.split(" ").map(String::toInt)
    var recovery = 0
    var counter = 1
    for(i in 0..numOfTakoyaki-2){
        for(j in counter..numOfTakoyaki-1){
            recovery += goodTaste[i] * goodTaste[j]
        }
        counter++
    }
    println(recovery)
}

Measured memory_bytes: 36496
#include <cstdio>
#include <cstring>
#define MAX_NUM 32767

using namespace std;

void array_add(int *a,int *b){
	int i;
	for(i = MAX_NUM - 1;i > 0;i--){
		a[i] = a[i] + b[i];
		a[i - 1] = a[i - 1] + a[i] / 10;
		a[i] %= 10;
	}
}

int main(void){
	int n, i, j, len1,len2, val1[MAX_NUM], val2[MAX_NUM];
	char c;
	scanf("%d%*c",&n);
	for(i = 0;i < n;i++){
		for(j = 0;(c = getchar()) != '\n';j++){
			val1[j] = c - '0';
		}
		len1 = j;
		for(j = 0;(c = getchar()) != '\n';j++){
			val2[j] = c - '0';
		}
		len2 = j;
		for(j = MAX_NUM - 1;j > MAX_NUM - 1 - len1;j--){
			val1[j] = val1[len1 - 1 + (j - (MAX_NUM - 1))];
		}
		for(;j >= 0;j--){
			val1[j] = 0;
		}
		val1[MAX_NUM] = 0;
		for(j = MAX_NUM - 1;j > MAX_NUM - 1 - len2;j--){
			val2[j] = val2[len2 - 1 + (j - (MAX_NUM - 1))];
		}
		for(;j >= 0;j--){
			val2[j] = 0;
		}
		array_add(val1,val2);
		for(j = 0;val1[j] == 0 && j < MAX_NUM;j++);
		if(j <= MAX_NUM - 81)
			printf("overflow");
		else if(j == MAX_NUM)
			printf("0");
		else{
		for(;j < MAX_NUM;j++){
			printf("%d",val1[j]);
		}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1288
N =int(input())
S = input()
Q = int(input())
k = list(map(int, input().split()))
D = []
C = []
Sm = [0]*N
S1 = [0]*N

Sc = [0]*N
for i in range(N):
    if S[i] == 'D':
        D.append(i)
    elif S[i] == 'M':
        Sm[i] = 1
    elif S[i] == 'C': 
        C.append(i)
        S1[i] = 1
for i in range(1, N):
    Sm[i] = Sm[i-1]+Sm[i]
    S1[i] = S1[i-1]+S1[i]
for i in C:
    Sc[i] = Sm[i]
for i in range(1, N):
    Sc[i] = Sc[i-1]+Sc[i]
for ki in k:
    res = 0
    for d in D:
        end = min(d+ki-1,N-1)
        res+=Sc[end]-Sc[d]-(S1[end]-S1[d])*Sm[d]
    print(res)    

Measured memory_bytes: 118124
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	string s;
	cin >> s;
	reverse(s.begin(), s.end());

	string t = "";
	for (int i = 0; i < s.length(); i++) {
		if (s.substr(i, 5) == "maerd") {
			t += "maerd";
			i += 4;
		}else if (s.substr(i, 7) == "remaerd") {
			t += "remaerd";
			i += 6;
		}else if (s.substr(i, 5) == "esare") {
			t += "esare";
			i += 4;
		}else if (s.substr(i, 6) == "resare") {
			t += "resare";
			i += 5;
		}
	}

	cout << (s == t ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 640
import math
k=int(input())
res=0
A=[]
for a in range(1,k+1):
    for b in range(1,k+1):
        A.append(math.gcd(a,b))
for a in A:
    for c in range(1,k+1):
        res+=math.gcd(a,c)
print(res)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}



void insert(int k){
  Node y = NIL; //x' parent
  Node x = root; //T root
  Node z;

  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;

  if(y==NIL){
    root=z;
  }else if(z->key < y->key){
    y->left=z;
  }else{
    y->right=z;
  }
}

  


void inorder(Node u){
  if(u==NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u==NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25176
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>

using namespace std;

int main() {
	int n, m;
	string s, t;

	map<string, int> word;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		word[s]++;
	}

	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> t;
		word[t]--;
	}

	int ans = 0;
	for (auto p: word) {
		ans = max(ans, p.second);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
from collections import deque
import sys
sys.setrecursionlimit(10**7)
n = int(input())
ad_ls = [[] for _ in range(n)]
for _ in range(n-1):
    a,b,w = map(int,input().split())
    ad_ls[a-1].append([b-1,w])
    ad_ls[b-1].append([a-1,w])

cost_ls = [0] * n
done_ls = [0] * n
def dfs(v,c):
    for new,cost in ad_ls[v]:
        if not done_ls[new]:
            cost_ls[new] = c+cost
            done_ls[new] = 1
            dfs(new,c+cost)

dfs(0,0)

color_ls = [0] * n
for i in range(n):
    color_ls[i] = cost_ls[i] % 2

for color in color_ls:
    print(color)

Measured memory_bytes: 93764
/*
题意是求一个序列中"所有子序列的中位数"所组成的序列的中位数 
看题解了，完全不会。https://www.cnblogs.com/quzhizhou/p/9535597.html  

首先我们先二分最后序列的中位数。设tot为中位数 >= mid的区间个数，若中位数序列的中位数 >= mid，
则有tot >= n(n+1)/4。
我们另外构造一个序列b[i], 当a[i]>=mid时b[i]=1, 否则bi=-1. 
那么若区间[l, r]的中位数 >= mid, 则b[l]+...+b[r] >= 0. 
于是我们求出序列b[i]的前缀和序列sum[i]，那么问题就变成了求满足l <= r且sum[r]-sum[l-1]>=0的数对(l,r)数量(0<=l,r<=n)，
这个问题可以用与求逆序对数量相似的方法解决. 树状数组即可. 
*/ 
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;

const int NN = 110000;
int a[NN], l, r, n, mid, ans;
int s[NN * 2];  
//树状数组，注意，[-n-1, n], 为了让每一个存的值都是>0, 都加上n即可（因为树状数组不能从0开始）
//所以开双倍空间给数组 

int lowbit(int x){
	return x & (-x);
} 

void add1(int x, int k){
	while (x <= n * 2){
		s[x] += k;
		x += lowbit(x);
	}
}

int getsum(int x){
	int sum = 0;
	while (x > 0){
		sum += s[x];
		x -= lowbit(x);
	}
	return sum;
}
/*
bool check(int mid){
	//memset(s, 0, sizeof(s));  //树状数组清0 
	 for(int i=1;i<=2*n;i++)s[i]=0;
	//与求逆序对的方法相同 
	add1(n, 1);  //因为在每个数的基础上都加了n，所以这句话相当于在和等于0的点+1
	long long sum = 0;
	long long tmp = 0;
	for (int i=1; i<=n; i++){
		if (a[i] >= mid) sum++;
		else sum--;
		tmp += getsum(sum + n);
		add1(sum + n, 1);
	} 
	long long nn = n * (n + 1) / 4; //注意！nn必须给long long 
	if (tmp >= nn) return true;
	else return false;
}*/ 

int check(int mid)
{
    for(int i=1;i<=2*n;i++)s[i]=0;
    ll tot=0, sum=0;
    add1(n,1);
    for(int i=1;i<=n;i++){
        sum+=(a[i]>=mid?1:-1);
        tot+=getsum(sum+n);
        add1(sum+n,1);
    }
//    printf("%d %lld\n",mid,tot);
    return tot>=1ll*n*(n+1)/4;
}

int main(){
	//freopen("atcoderarc101d.in", "r", stdin);
	
	scanf("%d", &n);
	l = 0x7fffffff; r = 0;
	for (int i=1; i<=n; i++){
		scanf("%d", &a[i]);
		if (a[i] >= r) r = a[i];
		if (a[i] <= l) l = a[i];
	}
	//printf("%d %d\n", l, r);
	while (l <= r){
		mid = (l + r) / 2;
		if (check(mid)){
			ans = mid; 
			l = mid + 1;
		} else r = mid-1;
	}
	printf("%d", ans);
	
	
	/*while(l<r){
        int mid=(l+r+1)>>1;
        if(check(mid))l=mid;
        else r=mid-1;
    }
    printf("%d\n",l);*/
	
	return 0;
} 

Measured memory_bytes: 1408
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.List (uncons)
import Data.Maybe (fromJust)

main :: IO ()
main = do
  let
    f :: (Int, Int) -> (Int, Int)
    f (x, y) = (x - y, x + y)
    g :: (Int, Int) -> [(Int, Int)] -> ((Int, Int), (Int, Int))
    g (u0, v0) = foldl step ((u0, u0), (v0, v0))
      where
        step ((min0, max0), (min1, max1)) (u, v) = (g' min0 max0 u, g' min1 max1 v)
        g' s t u | u < s     = (u, t)
                 | t < u     = (s, u)
                 | otherwise = (s, t)
    h :: ((Int, Int), (Int, Int)) -> Int
    h ((min0, max0), (min1, max1)) = max (max0 - min0) (max1 - min1)
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  xys <- map (unsafeListToPair . map unsafeTextToInt . T.words) . T.lines <$> T.getContents :: IO [(Int, Int)]
  print . h . uncurry g . fromJust . uncons . map f $ xys

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 4868
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#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>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef unsigned long long ull;
const int IINF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

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

	vi v;
	REP(i, IINF) {
		if(i*i > 1<<15)
			break;
		v.pb(i*i);
	}
	int n;
	while(cin >> n, n) {
		int cnt = 0;
		REP(i, v.size()) {
			FOR(j, i, v.size()) {
				FOR(k, j, v.size()) {
					FOR(l, k, v.size()) {
						if(v[i]+v[j]+v[k]+v[l] > n)
							break;
						else if(v[i]+v[j]+v[k]+v[l] == n)
							cnt++;
					}
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
def main():
    n, K = map(int, input().split())
    a = list(map(int, input().split()))

    # dp[i] is true if First player wins with i tiles left
    dp = [False]*(K+1)
    for k in range(1, K+1):
        for i in a:
            if k >= i and not dp[k-i]:
                dp[k] = True
    print(['Second', 'First'][dp[K]])


if __name__ == "__main__":
    main()


Measured memory_bytes: 39792
h,n=map(int,input().split())
dp=[10000000000]*(10**5+1)
dp[0]=0

a=[]
b=[]
for _ in range(n):
    a1,b1=map(int,input().split())
    a.append(a1)
    b.append(b1)
for i in range(10**4+2):
    
    for j in range(n):
        dp[i+a[j]]=min((dp[i+a[j]]),dp[i]+b[j])
print(min(dp[h:]))

Measured memory_bytes: 75492
n = input()
countArray = [0] * 2019
count = 0
countArray[0] += 1
nums=0
for i in range(len(n))[::-1]:
    nums = nums + int(n[len(n)-1-i])*pow(10,i,2019)
    countArray[nums%2019]+=1

for i in countArray:
    count += (i * (i - 1)) // 2
print(count)

Measured memory_bytes: 9212
#include<iostream>
using namespace std;
int a[10] = {1,2,4,8,16,32,64,128,256,512};
int weight,b[11];


int main(){
  while(cin >> weight){
    int l = 0;
    for(int i = 0;i<10;i++)
      b[i] = 0;
    while(weight != 0){
      for(int i =9;i>=0;i--){
	if(weight >= a[i]){
	  weight = weight - a[i];
	  b[i] = 1;
	}
      }
    }
    for(int i=0;i<10;i++){
     
      if(b[i] == 1){
	   if(l != 0) cout << " ";
	   cout << a[i]; l++;
	}

    }
    cout << endl;
  }
}

Measured memory_bytes: 1160
//hail to jwalaji
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define N 100005
#define INF 1e18
int main(){
lli n,w;
cin>>n>>w;
vector<vector<lli>> dp(n+5,vector<lli>(100005,0));
vector<lli> weight(n),value(n);
for(lli i=0;i<n;i++){
    cin>>weight[i]>>value[i];
}
for(lli i=1;i<=n;i++){
    for(lli j=0;j<N;j++){
        dp[i][j]=dp[i-1][j];
            if(j-weight[i-1]>=0)
        dp[i][j]=max(dp[i][j],dp[i-1][j-weight[i-1]]+value[i-1]);
    }
}
lli ans=0;
for(lli i=0;i<=w;++i){
    if(dp[n][i]>ans){
        ans=dp[n][i];
    }
}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 86388
#include <bits/stdc++.h>  
using namespace std;
#define forn(i, n) for (int i = 0; i < n; i++)
#define re return
#define fi first
#define mp make_pair
#define se second
#define sz(a) (int)a.size()
#define prev previ
#define tm tmmm
#define div divv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll mod = ll(1e9) + 7;
const int mak = 8, ma = 1024 * 128 * 2;
ll n, ans;
vector<ll> aa;

int main() {
	iostream::sync_with_stdio(0), cin.tie(0);
	//freopen("a.in", "r", stdin);
	cin >> n;
	aa.resize(n);
	forn (i, n) cin >> aa[i];
	ll sm = 0;
	for (int i = 0; i < n; i++) {
		sm += aa[i];
		if (i % 2 == 0){
			ans += max(sm + 1, 0LL);
			sm = min(sm, -1LL);
		} else {
			ans += max(1LL - sm, 0LL);
			sm = max(sm, 1LL);
		}

	}
	//cout << ans << "\n";
	ll ans2 = ans; ans = 0;
	sm = 0;
	for (int i = 0; i < n; i++) {
		sm += aa[i];
		if (i % 2 == 1){
			ans += max(sm + 1, 0LL);
			sm = min(sm, -1LL);
		} else {
			ans += max(1LL - sm, 0LL);
			sm = max(sm, 1LL);
		}
	}
	ans = min(ans, ans2);
	cout << ans;
	re 0;
}



Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ll N; cin >> N;
  int K; cin >> K;
  FOR(i,0,K) {
    ll x, y; cin >> x >> y;
    x = min(x, N - x + 1);
    y = min(y, N - y + 1);
    cout << (min(x, y) % 3 == 0 ? 3 : min(x, y) % 3) << '\n';
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    ll A, B, N;
    cin >> A >> B >> N;
    if (B - 1 >= N)
    {
        cout << (ll)(A * N / B) - A * (ll)(N / B) << endl;
        return 0;
    }
    cout << (ll)(A * (B - 1) / B) - A * (ll)((B - 1) / B) << endl;
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  int e[m];
  bool state[n+1];
  fill(state,state+n+1,false);
  for(int i = 0; i < m; ++i) cin >> e[i];
  for(int i = m-1; i >= 0; --i){
    if(!state[e[i]]){
      cout << e[i] << endl;
      state[e[i]] = true;
    }
  }
  for(int i = 1; i <= n; ++i) if(!state[i]) cout << i << endl;
}

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

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

#define rep(i,n) for (ll i = 0; i < (n); i++)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;

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

	for (int i = 0; i < 1200 ; i++) {
		if ((int)(i * 0.08) == a) {
			if ((int)(i * 0.1) == b) {
				cout << i << endl;
				return 0;
			}
		}
	}

	cout << -1 << endl;
	return 0;
}

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

int main(){
    int n,m;
    cin>>n;
    vector<string> blue(n);
    for(int i=0;i<n;i++){
        cin>>blue[i];
    }
    cin>>m;
    vector<string> red(m);
    for(int i=0;i<m;i++){
        cin>>red[i];
    }
    int max=0;
    vector<int> bcnt(n);
    for(int i=0;i<n;i++){
        if(bcnt[i]==0){
            int tmp=1;
            for(int k=i+1;k<n;k++){
                if(blue[i]==blue[k]){
                    tmp++;
                    bcnt[k]=1;
                }
            }
            for(int k=0;k<m;k++){
                if(blue[i]==red[k]){
                    tmp--;
                }
            }
            if(tmp>max)max=tmp;
        }
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	ll n; cin>>n;
	ll cnt=0;
	string t;
	rep(i,0,n){
		int a; cin>>a;
		if(a==1){
			swap(s,t);
		}
		else{
			int b; cin>>b;
			char c; cin>>c;
			if(b==1) t.push_back(c);
			else s.push_back(c);
		}
	}
	reverse(all(t));
	cout<<t+s;
	
	return 0;
}

Measured memory_bytes: 1248
#include<iostream>
#include<cstdio>
using namespace std;
int cards[4][13];

int main(){
	int n;
	char suit;
	int number;
	for(int i=0;i<4;i++){
		for(int j=0;j<13;j++){
			cards[i][j] = 0;
		}
	}
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin >> suit >> number;
		number -= 1;
		if(suit == 'S') cards[0][number] = 1;
		else if(suit == 'H') cards[1][number] = 1;
		else if(suit == 'C') cards[2][number] = 1;
		else if(suit == 'D') cards[3][number] = 1;
	}
	for(int i=0;i<13;i++){
		if(cards[0][i] == 0) printf("S %d\n",i+1);
	}
	for(int i=0;i<13;i++){
		if(cards[1][i] == 0) printf("H %d\n",i+1);
	}
	for(int i=0;i<13;i++){
		if(cards[2][i] == 0) printf("C %d\n",i+1);
	}
	for(int i=0;i<13;i++){
		if(cards[3][i] == 0) printf("D %d\n",i+1);
	}
	return 0;
}

Measured memory_bytes: 3200
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    System.out.println(b%a==0?a+b:b-a);
  }
}

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

int main(){

    int a = 0;
    int b = 0;
    int c = 0;
    int temp = 0;
    int k = 0;
    int ans = 0;

    scanf("%d%d%d%d", &a, &b, &c, &k);

    temp = a;
    if (temp < b){
        temp = b;
    }
    if (temp < c){
        temp = c;
    }
   
    ans = a + b + c + temp * (pow(2, k) - 1);

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
// O(log N)　keyのある場所を返す。なかったら-1を返す
int search(int key, vector<int> a){
  int right = a.size();
  int left = 0;
  while(right >= left){
    int middle = left + (right - left) / 2;
    if(a[middle] == key) return middle; //keyが入ってる場所を返す
    else if(a[middle] > key) right = middle - 1;
    else if(a[middle] < key) left = middle + 1;
  }
  //なければ-1を返す
  return -1;
}
// O(N^2) babble sort
int main(){
  int n,m;
  cin >> n >> m;
  n -= m;
  int time = pow(2, m);
  int ans = 1900 * m * time;
  ans += 100 * n * time;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
A = tuple(map(int, input().split()))
mod = 10**9+7

niseven = (n%2 == 0)

cd = dict()
for a in (A):
    cd.setdefault(a, 0)
    cd[a] += 1
    if a == 0 and cd[a] > 1:
        print(0)
        break
    if a > 0 and cd[a] > 2:
        print(0)
        break
    if (a%2==0) == niseven:
        print(0)
        break
else:
    print(pow(2, n//2, mod))


Measured memory_bytes: 20688
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

const char RED_TILE = '#';
const char AT_TILE = '@';

int vx[4] = {0,1,0,-1};
int vy[4] = {-1,0,1,0};

int w,h;
int visited[20][20];
int map[20][20];

int search(int x, int y){
	int count = 1;
	visited[x][y] = true;
	for (int i=0;i<4;++i){
		int tx=x+vx[i];
		int ty=y+vy[i];
		if (tx<0 || tx>=w || ty<0 || ty>=h) continue;
		if (!visited[tx][ty] && map[tx][ty]){
			count += search(tx,ty);
		}
	}
	return count;
}

int main(){
	while (true){
		cin >> w >> h;
		if (w==0 && h==0) break;
		int sx, sy;
		for (int i=0;i<h;++i){
			string s;
			cin >> s;
			for (int l=0;l<w;++l){
				if (s[l] == RED_TILE) {
					map[l][i] = false;
				} else if (s[l] == AT_TILE) {
					map[l][i] = true;
					sx = l;
					sy = i;
				} else {
					map[l][i] = true;
				}
			}
		}
		for (int i=0;i<20;++i) for (int l=0;l<20;++l) visited[i][l]=false;
		int result = search(sx,sy);
		cout << result << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

ll x,ans;

int main()
{
    cin >> x;
    ans+=(x/500)*1000;
    x%=500;
    ans+=(x/5)*5;
    cout << ans << endl;
}


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

int main()
{
	int i,j,k;
	int n,m;
	
	cin >> n >> m;
	
	int A[n][m];
	int b[m];
	int c[n];
	
	for(i = 0; i < n; i++)
	{
		c[i] = 0;
	}
	
	for(i = 0; i < n; i++)
	{
		for(j = 0; j < m; j++)
		{
			cin >> A[i][j];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> b[i];
	}
	
	for(i = 0; i < n; i++)
	{
		for(j = 0; j < m; j++)
		{
			c[i] += A[i][j] * b[j];
		}
	}
	
	for(i = 0; i < n; i++)
	{
		cout << c[i] << endl;
	}
}


Measured memory_bytes: 3136
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;
vector<int>ans;
vector<vector<int>>adjl;
vector<int>vis;
void bfs(int u){
    queue<int>q;
    q.push(u);
    int sz=1,dep=0;

    for(;!q.empty();sz=q.size(),dep++){
        while(sz--){
            int temp =q.front();
            q.pop();
            vis[temp]=1;
            for(int i=0;i<adjl[temp].size();i++){
                if(!vis[adjl[temp][i]]){
                    q.push(adjl[temp][i]);
                    vis[adjl[temp][i]]=1;
                    if(adjl[temp][i]>u){
                        ans[dep+1]++;
                    }

                }
            }
        }
    }
}
int main()
{
    int n,x,y;
    scanf("%d%d%d",&n,&x,&y);
    x--,y--;
    ans.resize(n);
    adjl.resize(n);
    for(int i=0;i<n-1;i++){
        adjl[i].push_back(i+1);
        adjl[i+1].push_back(i);
    }
    adjl[x].push_back(y);
    adjl[y].push_back(x);
    for(int i=0;i<n-1;i++){
        vis.clear();
        vis.resize(n);
        bfs(i);
    }
    for(int i=1;i<n;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}



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

int main(){

    int n;
    cin>>n;
    vector<int> A(n/2),B(n/2);
    vector<int> AC(100001),BC(100001);
    for(int i=0;i<n;i++){
        if(i%2==0){
            cin>>A.at(i/2);
            AC.at(A.at(i/2))++;
        }
        else{
            cin>>B.at(i/2);
            BC.at(B.at(i/2))++;
        }
    }
    int maxa=0,maxb=-1,maxa2=0,maxb2=-1,ansa,ansb;
    for(int i=1;i<100001;i++){
        if(AC.at(i)>maxa){
            maxa2=maxa;
            maxa=AC.at(i);
            ansa=i;
        }
        else if(AC.at(i)>maxa2){
            maxa2=AC.at(i);
        }
        if (BC.at(i)>maxb){
            maxb2=maxb;
            maxb=BC.at(i);
            ansb=i;
        }
        else if(BC.at(i)>maxb2){
            maxb2=BC.at(i);
        }
    }
    if(ansa!=ansb){
    cout<<n-maxa-maxb<<endl;
    }
    else cout<<min(n-maxa2-maxb,n-maxa-maxb2)<<endl;
}



Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
#define MOD 1000000007
int main(){
    ll N;
    cin >> N;
    ll i,j,k=1;
    while(k*(k+1)/2<N){
        k++;
    }
    ll t=1;
    if(k*(k+1)/2==N){
        cout << "Yes" <<endl;
        cout << k+1 << endl;
        vector<ll> v[k+1];
        for(i=0;i<k;i++){
            for(j=i+1;j<k+1;j++){
                v[i].push_back(t);
                v[j].push_back(t);
                t++;
            }
        }
        for(i=0;i<k+1;i++){
            cout << k;
            for(auto itr=v[i].begin();itr!=v[i].end();++itr){
                cout << " " << *itr;
            }
            cout << endl;
        }
    }else{
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3200
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<set>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<vector>
#include<limits.h>
#include<functional>
#include<stack>
#include<map>
#include<unordered_map>
typedef long long ll;
#pragma GCC optimize(2)
#define maxn 100100
#define lowbit(x) x & -x
#define endl '\n'
#define int ll
using namespace std;
int s[maxn], f[maxn], ans[maxn];
int n, q, top;
void solve(int p, int x, int t) {
	f[p] += t * (x / s[p]);
	x %= s[p];
	p = lower_bound(s + 1, s + 1 + p, x) - s;
	if (p == 1)
		f[1] += t, ans[x + 1] -= t;
	else
		solve(p - 1, x, t);
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> n >> q;
	s[++top] = n;
	while (q--) {
		int x;
		cin >> x;
		while (top && x <= s[top])
			--top;
		s[++top] = x;
	}
	f[top] = 1;
	for (int i = top; i > 1; i--) {
		solve(i - 1, s[i], f[i]);
	}
	for (int i = 1; i <= s[1]; i++) {
		ans[i] += ans[i - 1];
		cout << ans[i] + f[1] << endl;
	}
	n -= s[1];
	while (n--) {
		cout << 0 << endl;
	}
	

	return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int calc(int z, int w) {return abs(z-w);}

int main() {
    int n, z, w;
    cin >> n >> z >> w;
    vint a(n);
    rep(i, n) cin >> a[i];

    int ans = calc(a[n-1], w);
    if (n >= 2) ans = max(ans, calc(a[n-2], a[n-1]));

    cout << ans << endl;
    return 0;
}

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

/*==========type============*/
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
typedef std::pair<std::string,ll> psl;

/*==========constant============*/
#define INF INT_MAX
#define INF_L LONG_MAX
#define INF_LL LLONG_MAX
#define MOD 1000000007

/*==========function============*/
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

using namespace std;

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

    double a,b,h,m;
    cin >> a >> b >> h >> m;

    double a_s = (h * 60 + m) * 0.5 * M_PI/180.0;
    double b_s = m*6* M_PI/180.0;
    // cout << a_s << " " << b_s << endl;

    double a_y = a, a_x = 0;
    double b_y = b, b_x = 0;
    double a_yy = a_x*sin(-a_s) + a_y*cos(-a_s);
    double a_xx = a_x*cos(-a_s) - a_y*sin(-a_s);
    double b_yy = b_x*sin(-b_s) + b_y*cos(-b_s);
    double b_xx = b_x*cos(-b_s) - b_y*sin(-b_s);

    double ans = sqrt(pow(a_yy-b_yy,2) + pow(a_xx-b_xx,2));
    
    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}    

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

int main() {
  string S;
  cin >> S;
  int A, Z;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'A') {
      A = i;
      break;
    }
  }
  for (int i = S.length() - 1; 0 <= i; i--) {
    if (S[i] == 'Z') {
      Z = i;
      break;
    }
  }
  cout << Z - A + 1 << endl;
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int a[1000];
int dp[1001][4][2];

int main() {
  int n;
  while(cin >> n) {
    REP(i,n) {
      cin >> a[i];
    }
    sort(a,a+n);
    if (n == 1) {
      cout << a[0] << endl;
      continue;
    } 
    
    REP(i,1001)REP(j,4)REP(k,2)dp[i][j][k]=INF;
    dp[2][0][0] = 0;
    for (int i=2; i<=n; ++i) {
      REP(_,10) {
        chmin(dp[i][0][0], dp[i][3][1]+a[1]);
        chmin(dp[i][3][1], dp[i][0][0]+a[1]);
        for (int S=3; S>=0; --S) {
          if (i+1<n) {
            chmin(dp[i+2][S][1], dp[i][S][0] + a[i+1]);
          }
          REP(j,2) {
            if (S>>j&1) {
              chmin(dp[i][S^(1<<j)][0], dp[i][S][1]+a[j]);
            } else {
              if (i<n) {
                chmin(dp[i+1][S|1<<j][1], dp[i][S][0]+a[i]);
              }
            }
          }
        }
      }
    }
    cout << dp[n][3][1] << endl;
  }
}


Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define endl '\n'
#define modulo 1000000007
#define int int64_t
//#pragma GCC optimize("trapv")
#define float double
#define PI acos(-1);
#define sinDegrees(x) sin((x) * PI / 180.0)
#define tanDegrees(x) tan((x) * PI / 180.0)
#define atanDegrees(x) atan(x)* 180.0 / PI
using namespace std;
int power(int x,int y,int m)
{
int temp;
if(y == 0)
return 1;
temp = (power(x, y/2,m))%m;
if (y%2 == 0)
return ((temp%m)*temp);
else
return ((x*temp%m)*temp%m)%m;
}
int inv(int x)
{
return (power(x,modulo-2,modulo))%modulo;
}
bool comp(int a,int b)
{
return a<b;
}
///Solution created by:Ahmadsm2005
int32_t main()
{
//freopen("output.txt","w", stdout);
//freopen("output.txt","r", stdin);
//iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k,x,y,counter=0;
cin>>n>>k>>x>>y;
for(int i=1;i<=n;i++)
if(i<=k)
counter+=x;
else
counter+=y;
cout<<counter;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, x;
    vector<int> ns, xs;
    long long loop = 0;
    while (!(n == 0 && x == 0)) {
        cin >> n >> x;
        loop++;
        xs.push_back(x);
        ns.push_back(n);
    }

    int counter = 0;
    int* cList = new int[loop];

    for(int i=0; i<loop-1; i++) {
        for(int j=1; j<ns[i]+1; j++) {
            for(int k=j+1; k<ns[i]+1; k++) {
                for(int l=k+1; l<ns[i]+1; l++) {
                    if(j+k+l == xs[i]) {
                        counter++;
                    }
                }
            }
        }
        cList[i] = counter;
        counter = 0;
    }
    for (int i=0; i<loop-1; i++)
    {
        cout << cList[i] << endl;
    }
    return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int main(){
  string s;
  cin >> s;

  int res = INT_MAX;
  for(char i = 'a'; i <= 'z'; i++){
    string tmp = s;
    int count = 0;
    while(true){
      bool flag = false;
      for (int j = 0; j < int(tmp.size()); j++) {
        if(tmp[j] != i) flag = true;
      }
      if(!flag) break;
      string tmp2 = "";
      count++;
      for (int j = 0; j < int(tmp.size())-1; j++) {
        if(tmp[j] == i || tmp[j+1] == i) tmp2 += i;
        else tmp2 += tmp[j];
      }
      tmp = tmp2;
    }
    // cout << count << endl;
    // cout << i << endl;
    res = min(res, count);
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define ALF "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LLBIG 1999999999999999999LL
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

int H, W, h, w;

int main() {
	cin >> H >> W >> h >> w;
	cout << H * W - H * w - h * W + h * w << endl;



	return 0;
}

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

int main() {
    int a,b,c,d,e,k;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;
    if(e - a > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
const int INF = 1e9 + 7;
     
int main(){
      IOS;
      int N, K;
      cin>>N>>K;
      int h[N], dp[N];
      for(int i=0;i<N;i++){
            cin>>h[i];
      }
      dp[0] = 0;
      dp[1] = abs(h[1]-h[0]);
      for(int i=2;i<N;i++){
            int mini = INT_MAX, j = i-1, ctr = K;
            while(j >= 0 && ctr > 0){
                  int val = abs(h[i] - h[j]) + dp[j];
                  if(val < mini)
                        mini = val;
                  --j;
                  --ctr;
            }
            dp[i] = mini;
      }
      cout<<dp[N-1];
      return 0;
}

Measured memory_bytes: 4384
#include <iostream>
#include<algorithm>

using namespace std;

int main() {
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;

	if (r <= x && x <= w - r) {
		if (r <= y && y <= h - r) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout<<"No"<<endl;
	}

	return 0;
}



Measured memory_bytes: 3116