akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/agc036/tasks/agc036_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll S;
  cin >> S;

  ll base = 1e9;
  ll y1 = base;
  ll y2 = 1;
  ll x1 = S % base;
  ll x2 = S / base;

  if (x1 > 0) {
    x1 = base - x1;
    x2 += 1;
  }

  VL res = {0, 0, x1, y1, x2, y2};

  rep(i, res.size()) {
    if (i > 0) cout << " ";
    cout << res[i];
  }
  cout << "\n";
}


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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 2e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 998244353;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "4";

int seg[4 * siz], lazy[4 * siz];
int pw[siz], ppw[siz];

void init() {
    pw[1] = ppw[1] = 1;
    for (int i = 2; i < siz; i++) {
        pw[i] = (pw[i - 1] * 10) % mod;
        ppw[i] = (ppw[i - 1] + pw[i]) % mod;
    }
}

void build(int id, int st, int ed) {
    if (st == ed) {
        seg[id] = pw[st];
        return;
    }

    int mid = (st + ed) / 2;
    build(2 * id, st, mid);
    build(2 * id + 1, mid + 1, ed);

    seg[id] = (seg[2 * id] + seg[2 * id + 1]) % mod;
}

void propagate(int id, int st, int ed) {
    if (lazy[id] != -1) {
        seg[id] = ((ppw[ed] - ppw[st - 1] + mod) * lazy[id]) % mod;
        if (st != ed) {
            lazy[2 * id] = lazy[id];
            lazy[2 * id + 1] = lazy[id];
        }
        lazy[id] = -1;
    }
}

void range_update(int id, int st, int ed, int lt, int rt, int val) {
    propagate(id, st, ed);

    if (rt < st || ed < lt) {
        return;
    }

    if (lt <= st && ed <= rt) {
        lazy[id] = val;
        propagate(id, st, ed);
        return;
    }

    int mid = (st + ed) / 2;
    range_update(2 * id, st, mid, lt, rt, val);
    range_update(2 * id + 1, mid + 1, ed, lt, rt, val);

    seg[id] = (seg[2 * id] + seg[2 * id + 1]) % mod;
}

int range_sum(int id, int st, int ed, int lt, int rt) {
    propagate(id, st, ed);

    if (rt < st || ed < lt) {
        return 0;
    }

    if (lt <= st && ed <= rt) {
        return seg[id];
    }

    int mid = (st + ed) / 2;
    int s1 = range_sum(2 * id, st, mid, lt, rt);
    int s2 = range_sum(2 * id + 1, mid + 1, ed, lt, rt);

    return ((s1 + s2) % mod);
}

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

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    init();

    int n, q;
    cin >> n >> q;

    build(1, 1, n);
    memset(lazy, -1, sizeof(lazy));

    while (q--) {
        int l, r, d;
        cin >> l >> r >> d;

        range_update(1, 1, n, n - r + 1, n - l + 1, d);

        cout << range_sum(1, 1, n, 1, n) << "\n";
    }

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 17140
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)

int main(){
    int N,M,res,tmpL,tmpR;
    cin >> N >> M;

    int tmpRMin = 100001;
    int tmpLMax = 0;

    //N:IDカードの枚数
    //M:ゲートの数;
    //なんでも開けれる領域を求める
    // 左辺の最大と右辺の最小が求める領域

    REP(i,M){
        cin >> tmpL >> tmpR;
        if(tmpL > tmpLMax && tmpL <= N)tmpLMax = tmpL;
        if(tmpR < tmpRMin)tmpRMin = tmpR;

    }

    res = tmpRMin - tmpLMax + 1;
  	
  	if(res < 0)res = 0;
    cout << res << endl;

    return 0;
}



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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

void solve(long long n, long long m){
  cout << (n - 1) * (m - 1) << endl;
}

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


Measured memory_bytes: 3748
#include<cstdio>
#include<algorithm>


//mapの最大値
#define INDEX_WHMAP_MAX		12
//マップ(１番大きいとする)
int wh_map[INDEX_WHMAP_MAX][INDEX_WHMAP_MAX];
//四方を見るための配列
const int h_tate[4] = {1 , -1 , 0 , 0};
const int h_yoko[4] = {0 , 0 , 1 , -1};
//入力方法がわからないから文字で受け取る
char str_nyuuryoku[INDEX_WHMAP_MAX][INDEX_WHMAP_MAX + 1];




//----- 1つめの島を見つける関数 -----//
int f_firstsima(void);

//----- 島を見つけた場合、陸続きのものがあるかどうか調べる関数 -----//
void f_search(int , int);

//----- マップを初期化する関数 -----//
int f_syokika(void);



//*****----- main -----*****

int main(void)
{
	while (1)
	{
		//最初に初期化する(EOFが返ってきたら終了)
		if (f_syokika() == 0)
		{
			break;
		}

		//戻り値を出力
		int ans = f_firstsima();
		printf("%d\n" , ans);
	}

	return 0;
}




