akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long N = scn.nextLong();
		long ans = 0;
		ArrayList<Long> point = new ArrayList<Long>();

		for(long i = 1;;i++) {
			long p = i * (i+2);
			if(p>N)break;
			point.add(p);
		}
		
		for(int i = 0;i < point.size();i++) {
			long p = point.get(i);
			if((N-p)%(i+1)==0) {
				ans += (i+2)+(N-p)/(i+1);
			}
		}


		System.out.println(ans);
	}

}


Measured memory_bytes: 64980
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)

int main(){
    string s;
    cin >> s;
    string tmp = s;
    reverse(tmp.begin(), tmp.end());
    string b, c, d, e;
    rep(i, 0, (s.size()-1)/2) b += s[i];
    c = b;
    reverse(c.begin(), c.end());
    rep(i, (s.size() + 3)/ 2 - 1, s.size()) d += s[i];
    e = d;
    reverse(e.begin(), e.end());
    if(s==tmp && b == c && d==e){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}   

Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let v = Array.init n (fun _ -> Scanf.scanf " %f" (fun v -> v)) in
    Array.sort compare v;
    let rec loop i cur =
        if i = n then cur else
            loop (i + 1) ((cur +. v.(i)) /. 2.)
    in
    loop 1 v.(0) |> Printf.printf "%.6f\n"
)

Measured memory_bytes: 3956
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class FLCS {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s,t;
        in >> s >> t;
        int n=s.size(),m=t.size();
        vector<vector<int>> dp(n+1,vector<int>(m+1,0));
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(s[i-1]==t[j-1]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }else{
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        string ans="";
        int i=n,j=m;
        while(dp[i][j]!=0){
            while(i>0&&dp[i][j]==dp[i-1][j])i--;
            while(j>0&&dp[i][j]==dp[i][j-1])j--;
            i--;j--;
            ans=s[i]+ans;
        }

        out << ans << endl;
	}
};


