akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 8010
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 998244353;
int main(){
    string s;
    cin>>s;
    s='0'+s;
    int ans=0;
    reverse(ALL(s));
    REP(i,SZ(s)){
        int p=s[i]-'0';
        if(p>=6){
            int k=i+1;
            while(s[k]=='9')s[k++]='0';
            s[k]++;
        }else if(s[i]=='5'){
            if(s[i+1]>='5'){
                int k=i+1;
                while(s[k]=='9')s[k++]='0';
                s[k]++;
            }
        }
        ans+=min(p,10-p);
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 2308
#include <iostream>
#include <string>
#include <vector>
#include <cctype>

using namespace std;
void count(vector<int>& table, string str){
    for(int i = 0; i < str.size(); ++i){
        int index = toupper((int)str[i]) - 'A';
        if(0 <= index && index <= 26){
            table[index] += 1;
        }
    }
}
int main()
{
    vector<int> table(26);
    string s;
    while(getline(cin, s)){
        count(table, s);
    }
    for(int i = 0; i < 26; ++i){
        char c = 'a' + i;
        int n = table[i];
        cout << c << " : " << n << endl;
    }
    return 0;
}

Measured memory_bytes: 3132
#include <iostream>

using namespace std;
typedef long long ll;
ll n, a[200000], b[200010], ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (int i = 0; i <= n; i++) {
    ans += b[i] * (b[i] - 1LL) / 2LL;
  }
  for (int i = 0; i < n; i++) {
    cout << ans - b[a[i]] + 1LL << endl;
  }
}

Measured memory_bytes: 4736
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    int N = sc.nextInt();
    int K = sc.nextInt();

    int a[] = new int[N];
    for (int i = 0; i < K; i++) {
      int d = sc.nextInt();
      for (int j = 0; j < d; j++) {
        int A = sc.nextInt();
        a[A - 1] += 1;
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (a[i] == 0) {
        ans++;
      }
    }
    System.out.println(ans);

  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) {
      return buffer[ptr++];
    } else {
      return -1;
    }
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
}

Measured memory_bytes: 26292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef double dl;
#define mp make_pair
#define pb emplace_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define dst distance
#define INF 1000000000
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define MAXN 500110
ll MOD = 1e9+7;

ll A[MAXN];
ll N,D,Q,a;
ll L[MAXN];
ll C[MAXN];
ll out[MAXN];
priority_queue<pi, vector<pi>, greater<pi>> pq;

int main(){
	cin>>N>>D;
	for (ll i=1;i<=N;++i)cin>>A[i];
	L[0] = D;
	for (ll i=1;i<=N;++i){
		L[i] = min(L[i-1], abs(L[i-1] - A[i]));
	}
	if (L[N]!=0){
		cin>>Q;
		while(Q--)cout<<"YES\n";
		return 0;
	}
	C[N+1] = 1;
	for (ll i=N;i>=1;--i){
		if (C[i+1] <= A[i]/2){
			C[i] = C[i+1];
		}else {
			C[i] = C[i+1]+A[i];
		}
		// cout<<A[i]<<' '<<C[i]<<'\n';
	}
	for (ll i=1;i<=N;++i){
		// cout<<L[i-1]<<' '<<C[i+1]<<'\n';
		if (L[i-1] >= C[i+1])out[i]=1;
		else out[i]=0;
	}
	cin>>Q;
	while(Q--){
		cin>>a;
		if (out[a])cout<<"YES\n";
		else cout<<"NO\n";
	}
}

Measured memory_bytes: 17536
from collections import deque, Counter
from functools import reduce
from operator import add
H, W = map(int, input().split())
s = [input() for _ in range(H)]

cnt = Counter(reduce(add, s))

queue = deque()
depth = [[-1]*W for _ in range(H)]
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]


def bfs():
    # if x==W-1 and y==H-1:
    #    return d
    queue.append((0, 0))
    depth[0][0] = 1
    while queue:
        x, y = queue.popleft()
        for i in range(4):
            nx = dx[i] + x
            ny = dy[i] + y
            if nx < 0 or nx >= W or ny < 0 or ny >= H:
                continue
            if depth[ny][nx] != -1:
                continue
            if nx == W-1 and ny == H-1:
                depth[ny][nx] = depth[y][x] + 1
                return True
            if s[ny][nx] == '.':
                depth[ny][nx] = depth[y][x] + 1
                queue.append((nx, ny))
    return False

if bfs():
    print(H*W-depth[H-1][W-1]-cnt['#'])
else:
    print(-1)


