akhauriyash/Code-Regression huggingface dataset:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

R = I()
print(2 * math.pi * R)

Measured memory_bytes: 27084
import java.util.Scanner;

/**
 * Created by ui on 2016/02/03.
 */
 class XCubic {
     

     static void run () {
        int xc = readInput();
        printCubic(xc);
    }
     static int readInput() {
        Scanner sc = new Scanner(System.in);
        return sc.nextInt();
    }
     static void printCubic (int x){
        System.out.println(x*x*x);
    }
}
public class Main {
    public static void main(String[] args) {
        XCubic.run();
    }
}

Measured memory_bytes: 26240
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1e9 + 7;

// {black, white}
pair<ll, ll> dfs(map<ll, vector<ll> > &adj, ll a, ll parent) {
    ll all_white = 1;              // current node can be colored black
    ll some_black = 0;              // current node cannot be colored black        

    for(ll b: adj[a]) {
        if(b != parent) {
            pair<ll, ll> p = dfs(adj, b, a);
            // p.first is the number of ways to color the subtree such that 'b' is black
            ll orig = all_white;
            all_white = (orig * p.second) % MOD;
            some_black = (orig * p.first) % MOD + (some_black * (p.first + p.second)%MOD) % MOD;
        }
    }

    return {all_white, all_white + some_black};
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	while(t != 0) {
        ll n;
        cin >> n;
        ll a, b;
        map<ll, vector<ll> > adj;
        for(ll i = 0; i < n-1; i++) {
            cin >> a >> b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        pair<ll, ll> p = dfs(adj, 1, -1);
        cout << (p.first + p.second) % MOD << "\n";
	    t--;
	}
	return 0;
}


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

int main()
{
    int N; 
    cin >> N;
    int a[110];
    for (int i = 0; i < N; i++) cin >> a[i];

    int ans = 0;

    for (int i = 0; i < N; i++) {
        int num = 0;
        for (int j = 0; j < N; j++) {
            num = abs(a[i] - a[j]);
            ans = max(ans, num);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< vector< int > > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;
#define VT( T ) vector< T >
#define VVT( T ) vector< vector< T > >
#define LIM( T ) numeric_limits< T >

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) ( c ).begin(), ( c ).end()
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + p, ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

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

	int N;
	cin >> N;

	VI as( N );
	cin >> as;

	VI res( 5 );

	REP( i, 1, N - 1 )
	{
		const int j = find_if_not( as.begin() + i, as.end(), bind( equal_to< int >(), _1, as[i] ) ) - as.begin();
		if ( as[ i - 1 ] == as[i] || N <= j )
		{
			continue;
		}

		if ( as[ i - 1 ] < as[i] && as[i] > as[j] )
		{
			++res[ i + 1 == j ? 3 : 0 ];
		}
		else if ( as[ i - 1 ] > as[i] && as[i] < as[j] )
		{
			++res[ i + 1 == j ? 4 : 1 ];
		}
		else if ( i + 1 < j )
		{
			++res[2];
		}

		i = j - 1;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1524
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

x = abs(ni())
summ = 0
for i in range(10 ** 5):
    summ += i
    if summ >= x:
        print(i)
        exit()


Measured memory_bytes: 3316
import math
import itertools

def solve():
    n = math.factorial(N)
#    print(n)
    arr = [i for i in range(1,N+1)]
    arr = tuple(arr)
#    print(arr)
#    print(P)
    j = 1
    for i in list(itertools.permutations(arr)):
#        print(i)
        if i == tuple(P):
            a = j
            break
        j += 1
    j = 1
    for i in list(itertools.permutations(arr)):
        if i == tuple(Q):
            b = j
            break
        j += 1
    print(abs(a-b))    

if __name__ == "__main__":
    N = int(input())
    P = list(map(int, input().split()))  
    Q = list(map(int, input().split()))
    solve()


Measured memory_bytes: 13792
#include <iostream>
#include <string>
#include <algorithm>
// #include <vector>
// #include <algorithm>
// #include <cmath>
// #include <math.h>
using namespace std;

int main(){
    int N, X;
    cin >> N >> X;
    int a[N];
    for (int i=0; i<N; i++) cin >> a[i];
    sort(a, a + N);
    
    int res = 0;
    for (int i=0; i<N; i++){
        
        if (X >= a[i]){
            ++res;
            X -= a[i];
        } else {
            break;
        }
    } 
    if (N == res && X){
        --res;
    }
    
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#define LL long long
using namespace std;
#define maxn 100007

int x[maxn],y[maxn],t[maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    int n,i,j,k;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
    }
    t[0]=x[0]=y[0]=0;
    bool flag=1;
    for(i=1;i<=n;i++)
    {
        k=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
        if((t[i]-t[i-1])<k||k%2!=(t[i]-t[i-1])%2)
        {
            flag=0;
            break;
        }
    }
    if(flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

using namespace std;

constexpr int MAX = 100003;

int n;
int table[MAX];

int main() {
	cin >> n;
	int tmp;
	for (int i = 0; i < n; ++i) {
		cin >> tmp;
		table[tmp]++;
		table[tmp + 1]++;
		table[tmp - 1]++;
	}
	int ans = 0;
	for (int i = 0; i < MAX; ++i) {
		ans = max(ans, table[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
// In His Name

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define gcd __gcd
#define int long long
#define ull unsigned long long

using namespace std;

typedef pair<int, int> pii;

const int MAX = 500, INF = 1e18;
int n, a[MAX], PartialSum[MAX], dp[MAX][MAX];

main (){
	/*cin >> n;
	vector <int> v;
	for (int i = 0 ; i < n ; i++){
		int x;
		cin >> x;
		v.pb(x);
	}
	sort (v.begin() , v.end());
	while (v.size() > 1){
		/*for (auto u : v){
			cout << u << " ";
		}
		cout << endl;
		int x = v[0] + v[1];
		sum += x;
		v.erase(v.begin());
		v.erase(v.begin());
		v.pb(x);
		sort (v.begin() , v.end());
	}
	cout << sum;*/
	cin >> n;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i];
	}
	for (int i = 1 ; i <= n ; i++){
		PartialSum[i] = a[i - 1] + PartialSum[i - 1];
	}
	for (int i = 1 ; i < n ; i++){
		for (int l = 0 ; l + i < n ; l++){
			int r = l + i;
			if (r == l + 1){
				dp[l][r] = a[l] + a[r];
				continue;
			}
			dp[l][r] = INF;
			for (int j = l ; j < r ; j++){
				//cout << l << " " << r << " " << dp[l][r] << " " << dp[l][j] + dp[j + 1][r] + PartialSum[r + 1] - PartialSum[l] << endl;
				dp[l][r] = min (dp[l][r] , dp[l][j] + dp[j + 1][r] + PartialSum[r + 1] - PartialSum[l]);
			}
		}
	}
	/*for (int i = 0 ; i < n ; i++){
		for (int j = i + 1 ; j < n ; j++){
			cout << i << " " << j << " " << dp[i][j] << endl << endl;
		}
	}*/
	cout << dp[0][n - 1];
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)){
		cout << "Yes" << endl;
	}else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
LL a[SIZE],b[SIZE];
int main(){
    LL K;
    cin>>K;
    int N=50;
    REP(i,N)b[i]=49+K/N;
    REP(i,K%N){
        b[i]+=N;
        REP(j,N){
            if(i!=j)b[j]--;
        }
    }
    printf("%d\n",50);
    REP(i,N)printf("%lld%c",b[i]," \n"[i==N-1]);
    return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextLine() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(nextLine())
	if e != nil {
		panic(e)
	}
	return i
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func sumSlice(nums []int) int {
	sum := 0
	for _, n := range nums {
		sum += n
	}
	return sum
}

func binarySearch(idxB, idxC int, nums []int) int {
	c := nums[idxC]
	b := nums[idxB]
	minLength := c - b + 1

	left := 0
	right := idxB
	list := nums[:idxB]
	mid := (left + right) / 2

	for {
		if list[mid] < minLength {
			left = mid + 1
		} else {
			right = mid
		}
		mid = (left + right) / 2
		if left >= right {
			break
		}
	}
	total := idxB - mid
	return total
}

func main() {
	scanner.Split(bufio.ScanWords) // switch to separating by space
	// scanner.Buffer([]byte{}, 1000000009) // switch to read large size input
	N := nextInt()
	nums := scanNums(N)
	sort.Ints(nums)

	idxC := 0
	idxB := 0
	total := 0

	for i := 0; i < N-2; i++ {
		idxC = N - i - 1
		for j := i + 1; j < N-1; j++ {
			idxB = N - j - 1
			total += binarySearch(idxB, idxC, nums)
		}
	}

	fmt.Println(total)
}


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

int main(){
    ll n;
    string s;
    cin >> n;
    if(n<=9){cout << n << endl; return 0;}
    s = to_string(n);
    bool flg9 = true;
    for(int i = 0; i < s.size(); i++){
        if(i != 0 && s[i] != '9'){flg9 = false;}
    }
    int ans = 0;
    if(flg9){
        ans = (int)(s[0]-'0')+9*(s.size()-1);
    }else{
        ans = ((int)(s[0]-'0')-1)+9*(s.size()-1);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
 
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
vector<int> adj[50];
int power[50];
ll used;
int ans, rest, sum;
int N;
vector<int> per;
void dfs(int k_){
  if(k_ == N){
    ans = max(ans,  sum);
    return ;
  }
  int k = per[k_];
  //printf("%d:%d %d %d\n", k,sum , rest, ans);
  if(sum + rest <= ans){
    return;
  }
  ll usedtmp = used;
  int sumtmp = sum;
  int resttmp = rest;
  if(!(used >> k & 1)){
    used |= 1LL << k;
    sum += power[k];
    rest -= power[k];
    FORIT(it, adj[k])if(!(used >> (*it) & 1)){
      rest -= power[*it];
      used |= 1LL<<(*it);
    }
    dfs(k_ + 1);
    used = usedtmp;
    sum = sumtmp;
    rest = resttmp;
  }
  if(k != 0){
    if(!(used >> k & 1))rest -= power[k];
    used |= 1LL << k;
    dfs(k_ + 1);
  }
}
 
typedef pair<int, int> P;
int main(){
  while(cin>>N && N){
    ans = 0, rest = 0, sum = 0;
    REP(i, 50) adj[i].clear();
    used = 0;
    map<string, int> id;
    vector<string> adjstr[50];
    REP(i, N){
      string s; cin>>s; id[s] = i;
      cin>>power[i];
      rest += power[i];
      int k; cin>>k;
      while(k--){
        string str; cin>>str;
        adjstr[i].push_back(str);
      }
    }
    REP(i, N){
      REP(j, adjstr[i].size()){
        adj[i].push_back(id[adjstr[i][j]]);
      }
    }
    vector<P> ps(N-1);
    REP(i, N-1)ps[i] = P(-power[i+1], i+1);
    sort(ps.begin(), ps.end());
    per = vector<int>(N, 0);
    REP(i, N-1) per[i+1] = ps[i].second;
    used = 0;
    dfs(0);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1384
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define ll long long
#define maxn 100006
using namespace std;
ll ans=0;int n;
struct li{
	ll v;
	int lo;
	int san;
}mmp[maxn];
bool cmp(li a,li b){
	return a.v<b.v;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%lld",&mmp[i].v);
		mmp[i].lo=i;
	}
	sort(mmp+1,mmp+1+n,cmp);
	for(int i=1;i<=n;i++)mmp[i].san=i;
	for(int i=1;i<=n;i++){
		if(abs(mmp[i].san-mmp[i].lo)%2==1)ans++;
	}
	cout<<ans/2;
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N;
    ll sum = 0;
    vector<ll> A;
    cin >> N;
    A.resize(3 * N);
    for(ll i = 0;i < 3 * N;i++) cin >> A[i];
    sort(A.begin(), A.end(), greater<>());
    for(ll i = 1;i < 2 * N;i += 2) sum += A[i];
    cout << sum << endl;
    return 0;
}


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

int main()
{
    string T;
    cin >> T;

    int ans = 0;
    for (size_t i = 0; i < T.size(); i++)
    {
        if (T[i] == '?')
        {
            T[i] = 'D';
        }
        if (T[i] == 'D')
        {
            ans++;
        }
    }
    cout << T << endl;
}


Measured memory_bytes: 3732
#include<stdio.h>

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

int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	printf("%d\n", gcd(a ,b));
	return 0;
}

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

int main(void){

    int H,W;
    cin >> H >> W;
    string S[H];

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

    long score=0;

    int o_c[H];
    int i_c[W];
    for(int i=0;i<H;i++) o_c[i]=0;
    for(int i=0;i<W;i++) i_c[i]=0;
    
    for(int i=H-1;i>=0;i--){
        for(int j=S[i].size()-1;j>=0;j--){

            if(S[i][j]=='J'){
                score+=o_c[i]*i_c[j];
            }else{
                if(S[i][j]=='O') o_c[i]++;
                if(S[i][j]=='I') i_c[j]++;
            }
        }
    }
    
    cout << score << endl;

}



Measured memory_bytes: 24060
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
 
const int MOD = 998244353;
 

void solve() {
    int N, S; cin >> N >> S;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
 
    vector<vector<long long>> dp(N+1, vector<long long>(S+1));
 
    dp[0][0] = 1;

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= S; j++) {
            if (j - A[i-1] >= 0) {
                dp[i][j] += dp[i-1][j-A[i-1]];
                dp[i][j] %= MOD;
            }
            dp[i][j] += dp[i-1][j] * 2;
            dp[i][j] %= MOD;
        }
    }
 
    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j < S+1; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
 
    cout << dp[N][S] << endl;
}
 
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 73612
b,e = map(int,input().split())
r = [0]*1000
for _ in range(int(input())):
 b1,e2 =map(int,input().split())
 for x in range(b1,e2):
     r[x] = 1
def check():
 for x in range(b,e):
   if r[x] ==1:
     return 1
 return 0
print(check())


Measured memory_bytes: 5600
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		// input
		Scanner inData = new Scanner(System.in);

		// 文字列入力
		String S = inData.nextLine();

		System.out.println(S.substring(0, 3));

		// input close
		inData.close();
	}
}


Measured memory_bytes: 26864
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    E = []
    G = defaultdict(list)
    for i, s in enumerate(S):
        for j, c in enumerate(s[:]):
            if i < j and c == '1':
                E.append((i, j))
                G[i].append(j)
                G[j].append(i)
    
    def f(s):
        e = set(E)
        vs = [set([s])]
        while e:
            vs1 = set()
            for i in vs[-1]:
                for j in G[i]:
                    vs1.add(j)
                    if i > j:
                        u, v = j, i
                    else:
                        u, v = i, j
                    if (u, v) in e:
                        e.remove((u, v))
            vs.append(vs1)
            for i in vs[-1]:
                for j in G[i]:
                    if j in vs[-1]:
                        return -1

        return len(vs)

    ans = -1
    for i in range(N):
        ans = max(ans, f(i))
    return ans


def main():
    N = read_int()
    S = [read_str() for _ in range(N)]
    print(slv(N, S))

if __name__ == '__main__':
    main()


Measured memory_bytes: 86360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#include <atcoder/segtree>

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int INF = 1e9;
const int MAXA = 300000;

int ident() {
   return -INF;
}

int merge(int x, int y) {
   return max(x, y);
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N, K;
   cin >> N >> K;

   VI A(N);
   REP(i, N)
      cin >> A[i];

   atcoder::segtree<int, merge, ident> ST(MAXA+1);

   REP(i, N) {
      int a = A[i];
      int L = max(a-K, 0);
      int R = min(a+K, MAXA);
      int DP_i = 1 + ST.prod(L, R+1);
      if (DP_i <= 0)
         DP_i = 1;
      ST.set(a, DP_i);
   }

   int res = ST.all_prod();
   cout << res << endl;

   return 0;
}


Measured memory_bytes: 9800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    V<> p(n);
    cin >> p;
    int ans = 0;
    srepn(i, 1, n - 2) {
        if((p[i - 1] < p[i]) ^ (p[i] > p[i + 1])) ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3712
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

r_monster = 0
monster_cnt = 0

if A[-1] > B[-1]:
    monster_cnt += B[-1]
    B[-1] = 0
else:
    monster_cnt += A[-1]
    B[-1] -= A[-1]
for a, b in zip(reversed(A[:-1]), reversed(B)):
    if a+r_monster > b:
        monster_cnt += b
        r_monster = min(a+r_monster - b, a)
    else:
        monster_cnt += a+r_monster
        r_monster = 0

print(monster_cnt)


Measured memory_bytes: 73444
N, M = map(int, input().split())
Xlist = sorted(list(map(int, input().split())))
sbn = sorted([abs(Xlist[i + 1] - Xlist[i]) for i in range(M - 1)])[::-1]
if N >= M:
    print(0)
else:
    print(sum(sbn[N - 1:]))


Measured memory_bytes: 13968
A, B, C, X, Y = map(int, input().split())
C *= 2

ans1 = A*X + B*Y
ans2 = C*max(X,Y)

ans3 = C*min(X,Y)
if X < Y:
    ans3 += (Y-X)*B
else:
    ans3 += (X-Y)*A

#print(ans1, ans2, ans3)
print(min(ans1, ans2, ans3))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
  const char* dlm = "";
  for(const auto& x:v) os << exchange(dlm, " ") << x;
  return os;
}
int32_t main(){
  const size_t MAX=1e5+1;
  array<bool,MAX> isprime;
  for(size_t i=0; i<MAX; i+=2){
    isprime[i]=false; isprime[i+1]=true;
  }
  isprime[1]=false; isprime[2]=true;
  for(size_t i=3; i<sqrt(MAX); i+=2){
    if(isprime[i]){
      for(size_t j=i+i; j<MAX; j+=i){
        isprime[j]=false;
      }
    }
  }
  // for(const auto& x:isprime) cout<<x<<' ';

  array<size_t,MAX> n; fill(begin(n),end(n),0);
  for(size_t i=1; i<MAX; i+=2){
    if(isprime[i]&&isprime[(i+1)/2]) n[i]=1;
  }
  array<size_t,MAX+1> s; s[0]=0;
  for(size_t i=1; i<MAX+1; ++i) s[i]=s[i-1]+n[i-1];
  size_t q,l,r; cin>>q;
  for(size_t i=0; i<q; ++i){
    cin>>l>>r;
    cout<<(s[r+1]-s[l])<<'\n';
  }
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int p[51];
int d[51];
int main(){
    int n;
    cin >> n;
    reps(i,n){
        cin >> p[i];
        d[i]= i;
    }
    int cnt =0;
    reps(i, n){
        if(d[i]!=p[i])cnt++;
    }
    if(cnt > 2) cout << "NO" << endl;
    else cout << "YES" << endl;
}



Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    string S; cin >> S;
    int cost1 = 0;
    int cost2 = 0;

    REP(i,S.length())
    {
        if(i % 2 == 0)
        {
            if(S[i] != '0') cost1++;
        }
        else
        {
            if(S[i] != '1') cost1++;
        }
    }

    REP(i,S.length())
    {
        if(i % 2 == 0)
        {
            if(S[i] != '1') cost2++;
        }
        else
        {
            if(S[i] != '0') cost2++;
        }
    }
    cout << min(cost1,cost2) << endl;



}


Measured memory_bytes: 512
import math
x = int(input())
lis = [1]
for i in range(2, int(math.sqrt(x))+1):
    j = 2
    sample = 0
    while i ** j <= x:
        sample = i ** j
        j += 1
    if sample != 0:
        lis.append(sample)
print(max(lis))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <iomanip>

using namespace std;
typedef long long ll;

int main(){
    int n, m;
    int ans = 0;
    cin >> n >> m;
    vector<int> x(n), a(m), b(m);
    for (int i = 0; i < n; i++) {
        x[i] = i + 1;
    }
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
    }
    do {
        int cnt = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (((x[i - 1] == a[j]) && (x[i] == b[j])) || ((x[i - 1] == b[j]) && (x[i] == a[j]))) {
                    cnt++;
				}
            }
        }
        if (cnt == n - 1) {
            ans++;
        }
    } while (next_permutation(x.begin() + 1, x.end()));

    cout << ans << endl;

    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] > c[i]) {
            ans += v[i] - c[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// kyopro.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define rep(N) for(int i=0;i<N;i++)
#define rep2(N1,N2) for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)for(int k=0;k<N3;k++)
#define For(i,N) for(int i=0;i<N;i++)
void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int main(){
	long int X;
	cin >> X;
	int a = 0;
	a = X / 500;
	cout << a * 1000 + ((X - a*500)/5)*5;

}

Measured memory_bytes: 256
#include<stdio.h>
 int main(void)
 {
     int X,Y;
     int i,j=0,A=0;

     scanf("%d%d",&X,&Y);

     if((Y%2==0)&&(Y/2==X)) { printf("Yes\n"); return 0; }
     else if((Y%4==0)&&(Y/4==X)) { printf("Yes\n"); return 0; }
     else if(Y%2==0){
         for(i=1;i<=1000;i++){
           if(Y-4*i<0) { printf("No\n"); return 0; }
           if(Y-4*i>0) j++;
           A=(Y-4*i)/2;
           if(j+A==X) { printf("Yes\n"); return 0; }
         }
       }

     else printf("No\n");

     return 0;
 }



Measured memory_bytes: 1636
#!/usr/local/bin/ruby
while line=gets
  a=line.to_i
  w=a.to_s(2)
  rec=Array.new
  y=w.split("").map(&:to_i).reverse
  l=y.size
  (l-1).downto(0){|i|
    if y[i]==1
      rec.unshift(2**i)
    end
  }
  puts rec.join(" ")
end

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

using namespace std;

struct Edge
{
	int st, ed;
};

Edge a[100010];

int n, m, ans;

bool cmp(Edge x, Edge y)
{
	if (x.ed == y.ed)
		return x.st < y.st;
	else
		return x.ed < y.ed;
}

int main(int argc, char ** argv)
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
		cin >> a[i].st >> a[i].ed;
	sort(a + 1, a + m + 1, cmp);
	int Cur = 0;
	for (int i = 1; i <= m; i++)
	{
		if (a[i].st >= Cur)
		{
			ans++;
			Cur = a[i].ed;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			final int X = sc.nextInt();
			
			long[] cs = new long[N];
			long[][] as = new long[N][M];
			
			for(int i = 0; i < N; i++) {
				cs[i] = sc.nextLong();
				for(int j = 0; j < M; j++) {
					as[i][j] = sc.nextLong();
				}
			}
			
			long answer = Long.MAX_VALUE;
			long[] values = new long[M];
			
			for(int bit = 0; bit < (1 << N); bit++) {
				long sum = 0;
				Arrays.fill(values, 0);
				
				for(int item = 0; item < N; item++) {
					if((bit & (1 << item)) == 0) { continue; }
					
					sum += cs[item];
					for(int j = 0; j < M; j++) {
						values[j] += as[item][j];
					}
				}
				
				final long min = Arrays.stream(values).min().getAsLong();
				if(min >= X) { answer = Math.min(answer, sum); }
			}
			
			if(answer >= Long.MAX_VALUE) { answer = -1; }
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 36964
from collections import deque
n=int(input())
a=[]
for i in range(n):
    a.append(deque(map(lambda x:int(x)-1,input().split())))

nofrag=False
last=[0]*n
for i in range(n):
    stack=[(i,j) for j in list(a[i])[::-1]]
    check=[0]*n
    while stack:
        me,to=stack[-1]
        if a[to][0]==me:#お互いにpop
            a[to].popleft()
            a[me].popleft()
            day=max(last[me],last[to])+1
            last[to]=day
            last[me]=day
            stack.pop()
            check[me]=0
        else:#stackに追加し、自分のチェックもいれる
            if check[to]:#不可能
                nofrag=True
                break
            check[me]=1
            stack.append((to,a[to][0]))
    if nofrag:
        break

if nofrag:
    print(-1)
else:
    print(max(last))

Measured memory_bytes: 77148
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7


def mod_pow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        half_p = p // 2
        half = mod_pow(a, half_p)
        return half * half % mod
    else:
        return a * mod_pow(a, p - 1) % mod


ans = 0
for i in range(60):
    cnt = 0
    for a in A:
        if a >> i & 1:
            cnt += 1
    now = cnt * (N - cnt) % mod
    ans += now * mod_pow(2, i) % mod
    ans %= mod
print(ans)


Measured memory_bytes: 122808
#include <bits/stdc++.h>
#include <iostream>	
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(2e9);
const int mod = inf + 7;
using namespace std;

void solve()
{	
	int n, k;
	cin >> n >> k;
	cout << max(0, n - k + 1);
}

int main()
{
	Red;
	solve();
	return 0;
}

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

typedef long long int ll;

vector <ll> input;

int main()
{
	ll i,j,k,l,m,n,u,v;
	
	cin >> n >> k;

	for(i=0;i<n;i++)
	{
		cin >> l;
		input.push_back(l);
	}

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

	ll ans = 0;
	for(i=0;i<k;i++)
	{
		ans += input[i];
	}

	cout << ans << '\n';


}

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

int main(){
  int H,W;
  while(cin>>H>>W){
    if(H==0&&W==0) break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if(i==0||j==0||i==H-1||j==W-1)
	  cout<<'#';
	else
	  cout<<'.';
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3016
from itertools import product
n, m = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(n)]


ans = 0
for subset in product((-1, 1), repeat=3):
    INF = 10**18
    dp = [-INF]*(n+1)
    dp[0] = 0

    def func(xyz):
        return sum(x*a for x, a in zip(xyz, subset))

    values = list(map(func, xyz))
    for i, val in enumerate(values, 1):
        for j in reversed(range(1, i+1)):
            dp[j] = max(dp[j-1]+val, dp[j])
    if ans < dp[m]:
        ans = dp[m]

print(ans)

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

int main() {
  int N;
  cin >> N;
  int x = 0;
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    if (p != i + 1)
      x++;
  }
  if (x < 3)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::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
 


#define M 100010


int main(){
	IOS;
	tihs;

	
	ll n,k;cin>>n>>k;
	ll a[k],s=0;
	rep(i,0,k)cin>>a[i],s+=a[i];
	ll dif=n-s;
	if(dif<0)cout<<"-1";
	else cout<<dif;

	return 0;
}

Measured memory_bytes: 3692
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>
#include<cmath>

#define REP(i,n) for(int i=0;i<n;i++)
#define ll long long int

using namespace std;

int to_int(string s) {
  return atoi(s.c_str());
}

int main() {
  ll n;
  cin >> n;
  string s = "";

  if(n == 0) {
    cout << "0" << endl;
    return 0;
  }
  ll base = 1;
  ll m = 0;
  while(n != m) {
    ll tmp = n-m;
    if(abs(tmp)%(abs(base)*2) != 0) {
      s = "1" + s;
      m += base;
    } else {
      s = "0" + s;
    }
    base *= -2;
  }
  cout << s << endl;


}


Measured memory_bytes: 256
#!/mnt/c/Users/moiki/bash/env/bin/python
sx,sy,tx,ty = map(int, input().split())

ans = ""

#UP
ans += "U" * (ty-sy)
ans += "R" * (tx-sx)
ans += "D" * (ty-sy)
ans += "L" * (tx-sx)
ans += "L" + "U"* (ty-sy+1) + "R" * (tx-sx+1) + "D"
ans += "R" + "D" * (ty-sy+1) + "L"*(tx-sx+1) + "U"

print(ans)



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

int main(){
	string s;
	int r = 0;
	int l = 0;
	bool countR = true;
	bool countL = false;
	int idx = 0;
	
	getline(cin, s, '\n');
	int len = s.length();
	int data[len];

	for (int i = 0; i < len; i++){
		data[i]=0;
	}

	for (int i = 0; i < len; i++)
	{
		if(countR){
			if(s[i]=='R'){
				r++;
			}else{
				countR = false;
				countL = true;
				idx = i-1;
				l++;
			}
		}else{
			if(s[i]=='L'){
				l++;
			}else{
				countR = true;
				countL = false;
				
				data[idx]+=(int) r/2;
				data[idx+1]+=(int) r/2;
				if(r%2){
					data[idx]++;
				}

				data[idx] += (int) l/2;
				data[idx+1] += (int) l/2;
				if(l%2){
					data[idx+1]++;
				}

				l = 0;
				r = 1;	
			}
		}
		if(i==len-1){
			data[idx]+=(int) r/2;
			data[idx+1]+=(int) r/2;
			if(r%2){
				data[idx]++;
			}

			data[idx] += (int) l/2;
			data[idx+1] += (int) l/2;
			if(l%2){
				data[idx+1]++;
			}
		}
	}
	for (int i = 0; i < len; i++){
		printf("%d ", data[i]);
	}
	printf("\n");
}

Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int N, M, X;
vector<int> C;
vector<vector<int>> A(N,vector<int>(M));

void dfs(vector<int> buy,int &ans) {
  if(buy.size()==N) {
    vector<int> res(M);
    int price=0;
    rep(i,N) {
      if(buy[i]) {
        price+=C[i];
        rep(j,M) res[j]+=A[i][j];
      }
    }
    bool flag=true;
    rep(j,M) {
      if(res[j]<X) flag=false;
    }
    if(flag) ans=min(ans,price);
    return;
  }
  buy.push_back(0);
  dfs(buy,ans);
  buy.pop_back();
  buy.push_back(1);
  dfs(buy,ans);
}

int main() {
  cin >> N >> M >> X;
  C=vector<int>(N);
  A=vector<vector<int>>(N,vector<int>(M));
  rep(i,N) {
    cin >> C[i];
    rep(j,M) cin >> A[i][j];
  }
  int ans=INF;
  dfs({},ans);
  if(ans==INF) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

signed main () {
    int n;cin >> n;
    ll ans = n + n*n + n*n*n;
    cout << ans << endl;
}//https://atcoder.jp/contests/abc172/tasks/abc172_a

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

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<int> pque;
    rep(i, n) {
        int a; cin >> a;
        pque.push(a);
    }

    rep(i, m) {
        int t = pque.top()/2;
        pque.pop();
        pque.push(t);
    }

    ll ans = 0;
    rep(i, n) {
        ans += pque.top();
        pque.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int A[N];
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  
  bool finish = 0;
  for(int i = 0; ; i++){
    for(int j = 0; j < N; j++){
    	if(A[j] % 2 == 0){
          A[j] /= 2;
        }else{
          finish = 1;
          break;
        }
    }
    if(finish){
      cout << i << endl;
      break;
    }
  }
}

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

ll MOD = 1e9+7;

int main(){
    ll N; cin >> N;
    ll l = 0, r = N, m;

    cout << 0 << endl;
    string S; cin >> S;
    if(S == "Vacant") return 0;
    /*cout << N-1 << endl;
    string _; cin >> _;
    if(_ == "vacant") return 0;*/

    while(1){
        m = (l+r)/2;
        cout << m << endl;
        string T; cin >> T;
        if(T == "Vacant") return 0;
        if((m%2&&S!=T)||(m%2==0&&S==T)) l = m+1;
        /*if(((m)% 2 == 0 && S == T) || ((m)%2 == 1 && S != T)){
            l = m+1;
        }*/
        else{
            r = m;
        }
    }
}

Measured memory_bytes: 852
#include <stdio.h>
#include <math.h>

int is_prime(int a)
{
    int sqrt_a = (int)sqrt(a);
    int i;
    if(a == 1){
        return 0;
    }
    for(i = 2; i <= sqrt_a; i++){
        if(a % i == 0){
            return 0;
        }
    }
    return 1;
}

int main(void)
{
    int x;
    scanf("%d", &x);
    int ans = x;
    while(!is_prime(ans)){
        ans++;
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<long long int>v(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
		v[i] += v[i - 1];
	}
	long long int ans = MOD * MOD;
	for (int i = 0; i <= N; i++) {
		ans = min(ans, abs(v[N] - v[i] * 2));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792