//*****----- 1つめの島を見つける関数 -----*****//

int f_firstsima(void)
{
	//答えをカウントする変数
	int ans = 0;

	//マップの分だけforを回す
	for (int i = 0; i < 12; i++)
	{
		for (int j = 0; j < 12; j++)
		{
			//もしもまだ探索していない島だったら
			if (wh_map[i][j] == 1)
			{
				ans++;
				//再帰関数に現在座標を送って、陸続きのものを消してもらう
				f_search(i , j);
			}
		}
	}

	return ans;
}



//*****----- 島を見つけた場合陸続きなものがあるかどうか調べる関数 -----*****//

void f_search(int y , int x)
{
	//まず現在座標を0とする(島を消すため)
	wh_map[y][x] = 0;
	//四方を見るためにforを回す
	for (int i = 0; i < 4; i++)
	{
		//次の座標を宣言(マップがはみ出ないかどうかは重要である)
		int nextx = x + h_yoko[i];
		int nexty = y + h_tate[i];

		//はみでない
		if (nextx >= 0 && nextx < INDEX_WHMAP_MAX &&
			nexty >= 0 && nexty < INDEX_WHMAP_MAX)
		{
			//　+　陸続きである
			if (wh_map[nexty][nextx] == 1)
			{
				//再帰関数でさらに陸続きの場所がないか操作を続ける
				f_search(nexty , nextx);
			}
		}
	}
}




//*****----- マップ初期化関数の実体 -----*****//

int f_syokika(void)
{
	for (int i = 0; i < 12; i++)
	{
		//１行一気に入力されるらしい
		if (scanf("%s" , str_nyuuryoku[i]) == EOF)
		{
			return 0;
		}
	}

	//戻すのが面倒なので、文字列配列から整数配列へ移す
	for (int i = 0; i < 12; i++)
	{
		for (int j = 0; j < 12; j++)
		{
			wh_map[i][j] = str_nyuuryoku[i][j] - '0';
		}
	}

	return 1;
}

Measured memory_bytes: 968
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    ll d;
    cin>>n>>d;
    ll x,y,cnt=0;
    rep(i,n){
        cin>>x>>y;
        if(d*d>=x*x+y*y) cnt++;
    }
    cout<<cnt;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
const int N=1e5+10;
vector<int>f[N],a;
queue<int>q;
int n,m,p,x,y,in[N],ans,dp[N];
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%d",&x,&y);
		f[x].push_back(y);
		in[y]++;
	}
	for(int i=1;i<=n;i++)
		if(!in[i])q.push(i);
	while(!q.empty())
	{
		p=q.front();
		q.pop();
		a.push_back(p);
		for(int j=0;j<f[p].size();j++)
			if(!--in[f[p][j]])q.push(f[p][j]);
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<f[a[i]].size();j++)
			dp[f[a[i]][j]]=dp[a[i]]+1;
		ans=max(ans,dp[a[i]]);
	}
	printf("%d",ans);
	return 0;
}


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

using namespace std;

