akhauriyash/Code-Regression huggingface dataset:
def main():
    N = int(input())
    P = tuple(map(int, input().split()))

    p = []
    for i, n in enumerate(P):
        if i + 1 == n:
            if P[i-1] == n - 1:
                p[-1] += 1
            else:
                p.append(1)

    ans = 0
    for i in p:
        ans += (i + 1) // 2

    print(ans)

main()


Measured memory_bytes: 14008
#include<stdio.h>
 
int main(void){
  int i;
  int n;
  int m;
  int a[10010];
  scanf("%d%d",&n, &m);
  for(i = 0; i < m; i++){
    scanf("%d", &a[i]);
    n -= a[i];
  }
  if (n < -1)
    n=-1;
  printf("%d",n);
}

Measured memory_bytes: 1724
#include <iostream>
#include <string>
using namespace std;
int main() {
    int a, b;
    string s, op;
    cin >> s;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> op;
        if (op == "replace"){
            string p;
            cin >> a >> b >> p;
            for (int i = a, j = 0; i <= b; i++) {
                s[i] = p[j++];
            }
        } else if (op == "reverse") {
            cin >> a >> b;
            while (a < b) {
                swap(s[a++], s[b--]);
            }
        } else if (op == "print") {
            cin >> a >> b;
            for (int i = a; i <= b; i++) 
                cout << s[i];
            cout << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib> //abs(int)
using namespace std;
int main(void){
  int N, A, B /*, c, d*/;
  cin >> N >> A >> B /*>> c >> d*/;
  if(N == 1){
    cout << "Hello World";
  } else {
    cout << A + B;
  }
}

Measured memory_bytes: 256
import itertools

a=[]
b=[]
h, w, k = map(int, input().split())
h_list=[i for i in range(h)]
w_list=[i for i in range(w)]

for i in range(h+1) :
  c = list(itertools.combinations(h_list, i))
  a.extend(c)
for i in range(w+1) :
  c = list(itertools.combinations(w_list, i))
  b.extend(c)
list1 = []
for i in range(h):
  list1.append(input())

sum1 = 0
for i in range(h):
  for j in range(w):
    if list1[i][j] == '#':
      sum1 += 1
answer = 0
import copy
def count(list3,list4) :
  count1=0
  for i in list3 :
   for j in range(w) :
     if list1[i][j]=='#' :
       count1+=1
  for j in list4 :
   for i in range(h) :
     if list1[i][j]=='#' :
       count1+=1
  for i in list3 :
    for j in list4 :
      if list1[i][j] == '#':
        count1-=1
  return count1



answer = 0
for item1 in a :
  for item2 in b :
    if sum1-count(item1,item2)==k :
      answer += 1




print(answer)

Measured memory_bytes: 69544
import sys
input = sys.stdin.readline
from collections import Counter
def judge(vals):
    return vals[0] ^ vals[1] ^ vals[2] == 0
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = "No"
    c = Counter(A)
    con1 = len(c) == 2 and c[0] * 3 == N
    items = list(c.items())
    con2 = len(c) == 3 and items[0][1] * 3 == N and items[1][1] * 3 == N and judge(list(c.keys()))
    con3 = c[0] == N
    if con1 or con2 or con3:ans = "Yes"
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 57328
#我不知道怎么定义结构体，我是直接模拟的    QAQ
start = [1,2,3,5,4,6]

def N():
    start[0],start[1],start[3],start[5] = \
    start[1],start[5],start[0],start[3]
    
def S():
    start[0],start[1],start[3],start[5] = \
    start[3],start[0],start[5],start[1]
    
def W():
    start[0],start[2],start[4],start[5] = \
    start[2],start[5],start[0],start[4]

def E():
    start[0],start[2],start[4],start[5] = \
    start[4],start[0],start[5],start[2]

if __name__ == "__main__":
    lst = list(map(int,input().split()))
    s = input()
    for i in range(len(s)):
        if s[i]=='S':
            S()
        if s[i]=='E':
            E()
        if s[i]=='W':
            W()
        if s[i]=='N':
            N()
    print(lst[start[0]-1])


Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

char c[50][50];
int d[50][50];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
int h, w;

bool gcd(int x, int y){
    // cout << x << " " << y << endl;
    if(c[y][x] == '.') return true;
    for(int i=0; i<4; i++){
        if(y+dy[i] >= 0 && x+dx[i] >= 0 && y+dy[i] < 50 && x+dx[i] < 50){
            if(c[y+dy[i]][x+dx[i]] == '#'){
                return true;
            }
        }
    }
    return false;
    
}

int main(){
    cin >> h >> w;

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> c[i][j];
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(!gcd(j, i)){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
T = [int(input()) for _ in range(N)]
a = T[0]
for i in range(1,N):
    b = T[i]
    c = gcd(a,b)
    a = a*(b//c)
print(a)

Measured memory_bytes: 38256
import java.util.*;

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

        int n = sc.nextInt();
        Integer[] L = new Integer[n];

        for (int i = 0; i < L.length; i++) {
            L[i] = sc.nextInt();
        }
        Arrays.sort(L, Collections.reverseOrder());

        int sum = 0;
        for (int i = 1; i < L.length; i++) {
            sum += L[i];
        }
        if(L[0] < sum)  System.out.println("Yes");
        else System.out.println("No");
        
    }
}

Measured memory_bytes: 25172
def GCD(x, y):
    if y == 0:
        return x
    return GCD(y, x % y)


N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(set(A))

check = set()
for a in A:
    cnt = 0
    while a % 2 == 0:
        cnt += 1
        a //= 2
    check.add(cnt)

if len(check) > 1:
    print(0)
    exit()

LCM = 1
for a in A:
    gcd = GCD(LCM, a // 2)
    LCM = LCM * (a // 2) // gcd

ans = (M - LCM) // (2 * LCM) + 1
print(ans)

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

typedef long long ll;

int main(){
    ll h, ans = 0;
    cin >> h;
    ll two = 1, num = 0;

    while(two <= h){
        num++;
        two *= 2;
    }

    for(int i = 0; i < num; i++){
        ans += pow(2, i);
    }

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

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)
 
N, A, B, C, D = map(int, input().split())
s = list(input())
 
A -= 1
B -= 1
C -= 1
D -= 1
 
for i in range(len(s)):
    if i == len(s) - 1:
        continue
    else:
        if s[i] == '#' and s[i+1] == '#' and max(C, D) < i and i <= C:
            print("No")
            exit()
 
if D < C:
    tmp = 0
    for i in range(len(s)):
        if i == len(s) - 2 or i == len(s) - 1:
            continue
        else:
            if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.' and B <= i + 1 <= D:
                tmp = 1
    if tmp != 1:
        print("No")
        exit()
 
 
 
def check(s, start, goal, ans):
    if start == goal:
        return 1
    if s[start] == '#':
        return 0
    if start + 1 <= N - 1:
        ans += check(s, start + 1, goal, ans)
    if start + 2 <= N - 1:
        ans += check(s, start + 2, goal, ans)
    return ans
 
ans = 0
if not check(s, B, D, ans):
    print("No")
    exit()
#s[D] = '#'
if not check(s, A, C, ans):
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 104396
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    int n,m;
    cin>>n>>m;
    vector<ll>ac(n,0), pen(n,0);
    for(int i=0;i<m;i++)
    {
        ll p;
        string s;
        cin>>p>>s;

        if( s == "WA" )
        {
            if( ac[p-1] == 0 )
                pen[p-1]++;
        }
        else
        {
            ac[p-1] = 1;
        }
    }

    ll ans = 0;
    ll pe = 0;
    for(int i=0;i<n;i++)
    {
        ans += ac[i];
        if( ac[i] )
            pe += pen[i];
    }
    cout<<ans<<" "<<pe,nl;


    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long

void solve()
{
    int n,m,k,i,j,count=0,sum=0,maxi=0,mini=1e18,flag=0;
    cin>>n;
    
    int arr[10001];
    for(i=1;i<=10000;i++) arr[i]=0;
    
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                int temp=i*i+j*j+k*k+i*j+j*k+i*k;
                if(temp<=10000)
                arr[temp]++;
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        cout<<arr[i]<<"\n";
    }
    
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if(s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int m[111111],N,cnt;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    int cur=1;
    for(int i=1;i<=N;i++)cin>>m[i];
    while(cur&&cur!=2){
        int x=m[cur];
        m[cur]=0;
        cur=x;
        cnt++;
    }
    if(cur)cout<<cnt;
    else cout<<-1;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll x,y,z,ans;
  cin >> x >> y >> z;
  ans=x/(y+z);
  if((y+z)*ans+z>x)ans--;
  printf("%lld",ans);
}

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


int n;
int a[4];
int main() 
{
	
	for (int i = 1; i <= 3; i++)
		scanf("%d", &a[i]);
	cout << a[3] << " " << a[1] << " " << a[2] << endl;	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;

  if (a%2 == 0 || b%2 ==0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	m := readInt()
	a := make(map[int]bool, m)
	for i := 0; i < m; i++ {
		a[readInt()] = true
	}

	if n == 1 {
		fmt.Println("1")
		return
	}

	dp := make([]int, n)
	dp[0] = 1
	for i := 1; i < n; i++ {
		if a[i] {
			continue
		}
		if i < 2 {
			dp[i] = dp[i-1]
			continue
		}
		dp[i] = (dp[i-1] + dp[i-2]) % MOD
	}

	fmt.Println((dp[n-1] + dp[n-2]) % MOD)
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1000000007
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin>>n;
  vl A(n);
  rep(i,n){
    cin>>A[i];
  }
  map<ll,ll> mp;

  rep(i,n){
    mp[i+A[i]]+=1;
  }
  ll ans = 0;
  rep(i,n){
    ans+=mp[i-A[i]];
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(){
	int n,m;
	while(cin >> n >> m && n || m){
		vector<int> data(n);
		vector<int> del;
		int i=1;
		for(int i=0;i<n;i++){
			data[i] = i+1;
		}
		for(	vector<int>::iterator it = data.begin();
			data.size()!=1;
		){
			if(it == data.end()){
				it = data.begin();
			}
			if(i%m==0){
				it = data.erase( it );
			}else{
				it++;
			}
			i++;
		}
		cout << data[0] << endl;
	}
}

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

int main() 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int k,t,a;
	int Max = 0;
	
	cin >> k >> t;
	for(int i=0;i<t;i++)
	{
		cin >> a;
		Max = max(Max,a);
	}
	
	int b = k - Max;
	if(b>=Max)
	{
		cout << 0 << '\n';
	}
	else
	{
		cout << Max-b-1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
using namespace std;

int main(){
	int n,d,a,b;
	cin >> n >> d;
	a = n/(2*d+1);
	b = n%(2*d+1);

	if(b!=0){
		a++;
	}
	cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>

bool IsAcceptable(int val)
{
    if (val % 2 == 1)
    {
        return true;
    }

    const auto isTree = (val % 3 == 0);
    const auto isFive = (val % 5 == 0);

    return (isTree || isFive);
}

int main()
{
    int n = 0;
    std::cin >> n;

    for (auto count = 0; count < n; ++count)
    {
        int val = 0;
        std::cin >> val;
        if (!IsAcceptable(val))
        {
            std::cout << "DENIED";
            return 0;
        }
    }

    std::cout << "APPROVED";
    return 0;
   
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;

int mod = 998244353;
int n;
int x[200], y[200];
int power2[201];

P getPair(int pa, int pb) {
	int i;
	int tx = x[pb] - x[pa];
	int ty = y[pb] - y[pa];
	int minRet = n;
	int maxRet = -1;
	
	for (i = 0; i < n; i++) {
		int dx = x[i] - x[pa];
		int dy = y[i] - y[pa];
		if (tx * dy - ty * dx != 0) continue;
		maxRet = max(maxRet, i);
		minRet = min(minRet, i);
	}
	return P(minRet, maxRet);
}

int getCount(int pa, int pb) {
	int i;
	int tx = x[pb] - x[pa];
	int ty = y[pb] - y[pa];
	int ret = 0;
	
	for (i = 0; i < n; i++) {
		int dx = x[i] - x[pa];
		int dy = y[i] - y[pa];
		if (tx * dy - ty * dx != 0) continue;
		ret++;
	}
	return ret;
}

int count_line() {
	int i, j;
	vector<P> lines;
	
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			lines.push_back(getPair(i, j));
		}
	}
	sort(lines.begin(), lines.end());
	lines.erase(unique(lines.begin(), lines.end()), lines.end());
	
	int ret = 0;
	for (i = 0; i < lines.size(); i++) {
		int k = getCount(lines[i].first, lines[i].second);
		ret += power2[k] - k - 1;
		ret %= mod;
	}
	ret += n + 1;
	return ret;
}

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> x[i] >> y[i];
	
	power2[0] = 1;
	for (i = 1; i <= n; i++) power2[i] = (power2[i - 1] * 2) % mod;
	int k = count_line();
	int ans = (power2[n] - k + mod) % mod;
	cout << ans << endl;
	return 0;
}

//基本方針は全探索を丁寧に見直すこと。
//U:    {点1,点2,…,点n}
//f(S): S⊆Uについて, Sが凸なら1, 凸でないなら0.
//T(S): 凸なS⊆Uについて, Sの境界または内部にある点の集合.
//E(S): S⊆Uにおけるスコア. (Sが凸としたときのスコア. 非凸ならドントケア)
//とおくと
//Ans = Σf(S)E(S)
//E(S) = 2^(|T(S)| - |S|) = 2^|T(S) - S| = |2^(T(S) - S)| = |S・2^(T(S) - S)|
//が成り立つ.
//S・2^(T(S) - S)は, {∀u : S ⊆ u ⊆ T(S)}で表せる.
//
//ここで, g(S) = {S'| S'⊆U, f(S') = 1, S' ⊆ S ⊆ T(S')}とおく。
//すると, Σ|g(S)|が答えになる。(ループの順番を変えただけ）
//
//任意のSについて, Sの凸法(多角形)をP(S)とおく. P(S)はSの凸法の境界と内部にある無限個の点の集合である.
//g(S)を計算する。
//Sが一直線上 or 空集合のとき … S' ⊆ S, f(S') = 1となるS'は存在しないので, g(S) = 空集合.
//それ以外のとき …
//S' ⊆ S ⇒ P(S') ⊆ P(S)
//S  ⊆ T(S') ⇒ P(S) ⊆ P(T(S'))
//f(S') = 1 ⇒ P(S') = P(T(S'))
//より, 条件を満たすS'において, P(S) = P(S')が成り立つ.
//また, f(S') = 1より, P(S') and U = S'が成り立つ. そのようなS'はP(S')と1対1対応している.
//実際, S' = {Sの凸法に使われた点の集合}とすれば, P(S) = P(S')が成り立つ.
//(任意の点集合について凸法が一意に定まること, 凸法の包含の性質を使った）
//
//よって, 2^N - |{S|S⊆U,  Sが一直線上 or S=空集合}|が答えになる。直線の候補はnC2通りあるので, それらを列挙して, 重複除去をして,
//各直線に乗っている点の数をkとしたときの2^k - k - 1の合計値を求める. それにn + 1を足したものが答え.
//重複除去は, 直線上の{Min番の点の番号, Max番の点の番号}をペアとして持って, sort→uniqueとすれば、O(n^3)でできる。
//数え上げパートもO(n^3)なので、この問題はO(n^3)で解けた。
//
//E(S)の式変形パートをどうやって思いついたか？：
//｛N = 4, 非凸, どの3点も1直線上にない｝ケースについて以下の実験をした。
//・点の部分集合(16パターン)それぞれについて, 凸法を作図して, スコアを書く.
//あとは, ぐっと睨むと気付いた。


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IL inline
IL int read() {
	char ch = getchar(); int u = 0, f = 1;
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { u = (u << 1) + (u << 3) + ch - 48; ch = getchar(); }
	return u * f;
}
const int maxn = 1e5 + 10;
int a[maxn];
int main() {	
	int n = read(), x = read();
	for (int i = 1; i <= n; ++i) a[i] = read();
	sort(a + 1, a + 1 + n);
	int ans = 0, sum = 0;
	int pos;
	for (int i = 1; i <= n; ++i) {
		if (sum + a[i] > x) break;
		sum += a[i]; ans++;	
		pos = i;
	}
	if (sum != x && pos == n) ans--;
	if (ans == -1) ans++; 
	cout << ans << endl;
	return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> mp;
    REP(i,n){
        int a,b;
        cin >> a >> b;
        mp.emplace_back(b,a);
    }
    ll sum = 0;
    sort(mp.begin(),mp.end());
    for(const auto& i:mp){
        int limit = i.first;
        int timer = i.second;//timerの時間を順に足していく
        sum  += timer;
        if(sum>limit){
            COUT("No");
            return 0;
        }
    }
    COUT("Yes");
    return 0;
} 

Measured memory_bytes: 2420
// 解説PDFの通り実装
// K個の列を選んで長さを変えるのと、K個の列をなくすのとが同じことにまず気付く必要があった

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> Hs(N);
    REP(n, N) cin >> Hs[n];

    // dp[x][y]
    //   x: もっとも右の項の番号
    //   y: サイズ
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1));

	REP(x, N) {
		dp[x][1] = Hs[x];
	}

	FOR(y, 2, N + 1) {
		FOR(x, y - 1, N) {
			ll tmp = 1e18;
			//REP(i, x - 1) {
			FOR(i, y - 2, x) {
				auto prev = Hs[i];
				auto curr = Hs[x];
				tmp = min(tmp, dp[i][y - 1] + max(0, curr - prev));
			}
			dp[x][y] = tmp;
		}

		//REP(y1, N + 1) {
		//	cout << "y " << y1 << ": ";
		//	REP(x1, N) {
		//		cout << dp[x1][y1] << " ";
		//	}
		//	cout << endl;
		//}
		//cout << endl;
	}

	// コーナーケース!!
	// N = Kの場合は明らかにゼロ
	if (N == K) {
		cout << 0 << endl;
	}
	else {
		ll ans = 1e18;
		ll y = N - K;
		FOR(x, y - 1, N) {
			ans = min(ans, dp[x][y]);
		}
		cout << ans << endl;
	}

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<int MOD>
class ModInt{
public:
    ModInt():value(0){}
    ModInt(long long val):value((int)(val<0?MOD+val%MOD:val%MOD)){ }

    ModInt& operator+=(ModInt that){
        value = value+that.value;
        if(value>=MOD)value-=MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that){
        value -= that.value;
        if(value<0)value+=MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that){
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that){
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const{
        return ModInt(*this)+=that;
    }
    ModInt operator-(ModInt that) const{
        return ModInt(*this)-=that;
    }
    ModInt operator*(ModInt that) const{
        return ModInt(*this)*=that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt operator^(long long k) const{
        if(value == 0)return 0;
        ModInt n = *this, res = 1;
        while(k){
            if(k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while(b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const{ return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x){
    os << x.toi();
    return os;
}

int N, C;
vi A, B;

void solve(){
    // rep(i, N)if(A[i] != B[i])return;

    vector<vector<mint>> predp(N, vector<mint>(C + 1));
    rep(i, N){
        for(int x = A[i]; x <= B[i]; ++x){
            mint xa = 1;
            for(int c = 0; c <= C; ++c){
                predp[i][c] += xa;
                xa *= x;
            }
        }
    }

    // i番目まで見た。残りの雨はj個
    vector<vector<mint> > dp(N + 1, vector<mint>(C + 1));
    dp[0][C] = 1;

    rep(i, N)rep(j, C + 1)if(dp[i][j].toi()){
        rep(c, j+1){
            int nj = j - c;
            dp[i + 1][nj] += dp[i][j] * predp[i][c];
        }
    }

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

int main(){
    while(cin >> N >> C){
        A = B = vi(N);
        rep(i, N)scanf("%d", &A[i]);
        rep(i, N)scanf("%d", &B[i]);
        solve();
    }
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<bool>p(m,false);
    vector<int>x(n,0);
    int r;
    string s;
    int ac=0,pen=0;
    for(int i=0;i<m;i++)
    {
        cin>>r>>s;
        if(p[r-1]==false && s=="AC")
        {
            p[r-1]=true;
            ac++;
            pen+=x[r-1];
            x[r-1]=0;
        }
        else if(p[r-1]==false)
        {
            x[r-1]++;
        }
    }
    cout<<ac<<" "<<pen<<"\n";
}


Measured memory_bytes: 3768
#include <stdio.h>

int main()
{
    int hotel[4][3][10],i,j,k,test,b,f,r,v;
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                hotel[i][j][k]=0;
            }
        }
    }
    scanf("%d",&test);
    for(i=0;i<test;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        hotel[b-1][f-1][r-1]+=v;
    }
    for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",hotel[0][j][k]);
            }
            printf("\n");
        }
    for(i=1;i<4;i++){
        printf("####################\n");
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",hotel[i][j][k]);
            }
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2132
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

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); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,h[100010],ma = 0,mov[100010] = {};
	cin >> n;
	for(int i = 0;i < n;i++) cin >> h[i];
	h[n] = INF;
	for(int i = n - 1;i >= 0;i--){
		if(h[i] < h[i + 1]) mov[i] = 0;
		else mov[i] = mov[i + 1] + 1;
		chmax(ma,mov[i]);
	}
	cout << ma << endl;
}

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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

using ll = long long;
const int N = 3123;
constexpr ll mod = 998244353;

int a[N];

void add(ll& x, ll y) {
    x += y;
    if (x >= mod) x -= mod;
}

ll dp[N][N];
ll ps[N];

int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, s;
    cin >> n >> s;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (int i = 1; i <= n; i++) {
        dp[i][a[i]] += i;
        for (int w = s; w >= a[i]; w--)
            add(dp[i][w], ps[w - a[i]]);

        for (int w = 0; w <= s; w++)
            add(ps[w], dp[i][w]);
    }

    debug(
        for (int i = 1; i <= n; i++)
            cout << dp[i][s] << ' ';
        cout << endl;
        for (int w = 1; w <= s; w++)
            cout << ps[w] << ' ';
        cout << endl;
    )

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        add(ans, dp[i][s] * ll(n - i + 1) % mod);
    }

    cout << ans << endl;


    return 0;
%>

Measured memory_bytes: 73856
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef vector<P> vP;

int main() {
	while (true) {


		int n, m;
		cin >> n >> m;
		if (n == 0 && m == 0)return 0;
		vi x(3000009, 0);
		vi y(3000009, 0);
		x[0] = 1;
		y[0] = 1;
		vi h(max(n, m) + 1, 0);
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			int temp;
			cin >> temp;
			sum += temp;
			h[i] = sum;
		}
		for (int i = 0; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				x[h[j] - h[i]] += 1;
			}
		}
		sum = 0;
		for (int i = 1; i <= m; i++) {
			int temp;
			cin >> temp;
			sum += temp;
			h[i] = sum;
		}
		for (int i = 0; i <= m; i++) {
			for (int j = i + 1; j <= m; j++) {
				y[h[j] - h[i]] += 1;
			}
		}
		int ans = 0;
		for (int i = 1; i < 3000009; i++) {
			ans += x[i] * y[i];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 26252
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	char e[255],a;
	e['A']='T';
	e['C']='G';
	e['G']='C';
	e['T']='A';
	scanf("%c",&a);
	printf("%c\n",e[a]);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
static const int INF = 1ll<<60;
typedef pair<int,int> P1;
typedef pair<int,pair<int,int> > P2;

int N;

void solve(int A,int B){
    if(N==1){
        if(A==B)cout<<1<<endl;
        else cout<<0<<endl;
        return ;
    }
    if(A>B){
        cout<<0<<endl;
        return ;
    }
    else{
        int Min = (N-1)*A+B,Max = (N-1)*B+A;
        cout<<Max-Min+1<<endl;
    }
}

signed main(){
    int A,B;
    cin>>N>>A>>B;
    solve(A,B);
}


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

using namespace std;

int main(void){
    int n,m;
    vector<int> x,l;
    cin >> n >> m;
    for(int i=0;i<m;++i){
        int tmp;
        cin >> tmp;
        x.push_back(tmp);
    }
    if(n > m){
        cout << 0 << endl;
    }else{
        sort(x.begin(),x.end());
        for(int i=0;i<m-1;++i){            
            l.push_back(x[i+1]-x[i]);
        }
        sort(l.begin(),l.end(),greater<int>());
        int sum = 0;
        for(int i=0;i<n-1;i++){
            sum += l[i];
        }
        cout << x[m-1] - x[0] - sum << endl;
    }
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>

int main(void){
  int n;
  std::vector<int> p;
  int tmp;
  int count = 0;
  std::cin >> n;
  for(int i = 0; i < n; i++){
    std::cin >> tmp;
    p.push_back(tmp);
  }
  for(int i = 0; i < n - 2; i++){
    std::vector<int> check;
    check.push_back(p[i]);
    check.push_back(p[i+1]);
    check.push_back(p[i+2]);
    std::sort(check.begin(),check.end());
    if(check[1] == p[i+1])
      count++;
  }
  std::cout << count;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
 
#define PI 3.1415926535
 
using namespace std;
 
int main() {
    int a, b, C;
 
    cin >> a >> b >> C;
 
 
    double S = a*b*sin(C / 180.0 * PI) / 2;
    double L = sqrt(a*a + b*b - 2 * a*b*cos(C / 180.0 * PI)) + a + b;
    double h = 2 * S / a;
 
    printf("%.4f\n", S);
    printf("%.4f\n", L);
    printf("%.4f\n", h);
 
    return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
using namespace std;
int G[100][100] = {};
int timer = 0;
typedef struct ANS
{
	int id, t, e;
	bool done;
};

void rec(ANS a[],int t)
{
	if (a[t].done == true)return;
	timer++;
	a[t].t = timer;
	a[t].done = true;
	FOR(i, 0, 100)
	{
		if (G[t][i] == 1)
		{
			rec(a, i);
		}
	}
	timer++;
	a[t].e = timer;
}

int main()
{
	ANS ans[101];
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		ans[i].id = i + 1;
		ans[i].done = false;
		int u, m;
		cin >> u >> m;
		FOR(j, 0, m)
		{
			int l;
			cin >> l;
			G[u - 1][l - 1] = 1;
		}
	}
	FOR(i, 0, n)
	{
		rec(ans, i);
	}
	FOR(i, 0, n)
	{
		cout << ans[i].id << " " << ans[i].t << " " << ans[i].e << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            long lN = long.Parse(sS[0]);
            long lM = long.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            long lOut = 0L;
            long lNn = lN;          // S個数
            long lMn = lM;          // C個数
            while (true)
            {
                long lCz = lMn - lNn * 2;                               // Sに対応する Cを引いた残り
                if (lCz > 3)                                            // Cがまだある
                {
                    lOut += lNn;                                        // とりあえずSCC作成 Sの数
                    lMn = lCz;                                          // CはSCC作成後の残り
                    lNn = 0;                                            // SはSCC作成で0に
                    long lTmp = lMn / 4;
                    lNn = lTmp;                                         // CからS作成
                    lMn = lMn - lTmp * 2;                               // CからS作成した後のCの残り
                }
                else                                                    // Cがもうない
                {
                    long lTmp = lMn / 2;                                // 残りのCでSCC作成
                    if (lNn < lTmp) { lOut += lNn; }
                    else { lOut += lTmp; }
                    break;
                }
            }

            //出力
            Console.WriteLine("{0}", lOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
import java.util.*;


public class Main {

    private static final int INF = 1000000007;
    private static final int INF1 = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];

        for(int tmp=0; tmp < n; tmp++){
            for(int tmp1= 0; tmp1< d ; tmp1++) {
                int tmpx = sc.nextInt();
                x[tmp][tmp1] = tmpx;
            }
        }
        int result = 0;

        for(int tmp=0; tmp<n;tmp++){
            for(int tmp1=tmp + 1; tmp1<n; tmp1++){
                long sum = 0;
                for(int tmp2=0;tmp2<d;tmp2++){
                    long part = (long) Math.pow(Math.abs(x[tmp][tmp2] - x[tmp1][tmp2]),2);
                    sum += part;
                }
                double sumsqurt = Math.sqrt(sum);
                if(sumsqurt % 1 == 0){
                    result++;
                }
            }
        }
        System.out.println(result);

    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    int res = 0;
    int mi = 1e10;
    rep(i, n) {
        int p;
        cin >> p;
        if(p <= mi) res++;
        mi = min(mi, p); 
    }

    cout << res << endl;
    
    
    return 0;
}

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


int main(){
    int N, K;
    int d[110] = {0}, A[110][110] = {0};
    int B[110];
    int n = 0;

    int i, j, k;

    scanf("%d %d", &N, &K);

    for (i = 0; i < K; i++){
        scanf("%d", &d[i]);
        for (j = 0; j < d[i]; j++)
        {
            scanf("%d", &A[i][j]);
            B[A[i][j] - 1] = 1;
        }
    }

    for (i = 0; i < N; i++){
        if(B[i] == 0){
            n++;
        } 
    }

    printf("%d", n);

    return 0;
}


Measured memory_bytes: 1776
a = list(map(int, input().split()))
a += list(map(int, input().split()))
a += list(map(int, input().split()))
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
c = [x in b for x in a]
if (c[0] and c[1] and c[2]) or (c[3] and c[4] and c[5]) or (c[6] and c[7] and c[8]) or (c[0] and c[3] and c[6]) or (c[1] and c[4] and c[7]) or (c[2] and c[5] and c[8]) or (c[0] and c[4] and c[8]) or (c[2] and c[4] and c[6]):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
/*
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_H = 500000;
const int INF = 2147483647;

/* typedef */

/* global variables */

int as[MAX_H];

/* subroutines */

void max_heapify(int h, int A[], int i) {
  int l = i * 2 + 1;
  int r = i * 2 + 2;

  int largest = i;
  if (l < h && A[l] > A[largest]) largest = l;
  if (r < h && A[r] > A[largest]) largest = r;

  if (largest != i) {
    swap(A[i], A[largest]);
    max_heapify(h, A, largest);
  }
}

void build_max_heap(int h, int A[]) {
  for (int i = (h - 1) / 2; i >= 0; i--)
    max_heapify(h, A, i);
}
  
/* main */

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

  for (int i = 0; i < h; i++) cin >> as[i];

  build_max_heap(h, as);

  for (int i = 0; i < h; i++) printf(" %d", as[i]);
  putchar('\n');

  return 0;
}

Measured memory_bytes: 3096
<?php
 fscanf(STDIN, "%d", $N);
 fscanf(STDIN, "%s", $S);

$str = str_split($S);
$count = 0;
$max = 0;

foreach($str as $char){
	if($char == "I"){
      $count++;
      $max = max($count, $max);
    }elseif($char == "D"){
      $count--;
    }      
}
echo $max;

  ?>

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, y;
  cin >> n >> y;

  int a, b, c;
  a = b = c = -1;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n - i; ++j) {
      int k = n - i - j;
      if (10000 * i + 5000 * j + 1000 * k == y) {
        a = i;
        b = j;
        c = k;
        break;
      }
    }
  }

  cout << a << ' ' << b << ' ' << c << '\n';

  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
    string a,b;
    cin>>a>>b;
    if(a[0]=='H'){
        cout<<(b[0]=='H'?"H":"D")<<endl;
    }else{
        cout<<(b[0]=='H'?"D":"H")<<endl;
    }
    return 0;
}


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

#define MAX 2000000

// 1 originとして使う
int* heap = (int*)malloc(sizeof(int)*(MAX*2+1));
int H = 0;

int parent(int i) { return i/2;}
int left(int i) {return 2*i;}
int right(int i){return 2*i + 1;}

void maxHeapify(int i){
  int l = left(i);
  int r = right(i);
  int largest;

  if(l <= H && heap[i] < heap[l]) largest = l;
  else largest = i;
  if(r <= H && heap[largest] < heap[r]) largest = r;

  if(largest != i){
    swap(heap[i], heap[largest]);
    maxHeapify(largest);
  }
}

void buildMaxHeap(){
  for(int i=H/2; i>0; i--){
    maxHeapify(i);
  }
}

void insert(int key){
  H++;
  heap[H] = key;

  int idx = H;
  while(heap[idx] > heap[parent(idx)] && parent(idx) > 0){
    swap(heap[idx], heap[parent(idx)]);
    idx = parent(idx);
  }
}

int extractMax(){
  int ret = heap[1];
  heap[1] = heap[H--];
  maxHeapify(1);
  return ret;
}

int main(){

  char c[10];
  int key;

  while(1){
    scanf("%s",c);

    switch(c[2]){
      case 's':
      scanf("%d", &key);
      insert(key);
      break;

      case 't':
      printf("%d\n",extractMax());
      break;

      case 'd':
      default:
      return 0;
      break;
    }
  }

  return -1;
}



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

int main(){
    string S,T;
    cin >>S;
    cin >>T;
    size_t n = S.size();
    T=T.substr(0,n);

    if (T==S){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

template<uint32_t mod>
struct ModInt{
	uint32_t a;
	ModInt& s(uint32_t vv){
		a=vv<mod?vv:vv-mod;
		return *this;
	}

	ModInt(int64_t x=0){s(x%mod+mod);}

	ModInt& operator+=(const ModInt &x){return s(a+x.a);}
	ModInt& operator-=(const ModInt &x){return s(a+mod-x.a);}
	ModInt& operator*=(const ModInt &x){
		a=uint64_t(a)*x.a%mod;
		return *this;
	}
	ModInt& operator/=(const ModInt &x){
		*this*=x.inv();
		return *this;
	}

	ModInt operator+(const ModInt &x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt &x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt &x)const{return ModInt(*this)*=x;}
	ModInt operator/(const ModInt &x)const{return ModInt(*this)/=x;}
	bool operator==(const ModInt &x)const{return a==x.a;}
	bool operator!=(const ModInt &x)const{return a!=x.a;}
	bool operator<(const ModInt &x)const{return a<x.a;}

	ModInt operator-()const{return ModInt()-*this;}
	ModInt pow(int64_t n)const{
		ModInt res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}

	ModInt inv()const{return pow(mod-2);}
};

template<uint32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
	return (in>>a.a);
}
template<uint32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
	return (out<<a.a);
}
using mint=ModInt<1000000007>;
//using mint=ModInt<998244353>;

string L;
mint dp[111111][2];
signed main(){
	cin>>L;
	dp[0][0]=1;
	rep(i,L.size()){
		rep(j,2){
			rep(b,2){
				if(!j&&L[i]-'0'<b)continue;
				mint tmp=dp[i][j];
				if(b==1)tmp*=2;
				dp[i+1][j|(L[i]-'0'>b)]+=tmp;
			}
		}
	}
	cout<<dp[L.size()][0]+dp[L.size()][1]<<endl;
	return 0;
}

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
 
deque<int> next_good(deque<int> s) {
    int p = sz(s) - 1;
    while (p >= 0 && s[p] == 9) {
        s[p] = 0;
        p--;
    }
    if (p == -1) {
        s.push_front(1);
    } else {
        s[p]++;
    }
    while (true) {
        int b = -1;
        rep(i, 0, sz(s) - 1) {
            if (abs(s[i] - s[i + 1]) > 1) {
                b = i;
                break;
            }
        }
        if (b == -1) {
            break;
        }
        if (s[b + 1] > s[b]) {
            s[b]++;
        }
        int lll = max(s[b] - 1, 0);
        rep(i, b + 1, sz(s)) {
            s[i] = lll;
            lll = max(lll - 1, 0);
        }
    }
    return s;
}
 
int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;

    int k;
    cin >> k;
    deque<int> ans = {0};
    rep(i, 0, k) {
        ans = next_good(ans);
    }
    for (int i : ans) {
        cout << i;
    }
    cout << "\n";
    return 0;
}
 

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,b,x,y;
	int i,k,r;
	while((scanf("%d %d",&a,&b))!=EOF){
		if(a>b){
			k = a%b;
		}else{
			k = b%a;
		}
		if(k == 0){
			if(a>b){
				x = b;
			}else{
				x = a;
			}
		}else{
			for(i=1;i<k+1;i++){
				if(k%i == 0){
					r = k/i;
					if(a%r == 0 && b%r == 0){
						x = r;
						break;
					}
				}

			}
		}
		y = a * (b/x);
		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 592
s = input()

n = len(s)
l = int((n-1)/2)
b = int((n+3)/2)

for i in range(l - int(l/2)):
    if not s[i] == s[l-1-i]:
        print('No')
        exit()

for i in range(n-b - int((n-b)/2)):
    if not s[b-1+i] == s[n-1-i]:
        print('No')
        exit()

for i in range(int(n/2)):
    if not s[i] == s[n-1-i]:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 3064