akhauriyash/Code-Regression huggingface dataset:
n = int(input())
P = list(map(int, input().split()))

cnt = 0
for i in range(1, n-1):
	if (P[i-1]<P[i] and P[i]<P[i+1]) or (P[i-1]>P[i] and P[i]>P[i+1]):
		cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)
#define reps(i, a, b) for(ll i = a; i < b; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

///////////////////////////////////////////////////////////////////////////

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

    vector<ll> A(N), B(N), C(N - 1);

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

    ll ans = B[A[0] - 1];
    ll mae = A[0];


    for (ll i = 1; i < N; ++i) {
        ans += B[A[i] - 1];
        if (mae == A[i] - 1) {
            ans += C[mae - 1];
        }

        mae = A[i];
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#if 0

#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

string S;
size_t cur;

char readchar() {
  assert(cur < S.size());
  return S[cur++];
}
char peek() {
  assert(cur < S.size());
  return S[cur];
}
int digit() {
  assert(isdigit(peek()));
  int n = readchar() - '0';
  return n;
}
int number() {
  int n = digit();
  while (cur < S.size() && isdigit(peek()))
    n = n*10 + digit();
  return n;
}
int expression();
int factor() {
  if (peek() != '(')
    return number();
  cur += 1;
  int n = expression();
  assert(peek() == ')');
  cur += 1;
  return n;
}
int term() {
  int a = factor();
  while (cur < S.size() && (peek() == '*' || peek() == '/')) {
    char op = readchar();
    int b = factor();
    if (op == '*')
      a *= b;
    else
      a /= b;
  }
  return a;
}
int expression() {
  int a = term();
  while (cur < S.size() && (peek() == '+' || peek() == '-')) {
    char op = readchar();
    int b = term();
    if (op == '+')
      a += b;
    else
      a -= b;
  }
  return a;
}

int main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    cur = 0;
    cin >> S;
    S.resize(S.size()-1);
    cout << expression() << endl;
  }
}



Measured memory_bytes: 3124
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>


using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using mi=map<int,int>;