long long f(long long a) {
  return a * a * a * a * a;
}

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

  int x;
  cin >> x;
  for (int b = -1000; b <= 1000; ++b) {
    for (int a = -1000; a <= 1000; ++a) {
      if (f(a) - f(b) == x) {
        cout << a << ' ' << b;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n, m, X, Y;
  cin >> n >> m >> X >> Y;
  vi x(n);
  vi y(m);
  rep(i,n){
    cin >> x[i];
  }
  rep(i,m){
    cin >> y[i];
  }
  sort(all(x));
  sort(all(y));
  if(x[n-1]<y[0]&&x[n-1]<Y&&X<y[0]){
    print("No War");
  }
  else{
    print("War");
  }
}

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


int main(){

int k;
string s;
cin >>k >> s;

string ans = s;

if(s.size()>k){
    ans = s.substr(0,k) + "...";

}

cout << ans << endl;

}



Measured memory_bytes: 3624
def main():
    X, K, D = list(map(int, input().split()))
    
    def sgn(X):
        if X > 0:return 1
        if X < 0:return -1
        return 0
    
    if X > 0:
        x_greedy = X - K * D
    else:
        x_greedy = X + K * D
    
    if sgn(X) == sgn(x_greedy):
        print(abs(x_greedy))
        return
    
    x_r = X % D
    x_l = x_r - D

    r_parity = (abs(X - x_r) // D) % 2
    
    if K%2 == r_parity:
        print(abs(x_r))
    else:
        print(abs(x_l))
main()


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

int main() {
  int x;cin>>x;
  while(1){
    bool ans=true;
    for(int i=2;i<x;i++){
      if(x%i==0){
        ans=false;
        break;
      }
    }
    if(ans)break;
    x++;
  }
  cout<<x<<endl;
}

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

int main() {
	int N,T;
	int ans = 1001;
	cin >> N >> T;
	for(int i = 0; i < N; i++){
		int c,t;
		cin >> c >> t;
		if(t <= T && c < ans){
			ans = c;
		}
	}
	if(ans == 1001){
		cout << "TLE" << endl;
	} else {
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for(i=0;i<n;i++) cin >> a[i];
  int x = *max_element(a.begin(),a.end());
  int y = *min_element(a.begin(),a.end());
  cout << x-y << "\n";
  return 0;
}

Measured memory_bytes: 3624
/*786*/
#include <bits/stdc++.h>

#define pu ios_base::sync_with_stdio();cin.tie(NULL);cout.tie(NULL);

#define ll                  long long
#define yes                 cout<<"YES"<<endl
#define no                  cout<<"NO"<<endl
#define sp                  ' '
#define vi                  vector<int>
#define vl                  vector<ll>
#define pb                  push_back
#define mp                  make_pair
#define f(i,n)              for(i=0;i<n;i++)
#define stop                return 0;
#define new                 cout<<endl
#define res(x)              cout<<x<<endl;
#define vip                 vector<pair<int,int> >
#define srt(v)              sort(v.begin(),v.end());
#define test                int t;cin>>t;while(t--)
#define mx(a)               *max_element(a,a+n)

using namespace std;
int main()
{
    pu;
    ll n,i,s=0;
    cin>>n;
    for(i=1;i<=n;i++){
        if(!(i%3==0||i%5==0||(i%3==0&&i%5==0)))s+=i;
    }
    res(s);
        stop;
}


Measured memory_bytes: 3580
#include<stdio.h>

typedef struct{
  int left;
  int right;
  int parent;
}Tree;

void Preorder( int );
void Inorder( int );
void Postorder( int );

Tree T[25];

int main()
{
  int i, j, n, id, root, left, right;

  scanf("%d", &n);

  for( i=0; i<n; i++ )
    {
      T[i].parent = -1;
    }

  for( i=0; i<n; i++ )
    {
      scanf("%d%d%d", &id, &left, &right);
      
      T[id].left = left;
      T[id].right = right;
      if( left != -1 ) T[left].parent = id;
      if( right != -1 ) T[right].parent = id;
    }

  for( i=0; i<n; i++ )
    {
      if( T[i].parent == -1 ) root = i;
    }

  printf("Preorder\n");
  Preorder( root );

  printf("\nInorder\n");
  Inorder( root );

  printf("\nPostorder\n");
  Postorder( root );
  printf("\n");

  return 0;
}


void Preorder( int id )
{
  if( id == -1 ) return;

  printf(" %d", id);
  Preorder( T[id].left );
  Preorder( T[id].right );
}


void Inorder( int id )
{
  if( id == -1 ) return;

  Inorder( T[id].left );
  printf(" %d", id);
  Inorder( T[id].right );
}


void Postorder( int id )
{
  if( id == -1 ) return;

  Postorder( T[id].left );
  Postorder( T[id].right );
  printf(" %d", id);
}
  



Measured memory_bytes: 2112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


			String[] str = br.readLine().split(" ");
			int r = Integer.parseInt(str[0]);
			int c = Integer.parseInt(str[1]);
			int[] csum= new int[c + 1];

			for(int i = 0; i<r; i++){
				str = br.readLine().split(" ");
				int value=0;
				for(int j = 0; j<c; j++ ){
					value += Integer.parseInt(str[j]);
					csum[j] += Integer.parseInt(str[j]);
					System.out.print(str[j] + " ");
				}
				System.out.println(value);
			}
			for(int i=0;i<c;i++){
				csum[c] += csum[i];
				System.out.print(csum[i] + " ");
			}
			System.out.println(csum[c]);


	}
}

Measured memory_bytes: 30964
#include<bits/stdc++.h>
#define M 100005
#define INF 19260817
#define LHXAK {printf("Yes\n"); return 0;}
#define XFZSB {printf("No\n"); return 0;}
using namespace std;

int n,a[M]={0};

int main(){
	scanf("%d",&n);
	int maxn=0,minn=INF;
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		maxn=max(maxn,a[i]);
		minn=min(minn,a[i]);
	}
	if(maxn-minn>1) XFZSB
	if(maxn==minn){
		if(maxn==n-1) LHXAK
		if(maxn*2<=n) LHXAK
		XFZSB
	}
	int cnt=0;
	for(int i=1;i<=n;i++) if(a[i]==minn) cnt++;
	if(cnt<maxn&&n-cnt>=(maxn-cnt)*2) LHXAK
	XFZSB
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end() 

vector<ll> A{1,0,-1,0};
vector<ll> B{0,1,0,-1};


int main() {
ll H,W;
  cin>>H>>W;
vector<string> vec(H);
  for(ll i=0;i<H;i++) {
cin>>vec[i];
  }
  
  
  ll ans=0;
 for(ll i=0;i<H;i++) {
for(ll j=0;j<W;j++) {
  if(vec[i][j]=='#') {
continue;
  }
  vector<vector<ll>> dist(H,vector<ll>(W,-1));
  dist[i][j]=0;
  queue<pair<ll,ll>> S;
  S.push(make_pair(i,j));
  while(!S.empty()) {
    ll nh=S.front().first;
    ll nw=S.front().second;
    S.pop();
    for(ll h=0;h<4;h++) {
ll kh=nh+A[h];
      ll kw=nw+B[h];
      if(kh<0||kh>=H||kw<0||kw>=W) {
continue;
      }
      if(vec[kh][kw]=='#') {
continue;
      }
      if(dist[kh][kw]!=-1) {
continue;
      }
      
      dist[kh][kw]=dist[nh][nw]+1;
      S.push(make_pair(kh,kw));
    }
  }
  
  for(ll k=0;k<H;k++) {
for(ll g=0;g<W;g++) {
if(ans<dist[k][g]) {
ans=dist[k][g];
}
  }
  
}
 }
 }
  
  cout<<ans<<endl;
}
      
    

  

  
  
  
  
  
  
  
  
  

  


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a,z;
  for (int i=0; i<n; i++){
    if (s[i] == 'A'){
      a = i;
      break;
    }
  }
  for (int i=n-1; i>-1; i--){
    if (s[i] == 'Z'){
      z = i;
      break;
    }
  }
  cout << z-a+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
int mod = 1e9+7;

int main()
{
   ll n, m;
	cin >> n >> m;
	if(n>m)swap(m,n);
	if(abs(n-m)>1)
	{
		cout<<0<<endl;
		return 0;
	}
	ll ans = 1;
	ll now = 1;
	for(now;now<=n;now++)
	{
		ans = (ans * now%mod)%mod;
		ans = (ans * now%mod)%mod;
	}
	
	//cout<<ans<<endl;
	if(n!=m)ans= (ans * (now)%mod)%mod;
	else ans = ans*2%mod;
	cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 384
N = int(input())
ans = 0
for i in range(1, N+1, 2):
    count = 0
    for j in range(1, int(i ** 0.5) + 1):
        if i % j == 0:
            count += 2
    if int(i ** 0.5) ** 2 == i:
        count -= 1
    if count == 8:
        ans += 1
print(ans)


Measured memory_bytes: 2940
#include <stdio.h>

int main(){
  //long long int X, A, B, C;
  long long int i, j, k, cnt = 0;
  long long int N, max;
  long long int a[2][110];

  scanf("%lld", &N);

  for (i = 0; i < 2; i++) {
    for (j = 0; j < N; j++) {
      scanf("%lld", &a[i][j]);
    }
  }

  for (i = 1; i <= N; i++) {
    cnt = 0;
    for (j = 0; j < i; j++) {
      cnt += a[0][j];
    }
    for (k = j-1; k < N; k++) {
      cnt += a[1][k];
    }
    if (cnt > max) {max = cnt;}
    //printf("aa%lld\n", cnt);
  }
  
  printf("%lld\n", max);
  
  /* scanf("%ld%ld%ld%ld", &A, &B, &C, &X); */
  /* for (i = 0; i <= A; i++) { */
  /*   for (j = 0; j <= B; j++) { */
  /*     for (k = 0; k <= C; k++) { */
  /*       if (500*i + 100*j + 50*k == X) {cnt++;} */
  /*     } */
  /*   } */
  /* } */
  //printf("%d\n", cnt);

}


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

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> A(N),sum(N+1,0);
	for(int i=0;i<N;i++) cin >> A[i];
	sort(A.begin(),A.end());
	for(int i=1;i<=N;i++)sum[i] = sum[i-1] + A[i-1];

	ll ok=0,ng=300000,ans=0;
	while(ng-ok>1){
		ll mid = (ng+ok)/2;
		ll num = 0;
		ll anst = 0;
		ll ind = N;
		for(int i=0;i<N;i++){
			while( ind>0 && (A[ind-1] >= mid-A[i]) )ind--;
			num += N - ind;
			anst += (sum[N]-sum[ind])+A[i]*(N-ind);
		}
		if(num >= M){
			ok = mid;
			ans = anst - (num-M) * ok;
		}else{
			ng = mid;
		}
	}
	cout << ans << endl;
}

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

int main(){
  string S;
  cin>>S;
  int count=0;
  
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='+')
      count++;
    else
      count--;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

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

Measured memory_bytes: 3580
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int num=sc.nextInt();
		for(int i=3;i<=num;i++){
			if(i%3==0){
				System.out.printf(" %d",i);
			}else if(i%1==3){
				System.out.printf(" %d",i);
			}else if(i%10==3){
				System.out.printf(" %d",i);
			}else if(i%100>=30&&i%100<=39){
				System.out.printf(" %d",i);
			}else if(i%1000>=300&&i%1000<=399){
				System.out.printf(" %d",i);
			}else if(i%10000>=3000&&i%10000<=3999){
				System.out.printf(" %d",i);
			}
		}
		System.out.println("");

	}
}

