akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static llong MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<int> P(m, 0);
    vector<int> Y(m, 0);
    vector<vector<int> > V(n);
    rep(i, m) {
        int p, y;
        cin >> p >> y;
        V[p - 1].push_back(y);
        P[i] = p;
        Y[i] = y;
    }

    rep(i, n) {
        sort(all(V[i]));
    }

    rep(i, m) {
        auto itr = lower_bound(V[P[i] - 1].begin(), V[P[i] - 1].end(), Y[i]);
        cout << setfill('0') << right << setw(6) << P[i];
        cout << setfill('0') << right << setw(6) << distance(V[P[i] - 1].begin(), itr) + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 7808
// Problem : F - Three Variables Game
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
//#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
//int rnd(int x) { return mrand() % x;}
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 1e5 + 10; 

int n,a,b,c;
int type[maxn],cnt[3];

int main()
{
	fastIO;
	cin >> n >> a >> b >> c;
	rep(i,0,n) {
		string s; cin >> s;
		if(s == "AB") type[i] = 0;
		else if(s == "AC") type[i] = 1;
		else type[i] = 2;
		//cnt[type[i]]++;
	}	
	int suc = 1;
	vector<char>ans;
	rep(i,0,n){
		if(type[i] == 0) {
			if(a > b) a--,b++,ans.pb('B');
			else if(b > a) a++,b--,ans.pb('A');
			else {
				if(i == n - 1 || type[i + 1] == type[i]){
					a--,b++,ans.pb('B');
				}
				else if(a == 1 && c == 0) {
					if(type[i + 1] == 1) {
						a++,b--,ans.pb('A');
					}
					else {
						a--,b++,ans.pb('B');
					}
				}
				else {
					a--,b++,ans.pb('B');
				}
			}
		}
		else if(type[i] == 1){
			if(a > c) a--,c++,ans.pb('C');
			else if(c > a) a++,c--,ans.pb('A');
			else {
				if(i == n - 1 || type[i + 1] == type[i]){
					a--,c++,ans.pb('C');
				}
				else if(a == 1 && b == 0) {
					if(type[i + 1] == 2) {
						a--,c++,ans.pb('C');
					}
					else {
						a++,c--,ans.pb('A');
					}
				}
				else {
					a--,c++,ans.pb('C');
				}
			}
		}
		else {
			if(b > c) b--,c++,ans.pb('C');
			else if(c > b) b++,c--,ans.pb('B');
			else {
				if(i == n - 1 || type[i + 1] == type[i]){
					b--,c++,ans.pb('C');
				}
				else if(b == 1 && a == 0) {
					if(type[i + 1] == 0) {
						b++,c--,ans.pb('B');
					}
					else {
						b--,c++,ans.pb('C');
					}
				}
				else {
					b--,c++,ans.pb('C');
				}
			}
		}
		if(a < 0 || b < 0 || c < 0) {
			suc = 0;
			break;
		}
		//cnt[type[i]]--;
	}
	if(!suc) cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		for(auto it : ans) cout << it << endl; 
	}
	return 0;
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};

int a, b, c, x, y;



int main(){
	cin >> a >> b >> c >> x >> y;

	vector<llong int> rets;
	rets.push_back(a*x + b*y);
	rets.push_back(c*2*max(x, y));
	rets.push_back(c*2*min(x, y) + a*(x-min(x, y)) + b*(y-min(x, y)));
	sort(rets.begin(), rets.end());
	cout << rets[0] << endl;

	return 0;
}

Measured memory_bytes: 256
c = [list(map(int,input().split())) for i in range(3)]
a = c[0][0]-c[1][0]
b = c[1][0]-c[2][0]
d = c[0][0]-c[2][0]

if (a == c[0][1]-c[1][1]) and (a==c[0][2] - c[1][2]):
  if (b == c[1][1] - c[2][1]) and (b == c[1][2]-c[2][2]):
    if (d == c[0][1]-c[2][1]) and (d == c[0][2]-c[2][2]):
      print('Yes')
      exit()
      
      
print('No')

Measured memory_bytes: 3192
#include <iostream>
#include <string>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int h, w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    bool ans = true;
    const int dx[4] = {1, 0, -1, 0};
    const int dy[4] = {0, -1, 0, 1};
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '.') {
                continue;
            }
            bool single = true;
            for (int k = 0; k < 4; k++) {
                int tx = i + dx[k], ty = j + dy[k];
                if (tx >= 0 && tx < h && ty >= 0 && ty < w && s[tx][ty] == '#') {
                    single = false;
                }
            }
            if (single) {
                ans = false;
            }
        }
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll memo[100005][2][101];
int done[100005][2][101],cc=1;

