akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 200005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n, m;
D p[maxn], ans, sum[maxn];
int main() {
	n = read(), m = read();
	rep(i, 1, n) p[i] = (1 + read()) / 2.0, sum[i ] = sum[i - 1] + p[i];
	rep(i, m, n) ans = max(ans, sum[i] - sum[i - m]);
	printf("%.10lf", ans);
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    long long c;
    cin >> c;
    long long x[n], v[n];
    for (int i = 0; i < n; i++) cin >> x[i] >> v[i];
    long long cw[n], cwd[n], acw[n], acwd[n];
    cw[0] = v[0] - x[0];
    cwd[0] = v[0] - 2 * x[0];
    acw[n - 1] = v[n - 1] - (c - x[n - 1]);
    acwd[n - 1] = v[n - 1] - 2 * (c - x[n - 1]);
    for (int i = 1; i < n; i++) {
        cw[i] = cw[i - 1] + v[i] - (x[i] - x[i - 1]);
        cwd[i] = cwd[i - 1] + v[i] - 2 * (x[i] - x[i - 1]);
    }
    for (int i = n - 2; i >= 0; i--) {
        acw[i] = acw[i + 1] + v[i] - (x[i + 1] - x[i]);
        acwd[i] = acwd[i + 1] + v[i] - 2 * (x[i + 1] - x[i]);
    }
    long long res = 0;
    for (int i = 0; i < n; i++) {
        res = max(res, cw[i]);
        res = max(res, acw[i]);
    }
    for (int i = 1; i < n; i++) {
        cw[i] = max(cw[i], cw[i - 1]);
    }
    for (int i = n - 2; i >= 0; i--) {
        acw[i] = max(acw[i], acw[i + 1]);
    }
    for (int i = 0; i < n - 1; i++) {
        res = max(res, cwd[i] + acw[i + 1]);
    }
    for (int i = n - 1; i > 0; i--) {
        res = max(res, acwd[i] + cw[i - 1]);
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;


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

const int MOD = 1e9 + 7;



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}
/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	return (x / tmp) * y;
}


/******************************************************************************************/


int main() {

	
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	
	ll tmp1 = b / c - (a - 1) / c;
	ll tmp2 = b / d - (a - 1) / d;
	ll tmp3 = b / lcm(c, d) - (a - 1) / (lcm(c, d));
	cout << b - a + 1 - (tmp1 + tmp2 - tmp3) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int ans[100]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22};
