akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

struct seg{
	lint tree[270000];
	int lim;
	void init(int n){
		memset(tree, 0x3f, sizeof(tree));
		for(lim = 1; lim <= n; lim <<= 1);
	}
	void update(int x, lint v){
		x += lim;
		tree[x] = min(tree[x], v);
		while(x > 1){
			x >>= 1;
			tree[x] = min(tree[2*x], tree[2*x+1]);
		}
	}
	lint query(int s, int e){
		s += lim;
		e += lim;
		lint ret = 1e18;
		while(s < e){
			if(s%2 == 1) ret = min(ret, tree[s++]);
			if(e%2 == 0) ret = min(ret, tree[e--]);
			s >>= 1;
			e >>= 1;
		}
		if(s == e) ret = min(ret, tree[s]);
		return ret;
	}
}seg;

int n, e, t, a[100005];
lint dp[100005];


int main(){
	cin >> n >> e >> t;
	lint curmin = 1e18;
	int p = 0;
	seg.init(n);
	seg.update(0, 0);
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		while(p < i && 2 * a[i] - 2 * a[p+1] >= t){
			curmin = min(curmin, dp[p] - 2 * a[p+1]);
			p++;
		}
		dp[i] = curmin + 2 * a[i];
		dp[i] = min(dp[i], seg.query(p, i-1) + t);
		seg.update(i, dp[i]);
	}
	cout << dp[n] + e << endl;
}