ll dp(int i,int issmall,int rem,const int &d,const string &S,const int &len){
    if(i == len){
        if(rem == 0)
            return 1;
        return 0;
    }
    if(done[i][issmall][rem] == cc)
        return memo[i][issmall][rem];
    ll res = 0;
    int r = S[i] - '0';
    if(issmall){

        for(int j = 0;j<=9;j++){
            if(j >0 && i == 0) continue;
            res = (res + dp(i+1,issmall,(rem+j)%d,d,S,len) )%mod;
        }
    }
    else{
        for(int j = 0;j<r;j++){
            if(j == 0 && i == 0) continue;
            res = (res + dp(i+1,1,(rem+j)%d,d,S,len) )%mod;
        }
        res = (res + dp(i+1,0,(rem+r)%d,d,S,len) )%mod;
    }


    memo[i][issmall][rem] = res;
    done[i][issmall][rem] = cc;
    return res;
}

int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    string S;
    int d;
    cin >> S;
    scanf("%d",&d);
    ll res = (dp(0,0,0,d,S,S.size()) + dp(0,1,0,d,S,S.size()) -1 + mod)%mod;
    printf("%lld\n",res);
	return 0;
}


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

const int inf = -1000;

int main() {

    int n;
    cin>>n;

    int arr[n];

    for(int i=0;i<n;++i)
        cin>>arr[i];
    int ct  =0;
    for(int i=0;i<n-2;++i){
       int x = min(arr[i],arr[i+2]);
       int y = max(arr[i],arr[i+2]);
       if(arr[i+1]>x&&arr[i+1]<y)
        ct++;
    }
    cout<<ct;
    return 0;
      }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int get_sz(vector<vi> &tree, vi &sz, int v)
{
	int res = 1;
	for (auto u : tree[v])
	{
		res += get_sz(tree, sz, u);
	}
	return sz[v] = res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	vector<vi> g(n);
	REP(i, n - 1)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int r = 0;
	vector<bool> vis(n);
	vis[r] = true;
	vector<set<int>> tree(n);
	queue<int> que;
	que.push(r);
	vi par(n);
	par[r] = -1;
	while (!que.empty())
	{
		int v = que.front();
		que.pop();
		for (auto u : g[v])
		{
			if (vis[u]) continue;
			vis[u] = true;
			tree[v].insert(u);
			par[u] = v;
			que.push(u);
		}
	}
	vi childcnt(n);
	REP(i, n) childcnt[i] = tree[i].size();

	set<int> leaf;
	set<int> uncolor; REP(i, n) uncolor.insert(i);
	vi color(n, -1);
	REP(i, n)
	{
		if (tree[i].empty()) leaf.insert(i);
	}
	bool ans = true;
	//for (auto v : leaf)
	while(!leaf.empty())
	{
		int v = *leaf.begin();
		leaf.erase(v);
		if (v == r)
		{
			color[v] = 0;
		}
		else
		{
			int u = par[v];
			color[v] = 1;
			uncolor.erase(v);
			if (color[u] != -1)
			{
				ans = false;
				break;
			}
			color[u] = 0;
			uncolor.erase(u);

			if (u != r)
			{
				childcnt[par[u]]--;
				if (childcnt[par[u]] == 0)
				{
					leaf.insert(par[u]);
				}
			}
		}
	}

	if (ans)
	{
		REP(i, n)
		{
			assert(color[i] != -1);
		}
		vi color2(n);
		REP(i, n)
		{
			if (color[i] == 1)
			{
				color2[i] = 1;
				for (auto v : g[i]) color2[v] = 1;
			}
		}
		for (auto c : color2)
		{
			if (c == 0) ans = false;
		}
	}
	cout << (ans ? "Second" : "First") << endl;
	return 0;
}

Measured memory_bytes: 23424
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
N=int(input())
s=0
for i in range(1,N+1):
  for j in range(i+1,N+1):
    for h in range(j+1,N+1):
      a=gcd(i,j)
      s+=6*gcd(a,h)
for p in range(1,N+1):
  for q in range(1,N+1):
    if p==q:
      s+=p
    else:
      s+=3*gcd(p,q)
print(s)

Measured memory_bytes: 9200
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b = 0, n, k;
string s, t;
//cout<<<<endl;


