akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N=sc.nextInt();
        int[] A=new int[N+1];
        ArrayList<Integer>B=new ArrayList<>(N);
        for(int i=0;i<N+1;i++){
            A[i]=sc.nextInt();
        }
        for(int i=0;i<N;i++){
            B.add(sc.nextInt());
        }
        int kurikosi=0;
        long result=0;
        for(int i=0;i<N;i++){
                result+=Math.min(A[i],kurikosi+B.get(i));
                kurikosi=Math.max(0,Math.min(kurikosi+B.get(i)-A[i],B.get(i)));
        }
        result+=Math.min(kurikosi,A[N]);
        System.out.println(result);







    }
    static int gcd (int a, int b) {
        int temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
}


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

priority_queue<int> q1,q3;
priority_queue<int,vector<int>,greater<int> >q2,q4;
int n;
int a[100010];

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int now;
        scanf("%d",&now);
        q1.push(now);
        q3.push(now);
        q2.push(now);
        q4.push(now);
    }
    long long res = 0;
    if(n>=3){
        for(int i=0;i<n-2;i++){
            if(i%2){
                a[i] = q1.top();
                q1.pop();
            }
            else {
                a[i] = q2.top();
                q2.pop();
            }
            if(i)res+=abs(a[i]-a[i-1]);
        }
        res+=abs(q1.top()-a[0]);
        q1.pop();
        res+=max(abs(q1.top()-a[n-3]),abs(q2.top()-a[n-3]));
        long long ans = 0;
        for(int i=0;i<n-2;i++){
            if(i%2==0){
                a[i] = q3.top();
                q3.pop();
            }
            else{
                a[i] = q4.top();
                q4.pop();
            }
            if(i)ans+=abs(a[i]-a[i-1]);
        }
        ans+=abs(q4.top()-a[0]);
        q4.pop();
        ans+=max(abs(q4.top()-a[n-3]),abs(q3.top()-a[n-3]));
        res = max(res,ans);
    }
    else{
        res = abs(q1.top()-q2.top());
    }
        printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 2276
using System;

namespace teeeeeeeeeeeeeeest
{
    class Program
    {
        static void Main(string[] args)
        {
            string n,m;
            string[] M;
            double N,a=0;
            n = Console.ReadLine();
            m = Console.ReadLine();
            N = int.Parse(n);
            M = m.Split();
            for (int i = 0; i < N - 1; i++)
            {
                if (int.Parse(M[i])<int.Parse(M[i+1]))
                {
                    a++;
                }
            }
            Console.WriteLine(a);
            Console.ReadLine();
        }
    }
}



Measured memory_bytes: 24592
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <set>

using namespace std;

using PII = pair<int, int>;

vector<int> x, y;

int calc(PII pq, vector<PII> fromtos, int n) {
	long long p = pq.first;
	long long q = pq.second;

	// printf("calc pq %lld %lld\n", p, q);

	set<int> tos;
	set<int> points;
	for (auto fromto: fromtos) {
		// printf("\t (%d, %d)\n", fromto.first, fromto.second);
		tos.insert(fromto.second);
		points.insert(fromto.first);
		points.insert(fromto.second);
	}

	// printf("\tpoints: ");
	// for (auto x: points) {
	// 	printf("%d ", x);
	// }
	// printf("\n");
	// printf("\ttos: ");
	// for (auto x: tos) {
	// 	printf("%d ", x);
	// }
	// printf("\n");

	int ret = n;
	for (int x: points) {
		if (tos.count(x) > 0) {
			ret--;
		}
	}

	return ret;
}

