akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
INF = 10**12
 
n, m, l = [int(item) for item in input().split()]
dist = [[INF] * n for _ in range(n)]
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    a -= 1; b -= 1
    dist[a][b] = c
    dist[b][a] = c
 
for i in range(n):
    dist[i][i] = 0
 
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
 
for i in range(n):
    for j in range(n):
        if i == j:
            dist[i][j] = 0
        elif dist[i][j] <= l:
            dist[i][j] = 1
        else:
            dist[i][j] = INF
 
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
 
q = int(input())
for i in range(q):
    s, t = [int(item) - 1 for item in input().split()]
    if dist[s][t] == INF:
        print(-1)
    else:
        print(dist[s][t] - 1)

Measured memory_bytes: 56412
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	int a[N];
	rep(i, N) cin >> a[i];
	int ans = 0;
	int tmp = 0;
	rep(i, N - K) tmp += max(0LL, a[i]);
	int left = 0;
	rep(i, K) left += a[N - K + i];
	ans = max(ans, tmp + max(0LL, left));
	rep(i, N - K) {
		//cout << tmp << " " << left << " " << ans << endl;
		//cout << N - K - i - 1 << " " << N - i - 1 << endl;
		left = left + a[N - K - i - 1] - a[N - i - 1];
		tmp = tmp - max(0LL, a[N - K - i - 1]) + max(0LL, a[N - i - 1]);
		ans = max(ans, tmp + max(0LL, left));
	}
	cout << ans << endl;



    return 0;
}


Measured memory_bytes: 1024
from scipy.optimize import*;from numpy import*;n=int(input());x=array([list(map(int,input().split()))for _ in range(n)])
def r(a):return sqrt(square(x-a).sum(1).max())
print(minimize(r,[0,0],method="Nelder-Mead",tol=1e-8).fun)

Measured memory_bytes: 17464
#include<iostream>

int main(void){
  int n, m, max=0;
  int price[1000];

  for(int t=0; t<10000; t++){

    max = 0;
    std::cin >> n;
    std::cin >> m;
    if(n == 0 && m == 0){
      break;
    }

    for(int i=0; i<n; i++){
      std::cin >> price[i];
    }

    for(int j=0; j<n; j++){
      for(int s=0; s<n; s++){
	if(j == s){
	  break;
	}
	if(price[j] + price[s] > max && price[j] + price[s] <= m){
	  max = price[j] + price[s];
	}
      }
    }
    if(max > 0){
      std::cout << max << "\n";
    }else{
      std::cout << "NONE\n";
    }
  }
  return 0;
}



Measured memory_bytes: 3064
function main() {
    var nq = input[0].split(' ').map(Number),
        queue = [], process,
        total;
    input.slice(1, nq[0] + 1).forEach(function (process) {
        process = process.split(' ');
        process[1] = Number(process[1]);
        queue.push(process);
    });

    total = 0;
    while (queue.length !== 0) {
        process = queue.shift();
        if (process[1] > nq[1]) {
            process[1] -= nq[1];
            total += nq[1];
            queue.push(process);
        } else {
            total += process[1];
            console.log(process[0] + ' ' + total);
        }
    }
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
    input += chunk;
});
process.stdin.on('end', function () {
    input = input.split('\n');
    main();
});

Measured memory_bytes: 42728
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        String s = in.next();
        while (!".".equals(s)) {
            String t = in.next();
           // System.out.println("T* " + t);
            int res;
            int[] p = new int[4];
            for (int i = 0; i < 4; i++) {
                p[i] = t.charAt(i) - '0';
            }
            out.print(res = solve(s, p));

            int cnt = 0;
            for (int i = 0; i < 10000; i++) {
                int k = i;
                for (int j = 0; j < 4; j++) {
                    p[j] = k % 10;
                    k /= 10;
                }
                if (solve(s, p) == res) cnt++;
            }
            out.println(" " + cnt);

            s = in.next();
        }
        out.flush();
    }

    private static int solve(String s, int[] p) {
        if (s.length() == 1) {
            return p[s.charAt(0) - 'a'];
        }

        char op = s.charAt(1);
        int v0, v1, last = -1;

        if (s.charAt(2) != '[') {
            v0 = p[s.charAt(2) - 'a'];
            last = 2;
        } else {
            int depth = 1;
            for (int i = 3;; i++) {
                if (s.charAt(i) == '[') {
                    depth++;
                } else if (s.charAt(i) == ']') {
                    depth--;
                }
                if (depth == 0) {
                    last = i;
                    break;
                }
            }
            v0 = solve(s.substring(2, last + 1), p);
        }

        if (s.charAt(last + 1) != '[') {
            v1 = p[s.charAt(last + 1) - 'a'];
        } else {
            int depth = 1, last2 = -1;
            for (int i = last + 2;; i++) {
                if (s.charAt(i) == '[') {
                    depth++;
                } else if (s.charAt(i) == ']') {
                    depth--;
                }
                if (depth == 0) {
                    last2 = i;
                    break;
                }
            }
            v1 = solve(s.substring(last + 1, last2 + 1), p);
        }

        if (op == '+') {
            return v0 | v1;
        } else if (op == '*') {
            return v0 & v1;
        } else if (op == '^') {
            return v0 ^ v1;
        } else {
            throw new RuntimeException();
        }
    }
}



