akhauriyash/Code-Regression huggingface dataset:
//105
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
    int cake = 4;
    int donut = 7;
    int N;
    cin >> N;

    bool flag = false;
    for (int i = 0; i <= N; i++)
    {
        /* code */
        for (int j = 0; j <= N; j++)
        {
            /* code */
            int value = cake * i + donut * j;
            if (N == value)
            {
                flag = true;
                break;
            }
        }
    }
    if (flag)
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main () {
int a[3];
cin >> a[0] >> a[1] >> a[2];
sort (a, a + 3);
long long ans = a[2];
int k;
cin >> k;
for (int i = 0; i < k; i++) {
ans = ans * 2;
}
cout << ans + a[0] + a[1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"

#define int long long
const int N=1e18L+3;
#define double long double

int32_t main()
{
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
 IOS;
 
 	
 	int n,w;
 	cin>>n>>w;
 	int wt[n];
 	int va[n];
 	int sum=0;
 	for (int i = 0; i < n; ++i)
 	{
 		/* code */cin>>wt[i]>>va[i];
 		sum+=va[i];
 	}

std::vector<int> dp(sum+1,N);
 	dp[0]=0;
 	for (int i = 0; i <n ; ++i)
 	{
 		for (int j = sum-va[i]; j>=0; j--)
 		{
 			dp[j+va[i]]=min(dp[j+va[i]],dp[j]+wt[i]);
 		}
 	}
 	int ans=0;
 	for (int i = 0; i <=sum; ++i)
 	{
 		/* code */if(dp[i]<=w)
 		ans=max(ans,i);
 	}
 			
 	cout<<ans;
 	
 	

 	

 



  
 




  
return 0;
}


Measured memory_bytes: 3988
import sys
input = sys.stdin.readline

def main():
    l, r = map(int, input().split())
    mn = 10 ** 10
    
    for i in range(l, r + 1):
        for j in range(i + 1, r + 1):
            mn = min(mn, i * j % 2019)
            if mn == 0:
                print(0)
                exit()
    print(mn)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
NIL = -1


class Node():
    __slots__ = ["key", "parent", "left", "right"]

    def __init__(self, key=NIL, parent=NIL, left=NIL, right=NIL):
        self.key = key
        self.parent = parent
        self.left = left
        self.right = right


class BinaryTree():
    def __init__(self, node):
        self.root = node

    def insert(self, key):
        if self.root.key == NIL:
            self.root.key = key
            return

        now = self.root
        while now != NIL:
            parent = now
            if   key < now.key:
                now = now.left
            elif key > now.key:
                now = now.right
            else:
                raise
        
        insert = Node(key, parent)

        if   insert.key < parent.key:
            parent.left = insert
        elif insert.key > parent.key:
            parent.right = insert
        else:
            raise

    def find(self, key):
        now = self.root
        while now != NIL:
            if   key < now.key:
                now = now.left
            elif key > now.key:
                now = now.right
            else:
                break

        return now

    def delete(self, key):
        z = self.find(key)
        if isinstance(z, int):
            return

        if z.left == NIL or z.right == NIL:
            y = z
        else:
            y = self.get_successor(z)

        if y.left != NIL:
            x = y.left
        else:
            x = y.right

        if x != NIL:
            x.parent = y.parent

        if y.parent == NIL:
            self.root = x
        elif y == y.parent.left:
            y.parent.left = x
        else:
            y.parent.right = x

        if y != z:
            z.key = y.key

    def get_successor(self, x):
        if x.right != NIL:
            return self.get_minimum(x.right)

        y = x.parent
        while y != NIL and x == y.right:
            x = y
            y = y.parent
        return y

    def get_minimum(self, x):
        while x.left != NIL:
            x = x.left

        return x

    def treewalk_inorder(self, node):
        if isinstance(node, int):
            return

        self.treewalk_inorder(node.left)
        print(f" {node.key}", end="")
        self.treewalk_inorder(node.right)

    def treewalk_preorder(self, node):
        if isinstance(node, int):
            return

        print(f" {node.key}", end="")
        self.treewalk_preorder(node.left)
        self.treewalk_preorder(node.right)



m = int(input())

root = Node()
binary_tree = BinaryTree(root)


for _ in range(m):

    command, *list_num = input().split()

    if   command == "insert":
        k = int(list_num[0])
        binary_tree.insert(k)
    elif command == "find":
        k = int(list_num[0])
        if isinstance(binary_tree.find(k), int):
            print("no")
        else:
            print("yes")
    elif command == "delete":
        k = int(list_num[0])
        binary_tree.delete(k)
    elif command == "print":
        binary_tree.treewalk_inorder(root)
        print()
        binary_tree.treewalk_preorder(root)
        print()
    else:
        raise


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(max(a*c,a*d),max(b*c,b*d)) << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

int main(void) {
  ll N, M;
  cin >> N >> M;
  ll i;
  ll l=1, r=N;
  
  for(i=0; i<M; i++) {
    ll a, b;
    cin >> a >> b;
    chmax(l, a);
    chmin(r, b);
  }
  
  pt(max(0, r-l+1));
  
}


Measured memory_bytes: 256
def main():
    n,a,b=map(int,input().split())
    di = 0
    if (b-a)%2==1:
        w = a-1
        l = n-b
        di = (w - l)
        if di < 0:
            di = -w-1
        else:
            di = l+1
        a += di
        if a < 1:
            a = 1
        b += di
        if b > n:
            b = n
    #print(a,b,di)
    print((b-a)//2 + abs(di))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int K =sc.nextInt();
		int con = 0;
		while (N >= K) {
			con++;
			N = N / K;
		}
		con++;
		System.out.println(con);
	}
}

Measured memory_bytes: 35624
if __name__ == '__main__':

    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))

    field = [0 for i in range(h * w)]
    index = 0
    for i in range(n):
        for j in range(a[i]):
            field[index] = str(i + 1)
            index += 1
    for i in range(h):
        ans = field[(i * w):(i * w + w)]
        if i % 2 == 1:
            ans.reverse()
        print(' '.join(ans))


Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main(){
	string s;
	int k;
	cin >> s >> k;
	int n = s.size();
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'a') {
			continue;
		}
		if (int('z' - s[i] + 1) <= k) {
			k -= int('z' - s[i] + 1);
			s[i] = 'a';
		}
	}
	if (int(s[n - 1] + k) > int('z')) {
		while (int(s[n - 1] + k) > int('z')) {
			k -= 26;
		}
		s[n - 1] = char(s[n - 1] + k);
	}
	else {
		s[n - 1] = char(s[n - 1] + k);
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
     
     
typedef long long ll;
typedef vector <int> vi;
typedef pair <int,int> pi;
typedef tuple <int,int,int> ti;

#define forn(i,a,n) for(int i = a; i < n ; i++)
#define mem(str,a) memset(str, a, sizeof(str));
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(nullptr)
const int MOD = 1e9+7, N = 1e7 + 10, E = 1e-9;
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//vector <int> show;
//for (auto x : show)
//   cout << x << " ";
getline(cin,s);


*/

int main() {
    ll n,k;
    cin >> n >> k;
    int r;
    if(n%2 == 0)
        r = n/2;
    else
        r = n/2+1;
    ll ans = k * pow(k-1, n-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4036
N, K = [int(_) for _ in input().split()]
X = [int(_) for _ in input().split()]

result = 10 ** 20

for i in range(N - K + 1):
    a, b = X[i], X[i + K - 1]
    dmax = max(abs(a), abs(b))
    dmin = min(abs(a), abs(b))
    if a * b >= 0:
        r = dmax
    else:
        r = dmax + dmin * 2
    result = min(result, r)

print(result)


Measured memory_bytes: 14536
#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);

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

  int n;
  string s;
  cin >> n >> s;

  int ans = 0;

  for (char x = '0'; x <= '9'; x++) {
    auto pos1 = s.find(x);
    if (pos1 == string::npos || pos1 == s.size() - 1) continue;
    for (char y = '0'; y <= '9'; y++) {
      auto pos2 = s.find(y, pos1 + 1);
      if (pos2 == string::npos || pos2 == s.size() - 1) continue;
      for (char z = '0'; z <= '9'; z++) {
        auto pos3 = s.find(z, pos2 + 1);
        if (pos3 == string::npos) continue;
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
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; }

const int MOD = 1e9+7;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  rep(i, N) cin >> S[i];
  rep(i, M) cin >> T[i];
  vector<vector<int>> dp(N+1, vector<int>(M+1));
  dp[0][0] = 1;
  rep(i, N+1) rep(j, M+1) {
    if(i)
      dp[i][j] = (dp[i][j]+dp[i-1][j])%MOD;
    if(j)
      dp[i][j] = (dp[i][j]+dp[i][j-1])%MOD;
    if(i && j) {
      dp[i][j] = (dp[i][j]-dp[i-1][j-1]+MOD)%MOD;
      if(S[i-1] == T[j-1])
        dp[i][j] = (dp[i][j]+dp[i-1][j-1])%MOD;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}

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

void solve(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;

    while(k--){
        if(c<=a) c*=2;
        else if(c<=b) c*=2;
        else if(b<=a) b*=2;
    }
    if(c>b && b>a)
    cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main(){
    //int t;cin>>t;while(t--)
    solve();
}



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

using namespace std;

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> A(h, vector<int>(w)), B(h, vector<int>(w));
    for (int i = 0; i < h; i++)
        copy_n(istream_iterator<int>(cin), w, A[i].begin());

    for (int i = 0; i < h; i++)
        copy_n(istream_iterator<int>(cin), w, B[i].begin());

    const int sup = 160 * 160 + 1;
    vector<vector<bitset<sup>>> M(h + 1, vector<bitset<sup>>(w + 1));

    M[0][0][sup / 2] = true;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            int c = abs(A[i][j] - B[i][j]);
            M[i + 1][j] |= M[i][j] << c;
            M[i + 1][j] |= M[i][j] >> c;
            M[i][j + 1] |= M[i][j] << c;
            M[i][j + 1] |= M[i][j] >> c;
        }
    }

    int ans = 1e9;
    for (int k = 0; k < sup; k++){
        if (M[h - 1][w][k])
            ans = min(ans, abs(k - sup / 2));
    }

    cout << ans << endl;
}

Measured memory_bytes: 21248
#include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
static const int MAX_N = 1<<18;
typedef pair<int,int> PII;

LL S[MAX_N+1],n,m;
LL ans;

class BIT{
    public:
        int N;
        void init(int _N){
            N=_N;
            rep(i,N+1)S[i]=0;
        }

        LL getSum(int i){
            LL s=0;
            while(i){
                s+=S[i];
                i-=i&-i;
            }
            return s;
        }

        void add(int i,int x){
            while(i<=N){
                S[i]+=x;
                i+=i&-i;
            }
        }
};

int main(){
    while(1){
        BIT bit;
        int t=0;
        cin>>n>>m;
        if(n==0&&m==0)break;
        bit.init(n);
        FOR(i,1,n){
            int x;
            cin>>x;
            bit.add(i,x);
        }
        FOR(i,m,n){
            LL query=bit.getSum(i)-bit.getSum(t);
            ans=max(query,ans);
            t++;
        }
        cout<<ans<<endl;
        ans=0;
    }
    return 0;
}

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

//define ll long long;
//define ar array;

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

    string s;
    string t;
    cin >> s;
    cin >> t;
    long long cnt = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i]!=t[i]){
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3812
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 405;
const ll INF = 1e18L + 5;
ll dp[nax][nax];
// dp[i][j] - the minimum total cost of combining interval [i,j] into one vertex

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for(int& x : a) {
        scanf("%d", &x);
    }
    auto sum = [&](int L, int R) {
        ll s = 0;
        for(int i = L; i <= R; ++i) {
            s += a[i];
        }
        return s;
    };
    for(int L = n - 1; L >= 0; --L) {
        for(int R = L; R < n; ++R) {
            if(L == R) {
                dp[L][R] = 0;
            }
            else {
                dp[L][R] = INF;
                ll s = sum(L, R);
                for(int i = L; i <= R - 1; ++i) {
                    dp[L][R] = min(dp[L][R], dp[L][i] + dp[i+1][R] + s);
                }
            }
        }
    }
    
    printf("%lld\n", dp[0][n-1]);
}


Measured memory_bytes: 1536
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long


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

    int n,c,k; cin >> n >> c >> k;
    vector<int> t(n);
    for(int i = 0;i < n;i ++) cin >> t.at(i);

    sort(t.begin(),t.end());
    int ans = 0;
    int saisyo = t.at(0);
    int ninzu = 0;

    for(int i = 0;i < n;i ++){
        if(ninzu < c && t.at(i) - saisyo <= k){
            ninzu ++;
            continue;
        }
        else{
            ans ++;
            ninzu = 1;
            saisyo = t.at(i);
            continue;
        }
    }

    cout << ans + 1 << endl;

}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import bisect

n = int(input())
a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()])
c = sorted([int(x) for x in input().split()])