int main() {
	int n = 0;
	cin >> n;

	x.assign(n, 0);
	y.assign(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}

	map<PII, vector<PII>> pqs;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int p = x[j] - x[i];
			int q = y[j] - y[i];

			if (p > 0 || (p == 0 && q > 0)) {
				pqs[make_pair(p, q)].emplace_back(make_pair(i, j));
			}
		}
	}

	int ans = n;
	for (auto pq: pqs) {
		int tmp = calc(pq.first, pq.second, n);
		ans = min(tmp, ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int n, q;
	int S[10000], T[500];

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &S[i]);
	}
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		scanf("%d", &T[i]);
	}

	int c = 0;
	for (int i = 0; i < q; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (T[i] == S[j])
			{
				c++;
				break;
			}
		}
	}

	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 3216
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    a, b, c, d = LI()
    print(max([a * d, a * c, b * c, b * d]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 72500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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(){
    string s, a = "RSR";
    cin >> s;
    int ans = 0;
    if(!s.compare(a)) {
        cout << 1 << endl;
        return 0;
    }
    rep(i, s.size()){
        if(s.at(i) == 'R') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

vector<int> ra(MX,0);
vector<int> par(MX,0);

signed main(){
    int n, a, b ;
    cin >> n >> a >> b;

    int ans = min(n%(a+b),a);
    ans += n/(a+b)*a;
    cout << ans << endl;
    
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define N 100005
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
vector<vector<int>> dist;
vector<vector<char>> maze;
int h,w;
bool check(int mid){

  return false;
}

ll serch(ll ok,ll ng) {
	while (abs(ok-ng) > 1) {
		ll mid = (ok + ng) / 2;
		if (check(mid))ok = mid;
		else ng = mid;
	}
	return ok;
}

int bfs(int x ,int y){
  vector<vector<bool>> visited(h,vector<bool>(w,false));
  visited[x][y]=true;
  rep(i,h){
    rep(j,w){
      dist[i][j]=0;
    }
  }
  queue<P> q;
  q.push(make_pair(x,y));
  while(!q.empty()){
    P nq=q.front();q.pop();
    visited[nq.first][nq.second]=true;
    rep(i,4){
      int nx=nq.first+di[i];
      int ny=nq.second+dj[i];
      if(0<=nx&&nx<h&&0<=ny&&ny<w&&maze[nx][ny]=='.'&&!visited[nx][ny]){
        q.push(make_pair(nx,ny));
        visited[nx][ny]=true;
        dist[nx][ny]=dist[nq.first][nq.second]+1;
      }
    }
  }
  int m=0;
  rep(i,h){
    rep(j,w){
      m=max(m,dist[i][j]);
    }
  }
  return m;
}


int main(){
  cin>>h>>w;
  dist.resize(h);
  maze.resize(h);
  rep(i,h){
    dist[i].resize(w);
    maze[i].resize(w);
    rep(j,w){
      cin>>maze[i][j];
    }
  }
  int ans=0;
  rep(i,h){
    rep(j,w){
      if(maze[i][j]=='.'){
        ans=max(ans,bfs(i,j));
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int n=1,x=3,count=0;
    int i,j,k;
    while(1){
        scanf("%d %d",&n,&x);
        if(n==0 && x==0){
            break;
        }
        for(i=1;i<=n;i++){
            for(j=i+1;j<=n;j++){
                for(k=j+1;k<=n;k++){
                    if(i+j+k==x){
                        count++;
                    }
                }
            }
        }
        printf("%d\n",count);
        count=0;
    }
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(ll i = 1; i <= (ll)c; i++)
#define ll long long
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;
const int inf = 1000000000; // 10^9

int main(){
    double r, pi;
    cin >> r;

    pi = 3.1415926535;
    cout << r * 2 * pi << endl;

    return 0;
}


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

int t;
vector<vector<int>> humans;
vector<vector<int>> seats;

void bfs(int _y, int _x) {
    queue<pair<int,int>> q;
    q.push({_y,_x});
    while(!q.empty()) {
        auto&& yx = q.front(); q.pop();
        int y = yx.first, x = yx.second;
        if(y > 0 && seats[y - 1][x] > seats[y][x] + humans[y - 1][x]) {
            seats[y - 1][x] = seats[y][x] + humans[y - 1][x];
            q.push({y - 1, x});
        }
        if(y < t - 1 && seats[y + 1][x] > seats[y][x] + humans[y + 1][x]) {
            seats[y + 1][x] = seats[y][x] + humans[y + 1][x];
            q.push({y + 1, x});
        }
        if(x > 0 && seats[y][x - 1] > seats[y][x] + humans[y][x - 1]) {
            seats[y][x - 1] = seats[y][x] + humans[y][x - 1];
            q.push({y, x - 1});
        }
        if(x < t - 1 && seats[y][x + 1] > seats[y][x] + humans[y][x + 1]) {
            seats[y][x + 1] = seats[y][x] + humans[y][x + 1];
            q.push({y, x + 1});
        }
    }
}

int main() {
    cin >> t;
    for(int y = 0; y < t; y++) {
        vector<int> row;
        for(int x = 0; x < t; x++) {
            row.push_back(min({x, t - x - 1, y, t - y - 1}));
        }
        seats.push_back(row);
        vector<int> humanRow(t, 1);
        humans.push_back(humanRow);
    }
    int result = 0;
    for(int i = 0; i < t * t; i++) {
        int number;
        cin >> number;
        number--;
        int x = number % t;
        int y = number / t;
        result += seats[y][x];
        seats[y][x]--;
        humans[y][x]--;
        bfs(y, x);
    }
    cout << fixed << result;
}


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

int main(){
	int n;
	cin >> n;
	multiset<int> s;
	vector<int> v(n);
	for (int i=0; i<n; ++i){
		cin >> v[i];
	}
	for (int i=0; i<n; ++i){
		if (s.empty() or v[i] <= *s.begin()){
			s.emplace(v[i]);
		}
		else if (*s.rbegin() < v[i]){
			s.erase(s.find(*s.rbegin()));
			s.emplace(v[i]);
		}
		else{
			auto it=s.lower_bound(v[i]);
			it--;
			s.erase(it);
			s.emplace(v[i]);
		}
	}
	cout << s.size();
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main() {

  string S, T;
  cin >> S;
  cin >> T;

  string U = T+S;
  // vector<string> v;
  // for(int i=0; i<U.size(); i++) {
  //   // cout << U.substr(i, 1);
  //   v.push_back(U.substr(i, 1));
  // }
  // cout << endl;

  // sort(v.begin(), v.end());

  // for(int i=0; i<v.size(); i++) {
  //   // cout << U.substr(i, 1);
  //   cout << v[i];
  // }
  cout << U << endl;

  return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 998244353
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


// dp[i][j][k]: 長さiで最後の数はj, xorがk
// 各DPテーブルの更新はO(1)?

li a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
    li k;
    cin >> k;
    --k;
    cout << a[k] << endl;


    return 0;
}

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

using ll = long long;

vector<int> fact(ll n) {
	vector<int> ans;
	
	for(ll i = 1; i*i <= n; i++) {
		if(n % i == 0) {
			ans.push_back(i);
			if(i*i != n) ans.push_back(n/i);
		}
	}
	
	return ans;
}

ll gcd(ll a, ll b) {
	if(b == 0) return a;
	else return gcd(b, a%b);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll a, b;
	cin >> a >> b;
	ll GCD = gcd(a, b);
	
	int ans = 1;
	for(ll i = 2; i*i <= GCD; i++) {
		if(GCD % i == 0) {
			ans++;
			while(GCD % i == 0) {
				GCD /= i;
			}
		}
	}
	if(GCD > 1) ans++;
	cout << ans << endl;
}


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

void solve(int N, vector<int> A)
{
    int64_t m = 1000;
    int64_t p_b, p_s;
    p_b = A.at(0);
    for (int i = 1; i < N; i++)
    {
        if (A.at(i - 1) > A.at(i))
        {
            p_s = A.at(i - 1);
            int64_t n_stock = m / p_b;
            m += n_stock * (p_s - p_b);
            p_b = A.at(i);
        }
    }
    p_s = A.at(N - 1);
    int64_t n_stock = m / p_b;
    m += n_stock * (p_s - p_b);
    cout << m << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    solve(N, move(A));
    return 0;
}


Measured memory_bytes: 3596
n = int(input())
as_ = [int(input()) - 1 for _ in range(n)]

visited = [0] * n

index = 0
num_push = 0
goal = False
while True:
    if visited[index] == 1:
        break

    visited[index] = 1
    if index == 1:
        goal = True
        break

    index = as_[index]
    num_push += 1

if goal:
    print(num_push)
else:
    print(-1)


Measured memory_bytes: 7852
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;
import std.range;
import std.math;

void main() {
    while (true) {
        int n = readln.chomp.to!int;
        if (n == 0) break;

        int[] s;
        foreach (i; 0..n) {
            s ~= readln.chomp.to!int;
        }

        writeln((s.reduce!("a + b") - s.minPos[0] - s.minPos!("a > b")[0])
                / (n - 2));
    }
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
const int INF = 0x3f3f3f3f, MAXN = 25, MAXM = 1<<21, MOD = 1e9 + 7;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
int N;
bool com[MAXN][MAXN];
ll dp[MAXN][MAXM];
ll f(int n, int mask){
	if (n==N+1&&mask==0) return 1;
	if (dp[n][mask]!=-1) return dp[n][mask];
	dp[n][mask] = 0;
	for (int i = 1; i<=N; i++){
		if (com[n][i]&&(mask&(1<<(i-1)))){
			dp[n][mask]+=f(n+1, mask - (1<<(i-1)));
			dp[n][mask]%=MOD;
		}
	}
	return dp[n][mask];
}
int main(){
	//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	scanf("%d", &N);
	for (int i = 1; i<=N; i++){
		for (int j = 1; j<=N; j++){
			scanf("%d", &com[i][j]);
		}
	}
	memset(dp, -1, sizeof dp);
	printf("%lld\n", f(1, (1<<N)-1));
}

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

int main()
{
	int q = 0;
	int	p0x = 0, p0y = 0, p1x = 0, p1y = 0, p2x = 0, p2y = 0, p3x = 0, p3y = 0;
	int n = 0;
	double u = 0, s = 0, t = 0;

	cin >> q;
	
	for (int i = 0; i < q; i++) {
		cin >> p0x >> p0y >> p1x >> p1y >> p2x >> p2y >> p3x >> p3y;
		n = 0;

		u = (p3y - p0y) * (p2x - p0x) - (p3x - p0x) * (p2y - p0y);
		
		if (u != 0) {
			s = (double)((p3y - p0y) * (p1x - p0x) - (p3x - p0x) * (p1y - p0y)) / u;
			t = - (double)((p2y - p0y) * (p1x - p0x) - (p2x - p0x) * (p1y - p0y)) / u;

			if (s >= 0 && t >= 0) {
				if (s + t >= 1)
					n = 1;
			}
		}
		else {
			if (p1x - p0x != 0) {
				if ((p0x - p2x) * (p0x - p3x) <= 0)
					n = 1;
				else if(((p2x - p0x) * (p2x - p1x) <= 0) | ((p3x - p0x) * (p3x - p1x) <= 0))
					n = 1;
			}
			else
				if ((p0y - p2y) * (p0y - p3y) <= 0)
					n = 1;			
				else if (((p2y - p0y) * (p2y - p1y) <= 0) | ((p3y - p0y) * (p3y - p1y) <= 0))
					n = 1;
		}

		cout << n << endl;
	}
		
	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n; cin>>n;
	ll ans=0;
	rep(i,0,n){
		ll a; cin>>a; --a;
		ans+=a;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
vector<ll> v;
ll truer[100000];
int main(){
	ll tmp = 0;
	ll n; cin >> n;
	for(ll i = 1; i <= n; ++i){
		tmp += i;
		truer[i] = i;
		v.push_back(tmp);
		if(tmp >= n)break;
	}
	cout << v.size() << "\n";
	n -= v.size();
	v.pop_back();
	while(1){
		if(n == 0)break;
		if(v.size() >= n){
			cout << truer[n] << "\n";
			n -= truer[n];
		}else{
			n -= truer[v.size()];
			cout << truer[v.size()] << "\n";
			v.pop_back();
		}
	}
    return 0;
}


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

class Program
{
    void Run()
    {
        var sc = new Scanner();
        string s = sc.NextString();
        var d = new Dictionary<char, int>();
        for (int i = 0; i < 4; i++)
        {
            if (!d.ContainsKey(s[i])) d.Add(s[i], 0);
            d[s[i]]++;
        }
        Console.WriteLine(d.Keys.Count == 2 && d.Values.All(p => p == 2) ? "Yes" : "No");
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }

    static long Lcm(long a, long b)
    {
        long d = Gcd(a, b);
        return a / d * b;
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13152
import itertools

n, m, q = map(int, input().split())
a_list = [list(map(int, input().split())) for _ in range(q)]

A_comb = itertools.combinations_with_replacement(range(1, m+1), n)

d_sum = 0
for comb in A_comb:
    d_sum_by_comb  = 0
    for aq in a_list:
        b = aq[1]
        a = aq[0]
        c = aq[2]
        d = aq[3]
        if comb[b-1] - comb[a-1] == c:
            d_sum_by_comb += d

    if d_sum < d_sum_by_comb:
        d_sum = d_sum_by_comb

print(d_sum)


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	string a,b;
	cin>>a>>b;
	ll cnt=0;
	if(a[0]==b[0])cnt++;
	if(a[1]==b[1])cnt++;
	if(a[2]==b[2])cnt++;
	cout<<cnt<<endl;
	return 0;
}


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

#define ll long long

void solve(){
	int a, b;
	cin>>a>>b;
	cout<<a*b<<endl;
}

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


Measured memory_bytes: 3580
a = input().split()
N, A, B = int(a[0]), int(a[1]), int(a[2])

result = 0
for n in range(N+1):
  a = 0
  for i in str(n):
    a = a + int(i)
  if A <= a & a <= B:
    result = result + n
    
print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e5+7;

LL n,m,a[maxn];
char ans[maxn];
LL f[100],sum[100];
int main(){
    f[0]=1;
    fo(i,1,100) f[i]=f[i-1]*26;
    cin>>n;
    int len = 0;
    LL nw = 0;
    while (nw < n) {
        len++;nw += f[len];
    }
    nw-=f[len];
    n-=nw;



    fo(i, 1, len) {
        LL x=n/f[len-i];
        if(n%f[len-i]==0) x--;
        n-=x*f[len-i];
        ans[i]=x+'a';
    }

    fo(i, 1, len) cout << ans[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 3636
n=int(input())
a=list(map(int,input().split()))
# + - + - 
su=0
op1=0
for i in range(n):
#    print(i,su,end=' i,su\n')
    if i%2==0:
        #su>0
        if su+a[i]<=0:
            diff=1-(su+a[i])
            op1+=diff
            su+=diff
 #           print(i,diff)
    if i%2==1:
        #su<0
        if su+a[i]>=0:
            diff=(su+a[i])+1
            op1+=diff
            su-=diff
  #          print(i,diff)
    su+=a[i]
su=0
op2=0
for i in range(n):
   # print(i,su,end=' i,su\n')
    if i%2==1:
        #su>0
        if su+a[i]<=0:
            diff=1-(su+a[i])
            op2+=diff
            su+=diff
    #        print(i,diff)
    if i%2==0:
        #su<0
        if su+a[i]>=0:
            diff=(su+a[i])+1
            op2+=diff
            su-=diff
     #       print(i,diff)
    su+=a[i]
print(min(op1,op2))


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

using namespace std;

int main()
{
	int H, N;
	cin >> H >> N;
	int s = 0;
	int v;
	for (int i = 0; i < N; ++i)
	{
		cin >> v;
		s += v;
	}
	cout << (s >= H ? "Yes" : "No");


	return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	string S=in<string>();
	int N = S.size();
	int num = 0;
	bool flag = false;
	for(int i=0;i<N;){
		if(i<N-1 && S[i]==S[i+1]){
			if(i+2<N) num+=2;
			else num++;
			i+=3;
		}
		else{
			num++;
			i++;
		}
	}
	if(N==1) num = 1;

	out(num);
	return 0;
}


Measured memory_bytes: 720
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for d in range(A +1):
    for e in range(B+ 1):
        for f in range(C+1):
            if d* 500 + e* 100 + f*50 == X:
                count = count + 1
print(int(count))

Measured memory_bytes: 3064
#include<stdio.h>

void rotation(char a[], int n){
	int backup = a[0];
	for(int i=0;i<n-1;i++){
		a[i] = a[i+1];
	}
	a[n-1] = backup;
}

int judge(char a[], char b[], int n){
	int ans = 0;
	for(int i=0;i<n;i++){
		if(a[i] == b[i]){
			ans++;
		}
	}
	return ans;
}


int main(void){
	char a[100];
	char b[100];
	scanf("%s",a);
	scanf("%s",b);
	
	int n=0;
	while(a[n] != '\0'){
			n++;
	}
	
	int judges = 0;
	for(int i=0;i<=n;i++){
		if(judge(a,b,n)==n){
			judges++;
			break;
		}
		rotation(a,n);
	}

	if(judges == 1){
		printf("Yes");
	}
	if(judges == 0){
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int root[100000];
int getRoot(int v){ return root[v] == -1 ? v : root[v] = getRoot(root[v]); }

int main(){
	int N, M;
	while(cin >> N >> M){
		vector<int> p(N);
		for(auto& t : p){ cin >> t; --t; }
		fill(root, root+N, -1);
		for(int i=0;i<M;i++){
			int x, y;
			cin >> x >> y;
			--x; --y;
			int p = getRoot(x);
			int q = getRoot(y);
			if(p != q) root[q] = p;
		}
		int res = 0;
		for(int i=0;i<N;i++){
			if(getRoot(i) == getRoot(p[i])) ++res;
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }


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

int cnt;
vector<int> G;

void insertionSort(vector<int> &A,int n, int g){
    for(int i=g;i<n;i++){
        int v = A[i];
        int j = i - g;
        while(j>=0 && A[j] > v){
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}
void shellSort(vector<int> &A, int n){
    cnt = 0;
    for(int h=1;h<=n;){
        G.push_back(h);
        h = 3*h + 1;
    }
    for(int i=G.size()-1;i>=0;i--) insertionSort(A,n,G[i]);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;cin>>N;
    vector<int> a(N);
    REP(i,N){
        cin>>a[i];
    }
    shellSort(a,N);
    cout<<G.size()<<endl;
    for(int i=G.size()-1;i>=0;i--){
        cout<<G[i];
        if(i) cout<<" ";
    }
    cout<<endl;
    cout<<cnt<<endl;
    REP(i,N){
        cout<<a[i]<<endl;
    }
}


Measured memory_bytes: 6788
from collections import defaultdict
 
n = int(input())
a = list(map(int, input().split()))
q = int(input())
 
total = sum(a)
 
numbers = defaultdict(int)
 
for item in a:
    numbers[item] += 1
 
for i in range(q):
    b, c = map(int, input().split())
    taken = numbers[b]
    total -= numbers[b]*b
    numbers[c] += numbers[b]
    numbers[b] = 0
    total += taken*c
    print(total)

Measured memory_bytes: 89664
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

int main(void){

    string S; cin>>S;

    cout<<((S=="ABC")? "ARC" : "ABC" )<<endl;

}


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


int i, T, N, K, X[100000+10], A[100000+10];
using namespace std;
int main(){
  cin >> T;
  for (int t = 0; t < T; ++t){
    for (i = 0; i < 100000+10; ++i){A[i] = 0;X[i] = 0;}
    cin >> N >> K; 
    int dist;
    for (i = 0; i < N; ++i){
      cin >> X[i];
      if(i>0){A[i-1]=X[i]-X[i-1];}
      if(i==N-1){
        dist = X[i]-X[0];
      }
    }
    if(N <= K){cout << 0 << endl;continue;}

    sort(begin(A), end(A));
    reverse(begin(A), end(A));


    for (i = 0; i+1 < K; ++i){
      dist -= A[i];
    }
    cout << dist << endl;
  }
}

Measured memory_bytes: 3880
/* 
    Author : Jeff Ahn
    Sat 13 Jun 2020 01:57:28 AM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const map<T,T> &vec){ os<< "{"; for (auto p : vec) os << "(" << p.first << "," << p.second << "), "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_map<T,T>&vec){ os<< "{"; for (auto p : vec) os << "(" << p.first << "," << p.second << "), "; os << "}"; return os; }

string n;
int k;

int dp[110][2][5];

int solve(int i, int flag, int n0) {
  if (n0 > k) return 0;
  if (i == n.size()) {
    return (n0 == k);
  }
  int& res = dp[i][flag][n0];
  if (res != -1) return res;
  res = 0;
  int maxi = flag ? n[i] - '0' : 9;
  for (int idx = 0; idx <= maxi; idx++) {
    res += solve(i + 1, flag && (idx == maxi), n0 + (idx != 0));
  }
  return res;
}

signed main() {
  fastio;
  cin >> n >> k;
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 1, 0) << endl;
  
}


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

#define rep(i,n) for(int i = 0;i<n;i++)
#define cint(a) int a; cin >> a;
#define cstr(str) string str; cin >> str;
#define vv(Type, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;

const ll mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }


int main(void) {

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k; cin >> n >> k;
    vector<int> s, t, a(n);

    rep(i, n) {
        cin >> a[i];
        if (a[i] < 0) t.push_back(a[i]);
        else s.push_back(a[i]);
    }


    int S = s.size();
    int T = t.size();
    bool ok = false;
    if (S > 0) {
        if (n == k) ok = (T % 2 == 0);
        else ok = true;
    }
    else ok = (k % 2 == 0);

    mint ans = 1;
    if (!ok) {
        sort(a.begin(), a.end(), [](int x, int y) {return abs(x) < abs(y); });
        rep(i, k) ans *= a[i];
    }
    else {
        sort(s.begin(), s.end());
        sort(t.rbegin(), t.rend());
        if (k % 2 == 1) {
            ans *= s.back();
            s.pop_back();
        }

        vector<ll> p;
        while (s.size() >= 2) {
            ll x = s.back(); s.pop_back();
            x *= s.back(); s.pop_back();
            p.push_back(x);
        }
        while (t.size() >= 2) {
            ll x = t.back(); t.pop_back();
            x *= t.back(); t.pop_back();
            p.push_back(x);
        }
        sort(p.rbegin(), p.rend());
        rep(i, k / 2) ans *= p[i];
    }

    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 6336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
typedef long long ll;
 
int main() {
  char s[3];
  rep(i,3) {
    cin>>s[i];
    if (s[i]=='1') s[i]='9';
    else if (s[i]=='9') s[i]='1';
    cout<<s[i];
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    int a=0;
    for(int i=0;i<3;i++){
        if(s.at(i)==t.at(i))a++;
    }
    cout<<a;
}


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

using namespace std;

void solve() {
    int n;
    int ans = 1;
    cin >> n;
    if (n == 1) {
        cout << 1;
        return;
    }
    while (ans < n) {
        ans *= 2;
    }
    cout << ((ans != n) ? (ans>>1) : ans);

}

int main() {

	solve();
    return 0;
}


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

int main(){
	int a,b,k;

	cin >>a >>b >>k;
	
	if((b-a)/2<k){
		while(a<=b){
			cout<<a<<endl;
			a++;
		}
	}

	else{
		for(int i=0;i<k;i++){
			cout<<a<<endl;
			a++;
		}
		for(int i=1;i<k+1;i++){
			cout<<b-k+i<<endl;
		}
	}
	return 0;
}

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX 1000

typedef long long ll;
char maps[3000][3000];
int sum_o[3010][3010];
int sum_k[3010][3010];

int main(){
    int N;
    cin >> N;
    vector<int> l(N);
    Rep(i,N){
        cin >> l[i];
    }
    sort(All(l));
    int sum = 0;
    Rep(i,N-1){
        sum += l[i];
    }    
    if(sum > l[N-1])cout << "Yes" << endl;
    else cout << "No" << endl;
    //cin >> N;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
typedef long long ll;
typedef pair<ll, ll> P;
map<long long, long long> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
bool bitcheck(int x, int y) { return (x >> y) & 1; }
signed main() {
    ll d, g;
    cin >> d >> g;
    vector<ll> p(d);
    vector<ll> c(d);
    REP(i, d) {
        cin >> p[i];
        cin >> c[i];
    }
    ll mnproblems = 1000000;
    REP(i, 1 << d) {
        ll sum = 0;
        ll problems = 0;
        REP(j, d) {
            if (bitcheck(i, j)) {
                sum += p[j] * (j + 1) * 100 + c[j];
                problems += p[j];
            }
        }
                if (sum >= g) {
                    mnproblems = min(mnproblems, problems);
                }
        for (int j = d - 1; j >= 0; j--) {
            if (!bitcheck(i, j)) {
                if (sum < g) {
                    problems += (((g - sum + (j + 1) * 100) - 1) / ((j + 1) * 100));
                }
                sum += (p[j] - 1) * (j + 1) * 100;
                if (sum >= g) {
                    mnproblems = min(mnproblems, problems);
                }
              break;
            }
        }
    }
    cout << mnproblems << endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)

int main() {
    int k; cin >> k;
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    vector<int> b(n);
    b[0] = a[0]-a[n-1]+k;
    rep(i,n-1){
        b[i+1] = a[i+1]-a[i];
    }

    sort(b.begin(),b.end());
    int ans = k-b[n-1];
    cout << ans << endl;
}


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

int mod = 1000000007;

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

    vector<int> hight(N);
    vector<bool> list(N, true);

    for (int i = 0; i < N; i++)
    {
        cin >> hight[i];
    }

    int p, q;
    for (int i = 0; i < M; i++)
    {
        cin >> p >> q;
        p--;
        q--;
        if (hight[p] <= hight[q])
            list[p] = false;
        if (hight[p] >= hight[q])
            list[q] = false;
    }

    int count = 0;

    for (int i = 0; i < N; i++)
    {
        if(list[i])
            count++;
    }
    cout << count;
}

Measured memory_bytes: 3784
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct Node{
  int key;
  struct Node *right,*left,*parent;
}Node;

Node *root,*NIL;

Node *find(Node *,int);
void insert(int);
void inorder(Node *);
void preorder(Node *);

int main() {

  int n,i,x;
  char com[10];

  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s",com);
    if(com[0] == 'f') {
      scanf("%d",&x);
      Node *t = find(root,x);
      if(t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if(com[0] == 'i') {
      scanf("%d",&x);
      insert(x);
    } else if(com[0] == 'p') {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;

}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL ) {
    y = x;
    if(z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if(y == NIL) {
    root = z;
  } else {
    if(z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Node *find(Node *u,int k) {
  while( u != NIL && k != u->key) {
    if(k < u->key) u = u->left;
    else u = u->right;
  }

  return u;
}


Measured memory_bytes: 20540
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail
{
  template <typename T, std::size_t NDIMS>
  struct vector_builder
  {
    using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
      if (!dims.empty())
        dims.pop_back();
      return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
    }
  };

  template <typename T>
  struct vector_builder<T, 1>
  {
    using type = std::vector<T>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      return type(dims.empty() ? 0 : dims.back(), v);
    }
  };
} // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T &v, SIZE_T... dims)
{
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<long long> A)
{

  LL sum = 0;
  int cnt = 0;
  for (auto a : A)
    sum += a;
  for (auto a : A)
  {
    if (a * 4 * M >= sum)
      cnt++;
  }
  cout << (cnt >= M ? YES : NO) << endl;
}

int main()
{
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
  }
  solve(N, M, std::move(A));
  return 0;
}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
int l,num=1,m,nl;
int main()
{
	cin>>l;l--;nl=l;
	while(nl)
	{
		if(nl%2==0){nl--;m++;}
		m+=2;nl/=2;num++;
	}
	printf("%d %d\n",num,m);
	while(l)
	{
		if(l%2==0){printf("%d %d %d\n",1,num,l);l--;}
		printf("%d %d %d\n",num-1,num,(l+1)/2);
		printf("%d %d %d\n",num-1,num,0);
		l/=2;num--;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while (cin >> n) {
        vi a(n);
        deque<int> b;
        rep(i, n)cin >> a[i];
        b.push_back(a[0]);
        for (int i = 1; i < n; ++i) {
            if ((n % 2 == 0 && i % 2 == 1) || (n % 2 == 1 && i % 2 == 0)) {
                b.push_front(a[i]);
            }
            else {
                b.push_back(a[i]);
            }
        }
        rep(i, n) {
            cout << b[i] << (i == n - 1 ? '\n' : ' ');
        }
    }
}


Measured memory_bytes: 3840
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <limits>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <iterator>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef unsigned                    ui;
typedef int                         si;
typedef long                        sl;
typedef long long                   ll;
typedef unsigned long long          ull;

#ifdef LOCALHOST
std::ifstream in("input.txt", std::ifstream::in);
#endif // LOCALHOST

#ifdef LOCALHOST
#define is in
#else
#define is cin
#endif // LOCALHOST

int main(int argc, char *argv[])
{
    std::ios_base::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;
    if (m >= n) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);

int n;
int arr[21][21];
int dp[21][1<<21];

int func(int idx, int mask)
{
	if(idx==n)
		return (mask == (int)pow(2,n)-1);
	int & ans = dp[idx][mask];
	if(ans != -1)
		return ans;
    ans = 0;
	for(int j=0;j<n;j++)
	{
		if(arr[idx][j] && !(mask & (1<<(n-j-1))))
			ans = (ans + func(idx+1,mask|(1<<(n-j-1))))%mod;
	}
	return ans;
}

int main()
{
	fast;
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>arr[i][j];
	memset(dp,-1,sizeof(dp));
	cout<<func(0,0);
	return 0;
}

Measured memory_bytes: 172288