akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,m,ans,a[N];
char s[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
bool cmp(int x,int y)
{
	return x>y;
}
signed main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1,cmp);
	for(int i=m+1;i<=n;i++)ans+=a[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3328
#!/usr/bin/env python3

def main():
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        l = list(map(int, input().split()))
        a.append(l)

    hold = False
    opers = []
    for i in range(h):
        jlist = range(w) if i % 2 == 0 else reversed(range(w))
        for j in jlist:
            if not (i == j == 0):
                if hold:
                    opers.append((ipre + 1, jpre + 1, i + 1, j + 1))
            hold = (hold != (a[i][j] % 2 == 1))
            ipre = i
            jpre = j
    print(len(opers))
    for o in opers:
        p, q, r, s = o
        print(p, q, r, s)

if __name__ == "__main__":
    main()


Measured memory_bytes: 26688
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;

    int score = 1;
    for (int i = 0; i < n; i++) {
        if (score < k) {
            score *= 2;
        } else {
            score += k;
        }
    }
    cout << score << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
using namespace std;
string encode(vector<int> v){
    string res = "";
    for(int i = 0; i<v.size(); i++){
        res += to_string(v[i]) + "#";
    }
    return res;
}
void permute(int curr, vector<int>& v, vector<vector<int> >& res){
    if(curr == v.size()){
        res.push_back(v);
        return;
    }
    for(int i= curr; i<v.size(); i++ ){
        swap(v[i], v[curr]);
        permute(curr + 1, v, res);
        swap(v[i], v[curr]);
    }
}
int main(){
    int n;
    cin>>n;
    vector<int> v1(n);
    for(int i = 0; i<n; i++){
        cin>>v1[i];
    }
    string s1 = encode(v1);
    vector<int> v2(n);
    for(int i = 0; i<n; i++){
        cin>>v2[i];
    }
    string s2 = encode(v2);

    vector<int> v;
    for(int i= 1; i<=n; i++){
       v.push_back(i); 
    }
    unordered_map<string , int> m;
    vector<vector<int> > res;
    int num = 1;
    permute(0, v, res);
    sort(res.begin(), res.end());
    for(int i = 0; i<res.size(); i++){
        string x = encode(res[i]);
        m[x] = i+1;
    }
    cout<<abs(m[s1]- m[s2])<<endl;
    return 0;
}

Measured memory_bytes: 7988
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
//#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


//namespace mp = boost::multiprecision;

//using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int size(int n) {
	int count = 0;
	while (n > 0) {
		n /= 10;
		count++;
	}
	return count;
}

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}
int main() {
	int N;
	int ret=scanf("%d", &N);
	int sizeN = size(N);
	string S357 = "357";
	int i = 27;
	int ans = 0;
	while (i < pow(4, sizeN)) {
		deque<char>tmpS;
		vector<int>count(3);
		int tmp = i;
		bool flag = true;
		while (tmp > 0) {
			int ttmp = tmp % 4;
			rep(j, 3) {
				if (ttmp  == j + 1) {
					tmpS.push_front(S357[j]);
					count[j]++;
				}
				else if (ttmp == 0) {
					flag = false;
					break;
				}
			}
			tmp /= 4;
		}
		if (*min_element(all(count)) > 0&&flag) {
			string s = "";
			rep(j, tmpS.size()) {
				s += tmpS[j];
			}
			int aa = stoi(s);
			if (aa <= N) {
				ans++;
			}
		}

		i++;
	}
	printf("%d\n", ans) ;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9 + 7;
ll inf = 1e15;

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

  ll n, m, r;
  cin >> n >> m >> r;
  vll x(r);
  REP(i, r){
    cin >> x[i];
    x[i]--;
  }
  VSORT(x);

  ll a, b, c;
  vvll d(n, vll(n, inf));
  REP(i, n) d[i][i] = 0;
  REP(i, m){
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b] = d[b][a] = c;
  }
  
  REP(k, n){
    REP(i, n){
      REP(j, n){
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  ll ans = inf, res;
  do{
    res = 0;
    REP(i, r - 1) res += d[x[i]][x[i + 1]];
    ans = min(ans, res);
  }while(next_permutation(x.begin(), x.end()));

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


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, a[100000], s[100000][32], s2[100000][32], b[100000 * 32];
long long mx;
int main() {
  cin >> n >> m;
  for(int i = 0; i < n; ++i)
    cin >> a[i], mx += a[i];
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < 32; ++j)
      s[i][j] = a[i] / (1 << j);
  for(int i = 0; i < n; ++i)
    for(int j = 1; j < 32; ++j)
      s2[i][j] = s[i][j - 1] - s[i][j];

  for(int i = 0; i < n; ++i)
    for(int j = 0; j < 32; ++j)
      b[i * 32 + j] = s2[i][j];
  sort(b, b + (n * 32));
  reverse(b, b + (n * 32));
  /*
  for(int i = 0; i < n * 31; ++i)
    cout << b[i] << " ";
  cout << endl;
  */
  for(int i = 0; i < min(m, n * 32); ++i)
    mx -= b[i];
  cout << mx << endl;
}

Measured memory_bytes: 38144
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    char a, b;
    vector<int> v(3);
    v[0] = 1;
    while(scanf(" %c,%c", &a, &b) != EOF){
        swap(v[a-'A'], v[b-'A']);
    }
    for (int i = 0; i < 3; ++i) if(v[i]) printf("%c\n", i+'A');
    return 0;
}


Measured memory_bytes: 3152
/*  よろしくお願いします
    LEARNING DP:    Grid 1
        + GRID HxW
        + MOVING RIGHT or DOWN to an ADJACENT EMPTY square
        + THE NUMBER OF PATH to move from (1,1) to (H,W) mod 1e9+7
    CONSTRAINT:
        +2 <= H, W <= 1000
    RECURSIVE:

    IF WE KNOW:

    PRE DP:

    TIME COMPLEXITY:
        O(N*M)
*/
#include <bits/stdc++.h>
using namespace std;

#define DB(_x)      cout << #_x << " is " << (_x) << "\n";
#define FOR(_a,_b)  for (_a = 0; _a < _b; ++_a)
#define fs          first
#define sc          second
#define pb          push_back
//#define IOFILE

using LL = long long;
using LD = long double;
using VI = vector<int>;
using PI = pair<int,int>;

int i, j, n ,m, ans, mod = 1e9+7;
vector<VI> a, dp;

int DFS(int u, int v){
    if (dp[u][v] != -1) return dp[u][v];
    if (u == n-1 && v == m-1) return 1;
    int cnt = 0;
    if (v+1 < m && a[u][v+1]){
        cnt += DFS(u,v+1);
        cnt %= mod;
    }
    if (u+1 < n && a[u+1][v]){
        cnt += DFS(u+1,v);
        cnt %= mod;
    }
    return dp[u][v] = cnt;
}

void Excalibur(){
    while (cin >> n >> m){
        a = vector<VI>(n, VI(m));
        dp = vector<VI> (n, VI(m,-1));
        FOR(i, n) FOR (j, m){
            char x; cin >> x;
            a[i][j] = (x == '.');
        }
        cout << DFS(0,0) << "\n";
    }
}

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

#ifdef  IOFILE
    freopen("INPUT.in", "r", stdin);
    freopen("OUTPUT.out", "w", stdout);
#endif

Excalibur();
return 0;}