int gcd(int a, int b)
{
	int c;

	while((c=a%b))
	{
		a=b;
		b=c;
	}
	return b;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi a(n);
		vi f(n+2);
		vi b(n+2);

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

		f[0]=a[0];
		for(int i=1;i<n;i++)
		{
			f[i]=gcd(f[i-1], a[i]);
		}

		b[n-1]=a[n-1];
		for(int i=n-2;i>=0;i--)
		{
			b[i]=gcd(b[i+1], a[i]);
		}


		int ans=max(f[n-2], b[1]);
		for(int i=1;i<n-1;i++)
		{
			ans=max(ans, gcd(f[i-1], b[i+1]));
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1408
N=int(input())
X=list(map(int,input().split()))
ans=10000000
for i in range(1,101):
    P=i
    sums=0
    for j in range(N):
        sums+=(X[j]-P)*(X[j]-P)
    if(sums<ans):
        ans=sums
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<vector<int>> dp(401, vector<int>(401, M));
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        for (int j = 400; j >= a; --j) {
            for (int k = 400; k >= b; --k) {
                dp[j][k] = min(dp[j][k], dp[j - a][k - b] + c);
            }
        }
    }
    int ans = M;
    for (int i = 1; ma * i < 401 && mb * i < 401; ++i) {
        ans = min(ans, dp[ma * i][mb * i]);
    }
    cout << (ans == M ? -1 : ans) << "\n";
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<int> score(n);
            REP(i, n) cin >> score[i];
            whole(sort, score);
            int ans = INF;
            REP(i, n - 1) ans = min(ans, score[i + 1] - score[i]);
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    string s;
    cin >> s;

    bool flg = true;
    for( int i = s.size() - 1; i > 0; --i ) {
        if( s[i] != '9' ) flg = false;

    }

    if( flg ) cout << ( s[0] - '0' ) + ( 9 * ( s.size() - 1 ) ) << endl;
    else cout << ( s[0] - '0' - 1 ) + ( 9 * ( s.size() - 1 ) ) << endl;

    return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;

int main() {
	ll n, a;

	cin >> n >> a;

	if (a >= n % 500) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
 
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int count=0,count2=0;
  rep(i,s.size()){
   if(s[i]=='c')cout << "No" << endl;
    else if(s[i]=='a' && count<a+b){
      cout << "Yes" << endl;
      count++;
    }
    else if(s[i]=='b' && count<a+b &&count2<b){
     cout << "Yes" << endl;
      count++;
      count2++;
    }
    else cout << "No" << endl;
  }
return 0;}

Measured memory_bytes: 896
# -*- coding: utf-8 -*-

n, m, c = map(int, raw_input().split())

b = map(int, raw_input().split())

a = []

for i in range(n):
    raw = list(map(int, raw_input().split()))
    a.append(raw)

ans = 0
for i in range(n):
    cnt = 0
    for j in range(m):
        cnt += a[i][j]*b[j]
    cnt += c
    if cnt > 0:
        ans += 1

print ans



Measured memory_bytes: 2568
using System;
using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace _1_A
//{
class Program
{
    static void Main(string[] args)
    {
        string a = Console.ReadLine();
        string[] array = a.Split(' ');

        int i = int.Parse(array[0]);
        int j = int.Parse(array[1]);
        int k = int.Parse(array[2]);

        int[] iarray = new int[3];
        iarray[0] = i;
        iarray[1] = j;
        iarray[2] = k;

        Array.Sort(iarray);

        for (i = 0; i < iarray.Length; i++)
        {
            Console.Write(iarray[i]);
            if (i < 2)
                Console.Write(" ");
        }
        Console.WriteLine();
        //Console.Read();
    }
}
//}

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

int main() {
  double n, d; cin >> n >> d;
  int ans = 0;
  rep(i,n) {
    double x, y; cin >> x >> y;
    if (sqrt(x*x+y*y) <= d) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3760
import Foundation

func readInt() -> [Int]{
    return readLine()!.split(separator:" ").map{Int($0)!}
}
let nd = readInt()
var c = 0
for i in 1...nd[0]{
  let xy = readInt()
  if(xy[0] * xy[0] + xy[1] * xy[1] <= nd[1] * nd[1]){
    c += 1
  }
}
print(c)

Measured memory_bytes: 13596
#include <stdio.h>
int main(){
 int n;
 int debt=100000;
 scanf("%d",&n);
 while(n--){
   debt += debt*0.05;
   if(debt%1000!=0){
     debt -= debt%1000;
     debt += 1000;
   }
 }
 printf("%d\n",debt);
 return 0;
}

Measured memory_bytes: 1020
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N, A, B = map(int, input().split())
    if A == 0:
        print(0)
        exit()

    ans = (N // (A + B)) * A
    if N % (A + B) > 0:
        ans += min(N % (A + B), A)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 65544
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define pb push_back
#define md 1000000007
int main()
{
	fast;
	int s, w;
	cin >> s >> w;
	if (w >= s)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;
	return 0;
}


Measured memory_bytes: 3584
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n,k;cin>>n>>k;

    vector<bool> f(n);

    REP(i,k){
        int d;cin>>d;
        REP(j,d){
            int a;cin>>a;
            a--;
            f[a] = true;
        }
    }
    int result = 0;
    REP(i,n){
        if(!f[i]){
            result++;
        }
    }
    cout<<result<<endl;
    
    return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;
const ll mod=1000000007;
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll a,b,n;cin>>n>>a>>b;
 if((b-a)%2!=0){
  ll ans=min(n-b,a-1);
  ans+=1+(b-a-1)/2;
  pr(ans);
  return 0;
 }
 ll ans=min(b-1,(b-a)/2);
 ans=min(n-a,ans);
 pr((b-a)/2);
return 0;}
// (10^x -1)*7/9=n*k
// (10^x -1)*7=n*k*9
// nが7の倍数じゃないときは、kは7の倍数


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define YESNO(i) if((i)) puts("YES");else puts("NO");
#define YesNo(i) if((i)) puts("Yes");else puts("No");
#define yesno(i) if((i)) puts("yes");else puts("no");
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x,y,z;cin>>x>>y>>z;
  printf("%lld %lld %lld\n",z,x,y);
  return 0;
}


Measured memory_bytes: 256
# 二項係数を"やるだけ"にしてくれるライブラリ
MAX = 510000
MOD = 1000000007
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX
 
 
# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD
 
 
# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD
 
 
# 前処理完了
COMinit()

N, K = map(int,input().split())
mod = 10 ** 9 + 7

for blue in range(1, K+1):
  red = N - K
  b = COM(K-1, blue-1)
  r = COM(red + 1, blue)
  print(b * r % mod)

Measured memory_bytes: 63860
#include <stdio.h>
#include <stdlib.h>

void CountingSort(int *,int *,int,int);

int main(){
  int n,i,k;
  int *A;
  int *B;
  k=0;
  scanf("%d",&n);
  A = (int *)malloc(n*sizeof(int)+2);
  B = (int *)malloc(n*sizeof(int)+2);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
    if(k < A[i]) k = A[i];
  }

  CountingSort(A,B,n,k);

  for(i=1; i<=n; i++){
    if(i != 1 )printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}

void CountingSort(int A[],int B[],int n,int k){
  int i,j;
  int *C;
  C =(int *)malloc(k*sizeof(int)+1);

  for(i=0; i<=k; i++) C[i]=0;

  for(j=0; j<n; j++) C[A[j]]++;

  for(i=0; i<k; i++) C[i+1] += C[i];

  for(j=n-1; j>=0; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
}



Measured memory_bytes: 18272
using System;

namespace Atcoder_program_test_Csharp
{
    using System;
    class Program
    {
        static void Main(string[] args)
        {
            int S = int.Parse(Console.ReadLine());
            int A = S % 10;
            int B = S % 100 / 10;
            int C = S % 1000 / 100;
            int D = S / 1000;
            int count = 0;
            if (D == C)
            {
                Console.Write("Bad");
                count = count + 1;
            }
                if (C == B)
                {
                    if(count == 0)Console.Write("Bad");
                    count = count + 1;
                }
            if (B == A)
            {
                if (count == 0) Console.Write("Bad");
                count = count + 1;
            }
            if (count == 0) Console.Write("Good");
        }
    }
}

Measured memory_bytes: 13140
#!/usr/bin/env python3
 
import sys, math, bisect
sys.setrecursionlimit(300000)
 
 
def solve(N: int, D: int, A: int, X: "List[int]", H: "List[int]"):
    p = []
    for i in range(N):
        p.append([X[i], H[i]])
    p.sort()
    ret = 0
    idx = []
    val = []
    cur = 0
    nex = 0
    cum = 0
    minus = 0
    l = 0
    for i in range(N):
        v = cum
        while l < i and idx[l] < i:
            minus = val[l]
            l += 1
        v -= minus
        p[i][1] = max(0, p[i][1] - v * A)
        tmp = math.ceil(p[i][1] / A)
        ret += tmp
        x = p[i][0] + D
        while nex < N and p[nex][0] <= x + D:
            #$print('hogehoge')
            #$print(nex, p[nex][0], x + D)
            nex += 1
        cum += tmp
        idx.append(nex - 1)
        val.append(cum)
        #print(i)
        #print(idx)
        #print(val)
        #print('tmp ', tmp)
        #print(ret)
        #print(cum)
        #print()
    print(ret)
    return
 
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    H = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        H[i] = int(next(tokens))
    solve(N, D, A, X, H)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 119892
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        int i;
        int k = 360;
        int j = 1;

        Scanner sc = new Scanner(System.in);

        if (!sc.hasNextInt()) {
            System.err.println("整数を入力してください");
        }

        i = Integer.parseInt(sc.nextLine());

        if (1 <= i && i <= 179) {

            while (!((i * j) % k == 0)) {
                ++j;
            }
            System.out.println(j);
        } else {
            System.out.println("回転する角度は１～１７９の間で入力してください。");
        }
    }
}

Measured memory_bytes: 35756
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

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

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input) {
        initialize(n_input, f_input, e_input);
    }

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

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

    T get(int k) {
        return dat[k+n-1];
    }
    // [a, b)
    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    // [a, b)
    T _query(int a, int b, int k, int l, int r) {
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = _query(a, b, 2*k+1, l, (l+r)/2);
        T vr = _query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};
