akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#define LL long long
#define db double

using namespace std;
const int N=2e5+10,mod=1e9+7;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
struct node
{
	int x,y;
	bool operator < (const node &bb) const {return y!=bb.y?y<bb.y:x<bb.x;}
}b[N],a[N];
int n,mx[N][20],mi[N][20],l2[N],sm=1;
int gmx(int l,int r)
{
	int z=l2[r-l+1];
	return max(mx[l][z],mx[r-(1<<z)+1][z]);
}
int gmi(int l,int r)
{
	int z=l2[r-l+1];
	return min(mi[l][z],mi[r-(1<<z)+1][z]);
}
int c[N];
void ad(int x,int y){while(x<=n) c[x]=(c[x]+y)%mod,x+=x&(-x);}
int gsm(int x){int an=x>=0;while(x>0) an=(an+c[x])%mod,x-=x&(-x);return an;}

int main()
{
    //gugugu
	n=rd();
	for(int i=1;i<=n;++i) b[i].x=rd(),b[i].y=rd();
	sort(b+1,b+n+1);
	for(int i=1;i<=n;++i) mx[i][0]=mi[i][0]=b[i].x;
	for(int i=2;i<=n;++i) l2[i]=l2[i>>1]+1;
	for(int j=1;j<=l2[n];++j)
		for(int i=1;i+(1<<j)-1<=n;++i)
		{
			mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
			mi[i][j]=min(mi[i][j-1],mi[i+(1<<(j-1))][j-1]);
		}
	for(int i=1;i<=n;++i)
	{
		a[i].x=a[i].y=i;
		int l=1,r=i-1;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(gmx(1,mid)>b[i].x) a[i].x=mid,r=mid-1;
			else l=mid+1;
		}
		l=i+1,r=n;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(gmi(mid,r)<b[i].x) a[i].y=mid,l=mid+1;
			else r=mid-1;
		}
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i)
	{
		int ll=a[i].x,rr=a[i].y;
		int nf=(sm-gsm(ll-2)+mod)%mod;
		sm=(sm+nf)%mod;
		ad(rr,nf);
	}
	printf("%d\n",(sm-gsm(n-1)+mod)%mod);
    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m,q; cin>>n>>m>>q;
	vector<int>a(q),b(q),c(q),d(q);
	for(int i=0;i<q;++i){
		cin>>a.at(i)>>b.at(i)>>c.at(i)>>d.at(i);
		--a.at(i),--b.at(i);
	}
	int ans=0;
	vector<int>A(n,0),lim(n,m-1); A.back()=-1;
	while(A!=lim){
		for(int i=n-1;i>=0;--i){
			if(A.at(i)<m-1){
				++A.at(i);
				for(int j=i;j<n;++j)A.at(j)=A.at(i);
				break;
			}
		}
		int sum=0;
		for(int i=0;i<q;++i){
			if(A.at(b.at(i))-A.at(a.at(i))==c.at(i))sum+=d.at(i);
		}
		ans=max(ans,sum);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 3628
class Node:
    id = None
    depth = None
    degree = None
    parent = None
    children = None

    def __init__(self, id):
        self.id = id

    def __str__(self):
        if self.degree == 0:
            children_str = '[]'
        else:
            children_id = []
            for child in self.children:
                children_id.append(child.id)
            children_str = '[' + ', '.join(map(str, children_id)) + ']'

        return 'node {}: parent = {}, depth = {}, {}, {}'.format(self.id, self.parent, self.depth, self.get_type(), children_str)

    def get_type(self):
        if self.depth == 0:
            return 'root'
        elif self.degree == 0:
            return 'leaf'
        else:
            return 'internal node'

    def add_child(self, child):
        if self.children is None:
            self.children = []
            self.children.append(child)
        else:
            self.children.append(child)


def set_children_depth(node):
    if node.degree != 0:
        for child in node.children:
            child.depth = node.depth + 1
            set_children_depth(child)


n = int(input())

nodes = []
for i in range(n):
    nodes.append(Node(i))
# nodes[0].depth = 0
# nodes[0].parent = -1
#
# for i in range(n):
#     _ = list(map(int, input().split()))
#     nodes[i].degree = _[1]
#
#     if _[1] >= 1:
#         nodes[i].children = _[2:]
#         for j in range(_[1]):
#             nodes[_[j+2]].depth = nodes[i].depth + 1
#             nodes[_[j+2]].parent = i
#
# for i in range(n):
#     print(nodes[i])

for i in range(n):
    _ = list(map(int, input().split()))
    # print(_)
    id = _[0]
    nodes[id].degree = _[1]
    if _[1] >= 1:
        for j in range(_[1]):
            nodes[id].add_child(nodes[_[j+2]])
            nodes[_[j+2]].parent = id
    # print(nodes[i])

root_id = -1
for i in range(n):
    if nodes[i].parent is None:
        nodes[i].parent = -1
        nodes[i].depth = 0
        root_id = i
        break

# for i in range(n):
#     print(nodes[i])
#     print(nodes[i].degree)

set_children_depth(nodes[root_id])

for i in range(n):
    print(nodes[i])



Measured memory_bytes: 48032
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n;
	vector<vector<int>>v(n, vector<int>(3));
	rep(i, 0, n)rep(j, 0, 3)cin >> v[i][j];
	vector<int>ans(n, 0);
	rep(i, 0, 3) {
		vector<int>t(150, 0);
		rep(j, 0, n) {
			t[v[j][i]]++;
		}
		rep(j, 0, n) {
			if (t[v[j][i]] == 1)ans[j] += v[j][i];
		}

	}
	rep(i, 0, n) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <vector>
using namespace std;
int main(){
    int n,a[200],c=0;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    while(1){
        for(int i=0;i<n;i++){
            if(a[i]%2==0)a[i]/=2;
            else{
                cout<<c<<endl;
                return 0;
            }
        }
        c++;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define inf INF
#define out(i) cout<<i<<endl;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}

signed main(){
  int a,b;
  cin>>a>>b;
  int c=b-a+1;
  c/=2;
  c%=2;
  int res;
  if(a%2==0){
    if(b%2==0)res=b^c;
    else res=c;
  }
  else {
    if(b%2==0)res=a^b^(c^1);
    else res=a^c;
  }
  out(res);

  return 0;
}



Measured memory_bytes: 256
// http://yumai6.hatenablog.com/entry/2015/12/21/222930

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define mp(x, y) make_pair(x, y)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

//---------------------------------------------------------------
// Ｎ個の県、Ｍ個の市　市に１２桁のコードを振る
// 上６桁は県の番号、下６件は県の中での市の誕生順の連番
//---------------------------------------------------------------

int N, M;

// インデックスが県、map key:年 value:市
map<int, int> v[100010];

// 市をインデックスとし、県の番号と市の順番（県の中での）を保存する
int ans[100010][2];

signed main(){
	cin >> N >> M;
	
	map<int, int> *d;
	int p, y;
	REP(i, M) {				// 市の数分、読み込む
		cin >> p >> y;		// 県番号と市の誕生年
		
		d = &v[p - 1];
		if (d == NULL) {
			d = new map<int, int>();
			v[p - 1] = *d;
		}
		d->insert(mp(y, i));
	}

//	REP(i, N) {
//   	for(auto x : v[i]) {
//    		cout << "P = " << i
//    		    << ", key = " << x.first				// キーを表示
//    			<< ", val = " << x.second << endl;		// 値を表示
//        }
//	}
	
	int no;
	char *numStr;
	REP(i, N) {				// 県の数分、繰り返す
		no = 1;
		d = &v[i];
		if(d != NULL) {
			for(auto j : *d) {
				ans[j.second][0] = i + 1;
				ans[j.second][1] = no;
				no ++;
			}
		}
	}
	REP(i, M) {				// 市の数分、結果を書き出す
		printf("%06d%06d\n", ans[i][0], ans[i][1]);
	}

	return 0;
}


Measured memory_bytes: 11648
#include <stdlib.h>
#include <iostream>
using namespace std;


#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)

int main(){
	int n;
	long x;

	cin >> n >> x;

	long *box = (long *)calloc((n+2), sizeof(long));
	long *sum = (long *)calloc((n+2), sizeof(long));

	FOR(i, 1, n+1){
		cin >> box[i];
		sum[i] = box[i] + box[i-1];
	}

	long result = 0;
	long dif = 0;
	FOR(i, 1, n+1){
		dif = sum[i] - x;
		if(dif > 0){
			if(box[i] < dif){
				dif = box[i];
			}
			sum[i+1] -= dif;
			result += dif;
		}
	}
	cout << result << endl;
	
	return 0;
}



Measured memory_bytes: 1792
#include<stdio.h>
int main()
{

	int a, ei, b,tr;
	scanf("%d", &a);
	scanf("%d", &b);
	ei = a*b;
	tr = a * 2+ b * 2;
	printf("%d", ei);
	printf(" ");
		printf("%d", tr);

	printf("\n");


	return 0;
}

Measured memory_bytes: 600
package main

import "fmt"

func main() {
	var c [3][3]int
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			fmt.Scan(&c[i][j])
		}
	}
	for a1 := 0; a1 <= c[0][0]; a1++ {
		b1 := c[0][0] - a1
		b2 := c[0][1] - a1
		b3 := c[0][2] - a1
		a2 := c[1][0] - b1
		a3 := c[2][0] - b1
		if a2+b2 == c[1][1] && a3+b3 == c[2][2] && a2+b3 == c[1][2] && a3+b2 == c[2][1] {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;


long long L[90];

int main() {
    L[0] = 2;
    L[1] = 1;
    int n;
    cin >> n;
    for(int i = 2; i <= n; ++i) L[i] = L[i - 1] + L[i - 2];
    cout << L[n] << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

ll good_mod(ll n) {
    return (n%2 + 2) % 2;
}

int main() {
    ll H, N;
    cin >> H >> N;
    struct Magic {
        ll damage;
        ll mp;
    };
    vector<Magic> magics(N);
    rep(i,0,N) {
        cin >> magics[i].damage >> magics[i].mp;
    }
    auto dp = make_vec_nd(numeric_limits<ll>::max(), N+1, H+1);
    dp[0][0] = 0;
    rep(n,1,N+1) {
        rep(h,0,H+1) {
//            dp[n][h] =
            dp[n][h] = dp[n-1][h];
            if (h > magics[n-1].damage) {
                dp[n][h] = min(dp[n][h], dp[n][h-magics[n-1].damage] + magics[n-1].mp);
            } else {
                dp[n][h] = min(dp[n][h], magics[n-1].mp);
            }
        }
    }
    cout << dp[N][H] << endl;
}



Measured memory_bytes: 78592
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 1005;

ll power(ll a,ll n=5,ll m=M){
    ll ans=1;
    while(n){
        if(n&1) ans=ans*a;
        a=a*a;
        n=n>>1;
    }
    return ans;
}

void solve(){
    ll x;
    cin>>x;
    rep(i,-N,N) rep(j,-N,N){
        if(power(i)-power(j) == x){
            cout<<i<<" "<<j<<endl;
            return;
        }
    }
    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll no;
    // cin>>no;
    no = 1;
    while(no--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3608
N,A,B = [int(x) for x in input().split()]
S = input()
a=0
b=0
for i in S:
    if(i=='a'):
        if(a+b<A+B):
            a+=1
            print("Yes")
        else:
            print("No")
    if(i=='b'):
        if(a+b<A+B and b<B):
            b+=1
            print("Yes")
        else:
            print("No")
    if(i=='c'):
            print("No")


Measured memory_bytes: 4116
#include <bits/stdc++.h>
#define REP(i, n) for(llong i = 0;i < n;i++)
#define REPR(i, n) for(llong i = n;i >= 1;i--)
#define FOR(i, m, n) for(llong i = m;i < n;i++)
#define FORR(i, m, n) for(llog i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
llong mod = 1000000007;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};


int main(){
  int N;cin >> N;
  int flag =0;
  REP(i,10){
    if(flag == 0)
    REP(j,10){
      if(flag == 0)
      if(i*j == N){
        cout <<"Yes"<< endl;
        flag =1;
      }
    if(i ==9 && j == 9 && flag ==0)cout << "No"<<endl;
    }
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second

typedef long long ll;

using namespace std;

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n;

    cin >> n;

    int arr[n];

    for (int i = 0; i < n; i++) cin >> arr[i];

    sort(arr, arr+n);

    cout << arr[n/2]-arr[n/2-1];

    return 0;
}


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

int a[200], b[200];
int main() {
	int n, m; cin >> n >> m;
	rep(i, 2 * n)a[i] = b[i] = i + 1;
	rep(i, m) {
		int k; cin >> k;
		if (k) {
			for (int j = 0; j < 2 * n - k; j++)a[j] = b[j + k];
			for (int j = 2 * n - k; j < 2 * n; j++)a[j] = b[j - 2 * n + k];
		}
		else {
			rep(i, 2 * n) {
				if (i & 1)a[i] = b[n + i / 2];
				else a[i] = b[i / 2];
			}
		}
		memcpy(b, a, 4 * (2 * n));
	}

	rep(i, 2 * n) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n);
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_A&lang=jp

int main() {
	queue<char> Q;
	int sx,sy,tx,ty;
	SCD2(sx,sy); SCD2(tx,ty);
	
	REP(i,ty-sy){
		Q.push('U');
	}
	
	REP(i,tx-sx){
		Q.push('R');
	}
	
	REP(i,ty-sy){
		Q.push('D');
	}
	
	REP(i,tx-sx){
		Q.push('L');
	}
	
	//
	
	Q.push('L');
	
	REP(i,ty-sy+1){
		Q.push('U');
	}
	
	REP(i,tx-sx+1){
		Q.push('R');
	}
	
	Q.push('D');
	Q.push('R');
	
	REP(i,ty-sy+1){
		Q.push('D');
	}
	
	REP(i,tx-sx+1){
		Q.push('L');
	}
	
	Q.push('U');
		
	while(!Q.empty()){
		char x = Q.front(); Q.pop();
		printf("%c",x);
	}
	
	printf("\n");
}










Measured memory_bytes: 256
P = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0]*(S+1) for i in range(N+1)]
# dp = [[0]*(S+1) for i in range(N)]
# dp[i][j] i番目まで見た時に和がjになる組み合わせの個数
dp[0][0] = 1
for i in range(N):
    num = A[i]
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]*2
        if j-num >= 0:
            dp[i+1][j] += dp[i][j-num]
        dp[i+1][j] %= P
print(dp[N][S])

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N, K;
string S;

signed main() {
    cin >> N >> K >> S;
    S[K - 1] += 'a' - 'A';
    cout << S << endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<utility>//pair
#include<list>
#include<vector>//可変長配列
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<ll,ll>
#define F first
#define S second
int dx[8] = { 1,0,-1,0,1,-1,-1,1 };
int dy[8] = { 0,1,0,-1,1,1,-1,-1 };


int ans[222222];
int n;
ll a[222222];
ll all;

int main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)ans[a[i]]++;

	rep(i, n + 1) {
		if (ans[i] < 2)
			continue;
		ll now = ans[i];
		all += (now * (now - 1LL)) / 2LL;
	}


	rep(i, n) {
		
		ll ret = all;
		if (ans[a[i]] < 2) {
			cout << all << endl;
			continue;
		}
		ll now = ans[a[i]];
		ret-= (now * (now - 1LL)) / 2LL;


			now = ans[a[i]] - 1;
			ret += (now * (now - 1LL)) / 2LL;

		cout << ret<< endl;
	}
	return 0;
}


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

vector<string> read_input() {
    int n;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a.at(i);
    }
    return a;
}

int main() {
    vector<string> a = read_input();
    vector<string> b = read_input();
    int ans = 0;
    for (size_t i = 0; i < a.size(); ++i) {
        int cnt = 0;
        for (size_t j = 0; j < a.size(); ++j) {
            if (a.at(j) == a.at(i)) {
                cnt += 1;
            }
        }
        for (size_t j = 0; j < b.size(); ++j) {
            if (b.at(j) == a.at(i)) {
                cnt -= 1;
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
X,N = LI()
p = set(LI())
ans,distance = 0,float('INF')
for x in range(-202,202)[::-1]:
    if x in p:
        continue
    now_distance = abs(X-x)
    if now_distance<=distance:
        ans = x
        distance = now_distance
print(ans)


Measured memory_bytes: 9192
#include <iostream>
#include <sstream>

class Dice {
public:
    int num[6];
    void move (char cmd) {
        if (cmd == 'N') north();
        if (cmd == 'S') south();
        if (cmd == 'E') east();
        if (cmd == 'W') west();
        if (cmd == 'R') right();
        if (cmd == 'L') left();
    }
    void north () {
        std::swap(num[0], num[1]);
        std::swap(num[1], num[5]);
        std::swap(num[5], num[4]);
    }
    void south () {
        std::swap(num[0], num[4]);
        std::swap(num[4], num[5]);
        std::swap(num[5], num[1]);
    }
    void east () {
        std::swap(num[0], num[3]);
        std::swap(num[3], num[5]);
        std::swap(num[5], num[2]);
    }
    void west () {
        std::swap(num[0], num[2]);
        std::swap(num[2], num[5]);
        std::swap(num[5], num[3]);
    }
    void right () {
        move('W'); move('S'); move('E');
    }
    void left () {
        move('E'); move('S'); move('W');
    }
};

int main() {
    std::stringstream ss;
    Dice dice;
    for (int i=0;i<6;++i)
        std::cin >> dice.num[i];
    int q;
    std::cin >> q;
    for (int i=0;i<q;++i) {
        int top, front;
        std::cin >> top >> front;
        std::string cmd = "NNNEEE";
        for (int i=0;i<(int)cmd.size();++i) {
            if (dice.num[0] == top) break;
            else dice.move(cmd[i]);
        }
        cmd = "RRR";
        for (int i=0;i<(int)cmd.size();++i) {
            if (dice.num[1] == front) break;
            else dice.move(cmd[i]);
        }
        ss << dice.num[2] << std::endl;
    }
    std::cout << ss.str();
    
    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr double eps = 1e-7;
    int n, k;
    std::cin >> n >> k;

    std::vector<std::pair<int, int>> vs;
    std::vector<int> cs;
    for (int i = 0; i < n; i++) {
        int x, y, c;
        std::cin >> x >> y >> c;
        vs.emplace_back(x, y);
        cs.push_back(c);
    }

    if (k == 1) {
        std::cout << 0 << std::endl;
        return 0;
    }

    double l = -eps, r = 200000000.0;
    while (r - l > eps) {
        const double mid = (l + r) / 2;
        std::vector<std::pair<double, double>> cands;
        for (int i = 0; i < n; i++) cands.emplace_back(vs[i].first, vs[i].second);
        for (int i = 1; i < n; i++) for (int j = 0; j < i; j++) {
            double ri = mid / cs[i], rj = mid / cs[j];
            int dx = vs[j].first - vs[i].first, dy = vs[j].second - vs[i].second;
            const double len = std::sqrt(dx * dx + dy * dy);
            if (ri + rj < len + eps || len + ri < rj + eps || len + rj < ri + eps) continue;
            if (ri > len || rj > len) {
                if (ri > rj) {
                    std::swap(ri, rj);
                    dx = -dx;
                    dy = -dy;
                }
                const double x = (rj * rj - ri * ri - len * len) / (2 * len);
                const double h = std::sqrt(ri * ri - x * x);
                const double mx = vs[i].first - x / len * dx, my = vs[i].second - x / len * dy;
                cands.emplace_back(mx - h * dy / len, my + h * dx / len);
                cands.emplace_back(mx + h * dy / len, my - h * dx / len);
            } else {
                const double x = (ri * ri - rj * rj + len * len) / (2 * len);
                const double h = std::sqrt(ri * ri - x * x);
                const double mx = vs[i].first + x / len * dx, my = vs[i].second + x / len * dy;
                cands.emplace_back(mx - h * dy / len, my + h * dx / len);
                cands.emplace_back(mx + h * dy / len, my - h * dx / len);
            }
        }

        const bool ok = std::any_of(cands.begin(), cands.end(), [&](const auto &e) {
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                const double dx = vs[i].first - e.first, dy = vs[i].second - e.second;
                if (cs[i] * std::sqrt(dx * dx + dy * dy) <= mid + eps) cnt++;
            }
            return cnt >= k;
        });

        if (ok) r = mid;
        else l = mid;
    }

    std::cout << std::fixed << std::setprecision(10) << std::max(0., r) << std::endl;

    return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

bool prime(int x) {
	if (x<2) return false;
	for (int i=2 ; i*i<=x ; i++) {
		if (x%i==0) return false;
	}
	return true;
}

int main() {
	int x;
	cin >>x;
	while (!prime(x)) x++;
	cout <<x<<endl;
	return 0;
}

Measured memory_bytes: 256
//Name: Summer of Phyonkichi
//Level: 3
//Category: グラフ,Graph,探索,メモ化,幅優先探索,BFS
//Note: 

/**
 * 時間を1つずつ進めながら、死なないで到達できるようなセルの集合を管理する。
 *
 * オーダーは O(HWN)。
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int DX[12] = {2, 2, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2};
const int DY[12] = {0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2, 1};

bool solve() {
    int X, Y;
    if(!(cin >> X >> Y)) return false;
    if(!X && !Y) return false;
    int N;
    cin >> N;
    vector<pair<int,int>> ss;
    for(int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        ss.emplace_back(x, y);
    }

    vector<pair<int,int>> v[2];
    v[0].emplace_back(X, Y);
    for(int t = 0; t < N; ++t) {
        v[1].clear();
        for (const auto &cur : v[0]) {
            for(int d = 0; d < 12; ++d) {
                const int nx = cur.first + DX[d];
                const int ny = cur.second + DY[d];
                if(nx < 0 || nx >= 10 || ny < 0 || ny >= 10) continue;
                if(max(abs(nx-ss[t].first), abs(ny-ss[t].second)) > 1) continue;
                v[1].emplace_back(nx, ny);
            }
        }
        sort(begin(v[1]), end(v[1]));
        v[1].erase(unique(begin(v[1]), end(v[1])), end(v[1]));
        v[0].swap(v[1]);
    }
    cout << (v[0].size() > 0 ? "OK" : "NA") << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    while(solve()) ;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

const ll mod =1000000007;

#define rep(i,m,n) for(ll i=m;i<n;i++)

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

 ll n,m;
  cin >> n >> m;
  vector<long> x(n),y(m);
  rep(i,0,n) cin >> x[i];
  rep(i,0,m) cin >> y[i];

  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  
  
  ll res=1,sum=0; 
  rep(i,0,n){
   sum+=i*x[i]-(n-1-i)*x[i];
   sum%=mod;
  }
  res*=sum;
  res%=mod;
  sum=0;
  rep(i,0,m){
   sum+=i*y[i]-(m-1-i)*y[i];
   sum%=mod;
  }
  res*=sum;
  res%=mod;
  
  cout << res << endl;
}

Measured memory_bytes: 1792
n,a,b = map(int,input().split())

mod = 10**9 + 7

def comb(n:int,k:int,MOD:int):
    """return nCk (mod MOD)
    """
    nCk = 1
    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD
    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

all = pow(2,n,mod)-1
comb_a = comb(n,a,mod)
comb_b = comb(n,b,mod)
answer = (all -comb_a -comb_b) % mod

print(answer)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#if !defined(M_PI)
#define M_E 2.71828182845904523536
#define M_LOG2E 1.44269504088896340736
#define M_LOG10E 0.434294481903251827651
#define M_LN2 0.693147180559945309417
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.785398163397448309616
#define M_1_PI 0.318309886183790671538
#define M_2_PI 0.636619772367581343076
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.707106781186547524401
#endif

int solve() {
    string s, t;
    cin >> s >> t;

    int ans = s.size();
    for (int i = 0; i < s.size() - t.size() + 1; i++) {
        int miss = 0;
        for (int j = 0; j < t.size(); j++) {
            if (s[i + j] != t[j])
                miss++;
        }
        ans = min(ans, miss);
    }
    return ans;
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int tt = 1;
    // cin >> tt;

    for (int tc = 1; tc <= tt; tc++) {
        cout << solve() << "\n";
    }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<*it.F<<' '<<*it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)

ll power(ll x, unsigned ll y, unsigned ll m=MOD) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2, m) % m; 
	p = (p * p) % m; 

	return (y%2 == 0)? p : (x * p) % m; 
} 


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,x,t,m;
	cin>>n;
	vi c;
	in(c,n);
	sort(all(c));
	ll ans = 0;
	for(int i=1;i<=n;i++){
	    ans = ans + ((((n-i+2)*power(2,2*n-2))%MOD)*c[i-1])%MOD;
	    ans%=MOD;
	}
	cout<<ans;
	

	return 0;
}







Measured memory_bytes: 2420
N, K = map(int, input().split())
h=[]
for _ in range(N):
    h.append(int(input()))
h.sort(reverse=True)
#print(h)
for i in range(N-K+1):
    h[i]-=h[i+K-1]
#print(h)
print(min(h[:N-K+1]))

Measured memory_bytes: 51032
#include<string>
#include<iostream>

using namespace std;

int a,b;

int main()
{
    cin>>a>>b;
    
    for(int i=1;i<=a;i++)
        for(int j=1;j<=b;j++)
        {
            string str;cin>>str;
            if(str=="snuke")
            {
                cout<<char(j+'A'-1)<<i<<endl;
                return 0;
            }
        }
}

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

int main(void){
    int n,m,x,i,sum=0,a=0;
    double d;
    vector<int> v;
    cin>>n>>m;
    for(i=1;i<=n;++i){
        cin>>x;
        v.push_back(x);
        sum+=x;
    }
    d=(double)sum/(4*m);
    for(i=1;i<=n;++i){
        x=v.at(i-1);
        if(x>=d)++a;
    }
    if(a>=m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
n = input()    
m = n.split()
p = [int(i) for i in m]
a = p[2] -p[1]
if a % 2 == 0:
    print(int(a//2))
else:
    A = (a-1)//2 + min(p[1]-1,p[0]-p[2]) + 1
    print(A)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int n;
    cin>>n;
    vector<vector<int>> mat(n, vector<int>(n));
    rep(i, n) {
        int u, k, v;
        cin>>u>>k; u--;
        rep(j, k) {
            cin>>v; v--;
            mat[u][v] = 1;
        }
    }
    rep(i, n) {
        rep(j, n - 1) cout<<mat[i][j]<<" ";
        cout<<mat[i][n - 1]<<endl;
    }
}


Measured memory_bytes: 3140
"use strict"
function Main(input) {
  input = Number(input.trim());

  let flg = false;
  for(let a=0;a<26;++a){
    for(let b=0;b<15; ++b){
      let cnt = 4*a+7*b;
      if(cnt==input) {
        flg=true;
        break;
      }
    }
  }


  console.log(flg?'Yes':'No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7496
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,c,N;cin >> N;
    
    for(int i=int(sqrt(N));i>0;i--){
        if(N%i==0){
            a = i;
            b = N/i;
            break;
        }
    }
    cout << a+b-2 << endl;

}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)
    val S = scanner.nextLine()
    println(S match {
      case "SUN" => 7
      case "MON" => 6
      case "TUE" => 5
      case "WED" => 4
      case "THU" => 3
      case "FRI" => 2
      case "SAT" => 1
    })
  }
}


Measured memory_bytes: 25648
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    XY = [[] for _ in range(n)]

    try:
        it = iter(args[1:])
        a = next(it)
        i = 0
        while a:
            for _ in range(int(a)):
                x, y = map(int, next(it).split())
                XY[i].append((x-1, y == 1))
            a = next(it)
            i += 1
    except StopIteration:
        pass

    ret = 0
    for hypo in range(2**n):
        consistent = True
        truth = [None]*n
        count = 0
        i = 0
        while consistent and i < n:
            if (hypo >> i) & 1:
                count += 1
                for x, y in XY[i]:
                    if truth[x] is None:
                        truth[x] = y
                    elif truth[x] != y:
                        consistent = False

                    consistent &= (hypo >> x) & 1 == y
            i += 1

        if consistent:
            ret = max(ret, count)

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 3064
import sys


def solve(x, n):
    if n == 0:
        return x
    ps = set(map(int, input().split()))
    if x not in ps:
        return x
    # 解の候補
    qs = list(set(range(102)) - ps)
    ans = [1000, 1000]  # [距離,解]
    for q in qs:
        if abs(q - x) < ans[0]:
            ans[0] = abs(q - x)
            ans[1] = q
        elif abs(q - x) == ans[0] and q < ans[1]:
            ans[1] = q
    return ans[1]


def main():
    input = sys.stdin.buffer.readline
    x, n = map(int, input().split())
    print(solve(x, n))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
using ll = int64_t;
using v = vector<int>;

int main() {
  int N, M;
  ll sum = 0;
  cin >> N >> M;
  rep(i,M) {
    int A;
    cin >> A;
    sum += A;
  }
  if (sum>N) cout << -1 << endl;
  else cout << N-sum << endl;


}

Measured memory_bytes: 3636
#include <cstdio>
#include <vector>
#include <deque>
using namespace std;


vector<int> slidemin(int n,int m,vector<int> &A)
{
  deque<int> Q;
  vector<int> B(n,0);
  for(int i=0;i<n;i++){
    while(!Q.empty()&&A[Q.back()]>=A[i]){
      Q.pop_back();
    }
    Q.push_back(i);
    if(i>=m&&Q.front()==i-m){
      Q.pop_front();
    }
    if(i>=m-1){
      B[i]=A[Q.front()];
    }
  }
  return B;
}

int main()
{
  int n,k;
  scanf("%d%d",&n,&k);
  vector<int> a(n),ma(n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    ma[i]=-a[i];
  }
  vector<int> b,mb,L(n);
  b=slidemin(n,k-1,a);
  mb=slidemin(n,k-1,ma);
  L[0]=1;
  for(int i=1;i<n;i++){
    L[i]=(a[i-1]<=a[i]?L[i-1]+1:1);
  }
  int ans=0;
  bool F=false;
  for(int i=k-1;i<n;i++){
    if(L[i]>=k){
      if(!F){
	F=true;
	ans++;
      }
    }
    else if(!(i>=k&&a[i-k]<=b[i-1]&&-mb[i-1]<=a[i])){
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 4336
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n,m,d;
    int ma[90005][2],ans[90005];
    cin >> n >> m >> d;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            int a;
            scanf("%d",&a);
            ma[a][0]=i;
            ma[a][1]=j;
        }
    for(int i=1;i<=n*m;i++)
    {
        if(i<=d) ans[i]=0;
        else
        {
            ans[i]=ans[i-d]+abs(ma[i][0]-ma[i-d][0])+abs(ma[i][1]-ma[i-d][1]);
        }
    }
    int q,l,r;
    cin >> q;
    while(q--)
    {
        scanf("%d %d",&l,&r);
        printf("%d\n",ans[r]-ans[l]);
    }
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int r,g,b;
	scanf("%d %d %d",&r,&g,&b);
	int temp=100*r+10*g+b;
	if(temp%4==0)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

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

namespace ABC102B_cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var result = a.Max() - a.Min();
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13396
MODULO = 10**9+7
n, k = map(int, input().split())


ans = 0
for num_add in range(k, n+2):
	min_res = (0 + num_add-1) * num_add // 2
	max_res = (n-num_add+1 + n) * num_add // 2
	ans += (max_res - min_res + 1) % MODULO
	ans %= MODULO
	# print("ans", ans)

print(ans)


Measured memory_bytes: 63764
S = input()

TARGET = ['A', 'C', 'G', 'T']

length = 0

head = 0

while head < len(S):
    tail = head
    while S[tail] in TARGET:
        tail += 1
        if tail >= len(S):
            break
    length = max(length, tail - head)
    head = tail + 1
print(length)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define ll long long
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  long long n,ans=1;
  map <int ,int>m;
  cin>>n;

  for(int i=2;i<=n;i++){
    int tmp=i;
    int cnt=2;
    //cout<<i<<endl;
    while(tmp>1){
      //cout<<tmp<<endl;
      if(tmp%cnt==0){
	//cout<<cnt<<endl;
	m[cnt]++;
	tmp/=cnt;
      }else{
	cnt++;
      }
    }
  }
  
  for(int i=1;i<=1000;i++){
    //cout<<m[i]<<endl;
    ans=ans*(m[i]+1)%mod;
  }
  
  cout<<ans<<endl;
  
  
}

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

typedef pair<int,int>pii;
#define MOD 1000000007
#define MAXN 100005
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define pb push_back
#define f first
#define s second
#define debug(x) cout << "debug 1: " << x << "\n";
#define debug2(x, y) cout << "debug 2: " << x << " " << y << "\n";
#define debug3(x, y, z) cout << "debug 3: " << x << " " << y << " " << z << "\n";


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char B[1 << 15], *S = B, *T = B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}

char s1[110][110], s2[110][110];
int m;
inline bool diff(int x, int y)
{
	for (int i = 0; i < m; ++i)
		for (int j = 0; j < m; ++j)
			if (s1[x + i][y + j] != s2[i][j])
				return 0;
	return 1;
}
int main()
{
//	setfile();
	int n; scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i)
			scanf("%s", s1[i] + 1);

	for (int i = 0; i < m; ++i)
			scanf("%s", s2[i]);

	for (int i = 1; i + m - 1 <= n; ++i)
		for (int j = 1; j + m - 1 <= n; ++j)
			if (diff(i, j))
			{
				puts("Yes");
				return 0;
			}
	puts("No");
	return 0;
}


Measured memory_bytes: 128
n,k = map(int,input().split())
 
p = list(map(int,input().split()))
 
s = [0]*(n+1)
 
for i in range(n):
    s[i+1] = s[i] + (p[i] + 1)/2
 
res = 0
 
for i in range(n-k+1):
    res = max(res, s[i+k] - s[i])
    
print("{:.10f}".format(res))

Measured memory_bytes: 32040
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> p(n+1);
    rep(i,n) cin >> p[i];
    p[n] = -1;
    ll cnt = 0,stock = 0;
    rep(i,n+1){
        if (p[i] == i+1) stock++;
        else{
            if (stock%2) cnt += stock/2+1;
            else cnt += stock/2;
            stock = 0;
        } 
    }
    PRINT(cnt);
}



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

int n,h,w,a,b;
int brojac;

int main(){
	cin>>n>>h>>w;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		if(a>=h && b>=w)brojac++;		
	}
	
	cout<<brojac;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <limits>
#include <algorithm>
using namespace std;

double minkowski_length(vector<double>& x, vector<double>& y, double p=numeric_limits<double>::infinity()){
	if (p == numeric_limits<double>::infinity()) {
		double D = abs(x[0]-y[0]);
		for (int i = 0; i < x.size(); ++i) {
			D = max(D, abs(x[i] - y[i]));
		}
		return D;
	}
	else {
		double sum = 0;
		for (int i = 0; i < x.size(); ++i) {
			sum += pow(abs(x[i] - y[i]), p);
		}
		return pow(sum, 1.0 / p);
	}
}

int main() {
	cout << fixed << std::setprecision(6);
	int n;
	vector<double>x, y;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		double a;
		cin >> a;
		x.push_back(a);
	}
	for (int i = 0; i < n; ++i) {
		double a;
		cin >> a;
		y.push_back(a);
	}
	double l1 = minkowski_length(x, y, 1);
	double l2 = minkowski_length(x, y, 2);
	double l3 = minkowski_length(x, y, 3);
	double linf = minkowski_length(x, y);
	cout << l1 << endl << l2 << endl << l3 << endl << linf << endl;
	return 0;
}



Measured memory_bytes: 3480
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=1000005,mod=1e9+7;
int a[N],b[N],c[N],d[N];
int add(int x,int y)
{
  x+=y;
  if(x>=mod) x-=mod;
  return x;
}
int mult(int x,int y)
{
  ll tmp=(ll)x*y;
  if(tmp>=mod) tmp%=mod;
  return tmp;
}
int pow1(int x,int y)
{
  int ans=1;
  while(y)
    {
      if(y&1) ans=mult(ans,x);
      x=mult(x,x);
      y>>=1;
    }
  return ans;
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  string s;
  cin>>s;
  int n=sz(s);
  s="#"+s;
  rep(i,1,n+1) a[i]=a[i-1]+(s[i]=='A');
  rep(i,1,n+1) b[i]=b[i-1]+(s[i]=='B');
  rep(i,1,n+1) c[i]=c[i-1]+(s[i]=='C');
  rep(i,1,n+1) d[i]=d[i-1]+(s[i]=='?');
  int ans=0;
  int tot=d[n],val=pow1(3,tot);
  rep(i,1,n+1)
    {
      if(s[i]=='B')
	{
	  ans=add(ans,mult(val,mult(a[i-1],c[n]-c[i])));
	  if(tot>=1)
	    {
	      int tmp=pow1(3,tot-1);
	      ans=add(ans,mult(tmp,mult(d[i-1],c[n]-c[i])));
	      ans=add(ans,mult(tmp,mult(a[i-1],d[n]-d[i])));
	    }
	  if(tot>=2)
	    {
	      int tmp=pow1(3,tot-2);
	      ans=add(ans,mult(tmp,mult(d[i-1],d[n]-d[i])));
	    }
	}
      else if(s[i]=='?')
	{
	  tot--; val=pow1(3,tot);
	  ans=add(ans,mult(val,mult(a[i-1],c[n]-c[i])));
	  if(tot>=1)
	    {
	      int tmp=pow1(3,tot-1);
	      ans=add(ans,mult(tmp,mult(d[i-1],c[n]-c[i])));
	      ans=add(ans,mult(tmp,mult(a[i-1],d[n]-d[i])));
	    }
	  if(tot>=2)
	    {
	      int tmp=pow1(3,tot-2);
	      ans=add(ans,mult(tmp,mult(d[i-1],d[n]-d[i])));
	    }
	  tot++; val=pow1(3,tot);
	}
    }
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 10988
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
 
n = int(input())
 
for _ in range(n):
    (b,f,r,v) = [int(i) for i in input().split()]
    data[b - 1][f - 1][r - 1] += v
 
for b in range(4):
    for f in range(3):
        for r in range(10):
            print('',data[b][f][r], end='')
        print()
    if b < 3:
        print('#' * 20)

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

using namespace std;
int n;
struct activites{
    int a,b,c;
};
int kq;
activites a[100001];
activites d[100001];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].a>>a[i].b>>a[i].c;
    }
    for(int i=1;i<=n;i++)
    {
        d[i].a=max(d[i-1].c,d[i-1].b)+a[i].a;
        d[i].b=max(d[i-1].c,d[i-1].a)+a[i].b;
        d[i].c=max(d[i-1].a,d[i-1].b)+a[i].c;
    }
    cout<<max(d[n].a,max(d[n].b,d[n].c));
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;


int main()
{
int n,ac;
bool ans;
ans=true;
ac=0;
cin>>n;
vector<pair<int, int>> ab(n);
for(int i=0;i<n;i++){
  int a, b;
  cin >> a >> b;
  ab[i] = make_pair(b, a);
}
sort(ab.begin(), ab.end());
for(int i=0;i<n;i++){
  if(ac+ab[i].second>ab[i].first)  ans=false;
  ac+=ab[i].second;
}
if(ans==true)	cout << "Yes";
else	cout << "No";
  return 0;
}

Measured memory_bytes: 1792