akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200010;
int n;
ll ans;
char ch[N];
int s[N],sum[N][3];
int main(){
	scanf("%s",ch+1);
	n=strlen(ch+1);
	int t=0;
	for(int i=1;i<=n;i++){
		if(ch[i]=='A')
			s[++t]=0;
		else if(ch[i]=='B'){
			if(i+1<=n&&ch[i+1]=='C'){
				s[++t]=1;
				i++;
			}
			else
				s[++t]=2;
		}
		else
			s[++t]=2;
	}
	for(int i=1;i<=n;i++){
		for(int t=0;t<=2;t++)
			sum[i][t]=sum[i-1][t];
		sum[i][s[i]]++;
	}
	int tmp;
	for(int i=1;i<=n;i++)
		if(s[i]==0){
			int l=i,r=t;
			tmp=l;
			while(l<=r){
				int mid=(l+r)>>1;
				if(sum[mid][2]-sum[l-1][2]==0)
					tmp=mid,l=mid+1;
				else
					r=mid-1;
			}
			ans+=sum[tmp][1]-sum[i-1][1];
		}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  
int N,n;
  cin >> N;
  if(N==100000)
    cout <<"90909" << endl;
  
  else if(N>=10000){
    N=N-10000+1;
    N=N+900+9;
    cout << N << endl;
  }
  else if(N>=1000){
    cout << "909" << endl;
  }else if(N>=100){
    N=N-100+1;
    N=N+9;
    cout << N << endl;
  }else if(N>=10){
    cout << "9" << endl;
  }else{
    cout << N << endl;
  }
  
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;

struct UnionFind{
	vector<int> parent;
	UnionFind(int N) : parent(N){
		for(int i=0; i<N; i++){
			parent[i] = i;
		}
	}
	int getParent(int x){
		return parent[x];
	}

	int root(int x){
		if(parent[x]==x){
			return x;
		}else{
			parent[x] = root(parent[x]);
			return parent[x];
		}
	}
	void unite(int x, int y){
		int rx = root(x);
		int ry = root(y);
		if(rx!=ry){
			parent[ry] = rx;
		}
	}
	bool same(int x, int y){
		int rx = root(x);
		int ry = root(y);
		return rx==ry;
	}
};

int main(int argc, char* argv[]){
	int N,M;
	scanf("%d %d", &N, &M);
	vector<int>A(M);
	vector<int>B(M);
	UnionFind tree(N);
	for(int i=0; i<M; i++){
		scanf("%d %d", &A[i], &B[i]);
		if(A[i]>B[i]){
			int tmp;
			tmp =  B[i];
			B[i] = A[i];
			A[i] = tmp;
		}
		tree.unite(A[i]-1, B[i]-1);
	}
	int count = 0;
	for(int i=0; i<N; i++){
		if(tree.getParent(i)==i){
			count++;
		}
	}
	printf("%d\n", count-1);

}



Measured memory_bytes: 4588
#include <stdio.h>
#include <algorithm>
int x[200010],y[200010];
int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++)
	{
		int b,c;
		scanf("%d%d",&b,&c);
		x[i] = b-c;
		y[i] = b+c;
	}
	std::sort(x+1,x+a+1);
	std::sort(y+1,y+a+1);
	long long int s1 = x[a]-x[1];
	long long int s2 = y[a]-y[1];
	printf("%lld",s1>s2?s1:s2);
}

Measured memory_bytes: 3296
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

const long long INF = 1e9;
long long dist[100][100];