Measured memory_bytes: 3692
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = sc.nextInt();
    int a = sc.nextInt();
    double ans = 100001.0;
    double bef;
    int answer = 0;
    for(int i=0; i<n; i++){
      bef = ans;
      ans = Math.min( ans,Math.abs( a-(t-sc.nextInt()*0.006) ) );
      if(bef != ans) answer = i+1;
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
const long long INF=1e18,MOD=1e9+7;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b>=c){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        solve(s);
    }

    static void solve(String s) {
    	StringBuilder sb1 = new StringBuilder();

    	for(int i = 0; i < s.length(); i++) {
    		if(i % 2 == 0) {
    			sb1.append('1');
    		} else {
    			sb1.append('0');
    		}
    	}
    	String p1 = sb1.toString();

    	StringBuilder sb2 = new StringBuilder();
    	for(int i = 0; i < s.length(); i++) {
    		if(i % 2 == 0) {
    			sb2.append('0');
    		} else {
    			sb2.append('1');
    		}
    	}
    	String p2 = sb2.toString();
    	int ans = Math.min(countDiff(s,p1), countDiff(s,p2)) ;
    	System.out.println(ans);
    }

    static int countDiff(String s, String p) {
    	int count = 0;
    	for(int i = 0; i < s.length(); i++) {
    		if(s.charAt(i) != p.charAt(i)) count++;
    	}
    	return count;
    }
}

Measured memory_bytes: 26312
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
	int n;
	std::vector<int> vec;
	for (int i = 0; i < 10; i++) {
		std::cin >> n;
		vec.emplace_back(n);
	}
	std::sort(vec.begin(), vec.end());
	for (int i = 9; i > 6; i--) {
		std::cout << vec[i] << std::endl;
	}
}

Measured memory_bytes: 3160
#! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)


YES = "Yes"  # type: str
NO = "No"  # type: str

INF=10**20
def solve(A: int, B: int, C: int, D: int):
    while True:
        C-=B
        if C <= 0:
            print(YES)
            break
        
        A-=D
        if A <= 0:
            print(NO)
            break



    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)



if __name__ == "__main__":
    main()


