akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = (int)3e3 + 9, INF = 0x3f3f3f3f;
int n, m, xtot, xque[maxn], ytot, yque[maxn];
struct Line {
	int L, R, pos;
	void read() {
		scanf("%d%d%d", &L, &R, &pos);
	}
} er[maxn], ec[maxn];
bool vis[maxn][maxn], banL[maxn][maxn], banR[maxn][maxn], banU[maxn][maxn], banD[maxn][maxn];
int main() {
	int T = 1;
	// scanf("%d", &T);
	for(int Case = 1; Case <= T; ++Case) {
		scanf("%d%d", &n, &m);
		xtot = ytot = 0;
		xque[xtot++] = yque[ytot++] = -INF;
		xque[xtot++] = yque[ytot++] = INF;
		for(int i = 0; i < n; ++i) {
			Line &cur = er[i];
			cur.read(); // xL xR y
			xque[xtot++] = cur.L;
			xque[xtot++] = cur.R;
			yque[ytot++] = cur.pos;
		}
		for(int i = 0; i < m; ++i) {
			Line &cur = ec[i];
			cur.read(); // x yL yR
			swap(cur.pos, cur.L); // yR yL x
			swap(cur.L, cur.R); // yL yR x
			yque[ytot++] = cur.L;
			yque[ytot++] = cur.R;
			xque[xtot++] = cur.pos;
		}
		sort(xque, xque + xtot);
		xtot = unique(xque, xque + xtot) - xque;
		sort(yque, yque + ytot);
		ytot = unique(yque, yque + ytot) - yque;
		for(int i = 0; i < xtot - 1; ++i)
			for(int j = 0; j < ytot - 1; ++j) {
				vis[i][j] = 0;
				banL[i][j] = j == 0;
				banR[i][j] = j == ytot - 2;
				banU[i][j] = i == 0;
				banD[i][j] = i == xtot - 2;
			}
		for(int i = 0; i < n; ++i) {
			Line &cur = er[i];
			int xL = lower_bound(xque, xque + xtot, cur.L) - xque;
			int xR = lower_bound(xque, xque + xtot, cur.R) - xque;
			int y = lower_bound(yque, yque + ytot, cur.pos) - yque;
			for(int x = xL; x < xR; ++x) {
				banL[x][y] = 1;
				banR[x][y - 1] = 1;
			}
//			printf("ban [%d, %d) x %d\n", xL, xR, y);
//			show();
		}
		for(int i = 0; i < m; ++i) {
			Line &cur = ec[i];
			int yL = lower_bound(yque, yque + ytot, cur.L) - yque;
			int yR = lower_bound(yque, yque + ytot, cur.R) - yque;
			int x = lower_bound(xque, xque + xtot, cur.pos) - xque;
			for(int y = yL; y < yR; ++y) {
				banU[x][y] = 1;
				banD[x - 1][y] = 1;
			}
//			printf("ban %d x [%d, %d)\n", x, yL, yR);
//			show();
		}
		int sx = lower_bound(xque, xque + xtot, 0) - xque - 1;
		int sy = lower_bound(yque, yque + ytot, 0) - yque - 1;
		LL ans = 0;
		bool inf = 0;
		int tot = 0;
		static pair<int, int> que[maxn * maxn];
		auto append = [&](int x, int y) {
			if(x < 0 || x >= xtot - 1 || y < 0 || y >= ytot - 1 || vis[x][y])
				return;
			vis[x][y] = 1;
			inf |= x == 0 || x == xtot - 2 || y == 0 || y == ytot - 2;
			ans += (LL)(xque[x + 1] - xque[x]) * (yque[y + 1] - yque[y]);
			que[tot++] = make_pair(x, y);
		};
		append(sx, sy);
		for(int i = 0; !inf && i < tot; ++i) {
			int x, y;
			tie(x, y) = que[i];
			if(!banL[x][y])
				append(x, y - 1);
			if(!banR[x][y])
				append(x, y + 1);
			if(!banU[x][y])
				append(x - 1, y);
			if(!banD[x][y])
				append(x + 1, y);
		}
		if(inf) {
			puts("INF");
		} else {
			printf("%lld\n", ans);
		}
//		printf("%d %d\n", sx, sy);
//		show();
	}
	return 0;
}