/** Usage:
Segtree<int> seg(n, [](int a, int b) {return max(a,b);}, 0); // init
REP(i, n+1) st.update(i, i)
st.query(a, b)
*/

struct node {
    bool s[26]={};
    int n = 0;
    node() {}
    node(char c) { s[c-'a']=1; n++;}
};

node add(node &a, node &b) {
    node n = node();
    for(int i=0; i<26; i++) {
        n.s[i] = a.s[i] | b.s[i];
        if(n.s[i]) n.n++;
    }
    return n;
}
const int N = 5e5+5;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    Segtree<node> seg(n, [](auto a, auto b) { return add(a,b); }, {});

    for(int i=0; i<(int)s.length(); i++) {
        seg.update(i, node(s[i]));
    }

    int Q;
    cin >> Q;
    while(Q--) {
        int t;
        cin >> t;
        if(t == 1) {
            int a;
            cin >> a;
            --a;
            char c;
            cin >> c;
            seg.update(a, node(c));
        } else {
            int a, b;
            cin >> a >> b;
            cout << seg.query(a-1, b).n << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 33692
N,W = gets.chomp.split(" ").map(&:to_i)
dp = Array.new(N+1).map{Array.new(N+1).map{Array.new(3*N,0)}}
wv = N.times.map{gets.chomp.split(" ").map(&:to_i)}
w1 = wv[0][0]
for i in 0..N-1
  wv[i][0] -= w1
end
for i in 1..N
  for j in 1..i
    for k in 0..wv[i-1][0]
      dp[i][j][k] = dp[i-1][j][k]
    end
    for k in wv[i-1][0]..3*N-1
      if j*w1+k <= W && dp[i-1][j][k] < dp[i-1][j-1][k-wv[i-1][0]]+wv[i-1][1]
        dp[i][j][k] = dp[i-1][j-1][k-wv[i-1][0]]+wv[i-1][1]
      else
        dp[i][j][k] = dp[i-1][j][k]
      end
    end
  end
end
ans = 0
dp[-1].each do |arr|
  arr.each do |v|
    ans = [ans,v].max
  end
end
p ans

Measured memory_bytes: 28668
// D - Sum of Large Numbers
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	ll MOD = 1'000'000'007;
	int N,K; cin>>N>>K;
	vector<ll> cnt(N+2);
	rp(i, 0, N+1) cnt[i+1] += cnt[i] + i;
	ll ans = 0;
	rp(k, K, (N+1)+1){
		ll mn = cnt[k];
		ll mx = cnt[N+1] - cnt[N+1-k];
		ans += mx - mn + 1;
		ans %= MOD;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 4800
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
using namespace std;
#define ll long long


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(c - (a - b), 0) << endl;
	return 0;
}

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

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

ll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)); return a; }

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

	ll x, k, d; cin >> x >> k >> d;

	ll rm = llabs(x);
	ll ht = rm / d;

	if (ht >= k)
	{
		if (x > 0) x -= k * d;
		else x += k * d;

		cout << llabs(x);

		return 0;
	}

	if (x > 0) x -= ht * d;
	else x += ht * d;

	k -= ht;
	if (k % 2)
	{
		if (x > 0) x -= d;
		else x += d;
	}

	cout << llabs(x);
}

