akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = 10000000;
const long long INFL = (1LL<<50);
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

const int MAX=100005;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX];

void binom_init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; ////  inv[i] = div(1,i) =  (1/i) mod M;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long binom(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int v[MAX];

int main() {
    int n;cin>>n;
    vector<int> a(n+1);cin>>a;
    int s,g;
    g = -1;s = -1;
    rep(i,MAX)v[i] = -1;
    rep(i,n+1){
        if(v[a[i]] != -1) {s = v[a[i]]; g = i;}
        v[a[i]] = i;
    }
    
    int dist = g-s+1;
    
    binom_init();
    
    rep(k,n+1){
        cout<<(MOD+binom(n+1,k+1) - binom(n+1-dist,k))%MOD<<endl;
    }
    
    return 0;
}












Measured memory_bytes: 4352
N = int(input()) % 10
l1 = [2, 4, 5, 7, 9]
l2 = [0, 1, 6, 8]
l3 = [3]
 
if N in l1:
    print("hon")
elif N in l2:
  print('pon')
else:
  print('bon')

Measured memory_bytes: 9060
#include <iostream>

int main()
{
    int n, y;
    std::cin >> n >> y;

    bool is_ok = false;
    int a = -1, b = -1, c = -1;
    for (int ii = 0; ii <= n; ++ii)
    {
        for (int jj = 0; jj <= n - ii; ++jj)
        {
            int kk = n - ii - jj;
            if (ii * 10000 + jj * 5000 + kk * 1000 == y)
            {
                is_ok = true;
                a = ii, b = jj, c = kk;
                break;
            }
        }
        if (is_ok)
        {
            break;
        }
    }

    std::cout << a << " " << b << " " << c;
}


Measured memory_bytes: 256
N = int(input())
A = []
B = []
for i in range(N):
	a,b = map(int,input().split())
	A.append(a)
	B.append(b)
A.sort()
B.sort()
m_l = A[N//2] if N % 2 == 1 else A[N//2-1] + A[N//2]
m_r = B[N//2] if N % 2 == 1 else B[N//2-1] + B[N//2]
print(m_r - m_l + 1)

Measured memory_bytes: 25532
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int countr = 0;
		int countg = 0;
		int countb = 0;
		long sum = 0;
		for(int i=0;i<n;i++){
			if((int)s.charAt(i)==(int)'R'){
				countr++;
			}
			if((int)s.charAt(i)==(int)'G'){
				countg++;
			}
			if((int)s.charAt(i)==(int)'B'){
				countb++;
			}
		}
		sum = (long)countr * (long)countg * (long)countb;
		long countx = 0;
		for(int i=0;i<n;i++){
			for(int j=1;j<n;j++){
				if(i+2*j>=n){
					break;
				}
				int left = (int)s.charAt(i);
				int center = (int)s.charAt(i+j);
				int right = (int)s.charAt(i+2*j);
				if(left!=center && center!=right && left!=right){
					countx++;
				}
			}
		}
		System.out.println(sum - countx);
	}
}

Measured memory_bytes: 36908
#include <iostream>
#include <cstdio>
 
using namespace std;
 
int main()
{
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      printf("%dx%d=%d\n",i,j,i*j);
    }
  }
  return 0;
}

Measured memory_bytes: 1092
package main

import "fmt"

func main() {
  var n, m int
  fmt.Scan(&n, &m)
  f := make([]int, m)
  for i := 0; i < n; i++ {
    var k int
    fmt.Scan(&k)
    a := make([]int, k)
    for i := 0; i < k; i++ {
      fmt.Scan(&a[i])
      f[a[i]-1]++
    }
  }
  var count int
  for _, v := range f {
    if v == n {
      count++
    }
  }
  fmt.Println(count)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else 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;
}

