akhauriyash/Code-Regression huggingface dataset:
N = int(input())
LS = [int(i) for i in input().split()]

cnt = 0
for idxi, i in enumerate(LS):
  for idxj, j in list(enumerate(LS))[idxi+1:]:
    for k in LS[idxj+1:]:
      if i != j and j != k and i != k:
        m = max(i, j, k)
        l = sum([i, j, k]) - m
        if l > m:
          cnt += 1

print(cnt)


Measured memory_bytes: 9188
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    V<double> p(n); REP(i, n) cin >> p[i];
    V< V<double> > dp(n+1, V<double>(n+1, 0));
    dp[0][0] = 1.0;
    rep(i, 1, n+1) {
        REP(j, n+1) {
            dp[i][j] = dp[i-1][j]*(1-p[i-1]) + dp[i-1][j-1]*p[i-1];
        }
    }
    double sum = 0.0;
    rep(i, (n+1)/2, n+1) sum += dp[n][i];
    cout << fixed << setprecision(12) << sum << '\n';
    return 0;
}


Measured memory_bytes: 70784
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

VI aa, a, unzip(100010);
unordered_map<int, int> zip;
int n;
VI compress() {
  a = aa;
  sort(ALL(aa));
  aa.erase(unique(ALL(aa)), aa.end());
  REP(i, aa.size()) {
    zip[aa[i]] = i;
    unzip[i] = aa[i];
  }
  REP(i, a.size()) {
    a[i] = zip[a[i]];
  }
  return a;
}

int b[100010];
int c[100010];
signed main(void)
{
  cin >> n;
  REP(i, n) {
    int tmp;
    cin >> tmp;
    b[i] = tmp;
    aa.PB(tmp);
  }
  compress();
  sort(ALL(a));

  int ret = 0;
  REP(i, n) {
    // cout << b[i] << " " << zip[b[i]] << " " << c[zip[b[i]]] << endl;
    if(zip[b[i]]%2 != i%2) ret++;
  }
  cout << ret/2 << endl;

  return 0;
}


Measured memory_bytes: 6288
h, w = map(int, input().split())
al = list(list(input()) for _ in range(h))
row = [False] * w
col = [False] * h

for i in range(h):
    for j in range(w):
        if al[i][j] == '#':
            col[i] = True
            row[j] = True
ans = []
w_len = len(row) - row.count(False)
for i in range(h):
    tmp = ''
    if col[i]:
        for j in range(w):
            if row[j]:
                tmp += al[i][j]
        ans.append(tmp)

for a in ans:
    print(*a, sep='')

Measured memory_bytes: 4468
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

//������԰
char field[105][105];
int dx[4] = {-1,0,1,0},dy[4] = {0,-1,0,1};
int res = 0;
int M,N;
void dfs(int x, int y){
    char c = field[x][y];
    field[x][y] = ' ';
    for(int m = 0; m < 4; m++){
        int a = x+dx[m];
        int b = y + dy[m];
        if(a>0&&b>0&&a<=M&&b<=N){
            if(field[a][b] == c) {

                dfs(a,b);
            }
        }
    }
    return ;
}
int main()
{   while(cin>>M>>N){
    if(M==0||N==0) break;
    for(int i = 1;i <=M;i++){
        for(int j = 1;j <= N;j++){
            cin>>field[i][j];
        }
    }
    for(int i = 1;i <= M;i++){
        for(int j = 1;j <= N;j++){
            if(field[i][j] != ' ') {
                dfs(i,j);
                field[i][j] = '0';
                }
            }
        }

    for(int i = 1;i <= M;i++){
        for(int j = 1;j <= N;j++){
            if(field[i][j] == '0') res++;
            //cout<<field[i][j];
        }
        //cout<<endl;
    }
    cout<<res<<endl;
    res = 0;
}
      return 0;
}



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