Measured memory_bytes: 3584
// ABC073 D-joisino's travel ワーシャルフロイド
// https://atcoder.jp/contests/abc073/tasks/abc073_d
// はまりポイント１　next_permutationは、sort(r.begin(),r.end());　してから使う
// はまりポイント２　『 cost[i][j] = INT_MAX;
// 』でそのまま足し算してしまっては、まずい INT_MAX + INT_MAX = 01111111 +
// 01111111 = 11111110 = -2
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    const int INF = INT_MAX / 2;
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r;
    for(int i = 0; i < R; i++) {
        int temp;
        cin >> temp;
        r.push_back(temp);
    }
    int cost[N + 1][N + 1];
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= N; j++) {
            if(i == j) {
                cost[i][j] = 0;
            } else {
                cost[i][j] = INF;
            }
        }
    }
    for(int i = 0; i < M; i++) {
        int A, B, C;
        cin >> A >> B >> C;
        cost[A][B] = C;
        cost[B][A] = C;
    }
    for(int k = 1; k <= N; ++k) {
        for(int i = 1; i <= N; ++i) {
            for(int j = 1; j <= N; ++j) {
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }
    int min = INF;
    sort(r.begin(), r.end());
    do {
        int tempcost = 0;
        for(int i = 1; i < r.size(); i++) {
            if(cost[r[i - 1]][r[i]] >= INF || tempcost > INF) {
                tempcost = INF;
            } else {
                tempcost += cost[r[i - 1]][r[i]];
            }
        }
        if(tempcost < min) {
            min = tempcost;
        }
    } while(next_permutation(r.begin(), r.end()));
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 384
(defun split (input stack-string output-list)
  (let ((chara (car input)))
    (case chara
          ((nil) (append output-list (list stack-string)))
          (#\space (split (cdr input)
                                  '()
                                  (append output-list (list stack-string))))
          (otherwise (split (cdr input)
                                    (concatenate 'string stack-string (list chara))
                                    output-list)))))

(defun input-to-list (input)
  (mapcar #'parse-integer (split (concatenate 'list input)
                                 '()
                                 '())))

(defun grouping (lst num)
  (list (apply #'+ (subseq lst 0 num)) (apply #'+ (subseq lst num))))

(defparameter num (read))
(defparameter weights (input-to-list (read-line)))

(format t "~d" (apply #'min (loop for n from 1 to (1- num)
                          collect (abs (apply #'- (grouping weights n))))))


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

using namespace std;

int main(){
  int array[3] = {};
  string s;
  cin >> s;
  for (auto it = s.begin();it != s.end();it++) {
    array[int(*it) - 97]++;
  }
  for (int i=0;i<3;i++) {
    if (array[i] != 1) {
      cout << "No" << endl;
      return(0);
    }
  }
  cout << "Yes"  << endl;
  return(0);
}


Measured memory_bytes: 256
N=int(input())
h=list(map(int,input().split()))
dp=[float('inf')]*N
dp[0]=0
dp[1]=abs(h[0]-h[1])
for i in range(2,len(h)):
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[N-1])




Measured memory_bytes: 13928
package main

import (
        "fmt"
)

func solution(s string) int {
        if len(s) == 0 {
                return 0
        }
        z, o := 0, 0
        for i := range s {
                if s[i] == '0' {
                        z++
                } else {
                        o++
                }
        }
        return 2 * min(z, o)

}

func min(x, y int) int {
        if x < y {
                return x
        }
        return y
}

func main() {
        var s string
        fmt.Scan(&s)
        fmt.Println(solution(s))
}

Measured memory_bytes: 2484
import java.util.*;

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

        long N = sc.nextLong();
        long K = sc.nextLong();

        long ans = 0;

        for(long b = K+1; b <= N; b++) {
            if(N % b != 0) {
                ans += (N / b) * (b - K) + Math.max(0, (N % b) - K + 1);
            } else {
                ans += (N / b) * (b - K);
            }
            
        }
        if(K == 0) {
            ans = N * N;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
c = [[int(i) for i in input().split()] for i in range(3)]
diff_a, diff_b = [], []
possible = True

for i in range(2):
    if not c[i][0]-c[i][1] == c[i+1][0]-c[i+1][1]:
        possible = False
    if not c[i][1]-c[i][2] == c[i+1][1]-c[i+1][2]:
        possible = False
    if not c[0][i]-c[1][i] == c[0][i+1]-c[1][i+1]:
        possible = False
    if not c[1][i]-c[2][i] == c[1][i+1]-c[2][i+1]:
        possible = False
print('Yes' if possible else 'No')


Measured memory_bytes: 38256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  ll N, K; cin >> N >> K;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];

  vector <int> num[200001], index(N);
  for (int i = 0; i < N; i++){
    num[A[i]].push_back(i);
    index[i] = num[A[i]].size() - 1;
  }
  
  vector <Pii> Top;
  int now_num = A[0], now_index = 0;
  while (now_index < N){
    int inside_index = index[now_index];

    if (inside_index + 1 == num[now_num].size()){
      Top.push_back(make_pair(now_num, now_index));

      now_index = num[now_num][0] + 1;
      if (now_index == N) break;
      now_num = A[now_index];
    }else{
      now_index = num[now_num][inside_index + 1] + 1;
      if (now_index == N) break;
      now_num = A[now_index];
    }
  }

  ll T = Top.size() + 1, Order = K % T;

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

  now_index = Top[Order - 1].second;
  vector <int> Ans;
  while (now_index < N){
    int now_num = A[now_index];
    int inside_index = index[now_index];
    if (inside_index + 1 == num[now_num].size()){
      Ans.push_back(now_num);
      now_index++;
    }else{
      now_index = num[now_num][inside_index + 1] + 1;
    }
  }
  
  for (int i = 0; i < Ans.size(); i++){
    cout << Ans[i];
    if (i == Ans.size() - 1) cout << endl;
    else cout << " " ;
  }
  
  
  

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	LLi n, fv=10, ans=0;
	cin>> n;
  
  	if(n%2){
      cout<< "0" <<endl;
    	return 0;
    }

  	while(1){
      ans+=n/fv;
      fv*=5;
      if(n<fv) break;
    }
  
  	cout<< ans <<endl;
 
	return 0;
}


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

using pii = pair<int, int>;

struct edge {
    int to, cost;
};

using edges = vector<edge>;
using graph = vector<edges>;

constexpr int INF = 1e9;

// leaf, far
pair<int, int> dfs(int v, int prev, graph const& g, int sum) {
    pii res = make_pair(0, 0);
    if(g[v].size() == 1 && prev != -1) {
        res.first = g[v][0].cost;
        res.second = sum - g[v][0].cost;
        return res;
    }
    for(auto& e : g[v]) {
        if(e.to == prev) {
            continue;
        }
        pii p2 = dfs(e.to, v, g, sum+e.cost);
        res.first += p2.first;
        res.second = max(res.second, p2.second);
    }
    return res;
}

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> p(n-1), d(n-1);
        for(int i=0; i<n-1; ++i) {
            cin >> p[i];
            p[i]--;
        }
        int sum = 0;
        for(int i=0; i<n-1; ++i) {
            cin >> d[i];
            sum += d[i];
        }
        graph g(n);
        for(int i=0; i<n-1; ++i) {
            g[i+1].push_back(edge{p[i], d[i]});
            g[p[i]].push_back(edge{i+1, d[i]});
        }
        int res = INF;
        for(int i=0; i<n; ++i) {
            pii t = dfs(i, -1, g, 0);
            res = min(res, (sum-t.first)*3 + t.first - t.second);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 3132
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a =sc.nextInt();
		String s=sc.next();
		if(a>=3200){
			System.out.println(s);
		}else{
			System.out.println("red");
		}
	}
}


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

int main() {
  int n, x, i, ans = 0;
  cin >> n >> x;
  vector<int> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  for (i = 0; i < n; i++) {
    x -= a[i];
    ans++;
    if (x < 0) {
      break;
    }
  }
  if (x == 0) {
    cout << ans << "\n";
  } else {
    cout << max(0, ans - 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 rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;
int main() {
   int n;
   cin >> n;
   vector<int> x(n), y(n);
   rep(i, n) { cin >> x[i]; }
   rep(i, n) { cin >> y[i]; }
   double D = 0.0;
   rep(i, n) {
      double norm = abs(x[i] - y[i]);
      D += norm;
   }
   printf("%0.6f\n", D);
   D = 0.0;
   rep(i, n) {
      double norm = abs(x[i] - y[i]);
      D += norm * norm;
   }
   D = sqrt(D);
   printf("%0.6f\n", D);
   D = 0.0;
   rep(i, n) {
      double norm = abs(x[i] - y[i]);
      D += norm * norm * norm;
   }
   D = cbrt(D);
   printf("%0.6f\n", D);
   D = 0.0;
   rep(i, n) { D = max(D, (double)abs(x[i] - y[i])); }
   printf("%0.6f\n", D);
   return 0;
}


Measured memory_bytes: 3288
#include<stdio.h>

 int main()
 {
   int i , j, b, v, k, A[200];
   scanf("%d",&b);
   for(i=0; i < b; i++){
    scanf("%d",&A[i]);
   }
   
   for(i=1; i<b; i++){
    v = A[i];
    j = i - 1;
    for(k=1; k<=b; k++){
      if (k > 1){
      printf(" ");
    }
      printf("%d", A[k-1]);
    }
   printf("\n");
    while(j >= 0 && A[j] > v){
     A[j+1] = A[j];
     j--;
    A[j+1] = v;
    }
   }
         for(k=1; k<=b; k++){
    if (k > 1){
    printf(" ");
    }
    printf("%d", A[k-1]);
  }
    printf("\n");
    
   return 0;
    }

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N, K;
    ll H;
    vector<ll> h, sur;
    cin>>N>>K;
    rep(i, N){
        cin>>H;
        h.push_back(H);
    }
    ll Minim=9999999999;
    sort(all(h));
    rep(i, N-K+1){
        Minim=min(h[i+K-1]-h[i], Minim);
    }
    cout<<Minim<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
const ll arg1=109,arg2=100005;
ll n,wt,w[1000],v[1000],c[100009],mn=1000000,mem[arg1][arg2];

ll calc(ll m,ll wt)
{
    if(mem[m][wt]!=-1)
    {
        return mem[m][wt];
    }
    if(m>n)
    {
        return 0;
    }
    //if(me)
    ll x=-1,y=-1;
    //leave
    x=calc(m+1,wt);
    //take
    if(w[m]<=wt)
    {
        y=v[m]+calc(m+1,wt-w[m]);
    }
    return mem[m][wt]= max(x,y);
}

int main()
{
    for(int i=0;i<arg1;i++)
    {
        for(int j=0;j<arg2;j++)
        {
            mem[i][j]=-1;
        }
    }
    cin>>n>>wt;
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    cout<<calc(0,wt);

    return 0;
}


Measured memory_bytes: 85376
// Your code here!
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    use std::collections::HashMap;
    use std::collections::hash_map::Entry::{Occupied, Vacant};
    
    let mut map: HashMap<String, usize> = HashMap::new();
    let n: usize = read();
    
    for _ in 0..n{
        let x : String = read();
        let mut y: Vec<char> = x.chars().into_iter().collect();
        
        y.sort();
        let s: String = y.into_iter().collect();
        
        
        match map.entry(s) {
            Occupied(mut e) => {
                let value = e.get_mut();
                *value += 1;
            }
            Vacant(e) => { e.insert(1); }
        }
        
    }
    let mut ans = 0;
    for (_,v) in map.iter(){
        ans+=v*(v-1)/2;
    }
    
    println!("{}",ans)
    
}




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

int main(){
    int N;
    cin >> N;
    int W[N];
    for(int i = 0; i < N; i++)
        cin >> W[i];
    
    int ans = MOD;
    int tmp;
    int S1 = 0, S2 = 0;
    for(int i = 0; i < N; i++)
        S2 += W[i];
    tmp = abs(S1 - S2);
    ans = min(ans,tmp);
    
    for(int i = 0; i < N; i++){
        S1 += W[i];
        S2 -= W[i];
        tmp = abs(S1 - S2);
        ans = min(ans,tmp);
        //cout << W[i] << "  " << tmp << "  " << ans << "\n";
    }
    
    cout << ans << "\n";
    return 0;
} 


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[4] = {}, ans = 0;
	scanf("%d%d%d%d", &a[0], &a[1], &a[2], &a[3]);
	for (int i = 0; i < 4; i++)
	{
		if (a[i] == 1)
		{
			for (i = 0; i < 4; i++)
			{
				if (a[i] == 9)
				{
					for (i = 0; i < 4; i++)
					{
						if (a[i] == 7)
						{
							for (i = 0; i < 4; i++)
							{
								if (a[i] == 4) ans = 1;
							}
						}
					}
				}
			}
		}
	}
	if (ans)
	{
		printf("YES");
	}
	else printf("NO");
	return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

ll A;
long double B;

int main(){
	fast;
	
	cin>>A>>B;
	
	cout<<ll(A * B);
	
}



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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    vector<int> a(N);
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
        ans += a.at(i) - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> R,B;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        R.push_back({a,b});       
    } 
    rep(i,n){
        int c,d;
        cin>>c>>d;
        B.push_back({c,d});
    }

    sort(all(B));
    vector<bool> exist(n,true);

    int ans=0;
    rep(i,n){
        int x=B[i].first;
        int y=B[i].second;
        int ma=-1,id=-1;
        rep(j,n){
            int xx=R[j].first;
            int yy=R[j].second;
            if(!exist[j]) continue;
            if(xx>=x || yy>=y) continue;
            if(ma<yy){
                ma=yy;
                id=j;
            }
        }

        if(id!=-1){
            ans++;
            exist[id]=false;
        }
    }

    cout<<ans<<endl;
}

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

static double
round3(double r)
{
	r *= 1000.0;
	r = round(r);
	r /= 1000.0;
	
	if (r == -0) {
		r = 0;
	}
	
	return r;
}

int
main(void)
{
	char line[80];
	double a;
	double b;
	double c;
	double d;
	double e;
	double f;
	double x;
	double y;

	while (gets(line)) {
		if (sscanf(line, "%lf %lf %lf %lf %lf %lf",
				   &a, &b, &c, &d, &e, &f) == 6) {
			x = (e*c  -b*f)/(a*e - b*d);
			y = (d*c - a*f)/(d*b - a*e);
			
			printf("%.3f %.3f\n", round3(x), round3(y));
		}
	}

	return 0;
}

Measured memory_bytes: 1108
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
ll N;
vector<vector<ll>> A(16, vector<ll>(16, 0));
//dp[i]は集合の状態がiのときの最大値
vector<ll> dp((1<<16),0);



int main(){
    cin>>N;
    for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)cin>>A[i][j];

    for(ll S=0;S<(1<<N);S++){
        for(ll i=0;i<N;i++)
            for(ll j=0;j<i;j++){
                if(S>>i&S>>j&1)dp[S]+=A[i][j];
            }
        for(ll T=S;T>0;T=(T-1)&S)chmax(dp[S],dp[T]+dp[S-T]);
    }

    print(dp[(1<<N)-1])


    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>

using namespace std;
using ll = long long int;
using vec = vector<int>;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end())
const int INF = 2147483647;
const ll  MOD = 1000000007;

int main() {
    int n, m; cin >> n >> m;
    cout << ((n == m) ? "Yes" : "No");
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (H, W) = read!(usize, usize);
    println!("{}", (H - 1) * (W - 1))
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	vi vec(n);
	rep(i,0,n) cin>>vec[i];
	sort(all(vec));
	int m=n/2;
	cout<<vec[m]-vec[m-1];
	
	return 0;
}

Measured memory_bytes: 640
A,B,K= input().split()
Ax=int(A)
Bx=int(B)
Kx=int(K)
for i in range(Kx):
    if (i+1)%2!=0:#高橋君
        if Ax%2!=0:
            Ax=Ax-1
        Ax=Ax/2
        Bx=Bx+Ax
    else:
        if Bx%2!=0:
            Bx=Bx-1
        Bx=Bx/2
        Ax=Ax+Bx
print(str(int(Ax))+" "+str(int(Bx)))


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        int[] count = new int[n+1];
        for(int x=1; x<Math.sqrt(n); x++) {
            if((x+2)*(x+2)-(2*x) > n) break;
            for(int y=1; y<Math.sqrt(n); y++) {
                if((x+y+1)*(x+y+1)-(x*y+y+x) > n) break;
                for(int z=1; z<Math.sqrt(n); z++) {
                    if((x+y+z)*(x+y+z)-(x*y+y*z+z*x) > n) break;
                    count[(x+y+z)*(x+y+z)-(x*y+y*z+z*x)]++;
                }
            }
        }
        
        for(int i=1; i<=n; i++) {
            System.out.println(count[i]);
        }
    
    }
}


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

typedef pair<int,int> P;

int dp[4000][4000][2];

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

    vector<P> v;

    for(int i=0;i<N;i++) {
        int a,b;
        cin >> a >> b;
        v.push_back(P(a,b));
    }

    for (int i=1;i<=N;i++) {
        for (int j=0;j<T;j++) {
            if (j>=v[i-1].first) {
                dp[i][j][0] = max(dp[i-1][j-v[i-1].first][0]+v[i-1].second, dp[i-1][j][0]);
                dp[i][j][1] = max(dp[i-1][j][0]+v[i-1].second, max(dp[i-1][j-v[i-1].first][1]+v[i-1].second, dp[i-1][j][1]));
            }
            else {
                dp[i][j][0] = dp[i-1][j][0];
                dp[i][j][1] = max(dp[i-1][j][0]+v[i-1].second, dp[i-1][j][1]);
            }
        }
    }
    int ans = dp[N][T-1][1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 94208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
//#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
//#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
//#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
//template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
//template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
//
//using Graph = vector<vector<int>>;
//using P = pair<int, int>;
//using Tuple = tuple<int, int, int>;

ll dp[202020][2][3];


int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    rep(i, n+1) rep(j, 2) rep(k, 3) dp[i][j][k] = -1LL<<60;
    dp[0][1][0]=0;

    rep(i, n) rep(j, 2) rep(k,3) {
        if(k+j < 3) dp[i+1][1][k+j] = max(dp[i+1][1][k+j], dp[i][j][k]);
        if(j==1) dp[i+1][0][k] = max(dp[i+1][0][k], dp[i][j][k]+a[i]);
    }

    if(n%2==0) cout << max(dp[n][1][0], dp[n][0][1]) << endl;
    else cout << max(dp[n][0][2], dp[n][1][1]) << endl;


    return 0;
}


Measured memory_bytes: 14032
x = int(input())
ans = 0
flag = False
for a in range((x//100)+1):
  for b in range((x//101)+1):
    for c in range((x//102)+1):
      for d in range((x//103)+1):
        for e in range((x//104)+1):
          for f in range((x//105)+1):           
            if (100*a) + (101*b) + (102*c) + (103*d) + (104*e) + (105*f)== x:
              ans += 1
              flag = True
              break
          if flag:
            break
        if flag:
          break
      if flag:
        break
    if flag:
      break
  if flag:
    break
  
if ans == 0:
  print(0)
else:
  print(1)


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


public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try{
			int i = Integer.parseInt(br.readLine());
			for(;i>0;i--){
				String[] abc = br.readLine().split(" ");
				int a = Integer.parseInt(abc[0]);
				int b = Integer.parseInt(abc[1]);
				int c = Integer.parseInt(abc[2]);
				if(a*a+b*b==c*c||b*b+c*c==a*a||c*c+a*a==b*b){
					System.out.println("YES");
				} else System.out.println("NO");
			}
		} catch(Exception e){
			e.printStackTrace();
		}
	}

}

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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll K;
vector<ll> A;

int main(int argc, char **argv)
{
	cin >> K;
	A.resize(K);
	REP(i, K) cin >> A[i];
	reverse(ALL(A));

	P ok;
	ok.first = ok.second = 2;
	REP(i, K)
	{
		ll l = ok.first;
		ll r = ok.second;

		ll ln = (l + A[i] - 1)/ A[i];
		ll rn = r/ A[i];

		if (ln > rn)
		{
			std::cout << -1 << std::endl;
			return 0;
		}

		ok.first = ln*A[i];
		ok.second = rn*A[i] + A[i]-1;
	}

	std::cout << ok.first << " " << ok.second << std::endl;
}


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

int main()
{
    int n,d1,d2,flag = 0,count = 0;
    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> d1 >> d2;
        if (d1 == d2)
        {
           count++;
        }
        else
        {
            count = 0;
        }
        if (count >= 3)
        {
            flag = 1;
        }
        
    }

    if (flag == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
} 

Measured memory_bytes: 3592
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  int n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll mxabs=0;
  int mxabsi=0;
  bool pls=1;
  vector<pii> ans(0);
  rep(i,n){
    if(mxabs<abs(a[i])){
      chmax(mxabs,abs(a[i]));
      mxabsi=i;
      if(a[i]<0) pls=0;
      else pls=1;
    }
  }
  rep(i,n){
    if(pls){
      if(a[i]<0){
        a[i]=a[i]+mxabs;
        ans.push_back(pii(mxabsi,i));
      }
    }
    else{
      if(a[i]>0){
        a[i]=a[i]-mxabs;
        ans.push_back(pii(mxabsi,i));
      }
    }
  }
  if(pls){
    for(int i=0;i<n-1;i++){
      ans.push_back(pii(i,i+1));
    }
  }
  else{
    for(int i=n-1;i>0;i--){
      ans.push_back(pii(i,i-1));
    }
  }
  cout << ans.size() << endl;
  rep(i,ans.size()){
    cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
  }
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(),m = scanner.nextInt();
		char[][] a = new char[n][n];
		char[][] b = new char[m][m];
		for(int i=0;i<n;i++){
			a[i] = scanner.next().toCharArray();
		}
		for(int i=0;i<m;i++){
			b[i] = scanner.next().toCharArray();
		}
		for(int i=0;i<n-m+1;i++){
			for(int j=0;j<n-m+1;j++){
				boolean check = true;
				for(int k=0;k<m;k++){
					for(int l=0;l<m;l++){
						if(a[i+k][j+l] != b[k][l]){
							check = false;
						}
					}
				}
				if(check){
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");

	}

}


Measured memory_bytes: 22996
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		new Main().mainrun();
	}

	private Scanner scan;
	private int n;

	double px,py,r;
	double x1,x2,x3,y1,y2,y3;			//読み込み用
	double x12,x23,y12,y23,xy12,xy23;	//演算用

	private void mainrun() {
		scan = new Scanner(System.in);

		n = scan.nextInt();

		for(int i = 0;i < n;i++) {
			looprun();
		}

		scan.close();
	}

	private void looprun() {

		x1 = scan.nextDouble();
		y1 = scan.nextDouble();
		x2 = scan.nextDouble();
		y2 = scan.nextDouble();
		x3 = scan.nextDouble();
		y3 = scan.nextDouble();

		x12 = 2 * ( x2 - x1) ;
		x23 = 2 * ( x3 - x2 );
		y12 = 2 * ( y2 - y1 );
		y23 = 2 * ( y3 - y2 );
		xy12 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
		xy23 = x2 * x2 - x3 * x3 + y2 * y2 - y3 * y3;

		py = (x23 * xy12 - x12 * xy23 )/(x12 * y23 - x23 * y12);

		px = (y12 * xy23 - y23 * xy12 ) / (x12 * y23 - x23 * y12) ;

		r = Math.hypot(x1 - px , y1 - py);

		System.out.println(String.format("%.3f %.3f %.3f",px ,py ,r ));
	}
}


Measured memory_bytes: 28808
def f(n):
  ans=1
  while n!=0:
    ans+=1
    n%=bin(n).count("1")
  return ans
n=int(input())
x=input()
o=x.count("1")
if o==0:exit(print(*[1]*n))
if o==1:
  if x[-1]=="1":
    ans=[2]*n
    ans[-1]=0
  else:
    ans=[1]*n
    ans[-1]=2
    ans[x.index("1")]=0
  exit(print(*ans))
mo=0
mz=0
for i in range(n):
  if x[n-i-1]=="1":
    mo=(pow(2,i,o+1)+mo)%(o+1)
    mz=(pow(2,i,o-1)+mz)%(o-1)
for i in range(n):
  if x[i]=="1":
    m=(mz-pow(2,n-i-1,o-1))%(o-1)
  else:
    m=(mo+pow(2,n-i-1,o+1))%(o+1)
  print(f(m))

Measured memory_bytes: 84004
import math
def li():
    return [int(x) for x in input().split()]

d, g = li()
ps, cs = [], []
for i in range(d):
    p, c = li()
    ps.append(p)
    cs.append(c)
ps.reverse()
cs.reverse()
# ボーナス得点のパターンを先に全て列挙し、点数が届いていなければ高得点から埋めていく
qcnts = []

for mask in range(2**d):
    score = 0
    qcnt = 0
    #ボーナス計算
    for i in range(d):
        # i番目のフラグが立ってる
        if mask & (1 << i):
            score += cs[i] + ps[i] * 100 * (d-i)
            qcnt += ps[i]
    #残りを高得点から埋めていく
    required_score = g - score
    if required_score >= 0:
        for i in range(d):
            # i番目のフラグが立っているならスキップ
            if mask & (1 << i):
                continue
            required_qcnt = min(math.floor(required_score / (100 * (d-i))), ps[i])
            qcnt += required_qcnt
            score += required_qcnt * (100 * (d-i))
            if score >= g:
                break
    qcnts.append(qcnt)

print(min(qcnts))


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define PII pair<int,int>
#define INF LONG_MAX
#define ull unsigned long long
#define long long long
#define PIL pair<long,int>
#define M 1000000007
#define endl "\n"

void fastIO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

}

int main()
{
	fastIO();
    int n;
    cin>>n;
    long ar[n];
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    long prefix[n]={0};
    prefix[0] = ar[0];
    for(int i =1;i<n;i++){
        prefix[i]  = (prefix[i-1]+ar[i])%M;
    }
    long ans = 0;
    int k = n-1;
    for(int i=0;i<n;i++){
        long store = prefix[n-1]-prefix[i];
        ans = (ans+(ar[i]*store)%M+M)%M;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 6760
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int T = in.nextInt();
        long s = 0;
        int t_prev = in.nextInt();
        for(int i=2; i<=n; i++) {
            int t = in.nextInt();
            s += Math.min(T, t-t_prev);
            t_prev = t;
        }
        s += T;
        System.out.println(s);
    }
}


Measured memory_bytes: 60488
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c; cin >> a >> b >> c;
    int v = b / a;
    cout << min(v, c) << endl;
    return 0;
}



Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    l = ni()
    print((l / 3) ** 3)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int x, n;
    cin >> x >> n;
    vector<int> p(105, 0);
    for(int i = 0; i < n; ++i){
        int foo;
        cin >> foo;
        ++p[foo];
    }
    int ans = 0;
    int dif = INF;
    for(int i = 0; i <= 102; ++i){
        if(p[i])    continue;
        if(abs(x - i) < dif){
            dif = abs(x - i);
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/


void solve() {
	int n; cin >> n;
	vector<int> a(n);
	unordered_map<int, int> m;
	for (int i = 0; i < n; i++) cin >> a[i], m[a[i]]++;
	int ans = 0;
	for (auto x : m) {
		if (x.second >= 2) {
			ans += (x.second * (x.second - 1) / 2);
		}
	}
	for (int i = 0; i < n; i++) {
		int g = ans, h = m[a[i]];
		if (h >= 2) g -= h * (h - 1) / 2;
		h--;
		if (h >= 2) g += h * (h - 1) / 2;
		cout << g << endl;
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 11820
import sys
input = sys.stdin.readline
N,U,V = map(int, input().split())
d = [set() for _ in range(N+1)]
dps = [0 for _ in range(N+1)]
dpss = [0 for _ in range(N+1)]

def it(v):
    stack = [v]
    vs = set()
    path = []
    while True:
        if not len(stack):
            break
        v = stack.pop()
        if v > 0:
            path.append(v)
            vs.add(v)
            for u in d[v]:
                if u in vs:
                    continue
                if u == V:
                    r = path[:]
                dps[u] = dps[v] + 1
                stack.append(-v)
                stack.append(u)
        else:
            path.pop()
    return r

def it2(v, path):
    stack = [v]
    vs = set()
    while True:
        if not len(stack):
            break
        v = stack.pop()
        vs.add(v)
        for u in d[v]:
            if u in vs:
                continue
            if dps[v] >= dpss[v] and u not in path:
                continue
            dpss[u] = dpss[v] + 1
            stack.append(u)

for _ in range(N-1):
    a, b = [int(x) for x in input().split()]
    d[a].add(b)
    d[b].add(a)

path = set(it(U))
it2(V, path)
print(max(dpss)-1)


Measured memory_bytes: 88752
N,K=map(int,input().split())
x=list(map(int,input().split()))
n=N-K+1
left=[0]*n
for i in range(n):left[i]=abs(x[i])+abs(x[i]-x[i+K-1])
x=x[::-1]
right=[0]*n
for i in range(n):right[i]=abs(x[i])+abs(x[i]-x[i+K-1])
print(min(min(left),min(right)))

Measured memory_bytes: 14384
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

const int MOD = 1e9+7;
const int maxm = 2e6+5;

LL F[maxm], Finv[maxm], inv[maxm];

LL comb(int n, int m) { //C(n, m)
    if(m < 0 || m > n) return 0;
    return F[n]*Finv[n-m]%MOD*Finv[m]%MOD;
}

void run_case() {
    int r1, c1, r2, c2, n;
    cin >> r1 >> c1 >> r2 >> c2;
    n = c2+r2+2;
    inv[1] = 1;
    for(int i = 2; i <= n; ++i)
        inv[i] = (MOD - MOD / i) * 1LL * inv[MOD % i] % MOD;
    F[0] = Finv[0] = 1;
    for(int i = 1; i <= n; ++i) {
        F[i] = F[i-1] *1LL* i % MOD;
        Finv[i] = Finv[i-1] * 1LL * inv[i] % MOD;
    }
    LL ans1=0,ans2=0,ans3=0,ans4=0;
    for(int i = 0; i <= r2; ++i) (ans1+=comb(c2+1+i,c2))%=MOD;
    for(int i = 0; i <= r2; ++i) (ans2+=comb(c1+i,c1-1))%=MOD;
    for(int i = 0; i <= r1-1; ++i) (ans3+=comb(c2+1+i,c2))%=MOD;
    for(int i = 0; i <= r1-1; ++i) (ans4+=comb(c1+i,c1-1))%=MOD;
    cout << (ans1+ans4-ans2-ans3+MOD)%MOD;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    //cout.setf(ios_base::showpoint);cout.precision(8);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int N;
    cin >> N;
    vector<int> vec('z', 10000);
    rep(i, N) {
        vector<int> tmp('z', 0);
        string S;
        cin >> S;
        rep(i, S.size()) tmp[S[i] - 'a'] += 1;
        rep(i, 'z') {
            vec[i] = min(vec[i], tmp[i]);
        }
    }
    string ans = "";
    rep(i, 'z') {
        while (vec[i] != 0) {
            ans += (char)(i + 'a');
            vec[i] -= 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int n;
  cin >> n;

  if (n == 1) {
    cout << "0\n";
    return;
  }

  int ma = 0;
  int cnt = 0;
  ll h, oh;
  cin >> oh >> h;
  if (h <= oh) {
    cnt = 1;
    ma = 1;
  }
  oh = h;

  for (int i = 2; i < n; i++) {
    cin >> h;
    if (h <= oh) {
      ++cnt;
    } else {
      ma = max(ma, cnt);
      cnt = 0;
    }
    oh = h;
  }
  cout << max(ma, cnt) << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int N,D,X;
	cin>>N;
	cin>>D>>X;
	int aw=0;
	int i,d;
	int A;
	for (i=0;i<N;i++){
		cin>>A;
		d=1;
		int j=1;
		while(d<=D){
			aw++;
			d=A*j+1;
			j++;
		}
	}
	cout<<aw+X<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)



int main() {
	ll n, m, p, y;
	ostringstream sout;
	in(n);
	in(m);

	map<ll,ll> dic;
	vector<pair<ll, ll>> c(m);
	map<ll,string> ans;
	vll ord(m);
	rep(i, 0, m) {
		in(p);
		in(y);
		c[i] = make_pair(y, p);
		ord[i] = y;
	}

	sort(c.begin(), c.end());
	rep(i, 0, c.size()) {
		dic[c[i].second]++;

		sout << setfill('0') << setw(6) << c[i].second;
		ans[c[i].first] = sout.str();
		sout.str("");
		sout << setfill('0') << setw(6) << dic[c[i].second];
		ans[c[i].first] += sout.str();
		sout.str("");
	}

	rep(i, 0, m) {
		outn(ans[ord[i]]);
	}

	return 0;

}


Measured memory_bytes: 20992
S=input()
N=len(S)
i=0
ans=0
d=0

p=""
while i<N:
  if S[i]=="A":
    if p=="B":
      d=0
    d+=1
  elif S[i]=="B":
    if p=="B":
      d=0
  else:
    if p=="B":
      ans+=d
    else:
      d=0
      
  p=S[i]
  i+=1
print(ans)

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

int main() {
  double H,W,N,M,d;
  cin >>N>>M>>d;
  double ans;
  ans=0;
  if(d!=0){
    ans=2*(N-d)/(N*N)*(M-1);
  }
  else{
    ans=(M-1)/N;
  }
  cout << std::setprecision(10) << ans<<endl;
}
 

Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;

    vector<pii> v;
    vector<int> ans(N);
    rep(i,0,N) {
        int val; cin >> val;
        v.push_back(make_pair(val, i));
    }

    sort(v.begin(), v.end());
    rep(i,0,N) {
        int idx = v[i].second;
        if(i < N / 2) {
            ans[idx] = v[N/2].first;
        }
        else {
            ans[idx] = v[N/2 - 1].first;
        }
    }

    rep(i,0,N) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 7792
/**
 * auther: moririn_cocoa
 */
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_)

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

#define rep(i,n) for(int i=0;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 eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second

int main(int argc, char* argv[]) {
  
  int N;
  
  cin >> N;
  
  if ( N % 2 == 0 ) {
    
    cout << N << endl;
  }
  
  else if ( N % 2 == 1 ) {
    
    cout << N * 2 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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




// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    char str;
    cin>>str;
    if(!isupper(str)){
        cout<<'a'<<endl;
    }else{
        cout<<'A'<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628