Measured memory_bytes: 34000
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int H, W;
string S[50];

const int INF = 1 << 30;
const int dx[4] = {0, -1, 1, 0};
const int dy[4] = {-1, 0, 0, 1};

// 境界判定用関数
bool inarea(int x, int y) {
    return x >= 0 && x < H && y >= 0 && y < W;
}

// 幅優先探索部分を抽出
int bfs() {
    vector<vector<int>> d(H, vector<int>(W, INF));
    queue<pair<int, int>> q;

    d[0][0] = 1;
    q.push({0, 0});

    while (!q.empty()) {
        pair<int, int> p = q.front();
        int x = p.first;
        int y = p.second;

        q.pop();

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if (!inarea(nx, ny)) continue;
            // ネストを減らす

            if (S[nx][ny] == '.' && d[x][y] + 1 < d[nx][ny]) {
                d[nx][ny] = d[x][y] + 1;
                q.push({nx, ny});
            }
        }
    }

    return d[H - 1][W - 1];
}

int main() {
    cin >> H >> W;

    int wnum = 0;
    for (int i = 0; i < H; i++) {
        cin >> S[i];
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '.') wnum++;
        }
    }

    int d = bfs();

    if (d == INF) {
        cout << -1 << endl;
    } else {
        cout << wnum - d << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll MOD = 1000000007;
ll Bunshi(ll A, ll B){
	ll res = 1;
	for(int i=0;i<B;i++){
		res *= (A-i);
		res %= MOD;
	}
	return res;
}

ll Bunbo(ll B){
	ll res = 1;
	for(int i=0;i<B;i++){
		res *= (i+1);
		res %= MOD;
	}
	return res;
}
ll beki(ll B, ll n, ll p){
	if(n==0) return 1;
	else{
		ll res = beki((B*B)%p, n/2, p);
		if(n%2==1){
			res *= B;
			res %= p;
		}
		return res;
	}
}

int main(){
	ll X, Y;
	cin >> X >> Y;

	if((2*X-Y)%3!=0 || (2*X-Y)<0 || (-X+2*Y)%3!=0 || (-X+2*Y)<0){
		cout << 0 <<endl;
		return 0;
	}

	ll R = (2*X-Y)/3;
	ll U = (-X+2*Y)/3;

	ll ans = Bunshi(R+U, U);
	ans *= beki(Bunbo(U), MOD-2, MOD);
	ans %= MOD;
	cout << ans <<endl;


  	return 0;
}


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

const int maxn = 310;

using namespace std;

int n,K,f[maxn][maxn][maxn];
string t;

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>t;
    cin>>K;
    n= t.length();
    for (int i=n-1;i>=0;i--)
        for (int j=i;j<n;j++)
            for (int k=0;k<=K;k++) {
                    if (i==j) {
                        f[i][j][k] = 1;
                        continue;
                    }
                    if (i+1==j) {
                        f[i][j][k] = ((t[i] == t[j] || k>0) ? 2 : 1);
                        continue;
                    }
                    f[i][j][k] = max(f[i+1][j][k], f[i][j-1][k]);
                    if (t[i]==t[j]) f[i][j][k] = max(f[i][j][k], f[i+1][j-1][k] + 2);
                    else if (k>0) f[i][j][k] = max(f[i][j][k], f[i+1][j-1][k-1] +2);
            }
    cout<<f[0][n-1][K]<<endl;
}