Measured memory_bytes: 165452
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    char str[1024][64];
    int i, j;
    int ls;
    int lsl;
    int sl;
    int mus;
    int stri[1024];
     
    for (i = 0; i < 1024; i++){
        stri[i] = 0;
    }
    i = 0;
    ls = 0;
    lsl = 0;
    while (scanf("%s", str[i]) != EOF){
        sl = strlen(str[i]);
        if (sl > lsl){
            ls = i;
            lsl = sl;
        }
        for (j = 0; j <= i; j++){
            if (strcmp(str[j], str[i]) == 0){
                stri[j]++;
                break;
            }
        }
        i++;
    }
    mus = 0;
    for (j = 1; j < i; j++){
        if (stri[j] > stri[mus]){
            mus = j;
        }
    }
     
    printf("%s %s\n", str[mus], str[ls]);
     
    return (0);
}

Measured memory_bytes: 568
#include <iostream>
#include <stdio.h>
#include <cctype>
#include <cmath>
#include <math.h>
using namespace std;

void printa(int a[], int n) {
  for (int i=0;i<n;i++) {
    if (i!=(n-1)) {
      cout << a[i] << " ";
    } else {
      cout << a[i] <<endl;
    }
  }
}

int stack[200];
int sp = 0;
void push(int a) {
  stack[sp++] = a;
}
int pop() {
  return stack[--sp];
}

#define QUEMAX 100000
int queue[QUEMAX];
int head=0,tail=0;
void enque(int a) {
  queue[tail] = a;
  if ((++tail)==QUEMAX) {
    tail = 0;
  }
}
int deque() {
  int a = queue[head];
  queue[head] =0;
  if ((++head)==QUEMAX) {
    head = 0;
  }
  return a;
}

int queue2[QUEMAX];
int head2=0,tail2=0;
void enque2(int a) {
  queue2[tail2] = a;
  if ((++tail2)==QUEMAX) {
    tail2 = 0;
  }
}
int deque2() {
  int a = queue2[head2];
  queue2[head2] =0;
  if ((++head2)==QUEMAX) {
    head2 = 0;
  }
  return a;
}

void printque() {
  for (int i=0;i<QUEMAX;i++) {
    cout << queue[i] << " ";
  }cout << endl;
}

int main(){
  int n,q,time,i=0,tmp,tmpname;
  int now=0,timesum=0;
  string name[QUEMAX];
  cin >> n >> q;
  for (int i=0;i<n;i++) {
    cin >> name[i] >> time;
    enque(time);
    enque2(i);
    timesum += time;
  }

  while(now<timesum){
    tmp = deque()-q;
    tmpname = deque2();
    if (tmp>0) {
      enque(tmp);
      enque2(tmpname);
      now += q;
    } else {
      now += tmp + q;
      cout << name[tmpname] << " " << now << endl;
    }
  }
}



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

void copy_ary(char a[], const char b[], int n){
  int i;
  for(i = 0; i < n; i++){
    a[i] = b[i];
  }
}

void exchange(char a[], char b[],int  n){
  int i;
  char tmp[n];

  for(i = 0; i < n; i++){
    copy_ary(tmp, a, 3);
    copy_ary(a, b, 3);
    copy_ary(b, tmp, 3);
  }
}

int pickup(char k, const char a[][3], char tmp[], int n){
  int i;
  int m = 0;

  for(i = 0; i < n; i++){
    if(a[i][1] == k){
      tmp[m++] = a[i][0];
    }
  }

  return m;
}

int check_stable(char org[][3], char a[][3], int n){
  int i, j, m;
  char tmp[n];
  char tmp_or[n];

  int flag = 1;

  i = 0;
  while(i < n){
    m = pickup(a[i][1], a, tmp, n);
    m = pickup(a[i][1], org, tmp_or, n);
    for(j = 0; j < m; j++){
      if(tmp[j] != tmp_or[j]){
        flag = 0;
      }
    }
    i += m;
  }

  return flag;
}


int main(){
  int n, i, j, minj;

  cin>>n;
  char origin[n][3];
  char bbl[n][3];
  char slc[n][3];
  for(i = 0; i < n; i++){
    cin>>origin[i];
    copy_ary(bbl[i], origin[i], 3);
    copy_ary(slc[i], origin[i], 3);
  }


//----------------------------------bubble
  int flag = 1;
  while(flag){
    flag = 0;
    for(i = n-1; i > 0; i--){
      if(bbl[i][1] < bbl[i-1][1]){
        exchange(bbl[i], bbl[i-1], 3);
        flag = 1;
      }
    }
  }

//----------------------------------seleciton sort
  for(i = 0; i < n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(slc[j][1] < slc[minj][1]){
        minj = j;
      }
    }
    if(i != minj){
      exchange(slc[i], slc[minj], 3);
    }
  }