int main(){

    int N, M;
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i == j){
                dist[i][j] = 0;
            }
            else{
                dist[i][j] = INF;
            }
        }
    }

    vector<pair<pair<int, int>, int>> E(M);

    int a, b, c;
    for(int i = 0; i < M; i++){
        cin >> a >> b >> c;
        dist[a - 1][b - 1] = c;
        dist[b - 1][a - 1] = c;
        E[i] = make_pair(make_pair(a - 1, b - 1), c);
    }

    for(int k = 0; k < N; k++){
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                long long temp = dist[i][k] + dist[k][j];
                if(temp < dist[i][j]){
                    dist[i][j] = temp;
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < M; i++){
        auto temp = E[i];
        int a = temp.first.first;
        int b = temp.first.second;
        int c = temp.second;

        if(dist[a][b] != c){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy


if __name__ == "__main__":
    x,n = map(int,input().split())
    p = set(list(map(int,input().split())))
    ans = 10000000000
    for i in range(-1000,1001):
        if i in p:
            continue
        else:
            d = abs(x-i)
            if d < ans:
               ans = d
               check = i 
    print(check)

Measured memory_bytes: 9608
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
int main()
{
	long long int n, p, a[101], ou = 0, ji = 0, i, j;
	long long int res = 0;
	long long int C[55][55], pow[55];
	C[0][0] = 1;
	pow[0] = 1;
	for (i = 1; i <= 50; i++)
		pow[i] = pow[i - 1] * 2;
	for (i = 0; i <= 50; i++) {
		C[i][0] = 1;
		C[i][i] = 1;
	}
	for (i = 1; i <= 50; i++) {
		for (j = 0; j < i; j++) {
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
		}
	}
	pow[0] = 1;
	scanf("%lld %lld", &n, &p);
	for (i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		if (a[i] % 2)
			ji++;
		else
			ou++;
	}

	for (i = p; i <= ji; i += 2) {
		res += C[ji][i] * pow[ou];
	}
	printf("%lld\n", res);
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int N;
    scanf("%d",&N);

    //A[0]~A[N-1]に格納する
    int* A;
    NEW(A,N);
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
    }

    if(N%2==0){
        for(int i=(N/2)-1;i>=0;i--) printf("%d ",A[i*2+1]);
        for(int i=0;i<N/2;i++) printf("%d ",A[i*2]);
    }
    else{
        for(int i=(N/2);i>=0;i--) printf("%d ",A[i*2]);
        for(int i=0;i<N/2;i++) printf("%d ",A[i*2+1]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 2816
import java.util.Scanner;

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

        int N = sc.nextInt();

        System.out.println(solve(N));

        sc.close();
    }

    static long solve(int N) {
        long prev = 2;
        long curr = 1;
        for (int i = 0; i < N - 1; ++i) {
            long next = prev + curr;

            prev = curr;
            curr = next;
        }

        return curr;
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> arr(101);
int n;
int f(vector<int> v)
{
    if (v.size()==1&&v[0]==0) return 0;
    int m=v.size();
    int mi=INT_MAX;
    int ret=0;
    vector<int> a;
    for (int i=0;i<m;i++) {
        if (mi>v[i]) mi=v[i];
    }
    if (mi<=100) ret+=mi;
    else return 0;
    for (int i=0;i<m;i++) {
        v[i]-=mi;
        if (v[i]==0) {
            ret+=f(a);
            a.clear();
        }
        else a.push_back(v[i]);
    }
    ret+=f(a);
    //printf("%d\n",ret);
    return ret;
}
int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++) {
        scanf("%d",&arr[i]);
    }
    printf("%d",f(arr));
}


Measured memory_bytes: 256
#include <iostream>
    #include <string>
    #include <set>  
    #include <stack>
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
    #include <cassert>
    #include <iomanip>
    #include <sstream>
    #include <ctime>
    #include <bitset> 
using namespace std;
#define for1(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,maxn) for1(i,0,maxn)
#define ford(i,b,a) for(int i=(int)(b)-1;i>=a;--i)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii > piii;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define dprintf(...) printf(__VA_ARGS__)
string s;
int n;
map<string,int> m;
int main()
{
	cin>>n>>s;
	rep(i,(1<<n))
	{
		string red="",ble="";
		rep(j,n)
		{
			if(i&(1<<j))
			{
				red.pb(s[j]);
			}
			else
			{
				ble.pb(s[j]);
			}
		}
	//	cout<<red<<" "<<ble<<endl;
	//	system("pause"); 
		m[red+" "+ble]++;
	}
	ll ans=0;
	reverse(s.begin(),s.end());
	rep(i,(1<<n))
	{
		string red="",ble="";
		rep(j,n)
		{
			if(i&(1<<j))
			{
				ble.pb(s[j]);
			}
			else
			{
				red.pb(s[j]);
			}
		}
		ans+=m[red+" "+ble];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 67200
N = int(input())
s = sorted([int(input()) for _ in range(N)])
if sum(s)%10 != 0:
    print(sum(s))
else:
    for i in range(N):
        if s[i]%10 != 0:
            print(sum(s)-s[i])
            break
        if i == N-1:
            print(0)

Measured memory_bytes: 3060
n,k=map(int,input().split())
l=list(map(int,input().split()))
l=[i+1 for i in l]
t=sum(l[:k])
ans=t
for i in range(k,n):
    t+=l[i]-l[i-k]
    ans=max(ans,t)
print(ans/2)

Measured memory_bytes: 77448
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  map<long long, int> mp;
  mp[0] = 1;
  long long ans = 0;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum = (sum + a[i]) % m;
    ans += mp[sum];
    mp[sum] += 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

string s, t;
int dp[3300][3300];
int main(){
    cin >> s >> t;
    int n = s.size(), m = t.size();

    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= m;j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i-1] == t[j-1]){
                dp[i][j] = max(dp[i-1][j-1] + 1, dp[i][j]);
            }
        }
    }

    string rewsna = "";

    while(n > 0 && m > 0){
        if(dp[n][m] == dp[n-1][m])n--;
        else if(dp[n][m] == dp[n][m-1])m--;
        else {
            rewsna += s[n-1];
            n--;
            m--;
        }
    }

    int l = rewsna.size();
    for(int i = 0;i < l;i++){
        cout << rewsna[l-i-1];
    }cout << endl;
    
    return 0;
}


Measured memory_bytes: 39168
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n;
int a[3*100001];
ll lmax[100002];
ll rmin[100002];
const ll inf=(ll)1e18;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1=freopen("in","r",stdin);
    //stream2=freopen("out","w",stdout);
    if(stream1==NULL)return 0;
    //if(stream2==NULL)return 0;
#endif
    cin>>n;
    ll suml=0,sumr=0;
    for(int i=0;i<3*n;i++){
        cin>>a[i];
        if(i<n)suml+=a[i];
    }
    priority_queue<int> l;
    for(int i=0;i<n;i++){
        l.push(-a[i]);
    }
    lmax[0]=suml;
    for(int i=0;i<n;i++){
        l.push(-a[n+i]);
        suml+=a[n+i]+l.top();
        l.pop();
        lmax[i+1]=suml;
    }
    priority_queue<int> r;
    for(int i=0;i<n;i++){
        r.push(a[2*n+i]);
        sumr+=a[2*n+i];
    }
    rmin[n]=sumr;
    for(int i=0;i<n;i++){
        r.push(a[2*n-1-i]);
        sumr+=a[2*n-1-i]-r.top();
        r.pop();
        rmin[n-1-i]=sumr;
    }
    ll ans=-inf;
    for(int i=0;i<=n;i++){
        //cerr<<lmax[i]<<" "<<rmin[i]<<endl;
        ans=max(ans,lmax[i]-rmin[i]);
    }
    cout<<ans<<endl;
#ifdef LOCAL_DEFINE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    fclose(stream1);
    //fclose(stream2);
#endif
    return 0;
}


