akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

long long dp[4009][4009], L[4009], R[4009], mod = 998244353; string S;

int main() {
	cin >> S; int a = 0, b = 0;
	for (int i = 1; i <= S.size() * 2; i++) {
		if (i <= S.size()) {
			if (S[i - 1] == '0') { a += 2; b += 0; }
			if (S[i - 1] == '1') { a += 1; b += 1; }
			if (S[i - 1] == '2') { a += 0; b += 2; }
		}
		L[i] = max(0, i - b);
		R[i] = min(i, a);
	}
	dp[0][0] = 1;
	for (int i = 1; i <= 2 * S.size(); i++) {
		for (int j = L[i]; j <= R[i]; j++) {
			dp[i][j] += dp[i - 1][j];
			if (j >= 1) dp[i][j] += dp[i - 1][j - 1];
			dp[i][j] %= mod;
		}
	}
	cout << dp[2 * S.size()][a] << endl;
	return 0;
}

Measured memory_bytes: 123520
#include<stdio.h>

int main(void)
{
  char s[200001],t[200001];
  int i,sum=0;
  
  scanf("%s%s",s,t);
  
  for(i=0;i<200000;i++){
    if(s[i]!=t[i])
      sum++;
    if(s[i]==0)
      break;
  }
  
  printf("%d", sum);
  
  return 0;

}