//-------------------------------------------------

  for(i = 0; i < n-1; i++){
    cout<<bbl[i]<<" ";
  }
  cout<<bbl[n-1]<<endl;
  if(check_stable(origin, bbl, n)){
    cout<<"Stable"<<endl;
  }else{
    cout<<"Not stable"<<endl;
  }


  for(i = 0; i < n-1; i++){
    cout<<slc[i]<<" ";
  }
  cout<<slc[n-1]<<endl;
  if(check_stable(origin, slc, n)){
    cout<<"Stable"<<endl;
  }else{
    cout<<"Not stable"<<endl;
  }


}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <numeric>
#include <unistd.h>

typedef long long ll;
using namespace std;

int main(){
	int a;
	cin >> a;
	if(a%2==0){
		cout << a*a/4 <<endl;
	}
	else{
		cout << (a*a-1)/4<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d%d", $n,$x);
  $l = explode(" ",trim(fgets(STDIN)));
  $jump = 0;
  $count = 1;
  for($i=0; $i<$n; $i++){
      $jump += $l[$i];
      if($jump <= $x) $count++;
  }
  echo $count;

Measured memory_bytes: 4728
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy

ans = ""
ans += "U" * dy
ans += "R" * dx
ans += "D" * dy
ans += "L" * (1 + dx)
ans += "U" * (1 + dy)
ans += "R" * (1 + dx)
ans += "DR"
ans += "D" * (1 + dy)
ans += "L" * (1 + dx)
ans += "U"
print(ans)


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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,q;
string s;
vint l,r;

int main(){
  cin >> n >> q;
  s.resize(n);l.resize(q);r.resize(q);
  cin >> s;
  rep(i,q) cin >> l[i] >> r[i];
  
  vint sigma(n,0);
  for(int i=1;i<n;++i){
    if(s[i-1]=='A'&&s[i]=='C') sigma[i]=sigma[i-1]+1;
    else sigma[i]=sigma[i-1];
  }

  rep(i,q){
    cout << sigma[r[i]-1]-sigma[l[i]-1] << endl;
  }
  return 0;
}



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

int main(){
  int X;
  scanf("%d", &X);

  int cnt=1;

  for(int n=2; n<X; n++){
    for(int i=2; i<X; i++){
      int p=pow(n,i);
      if(p<=X){
	if(cnt<p){
	  cnt=p;
	}
      }else{
	break;
      }
    }
  }

  printf("%d\n",cnt);

  return 0;
}

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

int N, T;

int main() {
    cin >> N >> T;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int mn = A[0];
    int profit = 0, cnt = 0;
    for (int i = 1; i < N; i++) {
        if (A[i] < mn) {
            mn = A[i];
        }
        
        if (profit == A[i] - mn) {
            cnt++;
        } else if (profit < A[i] - mn) {
            cnt = 1;
            profit = A[i] - mn;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 768
#coding utf-8
N=int(input())
A=list(map(int,input().split())) 
B=list(map(int,input().split())) 
C=list(map(int,input().split())) 
ans=0
ans +=sum(B)
for i in range(N-1):
  if A[i]+1==A[i+1]:
    ans +=C[A[i]-1]
print(ans)


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

using namespace std;

int W, H;
vector<string> m;
vector<string> m2;

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

void paint(int x, int y, char c) {
	if (x < 0 || x >= W || y < 0 || y >= H) return;

	char c2 = c-'A'+'a';
	if (m[y][x] == '.') {
		m[y][x] = c2;
	}
	else if (m[y][x] == 'W' || m[y][x] == 'B') return;
	else if (m[y][x] == '#') return;
	else if (m[y][x] == c2) return;
	else m[y][x] = '#';

	for (int d = 0; d < 4; ++d) {
		paint(x+dx[d], y+dy[d], c);
	}
}

int main() {
	while ( cin >> W >> H, W || H ) {
		m.resize(H);
		for (int y = 0; y < H; ++y) {
			cin >> m[y];
		}
		for (int y = 0; y < H; ++y) {
			for (int x = 0; x < W; ++x) {
				if (m[y][x] == 'W' || m[y][x] == 'B') {
					for (int d = 0; d < 4; ++d) {
						paint(x+dx[d], y+dy[d], m[y][x]);
					}
				}
			}
		}
		int w = 0, b = 0;
		for (int y = 0; y < H; ++y) {
			for (int x = 0; x < W; ++x) {
				if (m[y][x] == 'w') ++w;
				if (m[y][x] == 'b') ++b;
			}
		}
		cout << b << " " << w << endl;
	}
}

Measured memory_bytes: 1312
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

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

  int x = a[0];
  for(int i = 1; i < n; i++){
    x = a[i] - x;
  }
  x = x / 2;

  int ans[n];
  ans[0] = 2 * x;
  for(int i = 1; i < n; i++){
    ans[i] = 2 * (a[i - 1] - x);
    x = a[i - 1] - x;
  }

  string buf;
  for(int i = 0; i < n; i++){
    buf += to_string(ans[i]) + " ";
  }

  cout << buf << endl;

  return 0;
}


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N, L;
vector<int> a;

int main()
{
    cin >> N >> L;
    a.resize(N);
    cin >> a;

    int pos = -1;
    REP(i, N - 1) if (a[i] + a[i + 1] >= L) pos = i;
    if (pos < 0) puts("Impossible");
    else
    {
        puts("Possible");
        REP(i, pos) printf("%d\n", i + 1);
        IFOR(i, pos, N - 1) printf("%d\n", i + 1);
    }
}


Measured memory_bytes: 1280
n,m=(int(i) for i in input().split())
#print(n,m)

mod=10**9+7
ans=1

if abs(n-m) > 1:
  print(0)
elif n==m:
  for i in range(n,0,-1):
    ans=ans%mod
    ans*=i
  for i in range(m,0,-1):
    ans=ans%mod
    ans*=i
  ans=ans*2%mod
  print(ans%mod)
else:
  for i in range(n,0,-1):
    ans=ans%mod
    ans*=i
  for i in range(m,0,-1):
    ans=ans%mod
    ans*=i
  print(ans%mod)
    


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

double ev[305][305][305], p[305][305][305];

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

    vector<int> cnt(4,0);

    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;

        cnt[x]++;
    }   

    p[cnt[1]][cnt[2]][cnt[3]] = 1;

    for(int c=n; c >= 0; c--)
    {
        for(int b=n; b >= 0; b--)
        {
            for(int a=n; a >= 0; a--)
            {
                if(a==0 && b==0 && c==0)
                    continue;

                if(a+b+c > n)
                    continue;

                double p_waste = (double)(n - (a+b+c))/n;
                double ev_waste = (double)p_waste/(1 - p_waste);

                //debug() << imie(a) imie(b) imie(c) imie(ev_waste);

                ev[a][b][c] += ev_waste*p[a][b][c];

                if(a != 0)
                {
                    double p_go = (double)a/(a+b+c);
                    p[a-1][b][c] += p[a][b][c]*p_go;
                    ev[a-1][b][c] += ev[a][b][c]*p_go;
                }

                if(b != 0)
                {
                    double p_go = (double)b/(a+b+c);
                    p[a+1][b-1][c] += p[a][b][c]*p_go;
                    ev[a+1][b-1][c] += ev[a][b][c]*p_go;
                }

                if(c != 0)
                {
                    double p_go = (double)c/(a+b+c);
                    p[a][b+1][c-1] += p[a][b][c]*p_go;
                    ev[a][b+1][c-1] += ev[a][b][c]*p_go;
                }
            }
        }
    }

    cout<<fixed<<setprecision(10)<<ev[0][0][0] + cnt[1] + 2*cnt[2] + 3*cnt[3]<<endl;
}


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


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

    string w;
    cin >> w;
    sort(w.begin(),w.end());
    string ans="Yes";
    int s=w.size();
    if(s%2!=0) ans="No";
    else {
        rep(i,s/2){
            if(w.at(2*i)!=w.at(2*i+1)) ans="No";
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// get a integer
		int a = sc.nextInt();
		// get two integers separated with half-width break
		int b = sc.nextInt();
		int h = sc.nextInt();
		System.out.println((a+b)*h/2);
	}
}

Measured memory_bytes: 8916
n = input()
a = map(int, raw_input().split())
oo = sum(a) + 1

dp_max = [[-oo] * n for _ in range(n)]
dp_min = [[oo] * n for _ in range(n)]

for i in range(n):
    dp_max[i][i] = a[i]
    dp_min[i][i] = -a[i]

for i in range(1, n):
    for j in range(n - i):
        k = i + j
        dp_max[j][k] = max(dp_min[j + 1][k] + a[j], dp_min[j][k - 1] + a[k])
        dp_min[j][k] = min(dp_max[j + 1][k] - a[j], dp_max[j][k - 1] - a[k])
print(dp_max[0][n - 1])


Measured memory_bytes: 174108
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int x = sc.nextInt();
    int a[] = new int[N];
    for(int i=0;i<N;i++){
      a[i]=sc.nextInt();
    }
    Arrays.sort(a);
    int ans=0;
    for(int i=0;i<N-1;i++){
      if(x>=a[i]){
        ans++;
        x=x-a[i];
      }
    }
    if(x==a[N-1])ans++;
    System.out.println(ans);

  }
  

  
}


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