int main()
{
  int a1,a2,a3;
  cin >> a1 >> a2 >> a3;

  if(a1+a2+a3>21)  cout<<"bust";
  else cout<<"win";
      
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define SIZE 11
int mat[SIZE][SIZE], visited[SIZE], COUNT;

bool isVisited(int M) {
    for (int i = 1; i <= M; i++) if (not visited[i]) return false;
    return true;
}

void DFS (int next, int N, int M) {
    if (next > N) {
        if (isVisited(M)) COUNT++;
        return;
    }

    DFS(next+1, N, M);
    for (int i = 1; i <= M; i++) visited[i] ^= mat[next][i];
    DFS(next+1, N, M);
}

int main(){
    int N, M; cin >> N >> M; int k;
    for (int i = 1; i <= M; i++){
        cin >> k; int s;
        while (k--) cin >> s, mat[s][i] = 1;
    }

    for (int i = 1; i <= M; i++){
        int p; cin >> p; visited[i] = not p;
    }

    DFS(1, N, M);
    cout << COUNT << endl;

    return 0;
}


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

int main()
{
  int N;
  int count=1;
  cin >> N;
  vector<string> A(N);
  vector<string> chk(N);
  for(int i=0; i<N; i++)
  {
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  if(N==1)
  {

  }
  else
  {
  for(int i=0; i<N-1; i++)
  {
    if(A.at(i)==A.at(i+1))
    {

    }
    else
    {
      count++;
    } 
  }
  }
  cout << count << endl;
}

Measured memory_bytes: 15620
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int q = scanner.nextInt();
        int h = scanner.nextInt();
        int s = scanner.nextInt();
        int d = scanner.nextInt();
        int n = scanner.nextInt();

        long min1 = Math.min(q * 4L, Math.min(h * 2L, s));
        long min2 = Math.min(min1 * 2L, d);
        System.out.println(n / 2 * min2 + (n & 1) * min1);
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007

bool prime_judge(int A)
{
  for (int i = 2; i <= sqrt(A); i++)
  {
    if(A%i == 0) return true;
  }

  return false;
  
  
}


void solve(void)
{ 
  int A,B;
  cin>>A>>B;
  if(A+B == 3)
  {
    cout<<3<<endl;
  }
  else if(A+B == 4)
  {
    cout<<2<<endl;
  }
  else
  {
    cout<<1<<endl;
  }
  
  return;  
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 256
def inverse(a, mod):
    a %= mod
    p = mod
    x, y = 0, 1
    while a > 0:
        n = p // a
        p, a = a, p % a, 
        x, y = y, x - n * y
    return x % mod

def power(x, n, mod):
    ans = 1
    while n > 0:
        if n % 2 == 1:
            ans = ans * x % mod
        n //= 2
        x = x * x % mod
    return ans

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
ans = power(2, n, mod)
nCa = 1
for i in range(a):
    nCa = nCa * inverse(i + 1, mod) % mod * (n - i) % mod
nCb = 1
for i in range(b):
    nCb = nCb * inverse(i + 1, mod) % mod * (n - i) % mod
ans = (ans - nCa - nCb - 1) % mod
print(ans)

Measured memory_bytes: 73716
#include <iostream>

using namespace std;

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

    int a, b, c; cin >> a >> b >> c;
    int d, e;
    if(c == 1e9) d = 1e9, e = 1;
    else d = c, e = 1e9;

    for(int i = 0; i < b; ++i) cout << d << ' ';
    for(int i = b; i < a; ++i) cout << e << ' ';
}


Measured memory_bytes: 1280
#include <stdio.h>
int main(void){
    int n,i,a,min=1000000,max=0;
    double sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        if(i==0){
            min=a;
            max=a;
        }
        if(min>a){
            min=a;
        }
        if(max<a){
            max=a;
        }
        sum=sum+a;
    }
    printf("%d %d %.0lf\n",min,max,sum);
    return 0;
}

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

int n;
string s;

int main(){
  cin >> n >> s;
  s.push_back('X');
  int res = 0;
  rep(i, n){
    if(s[i] != s[i + 1]) res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 512
a,b,c=map(int,input().split())
cnt=0
if a%2==1 or b%2==1 or c%2==1:
    print(0)
    exit()
elif a==b==c:
    print(-1)
    exit()
else:
    while a%2==0 and b%2==0 and c%2==0:
        a,b,c=b//2+c//2,a//2+c//2,a//2+b//2
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i,n){
		char c;
		cin >> c;
		if(c == 'Y'){
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int gcd(int a, int b)
{
    if (b == 0)
        return a;

    return gcd(b, a % b);
}

int N;
int A[101010];

int main()
{
    cin >> N;
    rep(i, 0, N)
    {
        cin >> A[i];
    }
    ll ans = gcd(A[0], A[1]);
    rep(i, 2, N)
    {
        ans = gcd(ans, A[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
"""Counting Sort."""

def countingSort(A, B, k):
    """Sort the elements of list A with Counting Sort algorithm.

    n is the length of A.
    The elements of A are intergers between 0 and k, inclusive.
    B is the output list where the sorted elements will be arranged.
    
    Print the elements of B in a line separated by a space character.
    """

    C = [0 for i in range(k + 1)]

    for i in A:
        C[i] += 1

    for i in range(1, k + 1):
        C[i] = C[i] + C[i - 1]
    
    for i in A[::-1]:
        B[C[i]] = i
        C[i] -= 1

    print(*B[1:])


n = int(input())

A = list(map(int, input().split()))

B = [0 for i in range(n + 1)]

k = max(A)

countingSort(A, B, k)

Measured memory_bytes: 230796
import java.math.BigDecimal

const val mod: Long = 1000000007L

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toLong() }
    val arr = readLine()!!.split(" ").map { it.toInt() }
    val leftCnt: Array<Long> = Array(n.toInt()) { 0L }
    for (i in 0 until arr.size) {
        var count = 0
        for (j in i + 1 until arr.size) {
            if (arr[i] > arr[j]) {
                count++
            }
        }
        leftCnt[i] = count.toLong()
    }
    val cnt = arr.map { i ->
        arr.filter { i > it }.count()
    }
    var ans = BigDecimal.ZERO
    val kk = (k*(k-1)/2) % mod
    ans += BigDecimal.valueOf(cnt.sum().toLong()) * BigDecimal.valueOf(kk) % BigDecimal.valueOf(mod)
    ans += BigDecimal.valueOf(leftCnt.sum() * k % mod)
    println(ans % BigDecimal.valueOf(mod))
}

Measured memory_bytes: 44656
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  vector <int> q(n);
  for (int i = 0; i < n; i++) {
    cin >> q[i];
    q[i]--;
  }
  auto f = [&] (vector <int> t) {
    int ans = 0;
    while (prev_permutation(t.begin(), t.end())) {
      ans++;
    }
    return ans;
  };
  cout << abs(f(p) - f(q)) << '\n';
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

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

    bool flag = true;
    for (size_t i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (a%2==0)
        {
            flag &= (a%3==0)||(a%5==0);
        }
    }
    

    string ans = flag ? "APPROVED" : "DENIED";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
 
//const int MOD=998244353;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    vector<string> v(n);
    for(auto&s:v) cin>>s;
    
    vector<int> lab(n,-1);
    
    queue<int> q;
    q.push(1);
    lab[1]==1;
    while(q.size()){
        int cur=q.front();
        q.pop();
        for(int j=0; j<n; j++){
            if(v[cur][j]=='1'){
                if(lab[j]==-1){
                    lab[j]=!lab[cur];
                    q.push(j);
                }
                if(lab[j]==lab[cur]){
                    cout<<-1;
                    return 0;
                }
            }
        }
    }
    vector<vector<int>> d(n,vector<int>(n,2*n));
    
    for(int i=0; i<n; i++) d[i][i]=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(v[i][j]=='1') d[i][j]=1;
        }
    }
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(d[i][j]>d[i][k]+d[k][j]){
                    d[i][j]=d[i][k]+d[k][j];
                }
            }
        }
    }
    int ans=0;
    for(int i=0; i<n; i++){
        ans=max(ans,*max_element(d[i].begin(),d[i].end())+1);
    }
    
    cout<<ans;
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 556
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
 ll D,N;
  in(D>>N);
 if(N==100){
 if(D==0)out(101);
 if(D==1)out(10100);
  if(D==2) out(1010000);
 }
  else if(D==0) out(N);
  else if(D==1) out(N*100);
  else if(D==2) out(N*10000);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int N=10010;
int h,w,n,a[N],cnt,b[110][110];
int main()
{
    ios::sync_with_stdio(false);
    cin>>h>>w>>n;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    cnt=1;
    for(int i=1;i<=h;++i)
    {
        for(int j=1;j<=w;++j)
        {
            if(a[cnt]==0) ++cnt;
            --a[cnt];
            if(i%2)
                b[i][j]=cnt;
            else
                b[i][w-j+1]=cnt;
        }
    }
    for(int i=1;i<=h;++i)
    {
        for(int j=1;j<=w;++j)
            cout<<b[i][j]<<' ';
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		arr[i] = tmp
	}
	dp := make([]int, n)
	dp[0] = 0
	dp[1] = abs(arr[0] - arr[1])
	for i := 1; i < n - 1; i++ {
		dp[i + 1] = min1(dp[i] + abs(arr[i + 1] - arr[i]), dp[i - 1] + abs(arr[i + 1] - arr[i - 1]))
	}
	fmt.Println(dp[len(dp) - 1])
}

func min1(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

Measured memory_bytes: 5504
#include <stdio.h>
int main()
{
	int a,b,c,d,e,f,g,h,l,m,n,o,sum,i;
	scanf("%d%d%d",&a,&b,&c);
	sum=0;
	for(i=1;i<=a;i++)
	{
		if(i<10)
			if(i>=b&&i<=c)
			sum=sum+i;
			if(i==10)
			{if(1>=b)
			sum=sum+i;
			}
				if(i>10&&i<100)
				{d=i%10;
				e=i/10;
					{if(d+e>=b&&d+e<=c)
					sum=sum+i;
					}
				}
						if(i>=100&&i<1000)
						{f=i%10;
						g=i%100/10;
						h=i/100;
							if(f+g+h<=c&&f+g+h>=b)
							sum=sum+i; } 
							if(i<10000&&i>=1000)
								{l=i%10;
								m=i%100/10;
								n=i%1000/100;
								o=i/1000;                             
								if(l+m+n+o<=c&&l+m+n+o>=b)
								sum=sum+i;} 
								if(i==10000)
								{if(1>=b)
								sum=sum+i;
								} 
                                   
							
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
// C - Pyramid
#include <bits/stdc++.h>
using namespace std;
using TP = tuple<int,int,int>;
using VT = vector<TP>;
#define rp(i,n) for(int i=0;i<(n);i++)
#define eb(x,y,h) emplace_back((x),(y),(h))
#define manhattan(x1,y1,x2,y2) (abs((x1)-(x2))+abs((y1)-(y2)))
#define XMAX 100
#define YMAX 100

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

	VT A;
	rp(i, N){
		int x,y,h; cin>>x>>y>>h;
		A.eb(x,y,h);
	}

	rp(y0, YMAX+1){
		rp(x0, XMAX+1){

			int x,y,h;
			rp(i, N){
				tie(x,y,h) = A[i];
				if(h > 0) break;
			}

			int h0 = h + manhattan(x0,y0, x,y);

			bool exist = true;
			rp(i, N){
				tie(x,y,h) = A[i];
				if(h <= 0) continue;
				if(h0 != h + manhattan(x0,y0, x,y)){
					exist = false;
					break;
				}
			}
			if(!exist) continue;

			rp(i, N){
				tie(x,y,h) = A[i];
				if(h > 0) continue;
				if(h0 - manhattan(x0,y0, x,y) > 0){
					exist = false;
					break;
				}
			}
			if(exist){
				cout<<x0<<" "<<y0<<" "<<h0<<"\n";
				return 0;
			}

		}
	}

}

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

const int mod = 998244353;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> l(k), r(k);
    rep(i, k) cin >> l[i] >> r[i];
    vector<mint> dp(n), sdp(n + 1);
    dp[0] = 1;
    sdp[1] = dp[0];
    for (int i = 1; i < n; i++)
    {
        rep(j, k)
        {
            int left = i - r[j];
            int right = i - l[j] + 1;
            left = max(left, 0);
            right = max(right, 0);
            dp[i] += sdp[right] - sdp[left];
        }
        sdp[i + 1] = sdp[i] + dp[i];
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 6352
codes = [
    [],
    list('.,!? '),
    list('abc'),
    list('def'),
    list('ghi'),
    list('jkl'),
    list('mno'),
    list('pqrs'),
    list('tuv'),
    list('wxyz'),
]

n = int(input())
for _ in range(n):
    s = input()
    i = None
    cnt = 0
    ans = ''
    for si in list(s):
        sii = int(si)
        if sii == 0:
            if i is not None:
                ans += codes[i][cnt % len(codes[i])]
            i = None
        else:
            if i != sii:
                i = sii
                cnt = 0
            else:
                cnt += 1
    print(ans)


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}

template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}

template <typename T> void print(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void print(const T &value, const Args&... args){std::cout << value << " ";print(args...);}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N;

  while(cin >> N){
    vector<int> A(N+1); cin >> A;

    bool ok = true;
    i64 ans = 0;

    vector<i64> MAX(N+1);

    i64 x = 1;
    FORE(i,0,N){
      if(x < A[i]){
        ok = false;
        break;
      }
      
      MAX[i] = x;

      x -= A[i];
      if(x <= 1e15) x *= 2;
    }
    
    i64 t = 0;
    REV(i,N,0){
      i64 a = (t + 1) / 2;
      i64 b = min(t, MAX[i]);

      if(MAX[i] - A[i] < a){
        ok = false;
        break;
      }
      
      ans += t;

      t = min(MAX[i], b + A[i]);
    }

    ans += t;

    if(ok){
      print(ans);
    }else{
      print(-1);      
    }
  }
  
  return 0;
}


Measured memory_bytes: 4516
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
////////////////////////////////////////////////
int main()
{
    int n, m;
    cin >> n >> m;
    int day = 0;
    rep(i, m)
    {
        int a;
        cin >> a;
        day += a;
    }
    if (day <= n)
        cout << n - day << endl;

    else
        cout << -1 << endl;
}

Measured memory_bytes: 3636
use proconio::input;
use std::cmp;
fn main() {
    input!(n: usize, m: usize, x: i32, a: [[i32; m + 1]; n],);
    let mut ans = i32::max_value();
    for i in 0..(1 << n) {
        let mut cost = 0;
        let mut sum = vec![0; m];
        for j in 0..n {
            if ((i >> j) & 1) == 0 {
                continue;
            }
            cost += a[j][0];
            for k in 0..m {
                sum[k] += a[j][k + 1];
            }
        }
        if sum.iter().all(|&a| a >= x){
            ans = cmp::min(ans, cost);
        }
    }
    if ans != i32::max_value() {
        println!("{}", ans);
    } else {
        println!("-1");
    }
}


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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
    ll n; cin >> n;
    ll ans = 0;

    vector<ll> p = {};
    vector<ll> q = {};

    for(int i = 2; i<=1000000; i++){
        bool isPrime = true;
        int j = 0;
        while(j < (int)p.size() && p[j]*p[j] <= i){
            if(i % p[j] == 0) isPrime = false;
            j++;
        }
        if( isPrime ) {
            ll k = i;
            p.push_back(i);
            while(k <= 1000000000000){
                q.push_back(k);
                k *= i;
            }
        }
    }
    sort(q.begin(),q.end());

    rep(i,0,(int)q.size()){
        if(n % q[i]  == 0){
            n /= q[i];
            ans++;
            //cout << n  << " " << q[i]<< "\n";
        }
    }
    if(n > 1000000) cout << ans+1 << "\n";
    else cout << ans << "\n";
} 


Measured memory_bytes: 6260
# region header
import sys
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos, pi, e
from operator import itemgetter
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
S = rs()
N = len(S)
if N > 1:
    for i in range(N - 1):
        if S[i] == S[i + 1]:
            print('Bad')
            exit()
print('Good')


Measured memory_bytes: 63084
import java.util.*;
public class Main { 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			String a = stdIn.next();
			if(a.equals("#")) break;
			if(a.length() == 5) {
				System.out.println(0);
				continue;
			}
			if(a.length() == 4) {
				System.out.println(90);
				continue;
			}
			int b = 0;
			int c = 1;
			
			int d = a.length()-1;
			if(a.charAt(d) == 'h') {
				d-= 5;
			}
			else {
				d-=4;
				b = 90;
			}
			
			while(true) {
				if(d <= 0) break;
				c = c << 1;
				if(a.charAt(d) == 'h') {
					d -= 5;
					b = 2 * b - 90;
					continue;
				}
				else {
					d -= 4;
					b = 2 * b + 90;
					continue;
				}
			}
			
			int gcd = gcd(b,c);
			if(b % c == 0) {
				System.out.println(b / c);
			}
			else {
				System.out.println(b/gcd + "/" + c/gcd);
			}
		}
	}
	
	public static int gcd(int b, int c) {
		
		if(c == 0) return b;
		return gcd(c,b%c);
	}
}

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