int main() {
	FLCS solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////

int main(){
    string T;
    getline(cin,T);
    bool N,W,S,E;
    N = W = S = E = false;
    
    REP(i,T.length()){
        if (T[i] == 'N') N = true;
        if (T[i] == 'W') W = true;
        if (T[i] == 'S') S = true;
        if (T[i] == 'E') E = true;
    }

    bool ans = true;
    if (N and (!S)) ans = false;
    if (S and (!N)) ans = false;
    if (W and (!E)) ans = false;
    if (E and (!W)) ans = false;
    //cout << N << W << S << E;
    if (ans) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
    n = int(input())
    A = list(map(int,input().split()))
    C = Counter(A)
    total = 0
    for key, val in C.items():
        total += val * (val - 1) // 2
    for a in A:
        print(total - C[a] + 1)
resolve()

Measured memory_bytes: 82768
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int main() {
    string w;
    cin >> w;
    rep(i, w.size()) w.at(i) = tolower(w.at(i));
    int ans = 0;
    while(true){
        string s;
        cin >> s;
        if(s == "END_OF_TEXT" ){
            break;
        }
        if(s.size() != w.size()) continue;
        rep(i, s.size()) s.at(i) = tolower(s.at(i));
        if(s.find(w) == string::npos ) continue;
        else ans++;


    }
    cout << ans << endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

//int mod = 1000000007;
int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

int modpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

signed main(){

    int N; cin >> N;
    vec a(N); readv(a);
    int S = 0; REP(i, N) S += a[i];

    int M = 90000;
    mat dp(N + 1, vec(M + 1, 0));
    dp[0][0] = 1;
    REP(i, N){
        REP(j, M + 1){
            if(j + a[i] <= M) Add(dp[i + 1][j + a[i]], dp[i][j]);
            Add(dp[i + 1][j], 2 * dp[i][j]);
        }
    }
    int x = 0;
    FOR(j, (S + 1) / 2, M + 1) Add(x, dp[N][j]); 

    mat dp2(N + 1, vec(M + 1, 0));
    dp2[0][0] = 1;
    REP(i, N){
        REP(j, M + 1){
            if(j + a[i] <= M) Add(dp2[i + 1][j + a[i]], dp2[i][j]);
            Add(dp2[i + 1][j], dp2[i][j]);
        }
    }

    int p = modpow(3, N, mod);
    int ans = p - 3 * x;
    if(S % 2 == 0) ans += 3 * dp2[N][S / 2];
    ans = (ans % mod + mod) % mod;
    cout << ans << endl;

    return 0;
}


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


int main()
{
	int n,k,i;

	scanf("%d %d",&n,&k);

	int a=1;
	i = k;
	while(n>=i)
	{
		i = k * i;
		a++;
	} 

	printf("%d",a);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	if(c >= a && c <= b) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define pb push_back
#define mod 1000000007
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};

ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

 // void dfs(ll node){
 // 	vis[node]=1;
 // 	res.pb(node);
 //    vector<ll> ans;


 // 	for(auto i:v[node]){
 // 		if(!vis[i]){
 // 			ans.pb(i);

 // 		}
 // 	}
 // 	sort(ans.begin(),ans.end());

 // 	for(auto i:ans){
 // 		if(!vis[i])
 // 			dfs(i);
 // 	}




 // }
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
bool sortbyme(const pair<int,int> &a, 
              const pair<int,int> &b){
	return (a.first+a.second > b.first+b.second);

}
ll dp[1000000];
ll tot=INT_MAX;


ll dmch(vector<ll> a,ll ind,ll x,ll n){



	if(ind>=n-1)return 0;
	else if(dp[ind]!=-1){
		return dp[ind];

	}
	else{
		ll ans=INT_MAX;
		for(ll i=1;i<=2;i++)
			if(i+ind<n)
			{
				ans=min(abs(a[ind]-a[ind+i])+dmch(a,ind+i,x,n),ans);

			}
			else
				break;

		// ans=min(a[ind]+dmch(a,ind+1LL,x,n),min(a[ind]+dmch(a,ind+2ll,x,n)+x,a[ind]+x*2+dmch(a,ind+3ll,x,n)));
		dp[ind]=ans;
		return dp[ind];

	}
}
void solve(){
	int n;
	cin >> n;
	int arr[n];
	for(int& i : arr) cin >> i;
	int DP[n];
	DP[n-1] = 0;
	for(int i = n-2; i >=0; --i){
		DP[i] = DP[i+1] + abs(arr[i] - arr[i+1]);
		if(i+2 < n) DP[i] = min(DP[i], DP[i+2] + abs(arr[i] - arr[i+2]));
	}
	cout << DP[0] << endl;





return;
}



int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    

    ll t;
    t=1;
    //cin>>t;
    while(t--){
    	solve();
    }
    
   
  



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int a[100100]; 
int main() {
	int n, k;
	cin >> n >> k;
	rep(i,n) cin >> a[i];
	
	sort(a,a+n);

	bool can = true;
	if (a[n-1] < k) can = false;
	int g = a[0];
	rep(i,n) g = __gcd(g,a[i]);
	if (k % g != 0) can = false;

	if (can) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <algorithm>

using namespace std;

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

    int t1, t2;
    cin >> t1;

    int total = 0;
    for (int i = 1; i < N; i++) {
        cin >> t2;
        total += min(T, t2-t1);
        t1 = t2;
    }
    total += T;

    cout << total << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong p) {
	int i=0;
	for(int j = 0; j < k; j++ ) {
		llong sum = 0;
		while( sum + T[i] <= p) {
			sum += T[i];
			i++;
			if(i == n ) return n;
		}
	}
	return i;
}

int solve() {
	llong left = 0;
	llong right = 100000 * 10000;
	llong mid;
	while(left < right) {
		mid = (left + right) / 2;
		int v = check(mid);
		if(v == n) right = mid;
		else left = mid + 1;
	}
	return right;
}

main() {
	cin >> n >> k;
	for( int i = 0; i < n; i++) cin >> T[i];
	llong ans = solve();
	cout << ans << endl;
}

Measured memory_bytes: 3864
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from fractions import gcd
def resolve():
    N,=pin()
    A=lispin()
    temp=A[0]
    for i in range(1,N):
        temp=gcd(temp,A[i])
    for j in range(10**7):
        if temp%2:print(j);break
        temp//=2
        
#%%submit!    
resolve()

Measured memory_bytes: 63852
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace ABC126
{
    class E
    {
        static void Main()
        {

            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int N = input[0];
            int M = input[1];

            List<int>[] list = new List<int>[N];

            for (int i = 0; i < N; i++)
            {
                list[i] = new List<int>();
            }

            int x = 0;
            int y = 0;
            for (int i = 0; i < M; i++)
            {
                input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                x = input[0] - 1;
                y = input[1] - 1;
                list[x].Add(y);
                list[y].Add(x);
            }

            int count = 0;
            bool[] Used = new bool[N];

            Queue<int> q = new Queue<int>();
            for (int i = 0; i < N; i++)
            {
                if (Used[i]) continue;
                count++;
                Used[i] = true;
                q.Enqueue(i);

                while (q.Any())
                {
                    foreach (var item in list[q.Dequeue()])
                    {
                        if (Used[item]) continue;
                        Used[item] = true;
                        q.Enqueue(item);
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 26568
#include<bits/stdc++.h>
#define MAX_V 100000
#define INF 1<<29
using namespace std;
struct edge{int to,cap,rev;};
vector<edge>G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}
void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int>q;
  level[s]=0;
  q.push(s);
  while(!q.empty()){
    int v=q.front();q.pop();
    for(int i=0;i<(int)(G[v].size());i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[e.to]<0){
        level[e.to]=level[v]+1;
        q.push(e.to);
      }
    }
  }
}
int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<(int)(G[v].size());i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s,int t){
  int flow=0;
  while(1){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}
int main(){
  int x,y,n,s,t;
  vector<pair<int,int>> A,B;
  cin>>n;
  x=n;
  y=n;
  for(int i=0;i<n;i++){
  	cin>>s>>t;
  	A.push_back({s,t});
  }
  for(int i=0;i<n;i++){
  	cin>>s>>t;
  	B.push_back({s,t});
  }
  for(int i=0;i<n;i++){
  	for(int j=0;j<n;j++){
  		if(A[i].first<B[j].first&&A[i].second<B[j].second){
  			add_edge(i+1,n+j+1,1);
  		}
  	}
  }
  for(int i=0;i<y;i++){
  	add_edge(x+i+1,x+y+1,1);
  }
  for(int i=0;i<x;i++){
  	add_edge(0,i+1,1);
  }
  cout<<max_flow(0,x+y+1)<<endl;
}


Measured memory_bytes: 3456
// B - Minesweeper

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

char field[52][52];

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

	for (int i=0; i<H+2; i++) {
		for (int j=0; j<W+2; j++) {
			field[i][j] = '@';
		}
	}

	for (int i=1; i<=H; i++) {
		for (int j=1; j<=W; j++) {
			cin >> field[i][j];
		}
	}

	for (int i=1; i<=H; i++) {
		for (int j=1; j<=W; j++) {
			if (field[i][j] == '#') continue;

			int n = 0;
			if (field[i-1][j-1] == '#') n++;
			if (field[i-1][j] == '#') n++;
			if (field[i-1][j+1] == '#') n++;
			if (field[i][j-1] == '#') n++;
			if (field[i][j+1] == '#') n++;
			if (field[i+1][j-1] == '#') n++;
			if (field[i+1][j] == '#') n++;
			if (field[i+1][j+1] == '#') n++;
			field[i][j] = '0' + n;
		}
	}

	for (int i=1; i<=H; i++) {
		for (int j=1; j<=W; j++) {
			cout << field[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] dn = scanner.nextLine().split(" ", 2);
        int d = Integer.parseInt(dn[0]);
        int n = Integer.parseInt(dn[1]);

        int result = 1;
        for (int i = 0; i < d; i++) {
            result *= 100;
        }
        if (n == 100) {
            n++;
        }
        result *= n;
        System.out.println(result);
    }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
  cin>>a>>b>>c;
  if(a== b && b == c && a % 2 != 1 ) cout <<"-1"<<endl;
  else{int count=0;
      

while(a % 2 ==0 && b % 2 ==0 && c % 2 ==0){
   int d=b/2+c/2,e=c/2+a/2,f=a/2+b/2;
 a=d;
  b=e;
  c=f;
  
  count++;

 	 }
cout << count <<endl;
	}
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <deque>
using namespace std;
using T = tuple<int,int,int>;

bool ob[140][140];//x,y
bool visited[140][140];

int main(){
    int t,n;
    while(cin>>t>>n,t){
        fill(ob[0],ob[140],false);
        for(int i=0;i<n;i++){
            int x,y;
            cin>>x>>y;
            ob[x+70][y+70]=true;
        }
        int sx,sy;
        cin>>sx>>sy;
        sx+=70; sy+=70;
        fill(visited[0],visited[140],false);
        deque<T> Q;
        Q.emplace_back(sx,sy,0);
        while(!Q.empty()){
            int x,y,turn;
            tie(x,y,turn) = Q.front(); Q.pop_front();
            if(visited[x][y]||turn>t) continue;
            visited[x][y]=true;
            int nx,ny;
            if(++turn<=t){
                nx=x+1; ny=y;
                if(!visited[nx][ny]&&!ob[nx][ny]) Q.emplace_back(nx,ny,turn);
                nx=x+1; ny=y+1;
                if(!visited[nx][ny]&&!ob[nx][ny]) Q.emplace_back(nx,ny,turn);
                nx=x; ny=y+1;
                if(!visited[nx][ny]&&!ob[nx][ny]) Q.emplace_back(nx,ny,turn);
                nx=x-1; ny=y;
                if(!visited[nx][ny]&&!ob[nx][ny]) Q.emplace_back(nx,ny,turn);
                nx=x-1; ny=y-1;
                if(!visited[nx][ny]&&!ob[nx][ny]) Q.emplace_back(nx,ny,turn);
                nx=x; ny=y-1;
                if(!visited[nx][ny]&&!ob[nx][ny]) Q.emplace_back(nx,ny,turn);
            }
        }
        int ans = 0;
        for(int i=0;i<140;i++){
            for(int j=0;j<140;j++) ans+=visited[i][j];
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3204
n=int(input())
ns=list(map(int,input().split()))
ans=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if(ns[j]<ns[minj]):
            minj=j
    if i!=minj:
        ans+=1
        k=ns[i]
        ns[i]=ns[minj]
        ns[minj]=k

for i in range(n):
    if(i!=n-1):
        print(ns[i],end=' ')
print(ns[n-1])
print(ans)

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

int main() {
  int N, i, X;
  cin >> N;
  vector<int> vec(N);
  for ( i = 0; i < N; i++) {
  cin >> vec.at(i);  
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  X = 0;
  for ( i = 0; i < N; i++) {
    if(i == 0) X++;
    else if ( vec.at(i) < vec.at(i-1)) X++;
    else continue;
  }
  cout << X << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 1000

main(){
  int n;
  int T[MAX+1];
  while( cin >> n && n ){
    T[0] = 0;
    for ( int i = 1; i <= n; i++ ) T[i] = T[i-1] + i;
    int sum = 0;
    for ( int i = 0; i <=n-2; i++ ){
      for ( int j = i+2; j <= n; j++ ){
	if ( T[j]-T[i] == n ) {
	  sum++;
	}
      }
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 0
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <list>
#include <set>
#include <string>
#include <queue>
using namespace std;
typedef long long int ll;

struct edge {
	ll from, to, cost;
};

#define INF 1LL << 50
int main() {
	int N, M;
	cin >> N >> M;
	vector<ll> d(N, INF);
	vector<bool> loop(N, false);
	vector<edge> es(M);
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		es[i] = { a,b,-c };
	}
	d[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			edge e = es[j];
			if (d[e.from] == INF)continue;
			if (d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
			}
		}
	}
	for (int i = 0; i < N; i++)for (int j = 0; j < M; j++) {
		edge e = es[j];
		if (d[e.from] == INF) continue;
		if (d[e.to] > d[e.from] + e.cost) {
			d[e.to] = d[e.from] + e.cost;
			loop[e.to] = true;
		}
		if (loop[e.from])loop[e.to] = true;
	}

	if (!loop[N-1])cout << -d[N - 1] << endl;
	else cout << "inf" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef jayinnn
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 100005;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();
    ll sum = 0;
    int n;
    cin >> n;
    vector<ll> a(n);
    
    debug(sum);
    REP(i, n){
        cin >> a[i];
        sum += a[i];
        sum %= MOD;
    }
    ll ans = 0;
    REP(i, n){
        sum -= a[i];
        while(sum <= 0) sum += MOD;
        sum %= MOD;
        ans += sum * a[i];
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4780
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Control.Monad
import Control.Monad.ST
import qualified Data.IntSet as I

solve0 n m s abs = if solve n m s abs then "Yes" else "No"

solve :: Int -> Int -> String -> [[Int]] -> Bool
solve n m s abs = runST $ do
  label <- VUM.new (n+1)
  forM (zip [1..] s) $ \(i,c) -> do
    VUM.write label i c

  nbrA <- VM.replicate (n+1) I.empty
  nbrB <- VM.replicate (n+1) I.empty
  forM abs $ \[x,y] -> do
    labX <- VUM.read label x
    labY <- VUM.read label y
    if labX == 'A' then VM.modify nbrA (I.insert x) y
                   else VM.modify nbrB (I.insert x) y
    if labY == 'A' then VM.modify nbrA (I.insert y) x
                   else VM.modify nbrB (I.insert y) x
  repRemove nbrA nbrB label
  remained <- forM [1..n] $ \i -> do
    i_nbrA <- VM.read nbrA i
    return (not (I.null i_nbrA))
  return (or remained)

  where
    repRemove nbrA nbrB label = do
      lst_chgd <- forM [1..n] $ \i -> do
        i_nbrA <- VM.read nbrA i
        i_nbrB <- VM.read nbrB i
        if ((I.null i_nbrA) `xor` (I.null i_nbrB)) then do
          remove i i_nbrA i_nbrB
          return True
          else return False
      if or lst_chgd then repRemove nbrA nbrB label
        else return ()

      where
        remove i i_nbrA i_nbrB = do
          VM.write nbrA i I.empty
          VM.write nbrB i I.empty
          let i_nbr = if I.null i_nbrA then i_nbrB else i_nbrA
          lab <- VUM.read label i
          let nbr = if lab == 'A' then nbrA else nbrB
          forM_ (I.toList i_nbr) $ \j -> do
            VM.modify nbr (I.delete i) j
            j_nbrA <- VM.read nbrA j
            j_nbrB <- VM.read nbrB j
            if ((I.null j_nbrA) `xor` (I.null j_nbrB)) then do
              remove j j_nbrA j_nbrB
              else return ()

xor b1 b2 = (b1 && not b2) || ((not b1) && b2)

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

tmain :: B.ByteString -> String
tmain cont =
  let line1 : line2 : lines = B.lines cont
      [n,m] = bsReadInts line1
      [s] = B.words line2
      abs = map bsReadInts lines
  in solve0 n m (B.unpack s) abs

main = putStrLn . tmain =<< B.getContents


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

using ll = long long;
using namespace std;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19
constexpr static double EPS = 1e-10;

int main() {
    int n, d;
    cin >> n >> d;
    int ans = ceil((double)n / (2 * d + 1));
    cout << ans << endl;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    vector<ll> primes;
    for(ll i = 2; i <= 10000; i++) {
        bool checker = true;
        for(ll j = 2; j * j <= i; j++) {
            if(i % j == 0) {
                checker = false;
                break;
            }
        }
        if(checker) primes.push_back(i);
    }
    vector<ll> triple;
    for(int i = 0; i < primes.size(); i++) {
        ll val = primes[i];
        triple.push_back(val*val*val);
    }
    //cout << primes.size() << endl;
    ll N;
    cin >> N;
    vector<ll> s(N);
    map<vector<l_l>, ll> mp;
    map<int, vector<l_l> > mp2;
    for(int i = 0; i < N; i++) {
        cin >> s[i];
        ll copy = s[i];
        vector<l_l> to_map;
        for(int j = 0; j < primes.size(); j++) {
            while(s[i] % triple[j] == 0) {
                s[i] /= triple[j];
                copy /= triple[j];
            }
            ll now = 0;
            if(s[i] % primes[j] == 0) {
                copy /= primes[j];
                now = 1;
            }
            if(s[i] % (primes[j] * primes[j]) == 0) {
                copy /= primes[j];
                now = 2;
            }
            if(now > 0) {
                to_map.push_back({j, now});
            }
        }
        if(copy > 1) {
            ll ok = 1000;
            ll ng = 10000000000;
            while(ng - ok > 1) {
                ll mid = (ok + ng) / 2;
                if(mid * mid <= copy) {
                    ok = mid;
                } else ng = mid;
            }
            if(copy % (ok * ok) == 0) {
                to_map.push_back({ok, 2});
            } else to_map.push_back({copy, 1});
        }
        mp[to_map]++;
        mp2[i] = to_map;
    }
    ll ans = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 1) {
            vector<l_l> emp;
            if(mp[emp] > 0) {
                ans++;
            }
            mp[emp] = 0;
            continue;
        }
        vector<l_l> now = mp2[i];
        vector<l_l> rev;
        for(int j = 0; j < now.size(); j++) {
            l_l NEW = now[j];
            NEW.second = 3 - NEW.second;
            rev.push_back(NEW);
        }
        /*
        for(int j = 0; j < primes.size(); j++) {
            ll val = 0;
            if(s[i] % primes[j] == 0) {
                val = 1;
            }
            if(s[i] % (primes[j] * primes[j]) == 0) {
                val = 2;
            }
            if(val > 0) {
                now.push_back({j, val});
                rev.push_back({j, 3 - val});
            }
        }
        */
        ans += max(mp[now], mp[rev]);
        //cout << i << " " << s[i] << " " << ans << endl;
        mp[now] = 0;
        mp[rev] = 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 44544
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

ll dfs(map<ll, ll>& memo, const ll& n, const ll& a, const ll& b, const ll& c, const ll& d) {
  if (n == 0) return 0;
  if (memo[n] != 0) return memo[n];

  ll ans = INFLL;
  if (n < ans / d) ans = n * d;  // n * d が桁あふれする場合があるのでガードしておく

  {
    ll mod = n % 2;
    chmin(ans, dfs(memo, (n+mod)/2, a, b, c, d) + a + mod * d);
    chmin(ans, dfs(memo, (n-mod)/2, a, b, c, d) + a + (2-mod) * d);
  }
  {
    ll mod = n % 3;
    chmin(ans, dfs(memo, (n-mod)/3, a, b, c, d) + b + mod * d);
    chmin(ans, dfs(memo, (n+3-mod)/3, a, b, c, d) + b + (3-mod) * d);
  }
  {
    ll mod = n % 5;
    chmin(ans, dfs(memo, (n-mod)/5, a, b, c, d) + c + mod * d);
    chmin(ans, dfs(memo, (n+5-mod)/5, a, b, c, d) + c + (5-mod) * d);
  }

  memo[n] = ans;
  return ans;
}


void solve() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  map<ll, ll> memo;
  memo[1] = d;

  ll ans = dfs(memo, n, a, b, c, d);
  cout << ans << endl;
}

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

  int t;
  cin >> t;
  rep(i, t) solve();

  return 0;
}


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

int main () {
  int N; cin >> N;
  vector<vector<int>> F(N, vector<int>(10));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) cin >> F.at(i).at(j);
  }
  vector<vector<int>> P(N, vector<int>(11));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) cin >> P.at(i).at(j);
  }
  int ans = -1000000000;
  for (int tmp = 1; tmp < (1 << 10); tmp++) {
    bitset<10> s(tmp);
    int sum = 0;
    vector<int> cnt(N, 0);
    for (int i = 0; i < 10; i++) {
      if (s.test(i)) {
        for (int j = 0; j < N; j++) {
          if (F.at(j).at(i)) cnt.at(j)++;
        }
      }
    }
    for (int i = 0; i < N; i++) sum += P.at(i).at(cnt.at(i));
    ans = max(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//author: Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  string s;
  cin>>s;
  cout<<s.substr(0,3);
  return 0;
}


Measured memory_bytes: 3560
#include <iostream>
#define N_MAX 100000
using namespace std;

int dp[N_MAX];
int h[N_MAX]={0};

int main(){
  int N,K,i,k;
  cin>>N>>K;
  for(i=0;i<N;i++){
    cin>>h[i];
    dp[i]=-1;
  }
  dp[0]=0;
  for(i=0;i<N;i++){
    for(k=1;(k<=K)&&(i+k<N);k++){
      if(dp[i+k]==-1){
        dp[i+k]=dp[i]+abs(h[i+k]-h[i]);
      }else{
        dp[i+k]=min(dp[i+k],dp[i]+abs(h[i+k]-h[i]));
      }
    }
  }
  cout<<dp[N-1]<<endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

int main() {
  ll N, K; cin >> N >> K;
  vector<ll> A(N);
  REP(i, N) {
    cin >> A[i];
    A[i]--;
  }
  vector<ll> memo(N, -1); ll ans = 0; ll tmp = 0;
  for(ll i = 0; i < K; ++i) {
    if(memo[A[tmp]] != -1) {
      const ll t = i - memo[A[tmp]]; // ループ1周分の長さ
      const ll c = (K - i - 1) / t; // ループはあと何周するか？
      i += t * c;
    } else {
      memo[A[tmp]] = i;
    }
    tmp = A[tmp];
  }
  cout << tmp + 1 << endl;
}

Measured memory_bytes: 6420
#include <stdio.h>
#include <string.h>
#define SIZE 10028
int main() {

	int i,n,out,hit,ans;
	char str[SIZE],*line;

	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d",&n);
	for(i=0;i<n;i++){
	out=0; hit=0; ans=0;
	while(out!=3){
		fgets(str,sizeof(str),stdin);
		if(strstr(str,"OUT")!=NULL)
			out++;
		if(strstr(str,"HIT")!=NULL)
			hit++;
		if(hit>3){
			ans++;
			hit=3;
		}
		if(strstr(str,"HOMERUN")!=NULL){
			ans+=hit+1;
			hit=0;
		}
	}
	printf("%d\n",ans);
	}
	return 0;			
}

Measured memory_bytes: 616
const stdin = require("fs").readFileSync("/dev/stdin", "utf8");
const [sx, sy, tx, ty] = stdin.split(" ").map(Number);
const diff = (x1, x2) => x2 - x1;
const dx = diff(sx, tx);
const dy = diff(sy, ty);
let result = "U".repeat(dy) + "R".repeat(dx);
result += "D".repeat(dy) + "L".repeat(dx);
result += "L".repeat(1) + "U".repeat(dy + 1) + "R".repeat(dx + 1) + "D".repeat(1);
result += "R".repeat(1) + "D".repeat(dy + 1) + "L".repeat(dx + 1) + "U".repeat(1);
console.log(result);


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

int a,b,c,x;
int ans;

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

	cin>>a>>b>>c>>x;
	REP(i,a+1) REP(j,b+1) REP(k,c+1) if(i*500+j*100+k*50==x) ans++;
	cout<<ans<<endl;

	return 0;
}


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

const int length = 1005;
int dp[length][length];

void LCS(std::string X, std::string Y)
{
  auto m = X.length();
  auto n = Y.length();


  for (int i=0; i<m; ++i)
    dp[i][0] = 0;
  for (int j=1; j<n; ++j)
    dp[0][j] = 0;

  for (int i=1; i<=m; ++i)
    {
      for (int j=1; j<=n; ++j)
        {
          if (X[i-1] == Y[j-1])
            dp[i][j] = dp[i-1][j-1] + 1;
          else
            {
              dp[i][j] = std::max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
}

int main ()
{
  int q;
  std::cin >> q;

  std::string X, Y;
  for (int i=0; i<q; ++i)
    {
      std::cin >> X >> Y;
      LCS(X, Y);
      std::cout << dp[X.length()][Y.length()] << std::endl;
    }
}



Measured memory_bytes: 7104
#include <iostream>
#include <queue>
#include <vector>
#include <set>

using namespace std;

int N;

pair <int, int> X[100005];

multiset <long long> Left;
multiset <long long > Right;

long long A, B;

long long leftSum, rightSum;

void Read(){
    cin >> N;
    for(int i = 1; i <= N; i++)
        cin >> X[i].first >> X[i].second;
}

void init(){
    Left.insert(X[1].second);
    Right.insert(X[1].second);
    A = 1;
    B = -X[1].second;
}
set <long long> :: iterator prev(set <long long> :: iterator it){
    --it;
    return it;
}
void addRectangle(int len, int lastLen, int pos){
    leftSum -= lastLen;
    rightSum += len;
    set <long long> :: iterator it = Left.end();
    --it;
    if(pos - leftSum <= *(it)){
        Left.insert(pos - leftSum);
        Left.insert(pos - leftSum);
        long long top = *prev(Left.end());
        Left.erase(prev(Left.end()));
        Right.insert(top + leftSum - rightSum);

    }
    else{
        Right.insert(pos - rightSum);
        Right.insert(pos - rightSum);
        long long top = *Right.begin();
        Right.erase(Right.begin());
        Left.insert(top + rightSum - leftSum);
    }
    ++A;
    B -= pos + len * (A - 1);
}

void findAns(){
    while(A > 0){
        B += *prev(Right.end()) + rightSum;
        Right.erase(prev(Right.end()));
        --A;
    }
    cout << B << '\n';
}

void Solve(){
    for(int i = 2; i <= N; i++){
        addRectangle(X[i].second - X[i].first, X[i - 1].second - X[i - 1].first, X[i].second);
    }
}
int main()
{
    Read();
    init();
    Solve();
    findAns();
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> l(n);
	rep(i,n) cin >> l[i];
	sort(l.rbegin(), l.rend());
	int tmp=0;
	rep(i,n){
		if(i==0){
			tmp += l[i];
		}else{
			tmp -= l[i];
		}
	}
	if(tmp<0){
		cout << "Yes" << endl;
	}else cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    string s; cin >> s;
    int cnt = 0, ans = 0;
    rep(i,0,s.length()) {
        if(cnt == 0) {
            // g
            if(s[i] == 'p') ans--, cnt++;
            else cnt++;
        }
        else {
            // p
            if(s[i] == 'p') cnt--;
            if(s[i] == 'g') cnt--, ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(scanf("%d",&n)!= EOF){
    int ans  = 0;
    for(int i = 0;i<=9;i++){
      for(int j= 0;j<=9;j++){
	for(int k = 0;k<=9;k++){
	  for(int l = 0;l<=9;l++){
	    if(i+j+k+l == n)ans++;
	  }
	}
      }
    }
    cout << ans << endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long MOD = 998244353;

bool checkPalindrome(string s, int n) {
    int i = 0, j = n - 1;
    while (i < j) {
        if (s[i] != s[j]) return false;
        i++, j--;
    }
    return true;
}

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

    double l;
    cin >> l;
    cout << fixed << setprecision(10) << l * l * l / 27;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
remain = [0 for i in range(max(a) + 1)]
for ai in a:
    remain[ai] += 1
res = 0
max_a = max(a)
for i in range(1, max_a + 1):
    if remain[i] == 1:
        res += 1
    if remain[i]:
        for j in range(i * 2, max_a + 1, i):
            remain[j] = 0
print(res)


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

int main(){
	int N, K;
	char S[100002];

	cin >> N >> K;
	cin >> S;

	int change_num = 0;
	char c = S[0];
	for(int i = 1; i < N; i++){
		if( S[ i-1 ] != S[i] ) change_num++;
	}
	
	for( int i = 0; i < K; i++ ){
		if( change_num <= 1 ){
			change_num = 0; 
			break;
		}
		else {
			change_num -=2;
		}
	}
	
	cout << N - change_num - 1 << endl;

}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s[i] == s[i + 1]) {
			cout << "Bad";
			break;
		}
		if (i == 2) {
			cout << "Good";
		
		}
	}
}

Measured memory_bytes: 256
#!/usr/bin/env python3
N = int(input())

print(0, flush=True)
w0 = input()
if w0 == 'Vacant':
    exit()

l, r = 0, N
while True:
    m = (l + r) // 2
    print(m, flush=True)
    w1 = input()
    if w1 == 'Vacant':
        break
    if m % 2 == (w0 != w1):
        l = m
    else:
        r = m


Measured memory_bytes: 3660
#include <iostream>
    #include <utility>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <set>
    #include <cmath>
             
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
       
    #define PI 3.14159265358979323846
             
    const double EPS = 1e-8;
            
    int main()
    {
		ll a,b,h[3]={};
 
		cin >> a >> b;
 
		if((a==1||a==3||a==5||a==7||a==8||a==10||a==12)){
			h[0]++;
		}else if((a==4||a==6||a==9||a==11)){
			h[1]++;
		}else{
			h[2]++;
		}
		
		if((b==1||b==3||b==5||b==7||b==8||b==10||b==12)){
			h[0]++;
		}else if((b==4||b==6||b==9||b==11)){
			h[1]++;
		}else{
			h[2]++;
		}
 
		if(h[0]!=2&&h[1]!=2&&h[2]!=2){
		cout << "No" << endl;
		}else{
		cout << "Yes" <<endl;
		}
 
		return 0;
    }

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

int main() {
    int n;
    int a[210];
    int x = 0;

    std::cin >> n;
    for(int i=0;i<n;i++){
        std::cin >> a[i];
    } 
    
    bool odd_exist=false;
    while(1){
        for(int i=0;i<n;i++){
            if(a[i] % 2 !=0)    odd_exist=true;
        }
        if(odd_exist)   break;
        for(int i=0;i<n;i++){
            a[i] /= 2;
        }
        x++;
    }

    std::cout << x << std::endl;


}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    int k, m = 0;
    x = 0;
    while (true)
    {
        k = getchar();
        if (k == '-')
        {
            m = 1; break;
        }
        if ('0' <= k && k <= '9')
        {
            x = k - '0';
            break;
        }
    }
    while (true)
    {
        k = getchar();
        if (k < '0' || k > '9') break;
        x = x * 10 + k - '0';
    }
    if (m) x = -x;
}

int main()
{
    int N, K;

    gc(N);
    gc(K);

    long long int a;

    vector<long long int> vSM(100001);
    vector<long long int> vZR(100001);

    for (int i = 0; i < N; i++)
    {
        gc(a);
        vSM[i + 1] = vSM[i] + a;
        vZR[i + 1] = vZR[i] + max(a, 0LL);
    }

    long long int score = 0LL;
    for (int i = 0; i < N - K + 1; i++)
    {
        int l = i;
        int r = i + K;

        // 最後に塗るところ以外
        long long int pre = vZR[l] + (vZR[N] - vZR[r]);

        // 最後に白く塗る(0LL)、黒く塗る(vSM[r] - vSM[l])
        score = max(score, pre + max(vSM[r] - vSM[l], 0LL));
    }

    printf("%lld\n", score);
    return 0;
}


Measured memory_bytes: 1792
from itertools import product

def read():
    N = int(input())
    return N,

def solve(N):
    count = 0
    for i in range(3, 10):
        for x in product('357',repeat=i):
            if all(x.count(d) for d in '357'):
                if int(''.join(x), 10) <= N:
                    count += 1
    return count

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll n, m ;
    cin >> n >> m;

    if (n >= m / 2) {
        put(m / 2);
        return;
    }

    ll sum = n;
    ll rem = m - 2 * n;
    sum += rem / 4;

    put(sum);
    
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3676