template<typename T>
struct Segtree {
    int n;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.resize(2*n-1, e);
    }

    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k){
        return dat[k+n-1];
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

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

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){
        return sz[find(x)];
    }
};

int main(){
    int N;
    int64_t D;
    cin >> N >> D;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    typedef pair<int64_t, int> P;
    P INFP = {1e18, -1};
    Segtree<P> stL(N, [](auto a, auto b){ return min(a, b); }, INFP);
    Segtree<P> stR(N, [](auto a, auto b){ return min(a, b); }, INFP);

    vector<int> order(N);
    for(int i=0; i<N; i++) order[i] = i;
    sort(order.begin(), order.end(), [&](int i, int j){ return A[i] < A[j]; });
    vector<vector<int64_t>> edges;

    for(int i : order){
        int j = stL.between(0, i-1).second;
        if(j != -1){
            int64_t c = abs(i-j)*D + A[i] + A[j];
            edges.push_back({c, i, j});
        }
        j = stR.between(i+1, N-1).second;
        if(j != -1){
            int64_t c = abs(i-j)*D + A[i] + A[j];
            edges.push_back({c, i, j});
        }
        stL.update(i, {A[i]-D*i, i});
        stR.update(i, {A[i]+D*i, i});
    }

    sort(edges.begin(), edges.end());
    UnionFind uf(N);
    int64_t ans = 0;
    for(auto& e : edges){
        int64_t c = e[0], i = e[1], j = e[2];
        if(uf.unite(i, j)) ans += c;
    }
    cout << ans << endl;
    return 0;
}

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

