akhauriyash/Code-Regression huggingface dataset:
i=0
x=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
k2=0
j2=10
while i<20 :
    x[i]=int(input())
    i=1+i
while k2<9 :
    k=0
    while k<9 :
        if x[k]<x[k+1] : 
            ex=x[k]
            x[k]=x[k+1]
            x[k+1]=ex
        k=k+1
    k2=k2+1
while j2<19 :
    j=10
    while j<19 :
        if x[j]<x[j+1] : 
            ex=x[j]
            x[j]=x[j+1]
            x[j+1]=ex
        j=j+1
    j2=j2+1

ave1=x[0]+x[1]+x[2]
ave2=x[10]+x[11]+x[12]
print(ave1,end=" ")
print(ave2)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)




int main(){
    int S,W;
    cin>>S>>W;
    if(S<=W){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }
}



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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i < N; i++) cin >> x[i];
  int res = 1000000000;
  for (int i = 0; i < N-K+1; i++) {
    int tmp;
    if (x[i] >= 0 && x[i+K-1] >= 0) tmp = x[i+K-1];
    else if (x[i] < 0 && x[i+K-1] < 0) tmp = (-1)*x[i];
    else {
      int a = abs(x[i]);
      int b = abs(x[i+K-1]);
      int c = min(a, b);
      tmp = a+b+c;
    }
    if (tmp < res) res = tmp;
  }
  cout << res << endl;
}


Measured memory_bytes: 640
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;



int main() {
	int n;
	cin >> n;
	cout <<  ((n + 999) / 1000) * 1000 - n << endl;


	return 0;
}


Measured memory_bytes: 3192
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

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

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()

	ans := 0
	for i := 0; i < n; i++ {
		h := nextInt()
		debugf("%d %d\n", h, k)
		if h >= k {
			ans++
		}
	}

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

int main(void) {
  string s; cin >> s;
  const int n = sz(s);
  rep(i,n) {
    s.pop_back();
    if (sz(s) % 2 == 1) continue;
    int m = sz(s)/2;
    if (s.substr(0,m) == s.substr(m,m)) plexit(sz(s))
  }
  return 0;
}


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

using namespace std;

int inter(int l1, int r1, int l2, int r2) {
  return max(0, min(r1, r2) - max(l1, l2) + 1);
}

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

  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; ++i) {
    int l, r;
    cin >> l >> r;
    a[i] = {l, r};
  };
  sort(a.begin(), a.end());
  int ans = 0;
  vector<int> l(n), r(n);
  l[n - 1] = a[n - 1].first, r[n - 1] = a[n - 1].second;
  for (int i = n - 2; i >= 0; --i) {
    l[i] = max(l[i + 1], a[i].first);
    r[i] = min(r[i + 1], a[i].second);
  }
  int L = 0, R = 1e9;
  for (int i = 0; i < n - 1; ++i) {
    ans = max(ans, a[i].second - a[i].first + 1 + inter(L, R, l[i + 1], r[i + 1]));
    L = max(L, a[i].first);
    R = min(R, a[i].second);
    ans = max(ans, max(0, R - L + 1) + max(0, r[i + 1] - l[i + 1] + 1));
  }
  cout << ans;

  return 0;
}

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

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

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

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    string s;
    cin >> s;
    int f=0;
    REP(i,s.length()){
        if(s[i]=='C' && f==0){
            f= 1;
        }
        if(s[i]=='F' && f==1){
            f=2;
        }
    }

    if(f==2){
        cout << "Yes" << ENDL;
    }else{
        cout << "No" << ENDL;
    }
    
    return 0;
}

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

using namespace std;

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

  int N, a; 
  cin >> N;
  set<int> A;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    A.insert(a);
  }
  cout << (A.size() == N ? "YES" : "NO") << endl;

	return 0;
}



Measured memory_bytes: 9600
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
	int a, b, c, d, e, f, g, h, i, N;
	scanf("%d", &N);
	a = N / 100000000;
	b = (N - a * 100000000) / 10000000;
	c = (N - (a * 100000000 + b * 10000000)) / 1000000;
	d = (N - (a * 100000000 + b * 10000000 + c * 1000000)) / 100000;
	e = (N - (a * 100000000 + b * 10000000 + c * 1000000 + d * 100000)) / 10000;
	f = (N - (a * 100000000 + b * 10000000 + c * 1000000 + d * 100000 + e * 10000)) / 1000;
	g = (N - (a * 100000000 + b * 10000000 + c * 1000000 + d * 100000 + e * 10000 + f * 1000 )) / 100;
	h = (N - (a * 100000000 + b * 10000000 + c * 1000000 + d * 100000 + e * 10000 + f * 1000 + g * 100)) / 10;
	i = N - (a * 100000000 + b * 10000000 + c * 1000000 + d * 100000 + e * 10000 + f * 1000 + g*100 + h*10);


	if (N % (a + b + c + d + e+f+g+h+i) == 0) {
		printf("Yes\n");
	}else {
		printf("No\n");
	}


}  

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;scanf("%d%d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<k;i++)ans+=a[n-1-i];
    printf("%d\n",ans);
    return 0;
}

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