Measured memory_bytes: 112896
let S = stdin.ReadLine()

let seq0 = S |> Seq.map (fun x -> (int x) - (int '0'))
let seq1 = Seq.initInfinite (fun x -> (x % 2)) // 01010101010
let seq2 = seq1 |> Seq.skip 1 //101010101

Seq.zip3 seq0 seq1 seq2
|> Seq.fold (fun (cnt1,cnt2) -> fun (x,a,b) -> 
    if x = a then (cnt1, cnt2+1) else (cnt1+1, cnt2)) (0,0)
|> fun (a, b) -> min a b
|> printfn "%d"

Measured memory_bytes: 18980
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    while (1) {
        int N, M;
        cin >> N >> M;
        if (!(N || M)) break;
        vector<int> A(N + 1, 0);
        for (int i = 0; i < N; i++) cin >> A[i];

        vector<int> pool;
        for (int i = 0; i <= N; i++) {
            for (int j = i; j <= N; j++) {
                pool.push_back(A[i] + A[j]);
            }
        }
        sort(pool.begin(), pool.end());

        int ret = 0;
        for (int i = 0; i < pool.size(); i++) {
            int remain = M - pool[i];
            auto it = upper_bound(pool.begin(), pool.end(), remain);
            if (it == pool.begin()) continue;
            ret = max(pool[i] + *(it - 1), ret);
        }

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


Measured memory_bytes: 10764
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

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

#define dump(x) cerr << #x << " = " <<(x)<<endl;
#define debug(x) cerr << #x << " = " <<(x) << "(L" << __LINE__ << ")" << __FILE__ << endl;

#define BIT_ON(x,b) ((x)|=(b))
#define BIT_OFF(x,b) ((x)&=~(b))
#define BIT_IS_ON(x,b) (((x)&(b))==(b))


using namespace std;
typedef long long ll;

int main(void){
  ll a,b;
  cin >> a>> b;
  if(a>0){
    cout << "Positive" << endl;
    return 0;
  }
  if(0>=a*b) {
    cout << "Zero" << endl;
    return 0;
  }
  a *= -1;
  ll c = a+b;
  if(0==c%2){ cout << "Negative" << endl;}
  else{ cout << "Positive" << endl;}

  return 0;
}


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

using namespace std;
using ll = long long;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll K, N;
    cin >> K >> N;
    vector<ll> A(N);
    REP(i,0,N) cin >> A[i];

    ll m = 0, sum = 0;
    REP(i,0,N-1) {
        sum += abs(A[i+1] - A[i]);
        m = MAX(m,abs(A[i+1] - A[i]));
    }
    sum += abs(K - A[N-1]) + A[0];
    if(m < abs(K - A[N-1]) + A[0]) {
        m = abs(K - A[N-1]) + A[0];
    }
    sum -= m;
    _PR(sum);

    return 0;
}

