akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n;
  cin >> n;
  long long h[n];
  vector<int> res;

  int count = 0;
  cin >> h[0];
  for (long i = 1; i < n; i++)
  {
    cin >> h[i];
    if(h[i] - h[i-1] <= 0){
      count++;
    }else{
      res.push_back(count);
      count = 0;
    }
  }
  res.push_back(count);
  sort(res.begin(), res.end(), greater<int>());
  
  cout << res[0] << endl;
}

Measured memory_bytes: 1528
using System;
using static System.Console;

namespace abc158
{
    class Program
    {
        static void Main()
        {
            var ab = ReadLine().Split(' ');
            var a = int.Parse(ab[0]) * 100;
            var b = int.Parse(ab[1]) * 100;
            for (var i = 0; i < 1010; ++i)
            {
                if (a == i * 8 - (i * 8) % 100 && b == i * 10 - (i * 10) % 100)
                {
                    WriteLine(i);
                    return;
                }
            }
            WriteLine(-1);
        }
    }
}


Measured memory_bytes: 27280
#include<stdio.h>
#include<math.h>
int main()
{
	int A,B,C,D,m,n,k;
	
	scanf("%d%d%d%d",&A,&B,&C,&D);
	
	if(A>=0 && A<=100 && B>A && B<=100 && C>=0 && C<=100 && D>C && D<=100)
	{
		if(C>=B || A>D)
			k=0;
			
		else
		{
			if(A>C)
				m=A;
			else
				m=C;
			if(B>D)
				n=D;
			else
				n=B;
				
			k=fabs(n-m);
		}
		printf("%d",k);
	}
	
	
	return 0;
}

Measured memory_bytes: 128
import copy
import numpy as np
from collections import deque
m,n = list(map(int, input().split()))
o2 = []
dist_mat = []
for i in range(m):
    o1 = list(str(input()))
    o2.append(o1)
    dist_mat.append(np.zeros(len(o1)))

in_mat = np.array(o2)
#dist_mat = np.zeros_like(in_mat)
dist_mat = []
for i in in_mat:
    dist_mat.append(np.zeros(len(i)))
dist_mat = np.array(dist_mat)
rows,cols = dist_mat.shape

qu = deque()

for r in range(rows):
    for c in range(cols):
        if in_mat[r][c] == ".":
            qu.appendleft((r,c))

dist_mat_base = copy.deepcopy(dist_mat)

ans = []
lenqu = len(qu)
for i in range(lenqu):
    strt = qu.pop()
    qu2 = deque()
    qu2.appendleft(strt)
    dist_mat = copy.deepcopy(dist_mat_base)

    while qu2:
        curr_r, curr_c = qu2.pop()
        dist = dist_mat[curr_r][curr_c]
        adj_cells = [(0,1), (1,0), (0,-1), (-1,0)]
        for r_adj, c_adj in adj_cells:
            adj_row = curr_r + r_adj
            adj_col = curr_c + c_adj
            if 0 <= adj_row < rows and 0 <= adj_col < cols:
                if dist_mat[adj_row][adj_col] == 0 and in_mat[adj_row][adj_col] == "." and not (adj_row, adj_col) == strt:
                    dist_mat[adj_row][adj_col] = dist + 1
                    qu2.appendleft((adj_row, adj_col))

    dist_vec = np.concatenate(dist_mat)
    ans.append(round(max(dist_vec)))

print(int(max(ans)))

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



const int N = 1e5 + 5, INF = 2e9;



int n, a[N][3], dp[N][3];


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 3; j++){
            cin >> a[i][j];
        }
    }
    dp[1][0] = a[1][0];
    dp[1][1] = a[1][1];
    dp[1][2] = a[1][2];
    for(int i = 2; i <= n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j != k){
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
                }
            }
        }
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]});
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

int H,W;
int N;

vint lis[222222];