int main(void){
  int a, b, c, i;
  cin >> a >> b >> c;
  for(i = 1; i <= b; i++){
    if(a*i%b == c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	double dp[3000];
	dp[0] = 1;
	for (int j = 1; j <= n; j++) dp[j] = 0;
	for (int i = 1; i <= n; i++) {
		double p;
		cin >> p;
		for (int j = n; j >= 0; j--) {
			dp[j] *= (1-p);
			if (j >= 1) dp[j] += dp[j-1] * p;
		}
	}
	double ans = 0;
	for (int j = n/2 + 1; j <= n; j++) ans += dp[j];
	printf("%.15lf\n", ans);
	return 0;
}

Measured memory_bytes: 256
from math import ceil
n,h=[int(i)for i in input().split()]
ab=[[int(i) for i in input().split()] for j in range(n)]
ans=0


a=[ab[i][0] for i in range(n)]
b=[ab[i][1] for i in range(n)]
a.sort()
b.sort()
while h>0 and len(b)>0 and b[-1]>a[-1]:
        h-=b[-1]
        b.pop(-1)
        ans+=1
if h>0:
        ans+=int(ceil(h/a[-1]))
print(ans)

Measured memory_bytes: 23120
package main

import (
	"fmt"
)

type Set [4]int64

func main() {
	var m, n, q int64
	fmt.Scanf("%d %d %d", &n, &m, &q)

	setList := make([]Set, q)
	for i := int64(0); i < q; i++ {
		fmt.Scanf("%d %d %d %d", &setList[i][0], &setList[i][1], &setList[i][2], &setList[i][3])
	}

	score := solve(make([]int64, n), m, setList, -1)

	fmt.Printf("%d\n", score)
}

func solve(a []int64, m int64, setList []Set, deps int) int64 {
	if deps >= len(a) - 1 {
		return calcScore(a, setList)
	}
	nextDeps := deps+1

	first := int64(1)
	if deps >= 0 {
		first = a[deps]
	}
	max := int64(0)
	for i := first; i <= m; i++ {
		nextA := a
		nextA[nextDeps] = i
		score := solve(nextA, m, setList, nextDeps)
		if max < score {
			max = score
		}
	}
	return max
}

func calcScore(a []int64, setList []Set) int64 {
	var score int64
	for _, set := range setList {
		if a[set[1] - 1] - a[set[0] - 1] == set[2] {
			score += set[3]
		}
	}
	return score
}


Measured memory_bytes: 1856
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

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

int cutcount = 0;
class Cake{
	public:
	int h,w,birth;
	Cake(int h,int w):h(h),w(w){
		birth = cutcount;
	}
	
	bool operator<(const Cake& c)const{
		if(birth==c.birth){
			return w*h<(c.w*c.h);
		}
		return birth<c.birth;
	}
};


int main(){
	A:;
	int n,w,h;
	cin>>n>>w>>h;
	if(n==0 && w==0 && h==0)return 0;
	
	vector<Cake> cakes;
	cakes.push_back(Cake(h,w));
	
	rep(i,n){
		int a,b;
		cin>>a>>b;
		a--;
		
		int bw = cakes[a].w;
		int bh = cakes[a].h;
		
		int pos=0;
		while(1){
			rep(j,4){
				int v = bw;
				if(pos==1 || pos==3)v = bh;
				
				if(b<v)goto B;
				pos = (pos+1)%4;
				b-=v;
			}
		}
		B:;
		
		cakes.erase(cakes.begin()+a);
		cutcount++;
		
		if(pos%2==0){
			cakes.push_back(Cake(bh,b));
			cakes.push_back(Cake(bh,bw-b));
		}
		if(pos%2==1){
			cakes.push_back(Cake(b,bw));
			cakes.push_back(Cake(bh-b,bw));
		}
		sort(cakes.begin(),cakes.end());
		/*
		printf("cakes ");
		rep(i,cakes.size()){
			if(i!=0)printf(" ");
			printf("(%d,%d,%d)",cakes[i].w,cakes[i].h,cakes[i].w*cakes[i].h);
		}puts("");*/
	}
	
	
	rep(i,cakes.size()){
		cakes[i].birth=0;
	}
	sort(cakes.begin(),cakes.end());
	
	rep(i,cakes.size()){
		if(i!=0)printf(" ");
		printf("%d",cakes[i].w*cakes[i].h);
	}puts("");
	
	goto A;
}

Measured memory_bytes: 1188
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  int ans = 0;
  if (n == 0) ++ans;
  while ( n > 0 ) {
    ++ans;
    n /= k;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
     
    #define fi first
    #define se second
    #define pb(a) push_back(a)
    #define mp(a, b) make_pair(a, b)
    #define el '\n'
     
    using namespace std;
    using ll = long long;
    using pii = pair<int, int>;
    using pll = pair<ll, ll>;
     
    const int N = 2e5 + 10;
    const ll INF = 1e18;
     
    int n;
    pll ar[N];
     
    ll mn1 = INF, mn2 = INF; // x + y, x - y

	bool valid(ll a){
    	return 1 <= a && a <= 1000000000;
    }
     
    int main () {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
     
        cin >> n;
        for (int i=1;i<=n;i++){
            cin >> ar[i].fi >> ar[i].se;
          assert(valid(ar[i].fi) && valid(ar[i].se));
        } 
        sort(ar + 1, ar + n + 1);
        ll ans = 0;
        for (int i=1;i<=n;i++){
            ll a = ar[i].fi + ar[i].se;
            ll b = ar[i].fi - ar[i].se;
            ans = max(ans, a - mn1);
            ans = max(ans, b - mn2);
            mn1 = min(mn1, a);
            mn2 = min(mn2, b);
        }
        cout << ans << el;
     
        return 0;
    }

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

int main(){
  int64_t k,a,b,ans=1;
  cin >> k >> a >> b;
  if(b-a>2&&k>a-1){
    ans=a;
    k-=a-1;
    ans+=k/2*(b-a);
    //cout << k/2*(b-a) << "#" << k << "#";
    ans+=k%2;
  }else{
    ans+=k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
import java.io.*;
import java.util.Arrays;
class Main{
    public static void main(String[] args) throws IOException {
        int i,j,sum;
        int[] A = new int[100];
        int[][] B = new int[100][100];
        int[] n = new int[990];
        String[] str = new String[990];
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<2;i++){
            n[i]=Integer.parseInt(str[i]);
        }
        for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                B[i][j]=Integer.parseInt(str[j]);
            }
        }
        for(i=0;i<n[1];i++){
            A[i] = Integer.parseInt(in.readLine());
        }
        for(i=0;i<n[0];i++){
            sum=0;
            for(j=0;j<n[1];j++){
                sum+=B[i][j]*A[j];
            }
            System.out.println(sum);
        }
        System.out.flush();
    }
}

Measured memory_bytes: 27184
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll pref[101000];
ll suff[101000];
ll ara[101000];
int main()
{
  int b , r;
  cin >> b;
  map<string,int>blu,red;
  vector<string>v;
  for(int i=0; i<b; i++)
  {
      string s;
      cin >> s;
      blu[s]++;
      if(blu[s]==1)
        v.push_back(s);

  }
  int mx = 0 ;
  cin >> r;
  for(int i=0; i<r; i++)
  {
      string s;
      cin >> s;
      red[s]++;

  }

  for(int i=0; i<v.size(); i++)
  {
      mx = max(mx,blu[v[i]]-red[v[i]]);
  }
  cout << mx << endl;

 }


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

set<pair<int, int>> g[maxn];

string twelve(int a, int b) {
    string aa = to_string(a);
    string bb = to_string(b);
    int zero1 = 6 - aa.size(), zero2 = 6 - bb.size();
    return string(zero1, '0') + aa + string(zero2, '0') + bb;
}

void solve() {
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        g[a].insert({b, i});
    }
    vector<string> ans(m);
    for (int i = 0; i < maxn; i++) {
        int id = 1;
        for (auto x: g[i]) {
            int p = i;
            ans[x.second] = twelve(p, id);
            id++;
        }
    }
    for (auto x: ans)cout << x << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 19456
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
        if((a+b)%2==0)
        {
            printf("%d\n",(a+b)/2);
            return 0;
        }
        else
            printf("IMPOSSIBLE\n");
        return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
vector<ll>adj[100005];
int vis[5];
vector<ll>v;
map<ll,ll>mp;
int main()
{
    ll k,a,b;
    cin>>k>>a>>b;
    ll kk = k;
    if(a>=b || k<a-2)
    {
        cout<<k+1<<endl;
        return 0;
    }
    ll cnt = 0;
    k-=(a-1);
    k--;
    k--;
    if(k<0) {
        cout<<kk+1<<endl;return 0;
    }
    cnt+=b;
    if(k%2)
        cnt++;
    k/=2;

    cnt+=(1LL*(b-a)*k);
    cout<<max(kk+1,cnt)<<endl;
    return 0;
}



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

bool solve(const vector<string>& W){
  const int n = W.size();
  rep(i,n-1){
    if(W[i].back() != W[i+1].front()) return false;
  }
  rep(i,n){
    for(int j = i+1; j<n; j++){
      if(W[i] == W[j]) return false;
    }
  }
  return true;
}

vector<string> input(){
  int n;
  cin >>n;
  vector<string> W(n);
  rep(i,n) cin >>W[i];
  return W;
}

int main(){
  const vector<string> W = input();
  if(solve(W)){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
import bisect
from functools import reduce

def main():
    H, A = MI()
    print(math.ceil(H / A))


if __name__ == "__main__":
    main()



Measured memory_bytes: 74668
N = int(input())

AB = [[int(_) for _ in input().split()] for i in range(N)]
CD = [[int(_) for _ in input().split()] + [0, ] for i in range(N)]
AB.sort(reverse=True)
CD.sort(reverse=True)
ans = 0
for a, b in AB:
    # for c, d, f in CD:
    min_idx = -1
    min_val = 1e10

    for i in range(N):
        c, d, f = CD[i]
        if f: continue
        if c <= a and d <= b: break
        if c <= a or d <= b: continue
        if min_val > d:
            min_val = d
            min_idx = i
    if min_idx >= 0:
        ans += 1
        CD[min_idx][2] = 1
        #print('pare:', (a, b), CD[min_idx])
print(ans)

Measured memory_bytes: 39024
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

dp = [0] * 5005
dp[0] = 1

for a in A:
    for i in range(5000, 0, -1):
        if i - a >= 0:
            dp[i] += dp[i - a]

print(sum(dp[i] for i in range(len(dp)) if i % 2 == P))

Measured memory_bytes: 9544
n,m = map(int,input().split())
ans_value = ['1'] + ['0'] * (n - 1)
check_sum = [0] * n
exist = True

for i in range(m):
	s,c = input().split()
	s = int(s)
	if not ans_value[s-1] == c:
		check_sum[s-1] += 1
	ans_value[s-1] = c
	if check_sum[s-1] >= 2:
		exist = False

if n == 1 and m == 0:
	ans = ['0']
elif n == 1 and exist:
	ans = ans_value
elif n > 1 and exist and not(ans_value[0] == '0'):
	ans = ans_value
else:
	ans = ['-1']

print(''.join(ans))


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

n=int(input())
k=int(input())

dp1=[0]*(k+1)
dp2=[0]*(k+1)
dp1[0]=1

for x in map(int,str(n)):
    for j in range(k,-1,-1):
        if j>0:
            dp2[j]+=dp2[j-1]*9
            if x!=0:
                dp2[j]+=dp1[j-1]*(x-1)+dp1[j]
                dp1[j]=dp1[j-1]
            #print(dp1)
            #print(dp2)
        else:
            dp2[j]=1
            dp1[j]=0
print(dp1[k]+dp2[k])


Measured memory_bytes: 62092
N,M=map(int,input().split())

set_1=set()
set_n=set()
for i in range(M):
  a,b=map(int,input().split())
  if a==1:
    set_1.add(b)
  if b==N:
    set_n.add(a)
    
#print(set_1,set_n)
for x in set_1:
  if x in set_n:
    print("POSSIBLE")
    break
else:
  print("IMPOSSIBLE")

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

int main()
{
    int n,m,s=0,I,O,M=0;
    cin>>n>>m;
    s=m;

    for(int i=0;i<n;i++){
        cin>>I>>O;

        s+=I;
        s-=O;

        if(s<0){
            cout<<0<<endl;
            return 0;
        }

        M=max(M,s);
    }

    cout<<M<<endl;

    return 0;
}


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

#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define MAX(X,Y) ((X)>(Y)?(X):(Y))

int mtx[100][100];
int main(void){
  int n;
  
  cin >> n;
  for (int i=0; i<n; i++){
    int dg;
    cin >> dg >> dg;
    for (int j=0; j<dg; j++){
      int to;
      cin >> to;
      mtx[i][to-1]=1;
    }
  }
  
  for (int i=0; i<n; i++){
    cout << mtx[i][0];
    for (int j=1; j<n; j++){
      cout << " " << mtx[i][j];
    } cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	bool ans = false;
	if(a+b==c)ans = true;
	if(c+b==a)ans = true;
	if(a+c==b)ans = true;
	cout<<((ans)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
main=do
 let x=[1,3,5,7,8,10,12]
     y=[4,6,9,11]
 [a,b]<-map read.words<$>getLine
 putStrLn$if(a==b)||((elem a x)&&(elem b x))||((elem a y)&&(elem b y))then"Yes"else"No"

Measured memory_bytes: 508
def dist(x0, y0, x1, y1):
    from math import sqrt
    return sqrt((x1-x0)**2 + (y1-y0)**2)

from itertools import permutations

N = int(input())
points = [tuple(map(int, input().split())) for _ in range(N)] #; print(points)

dsum = 0
for i, j in permutations(points, 2):
    dsum += dist(*i, *j)
print(dsum/N)

Measured memory_bytes: 8880
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rev(a) a.rbegin(),a.rend()
#define pi pair<int,int>
#define vii vector<pi>
#define size(a)  (int)(a.size())
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define precise(a,k) cout<<fixed<<setprecision(k)<<a;
#define debug(...) cerr<<" ["<<#__VA_ARGS__<<": "<<(__VA_ARGS__)<<"] ";
#define debugv(...) for(int i=0; i<size(__VA_ARGS__); i++) cerr<<" ["<<#__VA_ARGS__<<i<<": "<<(__VA_ARGS__)[i]<<"] ";
const int mod = 1e9+7;
const int inf = 1e9+5;
const int inf64 = 1e18+5;
//           -------"Binary Search Is OP"-------
const int nax = 305;
double p[nax][nax][nax],ev[nax][nax][nax];
void solve(){
    int n;
    cin>>n;
    vector<int> cnt(4);
    rep(i,0,n){
        int x;
        cin>>x;
        cnt[x]++;
    }
    p[cnt[1]][cnt[2]][cnt[3]]=1;
    rep(c,n+1,0){
        rep(b,n+1,0){
            rep(a,n+1,0){
                if(a+b+c>n || a+b+c==0) continue;
                double waste = (double)(n-a-b-c)/n;
                double states = waste/(1-waste) +1;
                ev[a][b][c]+= states*p[a][b][c];
                if(a>0){
                    double t = (double)a/(a+b+c);
                    p[a-1][b][c]+= p[a][b][c]*t;
                    ev[a-1][b][c]+= ev[a][b][c]*t;
                }
                if(b>0){
                    double t = (double)b/(a+b+c);
                    p[a+1][b-1][c]+= p[a][b][c]*t;
                    ev[a+1][b-1][c]+= ev[a][b][c]*t;
                }
                if(c>0){
                    double t = (double)c/(a+b+c);
                    p[a][b+1][c-1]+= p[a][b][c]*t;
                    ev[a][b+1][c-1]+= ev[a][b][c]*t;
                }
            }
        }
    }
    precise(ev[0][0][0],10);

}
signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif
    */
	int test;
	//cin>>test;
	test=1;
	while(test--){
         solve();
         cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 427972
#include <bits/stdc++.h>
using namespace std;
int h[100001], dp[100001];
int main(){
	int N, K; scanf("%d%d",&N,&K);
	for(int i=1; i<=N; ++i) scanf("%d",h+i);
	for(int i=2; i<=N; ++i){
		dp[i] = 2e9;
		for(int j=max(1,i-K); j<i; ++j) dp[i] = min(dp[i], dp[j]+abs(h[i]-h[j]));  
	}
	printf("%d",dp[N]);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int n;
    cin>>n;
    vector<int> p(n),q(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
        q[i]=p[i];
    }
    sort(q.begin(),q.end());
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            vector<int> d(n);
            for(int k=0;k<n;k++){
                d[k]=p[k];
            }
            swap(d[i],d[j]);
            if(d==q){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
def main():
    n, k = map(int, input().split())
    
    a = []
    for i in range(k):
        d = int(input())
        tmp_a = list(map(int, input().split()))
        a.extend(tmp_a)
    ans = len(set(range(1, n+1)) - set(a))
    print(ans)
    
main()


Measured memory_bytes: 9124
n,m = map(int,input().split(" "))

ab_array = []

for i in range(m):
    ab = list(map(int,input().split(" ")))
    ab_array.append(ab)

ab_array = sorted(ab_array, key = lambda x:x[1])

ans = [ab_array[0][1]]

for i in ab_array:
    if not i[0] < ans[-1] <=i[1]:
        ans.append(i[1])
print(len(ans))

Measured memory_bytes: 29840
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, k;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    vector<bool> ans(n,false);
    rep(i,k){
        int d;
        cin>>d;
        rep(j,d){
            int temp;
            cin>>temp;
            temp--;
            ans[temp]=true;
        }
    }
    int count=0;
    rep(i,n){
        if(!ans[i])count++;
    }
    cout<<count<<"\n";
}


Measured memory_bytes: 3620
#include <iostream>

int main(int argc, const char * argv[]) {
    int a;
    int b;
    int c;
    std::cin >> a >> b >> c;
    if (a<b) {
        if (b<c) {
            std::cout << "Yes" << std::endl;
        }
        else{
            std::cout << "No" << std::endl;
        }
    }
    else{
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 3084
if __name__ == '__main__':
    # n = 100
    # n = 9995
    # n = 3141592653589793
    n = input()

    ary = list(map(int, list(str(n))))

    # x..xxの全探索
    m = -1
    middle = [9 for i in range(0, len(ary[1:-2]))] # 数列の真ん中
    for i in range(0, 10):
        for j in range(0, 10):
            for k in range(0, 10):
                if m < sum([i] + middle + [j, k]) and int(''.join(map(str, [i] + middle + [j, k]))) <= int(n):
                    m = sum([i] + middle + [j, k])
    print(m)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
#define LL long long
const LL MAX = 1e6+10;
LL n,m,k,x,y;
LL a[MAX];
map<LL,LL>TM;
int main ()
{
    cin>>n;
    LL sum=0;
    LL add=0;
    TM[0]=1;
    for(LL i=1;i<=n;i++)
    {
        cin>>x;
        sum+=x;
        add+=TM[sum];
        TM[sum]++;
        //cout<<add<<"_"<<sum<<endl;
    }
    cout<<add<<endl;
    return 0;
}

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

int main(void) {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    for(int i = 0; i < 3; ++i) {
        for(int j = i + 1; j < 3; ++j) {
            if(a[i] > a[j]) {
                int copy = a[i];
                a[i] = a[j]; 
                a[j] = copy;
            }
        }
    }
    
    cout << a[0];
    for(int i = 1; i < 3; ++i) {
        cout << " " << a[i];
    }
    cout << endl;
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <sstream>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{    
    int n,m;
    cin >> n;
    unordered_map<string,int> cnts;
    rep(i,n)
    {
        string si; 
        cin >> si;
        if(cnts.count(si)>0)
            cnts[si]++;
        else
            cnts[si] = 1;
    } 
    cin >> m;
    rep(i,m)
    {
        string ti;
        cin >> ti;
        if(cnts.count(ti)>0)
            cnts[ti]--;
        else
            cnts[ti] = -1;
    }

    int max_cnt = 0;
    for(auto& cnt:cnts)
        max_cnt = max(max_cnt, cnt.second);

    cout << max_cnt << endl;        
    return 0;
}

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

int main() {

  int n;
  cin >> n;

  vector<bool> s(13);
  vector<bool> h(13);
  vector<bool> c(13);
  vector<bool> d(13);
  
  for (int i = 0; i < n; i++) {
    string t;
    int v;
    cin >> t >> v;
    --v;
    if (t == "S") {
      s[v] = true;
    } else if (t == "H") {
      h[v] = true;
    } else if (t == "C") {
      c[v] = true;
    } else {
      d[v] = true;
    }
  }

  for (int i = 0; i < 13; i++) {
    if (s[i] == false) {
      cout << "S " << i + 1 << endl;
    }
  }

  for (int i = 0; i < 13; i++) {
    if (h[i] == false) {
      cout << "H " << i + 1 << endl;
    }
  }

  for (int i = 0; i < 13; i++) {
    if (c[i] == false) {
      cout << "C " << i + 1 << endl;
    }
  }

  for (int i = 0; i < 13; i++) {
    if (d[i] == false) {
      cout << "D " << i + 1 << endl;
    }
  }

  return 0;

}


Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <climits>

int main(void) {
  int N, Y;
  std::cin >> N >> Y;
  
  int n[3] = {0};
  if (Y >= 10000) {
    n[0] = Y / 10000;
    Y %= 10000;
  };
  if (Y >= 5000) {
    n[1] = Y / 5000;
    Y %= 5000;
  };
  if (Y >= 1000) {
    n[2] = Y / 1000;
    Y %= 1000;
  };
  
  int sum = n[0] + n[1] + n[2];
  //std::cout << n[0] << "," << n[1] << "," << n[2] << std::endl;
  //std::cout << "sum:" << sum << std::endl;
  if (sum > N) {
    std::cout << -1 << " " << -1 << " " << -1 << std::endl;
    return 0;
  }
  
  int diff = N - sum;
  //std::cout << "diff:" << diff << std::endl;
  for (int i = 0; i <= n[0]; i++) {
    /*10000 --> 5000*/
    for (int j = 0; j <= n[0] - i; j++) {
      /*10000 --> 1000*/
      for (int k = 0; k <= n[1]; k++) {
        /*5000 --> 1000*/
        //std::cout << "ptn:" << 1*i + 9*j + k*4 << std::endl;
        if (1*i + 9*j + k*4 == diff) {
          n[0] +=   -i - j;
          n[1] +=  2*i - k;
          n[2] += 10*j + 5*k;
          std::cout << n[0] << " " << n[1] << " " << n[2] << std::endl;
          return 0;
        }
      }
    }
  }
  
  std::cout << -1 << " " << -1 << " " << -1 << std::endl;
  return 0;
}


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

int main() {
    string var="";
    cin >> var;

    char a=var[0];
    int count =0;
    for(auto tmp:var){
        if(tmp == a){
            count++;
        }
    }
    if(count == 4){
        cout << "No";
        return 0;
    }

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

    if((var[0] == var[1])&&(var[2] == var[3])){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def solve():
    c = [list(map(int, input().split())) for _ in range(3)]
    for a0 in range(-100, 101) :
        b = [c[0][i] - a0 for i in range(3)]
        if any(c[1][0] - b[0] != c[1][i] - b[i] for i in range(3)):
            continue
        if any(c[2][0] - b[0] != c[2][i] - b[i] for i in range(3)):
            continue
        return True
    return False


if solve() :
    print("Yes")
else :
    print("No")


Measured memory_bytes: 3064
def parse(S):
    poly = []
    t = []
    for x in S.split('+'):
        if '-' in x:
            t = t + ['-' + a if i != 0 else a for i, a in enumerate(x.split('-'))]
        else:
            t.append(x)

    for x in t:
        if '^' in x:
            t = x.split('x^')
            if len(t[0]) == 0:
                a = 1
            else:
                a = int(t[0])
            b = int(t[1])
        else:
            if 'x' in x:
                if x == 'x':
                    a = 1
                elif x == '-x':
                    a = -1
                else:
                    a = int(x[:-1])
                b = 1
            else:
                a = int(x)
                b = 0

        poly.append((a, b))

    return poly

def calc_yaku(n):
    ret = []
    for i in range(n + 1):
        if i != 0 and n % i == 0:
            ret.append(i)

    return reversed(sorted(ret + [-x for x in ret]))

def calc(poly, x):
    ret = 0
    for p in poly:
        ret += p[0] * x ** p[1]

    return ret


def solve(S):
    poly = parse(S)
    n = abs(poly[-1][0])
    yaku = calc_yaku(n)

    ans = []
    for x in yaku:
        if calc(poly, x) == 0:
            ans.append(-x)

    for x in ans:
        if x > 0:
            print('(x+{})'.format(x), end='')
        else:
            print('(x{})'.format(x), end='')

    print('')

S=input()
solve(S)

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

int main(){
    int N, T, A;
    cin >> N;
    cin >> T;
    cin >> A;
    double H[N];
    for(int i=0; i<N; i++) cin >> H[i];
    for(int i=0; i<N; i++) H[i] = T - H[i]*0.006 - A;
    double delta = 10000000;
    int index=0;
    for(int i=0; i<N; i++){
        if(delta > abs(H[i])){
            delta = abs(H[i]);
            index = i+1;
        }
    }
    cout << index << endl;
    return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<ll,int> > hs;
    vector<int> h(n+1);
    for(int i = 1; i <= n; i++){
        ll tmp;
        cin >> tmp;
        hs.push_back(make_pair(tmp,i));
        h[i] = tmp;
    }
    vector<int> to[n+1];
    vector<bool> checked(n+1,0);
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        to[a].push_back(b);
        to[b].push_back(a);
        if(h[a] > h[b]){
            checked[b] = true;
        } else if(h[a] < h[b]){
            checked[a] = true;
        } else {
            checked[a] = true;
            checked[b] = true;
        }
    }
    
    int ans = 0;
    sort(hs.begin(),hs.end(),greater<pair<ll,int> >());
    for(int i = 0; i < n; i++){
        int node = hs[i].second;
        int nh = hs[i].first;
        if(checked[node] == true) continue;
        checked[node] = true;
        ans += 1;
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 10408
n,m = map(int,input().split())
h = list(map(int,input().split()))

check = [True] * n #小さかったらfalseに
for i in range(m):
    #print(i)
    a,b = (map(int,input().split()))
    if h[a-1] > h[b-1]:
        check[b-1] = False
    elif h[a-1] < h[b-1]:
       # print("i,check",i,check)
        check[a-1] = False
    else:
        check[a-1] = False
        check[b-1] = False
print(sum(check))



Measured memory_bytes: 20112
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
int main(void) {
  int n, k;
  int a[50];
  int ans=0;
  cin>>n>>k;
  for(int i=0; i<n; i++) {
    cin>>a[i];
  }
  sort(a, a+n, greater<int>());
  for(int i=0; i<k; i++) {
    ans+=a[i];
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> Ai(n);
    vector<ll> B;
    vector<ll> arr;
    vector<ll> rev;
    REP(i, n)
    {
        cin >> Ai.at(i);
        if (i % 2 == 0)
        {
            arr.push_back(Ai.at(i));
        }
        else
        {
            rev.push_back(Ai.at(i));
        }
    }
    reverse(rev.begin(), rev.end());
    for (int x : rev)
    {
        B.push_back(x);
    }
    for (int y : arr)
    {
        B.push_back(y);
    }
    if (n % 2 == 1)
    {
        reverse(B.begin(), B.end());
    }
    REP(k, n - 1)
    {
        cout << B[k] << " ";
    }

    cout << B[n - 1] << endl;
}

Measured memory_bytes: 7016
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<climits>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<map>

using namespace std;

typedef struct node{
	int val;
	struct node *link;
}node;
typedef pair<int,int> pi;
typedef pair<int,pi > pii;
typedef pair<pi,pi > pi2;
typedef vector<node> vn;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
typedef vector<pi2 > vpi2;
typedef long long ll;

#define sz(a) int((a).size()) 
#define pb push_back 
#define mp make_pair
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
 
const int M=998244353;
ll fact[300005];
int inv_fact[300005];

int powM(ll a, int r){
	if(r==0)
		return 1;
	if(r==1)
		return a%M;
	ll temp=powM(a,r/2);
	temp=(temp*temp)%M;
	if(r%2)
		return (temp*a)%M;
	else
		return temp;
}


int mod_inverse(int r){
	if(inv_fact[r]==-1){
		inv_fact[r]=powM(fact[r],M-2);
	}
	return inv_fact[r];
}

int compute_ncr(int n, int r){
	if(r==0 || r==n)
		return 1;
	if(r==1 || r==n-1)
		return n;
	return ((fact[n]*mod_inverse(r))%M*mod_inverse(n-r))%M;
}

int main(){
	int n;
	ll a,b,k;
	cin>>n>>a>>b>>k;
	fact[0]=fact[1]=1;
	inv_fact[0]=inv_fact[1]=1;
	for(int i=2;i<=n;i++){
		fact[i]=(fact[i-1]*i)%M;
		inv_fact[i]=-1;
	}
	ll count=0;
	for(int i=0;i<=n && (k-i*a)>=0;i++){
		if((k-i*a)%b==0 && (k-i*a)/b<=n){
			//cout<<i<<"\n";
			//cout<<compute_ncr(n,i)<<" "<<compute_ncr(n,(k-i*a)/b)<<"\n";
			count=(count+((ll)compute_ncr(n,i)*compute_ncr(n,(k-i*a)/b))%M)%M;
		}
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 3712
N=int(input())
a = list(map(int,input().split()))

x = {}

for i in range(N):
    if a[i] in x:
        x[a[i]]=x[a[i]]+1
    else:
        x[a[i]]=1


ans = 0
for k in x:
    if(x[k]>=k):
        ans+=x[k]-k
    else:
        ans+=x[k]


print(ans)

Measured memory_bytes: 18168
l = list(map(int,input().split()))
a,b,c,x,y = l[0],l[1],l[2],l[3],l[4]
ans = 0
minxy = min(x,y)
maxxy = max(x,y)
if maxxy == x:
    remab = a
elif maxxy == y:
    remab = b
rem = maxxy - minxy
if a + b >= 2*c:
    ans += 2*minxy*c
else:
    ans += minxy*(a+b)
if rem == 0:
    print(ans)
else:
    if 2*c <= remab:
        ans += 2*rem*c
    else:
        ans += rem*remab
    print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
char s[101];
int l,i,j;
int main()
{
    scanf("%s",s);
    l=strlen(s);
    for(i=0;i<l;i++)
    {if(s[i]=='C')
    {for(j=i+1;j<l;j++)
    {if(s[j]=='F')
    {printf("Yes\n");
    return 0;}}}}
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include <cmath>
using namespace std;
int main(){
	long a,b,x;
	cin>>a>>b>>x;
	if(2*x<=a*a*b){
		cout<<std::setprecision(10)<<atan((float)a*b*b/(2*x))*180/acos(-1);
	}else{
		cout<<std::setprecision(10)<<atan((float)(b*a*a-x)*2/(a*a*a))*180/acos(-1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
 
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
int main() {
  ll a,b,A,B,t,T,sa,sb,ans=0;
  string word;
  bool flag;
  cin>>t>>T;
  cin>>a>>A;
  cin>>b>>B;
  //xa=t*a;XA=T*A;
  //yb=t*b;YB=T*B;
  sa=t*a-t*b;sb=T*A-T*B;
  if((sa+sb)==0)cout<<"infinity"<<endl;
  else if(sa>0){if(sb<0){ans=1+2*ll((abs(sa)/abs(sa+sb)));
  if((abs(sa)%abs(sa+sb)==0))ans--;if(sa+sb>0)ans=0;cout<<ans<<endl;}
  else cout<<0<<endl;}
  else if(sa<0){if(sb>0){ans=1+2*ll((abs(sa)/abs(sa+sb)));
  if((abs(sa)%abs(sa+sb)==0))ans--;if(sa+sb<0)ans=0;cout<<ans<<endl;}
  else cout<<0<<endl;}
  //vector<vector<int>> sss(h,vector<int>(w));
  //vector<int> a(k),b(k);
  //char x;
}

Measured memory_bytes: 256
import numpy as np
import math
n=int(input())
machi = [[0]*2 for _ in range(n)]
for i in range(n):
    x,y = map(int,input().split())
    machi[i][0] = x
    machi[i][1] = y

kyori = np.array([[0]*n for _ in range(n)],dtype='float')

for i in range(n):
    for j in range(n):
        kyori[i][j] = np.sqrt((machi[i][0]-machi[j][0])**2+(machi[i][1]-machi[j][1])**2)

ans = np.sum(kyori) / n
print(ans)

Measured memory_bytes: 13328
import itertools
A,B,C=map(int,input().split())
K=int(input())

l=[0,1,2,3,4,5,6,7]

for c  in itertools.product(l, repeat=3):
    if sum(c) == K and A*2**c[0]<B*2**c[1] and B*2**c[1]<C*2**c[2]:
      print("Yes")
      exit(0)
print("No")


Measured memory_bytes: 9184
n = gets.to_i
n.times{
	num = gets.split(" ")
	a,b,c = num[0].to_i,num[1].to_i,num[2].to_i
	a,b,c = a**2,b**2,c**2
	if a+b==c || b+c==a || a+c==b then puts("YES")
	else puts("NO")
	end
}

Measured memory_bytes: 6104
import math
X, Y = map(int, input().split())
      
def cmb(n, r, mod):
  if (r<0) or (n<r):
    return 0
  r = min(r, n-r)
  return (fac[n] * finv[r] * finv[n-r]) % mod

mod = 10**9+7
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, (X+Y)//3+1):
  fac.append(fac[-1] * i % mod)
  inv.append(-inv[mod % i] * (mod // i) % mod)
  finv.append(finv[-1] * inv[-1] % mod)
  
ans = 0
x = 0
y = 0
if (X + Y) % 3 == 0:
  x = (2*Y-X) // 3
  y = (2*X-Y) // 3
  ans = cmb(x+y, x, mod)

print(ans)

Measured memory_bytes: 88332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

void mainsolve(){

	ll n;
	cin >> n;
	string s;
	cin >> s;

	vector<set<ll>> memo(26);
	string alp = "abcdefghijklmnopqrstuvwxyz";

	rep(i,n){
		memo[s[i]-'a'].insert(i);
	}


	ll q;
	cin >> q;
	rep(i,q){
		ll j;
		cin >> j;
		if(j==1){
			ll k;
			cin >> k;
			--k;
			char c;
			cin >> c;

			memo[s[k]-'a'].erase(k);
			memo[c-'a'].insert(k);
			s[k] = c;


		}
		else{
			ll l,r;
			cin >> l >> r;
			--l; --r;
			ll res = 0;
			rep(k,26){
				if(memo[k].empty()) continue;
				auto aa = memo[k].lower_bound(l);
				if(aa != memo[k].end() && *aa <= r) res++;
			}

			cout << res << endl;

		}
	}

	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 24324
package main

import "fmt"

var n int
var a []int

func main() {
	fmt.Scan(&n)
	a = make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	ans := 0
	for i := 0; i < n-1; i++ {
		if a[i]%2 == 1 {
			if a[i+1] == 0 {
				continue
			}
			a[i]--
			a[i+1]--
			ans++
		}
	}

	for i := range a {
		ans += a[i] /2
	}
	fmt.Println(ans)
}


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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    int m1 = INF, s = 0, m2 = INF;
    rep(i, n){
        a[i] = l + i;
        s += a[i];
        if(a[i] >= 0) {
            m1 = min(m1, abs(a[i]));
        }else{
            m2 = min(m2, abs(a[i]));
        }
    }
    if(m1 <= m2){
        cout << s - m1 << endl;
    }else{
        cout << s + m2 << endl;
    }
}

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

int main() {
	int N, M;
	int d[110000];
	int dis[110000];
	int counter = 0;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> d[i];
	}

	sort(d, d + M);

	for (int i = 0; i < M - 1; i++) {
		dis[i] = d[i + 1] - d[i];
	}

	sort(dis, dis + M - 1, greater<int>());

	for (int i = N-1; i < M - 1; i++) {
		counter += dis[i];
	}

	cout << counter << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
using namespace std;
void aswap(int *a,int n);
int main()
{
	int n,a[50],i,i1=-1,i2=-1;
	bool s=false;
	cin>>n;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n-1;i++)
		if(a[i]!=i+1&&i1==-1)
		{
			i1=i;
			continue;	
		}
		else if(a[i]!=i+1&&i2==-1)
		{
			i2=i;
			swap(a[i1],a[i2]);
			i=-1;
			continue;
		}
		else if(a[i]!=i+1)
		{
			break;
		}
		else if(i==n-2) s=true;
	if(s) cout<<"YES";
	else cout<<"NO";
	return 0;
}


Measured memory_bytes: 256