akhauriyash/Code-Regression huggingface dataset:
//package codeforces;

import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.TreeMap;
import java.util.TreeSet;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Stack;

public class Main {
	// Integer.bitCount(i); count no of 1 bit in a given number
	static Scanner scn = new Scanner(System.in);
//	static class FastReader {
//	BufferedReader br;
//	StringTokenizer st;
//
//	public FastReader() {
//		br = new BufferedReader(new InputStreamReader(System.in));
//	}
//
//	String next() {
//		while (st == null || !st.hasMoreElements()) {
//			try {
//				st = new StringTokenizer(br.readLine());
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//		}
//		return st.nextToken();
//	}
//
//	int nextInt() {
//		return Integer.parseInt(next());
//	}
//
//	long nextLong() {
//		return Long.parseLong(next());
//	}
//
//	double nextDouble() {
//		return Double.parseDouble(next());
//	}
//
//	String nextLine() {
//		String str = "";
//		try {
//			str = br.readLine();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//		return str;
//	}
//}
//
//static FastReader s = new FastReader();
	

	
	public static void main(String[] args) {
		/* TODO Auto-generated method stub */
		// System.out.format("%.10f", ans);char c = sc.next().charAt(0);
		
		
		long a=scn.nextLong(),b=scn.nextLong(),c=scn.nextLong(),k=scn.nextLong(),t=0;
		t=k;
		k-=(a+b);
		if(k<=0)
			System.out.println(Math.min(a,t));
		else if(k>0)
		{
			k-=c;
			if(k==0)
				System.out.println(a-c);
			else if(k<0)
			{	t-=(a+b);
			
				System.out.println(a-t);
			}
			else if(k>0)
			{
				System.out.println(a-c);
			}
		}
		
}
}
	class pair
	{
		int x;
		int y;
		
		pair(int a,int b)
		{
			this.x=a;
			this.y=b;
			
		}
		public int hashCode()
		 {
		  return x*31+y*31;
		 }
		 
		 public boolean equals(Object other)
		 {
		  if(this==other) return true;
		  
		  if(other instanceof pair)
		  {
		   pair pt = (pair)other;
		   
		   return pt.x==this.x && pt.y==this.y;
		  }
		  else return false;
		 }
	}
	class sorting implements Comparator<pair>
	{

		@Override
		public int compare(pair o1, pair o2) {
			// TODO Auto-generated method stub
			int a=Math.max(o1.x,o2.x),b=o1.y-o2.y;
			return o1.x-o2.x;
		}
		
	}



Measured memory_bytes: 35752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll n,z,w;
ll a[2001];
ll memo[2001][2001][2];

ll hoge(ll i,ll j,ll k){
    if(memo[i][j][k]!=-1){
        return memo[i][j][k];
    }
    if(i==n || j==n){
        return memo[i][j][k]=abs(a[i]-a[j]);
    }
    if(k==0){
        return memo[i][j][k]=max(hoge(max(i,j)+1,j,0),hoge(max(i,j)+1,j,1));
    }else{
        return memo[i][j][k]=min(hoge(i,max(i,j)+1,0),hoge(i,max(i,j)+1,1));
    }
}

int main(){fastio
    cin>>n>>z>>w;
    rep(i,1,n)cin>>a[i];
    a[0]=w;
    rep(i,0,n){
        rep(j,0,n){
            rep(k,0,1){
                memo[i][j][k]=-1;
            }
        }
    }
    cout<<hoge(0,0,0)<<endl;
    
    return 0;
}





Measured memory_bytes: 66348
'use strict'
function main(input) {
    const tmp = input.split('\n');
    const N = parseInt(tmp[0], 10);
    const a = tmp[1].split(' ').map((elem) => parseInt(elem, 10));

    const border = [1, 2, 3, 4, 5, 6, 7, 8].map((elem) => elem * 400);
    border.unshift(1);
    let population = Array(8).fill(0);
    let rainbowCount = 0;

    for (let i = 0; i < N; i++) {
        for (let j = 0; j < 8; j++) {
            if (border[j] <= a[i] && a[i] < border[j + 1]) {
                population[j]++;
            }
        }
        if (border[border.length - 1] <= a[i]) {
            rainbowCount++;
        }
    }


    let minKind = 0;
    let maxKind = 0;
    const c = population.length - howManyZero(population);
    if (c === 0) {
        minKind = 1;
    } else {
        minKind = c;
    }

    maxKind = rainbowCount + c;

    console.log(minKind + " " + maxKind);
}

