akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
int a[55];
bool check1(int n){
    for(int i=1;i<=n;i++){
        if(a[i]<=0) continue;
        return false;
    }
    return true;
}
bool check2(int n){
    for(int i=1;i<=n;i++){
        if(a[i]>=0) continue;
        return false;
    }
    return true;
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    if(check1(n)){
        cout<<n-1<<endl;
        for(int i=n-1;i>=1;i--){
            cout<<i+1<<" "<<i<<endl;
        }
    }
    else if(check2(n)){
        cout<<n-1<<endl;
        for(int i=1;i<=n-1;i++){
            cout<<i<<" "<<i+1<<endl;
        }
    }
    else{
        int maxx=-1000005,minn=1000005;
        int tmp1=0,tmp2=0;
        for(int i=1;i<=n;i++){
            if(maxx<a[i]){
                maxx=a[i];
                tmp1=i;
            }
            if(minn>a[i]){
                minn=a[i];
                tmp2=i;
            }
        }
        if(abs(maxx)>=abs(minn)){
            cout<<2*n-1<<endl;
            for(int i=1;i<=n;i++){
                cout<<tmp1<<" "<<i<<endl;
            }
            for(int i=1;i<=n-1;i++){
                cout<<i<<" "<<i+1<<endl;
            }
        }
        else{
            cout<<2*n-1<<endl;
            for(int i=1;i<=n;i++){
                cout<<tmp2<<" "<<i<<endl;
            }
            for(int i=n-1;i>=1;i--){
                cout<<i+1<<" "<<i<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
N, K = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

a = [p[0]]
for i in range(1,N):
    a += [a[i-1] + p[i]]

ans =0
if N-K>0:
    for i in range(N-K):
        ans = max(a[i+K] - a[i], ans)
else:
    ans = a[-1]
print("{0:.8f}".format((ans+K)*0.5))


Measured memory_bytes: 25316
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;

int main(){
    int n;
    cin >> n;
    double ans = 0.0;
    REP(i, n){
        double x;
        string str;
        cin >> x >> str;
        if (str == "JPY") ans += x;
        else if (str == "BTC") ans += x * 380000.0;
    }
    cout << (double)ans << "\n";
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s, t, u string
	var a, b int
	fmt.Scan(&s, &t, &a, &b, &u)

	if s == u {
		fmt.Println(a-1, b)
	} else if t == u {
		fmt.Println(a, b-1)
	}
}


Measured memory_bytes: 512
K = int(input())


import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
                ans += gcd(i,j,k)
print(ans)

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

void solve(long long A, long long B){
    int ans = 0;

    for (int i = A; i <= B; i++) {
        string str = to_string(i);
        string tmp = str;
        reverse(tmp.begin(), tmp.end());
        if (str == tmp)
            ans++;
    }

    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def main():
    N, M = map(int, readline().rstrip().split())
    ans = 1
    for d in  make_divisors(M):
        if M // d >= N:
            ans = d
        else:
            break

    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
  int n, p, w, g, y;
  string s;
  p = 0;
  w = 0;
  g = 0;
  y = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> s;
    if( s == "P")
      p = 1;
    if( s == "W")
      w = 1;
    if( s == "G")
      g = 1;
    if( s == "Y")
      y = 1;
  }
  int Type;
  Type = p + w + g + y;
  if ( Type == 3 )
    cout << "Three" << endl;
  if ( Type == 4 )
    cout << "Four" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
 public static void main(String[] args) {
 // 標準入力からデータを読み込む準備
 Scanner sc = new Scanner(System.in);
 // 3つの文字の固まりをそれぞれ整数値と想定して読み込む
 int a = sc.nextInt();
 int b = sc.nextInt();
 int c = sc.nextInt();
 if (a < b) {
  if (b < c) {
   System.out.printf("%d %d %d", a, b, c);
   System.out.println();
  } else if (a < c) {
  System.out.printf("%d %d %d", a, c, b);
   System.out.println();
  } else {
  System.out.printf("%d %d %d", c, a, b);
   System.out.println();
  }
 }
 else {
  if (a < c) {
   System.out.printf("%d %d %d", b, a, c);
   System.out.println();
  }
  else if (b < c) {
  System.out.printf("%d %d %d", b, c, a);
  System.out.println();
  }
  else {
  System.out.printf("%d %d %d", c, b, a);
  System.out.println();
  }
 }
}
}


Measured memory_bytes: 26256
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	int m;
	cin>>m;
	cout<<48-m;
	re 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <ctype.h>

int main()
{
    int a,b;
    std::string s;

    std::cin >> a;
    std::cin >> b;
    std::cin >> s;

    if(s[a] == '-' && s.length() == a + b + 1)
    {
        s.erase(a,1);

        for(const auto n : s)
        {
            if(!isdigit(n))
            {
                std::cout<<"No"<<std::endl;
                return 0;
            }
        }

        std::cout<<"Yes"<<std::endl;
    }
    else std::cout<<"No"<<std::endl;
}

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

int main(){
  int n,m,c;
  cin>>n>>m>>c;
  int b[m];
  rep(i,0,m){
    cin>>b[i];
  }
  int ans=0;
  rep(i,0,n){
    int a[m];
    rep(i,0,m){
      cin>>a[i];
    }
    int cur=0;
    rep(i,0,m){
      cur+=a[i]*b[i];
    }
    if(cur+c>0){
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

int main(){
    ll n , a, b;
    cin >> n >> a >> b;
    ll q = n/(a+b);
    ll r = n % (a+b);
    ll ans = 0;
    ans = a*q + ((r < a) ? r : a); 
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<int>a(n);

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

	int m; cin >> m;

	int ans = 1;
	for (int i = 0; i < m; i++) {
		int b; cin >> b;

		ans*=binary_search(a.begin(), a.end(), b);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<queue>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

#define REP(i,n) for(int i = 0;i<n;i++)
int vec1[]={0,1,-1,1,-1,0};
int vec2[]={1,1,0,0,-1,-1};

int t,n;
int table[200][200];

typedef pair<int,int> pii;
typedef pair<int,pii> piii;

int ans;

int solve(int y,int x){
	queue<piii> q1;
	q1.push(make_pair(0,make_pair(y,x)));
	while(!q1.empty()){
		if(t <= q1.front().first)
			return 0;
		REP(i,6){
			int n_y = q1.front().second.first + vec1[i];
			int n_x = q1.front().second.second + vec2[i];
			if(table[n_y][n_x] == 0){
				ans++;
				table[n_y][n_x] = 1;
				q1.push(make_pair(q1.front().first + 1,make_pair(n_y,n_x)));
			}
		}
		q1.pop();
	}
	return 0;
}


int main(){
	while(cin>>t>>n,t+n){
		ans = 0;
		fill_n(table[0],200*200,0);
		REP(i,n){
			int x,y;
			cin>>x>>y;
			table[100+y][100+x] = 1;
		}
		int x,y;
		cin>>x>>y;
		table[100+y][100+x] = 1;
		solve(100+y,100+x);
		cout<<ans+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3252
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll K;
    cin >> K;
    vector<ll> A(K);
    for(int i=0;i<K;i++) cin >> A[i];

    ll ma=2,mi=2;
    for(int i=K-1;i>=0;i--){
        if(ma<A[i] || mi>ma){
            cout << -1 << endl;
            return 0;
        }
        ma=A[i]*(ma/A[i]) + A[i]-1;
        mi=A[i]*(mi/A[i]+(mi%A[i]!=0));
    }
    if(mi>ma){
        cout << -1 << endl;
        return 0;
    }
    cout << mi << " " << ma << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <iomanip>


int main()
{
	long long n;
	std::string s;

	std::cin >> n;

	if (n < 1200) {
		std::cout << "ABC" << std::endl;
	} else {
		std::cout << "ARC" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    int h,w;
    cin>>h>>w;
    string s[h];
    rep(i,h){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        rep(abababa,2){
            cout<<s[i]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()


Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;
int min(int a,int b){
    return a<b?a:b;
}
int main(void){
    int N;
    cin >> N;
    cout << (N+1) / 2 << endl;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=5e5,inf=1e9;
int bit[26][N+2];
void upd(int i,int x,int vl)
{
  for( ;x<=N;x+=x&-x)bit[i][x]+=vl;
}
int get(int i,int x)
{
  int ret=0;
  for( ;x>0;x-=x&-x)ret+=bit[i][x];
  return ret;
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n;cin>>n;string s;cin>>s;
  for(int i=1;i<=n;i++)
  {
    int c=s[i-1]-'a';upd(c,i,1);
  }
  //cout<<"here"<<endl;
  int q;cin>>q;
  while(q--)
  {
    int ty;cin>>ty;
    if(ty==1)
    {
      int id;cin>>id;char ch;cin>>ch;

      upd(s[id-1]-'a',id,-1);s[id-1]=ch;
      upd(s[id-1]-'a',id,1);
    }
    else
    {
      int l,r;cin>>l>>r;
      int cnt=0;
      for(int i=0;i<26;i++)
        cnt+=(bool)(get(i,r)-get(i,l-1));
      cout<<cnt<<"\n";
    }
  }
  return 0;
}

Measured memory_bytes: 51740
def main():
        
    import numpy as np

    N = int(input())
    numbers = list(map(int, input().split()))

    np_numbers = np.array(numbers, np.int64)

    module = 10 ** 9 + 7

    cumsum = np.cumsum(np_numbers)
    cumsum.tolist()
    summ = cumsum[-1]
    ans = 0

    for i in range(N):
        tmp = (summ - cumsum[i]) % module
        ans += ((np_numbers[i] % module) * tmp) % module
        
        ans %= module
        
        
        

    ans %= module

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49716
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H, W;
	scanf("%d", &H);
	scanf("%d", &W);

	ll dp[1001];
	dp[0] = 1;
	char A[1001];
	scanf("%s", A);
	rep1(w, W - 1) dp[w] = (A[w] == '.' ? dp[w - 1] : 0);

	rep1(h, H - 1) {
		scanf("%s", A);
		dp[0] = (A[0] == '.' ? dp[0] : 0);
		rep1(w, W - 1) {
			dp[w] = (A[w] == '.' ? dp[w] + dp[w - 1] : 0);
			if ((h + w) % 30 == 0) dp[w] %= mod;
		}
	}
	printf("%d", dp[W - 1] % mod);

	Would you please return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"math"
)

var N, cnt int

func main() {
	fmt.Scan(&N)
	T := make([]uint64, N)

	for i := 0; i < N; i++ {
		fmt.Scan(&T[i])
	}
	var ans uint64 = uint64(T[0])

	// x,yの最小公倍数はx*y/gcd(x,y)
	// 具体例
	//   15 = 3*5
	//   24 = 2*2*2*3

	for _, value := range T {
		ans = (ans / gcd(ans, value)) * value
	}
	fmt.Println(ans)
}

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

/*  ----------------------------------------  */

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i][0] == a[j][0] {
		return a[i][1] > a[j][1]
	}
	return a[i][0] > a[j][0]
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int personNum = Integer.parseInt(sc.nextLine());
		List<String> elements = Arrays.asList(sc.nextLine().split(""));
		
		long red_count = elements.stream().filter( s -> s.equals("R") ).count();
		int harfNum = personNum%2 == 0 ? personNum/2 + 1 : (personNum+1)/2;
		String result = harfNum <= red_count ? "Yes" : "No";
		System.out.println(result);
		sc.close();
	}
}


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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<P,int>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e6)+3;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;

vector<ll> fact(MOD), inv(MOD);

ll power(ll x, ll n){
    x %= MOD;
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res*x%MOD;
        }
        x = x*x%MOD;
        n >>= 1;
    }
    return res;
}

ll init(){
    fact[0] = 1;
    inv[0] = 1;
    for(int i=1;i<MOD;i++){
        fact[i] = fact[i-1]*i%MOD;
        inv[i] = power(fact[i], MOD-2);
    }
}

ll solve(ll x, ll d, ll n){
    if(d==0) return power(x,n);
    if(x==0 || n>=MOD) return 0;
    ll y = x*power(d,MOD-2)%MOD;
    if((y+n-1)>=MOD) return 0;
    return power(d,n)*fact[y+n-1]%MOD*inv[y-1]%MOD;
}

int main(){
    init();
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        ll x, d, n;
        cin >> x >> d >> n;
        cout << solve(x,d,n) << endl;
    }
    return 0;
}

Measured memory_bytes: 16512
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

unew :: VU.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.unsafeNew n

uread :: VU.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VU.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

umodify :: VU.Unbox a => Int -> (a -> a) -> VUM.IOVector a -> VUM.IOVector a
umodify !i !f !v =
  accursedUnutterablePerformIO $ VUM.unsafeModify v f i >> return v

uthaw :: VU.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VU.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

solve :: Int -> VU.Vector Int -> Int
solve n hs = uread (n - 1) dp
 where
  -- dp[i]: minimal cost of moving from 1st to i-th place
  dp = VU.foldl'
    (\(!dp) (!i, !v) -> if i == 0
      then uwrite 0 0 dp
      else if i == 1
        then uwrite 1 (uread 0 dp + abs (v - hs VU.! 0)) dp
        else uwrite
          i
          (min (uread (i - 1) dp + abs (v - hs VU.! (i - 1)))
               (uread (i - 2) dp + abs (v - hs VU.! (i - 2)))
          )
          dp
    )
    (unew n)
    (VU.indexed hs)

main = do
  let readInt = fmap (second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  hs <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n hs


Measured memory_bytes: 3580
local read = io.read

local n = read("n")

local four_times_count = 0
local two_times_count = 0
for i = 1, n do
	local a_i = read("n")
	if a_i % 4 == 0 then
		four_times_count = four_times_count + 1
	elseif a_i % 2 == 0 then
		two_times_count = two_times_count + 1
	end
end

local sum_count = 0
if two_times_count == n then
	sum_count = n
elseif two_times_count >= 1 then
	sum_count = four_times_count * 2 + two_times_count
else
	sum_count = four_times_count * 2 + 1
end

print((sum_count >= n) and "Yes" or "No")


Measured memory_bytes: 2560
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut aseq = vec![0; n];
    for i in 0..n {
        aseq[i] = read::<i64>();
    }
    let mut sum = 0;
    let b = -1e+9 as i64;
    let mut ds = vec![0; n];
    let mut cnt = n as i64;
    for i in 0..n {
        sum += (aseq[i] - (b + i as i64 + 1)).abs();
        ds[i] = aseq[i] - (b + i as i64 + 1);
    }
    assert!(sum >= 0);
    ds.sort();
    let mut ans = sum;
    let mut prev = 0;
    // println!("{}", sum);
    for i in 0..n {
        let d = ds[i] - prev;
        sum -= d * cnt;
        // println!("{} {} {}", sum, d, cnt);
        cnt -= 2;
        prev = ds[i];
        ans = std::cmp::min(ans, sum);
        assert!(sum >= 0);
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define pb push_back
#define long long long
#define pll pair < long , long >
#define vll vector < pll >
#define ml map < long , long >
#define mll map < pll , long >
#define x first
#define y second
#define vl vector < long >
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
long i,v[200005]={0},n,f=0,ans=0,j,cur=0,mm,m,in;
ml mp;
int main()
{
    io
    string s;
    cin>>s;
    n=s.length();
    mp[0]=0;
    for(i=0;i<n;i++)
    {
        cur^=(1<<(s[i]-'a'));
        if(mp.find(cur)!=mp.end())
        m=mp[cur];
        else m=1e9;
        for(j=0;j<26;++j)
        if(mp.find(cur^(1<<j))!=mp.end())
        m=min(m,mp[cur^(1<<j)]);
        if(mp.find(cur)!=mp.end())
        mp[cur]=min(mp[cur],1+m);
        else mp[cur]=1+m;
    }
    cout<<max(1LL,mp[cur]);
    return 0;
}


Measured memory_bytes: 12948
#include <bits/stdc++.h>
#define pb push_back
#define ff first;
#define ss second;
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define INF 1000000000
#define endl '\n'
const double pi = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
	
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b;
	cin >> a >> b; 
	int sum = a+b;
	if(sum%3==0){
		cout << "Possible" << endl;
	}
	else if(a%3==0 || b%3==0){
		cout << "Possible" << endl;
	}
	else{
		cout << "Impossible" << endl;
	}
	return 0;
}



Measured memory_bytes: 3548
import java.util.*;
class Main{
  public static void main(String args[]){
    int tmp;
    int count = 0;
    int minj;
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int [] Array = new int[n];

    for(int i = 0; i<n; i++){
      Array[i] = sc.nextInt();
    }

    for(int i = 0; i<n; i++){
      minj = i;
      for(int j = i; j<n;j++){
        if(Array[j]<Array[minj]){
          minj = j;
        }
      }
      if(i != minj){
        tmp = Array[i];
        Array[i] = Array[minj];
        Array[minj] = tmp;
        count++;
      }
    }
    for(int i = 0; i<n-1; i++){
      System.out.printf("%d ",Array[i]);
    }
    System.out.println(Array[n-1]);
    System.out.println(count);
  }
}


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

struct Food{
  string name;
  int weight, durability;
};

int n, minG;
Food bag[11];
int order[11], bestOrder[11];
bool used[11];

void dfs(int selectedNum, int totalWeight, int numerG){
  if(selectedNum != 0 && numerG > minG) return;

  if(selectedNum == n){
    if(numerG < minG){
      minG = numerG;
      for(int i = 1; i <= n; i++) bestOrder[i] = order[i];
    }
    return;
  }

  for(int i = 1; i <= n; i++){
    if(!used[i] && bag[i].durability >= totalWeight){
      used[i] = true;
      order[selectedNum + 1] = i;
      dfs(selectedNum + 1, totalWeight + bag[i].weight, numerG + (n - selectedNum) * bag[i].weight);
      used[i] = false;
    }
  }
}

int main(void){
  while(cin >> n && n != 0){
    minG = INT_MAX;
    for(int i = 1; i <= n; i++){
      cin >> bag[i].name >> bag[i].weight >> bag[i].durability;
      used[i] = false;
    }
    dfs(0, 0, 0);
    for(int i = n; i >= 1; i--) cout << bag[bestOrder[i]].name << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cmath>
#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)
using namespace std;
typedef long long ll;

#define ECHO(v) cout << v << endl;

int main(void){
    ll n, k, x, y;
    cin >> n;
    cin >> k;
    cin >> x;
    cin >> y;
    ll sum = 0;
    REP(i, n){
        if(i < k){
            sum+=x;
        }else{
            sum+=y;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL<<60;

int calc_digit(long long n) {
    int res = 0;
    while (n > 0) {
        ++res;
        n /= 10;
    }
    return res;
}

int main() {
    long long N; cin >> N;
    long long res = INF;
    for (long long a = 1; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long b = N/a;
        long long tmp = max(calc_digit(a), calc_digit(b));
        res = min(res, tmp);
    }
    cout << res << endl;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)

int main() {
    int A,B,r=0;
    cin >> A >> B;

    rep(i,B-A+1) {
        string s = to_string(A+i);
        if(s.at(0)==s.at(4) && s.at(1)==s.at(3))
            r++;
    }

    cout << r << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    if(a+b>c*2) cout<<min(x,y)*c*2+min((x-min(x,y))*a+(y-min(x,y))*b,(x-min(x,y))*c*2+(y-min(x,y))*c*2);
    else cout<<a*x+b*y;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

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

struct Vector2D {
  int x, y;
  Vector2D() {}
  Vector2D(int x, int y) : x(x), y(y) {}

  bool operator<(Vector2D v) const { return tie(x, y) < tie(v.x, v.y); }
  bool operator==(Vector2D v) const { return tie(x, y) == tie(v.x, v.y); }
  bool operator>(Vector2D v) const { return tie(x, y) > tie(v.x, v.y); }
  bool operator<=(Vector2D v) const { return tie(x, y) <= tie(v.x, v.y); }
  bool operator>=(Vector2D v) const { return tie(x, y) >= tie(v.x, v.y); }

  Vector2D normalize() {
    if (x == 0) {
      return Vector2D(0, 1);
    }
    if (y == 0) {
      return Vector2D(1, 0);
    }
    int g = __gcd(x, y);
    Vector2D norm(x / g, y / g);
    if (norm.y < 0) norm.x = -norm.x, norm.y = -norm.y;
    return norm;
  }
  Vector2D normalized_orthogonal() {
    if (x == 0) {
      return Vector2D(1, 0);
    }
    if (y == 0) {
      return Vector2D(0, 1);
    }
    int g = __gcd(x, y);
    Vector2D ort = Vector2D(-y / g, x / g);
    if (ort.y < 0) ort.x = -ort.x, ort.y = -ort.y;
    return ort;
  }
};

void solution() {
  map<Vector2D, int> m;
  int n;
  cin >> n;
  int pot2[n + 1];
  pot2[0] = 1;
  for (int i = 1; i <= n; i++) pot2[i] = mod(pot2[i - 1] * 2LL, M);
  int lixo = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      lixo++;
      continue;
    }
    Vector2D vec(a, b);
    vec = vec.normalize();
    m[vec]++;
  }
  set<Vector2D> vis;
  int ans = 1LL;
  for (auto p : m) {
    auto vec = p.ff;
    int cnt = p.ss;
    if (vis.count(vec.normalized_orthogonal())) continue;
    vis.insert(vec);
    ans = mod(
        ans * mod(pot2[cnt] + pot2[m[vec.normalized_orthogonal()]] - 1LL, M),
        M);
  }
  ans = mod(ans + lixo - 1LL, M);
  cout << ans << endl;
}

int32_t main() {
  DESYNC;
  solution();
}


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

const int C = 1300000;
bool isprime[C];
vector<int> prime;

void init() {
  fill(isprime, isprime+C, true);
  isprime[0] = isprime[1] = false;
  for (auto i=2; i<C; i++) {
    if (isprime[i]) {
      prime.push_back(i);
      for (auto j=2; j<C; j++) {
	if ( i * j >= C) break;
	isprime[i*j] = false;
      }
    }
  }
}

int main() {
  init();
  int N;
  while (cin >> N && N) {
    if (isprime[N]) {
      cout << "0" << endl;
    } else {
      int p = 0;
      int q = 0;
      for (auto i=0; i<prime.size(); i++) {
	if (prime[i] < N) p = prime[i];
	else if (prime[i] > N) {
	  q = prime[i];
	  break;
	}
      }
      cout << q-p << endl;
    }
  }
}

Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll rm(ll n){
    ll ten = 1, ans = 0;
    while(n > 0){
        ll x = n % 10;
        if(x != 0){
            ans += x * ten;
            ten *= 10;
        }
        n /= 10;
    }
    return ans;
}
 
int main()
{
	string s;
	cin>>s;
	int ans = 0;
	for (int i = 0; i < 4; ++i) {
		if (s[i] == '+') ++ans;
		else --ans;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3592
H,N = map(int, input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
  
BIG = 10**8+1
dp = [BIG for i in range(2*10**4+1)]
dp[0] = 0
for i in range(H+1):
    for j in range(N):
        dp[i+A[j]] = min(dp[i+A[j]],dp[i]+B[j])
        
print(min(dp[H:]))

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

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

int main(){

  int n;cin>>n;
  ll sum=0;

  rep(i,0,n){
    int l,r;cin>>l>>r;
    sum+=r-l+1;
  }
  out(sum);

  return 0;
}


Measured memory_bytes: 256
//https://cs.stackexchange.com/questions/84426/find-a-node-with-maximum-distance-from-given-node-in-a-tree
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//#include <ext/rope> //header with rope
//using namespace __gnu_cxx;
//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order tells index pr kon hai..
// order_by_key  tells ki us element se kitne strictly smaller element hai...
#define mod 1000000007
#define INF 1000000000000000000
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll fact[1000007];
ll mdpower(ll a,ll b)
{
    ll res =1;
    while(b)
    {
        if(b&1) res = (res%mod*a%mod)%mod;
        b/=2;
        a = (a%mod*a%mod)%mod;
    }
    return res;
}
void factorial()
{
    fact[0]=1;
    for(int i=1;i<1000007;i++)
        fact[i] = (fact[i-1]%mod*i%mod)%mod;
}
ll inverse(ll a,ll b)
{
    return mdpower(a,b-2);
}
ll power(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)
            res=(res*a);
        a=(a*a);
        b/=2;
    }
    return res;
}
int main()
{   
    Senky_Bansal
    IIIT_ALLAHABAD

        ll n,k;
        cin>>n>>k;
        ll h[n];
        for(int i=0;i<n;i++)
        {
            cin>>h[i];
        }
        ll dp[n+1];
        for(int i=1;i<=n;i++){
            dp[i]=INF;
        }
        dp[0]=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<=min(i+k,n);j++)
            dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
        }
        cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i <(int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i,k,n) for (int i = (int)(n)-1; i >= k; i--)
#define INF 1LL<<61
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(){
    ll a,b;
    cin >> a >> b;
    ll c = gcd(a,b);
    ll ans = 1;
    for(ll i=2;i*i<=c;i++){
        if(c%i) continue;
        ans++;
        while(c%i==0)c/=i;
    }
    if(c!=1) ans++;
    cout << ans << endl;
    return 0;
}


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

struct TMatrix
{
	int Row;
	int Col;
	
	TMatrix(int ARow, int ACol);
};

TMatrix::TMatrix(int ARow, int ACol)
: Row(ARow), Col(ACol)
{
}

class TMinimumMultiplications
{
	std::vector<std::vector<int> > FTable;
	const std::vector<TMatrix>& FMatrixChain;
	
	int GetMinimum(int Begin, int End);
public:
	TMinimumMultiplications(const std::vector<TMatrix>& MatrixChain);
	
	int Get(int Begin, int End);
};

TMinimumMultiplications::TMinimumMultiplications(const std::vector<TMatrix>& MatrixChain)
: FMatrixChain(MatrixChain), FTable(MatrixChain.size(), std::vector<int>(MatrixChain.size(), -1))
{
}

int TMinimumMultiplications::GetMinimum(int Begin, int End)
{
	int Minimum = INT_MAX;
	for(int i = Begin; i < End; ++i){
		int Total = Get(Begin, i)
		          + Get(i + 1, End)
		          + FMatrixChain[Begin].Row * FMatrixChain[i + 1].Row * FMatrixChain[End].Col;
		if(Minimum > Total) Minimum = Total;
	}
	return Minimum;
}

int TMinimumMultiplications::Get(int Begin, int End)
{
	if(Begin == End) return 0;
	if(FTable[Begin][End] < 0){
		FTable[Begin][End] = GetMinimum(Begin, End);
	}
	return FTable[Begin][End];
}

int MinimumMultiplicationCount(const std::vector<TMatrix>& MatrixChain)
{
	TMinimumMultiplications Minimum(MatrixChain);
	return Minimum.Get(0, MatrixChain.size() - 1);
}

int main()
{
	int Count;
	std::cin >> Count;
	std::vector<TMatrix> MatrixChain;
	for(int i = 0; i < Count; ++i){
		int Row, Col;
		std::cin >> Row >> Col;
		MatrixChain.push_back(TMatrix(Row, Col));
	}
	
	std::cout << MinimumMultiplicationCount(MatrixChain) << std::endl;
	return 0;
}

Measured memory_bytes: 3160
import java.util.*;

public class Main{
  public static void main(String[] args) throws Exception{
	Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int rest = N % 500;
    String result = A >= rest ? "Yes" : "No";
    System.out.println(result);
  }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     string s;
     ll i,j,c=0;
     cin>>s;
     i=0,j=s.size()-1;
     while(i<j)
     {
         if(s[i]!=s[j])c++;
         i++,j--;
     }
     cout<<c<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		int n = 0;
		
		while(a < 1 || a > 10000 || b < 1 || b> 10000 || c < 1 || c > 10000) {
			a = stdIn.nextInt();
			b = stdIn.nextInt();
			c = stdIn.nextInt();
		}
		
		for(int i = a; i <= b; i++) {
			if(c % i == 0) {
				n++;
			}
		}
		
		System.out.println(n);
	}
}


Measured memory_bytes: 26396
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int N, Y;
	cin >> N >> Y;
	Y /= 1000;
	
	REP(i, N + 1) { // 10000
		REP(j, N + 1) { // 5000
			int k = Y - 10*i - 5*j;
			if (k < 0 || i + j + k != N) continue;
			
			printf("%d %d %d\n", i, j, k);
			return 0;
		}
	}
	
	puts("-1 -1 -1");
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
stack = list()

for s in S:
    if stack:
        p = stack.pop()
        if p == "(" and s == ")":
            continue
        else:
            stack.append(p)
            stack.append(s)
    else:
        stack.append(s)

while stack:
    p = stack.pop()
    if p == "(":
        S = S + ")"
    else:
        S = "(" + S

print(S)


Measured memory_bytes: 2940
import Control.Monad

ok' bit s p = (length $ [] ++ [()| si <- s, bit !! (si-1) ]) `mod` 2 == p
ok bit s p m = (length $ [] ++ [()| i <- [0..m - 1], ok' bit (s !! i) (p !! i)]) == m
f = fmap (map read . words) getLine

main = do
    [n, m] <- f
    s <- replicateM m $ fmap (tail . map read . words) getLine
    p <- f
    print.length $ [()| bit <- sequence $ replicate n [False, True], ok bit s p m ]

Measured memory_bytes: 4440
#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 ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll a[n], i, sum = 0;
    vector<ll> freq(100001, 0);
    for(i = 0; i < n; i++) {
    	cin >> a[i];
    	sum += a[i];
    	freq[a[i]]++;
    }
    ll q;
    cin >> q;
    while(q--) {
    	ll b, c;
    	cin >> b >> c;
    	sum = sum - freq[b]*b + freq[b]*c;
    	freq[c] += freq[b];
    	freq[b] = 0;
    	cout << sum << "\n";
    }

}

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

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
	
	int n,m;
	cin >> n >> m;
	long long sum = 0;
	for (int i=0; i<m; ++i) {
		int x; cin >> x;
		sum += x;
	}
	if (n - sum >=0 ) cout << n-sum << endl;
	else cout << -1 << endl;
}


Measured memory_bytes: 3644
// https://atcoder.jp/contests/arc093/tasks/arc093_b

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

void solve() {
  ll A, B;
  cin >> A >> B;

  auto mat = V<string>(100);

  // 上半分が白、 下半分が黒
  rep(i, 0, 50) mat[i] = string(100, '.');
  rep(i, 50, 100) mat[i] = string(100, '#');

  // 上半分に B-1 個の黒点を置く
  rep(i, 0, B - 1) {
    ll h = i / 50;
    ll w = i % 50;
    mat[2 * h][2 * w] = '#';
  }

  // 下半分に A-1 個の白点を置く
  rep(i, 0, A - 1) {
    ll h = i / 50;
    ll w = i % 50;
    mat[99 - 2 * h][2 * w] = '.';
  }

  print_ints(V<ll>{100, 100});
  rep(i, 0, 100) cout << mat[i] << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, 0, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = Input.num;
        var ab = new long[num][];
        for (var i = 0; i < num; i++)
            ab[i] = Input.arL;
        var ct = 0L;
        ab = ab.Reverse().ToArray();
        for (var i = 0; i < num; i++)
            ct += (ab[i][1] - (ab[i][0] + ct) % ab[i][1])%ab[i][1];
        WriteLine(ct);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 25916
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();int m = sc.nextInt();
        if(n==0) {
            if(m==100) {System.out.println(101); return;}
            System.out.println(m);
        }
        else if(n==1) {
            if(m==100) {System.out.println(10100); return;}
            System.out.println(m*100);
        }
        else 
            if(m==100) {System.out.println(1010000); return;} else
        System.out.println(m*100*100);
    }
}


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

int main() {
  int N, M;
  cin >> N >> M;
	if(N < 6){
      cout << 0 << endl;
    }else if(N <13){
      cout << M/2 <<endl;
    }else{
      cout << M <<endl;
    }
}

Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans=0
for i in range(n):
    tmp=0
    a = list(map(int, input().split()))
    for j in range(m):
        tmp += a[j] * b[j]
    tmp += c
    if(tmp>0):
        ans += 1

print(ans)

Measured memory_bytes: 3064
import math
N=int(input())
a=math.sqrt(N)
b=int(a//1)+1
ans=10000000000000
c=0
for n in range(1,b):
    if N%n==0:
        ans=min(ans,N//n+n)
        c=1
if c==0:
    print(N-1)
else:
    print(ans-2)



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

int alpha_to_int(char a) {
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    return alpha.find(a);
}

int main() {
    string s;
    cin >> s;
    int a[26] = {};
    rep(i,s.size()) {
        a[alpha_to_int(s[i])]++;
    }
    rep(i,26) {
        if (a[i] > 1) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    ll n, x;
    cin >> n >> x;
    vector<int> a, b(n);
    vin(a, n);
    ll ans = 0;
    rep(i, n) {
        b[i] = a[i];
        ans += a[i];
    }
    rep(k, n) {
        ll tmp = k * x;
        rep(i, n) {
            b[i] = min(b[i], a[(i - k + n) % n]);
            tmp += b[i];
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int jud(int x,int y){
	if(x == y) return 0;
	return (x > y ? -1 : 1);
}

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int ans = 0;
	for(int i = 0; i < n; ans++){
		int ch = 0;
		//cout << i << endl;
		while(i < n-1){
			int now = jud(a[i],a[i+1]);
			if(now == 0) i++;
			else{
				if(ch == 0) ch = now;
				if(ch != now) break;
				i++;
			}
		}
		i++;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
bool palin(int N){//Nが回文数かどうか
    string S = to_string(N);
    int M = (S.size()-1)/2 + 1;
    int n = S.size();
    bool flag = true;

    for(int i = M;i<n;i++){
        if(S[i] != S[n-i-1]) flag = false;
    }
   return flag;
}
/*
*/

int main() {
  int n,m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;

ll n;
ll a[55];

int main()
{
	ll mpos = 1;

	scanf("%lld", &n);
	for (ll i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}

	for (ll i = 2; i <= n; i++) {
		if (llabs(a[mpos]) < llabs(a[i])) {
			mpos = i;
		}
	}

	printf("%lld\n", 2 * n - 1);
	for (ll i = 1; i <= n; i++) {
		a[i] += a[mpos];
		printf("%lld %lld\n", mpos, i);
	}

	if (a[mpos] >= 0) {
		for (ll i = 1; i < n; i++) {
			printf("%lld %lld\n", i, i + 1);
		}


	} else {
		for (ll i = n - 1; i >= 1; i--) {
			printf("%lld %lld\n", i + 1, i);
		}
	}

	return 0;
}


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

int main(){
    string s;
    cin>>s;
    if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])  cout<<"Bad"<<endl;
    else                                    cout<<"Good"<<endl;
    return 0;
}

Measured memory_bytes: 256