signed main(){
    scanf("%lld%lld%lld",&H,&W,&N);
    rep(i,N){
        int y,x;
        scanf("%lld%lld",&y,&x);
        y--;x--;
        lis[y].pb(x);
    }

    rep(i,H)sort(all(lis[i]));
    int r=1;

    rep(i,H-1){
        if(lis[i+1].size()&&lis[i+1][0]<r){
            cout<<i+1<<endl;
            return 0;
        }
        if(lis[i+1].size()==0||lis[i+1][0]>r)r++;
        chmin(r,W);
    }
    
    cout<<H<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n,m,x,sz[200],da=0,xiao=0,i;
    scanf("%d%d%d",&n,&m,&x);
    for(i=0;i<m;i++)
    {
        scanf("%d",&sz[i]);
        if(sz[i]>x)
            da++;
        if(sz[i]<x)
            xiao++;

    }
    if(da>xiao)
        printf("%d\n",xiao);
    else
        printf("%d\n",da);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
//#define int long long
int32_t main()
{
	int n; cin >> n;
	cout << (!n);
    		
}

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

const int MAX_N = 10010;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int N, M;
    cin >> N >> M;
    priority_queue<pii, vector<pii>, greater<pii> > query;
    REP(i, M){
        int a, b;
        cin >> a >> b;
        if(a>b) swap(a, b);
        query.push(make_pair(a, b));
    }
    while(query.size()>1){
        pii x = query.top();query.pop();
        pii y = query.top();query.pop();
        if(x.first == y.first){
            pii z = make_pair(x.second, y.second);
            if(z.first>z.second) swap(z.first, z.second);
            if(z.first != z.second){
                query.push(z);
            }
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    if(query.size()==1){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
const ll INF = (1LL<<60);
const int MOD = 1000000007;

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

    ll al = 1, ol = 1, ng = 1;
    rep(i,n){
        al *= 10;
        al %= MOD;
        ol *= 9;
        ol %= MOD;
        ng *= 8;
        ng %= MOD;
    }
    ol -= ng;
    if(ol < 0) ol += MOD;

    ll res = al;
    res -= ng;
    res %= MOD;
    res -= ol;
    res %= MOD;
    res -= ol;
    res %= MOD;
    if(res < 0) res += MOD;
    cout << res << endl;
}

Measured memory_bytes: 3608
N = int(input())
W = [input() for _ in range(N)]

d = dict()
last = W[0][0]

good = True
for w in W:
    if d.get(w) != None:
        good = False
        break
    elif w[0] != last:
        good = False
        break
    else:
        d[w] = 1
        last = w[-1]

if good:
    print("Yes")
else:
    print("No")
        


Measured memory_bytes: 9100
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int X = sc.nextInt();

		int L[] = new int[N];
		int D[] = new int[N + 1];

		int count = 0;

		for (int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
		}

		for (int i = 0; i <= N; i++) {
			if (i == 0) {
				D[0] = 0;
				continue;
			}

			D[i] = D[i - 1] + L[i - 1];

		}

		for (int i = 0; i <= N; i++) {
			if (D[i] <= X) {
				count++;
			}
		}

		System.out.print(count);

	}
}


Measured memory_bytes: 23888
#include<set>
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

ll const MAX = 300007;
ll a[MAX];
ll color[MAX] = {};

struct numb {
	ll val; ll pos;
	bool operator<(const numb& rhs) const {
		return val < rhs.val;
	}
};
priority_queue<numb> pq1, pq2, pq3;

int main(){
	ll n;
	cin >> n;
	ll cnt = 0;
	REP(i, 1, 3 * n) {
		cin >> a[i];
	}
	REP(i, 1, n) {
		pq1.push({ -a[i],i });
		cnt += a[i];
	}
	REP(i, n + 1, 3 * n) {
		pq2.push({ a[i],i });
		cnt -= a[i];
	}
	REP(i, 1, n) {
		numb p = pq2.top();
		pq2.pop();
		color[p.pos] = 1;
		cnt += p.val;
		pq3.push({ -p.val,p.pos });
	}
	ll ans = cnt;
	REP(i, n + 1, n * 2) {
		pq1.push({ -a[i],i });
		cnt += a[i];
		numb p = pq1.top();
		cnt += p.val;
		pq1.pop();
		if (color[i] == 0) {
			cnt += a[i];
			numb q = pq3.top();
			while (q.pos <= i) {
				pq3.pop();
				q = pq3.top();
			}
			pq3.pop();
			cnt += q.val;
			color[q.pos] = 0;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;

}


Measured memory_bytes: 13420
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, a[110];
signed main() {
	cin >> n;
	double sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += 1.0 / a[i];
	}
	printf("%.12lf\n", 1.0 / sum);
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())

    pattern_num = 0
    for cake_num in range(N//4 + 1):
        for dotat_num in range(N//7 + 1):
            total_price = 4 * cake_num + 7 * dotat_num
            if total_price == N:
                pattern_num += 1

    if pattern_num >= 1:
        print("Yes")
    else:
        print("No")

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

#define check cout<<"-------"<<endl
#define debug(x) cout<<x<<endl;
#define loop(i,x,n) for(int i = x; i < n; i++)
#define lop(i,n) repi(i,0,n)
#define fix(x) cout<<fixed<<setprecision(x);

//Node構造体
typedef struct node {
    int value = -1;
    node *parent = nullptr;  //親
    node *left = nullptr; //左の子
    node *right = nullptr; //右の子
} Node;

//rootノードの仮作成
Node *root = nullptr;

void Free(Node *);
void Insert(int);
void InorderPrint(Node *);
void PreorderPrint(Node *);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; //命令の数
    cin>>N;
    
    char cmd[7]; //命令
    int v; //値
    while(N--) {
        cin>>cmd;
        if(cmd[0] == 'i') {  //入力がinsertの時
            cin>>v;
            Insert(v);
        } else if(cmd[0] == 'p') { //入力がprintの時
            InorderPrint(root);
            cout<<endl;
            PreorderPrint(root);
            cout<<endl;
        }
    }
    Free(root);
    return 0;
}

//メモリの開放
void Free(Node *a) {
    if(a->left != nullptr) Free(a->left);
    if(a->right != nullptr) Free(a->right);
    free(a);
}

//ノードを追加
void Insert(int x) {
    
    //追加するノードの作成
    Node *newNode = (Node *)malloc(sizeof(Node));
    newNode->value = x;
    
    //rootノード作成
    if(root == nullptr) {
        root = newNode;
        return;
    }
    
    Node *y;
    Node *subroot = root;
    while(subroot != nullptr) {
        y = subroot;
        if(subroot->value > x) subroot = subroot->left;
        else if(subroot->value < x) subroot = subroot->right;
    }
    
    newNode->parent = y;
    if(y->value > x) y->left = newNode;
    else if(y->value < x) y->right = newNode;
}

//inorder巡回
void InorderPrint(Node *a) {
    if(a->left != nullptr) InorderPrint(a->left);
    cout<<' '<<(*a).value;
    if(a->right != nullptr) InorderPrint(a->right);
}

//preorder巡回
void PreorderPrint(Node *a) {
    cout<<' '<<a->value;
    if(a->left != nullptr) PreorderPrint(a->left);
    if(a->right != nullptr) PreorderPrint(a->right);
}



Measured memory_bytes: 26468
#include <bits/stdc++.h>
  using namespace std;
 
  int main()
 {
     int n,l;
     cin >>n>>l;
      vector<string> vecS;
      while(n--)
      {
          string s;
          cin >> s;
          vecS.push_back(s);
      }
          sort(vecS.begin(), vecS.end());
          for(auto i: vecS)
          {
              cout << i;
          }
          cout << endl;
 }

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#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())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

const int K = 1005;
int s[2*K][2 * K];

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	REP(i, n) {
		int x, y;
		char ch[2];
		scanf("%d%d%s", &x, &y, &ch);
		if (ch[0] == 'B')x += k;
		x %= 2 * k;
		y %= 2 * k;
		FOR(ti, -2, 3) {
			FOR(tj, -2, 3) {
				if ((ti + tj+10) % 2 == 1)continue;
				int xs = max(min(x + tj * k, 2 * k), 0);
				int xe = max(min(x + tj * k + k, 2 * k), 0);
				int ys = max(min(y + ti * k, 2 * k), 0);
				int ye = max(min(y + ti * k + k, 2 * k), 0);
				s[xs][ys]++;
				s[xe][ys]--;
				s[xs][ye]--;
				s[xe][ye]++;
			}
		}
	}
	REP(i, 2 * k+1)REP(j, 2 * k) s[i][j + 1] += s[i][j];
	REP(i, 2 * k)REP(j, 2 * k+1) s[i+1][j] += s[i][j];
	int ret = 0;
	REP(i, 2 * k)REP(j, 2 * k)ret = max(ret, s[i][j]);
	cout << ret << endl;
	return 0;
}

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




def f(N, a, b):
    s = 0
    d = 1

    if a == b and a <= N:
        s += 1

    N0 = N

    N //= 10
    while(N > a):
        s += d
        d *= 10
        N //= 10
    
    if N == a:
        s += (N0 - d*a*10 - b)//10 + 1

    return s


N = int(input())

p = [[0]*10 for _ in range(10)]

for a in range(1, 10):
    for b in range(1, 10):
        p[a][b] = f(N, a, b)

s = 0
for a in range(1, 10):
    for b in range(1, 10):
        s += p[a][b]*p[b][a]

print(s)




Measured memory_bytes: 3064
/*
By Snickeen
*/
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VL vector<LL>
#define VII vector<PII >
#define VLL vector<PLL >
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define FF first
#define SS second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL MAXN=1e5+10;
LL t,n,m,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;

string s;

int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0;
	cin>>s;
	rep(i,0,s.size())
		cout<<(s[i]==','?' ':s[i]);
	cout<<endl;
	return 0;
}

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

int main()
{
	int X, Y,A,B,C,ANS;
	cin >> X >> Y;

	A = X + Y;
	B = X - Y;
	C = X * Y;

	if (A > B) {
		if (A > C)ANS = A;
		else ANS = C;
	}
	else {
		if (B > C)ANS = B;
		else ANS = C;
	}

	cout << ANS << endl;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const int N = 105;
const int K = 4;
ll dp1[N][K], dp2[N][K];

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	string s; int k;
	cin >> s >> k;
	int n = s.length();

	dp1[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= k; j++) {
			if (s[i-1] == '0') {
				dp1[i][j] += dp1[i-1][j];
				dp2[i][j] += dp2[i-1][j];
			}
			else {
				dp2[i][j] += dp1[i-1][j] + dp2[i-1][j];
			}

			if (j == 0) continue;

			for (char c = '1'; c <= '9'; c++) {
				if (c < s[i-1]) {
					dp2[i][j] += dp2[i-1][j-1] + dp1[i-1][j-1];
				}
				else if (c == s[i-1]) {
					dp1[i][j] += dp1[i-1][j-1];
					dp2[i][j] += dp2[i-1][j-1];
				}
				else {
					dp2[i][j] += dp2[i-1][j-1];
				}
			}
		}
	}
	cout << (dp1[n][k] + dp2[n][k]) << endl;
}