Measured memory_bytes: 117904
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>V(n),L(n);
    for(int i=0;i<n;i++)cin>>V[i];
    for(int i=0;i<m;i++){
        int a;
        cin>>a;
        for(int j=0;j<n;j++){
            if(a>=V[j]){
                L[j]++;
                break;
            }
        }
    }

    int mxm=-1,pnt;
    for(int i=0;i<n;i++){
        if(mxm<L[i]){
            mxm=L[i];
            pnt=i+1;
        }
    }
    cout<<pnt<<endl;

    return 0;



}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int N = 1e5 + 10;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a[3] = {1, 1, 1};
	int x;
	cin >> x;
	a[x - 1] = 0;
	cin >> x;
	a[x - 1] = 0;
	for (int i = 0; i < 3; i++) {
		if(a[i])
			return cout << i + 1 << "\n", 0;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <list>
#include <set>

using namespace std;

map<string,int> ma;
queue<string> qu;
stack<int> st;
priority_queue<long long> lpr;
stack<long long> lst,lst1;
queue<long long> lqu;
list<long long> lli;
set<long long> lse;

int n;

struct node{
    int i,j;
    node(int i,int j):i(i),j(j){};
};  stack<node> nst;    queue<node> nqu;


int main(){
    cin>>n;
    int x,s=1;
    list<int> li;
    for(int i=0;i<n;i++){
        cin>>x;     li.push_back(x);
    }
    list<int>::iterator it;
    for(int j,i=0;i<n;i++){
        it=li.end();
        for(j=n-i;j>0;j--){   it--;
            if(*it==j) {
                st.push(j);     li.erase(it);   break;
            }
        }
        if(!j) {cout<<-1;   //break;
            return 0;
        }
    }
    while(!st.empty()){
        cout<<st.top()<<endl;       st.pop();
    }
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#define ll long long

using namespace std;



int main() {
	int N; cin >> N;
	vector<int>R;
	for (int i = 0; i < N; i++) {
		int pt; cin >> pt;
		R.push_back(pt);
	}

	int lag = -2002002002;
	int mnIdx = 0;

	for (int i = 0; i < N; i++) {
		if (i > mnIdx && lag < R[i] - R[mnIdx]) lag = R[i] - R[mnIdx];
		if (R[i] < R[mnIdx])mnIdx = i;
	}
	cout << lag << endl;



}





Measured memory_bytes: 3824
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

// 素数判定
template<typename T>
bool is_prime(T n)
{
	if (n == 2)
	{
		return true;
	}
	else if ((n == 1) || (n % 2 == 0))
	{
		return false;
	}

	T p = (T)sqrt(n);
	for (T i = 3; i <= p; i += 2)
	{
		if (n % i == 0)
		{
			return false;
		}
	}

	return true;
}

int main()
{
	vector<int> prime;
	for (int i = 2; i <= 50000; i += (i == 2 ? 1 : 2))
	{
		if (is_prime(i))
		{
			prime.push_back(i);
		}
	}


	for (; ;)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
		{
			break;
		}

		int cnt = 0;
		//if (n % 2 == 0)
		{
			for (int i = 0; i < prime.size(); i++)
			{
				if (n / 2 < prime.at(i))
				{
					break;
				}
				else if (n == 2 * prime.at(i))
				{
					cnt++;
				}
				else
				{
					int x = n - prime.at(i);
					if (*lower_bound(prime.begin(), prime.end(), x) == x)
					{
						cnt++;
					}
				}
			}
		}

		cout << cnt << endl;
	}
}


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

public class Hello{
    public static void Main(){
        // Here your code !
        Planet ThePlanet = new Planet();
        while(true){
            int GemNum = int.Parse(Console.ReadLine());
            if(GemNum == 0) break;
            
            ThePlanet.Init(GemNum);
            Console.WriteLine(GemNum == ThePlanet.Solve() ? "Yes" : "No");
        }
    }
}

public class Planet{
    private bool[,] Map = new bool[Consts.Y_SIZE,Consts.X_SIZE];
    private List<Command> Commands = new List<Command>();
    public void Init(int GemNum){
        // Map Init
        for(int y = 0; y < Consts.Y_SIZE; y++){
            for(int x = 0; x < Consts.X_SIZE; x++){
                Map[y,x] = false;
            }
        }
        
        // Gem Input to Map
        for(int i = 0; i < GemNum; i++){
            string[] GemX_Y = Console.ReadLine().Split(' ');
            Map[int.Parse(GemX_Y[1]),int.Parse(GemX_Y[0])] = true;
        }
        
        // Commands Init
        Commands.Clear();
        int CommandNum = int.Parse(Console.ReadLine());
        for(int i = 0; i < CommandNum; i++){
            string[] V_D = Console.ReadLine().Split(' ');
            Commands.Add(new Command());
            Commands[i].Init(V_D);
        }
    }
    
    public int Solve(){
        int BotX = Consts.InitBotX;
        int BotY = Consts.InitBotY;
        int dx = 0;
        int dy = 0;
        int CorrectedGemNum = 0;
        for(int i = 0; i < Commands.Count; i++){
            switch(Commands[i].Vector){
                case "E": 
                    dx = 1; dy = 0;
                    break;
                case "W":
                    dx = -1; dy = 0;
                    break;
                case "S":
                    dx = 0; dy = -1;
                    break;
                case "N":
                    dx = 0; dy = 1;
                    break;
                default:
                    break;
            }
            for(int d = 1; d <= Commands[i].Distance; d++){
                BotX += dx;
                BotY += dy;
                if(Map[BotY, BotX]){
                    Map[BotY, BotX] = false;
                    CorrectedGemNum++;
                }
            }
        }
        return CorrectedGemNum;
    }
}

public class Command{
    public string Vector { get; private set; }
    public int Distance { get; private set; }
    public void Init(string[] V_D){
        Vector = V_D[0];
        Distance = int.Parse(V_D[1]);
    }
}

public class Consts{
    public static readonly int X_SIZE = 21;
    public static readonly int Y_SIZE = 21;
    public static readonly int InitBotX = 10;
    public static readonly int InitBotY = 10;
}

Measured memory_bytes: 9180
S = input()
S = S[::-1]
d = 1
mods = [0]
counter = [0]*2019
counter[0] += 1
result = 0
for s in S:
  s = int(s)
  mods.append((mods[-1]+s*d)%2019)
  counter[mods[-1]] += 1
  result += counter[mods[-1]] - 1
  d *= 10
  d %= 2019

print(result)

Measured memory_bytes: 16568
# -*- coding: utf-8 -*-

import bisect

INF = 1e20

A, B, Q = map(int, input().split())
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]

for x in X:
    ans = INF
    iS, iT = bisect.bisect_left(S, x), bisect.bisect_left(T, x)

    for s in [S[iS - 1], S[iS]]:
        for t in [T[iT - 1], T[iT]]:
            a1, a2 = abs(s - x) + abs(s - t), abs(t - x) + abs(t - s)
            ans = min(ans, a1, a2)

    print(ans)