Measured memory_bytes: 61768
#include <iostream>
#include <cstdio>
using namespace std;
int n, s, mv, t[105], v[105], x[105], z[40005];
int main() {
	int i, j;
	cin>>n;
	for(i=1; i<=n; i++) cin>>t[i], t[i]*=2, x[i] = x[i-1] + t[i];;
	for(i=1; i<=n; i++) cin>>v[i], v[i]*=2;
	for(i=1, j=0; i<=n; i++) {
		z[j] = min(z[j], v[i]);
		for(j=j+1; j<=x[i]; j++) z[j] = min(z[j-1]+1, v[i]);
		j-=1;
	}
	for(i=x[n]-1; i; i--) {
		mv = min(z[i], mv+1);
		s += mv;
	}
	printf("%.9f", s/4.0);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(c) c.begin(),c.end()


int main()
{

    int n, m;
    cin >> n >> m;
    long long sum = 0;
    for(int i =0; i < m ; i++)
    {
        int x;
        cin >> x;
        sum+=x;
    }
    if(sum > n)
        cout << -1;
    else
        cout << n - sum ;




    return 0;
}


Measured memory_bytes: 3636
# グリッド
h, w = gets.chomp.split.map(&:to_i)
sa = []
h.times do
  sa.push(gets.chomp.chars)
end

sa.each_with_index do |row, row_index|
  row.each_with_index do |value, col_index|
    next if value == "."
    next if row_index > 0 && sa[row_index - 1][col_index] == "#"
    next if row_index < h-1 && sa[row_index + 1][col_index] == "#"
    next if col_index > 0 && sa[row_index][col_index - 1] == "#"
    next if col_index < w-1 && sa[row_index][col_index + 1] == "#"
    puts "No"
    exit
  end
end

puts "Yes"


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

int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int p = 0, o = k;
    rep(i, n - k){
        if(a[p] < a[o]) cout << "Yes" << endl;
        else cout << "No" << endl;
        ++p; ++o;
    }
    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;


ll ar[ms];

int main()
{
    idfc;
    int n,k;
    cin>>n>>k;
    int i;
    for(i=1;i<=n+1;i++)
    {
        ar[i]=ar[i-1]+i;
    }
    ll ans=0;
    ll a; ll b;
    for(i=k;i<=(n+1);i++)
    {
        a=ar[i];
        b=ar[n+1]-ar[n+1-i];
     //   cout<<a<<" "<<b<<endl;
        ans+=(b+1-a);
        ans%=modo;
    }
    cout<<ans;
    return 0;
}

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

int main(void){
	int n,q;
	cin >> n >> q;
	vector<string> names(n);
	vector<int> times(n);

	queue<int> que;
	for(int i=0;i<n;i++){
		cin >> names[i] >> times[i];
		que.push(i);
	}

	int t = 0;
	while(!que.empty()){
		int id = que.front();que.pop();
		t += min(times[id],q);
		times[id] = max(0,times[id] - q);

		if(times[id] == 0)
			cout << names[id] << " " << t << endl;
		else
			que.push(id);
	}

	return 0;
}

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

int main(){
	int h;
	int w;
	int a;
	while(true) {
		cin >> h >> w;
		if ( h==0 && w==0 ) break;
		while ( h>0 ) {
			a=w;
			while ( a>0 ) {
				cout << "#";
				a--;
			}
			cout << endl;
			h--;
		}
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 1152
n,a,b=map(int,input().split());k=10**9+7;c=(1<<n)%k-1;X=Y=1
for i in range(b):
	X=X*(n-i)%k;Y=Y*(i+1)%k
	if i+1 in(a,b):c-=X*pow(Y,k-2,k)
print(c%k)

Measured memory_bytes: 263412
n = int(input())
s = input()

pins = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        pins.append(str('00')+i)
    elif len(i) == 2:
        pins.append(str('0')+i)
    else:
        pins.append(i)

ans = 0
for pin in pins:
    c = 0
    for i in s:
        if pin[c] == i:
            c += 1
        if c == 3:
            ans += 1
            break

print(ans)

Measured memory_bytes: 42896
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    if N % 1000 == 0:
        ans = 0
    else:
        ans = 1000*(N//1000+1)-N
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61800
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

template<typename T, typename U>
ostream& operator<<(ostream& o, const pair<T,U>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}

template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (const T& x : v)
    o << x << ",";
  return o << "]";
}

template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T>>& v) {
  o << "[";
  for (const vector<T>& x : v)
    o << x << ",\n";
  return o << "]";
}

const int INF = 1e18;
constexpr pii offs[] = {{-1,0},{0,1},{1,0},{0,-1}};

vvi d;
vvi occ;

void propdists(int i, int j) {
  for (const pii& off : offs) {
    int ii = i+off.first;
    int jj = j+off.second;
    if (ii<0 || ii>=d.size() || jj<0 || jj>=d.size())
      continue;
    if (d[ii][jj] > d[i][j] + occ[i][j]) {
      d[ii][jj] = d[i][j] + occ[i][j];
      propdists(ii,jj);
    }
  }
}

void initdists() {
  const int n = d.size();
  for (int i=0; i<n; ++i) {
    for (int j=0; j<n; ++j) {
      d[i][j] = min(i,min(j,min(n-1-i,n-1-j)));
    }
  }
}

void unitestuff(int i, int j) {
  for (const pii& off : offs) {
    int ii = i + off.first;
    int jj = j + off.second;
    if (ii<0 || ii>=d.size() || jj<0 || jj>=d.size())
      continue;
    if (d[ii][jj] > d[i][j]) {
      d[ii][jj] = d[i][j];
      propdists(ii,jj);
    }
  }
}

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

  int n;
  cin >> n;
  vi ps(n*n);
  for (int& pi : ps)
    cin >> pi;

  occ = vvi(n, vi(n, 1));
  d = vvi(n, vi(n, INF));
  initdists();

  int haters = 0;
  for (int pi : ps) {
    int i = (pi-1)/n;
    int j = (pi-1)%n;
    haters += d[i][j];
    occ[i][j] = 0;
    unitestuff(i,j);
  }
  cout << haters << "\n";
}


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

int main()
{
	int n;
  	cin>>n;
  	string str;
  	map<string,int> char_count;
  	for(int i=0 ; i<n ; ++i)
    {
    	cin>>str;
    	++char_count[str];
    }
    cout<<(char_count.size()==3?"Three":"Four")<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    string S, T; cin >> S >> T;
    int n = S.length();
    if (S == T.substr(0, n) && (int) T.length() == n + 1) {
		cout << "Yes" << nl;
	} else {
		cout << "No" << nl;
	}
    	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3608
from itertools import permutations

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

dist = [[0] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        dist[i][j] = ((X[i][0] - X[j][0]) ** 2
                      + (X[i][1] - X[j][1]) ** 2) ** 0.5

ans = []
for v in permutations(range(N), N):
    tmp = 0
    for i in range(N - 1):
        tmp += dist[v[i]][v[i + 1]]
    ans.append(tmp)

print(sum(ans) / len(ans))


Measured memory_bytes: 41708
import java.util.Scanner;

public class Main {
    static int n;
    static int m;
    static long[] fac;
    static long[] finv;
    static long[] inv;
    static int max = 100001;
    static int mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();

        fac = new long[max];
        finv = new long[max];
        inv = new long[max];

        COMinit();

        //差が２以上だと交互に配置できない
        if (Math.abs(n - m) > 1) {
            System.out.println(0);
        } else if(m == n) {
            //数が同じ場合はスタートがnかmかで２通りあるので*2
            System.out.println(fac[n] * fac[m] * 2 % mod);
        } else {
            System.out.println(fac[n] * fac[m] % mod);
        }
    }

    //二項定理前処理 O(N)
    //階乗 n! をfac[]に格納　n!**-1 をinv[]に格納 nCrをfinv[]に格納
    static void COMinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;

        for (int i = 2; i < max; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }

    //nCr二項定理を返す O(1)
    // nCk=n!k!(n−k)!=(n!)×(k!)−1×((n−k)!)−1
    static long COM(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
constexpr ll INF = 1LL<<60;

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

    REP(i, m) n -= a[i];
    if(n < 0) cout << -1 << endl;
    else cout << n << endl;

    return 0;
}


Measured memory_bytes: 3704
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N;
	cin >> N;
	vector<vector<int>>A(2, vector<int>(N)), dp(2, vector<int>(N));
	rep(i, 2)rep(j, N)cin >> A[i][j];
	rep(i, 2)rep(j, N)dp[i][j] = 0;
	dp[0][0] = A[0][0];
	rep(i, N - 1)dp[0][i + 1] = dp[0][i] + A[0][i + 1];
	dp[1][0] = A[0][0] + A[1][0];
	rep(i, N - 1)dp[1][i + 1] = max(dp[1][i], dp[0][i + 1]) + A[1][i + 1];
	cout << dp[1][N - 1];
}

Measured memory_bytes: 256
A,B,Q=map(int,input().split())
inf=1e50
s=[-inf]
for _ in range(A):
    s.append(int(input()))
s.append(inf)

t=[-inf]
for _ in range(B):
    t.append(int(input()))
t.append(inf)
from bisect import bisect

for _ in range(Q):
    x=int(input())
    i=bisect(s,x)
    j=bisect(t,x)
    
    sL=x-s[i-1]
    sR=s[i]-x
    
    tL=x-t[j-1]
    tR=t[j]-x
    print(min(max(sR,tR),max(sL,tL),sR+tL+min(sR,tL),sL+tR+min(sL,tR)))




Measured memory_bytes: 12144
import java.util.*;
public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int date = input.nextInt();

        switch (date) {
            case 22: System.out.print("Christmas Eve Eve Eve"); break;
            case 23: System.out.print("Christmas Eve Eve"); break;
            case 24: System.out.print("Christmas Eve"); break;
            case 25: System.out.print("Christmas"); break;
        }


    }
}


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

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

    int num_0=0;
    int num_1=0;

    for(int i=0; i < S.size() ; i++){
        if(S[i]=='0'){
            num_0++;
        }
        else{
            num_1++;
        }
    }

    cout << 2*min(num_0, num_1) <<endl;
}