/*



*/

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int ans = a;
  if (b < a) {
    ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
  n = int(input())
  l = sorted(list(map(int,input().split())))
  ans = 0
  for i in range(n-2):
    for j in range(i+1,n-1):
      for k in range(j+1,n):
        a = l[i]
        b = l[j]
        c = l[k]
        if a+b>c and abs(a-b)<c and a!=b and b!=c and c!=a:
          ans += 1
  print(ans)
  
if __name__=="__main__":
  main()

Measured memory_bytes: 9136
#include <bits/stdc++.h>
//#include <conio.h>
#define fto(i,x,y) for(i=(x);i<=(y);i++)
#define fdto(i,x,y) for(i=(x);i>=(y);i--)
#define ftoi(i,x,y) for(int i=(x);i<=(y);i++)
#define fdtoi(i,x,y) for(int i=(x);i>=(y);i--)
#define ll long long
#define ld double
#define oo (ll) 2000000000
#define ull unsigned long long
#define ui unsigned int
#define zero 1E-6
#define ii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define miii map<int,int>::iterator
#define ftoimii(it,m) for(map<int,int>::iterator it=m.begin();it!=m.end();it++)
#define ftoimsi(it,m) for(map<string,int>::iterator it=m.begin();it!=m.end();it++)

#define bug(x) printf("%d ", x)
#define sbug(x) printf("%s ", x);
#define abug(a,x,y) ftoi(i,x,y){printf("%d ",a[i]);}
#define wait() getch()
using namespace std;
int a[3][101];
int main () {
  int N, i, j;
  scanf ("%d", &N);
  fto (i, 1, 2)
    fto (j, 1, N)
      scanf ("%d", &a[i][j]);
  if (N == 1){
    printf ("%d", a[1][1] + a[2][1]);
  } else {

    fto (i, 2, N)
      a[1][i] = a[1][i] + a[1][i-1];
    a[2][1] += a[1][1];
    fto (i, 2, N)
      a[2][i] = a[2][i] + max (a[1][i], a[2][i-1]);
    printf("%d", a[2][N]);
  }
}


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

int main(void) {
	int N, M;
	cin >> N >> M;
	vector<double>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	//------------------------------------
	double Asum = 0;
	for (int i = 0; i < N; i++) {
		Asum = Asum + A[i];
	}
	//選定できるか否かのライン
	double a = Asum / (4 * M);

	int Ans = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] >= a) {
			Ans += 1;
		}
	}
	if (Ans >= M) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
import java.io.*;

