akhauriyash/Code-Regression huggingface dataset:
//
//AtCoder Beginner Contest 134
//D - Preparing Boxes
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int m = 0;
    vector<int> b(n, 0);

    REPD(i, n){
        int x = a[i];
        int sum = 0;
        for(int j=i; j<n; j+=(i+1)){
            sum+=b[j];
        }
        if (sum%2 != a[i]){
            m++;
            b[i] = 1;
        }
    }

    cout << m << endl;
    REP(i,n) {
        if (b[i]==1) cout << i+1 << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2432
#define _USE_MATH_DEFINES 
#include <cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#define rep(i,start,n) for(int i=start;i<n;i++)
#define And &&
#define Or ||
#define Lb cout<<endl
using namespace std;

int main(void) {
	int r, c; cin >> r >> c;
	vector<vector<int> > a(r, vector<int>(c));
	vector<int> b(r);
	vector<int> cc(c);
	rep(i, 0, r) {
		rep(j, 0, c) {
			cin >> a[i][j];

		}
	}
	rep(i, 0, r) {
		rep(j, 0, c) {
			b[i] += a[i][j];
		}
	}
	rep(i, 0, c) {
		rep(j, 0, r) {
			cc[i] += a[j][i];
		}
	}
	int d = 0;
	rep(i, 0, r) {
		d += b[i];
	}
	rep(i, 0, r) {
		rep(j, 0, c) {
			cout << a[i][j]<<" ";
		}
		cout << b[i] << endl;
	}
	rep(i, 0, c) {
		cout << cc[i]<<" ";
	}
	cout << d << endl;


}

Measured memory_bytes: 1256
from collections import deque
def bfn():
    q=deque([0])
    visit[0]=True
    while q:
        room_proper=q.popleft()
        for i in graph[room_proper]:
            if visit[i]==False:
                visit[i]=True
                shirube[i]=room_proper
                q.append(i)



if __name__ == "__main__":

    n,m=map(int,input().split())
    shirube=[0]*n
    b=[]
    visit=[False]*n
    graph=[[]*n for _ in range(n)]
    for i in range(m):
        a,b=map(int,input().split())
        a-=1
        b-=1
        graph[a].append(b)
        graph[b].append(a)
    bfn()

    if all(visit)==True:
        print("Yes")
        for i in range(1,n):
            print(shirube[i]+1)
    else:
        print("No")


Measured memory_bytes: 34764
#include <stdio.h>
int main(void)
{
  
	long long a,b,x,y=0;
    
	scanf("%lld%lld%lld",&a,&b,&x);
	if(a%x==0) y++;
	printf("%lld\n",b/x-a/x+y);
  
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int main(){
  string s;
  while(cin>>s,s[0]!='#'){
    string t[9];
    int q=0,r=0,a,b,c,d;
    r(i,s.size()){
      if(s[i]=='/')r++,q=0;
      else if(s[i]=='b')t[r]+='b',q++;
      else r(j,s[i]-'0')t[r]+='.',q++;
    }
    cin>>a>>b>>c>>d;
    a--;b--;c--;d--;
    if(t[a][b]=='.')t[a][b]='b',t[c][d]='.';
    else t[a][b]='.',t[c][d]='b';
    r(i,r+1){r(j,q){
      if(t[i][j]=='b')cout<<'b';
      else{
        int p=0;
        for(;j<q;j++,p++)if(t[i][j+1]!='.')break;
        cout<<p+1;
      }
      }
      if(i!=r)cout<<'/';
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define int long long 

int dp[200005],a[100005];
int32_t main()
{
    int n,k,i;
    scanf("%d%d",&n,&k);

    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    
    int j;

    for(i=0;i<=k;i++)
    {
        if(dp[i]==0)
        {
            for(j=1;j<=n;j++)
                dp[i+a[j]] = 1;
        }
    }

    if(dp[k])
        printf("First\n");
    else 
        printf("Second\n");
    return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  k %= 2;
  k += 2;
  while (k--) {
    ll a2, b2, c2;
    a2 = b + c;
    b2 = c + a;
    c2 = a + b;
    a = a2; b = b2; c = c2;
  }
  cout << a - b << endl;
}


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

int main()
{
	int n,m=1;
	string s;

	cin >> n>>s;

	for (int i = 0;i < n;i++)
	{
		if (s[i] != s[i + 1]&& i+1<n)
		{
			m++;
		}
	}

	cout << m;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[20];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	int ret=mod;
	for(int i=0;i+2<n;i++){
		ret=min(ret,ABS(753-((in[i]-'0')*100+(in[i+1]-'0')*10+in[i+2]-'0')));
	}
	printf("%d\n",ret);
}


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

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

    int r,s,p;
    cin >> r >> s >> p;
    string t;
    cin >> t;

    ll ans = 0;
    vector<char>was(n ,'x');
    for(int i=0;i<n;i++){
        if(i-k >=0){
            if(was[i-k]!='r' && t[i]=='r'){
                ans += p;
                was[i] = 'r';
            }
            if(was[i-k]!='s' && t[i]=='s'){
                ans += r;
                was[i] = 's';
            }
            if(was[i-k]!='p' && t[i]=='p'){
                ans += s;
                was[i] = 'p';
            }
        }else{
            if( t[i]=='r'){
                ans += p;
                was[i] = 'r';
            }
            if( t[i]=='s'){
                ans += r;
                was[i] = 's';
            }
            if( t[i]=='p'){
                ans += s;
                was[i] = 'p';
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(n):
        h = min(a[i], b[i])
        cnt += h
        a[i] -= h
        b[i] -= h
        h = min(a[i+1], b[i])
        cnt += h
        a[i+1] -= h
        b[i] -= h
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 76416
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define PII pair<int,int>
#define X first
#define Y second
#define MP make_pair
#define PI acos(-1.0)
#define eps 1e-8
const int maxn=5e4+10;
const int maxm=1.5e7+10;
const int mod=998244353;
using namespace std;
 
int n;
int a[maxn];
char s[maxn];
vector<int>st[3];

int main()
{
    scanf("%d%s",&n,s);
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R') a[i]=0;
        else if(s[i]=='G') a[i]=1;
        else a[i]=2;
        st[a[i]].pb(i);
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=2;j++)
        {
            for(int k=0;k<=2;k++)
            {
                if(j!=k&&j!=a[i]&&k!=a[i])
                {
                    vector<int>::iterator it=lower_bound(st[j].begin(),st[j].end(),i);
                    for(;it!=st[j].end();it++)
                    {
                        int tmp=2*(*it)-i;
                        ans+=st[k].end()-lower_bound(st[k].begin(),st[k].end(),*it);
                        vector<int>::iterator itt=lower_bound(st[k].begin(),st[k].end(),tmp);
                        if(itt!=st[k].end()&&*itt==tmp)
                            ans--;
                    }
                }
            }
        }
    }
    printf("%lld",ans);
    // system("pause");
    return 0;
}

Measured memory_bytes: 3840
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int alice(char c, int x, int y);
int main(){
  vector<int> q(4);
  while(cin >>q[0]>>q[1]>>q[2]>>q[3],q[0]||q[1]||q[2]||q[3]){
    vector<char> a(3),b(3),c(3);
    a[0] = b[0] = c[0] = '+';
    a[1] = b[1] = c[1] = '-';
    a[2] = b[2] = c[2] = '*';
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    sort(q.begin(),q.end());
    do{
      do{
	do{
	  do{
	    if(alice(a[0],q[0],alice(b[0],q[1],alice(c[0],q[2],q[3]))) == 10){
	      cout <<"("<<q[0]<<" "<<a[0]<<" ("<<q[1]<<" "<<b[0]<<" ("<<q[2]<<" "<<c[0]<<" "<<q[3]<<")))"<<endl;
	      goto flag;
	    }
	    if(alice(a[0],q[0],alice(c[0],alice(b[0],q[1],q[2]),q[3])) == 10){
	      cout <<"("<<q[0]<<" "<<a[0]<<" (("<<q[1]<<" "<<b[0]<<" "<<q[2]<<") "<<c[0]<<" "<<q[3]<<"))"<<endl;
	      goto flag;
	    }
	    if(alice(b[0],alice(a[0],q[0],q[1]),alice(c[0],q[2],q[3])) == 10){
	      cout <<"(("<<q[0]<<" "<<a[0]<<" "<<q[1]<<") "<<b[0]<<" ("<<q[2]<<" "<<c[0]<<" "<<q[3]<<"))"<<endl;
	      goto flag;
	    }
	    if(alice(c[0],alice(b[0],alice(a[0],q[0],q[1]),q[2]),q[3]) == 10){
	      cout <<"((("<<q[0]<<" "<<a[0]<<" "<<q[1]<<") "<<b[0]<<" "<<q[2]<<") "<<c[0]<<" "<<q[3]<<")"<<endl;
	      goto flag;
	    }
	    if(alice(a[0],q[0],alice(c[0],alice(b[0],q[1],q[2]),q[3])) == 10){
	      cout <<"("<<q[0]<<" "<<a[0]<<" (("<<q[1]<<" "<<b[0]<<" "<<q[2]<<") "<<c[0]<<" "<<q[3]<<"))"<<endl;
	      goto flag;
	    }
	  }while(next_permutation(q.begin(),q.end()));
	}while(next_permutation(a.begin(),a.end()));
      }while(next_permutation(b.begin(),b.end()));
    }while(next_permutation(c.begin(),c.end()));
    cout <<"0"<<endl;
  flag:;
  }
  return 0;
}
int alice(char c, int x, int y){
  if(c == '+') return x+y;
  if(c == '-') return x-y;
  return x*y;
}

Measured memory_bytes: 1224
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define MAX 500000
#define K 30
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;

int n,x[1001],dp[5000];
vi adj[5000];

bool dfs(int s){
    int mn=0,mx=0;
    vi v;
    for(auto t:adj[s]){
        if(!dfs(t))return false;
        int X = min(dp[t],x[t]);
        int y = max(dp[t],x[t]);
        v.pb({y-X});
        mn+=X;
        mx+=y;
    }
    bitset<5005> bit;
    bit[0]=1;
    for(auto t:v){
        bit|=(bit<<t);
    }
    for(int i=x[s]-mn;i>=0;i--)if(bit[i]){
        dp[s] = mx-i;
        return true;
    }
    return false;
}

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
    cin >> n ;
    for(int i=2;i<=n;i++){
        int p;
        cin >> p;
        adj[p].pb(i);
    }
    for(int i=1;i<=n;i++)cin >> x[i];
    if(dfs(1)){
        cout << "POSSIBLE" << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }

return 0;}
///....


Measured memory_bytes: 1280
N=int(input())
a=list(map(int,input().split()))
a.sort()
n=a[-1]
r=0
#print(a)
tmp=0
for i in range(N):
    b=min(a[i],n-a[i])
    if tmp<b:
        tmp=b
        r=a[i]

print(str(n)+" "+str(r))

Measured memory_bytes: 62704
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
 
	public static void main(String[] args) {
		new Main();	
	}
 
	public Main() {
		new A().doIt();
	}
	class A{
		int large[]={60,80,100,120,140,160};
		int kgs[]={2,5,10,15,20,25};
		int num[]={600,800,1000,1200,1400,1600};
		int money(int kg,int xyz){
			int result = 0;
			for(int i = large.length - 1;i >= 0;i--){
				if(kg <= kgs[i] && xyz <= large[i])result = num[i];
			}
			return result;
		}
		void doIt(){
			while(true){
				int n = sc.nextInt();
				if(n == 0)break;
				int ans = 0;
				for(int i = 0;i < n;i++){
					int x = sc.nextInt();
					int y = sc.nextInt();
					int z = sc.nextInt();
					int kg = sc.nextInt();
					int max = x+y+z;
					ans = ans + money(kg,max);
				}
				System.out.println(ans);
			}
		}
	}
}

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

int main() {
  int n, l, r;
  int ans = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
      cin >> l >> r;
      ans += r - l + 1;
  }

  cout << ans << endl;
}

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

ll solve(ll h) {
  if (h == 1) {
    return 1;
  }
  return solve(h/2) * 2 + 1;
}

int main() {
  ll H;
  cin >> H;
  
  cout << solve(H) << endl;
  
  return 0;
}

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

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

    if (S == "hi") {
      cout << "Yes" << endl;
    }
    else if (S == "hihi") {
      cout << "Yes" << endl;
    }
    else if (S == "hihihi") {
      cout << "Yes" << endl;
    }
    else if (S == "hihihihi") {
      cout << "Yes" << endl;
    }
  	else if (S == "hihihihihi") {
      cout << "Yes" << endl;
	}
    else {
      cout << "No" << endl;
	}
  }

Measured memory_bytes: 256
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

import itertools
a = tuple(i for i in range(1,n+1))
x = list(itertools.permutations(a))
#print(x)
px = x.index(p)
qx = x.index(q)
print(abs(px-qx))


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

int main(){

    int c11, c12, c13;
    int c21, c22, c23;
    int c31, c32, c33;

    cin >> c11 >> c12 >> c13;
    cin >> c21 >> c22 >> c23;
    cin >> c31 >> c32 >> c33;

    bool ans = false;
    for(int a1 = 0; a1 <= max({c11, c12, c13}); a1++){
        for(int b1 = 0; b1 <= max({c11, c21, c31}); b1++){
            if(c11 == a1 + b1){
                for(int a2 = 0; a2 <= max({c21, c22, c23}); a2++){
                    if(c21 == a2 + b1){
                        for(int b2 = 0; b2 <= max({c12, c22, c32}); b2++){
                            if(c12 == a1 + b2 && c22 == a2 + b2){
                                for(int a3 = 0; a3 <= max({c31, c32, c33}); a3++){
                                    if(c31 == a3 + b1 && c32 == a3 + b2){
                                        for(int b3 = 0; b3 <= max({c13, c23, c33}); b3++){
                                            if(c13 == a1 + b3 && c23 == a2 + b3 && c33 == a3 + b3){
                                                ans = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/*
 * 首先, 如果 k>=n 的话, 显然我们可以构造出所有状态, 相当于n个相同球放到
 * n个相同盒中, 盒子可以空. 即 C(n+n-1,n) (by start and bar).
 *
 * k<n 的情况即必须要有 n-k 个盒子非空, 我们把所有情况算出来去掉不合法情
 * 况即可. 不合法情况: 仅有x个盒子非空 x∈[1,n-k-1], 相当于n个球放到x个盒
 * 子里每个盒子都非空的情况, 算一算即可.
 */

const int mod = 1e9+7;
const int maxn = 5e5;
int fac[maxn], inv[maxn];

int pow(const int a, const int p)
{
    int x = a, ans = 1;
    FOR(i,0,31) {
        if (p & (1<<i)) {
            ans = 1LL * ans * x % mod;
        }
        x = 1LL * x*x % mod;
    }
    return ans;
}

int cnk(const int n, const int k)
{ return 1LL * fac[n] * inv[n-k] % mod * inv[k] % mod; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    fac[0] = inv[0] = 1;
    FOR(i,1,maxn) {
        fac[i] = 1LL*i*fac[i-1] % mod;
        inv[i] = pow(fac[i], mod-2);
    }
    int n,k;
    while (cin >> n >> k) {
        int ans = cnk(n+n-1,n);
        if (k < n) {
            FOR(x,1,n-k) {
                const int y = n-x;
                ans -= 1LL * cnk(n,x) * cnk(x+y-1,y) % mod;
                ans %= mod;
            }
        }
        ans += mod;
        ans %= mod;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}

void solve(){
    ll n;
    cin >> n;
    map<ll,ll> cnt;
    vll v;
    fo(i, n){
        ll x;
        cin >> x;
        if(!cnt[x])v.pb(x);
        cnt[x]++;
    }
    sort(all(v));
    ll p = sz(v);
    ll ans = 0;
    fo(i, p){
        foa(j, i + 1, p){
            foa(k, j + 1, p){
                if(v[i] + v[j] > v[k]){
                    ans += cnt[v[i]]*cnt[v[j]]*cnt[v[k]];
                }
            }
        }
    }
    ANS;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    //pre();
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3844
#include<bits/stdc++.h>
#define lg long long int
#define loop(i,s,e) for(lg i=s;i<=e;i++)
#define iloop(i,s,e) for(lg i=e;i>=s;i--)
#define pb push_back
#define mp make_pair
using namespace std;

lg min(lg a,lg b)
{return a<b?a:b;}
lg max(lg a,lg b)
{return a>b?a:b;}
lg lcm(lg a ,lg b)
{
    return (a*b)/__gcd(a,b);
}
int main()
{
    lg n,x,t;
    cin>>n>>x>>t;
    /*
    vector<lg>a(n,0);
    for(lg i=0;i<n;i++)
        cin>>a[i];
    */
    lg ans = (n/x)*t;
    if(n%x!=0)
        ans+=t;
    cout<<ans<<endl;
}


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

using namespace std;

typedef long long ll;

namespace comb {
	ll fact[500001];
	ll fact_inv[500001];
	const ll MOD = 1000000007;

	ll modpow(ll a, ll b) {
		ll base = 1, kakeru = a;
		while (b > 0) {
			if (b & 1)base *= kakeru, base %= MOD;
			kakeru *= kakeru, kakeru %= MOD;
			b >>= 1;
		}
		return base;
	}

	void setup() {
		fact[0] = 1, fact[1] = 1;
		for (int i = 2; i <= 500000; i++) {
			fact[i] = (fact[i - 1] * i) % MOD;
		}

		fact_inv[500000] = modpow(fact[500000], MOD - 2);

		for (int i = 499999; i >= 0; i--) {
			fact_inv[i] = fact_inv[i + 1] * (i + 1);
			fact_inv[i] %= MOD;
		}

	}

	ll combination(int a, int b) {
		if (a - b < 0)return 0;
		ll ret = fact[a];
		ret *= fact_inv[b], ret %= MOD;
		ret *= fact_inv[a - b], ret %= MOD;
		return ret;
	}

	ll permutation(int a, int b) {
		if (a - b < 0)return 0;
		ll ret = fact[a];
		ret *= fact_inv[a - b], ret %= MOD;
		return ret;
	}

	ll homogeneous(int a, int b) {
		return combination(a + b - 1, b);
	}

}

ll Combination(ll n, ll r) {
	ll ret = 1;
	for (ll i = n; i >= n - r + 1; i--) {
		ret *= i;
		ret %= comb::MOD;
	}
	ret *= comb::fact_inv[r];
	ret %= comb::MOD;
	return ret;
}

int main() {
	ll n, a, b;
	comb::setup();
	cin >> n >> a >> b;
	
	ll ans = -1 + comb::modpow(2, n);
	ans = ans + comb::MOD - Combination(n, a);
	ans %= comb::MOD;
	ans = ans + comb::MOD - Combination(n, b);
	ans %= comb::MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8696
require 'pp'
N=10
H,W=gets.split.map(&:to_i)
c = []
N.times do
  c << gets.split.map(&:to_i)
end
A = []
H.times do
  A << gets.split.map(&:to_i)
end

# ワーシャルフロイド
MAX = 1<<30
N.times do |k|
  N.times do |i|
    N.times do |j|
      c[i][j] = c[i][k]+c[k][j] if c[i][j] > c[i][k]+c[k][j]
    end
  end
end

ans = 0
H.times do |i|
  W.times do |j|
    if A[i][j] == -1 || A[i][j] == 1
      next
    else
      ans += c[A[i][j]][1]
    end
  end
end

p ans

Measured memory_bytes: 3068
import java.util.Scanner;

public class Main {
	static int w;
	static int h;
	public boolean[][] map;
	
	Main(boolean[][] map) {
		this.map = map;
	}
		
	int solve(int y, int x) {
		if (y < 0 || x < 0 || y >= h || x >= w || !map[y][x]) return 0;
		map[y][x] = false;
		return solve(y + 1, x) + solve(y - 1, x) + solve(y, x + 1) + solve(y, x - 1) + 1;
	}
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(true) {
			w = scan.nextInt();
			h = scan.nextInt();
			if (w == 0 && h == 0) break;
			boolean[][] room = new boolean[h][];
			int y = 0;
			int x = 0;
			scan.nextLine();
			for (int i = 0; i < h; i++)
				room[i] = new boolean[w];
			for (int i = 0; i < h; i++) {
				String str = scan.nextLine();
				for (int j = 0; j < w; j++) {
					switch (str.charAt(j)) {
						case '.': room[i][j] = true; break;
						case '#': room[i][j] = false; break;
						case '@':
							room[i][j] = true;
							y = i;
							x = j;
							break;
					}
				}
			}
			System.out.println(new Main(room).solve(y, x));
		}
	}
}

Measured memory_bytes: 47512
#include <iostream>
#include <algorithm>
using namespace std;
int L[205];
int main( void )
{
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for( int i=0; i<2*N; i++ ){
    cin >> L[i];
  }
  sort( L, L+2*N );
  int ret = 0;
  for( int i=0; i<N; i++ ){
    ret += L[i*2];
  }
  cout << ret << endl;
}

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

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

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

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

	int cnt=0;
	for(int i=0; i<n-1; ++i){
		if(a[i]==i+1){
			swap(a[i], a[i+1]);
			cnt++;
		}
	}

	if(a[n-1]==n){
		swap(a[n-1], a[n-2]);
		cnt++;
	}

	cout<<cnt<<endl;


	return 0;
}




Measured memory_bytes: 640
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = unsigned long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;




int main(){
   int n;
   cin >> n;
   vector<ll> t(n), a(n);
   rep(i, n)cin >> t[i] >> a[i];

   REP(i, 1, n - 1){
      ll n = max((a[i - 1] + a[i] - 1) / a[i], (t[i - 1] + t[i] - 1) / t[i]);
      if(n == 0)continue;
      a[i] *= n;
      t[i] *= n;
   }
   cout << a[n - 1] + t[n - 1] << endl;
   //rep(i, n)cout << t[i] << " " << a[i] << endl;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int a, b, c;
  cin >> a >> b >> c;

  cout << (a * c <= b ? c : b / a) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void) 
{
	int x, h;
	double S;
	while (1) {
		scanf("%d", &x);
		scanf("%d", &h);
		if (x == 0 && h == 0) {
			break;
		}
		S = x * x + 4 * 0.5 * x * sqrt(x * 0.5 * x * 0.5 + h * h);
		printf("%f\n", S);
	}
	return 0;
}



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

int mod = 1000000007;

int mul(int x, int y){
	return (1ll*x*y)%mod;
}

int fact(int x){
	long long ret = 1;
	for(int i = 2; i<=x;i++)
		ret = (ret * i)%mod;
	return ret;
}

int power(int a, int p){
	if(p == 0)	return 1;
	int ret = power(a, p/2);
	ret = mul(ret, ret);
	if(p%2)	ret = mul(ret, a);
	return ret;
}

int inv(int a){
	return power(a, mod-2);
}

int main() {
	int x, y;
	cin>>x>>y;
	if((2*x - y)%3 != 0 || (2*y-x)%3 != 0 || 2*x < y || 2*y < x){
		cout<<0;
		return 0;
	}
	int b = (2*x-y)/3;
	int a = (2*y-x)/3;
	cout<<mul(fact(a+b),mul(inv(fact(a)),inv(fact(b))));
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
co = {}
b = gets.split.map(&:to_i)

b.each do |k|
  if co.has_key?(k)
    co[k] +=1
  else
    co[k] = 1
  end
end

sum = 0

co.each do |k, v|
  sum += v*(v-1)/2
end

b.each do |k|
  d = co[k]
  puts sum - (d*(d-1)/2) + (d-1)*(d-2)/2 
end


Measured memory_bytes: 30340
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x>>y>>z>>w;
std::cout << min(x,y)+min(z,w) << '\n';
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){
  ll n;
  cin>>n;

  vector<ll> a(n);
  ll b[n];
  memset(b,0,sizeof(b));

  rep(i,n){
     cin>>a[i];
     ll x=a[i];
     b[x-1]++;
  }

  ll sum=0;
  rep(i,n){
     ll c=(b[i]*(b[i]-1))/2;
     if(c<=0) c=0;
     sum+=c;
  }

   for(int i=1;i<=n;i++){
      ll ans=sum;
      ll y=a[i-1];
      ll x=b[y-1];
      ll mai=(x*(x-1))/2;
      ll plu=((x-1)*(x-2))/2;
      
      if(x==0) {
         mai=0;
         plu=0;
      }
      else if(x==1) plu=0;
       
       
      cout<<ans-mai+plu<<endl;
   }

  
return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define debug(args...){string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> ii;
typedef pair <ii, int> iii;

void err(istream_iterator<string> it){}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
  int n;
  cin >> n;
  vector <pair <ll, ll>> p;
  for(int i = 0; i < n; i++){
    ll x, y;
    cin >> x >> y;
    p.push_back({x, y});
  }
  vector <pair<ll, int>> aux1, aux2;
  int cnt = 0;
  for(auto &[x, y] : p){
    aux1.push_back({x+y, cnt});
    aux2.push_back({x-y, cnt});
    cnt++;
  }
  sort(all(aux1));
  sort(all(aux2));
  int i = aux1[0].second, j = aux1[n-1].second;
  int k = aux2[0].second, l = aux2[n-1].second;
  cout << max(abs(p[i].first-p[j].first)+abs(p[i].second-p[j].second),
  abs(p[k].first-p[l].first)+abs(p[k].second-p[l].second)
  ) << endl;
  return 0;
}

Measured memory_bytes: 15876
s = [input() for i in range(3)]
flg = 1
while(True):
    if flg == 1:
        if s[0] == '':
            print('A')
            break
        elif s[0][0] == 'a':
            s[0] = s[0][1:]
            flg = 1
        elif s[0][0] == 'b':
            s[0] = s[0][1:]
            flg = 2
        elif s[0][0] == 'c':
            s[0] = s[0][1:]
            flg = 3
        
    elif flg == 2:
        if s[1] == '':
            print('B')
            break
        elif s[1][0] == 'a':
            s[1] = s[1][1:]
            flg = 1
        elif s[1][0] == 'b':
            s[1] = s[1][1:]
            flg = 2
        elif s[1][0] == 'c':
            s[1] = s[1][1:]
            flg = 3

    elif flg == 3:
        if s[2] == '':
            print('C')
            break
        elif s[2][0] == 'a':
            s[2] = s[2][1:]
            flg = 1
        elif s[2][0] == 'b':
            s[2] = s[2][1:]
            flg = 2
        elif s[2][0] == 'c':
            s[2] = s[2][1:]
            flg = 3

Measured memory_bytes: 3064
#![allow(unused_imports)]
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;
use std::str::FromStr;

type Error = Box<dyn std::error::Error>;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

struct Scanner {
    buff: Vec<String>,
    pos: usize,
}


#[allow(dead_code)]
impl Scanner {
    pub fn new() -> Self {
        Scanner {
            buff: Vec::new(),
            pos: 0,
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T {
        while self.buff.len() <= self.pos {
            self.pos = 0;
            self.buff = read_line().split_whitespace().map(|s| s.to_owned()).collect();
        }

        let result = self.buff[self.pos].parse::<T>();
        self.pos += 1;
        result.ok().unwrap()
    }

    pub fn next_line(&mut self) -> String {
        let result  = read_line().trim().to_owned();
        self.buff.clear();
        self.pos = 0;

        result
    }

    pub fn next_vec<T: FromStr>(&mut self) -> Vec<T> {
        self.buff.clear();
        self.pos = 0;
        read_line().trim().split_whitespace().map(|s| s.parse().ok().unwrap()).collect()
    }
    
    pub fn next_line_chars(&mut self) -> Vec<char> {
        let result  = read_line().trim().chars().collect();
        self.buff.clear();
        self.pos = 0;

        result
    }
}

fn func(n: &Vec<char>, idx: usize, k: usize) -> u64 {
    if k==0 {
        return 1;
    }
    if idx >= n.len() {
        return 0;
    }

    let m = n.len();
    let p = (n[idx] as u8 - '0' as u8) as u64;
    let mut tmp = 0;
    if p > 0 {
        tmp += dbg!((p-1) * func2(m-idx, k-1));
        tmp += func(n, idx+1, k-1);
        tmp += func2(m-idx, k);
    } else {
        tmp += func(n, idx+1, k);
    }
    
    dbg!(tmp)
}

fn func2(m: usize, k: usize) -> u64 {
    if m < k || m == 0 {
        return 0;
    }
    let mut tmp = 1;

    for _i in 0..k {
        tmp *= 9 as u64;
    }

    for i in 0..k {
        tmp *= (m-i-1) as u64;
    }
    for i in 0..k {
        tmp /= (i+1) as u64;
    }
    dbg!(tmp)
}

fn func3(n: &Vec<char>, k:usize) -> u64 {
    let mut ans = 0;
    let mut tmp = 0;
    for &c in n.iter() {
        tmp *= 10;
        tmp += (c as u8 - '0' as u8) as u64;
    }
    let n = tmp;
    for i in 0..n+1 {
        let mut tmp = i;
        let mut count = 0;
        while tmp > 0 {
            let p = tmp %10;
            if p > 0 {
                count += 1;
            }
            tmp /= 10;
        }
        if count == k {
            ans += 1;
        }
    }
    ans
}


fn main() {
    let mut sc = Scanner::new();

    let n: Vec<char> = sc.next_line_chars();
    let k: usize = sc.next();
    let mut m = n.len();

    let ans: u64 = func(&n, 0, k);
    // for i in 1..1000000 {
    //     for k in 1..4 {
    //         let n: Vec<char> = i.to_string().chars().collect();
    //         println!("check: {} {}", i, k);
    //         debug_assert_eq!(func(&n, 0, k), func3(&n, k));
    //     }
    // }


    println!("{}", ans);
}


Measured memory_bytes: 2164
program main
    implicit none
    integer(8) i, n, ans
    ans = 0
    read *, n
    do i = 1, n
        if (mod(i, 3) /= 0 .and. mod(i, 5) /= 0) then
            ans = ans + i
        end if
    end do
    print "(i0)", ans
 end program main

Measured memory_bytes: 2884
N = gets.to_i
A = gets.split.map!(&:to_i)
B = gets.split.map!(&:to_i)
C = gets.split.map!(&:to_i)

ans = 0
0.upto(N-1) do |i|
  ans += B[A[i]-1]
  ans += C[A[i-1]-1] if i > 0 && A[i] - 1 == A[i-1]
end

puts ans


Measured memory_bytes: 1788
from itertools import product

ans = 0
H, W, k = map(int, input().split())

field = [None] * H
for i in range(H):
    field[i] = input()

for hbit in product([0, 1], repeat=H):
    for wbit in product([0, 1], repeat=W):
        hb = list(hbit)
        wb = list(wbit)
        cnt = 0
        for h in range(H):
            for w in range(W):
                if hb[h] == 0 and wb[w] == 0 and field[h][w] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)


Measured memory_bytes: 74180
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> v(m);
    ll sum = 0;
    rep(i,m){
        ll a;
        cin>>a;
        sum+=a;
    }
    if(sum>n) cout<<"-1"<<endl;
    else cout<<n-sum<<endl;
    return 0;
}


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

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
                int[] b = new int[n];
                int[] f = new int[n];
                int[] r = new int[n];
                int[] v = new int[n];
                int[,,] room = new int[4, 3, 10];

            for (int i = 0; i < n; i++)
            {
                List<int> list = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
                    b[i] = list[0] - 1;
                    f[i] = list[1] - 1;
                    r[i] = list[2] - 1;
                    room[b[i],f[i],r[i]] += list[3];
            }

            for (int i = 0; i < 4; i++)
            {
                for(int j = 0; j < 3; j++)
                {
                    for(int k = 0; k < 10; k++)
                    {
                        Console.Write(" " + room[i, j, k]);
                    }
                    Console.WriteLine();

                }
                if (!(i == 3))
                {
                    Console.WriteLine("####################");
                }
            }

        }
    }
}



Measured memory_bytes: 16324
#![allow(non_snake_case, unused_variables, unused_mut, dead_code)]
//use permutohedron::LexicalPermutation as _;
//use proconio::input;
//use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;

fn main() {
    proconio::input! {
        mut A:[usize;9],
        N:usize,
        B:[usize;N]
    }
    for i in 0..N {
        A = A.iter().map(|&a| if a == B[i] { 0 } else { a }).collect();
    }
    //println!("{:?}", A);
    for i in 0..3 {
        if (A[i + 0] == 0 && A[i + 3] == 0 && A[i + 6] == 0)
            || (A[i * 3] == 0 && A[i * 3 + 1] == 0 && A[i * 3 + 2] == 0)
        {
            println!("Yes");
            return;
        }
    }

    if (A[0] == 0 && A[4] == 0 && A[8] == 0) || (A[2] == 0 && A[4] == 0 && A[6] == 0) {
        println!("Yes");
        return;
    }
    println!("No");
}


Measured memory_bytes: 2084
import java.util.Scanner;

public class Main{
	static char[][] keitai = {{},{'.',',','!','?',' '},{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'},{'m','n','o'},{'p','q','r','s'},{'t','u','v'},{'w','x','y','z'}};
	static char change(int a,int b) {
		int d = 0;
		if(a==0)
			d = 0;
		if(b==1)
			d = b%4;
		if(b==7 || b==9) {
			d = b%3;
		}
		else
			d = b%2;
		char in = keitai[a][d];
		return in;
	}
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			for(int j=0;j<n;j++) {
				char[] s = sc.next().toCharArray();
				StringBuilder sb = new StringBuilder(s.length);

				int i = 0;
				while(i<s.length){
	                if(s[i]=='0')i++;
	                else{
	                    char c = s[i++];
	                    int k = 0;
	                    while(s[i]==c){i++;k++;}
	                    sb.append(keitai[c-'0'][k%keitai[c-'0'].length]);
	                    i++;
	                }
	            }
				System.out.println(sb.toString());
			}
		}
	}
}



Measured memory_bytes: 29280
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];


int main()
{
	long long N, cnt = 0, tmp, ans = 0;
	long long i;

	cin >> N >> i;
	cout << N - i + 1;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	//入力
	int N, K;
	cin >> N >> K;

	vector<ll> V(N);
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}

	//A,Bを全探索
	ll total_value;
	ll minus_total;
	ll max_value = 0;
	vector<ll> V_minus(0);
	for (int A = 0; A <= K; A++) {
		for (int B = 0; A + B <= K; B++) {
			if (A + B > N) {//宝石が空なのに拾ってもしゃーない
				break;
			}

			//拾う
			total_value = 0;
			V_minus.clear();

			for (int i = 0; i < A; i++) {
				total_value += V[i];
				if (V[i] < 0) {//負なら負の価値の宝石の配列にadd
					V_minus.push_back(V[i]);

				}
			}

			for (int i = 0; i < B; i++) {
				total_value += V[N - 1 - i];
				if (V[N - 1 - i] < 0) {//負なら負の価値の宝石の配列にadd
					V_minus.push_back(V[N - 1 - i]);
				}
			}

			//負の宝石を昇順ソート
			sort(V_minus.begin(), V_minus.end());

			//K-(A+B)だけ捨てる。それ以下なら全部捨てることになるね。
			minus_total = 0;
			for (int i = 0; i < K - (A + B); i++) {
				if (i == V_minus.size()) { break; }//負の宝石を使い切ったらbreak
				minus_total += V_minus[i];
			}

			//負の宝石を捨てる（＝その分足す）
			if (max_value < total_value - minus_total) {
				max_value = total_value - minus_total;
			}
		}
	}

	cout << max_value;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
L = [list(map(int,input().split()))[1:] for _ in range(N)]

# 人[0, N) 言語[N N+M)
ad = [[] for _ in range(N+M)]

for i in range(N):
    for l in L[i]:
        l -= 1
        ad[i].append((l+N, 1))
        ad[l+N].append((i, 1))

from heapq import heappush, heappop
inf = float('inf')

# 計算量O((E+V)logV)
# 引数(始点,隣接リスト)
def dijkstra(start,ad):
    global dist
    #global cnt
    N = len(ad)
    dist = [inf] * N
    dist[start] = 0
    #cnt = [0] * N
    #cnt[start] = 1
    pq = [(dist[start], start)]
    while pq:
        dist_v, v = heappop(pq)
        for nv, nw in ad[v]:
            if dist[nv] > dist_v + nw:
                dist[nv] = dist_v + nw
                heappush(pq,(dist[nv], nv))
            #if dist[nv] == dist_v + nw:
                #cnt[nv] += cnt[v]
                #cnt[nv] %= mod

dijkstra(0, ad)

for i in range(N):
    if dist[i] == inf:
        print("NO")
        exit()

print("YES")

Measured memory_bytes: 64480
#include<iostream>
#include<stack>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

int main(){
	stack<int> intStack;
	char c[5];
	
	while((scanf("%s",&c))!=EOF){
		
		if(c[0]=='+'||c[0]=='-'||c[0]=='*'){
			int in,a,b;
			b=intStack.top();intStack.pop();
			a=intStack.top();intStack.pop();
			switch (c[0]){
				case '+':	in=a+b;break;
				case '-':	in=a-b;break;
				case '*':	in=a*b;break;
				default: break;
			}
			intStack.push(in);
		}else{
			intStack.push(atoi(c));
		}
		
	}
	cout<<intStack.top()<<endl;
	return 0;
	
}

Measured memory_bytes: 1204
N = int(input())
nine = [9**5, 9**4, 9**3, 9**2, 9, 1]
six = [6**6, 6**5, 6**4, 6**3, 6**2, 6, 1]
counter = 100000

for i in range(N+1):
    j = N-i
    countN = 0
    for k in nine:
        if not i:
            break
        countN += i // k
        i = i % k

    countS = 0
    for k in six:
        if not j:
            break
        countS += j // k
        j = j % k

    counter = min(counter, countN+countS)

print(counter)


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

ll min_cut(vector<ll> &A, ll x, ll N){
    ll ans = 0;
    rep(i,N){
        if (A[i] % x == 0) ans += (A[i] / x - 1);
        else ans += (A[i] / x);
    }
    return ans;
}

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    sort(all(A));
    ll ans = 0;
    if (min_cut(A, 1, N) <= K){
        ans = 1;
    }
    else{
        ll left = 1;
        ll right = A[N - 1];
        while(true){
            if (right - left == 1){
                ans = right;
                break;
            }
            else{
                if (min_cut(A, (left + right) / 2, N) <= K){
                    right = (left + right) / 2;
                }
                else{
                    left = (left + right) / 2;
                }
            }
        }
    }
    cout << ans << endl;
}


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

int main(){

  int N;


  cin>>N;

  int h[22];
  
  
  for(int i=0;i<N;i++){
	cin>>h[i];
  }

  int cnt=1;
  
  for(int i=1;i<N;i++){

	int maxx=0;
	for(int j=0;j<i;j++){
	  maxx=max(maxx,h[j]);
	}
	if(maxx<=h[i]){
	  cnt++;
	}
  }

  cout<<cnt<<endl;
  
  
  return 0;
}


Measured memory_bytes: 256