Measured memory_bytes: 512
s = input()
t = input()
sd = sorted(s,key=lambda a:ord(a))
td = sorted(t,key=lambda a:-ord(a))
if len(sd) == len(td):
    for sm, tm in zip(sd, td):
        if ord(sm) < ord(tm):
            print('Yes')
            exit()
        elif ord(sm) > ord(tm):
            print('No')
            exit()
    print('No')
else: 
    minsize = min(len(s), len(t))
    sd = sd[:minsize]
    td = td[:minsize]
    if sd == td:
        if len(s) < len(t):
            print('Yes')
        else:
            print('No')
    else:
        for sm, tm in zip(sd, td):
            if ord(sm) < ord(tm):
                print('Yes')
                exit()
            elif ord(sm) > ord(tm):
                print('No')
                exit()
        print('No')




Measured memory_bytes: 3064
n=io.read("*n")
o=tostring(n)
for i=2,#o do
    if o:sub(i,i)~="9" then
        print(math.floor(tonumber(o:sub(1,1)-1)+9*(#o-1)))
        return
    end
end
print(math.floor(tonumber(o:sub(1,1))+9*(#o-1)))

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

int main() {
  int n;

  cin >> n;

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == b)
      cnt++;
    else
      cnt = 0;
    if (cnt == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int square = a*b;
    square -= c*b;
    square -= d*(a-c);
    System.out.println(square);
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct Timer{
    chrono::high_resolution_clock::time_point st;

    Timer() { reset(); }

    void reset(){
        st = chrono::high_resolution_clock::now();
    }

    chrono::milliseconds::rep elapsed(){
        auto ed = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(ed - st).count();
    }
};

struct RNG{
    mt19937 mt;

    RNG() : mt(chrono::steady_clock::now().time_since_epoch().count()){}

    int operator()(int a, int b){
        uniform_int_distribution<int> dist(a, b - 1);
        return dist(mt);
    }

    int operator()(int b){
        return (*this)(0, b);
    }
};

constexpr int D = 365;
vector<int> c(26);
vector<vector<int>> s(D, vector<int>(26));
Timer TimeKeeper;
RNG rng;
constexpr ll inf = 1e+15;

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

    int kyomu;
    cin >> kyomu;
    for(int i = 0; i < 26; ++i) cin >> c[i];
    vector<int> maxe(D, -1);
    vector<int> cur(D, 0);
    for(int i = 0; i < D; ++i){
        for(int j = 0; j < 26; ++j){
            cin >> s[i][j];
            if(chmax(maxe[i], s[i][j])) cur[i] = j;
        }
    }

    ll BestScore = 0;
    auto calc_score = [&](vector<int>& v) -> ll {
        ll res = 0;
        vector<int> pre(26, -1);
        for(int i = 0; i < D; ++i){
            res += s[i][v[i]];
            pre[v[i]] = i;
            for(int j = 0; j < 26; ++j){
                res -= c[j] * (i - pre[j]);
            }
        }
        return res;
    };
    BestScore = calc_score(cur);

    int Day = 0;
    while(TimeKeeper.elapsed() < 1988){
        ll NxtScore = -inf;
        int ProblemType = -1;
        vector<int> nxt = cur;
        for(int i = 0; i < 26; ++i){
            if(i == cur[Day])   continue;
            nxt[Day] = i;
            if(chmax(NxtScore, calc_score(nxt)))    ProblemType = i;
        }
        if(chmax(BestScore, NxtScore)){
            cur[Day] = ProblemType;
        }
        if(++Day == D)  Day = 0;
    }

    for(int i = 0; i < D; ++i)  cout << cur[i] + 1 << '\n';
}

Measured memory_bytes: 3704
def main():
    import sys
    from itertools import permutations
    # readline = sys.stdin.buffer.readline
    readlines = sys.stdin.readlines
    N, M = map(int, input().split())
    edge = [[0] * N for _ in range(N)]
    for s in readlines():
        a, b = map(int, s.split())
        a -= 1; b -= 1
        edge[a][b] = 1
        edge[b][a] = 1

    cnt = 0
    for path in permutations(range(1, N)):
        path = [0] + list(path)
        for i in range(N - 1):
            v = path[i]
            nv = path[i + 1]
            if edge[v][nv] == 0:
                break
        else:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


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

int main() {
    int d,evenum;
    cin >> d;
    evenum = 0;
    string ans;
    ans = "Christmas";
    d = 25-d;
    rep(i,d){
        ans += " Eve";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    S = sum(A)
    cunt_A = Counter(A)
    for q in range(Q):
        b, c = map(int,input().split())
        S += (c-b)*cunt_A[b]
        cunt_A[c] += cunt_A[b]
        cunt_A[b] = 0
        print(S)

if __name__=='__main__':
    main()

Measured memory_bytes: 94388
#include<stdio.h>
#include<stdlib.h>

int main(void){

  int N;
  scanf("%d\n", &N);

  int *a;
  a = (int*)malloc(N*sizeof(int));
  for(int i=0; i<N; i++){
    scanf("%d", &a[i]);
  }

  int ans=0;
  int buf=0;

  for(int i=0; i<N; i++){
    if(buf==a[i]){
      ans++;
      i++;
    }
    buf = a[i];
  }



  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int inf=0x3f3f3f3f;
#define N 5050
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,x,y;
int cnt,head[N],dis[N],ans[N];
queue<int> q;
struct Edge{
	int to,nxt;
}edge[N<<1];
void add(int a,int b){
	++cnt;
	edge[cnt].to=b;
	edge[cnt].nxt=head[a];
	head[a]=cnt;
}
int main(){
	n=read(),x=read(),y=read();
	add(x,y),add(y,x);
	for(int i=1;i<n;++i){
		add(i,i+1),add(i+1,i);
	}
	for(int s=1;s<=n;++s){
		memset(dis,0x3f,sizeof(dis));
		q.push(s);
		dis[s]=0;
		while(!q.empty()){
			int u=q.front();
			q.pop();
			for(int i=head[u];i;i=edge[i].nxt){
				int v=edge[i].to;
				if(dis[v]==inf){
					dis[v]=dis[u]+1;
					ans[dis[v]]++;
					q.push(v);
				} 
			}
		} 
	}
	for(int i=1;i<n;++i){
		printf("%d\n",ans[i]/2);
	}
	return 0;
}


Measured memory_bytes: 384
#include <string>
#include <algorithm>
#include <limits.h>
#include <iostream>

using namespace std;

int main()
{
	long long i, j, k, sl;
	string S;

	cin >> S;
	sl = S.size();

	for (i = 0; i < sl-1; i++) {
		for (j = i+1; j < sl; j++) {
			if (S[i] == S[j]) {
				cout << "no" << endl;
				return 0;
			}
		}
	}

	cout << "yes" << endl;
	return 0;
}

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

long long int b[214514] = {};

int main() {

    long long int n;
    cin >> n;

    vector< long long int > v;

    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        v.push_back( in );
    }


    vector< long long int > ans;

    for ( long long int i = n - 1; i >= 0; i-- ) {
        if ( b[i] == v[i] ) continue;

        long long int p = i + 1;
        ans.push_back( p );
        for ( long long int j = 1; j * j <= p; j++ ) {
            if ( ( p % j ) != 0 ) continue;
            b[j-1] ^= 1;
            if ( j * j == p ) continue;
            b[p/j-1] ^= 1;
        }
    }

    cout << ans.size() << endl;
    if ( ans.size() == 0 ) return 0;
    sort( ans.begin(), ans.end() );
    for ( long long int i = 0; i < ans.size(); i++ ) {
        if ( i > 0 ) cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;

}


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

int gcd(int a,int b)
{
 int r, tmp;
 if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(){
	int n,m;
	cin >> n>>m;
	string s,t;
	cin >> s >> t;
	int g=gcd(n,m);
	bool ok = true;
	
	if(s[0] != t[0]) {
		cout << "-1" << endl;
		return 0;
	}
	int cs = n/g;
	int ct = m/g;
	for(int i = 1; (i*cs<n) &&(i*ct<m);i++) {
		if(s[i*cs] != t[i*ct]) {
			ok = false;
			break;
		}
	}
	long tt = (long)n*(long)m/g;
	if(ok) {
		cout << tt << endl;
	} else {
		cout << "-1" << endl;
	}
	
}

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

typedef long long ll;

#define PI 3.1415926535897932384626433
#define MOD 1000000007

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

    int ans = 100000;
    for (int i = 0; i < n; i++){
        int s1 = 0 , s2 = 0;
        for (int j = 0; j < i; j++){
            s1 += w[j];
        }
        for (int j = i; j < n; j++){
            s2 += w[j];
        }
        ans = min(ans, abs(s1 - s2));
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    string ans;
    if (S == "AAA" || S == "BBB") {
        ans = "No";
    } else {
        ans = "Yes";
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("avx")

#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vector<double> x(n), y(n);
    vector<char> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> d[i];
    }
    double uu = -INF, ud = -INF, um = -INF;
    double du = INF, dd = INF, dm = INF;
    double lle = INF, lr = INF, lm = INF;
    double rl = -INF, rr = -INF, rm = -INF;
    for (int i = 0; i < n; ++i) {
        if (d[i] == 'U') {
            chmax(uu, y[i]);
            chmin(du, y[i]);
            chmax(rm, x[i]);
            chmin(lm, x[i]);
        } else if (d[i] == 'D') {
            chmax(ud, y[i]);
            chmin(dd, y[i]);
            chmax(rm, x[i]);
            chmin(lm, x[i]);
        } else if (d[i] == 'L') {
            chmax(um, y[i]);
            chmin(dm, y[i]);
            chmax(rl, x[i]);
            chmin(lle, x[i]);
        } else if (d[i] == 'R') {
            chmax(um, y[i]);
            chmin(dm, y[i]);
            chmax(rr, x[i]);
            chmin(lr, x[i]);
        }
    }
    double lastx = 1e20, lasty = 1e20;
    double ret = 1e20;
    for (int i = 0; i <= 400000000; ++i) {
        double time = 0.5 * i;
        double u    = max({uu + time, ud - time, um});
        double d    = min({du + time, dd - time, dm});
        double l    = min({lr + time, lle - time, lm});
        double r    = max({rr + time, rl - time, rm});
        double xx   = r - l;
        double yy   = u - d;
        chmin(ret, xx * yy);
        if (xx > lastx && yy > lasty)
            break;
        lastx = xx;
        lasty = yy;
    }
    cout << fixed << setprecision(15) << ret << "\n";
    return 0;
}

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

int main() {
    int M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;

    if (M1 == M2) {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }

    return 0;
}

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

using namespace std;

int main()
{
    int n, a;
    set <int> s;
    cin >> n;

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

        if (s.find(a) != s.end())
            s.erase(a);
        else
            s.insert(a);
    }

    cout << s.size();
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    string s,t;
    cin >> s >> t;
    REP(i,s.size()){
        if(s[i]!=t[i]){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 3524
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
#define ll  long long 
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b,c;cin>>a>>b>>c;
  ll d=b+c;
  ll e=a/d;
  ll f=a%d;
  cout<<e*b+min(f,b);
}

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

using namespace std;

using ll= long long;

#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
# define M_PI 3.14159265358979323846

void solve(){
    int k;
    cin>>k;
    string s;
    cin>>s;
    k= min(k,sz(s));
    for(int i=0;i<k;i++){
        cout<<s[i];
    }
    if(sz(s)>k){
        cout<<"...\n";
    }
}

int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	// cin>>_;
	_=1;
	while(_--){
        solve();
    }
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

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

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

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

    while (1) {
        sort(A.begin(), A.end());
        A.erase(remove(A.begin(), A.end(), 0), A.end());
        if (A.size() == 1) {
            cout << A[0] << endl;
            return 0;
        }
        for (int i = 1; i < N; i++) {
            A[i] = A[i] % A[0];
        }
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#define llint long long
#define mod 1000000009

using namespace std;
typedef pair<llint, llint> P;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint n, m;
llint a[20], b[20], c[20];
llint N, M, S;
vector<llint> comp;
vector<P> vec;
UnionFind uf(40), tmp(40);

llint fact[3000005], fact_inv[3000005];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < 3000005; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	for(int i = 0; i < 3000005; i++){
		fact_inv[i] = modpow(fact[i], mod-2);
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

void count(UnionFind &uf, int cnt[])
{
	map<llint, llint> mp;
	for(int i = 1; i <= N; i++) mp[uf.root(i)]++;
	for(int i = 1; i <= 4; i++) cnt[i] = 0;
	for(auto it = mp.begin(); it != mp.end(); it++){
		if(it->second > 4) it->second = 4;
		cnt[it->second]++;
	}
	cnt[1] += 3*n - N;
}

llint calc(int cnt[])
{
	if(cnt[4] > 0) return 0;
	if(cnt[2] > cnt[1]) return 0;
	
	llint ret = 1;
	ret *= fact[cnt[1]] * fact_inv[cnt[1]-cnt[2]] % mod, ret %= mod;
	cnt[1] -= cnt[2];
	ret *= fact[cnt[1]], ret %= mod;
	ret *= modpow(modpow(6, cnt[1]/3), mod-2), ret %= mod;
	ret *= fact_inv[cnt[1]/3], ret %= mod;
	return ret;
}

int main(void)
{
	make_fact();
	
	cin >> n >> m;
	for(int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> c[i];
	for(int i = 1; i <= m; i++){
		comp.push_back(a[i]);
		comp.push_back(b[i]);
	}
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	for(int i = 1; i <= m; i++){
		a[i] = lower_bound(comp.begin(), comp.end(), a[i]) - comp.begin() + 1;
		b[i] = lower_bound(comp.begin(), comp.end(), b[i]) - comp.begin() + 1;
	}
	N = comp.size();
	
	for(int i = 1; i <= m; i++){
		if(c[i] == 0) uf.unite(a[i], b[i]);
		else vec.push_back(make_pair(a[i], b[i]));
	}
	
	int cnt[5];
	count(uf, cnt);
	llint ans = calc(cnt);
	
	M = vec.size(), S = 1<<M;
	for(int i = 1; i < S; i++){
		for(int j = 1; j <= N; j++) tmp.parent[j] = uf.parent[j];
		for(int j = 0; j < M; j++){
			if(i & (1<<j)) tmp.unite(vec[j].first, vec[j].second);
		}
		
		count(tmp, cnt);
		llint sum = calc(cnt);
		
		llint pop = 0;
		for(int j = 0; j < M; j++) if(i & (1<<j)) pop++;
		if(pop%2) ans += mod - sum; else ans += sum;
		ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 50032
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;

template<typename T> void print(T t) { cout << t << endl; }

int main() {
	int N, K, p;
	cin >> N >> K;
	vector<ll> kitai2(N);
	for (int i = 0; i < N; i++) {
		cin >> p;
		kitai2[i] = 1ll + p;
	}
	ll k=0, kmax;
	for (int i = 0; i < K; i++) {
		k += kitai2[i];
	}
	kmax = k;

	for (int i = K; i < N; i++) {
		k += kitai2[i] - kitai2[i-K];
		kmax = max(kmax, k);
	}
	cout << fixed << setprecision(12) << kmax * 0.5 << endl;

}

Measured memory_bytes: 4756
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int R;
  cin >> R;
  cout << 2.0 * 3.14159265 * R << endl;
  return 0;
}


Measured memory_bytes: 3260
n = int(input())
a_list = list(map(int, input().split()))

ans = 'APPROVED'
for i in range(0, n) :
  if a_list[i]%2 == 0 :
    if (a_list[i]%3)*(a_list[i]%5) != 0 :
      ans = 'DENIED'
      break
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> h(n);
    for (int &x : h)
    {
        scanf("%d", &x);
    }
    vector<int> dp(n, 1e9 + 5);
    dp[0] = 0;

    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j <= i + k; ++j)
        {
            if (j < n)
            {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }
    printf("%d\n", dp[n - 1]);
}

Measured memory_bytes: 1024
using System;
using System.Linq;

class Program {
  static void Main() {
    int L;
    while ((L = int.Parse(Console.ReadLine())) != 0) {
      int sum = 0;
      var ans = "NA";
      var f = false;
      for (int i = 1; i <= 12; i++) {
        sum += Console.ReadLine().Split().Select(int.Parse).Aggregate((m, n) => m - n);
        if (f) continue;
        if (sum >= L) {
          ans = i.ToString();
          f = true;
        }
      }
      Console.WriteLine(ans);
    }
  }
}


Measured memory_bytes: 14164
#include<bits/stdc++.h>
#include<map>
using namespace std;
int n,t;
string s;
map<string ,int> mp;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>s;
		if(mp.find(s)==mp.end()){
			mp.insert(pair<string,int>(s,1));
		}	
		else{
			mp[s]++;
		}
		t=max(mp[s],t);	
	}
	map<string, int>::iterator it;
	for( it=mp.begin();it!=mp.end();it++){
		if(it->second==t){
			cout<<it->first<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll a,b,c;
    cin >> a>>b>>c;
    if(a==b&&a!=c ||a==c&&a!=b ||c==b&&a!=c){
        cout << "Yes" << endl;
    }else cout << "No" << endl;
}


Measured memory_bytes: 256
N,K=map(  int,raw_input().split() )
X=map(  int,raw_input().split() )

ans=float("inf")
t=float("inf")
for l in range(N-K+1):
	r=l+K-1
	if X[l]<0:
		if X[r]<0:	
			ans=min(ans, abs(X[l]) )
		else:	
			ans=min(ans, 2*abs(X[l])+abs(X[r]) , abs(X[l])+2*abs(X[r]) )
	elif X[l]>=0 and X[r]>=0:
		ans=min(ans, X[r] )


print ans

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

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;

ll n, k;

struct matrix{
    vector<vector<ll>> mt;
};

matrix operator* (const matrix& a, const matrix& b){
    matrix tmp;
    tmp.mt.resize(a.mt.size(), vector<ll>(b.mt[0].size()));
    for(int i = 0; i < (int) a.mt.size(); i++){
        for(int j = 0; j < (int) b.mt[0].size(); j++){
            tmp.mt[i][j] = 0;
            for(int kk = 0; kk < (int) b.mt.size(); kk++){
                tmp.mt[i][j] += ((a.mt[i][kk]%mod) * (b.mt[kk][j]%mod)) % mod;
            }
        }
    }
    return tmp;
}

matrix operator^ (matrix a, ll p){
    matrix tmp;
    tmp.mt.resize(a.mt.size(), vector<ll>(a.mt[0].size()));
    for(int i = 0; i < (int) a.mt.size(); i++) tmp.mt[i][i] = 1;
    while(p){
        if(p & 1){
            tmp = tmp * a;
        }
        a = a * a;
        p /= 2;
    }
    return tmp;
}

int main(){
    cin>>n>>k;
    matrix mat;
    mat.mt.resize(n, vector<ll>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin>>mat.mt[i][j];
        }
    }
    mat = mat ^ k;
    ll res = 0;
    for(auto x : mat.mt){
        for(auto y : x){
            res = (res + y) % mod;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<b>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j);a×b行列の入力
 
int main() {
  ll a,b;
  ci(a>>b);
  vec c(a);
  ll d=0;
  for(i,0,a){
    ci(c[i]);
    d+=c[i];
  }
  sort(c,c);
  ll e=a;
  b-=d;
  ll f=b;
  for(i,0,f){
    if(b-c[0]>=0){
      e++;
      b-=c[0];
    }
    else
      break;
  }
  co(e);
}

Measured memory_bytes: 256