cnt = 0
for j in range(n):
    ai = bisect.bisect_left(a,b[j])
    ci = n-bisect.bisect_right(c,b[j])
    cnt += ai*ci
print(cnt)


Measured memory_bytes: 23092
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
////////////////////////////////





////////////////////////////////
int main(int argc, const char * argv[]) {
    // input from txt （提出時にこの箇所は削除すること）
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////
    
    int H,W;
    cin>>H>>W;
    vector<vector<char>>masume(H,vector<char>(W));
    for(int i=0;i<H;i++){
        string A;
        cin>>A;
        for(int j=0;j<W;j++){
            masume.at(i).at(j)=A.at(j);
        }
    }
    for(int j=0;j<W;j++){
        for(int i=0;i<H;i++){
            if(masume.at(i).at(j)=='#'){
                break;
            }
            else if(i==H-1){
                for(int k=0;k<H;k++){
                    masume.at(k).at(j)=' ';
                }
            }
        }
    }
    for(int i=0;i<H;i++){
        bool finish=false;
        for(int j=0;j<W;j++){
            if(masume.at(i).at(j)=='#'){
                break;
            }
            else if(j==W-1){
                finish=true;
            }
        }
        if(finish){
            continue;
        }
        for(int j=0;j<W;j++){
            if(masume.at(i).at(j)!=' '){
                cout<<masume.at(i).at(j);
            }
            if(j==W-1){
                cout<<endl;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import qualified Data.Set as S

solve :: Int -> [(Int,Int)] -> Bool
solve n m =
    let p1 = S.fromList [ fst i | i <- m, snd i == n]
        p2 = S.fromList [ snd i | i <- m, fst i == 1]
     in not . S.null $ S.intersection p1 p2

main :: IO ()
main = do
    [n,_] <- map read . words <$> getLine :: IO [Int]
    ab <- map ((\[a,b] -> (a,b)) . map (fst . fromJust . BS.readInt) . BS.words)
        . BS.lines <$> BS.getContents :: IO [(Int,Int)]
    putStrLn $ if solve n ab then "POSSIBLE" else "IMPOSSIBLE"


Measured memory_bytes: 65916
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        List<Integer> g = new ArrayList<>();
        for (int h = 1;;) {
            if (h > arr.length) break;
            g.add(h);
            h = 3 * h + 1;
        }
        Collections.reverse(g);

        int count = shellSort(arr, g);
        System.out.println(g.size());
        printList(g);
        System.out.println(count);
        for (int i : arr) {
            System.out.println(i);
        }
    }

    static int shellSort(int[] arr, List<Integer> g) {
        int counter = 0;
        for (int i : g) {
            counter += insertionSort(arr, i);
        }
        return counter;
    }

    static int insertionSort(int[] arr, int g) {
        int counter = 0;
        int n = arr.length;
        for (int i = g; i < n; i++) {
            int v = arr[i];
            int j = i - g;
            while (j >= 0 && arr[j] > v) {
                arr[j + g] = arr[j];
                j = j - g;
                counter++;
            }
            arr[j + g] = v;
        }
        return counter;
    }

    static void printArray(int[] arr) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length - 1; i++) {
            sb.append(arr[i]);
            sb.append(" ");
        }
        sb.append(arr[arr.length - 1]);
        System.out.println(sb.toString());
    }

    static void printList(List<Integer> list) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size() - 1; i++) {
            sb.append(list.get(i));
            sb.append(" ");
        }
        sb.append(list.get(list.size() - 1));
        System.out.println(sb.toString());
    }
}



