akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {

	int n,m;
	cin >> n >> m;

	int res = 0;

	vector<vector<int>> aa(m + 1,vector<int> (2));
	for(int i=1;i<=m;i++)	{
		cin >> aa[i][0] >> aa[i][1];
	}

	for (int k = 1; k <= m; k++) {

		vector < vector<int>> G(n + 1);

		//グラフ隣接リスト読み込み
		for (int i = 1; i <= m; i++) {
			if (i != k) {
				G[aa[i][0]].push_back(aa[i][1]);
				G[aa[i][1]].push_back(aa[i][0]);
			}
		}

		//幅優先探索処理
		vector<bool> seen(n + 1, false);	//発見したらtrue
		deque<int> todo;					//行く所のスタック

		int s = 1;							//今いる場所

		int j = 1; //この問題では１から到達できるところを調べる
		int counter = 1;

		if (seen[j] == false) {			//訪れてなかったら処理すすめる
			seen[j] = true;
			todo.push_back(j);

			while (todo.empty() != true) {				//スタックが空になるまで処理	
				s = todo.front();						//処理番号を指定
				int tugiflg = false;					//次があったらtrueにするフラグ
				for (int i = 0; i < G[s].size(); i++) {
					if (seen[G[s][i]] != true) {
						seen[G[s][i]] = true;
						todo.push_back(G[s][i]);
						counter++;
						tugiflg = true;
					}
				}
				todo.pop_front(); //次を全部探したので削除する
			}
		}

		if (counter != n) { res++; }

	}

	cout <<res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define UB upper_bound
#define LB lower_bound
#define PB push_back
#define mp make_pair
#define F first
#define S second
#define be(a) (a).begin(),(a).end()
#define deb(x) cout<< #x <<" "<<endl;
#define deb2(x, y) cout<< #x <<" "<< x <<endl<< #y <<" "<<y<<endl
#define fo(i, n) for(long long i=0; i<n; i++)
#define Fo(i, n, k) for(long long i=k; i<n; i++)
#define mod 1000000007
#define int long long

typedef long long ll;

void fileIO()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
typedef vector<pair<int, int>> vll;
typedef unordered_map<int, int> ump;



bool sortbysecdesc(const pair<int, int> &a, 
                    const pair<int, int> &b) 
{ 
    return a.second>b.second;
}

int val = -1 * (1e13);

vector<vector<int>> dp(3001, vector<int>(3001, val));

int optimal(vector<int> &a, int i, int j)
{
    int &ans = dp[i][j];
    if(ans != val) return ans;
    if(i==j) ans = a[i];
    else if(i+1 == j) ans = max(a[i], a[j]);
    else
    {
        ans =  max(a[i] + min(optimal(a, i+2, j), optimal(a, i+1, j-1)), 
                   a[j] + min(optimal(a, i+1, j-1), optimal(a, i, j-2)));
    }

    return ans;  

}



int32_t main()
{
    IOS;
    fileIO();
    int T;
    T = 1;
    //cin>>T;

    while(T--)
    {
        int n;
        cin>>n;
        vector<int> a(n);
        int sum = 0;
        for(int i = 0; i<n; i++)
        {
            cin>>a[i];
            sum += a[i];
        }

        int X = optimal(a, 0, n-1);
        int Y = sum - X;

        cout<<X-Y<<"\n";


    }
    
    return 0;
}



Measured memory_bytes: 74288
using System;

namespace lower
{
    class Program
    {
        static void Main(string[] args)
        {
            string n_line = System.Console.ReadLine();
            int n = System.Int32.Parse(n_line);

            string line = System.Console.ReadLine();
            string[] l = line.Split(' ');
            int[] height_arr = Array.ConvertAll<string, int>(l,delegate (string value) { return int.Parse(value); });


            int score = 0;

            for(int first_pos = 0; first_pos < n - 1; first_pos++)
            {
                int count = 0;
                for (int now_pos = first_pos; now_pos < n-1; now_pos++)
                {
                    if (height_arr[now_pos] >= height_arr[now_pos + 1])
                    {
                        count += 1;
                    }
                    else
                    {
                        break;
                    }
                }
                if (score < count)
                {
                    score = count;
                }
                if (score > n - first_pos)
                {
                    break;
                }
            }
            Console.WriteLine(score);
        }
    }
}


Measured memory_bytes: 23004
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

int main()
{
	int N;
	cin >> N;
	map<string, int> C;
	rep(i, N) {
		string S;
		cin >> S;
		C[S]++;
	}
	cout << "AC x " << C["AC"] << endl;
	cout << "WA x " << C["WA"] << endl;
	cout << "TLE x " << C["TLE"] << endl;
	cout << "RE x " << C["RE"] << endl;
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}


int main()
{
    int N = inputValue();
    string S;
    cin >> S;
    string cur = "";
    int ans = 0;
    REP(i, N){
        if(cur[0] != S[i]){
            ans++;
            cur = S[i];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
e = gets.to_i

sum = [a, b, c, d, e].map do |n|
  x = n / 10
  y = n % 10
  (y == 0 ? x : x + 1) * 10
end.reduce(&:+)
min = [a, b, c, d, e].map do |n|
  x = n % 10
  x == 0 ? 10 : x
end.min
ans = sum - (min == 10 ? 0 : 10 - min)
puts ans


Measured memory_bytes: 1788
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for x in range(N + 1)]
def ok(sec4):
  for i in range(4):
    tem = list(sec4)
    if i >= 1:
      tem[i - 1], tem[i] = tem[i], tem[i - 1]
    tem2 = "".join(tem)  
    if tem2[:3] == "AGC" or tem2[1:] == "AGC":
      return False
  return True
def dfs(cur, last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur == N:
    return 1
  ret = 0
  for s in "AGCT":
    if ok(last3 + s):
      ret = ret + dfs(cur + 1, last3[1:] + s)
  memo[cur][last3] = ret
  return ret
print(dfs(0, "TTT") % MOD)

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int a[N], b[N], c[N], f[N][3];

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
	    cin >> a[i] >> b[i] >> c[i];
	}
	
	f[0][0] = a[0];
	f[0][1] = b[0];
	f[0][2] = c[0];
	
	for(int i = 1; i < n; i++){
	    for(int j = 0; j < 3; j++){
	        if(j == 0)
	        f[i][j] = max(f[i-1][j+1],f[i-1][j+2]) + a[i];
	        else if(j == 1)
	        f[i][j] = max(f[i-1][j-1],f[i-1][j+1]) + b[i];
	        else
	        f[i][j] = max(f[i-1][j-2],f[i-1][j-1]) + c[i];
	    }
	}
	cout << max(f[n-1][0],max(f[n-1][1],f[n-1][2]));
}


Measured memory_bytes: 5980
(defun split (string &key (delimiterp #'delimiterp))
  (loop :for beg = (position-if-not delimiterp string)
    :then (position-if-not delimiterp string :start (1+ end))
    :for end = (and beg (position-if delimiterp string :start beg))
    :when beg :collect (subseq string beg end)
    :while end))
(defun delimiterp (c) (position c " ,.;/"))

(defun make-array-from-list (l)
  (make-array (list (length l)) :initial-contents l)
  )

(defun main()
  (let* ((n (read))
        (ts (make-array-from-list (map 'list #'parse-integer (split (read-line)))))
        (m (read))
        (sum (reduce #'+ ts)))

    (loop :for i :below m :do
          (let ((p (read)) (x (read)))
            (princ (+ (- sum (aref ts (1- p))) x))
            (princ #\newline))))
)
(main)

Measured memory_bytes: 16740
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))


;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))
(defmacro aif (test-form then-form &optional else-form)
  `(let ((it ,test-form))
     (if it ,then-form ,else-form)))

;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

(defmacro defchangef (name op default-val)
  `(defmacro ,name (var &optional (val ,default-val))
     `(setq ,var (,',op ,val ,var))))
(defmacro read-str ()
  `(write-to-string (read)))

;;本体
(defun ctoi (c)
  (- (char-code c) (char-code #\0)))
(defun main()
  (println (reduce #'+ (map 'list #'ctoi (read-str)))))

#-swank(main)


Measured memory_bytes: 19424
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;
    
    vector<char> K;
    rep(i, S.size()) {
        if (i == 0) {
            K.push_back(S[i]);
            continue;
        }
        if (S[i] == K.back()) {
            if (i != S.size() - 1) {
                K.push_back('{');
                ++i;
            }
        } else {
            K.push_back(S[i]);
        }
    }
    cout << K.size() << endl;
    return 0;
}


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

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayLong();
            var A = (double)input[0];
            var B = (double)input[1];
            var ans = -1;
            for (int i = 1; i <= 10000; i++)
            {
                var taxA = (int)(i * 0.08);
                var taxB = (int)(i * 0.1);
                if (A == taxA && B == taxB)
                {
                    ans = i;
                    break;
                }
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13396
#include<stdio.h>

void sort(int num[]){
  int i,j,tmp;
  for(i=0;i<3;i++){
    for(j=i+1;j<3;j++){
      if(num[i]<num[j]){
        tmp=num[i];
        num[i]=num[j];
        num[j]=tmp;
      }
    }
  }
}
  
int main(void){
  int num[3],i,tmp,l,sum;
  scanf("%d %d %d",&num[0],&num[1],&num[2]);
  scanf("%d",&l);
  for(i=0;i<l;i++){
    sort(&num);
    num[0]*=2;
  }
  sum=num[0]+num[1]+num[2];
  printf("%d",sum);
  return 0;
}
  
  
  

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

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        char[] c=sc.next().toCharArray();
        sc.close();
        int[] f=new int[10];
        int[] b=new int[10];
        for(int i=0;i<10;i++){
            f[i]=-1;b[i]=-1;
        }
        for(int i=0;i<n;i++){
            int fn=c[i]-'0';
            int bn=c[n-i-1]-'0';
            if(f[fn]<0) f[fn]=i;
            if(b[bn]<0) b[bn]=n-i-1;
        }
        long ans=0;
        for(int i=0;i<10;i++){
            if(f[i]<0) continue;
            for(int j=0;j<10;j++){
                if(b[j]<0) continue;
                HashSet<Integer> set=new HashSet<>();
                for(int k=f[i]+1;k<b[j];k++){
                    if(set.size()==10) break;
                    set.add(c[k]-'0');
                }
                ans+=set.size();
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 24372
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(llint i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
const ll mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const ll INF = 1000000000;

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
int c(int a, int b, int m) {
	int ans = 1;
	for (int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}


int main() {
	llint n;
	cin >> n;
	ll ans = modpow(10,n,mod)+modpow(8,n,mod);
	ans %= mod;
	ans -= modpow(9, n, mod) * 2;
	ans %= mod;
	while (ans < 0)ans += mod;
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
lines = []
colums = []
  
while True:
  H,W = map(int,input().split())
  if H == 0 and W == 0:
    break
  lines.append(H)
  colums.append(W)
  
for H,W in zip(lines,colums):
  for i in range(H):
    if i == 0 or i == H-1:
      for j in range(W):
        print("#",end="")
    else:
      for j in range(W):
        if 0 < j and j < W-1:
          print(".",end="")
        else:
          print("#",end="")
    print("\n",end="")
  print("\n",end="")


Measured memory_bytes: 7020
#include <iostream>
#include <queue>
#include <assert.h>
using namespace std;

long cnt = 0;
void Merge(int A[], int left, int mid, int right)
{
	queue<int>n1;
	queue<int>n2;
	for (int i = left; i < mid; ++i)
	{
		n1.push(A[i]);
	}
	for (int i = mid; i < right; ++i)
	{
		n2.push(A[i]);
	}
	for (int i = left; i < right; ++i)
	{
		int n1_size = n1.size();
		int n1_flag = 0;
		if ((n1.size() != 0) && (n2.size() != 0))
		{
			if (n1.front() < n2.front())
			{
				A[i] = n1.front();
				n1.pop();
				n1_flag++;
			}
			else
			{
				A[i] = n2.front();
				n2.pop();
				cnt = cnt + n1_size - n1_flag;
			}
		}
		else if (n1.size() == 0)
		{
			A[i] = n2.front();
			n2.pop();
		}
		else
		{
			A[i] = n1.front();
			n1.pop();
		}
	}
	assert((n1.size() == 0) && n2.size() == 0);
}
void MergeSort(int A[], int left, int right)
{
	if ((left + 1) < right)
	{
		int mid = (left + right) / 2;
		MergeSort(A, left, mid);
		MergeSort(A, mid, right);
		Merge(A, left, mid, right);
	}
}
int main()
{
	int n;
	cin >> n;
	int* A = new int[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> A[i];
	}
	MergeSort(A, 0, n);
	cout << cnt << endl;
	delete[]A;
	return 0;
}


Measured memory_bytes: 4560
a, b, c = gets.split(" ").map(&:to_i)

if a == b && b == c && a%2 == 0
  puts -1
  exit
end

ans = 0

while a%2 == 0 && b%2 == 0 && c%2 == 0 do
  tmpa = a
  tmpb = b
  tmpc = c
  a = (tmpb+tmpc)/2
  b = (tmpc+tmpa)/2
  c = (tmpa+tmpb)/2
  ans += 1
end

puts ans


Measured memory_bytes: 1788
def main():
    N, K = map(int, input().split())
    value_diff_abs = 0

    if N == 0 or N == K :
        print("0")
    elif N > K :
        ans = N % K
        #print(ans)
        N = ans
        for i in range(0 , N + 1) :
            value_diff_abs = N
            N = abs(N - K)
            #print(str(value_diff_abs))
            if value_diff_abs < N :
                print(str(value_diff_abs))
                break
            elif value_diff_abs == N :
                print(str(value_diff_abs))
                break
    else :
        for i in range(0 , N + 1) :
            value_diff_abs = N
            N = abs(N - K)
            if value_diff_abs < N :
                print(str(value_diff_abs))
                break
            elif value_diff_abs == N :
                print(str(value_diff_abs))
                break


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import Data.List

main :: IO()
main = do
    getLine
    str <- getLine
    print $ getsolve 0 0 str


getsolve :: Int -> Int -> String -> Int
getsolve num _ [] = num
getsolve num now ('I':strs) = getsolve (max num (now + 1)) (now + 1) strs
getsolve num now ('D':strs) = getsolve num (now - 1) strs


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(size_t i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(size_t i=(b)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))

bool check(vector<int> v) {
	int tmp = 0;
	Foreach(item, v) {
		if (tmp == item) return false;
		tmp = item;
	}
	return true;
}

int N, M;
vector<int> graph[10];
int ans = 0;

int dfs(int current, vector<bool> used) {
	if (used[current])return 0;
	used[current] = true;
	bool all = true;
	REP(i, N + 1) if (!used[i]) { all = false; break; }
	if (all) return 1;
	Foreach(item, graph[current]) {
		ans += dfs(item, used);
	}
	return 0;
}

int main(){
	cin >> N >> M;
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	vector<bool> used(N + 1, false);
	used[0] = true;
	dfs(1, used);
	out(ans);
}



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

int main(){
    int N;cin>>N;
    vector<int> p(N);
    for(int i=0;i<N;i++){
        cin>>p[i];
    }
    int cnt=0;
    for(int i=1;i<N-1;i++){
        if((p[i-1]<p[i])&&(p[i]<p[i+1])) cnt++;
        if((p[i-1]>p[i])&&(p[i]>p[i+1])) cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int a, b;
    cin >> a >> b;
    if(a+b >= 10) {
        cout << "error";
    }
    else {
        cout << a+b;
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

#define MAX_NM 200005
#define INF (1<<30)

int N, M;
long long K;
long long A[MAX_NM], B[MAX_NM];

int main() {
  scanf("%d %d %lld", &N, &M, &K);
  for (int i = 0; i < MAX_NM; i++) {
    A[i] = B[i] = INF;
  }
  for (int i = 0; i < N; i++) {
    scanf("%lld", A+i);
  }
  for (int i = 0; i < M; i++) {
    scanf("%lld", B+i);
  }

  long long AA[MAX_NM], BB[MAX_NM];
  AA[0] = 0, BB[0] = 0;
  for (int i = 1; i < MAX_NM; i++) {
    AA[i] = AA[i-1] + A[i-1];
  }
  for (int i = 1; i < MAX_NM; i++) {
    BB[i] = BB[i-1] + B[i-1];
  }
  // for (int i = 0; i < N; i++) {
  //   printf("%lld ", AA[i]);
  // }
  // puts("");
  // for (int i = 0; i < M; i++) {
  //   printf("%lld ", BB[i]);
  // }
  // puts("");

  int ans = 0;
  for (int i = 0; i <= N; i++) {
    if (AA[i] > K) { break; }

    int ok = 0, ng = M+1;
    while (abs(ng-ok) > 1) {
      int mid = (ok+ng)/2;
      if (AA[i] + BB[mid] <= K) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    if (AA[i] + BB[ok] <= K && ans < i+ok) {
      ans = i+ok;
    }
    // for (int j = 0; j <= M; j++) {
    //   if (AA[i] + BB[j] <= K && ans < i+j) {
    //     ans = i + j;
    //   }
    // }
  }
  printf("%d\n", ans);
}

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

MOD = 10 ** 9 + 7

N,M = map(int,input().split())
X = int(input())
UVW = [[int(x) for x in input().split()] for _ in range(M)]
UVW.sort(key = lambda x: x[2])

root = list(range(N+1))
def find_root(x):
    y = root[x]
    if x == y:
        return x
    z = find_root(y)
    root[x] = z
    return z

# min spanning tree
tree = [set() for _ in range(N+1)]
min_tree_size = 0
for u,v,w in UVW:
    ru = find_root(u)
    rv = find_root(v)
    if ru == rv:
        continue
    root[ru] = rv
    min_tree_size += w
    tree[u].add((v,w))
    tree[v].add((u,w))

# treeにおける2頂点の間の辺の最大値を求めたい
# LCA。2^n個手前およびそこまでの最大値を覚える

parent = [[0] * 12 for _ in range(N+1)]
max_wt = [[0] * 12 for _ in range(N+1)]
depth = [0] * (N+1)

def dfs(v=1,p=0,dep=0,w=0):
    parent[v][0] = p
    depth[v] = dep
    max_wt[v][0] = w
    for n in range(1,11):
        parent[v][n] = parent[parent[v][n-1]][n-1]
        max_wt[v][n] = max(max_wt[v][n-1], max_wt[parent[v][n-1]][n-1])
    for u,w in tree[v]:
        if u == p:
            continue
        dfs(u,v,dep+1,w)

dfs()

def max_wt_between(x,y):
    # LCA しながら重みの最大値を得る
    wt = 0
    dx,dy = depth[x], depth[y]
    if dx > dy:
        x,y = y,x
        dx,dy = dy,dx
    while dy > dx:
        diff = dy - dx
        step = diff & (-diff)
        n = step.bit_length() - 1
        wt = max(wt, max_wt[y][n])
        y = parent[y][n]
        dy -= step
    if x == y:
        return wt
    step = 1 << 11
    while step:
        n = step.bit_length() - 1
        rx,ry = parent[x][n], parent[y][n]
        if rx != ry:
            wt = max(wt, max_wt[x][n], max_wt[y][n])
            x,y = rx,ry
        step >>= 1
    return max(wt, max_wt[x][0], max_wt[y][0])

# 各edgeに対して、その辺を含む最小の全域木の大きさを求める
min_size = []
for u,v,w in UVW:
    if (v,w) in tree[u]:
        min_size.append(min_tree_size)
    else:
        x = max_wt_between(u,v)
        min_size.append(min_tree_size + w - x)

sm = sum(1 if s < X else 0 for s in min_size)
eq = sum(1 if s == X else 0 for s in min_size)
gr = sum(1 if s > X else 0 for s in min_size)

if eq == 0:
    answer = 0
elif sm == 0:
    # eq 内の辺が完全同色でなければよい
    answer = (pow(2,eq,MOD) - 2) * pow(2,gr,MOD) % MOD
else:
    # sm 内が完全同色でなければならない。
    # eq 内は、smの色と異なる色を持っていれば何でもよい
    answer = 2 * (pow(2,eq,MOD) - 1) * pow(2,gr,MOD) % MOD

print(answer)



Measured memory_bytes: 5108
#include <stdio.h>
int main(){
	int n,b;
	scanf("%d",&n);
	int a[n];
	for (int i = 0; i <= n; ++i)
	{
		scanf("%d",&a[i]);
	}
	b=0;
	for (int j = 0; j < n; ++j)
	{
		b=b+(a[j]-1);
	}
	printf("%d\n",b);
}

Measured memory_bytes: 128
n,a,b = gets.split.map(&:to_i)
mod = 10**9+7

def pow(n, power, mod)
  return 1 if power == 0
  res = pow(n, power/2, mod)
  res * res % mod * (power.odd? ? n : 1) % mod
end

def comb(n, k, mod)
  x = y = 1
  (1..k).each do |i|
    x = x * n % mod
    y = y * i % mod
    n -= 1
  end
  x * pow(y, mod - 2, mod) % mod
end
 
puts (pow(2, n, mod) - 1 - comb(n, b, mod) - comb(n, a, mod)) % mod


Measured memory_bytes: 1788
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)

        if x in (1,n-1): continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True
 
def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1
 
print(cnt)

Measured memory_bytes: 7700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 1; i <= n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 1;i <= n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//______________________________________________________________________________
int main()
{
       speed;
       string s;
       cin>>s;
       if(s == "SSS"){cout<<0<<endl;return 0;}
       if(s == "RRS" || s == "SRR"){cout<<"2";return 0;}
       if(s == "RRR"){cout<<3<<endl;return 0;}
       cout<<1<<endl;
}


Measured memory_bytes: 3612
#include<stdio.h>
  
void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
  
int n;
int a[1000];
int b[1000];
int vd[1000];
int cnt,sum,mini;
  
int min(int x,int y){
  if(x<y)return x;
  else return y;
}
  
int search(int x){
  int i;
  for(i=0;i<n;i++)if(a[i]==x) return i;
}
  
int main(){
  int i,j,ans,x;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    b[i]=a[i];
  }
  
  for(i=n-1;i>0;i--)
    for(j=0;j<i;j++)
      if(b[j]>b[j+1])swap(&b[j],&b[j+1]);
    
  ans=0;
  for(i=0;i<n;i++)vd[i]=0;
  
  for(i=0;i<n;i++){   
    x=i;
    cnt=sum=0;
    mini=(1<<24);
    while(vd[x]==0){
      vd[x]=1;
      cnt++;
      sum+=a[x];
      mini=min(mini,a[x]);
      x=search(b[x]);
    }
    if(cnt<2)continue;
    ans+=min(sum+b[0]*(cnt+1)+mini,sum+mini*(cnt-2));
  
  }
  
  printf("%d\n",ans);
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  ll n, a, ans = 1;
  cin >> n;
  vector<ll> cnt(n + 1, 0);
  rep(i, n) {
    cin >> a;
    if (a == 0)
      (ans *= (3 - cnt[a])) %= mod;
    else
      (ans *= (cnt[a - 1] - cnt[a])) %= mod;
    cnt[a]++;
  }
  cout << ans << endl;
  return 0;
}

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


int n,q;


//Aのｋ番目（0〜n-1）以降の要素をつかって、Mを作れるかを判定。成功：１　失敗:０
int judge(int *A,int M,int k){
  if(k==n-1){
    if(A[k]==M) return 1;
    else return 0;
  }
  else{
    if(M <A[k]) return judge(A,M,k+1);
    else if(M==A[k]) return 1;
    else{
      if(judge(A,M-A[k],k+1)==1 || judge(A,M,k+1)==1) return 1;
      else return 0;
    }
  }
}
  



int main(){
  int *A;
  int M;
  int i,j;
  
  scanf("%d",&n);
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%*[ \n]%d",&A[i]);
  }

 int max;
  int cha;
  for(i=0;i<n-1;i++){
    max=i;
    for(j=i+1;j<n;j++){
      if(A[max] > A[j]) max=j;
    }
    cha=A[max];
    A[max] =A[i];
    A[i]=cha;
  }//降順にソート 

  
  scanf("%*[ \n]%d",&q);
  for(i=0;i<q;i++){
    scanf("%*[ \n]%d",&M);
    if(judge(A,M,0)==1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}




    


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

int main() {
	fast();
 
    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    ll n, a, b;
    cin >> n >> a >> b;
    ll z = n/(a+b);
    ll k = n%(a+b);
    ll ans = a*z;
    ans += min(k, a);
    cout << ans << endl;
}

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

using namespace std;

bool check(string S){
    int L = S.length();
    for(int i=0; i < L/2 ; i++){
        if(S[i] != S[L-1-i]){
            return false;
        }
    }
    return true;
}
int main(void){
    string S;
    bool flag1,flag2,flag3;
    cin >> S;
    int L = S.length();
    flag1 = check(S);
    flag2 = check(S.substr(0,(L-1/2)));
    flag3 = check(S.substr(((L+3)/2)-1));
    if(flag1 == true && flag2 == true && flag3 == true){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#coding:utf-8

import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    from collections import defaultdict
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    P1 = 2**127-1
    P2 = 2**31-1
    P1 = 10**9*7
    P2 = 10**7-9
    base = 26
    N = II()
    S = list(map(ord,list(input())))
    pow1 = [1]*N
    pow2 = [1]*N
    for i in range(N-1):
        pow1[i+1] = pow1[i]*base%P1
        pow2[i+1] = pow2[i]*base%P2
    hash1 = [0]*(N+1)
    hash2 = [0]*(N+1)
    hash1[1] = hash2[1] = S[0]
    for i in range(2,N+1):
        hash1[i] = (hash1[i-1]*base + S[i-1]) % P1
        hash2[i] = (hash2[i-1]*base + S[i-1]) % P2
    
    def f(x):
        hashes = defaultdict(lambda : -1)
        for i in range(N-x+1):
            #S[i:i+x]
            h1 = (hash1[i+x] - hash1[i] * pow1[x]) % P1
            h2 = (hash2[i+x] - hash2[i] * pow2[x]) % P2
            if hashes[(h1,h2)] == -1:
                hashes[(h1,h2)] = i
            elif hashes[(h1,h2)] + x <= i:
                return True
        # print(hashes)
        return False
    
    ok = -1
    ng = N//2+1
    while ng-ok > 1:
        
        m = (ok+ng)//2
        # print(m)
        if f(m):
            ok = m
        else:
            ng = m
    print(ok)

if __name__ == '__main__':
    main()

Measured memory_bytes: 76164
#include <iostream>
#include <string>
#include <queue>
#include <utility>
using namespace std;

int main(void){
    int N;
    cin >> N;
    int W[N],min=101;
    for(int i = 0; i < N; i++){
        cin >> W[i];
    }
    int t = 0,l = 0;

    for(int T=0;T<N;T++){
        t = t + W[T];
        for(int K=T+1;K < N;K++){
            l = l + W[K];
        }
        int p = t-l;
        if(min > abs(p)){
            min = abs(p);
        }
        l = 0;
    }
    cout << min  << endl;
    return 0;
}

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

class DisjointSet {
public:
    vector<int> rank, p;

    DisjointSet() {};
    DisjointSet(int s) {
        rank.resize(s, 0);
        p.resize(s, 0);
        for (int i = 0; i < s; i++) makeSet(i);
    }

    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y) {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }

    int findSet(int x) {
        while (x != p[x]) {
            x = p[x];
        }
        return x;
    }
};

class Edge {
public:
    int source, target, cost;

    Edge(int source = 0, int target = 0, int cost = 0):
        source(source), target(target), cost(cost) {}

    bool operator < (const Edge &e) const {
        return cost < e.cost;
    }
};

vector<Edge> edges;

int kruskal(int V) {
    int totalCost = 0;
    sort(edges.begin(), edges.end());
    DisjointSet ds = DisjointSet(V);

    for (auto i = 0; i < edges.size(); i++) {
        Edge e = edges[i];
        if (!ds.same(e.source, e.target)) {
            totalCost += e.cost;
            ds.unite(e.source, e.target);
        }
    }
    return totalCost;
}

int main(void) {
    int v, e;
    int s, t, w;
    cin >> v >> e;
    for (int i = 0; i < e; i++) {
        cin >> s >> t >> w;
        edges.push_back(Edge(s, t, w));
    }

    cout << kruskal(v) << endl;

    return 0;
}

Measured memory_bytes: 2704
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

ll D;
vll now, c(26);
vvl s;
vector<set<ll>> st(26);
ll now_score = 0;

void init(ll d){
  D = d;
  now.resize(d, 0);
  s = VV(d, 26, 0, ll);
}
void make_set(vll t){
  for(int i=0;i<D;i++) st[t[i]].insert(i);
  for(int i=0;i<26;i++) st[i].insert(-1);
  for(int i=0;i<26;i++) st[i].insert(D);
}
ll calc(vll t){
  ll score = 0;
  vll cnt(26, 0);
  for(int i=0;i<D;i++){
    ll idx = t[i];
    for(int j=0;j<26;j++){
      if(j==idx) cnt[j] = 0;
      else{
        cnt[j]++;
        score -= cnt[j]*c[j];
      }
    }
    score += s[i][idx];
  }
  return score;
}

ll ch_score(ll day, ll after){
  ll score = now_score;
  ll prev = now[day];//前に選択していたもの
  if(prev==after) return score;

  //prevを消したことで減るスコア
  score -= s[day][prev];

  auto itr = st[prev].find(day);
  auto p = itr, q = itr;
  ll x = day - (*--p) - 1;
  ll y = (*++q) - day - 1;

  ll z = x + y + 1;
  //x, y分増え、z分減る
  score += c[prev]*((x*(x+1))/2 + (y*(y+1))/2);
  score -= c[prev]*((z*(z+1))/2);
  //afterを挿入した事で増えるスコア
  score += s[day][after];
  itr = st[after].upper_bound(day);
  p = itr;
  p--;

  z = (*itr) - (*p) - 1;
  x = day - (*p) - 1;
  y = (*itr) - day - 1;

  score += c[after]*(z*(z+1)/2);
  score -= c[after]*((x*(x+1))/2 + (y*(y+1))/2);
  return score;
}

void change(ll day, ll after){
  ll prev = now[day];
  st[prev].erase(day);
  st[after].insert(day);
  now[day] = after;
}


int main(int argc, char const *argv[]) {
  ll d;std::cin >> d;
  init(d);
  re(i, 26) std::cin >> c[i];
  re(i, D) re(j, 26) std::cin >> s[i][j];

  re(i, D) {
    std::cin >> now[i];
    now[i]--;
  }

  //初期化
  make_set(now);
  now_score = calc(now);

  //x日目をyに変化させた時のスコアを計算
  ll m;std::cin >> m;
  for(int i=0;i<m;i++){
    ll x, y;std::cin >> x >> y;
    x--, y--;
    //変えた場合を試算
    std::cout << ch_score(x, y) << '\n';
    now_score = ch_score(x, y);
    change(x, y);
  }
  //calc(now);
  //std::cout << calc(t) << '\n';
  return 0;
}


Measured memory_bytes: 3272
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int h, w;
    cin >> h >> w;
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char x;
            cin >> x;
            ans += (x == '#');
        }
    }
    cout << (ans == h + w - 1 ? "Possible" : "Impossible");
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll x0 = 1000, x1 = 0, y1 = 0;

    for (int i = 0; i < n; i++) {
        x0 = max(x0, x1 + y1 * a[i]);
        x1 = x0 % a[i];
        y1 = x0 / a[i];
    }

    cout << x0 << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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<int Mod> class ModInt {
  int v;
public:
  constexpr ModInt(const long long x = 0) noexcept : v((x % Mod + Mod) % Mod) {};
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    v += rhs.v;
    if (v >= Mod)
      v -= Mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (v < rhs.v)
      v += Mod;
    v -= rhs.v;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    v = int(1LL * v * rhs.v % Mod);
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    long long exp = Mod - 2;
    while (exp) {
      if (exp & 1)
        *this *= rhs;
      rhs *= rhs;
      exp >>= 1;
    }
    return *this;
  }
  constexpr ModInt operator-() const noexcept { return ModInt(-v); }
  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr bool operator==(const ModInt rhs) const noexcept {
    return v == rhs.v;
  }
  constexpr bool operator!=(const ModInt rhs) const noexcept {
    return v != rhs.v;
  }
  constexpr ModInt pow(long long exp) const noexcept {
    ModInt res(1), mul(v);
    while (exp) {
      if (exp & 1)
        res *= mul;
      mul *= mul;
      exp >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt obj) noexcept {
    return os << obj.v;
  }
  friend istream &operator>>(istream &is, ModInt &obj) noexcept {
    long long tmp;
    is >> tmp;
    obj = ModInt<Mod>(tmp);
    return is;
  }
};
constexpr int MOD = 1000000007;
using mint = ModInt<MOD>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  vector<mint> p(n);
  p[0] = 1;
  for (int i = 1; i < n; i++)
    p[i] = p[i-1]+mint(1)/(i+1);
  mint ans = 0;
  rep(i, n-1)
    ans += p[i]*(x[i+1]-x[i]);
  for (int i = 2; i < n; i++)
    ans *= i;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);

        if (a < c && c < b)
        {
            Console.WriteLine("Yes");
        }
        else if (b < c && c < a)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  ll n;cin>>n;
  vll a(n),sum(n+1,0);
  rep(i,0,n){
    cin>>a[i];
  }
  drep(i,n-1,0){
    sum[i]=sum[i+1]+a[i];
    sum[i]%=MOD;
  }
  ll ans=0;
  rep(i,0,n){
    ans+=(a[i]*sum[i+1])%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 6412
##貪欲法(greedy)
#区間スケジューリング
#B - Robot Arms

n = int(input())
lst = []
for _ in range(n):
    x, l = list(map(int,input().split()))
    lst.append([x,l,x-l,x+l])

lst.sort(key=lambda x: x[3])
ans = []
ans.append(lst[0])

for i in range(1,n):
    if ans[-1][3] <= lst[i][2]:
        ans.append(lst[i])

print(len(ans))

Measured memory_bytes: 35496
import std.stdio, std.string, std.array, std.conv, std.algorithm.iteration, std.functional;

char[54][54] NS;
char[54][54] MS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto n = nm[0];
    auto m = nm[1];

    foreach (i; 0..n) {
        auto line = readln;
        foreach (j, c; line)
            NS[i][j] = c;
    }
    
    foreach (i; 0..m) {
        auto line = readln;
        foreach (j, c; line)
            MS[i][j] = c;
    }
    
    foreach (i; 0..n-m+1) {
        foreach (j; 0..n-m+1) {
            bool check() {
                foreach (ii; 0..m) {
                    foreach (jj; 0..m) {
                        if (NS[i+ii][j+jj] != MS[ii][jj]) return false;
                    }
                }
                return true;
            }
            if (check()) {
                writeln("Yes");
                return;
            }
        }
    }
    writeln("No");
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    string s; cin >> s;
    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (s == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
    return 0;
}


Measured memory_bytes: 888
import heapq
import sys
input = sys.stdin.readline

def main():
  n = int(input())
  abs = [tuple(map(int, input().split())) for _ in range(n)]

  pq = []

  for ab in abs:
    a,b = ab[0],ab[1]
    heapq.heappush(pq, tuple([b,a]))

  dl = 0
  tc = 0

  ans = "Yes"

  for i in range(n):
    ba = heapq.heappop(pq)
    dl = ba[0]
    tc += ba[1]
    if dl < tc:
      ans = "No"
      break
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 43004