set<int> divisor(int n) {
    set<int> ret;
    for (auto i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.insert(i);
            if(n % (n / i) == 0) ret.insert(n / i);
        }
    }
    return ret;
}

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

    int g = 0;
    for (auto i = 0; i < n; i++) {
        int a; cin >> a;
        if(i == 0) g = a;
        else g = __gcd(g, a);
    }

    auto d = divisor(g);
    for (auto & elm : d) cout << elm << endl;

    return 0;
}


Measured memory_bytes: 3096
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = GetNumbers();

            var operate = string.Empty;

            if (nums[0] < nums[1])
            {
                operate = "<";
            }
            else if (nums[0] > nums[1])
            {
                operate = ">";
            }
            else
            {
                operate = "==";
            }

            Console.WriteLine(string.Format("a {0} b", operate));
        }

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static List<int> GetNumbers()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
        }

        static List<string> GetStrings()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
        }
    }
}

Measured memory_bytes: 10048
from itertools import groupby
def ceil(x, y):
  return (x -1) // y + 1

input()
li = list(map(int, input().split()))
lii = []
for itr, val in enumerate(li):
  if itr + 1 == val:
    lii.append(True)
  else:
    lii.append(False)
gbli = [[key, len(list(group))] for key, group in groupby(lii)]

ans = 0
for i,j in gbli:
  if i == True:
    ans += ceil(j, 2)
print(ans)



Measured memory_bytes: 65004
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 最大はスター　0から(N-1)C2まで可能
N, K = lr()
max = (N-1) * (N-2) // 2
if K > max:
    print(-1)
    exit()
minus = max - K
print(N - 1 + minus) # 辺の数
# 1を中心とする
for i in range(2, N+1):
    print(1, i)

leaf_com = []
for x in itertools.combinations(range(2, N+1), 2):
    leaf_com.append(x)

for i in range(minus):
    u, v = leaf_com[i]
    print(u, v)

# 38

Measured memory_bytes: 3992
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        int element;
        cin>>element;
    }
    cout<<ceil(((n-1)*1.0)/(--k));
}

Measured memory_bytes: 3768
import itertools
import numpy as np

C = np.zeros((3, 3), dtype=int)

C[0][0], C[0][1], C[0][2] = map(int, input().split())
C[1][0], C[1][1], C[1][2] = map(int, input().split())
C[2][0], C[2][1], C[2][2] = map(int, input().split())

# print(C)

for x in range(3):
    for y in range(3):
        if not ((C[x][0] - C[y][0]) == (C[x][1] - C[y][1]) and \
            (C[x][0] - C[y][0]) == (C[x][2] - C[y][2])):
            print('No')
            exit(0)

for x in range(3):
    for y in range(3):
        if not ((C[0][x] - C[0][y]) == (C[1][x] - C[1][y]) and \
            (C[0][x] - C[0][y]) == (C[2][x] - C[2][y])):
            print('No')
            exit(0)

print('Yes')

        


Measured memory_bytes: 17976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N), b(N);
    ll suma=0,sumb=0;
    rep(i,N){
        cin >> a[i];
        suma += a[i];
    }
    rep(i,N){
        cin >> b[i];
        sumb += b[i];
    }
    ll nop = sumb - suma;
    if(nop < 0){
        cout << "No" <<endl;
        return 0;
    }
    ll cnt=0;
    /*rep(i,N){
        cnt += max(0LL, a[i]-b[i]);
    }
    ll ta = cnt*2;*/
    rep(i,N){
        cnt += max(0LL, (b[i]-a[i]+1)/2);
    }
    if(cnt <= nop){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    int p[N];
    int m=0,sum=0;
    rep(i,N){
        cin >> p[i];
        sum+=p[i];
        m=max(m,p[i]);
    }
    cout << sum-m/2 << endl;




}


Measured memory_bytes: 256
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

res = 0
while sum(a):
    res += 1
    f = False
    for i in range(n):
        if a[i] > 0:
            a[i] -= 1
            f = True
        elif f is True:
            break

print(res)

Measured memory_bytes: 3064
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N = 0;
    cin >> N;

    //本文
    ll  ans = 0;
    ll RN = sqrt(N);
    ll A = 0;
    for(ll i = 1; i<=RN;i++){
      if(N%i==0){
        A = i;
      }
    }
    ll B = N/A;

    ll Ac = 0, Bc = 0;
    Ac = to_string(A).size();
    Bc = to_string(B).size();
    ans = max(Ac,Bc);



    //出力
    cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3756
#include<cstdio>