public class Main { 
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str1 = br.readLine();
		String str2 = br.readLine();
		int n = str1.length();
		int m = str2.length();
		int[][] dp = new int[n+1][m+1];
		for(int i=0; i<=n; i++) {
			for(int j=0; j<=m; j++) {
				if(i==0) dp[i][0] = 0;
				else if(j==0) dp[0][j] = 0;
				else if(j>0 && i>0 && str1.charAt(i-1)==str2.charAt(j-1)) dp[i][j] = dp[i-1][j-1]+1;
				else dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
			}
		}
		StringBuffer lcs = new StringBuffer("");
		int i=n, j = m;
		while(i>0 && j>0) {
			if(str1.charAt(i-1) == str2.charAt(j-1)) {
				i--;j--;
				lcs.append(str1.charAt(i));
			}
			else if(dp[i-1][j] > dp[i][j-1]) i-- ;
			else j--;
		}
		System.out.println(lcs.reverse().toString());
	}
}


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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> ans(n);
    for (int i = 1; i <= n; i++) {
        for (int j = i+1; j <= n; j++) {
            int d = min(j-i, abs(x-i) + 1 + abs(y-j));
            ans[d]++;
        }
    }
    for (int i = 1; i < n; i++) {
        cout << ans[i] << "\n";
    }
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main
{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    int[] freq = new int[(int)1e5 + 1];
    //10^5 = 100,000
    //~2e9
    for (int i = 0; i < N; i++)
    {
      A[i] = sc.nextInt();
    }
    for (int i = 0; i < N; i++)
    {
      freq[A[i]] += 1; //case do nothing:
      if (A[i] - 1 >= 0) freq[A[i] - 1] += 1;
      freq[A[i] + 1] += 1;
    }
    int count = 0;
    for (int i = 0; i< 1e5 + 1; i++)
    {
      count = Math.max(count, freq[i]);
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 61392
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double



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


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

int n,m,a[310][310];
int cnt[310];bool used[310];priority_queue<P> que;
bool j(int x){
  rep(i,n){
    cnt[a[i][0]]++;
  }
  P mx = P(-1, -1);
  rep(i,m){
    chmax(mx, P(cnt[i], i));
    used[i] = true;
  }
  while(mx.first > x){
    used[mx.second] = false;
    rep(i,m)cnt[i] = 0;
    rep(i,n){
      bool updated = false;
      rep(j,m){
        if(used[a[i][j]]){
          cnt[a[i][j]]++;
          updated = true;
          break;
        }
      }
      if(!updated)return false;
    }
    mx = P(-1, -1);
    rep(i,m)chmax(mx, P(cnt[i], i));
    if(mx.first <= x)return true;
  }
  return false;
}

signed main(){
  double t;double ans;
  cin>>t;
    double cnt = 0;
    repd(i,1,t+1)if(i%2 == 1)cnt += 1.0;
    cout << cnt/t << endl;
}


Measured memory_bytes: 256
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    N = int(input())
    ans = int()
    for i in range(1, N+1):
        if (i%3 != 0 and i%5 != 0):
            ans += i
    print(ans)
    return

if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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 isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int n;
    cin >> n;
    
    for(double i=1;i<50000;i++){
        if (n<=i*1.08&&i*1.08<n+1) {
			cout << i << endl;
			return 0;
		}
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
s = input()
n = len(s)-1
comb = 2**n-1 #0b1111
S = 0
for i in range(comb+1):
    #print('{:04b}'.format(i))
    sep =[]
    j0 = 0
    for j in range(n):
        #print('j=', j,  i>>j & 1)
        if (i>>j & 1):
            sep.append(s[j0:j+1])
            j0 = j+1
    sep.append(s[j0:])
    #print(sep)
    x = list(map(int, sep))
    S += sum(x)

print(S)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	int x, y, z;
	int s, ans;
	scanf("%d %d", &x, &y);
	x += (2 * y);
	ans = x / ((2*y) + 1);

	printf("%d\n", ans);


	return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

int main()
{
    const char *Yes = "Yes";
    const char *No = "No";

    char N[10];

    if (scanf("%s", N) < 1) return 0;

    int len = strlen(N);

    int sum = 0;
    for (int i = 0; i < len; i++)
    {
        sum += N[i] - '0';
    }

    int n = stoi(N);

    printf("%s\n", n % sum ? No : Yes);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG(x) cout << #x << " = " << x << endl
#define pb push_back
using namespace std;
typedef long long ll;


const int MAXN = 1000005;
const int MOD = 1000000007;
ll s[MAXN];
int main()
{
    //freopen("input.txt", "r", stdin);
    ll n;
    cin >> n;
    s[0] = 1;
    s[1] = 1;
    ll S = 0;
    for (int i = 2; i <= n; i++)
    {
        s[i] = (s[i-1] + S) % MOD;
        S = (S + s[i-2]) % MOD;
    }

    ll g = 0;
    for (int i = 0; i <= n-2; i++)
    {
        g += s[i] * (i+1);
        g %= MOD;
    }

  //  cout << g << endl;
   // cout << s[n-1] <<  endl;

    ll ans = (  g + s[n] + ((s[n-1]*(n-1))%MOD) + (S*((n-1)*(n-1)%MOD)%MOD)  ) % MOD;
    cout << ans;
    return 0;
}



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

#define MIN -10000

int main(){
    int num[10] = {0,2,5,5,4,5,6,3,7,6};
    int n,m;
    cin >> n >> m;
    vector<int> a(m, 0);
    for (int i=0;i<m;i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());

    vector<int> dp(n+1,0);

    for (int i=1;i<n+1;i++){
        vector<int> tmp(m,MIN);
        for (int j=0;j<m;j++){
            if (i-num[a[j]] >= 0){
                tmp[j] = dp[i-num[a[j]]]+1;
            }
        }
        dp[i] = *max_element(tmp.begin(), tmp.end());
    }

    vector<int> ans(dp[n], 0);
    int n_ = n;
    for (int i=0;i<dp[n];i++){
        for (int j=0;j<m;j++){
            if (n_-num[a[j]] >= 0 && dp[n_-num[a[j]]]==dp[n_]-1){
                ans[i] = a[j];
                n_ = n_-num[a[j]];
                break;
            }
        }
    }

    for (int i=0;i<dp[n];i++){
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using pll = pair<ll,ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
using vstr = vector<string>;
const ll MOD=1000000007;
vll dx{0,1,0,-1};
vll dy{1,0,-1,0};


template <class type> void printVector(vector<type> vec){
    stringstream ss;
    ll n=vec.size();
    for(ll i=0;i<n;i++)
    {
        ss<<vec[i]<<" ";
        if(i!=n-1)ss<<" ";
    }
    cout<<ss.str()<<endl;
}

template <class type> void inputVector(vector<type>& vec){
    for(ll i=0;i<vec.size();i++)
    {
        cin>>vec[i];
    }
}
int main(){
    ll N;
    cin>>N;
    ll count=0;
    rep(i,N)
    {
        ll d1,d2;cin>>d1>>d2;
        if(d1==d2)count++;
        else count=0;
        if(count==3)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
typedef set<ll> Set;

int main(){
    ll k,n;
    cin >> k >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    sort(a,a+n);
    ll ma=0;
    ma=max(ma,k-a[n-1]+a[0]);
    for(ll i=0;i<n-1;i++) ma=max(ma,a[i+1]-a[i]);
    kaku(k-ma);
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    ll sum=0;
    vec A(n),num(100001,0);
    rep(i,n) cin>>A[i],num[A[i]]++,sum+=A[i];
    int q;
    cin>>q;
    rep(query,q){
        int b,c;
        cin>>b>>c;
        sum+=(c-b)*num[b];
        num[c]+=num[b],num[b]=0;
        cout<<sum<<"\n";
    }
}

Measured memory_bytes: 4764
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 200000;
int n, k;
int p[MAX_N];
long double s[MAX_N];

int main() {
    fastio();

    cin >> n >> k;
    forn(i, n) {
        cin >> p[i];
        s[i] = 1.0 * (1 + p[i]) * p[i] / 2 / p[i];
    }

    long double ans = accumulate(s, s + k, 0.0L);
    long double temp = ans;
    for (int i = k, j = 0; i < n; i++, j++) {
        temp += s[i] - s[j];
        chmax(ans, temp);
    }

    printf("%.15Lf\n", ans);

    return 0;
}

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

int main(){
  int n; cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n; i++) cin>>b[i];
  
  long long minus=0;
  vector<int> plus(0);
  int ans=0;  
  for (int i=0; i<n; i++){
    if (b[i]>a[i]){
      minus+=b[i]-a[i];
      ans+=1;
    }
    else plus.push_back(a[i]-b[i]);
  }
  
  if (minus==0){
    cout<<0<<endl;
    return 0;
  }
  
  sort(plus.rbegin(),plus.rend());
  for (auto d : plus){
    ans+=1;
    minus-=d;
    if (minus<=0){
      cout<<ans<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 4668
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, Ma, Mb := sc.nextInt(), sc.nextInt(), sc.nextInt()
	A := make([]int, N)
	B := make([]int, N)
	C := make([]int, N)
	for i := 0; i < N; i++ {
		a, b, c := sc.nextInt(), sc.nextInt(), sc.nextInt()
		A[i] = a
		B[i] = b
		C[i] = c
	}
	var dp [41][401][401]int
	for i := 0; i < N+1; i++ {
		for j := 0; j < 401; j++ {
			for k := 0; k < 401; k++ {
				dp[i][j][k] = INF
			}
		}
	}
	dp[0][0][0] = 0
	for i := 1; i < N+1; i++ {
		for j := 0; j < 401; j++ {
			for k := 0; k < 401; k++ {
				dp[i][j][k] = dp[i-1][j][k]
				if j >= A[i-1] && k >= B[i-1] {
					dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-A[i-1]][k-B[i-1]]+C[i-1])
				}
			}
		}
	}
	ans := INF
	for i := 1; i < 401; i++ {
		if Ma*i > 400 || Mb*i > 400 {
			continue
		}
		ans = min(ans, dp[N][Ma*i][Mb*i])
	}

	if ans == INF {
		fmt.Fprintln(wtr, -1)
	} else {
		fmt.Fprintln(wtr, ans)
	}
}


Measured memory_bytes: 53760