Measured memory_bytes: 3660
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef vector<pii>vip;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 10000000;
ll divcnt[maxn];
void DivisorCount(){
    for(int i = 1; i<=maxn; i++){
        for(int j  = i; j<=maxn; j+=i){
            divcnt[j]++;
        }
    }
}

int main(){
        _
        DivisorCount();
        ll n; cin >> n;
        ll ans = 0;
        for(ll k  = 1; k<=n; k++){
            ans+=(k*divcnt[k]);
        }
        cout << ans << endl;

return 0;
}



Measured memory_bytes: 81776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n));
  REP(i, n) {
    REP(j, n) {
      cin >> a[i][j];
    }
  }
  vector<ll> dp(1 << n, 0);
  dp[0] = 1;
  REP(i, (1 << n)) {
    int k = __builtin_popcount(i);
    REP(j, n) {
      if (i & (1 << j)) {
        continue;
      }
      if (a[k][j] == 0) {
        continue;
      }
      dp[i | (1 << j)] += dp[i];
      dp[i | (1 << j)] %= MOD;
    }
  }
  cout << *(dp.rbegin()) << endl;
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 16640
#include<stdio.h>
#include<string.h>

int main(){
	int hi[110][60],i,j,a;
	
	memset(hi,0,sizeof(hi));
	i=0;
	j=0;
	while(0<=scanf(" %d",&hi[i][j])){
		++j;
		while(','==getc(stdin)){
			scanf("%d",&hi[i][j]);
			++j;
		}
		j=0;
		++i;
	}
	
	for(a=1;a*2<i;a++){
		hi[a][0]+=hi[a-1][0];
		for(j=1;j<60;j++){
			hi[a][j]=hi[a-1][j-1]>hi[a-1][j]?hi[a][j]+hi[a-1][j-1]:hi[a][j]+hi[a-1][j];
		}
	}
	
	for(;a<i;a++){
		for(j=0;j<59;j++){
			hi[a][j]=hi[a-1][j]>hi[a-1][j+1]?hi[a][j]+hi[a-1][j]:hi[a][j]+hi[a-1][j+1];
		}
	}
	
	for(a=100;;--a){
		if(hi[a][0]){
			printf("%d\n",hi[a][0]);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
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);
}
struct UnionFind
{
    vector<int> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

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

    int find(int k)
    {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k)
    {
        return (-data[find(k)]);
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};

int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind Friend(N), Block(N);
    //    vvint block = vvint(N), fr = vvint(N);
    vector<set<int>> block(N), fr(N);
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        Friend.unite(a, b);
        fr[a].insert(b);
        fr[b].insert(a);
    }
    rep(i, K)
    {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        //        Block.unite(c, d);
        block[c].insert(d);
        block[d].insert(c);
    }
    rep(i, N)
    {
        int num = 0;
        num = 1 + fr[i].size() + block[i].size() + N - Friend.size(i);

        for (auto j : block[i])
        {
            if (i != j and !Friend.same(j, i))
                num--;
        }
        cout << N - num << " ";
    }
    return 0;
}

