akhauriyash/Code-Regression huggingface dataset:
n = int(input())
count_ab = 0
tail_a = 0
head_b = 0
hb_ta = 0
ans = 0
for i in range(n):
    s = str(input())
    if s[0] == "B" and s[-1] == "A":
        hb_ta += 1
    elif s[0] == "B":
        head_b += 1
    elif s[-1] == "A":
        tail_a += 1
    for j in range(len(s)-1):
        if s[j:j+2] == "AB":
            count_ab += 1

if tail_a > 0 and head_b > 0:
    ans = 1 + hb_ta
    ans += min(tail_a-1, head_b-1)
elif tail_a > 0 or head_b > 0:
    # head_bかtail_aが0の時
    ans = hb_ta
else:
    # どちらも0のとき
    if hb_ta > 0:
        ans = hb_ta - 1
    else:
        ans = 0
ans += count_ab
print(ans)




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

int main()
{
    string s;
    ll k;
    cin >> s >> k;

    int n = s.size();
    int oneLen = 0;
    rep (i, n)
        if (s[i] == '1')
            oneLen++;
        else
            break;

    cout << (k > oneLen ? s[oneLen] : '1') << endl;
    return 0;
}

Measured memory_bytes: 3520
#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, l;
    cin >> n >> l;

    int ans = 0;
    int minv = 101;
    rep(i, n) {
        int t = l + i;
        minv = min(minv, abs(t));
    }

    rep(i, n) {
        int t = l + i;
        if (abs(t) != minv) ans += t;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

while True:
	str = input()
	if str == "-":
		break

	dq = deque(char for char in list(str))
	shuffle_count = int(input())

	for i in range(shuffle_count):
		h = int(input())
		dq.rotate(h * -1)

	print(''.join(dq))

Measured memory_bytes: 7996
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    string s,t;cin>>s>>t;
    bool f=1;
    rep(i,s.size()){
        if(s[i]!=t[i])f=0;
    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
int main()
{
  int n,m;
  for(;cin>>n>>m,n;)
    {
      int edge[n][n];
      memset(edge,-1,sizeof(edge));
      for(int i=0;i<m;i++)
	{
	  int a,b,cost;
	  cin>>a>>b>>cost;
	  edge[a][b]=cost;
	  edge[b][a]=cost;
	}
      bool closed[n];
      memset(closed,false,sizeof(closed));
      int cnt=n-1;
      int ans=0;
      closed[0]=true;
      priority_queue<pair<int,int>, vector<pair<int,int> > ,greater<pair<int,int> > > qu;
      for(int i=0;i<n;i++)
	{
	  if(edge[0][i]!=-1)
	    qu.push(make_pair(edge[0][i],i));
	}
      while(true)
	{
	  int pos=qu.top().second;
	  int cost=qu.top().first;
	  //  cout<<"#"<<pos<<" "<<cost<<endl;
	  qu.pop();
	  if(closed[pos])
	    continue;
	  closed[pos]=true;
	  ans+=cost;
	  cnt--;
	  if(cnt<=0)
	    break;
	  for(int i=0;i<n;i++)
	    {
	      if(edge[pos][i]!=-1)
		qu.push(make_pair(edge[pos][i],i));
	    }
	}
      cout<<ans<<endl;
    }

}

Measured memory_bytes: 1244
#include <cstdio>
#include <algorithm>
#include <numeric>

int main()
{
  int e[10];
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
  {
    scanf("%d", e + i);
  }
  std::sort(e, e + n);
  puts(std::accumulate(e, e + n - 1, 0) > e[n - 1] ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define MOD1		1000000007
#define MOD2		998244353
#define BOOST		ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

ll n, ans;
set<ll> divisors;
void compute(ll i)
{
    ll temp = n;
    if(i == 1)
        return;
    while((temp % i) == 0)
        temp /= i;
    if(temp % i == 1)
        ans++;
}

void solve()
{
   cin >> n;    
    for(ll i = 1; i * i <= n; ++i)
    {
        if(n % i == 0)
        {
            compute(i);
            divisors.insert(i);
            if(i * i != n)
            {
                compute(n / i);
                divisors.insert(n / i);
            }
        }
    }
   n--;
   for(ll i = 1; i * i <= n; ++i)
   {
        if(n % i == 0)
        {
            if(divisors.find(i) == divisors.end())
                ++ans;
            if(i * i != n)
            {
                if(divisors.find(n/i) == divisors.end())
                    ++ans;
            }
        }
   }
   cout << ans << "\n";
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif

    ll t = 1;
    //cin >> t;
    while(t--)
        solve();

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int m,n,i,j,t,y;
	int e[15]={10000};
	for(i=0;i<12;i++){
		scanf("%d",&e[i]);
	}
	sort(e,e+12);
	
	if(e[0]==e[1] && e[2]==e[3] && e[4]==e[5] && e[6]==e[7] && e[8]==e[9] && e[10] == e[11]){
		printf("yes\n");
	}
	else{
		printf("no\n");
		}
	}
	

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, wt;
  cin>>n>>wt;
  int w[n+1], v[n+1];
  long long int dp[wt+1];
  for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
  for(int i=0;i<=wt;i++) dp[i]=0;
  for(int j=1;j<=n;j++) for(int i=wt;i>=0;i--) if(w[j]<=i) dp[i]=max(dp[i],dp[i-w[j]]+v[j]);
  cout<<dp[wt];
}

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

typedef long long ll;

const int N = 3005;

int mod = 1e9 + 7;

void add(int x, int &y) {
    y += x;
    y %= mod;
}

int dp[N][N + N][2];

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;

    for(int i = 1; i <= m; i++) {
        for(int red = 0; red <= n + m; red++) {
            if(i == 1) {
                if(red == 0) dp[i][red][1] = 1;
                else if(red <= n) dp[i][red][0] = 1;
            }
            for(int f = 0;f < 2; f++) {
                if(red > 0) {
                    add(dp[i][red][f], dp[i+1][red][f|(red==1)]);
                    add(dp[i][red][f], dp[i+1][red-1][f|(red==1)]);
                }
                int blue = n-red;
                if(blue > 0) {
                    add(dp[i][red][f], dp[i+1][red][f]);
                    add(dp[i][red][f], dp[i+1][red+1][f]);
                }
            }
        }
    }
    int ans = 0;
    for(int red = 0; red <= n + m; red++) {
        ans += dp[m + 1][red][1];
        ans %= mod;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 141184
#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, int>;

#define INF 1e18

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  cout << ((n+x-1)/x)*t << endl;

  return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

const int MAX=1<<17;

vector<int> G[MAX];
int root;
int V;

int vs[MAX*2-1];
int depth[MAX*2-1];
int id[MAX];

int n;
int dat[MAX*4-1];//0-indexed

void rmq_init(int V)
{
	n=1;
	while(n<V)n<<=1;
	for(int i=0;i<2*n-1;i++)dat[i]=-1;
	return;
}

void update(int k,int a)
{
	k+=n-1;
	dat[k]=a;
	while(k>0)
	{
		k=(k-1)/2;
		int b1=dat[k*2+1],b2=dat[k*2+2];
		if(b1!=-1&&b2!=-1)dat[k]=(depth[b1]<=depth[b2]?b1:b2);
		else if(b2!=-1)dat[k]=b2;
		else dat[k]=b1;
	}
	return;
}

int getmin(int a,int b,int k,int l,int r)//[a,b),vertex-number(0),k's range[l,r)
{
	if(r<=a||b<=l)return -1;
	
	if(a<=l&&r<=b)return dat[k];
	else
	{
		int vl=getmin(a,b,k*2+1,l,(l+r)/2);
		int vr=getmin(a,b,k*2+2,(l+r)/2,r);
		if(vl!=-1&&vr!=-1)return (depth[vl]<=depth[vr]?vl:vr);
		else if(vr!=-1)return vr;
		else return vl;
	}
}

void dfs(int v,int p,int d,int &k)
{
	id[v]=k;
	vs[k]=v;
	depth[k]=d;
	k++;
	for(int i=0;i<G[v].size();i++)
	{
		if(G[v][i]!=p)
		{
			dfs(G[v][i],v,d+1,k);
			vs[k]=v;
			depth[k]=d;
			k++;
		}
	}
	return;
}

void init()
{
	int k=0;
	root=0;
	dfs(root,-1,0,k);
	rmq_init(V*2-1);
	for(int i=0;i<V*2-1;i++)update(i,i);
	return;
}

int lca(int u,int v)
{
	if(id[u]>id[v])swap(u,v);
	return vs[getmin(id[u],id[v]+1,0,0,n)];
}

int main()
{
	cin>>V;
	int k,c;
	for(int i=0;i<V;i++)
	{
		cin>>k;
		for(int j=0;j<k;j++)
		{
			cin>>c;
			G[i].push_back(c);
			G[c].push_back(i);
		}
	}
	init();
	int q;
	cin>>q;
	int u,v;
	for(int i=0;i<q;i++)
	{
		cin>>u>>v;
		cout<<lca(u,v)<<endl;
	}
	return 0;
}

Measured memory_bytes: 21056
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <assert.h>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();

    map<int, int> mp;
    int cnt = 0;
    VI ans;
    REP(i,n){
        int x = a[i], y = a[n-1-i];
        if (x != y){
            if (mp[x] == 0) cnt++;
            if (mp[x] == -1) cnt--;
            mp[x]++;

            if (mp[y] == 0) cnt++;
            if (mp[y] == 1) cnt--;
            mp[y]--;
        }
        if (cnt == 0) ans.push_back(i + 1);
    }

    REP(i,ans.size()){
        if (i > 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


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

int main() {
  vector<int> vec(5);
  int cnt=0;
  rep(i,5){
    cin>>vec[i];
    cnt+=(vec[i]+9)/10*10;
  }
  int ans=cnt;
  rep(i,5){
    int x=vec[i]%10;
    if(x!=0)ans=min(ans,cnt+x-10);
  }
  cout<<ans<<endl;
}

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

int main(){
  long int x,y ;
  cin >> x >> y ;
  if(x==0){
    if(y>=0){
      cout << y << endl ;
    }else{
      y *= -1 ;
      cout << y+1 << endl ;
    }
    return 0 ;
  }
  if(y==0){
    if(x>=0){
      cout << x+1 << endl ;
    }else{
      x *= -1 ;
      cout << x << endl ;
    }
    return 0 ;
  }
  if(x>=0&&y>=0){
    if(x<=y){
      cout << y-x << endl ;
    }else{
      cout << x-y+2 << endl ;
    }
  }else if(x>=0){
    y *= -1 ;
    cout << max(x,y)-min(x,y)+1 << endl ;
  }else if(y>=0){
    x *= -1 ;
    cout << max(x,y)-min(x,y)+1 << endl ;
  }else{
    x *= -1 ; y *= -1 ;
    if(x>=y){
      cout << x-y << endl ;
    }else{
      cout << y-x+2 << endl ;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<set> 
#include<queue> 
#include<stack> 
#include<vector> 
#include<string> 
#include<numeric> 
#include<algorithm> 
#include<math.h> 
#include<iomanip>
using namespace std;
int main()
{
	long long int a,b,sum;
	cin>>a>>b;
	sum=a+b;
	if((sum%2)==1)
	{
		cout<<"IMPOSSIBLE";
		return 0; 
	}
	else if(a>=0&&b>=0)
	{
		cout<<(sum)/2;
		return 0;
	} 
	return 0;
}


Measured memory_bytes: 256
cards = [input().strip()+'X' for _ in range(3)]
pos = [0,0,0]

now = 0

while True:
  if cards[now][pos[now]] == 'X':
    print(chr(ord('A')+now))
    break
  pos[now] += 1
  now = ord(cards[now][pos[now]-1])-ord('a')



Measured memory_bytes: 38384
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#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++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
const ll inf = 1000000007;
int main() {
  ll n; cin >>n;
  if(n%2==0)cout <<n/2<<endl;
  else  cout <<n/2+1<<endl;
}

Measured memory_bytes: 256
num=int(input())
data=list(input())
count=0

if num%2==1:
  print("No")

else:
  half=num//2
  for i in range(half):
    if data[i]==data[half+i]:
      count+=1          
  if count==half:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 3060
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
abcd = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
cd = lcm(c, d)
print(b-a-(b//c-((a-1)//c + 1))-(b//d - ((a-1)//d + 1))+(b//cd-((a-1)//cd + 1)))

Measured memory_bytes: 5048
import java.util.*;

public class Main {

    private static int N;
    private static int K;
    private static Deque<Integer> V;

    private static void read() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
        V = new LinkedList<>();
        for (int i = 0; i < N; i += 1) {
            V.add(sc.nextInt());
        }
    }

    public static void main(String[] args) {
        read();
        solve();
    }

    private static void solve() {
        int R = Integer.min(N, K);

        int max = Integer.MIN_VALUE;
        for (int r = 0; r <= R; r += 1) { // `r`: count of picking gems
            for (int A = 0; A <= r; A += 1) { // `A: count of picking from left
                int B = r - A;  // `B: count of picking from right
                int D = K - A - B; // `D: count of disposed gems

                Deque<Integer> copyV = new LinkedList<>(V);

                List<Integer> gems = new ArrayList<>();
                for (int i = 0; i < A; i +=1) {
                    gems.add(copyV.removeFirst());
                }
                for (int i = 0; i < B; i +=1) {
                    gems.add(copyV.removeLast());
                }

                Collections.sort(gems);
                for (int i = 0; i < D; i += 1) {
                    if (!gems.isEmpty() && gems.get(0) < 0) {
                        gems.remove(0);
                    }
                }

                int tmpMax = 0;
                for (int gem : gems) {
                    tmpMax += gem;
                }
                max = Integer.max(max, tmpMax);
            }
        }

        System.out.println(max);
    }

}


Measured memory_bytes: 23764
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// 2013/03/16
public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;

	int n;
	int[] a, b;

	void run(){
		n=sc.nextInt();
		a=new int[n];
		b=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.next().charAt(0);
			b[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		int left=0;
		boolean ok=true;
		for(int i=0; i<n; i++){
			if(a[i]=='('){
				left+=b[i];
			}else{
				left-=b[i];
			}
			ok&=left>=0;
		}
		ok&=left==0;
		println(ok?"YES":"NO");
	}

	void println(String s){
		System.out.println(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

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

}

Measured memory_bytes: 24940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;



int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum=0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int cnt=0;
    rep(i,n){
        if(a[i]*100 >= 25*sum/m){
            cnt++;
        }
    }
    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;

   

}

Measured memory_bytes: 3644
def main():
    is_exist = [False] * 8
    free = 0
    n = int(input())
    A = list(map(int, (input().split())))
    for a in A:
        color = a // 400
        if color >= 8:
            free += 1
        else:
            is_exist[color] = True

    normal_colors = sum(is_exist)
    minimum = normal_colors
    if not minimum and free:
        minimum = 1

    maximum = free + normal_colors
    print(minimum, maximum)


if __name__ == "__main__":
    main()
    

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

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

	vector<char> mis(26), com(26);
	string tmp;
	int n;
	cin >> n;
	cin >> tmp;
	for ( auto l : tmp )
		com[l-'a']++;
	for ( int i = 1 ; i < n ; i++ ){
		cin >> tmp;
		mis = com;
		com = vector<char>(26);
		for ( auto l : tmp ) {
			if ( mis[l-'a'] > 0 ){
				mis[l-'a']--;
				com[l-'a']++;
			}
		}
	}
	for ( int i = 0 ; i < com.size() ; i++ ){
		for ( int j = 0 ; j < com[i] ; j++ ){
			cout << char(i + 'a');
		}
	}
	cout << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1000000000;
const ll inf2 = 1000000000000000000;
const ll mod = 1000000007;
 
int main() {
    ll a;
    cin >> a;
    ll ans = 1;
    bool d = true;
    rep(i, 0, a){
        ll b;
        cin >> b;
        if(b == 0){
            cout << 0 << endl;
            return 0;
        }
        else if(inf*inf/ans >= b){
            ans *= b;
        }
        else{
            ans = 1;
            d = false;
        }
    }if(d)cout << ans << endl;
    else cout << -1 << endl;
    
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define sq(x) ((x)*(x))
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17

#define maxn 300005
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pii;

int main()
{
    int n , k ;

    scanf("%d %d",&n,&k) ;

    if( k==1 ) printf("0\n") ;
    else printf("%d\n",n-k) ;

    return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);

  if(b>c)
    {
      int d=b;
      b=c;
      c=d;
    }
  if(a>b)
    {
      int d=a;
      a=b;
      b=d;
    }

  if(b>c)
    {
      int d=b;
      b=c;
      c=d;
    }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m;
	cin >> n >> m;
	vi x(n), y(m);
	cin >> x >> y;
	vi a(n - 1), b(m - 1);
	REP(i, n - 1) a[i] = x[i + 1] - x[i];
	REP(i, m - 1) b[i] = y[i + 1] - y[i];
	vi cnta(n - 1), cntb(m - 1);
	cnta[0] = cnta[n - 2] = n - 1;
	FOR(i, 1, (n - 1) / 2 + 1)
	{
		cnta[i] = cnta[n - i - 2] = cnta[i - 1] + (n - 1 - i * 2);
	}
	cntb[0] = cntb[m - 2] = m - 1;
	FOR(i, 1, (m - 1) / 2 + 1)
	{
		cntb[i] = cntb[m - i - 2] = cntb[i - 1] + (m - 1 - i * 2);
	}
	ll p = 0, q = 0;
	REP(i, n - 1)
	{
		p += cnta[i] * a[i];
		p %= MOD;
	}
	REP(i, m - 1)
	{
		q += cntb[i] * b[i];
		q %= MOD;
	}
	cout << p * q % MOD << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;

const int N = 2e5+10;
int a[N];
map<int,int> mmap;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mmap[a[i]]++;
	}
	long long sum = 0;
	for(auto elem:mmap){
		long long t = elem.second;
		sum += t*(t-1)/2;
	}
	for(int i=0;i<n;i++){
		cout<<sum-mmap[a[i]]+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 8320
#include <stdio.h>

int main(void)
{
    double a,b,c,d,e,f,x,y,det;

    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!= EOF){
        det = a*e - b*d;
        x = 1.0/det * ( e*c - b*f);
        y = 1.0/det * (-d*c + a*f);
        if(-0.0005 < x && x < 0.0005){
            x = 0.0;
        }
        if(-0.0005 < y && y < 0.0005){
            y = 0.0;
        }      
        printf("%.3f %.3f\n", x, y);
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int a[N];
    rep(i, N) {
        cin >> a[i];
    }
    int b[100001];
    rep(i, 100001) {
        b[i] = 0;
    }

    sort(a, a+N);

    int t = a[0];
    rep(i, N) {
        if(a[i] != t) {
            t = a[i];
        }
        if(100000 < t) {
            b[0] = N - i;
            break;
        }
        b[t]++;
    }

    int ans = 0;
    rep(i, 100001) {
        if(i <= b[i]) {
            ans += b[i] - i;
        }
        else {
            ans += b[i];
        }
    }

    cout << ans;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
"""
map(int,input().split())

"""
N,K = map(int,input().split())
S = input()
s = []
for i in range(0,len(S)):
    s.append(S[i])


Nums = []
now = 1
cnt = 0
for i in range(0,N):
    if(s[i] == str(now)):
        cnt+=1
    else:
        Nums.append(cnt)
        now = 1-now
        cnt = 1

if cnt!=0:
    Nums.append(cnt)

if len(Nums)%2 == 0:
    Nums.append(0)

Add = 2*K + 1
ans = 0
W = []

wsm = 0
for i in range(0,len(Nums)):
    wsm = Nums[i] + wsm
    W.append(wsm)

W.append(wsm)
W.append(wsm)

for i in range(0,len(Nums),2):
    tmp = 0
    left = i
    if left == 0:
        left = 1
    right = min(i + Add , len(Nums))
    if left-1<=0:
        tmp = W[right-1]
    else:
        tmp = W[right-1] - W[left-1]
    #print(tmp,left,right)
    ans = max(tmp,ans)
if  N == 1:
    print(1)
else:
    print(ans)


Measured memory_bytes: 8700
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 310000
ll MOD=998244353;

int a[1100][1100];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
main(){
    int h=in(),w=in(),n=in();
    int x=in(),y=in();
    string s,t;cin>>s>>t;
    int u=x,d=x,uu=0,dd=0;
    bool flag=false;
    rep(i,n){
        if(s[i]=='U')u--;
        else if(s[i]=='D')d++;
        if(uu>=u||dd>=h+1-d){
            flag=true;
        }
        if(t[i]=='U')d=max(d-1,1);
        else if(t[i]=='D')u=min(u+1,h);
        
    }
    int l=y,r=y;
    rep(i,n){
        if(s[i]=='L')l--;
        else if(s[i]=='R')r++;
        if(l==0||r==w+1)flag=true;
        if(t[i]=='L')r=max(r-1,1);
        if(t[i]=='R')l=min(l+1,w);
    }
    cout<<(flag?"NO":"YES");
}



Measured memory_bytes: 776
#include <iostream>
#include <vector>
#define max 300000
using namespace std;
vector<bool> p(300000,true);
void make(vector<bool> &p)
{
p[1]=false;
int i=0;
while(i<=max){
	if(i%7!=1&&i%7!=6)
p[i]=false;
i++;
}
for(int j=0;j<=max;j++){
	if(p[j]){
		int k=2;
		while(j*k<=max){
p[j*k]=false;
			k++;
		}
	}
}
}
int main(void)
{
	make(p);
	int n;
	while(1){
		cin>>n;
		if(n==1)break;
		cout<<n<<":";
		for(int i=0;i<=n;i++){
			if(p[i]){
				if(n%i==0)
				cout<<" "<<i;
			}
		}cout<<endl;
	}
	return 0;
}

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

typedef long long ll;

ll N, M, L, Q;
vector<vector<ll>> Dist, Res;
const ll INF = 1ll << 60;

int main() {
  cin >> N >> M >> L;
  Dist.resize(N);
  for (auto &dist : Dist) dist.resize(N, INF);
  for (ll i = 0; i < M; ++i) {
    ll a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    Dist[a][b] = Dist[b][a] = c;
  }
  for (ll w = 0; w < N; ++w)
    for (ll u = 0; u < N; ++u)
      for (ll v = 0; v < N; ++v)
        Dist[u][v] = min(Dist[u][v], Dist[u][w] + Dist[w][v]);
  Res.resize(N);
  for (auto &res : Res) res.resize(N, INF);
  for (ll u = 0; u < N; ++u)
    for (ll v = 0; v < N; ++v)
      if (Dist[u][v] <= L) Res[u][v] = 1;
  for (ll w = 0; w < N; ++w)
    for (ll u = 0; u < N; ++u)
      for (ll v = 0; v < N; ++v)
        Res[u][v] = min(Res[u][v], Res[u][w] + Res[w][v]);
  cin >> Q;
  for (ll q = 0; q < Q; ++q) {
    ll s, t;
    cin >> s >> t;
    --s;
    --t;
    ll res = Res[s][t];
    cout << (res == INF ? -1 : res - 1) << endl;
  }
  return 0;
}


Measured memory_bytes: 1920
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


# --------------------------------------------

dp = None


def main():
    N = int(input())

    ans = 0
    while 2**ans <= N:
        ans += 1

    print(2**(ans - 1))


main()


Measured memory_bytes: 4980
n, m = map(int, input().split())
ab = []
for i in range(n):
	ab.append(list(map(int, input().split())))
ab.sort()

pay = 0
to = 0
j = 0
while to < m:
	if to+ab[j][1] <= m:
		to += ab[j][1]
		pay += ab[j][0]*ab[j][1]
		j += 1
	else:
		pay += ab[j][0]*(m-to)
		to = m

print(pay)

Measured memory_bytes: 27760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		if (X == 3 || X == 5 || X == 7) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	}
}


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

typedef long long LL;
typedef long double LD;
typedef string ST;



void func() {
  LL H, W;
  cin >> H >> W;

  set<pair<LL, LL>> M;
  vector<string> MAP(H);
  for (LL i = 0; i < H; ++i) {
    cin >> MAP[i];
    for (LL j = 0; j < W; ++j) {
      char c = MAP[i][j];
      if (c == '#') {
        M.insert(make_pair(i, j));
      }
    }
  }

  if (M.size() == H * W) {
    cout << 0;
    return;
  }

  LL num = M.size();

  LL cnt = 0;
  while (num < H*W) {
    for (auto map : MAP) {
      //cerr << map << endl;
    }

    set<pair<LL, LL>> P;
    for (auto m : M) {
      //cerr << m.first << " : " << m.second << endl;
      LL i = m.first;
      LL j = m.second;

      if (j - 1 >= 0) {
        if (MAP[i][j - 1] == '.') {
          P.insert(make_pair(i, j - 1));
          MAP[i][j - 1] = '#';
          num++;
        }
      }
      if (j + 1 < W) {
        if (MAP[i][j + 1] == '.') {
          P.insert(make_pair(i, j + 1));
          MAP[i][j + 1] = '#';
          num++;
        }
      }
      if (i - 1 >= 0) {
        if (MAP[i - 1][j] == '.') {
          P.insert(make_pair(i - 1, j));
          MAP[i - 1][j] = '#';
          num++;
        }
      }
      if (i + 1 < H) {
        if (MAP[i + 1][j] == '.') {
          P.insert(make_pair(i + 1, j));
          MAP[i + 1][j] = '#';
          num++;
        }
      }
    }
    M = P;
    P.clear();
    cnt++;
  }
  cout << cnt;
}


#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "\n%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





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

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define show(x) cerr << #x << " " << x << endl

typedef long long ll;
typedef unsigned long long ull;

constexpr const int INT_INF=0x3f3f3f3f; // 1061109567
constexpr const ll LL_INF=0x3f3f3f3f3f3f3f3f; // 4557430888798830399

template <typename T> bool chmin(T &a, T b) {
    if (a > b) {a = b;return true;}return false;
}

template <typename T> bool chmax(T &a, T b) {
    if (a < b) {a = b;return true;}return false;
}

// INT
#define GCD(a, b) __gcd(a, b)
template <typename T> T LCM(T a, T b) {return a / GCD(a, b) * b;}
template <typename T> T EXTGCD(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {d=EXTGCD(b,a%b,y,x);y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> bool is_prime(T a) {
    for(int i=2;i*i<=a;i++)if(a%i==0)return 1;
    return 0;
}

// MOD
const ll MOD = 998244353L;
#define add(a, b) ((a % MOD) + (b % MOD)) % MOD
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define sub(a, b) ((a % MOD) + MOD - (b % MOD)) % MOD
template <typename T> T mod_inverse(T a, T mod, bool prime){ // if mod is prime, "prime" is true.
    if(prime){
        T tmp=mod-2,now=a,res=1;while(tmp){if(tmp&1)res=mul(res,now);now=mul(now,now);tmp>>=1;}
        return res;
    }else{T x,y;EXTGCD(a,mod,x,y);return (mod+x%mod)%mod;}
}
#define divide(a, b) ((a % MOD) * (mod_inverse(b, MOD, true))) % MOD

//LLの数値をつかう時は最後にLをつける癖をつけよう
//
//  　　┓　　　┏
//  　＊┗┓　┏┛
//  　　　┫　┣　＊
//  　┏┳┻━┻┳┓
//  　┗┫　　　┣┛
//  ＊　┣　　━┃　＊        Merry Christmas!!
//  　┏┛　　〃┃
//  　┃●　　　┣━┳┓
//  　┗┻┳━━┛　┣┛
//  　＊　┃┏┓┣┓┃
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

int k;
ll a[100001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1 = freopen("/Users/aim_cpo/CLionProjects/competitive/in.txt", "r", stdin);
    //stream2 = freopen("out.txt", "w", stdout);
    if (stream1 == nullptr) return 0;
    //if (stream2 == NULL) return 0;
#endif
    cin >> k;
    for (int i = 0; i < k; i++) {
        cin >> a[i];
    }
    if (a[k - 1] != 2) {
        cout << -1 << endl;
        return 0;
    }
    ll left = 2L, right = 2L;
    for (int i = k - 1; i >= 0; i--) {
        if (left % a[i] == 0) {
            left = (left / a[i]) * a[i];
        } else {
            left = (left / a[i] + 1) * a[i];
        }
        right = right / a[i] * a[i] + a[i] - 1;
        if (left > right) {
            cout << -1 << endl;
            return 0;
        }
        // show(left);
        // show(right);
    }
    cout << left << " " << right << endl;
#ifdef  LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
  if(1<=a&&c<=10){
    if((a==5&&b==5&&c==7)||(a==5&&c==5&&b==7)||(b==5&&c==5&&a==7)){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
  }
  }
    else{
      cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define double long double
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
double eps=1e-8;
int mod=1e9+7;
int inf=1LL<<55;

priority_queue<P,vector<P>,greater<P> > pq;

template <typename T>
int Count(const vector<T> &v, T l,T r){
  //counting [l,r]
  auto L = lower_bound(v.begin(), v.end(), l );
  auto R = upper_bound(v.begin(), v.end(), r );
  // [l,r) change upper -> lower
  return R-L;
}
int n,a[200000],sm1[200000],sm2[200000],x1[200000],x2[200000];

signed main(){
 
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i],sm1[i]=a[i],sm2[i]=a[i];
  }

  for(int i=1;i<n;i++)sm1[i]+=sm1[i-1];
  for(int i=n-2;i>=0;i--)sm2[i]+=sm2[i+1];
  
  for(int i=n-1;i>=0;i--){
    int y=(i+1<n?x1[i+1]:0);
    if(a[i]==0)x1[i]=min(y+2,sm2[i]);
    else x1[i]=min(y+a[i]%2,sm2[i]);
  }

  for(int i=0;i<n;i++){
    int y=(i-1>=0?x2[i-1]:0);
    if(a[i]==0)x2[i]=min(y+2,sm1[i]);
    else x2[i]=min(y+a[i]%2,sm1[i]);
  }
  
  int ans=1e9,c=0,f=1;

  for(int i=0;i<n;i++){
    ans=min(ans,x1[i]+c);
    if(a[i]%2==0)c=min(c+1,x2[i]);
  }

  ans=min(ans,c);

  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int W, H; cin >> W >> H;
    vector<PII> E;
    for(int i=0; i<W; i++){
        int p; cin >> p;
        E.push_back({p, 0});
    }
    
    for(int i=0; i<H; i++){
        int q; cin >> q;
        E.push_back({q, 1});
    }

    sort(E.begin(), E.end());
    ll ans = 0;
    
    int w = W + 1;
    int h = H + 1;
    for(int i=0; i<W+H; i++){
        if(E[i].sc==0){
            ans += (ll)E[i].fs * h;
            w--;
        }
        else{
            ans += (ll)E[i].fs * w;
            h--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2548
def f(n, a):
    inf = float("inf")
    dp = [[0] * n for _ in range(n)]
    for i in range(n - 2, -1, -1):
        s = a[i]
        dpi = dp[i]
        for j in range(i + 1, n):
            mn = inf
            s += a[j]
            for d in range(i, j):
                k = dpi[d] + dp[d + 1][j]
                if k < mn:
                    mn = k
            dpi[j] = mn + s
    return dp[0][-1]


n = int(input())
a = tuple(map(int, input().split()))
print(f(n, a))


Measured memory_bytes: 7460
#include <bits/stdc++.h>
using namespace std;
int  main(){
int n;
  cin>>n;
  double value=0;
  cout<<setprecision(20);
  cout<<fixed;
  
  for ( int i=0;i<n;i++)
  {
    double aa;
    cin>>aa;
    value+=1/aa;
  }
  cout<<1/value<<'\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<array>
#include<algorithm>

using namespace std;

int main()
{
	int n, a = 0, b = 0, c = 0, count = 0;
	float abc = 0;
	cin >> n;
	array<int, 2000> l;
	l.fill(0);
	for(a = 0; a < n; a++)
		cin >> l[a];
	
	sort(l.begin(), l.end(), greater<int>());
	for(a = 0; a < n; a++)
	{
		for(b = a+1; b < n; b++)
		{
			for(c = b+1; l[b]+l[c] > l[a] && c < n; c++)
			{
				//cout << l[a] << " " << l[b] << " " << l[c] << endl;
					count++;
			}
		}
	}
	cout << count << endl;
	return 0;
}



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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
	fastio;

	int h, n;
	cin >> h >> n;
	vector<int> dp(h + 1, INT_MAX);
	dp[0] = 0;
	while(n--) {
		int a, b;
		cin >> a >> b;
		for(int i = 0; i <= h; ++i) {
			int j = min(h, i + a);
			dp[j] = min(dp[j], dp[i] + b);
		}
	}
	cout << dp[h];

	return 0;
}


Measured memory_bytes: 3716
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io, flush := NewIO()
	defer flush()
	n, m := io.ScanInt(), io.ScanInt()
	homeworks := io.ScanInts(m)
	total := Sum(homeworks...)
	if total > n {
		fmt.Println(-1)
		return
	}
	fmt.Println(n - total)
}

func Sum(nums ...int) (sum int) {
	for _, n := range nums {
		sum += n
	}
	return sum
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 2320
#include<iostream>
#include<algorithm>//next_permutation
using namespace std;

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

int main(){
    int n;cin>>n;
    int array[n];
    rep(i,n)array[i]=i+1;
    
    int a[n],b[n];
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    
    int cc=0,cc1,cc2;
    
    do{
        cc++;
        int c1=0;
        int c2=0;
        rep(i,n){
            if(array[i]==a[i])c1++;
            if(array[i]==b[i])c2++;
        }
        if(c1==n)cc1=cc;
        if(c2==n)cc2=cc;
    }while(next_permutation(array,array + n));
    
    cout<<abs(cc2-cc1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,x,i,j,k,t;
	while(1){
		scanf("%d %d",&n,&x);
		if(n==0&&x==0)break;
		t=0;
		for(i=1;i<=n;i++)for(j=i+1;j<=n;j++)for(k=j+1;k<=n;k++){
			if(i!=j&&j!=k&&i+j+k==x)t++;
		}
		printf("%d\n",t);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  int ans[200005];
  ans[0] = 0;
  int tmp;
  for(int i=1;i<200005;++i) {
    tmp = 0;
    for(int j=0;j<20;++j) {
      if((i&(1<<j))!=0) tmp++;
    }
    ans[i] = 1 + ans[i%tmp];
  }
  tmp = 0;
  for(int i=0;i<S.size();++i) {
    if(S[i]=='1') tmp++;
  }
  if(tmp==0) {
    for(int i=0;i<S.size();++i) cout<<1<<endl;
    return 0;
  }
  if(tmp==1) {
    for(int i=0;i<S.size();++i) {
      if(S[i]=='0') {
        if(i==S.size()-1) cout<<2<<endl;
        else cout<<1<<endl;
      }
      else {
        cout<<0<<endl;
      }
    }
    return 0;
  }
  int tmpadd=tmp+1, tmpsub=tmp-1;
  int add=0, sub=0;
  int twoadd=1, twosub=1;
  for(int i=S.size()-1;i>=0;--i) {
    if(S[i]=='1') {
      add += twoadd;
      sub += twosub;
      add %= tmpadd;
      sub %= tmpsub;
    }
    twoadd *= 2;
    twoadd %= tmpadd;
    twosub *= 2;
    twosub %= tmpsub;
  }
  int ans1[S.size()];
  twoadd=1;
  twosub=1;
  for(int i=S.size()-1;i>=0;--i) {
    if(S[i]=='1') {
      ans1[i] = 1+ans[(sub-twosub+tmpsub)%tmpsub];
    }
    else {
      ans1[i] = 1+ans[(add+twoadd)%tmpadd];
    }
    twoadd *= 2;
    twoadd %= tmpadd;
    twosub *= 2;
    twosub %= tmpsub;
  }
  for(int i=0;i<S.size();++i) cout<<ans1[i]<<endl;
}



Measured memory_bytes: 5312
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		char[] s = scanner.next().toCharArray();
		char[] t = scanner.next().toCharArray();



		for(int i = s.length-t.length; i >= 0; i--){
			boolean flag = false;
			char[] temp = new char[s.length];
			System.arraycopy(s, 0, temp, 0, s.length);

			for(int j = 0; j < t.length; j++){
				if(temp[i+j] == t[j] || temp[i+j] == '?'){
					flag = true;
					temp[i+j] = t[j];
				}else {
					flag = false;
					break;
				}
			}

			if(flag){
				for(int j = 0; j < s.length; j++){
					if(temp[j] == '?'){
						temp[j] = 'a';
					}
					System.out.print(temp[j]);
				}
				System.out.println();
				return;
			}
		}
		System.out.println("UNRESTORABLE");
	}
}



Measured memory_bytes: 23764
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int num[] = {3, 3, 3, 3, 3, 4, 3, 4};
    char x = 'a';
    vector<char> button(256);
    for(int i=0; i<8; ++i){
        for(int j=0; j<num[i]; ++j){
            button[x] = '2' + i;
            ++ x;
        }
    }

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        map<string, vector<string> > dic;
        for(int i=0; i<n; ++i){
            string s;
            cin >> s;
            int m = s.size();
            string b(m, ' ');
            for(int i=0; i<m; ++i)
                b[i] = button[s[i]];
            dic[b].push_back(s);
        }

        string press;
        cin >> press;
        n = press.size();
        vector<vector<string> > ret(n+1);
        ret[0].push_back("");
        for(int i=0; i<n; ++i){
            for(int j=max(0, i-49); j<=i; ++j){
                string s = press.substr(j, i-j+1);
                map<string, vector<string> >::iterator it = dic.find(s);
                if(it != dic.end()){
                    for(unsigned k=0; k<ret[j].size(); ++k){
                        for(unsigned l=0; l<it->second.size(); ++l){
                            ret[i+1].push_back(ret[j][k] + it->second[l] + ' ');
                        }
                    }
                }
            }
        }

        for(unsigned k=0; k<ret[n].size(); ++k){
            ret[n][k][ret[n][k].size()-1] = '.';
            cout << ret[n][k] << endl;
        }
        cout << "--" << endl;
    }
}

Measured memory_bytes: 0
N = int(input())
S = list(map(int,input().split()))
B = list(reversed(S))
B.sort()
count = 0
for i in range(len(S)):
    if S[i] != B[i]:
        count += 1
if count == 2 or count == 0:
    print("YES")
else:
    print("NO")

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

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

  int n;
  cin>>n;

  double pi = acos(-1);
  cout.precision(10);
  cout<<fixed<<pi * 2 * n << endl;

	return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N;
	cin >> N;
	if (N/100 == N%10)
		cout << "Yes\n";
	else
		cout << "No\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256