int main()
{
	int p[100001],q,l,r;
	cin >> q;
	rep(i,100001){
		p[i]=0;
		if(IsPrime(i) && IsPrime((i+1)/2)) p[i]++;
		if(i!=0) p[i]+=p[i-1];
	}
	rep(i,q){
		cin >> l >> r;
		if(l==0) l=1;
		cout << p[r]-p[l-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a;
  int ans=0;
  std::cin >> a;
  for (int i = 0; i < 4; i++) {
    /* code */
    if(a[i]=='+')ans++;
    else ans--;
  }
  std::cout << ans << std::endl;
}

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

using namespace std;

int main(){
	int n, m; cin >> n >> m;
	priority_queue<int> q;
	for(int i = 0; i < n; i++){
		int act; cin >> act;
		q.push(act);
	}
	for(int i = 0; i < m; i++){
		int a = q.top();
		q.pop();
		q.push(a/2);
	}
	long long sum= 0;
	while(!q.empty()){
		sum+=q.top();
		q.pop();
	}
	cout << sum << '\n';
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    int n;
    cin >> n;
    vi p(n);
    int cnt = 0;
    rep (i, n) {
        cin >> p[i];
        p[i]--;
        if (p[i] != i) cnt++;
    }
    cout << (cnt <= 2 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1E+9 + 7;
using namespace std;

struct DP {
	uint64_t b = 0, w = 0;
};

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

	for (int i = 0, j = S.length(); i < j; i += 2) {
		if (S[i] == 'B') S[i] = 'W';
		else S[i] = 'B';
	}
	uint64_t ans = 1;
	for (int i = 2; i <= N; i++) {
		ans *= i;
		ans %= MOD;
	}
	int tmp = 0;
	rep(i, 2 * N) {
			if (S[i] == 'W') tmp++;
			else {
				if (!tmp) {
					cout << 0 << endl;
					return 0;
				}
				ans *= tmp;
				ans %= MOD;
				tmp--;
			}
	}
	if (tmp) {
		cout << 0 << endl;
		return 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
# from collections import defaultdict
def main():
    N, M = map( int, input().split())
    d = dict()
    for _ in range(M):
        a, b, c = map( int, input().split())
        a, b = a-1, b-1
        d[(a,b)] = -c
    INF = 10**14
    V = [INF]*N
    V[0] = 0
    for _ in range(N-1):
        for e in d:
            s, t = e
            if V[s] + d[e] < V[t]:
                V[t] = V[s] + d[e]
    ans = V[N-1]
    for _ in range(N):
        for e in d:
            s, t = e
            if V[s] + d[e] < V[t]:
                V[t] = V[s] + d[e]
    if ans == V[N-1]:
        print(-ans)
    else:
        print("inf")
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 41072
#include <stdio.h>

int main() {
  int n;
  scanf("%d",&n);
  if (n == 1) {
    printf("Hello World\n");
  }
  if (n == 2) {
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d\n",a+b);
  }
  return 0;
}


Measured memory_bytes: 128
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  vector<int> a = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  cin >> A;
  sort(all(A));
  reverse(all(A));
  int mi = INF;
  for (int ele : A) { chmin(mi, a[ele]); }
  vector<int> dp(N + 1, -INF);
  dp[0] = 0;
  for (int i = 1; i <= N; i++) {
    for (int j : A) {
      if (i - a[j] >= 0) chmax(dp[i], dp[i - a[j]] + 1);
    }
  }
  int cur = N;
  vector<int> ans;
  for (int i = 0; i < dp[N]; i++) {
    for (int j : A) {
      if (cur - a[j] >= 0 && dp[cur - a[j]] == dp[cur] - 1) {
        ans.push_back(j);
        cur -= a[j];
        break;
      }
    }
  }
  for (int i = 0; i < ans.size(); i++) cout << ans[i];
  cout << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 384
using System;

namespace ABC059_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = Console.ReadLine();
            var B = Console.ReadLine();

            if (A.Length == B.Length)
            {
                if (A == B) { Console.WriteLine("EQUAL"); }
                else
                {
                    for (var i = 0; i < A.Length; i++)
                    {
                        var x = int.Parse(A.Substring(i, 1));
                        var y = int.Parse(B.Substring(i, 1));
                        if (x > y) { Console.WriteLine("GREATER"); break; }
                        else if (x < y) { Console.WriteLine("LESS"); break; }
                        else continue;
                    }
                }
            }
            else if (A.Length > B.Length) { Console.WriteLine("GREATER"); }
            else { Console.WriteLine("LESS"); }
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
struct process_info_t {
	char name[11];
	int time;
	struct process_info_t *next;
};
typedef struct process_info_t ProcessInfo;

int main(void) {
	int num, qt, i, process, living_process;
	ProcessInfo rrs[100001], *p, *prev;

	scanf("%d %d ", &num, &qt);
	for (i = 0; i < num; i++) {
		scanf("%10s %d ", rrs[i].name, &rrs[i].time);
		rrs[i].next = &rrs[i+1];
	}
	rrs[num-1].next = &rrs[0];

	process = 0;
	living_process = num;
	prev = &rrs[num-1];
	for (p = &rrs[0];; p = p->next) {
		p->time -= qt;
		if (p->time > 0) {
			process += qt;
			prev = p;
		} else {
			process += qt + p->time;
			printf("%s %d\n", p->name, process);
			prev->next = p->next;
			if (--living_process <= 0)
				break;
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 100000000000

vector<ll> v[100001];

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

	ll N, M;

	cin >> N >> M;

	vector<P> city(M);
	ll P, Y;
	rep(i, M) {
		cin >> P >> Y;
		v[P].push_back(Y);
		city[i] = make_pair(P, Y);
	}

	rep(i, N+1) {
		if (v[i].size() != 0) {
			sort(ALL(v[i]));
		}
	}

	ll x = 0;
	rep(i, M) {
		P = city[i].first;
		Y = city[i].second;
		auto itr = lower_bound(ALL(v[P]), Y);
		x = itr - v[P].begin();
		cout << setfill('0') << std::right << std::setw(6) << P;
		cout << setfill('0') << std::right << std::setw(6) << x + 1;
		cout << "\n";
	}
	
	return 0;
}


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

const int inf = (1<<28);
const int N = 1000*1000;

vector<vector<int>> adj(N, vector<int>());
vector<int> memo(N, -1);

int dfs(int i) {
  if (memo[i] != -1) return memo[i];
  memo[i] = inf;
  int r = 1;
  for (auto it=adj[i].begin(); it!=adj[i].end(); it++)
    r = max(r, dfs(*it) + 1);
  return memo[i] = r;
}

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

  for (int i=0; i<n; i++) {
    for (int j=0, z=-1; j<n-1; j++) {
      int x; cin >> x; x--;
      if (z != -1) adj[min(i, z)*1000+max(i, z)].push_back(min(i, x)*1000+max(i, x));
      z = x;
    }
  }

  int r = -1;
  for (int i=0; i<N; i++)
    if (memo[i] == -1)
      r = max(r, dfs(i));

  cout << (r >= inf ? -1 : r) << endl;

  return 0;
}


Measured memory_bytes: 43392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}

void deb_p(pii p) { printf("pair = %d %d\n", p.fi, p.se); }
void deb_i(int i) { printf("i = %d\n", i); }
void deb_v(vector<int> v) {
  printf("v = ");
  for (auto i : v) printf("%d ", i);
  printf("\n");
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int x, a, b;
  cin >> x >> a >> b;
  if (b <= a)
    out("delicious");
  else if (abs(b - a) <= x)
    out("safe");
  else
    out("dangerous");
}
int main(void) { solve(); }


Measured memory_bytes: 3672
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s,t;
cin>>s>>t;
int co=0;
for(int i=0;i<3;i++)
    if(s[i]==t[i])
co++;
cout<<co<<endl;

}













Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=200000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,x;
ll a[N],s[N];

int main()
{
    n=read();x=read();
    rep(i,1,n) s[i]=s[i-1]+read();
    a[1]=5;
    rep(i,2,n) a[i]=i*2+1;
    db ans=1e100;
    rep(k,1,n)
    {
        db now=0;int j=1;
        //cout << "now " << k << endl;
        rep(i,1,(n-1)/k+1)
        {
            int r=n-(i-1)*k,l=r-k+1;l=max(1,l);
            //cout << l << " " << r << " " << j << endl;
            now+=a[i]*(s[r]-s[l-1]);j++;
        }
        now+=1ll*x*(n+k);
        ans=min(now,ans);
    }
    printf("%lld\n",(ll)ans);
    return 0;
}


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

using namespace std;

#define MAXN 1005
#define MAXH 10005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

int H, N, A[MAXH], B[MAXH], id;

ll dp[MAXN][MAXH], INF=1e9+5;

void print_table(){
    rep(i, N+1){
        rep(j, H+1){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

void solve(){
    rep(i, N+1) rep(j, H+1) dp[i][j] = INF;
    dp[0][0] = 0;

    // print_table();

    // cout << endl;

    rep(i, N){
        rep(j, H+1){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);    
            dp[i+1][min(j+A[i], H)] = min(dp[i+1][j] + B[i], dp[i+1][min(j+A[i], H)]);
        }
    }

    // print_table();
    // rep(i, N+1)
    //     cout << dp[i][H] << endl;

    cout << dp[N][H] << endl;
    }

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

    rep(i, N){
        cin >> A[i] >> B[i];
    }

    // rep(i, N+1)
    //     cout << A[i] << " " << B[i] << endl;
    solve();
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

ll n , k , q;
ll x[MAXX];
ll a[MAXX];

int main()
{
    _FastIO;
    cin >> n >> k >> q;
    ll s = 0;
    for(ll i = 0; i < q; i++){
        cin >> x[i];
        a[x[i]]++;
    }
    for(ll i = 1; i <= n; i++){
        if(k - (q - a[i]) > 0){
            cout << "Yes" << endl;
        }
        else
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
V<int> g;
V<bool> vis;
bool cc;
V<int> cir;
int siz;
int st;
void dfs(int cur,int last){
    if(last==cur)return;
   if(!vis[g[cur]]){
        vis[g[cur]]=true;
        dfs(g[cur],cur);
    }else{
         int next=(cc?cur:last);
         if(cc)st=cur;
         cc=false;
         cir.emplace_back(cur);
         dfs(g[cur],next);
    }
    return;
}
int main(){
 ll  n,k;
 cin>>n>>k;
 V<ll> d(n);
 g.resize(n);
 vis.assign(n,false);
 cc=true;
 for(int i=0;i<n;i++){
   cin>>d[i];
   g[i]=d[i]-1;
  }
  vis[0]=true;
  dfs(0,-1);
  int now=0;
  int cnt=0;
    if(k<200005){
     ll x=ll(k);
     now=0;
    for(int i=0;i<x;i++){
      now=g[now];
      }
      cout<<now+1<<"\n";
      return 0;
   }
  for(int i=0;i<n;i++){
    if(now==st)break;
     now=g[now];cnt++;
   }
   k-=cnt;
   int m=cir.size();
   cout<<cir[k%m]+1<<"\n";
}


Measured memory_bytes: 17728
N = int(input())
X = list(map(int, input().split()))

def dist(a, X):
	l = 0
	for i in X:
		l += (a-i)**2
	return l

ans = 10000000
for i in range(min(X), max(X)+1):
	if ans > dist(i,X):
		ans = dist(i,X)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

bool IsPrime(int num)
{
  if (num < 2) return false;
  else 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;
}

int main(){

  int X;
  cin >> X;

  bool flag = false;
  while (flag == false){
    flag = IsPrime(X);
    if(flag == false) X++;
  }

  cout << X << endl;

  return 0;
}

Measured memory_bytes: 256
from collections import Counter

N, M = map(int, input().split())
A = [int(i)%M for i in input().split()]

B = [0] * (N+1)
for i in range(N):
  B[i+1] = (B[i]+A[i]) % M
  
counter = dict(Counter(B))
ans = 0
for num in counter:
  ans += (counter[num]-1) * counter[num] // 2

print(ans)



Measured memory_bytes: 18100
#include <bits/stdc++.h>
using namespace std;
int a[2010];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    sort(a+1, a+1+n);
    long long ans = 0;
    for(int i=1;i<=n;i++){
        int k = i;
        for(int j=i+1;j<=n;j++){
            k = max(k, j+1);
            while(k <= n && a[i]+a[j] > a[k]) k++;
            ans += k-j-1;
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
l = dict()
t, f = 0, 0
n, m = map(int, input().split(" "))
for _ in range(m):
  p, s = input().split(" ")
  if not p in l:
    l[p] = [None, 0]
  if s == "WA":
    l[p][1] += 1 
  elif s == "AC":
    if l[p][0] != True:
      l[p][0] = True
      t += 1
      f += l[p][1]

print(t, f)

Measured memory_bytes: 25284
#include <cstdio>
#include <map>

int main()
{
  std::map<char, long long> m;
  int n;
  scanf("%d", &n);
  char s[11];
  for (int i = 0; i < n; ++i)
  {
    scanf("%s", s);
    m[*s]++;
  }
  
  long long ans = 0;
  const char march[] = "MARCH";
  for (int i = 0; i < 3; ++i)
  {
    for (int j = i + 1; j < 4; ++j)
    {
      for (int k = j + 1; k < 5; ++k)
      {
        ans += m[march[i]] * m[march[j]] * m[march[k]];
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

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

int main(){
	int S, h, m, s;
	cin >> S;

	s = S % 60;
	m = (S / 60) % 60;
	h = S / 3600;

	cout << h << ":" << m <<  ":" << s << endl;

	return 0;
}

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

#define F                   first
#define S                   second
#define int                 long long int
#define pb                  push_back
#define mp                  make_pair
#define pii                 pair<int,int>
#define vi                  vector<int>
#define mii                 map<int,int>
#define pqb                 priority_queue<int>
#define pqs                 priority_queue<int,vi,greater<int> >
#define mod                 1000000007
#define endl                '\n'
#define rep(i,a,b)            for(int i=a;i<b;i++)
int n, m;
int rec(vector<vector<char>> &a, int i, int j, vector<vector<int>> &dp) {
    if (i > n or j > m or a[i][j] == '#') {
        return 0;
    }
    if (i == n - 1 and j == m - 1) {
        return 1;
    }
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    int x = rec(a, i + 1, j, dp);
    int y = rec(a, i, j + 1, dp);

    return dp[i][j] = (x % mod + y % mod) % mod;
}
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
    c_p_c();

    cin >> n >> m;
    vector<vector<char>> a(n + 1, vector<char>(m + 1, -1));
    rep(i, 0, n) {
        rep(j, 0, m) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> dp(n + 1, vi(m + 1, -1));

    cout << rec(a, 0, 0, dp) % mod;

    return 0;
}

Measured memory_bytes: 12172
#include<stdio.h>

int main()
{
  int A,B,X;

    scanf("%d%d%d",&A,&B,&X);

    if(A<=X){

    if(A+B>X){
    printf("YES\n");
  }

  else{
    printf("NO\n");
  }
    }
    else{
      printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  int k;cin >> k;
  int n;cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  int mx = 0;
  for(int i=0;i<n;i++){
    int h;
    if(i==0){
      h = a[0] + k - a[n-1];
    }
    else h = a[i] - a[i-1];
    umax(mx,h);
  } 
  cout << k-mx << endl;
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

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

int N,W,D;

struct Rect{
  int w,h;
  int get() const{ return w*h; }
  bool operator < (const Rect &r ) const {
    return get() < r.get();
  }
};

int main(){

  while( cin >> N >> W >> D && (N||W||D) ){
    vector<Rect> v;
    v.push_back( (Rect){W,D} );
    for(int i=0;i<N;i++){
      int p,s; cin >> p >> s; --p;
      Rect r1,r2;

      for(int j=0;;j++){
	if( j&1 ) {
	  if( v[p].h > s ){
	    r1 = (Rect){v[p].w, v[p].h-s};
	    r2 = (Rect){v[p].w, s};
	    break;
	  }
	  s-=v[p].h;
	} else {
	  if( v[p].w > s ){
	    r1 = (Rect){v[p].w-s,v[p].h};
	    r2 = (Rect){s,v[p].h};
	    break;
	  }
	  s-=v[p].w;
	}	
      }
      if( r1 < r2 ){
	v.push_back( r1 ); v.push_back( r2 );
      } else {
	v.push_back( r2 ); v.push_back( r1 );
      }
      v.erase( v.begin() + p );
    }
    sort(v.begin(),v.end());
    for(int i=0;i<(int)v.size();i++){
      if( i ) cout << " ";
      cout << v[i].get();
    }
    cout << endl;
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
vector<int> InputLine(int N);

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> A = InputLine(M);
    int ans = N - accumulate(A.begin(),A.end(),0);
    if(ans < 0){
        ans = -1;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	ll n,m;
	cin>>n>>m;
	vector<ll> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end());
	map<ll,ll> t;
	for(int i=0;i<n;i++)t[a[i]]++;
	vector<mp> bb(m);
	//for(int i=0;i<m;i++)cin>>bb[i].second>>bb[i].first;
	//sort(bb.begin(),bb.end());

	for(int i=0;i<m;i++){
		ll b,c;
		cin>>b>>c;
		t[c] = t[c]+b;
	}
	ll sum = 0;
	vector<mp> aa;
	//cout<<"t"<<endl;
	for(auto it:t){
	//	cout<<it.first<<' '<<it.second<<endl;
		aa.push_back(it);
	}
	//cout<<"sun"<<endl;
	for(int i=aa.size()-1;i>=0;i--){
		if(aa[i].second > n){
			//cout<<aa[i].first<<' '<<aa[i].second<<endl;
			sum+= aa[i].first*n;
			break;
		}else{
			//cout<<aa[i].first<<' '<<aa[i].second<<endl;
			sum+=aa[i].first*aa[i].second;
			n -=aa[i].second;
		}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 21360
#include <stdio.h>

int main(){
	int m, f, r;
    
	scanf("%d %d %d", &m, &f, &r);
	while(!(m == -1 &&f == -1 && r == -1)){
		if(m == -1 || f == -1){
			printf("F\n");
		}else if(m + f >= 80){
			printf("A\n");
		}else if(65 <= m + f && m + f < 80){
			printf("B\n");
		}else if(50 <= m + f && m + f < 65){
			printf("C\n");
		}else if(30 <= m + f && m + f < 50){
			if(r >= 50){
				printf("C\n");
			}else{
				printf("D\n");
			}
		}else{
			printf("F\n");
		}
			scanf("%d %d %d", &m, &f, &r); 
	}
	return 0;
}

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

using namespace std;
using ll = long long;
const int N = 15, M = 1005;

int n, m, k;

char mat[N][M];

int mark[N];

int solve() {
	vector<pair<int, int>> ranges;
	for(int i = 0; i < n; i++) {
		int j = i;
		while(j + 1 < n and !mark[j]) j++;
		ranges.emplace_back(i, j);
		i = j;
	}
	vector<int> sum(ranges.size());

	int ans = 0;
	for(int j = 0; j < m; j++) {
		bool ok = true;
		for(int id = 0; id < (int)ranges.size(); id++) {
			int l, r;
			tie(l, r) = ranges[id];
			for(int i = l; i <= r; i++) {
				sum[id] += mat[i][j] == '1';
			}
			if(sum[id] > k) ok = false;
		}
		if(ok) continue;

		ans++;

		fill(sum.begin(), sum.end(), 0);

		ok = true;
		for(int id = 0; id < (int)ranges.size(); id++) {
			int l, r;
			tie(l, r) = ranges[id];
			for(int i = l; i <= r; i++) {
				sum[id] += mat[i][j] == '1';
			}
			if(sum[id] > k) ok = false;
		}
		if(!ok) return 1000000;
	}
	return ans;
}

int main() {
	scanf("%d %d %d", &n, &m, &k);

	for(int i = 0; i < n; i++) scanf(" %s", mat[i]);

	int ans = n - 1 + m - 1;
	for(int b = 0; b < (1 << n); b++) {
		for(int i = 0; i < n; i++) mark[i] = b >> i & 1;
		ans = min(ans, solve() + __builtin_popcount(b));
	}

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


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define int long long
#pragma region alias
#define inf (1<<64)-1
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repr(i,n) for(int i=(int)(n-1);i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))
#define sz(v) ((int)(v).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vec vector
using vi=vec<int>;
using vs=vec<string>;
using ii=pair<int,int>;
#pragma endregion

// define variables here
const short R=0,G=1,N=2;
int x,y,a,b,c;
vec<ii> mixed;
void solve(){
  // write code here
  cin>>x>>y>>a>>b>>c;
  rep(i,a){
    int p;
    cin>>p;
    mixed.pb(mp(p,R));
  }
  rep(i,b){
    int q;
    cin>>q;
    mixed.pb(mp(q,G));
  }
  rep(i,c){
    int r;
    cin>>r;
    mixed.pb(mp(r,N));
  }
  //sort by deliciousness
  sort(all(mixed),greater<ii>());

  int ans=0,cntR=0,cntG=0,cntN=0;
  for (ii v:mixed){
    if(cntR+cntG+cntN>=x+y)break;
    if(v.se==N){
      ans+=v.fi;
      cntN++;
    }else if(v.se==R&&cntR<x){
      ans+=v.fi;
      cntR++;
    }else if(v.se==G&&cntG<y){
      ans+=v.fi;
      cntG++;
    }
  }
  cout<<ans<<endl;
}

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

Measured memory_bytes: 10476
n = int(input())
a = list(map(int,input().split()))
am = [a[i]*(-2) for i in range(0,n,2)]

ans = [0 for i in range(n)]
ans[n-1] = sum(a) + sum(am) - am[(n-1)//2]

for i in range(n-2,-1,-1) :
  ans[i] = (a[i]-ans[i+1]//2)*2
  
print(*ans)


Measured memory_bytes: 16020
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here! sakuraihaaho
    string a;
    getline(cin,a);
    //cout<<a.size();
    for(int i = 0;i<a.size();i++){
        if((int)'a'<=(int)a.at(i)&&(int)'z'>=(int)a.at(i)) cout<<(char)((int)'A' + (int)a.at(i) -(int)'a'); 
         else   if((int)'A'<=(int)a.at(i)&&(int)'Z'>=(int)a.at(i)) cout<<(char)((int)'a' + (int)a.at(i) -(int)'A'); 
        else   cout<<a.at(i);
        
    }
    cout<<endl;
}



Measured memory_bytes: 3136
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};

int M, T, P, R;

struct Team {
	int correct, time, id;
	Team(int _c, int _t, int _i) : correct(_c), time(_t), id(_i) {}
};

bool operator > (const Team& a, const Team& b) {
	if (a.correct == b.correct) {
		if (a.time == b.time) {
			return a.id > b.id;
		}
		return a.time < b.time;
	}
	return a.correct > b.correct;
}

bool operator < (const Team& a, const Team& b) {
	return b > a;
}

bool eq(const Team& a, const Team& b) {
	return a.correct == b.correct && a.time == b.time;
}

void solve() {
	Matrix penalty(T, Array(P, 0));
	vector< vector< bool > > correct(T, vector< bool >(P, false));
	
	vector< Team > vt(T, Team(0, 0, 0));
	for_(i,0,T) vt[i].id = i + 1;
	
	for_(i,0,R) {
		int m, t, p, j; cin >> m >> t >> p >> j;
		--t; --p;
		
		if (correct[t][p]) continue;
		
		if (j == 0) {
			++vt[t].correct;
			vt[t].time += penalty[t][p] + m;
			correct[t][p] = true;
		} else {
			penalty[t][p] += 20;
		}
	}
	
	sort(allof(vt), greater<Team>());
	
	for_(i,0,T) {
		if (i > 0) {
			if (eq(vt[i - 1], vt[i])) cout << "=";
			else cout << ",";
		}
		
		cout << vt[i].id;
	}
	cout << endl;
}

int main() {
	while (cin >> M >> T >> P >> R, M) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1224
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e3+5;

const int mod = 1e9+7;

int n;
double a[N];

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1 , a + n + 1);
    for(int i = 2; i <= n; i++){
        a[i] = (a[i] + a[i - 1])/ 2;
    }
    cout << a[n];
}


Measured memory_bytes: 384
#include <stdio.h>
int main(){
    double a,b;
    while(scanf("%lf%lf",&a,&b)!=EOF){
        if(a<35.5&&b<71)printf("AAA\n");
        else if(a<37.5&&b<77)printf("AA\n");
        else if(a<40&&b<83)printf("A\n");
        else if(a<43&&b<89)printf("B\n");
        else if(a<50&&b<105)printf("C\n");
        else if(a<55&&b<116)printf("D\n");
        else if(a<70&&b<148)printf("E\n");
        else printf("NA\n");
    }
}

Measured memory_bytes: 2576
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  char l; scanf("%c", &l);
  if (l >= 'A' && l <= 'Z') printf("A\n");
  else printf("a\n");
  return 0;
}

Measured memory_bytes: 3756
A, B, M = map(int, input().split())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
ans = min(an)+min(bn)
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, an[x-1] + bn[y-1] - c)
print(ans)


Measured memory_bytes: 18612
n,m = gets.split.map{|x| x.to_i}

g = []

m.times do
  g << gets.split.map{|x| x.to_i}
end

ans = 0

$f = []

def get x 
  return x if x == $f[x]
  return get $f[x]
end

m.times do |x|
  $f = Array(0..n)
  m.times do |y|
    if x != y && get(g[y][0])!=get(g[y][1]) 
      $f[get(g[y][0])] = get(g[y][1])
    end
  end
  for x in (2..n) 
    if get(x)!=get(x-1) 
      ans+=1
      break
    end
  end
end

p ans

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


int main(){
int N,K;
cin>>N>>K;
int ans[N]={0};
for(int i=0; i<K; i++){
    int d=0;
    cin>>d;
    int A[d]={0};
    for(int j=0; j<d; j++){
        cin>>A[j];
    }
    for(int j=0; j<d; j++){
        ans[A[j]-1]=1;
    }
}
int answ=0;
for(int i=0; i<N; i++){
    if(ans[i]==0)answ++;
}
cout<< answ <<endl;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	set<string>ss;
	for(int i=0;i<n;++i){
		string s; cin>>s;
		ss.insert(s);
	}
	cout<<ss.size()<<"\n"s;
}

Measured memory_bytes: 19252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
const ll MOD = 1e9 + 7;

int n, m;

int main() {
	cin>>n>>m;
  	int ans = 0;
  ans += n * (n - 1) / 2;
  ans += m * (m - 1) / 2;
  cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define llong long long
#define mp make_pair
#define f first
#define s second

using namespace::std;

const int MAXN = 2e9 + 5;

int main()
{
    ios::sync_with_stdio(false);
    ifstream fin("input.txt");
    set<int> cnt;
    int N;
    cin >> N;
    vector<int> arr(N);
    int K = 0;
    int minval = MAXN;
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
        K = max(K, arr[i]);
        minval = min(minval, arr[i]);
    }
    if (K - minval > 1) {
        cout << "No\n";
        return 0;
    }

    if (K == minval) {
        if (K + 1 == N || 2 * K <= N) {
            cout << "Yes\n";
        }
        else {
            cout << "No\n";
        }
        return 0;
    }

    int n = 0, m = 0;

    for (int i = 0; i < N; i++) {
        if (arr[i] == K) {
            n++;
        }
        else if (arr[i] == K - 1) {
            m++;
        }
    }

    //cout << maxval << " " << minval << " " << m << "\n";

    if ((N - m) / 2  >= K - m && K - m >= 1) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}


Measured memory_bytes: 640
import bisect
a, b, q = map(int, input().split())

s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]

s.append(-100000000000)
s.append(100000000000)
t.append(-100000000000)
t.append(100000000000)
s.sort()
t.sort()

for _ in range(q):
    x = int(input())

    idxs = bisect.bisect_right(s, x)
    idxt = bisect.bisect_right(t, x)
    left_s = s[idxs - 1]
    right_s = s[idxs]
    left_t = t[idxt - 1]
    right_t = t[idxt]

    kouho1 = max(x - left_s, x - left_t)
    kouho2 = max(right_s - x, right_t - x)
    kouho3 = min(x - left_s, right_t - x) * 2 + max(x - left_s, right_t - x)
    kouho4 = min(x - left_t, right_s - x) * 2 + max(x - left_t, right_s - x)
    print(min(kouho1, kouho2, kouho3, kouho4))


Measured memory_bytes: 16924
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}
long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	int num[100001] = {};
	bool used[100001] = {};
	used[1] = true;
	for (int i = 1; i <= N; i++)cin >> num[i];
	int current = num[1];
	ans = 1;
	while (!used[current]) {
		if (current == 2) {
			cout << ans << endl;
			return 0;
		}
		used[current] = true;
		current = num[current];
		ans++;
		
	}
	cout << "-1\n";
	return 0;
}

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

int main() {
  int n;
  double ans;
  int tmp;
  cin >> n;
  if (n%2==0) {
    ans = 0.5;
    cout << ans << endl;
  }
  else {
    tmp = n / 2;
    tmp++;
    ans = (double)tmp / n;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,x;

int a[100005];
int main(void){
	scanf("%d%d",&n,&x);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	ll sum=0;
	ll now=0,prev=0;
	for(int i=0;i<n;i++){
		now+=a[i];
		ll tmp=a[i];
		if(now>=x){
			sum+=now-x;
			tmp-=now-x;
			now=x;	
		}
		now-=prev;
		prev=tmp;
	}
	ll sum2=0;
	now=0;
	prev=0;
	for(int i=n-1;i>=0;i--){
		now+=a[i];
		if(now>=x){
			sum2+=now-x;
			a[i]-=now-x;
			now=x;	
		}
		now-=prev;
		prev=a[i];
	}
	sum=min(sum,sum2);
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long k = sc.nextInt();
		long ans;
		if (k % 2 == 0) {
			ans = (n / k) * (n / k) * (n / k);
			n += k / 2;
			ans += (n / k) * (n / k) * (n / k);
		} else {
			ans = (n / k) * (n / k) * (n / k);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s[n];
    rep(i, n) cin >> s[i];
    int ans = 0;

    rep(i, n) {

        rep(j, s[i].length() - 1) {
            if (s[i][j] == 'A' && s[i][j + 1] == 'B') ans++;
        }
    }

    int xa = 0, ba = 0, bx = 0;

    rep(i, n) {
        char ai = *s[i].begin();
        char bi = *s[i].rbegin();
        if (ai == 'B' && bi == 'A') ba++;
        else if (ai == 'B') bx++;
        else if (bi == 'A') xa++;
    }

    if (xa > 0 && bx > 0) {
        ans += ba + 1;
        xa--, bx--;
        ans += min(xa, bx);
    } else if (xa > 0 || bx > 0) {
        ans += ba;
    } else {
        ans += max(ba - 1, 0);
    }

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



Measured memory_bytes: 768