int n,a,b,c,x;
int y[101];
int main(void){
	while(1){
		scanf("%d %d %d %d %d",&n,&a,&b,&c,&x);
		if(n+a+b+c+x==0)break;
		for(int i=0;i<n;i++){
			scanf("%d",&y[i]);
		}
		int cnt=0,j=0;
		while(j<n && cnt<=10000){
			if(x==y[j])j++;
			if(j<n)cnt++;
			x=(a*x+b)%c;
		}
		printf("%d\n",cnt<=10000?cnt:-1);
	}
	return 0;
}

Measured memory_bytes: 1028
from math import log2
n,x,m = map(int, input().split())

logn = int(log2(n))+1
db = [[0]*m for _ in range(logn)]
dbs = [[0]*m for _ in range(logn)]

for i in range(m):
    db[0][i] = (i**2)%m
    dbs[0][i] = (i**2)%m

for i in range(logn-1):
    for j in range(m):
        db[i+1][j] = db[i][db[i][j]]
        dbs[i+1][j] = dbs[i][db[i][j]] + dbs[i][j]


ans = x
now = x
for i in range(logn):
    if (n-1)&(1<<i) > 0:
        ans += dbs[i][now]
        now = db[i][now]

print(ans)

Measured memory_bytes: 119760
#include <bits/stdc++.h>
#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(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b;
  cin >> a >> b;
  if(a>0&&b>0) cout << "Positive" << endl;
  else if((ll)a*b<=0) cout << "Zero" << endl;
  else{
    a *= -1;
    b *= -1;
    cout << (((ll)a-b+1)%2==0 ? "Positive" : "Negative") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < n; i++) 

using namespace std;

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

const ll MOD = 1e9 + 7;

int main() {
  int n; scanf("%d", &n);
  ll a[n];
  FOR(i, n) scanf("%lld", a + i);
  int xd[100]; FOR(i, 60) xd[i] = 0;
  FOR(i, n) {
    FOR(k, 60) {
      if (a[i] & (1LL << k)) xd[k]++;
    }
  }
  ll sum = 0;
  FOR(k, 60) {
    sum += ((1LL << k) % MOD) * ((ll)xd[k] * (n - xd[k]) % MOD) % MOD;
    sum %= MOD;
  }
  sum += MOD;
  sum %= MOD;
  printf("%d\n", (int) sum);
  return 0;
}


Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <list>
using namespace std;

int main() {
	list<int> l;
	int q; scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		char s[20];
		scanf("%s", s);
		if (s[0] == 'i') {
			int x; scanf("%d", &x);
			l.push_front(x);
		}
		else if (s[6] == 'F')l.pop_front();
		else if (s[6] == 'L')l.pop_back();
		else{
			int x; scanf("%d", &x);
			auto it = l.begin();
			while (it != l.end()) {
				if (*it == x) { l.erase(it); break; }
				it++;
			}
		}
	}

	if (!l.empty()) {
		printf("%d", l.front());
		auto it = l.begin(); it++;
		while (it != l.end()) {
			printf(" %d", *it);
			it++;
		}
	}
	puts("");
}