int main()
{
	cin >> n>>k;
	vector<int> h(n);
	rep(i, n)
		cin >> h[i];
	int count=0;
	rep(i, n)
	{
		if (h[i] >= k)
			count++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>

using namespace std;

int main()
{
    // 整数の入力
    int A,B;
    cin >> A >> B;
    if (A <= 8 && B<=8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

const Inf = 1 << 60

func main() {
	H, W, K := ReadInt(), ReadInt(), ReadInt()
	x1, y1, x2, y2 := ReadInt()-1, ReadInt()-1, ReadInt()-1, ReadInt()-1
	x1, y1 = y1, x1
	x2, y2 = y2, x2
	c := make([]string, H)
	for y := 0; y < H; y++ {
		c[y] = ReadString()
	}

	var dx = []int{1, 0, -1, 0}
	var dy = []int{0, 1, 0, -1}

	toID := func(x, y, dir int) int {
		return 4*(W*y+x) + dir
	}
	splatID := func(id int) (x, y, dir int) {
		return id / 4 % W, id / 4 / W, id % 4
	}

	dist := make([]int, W*H*4)
	for i := 0; i < W*H*4; i++ {
		dist[i] = Inf
	}

	q := Heap{}
	for i := 0; i < 4; i++ {
		q = append(q, State{
			Cost: 0,
			ID:   toID(x1, y1, i),
		})
	}
	for len(q) > 0 {
		now := q.pop()
		x, y, dir := splatID(now.ID)
		if c[y][x] == '@' {
			continue
		}
		if dist[now.ID] <= now.Cost {
			continue
		}
		dist[now.ID] = now.Cost
		if x == x2 && y == y2 {
			break
		}
		for i := 0; i < 4; i++ {
			q.push(State{
				Cost: (now.Cost + K - 1) / K * K,
				ID:   toID(x, y, i),
			})
		}
		nx := x + dx[dir]
		ny := y + dy[dir]
		if 0 <= nx && nx < W && 0 <= ny && ny < H {
			q.push(State{
				Cost: now.Cost + 1,
				ID:   toID(nx, ny, dir),
			})
		}
	}
	ans := Inf
	for i := 0; i < 4; i++ {
		id := toID(x2, y2, i)
		if dist[id] < ans {
			d2 := (dist[id] + K - 1) / K
			if d2 < ans {
				ans = d2
			}
		}
	}
	if ans < Inf {
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}
}

type State struct {
	Cost, ID int
}

type HeapElement = State
type Heap []HeapElement

func (h Heap) Less(i, j int) bool    { return h[i].Cost < h[j].Cost }
func (h Heap) Len() int              { return len(h) }
func (h Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *Heap) Push(x interface{})   { *h = append(*h, x.(HeapElement)) }
func (h *Heap) Pop() (x interface{}) { *h, x = (*h)[:len(*h)-1], (*h)[len(*h)-1]; return }
func (h *Heap) push(v HeapElement)   { heap.Push(h, v) }
func (h *Heap) pop() HeapElement     { return heap.Pop(h).(HeapElement) }

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 109452
# -*- coding utf-8 -*-
import heapq

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)

hq = []
visited = set()
c = 0

def visit(i, j, k):
    if (i < X and j < Y and k < Z) and (visited.isdisjoint({(i, j, k)})):
        heapq.heappush(hq, ( -(A[i] + B[j] + C[k]), (i, j, k)))
        visited.add((i, j, k))

visit(0, 0, 0)

while len(hq) != 0 and c < K:
    taberu = heapq.heappop(hq)
    print(-taberu[0])

    visit(taberu[1][0] + 1, taberu[1][1], taberu[1][2])
    visit(taberu[1][0], taberu[1][1] + 1, taberu[1][2])
    visit(taberu[1][0], taberu[1][1], taberu[1][2] + 1)

    c += 1


Measured memory_bytes: 5100
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n,q=map(int,input().split())
s=input()
td=[]
for i in range(q):
    td.append(input().split())

#左に集まる中でもっとも右の点を探す
ok1=-1
left=0
right=n
while left<right:
    mid=(left+right)//2
    tmp=mid
    for t,d in td:
        if s[tmp]==t:
            tmp=tmp-1 if d=='L' else tmp+1
        if tmp==-1 or tmp==n:
            break
    if tmp==-1:
        left=mid+1
        ok1=max(ok1,mid)
    else:
        right=mid

#右に集まる中でもっとも左の点を探す

ok2=n
left=0
right=n
while left<right:
    mid=(left+right)//2
    tmp=mid
    for t,d in td:
        if s[tmp]==t:
            tmp=tmp-1 if d=='L' else tmp+1
        if tmp==n or tmp==-1:break
    if tmp == n:
        right=mid
        ok2=min(ok2,mid)
    else:
        left=mid+1

print(max(0,ok2-ok1-1))
# print(ok2,ok1)


Measured memory_bytes: 83788
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    List<Integer>[] graph=new List[n];
    for(int i=0;i<n;i++){
      graph[i]=new LinkedList<Integer>();
    }
    for(int i=0;i<m;i++){
      int a=sc.nextInt()-1;
      int b=sc.nextInt()-1;
      graph[a].add(b);
      graph[b].add(a);
    }
    Deque<Integer> dq=new ArrayDeque<>();
    int[] dist=new int[n];
    Arrays.fill(dist,-1);
    dist[0]=0;
    dq.add(0);
    while(!dq.isEmpty()){
      int here=dq.pollFirst();
      for(int next:graph[here]){
        if(dist[next]==-1){
          dist[next]=dist[here]+1;
          if(dist[next]<2){
            dq.add(next);
          }
        }
      }
    }
    if(dist[n-1]==2){
      System.out.println("POSSIBLE");
    }else{
      System.out.println("IMPOSSIBLE");
    }
  }
}

Measured memory_bytes: 133988
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

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

    ans = (a-1)*(b-1);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    ll a, b; cin >> a >> b;
    string u; cin >> u;
    if (u == s) cout << a - 1 << ' ' << b << '\n';
    else cout << a << ' ' << b - 1 << '\n';
    return 0;
}


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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COUT(x) cout << x << endl
//#define int long long