Measured memory_bytes: 297612
#include <stdio.h>

int main(void)
{
  int P, Q, R, sum;
  scanf("%d %d %d", &P, &Q, &R);
  sum = P + Q;
  if (sum > P + R){
    sum = P + R;
   }
  if (sum > Q + R){
    sum = Q + R;
   }
  printf("%d", sum);
  
  return 0;
        }
  

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,k;
    cin >> n >> k;
    vi p(n);
    cin >> p;
    vi sum(n);
    rep(i,n-1) sum[i+1] = sum[i]+(p[i] < p[i+1]);
    if(n == k) {
        cout << 1 << endl;
        return 0;
    }
    int ans = n-k+1;
    set<int> st;
    rep2(i,1,k) st.insert(p[i]);
    bool flag = false;
    rep(i,n-k) {
        bool ok = true;
        ok &= *st.begin() > p[i];
        ok &= *st.rbegin() < p[i+k];
        if(sum[i+k]-sum[i+1] == k-1) {
            if(flag) ok = true;
            else flag = true;
        }
        if(ok) ans--;
        st.erase(p[i+1]);
        st.insert(p[i+k]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 13944
n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
minans=abs(2*a[0]-suma)
#print(minans)

mydata=0
for i in range(0,n-1):
  mydata+=a[i]
  ans=abs(2*mydata-suma)
  if ans < minans:
    minans = ans
    
print(minans)



Measured memory_bytes: 23800
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = a; i < (b + a); i++)
#define W1 while (1)
#define COUT(x) cout << x << endl
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define mod 1000000007
#define PB push_back
#define F first
#define S second

int main() {
  int n;
  cin >> n;
  vector<int> f(n + 1, 0);
  for (int i = 1; i * i <= n; i++) {
    for (int j = 1; j * j <= n; j++) {
      for (int k = 1; k * k <= n; k++) {
        int num = i * i + j * j + k * k + i * j + j * k + k * i;
        if (f.size() - 1 < num) continue;
        f[num]++;
      }
    }
  }
  FOR(i, 1, n) {
    COUT(f[i]);
  }

  return 0;
}


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

int main(void)
{
    char s[20],t[20];
    int len;
    scanf("%s %s",s,t);
    len=strlen(s);
    for(int i=0;i<len;i++){
        if(s[i]!=t[i]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

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

#define N 100010
#define MAX 1000000000000000000

int main (void)
{
    long n, q, a[N] = {0}, b[N] = {0}, c[N] = {0};
    long i, tmp;
    long long sum;

    scanf("%ld", &n);

    for (i = 0; i < n; i++) {
        scanf("%ld", &tmp);

        a[tmp]++;
    }

    scanf("%ld", &q);

    for (i = 0; i < q; i++) {
        scanf("%ld %ld", &(b[i]), &(c[i]));
    }

    for (i = 0; i < N; i++) {
        sum += i * a[i];
    }

    for (i = 0; i < q; i++) {
        sum = sum + ((c[i] - b[i]) * a[b[i]]);

        a[c[i]] += a[b[i]];
        a[b[i]] = 0;

        printf("%lld\n", sum);
    }

    return 0;
}


Measured memory_bytes: 4076
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

void solution(){
  ll n;
  cin >> n;
  ll total = 0;
  loop(i, n){
    ll tmp = i+1;
    if(!(tmp%3 == 0 || tmp%5 == 0)){
      total += tmp;
    }
  }

  cout << total << endl;
}     



Measured memory_bytes: 3196
import java.util.Scanner;
 
class Main{
  public static void main(String[] arg){
    int H, W;

    Scanner in = new Scanner(System.in);

    while(true){
        H = in.nextInt();
        W = in.nextInt();

        if(H == 0 && W == 0) return;
        
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(i%2 == 0){
                    if(j%2 == 0)
                        System.out.print("#");
                    else
                        System.out.print(".");
                }
                else {
                    if(j%2 == 0)
                        System.out.print(".");
                    else
                        System.out.print("#");
                }
            }
            System.out.println();
        }
        System.out.println();
    }
    
  }
}

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

const int N = 2e5 + 10;

vector <int> G[N];
int type[N], visited[N], legal[N], cnta[N], cntb[N];
char s[N];

void dfs(int x){
	int sz = G[x].size();
	int t;
	for (int i = 0; i < sz; i++){
		if (type[x] == 1) cnta[G[x][i]]--;
		else cntb[G[x][i]]--;
	}
	for (int i = 0; i < sz; i++){
		t = G[x][i];
		if (legal[t] && !visited[t] && (!cnta[t] || !cntb[t])){
			legal[t] = 0;
			visited[t] = 1;
			dfs(t);
		}
	}
}

int main(){
	int n, m, u, v;
	scanf("%d %d",&n,&m);
	scanf("%s",s);
	for (int i = 0; i < n; i++){
		if (s[i] == 'A') type[i + 1] = 1;
		else type[i + 1] = 2;
	}
	for (int i = 1; i <= m; i++){
		scanf("%d %d",&u,&v);
		if (u != v){
			G[u].push_back(v);
			G[v].push_back(u);
			if (type[u] == 1 && type[v] == 1){
				cnta[u]++;
				cnta[v]++;
			}
			else if (type[u] == 1 && type[v] == 2){
				cntb[u]++;
				cnta[v]++;
			}
			else if (type[u] == 2 && type[v] == 1){
				cnta[u]++;
				cntb[v]++;
			}
			else{
				cntb[u]++;
				cntb[v]++;
			}
		}
		else{
			G[u].push_back(v);
			if (type[u] == 1) cnta[u]++;
			else cntb[u]++;
		}
	}
	memset(visited, 0, sizeof(visited));
	for (int i = 1; i <= n; i++) legal[i] = 1;
	for (int i = 1; i <= n; i++){
		if (legal[i] && !visited[i] && (!cnta[i] || !cntb[i])){
			legal[i] = 0;
			visited[i] = 1;
			dfs(i);
		}
	}
	for (int i = 1; i <= n; i++){
		if (legal[i]){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/irange.hpp>
#include <boost/algorithm/string/join.hpp>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
    int n, l; cin >> n >> l;
    vector<string> s(n);

    for (auto i : boost::irange(0, n)) cin >> s[i];

    sort(s.begin(), s.end());

    string ans = boost::join(s, "");

    cout << ans << endl; 
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 5005;

#define getchar getchar_unlocked

inline int in() {
    int n = 0; short c;
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

int a[MAX_N], sm[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n = in(), K = in(), id = 0;
    rep(i,n){
        a[id] = in();
        if(a[id] < K-1) id++;
    }
    n = id;
    sort(a, a+n, greater<int>());
    rrep(i,n){
        sm[i] = sm[i+1] + a[i];
    }
    int ans = 0;
    bitset<MAX_N> dp;
    dp[0] = true;
    rep(i,n){
        if(K+a[i]-sm[i] > 0){
            bool flag = true;
            srep(j,max(0, K-sm[i]),K+a[i]-sm[i]){
                if(dp[j]){
                    flag = false;
                    break;
                }
            }
            ans += flag;
        }
        dp |= (dp << a[i]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type
#define int long long
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r, x)     for (int i = l; i < r; i+=x)
//#define ForE(i, l, r, x)    for (int i = l; i <= r; i+=x)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O 
#define openfile(file)      freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
#define testinput(file)     freopen(file".txt", "r", stdin); 
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define PrintV(a)           Fora(ii, a) cout << ii << ' '; cout << rl;
//#define PrintVl(a)          Fora(ii, a) cout << ii << rl;
//#define PrintA(a, l, r)     for (int ii = l; ii <= r; ii++) cout << a[ii] << ' '; cout << rl;
//#define PrintAl(a, l, r)    for (int ii = l; ii <= r; ii++) cout << a[ii] << rl;
//#define Ptest(x)            return cout << x, 0;
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.End()
#define rall(a)             a.rbegin(), a.rEnd()
#define sz(a)               a.size()
#define len(a)              a.length()
// geometry calc    
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAXN = 1000005, MAXM = 200010;
// code

int n, dp[MAXM][20], a[MAXM];
vector<int> calc(){
	vector<int> res(n+1, 0);
	for (int i = 0; i < 16; i++)
		dp[n][i] = i;
	
	for (int i = n - 1; i > 0; i--){
		int p = 1, t = 1, c = 0;
		res[i] = 1e18;
		for(int j = 0; j < 16; j++){
			while((1.0*a[i+1]/p) < (1.0*a[i]/t)){
				t*=4;
				c++;
			}
			dp[i][j] = j + dp[i+1][min(15ll, c)] + (n - i) * max(0ll, c - 15);
			p *= 4;
			res[i] = min(res[i], dp[i][j]);
		}
	}
	return res;
}

void Solve(){
    cin >> n;
	for (int i = 1; i <= n; i++){
	    cin >> a[i];
	}
	vector<int> suff = calc();
	reverse(a+1, a+n+1);
	vector<int> pref = calc();
	
	int ans = 1e18;
    for (int i = 0; i <= n; i++)
        ans = min(ans, 2*(suff[i+1] + pref[n+1-i]) + i);
        //cout << ans << ' ';
    
    cout << ans << endl;
}

signed main(){
    //openfile("task");
    FAST_IO;
    int TC = 1;
	//cin >> TC;
    while(TC--) Solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}


Measured memory_bytes: 39092
#include<bits/stdc++.h>
#include<math.h>
#define ll long long int
#define vl vector<long long int>
#define all(a) a.begin(),a.end()
using namespace std;

int main(){
  ll n,k;
  cin>>n>>k;
  vl a(n),f(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>f[i];
  }
  sort(all(a));
  sort(all(f));
  reverse(all(f));
  ll ng=-1,ok=a[n-1]*f[0]+1;
  while(abs(ok-ng)>1){
    ll mid,sum;
    mid=(ok+ng)/2;
    sum=0;
    for(int i=0;i<n;i++){
      sum+=max(0ll,a[i]-mid/f[i]);
    }
    if(sum<=k){
      ok=mid;
    }
    else{
      ng=mid;
    }
  }
  cout<<ok<<endl;
}

Measured memory_bytes: 3328
#ifndef TEMPLATE_HPP
#define TEMPLATE_HPP
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())
using namespace std;
using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void chmax(T &x, T y) { x = max(x, y); }
template <typename T> void chmin(T &x, T y) { x = min(x, y); }
template <typename T> T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename U> vector<U> make_vector(T&& n, U&& val) { return vector<U>(forward<T>(n), forward<U>(val)); }
template <typename T, typename... Args> decltype(auto) make_vector(T&& n, Args&&... args) { return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...)); }
const int INF = 1001001001;
const i64 LINF = 1001001001001001001ll;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
#endif

void solve() {
  int n, x;
  cin >> n >> x;
  int m = 2 * n - 1;
  if (x == 1 || x == m) {
    cout << "No" << endl;
    return;
  }
  if (n == 2) {
    cout << "Yes" << endl;
    cout << 1 << endl;
    cout << 2 << endl;
    cout << 3 << endl;
    return;
  }
  vi32 ans(m);
  vi32 used(m + 1);
  if (x != m - 1) {
    ans[n-2]=x+0, used[x+0]=1;
    ans[n-1]=x-1, used[x-1]=1;
    ans[n-3]=x+1, used[x+1]=1;
    ans[n-0]=x+2, used[x+2]=1;
  } else {
    ans[n-2]=x+0, used[x+0]=1;
    ans[n-1]=x+1, used[x+1]=1;
    ans[n-3]=x-1, used[x-1]=1;
    ans[n-0]=x-2, used[x-2]=1;
  }
  int num = 1;
  rep(i, m) if (ans[i] == 0) {
    while (used[num]) num++;
    ans[i]=num, used[num]=1;
  }
  cout << "Yes" << endl;
  rep(i, m) cout << ans[i] << '\n';
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  solve();
  return 0;
}

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

const int INF=INT_MAX;

struct bellford
{
    struct edge{int u, v, w;};
    int nv, ne;
    vector<int> d;
    vector<edge> E;

    bellford(int nv, int ne) : nv(nv), ne(ne)
    {
        d.resize(nv, INF);
    }

    void relax(int u, int v, int w)
    {
        if(d[u]!=INF && d[v]>d[u]+w) d[v]=d[u]+w;
    }

    bool get(int s)
    {
        d[s]=0;
        for(int i=0; i<nv-1; i++)
            for(auto &e : E)
                relax(e.u, e.v, e.w);
        
        for(auto &e : E)
            if (d[e.u]!=INF && d[e.v]>d[e.u]+e.w)
                return false;
        return true;
    }
};

int main()
{
    int nv, ne, r;
    cin>> nv >> ne >> r;
    bellford g(nv, ne);
    for(int i=0; i<ne; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        g.E.push_back({u, v, w});
    }
    if(!g.get(r)) printf("NEGATIVE CYCLE\n");
    else
    {
        for(int i=0; i<nv; i++)
        {
            if(g.d[i]==INF) printf("INF\n");
            else printf("%d\n", g.d[i]);
        }
    }
    
    return 0;
}


Measured memory_bytes: 3304
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char const* argv[])
{
  int weeks;
  cin >> weeks;

  int debt = 100;
  for (int i = 0; i < weeks; i++) {
    debt = ceil(debt * 1.05);
  }

  cout << debt * 1000 << endl;
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vector<double> p(n);
    rep(i,n){
        cin>>p[i];
    }
    double max=0;
    double tmp=0;
    rep(i,n){
        if(i+k>n){
            break;
        }
        if(i==0){
            REP(j,i,i+k){
                tmp+=((p[j]+1)*p[j]/2)/p[j];
            // cout<<((p[j]+1)*p[j]/2)<<'\n';
            }
        }
        else{
            tmp-=((p[i-1]+1)*p[i-1]/2)/p[i-1];
            tmp+=((p[i+k-1]+1)*p[i+k-1]/2)/p[i+k-1];
        }
        if(max<tmp){
            max=tmp;
        }
 
    }
    cout<<setprecision(8)<<max<<'\n';
    return(0);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n),b(n),c(m),d(m);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    rep(i,m){
        cin >> c[i] >> d[i];
    }
    rep(i,n){
        int id = 0;
        rep(j,m){
            if(abs(c[j]-a[i])+abs(d[j]-b[i])<abs(c[id]-a[i])+abs(d[id]-b[i])){
                id = j;
            }
        }
        cout << id+1 << endl; 
    }
    return 0;
}

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

typedef string::const_iterator State;
class ParseError{};

typedef unsigned long long ull;
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define all(a) (a).begin() ,(a).end()

const double eps = 1e-10;
const double inf = (int)1e8;
 
int expression(State &begin);
int term(State &begin);
int number(State &begin);
int factor(State &begin);

int number(State &begin){
    int ret = 0;
    
    while(isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin ++;
    }
    return ret;
}

int term(State & begin){
    int ret = factor(begin);
    
    for(;;){
        if(*begin == '*'){
            begin++;
            ret *= factor(begin);
        }else if(*begin == '/'){
            begin++;
            ret /= factor(begin);
        }else{
            break;
        }
    }
    return ret;
}

int expression(State &begin){
    int ret = term(begin);
    
    for(;;){
        if(*begin == '+'){
            begin++;
            ret += term(begin);
        }else if(*begin == '-'){
            begin++;
            ret -= term(begin);
        }else{
            break;
        }
    }
    return ret;
}

int factor(State &begin){
    if(*begin == '('){
        begin++;
        int ret = expression(begin);
        begin++; 
        return ret;
    } else {
        return number(begin);
    }
}

int main(void){
    int n;
    string s;
    cin>>n;
    getline(cin,s);
    while(n--){
        getline(cin,s);
        State begin = s.begin();
        cout<<expression(begin)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1204
def solve():
    N = int(input())
    W = [input() for i in range(N)]

    for i in range(N):
        for j in range(i+1,N):
            if W[i] == W[j]:
                print('No')
                return
    
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            print('No')
            return
    
    print('Yes')

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 210000;

vector<tuple<ll, ll, ll>> vv;

int n;
ll x;

ll sma;

ll get(tuple<ll, ll, ll> a) {
	ll b, l, u;
	tie(b, l, u) = a;
	return b * l + (x - b) * u;
}

ll sm[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> x;
	for (int i = 0; i < n; ++i) {
		ll b, l, u;
		cin >> b >> l >> u;
		sma += b * l;
		vv.emplace_back(b, l, u);
	}
	sort(ALL(vv), [] (tuple<ll, ll, ll> a, tuple<ll, ll, ll> b) -> bool {
				return get(a) > get(b);
			});
	for (int i = 0; i < n; ++i)
		sm[i + 1] = sm[i] + get(vv[i]);
	ll l = -1;
	ll r = x * n;
	while (r - l > 1) {
		ll m = (l + r) >> 1;
		ll ans = 0;
		int go = min(ll(n) - 1, m / x);
		for (int i = 0; i < n; ++i) {
			ll now = sm[go];
			if (i < go)
				now = sm[go + 1] - get(vv[i]);
			ll lf = m - go * x;
			ll b, l, u;
			tie(b, l, u) = vv[i];
			now += l * min(b, lf);
			if (lf > b)
				now += (lf - b) * u;
			ans = max(ans, now);
		}
		if (ans >= sma)
			r = m;
		else
			l = m;
	}
	cout << r << "\n";
	return 0;
}




Measured memory_bytes: 4980