Measured memory_bytes: 29824
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] cnt = new int[1_000_00 + 1];
		for (int i = 0; i < N; ++i) {
			++cnt[sc.nextInt()];
		}
		int distinct = 0;
		for (int i = 0; i < cnt.length; ++i) {
			if (cnt[i] > 0)
				++distinct;
		}
		if ((N - distinct) % 2 == 0) {
			System.out.println(distinct);
		} else {
			System.out.println(distinct - 1);
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


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

signed main(){
	int n; cin>>n;
  cout<<48-n;
	
	return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int Maxn=200000+10;
char s[Maxn];
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1),ans=0;
	for(int i=1;i<=n;++i)
	ans=(ans+s[i]-'0')%9;
	if(!ans)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3848
/*input
40
ferelibenterhominesidquodvoluntcredunt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	string s;
	ll k;
	cin>>k;
	cin>>s;
	if(s.length()<k+1)cout<<s<<endl;
	else {rep(i,0,k)cout<<s[i];cout<<"...\n";}
	return 0;
}




Measured memory_bytes: 3656
N = gets.to_i
CSF = (N-1).times.map{gets.split.map(&:to_i)}

ans = Array.new(N, 0)
(N-1).times do |i|
  a = 0
  (i...N-1).each do |j|
    c,s,f = CSF[j]
    a = s if a < s
    a += (f-(a-s))%f
    a += c
  end
  ans[i] = a
end
 
puts ans

Measured memory_bytes: 1788
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007


int N,M;
int H[100005];
bool isbad[100005];
signed main(){
    scanf("%lld %lld",&N,&M);
    rep(i,N){
        scanf("%lld",&H[i]);
    }
    rep(i,M){
        int a,b;
        scanf("%lld %lld",&a,&b);a--;b--;
        if(H[a]>=H[b])isbad[b]=true;
        if(H[a]<=H[b])isbad[a]=true;
    }
    int ans=0;
    rep(i,N){
        if(!isbad[i])ans++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2608
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000)
from collections import *

class FordFulkerson:
    def __init__(self, N, edges): #edges: (s, t, c) sからtに向かう容量cの有向辺
        self.N = N
        self.G = defaultdict(lambda : defaultdict(int))
        
        for s, t, cap in edges:
            self.G[s][t] = cap
        
    def dfs(self, v, t, f):
        if v==t:
            return f
        
        self.used[v] = True
        
        for nv, cap in self.G[v].items():
            if not self.used[nv] and self.G[v][nv]>0:
                d = self.dfs(nv, t, min(f, self.G[v][nv]))
                
                if d>0:
                    self.G[v][nv] -= d
                    self.G[nv][v] += d
                    
                    return d
        
        return 0
    
    def max_flow(self, s, t):
        flow = 0
        
        while True:
            self.used = [False]*self.N
            f = self.dfs(s, t, 10**18)
        
            if f==0:
                return flow
        
            flow += f

H, W = map(int, input().split())
a = [list(input()[:-1]) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if a[i][j]=='S':
            sx, sy = i, j
        
        if a[i][j]=='T':
            tx, ty = i, j

if sx==tx or sy==ty:
    print(-1)
    exit()
    
edges = []
edges.append((0, sx+1, 10**18))
edges.append((0, H+sy+1, 10**18))
edges.append((tx+1, H+W+1, 10**18))
edges.append((H+ty+1, H+W+1, 10**18))

for i in range(H):
    for j in range(W):
        if a[i][j]=='o':
            edges.append((i+1, H+j+1, 1))
            edges.append((H+j+1, i+1, 1))
    
ff = FordFulkerson(H+W+2, edges)
print(ff.max_flow(0, H+W+1))

Measured memory_bytes: 79476
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll w, a, b;
    cin >> w >> a >> b;
    ll ans = 0;
    if ((a <= b && b <= a + w) || (a <= b + w && b + w <= a + w))
    {
    }
    else
    {
        ans = min(abs(a + w - b), abs(b + w - a));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/**
 *    author:  zjsdut
 *    created: 2020/03/23 10:54:55
 **/
#include <bits/stdc++.h>

using namespace std;

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

template <typename A, typename B> bool chkmin(A &a, const B &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

template <typename A, typename B> bool chkmax(A &a, const B &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> istream &operator>>(istream &stream, vector<T> &vec) {
  for (auto &x : vec)
    stream >> x;
  return stream;
}

void scan() {}

template <class T, class... Args> void scan(T &a, Args &... rest) {
  cin >> a;
  scan(rest...);
}

using ll = long long;
using vl = vector<ll>;
using vb = vector<bool>;
using vi = vector<int>;
using pii = pair<int, int>;
template <typename T> using vv = vector<vector<T>>;
#define rng(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define up(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define down(i, b, a) for (int i = int(b); i >= int(a); i--)
#define TOKENPASTE(x, y) x##y
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
#define rep(n)                                                                 \
  for (int TOKENPASTE2(_iter_, __LINE__) = 0,                                  \
                               TOKENPASTE2(_num_, __LINE__) = (int)(n);        \
       TOKENPASTE2(_iter_, __LINE__) < TOKENPASTE2(_num_, __LINE__);           \
       ++TOKENPASTE2(_iter_, __LINE__))
#define FOR(x, cont) for (const auto &x : cont)
#define For(x, cont) for (auto &x : cont)
#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define SZ(x) (int)(x).size()
#define UNIQ(vec) (vec).erase(unique(all(vec)), end(vec))
#define LB(cont, x) int(lower_bound(all(cont), x) - begin(cont))
#define UB(cont, x) int(upper_bound(all(cont), x) - begin(cont))

template <typename T>
ostream &operator<<(ostream &stream, const vector<T> &vec) {
  if (!vec.empty()) {
    stream << vec[0];
    for (size_t i = 1; i != vec.size(); ++i)
      stream << ' ' << vec[i];
  }
  return stream;
}

template <typename T> void print(const vector<T> &t) { cout << t << '\n'; }

template <typename T> void print(const vector<vector<T>> &t) {
  for (const auto &row : t) {
    print(row);
  }
}

template <typename T> void print(const T &t) { cout << t << ' '; }

template <typename T, typename... Args>
void print(const T &t, const Args &... rest) {
  print(t);
  print(rest...);
}

template <typename T> void println(const T &t) { cout << t << '\n'; }

template <typename T, typename... Args>
void println(const T &t, const Args &... rest) {
  print(t);
  println(rest...);
}

int main() {
#if defined LOCAL && !defined DUIPAI
  ifstream in("in.txt");
  cin.rdbuf(in.rdbuf());
#endif
  int n;
  scan(n);
  vi a(n); scan(a);
  vi cnt(n + 1);
  ll sum = 0;
  FOR (x, a) {
    cnt[x]++;
  }
  FOR (x, cnt) {
    sum += 1ll * x * (x - 1) / 2;
  }
  FOR (x, a) {
    println(sum - (cnt[x] - 1));
  }
  return 0;
}

Measured memory_bytes: 4224
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;


string s[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
string t;

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

	cin >> t;

	for (int i = 0; i < 7; i++)
		if (s[i] == t) return cout << 7 - i << '\n', 0;
}


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

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> v(n), c(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 0; i < n; i++) if (v[i] - c[i] > 0) ans += v[i] - c[i];
  cout << ans << "\n";
}

Measured memory_bytes: 384
n, m = gets.split.map(&:to_i)
shop = []
ans  = 0

n.times do
  shop << gets.split.map(&:to_i)
end
shop.sort!

while m > 0
  if m >= shop[0][1]
    ans += shop[0][0] * shop[0][1]
    m   -= shop[0][1]
    shop.shift
  else
    ans += shop[0][0] * m
    break
  end
end

puts ans


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, m;
int a[5000];
LL sum[5000];
int b[5000][200];
int st[13][5000][200];
int lg[5001];

void stBuild() {
    int cur = 0;
    for (int i = 1; i <= 5000; ++i) {
        while ((2 << cur) < i) {
            ++cur;
        }
        lg[i] = cur;
    }
    forn(i, n) forn(j, m) {
        st[0][i][j] = b[i][j];
    }
    forn(i, 12) {
        forn(j, n - (2 << i) + 1) forn(k, m) {
            st[i + 1][j][k] = max(st[i][j][k], st[i][j + (1 << i)][k]);
        }
    }
}

int stGet(int from, int to, int pos) {
    int len = lg[to - from + 1];
    return max(st[len][from][pos], st[len][to - (1 << len) + 1][pos]);
}

LL ans = 0;

void solve(int from, int to, int lo, int hi) {
    if (from > to) {
        return;
    }
    int mid = (from + to) >> 1;
    int _lo = lo;
    lo = max(lo, mid);
    int bb[m];
    LL cur = 0;
    forn(i, m) {
        bb[i] = stGet(mid, lo, i);
        cur += bb[i];
    }
    cur -= sum[lo] - sum[mid];
    LL best = cur;
    int bestInd = lo;
    for (int ind = lo + 1; ind <= hi; ++ind) {
        forn(i, m) {
            if (b[ind][i] > bb[i]) {
                cur += b[ind][i] - bb[i];
                bb[i] = b[ind][i];
            }
        }
        cur -= a[ind - 1];
        if (cur > best) {
            best = cur;
            bestInd = ind;
        }
    }
    ans = max(ans, best);
    solve(from, mid - 1, _lo, bestInd);
    solve(mid + 1, to, bestInd, hi);
}

int main() {
    //freopen("input.txt", "r", stdin);
    scanf("%d%d", &n, &m);
    sum[0] = 0;
    forn(i, n - 1) {
        scanf("%d", a + i);
        sum[i + 1] = sum[i] + a[i];
    }
    forn(i, n) forn(j, m) {
        scanf("%d", b[i] + j);
    }
    stBuild();
    solve(0, n - 1, 0, n - 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 48640
s = input()
s += "?"
for i in range(len(s)-2):
    if len(set(list(s[i:i+3]))) < 3:
        if i == len(s)-3:
            print(i+1,i+2)
        else:
            print(i+1, i+3)
        exit()
print(-1, -1)

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

int main(){
    int H , W, i, j;

    for( ; ; ){
        cin >> H >> W;

        if (H == 0 && W == 0) break;

        for (j = 0; j < H ; j++){

            for (i = 0; i < W ; i++ ){
            cout << "#" ;
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3012
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define ll long long
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define in(a) a=read()
#define out(a) printf("%lld\n",a)
ll read(){
    ll f=1,x=0;char c=getchar();
    while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
#define maxn 200010
ll a[maxn];
int main(){
	int n;
	in(n);
	FOR(i,1,n){
		in(a[i]);
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	ll b=a[(n+1)/2];
	ll ans=0;
	FOR(i,1,n)ans+=abs(a[i]-b);
	out(ans);
}


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

#define inf 1e9 + 1
#define ll long long int
using namespace std;

int knapsac2(ll *w, ll *v, ll maxW, ll n){
    ll maxVal = 1000*n;   //its the maximum value that we can get as 0<=v[i]<=1000 and there ar n elements
    ll dp[n+1][maxVal+1]; // here we are thinking of dp state as what is in minimum knapsac weight how we can get exactly v value

    //Now base case
    for(int i=0;i<=maxVal;i++){
        dp[1][i] = inf;     //as this dp[1][i] means that we want exaclty 1 value but taking atmost 1 element
                            // so this is not possible as it by thaking a single element we have only 1 option of taking first element or not 
    }
    // not taking first element
    dp[1][0] = 0;
    //taking first element
    dp[1][v[1]] = w[1];  

    //now fill full dp table
    // i iterates over number of element that can be taken atmost
    for(int i=2;i<=n;i++){
        // v iterates over to get that value in knapsac with i elements subset
        for(int val=0;val<=maxVal;val++){
            dp[i][val] = dp[i-1][val];    //first case not taking the current element 
            // value of current element is greater than the max value which which we can include that is val
            if(v[i]> val){
                continue;  //then continue
            }
            // by including we have to add weight of the element and subtract the value of that element
            // minimum in this case because we want to minimize the weight of knapsac
            //here we are filling dp table with the value of knapsac weight 
            dp[i][val] = min(dp[i][val], w[i]+ dp[i-1][val-v[i]]);
        }
    }

    // getting the answer to given problem containing n elements
    // interating over the last row and checking if cell is less than maxW
    // then take that value
    ll ans = 0;
    for(int i=0;i<=maxVal;i++){
        if(dp[n][i] <=maxW){
            ans = i;
        }
    }

    return ans;
}

int main() {
    ll n, mW;
    cin >> n >> mW;

    //1 indexed arrays
    ll *w = new ll[n+1];
    ll *v = new ll[n+1];
    for(int i=1;i<=n;i++){
        cin >> w[i] >> v[i];
    }
    
    cout << knapsac2(w, v, mW, n) << endl;
}


Measured memory_bytes: 81732
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 1000000009
using P = pair<int,int>;
 
int main() {
  #define int long long
  int n,m,k;
  cin >> n >> m >> k;
  bool flag = false;
  erep(i,n) erep(j,m){
    int ans = i*(m-j) + j*(n-i);
    if(ans == k){
      flag = true;
      break;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
} 

Measured memory_bytes: 256