Measured memory_bytes: 33900
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  cin >> n;
  ll t[n],a[n];
  for(ll i=0;i<n;i++) cin >>t[i]>>a[i];
  ll ans1=t[0],ans=a[0];
  for(ll i=0;i<n-1;i++){
    ll k=t[i+1],l=a[i+1];
    if(k<ans1||l<ans) {
      ll p=ans1/t[i+1],q=ans/a[i+1];
      if(ans1%t[i+1]!=0) p++;
      if(ans%a[i+1]!=0) q++;
      ans1=max(p,q)*t[i+1];
      ans=max(p,q)*a[i+1];
    }
    else {
      ans1=t[i+1];
      ans=a[i+1];
    }
   }
   cout <<ans1+ans<<endl;
   return 0;
  }


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	i64 n, m;
	cin >> n >> m;
	i64 ans = 0;
	if (n > m / 2) {
		ans += m / 2;
	}
	else {
		ans += n;
		m -= n * 2;
		ans += m / 4;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
ll m_max = 40;
vector<ll> tfs;
vector<ll> tf(ll r){
	ll cur = 0;
	vector<ll> res;
	for(int i=0;i<tfs.size();i++){
		if(cur<=r){
			res.pb(1);
			cur += tfs[i];
		}
		else{
			res.pb(-1);
			cur -= tfs[i];
		}
	}
	reverse(res.begin(),res.end());
	return res;
}
int main(){
	ll n;
	cin>>n;
	vector<ll> x,y;
	for(int i=0;i<n;i++){
		ll tx,ty;
		cin>>tx>>ty;
		x.pb(tx);
		y.pb(ty);
		if( (abs(tx+ty)) % 2 != (abs(x[0]+y[0])) %2){
			cout<<-1<<endl;
			return 0;
		}
	}
	if( (abs(x[0]+y[0])) % 2 == 0){
		cout<<m_max<<endl;
		cout<<1<<" ";
		tfs.pb(1);
		ll cur = 1;
		for(int i=1;i<=m_max-1;i++){
			cout<<cur<<" ";
			tfs.pb(cur);
			cur = cur*2;
		}
		cout<<endl;
	}
	else{
		cout<<m_max<<endl;
		ll cur = 1;
		for(int i=1;i<=m_max;i++){
			cout<<cur<<" ";
			tfs.pb(cur);
			cur = cur * 2;
		}
		cout<<endl;
	}
	reverse(tfs.begin(),tfs.end());
	for(int i=0;i<n;i++){
		vector<ll> xp,yp;
		xp = tf(x[i]-y[i]);
		yp = tf(x[i]+y[i]);
		for(int j=0;j<=39;j++){
			if(xp[j]==1 && yp[j]==1){
				cout<<"R";
			}
			if(xp[j]==-1 && yp[j]==-1){
				cout<<"L";
			}
			if(xp[j]==-1 && yp[j]==1){
				cout<<"U";
			}
			if(xp[j]==1 && yp[j]==-1){
				cout<<"D";
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int	main(void)
{
  	int	N;
  	int	M;
  	int num;
  
  	num = scanf("%d %d", &N, &M);
  	if (num != 2)
      	return (0);
  
  	if (N == M)
      	printf("Yes");
  	else
      	printf("No");
  
  	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS  = 1e-10;
const bool debug = 0;
//---------------------------//

int N,A,B,C,D;
vector<int> a;
double ans = -INF;

int main(){
	cin >> N;
	a.resize(N);
  REP(i,N)cin >> a[i];
  sort(a.begin(),a.end());
  
  REP(i, N) {
  	FOR(j, i + 1, N) {
  		C = a[j]; D= a[i];
  		
  		int p = N - 1;
  		while (i == p || j == p) p--;
  		A = a[p]; p--;
  		
  		while (i == p || j == p) p--;
  		B = a[p];
  		
  		chmax(ans, (double)(A+B)/(C-D));
		}
  }
  
  printf("%.10f\n",ans);
	return 0;
}

Measured memory_bytes: 3268
#include <iostream>

using namespace std;

int main()
{
	int n, C1 = 0, C2 = 0, C3 = 0, C4 = 0;
	cin>>n;
	string o;
	for ( int i = 0; i < n ; i++ )
     {
          cin>>o;
          if ( o == "AC" )
               C1 += 1;
          else if ( o == "WA" )
               C2 += 1;
          else if ( o == "TLE" )
               C3 += 1;
          else if ( o == "RE" )
               C4 += 1;
     }
     cout<<"AC x "<<C1<<endl;
     cout<<"WA x "<<C2<<endl;
     cout<<"TLE x "<<C3<<endl;
     cout<<"RE x "<<C4<<endl;
    return 0;
}


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

int main(void){
  int n;
  cin >> n;
  string s[n];
  for(int i = 0; i < n; i++) cin >> s[i];
  int a[n][26], b[26];
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 26; j++){
      a[i][j] = 0;
    }
  }
  for(int i = 0; i < 26; i++) b[i] = 0;

  int temp;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < s[i].length(); j++){
      temp = s[i][j] - 'a';
      a[i][temp]++;
    }
  }
  for(int i = 0; i < 26; i++){
    temp = 100;
    for(int j = 0; j < n; j++){
      temp = min(temp, a[j][i]);
    }
    b[i] = temp;
  }

  string ans = "";
  for(int i = 0; i < 26; i++){
    temp = b[i];
    string str(temp, 'a' + i);
    ans += str;
  }
  
  cout << ans << endl;
  return 0;
}


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

int main() {
	string S,f="",l="";
	int Q,T,F,x = 0;
	char C;

	cin >> S >> Q;
	rep(i,Q) {
		cin >> T;
		if(T == 1)
			x++;
		else {
			cin >> F >> C;
			if((x+F)%2)
				f += C;
			else
				l += C;
		}
	}

	reverse(f.begin(), f.end());
	f += S+l;
	if(x%2)
		reverse(f.begin(), f.end());
	cout << f << endl;
}

Measured memory_bytes: 1348
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

h,w = map(int,input().split())
n = int(input())
A = list(map(int,input().split()))
C = [[0] * w for i in range(h)]
color = 0
for i in range(h):
  if i % 2 == 0:
    for j in range(w):
      C[i][j] = color + 1
      A[color] -= 1
      if A[color] == 0:color += 1
  else:
    for j in range(w-1,-1,-1):
      C[i][j] = color + 1
      A[color] -= 1
      if A[color] == 0:color += 1
for ci in C:
  print(*ci)


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

typedef pair<ll, ll> P;

vector<P> rl[400400];
vector<P> ud[400400];
vector<P> lu[400400];
vector<P> ld[400400];
vector<P> ru[400400];
vector<P> rd[400400];

ll calc(vector<P>& vec) {
    ll ans = 1e18;
    sort(vec.begin(), vec.end());
    for (int i = 0; i + 1 < vec.size(); i++) {
        if(vec[i].second == 0 && vec[i+1].second == 1){
            ans = min(ans, (vec[i + 1].first - vec[i].first) * 5);
        }
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        ll x, y;
        char u;
        cin >> x >> y >> u;
        if (u == 'R') {
            rl[y].emplace_back(x, 0);
            rd[x - y + 200000].emplace_back(x + y, 0);
            ru[x + y].emplace_back(x - y, 0);
        }
        if (u == 'L') {
            rl[y].emplace_back(x, 1);
            ld[x + y].emplace_back(x - y, 1);
            lu[x - y + 200000].emplace_back(x + y, 1);
        }
        if (u == 'U') {
            ud[x].emplace_back(y, 0);
            lu[x - y + 200000].emplace_back(x + y, 0);
            ru[x + y].emplace_back(x - y, 1);
        }
        if (u == 'D') {
            ud[x].emplace_back(y, 1);
            ld[x + y].emplace_back(x - y, 0);
            rd[x - y + 200000].emplace_back(x + y, 1);
        }
    }
    ll ans = 1e18;
    rep(i, 400001) {
        ans = min(ans, calc(lu[i]));
        ans = min(ans, calc(ld[i]));
        ans = min(ans, calc(ru[i]));
        ans = min(ans, calc(rd[i]));
        ans = min(ans, calc(rl[i]));
        ans = min(ans, calc(ud[i]));
    }
    if (ans == 1e18)
        puts("SAFE");
    else
        cout << ans << endl;
}

Measured memory_bytes: 78256
// 以下のソースを勉強する.
// zscoder氏.
// https://atcoder.jp/contests/dp/submissions/3938025
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL dp[111][111111];

int main(){
    
    // 1. 入力情報取得.
    vector<pair<LL, LL>> vec;
    int N;
    LL W;
    scanf("%d %lld", &N, &W);
    vec.push_back(make_pair(-1, -1));
    for(int i = 0; i < N ; i++){
        LL x, y;
        scanf("%lld %lld", &x, &y);
        vec.push_back(make_pair(x, y));
    }
    
    // 2. dp更新.
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= W; j++){
            dp[i][j] = dp[i - 1][j];
            if(j - vec[i].first >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - vec[i].first] + vec[i].second);
        }
    }
    // for(int i = 0; i <= N; ++i){
    //     for(int j = 0; j <= W; j++) printf("dp[%d][%d]=%lld ", i, j, dp[i][j]);
    //     printf("\n");
    // }
    
    // 3. 出力.
    LL ans = 0;
    for(int j = 0; j <= W; j++) ans = max(ans, dp[N][j]);
    printf("%lld\n", ans);
    return 0;
}

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