Measured memory_bytes: 3960
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int N;
int A[20], B[20];
int dp[20][1 << 20];

int main(void) {
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, N) {
        cin >> B[i];
    }

    REP(i, N) REP(j, 1 << N) {
        dp[i][j] = INF;
    }

    REP(i, N) {
        dp[i][1 << i] = i;
    }
    REP(bit, 1 << N) {
        const int bit_cnt = __builtin_popcount(bit);
        REP(j, N) if ((bit & (1 << j)) && dp[j][bit] < INF) {
            const int cur_val = (abs(bit_cnt - j - 1) % 2 == 0 ? A : B)[j];
            REP(k, N) if ((bit & (1 << k)) == 0) {
                const int nxt_val = ((abs(bit_cnt - k) % 2 == 0 ? A : B)[k]);
                if (nxt_val < cur_val) continue;
                int add = 0;
                REP(l, k) add += (bit & (1 << l)) == 0;
                chmin(dp[k][bit | (1 << k)], dp[j][bit] + add);
            }
        }
    }

    // REP(i, N) REP(j, (1 << N)) cout << i << " " << j << " " << dp[i][j] << endl;

    int ans = INF;
    REP(i, N) {
        chmin(ans, dp[i][(1 << N) - 1]);
    }
    if (ans == INF) {
        ans = -1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 36096
#include<bits/stdc++.h>
using namespace std;
int n,k,a[507],sum,p[507];
vector<int>q;
bool qz(int x){
	int mo=0,Mo=0;
	for(int i=1;i<=n;i++){
		p[i]=a[i]-a[i]/x*x;
		mo+=p[i];
	}
	sort(p+1,p+n+1);
	for(int i=1;i<=n;i++){
		Mo+=p[i];
		if(mo==(n-i)*x)break;
	}
	return Mo<=k;
}
int main() {
	scanf("%d%d",&n,&k);
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]),sum+=a[i];
	sort(a+1,a+n+1);
	for(int i=1; i*i<=sum; i++)if(sum%i==0)
			q.push_back(i),q.push_back(sum/i);
	sort(q.begin(),q.end());
	for(int i=q.size()-1; i>=0; i--)
		if(qz(q[i])) {
			printf("%d\n",q[i]);
			return 0;
		}
	return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val n = readLine()!!.toLong()

    var ans = n
    for(i in (1..n)) {
        if(i*i > n) {
            break
        }
        if(n % i == 0L) {
            val tmp = (i-1) + (n/i-1)
            ans = Math.min(ans, tmp)
        }
    }
    println(ans)
}


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

int main(){
    int ans[10]={0},mm[5]={0,6000,4000,3000,2000};
    for(int i=0;i<4;i++){
        int t,n;
        cin>>t>>n;
        ans[i]=mm[t]*n;
        }
    for(int i=0;i<4;i++){
            cout<<ans[i]<<endl;
    }
        return 0;
    }

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<map>
#include<bitset>
///////////////////////////////////////////
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define F first
#define S second
long long qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
int qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e18;


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