Measured memory_bytes: 256
include Math
theta = 90.0
puts $<.to_a.map{|i|i.split(',')}.map{|i|i.map(&:to_i)}.collect{|a|
  ret = [a[0] * cos(theta*PI/180.0), a[0] * sin(theta*PI/180.0)]
  theta -= a[1]
  ret
}.transpose.map{|i|i.inject(:+).to_i}.join("\n")

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  long long ans = 0;
  for(int i = 0; i < N; ++i)
    cin >> A[i];
  sort(A.rbegin(), A.rend());
  ans += A[0];
  int c = 1;
  for(int i = 1; i < N; ++i){
    if(c == N-1) break;
    ans += A[i], ++c;
    if(c < N-1) ans += A[i], ++c;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4020
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    ll r, D, x;
    cin >> r >> D >> x;
    for(int i = 0; i < 10; i++) {
        x = x*r - D;
        cout << x << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
main(){
	int n,m; std::cin>>n>>m;
  	std::vector<int> a(n);
    std::vector<std::pair<int,int>> p;
  	for(int i=0;i<n;++i) std::cin>>a[i];
  	std::sort(a.begin(),a.end());
  	for(int i=0;i<m;++i){
      	int a,b; std::cin>>a>>b; p.push_back({b,a});
    }
  	std::sort(p.begin(),p.end(),std::greater<std::pair<int,int>>());
  	for(int i=0,j=0;i<n;++i){
        if(p[j].first<=a[i] || j==m) break;
        a[i]=p[j].first; p[j].second--; if(!p[j].second) j++;
  	}
  	int64_t ret=0;
  	for(int i=0;i<n;++i) ret+=a[i];
  	std::cout<<ret;
}


Measured memory_bytes: 1784
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int kaijo (int a, int result) {
  if (a == 0) {
    return result;
  } else {
    return kaijo(a-1, result * a);
  }
}

int kaijo(int a) {
  return kaijo(a,1);
}

ll kaijo_ll (ll a, ll result) {
  if (a == 0) {
    return result;
  } else {
    return kaijo_ll(a-1, result * a);
  }
}

ll kaijo_ll(ll a) {
  return kaijo_ll(a,1);
}

int main () {
  int n;
  string s = "Yes";
  cin >> n;
  std::vector<int> h(n);
  rep(i,n) {
    cin >> h[i];
  }
  repr(i,n) {
    if(h[i] - h[i-1] <= -2) {
      s = "No";
      break;
    } else if(h[i] - h[i-1] == -1) {
      h[i-1] = h[i-1] - 1;
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 640
K = int(input())

# キューを作成
import queue
q = queue.Queue()
for i in range(1, 10):
  q.put(i)

# 取り出した要素に対して計算を行う
ans = 0
for i in range(K) :
  x = q.get()
  ans = x

  if (x%10) != 0 :
    q.put(10*x + x%10 - 1)

  q.put(10*x + x%10)

  if (x%10) != 9 :
    q.put(10*x + x%10 + 1)

print(ans)

Measured memory_bytes: 12452
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 998244353;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
  	int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    vi a;
    int tmp=1, sol=0;
    
    for(int i=0; i<n-2; i++){
        if(s[i]==s[i+1])
            tmp++;
        else{
            a.push_back(tmp);
            tmp=1;
        }
    }
    if(s[n-2]==s[n-1])
        tmp++;
    else{
        a.push_back(tmp);
        tmp=1;
    }
    a.push_back(tmp);
        
    for(int i=0; i<a.size(); i++)
        if(a[i]>1)
            sol+=a[i]-1;
    cout << min(sol+2*k, n-1);
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll p(n);
  rep(i,n) cin>>p[i], p[i]--;
  ll ans=0;
  vb b(n);
  rep(i,n){
    if(i==p[i]){
      ans++;
      b[i]=true;
    }
  }
  rep(i,n-1){
    if(b[i]&&b[i+1]){
      ans--;
      b[i]=b[i+1]=false;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#なぜ生きる？
#それは死ぬまでの暇つぶし
#人生など所詮その程度
K=int(input())
A,B=map(int,input().split())
for i in range(A,B+1):
    if i%K==0:
        print("OK")
        exit()
print("NG")

Measured memory_bytes: 9168
#include <bits/stdc++.h>
 
using namespace std;
 
//const int MOD=1e9+7;
 
const int MOD=998244353;


 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    double n,h,w;
    cin>>h>>w>>n;
    
    cout<<min(ceil(n/h),ceil(n/w));
    
    
    
    
    return 0;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

struct edge{
	int from, to;
	edge(int from, int to):from(from), to(to){}
};
using node = vector<edge>;
using graph = vector<node>;
void addedge(graph &g, int from, int to, bool bidirectional = false){
	g[from].emplace_back(edge(from, to));
	if(bidirectional)g[to].emplace_back(edge(to, from));
}


class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		vector<string> ss(n);
		for(int i=0; i<n; i++)cin >> ss[i];
		graph g(n);
		for(int i=0; i < n; i++)for(int j=0; j < n; j++)if(ss[i][j] == '1')addedge(g, i, j);
		int ret = 0;
		for(int i=0; i < n; i++){
			queue<int> q;
			vector<int> idx(n, -1);
			q.push(i);
			idx[i] = 0;
			while(!q.empty()){
				auto u = q.front();
				q.pop();
				for(auto e: g[u]){
					if(idx[e.to] != -1){
						if(idx[e.to] == idx[u]){
							cout << -1 << endl;
							return;
						}
					}else{
						idx[e.to] = idx[u] + 1;
						q.push(e.to);
					}
				}
			}
			for(int j=0; j < n; j++){
				updmax(ret, idx[j] + 1);
			}
		}
		cout << ret << "\n";
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

int A,B,C,D,cnt,ans;
int line[200];

int main(){
	
	scanf("%d %d %d %d",&A,&B,&C,&D);
	
	if(A > B) swap(A,B);
	if(C > D) swap(C,D);
	
	line[A]++;
	line[B]--;
	line[C]++;
	line[D]--;
	
	for(int i = 0;i <= 105;i++){
		cnt += line[i];
		if(cnt > 1) ans++;
	}
	
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;


long long a[2000];
long long dp_max[2000];
long long dp_min[2000];
int main(){
    int N;
    cin >> N;
    long long Z;
    long long W;
    cin >> Z >> W;
    for(int i = 0; i < N; i++){
        cin >> a[N - 1 - i];
    }
    if(N == 1){
        cout << abs(a[0] - W) << endl;
        return 0;
    }

    dp_max[0] = abs(a[0] - a[1]);
    dp_min[0] = abs(a[0] -a[1]);

    for(int i = 1; i < N - 1; i++){
        dp_max[i] = abs(a[i + 1] - a[0]);
        dp_min[i] = abs(a[i + 1] - a[0]);
        for(int j = 0; j < i; j++){
            dp_max[i] = max(dp_max[i], dp_min[j]);
            dp_min[i] = min(dp_min[i], dp_max[j]);
        }
    }
    dp_max[N - 1] = abs(W - a[0]);
    dp_min[N - 1] = abs(Z - a[0]);
    for(int i = 0; i < N - 1; i++){
        dp_max[N - 1] = max(dp_max[N - 1], dp_min[i]);
        dp_min[N - 1] = min(dp_min[N - 1], dp_max[i]);
    }
    cout << dp_max[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
sub f{my$i=pop;$p[$i]=$p[$i]-$i?f($p[$i]//=$i):$i}
($N,$M)=glob<>;
@s=(0,(1)x$N);
$%=$N*($N-1)/2;
map{
	unshift@a,$%;
	($A,$B)=glob;
	$A=f$A;
	$B=f$B;
	if($A!=$B){
		$%-=$s[$A]*$s[$B];
		$s[$B]+=$s[$A];
		$p[$A]=$B
	}
}reverse<>;
print"@a"


Measured memory_bytes: 41472
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;


int main(){
	int W, H, N;
	cin >> W >> H >> N;
	vector<int> x(N), y(N), a(N);
	int i, j, k;
	for (i = 0;i < N;i++) cin >> x[i] >> y[i] >> a[i];
	int color[100][100] = { 0 };
	for (i = 0;i < N;i++) {
		if (a[i] == 1) {
			for (j = 0;j < x[i];j++) {
				for (k = 0;k < H;k++) color[j][k] = 1;
			}
		}
		if (a[i] == 2) {
			for (j = x[i];j < W;j++) {
				for (k = 0;k < H; k++) color[j][k] = 1;
			}
		}
		if (a[i] == 3) {
			for (j = 0;j < y[i];j++) {
				for (k = 0;k < W;k++) color[k][j] = 1;
			}
		}
		if (a[i] == 4) {
			for (j = y[i];j < H;j++) {
				for (k = 0;k < W;k++) color[k][j] = 1;
			}
		}
	}
	int white = W*H;
	for (i = 0;i < W;i++) {
		for (j = 0;j < H;j++) white -= color[i][j];
	}
	cout << white << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

int n, u, v;

ll ans;

int main() {
	scanf("%d", &n); ans = 1ll * n * (n + 1) * (n + 2) / 6ll;
	for (int i = 1; i < n; ++i) {
		scanf("%d%d", &u, &v);
		if (u > v) swap(u, v);
		ans -= 1ll * u * (n - v + 1);
	}  printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 3824
import java.util.Scanner;

public class Main{
	

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int []a = new int [n];
		boolean p = false;
		for(int i = 0 ; i < n ;i++) {
			a[i] = Integer.parseInt(sc.next());
			if(a[i] % 2 != 0) {
				p = true;
			}
		}
		
		if(p) {
			System.out.println("first");
		}
		else {
			System.out.println("second");
		}
		
		
	
	}
}


Measured memory_bytes: 48812
#include <stdio.h>
int main(void){
    // Your code here!
    int N,T,t,c,A,B,cmin = 10000;
    scanf("%d %d",&N,&T);
    for(int i = 0; i < N; i++)
    {
        scanf("%d %d",&c,&t);
        if(t<=T && c<cmin) cmin = c;
    }
    if(cmin > 1000) printf("TLE\n");
    else            printf("%d\n",cmin);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	vector<pair<ll, ll>> to(M);
	vector<ll> box(N, 1);
	vector<bool> come_red(N, false);
	come_red[0] = true;
	
	for (ll i = 0; i < M; ++i)
	{
		ll a, b; cin >> a >> b;
		--a, --b;
		to[i] = pair<ll, ll>(a, b);

		--box[a], ++box[b];
		if (come_red[a])
			come_red[b] = true;
		if (box[a] == 0)
			come_red[a] = false;
	}
	
	ll res{0};
	for (ll i = 0; i < N; ++i)
	{
		if (come_red[i] && box[i])
			++res;
		
	}
	
	std::cout << res << std::endl;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
 


int main() {
	priority_queue<int>que;
	int n;
	string st;
	while (1) {cin >> st;
		if (st == "end")break;
		else if (st == "insert") {
			 cin >> n;
			que.push(n);
		}
		else if (st == "extract") {
			cout << que.top() << endl;
			que.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 7048
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
#define PI 3.14159265358979

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

    c=a-2*b;
   if(c<0){
       cout<<0;
   }

    else cout<<c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 10
#define INF 1e9
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
 
int H,W,sx,sy,gx,gy;
int field[MAX][MAX];
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
 
bool inField(int x,int y){
    return 0 <= x && x < W && 0 <= y && y < H;
}
 
int bfs(){
    queue<piii> Q;
    Q.push(piii(pii(sx,sy),6));
    int d[MAX][MAX][7];
    fill(d[0][0],d[0][0]+MAX*MAX*7,INF);
    d[sy][sx][6] = 0;
   
    while(!Q.empty()){
	piii p = Q.front(); Q.pop();
	int x = p.first.first, y = p.first.second;
	int life = p.second;
 
	if(x == gx && y == gy){
	    return d[y][x][life];
	}                                        
	if(life == 1) continue;
	for(int i = 0 ; i < 4 ; i++){
	    int nx = x + dx[i];
	    int ny = y + dy[i];
	    if(!inField(nx,ny)) continue;
	    if(field[ny][nx] == 0) continue;
	    if(field[ny][nx] == 4){
		if(d[y][x][life] + 1 < d[ny][nx][6]){
		    d[ny][nx][6] = d[y][x][life] + 1;
		    Q.push(piii(pii(nx,ny),6));
		}
	    }else{
		if(d[y][x][life] + 1 < d[ny][nx][life-1]){
		    d[ny][nx][life-1] = d[y][x][life] + 1;
		    Q.push(piii(pii(nx,ny),life-1));
		}
	    }
	}    
    }
    return -1;
}
 
int main(){
    while(cin >> W >> H, W){
	for(int i = 0 ; i < H ; i++){
	    for(int j = 0 ; j < W ; j++){
		cin >> field[i][j];
		if(field[i][j] == 2){
		    sx = j; sy = i;
		}else if(field[i][j] == 3){
		    gx = j; gy = i;
		}
	    }
	}
	cout << bfs() << endl;
    }
    return 0;
}

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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b==c||a+c==b||c+b==a) puts("Yes");
  else puts("No");
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()

const int MAXN = 1e5 + 10;
ll x, y, n, m, k;
ll a[MAXN];
ll b[MAXN];
ll c[MAXN];
vector <ll> tmp;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> x >> y >> n >> m >> k;
	for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= m; ++i) cin >> b[i];
    for(int i = 1; i <= k; ++i) cin >> c[i];
    sort(a + 1, a + n + 1);
    sort(b + 1, b + m + 1);
    sort(c + 1, c + k + 1);
    reverse(c + 1, c + k + 1);
    for(int i = n - x + 1; i <= n; ++i) tmp.pb(a[i]);
    for(int i = m - y + 1; i <= m; ++i) tmp.pb(b[i]);
    sort(tmp.begin(), tmp.end());
    ll ans = accumulate(a + n - x + 1, a + n + 1, 0ll);
    ans += accumulate(b + m - y + 1, b + m + 1, 0ll);
    for(int i = 1; i <= min(k, (ll)tmp.sz); ++i)
        if(c[i] - tmp[i - 1] > 0) ans += (c[i] - tmp[i - 1]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,x,n) for (int i = x; i < n; i++)
using ll = long long int;
int main() {
    long double pi = 3.14159265358979323846264338327950;
    int a,b,h,m; cin >> a >> b >> h >> m;
    long double rad = pi*2.0*(
        (long double)h/12.0+((long double)m/60.0)/12.0
            -(long double)m/60.0);
    long double raq = (long double)(a*a+b*b)
        -(long double)(2.0*a*b)*cosl(rad);
    cout << fixed << setprecision(20) << sqrtl(raq) << endl;
    return 0;
}

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

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;

    //-1で初期化
    //最初はすべてバラバラ
    UnionFind(int N){
        parent = vector<int>(N,-1);
    }

    //Aがどのグループに属しているか(Aの根)を調べる
    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A){
        return -parent[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B) {
    //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        //既にくっついているからくっつけない
        if(A == B) return false; 

        //大きいほう(A)に小さいほう(B)をくっつける
        //大証が逆ならひっくり返す
        if(size(A) < size(B)) swap(A,B);

        //Aのサイズを更新する
        parent[A] += parent[B];
        //Bの親をAに変更する
        parent[B] = A;

        return true;
    }

    //AとBが同じグループならtrueを返す
    bool same(int A, int B){
        return root(A)==root(B);
    } 
};

int main(){
    int n;
    cin>>n;
    vector<tuple<long long,long long,int>> vx,vy;
    for(int i=0;i<n;i++){
        long long x,y;
        cin>>x>>y;
        x--,y--;
        vx.push_back(make_tuple(x,y,i));
        vy.push_back(make_tuple(y,x,i));
    }

    vector<tuple<long long,int,int>> v;
    sort(vx.begin(),vx.end());
    sort(vy.begin(),vy.end());

    for(int i=1;i<n;i++){
        v.push_back(make_tuple(get<0>(vx[i])-get<0>(vx[i-1]),get<2>(vx[i]),get<2>(vx[i-1])));
        v.push_back(make_tuple(get<0>(vy[i])-get<0>(vy[i-1]),get<2>(vy[i]),get<2>(vy[i-1])));
    }
    sort(v.begin(),v.end());

    UnionFind uni(n);
    long ans=0;
    for(auto i:v){
        if(!uni.same(get<1>(i),get<2>(i))){
            uni.connect(get<1>(i),get<2>(i));
            ans+=get<0>(i);
        }
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 13860
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

c = 0
n.times do |i|
    c += a[i] <= b[i] ? (b[i] - a[i]) / 2 : b[i] - a[i]
end

puts c >= 0 ? "Yes" : "No"

Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
ll getGCD(ll a, ll b)
{
    // Greatest Common Divisor
    if (b == 0)	return a;
    return getGCD(b, a % b);
}
int main()
{
    // AGC018-A, 1168, 
    int n, k; cin >> n >> k;
    vector<int> a(n);
    bool isFoundOdd = false;
    rep(i, n) {
        cin >> a[i];
        if (a[i] % 2 == 1) isFoundOdd = true;
    }
    if (n == 1 && k != a[0]) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    else if (n == 1) {
        cout << "POSSIBLE" << endl;
        return 0;
    }
    sort(ALL(a));
    if (a.back() < k) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    if (!isFoundOdd && k % 2 == 1) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    ll gcd = llINF;
    rep(i, n - 1) {
        gcd = min(gcd, getGCD(a[i], a[i + 1]));
    }
    if (k % gcd != 0) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    cout << "POSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 3716
#import pysnooper
import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

s=input().rstrip()
ans=0
while 1:
    t=input().rstrip().split()
    if t[0]=="END_OF_TEXT":
        break
    for i in t:
        if s==i.lower():
            ans+=1
print(ans)


Measured memory_bytes: 6724
import sys
n = int(input())
memo_ls = [{i : [] for i in range(11)} for j in range(11)]
alpha = "abcdefghijklmnopqrstuvwxyz"
#memo_ls[i][j] : i個をjに分ける方法
memo_ls[1][1] = ["a"]
for i in range(1,10):
    for j in range(11):
        if j > i:
            continue
        else:
            for v in memo_ls[i][j]:
                for k in range(j):
                    memo_ls[i + 1][j].append(v + alpha[k])
                memo_ls[i+1][j+1].append(v + alpha[j])
ls = []
for i in range(11):
    for j in memo_ls[n][i]:
        ls.append(j)
print("\n".join(sorted(ls)))

Measured memory_bytes: 17952
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define ll long long
#define MODD 1000000007
#define ll long long
using namespace std;

int main() {
    int N;
    cin>>N;
    
    
    map<int,int> cts;
    
    for(int x=2;x<=N;x++) {
        int y=x;
        for(int i=2;i<=y;i++) {
            if (y%i==0) {
                int ct=0;
                while(y%i==0) {
                    ct++;
                    y/=i;
                }
                cts[i]+=ct;
            }
        }
    }
    
    ll answer = 1;
    
    for(map<int,int>::iterator it = cts.begin();
        it != cts.end();
        ++it) {
        answer = (answer * (it->second + 1))%MODD;
    }
    
    cout << answer << endl;
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	string s;
	cin >> s;
	reverse(s.begin(),s.end());
	int flag =0;
	while(1){
		if(s.size()==0){
			flag =1;
		}
		if(s.size()>=7&&s.substr(0,7)=="remaerd"){
			s.erase(s.begin(),s.begin()+7);
		}else if(s.size()>=5&&s.substr(0,5)=="maerd"){
			s.erase(s.begin(),s.begin()+5);
		}else if(s.size()>=6&&s.substr(0,6)=="resare"){
			s.erase(s.begin(),s.begin()+6);
		}else if(s.size()>=5&&s.substr(0,5)=="esare"){
			s.erase(s.begin(),s.begin()+5);
		}else{
			break;
		}
	}
	if(flag==1)cout << "YES" <<endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

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

		for (int i = 0; i < S.length(); i++) {

			if(S.charAt(i) == 'o') {
				c++;
			}
		}

		System.out.println(700 + c * 100);

		return;
	}

}


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


def solve():
    S, T = input(), input()
    q = int(input())

    ls, lt = len(S), len(T)
    acs, act = [0]*(ls+1), [0]*(lt+1)

    for i in range(1, ls+1):
        acs[i] = acs[i-1] + (S[i-1]=="A")
    for i in range(1, lt+1):
        act[i] = act[i-1] + (T[i-1]=="A")

    for _ in range(q):
        a, b, c, d = map(int, input().split())
        print("YES" if (acs[b]-acs[a-1]+b-a+1)%3==(act[d]-act[c-1]+d-c+1)%3 else "NO")

solve()


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        ll k, x;
        cin >> k >> x;
        for (ll i = x - k + 1; i < x + k; ++i) {
            cout << i << " ";
        }

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<memory.h>
using namespace std;
int main()
{
	while (1){
		char map[101][101];
		bool flag[101][101];
		bool f = false;
		
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0){
			return 0;
		}
		memset(flag, 0, sizeof(flag));
		for (int i = 0; i < h; i++){
			for (int i2 = 0; i2 < w; i2++){
				cin >> map[i][i2];
			}
		}
		int x, y;
		x = 0; y = 0;
		if (map[y][x] == '>'){
			x++;
		}
		if (map[y][x] == '<'){
			x--;
		}
		if (map[y][x] == '^'){
			y--;
		}
		if (map[y][x] == 'v'){
			y++;
		}

		while (map[y][x] != '.'){
			if (flag[y][x] == true){
				cout << "LOOP" << endl;
				f = true;
				break;
			}
			if (map[y][x] == '>'){
				flag[y][x] = true;
				x++;
			}
			else if (map[y][x] == '<'){
				flag[y][x] = true;
				x--;
			}
			else if (map[y][x] == '^'){
				flag[y][x] = true;
				y--;
			}
			else if (map[y][x] == 'v'){
				flag[y][x] = true;
				y++;
			}

		}
		if (!f){
			cout << x << " " << y << endl;
		}
	}
}

Measured memory_bytes: 1188
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int ans = 0;
	for(int i = 0; i<=a; i++)
		for(int j = 0; j<=b;j++)
			for(int k =0 ;k<=c;k++)
			{
				if(i*500+j*100+k*50==x) ans++;
			}
			cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(0, a + 1):
    for j in range(0, b + 1):
        for k in range(0, c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                ans += 1
print(ans)


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

int main()
{
int a, b, c;
char op;
do
{
cin >> a >> op >> b;

if(op == '+')
{
c = a + b;
cout << c << endl;

}

else if (op == '-')
{
c = a - b;
cout << c <<endl;
}

else if (op == '/')
{
	c = a / b;
	cout << c <<endl;
}
else if (op == '*')
{
	c = a * b;
	cout << c <<endl;
}
else 
{

}
}
while(op != '?');

}


Measured memory_bytes: 3092