const long long inf  = 1e12;
vector <long long> A, dp, au;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	A.resize(n);
	dp.resize(n);
	au.resize(n);
	for (int i = 0; i < n; i++){
		cin >> A[i];
	}
	dp[0] = A[0];
	au[0] = -1 * A[0];
	for (int i = 1; i < n; i++){
		dp[i] = max(au[i - 1], dp[i - 1]) + A[i];
		au[i] = max(au[i - 1] + 2 * A[i - 1], dp[i - 1] - 2 * A[i - 1]) - A[i];
		if (i == 1){
			dp[i] = dp[0] + A[1];
			au[i] = au[0] - A[1];
		}
		// cout << i << ' ' << dp[i] << ' ' << au[i] << '\n';
	}
	cout << max(dp[n - 1], au[n - 1]);
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;



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

  int a, b;

  cin >> a >> b;
  
  if(a % 2 == 0 || b % 2 == 0){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+10;
using namespace std;
inline ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
inline ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline void umax(ll &p,ll q){if(p<q)p=q;}
inline void umin(ll &p,ll q){if(p>q)p=q;}
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k,t;
int main()
{
    int i,j;
    scanf("%d",&n);
    rep(i,1,n){scanf("%d",&j);if(j&1)t++;}
    puts(t&1?"NO":"YES");
    return 0;
}


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

typedef long long ll;

const int Maxn = 305;
const ll Inf = 1000000000000000000ll;

int n, m, L;
ll dist[Maxn][Maxn];
ll res[Maxn][Maxn];

int main()
{
    scanf("%d %d %d", &n, &m, &L);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            dist[i][j] = (i != j) * Inf;
    for (int i = 0; i < m; i++) {
        int a, b, c; scanf("%d %d %d", &a, &b, &c);
        if (c < dist[a][b])
            dist[a][b] = dist[b][a] = c;
    }
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            res[i][j] = dist[i][j] <= L? 0: Inf;
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                res[i][j] = min(res[i][j], res[i][k] + 1 + res[k][j]);
    int q; scanf("%d", &q);
    while (q--) {
        int a, b; scanf("%d %d", &a, &b);
        if (res[a][b] >= Inf) printf("-1\n");
        else printf("%lld\n", res[a][b]);
    }
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a1, a2, a3, b1, b2, b3;
    int a11, a12, a13;
    int a21, a22, a23;
    int a31, a32, a33;
    scanf("%d%d%d%d%d%d%d%d%d", &a11, &a12, &a13, &a21, &a22, &a23,&a31, &a32, &a33);
    
    a1 = 0;
    b1 = a11 - a1;
    b2 = a12 - a1;
    b3 = a13 - a1;
    
    int ta2 = a21 - b1;
    int tta2 = a22 - b2;
    int ttta2 = a23 - b3;
    if (!(ta2 == tta2 && tta2 == ttta2)) {
        printf("No");
        return 0;
    }
    int ta3 = a31 - b1;
    int tta3 = a32 - b2;
    int ttta3 = a33 - b3;
    if (!(ta3 == tta3 && tta3 == ttta3)) {
        printf("No");
        return 0;
    }
    printf("Yes");
    
    return 0;
}


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

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

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

int main()
{
    ll N;
    cin >> N;
    vec H(N);
    REP(i,0,N) cin >> H[i];
    
    ll cnt = 0;
    vec C(N);
    reverse(ALL(H));
    REP(i,0,N-1) {
        C[i] = cnt;
        if(H[i] <= H[i+1]) ++cnt;
        else cnt = 0;
    }
    C[N-1] = cnt;
    ll m = 0;
    REP(i,0,N) m = MAX(m,C[i]);
    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-3;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;

ll dp[10001][100];
string k; int d;
void init() {
	dp[0][0] = 1;
	rep(i, 10000) {
		rep(j, d) {
			rep(k, 10) {
				(dp[i + 1][(j + k) % d] += dp[i][j]) %= mod;
			}
		}
	}
}
int main() {
	cin >> k >> d;
	init();
	int n = k.length();
	ll ans = 0; int sum = 0;
	rep(i,n){
		int t = k[i] - '0';
		rep(j, t) {
			int csum = sum + j; csum %= d; csum = (d - csum) % d;
			ans += dp[n - i - 1][csum]; ans %= mod;
		}
		sum += t; sum %= d;
	}
	if (sum == 0)ans++;
	cout << (ans-1+mod)%mod << endl;
	//stop
	return 0;
}

Measured memory_bytes: 8064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){

  int A,B,minN= 100000,res,digA,digB;
  int N;
  cin >> N;
  for(int i = 2; i <= N/2+1  ;i++){
    res = 0;
    A = i;
    B = N - i;
      while(A || B){
      digA = A % 10;
      digB = B % 10;
      res += digA + digB;
      A = A / 10;
      B = B / 10;
    }
    //if(res == 4) cout << i <<","<< (N-i)<<endl;
    minN = min(res,minN);
  }
  cout << minN << endl;
  return 0;
}


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

struct Process{
  char name[100];
  int time;
};

int top = 0; // 最後尾
int bottom = 0; // 先頭-1
const int SIZE = 1000000;
Process Q[SIZE];

Process pop() {
  if (bottom < SIZE-1) bottom++;
  else bottom = 0;
  return Q[bottom];
}

void push(Process pro) {
  if (top < SIZE-1) top++;
  else top = 0;
  Q[top] = pro;
}

bool isEmpty(){
  if (top == bottom) return true;
  else return false;
}

int main() {
  // 読み込み
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i=0; i<n; i++) {
    Process pro;
    scanf("%s", pro.name);
    scanf("%d", &pro.time);
    push(pro);
  }
  // 処理
  int count = 0;
  while (! isEmpty()) {
    Process pro = pop();
    if (pro.time>q) {
      count += q;
      pro.time -= q;
      push(pro);
    }
    else {
      count += pro.time;
      printf("%s %d\n", pro.name, count);
    }
  }
}