int main(){
int a,b,c;
char d,e;
cin >> a >>d >> b >> e >> c;
if(b>4) cout << "TBD" << endl;
else cout << "Heisei" << endl;
}

Measured memory_bytes: 256
//    _____                   _                       _
//   / ____|                 | |                     (_)
//  | (___   ___  _ __     __| | ___ _ __    ______ _ _
//   \___ \ / _ \| '_ \   / _` |/ _ \ '_ \  |_  / _` | |
//   ____) | (_) | | | | | (_| |  __/ |_) |  / / (_| | |
//  |_____/ \___/|_| |_|  \__,_|\___| .__/  /___\__,_|_|
//                                  | |
//                                  |_|
 
#include <bits/stdc++.h>
#define nmax 100005
#define oo 10000000007
#define mod 1000000007
#define reset(x) memset(x, 0, sizeof x)
#define F first
#define S second
#define sonin cin
#define sonout cout
#define debug(x) cout << "Loli -> " << #x << " : " << x << "\n"
#define debugAry(x, a, b, y) for(int y = a; y<=b; y++) cout << #x << "[" << y << "]" << " -> " << x[y] << "\n"
#define filename ""
#define fileNX freopen(filename".inp", "r", stdin); freopen(filename".out", "w", stdout);
#define fileN freopen(filename".inp", "r", stdin);
#define fileX freopen(filename".out", "w", stdout);
#define toiuuhoa ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(a) (int) a.size()
#define FOU(x,a,b) for (lli x=a;x<=b;x++)
#define FOD(x,a,b) for (lli x=a;x>=b;x--)
#define FOA(a,b) for(auto &a:b)
#define ALLvec(a) a.begin(),a.end()
#define REU(x,a,b) for (lli x=a;x<b;x++)
#define RED(x,a,b) for (lli x=a;x>b;x--)
#define AutoCinAry(a,b,x) for(int a = 1; a<=b; a++) cin >> x[i];
#define dembit1(x) __builtin_popcount(x)
#define bit(x,i) ((x>>(i-1))&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
#define EL cout << "\n";
#define EX exit(0);
#define Ary(x, i, j, a) x[(i - 1) * a + j]
#define epsinon 1e-8
#define Son_onii_chan main
#define times double stime = clock();
#define gettime cerr << "Time executed: " << (clock() - stime) / CLOCKS_PER_SEC * 1000 << "ms.\n";
using namespace std;
typedef long long lli;
typedef long double ldo;
typedef double dou;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
typedef vector<pii> vpi;
typedef deque<lli> dqll;
 
lli a,b,c,d;
int Son_onii_chan(){
    //fileNX
    toiuuhoa
    sonin >> a >> b >> c >> d;
  	lli res = max({a*c, b*d, a*d, b*c});
  	sonout << res;
	return 0;
}

Measured memory_bytes: 3644