int main() {
	int n, m; cin >> n >> m;
	vector<long long> x(n), y(n), z(n);
	rep(n) cin >> x[i] >> y[i] >> z[i];
	long long ans = -1 * INF;
	for (int i = 0; i <= 1; i++) { //x
		for (int j = 0; j <= 1; j++) {//y
			for (int k = 0; k <= 1; k++) { //z
				vector<long long> lyn(n);
				int a, b, c;
				(i == 0) ? a = 1 : a = -1;
				(j == 0) ? b = 1 : b = -1;
				(k == 0) ? c = 1 : c = -1;
				rep(n) lyn[i] = a * x[i] + b * y[i] + c * z[i];
				sort(all(lyn)); reverse(all(lyn));
				long long res = 0;
				rep(m) res += lyn[i];
				ans = max(ans, res);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    h, w = map(int, input().split())
    n = int(input())
    a = [-1] + [int(x) for x in input().split()]
    for i in range(1, n + 1):
        a[i] += a[i - 1]
    answer = ["-1" for _ in range(w * h)]
    index = 0
    for i in range(h * w):
        if not (a[index] < i <= a[index + 1]):
            index += 1
        answer[i] = str(index + 1)
    for i in range(h):
        if i % 2 == 0:
            print(" ".join(answer[i * w: (i + 1) * w]))
        else:
            print(" ".join(reversed(answer[i * w: (i + 1) * w])))


if __name__ == '__main__':
    main()



Measured memory_bytes: 4084
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

char str[1001];
int cnt[256];
int main() {
    scanf("%s", str);
    for (int i = 0; str[i]; ++i) {
        cnt[str[i]] = 1;
    }
    if (cnt['W'] == cnt['E'] && cnt['N'] == cnt['S']) printf("Yes\n");
    else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))

if N >= M:
    print(0)
else:
    A.sort()
    diff = []
    for i in range(M - 1):
        diff.append(A[i + 1] - A[i])

    diff.sort(reverse=True)
    print(sum(diff[N - 1 :]))


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

int main() {
    int n;
    vector<int> v;
    cin >> n;
    v.resize(n);
    map<int, int> cnt;
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
        cnt[v[i]]++;
    }

    sort(v.begin(), v.end());

    for(int i = 1; n - i > 0; i += 2) {
        if (cnt[n - i] != 2) {
            cout << 0 << endl;
            return 0;
        }
    }

    if (n % 2 == 1 && cnt[0] != 1) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 1;
    for (int i = 0; i < n / 2; ++i) {
        ans *= 2;
        ans %= 1000000007;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3584
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        String s = std.next();
        String[] vowels = {"a", "i", "u", "e", "o"};
        if (Arrays.asList(vowels).contains(s)) {
            System.out.println("vowel");
        } else {
            System.out.println("consonant");
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() {
  int X[300][300],cnt=0;
  for(int i=0; i<300; i++) {
      cin >> X[i][0] >> X[i][1];
      if(X[i][0]==0&&X[i][1]==0) {
          cnt=i;
          break;
      }
  }
  for(int i=0; i<cnt; i++) {
      for(int j=0; j<X[i][0]; j++) {
          for(int k=0; k<X[i][1]; k++) {
              if((j+k)%2==0) {
                  cout << '#';
              }
              else {
                  cout << '.';
              }
          }
          cout << endl;
      }
      cout << endl;
  }
}


Measured memory_bytes: 3124
/*



*/

#include <stdio.h>
#include <stdbool.h>

#define SIZE 1000001

//エラトステネスのふるい	0か1のみが入る
bool hurui[SIZE];

//素数リスト	0〜1,000,000までの範囲で、素数が入る。	数は78,500くらいらしい。
int primeList[SIZE] = {0};


//エラトステネスのふるいを作る関数。
int makeHurui(void);


int check(int data[], int key, int pos, int to);



int main(){
	
	int i, k;
	int n;
	int count = 0;
	
	k = makeHurui();
	
	
	while(1){
		
		scanf("%d", &n);
		
		if(n == 0){
			
			break;
			
		}
		
		printf("%d\n", check(primeList, n, 0, k));
		
	}
	
	
	
	return 0;
	
}



int makeHurui(void){
	
	int i, k;
	int m = 0;
	
	for(i=0; i<SIZE; i++){
		
		hurui[i] = 1;
		
	}
	
	hurui[0] = 0;
	hurui[1] = 0;
	
	for(i=2; i<SIZE; i++){
		
		if(hurui[i] == 1){
			
			for(k=i+i; k<SIZE; k+=i){
				
				hurui[k] = 0;
				
			}
			
			
			primeList[m] = i;
			m++;
			
		}
		
	}
	
	return m;
	
}



int check(int data[], int key, int pos, int to){
	
	int count = 0;
	
	if(data[pos] > key/2){
		
		return 0;
		
	}
	
	if(hurui[key - data[pos]] == 1){
		
		count++;
		//printf("%d, %d\n", data[pos], key-data[pos]);
		
	}
	
	return count + check(data, key, pos+1, to);
	
}

Measured memory_bytes: 3744
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pii pair<int,int>
#define ti3 tuple<ll,ll,ll>

struct BIT
{
    std::vector<int> bit;
    
    BIT(int size) : bit(size, 0){ }
    
    void add(int k, int x) {
        while (k < bit.size()) {
            bit[k] += x;
            k += k &-k;
        }
    }
    int sum(int k) {
        int res = 0;
        while (k > 0) {
            res += bit[k];
            k -= k&-k;
        }
        return res;
    }
};

struct UnionFind {
    vector<int> data;
    
    UnionFind(int size) : data(size, -1) { }
    
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y)
        {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

ll n, m;

int main(void)
{
    cin >> n >> m;
    auto s = n;
    auto c = m / 2;
    if(s >= c)
    {
        cout << c << endl;
        return 0;
    }
    else
    {
        ll sum = s;
        c-=s;
        sum += c/2;
        cout << sum << endl;
    }
    
    return 0;
}

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

const int L = 100005;

string s, t;

int a[L][26];

int main() {
  cin >> s >> t;
  rep(i, s.size()) rep(j, 26) a[i][j] = -1;
  rep(j, 26) {
    char c = 'a' + j;
    vector<int> cp;
    rep(i, s.size()) if (s[i] == c) cp.push_back(i);
    if (cp.size() == 0) continue;
    cp.push_back(cp[0]);
    int cpi = 0;
    rep(i, s.size()) {
      if (i == cp[cpi]) cpi++;
      a[i][j] = cp[cpi];
    }
  }
  // rep(i, s.size()) {
  //   rep(j, 26) printf("%d ", a[i][j]);
  //   printf("\n");
  // }
  int si = s.size()-1;
  ll ans = 0;
  rep(ti, t.size()) {
    int nsi = a[si][t[ti] - 'a'];
    if (nsi == -1) {
      ans = -1;
      break;
    }
    ans += nsi - si;
    if (nsi <= si) ans += s.size();
    si = nsi;
    // printf("ans = %lld\n", ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14376
#include <iostream>

using namespace std;
int main() {

	int a, b, c, i, x = 0;

	cin >> a >> b >> c;

	for (i = a; i <= b; i++) {
		if (c%i == 0) {
			x++;
		}
	}
	cout << x << endl;

	return 0;
}


Measured memory_bytes: 3100
N = int(input())
A = list(map(int, input().split()))

r = 0
res = 0
x = 0
s = 0
for l in range(N):
    while r < N and x ^ A[r] == s + A[r]:
        x ^= A[r]
        s += A[r]
        r += 1
    res += r - l

    if r == l:
        r += 1
    else:
        x ^= A[l]
        s -= A[l]

print(res)

Measured memory_bytes: 77900
package main

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

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()
	c := nextInt()
	k := nextInt()

	m := max(a, max(b, c))

	fmt.Println(a + b + c - m + m<<k)

}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int num;
    cin >> num;
    vector<int> arr(num); cins(arr);
    vector<int> brr(num); cins(brr);

    vector<int> pos;
    int64_t neg = 0;
    int ans = 0;
    for(int i = 0; i < num; i++) {
    int save = arr[i] - brr[i];
        if(save > 0) {
            pos.push_back(save);
        } else if (save == 0) {
            ans++;
        } else {
            neg += (-save);
        }
    }
    sort(pos.begin(), pos.end());
    while(neg > 0) {
        if(pos.empty()) {
            cout << -1 << endl;
            return 0;
        }
        int val = pos.back(); pos.pop_back();
        debug("%d -> %d\n", val, neg-val);
        neg -= val;
    }
    ans += pos.size();
    cout << num-ans << endl;
    return 0;
}

Measured memory_bytes: 4428
N = int(input())
A = list(map(int, input().split()))
x = 0
y = 0
z = 0
for i in range(N):
  a = A[i]
  c = 0
  while a%2== 0:
      a = a//2
      c += 1
  if c == 0:
    x += 1
  elif c == 1:
    y += 1
  else:
    z += 1
ans = 'No'
if x<=z:
  ans = 'Yes'
elif y == 0 and x==z+1:
  ans = 'Yes'
  
print(ans)
  

Measured memory_bytes: 14252
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;

typedef pair<int,bool> Pair;

int main(){

  int A,B;
	
  cin >> A >> B;
	
  if((A+B)%2 == 0) cout << (A+B)/2 << endl;
  else cout << "IMPOSSIBLE" << endl;
	
  return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

//2つの要素をまとめてソート、前の変数が優先。flag=0で小さい順、1で大きい順
void mysort2(vi &a,vi &b,ll flag){
  if (a.size()>0){
    vector<pair<ll, ll>> p(a.size());
    REP(i,a.size()){
      p[i].first=a[i];
      p[i].second=b[i];
    }
    sort(p.begin(),p.end());
    if (flag==1){
      reverse(p.begin(),p.end());
    }
    REP(i,a.size()){
      a[i]=p[i].first;
      b[i]=p[i].second;
    }
  }
  return;
}




int main(){
  ll ans=0;
  cin >> n;
  vector<string> s(n);
  vi inc(n),higt(n),mns(n);
  REP(i,n) cin>>s[i];

  string ss;

  REP(i,n){
    ss=s[i];

    ll mn=0;
    for(ll k=0;k<ss.length();k++){
      inc[i]+=1-(ll)(ss[k]-40)*2;
      mn=min(mn,inc[i]);
    }
    mns[i]=mn;
    higt[i]=min(inc[i]-mn,-mn);
  }







  ll tmp=0;
  ll plusn=0;
  for(ll i=0;i<n;i++){
    tmp+=inc[i];
    if (inc[i]>=0)plusn++;
  }
  if (tmp!=0){
    cout<<"No"<<endl;
    return 0;
  }

  //高くしていく
  //incがプラスでheightが低い順に
  tmp=0;
  vi incp(plusn),higtp(plusn);

  for(ll i=0;i<n;i++){
    if (inc[i]>=0){
      incp[tmp]=inc[i];
      higtp[tmp]=higt[i];
      tmp++;
    }
  }

  mysort2(higtp,incp,0);

  ll nowhight=0;
  
  for(ll i=0;i<plusn;i++){
    if (nowhight<higtp[i]){
      cout<<"No"<<endl;
      return 0;
    }
    nowhight+=incp[i];
  }


  //下げていく
  nowhight=0;
  ll mnusn=n-plusn;
  vi incm(mnusn),higtm(mnusn);

  tmp=0;
  for(ll i=0;i<n;i++){
    if (inc[i]<0){
      incm[tmp]=-inc[i];
      higtm[tmp]=higt[i];
      tmp++;
    }
  }
  
  mysort2(higtm,incm,0);

  for(ll i=0;i<mnusn;i++){
    if (nowhight<higtm[i]){
      cout<<"No"<<endl;
      return 0;
    }
    nowhight+=incm[i];
  }

  /*
  mysort2(higtm,incm,1);
  

  for(ll i=0;i<mnusn;i++){
    nowhight+=incm[i];
    if (nowhight<higtm[i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  */




  cout<<"Yes"<<endl;
  return 0;

}

Measured memory_bytes: 81260
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>num(n);
  for(int i = 0; i<n;i++){
    cin >> num[i];}
  bool ok = 1;
  for(int i=0;i<n;i++){
    if (num[i]%2==0){
      if(num[i]%3==0){
        ok = 1;}
      else if(num[i]%5==0){
        ok = 1;}
      else{ok = 0;
           break;}
    }
  }
      if(ok==0){cout << "DENIED";}
    else{cout << "APPROVED";}
    return 0;
  }

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

using namespace std;

int in(){ int a; cin >> a; return a; }
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main(){
  ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0); cerr.tie(0);
  long long a, b, k;
  cin >> a >> b >> k;
  if(a + b <= k){
    cout << "0 0" << endl;
    return 0;
  }
  long long a2 = a;
  a = max(0LL, a - k);
  k = max(0LL, k - a2);
  if(k == 0){
    cout << a << " " << b << endl;
    return 0;
  }
  b -= k;
  cout << a << " " << b << endl;
  return 0;
}



Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(10**7)

N=int(input())
A=[list(map(int,input().split())) for _ in range(N-1)]
C=[0]*N
D=[[] for i in range(N)]
for u,v,w in A:
  u-=1
  v-=1
  D[u].append((v,w))
  D[v].append((u,w))

def dfs(n,v,k):
  for i in D[n]:
    if k%2!=0:
      C[n]=1
    if v!=i[0]:
      dfs(i[0],n,k+i[1])       
        
dfs(0,0,0)

for i in C:
  print(i)

Measured memory_bytes: 99748
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int numOfPeople = sc.nextInt();
        int numOfFoodTypes = sc.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        int numOfResponses = 0;
        int cnt = 0;

        for (int i = 0; i < numOfPeople; i++) {
            numOfResponses = sc.nextInt();
            for (int j = 0; j < numOfResponses; j++) {
                int A = sc.nextInt();
                map.put(A, map.getOrDefault(A, 0) + 1);
            }
        }

        for (int i = 1; i <= numOfFoodTypes; i++) {
            if (map.containsKey(i) && map.get(i) == numOfPeople) {
                cnt++;
            }
        }

        System.out.println(cnt);

    }
}




Measured memory_bytes: 21200
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;
using ll = long long;

#define loopi(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define loop(i, n) for (int i = 0; i < (int)n; i++)
#define loopeq(i, n) for (int i = 0; i <= (int)n; i++)
#define loopll(i, n) for (ll i = 0; i < (ll)n; i++)
#define looplleq(i, n) for (ll i = 0; i <= (ll)n; i++)

int main() {
    int n; cin >> n;
    ll sum = 0;
    loopi(i, 1, n + 1) {
        if (i % 3 != 0 && i % 5 != 0) sum += i;
    }
    cout << sum << endl;
}

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

class Dice{
public:
	int num[6];

	Dice(int a, int b, int c, int d, int e, int f);
	void roll(char s);
	void mroll(string s);
	bool rolluf(int a, int b);
};

Dice::Dice(int a, int b, int c, int d, int e, int f){
	num[0] = a;
	num[1] = b;
	num[2] = c;
	num[3] = d;
	num[4] = e;
	num[5] = f;
}

void Dice::roll(char s){
	int dum;
	switch (s)
	{
		case 'N':
			dum = num[0];
			num[0] = num[1];
			num[1] = num[5];
			num[5] = num[4];
			num[4] = dum;
			break;
		case 'E':
			dum = num[0];
			num[0] = num[3];
			num[3] = num[5];
			num[5] = num[2];
			num[2] = dum;
			break;
		case 'W':
			dum = num[0];
			num[0] = num[2];
			num[2] = num[5];
			num[5] = num[3];
			num[3] = dum;
			break;
		case 'S':
			dum = num[0];
			num[0] = num[4];
			num[4] = num[5];
			num[5] = num[1];
			num[1] = dum;
			break;
		case 'R':
			dum = num[1];
			num[1] = num[2];
			num[2] = num[4];
			num[4] = num[3];
			num[3] = dum;
			break;
		case 'L':
			dum = num[1];
			num[1] = num[3];
			num[3] = num[4];
			num[4] = num[2];
			num[2] = dum;
			break;
		default:
			break;
	}
	return;
}

void Dice::mroll(string s){
	for (int i = 0; s[i] != '\0'; i++){
		roll(s[i]);
	}
	return;
}

bool Dice::rolluf(int a, int b){
	for (int j = 0; j < 3; j++){
		if (num[0] == a) break;
		roll('N');
		if (num[0] == a) break;
		roll('E');
	}
	if (num[0] != a) return false;
	for (int j = 0; j < 4; j++){
		if (num[1] == b) break;
		roll('L');
	}
	if (num[1] != b) return false;
	return true;
}

bool diceequal(Dice a, Dice b){
	return (a.num[0] == b.num[0] && a.num[1] == b.num[1] && a.num[2] == b.num[2] && a.num[3] == b.num[3] && a.num[4] == b.num[4] && a.num[5] == b.num[5]);
}

bool dicecmp(Dice a, Dice b){
	for (int i = 0; i < 6; i++){
		for (int j = 0; j < 4; j++){
			if (diceequal(a, b)) return true;
			b.roll('L');
		}
		b.roll(i % 2 == 0 ? 'N' : 'E');
	}
	return false;
}

int main(){
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	Dice dice1(a, b, c, d, e, f);
	cin >> a >> b >> c >> d >> e >> f;
	Dice dice2(a, b, c, d, e, f);
	cout << (dicecmp(dice1, dice2) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3108
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

const ll mod = 1000000007;

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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

ll n, m;
ll x[100010], y[100010];

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

  rep( i, n )
    scanf( "%lld", x+i );
  rep( i, m )
    scanf( "%lld", y+i );

  std::sort( x, x+n );
  std::sort( y, y+m );
  
  mint xsum = 0, ysum = 0;

  rep( i, n )
    xsum += mint(i)*x[i]-mint(n-i-1)*x[i];

  rep( i, m )
    ysum += mint(i)*y[i]-mint(m-i-1)*y[i];

  printf( "%lld\n", (xsum*ysum).x );

  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/


int main(){
    int N; cin >> N;
    vi t(N),ts(N+2,0),v(N);
    rep(i,N) cin >> t[i];
    rep(i,N) cin >> v[i];
    for_each(all(t),[](int& x) mutable {x*=2;});
    rep(i,N) ts[i+1] = ts[i] + t[i];        // ts[i] <= t <= ts[i+1] --> v[i]


    ll last = 0;
    rep(i,N) last += t[i];

    vector<double> up(last+10,10000);

    for(int now=0;now<=last;now++){
        chmin(up[now],0.5*now);
        chmin(up[now],0.5*(last-now));
    }

    rep(i,N){
        for(int now=0;now<=ts[i];now++){
            chmin(up[now],v[i]+0.5*(ts[i]-now));
        }
        for(int now=ts[i];now<=ts[i+1];now++){
            chmin(up[now],v[i]);
        }
        for(int now=ts[i+1];now<=last;now++){
            chmin(up[now],v[i]+0.5*(now-ts[i+1]));
        }
    }

    double ans = 0;
    for(int i=0;i<=last;i++){
        ans += up[i];
    }
    cout << Double(ans/2) << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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() {
    int n;
    cin >> n;
    vector<ll>a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans = 0;
    rep(i,n) {
        ll j = upper_bound(c.begin(),c.end(),b[i]) - c.begin();
        ll sum_c = c.size() - j;
        ll k = lower_bound(a.begin(),a.end(),b[i]) - a.begin();
        ll sum_a = k;
        ans += sum_c*sum_a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int a[][4],int b[][4][16],int x,int y,int gx,int gy,int n){
  int i=0;
  if(n==0){
    if(x==gx&&y==gy)
      return 1;
    else
      return 0;
  }
  if(b[x][y][n])
    return b[x][y][n];
  if(a[x-1][y])
    i++;
  else
    b[x][y][n]+=f(a,b,x-1,y,gx,gy,n-1);
  if(a[x][y-1])
    i++;
  else
    b[x][y][n]+=f(a,b,x,y-1,gx,gy,n-1);
  if(a[x+1][y])
    i++;
  else
    b[x][y][n]+=f(a,b,x+1,y,gx,gy,n-1);
  if(a[x][y+1])
    i++;
  else
    b[x][y][n]+=f(a,b,x,y+1,gx,gy,n-1);
  b[x][y][n]+=f(a,b,x,y,gx,gy,n-1)*i;
  return b[x][y][n];
}
int main(){
  int i,j;
  int a[4][4],b[4][4][16],n,sx,sy,gx,gy;
  char s;
  memset(a,-1,sizeof(a));
  while(cin>>n&&n){
    for(i=1;i<4;i++)
      for(j=1;j<4;j++)
	a[j][i]=0;
    cin>>s;
    sx=(s-'A')%3+1;
    sy=(s-'A')/3+1;
    cin>>s;
    gx=(s-'A')%3+1;
    gy=(s-'A')/3+1;
    cin>>s;
    a[(s-'A')%3+1][(s-'A')/3+1]=-1;
    memset(b,0,sizeof(b));
    printf("%.8lf\n",f(a,b,sx,sy,gx,gy,n)/pow(4,n));
  }
  return 0;
}

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

int main() {
  string S;
  cin >> S;
 
  for (char c = 'a'; c <= 'z'; c++){
    if (count(S.begin(), S.end(), c) == 0){
      cout << c << endl;
      return 0;
    }
  }
 
  cout << "None" << endl;;
 
  return 0;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
n=INT()
a=["a" for i in range(n)]
def f(num):
    global n,a
    if num==n:
        print("".join([str(n) for n in a]))
        return
    elif num==1:
        a[num]="a"
        f(num+1)
        a[num]="b"
        f(num+1)
    else:
        a[num]="a"
        f(num+1)
        a[num]="b"
        f(num+1)
        try:
            if a.index("b")<num:
                a[num]="c"
                f(num+1)
            if a.index("c")<num:
                a[num]="d"
                f(num+1)
            if a.index("d")<num:
                a[num]="e"
                f(num+1)
            if a.index("e")<num:
                a[num]="f"
                f(num+1)
            if a.index("f")<num:
                a[num]="g"
                f(num+1)
            if a.index("g")<num:
                a[num]="h"
                f(num+1)
            if a.index("h")<num:
                a[num]="i"
                f(num+1)
            if a.index("i")<num:
                a[num]="j"
                f(num+1)
        except:
            pass
f(1)
    

Measured memory_bytes: 4468
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int W = sc.nextInt();
    int[] w = new int[N];
    int[] v = new int[N];
    for (int i = 0; i < N; i++) {
      w[i] = sc.nextInt();
      v[i] = sc.nextInt();
    }
    sc.close();

    long[] dp = new long[W + 1];
    for (int i = 0; i < N; i++)
      for (int j = W; w[i] <= j; j--)
        dp[j] = Math.max(dp[j], dp[j - w[i]] + v[i]);

    long ans = 0;
    for (long val : dp) ans = Math.max(ans, val);
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
#include<stdio.h>
#include <string.h>
#include <string>
#include <iostream>

using namespace std;

int main(){
	string t, h;
	int n,i,tp=0,hp=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		cin >> t >> h;
		if(t>h)tp+=3;
		else if(t<h)hp+=3;
		else {
			tp+=1;
			hp+=1;
		}
	}
	printf("%d %d\n",tp,hp);
	return 0;
}

Measured memory_bytes: 3296
#include<stdio.h>
int main(void){
	int x;
	scanf("%d",&x);
	switch(x%7){
		case 1:
			printf("fri\n");
			break;
		case 2:
			printf("sat\n");
			break;
		case 3:
			printf("sun\n");
			break;
		case 4:
			printf("mon\n");
			break;
		case 5:
			printf("tue\n");
			break;
		case 6:
			printf("wed\n");
			break;
		case 0:
			printf("thu\n");
			break;
	}
	return 0;
}



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

using namespace std;

int main(){
	int N;
    cin >> N;
	int H[N];
	int k=0,max_k=0;
	for(int i=0;i<N;i++){
		cin>>H[i];
	}
	for(int i = 0;i<N-1;i++){
		if(H[i]>=H[i+1]){
			k++;
		}
		else{
			k = 0;
		}
		if(k>max_k)
			max_k = k;
	}
	cout<<max_k;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  int N;
  cin >> N;
  vector<int>A(N);
  for (int i = 0; i < N; i ++) cin >> A[i];
  int ma = A[0];
  ll ans = 0;
  for (int i = 1; i < N; i ++) {
    ans += (ll)max(ma - A[i], 0);
    ma = max(ma, A[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048