Measured memory_bytes: 22320
// https://atcoder.jp/contests/abc126/tasks/abc126_c

#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define ld long double
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    ld base = 1.0/N;
    ld tot = 0;
    for(int i = 1; i <= N; i++) {
        int cur = i;
        int flip = 0;
        while(cur < K) {
            cur*=2;
            flip++;
        }

        tot += base * (pow(0.5, flip));
    }
    cout << setprecision(420) << tot << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <iomanip>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
    int a[9];
    for (int i=0;i<9;++i){
        cin>>a[i];
    }
    int n;
    cin>>n;
    bool b[9]={};
    for (int i=0;i<n;++i){
        int z;
        cin>>z;
        auto f=find(a,a+9,z);
        if (f!=a+9){
            b[f-a]=true;
        }
    }
    for (int i=0;i<3;++i){
        if (b[0+i*3]&&b[1+i*3]&&b[2+i*3]){
            cout<<"Yes";
            return 0;
        }
        if (b[i+0*3]&&b[i+1*3]&&b[i+2*3]){
            cout<<"Yes";
            return 0;
        }
    }
    if (b[0+0*3]&&b[1+1*3]&&b[2+2*3]){
        cout<<"Yes";
        return 0;
    }
    if (b[2+0*3]&&b[1+1*3]&&b[0+2*3]){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	if(c=='-')f=-1,c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
ll k,phi;
ll qp(ll a,ll b,ll p){
	ll ans=1;
	while(b){
		if(b&1)ans=ans*a%p;
		a=a*a%p;
		b/=2;
	}
	return ans;
}
ll wws,ak;
int main(){
	k=d,ak=k;
	if(k%7==0)k/=7;
	if(k%2==0||k%5==0){
		cout<<-1;
		return 0;
	}
	if(k==1){
		cout<<1;
		return 0;
	}
	while(ak)ak/=10,wws++;
	ll kk=phi=k;
	for(int i=2;i*i<=k;i++)
		if(k%i==0){
			while(k%i==0)k/=i;
			phi=phi*(i-1)/i;
		}
	if(k!=1)phi=phi*(k-1)/k;
	ll cnt=0,now=0;
	while(1){
		cnt++;
		if(cnt<phi)now+=qp(10,cnt%phi,kk);
		else now+=qp(10,cnt%phi+phi,kk);
		if(now%kk==0&&cnt>=wws)break;
	}
	printf("%lld",cnt);
	return 0;
}


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

int main() {
  int perimeter, n, max = 0;
  cin >> perimeter >> n;
  int houses[n];
  int e[n];

  //Array input
  for(int i = 0; i < n; i++){
    cin >> houses[i];
  }

  //e[] input
  for(int i = 0; i < n - 1; i++){
    e[i] = houses[i+1] - houses[i];
  }
  e[n-1] = perimeter - houses[n-1] + houses[0];

  //Calculating the max value
  for(int i=0; i<n; i++){
    if(e[i] > max) max = e[i];
  }
  cout << perimeter - max << endl;
}


Measured memory_bytes: 1792
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

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


signed main() {
	string S, T;
		string ans="Yes";
	int N;
	cin >> S>>T;
	N = S. size();
	REP(i,N){
		if (S.at(i) != T.at(i)) {
			ans="No";
	}
	}
	cout << ans << endl;
	pause;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int n;cin>>n;
  int ec=0, oc=0;
  rep(i,n){
    int t;cin>>t;
    if(t%2==0)ec++;
    else oc++;
  }

  if(oc%2 && ec>0) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;

  return 0;
}

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

using namespace std;

const int N = 100005;

int a[N];

int main() {
	int n, x;
	scanf("%d %d", &n, &x);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	long long ans = 0;
	for (int i = 1; i < n; i++) {
		if ((long long)a[i] + a[i - 1] <= x) continue;
		long long k = (long long)a[i] + a[i - 1] - x;
		ans += k;
		if (k > a[i]) {
			a[i] = 0;
		} else {
			a[i] -= k;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    R = [I() for _ in range(n)]

    ans = -INF
    min_v = INF
    for i in range(n):
        ans = max(R[i]-min_v, ans)
        min_v = min(R[i], min_v)

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 13604
import java.util.Scanner;

public class Main {
    static long inversions;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        inversions = 0;
        mergeSort(a, 0, a.length);
        System.out.println(inversions);
    }

    private static void mergeSort(int[] a, int left, int right) {
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            mergeSort(a, left, mid);
            mergeSort(a, mid, right);
            merge(a, left, mid, right);
        }
    }

    private static void merge(int[] a, int left, int mid, int right) {
        int n1 = mid - left;
        int n2 = right - mid;
        int[] l = new int[n1];
        int[] r = new int[n2];
        for (int i = 0; i < n1; i++) {
            l[i] = a[left + i];
        }
        for (int i = 0; i < n2; i++) {
            r[i] = a[mid + i];
        }
        int i = 0;
        int j = 0;
        boolean addExtra = false; // True if the extra inversions have been added.
        for (int k = left; k < right; k++) {
            if (i < n1 && (j == n2 || l[i] <= r[j])) {
                a[k] = l[i];
                if (i > 0 && !addExtra) inversions += j;
                i++;
                addExtra = false;
            } else {
                a[k] = r[j];
                if (i < n1) {
                    inversions++;
                    if (i > 0 && !addExtra) inversions += j;
                    addExtra = true;
                }
                j++;
            }
        }
    }
}



Measured memory_bytes: 101668
/*
  AOJ #0309
  title:New Drug Development
  @kankichi573
 */
#include <stdio.h>
#include <string.h>
#define DIV 1000000007
int n;
int from[1001],to[1001];
char node[1001][3];
int res[1001];

long long solve(int no)
{
  char *p;
  int i;
  long long acc;
  
  p=&node[no][0];
  // printf("n=%d k=%s\n",no,p);
  
  if(*p=='E')
    {
      for(i=0,acc=1;i<n-1;i++)
	if(from[i]==no)
	  acc = (acc * solve(to[i])) % DIV;
      if(p[1]=='?')
	  acc = (acc + 1) % DIV;
    }

  if(*p=='R')
    {
      for(i=0,acc=1;i<n-1;i++)
	if(from[i]==no)
	  {
	    acc = (acc * (1+solve(to[i]))) % DIV;
	    // printf("%d* %d %d\n",i,solve(to[i]),acc);
	  }
      if(p[1]!='?')
	acc  = (acc - 1) % DIV;
    }
  
  if(*p=='A')
    {
      for(i=0,acc=0;i<n-1;i++)
	if(from[i]==no)
	  {
	    acc = (acc + solve(to[i])) % DIV;
	  }
      if(p[1]=='?')
	acc  = (acc + 1)  % DIV;
    }
  res[no]=acc;
  return(acc);
}
dump()
{
  int i;
  for(i=1;i<=n;i++)
    printf("%d: %d\n",i,res[i]);
}
int main()
{
  int i,ret;
  
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%s",&node[i][0]);

  for(i=0;i<n;i++)
    scanf("%d %d",&from[i],&to[i]);
  ret=solve(1);
  #ifdef DEBUG
  dump();
  #endif
  printf("%d\n",ret);
  return(0);
}

Measured memory_bytes: 680
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
 
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>;                         

const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;

void solve () {
	int n, d;
	cin >> n >> d;
	ll sum = 0;
	for (int i = 1; i <= n; i ++) {
		long double x, y;
		cin >> x >> y;
		if (sqrt (x * x + y * y) <= d) {
			sum ++;	
		}
	}
	cout << sum;
}   	
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//    cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 3864