Measured memory_bytes: 8192
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n: i64 = input();
    let mut x: i64 = input();
    let m: Vec<i64> = (0..n).map(|_| input()).collect();

    x -= m.iter().sum::<i64>();
    let m_min = m.iter().min().unwrap();
    println!("{}", n + x / m_min);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long llint;

const int MAXN = 1e5 + 10;

int x, y, a, b, c;
int p[MAXN], q[MAXN], r[MAXN];

int main(void) {
  scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
  for (int i = 0; i < a; ++i) scanf("%d", &p[i]);
  for (int i = 0; i < b; ++i) scanf("%d", &q[i]);
  for (int i = 0; i < c; ++i) scanf("%d", &r[i]);

  sort(p, p + a); reverse(p, p + a);
  sort(q, q + b); reverse(q, q + b);
  sort(r, r + c); reverse(r, r + c);

  vector<int> v;
  for (int i = 0; i < x; ++i) v.push_back(p[i]);
  for (int i = 0; i < y; ++i) v.push_back(q[i]);
  for (int i = 0; i < c; ++i) v.push_back(r[i]);

  sort(v.begin(), v.end()); reverse(v.begin(), v.end());

  llint sol = 0;
  for (int i = 0; i < x + y; ++i) sol += (llint) v[i];

  printf("%lld\n", sol);
  return 0;
}


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

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

ll N, X;
ll S[1005];

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

	cin >> N >> X;

	ll mod = 1e9+7;

	for (int i = 0;i < N;i++){
		cin >> S[i];
	}

	sort(S, S+N);
	reverse(S, S+N);

	ll dp[300][100005];
	memset(dp, 0, sizeof(dp));

	dp[0][X] = 1;

	for (int i = 0;i < N;i++){
		for (int j = 0;j <= X;j++){
			if(dp[i][j] == 0) continue;
			dp[i+1][j] += dp[i][j]*(N-1-i); dp[i+1][j] %= mod;
			dp[i+1][j%S[i]] += dp[i][j]; dp[i+1][j%S[i]] %= mod;
		}
	}

	ll ans = 0;

	for (int i = 0;i <= X;i++){
		ans += dp[N][i] * i;
		ans %= mod;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 234624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int main()
{
    int n,h,w,a,b;
    scanf("%d%d%d",&n,&h,&w);
    int s=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&a,&b);
        if(a>=h&&b>=w) s++;
    }
    printf("%d\n",s);
}


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

struct Vector{
    int x;
    int y;
    Vector(int x, int y) : x(x), y(y){}
    int abs_square(){
        return x * x + y * y;
    }
};