Measured memory_bytes: 16188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll a,b,c,d,n;
  cin>>a>>b>>c>>d>>n;
  if(n%2==0){
    cout<<min({n*a*4,n*b*2,n*c,n/2*d});
  }else{
    cout<<min({n*a*4,n*b*2,n*c,n/2*d+c,n/2*d+b*2,n/2*d+a*4});
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int K;
    cin >> K;

    vector<LL> all; 
    vector<vector<LL>> curr(10); 
    vector<vector<LL>> next(10);
    LL base = 1;
    curr[0].push_back(0);
    for (int i = 1; i <= 9; ++i) {
        curr[i].push_back(i);
        all.push_back(i);
    }

    while (all.size() < K) {
        base *= 10;
        for (int i = 0; i <= 9; ++i) {
            next[i].clear();
        }
        for (int i = 0; i <= 9; ++i) {
            for (int d = -1; d <= 1; ++d) {
                int j = i+d;
                if (j < 0 || 10 <= j) continue;
                for (int p: curr[i]) {
                    LL v = base * j + p;
                    next[j].push_back(v);
                    if (0 < j) {
                        all.push_back(v);
                    }
                }
            }
        }
        curr.swap(next);
    }

    sort(all.begin(), all.end());
    cout << all[K-1] << endl;

    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  n++;
  ll a[n];
  rep(i,n) R a[i];
  if(n==1&&a[0]!=1) {
    pr(-1);
    return;
  }
  ll d[n];
  d[n-1]=a[n-1];
  rrep(i,n-1) {
    ll x=MAXL;
    if(i<40) x=min(x,1LL<<i);
    d[i]=min(x,a[i]+d[i+1]);
  }
  rep(i,n) {
    d[i+1]=min(d[i+1],(d[i]-a[i])*2);
  }
  ll ans=0;
  rep(i,n) {
    if(d[i]<a[i]) {
      pr(-1);
      return;
    }
    ans+=d[i];
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 5176
object Main {
  def main(args: Array[String]): Unit = {
    var a, b = 0
    val n = io.StdIn.readInt()
    for (_ <- 0 until n) {
      val Array(ca, cb, _*) = io.StdIn.readLine().split(" ")
      val c = ca.compareTo(cb)
      if (c > 0) {
        a += 3
      } else if (c < 0) {
        b += 3
      } else {
        a += 1
        b += 1
      }
    }
    println(s"$a $b")
  }
}

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

int main(){
 int N,ans=0;
 
  scanf("%d",&N);
  
  
  int V[N],C[N];
  
  
  for(int i=0;i<N;i++){
    scanf("%d",&V[i]);
  }

  for(int i=0;i<N;i++){
    scanf("%d",&C[i]);  
  }
  
 
  for(int i = 0;i<N;i++){
    if(V[i]>C[i]){
      ans += V[i]-C[i];
    }
  }
  
  printf("%d",ans);

}

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

int dp[100001];
vector<int> e[100001];
void dfs(int x){
	vector<int> v;
	for(int it:e[x]){
		dfs(it);
		v.emplace_back(dp[it]);
	}
	sort(v.begin(),v.end(),greater<int>());
	for(int i=0;i<v.size();i++)
		dp[x]=max(dp[x],v[i]+i+1);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=2,x;i<=n;i++){
		cin>>x;
		e[x].emplace_back(i);
	}
	dfs(1);
	cout<<dp[1]<<endl;
}


Measured memory_bytes: 13952
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define forn(i,n) for(ll i=0 ; i<n ; i++)
#define arr(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
#define ub upper_bound
#define pb push_back
#define pi pair<int,int>
#define mod 1000000007
#define vectormax *max_element
#define vectormin *min_element
#define arraysize 1000000
#define setbit _builtin_popcountll
using namespace std;

ll ipow(ll x, ll n)
{
    ll result = 1;
    while (n) {
        if (n & 1)
            result = result * x ;
        n = n / 2;
        x = x * x;
    }
    return result;
}
int main(){
 int r,g,b;
 cin>>r>>g>>b;
int k;
cin>>k;
int count=0;
if(r>=g){
    while(1){
        if(g>r)
            break;
        g=g*2;
        count++;
    }
}
if(g>=b){
    while(1){
        if(b>g)
            break;
        b=b*2;
        count++;
    }
}
if(count>k)
    cout<<"No"<<endl;
else
    cout<<"Yes"<<endl;
return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, t, a[100100], p[100100], mn = 1<<30;

signed main() {
	cin >> n >> t;
	rep(i,n) {
		cin >> a[i];
		if (i) p[i] = a[i] - mn;
		chmin(mn, a[i]);
	}
	int mx = *max_element(p,p+n);
	cout << count(p,p+n,mx) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int n, arr[202020], brr[202020];
ll ans;

priority_queue<pii> pq;

inline int pv(int x) {
	if (x==0) return n-1;
	return --x;
}
inline int nx(int x) {
	if (x==n-1) return 0;
	return ++x;
}

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

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

	for (int i=0; i<n; i++) pq.push(pii(brr[i], i));

	while (!pq.empty()) {
		pii tmp = pq.top();
		pq.pop();

		//cout << tmp.va << ' ' << tmp.vb << '\n';
		int v = tmp.va, i = tmp.vb;
		if (v < arr[i]+brr[pv(i)]+brr[nx(i)]) {
			if (brr[i] == arr[i] && brr[pv(i)] == arr[pv(i)] && brr[nx(i)] == arr[nx(i)]) continue;
			break;
		}

		ans += (ll) (brr[i]-arr[i])/(brr[pv(i)]+brr[nx(i)]);
		brr[i] = (brr[i]-arr[i])%(brr[pv(i)]+brr[nx(i)])+arr[i];
		if (brr[i]<brr[nx(i)] || brr[i]<brr[pv(i)]) pq.push(pii(brr[i], i));
	}

	for (int i=0; i<n; i++) {
		if (arr[i] == brr[i]) continue;

		cout << -1;
		return 0;
	}

	cout << ans;
}

Measured memory_bytes: 3956
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
namespace io{
	const int SIZE=(1<<21)+1;char ibuf[SIZE],*iS,*iT,obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1,c,qu[55];int f,qr;
	#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,SIZE,stdin),(iS==iT?EOF:*iS++)):*iS++)
	inline void flush(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}inline void putc(char x){*oS++=x;if(oS==oT)flush();}
	template<class I>inline void gi(I&x){for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;}
	template<class I>inline void print(I x){if(!x)putc('0');if(x<0)putc('-'),x=-x;while(x)qu[++qr]=x%10+'0',x/=10;while(qr)putc(qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}

const int maxn=20+7;
int n,m,sum;

int main(){
	#ifdef LOCAL
		freopen("B.in","r",stdin);freopen("B.out","w",stdout);
	#endif
	io::gi(n);m=n;while(m)sum+=m%10,m/=10;if(n%sum==0)printf("Yes\n");else printf("No\n");
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
double PI=2.0*acos(0.0);
double hc=180.0;
int main(){
        int a,b,c,d; cin>>a>>b>>c>>d;
        auto sqr=[&](int a){return (double)a*a; };
        c=c*60+d;
        double hh=c/(double)2;
        double mh=d*6.0;
        double dhm=fabs(hh-mh);
        dhm=min(dhm,360-dhm);
        double dist=sqr(a)+sqr(b)-2.0*a*b*cos((PI*dhm)/hc);
        cout<<fixed<<setprecision(10)<<sqrt(dist)<<endl;
}



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

typedef long long int ll;

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  int maxH = 0;
  for(int i = 0;i < N;i++){
     cin >> H[i];
     maxH = max(maxH,H[i]);
  }
  int ans = 0;
  int memo = 0;
  for(int j = 0;j < maxH;j++){
     for(int i = 0;i < N;i++){
     if(H[i] > j){
        memo++;
     }else{
        if(memo > 0){
           ans++;
           memo = 0;
        }
     }
     if(i == N-1 && memo > 0 && H[i] >= j){
        ans++;
     }
     }
     memo = 0;
  }
  cout << ans << endl;
}

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

int main(void) {
	int h, w;
	char a[101][101];
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int t = 1; t <= w; t++) {
			cin >> a[i][t];
		}
	}

	for (int t = 1; t <= w+2; t++) {
		cout << "#";
	}
	cout << endl;;
	for (int i = 1; i <= h; i++) {
		for (int t = 0; t <= w+1; t++) {
			if ((t == 0) || (t == w + 1)) {
				cout << "#";
			}
			else {
				cout << a[i][t];
			}
		}
		cout << endl;
	}
	for (int t = 1; t <= w + 2; t++) {
		cout << "#";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 9999999999999LL
#define NINF -999999999999LL
#define EPS 0.0000001f
using namespace std;

typedef long long int lli;
typedef pair<lli,lli> pii;

lli n,t,ans;
vector<lli> a,ps;
int main() {
	ans = 0;
	scanf("%lld",&n);
	a.push_back(0);
	for(lli i=0;i<n;i++){
		scanf("%lld",&t);
		a.push_back(t);
	}
	sort(a.begin(),a.end());
	ps.push_back(0);
	for(int i=1;i<=n;i++){
		ps.push_back(ps[i-1] + a[i]);
	}
	for(int i=1;i<=n;i++){
		// attempt to fit n
		lli size = 0,newsize = a[i];
		//cout << i << " ";
		do {
			size = newsize;
			newsize = int(upper_bound(a.begin(),a.end(),size*2) - a.begin())-1;
			//cout << newsize << " ";
			newsize = ps[newsize];
		} while(size != newsize);
		//cout << endl << i << " max size is " << size << endl;
		if(size==ps[n]) ans++;
	}
	printf("%lli",ans);
}

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair

using namespace std;

using uint=unsigned int;
using ll=long long;

uint xor128(){
	static uint d[]={1145141919,1919810893,810893364,364114514};
	uint t=d[0]^(d[0]<<11);
	REP(i,3)
		d[i]=d[i+1];
	return d[3]=d[3]^(d[3]>>19)^(t^(t>>8));
}

struct Node{
	Node *l,*r;
	uint pri;
	int s,v,mn;
} buf[200000];

using NP=Node*;

NP newNode(int v){
	static int c=0;
	buf[c]=Node{NULL,NULL,xor128(),1,v,v};
	return &buf[c++];
}

const int inf=1145141919;

int Mini(NP x){
	return x?x->mn:inf;
}

int Size(NP x){
	return x?x->s:0;
}

NP Update(NP x){
	x->s=Size(x->l)+Size(x->r)+1;
	x->mn=min({x->v,Mini(x->l),Mini(x->r)});
	return x;
}

NP LinkL(NP x,NP l){
	x->l=l;
	return Update(x);
}

NP LinkR(NP x,NP r){
	x->r=r;
	return Update(x);
}

NP CutL(NP x){
	x->l=NULL;
	return Update(x);
}

NP CutR(NP x){
	x->r=NULL;
	return Update(x);
}

NP Merge(NP a,NP b){
	if(!a)
		return b;
	else if(!b)
		return a;
	else if(a->pri>b->pri)
		return LinkR(a,Merge(a->r,b));
	else
		return LinkL(b,Merge(a,b->l));
}

using Res=Node;

Res Split(NP x,int k){
	if(k<=0)
		return Res{NULL,x};
	else if(x->s<=k)
		return Res{x,NULL};
	else if(k<=Size(x->l)){
		Res s=Split(x->l,k);
		return Res{s.l,Merge(s.r,CutL(x))};
	}else{
		Res s=Split(x->r,k-Size(x->l)-1);
		return Res{Merge(CutR(x),s.l),s.r};
	}
}

void Set(NP x,int k,int v){
	int ls=Size(x->l);
	if(k<ls)
		Set(x->l,k,v);
	else if(k==ls)
		x->v=v;
	else
		Set(x->r,k-ls-1,v);
	Update(x);
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

NP t[200000];

int main(){
	int n=read(),q=read();
	REP(i,n)
		t[i]=newNode(read());
	while(n>1){
		int k=n/2;
		REP(i,k)
			t[i]=Merge(t[i*2],t[i*2+1]);
		if(k*2<n)
			t[k]=t[k*2];
		n=(n+1)/2;
	}
	NP root=t[0];
	REP(_,q){
		int x=read(),y=read(),z=read();
		if(x==0){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y-1);
			Res s3=Split(s2.r,1);
			root=Merge(Merge(s1.l,s3.l),Merge(s2.l,s3.r));
		}else if(x==1){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y);
			printf("%d\n",Mini(s2.l));
			root=Merge(s1.l,Merge(s2.l,s2.r));
		}else if(x==2){
			Set(root,y,z);
		}
	}
}

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

int main()
{
	int n;
	cin >> n;
	int a = 0, t = n;
	while(t > 0){
		a += (t % 10);
		t /= 10;
	}
	cout << (n % a == 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int max = K - A[N - 1] + A[0];
    rep(i, 1, N) { chmax(max, A[i] - A[i - 1]); }
    cout << K - max << endl;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int H, W;
    cin >> H >> W;
    string S[H];
    rep(i, H) cin >> S[i];
    int A[H-1][W-1];
    rep(i, H-1) rep(j, W-1){
        int cnt = 0;
        rep(x, 2) rep(y, 2){
            if(S[i+x][j+y] == '.') cnt++;
        }
        if(cnt%2 == 0) A[i][j] = 1;
        else A[i][j] = 0;
    }
    rep(i, H-1) rep(j, W-1){
        if(i == 0) continue;
        elif(A[i][j] == 1) A[i][j] += A[i-1][j];
    }
    int ans = H;
    rep(i, H-1){
        //j列目が一番高いときに[L[j],R[j])で長方形ができる
        int L[W-1], R[W-1];
        stack<int> sl, sr;
        rep(j, W-1){
            while(!sl.empty() && A[i][sl.top()] >= A[i][j]) sl.pop();
            if(sl.empty()) L[j] = 0;
            else L[j] = sl.top()+1;
            sl.push(j);
        }
        rep3(j, W-2, 0){
            while(!sr.empty() && A[i][sr.top()] >= A[i][j]) sr.pop();
            if(sr.empty()) R[j] = W-1;
            else R[j] = sr.top();
            sr.push(j);
        }
        rep(j, W-1){
            ans = max(ans, (A[i][j]+1)*(R[j]-L[j]+1));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 19968
s = input()
s0 = s[0]
count = 1
nodes = []
ans = 0
for i in range(1, len(s)):
  if s0 == s[i]:
    count += 1
  elif s0 == '>':
    s0 = s[i]
    nodes.append(-count)
    count = 1
  else:
    s0 = s[i]
    nodes.append(count)
    count = 1
if s0 == '>':
  nodes.append(-count)
else:
  nodes.append(count)

for i in range(1, len(nodes)):
  if nodes[i] < 0:
    if abs(nodes[i]) > abs(nodes[i - 1]):
      nodes[i] = abs(nodes[i])
      nodes[i - 1] -= 1
    else:
      nodes[i] = abs(nodes[i])
      nodes[i] -= 1
nodes[0] = abs(nodes[0])
for i in nodes:
  ans += (i * (i + 1)) // 2
print(ans)

Measured memory_bytes: 6300
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mod 1000000007
#define maxn 2005
using namespace std;
int n,K;
int f[maxn][maxn][3];
void add(int &x,int y)
{
    x+=y;
    if(x>=mod)  x-=mod;
}
int main()
{
    cin>>n>>K;
    f[n+1][0][2]=1;
    for(int i=n+1;i>1;i--)
    {
        for(int j=n;j>=0;j--)  add(f[i][j][1],f[i][j+1][1]);
        for(int j=0;j<=n;j++)
        {
            for(int t=1;t<=2;t++)
            {
                add(f[i-1][j+1][2],f[i][j][t]);
                add(f[i-1][j][1],f[i][j][t]);
            }
        }
    }
    int ans=f[1][n-K][1];
    for(int i=1;i<=n-K-1;i++)  ans=1ll*ans*2%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 47360
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=3.14159265359;

int main() {
    int K;
    string S;
    cin>>K>>S;
    if(S.size()<=K) cout<<S<<endl;
    else {
        for(int i=0;i<K;++i){
            cout<<S[i];
        }
        cout<<"...";
        cout<<endl;
    }
}



Measured memory_bytes: 3628
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;

int main(int argc, char *argv[])
{
    int W, H, N;
    std::cin >> W >> H >> N;

    std::vector<int> x(N), y(N), a(N);
    for (int i = 0; i < N; i++) {
        std::cin >> x[i] >> y[i] >> a[i];
    }

    int xmax = 0;
    int xmin = W;
    int ymax = 0;
    int ymin = H;
    for (int i = 0; i < N; i++) {
        if (a[i] == 1) {
            if (xmax < x[i]) {
                xmax = x[i];
            }
        } else if (a[i] == 2) {
            if (xmin > x[i]) {
                xmin = x[i];
            }
        } else if (a[i] == 3) {
            if (ymax < y[i]) {
                ymax = y[i];
            }
        } else if (a[i] == 4) {
            if (ymin > y[i]) {
                ymin = y[i];
            }
        }
    }

    int ans = 0;
    if (xmin - xmax > 0 && ymin - ymax > 0) {
        ans = (xmin - xmax)*(ymin - ymax);
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <chrono>
using namespace std::chrono;
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
/*    auto start = high_resolution_clock::now();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cout << "\nduration="<<duration.cnt()/1e6 << endl;
*/
#define pi 6.28318530717958623200

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    double r;
    cin>>r;
    cout<<pi*r;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int A, B;
	cin >> A >> B;

	int a, s, m;
	a = A + B;
	s = A - B;
	m = A * B;

	cout << max(max(a, s), m) << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
 
#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
const double pi = acos(-1.0);
int n;
 
double ans=0;
struct node
{
   int x,y;
   bool operator<(const node &p)const
   {
      return (x==p.x)?y<p.y:x<p.x;
   }
}a[200200];
double c[200200];
int main()
{
   double x1,y1,x2,y2;
   cin>>x1>>y1>>x2>>y2;
   ans=(abs(x1-x2)+abs(y1-y2))*(100);
   double X1=min(x1,x2),X2=max(x1,x2),Y1=min(y1,y2),Y2=max(y1,y2);
   cin>>n;
   int length=0;
   F(i,1,n)
   {
      double x,y;
      cin>>x>>y;
      if((x>=X1)&&(x<=X2)&&(y>=Y1)&&(y<=Y2)) a[++length].x=x,a[length].y=y;
   }
   n=length;
   if(n==0)
   {
      printf("%.15f\n",ans);return 0;
   }
   sort(a+1,a+1+n);
   int len=1;
   F(i,1,n) c[i]=a[i].y;
   if(x1>x2&&y1<y2||x1<x2&&y1>y2) F(i,1,n/2) swap(c[i],c[n+1-i]);
   F(i,2,n)
   {
    if(c[len]<c[i]) c[++len]=c[i];
    else c[lower_bound(c+1,c+1+len,c[i])-c]=c[i];
   }
   ans=ans-(20-5*pi)*len;
   int check=min(abs(y1-y2),abs(x1-x2))+1;
   if(len==check)  { ans+=5*pi;}
   printf("%.15f\n",ans );
   return 0;
}

Measured memory_bytes: 3328
import sys
from copy import deepcopy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
lst1 = [list(map(int,readline().split())) for i in range(n)]

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
st = deepcopy(lst1)
st = warshall_floyd(st)
ans = 0
for i in range(n):
    for j in range(i+1,n):
        if lst1[i][j] > st[i][j]:
            print(-1)
            exit()
        elif lst1[i][j]==st[i][j]:
            #他に最短距離がある場合はcontinue
            res = [0]*n
            for k in range(n):
                res[k] += lst1[i][k] + lst1[j][k]
            res[i] = -1
            res[j] = -1
            if any([res[k]==lst1[i][j] for k in range(n)]):
                continue
            else:
                ans += lst1[i][j]
        else:
            ans += lst1[i][j]

print(ans)

Measured memory_bytes: 60636
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;


int main() {
  int n, ma = -1;
  cin >> n;
  map<string, int> memo;
  //auto memo1 = memo;
  REP(i,n) {
    string s;
    cin >> s;
    if (memo.count(s)) ++memo[s];
    else memo[s] = 1;
   
  }
  for(auto m: memo){
    ma = max(ma,memo[m.first]);
  }
  for (auto s : memo) {
    if (s.second == ma) cout << s.first << "\n";
  }
}

Measured memory_bytes: 25344
import sys
# from collections import defaultdict

N = int(sys.stdin.readline().rstrip())
S = sys.stdin.readline().rstrip()
Q = int(sys.stdin.readline().rstrip())

BIT = [[0 for _ in range(N + 1)] for _ in range(26)]  # 初期化（アルファベット分）
alpha = {"a": 0, "b": 1, "c": 2, "d": 3, "e": 4,
         "f": 5, "g": 6, "h": 7, "i": 8, "j": 9,
         "k": 10, "l": 11, "m": 12, "n": 13, "o": 14,
         "p": 15, "q": 16, "r": 17, "s": 18, "t": 19,
         "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25}


# 初期化
def initialize():
    global BIT, S, N
    for j in range(N):
        c = alpha[S[j]]  # 文字切り出し／index に変換
        i = j + 1
        while i <= N:
            BIT[c][i] += 1
            i += (i & -i)


def identify(i):
    # i文字目を、変化点があった文字として探索する
    for c in range(26):
        if sum(i, c) != sum(i - 1, c):
            return c


# 文字の交換
def change(i, before, after):

    global BIT, N
    while i <= N:
        BIT[before][i] -= 1
        BIT[after][i] += 1
        i += (i & -i)


# 文字数の取り出し
def sum(i, c):

    global BIT

    _sum = 0
    while i > 0:
        _sum += BIT[c][i]
        i -= (i & -i)

    return _sum


initialize()

for _ in range(Q):
    q, x, y = sys.stdin.readline().rstrip().split()
    if q == "1":
        i = int(x)
        ac = alpha[y]
        bc = identify(i)
        change(i, bc, ac)

    else:
        x = int(x)
        y = int(y)
        count = 0
        for c in range(26):
            if sum(y, c) != sum(x - 1, c):
                count += 1
        print(count)

Measured memory_bytes: 240840
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	ios::sync_with_stdio(false);
	int n, k;
	string str;
	cin >> n >> str >> k;
	for (int i = 0; i < n; i++)
	{
		if (str[i] != str[k - 1])
		{
			str[i] = '*';
		}
	}
	cout << str;
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (a >= 13) cout << b << endl;
	else if (6 <= a && 12 >= a) cout << b / 2 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int a;
	char b;
	string c;
	int t[4] = {0,0,0,0};
	while(cin >> a >> b >> c){
		if(c=="A") t[0]++;
		if(c=="B") t[1]++;
		if(c=="AB") t[2]++;
		if(c=="O") t[3]++;
	}
	cout << t[0] << endl;
	cout << t[1] << endl;
	cout << t[2] << endl;
	cout << t[3] << endl;
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(){

  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  if((a==1&&b==2)||(a==2&&b==1)) printf("3");
  else if((a==1&&b==3)||(a==3&&b==1)) printf("2");
  else if((a==3&&b==2)||(a==2&&b==3)) printf("1");
}

Measured memory_bytes: 128
N,A,B=map(int,input().split())

if A>B:
    print(0)
elif N==1 and A<B:
    print(0)
elif N==1 and A==B:
    print(1)
elif N==2:
    print(1)
else:
    print(A+B*(N-1)-(A*(N-1)+B)+1)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

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

        double[] p = new double[n];
        for (int i = 0; i < n; i++) p[i] = (sc.nextDouble() + 1.0) / 2.0;

        double[] sumP = new double[n];
        for (int i = 0; i < n; i++) {
            if (i == 0) sumP[i] = p[i];
            else sumP[i] = sumP[i-1] + p[i];
        }

        List<Double> result = new ArrayList<>();
        for (int i = 0; i <= n-k; i++) {
            if (i == 0) result.add(sumP[k-1]);
            else result.add(sumP[i+k-1] - sumP[i-1]);

        }
        System.out.println(result.stream().max(Comparator.naturalOrder()).get());
    }
}

Measured memory_bytes: 158836
#include<stdio.h>
int main()
{
	char g[7];
	int y,m,d;
	while(1){
		scanf("%s",g);
		if(g[0]=='#'){
			break;
		}
		scanf("%d %d %d",&y,&m,&d);
		if(y<31){
			printf("HEISEI %d %d %d\n",y,m,d);
		}else if(y==31){
			if(m<=4){
				printf("HEISEI %d %d %d\n",y,m,d);
			}else{
				printf("? %d %d %d\n",y-30,m,d);
			}
		}else{
			printf("? %d %d %d\n",y-30,m,d);
		}
	}
	return 0;
}



Measured memory_bytes: 2696
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<utility>
#include<vector>

#define INF 1000000007

using ll = long long;
using namespace std;

int main(void){

    ll x, y;
    cin >> x >> y;

    ll ans = 0;
    if(abs(x)<abs(y)){
        if(x<0)ans += 1;
        ans += abs(y)-abs(x);
        if(y<0)ans++;
    }
    else if(x==y)ans = 0;
    else if(x==-y)ans = 1;
    else{
        if(x>0)ans += 1;
        ans += abs(x)-abs(y);
        if(y>0)ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int a,b;

  scanf("%d%d",&a,&b);

  if(a>=13){
    printf("%d",b);
  }else if(a<=5){
    puts("0");
  }else{
    printf("%d",b/2);
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define maxn 100005
#define Mod 1000000007
typedef pair<int,int> PII;
typedef map<int,int> MII;
typedef vector<int> VI;
typedef vector<vector<int>> VII;
typedef vector<long long> VLL; 
#define For(i,a,b) for(int i = (a); i < (b); ++i)
#define Rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
#define __builtin_popcountll bitCountLL
#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
const int INF = 2e9;
const LL ML = 4e18;

void solve() {
    char c;
    cin >> c;
    if(c >= 'a' && c <= 'z') cout << 'a';
    else cout << 'A';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
	//freopen("D:\\data_in.txt", "r", stdin);
    solve();
    
    /*clock_t start,finish;
    start = clock();
   
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;

/*
Tを区切り文字として考える
ｘ，y座標は独立して考える
DPで解ける
自分は，DPの書き方がわからなかった.
*2 ずつ遷移する場所が増えていくけど大丈夫なのかな...?


Tが連続しているとき
T % 2 == 1 : 軸の変換
T % 2 == 0: 軸そのまま
ただし， 初回にT=1のときは，Xの向きにしか進めない
*/

int main(){
  string s;
  cin >> s;
  int gx, gy;
  cin >> gx >> gy;
  // Xにすすめる区間，Yにすすめる区間を分ける．
  //はじめにTにがない場合を考える
  vector<int> mx;
  vector<int> my;
  bool flag = true;
  int cnt = 0;
  REP(i,s.size()){

    if(s[i] == 'F'){
      ++cnt;
      continue;
    }

    if(s[i] == 'T'){
      if(cnt != 0){
        if(flag) mx.push_back(cnt);
        else my.push_back(cnt);
        cnt = 0;
      }
      flag = !flag;
    }
  }
  if(cnt != 0){
    if(flag) mx.push_back(cnt);
    else my.push_back(cnt);
    cnt = 0;
  }

  // for(auto x : mx) cout << x << " ";
  // cout <<  endl;
  // for(auto x : my) cout << x << " ";
  // cout << endl;
  int xs = mx.size();
  int ys = my.size();

  vector<map<int, bool>> dpx(xs);
  vector<map<int, bool>> dpy(ys);

  //どちらかが初期値違う　初めにTがなければ，ｘの値は一意に決定する
  bool isx = false;
  bool isy = false;
  if(xs == 0) {
    if(gx == 0) isx = true;
  }
  else{

    if(s[0] == 'F') dpx[0][mx[0]] = true;
    else{
      dpx[0][mx[0]] = true;
      dpx[0][-mx[0]] = true;
    }

    //dpの操作

    REP2(i,1,xs){
      int movex = mx[i];
      for(auto x: dpx[i-1]){
        if(x.second){
          dpx[i][ x.first + movex] = true;
          dpx[i][ x.first - movex] = true;
        }
      }
    }
    if(dpx[xs-1].count(gx)){  //mapが存在するならば
      if(dpx[xs-1][gx]) isx = true;
    }
  }

  if(ys == 0){
    if(gy == 0) isy = true;
  }
  else{

  dpy[0][my[0]] = true;
  dpy[0][-my[0]] = true;

  REP2(i,1,ys){
    int movey = my[i];
    for(auto y: dpy[i-1]){
      if(y.second){
        dpy[i][ y.first + movey] = true;
        dpy[i][ y.first - movey] = true;
      }
    }
  }
  if(dpy[ys-1].count(gy)) { //count mapが存在するなら１　存在しないなら０
    if(dpy[ys-1][gy]) isy = true;
  }
}

  // for(auto x : dpx[xs-1]) cout <<x.first << ":" << x.second << " ";
  // cout << endl;
  // for(auto x : dpy[ys-1]) cout <<x.first << ":" << x.second << " ";
  // cout << endl;

  // //実現可能かの確認
  if(isx && isy) cout << "Yes" << endl;
  else  cout << "No" << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll h,w;
ll hcnt[2001][2001];
ll wcnt[2001][2001];
string s[2001];
int main(){
    cin >> h >> w;
    rep(i,h)cin >> s[i];
    rep(i,h){
        rep(j,w){
            if(s[i][j] == '.'){
                hcnt[i][j] = 1;
                wcnt[i][j] = 1;
            }
        }
    }

    rep(i,h){
        rep(j,w-1){
            if(hcnt[i][j+1] != 0)hcnt[i][j+1] += hcnt[i][j];
        }
        for(ll j = w - 1;j > 0;j--){
            if(hcnt[i][j-1] != 0 && hcnt[i][j] != 0)hcnt[i][j-1] = hcnt[i][j];
        }
    }

    rep(j,w){
        rep(i,h-1){
            if(wcnt[i+1][j] != 0)wcnt[i+1][j] += wcnt[i][j];
        }
        for(ll i = h - 1;i > 0;i--){
            if(wcnt[i-1][j] != 0 && wcnt[i][j] != 0)wcnt[i-1][j] = wcnt[i][j];
        }
    }
    //     rep(i,h){
    //     rep(j,w)cout << wcnt[i][j] << " ";
    //     cout << endl;
    // }
    ll ans = 0;
    rep(i,h)rep(j,w)ans = max(ans,wcnt[i][j] + hcnt[i][j] - 1);
    cout << ans << endl;
}

Measured memory_bytes: 66944
from collections import Counter
n = int(input())
ls = list(map(int, input().split()))
q = int(input())
count = Counter(ls)
sm = sum(ls)

for _ in range(q):
    b, q = map(int, input().split())
    if b in count:
        sm -= count[b] * b
        sm += count[b] * q
        print(sm)
    else:
        print(sm)
    if q in count:
        count[q] += count[b]

        count[b] = 0
    else:
        count[q] = count[b]

        count[b] = 0


Measured memory_bytes: 24112
#include<bits/stdc++.h>
#define mod 10000000000000
#define mod1 998244353
#define Mmax 1000005
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
bool comp(pair<li,pair<li,li>>a,pair<li,pair<li,li>>b)
{
  if(a.first<b.first)
  return 1;
  else if(a.first>b.first)
  return 0;
  else
  {
    return a.second.first<b.second.first;
  }
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
li modInverse(li n)
{
    return mpow(n, mod-2);
}

li nCrModPFermat(li n, li r,li x,li y,li z)
{
   // Base case
   if (r==0)
      return 1;
    // li fac[n+1];
    // fac[0] = 1;
    // for (int i=1 ; i<=n; i++)
    //     fac[i] = fac[i-1]*i%mod;
    return (x* modInverse(y) % mod *modInverse(z) % mod) % mod;
}
void bfs(vector<li>v[],li visit[],li s,li ans[])
{
  deque<li>q;
  q.push_back(s);
  visit[s]=1;
  while(!q.empty())
  {
    li x=q.front();
    q.pop_front();
    for(auto i=v[x].begin();i!=v[x].end();i++)
    {
      if(!visit[*i])
      {
        q.push_back(*i);
        visit[*i]=1;
      }
    }
  }
}
void buildtree(int*tree,int*arr,int start,int end,int treeNode)
{
  if(start<end)
  {
    int mid=start+(end-start)/2;
    buildtree(tree,arr,start,mid,2*treeNode);
    buildtree(tree,arr,mid+1,end,2*treeNode+1);
    tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
  }
}
void update(int*tree,int*arr,int start,int end,int pos,int val,int treeNode)
{
  if(start==end)
  tree[treeNode]=val;
  else
  {
    int mid=start+(end-start)/2;
    if(pos<=mid)
    update(tree,arr,start,mid,pos,val,2*treeNode);
    else
    update(tree,arr,mid+1,end,pos,val,2*treeNode+1);
    tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
  }
}

void dfs(vector<li>v[],li visit[],li s,li c[],li ans[],map<li,li>*m,li pred[])
{
    visit[s]=1;
     (*m)[c[s]]++;
    for(auto i=v[s].begin();i!=v[s].end();i++)
      {
        if(!visit[*i])
        {pred[*i]=s;
           dfs(v,visit,*i,c,ans,m,pred);
        }
      }
      if((*m)[c[pred[s]]]==1)
    ans[s]=(*m).size()-1;
    else
    ans[s]=(*m).size();
}
vector<li>factor(li n)
{
  vector<li>v;
  if(n%2==0)
  {
    while(n%2==0)
    {n/=2;
    v.push_back(2);
    }
  }
  for(li i=3;i<=sqrt(n);i+=2)
  {
    if(n%i==0)
    {
      while(n%i==0)
      {n/=i;
      v.push_back(i);
      }
    }
  }
  if(n>1)
  v.push_back(n);
  return v;
}
int main()
{
// li t,i,j;
// cin>>t;
// while(t--)
// {
//
//   cout<<endl;
// }
li n,k,x,p,i;
cin>>n>>k;
map<li,li>m;
for(i=0;i<k;i++)
{
  cin>>x;
  while(x--)
  {
    cin>>p;
    m[p]++;
  }
}
li ans=0;
for(i=1;i<=n;i++)
if(!m[i])
ans++;
cout<<ans;
return 0;
}


Measured memory_bytes: 3648