template<typename T> constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

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

	VI p(N);
	for (auto& P : p) {
		cin >> P;
	}

	VI list(N);
	int i = 1;
	for (auto& l : list) l = i++;

	int  diff = 0;
	rep (i, N) {
		if (p[i] != list[i]) diff++;
	}

	if (diff <= 2) COUT("YES");
	else COUT("NO");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

ll N, M, A, B, C, T;

namespace Matrix
{
  using number_type = long long;
  using Vec = vector<number_type>;
  using Mat = vector<Vec>;

  Mat operator * (Mat& A, Mat& B) {
    Mat C(A.size(), Vec(B[0].size()));
    rep(i, A.size()) rep(k, B.size()) rep(j, B[0].size())
      C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
    return C;
  }

  void operator *= (Mat& A, Mat& B) {
    A = A*B;
  }

  Mat pow(Mat A, ll n) {
    Mat B(A.size(), Vec(A.size()));
    rep(i, A.size()) {
      B[i][i] = 1;
    }
    while(n > 0) {
      if(n & 1) { B *= A; }
      A *= A;
      n >>= 1;
    }
    return std::move(B);
  }

  Mat operator ^ (Mat A, ll n) { return std::move(pow(std::move(A), n)); }

  Mat make_matrix(number_type a, number_type b, number_type c, number_type d) {
    Mat ret(2, Vec(2));
    ret[0][0] = a, ret[0][1] = b,
    ret[1][0] = c, ret[1][1] = d;
    return std::move(ret);
  }
}

//Matrix::Vec S;
Matrix::Mat S;

int main() {

  for(;cin >> N >> M >> A >> B >> C >> T && (N|M|A|B|C|T);) {

    // !!! Column Vector !!!
    S.clear();
    S.resize(N);
    rep(i, N) S[i].resize(1);
    rep(i, N) cin >> S[i][0];

    Matrix::Mat mat;
    int pos = 0;
    while(pos < N) {
      Matrix::Vec v(N);
      if(pos-1 >= 0 && pos-1 < N) { v[pos-1] = A; }
      if(pos+0 >= 0 && pos+0 < N) { v[pos+0] = B; }
      if(pos+1 >= 0 && pos+1 < N) { v[pos+1] = C; }
      pos ++;
      mat.push_back(v);
    }
    assert(mat.size() == N);

    mat = Matrix::pow(mat, T);

    Matrix::Mat res = Matrix::operator*(mat, S);
    /*
    rep(i, mat.size()) {
      rep(j, N) {
        res[j] += mat[i][j] * S[j] % M;
        res[j] %= M;
      }
    }
    */

    rep(i, N) {
      if(i) cout << " ";
      cout << res[i][0] % M;
    }
    cout << endl;
  }
  return 0;
}

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

#define MAX_N 100005

int n ,m;
int x ,y ,z;

int par[MAX_N];
int fnd(int u){
    return par[u] = (par[u] == u ? u : fnd(par[u]));
}
void unn(int u ,int v){
    u = fnd(u) ,v = fnd(v);
    if(u != v)
        par[u] = v;
}

int main()
{
    scanf("%d%d",&n,&m);
    iota(par ,par+n+1 ,0);
    for(int i=0; i<m; i++){
        scanf("%d%d%d",&x,&y,&z);
        z = (z&1);
        unn(x ,y);
    }

    set <int> ss;
    for(int i=1; i<=n ;i++)
        ss.insert(fnd(i));

    cout << ss.size() << endl;
}


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