Measured memory_bytes: 2072
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    vector<ll> indices(N+1);
    for (int i = 0; i < N; i++) {
        ll ai;
        cin >> ai;
        indices[ai] = i;
    }

    set<ll> used{ -1, N };

    ll ans = 0;
    for (ll val = 1; val <= N; val++) {
        ll index = indices[val];

        auto p = used.emplace(index);
        auto it = p.first;

        --it;
        ll left = *it;
        ++it;
        ++it;
        ll right = *it;

        ans += val * (index - left) * (right - index);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
ll INF = 1000000;
int main(){
    ll h, w, ans=0,tmp,start,goal;
    cin >> h >> w;
    vector<vector<char> > vec(h+2, vector<char>(w+2,'#'));
    ll dp[h+2][w+2][h+2][w+2];
    rep(i,h+2)rep(j,w+2)rep(k,h+2)rep(l,w+2)dp[i][j][k][l]=INF;
    rep(i,h)rep(j,w)dp[i+1][j+1][i+1][j+1]=0;
    rep(i,h)rep(j,w){
        cin >> vec.at(i+1).at(j+1);
    }
    int mvx[4]={0,-1,0,1},mvy[4]={-1,0,1,0};
    rep(i,h)rep(j,w){
        if(vec.at(i+1).at(j+1)=='.'){
            rep(k,4){
                if(vec.at(i+1+mvx[k]).at(j+1+mvy[k])=='.'){
                    dp[i+1][j+1][i+1+mvx[k]][j+1+mvy[k]]=1;
                }
            }
        }
    }
    rep(m,h){
        rep(n,w){
            rep(i,h){
                rep(j,w){
                    rep(k,h){
                        rep(l,w){
                            dp[i+1][j+1][k+1][l+1]=min(dp[i+1][j+1][k+1][l+1],dp[i+1][j+1][m+1][n+1]+dp[m+1][n+1][k+1][l+1]);
                        }
                    }
                }
            }
        }
    }
    ll mx=0LL;
    rep(i,h)rep(j,w)rep(k,h)rep(l,w){
        mx=max(mx,(dp[i+1][j+1][k+1][l+1]<INF)?dp[i+1][j+1][k+1][l+1]:0);
    }
    cout << mx << endl;
}


Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main()
{
    int n;cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int dp[n+1];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 4356
import sys
input = sys.stdin.buffer.readline

def main():
    n, m, k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    asum = [0]*(n+1)
    bsum = [0]*(m+1)

    for i in range(n):
        asum[i+1] = asum[i] + a[i]

    for i in range(m):
        bsum[i+1] = bsum[i] + b[i]

    # jを小さくしていく発想がなかった
    j = m
    res = 0
    for i in range(n+1):
        # asumの分岐をさせてからbsumとの和を考えていく
        if asum[i] > k:
            break
        while asum[i] + bsum[j] > k:
            j -= 1
        
        res = max(res, j+i)
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 48232
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

#define PI 3.14159265359


int main() {

    int a, b, h, m;

    cin >> a >> b >> h >> m;

    double theta = abs(h * (2 * PI / 12.0) + m * (2 * PI / 60.0) / 12.0 - 2 * PI * m / 60.0);
    // theta = min(theta, abs(2 * PI - theta));

    // cout << theta << "<- theta \n";

    double c = sqrt(a * a + b * b - 2 * a * b * cos(theta));

    cout << fixed << setprecision(20) << c << endl;

    return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a>b){
    swap(a,b);  
  }
  if(a>c){
    swap(a,c);
  }
  if(b>c){
    swap(b,c);
  }
  cout << a << ' ' << b << ' ' << c << endl;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long N;cin>>N;
    long long ans=1;
    for(long long i=1;i<=N;i++){
        ans*=i;
        ans%=1000000007;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <string>
#include <map>
using namespace std;


const int MAX_N = 6001;
const int MAX_CAP = 2002;

struct Edge {
  int to, cost;
  Edge() {}
  Edge(int to, int cost) : to(to), cost(cost) {}
};

struct State {
  int p, cost, oil;
  State() {}
  State(int p, int cost, int oil) : p(p), cost(cost), oil(oil) {}
  bool operator < (const State &s) const {
    if(cost != s.cost) return cost > s.cost;
    if(oil != s.oil) return oil < s.oil;
    return p < s.p;
  }
};

int Cap, num, Src, Dist;

map<string, int> id;
vector<Edge> E[MAX_N];

bool existS[MAX_N];
bool cost[MAX_N][MAX_CAP];

int getId(string s) {
  if(id.find(s) == id.end()) {
    id[s] = num++;
  }
  return id[s];
}


int solve() {
  priority_queue<State> que;
  State s(Src, 0, Cap);
  que.push(s);
  fill(cost[0], cost[num], 0);
  while(!que.empty()) {

    s = que.top(); que.pop();
    //    cout << s.p << ", " << s.cost << ", " << s.oil << endl;
    if(cost[s.p][s.oil]) continue;
    cost[s.p][s.oil] = true;

    if(s.p == Dist) return s.cost;

    for(int i = 0; i < E[s.p].size(); ++i) {
      int nextOil = s.oil - E[s.p][i].cost;
      if(nextOil < 0) continue;
      if(existS[E[s.p][i].to]) nextOil = Cap;
      if(cost[E[s.p][i].to][nextOil]) continue;

      que.push(State(E[s.p][i].to, s.cost + E[s.p][i].cost, nextOil));
    }
  }
  return -1;
}

int main() {
  int N, M;
  while(cin >> N >> M >> Cap && (N | M | Cap)) {
    num = 0;
    Cap *= 10;
    id.clear();
    for(int i = 0; i < MAX_N; ++i) E[i].clear();

    string src, dist;
    cin >> src >> dist;
    Src = getId(src);
    Dist = getId(dist);
    for(int i = 0; i < N; ++i) {
      string from, to;
      int d;
      cin >> from >> to >> d;
      E[getId(from)].push_back(Edge(getId(to), d));
      E[getId(to)].push_back(Edge(getId(from), d));
    }

    fill(existS, existS+MAX_N, false);
    for(int i = 0; i < M; ++i) {
      string name;
      cin >> name;
      existS[getId(name)] = true;
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 36000
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
#define ALL(V) V.begin(), V.end()
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}


string Main(int A, int B)
{
    ll sum = (ll)A + (ll)B;
    return (sum%2) ? "IMPOSSIBLE" : to_string(sum/2);
}

int main(void){
    int A, B;
    cin >> A >> B;
    cout << Main(A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
def resolve():
    n, k, q = map(int, input().split())
    score = [0] * n
    for _ in range(q):
        a = int(input())
        score[a-1] += 1
    for i in range(n):
        s = k + score[i] - q
        if s > 0:
            print("Yes")
        else:
            print("No")
resolve()

Measured memory_bytes: 9844
#include <stdio.h>
#include <math.h>

int main(void){
    double x1,x2,y1,y2;
    double tate,yoko,z; 

    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);

    tate=x2*1.0-x1;
    yoko=y2*1.0-y1;
    z=pow(tate,2)+pow(yoko,2);
    printf("%lf\n",pow(z,0.5));
    return 0;
}


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

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  
  vector<vector<char>> C(H, vector<char>(W));
 
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> C.at(i).at(j);
    }
  }
  
  int answer = 0;
  for (int mR = 0; mR < pow(2, H) - 1; mR++) {
    for(int mC = 0; mC < pow(2, W) - 1; mC++) {
      int black = 0;
      
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if(
            ((mR >> i) & 1) == 0 &&
            ((mC >> j) & 1) == 0 &&
            (C.at(i).at(j) == '#')
          ) {
            black++;  
          }
        }
      }
      if (black == K) answer++;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 4004
#include"bits/stdc++.h"
using namespace std;
#define rep(i, N) for(int i=0; i<N; ++i)
using ul = unsigned long;
using ll = long long;
#define MAX 1000000

set<int> memo3digits;
set<int> memo2digits;
set<int> memo1digits;

int main() {
    int N;
    string S;
    cin >> N >> S;
    set<int> s;
    for (int i=0; i<N-2; ++i) {
        if (memo3digits.find(S[i] - '0') != memo3digits.end()) continue;
        memo3digits.insert(S[i] - '0');
        for (int j=i+1; j<N-1; ++j) {
            if (memo2digits.find(S[j] - '0') != memo2digits.end()) continue;
            memo2digits.insert(S[j] - '0');
            for (int k=j+1; k<N; ++k) {
                if (memo1digits.find(S[k] - '0') != memo1digits.end()) continue;
                memo1digits.insert(S[k] - '0');
                string x;
                x += S[i];
                x += S[j];
                x += S[k];
                s.insert(atoi(x.c_str()));
            }
            memo1digits.erase(memo1digits.begin(), memo1digits.end());
        }
        memo2digits.erase(memo2digits.begin(), memo2digits.end());
    }
    cout << s.size() << endl;
}


Measured memory_bytes: 384
# 白だけ動いて(0,0)から(H-1, W-1)に行く
# その際にできるだけ黒を増やす
# 全体の白から最短距離を除いたものが答え

from collections import deque


H, W = map(int, input().split())
grid = [list(input()) for _ in range(H)] # .は白、#は黒
visited = [[-1] * W for _ in range(H)]
moves = [(1, 0), (0, 1), (-1, 0), (0, -1)]

q = deque()
q.append((0, 0))
visited[0][0] = 0

while q:
    y, x = q.popleft()

    for dy, dx in moves:
        moved_y = y + dy
        moved_x = x + dx

        if moved_y < 0 or H-1 < moved_y or moved_x < 0 or W-1 < moved_x:
            continue
        if grid[moved_y][moved_x] == '#':
            continue
        if visited[moved_y][moved_x] != -1:
            continue

        visited[moved_y][moved_x] = visited[y][x] + 1
        q.append((moved_y, moved_x))

min_route = visited[H-1][W-1]

if min_route == -1:
    answer = -1
else:
    total_white = 0
    for row in grid:
        total_white += row.count('.')

    answer = total_white - min_route - 1

print(answer)




Measured memory_bytes: 9456
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

#define rep(i,n) for(int (i)=0;(i)<(n); ++(i))
using namespace std;

int main() {
    int d, t, s;
    cin >> d >> t >> s;

    if(d <= t*s)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3132
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e9+7;
const int inf=1e9+7;
const double eps=1e-6;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
const double pi=acos(-1);


ll a[100];
ll v[100];

int main()
{
    TB
    int n;
    cin>>n;
    ll qian=1000,gu=0;
    fd(n) cin>>a[i];
    int i=0,flag=0;
    while(i<n){
        int j=i;
        while(j+1<n&&a[j]>=a[j+1]) j++;
        v[j]=2;
        i=j;j=i;
        if(j==n-1) break;
        while(j+1<n&&a[j]<=a[j+1]) j++;
        v[j]=1;
        flag++;
        i=j;i++;
    }
    //fd(n) deg(v[i])
    for(int i=0;i<n;i++){
        if(v[i]==2&&flag){
            flag--;
            gu+=qian/a[i];
            qian%=a[i];
        }else if(v[i]==1){
            qian+=gu*a[i];
            gu=0;
        }
    }
    cout<<qian<<'\n';
    return 0;
}


Measured memory_bytes: 3668
#include <string.h>
#include <math.h>
#include <iostream>
//#include <bits/stdc++.h>
 
using namespace std;

int main()
{
  long long int i,j,k,l=0;
  long long int space;
  long long int N,M,X;
  char S[256];
  char c = ' ';
  scanf("%s",S);
   if( strlen(S)==3 ){
     c = S[2];
   }
   if( strlen(S)==2 ){
     c = S[1];
   }
   if( strlen(S)==1 ){
     c = S[0];
   }
  
  if(c=='2'||c=='4'||c=='5'||c=='7'||c=='9'){
    printf("hon\n");
  }
  else if(c=='0'||c=='1'||c=='6'||c=='8'){
    printf("pon\n");
  }
  else{
    printf("bon\n");
  }
  
  return 0; 
  
}

Measured memory_bytes: 3760
#include<iostream>
#include<cmath>
#define LEN 6378.1
#define PI 3.141592653589793238
using namespace std;
double a, b, c, d, BC, CA, C;
int main() {
	while (true) {
		cin >> a >> b >> c >> d;
		if (a == -1) { break; }
		BC = PI / 180 * (90.0 - a);
		CA = PI / 180 * (90.0 - c);
		C = PI*(d - b) / 180;
		cout << (int)(0.5 + LEN*acos(cos(BC)*cos(CA) + sin(BC)*sin(CA)*cos(C)))<< endl;
	}
}

Measured memory_bytes: 1288
#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
const long long MAXN=100005,INF=4611686018427387903ll;
long long n,m,s,t,ecnt=0;
long long w[MAXN][2],d[MAXN][2];
long long st[MAXN][2],scnt=0;
struct edge
{
	long long v,c,nxt;
	edge(){}
	edge(long long vv,long long cc,long long nn)
	{
		v=vv,c=cc,nxt=nn;
	}
}ed[MAXN*4];
struct node
{
	long long u,d;
	node(){}
	node(long long uu,long long dd)
	{
		u=uu,d=dd;
	}
	bool operator < (const node& a) const
	{
		return a.d<d;
	}
};
priority_queue<node>q;
void addedge(long long u,long long v,long long a,long long o)
{
	ecnt++;
	ed[ecnt]=edge(v,a,w[u][o]);
	w[u][o]=ecnt;
	
	ecnt++;
	ed[ecnt]=edge(u,a,w[v][o]);
	w[v][o]=ecnt;
}
void dj(long long s,long long o)
{
	while(!q.empty())
		q.pop();
	d[s][o]=0;
	q.push(node(s,d[s][o]));
	while(!q.empty())
	{
		node k=q.top();
		q.pop();
		long long u=k.u;
		if(k.d!=d[u][o])
			continue;
		for(long long i=w[u][o];i;i=ed[i].nxt)
		{
			long long v=ed[i].v;
			long long c=ed[i].c;
			if(d[u][o]+c<d[v][o])
			{
				d[v][o]=d[u][o]+c;
				q.push(node(v,d[v][o]));
			}
		}
	}
}
int main()
{
	scanf("%lld %lld %lld %lld",&n,&m,&s,&t);
	memset(d,0x3f,sizeof(d));
	memset(w,0,sizeof(w));
	for(long long i=1;i<=m;i++)
	{
		long long u,v,a,b;
		scanf("%lld %lld %lld %lld",&u,&v,&a,&b);
		addedge(u,v,a,0);
		addedge(u,v,b,1);
	}
	dj(s,0);
	dj(t,1);
	scnt=0;
	for(long long i=1;i<=n;i++)
	{
		long long jans=d[i][0]+d[i][1];
		while(scnt>0&&jans<st[scnt][0])
			scnt--;
		scnt++;
		st[scnt][0]=jans;
		st[scnt][1]=i;
	}
	long long e=1;
	for(long long i=1;i<=n;i++)
	{
		while(st[e][1]<i)
			e++;
		printf("%lld\n",1000000000000000ll-st[e][0]);
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<long> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  
  vector<pair<long,int>> AC(N);
  AC.at(0)=make_pair(A.at(0),1);
  for(int i=1; i<N; i++){
    if(A.at(i)!=AC.at(i-1).first){
      AC.at(i)=make_pair(A.at(i),1);
    }
    else{
      AC.at(i)=make_pair(A.at(i),AC.at(i-1).second+1);
    }
  }
  
  int ans=0;
  for(int i=0; i<N; i++){
    if(AC.at(i).second%2){
      ans++;
    }
    else{
      ans--;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{
    int n,a,b,c;
    cin >> n;

	if(n/100==1)
        a=9;
    else
        a=1;
    if(n/10%10==1)
        b=9;
    else
        b=1;
    if(n%10==1)
        c=9;
    else
        c=1;
    n=a*100+b*10+c;
    cout << n << endl;
	return 0;
}


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

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T>
using MaxHeap = priority_queue<T, vector<T>, less<T>>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline void input(vector<T> &vec) {
    for (auto &e: vec) {
        cin >> e;
    }
}

template <class T>
inline void input(vector<vector<T>> &mat) {
    for (auto &vec: mat) {
        input(vec);
    }
}

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

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

    set<size_t> S;
    rep(i, 3) {
        var(size_t, x);
        S.insert(x);
    }

    cout << ((S.size() == 2) ? "Yes" : "No") << "\n";

    return 0;
}


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

int main() {
  set<int> SE;
  int A, B, K;
  cin >> A >> B >> K;
  int a = A, b = B;
  for (int i = 0; i < K; i++) SE.insert(a++), SE.insert(b--);
  for (auto se : SE) if (se >= A && se <= B) cout << se << "\n";
}

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

#define ff first
#define ss second
#define pb push_back

const long long MAXN = 1e5 + 21, inf = 1e18 + 21;

int n;
long long fac[10] = {1, 1};
long double x[MAXN], y[MAXN];
long double ans;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    for (int i = 2; i < 9; i++)
	fac[i] = fac[i - 1] * i;

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

    for (int i = 0; i < n; i++) 
	for (int j = i + 1; j < n; j++) {
	    long double d = sqrt(((x[i] - x[j]) * (x[i] - x[j])) + ((y[i] - y[j]) * (y[i] - y[j])));
	    ans += (d * 2 * fac[n - 2] * (n - 1));   
	}
    
    cout << fixed << setprecision(10) << ans / fac[n] << '\n';
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 1000000
int prime[MAX];
bool is_prime[MAX+1];

int solve(int n){
  int p = 0; 
  //fill(prime,prime+MAX,true);
  for(int i = 0 ; i <= n ; i ++)is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for(int i = 2 ; i <= n ; i ++){
    if(is_prime[i]){
      prime[p++] = i;
      for(int j = i + i ; j <= n ; j += i){
	is_prime[j] = false;
      }
    }
  }
  return p;
}
int main(void){ 
  
  long long int n;
  while(cin>>n){
    cout<<solve(n)<<endl;
  }
  
}

Measured memory_bytes: 2444
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    cout << (n + 1) / 2;
    return 0;
}

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

using namespace std;

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    long divd = 1000000007;
    int d[2*N];
    d[0]=1;
    int ln = 1;
    for(int i =1 ; i < 2*N; i++){ 
        if(S[i]!=S[i-1]){
            if(d[i-1] > 0){
                ln++;
                d[i] =ln;
            }
            else{
                d[i] = -1;
            }
        }
        else{
            if(d[i-1] > 0){
                d[i] = -1;
            }
            else{
                ln++;
                d[i] = ln;
            }
        }
    }

    long ans=1;
    if(S[0] == 'W' || S[2*N-1] == 'W' || ln != N) cout << 0 << endl;
    else{
        for(int i = 0; i<2*N; i++){
            if(d[i] > 0){
                ans *= (2*N-1) - i - 2*(ln - d[i]);
                ans %=divd;
            }
        }
        for(int i=1;i<=N;i++){
        ans *=i;
        ans %=divd;

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

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,v,j;
  cin >>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  for(int i=0;i<n;i++){
    v=a.at(i);
    j=i-1;
    while(j>=0&&a.at(j)>v){
      a.at(j+1)=a.at(j);
      j--;
      a.at(j+1)=v;
    }
    for(int k=0;k<n;k++){
      if(k==n-1)cout<<a.at(k)<<endl;
      else cout<<a.at(k)<<" ";
    }
  }
  return 0;
}


Measured memory_bytes: 3108
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAX_S = 2010;
ll dp[MAX_S][MAX_S];

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

  if (S < 3) {
    cout << 0 << endl;
    return 0;
  }

  memset(dp, 0, sizeof(dp));
  dp[0][S] = 1;
  ll ans = 1;
  int idx = 0;

  for (ll s = S; s >= 3; s -= 3) {
    ll cnt = dp[idx][s];

    for (ll i = s - 3; i >= 3; --i) {
      dp[idx + 1][i] += cnt;
      dp[idx + 1][i] %= MOD;
      ans += dp[idx + 1][i];
      ans %= MOD;
      cnt += dp[idx][i + 2];
      cnt %= MOD;
    }

    ++idx;
  }

  cout << ans % MOD << endl;

  return 0;
}


Measured memory_bytes: 35192
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=2e5+4;

int main()
{
	string s;

	cin>>s;

	if(s=="ABC")
	cout<<"ARC";
	else
	cout<<"ABC";

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> v;
    for (int i=1; i<=9; i++)
        for (int j=1; j<=9; j++)
            v.push_back(i*j);
    vector<int>::iterator it = find(v.begin(), v.end(), n);
    if (it != v.end())
	    cout << "Yes";
    else
	    cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
int H,N,i,sum=0;
cin>>H>>N;
while(N>0){
	cin>>i;
	sum+=i;
	N-=1;
}
if (sum>=H){
	cout<<"Yes";
}
else{
	cout<<"No";
}
	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long
#define all(x) begin(x), end(x)
#define range(x) begin(x), begin(x)
#define what(x) cout << #x << ": " << x << '\n'
#define print(x) for (auto &el: x) cout << el << ' '; cout << '\n'
using namespace std;

std::ostream& operator<<(std::ostream& dest, __int128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[ 128 ];
        char* d = std::end( buffer );
        do {
            -- d;
            *d = "0123456789"[ tmp % 10 ];
            tmp /= 10;
        } while ( tmp != 0 );
        if ( value < 0 ) -- d, *d = '-';
        int len = std::end( buffer ) - d;
        if ( dest.rdbuf()->sputn( d, len ) != len ) dest.setstate( std::ios_base::badbit );
    }
    return dest;
}

template<typename S, typename T>
ostream& operator <<(ostream &os, pair<S, T> &m) { 
    os << '[' << m.first << " " << m.second << ']';
    return os;
}

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

    ll a;
    int main, frac;
    cin >> a >> main;

    cin.ignore();
    cin >> frac;
    ll b = main * 100 + frac;

    cout << (a * b) / 100 << endl;

    return 0;
}


Measured memory_bytes: 3636
s = input()
q = int(input())
a, b = "", ""
rev = False
for _ in range(q):
    qr = list(map(str, input().split()))
    if qr[0] == '1':
        rev = 1 - rev
    else:
        if qr[1] == '1':
            if rev: b += qr[2]
            else  : a += qr[2]
        else:
            if rev: a += qr[2]
            else  : b += qr[2]
if rev:
    print(b[::-1] + s[::-1] + a)
else:
    print(a[::-1] + s + b)

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

using namespace std;

int main(void)
{
	string str;
	getline(cin, str);

	for(char& c : str){
		if(c >= 'a' && c <= 'z'){
			c += 'A' - 'a';
		}
	}


	cout << str << endl;


	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

#define MOD 1000000007 

int main()
{
  int n;
  string s1, s2;

  cin >> n >> s1 >> s2;
  
  int f = 0, i = 1;
  ll ans = 3;
  if(s1[0] == s1[1]){
    ans *= 2;
    f = 1;
    i++;
  }
  for(; i < n; i++){
    if(s1[i] == s1[i+1]){
      if(f) ans = (ans * 3) % MOD;
      else ans = (ans * 2) % MOD;
      f = 1;
      i++;
    }else{
      if(f) ans = (ans * 1) % MOD;
      else ans = (ans * 2) % MOD;
      f = 0;
    }
  }

  cout << ans << endl;

  return 0;
}


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

void print(char *str, const int a, const int b)
{
    int i;

    for( i = a; i < b+1; ++i )
        printf("%c", str[i]);
    printf("\n");
}

void reverse(char *dst, const int a, const int b)
{
    int i, j;
    char src[1001];

    strcpy(src, dst);

    for( i = a, j = b; i < b+1; ++i, --j )
        dst[i] = src[j];
}

void replace(char *dst, const int a, const int b)
{
    int i, j;

    char p[1001];
    scanf("%s", p);

    for( i = a, j = 0; i < b+1; ++i, ++j )
        dst[i] = p[j];
}

int main()
{
    int i;

    char str[1001], op[256];
    int q, a, b;
    scanf("%s%d", str, &q);
    for( i = 0; i < q; ++i ){
        scanf("%s%d%d", op, &a, &b);
        if( strcmp("print", op) == 0 ) print(str, a, b);
        else if( strcmp("reverse", op) == 0 ) reverse(str, a, b);
        else if( strcmp("replace", op) == 0 ) replace(str, a, b);
    }

    return 0;
}

Measured memory_bytes: 588
import java.util.Scanner;

public class Main {

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

		if(str.charAt(0) == str.charAt(1) && str.charAt(1) == str.charAt(2)) {
			System.out.println("Yes");
		}else if(str.charAt(1) == str.charAt(2) && str.charAt(2) == str.charAt(3)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 21716
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace competitive_programming
{
    class Program
    {
        static void Main(string[] args)
        {
            var main = new Program();
            main.solve();
        }

        void solve()
        {
            int[] abc = Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray();
            int a = abc[0];
            int b = abc[1];
            int c = abc[2];

            int count = 0;

            while (true)
            {
                if (a == b && b == c)
                {
                    Console.WriteLine(count);
                    return;
                }
                else if (a == b)
                {
                    if (a < c)
                    {
                        a++;
                        b++;
                        count++;
                    }
                    else
                    {
                        c += 2;
                        count++;
                    }
                }
                else if (b == c)
                {
                    if (a < b)
                    {
                        a += 2;
                        count++;
                    }
                    else
                    {
                        b++;
                        c++;
                        count++;
                    }
                }
                else if (a == c)
                {
                    if (a > b)
                    {
                        b += 2;
                        count++;
                    }
                    else
                    {
                        a++;
                        c++;
                        count++;
                    }
                }
                else
                {
                    if (a < b && b < c)
                    {
                        a += 2;
                        count++;
                    }
                    else if (a < c && c < b)
                    {
                        a += 2;
                        count++;
                    }
                    else if (b < a && a < c)
                    {
                        b += 2;
                        count++;
                    }
                    else if (b < c && c < a)
                    {
                        b += 2;
                        count++;
                    }
                    else if (c < a && a < b)
                    {
                        c += 2;
                        count++;
                    }
                    else
                    {
                        c += 2;
                        count++;
                    }
                }
            }
        }
    }
    struct Vector2
    {
        public Vector2(long x, long y)
        {
            this.x = x;
            this.y = y;
        }
        public long x;
        public long y;
    }

    struct Vector3
    {
        public int x;
        public int y;
        public int z;
    }
}


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

int main() {
  string s;
  cin >> s;
  int Ap,Tp,length;
  length = s.size();
  for(int i=0;i<length;i++) {
    if(s.at(i) == 'p') {
      Tp++;
    }
  }
  Ap = length / 2;
  cout << Ap - Tp << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

class A {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int[] a = new int[N];
        for (int i = 0; i < N; i++)
            a[i] = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < N; ) {
            int j = 1;
            while (i + j < N && a[i] == a[i + j])
                j++;
            ans += j / 2;
            i += j;
        }
        System.out.println(ans);
    }
}
public class Main {
    public static void main(String...args) {
        A.main();
    }
}


Measured memory_bytes: 20948
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		
		if(a>0 && b>0){
			System.out.println("Positive");
		}else if(a<0 && b>0){
			System.out.println("Zero");
		}else if(a<0 && b<0){
			if((b-a)%2==0){
				System.out.println("Negative");
			}else{
				System.out.println("Positive");
			}
		}
}
}

Measured memory_bytes: 9936
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

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

int LIS(const vector<int> &v){
    vector<int> u(v.size(), INF<int>);
    for (int i : v) {
        *lower_bound(u.begin(), u.end(), i) = i;
    }
    return static_cast<int>(distance(u.begin(), lower_bound(u.begin(), u.end(), INF<int>)));
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if(a+b-1 > n || a*b < n){
        puts("-1");
        return 0;
    }
    vector<ll> v(b,1);
    vector<vector<int>> ans(b);
    v[b-1] = a;
    ll k = n-a-b+1;
    ll cur = b-2;
    for (int i = 0; i < k; ++i) {
        if(v[cur] >= a) cur--;
        v[cur]++;
    }
    cur = 1;
    for (ll i = b - 1; i >= 0; --i) {
        for (int j = 0; j < v[i]; ++j) {
            ans[i].emplace_back(cur++);
        }
    }
    for (int i = 0; i < b; ++i) {
        for (int j = 0; j < ans[i].size(); ++j) {
            if(i | j) printf(" ");
            printf("%d", ans[i][j]);
        }
    }
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;

int main() {
    cin >> n;
    if (n < 1200)
        cout << "ABC" << endl;
    else if (n < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
    return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;

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

    int a, b; cin >> a >> b;
    cout << (((a * b) % 2) ? "Odd" : "Even") << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        int[] ab = Array.ConvertAll(ReadLine().Split(), int.Parse);
        int res = 0;
        res = ab[0] * ab[1];
        res -= ab[0] + ab[1] - 1;
        WriteLine(res);
    }
    public static partial class MyEnumerable
    {
        public static IEnumerable<int> Range(int count)
        {
            return Enumerable.Range(0, count);
        }
    }
}

Measured memory_bytes: 11092
N = int(input())

xs, ys, hs = [], [], []
for _ in range(N):
    x, y, h = map(int, input().split())
    xs.append(x)
    ys.append(y)
    hs.append(h)

ok = False
for x in range(101):
    for y in range(101):
        if ok:
            break
        cand = []
        for i in range(N):
            h = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
            if hs[i] == 0:
                cand.append((h, False))
            else:
                cand.append((h, True))

    
        cand2 = set([c[0] for c in cand if c[1]])
        if len(cand2) != 1:
            continue

        assert len(cand2) == 1
        ans = cand2.pop()

        if all([c[0] >= ans for c in cand if not c[1]]):
            print(x, y, ans)
            ok = True





assert ok


Measured memory_bytes: 3064
from itertools import chain, repeat

def solve(a, x, y):
    a[y][x] = 0
    for dx, dy in chain(zip(range(-3, 4), repeat(0)), zip(repeat(0), range(-3, 4))):
        if a[y+dy][x+dx]:
            solve(a, x+dx, y+dy)

for i in range(1, int(input())+1):
    input()
    empty = [[0]*14]*3
    a = empty + [[0,0,0]+list(map(int, input()))+[0,0,0] for _ in [0]*8] + empty
    x, y = int(input()), int(input())
    solve(a, x+2, y+2)

    print("Data {}:".format(i))
    for l in a[3:-3]:
        print("".join(map(str, l[3:-3])))



Measured memory_bytes: 5756
using System;
using System.Collections.Generic;
using System.Linq;

namespace id_0501cs
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }
                var convertUnits = new Dictionary<char, char>();
                foreach(var i in Enumerable.Range(0, n))
                {
                    var tmp = Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
                    convertUnits.Add(tmp[0], tmp[1]);
                }
                var m = int.Parse(Console.ReadLine());
                foreach(var i in Enumerable.Range(0, m))
                {
                    var x = char.Parse(Console.ReadLine().Trim());
                    if (convertUnits.ContainsKey(x))
                    {
                        Console.Write(convertUnits[x]);
                    }
                    else
                    {
                        Console.Write(x);
                    }
                }
                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 10072
# ABC096D
from itertools import combinations
def hurui(n):
    """n以下の素数のリストを返す
    """
    l = list(range(2,n))
    p = 2
    i = 0
    while True:
        l = [item for item in l if item==p or item%p!=0]
        i += 1
        p = l[i]
#         print(p)
        if p*p>n:
            break
    return l

n = int(input())
ps = hurui(55555*5)
is_prime = [False] * 55555*5
for item in ps:
    is_prime[item] = True
l = []
for p in ps:
    if p%5==2:
        l.append(p)
    if len(l)==n:
        break
print(*l)

Measured memory_bytes: 73200
n,m,c = map(int,input().split())
a = []
b = list(map(int,input().split()))

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

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

print(count)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	char str[10001];
	int i;
	int countj, counti;
	
	
	while (scanf("%s", str) != EOF){
		counti = countj = 0;
		i = 0;
		while (str[i + 2] != '\0'){
			if (str[i + 1] == 'O' && str[i + 2] == 'I'){
				if (str[i] == 'J'){
					countj++;
				}
				else if (str[i] == 'I'){
					counti++;
				}
			}
			
			i++;
		}
		
		printf("%d\n%d\n", countj, counti);
	}
	return (0);
}

Measured memory_bytes: 556
// finish date: 2018/03/16

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N, K;
    cin >> N >> K;
    vi a(N);
    vl sum(N);
    vl positive_sum(N);
    rep(i, N) {
        cin >> a[i];
        sum[i] = a[i];
        positive_sum[i] = max(0, a[i]);
        if (i != 0) {
            sum[i] += sum[i - 1];
            positive_sum[i] += positive_sum[i - 1];
        }
    }

    ll ans = LONG_LONG_MIN;
    rep(i, N - K + 1) {
        ll sum1 = (i > 0) ? positive_sum[i - 1] : 0;
        ll sum2 = max((ll) 0, (i > 0) ? sum[i + K - 1] - sum[i - 1] : sum[i + K - 1]);
        ll sum3 = positive_sum[N - 1] - positive_sum[i + K - 1];
        ans = max(ans, sum1 + sum2 + sum3);
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 2176
# include<iostream>
using namespace std;
int main()
{
    int N,x=0,A[100000],B[100000],C[100000],sum=0,a=0;
    cin>>N;
    sum=0;
    for(int i=1;i<=N;i++)
        cin>>A[i];
    for(int i=1;i<=N;i++)
        cin>>B[i];
        for(int i=1;i<=N-1;i++)
        cin>>C[i];
        for(int i=1;i<=N;i++){
            x=A[i];
            sum+=B[x];
        }
         for(int i=1;i<=N;i++){
           if(i && A[i-1]+1==A[i]){
            sum+=C[A[i]-1];
           }

        }
        cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define ll long long int
#define FOR(i,a,b) for(ll (i)=(a);i<(ll)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,n)
#define outi(a) printf("%lld\n",(a))
#define pb push_back
using namespace std;
inline ll read()
{
    ll x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
    return x;
}
//****************************
const ll mod = 1e9+7;
ll power(ll a, ll b)
{
    ll ans = 1;
    while(b > 0)
    {
        if(b&1) 
        {
            ans %= mod;
            ans = ans*a;
        }
        a%=mod;
        a = a*a%mod;
        b>>=1;
    }
    ans%=mod;
    return ans;
}
//****************************
void solve();
int main()
{
    ll n = read();
    vector<ll>ami(62);
    vector<ll>tumi(62);
    rep(i,n)
    {
        ll k = read();
        bitset<62>she(k);
        rep(i, 62)
        if(she[i] == 1) ami[i]++;
        else tumi[i]++;
    }
    ll sum = 0;
    rep(i,62)
    {
        ll p = power(2,i);
        p%=mod;
        sum += ((ami[i]*tumi[i])%mod)*p%mod;
    }
    cout << sum%mod << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=998244353;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  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;
  }
};
const int NMAX=100010;
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;	
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}

int main()
{
  int k,n;
  cin >> k >> n;
  Make_Fact();
  Make_InvFact();
  mint s = Comb(n+k-1,n);
  for(int i=2;i<=2*k;++i){
    int l = i/2;
    if(i-k-1>0){
      l -= (i-k-1);
    }
    //    cout << i << ":" << l << "\n";
    mint tmp;
    for(int m=1;m<=l;++m){
      if(m%2==1){
	tmp += Comb(l,m)*Comb(k+n-2*m-1,n-2*m);
      }
      else{
	tmp -= Comb(l,m)*Comb(k+n-2*m-1,n-2*m);
      }
    }
    cout << (s-tmp).x << "\n";
  }

  return 0;
}


Measured memory_bytes: 1792