int main(){
    int a,b;
    cin>>a>>b;
    int ab=a+b;
	cout<<ans[ab-1];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
vector<ll>edge[(ll)1e5+10];
int main(void){
    ll x;
    cin>>x;
    rep((ll)-1e3,i,(ll)1e3+1){
        rep((ll)-1e3,j,(ll)1e3+1)if(i*i*i*i*i-j*j*j*j*j==x){
            cout<<i<<" "<<j<<endl;
            return 0;
        }
    }
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll X, Y;
    cin >> X >> Y;

    REP(i, 101){
        ll j = X - i;
        if(j < 0) continue;

        if(i*2 + j*4 == Y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

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

	int N, Y;
	cin >> N >> Y;

	int x = -1;
	int y = -1;
	int z = -1;

	for( int i = 0; i <= N; ++i ) {
		for( int j = 0; i+j <= N; ++j ) {
			int k = (Y - 10000*i - 5000*j) / 1000;
			if( k >= 0 && i+j+k == N ) {
				x = i;
				y = j;
				z = k;
				break;
			}
		}

		if( x > -1 ) { break; }
	}

	cout << x << ' ' << y << ' ' << z << ' ' << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int n = sc.nextInt();
      sc.nextLine();
	  String s = sc.nextLine();
	  char[] c = s.toCharArray();
      int sum = 0;
      char last = '1';
	  for(int i=0;i<n;i++){
	  	if(last != c[i])sum++;
        last = c[i];
	  }
	  System.out.println(sum);

	}
}

Measured memory_bytes: 26188
N, K = map(int, input().split())
S = input()
ans = 0
l, r = 0, 0
for i in range(N-1):
	if S[i] == S[i+1]:
		ans += 1
	elif S[i] == 'L':
		l += 1
	else:
		r += 1
x = min(l, r)
if K > x:
	print(ans + 2 * x + min(K - x, abs(l - r)))
else:
	print(ans + 2 * K)

Measured memory_bytes: 3316
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main(){
  int x, k=0,a,b;
  int stack[101];
  char c[100];
 
  while(scanf("%s",c)!= EOF){
    if ( c[0] == '+' ){
      a = stack[k];
      b = stack[k-1];
      stack[k-1] = b + a;
      k--;
      
    } 
    else if ( c[0] == '-' ){
      a = stack[k];
      b = stack[k-1];
      stack[k-1] = b - a;
      k--;
      
    } 
    else if ( c[0] == '*' ){
      a = stack[k];
      b = stack[k-1];
      stack[k-1] = b * a;
      k--;
      
    } 
    else {
      x = atoi(c);
      k++;
      stack[k] = x;
    }
  }
  printf("%d\n",stack[k]);
 
  return 0;
}

Measured memory_bytes: 548
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
using namespace std;
long long k[1005][5], ans;
int main() {
	int a, b;
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> k[i][j];
		}
	}
  
	for (int i = 0; i < (1<<3); ++i) {
		long long sum = 0, mon[100005] = {};
		for (int j = 0; j < a; ++j) {
			for (int kk = 0; kk < 3; ++kk) {
				if (i / (1 << kk) % 2 == 0) {mon[j] += k[j][kk];}
				else {mon[j] -= k[j][kk];}
			}
		}
		sort(mon, mon + a);
		for (int j = a - 1; j >= a - b; --j) {
			sum += mon[j];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

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

const int INF = 1e9;

int main(void) {
  int N, M;
  while (cin >> N >> M, N||M) {
    vector<int> maxi(N, 0);
    vector<int> mini(N, 0);

    for (int i=0; i<M; i++) {
      int S, K; 
      cin >> S >> K;

      for (int j=0; j<K; j++) {
        int C; cin >> C;
        C--;

        if (K == 1) {
          mini[C] += S;
        }
        maxi[C] += S;
      }
    }

    int ans = 0;
    for (int i=0; i<N; i++) {
      int min_mini = INF;
      for (int j=0; j<N; j++) {
        if (i == j) continue;
        min_mini = min(min_mini, mini[j]);
      }
      ans = max(ans, maxi[i] - min_mini + 1);
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
using namespace std;

int main(){
    int n, m, i;
    cin >> n >> m;
    int a[m], b[m];
    for(i = 0; i < m; i++){
        cin >> a[i] >> b[i];
    }
    int now = 0, c = 0;
    while(1){
        int minb = n+1;
        for(i = 0; i < m; i++){
            if(a[i] >= now)
                minb = MIN(minb, b[i]);
        }
        if(minb == n+1) break;
        now = minb;
        c++;
    }
    cout << c << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<ll> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    sort(arr.begin(), arr.end());
    reverse(arr.begin(), arr.end());
    vector<ll> tmp = {arr[0]};
    int idx = 1;
    while(tmp.size() < n-1) {
        tmp.push_back(arr[idx]);
        tmp.push_back(arr[idx++]);
    }
    ll ans = accumulate(tmp.begin(), tmp.begin()+(n-1), 0LL);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6812
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define NUM 200020
#define MAX 1000000010

int stock[NUM]={0};

//長さlenの丸太が何本とれるか
int available(int len, int n)
{
    int j;
    int r=0;
    for(j=0;j<n;j++)
    {
        r+= ceil((double)stock[j]/(double)len);
    }
    //printf("len:%d ->%d\n",len,r);
    return r;
}

int main() {
    int n = 0,k=0;
    int i, j;
    int x = 0;
    scanf("%d %d", &n,&k);

    for (i = 0; i < n; i++) {
        scanf("%d", &(stock[i]));
    }

    //にぶたん
    int hi,lo,mid;
    hi = MAX;
    lo =0;

    while(hi-1 > lo)
    {
        mid =(hi+lo)/2;
        if(available(mid,n) > k+n){
            lo = mid;
        }
        else{
            hi = mid;
        }
    }
    if(k==0)
    {
        int max=0;
        for(i=0;i<n;i++)
        {
            if(stock[i]>max)max=stock[i];
        }
        printf("%d",max);
        return 0;
    }
    /*
    else
    {
        int l;
        for(l=lo;l>0;l--)
        {
            if(available(l,n)!=(n+k))break;
        }
        printf("%d",l+1);
        return 0;
    }
     */
    printf("%d",lo+1);
}



Measured memory_bytes: 2452
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007n
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
//typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

int main(){
    ll W,H,x,y;
    cin>>W>>H>>x>>y;
    double ans=(double)H*W/2.0;
    printf("%.10lf",ans);
    cout<<" ";
    if(x*2==W && y*2==H) cout<<1<<endl;
    else cout<<0<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Here your code !
    int x,y;
    scanf("%d %d", &x, &y);
    if(( (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 ) && (y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) )||
        ((x == 4 || x == 6 || x == 9 ) && (y == 6 || y == 9 || y ==11) )){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
fn main() {
    // input
    // let one = read_vec::<u32>();
    // N
    let n = read_line::<u64>();

    let count = (1..n + 1).filter(|n| n % 2 == 1).count();

    let ans = (count as f64) / (n as f64);
    println!("{}", ans);
}

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


Measured memory_bytes: 4352
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    if a[i]==i+1:
        b.append(a[i])
j=0
c=0
while j<(len(b)-1):
    if b[j]+1==b[j+1]:
        c+=1
        j+=2
    else:
        j+=1
print(len(b)-c)

Measured memory_bytes: 14008
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut sorted = a.clone();
    sorted.sort();
    sorted.reverse();
    let max = sorted[0];
    let secondary_max = sorted[1];
    for i in a {
        if i == max { println!("{}", secondary_max) }
        else { println!("{}", max) }
    }
}


Measured memory_bytes: 7184
n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
    abx = x2 - x1
    aby = y2 - y1
    cdx = x4 - x3
    cdy = y4 - y3
    if abs(aby * cdx) < 1e-10 and abs(cdy * abx) < 1e-10:
        print(['NO', 'YES'][abs(abx - cdx) < 1e-10 or abs(aby - cdy) < 1e-10])
    elif abs(aby * cdx - cdy * abx) < 1e-10:
        print('YES')
    else:
        print('NO')



Measured memory_bytes: 5620
#include <bits/stdc++.h>	
#define pb push_back
typedef long long ll;
const int inf = 2e9;
using namespace std;

ll n,x,sum,botellasN,minimo,ans;

int C[300005],W[300005];
char S[300005];

int main(){
	int n;
	scanf("%d%s",&n,S);

	C[0] = S[0] == 'E' ? 1 : 0;
	W[0] = S[0] == 'W' ? 1 : 0;

	for (int i = 1; i < n; ++i)
	{
		if(S[i]=='E') { C[i]=C[i-1]+1; W[i]=W[i-1]; }
		else { W[i]=W[i-1]+1; C[i] = C[i-1]; }
	}

	int minimo = inf;


	for (int i = 0; i < n; ++i)
	{
			minimo = min(minimo, C[n-1] - C[i] + W[i-1]);
	}

	return !printf("%d\n", minimo);
}

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

int main() {

  int D; cin >> D; // ランク件数
  int G; cin >> G; // 目標点数
  vector<int> P(D); // ランク別問題数
  vector<int> C(D); // ランク別コンプボーナス
  rep(i,D){ cin >> P.at(i) >> C.at(i) ; }
  int Ans = 1e9;    // 回答：最小回答数の初期値設定

  rep(i,(1<<D)){      // ランク別全探索
    bitset<10> b(i);  // コンプリートランクに関する全探索
    int wk_num = 0;   // このビットセットパターンでの回答数
    int wk_pt  = 0;   // このビットセットパターンでの取得点数
    for(int j=D-1;j>=0;j--) { // コンプリート判定ビットセットを大きい方から
      if (b.test(j)) {      // 判定ビット位置がランク件数未満の場合のみ、コンプ判定
        wk_num += P.at(j);                // コンプ時、ランク別問題数を加算
        wk_pt += (j+1) * 100 * P.at(j) + C.at(j);  // コンプ時、ランク別全取得点数を加算
        if ( wk_pt >= G ) { break; }    // 目標点数を越えたら、そこで試合終了
      }
    }
    if ( wk_pt >=G ){
      Ans = min(Ans,wk_num);
      continue;
    }

    // ビットセットパターンコンプをしたが。目標点数に届かなかった場合の、追加回答数
    for(int j=D-1;j>=0;j--){   // 大きい桁数から、非コンプ時取得点数を加算
      if(!b.test(j)){   // 非コンプランクの場合
        int wk_num_rank = 0;  // このランクでのコンプ数。最大、問題数－１
        rep(k,P.at(j)-1){    // ランクｊについて、問題数－１の加算を行う。
          wk_num +=1;  // ランク別回答数に＋１
          wk_pt += (j+1) * 100;
          if ( wk_pt >= G ) { break; }  // 目標点数を越えたら、そこで試合終了
        }
        if ( wk_pt >= G ) { break; }
      }
    }
    if ( wk_pt >=G ){
      Ans = min(Ans,wk_num);
      continue;
    }

  }

  cout << Ans << endl;

}


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

int main(){
    i64 N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i], A[i]--;

    vector<i64> visit_f(N, -1);
    vector<i64> visit_s(N, -1);

    int now = 0;
    for(int i = 0; i < N+1; i++){
        if(visit_f[now] != -1) {
            visit_s[now] = i;
            break;
        }
        visit_f[now] = i;
        now = A[now];
    }

    if(K >= visit_f[now]){
        K -= visit_f[now];
        K %= (visit_s[now] - visit_f[now]);
    } else {
        now = 0;
    }
    while(K--) now = A[now];

    cout << now+1 << endl;
}


Measured memory_bytes: 7160
import math

angle = int(input())
c = 1
x = 0
y = 1

while [round(x,2),round(y,2)] != [0,0]:
  angle_u= 180-angle*c
  y -= math.cos(math.radians(angle_u))
  x -= math.sin(math.radians(angle_u))
  c += 1
else:
  print(c)

Measured memory_bytes: 62360
#include<stdio.h>

/*選択ソート(0オリジン)*/
int selectionSort(int A[], int N) {
    int i, j, t, sw = 0, minj;
    for ( i = 0; i < N - 1; i++ ) {
        minj = i;
        for ( j = i; j < N; j++ ) {
            if ( A[j] < A[minj] ) minj = j;
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if ( i != minj ) sw++;
    }
    return sw;
}

int main() {
    int A[100], N, i, sw;

    scanf("%d", &N);
    for ( i = 0; i < N; i++ ) scanf("%d", &A[i]);

    sw = selectionSort(A, N);

    for ( i = 0; i < N; i++ ) {
        if ( i > 0 ) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);

    return 0;
}


Measured memory_bytes: 2016
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long MOD = 1e9 + 7;

template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << int(A != C) << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105000;

int n, m;
int a[MAXN];
map <long long, int> cnt;
long long ans;

int main() { 

  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  cnt[0] = 1;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    long long mod = sum % m;
    ans += cnt[mod];
    cnt[mod]++;
  }

  cout << ans << endl;

  return 0;
}


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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    int a, b, c;
    cin >> a >> b >> c;
    bool ans = false;
    if (b - a == c - b) {
        ans = true;
    }
    string ans2;
    if (ans) { ans2 = "YES"; }
    else { ans2 = "NO"; }
    cout << ans2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int n;
std::vector<int> l;
int ans;

signed main(){
	scanf("%ld", &n);
	for(int i = 0; i < 2*n; i++){
		int a;
		scanf("%ld", &a);
		l.push_back(a);
	}
	std::sort(l.begin(), l.end());
	for(int i = 0; i < n; i++){
		ans += l[2*i];
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld lond double
#define pll pair < long long , long long>
#define p_b push_back
#define all(x) x.begin(),x.end();
#define fi first
#define se second
#define string str
using namespace std;

int main()
{
    int n;
    cin >> n;
    bool chek = 0;
    for( int i = 0; i < n; i++)
    {
        int  b;
        cin >> b;
        if(b%2==0)
        {
            if(b%3!=0 && b%5!=0)
            {
                chek =1;
            }
        }
    }
    if(!chek)
    {
        cout << "APPROVED";
    }
    else
    {
        cout << "DENIED";
    }

}


Measured memory_bytes: 256
#include <cassert>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <tuple>

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

  size_t N;
  std::cin >> N;
  assert(N <= 100);

  std::vector<double> A(N);
  for (auto& ai: A) std::cin >> ai;

  double res = 0;
  for (auto ai: A) res += 1.0 / ai;
  res = 1.0 / res;

  std::cout << std::fixed << std::setprecision(10000000) << res << std::endl;
}


Measured memory_bytes: 60860
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int N;
    string S;
    cin >> N >> S;
    S = S.back() + S + S.front();
    bool sh[100010];//Sなら1
    for(int i = 0;i < 4;i++){
        sh[0] = i&1;
        sh[1] = i&2;
        sh[2] = sh[0]^sh[1];
        if(S[1] == 'o')sh[2] = !sh[2];
        for(int j = 2;j <= N;j++){
            sh[j+1] = sh[j-1]^sh[j];
            if(S[j] == 'o')sh[j+1] = !sh[j+1];
        }
        if(sh[0] == sh[N] && sh[1] == sh[N+1]){
            for(int j = 1;j <= N;j++)cout << (sh[j]?'S':'W');
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

int cmp(const int *a,const int *b){
  if(*a>*b){
    return 1;
  }
  else if(*a<*b)
  return -1;
  else return 0;
}

int main(void){

  long long int a,b,k;
  scanf("%lld%lld%lld",&a,&b,&k);

  if(a>k){
    a=a-k;
    k=0;
    printf("%lld %lld",a,b);
    return 0;
  }
  else if(a<=k){
    k=k-a;
    a=0;
    b=b-k;
    if(b<=0){
      b=0;
    }
    printf("%lld %lld",a,b);
  }
return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
	int a,b;
	char c;
	while(true){
		cin>>a>>c>>b;
		if(c=='?')break;
		if(c=='+'){
			cout<<a+b<<endl;
		}
		if(c=='-'){
			cout<<a-b<<endl;
		}
		if(c=='*'){
			cout<<a*b<<endl;
		}
		if(c=='/'){
			cout<<a/b<<endl;
		}
	}
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main(){
	int x, y, z;
	int s, ans;
	scanf("%d %d %d", &x, &y, &z);
	s = min(y, z);
	ans = max(0, y + z - x);

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


	return 0;
}


Measured memory_bytes: 128
s = int(input())

ans = [4, 2, 1]
flag = 0
cnt = 1
while flag == 0:
    if s in ans:
        cnt += 3
        print(cnt)
        flag = 1
    else:
        cnt += 1
        if s % 2 == 0:
            s = s / 2
        else:
            s = 3 * s + 1


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u * v / gcd(u, v);
}

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

    int N;
    cin >> N;
    vector<int> A(N);
    cin >> A;

    map<int, int> m;
    REP(i, N) {
        m[A[i]]++;
        m[A[i] - 1]++;
        m[A[i] + 1]++;
    }

    int max = m[0];
    for (auto&& s : m) {
        if (max < s.second) {
            max = s.second;
        }
    }
    cout << max << endl;

    return 0;
}

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

int main()
{
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;

	vector<int> index;
	index.resize(n + 1, 0);

	for (int i = 0; i < n - 1; ++i) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			index[i + 1] = index[i] + 1;
		}
		else {
			index[i + 1] = index[i];
		}
	}

	int l, r;
	vector<int> ret(q, 0);
	for (int i = 0; i < q; ++i) {
		cin >> l >> r;
		ret[i] = index[r - 1] - index[l - 1];

		//for (int j = l; j < r; ++j) {
		//	ret[i] += index[j];
		//}
	}

	for (int i = 0; i < q; ++i) {
		cout << ret[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define prime 1000000007
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    int N, M;
    cin >> N >> M;
    int Coin[M];
    rep(i, M) cin >> Coin[i];
    vector<int> dp(50005, INF);
    dp[0] = 0;
    rep(i, M) rep(j, N + 1) {
        if(j + Coin[i] <= N) dp[j + Coin[i]] = min(dp[j] + 1, dp[j + Coin[i]]);
    }
    cout << dp[N] << endl;
}



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

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    bool win[k+1]={};
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i>=a[j]&&win[i-a[j]]==false){
                win[i]=true;
                break;
            }
        }
    }
    cout<<(win[k]?"First":"Second")<<endl;
}

Measured memory_bytes: 384
//written by libra9z
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cmath>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define repit(it,a) for (__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define ITR(...) __VA_ARGS__::iterator
#define all(a) (a).begin(),(a).end()
#define reunique(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define sz(a) (int)a.size()
#define MP(...) make_pair(__VA_ARGS__)
#define X first
#define Y second
#define sqr(x) ((x)*(x))
const int inf=1e9;
const long long lnf=1e18;
const int mod=1e9+7;
const int Maxn=100005;
int n,m;
int p[Maxn];
vector <int> v[Maxn],a,b;
bool used[Maxn];
int res;
void dfs(int x)
{
	if (used[x]) return;
	used[x]=true;
	a.push_back(x);
	b.push_back(p[x]);
	for (auto &y:v[x]) dfs(y);
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cout<<setprecision(15);
	cin>>n>>m;
	for (int i=1;i<=n;i++) cin>>p[i];
	for (int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for (int i=1;i<=n;i++)
	{
		dfs(i);
		sort(all(a));
		sort(all(b));
		int l=0,r=0;
		while (l<sz(a) && r<sz(b))
		{
			if (a[l]<b[r]) l++;
			else if (a[l]>b[r]) r++;
			else
			{
				res++;
				l++;
				r++;
			}
		}
		a.clear();
		b.clear();
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 10156
i = 0
STDIN.each_line do |line|
    tokens = line.chomp!.split.map!(&:to_i)
    x, y = *tokens
    break if x == 0 && y == 0
    if x > y then 
      puts "#{y} #{x}"
    else
      puts "#{x} #{y}"
    end
end

Measured memory_bytes: 8740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define lowbit(x) ((x)&(-x))
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int maxn = 1e5 + 10;
const int maxm = 1e6 + 10;
const ll mod =  998244353;

int a[maxn];

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    int n;
    scanf("%d",&n);
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        int x,y;
        scanf("%d%d",&x,&y);
        a[i] = x + y;
        ans -= y;
    }
    sort(a, a + n);
    int cur = 1;
    for(int i = n - 1; i >= 0; i--) {
        if(cur) ans += a[i];
        cur ^= 1;
    }
    printf("%lld",ans);
    return 0;
}

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

const int NN = 2e5 + 100, M = 2020, N = 4040, MOD = 1000 * 1000 * 1000 + 7;

int sum(int a, int b) {
	a += b;
	if (a < 0)
		a += MOD;
	else if (a >= MOD)
		a -= MOD;
	return a;
}
void _sum(int &a, int b) {
	a = sum(a, b);
}
int mul(int a, int b) {
	return 1LL * a * b % MOD;
}
void _mul(int &a, int b) {
	a = mul(a, b);
}
int power(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1)
			_mul(res, a);
		_mul(a, a);
		b >>= 1;
	}
	return res;
}
int inv(int x) {
	return power(x, MOD - 2);
}

int n, a[NN], b[NN], ans, dp[N][N], c[N][N * 2];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	fill(c[0], c[0] + N, 1);
	for (int i = 1; i < N; i++)
		for (int j = 1; j < N * 2; j++)
			c[i][j] = sum(c[i - 1][j - 1], c[i][j - 1]);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		_sum(ans, -c[2 * a[i]][2 * (a[i] + b[i])]);
		dp[M - a[i]][M - b[i]]++;
	}
	for (int i = 1; i < N; i++)
		for (int j = 1; j < N; j++)
			_sum(dp[i][j], sum(dp[i - 1][j], dp[i][j - 1]));
	for (int i = 0; i < n; i++)
		_sum(ans, dp[M + a[i]][M + b[i]]);
	cout << mul(ans, inv(2));
}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
const ll LLINF = LLONG_MAX;
int n;
ll A[6300],dp[6300][2100][2]; // dp[left][len][player]


#define JOI 0
#define IOI 1

void compute(){
  rep(i,n) A[n+i] = A[n*2+i] = A[i];
  memset(dp,-1,sizeof(dp));
  rep(i,n) dp[n+i][1][JOI] = A[i];
  REP(length,1,n) {
    int player = !(length&1);
    rep(left,n*3) {
      if( dp[left][length][player] == -1 ) continue;
      ll &v = dp[left][length][player];

      if( player == IOI ) {
	dp[left-1][length+1][JOI] = max(dp[left-1][length+1][JOI],v+A[left-1]);
	dp[left  ][length+1][JOI] = max(dp[left  ][length+1][JOI],v+A[left+length]);
      } else { // IOI
	if( A[left-1] < A[left+length] ) {
	  dp[left  ][length+1][IOI] = max(dp[left  ][length+1][IOI],v);
	} else {
	  dp[left-1][length+1][IOI] = max(dp[left-1][length+1][IOI],v);
	}
      }
    }
  }
  ll maxi = 0;
  rep(i,n*3+3) rep(j,n+1) rep(k,2) {
    maxi = max(maxi,dp[i][j][k]);
  }
  cout << maxi << endl;
}

int main(){
  cin >> n;
  rep(i,n) cin >> A[i];
  compute();
  return 0;
}

Measured memory_bytes: 207940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int A[3][3];
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
            cin >> A[i][j];
    int N;
    cin >> N;

    int C[3][3] = {};
    for(int i=0;i<N;i++){
        int b;
        cin >> b;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(A[i][j] == b)
                    C[i][j] = 1;
            }
        }
    }

    // タテ・ヨコ
    for(int i=0;i<3;i++){
        if(C[i][0] == 1 && C[i][1] == 1 && C[i][2] == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    for(int i=0;i<3;i++){
        if(C[0][i] == 1 && C[1][i] == 1 && C[2][i] == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    // ナナメ
    if(C[0][0] == 1 && C[1][1] == 1 && C[2][2] == 1){
        cout << "Yes" << endl;
        return 0;
    }
    if(C[0][2] == 1 && C[1][1] == 1 && C[2][0] == 1){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

}

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

using namespace std;

const int INF = 1e9;
const long long INF64 = (1ll << 63) - 1ll;

vector <int> d;

long long f(int x){
    long long res = 0;
    int n = d.size();
    for (int i = 0; i < n; i++){
        res += 1ll * abs(1ll * d[i] - (x + i * 1ll + 1ll));
    }
    return res;
}

int main()
{
    #ifdef HOME
        freopen("input.txt", "rt", stdin);
    #endif // HOME
    int n;
    cin >> n;
    d.resize(n);
    for (int i = 0; i < n; i++){
        cin >> d[i];
    }
    int l, r, m1, m2;
    l = -INF, r = INF;
    for (int i = 0; i < 200; i++){
        m1 = (l + (r - l + 1) / 3);
        m2 = (r - (r - l + 3) / 3);
        if (f(m1) < f(m2)){
            r = m2;
        }
        else{
            l = m1;
        }
    }
    long long mn = INF64, ans = -1;
    for (int i = l - 100; i <= l + 100; i++){
        long long val = f(i);
        mn = min(val, mn);
        if (mn == val){
            ans = i;
        }
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 1024
S = input()
L = len(S)

MOD = 10 ** 9 + 7
dp = [[0] * 13 for _ in range(10**5+10)]
dp[0][0] = 1
for i in range(L):
    j = -1 if S[i] == "?" else int(S[i])
    if j > -1:
        # jが確定しているので、jを全探索する必要はなく、前回桁までの組み合わせの数にjを足して次のDPへ入れる
        # jが確定しているから数字の組み合わせ自体が増えるわけではない
        # そのためこれまで確定していた桁に対して、jを追加した場合のあまりを単純に移送することになる
        
        # 前回桁までの数 * 10 + j をすると、今回桁をjにしたときのあまりがわかる
        # 3?1 → 301 % 13 = 2, 30 % 13 = 4であるから、ki=4のとき、dp[i][4]の数値をdp[i+1][2]に足す
        # 30と4はmod13の世界では合同になっている
        # すなわち*10した結果である300と40も合同
        # そこにjを足した数 300+jと40+jもまた合同であると言える、ともにあまりは2
        # ここでは具体的な値である30は計算していないが、その具体的な数と合同である数字を用いて、今回桁で作成可能な数字のmodを数えているdp[i+1][2]にdp[i][4]を突っ込むことになる
        # modの世界では両辺に同じ数をかけても合同であるという性質を用いて、10をかけながら、桁ごとに数値を足していっていることになる

        for ki in range(13):
            dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]
    else:
        # jが確定していないので、jになりうる値を全て試す
        # 0-9の10パターンの数字が考えられるので、全ての組み合わせ自体は*10になる
        # ? だと10パターン ??だと100パターンになるので、?が来ると、数字の組み合わせが10倍になるのは自明
        # 10**(?の数) の組み合わせの総数になる
        for j in range(10):
            for ki in range(13):
                dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]
    
    for j in range(13):
        dp[i+1][j] %= MOD

print(dp[L][5])


Measured memory_bytes: 61788
n, k = map(int, input().split())
p = list(map(int, input().split()))

s = sum(p[:k])
s += k
s /= 2
ans = s

for i in range(n-k):
    s -= (p[i]+1)/2
    s += (p[i+k]+1)/2
    ans = max(ans, s)

print(ans)


Measured memory_bytes: 71792
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(a*b+" "+(2*a+2*b));
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}



Measured memory_bytes: 24464
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
typedef long long LL;
typedef unsigned long long ULL;
 
int main()
{
    LL n,a,b;
    cin>>n>>a>>b;
    if(a>b||(n==1&&a!=b))
    {
        cout<<0<<endl;
    }
    else if(n==1||n==2||a==b)
    {
        cout<<1<<endl;
    }
    else
    {
        cout<<(n-2)*(b-a)+1<<endl;
    }
    return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n, k;
    cin >> n >> k;
    
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    vector<int> b = a;
    reverse(b.begin(), b.end());

    vector< vector<int> > dp1(n + 1, vector<int>(k)), dp2(n + 1, vector<int>(k));
    dp1[0][0] = 1;
    dp2[0][0] = 1;
    rep(i, n){
        rep(j, k){
            dp1[i + 1][j] = dp1[i + 1][j] | dp1[i][j];
            dp2[i + 1][j] = dp2[i + 1][j] | dp2[i][j];
            if(j + a[i] < k){
                dp1[i + 1][j + a[i]] = dp1[i + 1][j + a[i]] | dp1[i][j];
            }
            if(j + b[i] < k){
                dp2[i + 1][j + b[i]] = dp2[i + 1][j + b[i]] | dp2[i][j];
            }
        }
    }
    rep(i, n + 1){
        REP(j, 1, k){
            dp1[i][j] += dp1[i][j - 1];
            dp2[i][j] += dp2[i][j - 1];
        }
    }

    int ans = 0;
    rep(i, n){
        if(a[i] >= k){
            continue;
        }
        bool flag = false;
        flag |= (dp1[i][0] > 0 && dp2[n - i - 1][k - 1] - dp2[n - i - 1][k - a[i] - 1] > 0);
        flag |= (dp2[n - i - 1][0] > 0 && dp1[i][k - 1] - dp1[i][k - a[i] - 1] > 0);
        REP(j, 1, k - a[i]){
            flag |= (dp1[i][j] - dp1[i][j - 1] > 0 && dp2[n - i - 1][k - j - 1] - dp2[n - i - 1][k - a[i] - j - 1] > 0);
            flag |= (dp2[n - i - 1][j] - dp2[n - i - 1][j - 1] > 0 && dp1[i][k - j - 1] - dp1[i][k - a[i] - j - 1] > 0);
        }
        REP(j, k - a[i], k){
            flag |= (dp1[i][j] - dp1[i][j - 1] > 1 && dp2[n - i - 1][k - j - 1] > 0);
            flag |= (dp2[n - i - 1][j] - dp2[n - i - 1][j - 1] > 0 && dp1[i][k - j - 1] > 0);
        }
        ans += !flag;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 196224
N = int(input())

Sn, Tn = [0] * N, [0] * N
XLn = []
for i in range(N):
    x, l = map(int, input().split())
    Sn[i], Tn[i] = x-l, x+l

for i in range(N):
    XLn.append((Tn[i], Sn[i]))

XLn = sorted(XLn, key=lambda x: x[0])

res, t = 0, -float("inf")
for i in range(N):
    if t <= XLn[i][1]:
        res += 1
        t = XLn[i][0]

print(res)

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

#define PI 3.14159265358979

// https://sarcasticresonance.wordpress.com/2010/06/22/water-to-the-edge/

int main() {
  double S, H, x;
  cin >> S >> H >> x;

  double V = S*S*H;
  double theta = 0;
  if (x < V/2) {
    // case 1 : h <= H/2 --> triangle is formed
    // x = kH/2
    // k = H.tan(theta)
    // x = H.H.tan(theta)/2
    // tan(theta) = 2.x/H.H

    theta = atan((H*H*S)/(2*x));
  } else {
    // case 2 : h >= H/2 --> trapezoid is formed
    double h = 2*(V - x)/(S*S);
    theta = atan(h/S);
  }

  printf("%.10f", (theta * 180/PI));
}

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

const int MAX_N = 300 * 300 + 5;
int wind[MAX_N];
int hind[MAX_N];
int ds[MAX_N];

int main() {
  int h, w, d;
  cin >> h >> w >> d;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int ind;
      cin >> ind;
      hind[ind-1] = i;
      wind[ind-1] = j;
    }
  }
  for (int j = 0; j < h*w; j ++) {
    if (j < d) {
      ds[j] = 0;
    }
    else {
      int h_dist = abs(hind[j] - hind[j-d]);
      int w_dist = abs(wind[j] - wind[j-d]);
      ds[j] = h_dist + w_dist + ds[j-d];
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << ds[r-1] - ds[l-1] << endl;
  }
}

Measured memory_bytes: 2176
//By Zank100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define din(t) long long t;cin>>t;
#define in(t) cin>>t;
int main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	din(n);din(m);
	char a[n][m];
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<m;j++)in(a[i][j]);
	}
	ll dp[n][m];
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<m;j++)dp[i][j]=0;
	}
	//dp[0][0]=1;
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<m;j++)
		{
			if(a[i][j]=='.')
			{
				if(i==0&&j==0){
					dp[i][j]=1;
				}else if(i==0&&j!=0){
					dp[i][j]=dp[i][j-1];
				}else if(i!=0&&j==0){
					dp[i][j]=dp[i-1][j];
				}else{
					dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
				}
			}
		}
		//cout<< endl;
	}
	/*for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<m;j++)cout<<dp[i][j]<<" ";
		cout<<endl;
	}*/
	cout<<dp[n-1][m-1];
	return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n,h;cin>>n>>h;
    vector<ll> a(n),b(n);
    REP(i,n)cin>>a[i]>>b[i];
    ll maxa=MAX(a), cnt=0;
    sort(ALL(b),greater<>());
    REP(i,n){
        if(maxa<=b[i]){
            h-=b[i];
            cnt++;
        }else{
            break;
        }
        if(h<=0){
            cout<<cnt<<endl;
            return 0;
        }
    }
    while(h>0){
        h-=maxa;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string wsq;
	cin>>wsq;
    int len=wsq.size();
    for(int i=0;i<=len;i++)
    if(wsq[i]=='C')
    for(int j=i+1;j<=len;j++)
    if(wsq[j]=='F')
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define  fast   ios_base::sync_with_stdio(false); cin.tie(NULL);
int main(){
    fast;
    int h=0,m=0;
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='R'){
            m++;
            break;
        }
    }
    if(m>0){
        for(int i=0;i<2;i++){
            if(s[i]==s[i+1] && s[i]=='R')h++;
        }

        cout<<h+1;
    }

    else cout<<0;
}

Measured memory_bytes: 3632
#include <stdio.h>

void sort(int nums[3])
{
    int i, j, tmp;
    for (i = 1; i < 3; ++i)
    {
        tmp = nums[i];
        if (tmp < nums[i - 1])
        {
            j = i;
            do
            {
                nums[j] = nums[j - 1];
                --j;
            } while(j > 0 && tmp < nums[j - 1]);
            nums[j] = tmp;
        }
    }
}

int main(void)
{
    int nums[3];
    char buf[256];
    fgets(buf, 256, stdin);
    buf[255] = '\0';

    sscanf(buf, "%d %d %d", nums, nums + 1, nums + 2);
    sort(nums);

    printf("%d %d %d\n", nums[0], nums[1], nums[2]);
}



Measured memory_bytes: 2048