int main(){
  int a,b,c,x; cin>>a>>b>>c>>x;
  int cnt=0;
  for (int i=0; i<=a; i++){
    for (int j=0; j<=b; j++){
      for (int k=0; k<=c; k++){
        if (500*i+100*j+50*k==x) cnt+=1;
      }
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
def prime_factorization(n):
    #素因数分解の結果を辞書に保存して返す
    #1の時は空の辞書を返す
    num = int(n ** 0.5)
    rec = dict()
    for prime in range(2, num + 2):
        if n % prime == 0:
            cnt = 0
            while True:
                if n % prime != 0:break
                cnt += 1
                n = n // prime
            rec[prime] = cnt

    if n != 1:rec[n] = 1
    return rec

n = int(input())
rec = prime_factorization(n)
ans = 0
for key, cnt in rec.items():
    temp = 1
    while True:
        if cnt < temp:break
        ans += 1
        cnt -= temp
        temp += 1
print(ans)

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
int arr[111];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++) scanf("%d",&arr[e]);
	int ans =0 ;
	sort(arr,arr+n);
	for(int e=2;e<n;e++){
		for(int p=0;p<e;p++){
			for(int q=p+1;q<e;q++){
				if(arr[p]==arr[q]||arr[p]==arr[e]||arr[q]==arr[e]) continue;
				if(arr[e]<arr[p]+arr[q]){
					ans++;
				}
			}
		}
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 3816
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int i,x,y,g1[7]={1,3,5,7,8,10,12},g2[4]={4,6,9,11},g3=2,tx,ty;
inline void solve(){
  IN2(x,y);
  REP(i,7)if(g1[i]==x)tx=1;
  REP(i,4)if(g2[i]==x)tx=2;
  if(g3==x)tx=3;
  REP(i,7)if(g1[i]==y)ty=1;
  REP(i,4)if(g2[i]==y)ty=2;
  if(g3==y)ty=3;
  if(tx==ty)OUT("Yes");
  else OUT("No");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

const int MAX_N = 310;
//????????????
int dp[MAX_N][MAX_N];

int N;
vector<int> W;

void solve(){
    for(int i=0; i<N-1; i++)
        if(abs(W[i]-W[i+1]) <= 1)
            dp[i][i+2] = 2;
    
    for(int l=3; l<=N; l++){
        for(int i=0; i<=N-l; i++){
            //segmentation
            for(int j=i; j<i+l; j++)
                dp[i][i+l] = max(dp[i][i+l], dp[i][j] + dp[j][i+l]);
            //expansion
            if(dp[i+1][i+l-1] == l-2 && abs(W[i]-W[i+l-1]) <= 1)
                dp[i][i+l] = l;
        }
    }
    
    cout << dp[0][N] << endl;
}

int main(){
    while(cin >> N, N){
        W.resize(N);
        for(auto &v: W)
            cin >> v;
        
        memset(dp, 0, sizeof(dp));
        solve();
    }
    return 0;
}

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

using namespace std;

int main()
{
  while(1){
    int n;
    cin>>n;

    if(n == 0){
      break;
    }

    int times = n / 4;
    int ans = 0;

    for(int i = 0;i < times;++i){
      int a;
      cin>>a;
      ans += a;
    }

    cout<<ans<<endl;
  }

  return 0;
}


Measured memory_bytes: 3080
#include<iostream>
using namespace std;
int main(){
	for(;;){
	   int t;
	   cin>>t;
	   if(t==0)break;
	   int n;
	   cin>>n;
	   int a[n],b[n];
	   for(int i=0;i<n;i++){
		   cin>>a[n]>>b[n];
		   t-=(b[n]-a[n]);
	   }
	   if(t<=0){
		   cout<<"OK"<<endl;
	   }
	   else{
		   cout<<t<<endl;
	   }
	}
	return 0;
}	      



Measured memory_bytes: 3072
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
#include <assert.h>
#include <complex.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define FILL(A,val) memset(A,val,sizeof(A))

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double Pi = acos(-1.0);
const int INF = 1000000000;
const int MAX = 510007;
const int MAXE = 2007000;
const int MAXV = 5000;
const int BASE = 1000000000;
const int ST = 1000000007;

const int MOD1 = 982450121;
const int MOD2 = 982453291;

int p1 = 1000003;
int p2 = 15484769;

Int H1[MAX];
Int H2[MAX];
int delta[MAX];


Int pw1[MAX];
Int pw2[MAX];

int main()
{
    //freopen("in.txt", "r", stdin);
    
    pw1[0] = 1;
    pw2[0] = 1;
    FOR(i,1,MAX)
    {
        pw1[i] = pw1[i - 1] * p1 % MOD1;
        pw2[i] = pw2[i - 1] * p2 % MOD2;
    }
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    H1[0] = 0;
    H2[0] = 0;
    delta[0] = n + 1;
    
    FOR(i,0,n)
    {
        H1[i + 1] = H1[i];
        H2[i + 1] = H2[i];
        delta[i + 1] += delta[i];
        
        if (s[i] == '<')
        {
            delta[i + 1] --;
        }
        if (s[i] == '>')
        {
            delta[i + 1] ++;
        }
        
        if (s[i] == '+')
        {
            H1[i + 1] += pw1[delta[i + 1]];
            H1[i + 1] %= MOD1;
            
            H2[i + 1] += pw2[delta[i + 1]];
            H2[i + 1] %= MOD2;
        }
        
        if (s[i] == '-')
        {
            H1[i + 1] += MOD1 - pw1[delta[i + 1]];
            H1[i + 1] %= MOD1;
            
            H2[i + 1] += MOD2 - pw2[delta[i + 1]];
            H2[i + 1] %= MOD2;
        }
        
    }
    
    Int res = 0;
    
    map<pair<Int, Int> , int> M;
    
    
    
    
    RFOR(i,n,0)
    {
        M[MP(H1[i + 1] * pw1[n] % MOD1 , H2[i + 1] * pw2[n] % MOD2)] ++;
        Int h1 = (H1[n] * pw1[delta[i] - delta[0] + n] + H1[i] * pw1[n]) % MOD1;
        Int h2 = (H2[n] * pw2[delta[i] - delta[0] + n] + H2[i] * pw2[n]) % MOD2;
        res += M[MP(h1,h2)];
    }
    
    cout << res << endl;
    
    
}



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

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

  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }

  int count = 0;
  while (accumulate(h.begin(), h.end(), 0) > 0) {
    bool mizuyari = false;
    for (int i = 0; i < N; i++) {
      if (h.at(i) > 0) {
        mizuyari = true;
        h.at(i)--;
        continue;
      }

      // 水やり中に0にあたったら終了
      if (mizuyari && h.at(i) == 0) {
        mizuyari = false;
        break;
      }
    }
    count++;
  }

  cout << count << endl;
}

Measured memory_bytes: 256
import math

i = list(map(int, input().split(" ")))
n = i[0]
d = i[1]
x = []
total = 0

for x_n in range(n):
    xx = list(map(int, input().split(" ")))
    x.append(xx)

for x_n in range(len(x)):
    a = x[x_n]
    for x_d in range(x_n+1, len(x)):
        b = x[x_d]
        t = [(aa - bb)**2 for aa, bb in zip(a, b)]
        t = math.sqrt(sum(t))
        if t.is_integer():
            total += 1
print(total)


Measured memory_bytes: 3064
#include<stdio.h>
int A[100000];
int partition(int p,int r){
  int i=p-1;
  int j,t,s,x;
  x=A[r];
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
s=A[i+1];
A[i+1]=A[r];
A[r]=s;
return i+1;
}
int main(){
int n,i,k;
scanf("%d",&n);
for(i=0;i<n;i++){
  scanf("%d",&A[i]);
}
k=partition(0,n-1);
for(i=0;i<k;i++){
  printf("%d ",A[i]);
}
printf("[");
printf("%d",A[k]);
printf("] ");
for(i=k+1;i<n;i++){
if(i==n-1){
  printf("%d\n",A[n-1]);
break;
}
printf("%d ",A[i]);
}
return 0;
}



Measured memory_bytes: 2104
n=int(input())
A=0
R=0
T=0
W=0
for i in range(n):
    s=input()
    if s=="AC":
        A+=1
    elif s=="RE":
        R+=1
    elif s=="TLE":
        T+=1
    else:
        W+=1
print("AC x "+str(A))
print("WA x "+str(W))
print("TLE x "+str(T))
print("RE x "+str(R))

Measured memory_bytes: 9180
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

void solve(void){
    int a,b,c,d;
    
    cin >> a >> b >> c>>d;
    
    if(a > b)cout << c*b+d*(a-b) << endl;
    else cout << c*a << endl;
    

}

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


Measured memory_bytes: 256
S=list(input())
N=len(S)

B=[0]*len(S)

s=0
for i in range(N):
    if S[i]=='R':
        s+=1
    else:
        if s%2==1:
            B[i]+=int((s-1)/2)
            B[i-1]+=int((s-1)/2+1)
        else:
            B[i]+=int(s/2)
            B[i-1]+=int(s/2)
        s=0

s=0
for i in range(N-1,-1,-1):
    if S[i]=='L':
        s+=1
    else:
        if s%2==1:
            B[i]+=int((s-1)/2)
            B[i+1]+=int((s-1)/2+1)
        else:
            B[i]+=int(s/2)
            B[i+1]+=int(s/2)
        s=0

print(' '.join(map(str,B)))


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

int main(){
    int a,b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main() {
  int a[4], b[4];
  while (scanf("%d", &a[0]) == 1) {
    for (int i = 1; i < 4; i++)
      scanf("%d", &a[i]);
    for (int i = 0; i < 4; i++)
      scanf("%d", &b[i]);
    int hit = 0, blow = 0;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++)
        if (a[j] == b[i]) {
          if (i == j)
            hit++;
          else
            blow++;
        }
    printf("%d %d\n", hit, blow);
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

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

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    int x, y;
    cin >> x >> y;
    rep(t, x + 1) {
        int r = x - t;
        if (t * 2 + r * 4 == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3632
S = input()
n = len(S)
k = int(input())
cnt = 0
itl = sorted(list(set(S)))
ans = set([])
for w in itl:
    for i, s in enumerate(S):
        if s != w:
            continue
        else:
            for j in range(i+1, i+k+1):
                ans.add(S[i:j])
    cnt += len(ans)
    if cnt >= k:
        break
    else:
        ans.clear()

ans = list(ans)
ans.sort()
index = k - 1 - (cnt - len(ans))
print(ans[index])


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int main()
{
  int *x,n,i,a,sum;
  scanf("%d",&n);
  x = (int*)malloc(sizeof(int) * n);
  for(i=0;i < n;i++){
    scanf("%d",x+i);
  }
  
  for(i=0;i <= n-2;i++){
    if (x[i] > x[i+1]){
      a = x[i+1];
      x[i+1] = x[i];
      x[i] = a;
    }
  }
  sum = 0;
  for (i=0;i < n-1;i++){
    sum += x[i];
  }
  if (sum > x[n-1]){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}




Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			String input = br.readLine();
			int n = Integer.parseInt(input);

			int fx = 0;
			int num = n;
			while(true) {
				fx += num % 10;
				num /= 10;
				if(num <= 0)
					break;
			}

			if(n % fx == 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(br != null) {
					br.close();
					br = null;
				}
			} catch (Exception e) {

			}
		}
	}
}


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

struct BIT {
    long long n;
    vector<long long> dat;

    void initialize(long long n_input){
        n = n_input + 1;
        dat.resize(n+1);
        for(int i = 0; i<=n; i++) dat[i] = 0;
    }

    long long sum(long long i){
        long long s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    void add(long long i, long long x){
        while(i <= n){
            dat[i] += x;
            i |= i+1;
        }
    }
};

int inversion(const vector<int> arr){
    BIT bit;
    bit.initialize(arr.size());
    int ret = 0;
    for(int i=0; i<arr.size(); i++){
        ret += i - bit.sum(arr[i]);
        bit.add(arr[i], 1);
    }
    return ret;
}

vector<vector<int>> abc;
double mid;

bool cmpx(int a, int b){
    double aa = (double)(-abc[a][0]*mid+abc[a][2]) / abc[a][1];
    double bb = (double)(-abc[b][0]*mid+abc[b][2]) / abc[b][1];
    return aa < bb;
}

bool cmpy(int a, int b){
    double aa = (double)(-abc[a][1]*mid+abc[a][2]) / abc[a][0];
    double bb = (double)(-abc[b][1]*mid+abc[b][2]) / abc[b][0];
    return aa < bb;
}

bool cmpdx(vector<int> a, vector<int> b){
    double aa = (double)a[0] / a[1];
    double bb = (double)b[0] / b[1];
    return aa < bb;
}

bool cmpdy(vector<int> a, vector<int> b){
    double aa = (double)a[1] / a[0];
    double bb = (double)b[1] / b[0];
    return aa < bb;
}

int main(){
    long long i, j, k;
    int N;
    cin >> N;
    abc.resize(N);
    for(i=0; i<N; i++){
        int a, b, c;
        cin >> a >> b >> c;
        abc[i] = {a, b, c};
    }
    int half = (N*(N-1)/2+1)/2;

    vector<int> order(N);
    for(i=0; i<N; i++) order[i] = i;

    sort(abc.begin(), abc.end(), cmpdx);
    double ub = 1e9, lb = -1e9;
    for(i=0; i<70; i++){
        mid = (ub+lb)/2;
        sort(order.begin(), order.end(),cmpx);
        int inv = inversion(order);
        if(inv<half){
            lb = mid;
        }else{
            ub = mid;
        }
    }
    double x = ub;

    sort(abc.begin(), abc.end(), cmpdy);
    ub = 1e9, lb = -1e9;
    for(i=0; i<70; i++){
        mid = (ub+lb)/2;
        sort(order.begin(), order.end(),cmpy);
        int inv = inversion(order);
        if(inv<half){
            lb = mid;
        }else{
            ub = mid;
        }
    }
    double y = ub;

    cout << fixed << setprecision(10);
    cout << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 3236
#include<cstdio>
#include<iostream>
#include<algorithm>
#define maxn 55
#define ll long long

using namespace std;

ll n,l,r,js1=0,js2=0,ans1,ans2=0;

ll a[maxn],s[maxn][maxn];

bool cmp(ll a,ll b)
{
	return a>b;
}

int main()
{
	s[0][0]=1;
	for(int i=1;i<=50;i++)
	{
		s[i][0]=1;
		for(int j=1;j<=i;j++)
		{
			s[i][j]=s[i-1][j]+s[i-1][j-1];
		}
	}
	cin>>n>>l>>r;
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+n+1,cmp);
	for(ll i=1;i<=l;i++)
	{
		ans2+=a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if(a[i]==a[l])
		{
			js1++;
		}
	}
	for(ll i=1;i<=l;i++)
	{
		if(a[i]==a[l])
		{
			js2++;
		}
	}
	if(a[1]==a[l])
	{
		for(ll i=l;i<=r;i++)
		{
			ans1+=s[js1][i];
		}
	}
	else
	{
		ans1=s[js1][js2];
	}
	printf("%lf\n%lld",(double)ans2/l*1.0,ans1);
	return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(v) (v).begin(), (v).end()
#define sp cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int n, m;
    cin >> n >> m;

    if (n == m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define D 1000000
using namespace std;
bool flg[D];
int ans[D];
int main(){
	
	int m,n;
	flg[1] = true;
	for(int i = 0;i <= D;i++){
		if(flg[i]){
			if(2*i<=D)flg[2*i] = true;
			if(3*i<=D)flg[3*i] = true;
			if(5*i<=D)flg[5*i] = true;
			//cout<<i<<endl;
		}
	}
	int cnt = 0;
	for(int i = 0;i <= D;i++){
		if(flg[i]) cnt++;
		ans[i] = cnt;
		//cout<<ans[i]<<endl;
	}
	while(cin>>m,m){
		cin>>n;
		cout<<ans[n] - ans[m-1]<<endl;
	}
	


}

Measured memory_bytes: 5732
#include<algorithm>
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
	int n,a[100005]={0};
	long s=0;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=0;i<=n;i++)s+=abs(a[i+1]-a[i]);
	for(int i=1;i<=n;i++)cout<<s-abs(a[i]-a[i+1])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1])<<endl;
	return 0;
}

Measured memory_bytes: 1664
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric;

void main(){
    auto l=readln.chomp;
    writeln(l[0],l.length-2,l[$-1]);
}


Measured memory_bytes: 256
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<class T>void put_double(T a){cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    Int a, b, c, k; cin >> a >> b >> c >> k;
    if(a >= k) println(k);
    else if(a + b >= k)  println(a);
    else println(a * 2 + b - k);
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main(void)
{
	int i, n;
	long long a, temp;

	cin>>n;

	temp=2; a=1;

	for(i=2; i<=n; i++){
		a+=temp;
		temp=a-temp;
	}
	if(n==0){
		cout<<"2"<<endl;
	}else if(n==1){
		cout<<"1"<<endl;
	}else{
		cout<<a<<endl;
	}
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	string s;
	cin >> s;
	int ans = 0;
	REP(i, s.length()) {
		if (s[i] == '+') ans++;
		else ans--;
	}
	cout << ans << endl;

}


Measured memory_bytes: 384
#include <iostream>
//#include <ctype.h>
#include <stdio.h>
//#include <string>
using namespace std;
int main(){
	char ch;
	int num=0;
	int counter[30]={0};
	while(cin >> ch ){
		if( ch-'a' < 0 ){
			num=ch-'A';
		}
		else
			num=ch-'a';
		counter[num] ++;
		//cout << num << endl;
	}
	for( int i=0 ; i<26 ; i++ ){
		char a=i+'a';
		cout << a <<" : "<<counter[i]<< endl;
	}
	return 0;
}

Measured memory_bytes: 3092
X, Y, Z = map(int, input().split())
ans = 0
BC = []
for _ in range(X+Y+Z):
    a, b, c = map(int, input().split())
    ans += a
    BC.append([b-a, c-a])
BC.sort(key=lambda x: x[1]-x[0])
import heapq
q = []
an = 0
for b, _ in BC[:Y]:
    heapq.heappush(q, b)
    an += b
A = [an]
for b, _ in BC[Y:-Z]:
    heapq.heappush(q, b)
    an += b
    b_ = heapq.heappop(q)
    an -= b_
    A.append(an)
q = []
an = 0
for _, c in BC[-Z:]:
    heapq.heappush(q, c)
    an += c
A[-1] += an
for i, (_, c) in enumerate(BC[-Z-1:Y-1:-1], 2):
    heapq.heappush(q, c)
    an += c
    c_ = heapq.heappop(q)
    an -= c_
    A[-i] += an
print(ans + max(A))


Measured memory_bytes: 25044
#include<bits/stdc++.h>
using namespace std;
int n,k;
int ans;
int main()
{
	cin>>k>>n;
	for(int x=0;x<=k;x++)
	for(int y=0;y<=k;y++)
	{
		int z=n-x-y;
		if(z>=0&&z<=k) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256