function howManyZero(arr) {
    let count = 0;
    for (let elem of arr) {
        if (elem === 0) {
            count++;
        }
    }

    return count;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

 using namespace std;

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

   vector<vector<char>> A(H + 1, vector<char>(W + 1));
   int count = 0;
   for (int i = 1; i <= H; i++) {
     for (int j = 1; j <= W; j++) {
       cin >> A.at(i).at(j);
       if (A.at(i).at(j) == '#') count++;
     }
   }
   if (count == H + W - 1) cout << "Possible" << endl;
   else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define swap(a,b) ((a != b) && (a += b,b = a - b,a -= b))
using namespace std;

int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}

int main()
{
    int sum=0;
    int max=0;
    int a,n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a;
        sum+=a;
        if(a>max)max=a;
    }
    sum-=max;
    string s;
    if(sum>max)s="Yes";
    else s="No";
    cout<<s<<endl;
    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>

int main(int argc,char* argv[]){
  
  int a,b,c,d,e,f;
  double per_x_a_to_d;
  double y;
  double x;

  while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f) != EOF){
    if(d == 0){
      y = (double)(f)/e;
    }else{
      per_x_a_to_d = ((double)(a))/d;
      y = (c - per_x_a_to_d*f)/(b - per_x_a_to_d*e);
    }
    
    if(a == 0){
      x = (f - e*y)/d; 
    }else{
      x = (c - b*y)/a;
    }
    printf("%.3lf %.3lf\n",x,y);
  }
  
  
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a<<"\n";
    return 0;  
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;
bool b[50];
int main() {
  string s,t;
  cin>>s>>t;
  char a[50];
  for (char i='a'; i<='z'; i++) a[i-'a']='A';
  for (char i='a'; i<='z'; i++) {
    for (int j=0; j<s.size(); j++) {
      if (s[j]!=i) continue;
      if (a[i-'a']=='A') {
	a[i-'a']=t[j];
      }
      else if (a[i-'a']!=t[j]) {
	cout<<"No"<<endl;
	return 0;
      }
    }
  }
  for (char i=0; i<26; i++) {
    if (a[i]=='A') continue;
    if (b[a[i]-'a']==false) b[a[i]-'a']=true;
    else {
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}



Measured memory_bytes: 776
(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 :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline split-ints-into-vector))
(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))
  (declare (string string)
           (function key)
           ((simple-array * (*)) dest-vector)
           ((integer 0 #.most-positive-fixnum) offset))
  (loop for idx from offset below (length dest-vector)
        for pos1 = 0 then (1+ pos2)
        for pos2 = (position #\space string :start pos1 :test #'char=)
        do (setf (aref dest-vector idx)
                 (funcall key (parse-integer string :start pos1 :end pos2)))
        finally (return dest-vector)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((n (read))
         (ls (make-array (+ n n) :element-type 'uint32)))
    (split-ints-into-vector (read-line) ls)
    (setf ls (sort ls #'<))
    (println
     (loop for i below n
           sum (min (aref ls (+ i i)) (aref ls (+ i i 1)))))))

#-swank(main)



Measured memory_bytes: 13412
#!/usr/bin/python
# -*- Coding: utf-8 -*-

def main():
    buttons = raw_input()
    buttons = buttons.split()
    ans = 0
    cnt = 0
    A = int(buttons[0])
    B = int(buttons[1])
    while cnt < 2:
        if A > B:
            ans += A
            A = A - 1
        elif A < B:
            ans += B
            B = B - 1
        elif A == B:
            ans += A
            A = A - 1
        cnt += 1
    print(ans)
main()


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

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);

    rep(i, n) cin >> p[i];
    sort(p.begin(), p.end());

    int ans = 0;

    rep(i,k) ans += p[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<numeric>
#include<string>
using namespace std;

int main(){
	string str;

	cin >> str;

	for (int i = str.size() - 1; i >= 0; i--){
		cout << str[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;

int main(){
	int n;
	while(scanf("%d",&n)==1){
		vector<int> args;
		for(int x=0;x<n;++x){
			int j;scanf("%d",&j);
			args.push_back(j);
		}
		sort(args.begin(),args.end());
		int penalty = 0, acum = 0;
		for(int x=0;x<n;++x){
			acum += args[x];
			penalty += acum;
		}
		cout<<penalty<<endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    long double N;
    cin >> N;
    long ans=-1;
    ll ii,jj;
    for(ll i=1; i<=3500; i++){
        ii = i;
        for(ll j=1; j<=3500; j++){
            jj = j;
            ll Z = N*i*j;
            ll W = 4*i*j - N*i - N*j;
            if(W > 0 && Z % W == 0){
                ans = Z / W;
                break;
            }
        }
        if(ans != -1)break;
    }
    cout << ii <<" "<< jj <<" "<< ans << endl;
}

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

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
	    int b = sc.nextInt(); 
	    int c = sc.nextInt();
	    System.out.println((a*b)/2);
	}
}

Measured memory_bytes: 21716
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.equals("SUN")) {
            System.out.println(7);
        } else if (s.equals("MON")) {
            System.out.println(6);
        } else if (s.equals("TUE")) {
            System.out.println(5);
        } else if (s.equals("WED")) {
            System.out.println(4);
        } else if (s.equals("THU")) {
            System.out.println(3);
        } else if (s.equals("FRI")) {
            System.out.println(2);
        } else if (s.equals("SAT")) {
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 21460
#include <stdio.h>

long fibo(int n)
{
  static long cache[50] = {1, 1};
  if (cache[n]>0) return cache[n];
  if (n<=1) return 1;
  long f = fibo(n-1) + fibo(n-2);
  cache[n]=f;
  return f;
}


int main()
{
  char str[10];
  int n = 0;
  char *p;
  fgets(str, 10, stdin);
  p = str;
  do {
    n = n*10 + *p-'0';
    p++;
  } while (*p&0x20);

  printf("%ld\n", fibo(n));
  return 0;
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

int main() {
 UL N;scanf("%u",&N);
 tuple<UL,UL,char,ULL,string> P[100000];
 rep(i,N) {
  UL v,w; char t; ULL d; char s[21];
  scanf("%u%u %c%llu %s",&v,&w,&t,&d,s);
  P[i]=make_tuple(v,w,t,d,string(s));
 }
 sort(P,P+N);
 rep(i,N) printf("%u %u %c %llu %s\n",get<0>(P[i]),get<1>(P[i]),get<2>(P[i]),get<3>(P[i]),get<4>(P[i]).c_str());
 return 0;
}




Measured memory_bytes: 11528
import java.io.*
import java.util.*

const val YES = "Yes"
const val NO = "No"
fun solve(N: Long){
    for (i in 1..9){
        if(N % i == 0L && N / i <= 9L) {
            println(YES)
            return
        }
    }
    println(NO)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    solve(N)
}



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

bool test(int a, int b, int c) {
  if (a == b || b == c || c == a) return false;
  int m = max(a, max(b, c));
  int s = a + b + c - m;
  if (s > m) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; ++i) cin >> l.at(i);
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      for (int k = j+1; k < n; ++k) {
        if (test(l.at(i), l.at(j), l.at(k))) {
          ++ans;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int sum(int x){
  int ac=0;
  for(;x>0;x/=10){
    ac+=x%10;
  }
  return ac;
}

int main(){
  int N;
  scanf("%d",&N);
  int best=1e9;
  for(int i=1;i<N;i++){
    best=std::min(best,sum(i)+sum(N-i));
  }
  printf("%d\n",best);
  return 0;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
using namespace std;

int main() {
    ll n, m, q;
    cin >> n >> m >> q;
    vector<pair<ll, ll> > v;
    int x, y;
    map< ll, vector<ll> > g;
    for (int i = 0; i < m; ++i) {
        cin >> x >> y;
        g[x].push_back(y);
    }
    for (auto it = g.begin(); it != g.end() ; ++it) {
        sort(it->second.begin() , it->second.end());
    }
    while(q--){
        int l,r;
        cin>>l>>r;
        int ans = 0;
        for (auto it = g.begin();  it != g.end() ; ++it) {
            if(it->first >= l && it->first <= r){
                int index = upper_bound(it->second.begin(), it->second.end(), r) - it->second.begin();
                if(index >= 0)
                ans += index;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D){
    cout << "Left" << endl;
  } else if (A + B < C + D){
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
int main(){
	ll a,b,c,k;
	ll ans;
	cin>>a>>b>>c>>k;
	if(k<=a){
		ans=k;
	}
	if(k>a&&k<=a+b)
		ans=a;
	if(k>a+b)
		ans=a-(k-(a+b));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  if(abs(n - m) > 1)
    cout << 0 << endl;
  else {
    ll o = 1;
    for(int i = 2; i <= n; i++)
      o = o * i % MOD;
    for(int i = 2; i <= m; i++)
      o = o * i % MOD;
    if(n == m)
      o = o * 2 % MOD;
    cout << o << endl;
  }
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())

if B - A + 1 < 2*K:
    for i in range(A, B + 1):
        print(i)

else:
    for i in range(A, A + K):
        print(i)

    for i in range(B - K + 1, B + 1):
        print(i)

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

int main(){
	scanf("%d%d", &k, &x);
	for(int i = x-k+1; i < x+k; i++) printf("%d%c", i, i == x+k-1 ? '\n' : ' ');
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
const lld inf = 1e18+5;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,w;
	cin >> n >> w;
	vector <int> we(n),va(n);
	lld sum=0;
	for(int i=0;i<n;i++)
	{
		cin >> we[i] >> va[i];
		sum+=va[i];
	}
	vector <vector<lld> > dp(n+1,vector <lld> (sum+1,inf));
	for(int i=0;i<=sum;i++)
	{
		dp[0][i]=inf;
	}
	for(int i=0;i<=n;i++)
	{
		dp[i][0]=0;
	}
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=sum;j++)
		{
			if(j-va[i-1]>=0)
			{
				dp[i][j] = min(dp[i-1][j],dp[i-1][j-va[i-1]]+we[i-1]);
			}
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	lld ans = 0;
	for(int i=0;i<=sum;i++)
	{
		if(dp[n][i]<=w)
		{
			ans = max(ans,(lld)i);
		}
	}	
	cout << ans;
}

Measured memory_bytes: 80256
#設定
import sys
input = sys.stdin.buffer.readline
INF = float("inf")

#ライブラリインポート
from collections import defaultdict
from heapq import heappop, heappush

#入力受け取り
def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b, w):
		self.graph[a].append((b, w))

	def get_nodes(self):
		return self.graph.keys()

class Dijkstra(object):
	def __init__(self, graph, s):
		self.g = graph.graph
		self.dist = defaultdict(lambda: INF)
		self.dist[s] = 0
		self.prev = defaultdict(lambda: None)
		self.Q = []
		heappush(self.Q, (self.dist[s], s))
		while self.Q:
			dist_u, u = heappop(self.Q)
			if self.dist[u] < dist_u:
				continue
			for v, w in self.g[u]:
				alt = dist_u + w
				if self.dist[v] > alt:
					self.dist[v] = alt
					self.prev[v] = u
					heappush(self.Q, (alt, v))

#処理内容
def main():
	N, M = getlist()
	G = Graph()
	for i in range(M):
		L, R, C = getlist()
		G.add_edge(L - 1, R - 1, C)
	for i in range(N - 1):
		G.add_edge(i + 1, i, 0)
	D = Dijkstra(G, 0)
	if D.dist[N - 1] == INF:
		print(-1)
	else:
		print(D.dist[N - 1])

if __name__ == '__main__':
	main()

Measured memory_bytes: 74000
#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;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int k, n;
	cin >> k >> n;
	int a[n];
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int mx = 0;
	for(int i = 1; i < n; i++) {
		mx = max(mx, a[i] - a[i - 1]);
	}
	mx = max(mx, k - (a[n - 1] - a[0]));
	cout << k - mx;

	return 0;
}

Measured memory_bytes: 1920
$a=$L=<>;
$c+=$a%2,$l++,$a>>=1while$a;
print$l,$",$l*2-3+$c,$/;
$a=1;
while(++$i<$l){
	print$i,$",$i+1,$",0,$/;
	print$i,$",$i+1,$",$a,$/;
	print$i,$",$l,$",$L-=$a,$/if$L&$a;
	$a<<=1
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
int main(){
	ll n,x;
	cin >> n >> x;
	ll a[n];
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	ll sum=0;
	rep(i,n){
		sum+=a[i];
		if(sum>x){cout << i << endl;return 0;}
	}
  	if(sum==x)cout << n << endl;
  else cout << n-1 << endl;
}


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

int main() {
  int N, M;
  int counter = 0;
  int sum = 0;
  cin >> N;
  M = N;
  
  while(M > 0){
    sum += M % 10;
    M /= 10;
    counter++;
  }
  
  if(N % sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n,d,i,j,k,l,ans=0;
  cin>>n>>d;
  int X[n][d];
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      cin>>X[i][j];
    }
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      l=0;
      for(k=0;k<d;k++){
        l=l+pow(X[i][k]-X[j][k],2);
      }
      k=sqrt(l);
      if(k*k==l)ans++;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
int main(){
    int n;
    cin >> n;
    ll ans=1;
    bool Ch=0;
    rep(i,n){
        ll a;
        cin >> a;
        if(a==0){
            cout<<0<<endl;
            return 0;
        }
        ll A=1000000000000000000/ans+1;
        if(ans!=0&&A<=a){
            Ch=1;
            ans=0;
        }
        ans*=a;
    }
    if(Ch==1){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3648
s = gets.chomp
flag = true
loop{
    if s.length==0 || flag==false then
        break
    end
    temp = s
    if ["dream", "erase"].include?(temp[-5, 5]) then
        temp = temp[0, temp.length-5]
    elsif ["eraser"].include?(temp[-6, 6]) then
        temp = temp[0, temp.length-6]
    elsif ["dreamer"].include?(temp[-7, 7]) then
        temp = temp[0, temp.length-7]
    else
        if temp==s then
            flag = false
        end
    end
    s = temp
}

puts flag ? "YES" : "NO"

Measured memory_bytes: 52548
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        char[] d = S.toCharArray();
        int len = d.length;
        int[] digits = new int[len+1];
        digits[0] = 0;
        for (int i = 1; i <= len; i++) {
            digits[i] = d[i-1] - '0';
        }
        int[][] dp = new int[len+1][2];
        dp[0][0] = 0;
        dp[0][1] = 1;
        for (int i = 1; i <= len; i++) {
            dp[i][0] = Math.min(dp[i - 1][0] + digits[i], dp[i - 1][1] + 10 - digits[i]);
            dp[i][1] = Math.min(dp[i - 1][0] + digits[i] + 1, dp[i - 1][1] + 10 - digits[i] - 1);
        }
        System.out.println(dp[len][0]);
    }
}


Measured memory_bytes: 64760
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    bool zero = false;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] == 0)
            zero = true;
    }
    if (zero) {
        cout << 0 << "\n";
        return 0;
    }
    lint ret = 1;
    lint maxi = 1000000000000000000LL;
    for (int i = 0; i < n; ++i) {
        if (maxi / a[i] < ret) {
            cout << -1 << "\n";
            return 0;
        }
        ret *= a[i];
        if (ret > maxi) {
            cout << -1 << "\n";
            return 0;
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 4000
x = int(input())
a = list()
a.append(1)
for i in range(2,32):
    j = 2  
    while i**j<1001:
        a.append(i**j)
        j= j+1
a = sorted(a)[::-1]
for i in range(len(a)):
    if a[i]<=x:
        print(a[i])
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#include <regex>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
ld n , d;
vector<vector<ld>> x(n,vector<ld>(d));

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

    ll ans = 0;
    
    for(int i=1;i<=1000001;i++){
        if(n%i==0){
            ll m = (n/i) - 1;
            if(m>i) ans+=m;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int f(int a, int b, int c) {
    if (a == b && a == c) {
        return 1;
    }
    if (a == b || a == c || b == c) {
        return 2;
    }
    return 3;
}

int main() {

    int a, b, c;
    cin >> a >> b >> c;

    int result = f(a, b, c);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;
int f,t,n;
int main()
{
	scanf("%d",&n);
	for(int i = 1,tmp;i <= n;i++)
	{
		scanf("%d",&tmp);
		if(tmp % 4 == 0)f++;
		else if(tmp % 2 == 0)t++;
	}
	int num = f * 2 + t;
	if(t == 0)num++;
	printf("%s",num >= n ? "Yes" : "No");
}

Measured memory_bytes: 256
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    #l,r,d=map(int,input().split())
    n=int(input())
    print("Yes") if n>=30 else print("No")


if __name__ == "__main__":

    main()


Measured memory_bytes: 72680
#include <iostream>
#include <stdlib.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */
#include <vector>
#include <stack>
#include <algorithm>
#include <string>

bool binarySearch(std::vector<int>& list, int L, int R, int T) {
    if (L>R) return false;
    int m = floor((L+R)/2);
    if (T<list[m]) {
        return binarySearch(list,L,m-1,T);
    } else if (T>list[m]) {
        return binarySearch(list,m+1,R,T);
    } else {
        return true;
    }
}

int linearSearch(std::vector<int>& list, std::vector<int>& seq) {
   int found = 0;
   for (int i=0; i<seq.size();i++) {
        if(binarySearch(list,0, list.size()-1,seq[i])) found++;
   }
   return found;
}

int main(void){
    int value;
    std::vector<int> list;
    int n;
    std::cin >> n;
    for(int i=0; i<n; i++) {
        std::cin >> value;
        list.push_back(value);
    } 
    std::vector<int> seq;
    int q;
    std::cin >> q;
    for(int j=0; j<q; j++) {
        std::cin >> value;
        seq.push_back(value);
    }
    std::cout << linearSearch(list,seq) << std::endl;
    return 0;
}

Measured memory_bytes: 1800
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int a[100010],b[100010];
signed main() {
	int s, d, f;
	cin >> s >> d >> f;
	rep(i, f) {
		cin >> a[i];
	}
	Rep(i, s) {
		b[i] = d;
	}
	rep(i, f) {
		b[a[i]]++;
	}
	Rep(i, s) {
		b[i] -= f;
	}
	Rep(i, s) {
		if (b[i] > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  vector<int> v(5);
  rep(i, 5) cin >> v[i];
  auto ceil10 = [](int x) { return (x + 9) / 10 * 10; };
  sort(all(v), [&](int a, int b) { return ceil10(a) - a < ceil10(b) - b; });
  int t = 0;
  rep(i, 5) t = ceil10(t) + v[i];
  out(t);
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
 long long int n,k;
  cin>>n>>k;
  long long int arr[n];
  for(long long int i=0;i<n;i++)cin>>arr[i];
   long long int sum[n];
  sum[0]=arr[0];
  for(long long int i=1;i<n;i++)sum[i]=sum[i-1]+arr[i];
  
 long long  int curr=sum[k-1];
  for( long long int i=1;i<n-k+1;i++){
    long long int s=sum[k-1+i]-sum[i-1];
    if(curr<s)curr=s;
    
    
  }
 long double max=(curr+k)/2.0;
  cout<< fixed << setprecision(6) << max << endl;
  
  
  
  
  return 0;
  
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(f) (f).begin(),(f).end()
#define allr(f) (f).rbegin(),(f).rend()
const int mod = 1e9+7, A = 1e2+5;
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n, m, k;
	cin >> n >> m;
	string s;
	map <int, pair<int, bool>> mop;
	while (m--)
	{
		cin >> k >> s;
		if (mop[k].S != 1)
			s == "WA"? mop[k].F++ : mop[k].S = 1;
	}
	int sum = 0, pen = 0;
	for (auto i : mop)
	{
		if (i.S.S == 1)
			sum++, pen += i.S.F;
	}
	cout << sum << ' ' << pen;
	return 0;
}


Measured memory_bytes: 6528
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

int dp[50001];
int N,M;
int C[20];
const int inf=0xfffffff;
int main()
{
	cin>>N>>M;
	rep(i,M) cin>>C[i];
	rep(i,N+1) dp[i]=inf;
	dp[0]=0;
	rep(i,N){
		rep(j,M){
			if(i+C[j]<=N){
				dp[i+C[j]]=min(dp[i+C[j]],dp[i]+1);
			}
		}
	} 
	cout<<dp[N]<<endl;
}


Measured memory_bytes: 3268
N = int(input())
import numpy as np
v = np.array([0, 10**1 - 1, 0, 10**3 - 10**2, 0, 10**5 - 10**4])
n = np.log10(N)
i = int(np.floor(n))
cnt = np.sum(v[:i+1]) 
if i in [0, 2, 4]:
    cnt += (N - 10 ** i + 1)
print(cnt)


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

int main(){
  string S;
  cin>>S;
  int len=S.length();
  if(S.at(len-1) !='s'){
    S+="s";
  }
  else{
    S+="es";
  }
  cout<<S<<endl;
  

  return 0;
}


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

int main() {
    double a, b, x;
    cin >> a >> b >> x;

    double pi = 4 * atan(1);
    double t = x / (a * a * b);
    double z;
    if (t < 0.5) {
        z = 0.5 * pi - atan2(a * t * 2, b);
    } else {
        z = atan2(b * (1 - t) * 2, a);
    }

    printf("%.10f\n", z * 180 / pi);

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std; 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
                     
#define pb push_back 
#define PII pair<int,int>
                     
#define VS vector<string>
#define VI vector<int>
#define ll long long int
#define debug(x) cout << x << " :" <<#x << endl  
int main(void) {     
    string s1, s2, s3;cin >> s1 >> s2 >> s3;
    cout << 'A' << s2[0] << 'C' << endl;                                                                                                       
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())


//INT_MAX
//INT_MIN
//LLONG_MAX
//LLONG_MIN
//DBL_MIN
//DBL_MAX
//LDBL_MIN
//LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    if (n % 2 == 0) {
        cout << (n + 1) * (n / 2) << endl;
    }else{
        cout << (n + 1) * (n / 2) + n / 2 + 1 << endl;
    }

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String k = scan.next();
		scan.close();

		for(int i=0;i<s.length();i++) {
			if(Character.getNumericValue(s.charAt(i))==1) {
				if(k.length()<=3) {
					int K = Integer.valueOf(k);
					if(K-1 == i) {
						System.out.println("1");
						break;
					}
				}
			}else {
				System.out.println(Character.getNumericValue(s.charAt(i)));
				break;
			}
		}
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/arc078_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<ll> c(N);
  ll total = 0;
  rep(i, N) {
    cin >> c[i];
    total += c[i];
  }

  ll sumX = c[0];
  ll sumY = total - sumX;
  ll ans = abs(sumX - sumY);
  repi(i, 1, N - 1) {
    sumX += c[i];
    ll sumY = total - sumX;
    ans = min(ans, abs(sumX - sumY));
  }

  cout << ans << endl;
}

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

using namespace std;
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int a[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }

  }
  int n;
  cin>>n;
  vector<int> v;
  vector<int> c;
  for(int i=0;i<n;i++){
    int t;
    cin>>t;
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(a[j][k]==t){
           v.push_back(j*3+k+1);
           c.push_back(k*3+j+1);
        }
      }
    }
  }
  sort(v.begin(),v.end());
  sort(c.begin(),c.end());
  int f=0;
  if(v.size()>=2){
  for(int i=0;i<v.size()-2;i++){
    if(v[i]==v[i+2]-2 && v[i]==v[i+1]-1 && v[i]%3==1){
       f=1;
    }
  }
  for(int i=0;i<c.size()-2;i++){
    if(c[i]==c[i+2]-2 && c[i]==c[i+1]-1 && c[i]%3==1){
       f=1;
    }
  }
  }
  
  std::vector<int>::iterator it=std::find(v.begin(),v.end(),1);
  std::vector<int>::iterator it2=std::find(v.begin(),v.end(),5);
  std::vector<int>::iterator it3=std::find(v.begin(),v.end(),9);
  std::vector<int>::iterator it4=std::find(v.begin(),v.end(),3);
  std::vector<int>::iterator it5=std::find(v.begin(),v.end(),5);
  std::vector<int>::iterator it6=std::find(v.begin(),v.end(),7);
  
  if((it!=v.end() && it2!=v.end() && it3!=v.end())||(it4!=v.end() && it5!=v.end() && it6!=v.end())||f){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }






}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using P = pair<int,int>;
//Write From this Line
const int inf = 1e9;
vector<int> dp(100100, inf);
vector<int> dp2(100100, inf);

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n){
		cin>>a[i];
		a[i]--;
	}
	vector<int> b(n+1);
	rep(i,n){
		b[a[i]] = i;
	}
	ll res = 1, cnt = 1;
	rep(i,n) {
		if (b[i+1] > b[i]) {
			cnt++;	
		}
		else {
			res = max(res,cnt);
			cnt = 1;
		}
	}
	cout << n - res << endl;
}


Measured memory_bytes: 2560
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            boolean[] dp = new boolean[k + 1];
            for (int i = 0; i <= k; i++) {
                for (int x : a) {
                    if (i - x >= 0 && !dp[i - x]) dp[i] = true;
                }
            }
            out.println(dp[k] ? "First" : "Second");
        }

    }
}



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

int main(){
    int a, b;
    char op;

    while(1){
        cin >> a >> op >> b;
        switch(op){
            case 43:
                cout << a + b << endl; break;
            case 45:
                cout << a - b << endl; break;
            case 42:
                cout << a * b << endl; break;
            case 47:
                cout << a / b << endl; break;
        }
        if(op == '?') break;
    };
    return 0;
}


Measured memory_bytes: 3064
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

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

int N, M;
int A[302][302];

pair<int, int> simulate(bool choice[302])
{
    int cnts[302];
    fill(begin(cnts), end(cnts), 0);

    FOR(i, 1, N+1) {
        FOR(j, 1, M+1) {
            int sport = A[i][j];
            if(choice[sport]) {
                ++cnts[sport];
                break;
            }
        }
    }

    auto it = max_element(cnts+1, cnts+M+1);
    int idx = 1 + distance(cnts+1, it);
    int cnt = *it;
    return make_pair(idx, cnt);
}

void solve()
{
    bool choice[302];
    fill(begin(choice), end(choice), true);

    auto idxcnt = simulate(choice);
    //cout << idxcnt.second << "\n";
    int result = idxcnt.second;
    for(int m = M; m > 1; --m) {
        choice[idxcnt.first] = false;
        idxcnt = simulate(choice);
        int cnt = idxcnt.second;
        //cout << cnt << "\n";
#if 0
        if(result < cnt) {
            break;
        }
        else {
            result = cnt;
        }
#endif
        if(result > cnt) {
            result = cnt;
        }
    }

    cout << result << "\n";
}

int main()
{
    cin >> N >> M;
    FOR(i, 1, N+1) {
        FOR(j, 1, M+1) {
            cin >> A[i][j];
            //cout << A[i][j] << " ";
        }
        //cout << "\n";
    }

    solve();

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
    int A,B;
    scanf("%d %d",&A,&B);
    if (A==1 && B==2)
    { printf("3");}
    if (A==3 && B==1)
        {printf("2");}
        if(A==2 && B==3)
        { printf("1");
            
        }
    if (A==2 && B==1)
    { printf("3");}
    if (A==1 && B==3)
        {printf("2");}
        if(A==3 && B==2)
        { printf("1");
        }
    return 0;
}


Measured memory_bytes: 128
program polynomial_construction
  implicit none
  integer :: p, a(0:3000) = 0, b(0:3000) = 0, i, j
  integer :: coef(0:3000,0:3000) = 0, f(0:3000) = 0
  integer :: g(0:3000) = 0, h
  read(*,*) p
  read(*,*) a(0:p-1)
  coef(0,0) = 1
  f(0) = 1
  do i = 1, p
    coef(i,1:i) = coef(i-1,0:i-1)
    coef(i,0:i-1) = mod(coef(i,0:i-1)+(p-i)*coef(i-1,0:i-1),p)
    f(i) = mod(i*f(i-1),p)
  end do
  do i = 0, p-1
    if (a(i) == 0) cycle
    h = mod(f(i)*f(p-1-i),p)
    if (mod(p-1-i,2) == 1) h = p-h
    h = inv(h,p)
    g(0:p) = coef(p,0:p)
    do j = p-1, 0, -1
      b(j) = mod(b(j)+h*g(j+1),p)
      g(j) = mod(g(j)+i*g(j+1),p)
    end do
  end do
  write(*,*) b(0:p-1)
contains
  function inv(n,p) result(y)
    integer, intent(in) :: n, p
    integer :: a, b, x, y, t, q
    a = mod(n,p)
    b = p
    x = 0
    y = 1
    do while (b /= 0)
      q = a/b
      t = b
      b = mod(a,b)
      a = t
      t = y
      y = x
      x = t-q*x
    end do
    y = mod(y,p)
    if (y < 0) y = y+p
  end
end program polynomial_construction

Measured memory_bytes: 35200