int dot(Vector v1, Vector v2){
    return v1.x * v2.x + v1.y * v2.y;
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1;
        cin >> x2 >> y2 >> x3 >> y3;
        Vector v1 = Vector(x1 - x0, y1 - y0);
        Vector v2 = Vector(x3 - x2, y3 - y2);
        int d = dot(v1, v2);
        if (d == 0) {
            cout << 1 << endl;
            continue;
        }
        if (v1.abs_square() * v2.abs_square() == d * d) {
            cout << 2 << endl;
            continue;
        }
        cout << 0 << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <climits>
#include <functional>
#include <map>
#include <stack>
#define endl '\n'
#define ll long long
#define NCONS 16001

using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    string a, b; cin >> a >> b;
    string temp = a + b;
    int number = stoi(temp);
    
    for(int i = 1; i * i <= 100100; i++)
    {
        if(i * i == number)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define DEV_VAL (1000000000 + 7)

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

  int ans[5];
  rep(i, 4)
  {
    ans[i] = 0;
  }
  rep(i, n)
  {
    string s;
    cin >> s;
    if(s == "AC") ans[0]++;
    else if(s == "WA") ans[1]++;
    else if(s == "TLE") ans[2]++;
    else ans[3]++;
  }

  cout << "AC x " << ans[0] << endl;
  cout << "WA x " << ans[1] << endl;
  cout << "TLE x " << ans[2] << endl;
  cout << "RE x " << ans[3] << endl;

  return 0;
}

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

ll c2(ll n) {
  ll res = 0;
  if (n < 2) {
    return res;
  }
  else {
    res = (n * (n - 1)) / 2;
    return res;
  }
}

int main() {
  int N;
  cin >> N;
  ll count[N];
  ll A[N];
  for (int i = 0; i < N; i++) {
    count[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
    count[A[i]]++;
  }
  ll def = 0;
  for (int i = 0; i < N; i++) {
    def += c2(count[i]);
  }
  for (int i = 0; i < N; i++) {
    ll ans = def;
    ans -= c2(count[A[i]]);
    count[A[i]]--;
    ans += c2(count[A[i]]);
    cout << ans << endl;
    count[A[i]]++;
  }
  return 0;
}

Measured memory_bytes: 5760
import java.util.Arrays;
import java.util.Scanner;
public class Main {

public static void main(String[] args) {
		Scanner input= new Scanner(System.in);
		int loop = input.nextInt();
		int  arr [] = new int [loop];
		int i=0;
		String x ="YES";
		while(i<loop) {
			arr[i]=input.nextInt();
			i++;
			
		}
		Arrays.sort(arr);
		i=0;
		while (i<loop-1) {
			if (arr[i] == arr[i+1]) {
				x="NO";
				break;
			
			}
			i++;
			
			
		}
		System.out.println(x);
		

	
}
}

Measured memory_bytes: 87448
# ABC 164 E 草案
import sys
sys.setrecursionlimit(10**6)

n,m,s= map(int, input().split())
g= [list(map(int, input().split())) for i in range(m)]
# 両替所
c= [list(map(int, input().split())) for i in range(n)]

x=2501
# 作るグラフ (点,所有銀貨,必要時間)
gg=[[[] for i in range(x)] for i in range(n)]
for i in range(n):
    for j in range(x-1):
        # 金貨を銀貨に交換
        y=j+c[i][0]
        if y>=x-1:
            y=x-1
        gg[i][j].append((i,y,c[i][1]))


for i in range(1,x):
    for u,v,a,b in g:
        u-=1
        v-=1
        # 銀貨足りる時移動できる
        if i-a>=0:
            gg[v][i].append((u,i-a,b))
            gg[u][i].append((v,i-a,b))





#ダイクストラ法
from heapq import heappush, heappop

def dijkstra(edges, size, source,gold):
    # edge=探索するグラフ
    # size=グラフの点の数
    # source=スタート点
    distance = [[float('inf')]*x for i in range(n)]
    distance[source][gold] = 0
    visited = [[False]*x for i in range(n)]
    pq = []
    heappush(pq, (0, source,gold))
    while pq:
        dist_v, u,v = heappop(pq)
        visited[u][v] = True
        for u,v, weight in edges[u][v]:
            if not visited[u][v]:
                new_dist = dist_v + weight
                if distance[u][v] > new_dist:
                    distance[u][v] = new_dist
                    heappush(pq, (new_dist, u,v))
    return distance
s=min(2500,s)
ans=dijkstra(gg,n,0,s)

for i in range(1,n):
    print(min(ans[i]))


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

const long long mo=1000000000+7;

long long a[3000][3000];

int main(){
  int N;
  std::cin>>N;
  std::string str;
  std::cin>>str;
  for(int i=0;i<N;++i){
    a[0][i]=1;//上にi文字あるときの場合の数
  }
  for(int i=0;i<N-1;++i){
    if(str[i]=='<'){
      long sum=0;
      for(int j=N-2;j>=0;--j){
	sum+=a[i][j+1];
	sum%=mo;
	a[i+1][j]+=sum;
	a[i+1][j]%=mo;
      }
    }else{
      long sum=0;
      for(int j=0;j<=N-2-i;++j){
	// N-1-i文字全体である。
	sum+=a[i][j];
	sum%=mo;
	a[i+1][j]+=sum;
	a[i+1][j]%=mo;
      }
    }
  }
  std::cout<<a[N-1][0]<<std::endl;
  return 0;
}


Measured memory_bytes: 70528
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,point,ans=0;cin>>N;
  vector<string> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  int M;cin>>M;
  vector<string> b(M);
  for(int i=0;i<M;i++)cin>>b.at(i);
  
  for(int i=0;i<N;i++){
    point=0;
    for(int j=0;j<N;j++)
      if(a.at(i)==a.at(j))point++;
    for(int j=0;j<M;j++)
      if(a.at(i)==b.at(j))point--;
    ans=max(ans,point);
  }
  cout<<max(ans,0)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n,m,max,t;
	scanf("%d %d %d",&n,&m,&t);
	max=m>n?m:n;
	if(t%max==0)
	printf("%d",t/max);
	else
	printf("%d",t/max+1);
	return 0;	
 } 

Measured memory_bytes: 128
# TLE

import sys

INF = float('inf')

input = sys.stdin.readline


def LIST():
    return list(map(int, input().split()))


N, K = LIST()
h = LIST()

# DP配列を初期化
dp = [INF] * N

# 初期条件を入力
dp[0] = 0

# テーブルを更新 もらうDP
for i in range(1, N):
    j = i - K
    x = [0, j][0 <= j]
    dp[i] = min([dp_ + abs(h[i] - h_) for dp_, h_ in zip(dp[x:i], h[x:i])])

print(dp[N - 1])


Measured memory_bytes: 13996
//http://abc058.contest.atcoder.jp/tasks/abc058_b
#include <iostream>
using namespace std;

string O, E;

void read_input(){
    cin >> O >> E;
}

int main(void){
    read_input();
    int i = 0;
    int O_size = O.size();
    int E_size = E.size();
    while(true){
        if(i >= O_size){
            break;
        }
        cout << O[i];
        if(i >= E_size){
            break;
        }
        cout << E[i];
        i++;
    }
    cout << endl;
    return 0;
}


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

int main()
{
	int N;
	cin >> N;
	vector<pair< int, int>> AB( N );
	for( int i = 0; i < N; i++ ) {
		cin >> AB[i].first >> AB[i].second;
	}

	sort( AB.begin(), AB.end() );
	int ans = AB[N - 1].first + AB[N - 1].second;

	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pi acos(-1)
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<double,double> Pdd;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 3666;
int n,l,t[N];Pdd res;
Pdd calc(int i, int j, double C){
	double thi=pi*(t[i]+t[j])/l+C;
	return Pdd(cos(thi),sin(thi));
}
int main() {
	read(n);read(l);
	rep(i,1,n)read(t[i]);
	rep(i,1,n)rep(j,i+1,n){
		Pdd tmp=calc(i,j,0);
		res=Pdd(res.fi+tmp.fi*(i-1+n-j),res.se+tmp.se*(i-1+n-j));
		tmp=calc(j,i,pi);
		res=Pdd(res.fi+tmp.fi*(j-i-1),res.se+tmp.se*(j-i-1));
	}
	printf("%.11lf %.11lf\n",res.fi/(1.0*n*(n-1)*(n-2)/6),res.se/(1.0*n*(n-1)*(n-2)/6));
	return 0;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int N;
int H;
int M;
int main(){
	cin >> N;
	for(int i=0;i<10;i++){
		if(N-(100*i)<100){
			H=i;
			break;
		}
	}
	M=(N-H);
		if(M%10==0){
			cout << "Yes";
	}else{
		cout <<"No";
		}
		return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 8)


def lowLink(N: int, Adj: list):
	articulation = []
	bridge = []
	order = [None] * N
	lowest = [1 << 100] * N

	def _dfs(cur, pre, k):
		order[cur] = lowest[cur] = k
		is_articulation = False
		cnt = 0
		for nxt in Adj[cur]:
			if order[nxt] is None:
				cnt += 1
				_dfs(nxt, cur, k + 1)
				if lowest[cur] > lowest[nxt]:
					lowest[cur] = lowest[nxt]
				is_articulation |= pre >= 0 and lowest[nxt] >= order[cur]
				if order[cur] < lowest[nxt]:
					bridge.append((cur, nxt))
			elif nxt != pre and lowest[cur] > order[nxt]:
				lowest[cur] = order[nxt]
		is_articulation |= pre < 0 and cnt > 1
		if is_articulation:
			articulation.append(cur)

	_dfs(0, -1, 0)
	return articulation, bridge


def main():
	n, m, *L = map(int, open(0).read().split())
	adj = [[] for _ in range(n)]
	for s, t in zip(*[iter(L)] * 2):
		adj[s] += t,
		adj[t] += s,
	articulation, _ = lowLink(n, adj)
	if articulation:
		print("\n".join(map(str, sorted(articulation))))


if __name__ == '__main__':
	main()



Measured memory_bytes: 22208
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, m = LI()
L = sorted(LIR(m), key=lambda x:x[1])
pre_end = 0
cnt = 0
for start, end in L:
    if start < pre_end:
        continue
    else:
        cnt += 1
        pre_end = end


print(cnt)




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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
 
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'
 
const ll MOD = 1000000007;

int main() {
   int n; scanf("%d", &n);
   vector<int> a(n);
   for (int &i : a)
      scanf("%d", &i);
   int m = *max_element(all(a));
   vector<int> s(m + 1, -1);
   for (int i = 2; i <= m; i++) {
      if (s[i] == -1) {
         s[i] = i;
         for (int j = 2 * i; j <= m; j += i)
            if (s[j] == -1) s[j] = i;
      }
   }
   unordered_set<int> p;
   int ans = 2;
   for (int i : a) {
      int temp = i;
      while (temp > 1) {
         int cur = s[temp];
         if (p.find(cur) != p.end()) ans = 1;
         p.insert(cur);
         while (temp % cur == 0)
            temp /= cur;
      }
   }
   unordered_set<int> p1;
   int temp = a[0];
   while (temp > 1) {
      int cur = s[temp];
      p1.insert(cur);
      temp /= cur;
   }
   for (int i = 1; i < n; i++) {
      vector<int> del;
      for (int j : p1)
         if (a[i] % j != 0) del.pb(j);
      for (int j : del)
         p1.erase(j);
   }
   if (!p1.empty()) ans = 0;
   if (ans == 2) {
      printf("pairwise coprime");
   } else if (ans == 1) {
      printf("setwise coprime");
   } else {
      printf("not coprime");
   }
   return 0;
}

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

int main(){
    int n;
    const int N = 1e6;

    vector<bool> is_prime(N,true);
    is_prime[0] = false;
    is_prime[1] = false;

    for(int i=2;i*i<N;i++){
        if(is_prime[i]){
            for(int j=i*2;j<N;j+=i){
                is_prime[j] = false;
            }
        }
    }

    while(cin >> n){
        if(n == 0) return 0;
        if(n%2) {
            if(is_prime[n-2]) cout << 1 << endl;
            else cout << 0 << endl;
        }
        else {
            int ans = 0;
            for(int i=1;i<=n/2;i++){
                if(is_prime[i] && is_prime[n-i]){
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }
}


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

int main() {
  int N, A, B;
  cin >> N;
  int s = 0;
  for(int i = 0; i < N; i++){
    cin >> A >> B;
    s += B - A + 1;
  }
  cout << s << endl;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

	int N;
	cin >> N;

	ddvi head_tail(10,vi(10,0));

	REP(i,10){
		REP(j,10){
			head_tail[i][j] = 0;
		}
	}

	string num;

	// cout << "pass";

	REP(i,N){
		num = to_string(i+1);
		char h, t;
		h = *num.begin();
		t = *(num.end()-1);
		int head = int(h - '0');
		int tail = int(t - '0');
		// cout << head << tail;
		head_tail[head][tail]++;
	}

	int ans = 0;
	FOR(i,1,10){
		FOR(j,1,10){
			ans += head_tail[i][j] * head_tail[j][i];
		}
	}

	cout << ans << "\n";

return 0;
}

Measured memory_bytes: 256
_counter = 0
_max = 0
_throw = int(input())

for _i in range(_throw):
  _numbers = list(map(int, input().split(" ")))
  if _numbers[0] == _numbers[1]:
    _counter += 1
    if _counter > _max:
      _max = _counter
  else:
    _counter = 0

if _max >= 3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9168
#include<iostream>
#include<cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=1010,P=1e9+7;
int n,m,ans,cnt;
int a[N],b[N],c[N],d[N],f[N],p[N],fc[N],vf[N],iv[N];
char s[N];
void ini(int n){
	iv[1]=fc[0]=vf[0]=1;
	FOR(i,2,n) iv[i]=1ll*(P-P/i)*iv[P%i]%P;
	FOR(i,1,n) fc[i]=1ll*fc[i-1]*i%P,vf[i]=1ll*vf[i-1]*iv[i]%P;
}
int C(int x,int y){return x<y?0:1ll*fc[x]*vf[x-y]%P*vf[y]%P;}
void work(int L,int s,int t){
	int r=1;
	FOR(i,1,m) c[i]=0,b[i]=f[i];b[L+1]=0;
	//FOR(i,1,L) cout<<b[i]<<' ';cout<<'\n';
	FOR(i,1,m)if(!a[i] && r<=L) b[c[i]=r]--,p[r++]=i;
	if(b[r]) return;r=1;
	FOR(i,1,m)if( a[i] && b[r] && p[r]<i) b[c[i]=r]--,p[r++]=i;
	if(b[r]) return;r=1;
	FOR(i,1,m)if(!c[i] && b[r] && p[r]<i && !--b[r]) r++;
	if(b[r]) return;
	int ret=fc[L];
	FOR(i,1,m) ret=1ll*ret*vf[d[i]]%P;
	(ans+=1ll*ret*C(t,2*s)%P)%=P;
}
void dfs(int x,int s,int t){
	if(t<2*s) return;work(x-1,s,t);
	FOR(i,1,min(f[x-1],m-s)) f[x]=i,d[i]++,dfs(x+1,s+i,t+2*(i>=2)),d[i]--;
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d%s",&n,&m,s+1);ini(1000);
	FOR(i,1,m) a[i]=s[i]=='b';
	f[0]=m;dfs(1,0,n+1);
	cout<<ans<<'\n';
}

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/
double di(double a,double b,double c,double d){return sqrt((c-a)*(c-a)+(d-b)*(d-b));}

int main(){
    double pai=3.141592653589;
    double x1,y1,x2,y2,ans;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    printf("%lf\n",di(x1,y1,x2,y2));
    return 0;
}

Measured memory_bytes: 1228
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    final int mod = 1_000_000_007;

    if (Math.abs(N - M) > 1) {
      System.out.println(0);
      return;
    }

    long ans = 1;
    ans *= factorial(N, mod);
    ans *= factorial(M, mod);
    ans %= mod;
    if (N == M) {
      ans *= 2;
      ans %= mod;
    }
    System.out.println(ans);
  }

  private static long factorial(int n, int mod) {
    long res = 1;
    while (n > 1) {
      res *= n;
      res %= mod;
      n--;
    }
    return res;
  }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	int ans=0;
	ans=min(a+b,b+c);
	ans=min(ans,a+c);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;

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

int main() {

    ll N,M;
    cin >> N >> M;
    priority_queue<ll> que;
    ll A = 0;
    ll out = 0;
    rep(i,N){
        cin >> A;
        que.push(A);
        out += A;
    }
    ll max = 0;
    rep(i,M){
        max = que.top();
        que.pop();
        que.push(max/2);
        out -= max-max/2;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 1400
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
 

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    ppl                      pair < int , pll>           
#define    sp(x)                    setprecision(x)

int32_t main()
{       
    speed upp
    int a,b,x,y=0;
    cin>>a>>b;
    f(i,1,b)
    {
        cin>>x;
        y+=x;
    }
    if(y>=a)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath> //これはlogを使うときに必要
#include <vector> //これは配列(vector)を使うときに必要
#include <math.h> //べき乗を使うときに必要
using namespace std;

//ビット全探索の基本のプログラム
int main() {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> vec(m);

  for(int i = 0; i < m; i++) {
    int k;
    cin >> k;
    //2次元配列vecのi番目の列のサイズをkに変える
    vec[i].resize(k);
    for(int j = 0; j < k; j++) {
      cin >> vec[i][j];
      //よくわからん
      　vec[i][j]--;
    }
  }

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

  int ans = 0;
  for(int i = 0; i < (1 << n); i++) {
    bool ok = true;
    for(int j = 0; j < m; j++) {
      int c = 0;
      for(int id : vec[j]) {
        if((i >> id) & 1) {
          c++;
        }
      }
      c %= 2;
      if(c != p[j]) {
        ok = false;
      }
    }
    if(ok) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a,b,i,j,k,l;
  while(scanf("%d",&a)!=EOF){
    b=0;
    for(i=0;i<=9;i++){
    for(j=0;j<=9;j++){
    for(k=0;k<=9;k++){
    for(l=0;l<=9;l++){
      if(a==(i+j+k+l)){
        b++;break;
      }
    }}}}
    printf("%d\n",b);
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.*;

class Main {
	static int mod=1_000_000_007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		int cnt = N-K+1;
		for (int i=1;i<=K;i++) {
			if (cnt>0) {
				System.out.println(nCr(N-K+1, i) * nCr(K-1, i-1) % mod);
			} else {
				System.out.println(0);
			}
			cnt--;
		}
	}

	public static long factorial(int n) {
		long tmp = 1;
		for (int i=n;i>0;i--) {
			tmp = (tmp*i)%mod;
		}
		return tmp;
	}

static long modinv(long a) {
    long b = mod;
    long u = 1L;
    long v = 0L;
    while (b>0) {
        long t = a / b;
        a -= t * b;
        long tmp_1 = a;
        a = b;
        b = tmp_1;

        u -= t * v;
        long tmp_2 = u;
        u = v;
        v = tmp_2;
    }
    u %= mod;
    if (u < 0) {
    	u += mod;
    }
    return u;
}

public static long nCr(int n, int r) {
	return factorial(n) * modinv(factorial(n-r)) % mod * modinv(factorial(r)) % mod;
}
}

Measured memory_bytes: 21716
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		for(int i = 0; i < n; i++) {
			x[i] = scanner.nextInt();
			y[i] = x[i];
		}
		Arrays.sort(x);
//		int min = x[n-1/2];
		
		for(int r = 0; r < n; r++) {
			if(y[r] <= x[n/2-1]) {
				System.out.println(x[n/2]);
			}else {
				System.out.println(x[n/2-1]);
			}
		}
	}

}

Measured memory_bytes: 93284
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		long n = s.nextLong();
		System.out.println(g(n));
	}
	
	private static long g(long n) {
		long r = 0;
		while(n>0) {
			return 1 + 2 * g(n/2);
		}
		return r;
	}
}


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

int main(){
  int n;
  cin >>n;
  int dis = n/15;
  cout << 800*n-200*dis << endl;
  return 0;
}


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

using namespace std;

int main(){
    int N; scanf("%d", &N);
    int ans = 0;
    for(int i = 1; i <= N; ++i){
        int val = i, cnt = 0;
        while(val){
            ++cnt, val /= 10;
        }
        if(cnt % 2) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



int main() {
//    cout << setprecision(100);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, d;
    cin >> n >> d;
    cout << ceil((double) n / (2 * d + 1));







}




Measured memory_bytes: 256
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){

  int H = 1, W = 1;
  int i, j;

  while(H > 0 || W > 0){
    scanf("%d %d", &H, &W);
    if(H == 0 && W == 0){
      break;
    }else{
      for(j = 0; j < W; j++){
	printf("#");
      }
      printf("\n");
      for(i = 1; i < H - 1; i++){
	printf("#");
	for(j = 1; j < W - 1; j++){
	  printf(".");
	}
	printf("#\n");
      }
      for(j = 0; j < W; j++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  
  return 0;
}


Measured memory_bytes: 2044
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 1000010
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, m;
// 4ab < (c - a - b) ^ 2
int main() {
	io(); ll a, b, c;
	cin >> a >> b >> c;
	if (4ll * a * b < (c - a - b) * (c - a - b) && (c > a + b)) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>	// require memset 

using namespace std;

const int N = 50000;
bool prime[N+1];

void make_prime (void)
{
	memset (prime, true , sizeof(prime ) );

	prime[0] = false;
	prime[1] = false;

	for (int i = 2; i*i <= N; ++i ) {
		if (prime[i] ) {
			for (int j = i*i; j <= N; j += i ) {
				prime[j] = false;
			} // end for
		} // end if
	} // end for
}

int main()
{
	make_prime();

	int n;
	while (cin >> n && n ) {
		int res = 0;

		for (int i = 2; i <= n/2; ++i ) {
			if (prime[i] && prime[n-i] ){
				++res;
			} // end for
		} // end for
		cout << res << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1216
s=input()
t=input()
S=[]
T=[]
for i in range(len(s)):
  S.append(s[i])
for i in range(len(t)):
  T.append(t[i])
s_sort=''
t_sort=''
for i in range(len(S)):
  s_sort=s_sort+sorted(S)[i]
for i in range(len(T)):
  t_sort=t_sort+sorted(T)[::-1][i]
print('Yes' if s_sort<t_sort else 'No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long daan[100005];
int main()
{
    int m;
    int a,b;
    int x,y,z,i;
    long long daan=0;
    priority_queue <int> q1;
    priority_queue <int> q2;
    priority_queue <int> q3;
    cin>>a>>b>>x>>y>>z;
    for(i=1;i<=x;i++)
    {
        scanf("%d",&m);
        q1.push(m);
    }

    for(i=1;i<=y;i++)
    {
        scanf("%d",&m);
        q2.push(m);
    }

    for(i=1;i<=z;i++)
    {
        scanf("%d",&m);
        q3.push(m);
    }

    for(i=1;i<=a;i++)
    {
        if(q1.empty())
        {
            daan+=q3.top();q3.pop();continue;
        }
        if(q3.empty())
        {
            daan+=q1.top();q1.pop();continue;
        }
        int p1=q1.top();
        int p2=q3.top();
        if(p1>=p2)
        {
            daan+=q1.top();q1.pop();
        }
        else
        {
            daan+=q3.top();
            q3.pop();
            q3.push(q1.top());
            q1.pop();
        }
    }

    for(i=1;i<=b;i++)
    {
        if(q2.empty())
        {
            daan+=q3.top();q3.pop();continue;
        }
        if(q3.empty())
        {
            daan+=q2.top();q2.pop();continue;
        }
        int p1=q2.top();
        int p2=q3.top();
        if(p1>=p2)
        {
            daan+=q2.top();q2.pop();
        }
        else
        {
            daan+=q3.top();
            q3.pop();
            q3.push(q2.top());
            q2.pop();
        }
    }
    cout<<daan<<endl;
    return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define REP(i,n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
#define ALL_OF(v) (v).begin(), (v).end()
constexpr ll LINF = numeric_limits<ll>::max();
constexpr ll  INF = numeric_limits<int>::max();

int main() {

    string s; cin >> s;
    ll n = s.size();

    // dp[i][j][k] := i桁見て状態jの数がNを下回って(k ? ない : いる)
    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(6, vector<ll>(2, 0)));
    dp[0][0][1] = 1;
    REP(i, n) {
        ll d = s[i] - '0';
        REP(j, 10) {
            switch (j) {
                case 5:
                    {
                        ll dist[6] = {1, 1, 3, 1, 1, 5};
                        REP(k, 6) dp[i+1][dist[k]][0] += dp[i][k][0];
                        if (j <= d) {
                            REP(k, 6) dp[i+1][dist[k]][j==d] += dp[i][k][1];
                        }
                    }
                    break;
                case 1:
                    {
                        ll dist[6] = {0, 2, 4, 2, 0, 5};
                        REP(k, 6) dp[i+1][dist[k]][0] += dp[i][k][0];
                        if (j <= d) {
                            REP(k, 6) dp[i+1][dist[k]][j==d] += dp[i][k][1];
                        }
                    }
                    break;
                case 3:
                    {
                        ll dist[6] = {0, 0, 4, 5, 5, 5};
                        REP(k, 6) dp[i+1][dist[k]][0] += dp[i][k][0];
                        if (j <= d) {
                            REP(k, 6) dp[i+1][dist[k]][j==d] += dp[i][k][1];
                        }
                    }
                    break;
                default:
                    {
                        ll dist[6] = {0, 0, 4, 0, 0, 5};
                        REP(k, 6) dp[i+1][dist[k]][0] += dp[i][k][0];
                        if (j <= d) {
                            REP(k, 6) dp[i+1][dist[k]][j==d] += dp[i][k][1];
                        }
                    }
            }
        }
    }

    // REP(j, 6) REP(i, n+1) cerr << setw(4) << dp[i][j][0] + dp[i][j][1] << " \n"[i==n];

    cout << dp[n][5][0] + dp[n][5][1] << endl;

}


Measured memory_bytes: 3220
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    # diff >= 0 → ノルマ成功
    diff = [a[i] - b[i] for i in range(n)]
    # 調整すべきテスト
    given_score_index = []
    # 調整すべき総点数
    given_score_sum = 0
    # 調整してあげるテスト
    give_score_value = []
    for i in range(n):
        if diff[i] < 0:
            given_score_index.append(i)
            given_score_sum += -diff[i]
        else:
            give_score_value.append(diff[i])
    if not given_score_index:
        print(0)
        return
    if sum(give_score_value) < given_score_sum:
        print(-1)
        return
    # 調整すべきテストは絶対カウント
    ans = len(given_score_index)
    num = 0
    give_score_value.sort(reverse=True)
    for value in give_score_value:
        num += 1
        given_score_sum -= value
        if given_score_sum > 0:
            continue
        break
    ans += num
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n;
ll a[100000];
ll sum = 0;
int s_p[300000];
ll sums[300000];

int main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) sum += a[i];
    int pos = 0;
    int cnt = 0;
    int hoge = 0;
    memset(s_p, -1, sizeof(s_p));
    while (true) {
        if (s_p[pos] == -1) s_p[pos] = cnt;
        sums[cnt++] = a[pos];
        pos = (pos + 2) % n;
        if (pos == 0) {
            hoge++;
            if (hoge == 2) break;
        }
    }
    for (int i = 1; i < cnt; i++) sums[i] += sums[i-1];
    sum /= 2;
    rep(i,n) {
        cout << (sum - (sums[s_p[(i-1+n)%n]+n/2]-sums[s_p[(i-1+n)%n]]))*2;
        if (i != n-1) cout << " ";
    }
    cout << endl;
}


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

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

Measured memory_bytes: 256
num=int(input().rstrip())
m=list(map(int,input().rstrip().split()))
if num<3:
    count=0
else:
    count=0
    for i in range(num-2):
        for j in range(i+1,num-1):
            for k in range(j+1,num):
                if m[i]==m[j] or m[j]==m[k] or m[k]==m[i]:
                    pass
                elif m[i]<m[j]+m[k] and abs(m[j]-m[k])<m[i]:
                    count+=1
print(count)


Measured memory_bytes: 9192
M,D = map(int,input().split())

ans = 0
for m in range(1,M+1):
    for d in range(22,D+1):
        d1 = d%10
        d2 = d//10
        if d1>=2 and d2>=2 and d1*d2 == m:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll h, w, n;
    cin >> h >> w >> n;
    vl a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }
    vl ret(10, 0);
    ret[0] = (h - 2) * (w - 2);
    map<pii, int> cnt;
    for (int i = 0; i < n; ++i) {
        for (int y = a[i] - 2; y <= a[i]; ++y) {
            for (int x = b[i] - 2; x <= b[i]; ++x) {
                if (0 <= y && 0 <= x && y < h - 2 && x < w - 2) {
                    pii bl = make_pair(y, x);
                    ret[cnt[bl]]--;
                    cnt[bl]++;
                    ret[cnt[bl]]++;
                }
            }
        }
    }
    for (auto &r : ret) {
        cout << r << "\n";
    }
    return 0;
}

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

ll lcm(ll m, ll n){ //最小公倍数
	if(0 == m || 0 == n)
		return 0;
	return
        ((m / __gcd(m, n)) * n);
}

int main(){
    ll N, M, L, a, b;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    
    L = lcm(N, M);
    a = L/N;
    b = L/M;
    // SはX[0], X[a], X[2a], ...,X[(N-1)*a]を連結したもの
    // TはX[0], X[b], X[2b], ...,X[(M-1)*b]を連結したもの
    ll l = min((N-1)*a + 1,(M-1)*b + 1), c;
    if(N > M)
        c = b;
    else
        c = a;
    for(ll i=0;i<=l;i += c){
        // a, bの公倍数となっている箇所をチェック
        if(i%a == 0 && i%b == 0){
            if(S[i/a] != T[i/b]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << L << endl;
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

vector<vector<int>> G;
vector<int> seen;

void dfs(int from, int pos, int cnt){
    cnt++;
    if(pos == 1){
        return;
    }

    for(int next: G[pos]){
        if(seen[next] != -1) return;
        else{
            seen[next] = cnt;
            dfs(pos,next,cnt);
        }
        
    }
}

int main() {
    int N; cin >> N;
    G.assign(N,{});
    seen.assign(N,-1);
    seen[0] = 0;

    REP(i,N){
        int a; cin >> a;
        a--;
        G[i].push_back(a);
    }

    dfs(-1,0,0);

    cout << seen[1] << endl;
    return 0;
}

Measured memory_bytes: 13732
#include <iostream>
#include <utility>
#include <stdint.h>
#include <deque>

using namespace std;

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

  deque<uint64_t> A;
  uint64_t X=0, Y=0;

  for (int n=0; n<N; ++n) {
    uint64_t a;
    cin >> a;
    A.push_back(a);
  }

  while (A.size() > 0) {
    if (X<=Y) {
      X += A.front();
      A.pop_front();
    } else {
      Y += A.back();
      A.pop_back();
    }
    // uint64_t common = min(X,Y);
    // X -= common;
    // Y -= common;
  }

  cout << max(X,Y) - min(X,Y) << endl;

  return 0;
}


Measured memory_bytes: 1920