akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

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

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  VI v(n);
  rep(i, n) cin >> v[i];
  rep(i, n) {
    v[i] = abs(x - v[i]);
  }
  int d = v[0];
  rep(i, n) {
    d = gcd(d, v[i]);
  }
  out(d);
  return 0;
}


Measured memory_bytes: 640
a = input()
b = input()
c = input()
ai=0
bi=0
ci=0
e=0
def turn(s,a,b,c,e):
    if s=='a':
        if len(a)==0:
            e=1
        else:
            s=a[0]
            a=a[1:]
    elif s=='b':
        if len(b)==0:
            e=1
        else:
            s=b[0]
            b=b[1:]
    elif s=='c':
        if len(c)==0:
            e=1
        else:
            s=c[0]
            c=c[1:]
    return s,a,b,c,e
s='a'
while e==0:
    s,a,b,c,e = turn(s,a,b,c,e)
print(s.upper())

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

int main() {
  int n; cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  h.push_back(0);

  int ans = 0;
  for(int i = 100 ; i>=1 ; i--){
    rep(j,n){
      if(h[j] >= i && h[j+1] < i) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
public class Main {

  private static void solve() {
    long a = nl();
    long v = nl();
    long b = nl();
    long w = nl();
    long t = nl();

    if (v <= w) {
      System.out.println("NO");
      return;
    }

    long dv = v - w;
    if (dv * t >= Math.abs(a - b)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 36816
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>
#include <set>
using namespace std;

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

#define max_n 100

int N;
int x[8];
int y[8];
double l[8][8];

int main() {

	cin >> N;

	rep(i,N){
		cin >> x[i];
		cin >> y[i];
	}

	rep(i,N){
		rep(j,N){
			l[i][j] = (x[i] - x[j])*(x[i] - x[j]) 
				+ (y[i] - y[j])*(y[i] - y[j]);
			l[i][j] = sqrt(l[i][j]);
		}
	}

	vector<int> v(N);
	rep(i, N)v.at(i) = i;

	double suml = 0;
	do {

		for(int i=0;i<N-1;i++)
		{
			suml += l[v.at(i)][v.at(i+1)];
		}
		
	} while (next_permutation(v.begin(), v.end()));     // 次の順列を生成

	rep(i,N)
	{
		suml /= (i+1);
	}

	printf("%f\n", suml);

	return 0;	
}

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

int main() {
  string str;
  stack<int> tmp;
  while(cin >> str) {

    if(isdigit(str[0])) {
      tmp.push( stoi(str) );
    } else {
      int b = tmp.top(); tmp.pop();
      int a = tmp.top(); tmp.pop();

      if(str == "+") {
	tmp.push( a+b );
      } else if(str == "-") {
	tmp.push( a-b );
      } else if(str == "*") {
	tmp.push( a*b );
      }
    }
  }

  cout << tmp.top() << endl;
}

Measured memory_bytes: 3168
#include<stdio.h>
int main(void)
{
	int a[200],b[200],c[200],sum[200];
	int flag;
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
		sum[i]=a[i]+b[i]+c[i];
	}
	for(i=0;i<n;i++){
		flag=0;
		for(j=0;j<n;j++){
			if(a[i]==a[j] && i!=j){
				flag=1;
			}
		}
		if(flag==1){
			sum[i]=sum[i]-a[i];
		}
		flag=0;
		for(j=0;j<n;j++){
			if(b[i]==b[j] && i!=j){
				flag=1;
			}
		}
		if(flag==1){
			sum[i]=sum[i]-b[i];
		}
		flag=0;
		for(j=0;j<n;j++){
			if(c[i]==c[j] && i!=j){
				flag=1;
			}
		}
		if(flag==1){
			sum[i]=sum[i]-c[i];
		}
		printf("%d\n",sum[i]);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
   // freopen("input.txt", "r", stdin);
    SPEED
    ll n, k;
    cin >> n >> k;
    n %= k;
    cout << min(n, k - n);
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


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

using namespace std;

int N;
vector<int>e[200010];
int d[200010];

void dfs(int x,int fa) {
	for (auto t:e[x]) {
		if (t != fa) {
			d[t] = d[x] + 1;
			dfs(t, x);
		}
	}
}

int getfar(int x) {
	d[x] = 0;
	dfs(x,0);
	int mx = 0, ret = 0;
	for (int i=1;i<=N;i++) {
		if (d[i] > mx) {
			mx = d[i];
			ret = i;
		}
	}
	return ret;
}

int main() {
	scanf("%d",&N);
	for (int i=1;i<N;i++) {
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	int x = getfar(1);
	int y = getfar(x);
	int len = d[y] + 1;
	//printf("len = %d\n",len);
	if (len == 1) {
		puts("First");
	} else if (len == 2) {
		puts("Second");
	} else if (len % 3 == 2) {
		puts("Second");
	} else {
		puts("First");
	}
}

Measured memory_bytes: 21376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


int main(){
	ll h,w;
	cin >> h >>w;
	if(h!=1 && w!=1) cout << (h*w+1)/2 << endl;
	else{
		cout << 1 << endl;
	}


  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	int n, m;
	cin >> n >> m;
	ll left = 0;
	ll right = INF;
	rep(i, m) {
		ll l, r;
		cin >> l >> r;
		left = max(left, l);
		right = min(right, r);
	}
	ll ans = right - left + 1;
	ans = max(0LL, ans);
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}


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

const long long  MOD = 998244353;
long long  dp[3010][3010][2];

int main() {
	int A, B, C, D; cin >> A >> B >> C >> D;
	dp[A][B][1] = 1;
	for (int i = A; i <= C; i++)
	{
		for (int j = B; j <= D; j++)
		{
			if(i == A && j == B) continue;
			dp[i][j][0] = ((dp[i-1][j][0] + dp[i-1][j][1]) % MOD) * j % MOD;
			dp[i][j][1] = (dp[i][j-1][0] + dp[i][j-1][1] * i % MOD) % MOD;
		}
	}

	cout << (dp[C][D][0] + dp[C][D][1]) % MOD << endl;
	return 0;
}


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

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] + a[1] == a[2])puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
import math

def fact(N):
    total = 1
    for i in range(1, N+1):
        total = total * i
    return total

def comb(a, b):
    return fact(a) // (fact(a-b) * fact(b))


def main():
    N, K = list(map(int, input().split(" ")))
    a = N - K + 1
    b = 1
    mod = 1000000007
    ans = ((a % mod) * (b % mod)) % mod
    print(ans)
    for i in range(1, K):
        tmp_a = (N-K+1-i)
        if tmp_a == 0:
            tmp_a = 1
        tmp_b = (K-1-i+1)
        if tmp_b == 0:
            tmp_b = 1
        a = (a * tmp_a) // (i+1)
        b = (b * tmp_b) // i
        ans = ((a % mod) * (b % mod)) % mod
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char stribuf[4194304];
uint32_t stribufs;

uint32_t nextpint(void){ char c=getc_unlocked(stdin); while(c<'0'||'9'<c) c=getc_unlocked(stdin); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getc_unlocked(stdin); } return x; }
void printpint(uint32_t x){ int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) stribuf[stribufs++]=s[i]; }
int main(void){
	uint32_t n=nextpint();
	uint32_t m=nextpint();
	{
		uint32_t a=m+1;
		for(uint32_t i=m/2; i>0; i--){
			printpint(i);
			stribuf[stribufs++]=32;
			printpint(a-i);
			stribuf[stribufs++]=10;
		}
	}
	{
		uint32_t a=(m+1)*2;
		for(uint32_t i=(m+1)/2; i>0; i--){
			printpint(m+i);
			stribuf[stribufs++]=32;
			printpint(a-i);
			stribuf[stribufs++]=10;
		}
	}
	write(1, stribuf, stribufs);
}




Measured memory_bytes: 2484
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){

    int N;
    cin>>N;
    int h[N+5]={};
    int cost[N+5]={};
    
    for(int i=0;i<N;i++){
        cin>>h[i];
    }
    cost[0]=0;
    cost[1]=abs(h[1]-h[0]);
    for(int i=2;i<N;i++){
        cost[i]=min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<cost[N-1]<<"\n";
    return(0);
}

Measured memory_bytes: 4392
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;
typedef long long ll;

char buf[200000+10];
int nextOccur[26][200000+10];
int lenFrom[200000+10];
int lastFrom[200000+10];

const int INF = 1000000000;

int main(void) {
  scanf("%s", buf);
  int n = strlen(buf);

  REP(c, 26) {
    nextOccur[c][n] = INF;
    for(int i = n-1; i >= 0; --i) {
      if(buf[i] == 'a'+c) {
        nextOccur[c][i] = i;
      } else {
        nextOccur[c][i] = nextOccur[c][i+1];
      }
    }
  }

  for(int i = n-1; i >= 0; --i) {
    int& maxi = lastFrom[i];
    maxi = -1;
    REP(c, 26) {
      maxi = max(nextOccur[c][i], maxi);
    }
    if(maxi == INF){
      lenFrom[i] = 0;
    } else {
      lenFrom[i] = lenFrom[maxi+1]+1;
    }
  }

  for(int pos = 0; ; ) {
    int minLen = INF;
    int minC = -1;
    REP(c, 26) {
      int len = nextOccur[c][pos] == INF ? -1 : lenFrom[nextOccur[c][pos]+1];
      if(len < minLen) {
        minLen = len;
        minC = c;
      }
    }
    
    printf("%c", 'a'+minC);
    if(minLen < 0) {
      break;
    } else {
      pos = nextOccur[minC][pos]+1;
    }
  }
  puts("");
  
  return 0;
}


Measured memory_bytes: 22272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll a, b;
  cin >> a >> b;
  if (a < b)
    swap(a, b);

  for (ll i = 0; i < a; i++)
  {
    cout << b;
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
// g++ -std=c++11 -O2 -Wall *.cpp -o *
#define eps 1e-9
#define MAX 1000001
#define MOD 1000000007
#define PI 3.14159265358979323846
#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define Rep(i, a, b) for (int i = a; i < b; ++i)
typedef long long ll;
typedef pair<int, int> pr_int;


int main()
{
	//freopen("input.txt", "r", stdin);
	ll h;
	cin >> h;

	ll n = ll(log2l(h * 1.0));

	ll s = 0;
	ll x = 1;

	Rep(i, 0, n + 1){
		s += x;
		x *= 2;
	}

	cout << s;

	return 0;
}



Measured memory_bytes: 384
int main(){
    int n;
    int i;
    int x;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        x=i;
        if(x%3==0){
            printf(" %d",i);
        }
        else{
            while(x!=0){
                if(x%10==3){
                    printf(" %d",i);
                    x=0;
                }
                x/=10;
            }
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2020
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,a[1000],c=1;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=1;i<n;i++){
        if(a[i]!=a[i-1])
            c++;
    }
    cout<<c<<endl;





    return 0;
}


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

struct fw
{
	vector<long long > arr;
	int n;
	fw(int nn)
	{
		n = nn;
		arr.resize(n + 10);
	}

	void upd(int x, long long  new_val)
	{
		for (int i = x; i < n; i += i & -i)
			arr[i] = max(arr[i], new_val);
	}

	long long query(int a)
	{
		long long  res = 0;
		for (int i = a; i > 0; i -= i & -i)
			res = max(res, arr[i]);
		return res;
	}
};
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	// dp[i] denotes maximum possible beauty when i is the last height
	vector<long long> dp(n + 1);

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

	vector<long long> beauty(n);
	for (int i = 0; i < n; i++)
		cin >> beauty[i];

	fw bit(n);
	for (int i = 0; i < n; i++)
	{
		dp[heights[i]] = bit.query(heights[i] - 1) + beauty[i];
		bit.upd(heights[i], dp[heights[i]]);
	}
	cout << *max_element(dp.begin(), dp.end()) << "\n";
}



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

int main() {
    int n;
    cin >> n;
    list<int> li;
    vector<int> v1(n);
    rep(i, n) cin >> v1[i];
    int nxt = 1;
    int count = 0;
    rep(i, n) {
        if (v1[i] == nxt) {
            nxt++;
            count++;
        }
    }
    if (count == 0) {
        cout << -1 << endl;
    }
    else {
        cout << n - count << endl;
    }
}


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

int main()
{
  int n, k;
  cin >> n >> k;
  int x[n];
  rep(i, n) cin >> x[i];
  int ans = 0;
  rep(i, n) ans += min((x[i] * 2),((k - x[i]) * 2));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,n,o;
  cin>>x>>n;
  vector<int> v;
  if(n==0){
    cout<<x<<endl;
  }
  else if(n==100){
    int z=x;
    if(z>50){
      cout<<101<<endl;
    }
    else{
      cout<<0<<endl;
    }
  }
      else{
  for (int p = -200; p < 301; p++) {
    v.push_back(p);
    }
  for (int i = 0; i < n; i++) {
    int y;
    cin>>y;
 vector<int>::iterator e = remove(v.begin(), v.end(), y);
  }
 for (int i = 0; i < n; i++) {
    v.pop_back();
  }
  int a=300,b,c;
  for (int i = 0; i < 500-n; i++) {
    b=v.at(i);
    c=abs(x-b);
    if(a>c){
      o=v.at(i);
    }
    a=c;
  }
cout<<o<<endl;    
  }
  }

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main(){
    int a[3];
    rep(i,3)cin >> a[i];
    sort(a,a+3);
    if(a[2]==a[1] && a[1] == a[0]){
        cout << "Yes"<<endl;
    }else{
        cout << "No" <<endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
	register int f=1,k=0;register char c=getchar();
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	return k*f;
}
int main()
{
	int a=read(),b=read(),c=read(),x=read(),y=read();
	int ans=(1ll<<30)-1;
	for (register int i=0;i<=max(x*2,y*2);i++)
	{
		int tmp=i*c;
		if (i<x*2)tmp+=(x-i/2)*a;
		if (i<y*2)tmp+=(y-i/2)*b ;
		ans=min(ans,tmp);
	}
//	int ans=min(max(x,y)*c*2,);
	printf("%d\n",ans); 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

#include <bits/stdc++.h>
using namespace std;

signed main(){
    int K,S; cin>>K>>S;
    int ans = 0;
    REP(i,K+1){
        REP(j,K+1){
            int L = S-i-j;
            if(L>=0&&L<=K){
              ans ++;
            }
        }
    }
    Out(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }

ll MNUM = pow(10,6);
vector<bool> isp(MNUM+1, true);

void sieve() {
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=MNUM; i++) {
    if (isp[i]) for(int j=2; i*j<=MNUM; j++) isp[i*j] = false;
  }
}

int main() {
  ll A, B; cin >> A >> B;
  ll g = gcd(A, B);

  sieve();
  int result = 1;
  for (ll i=2; i*i<=g; i++) {
    if (isp[i]&&g%i==0) {
      while(g%i==0) g/=i;
      result++;
    }
  }
  if (g!=1) result++;
  cout << result << endl;
  return 0;
}

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

using namespace std;

string x;

int main()
{

    int n;

    cin >> n;

    map <string ,int> m;

    vector <string > v;

    int apmax = 0;

    for(int i = 1; i <= n; i++)
    {
        cin >> x;


        m[x]++;
        if(m[x] > apmax)
        {
            apmax = m[x];
            v.clear();
            v.push_back(x);
        }
        else
        if(m[x] == apmax)
        v.push_back(x);
    }

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

    for(int i = 0; i < v.size(); i++)
     cout << v[i] <<'\n';

    return 0;
}


Measured memory_bytes: 26736
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int x_[4] = { 1,-1,0,0 };
int y_[4] = { 0,0,1,-1 };

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<ll> > map(H+2, vector<ll>(W+2, INF));
	vector<vector<vector<ll> > >  dp(H*W + 1, vector<vector<ll> >(H + 2, vector < ll >(W + 2, INF)));
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) {
		cin >> map[i + 1][j + 1];
	}

	dp[0][1][1] = 0;
	for (int i = 0; i < H*W; i++)for (int j = 1; j <= H; j++)for (int k = 1; k <= W; k++) {
		if (dp[i][j][k] == INF)continue;
		for (int s = 0; s < 4; s++) {
			dp[i + 1][j + x_[s]][k + y_[s]] = min(dp[i][j][k] + map[j + x_[s]][k + y_[s]] * (i * 2 + 1), dp[i + 1][j + x_[s]][k + y_[s]]);
		}
	}

	ll ans = INF;
	for (int i = 1; i < H*W + 1; i++) {
		if (dp[i][H][W] == -1)continue;
		ans = min(ans, dp[i][H][W]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 11352
N = int(input())
A = list(input().split())
A = sorted(A)
c = 0
for i in range(N-1):
  if A[i] == A[i+1]:
    c += 1
    break
  else:
    c += 0
if c == 1:
  print("NO")
else:
  print("YES")

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

int main() {
  int a;
  cin >> a;
  long long int count = 0;
  for(int i=0;i<a;i++){
    int j = i+1;
    if(j % 3 != 0 && j % 5 != 0){
      count += j;
    }
  }
    cout << count << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll a,b;
  cin >> a >> b;
  cout << (a+b)%24 << endl;
}

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

string s;
int a[] = {9, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

int main() {
  	cin >> s;
    cout << a[s[0] - '0'] << a[s[1] - '0'] << a[s[2] - '0'] << '\n';
  	return 0; 
}

Measured memory_bytes: 256
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n, = [int(num) for num in lines.pop(0).split(" ")]
l_list = [int(num) for num in lines.pop(0).split(" ")]
l_list.sort(reverse=True)
m = l_list.pop(0)
if m < sum(l_list):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9180
import numpy as np
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            #if i != n // i:
            #    divisors.append(n//i)

    # divisors.sort()
    return divisors

# coding: utf-8
# Your code here!
#N, K = map(int, input().split())
X = int(input())

div = make_divisors(X)

for diff in div:
    for a in range(int(X**0.5)):
        if (a**5 - (a-diff)**5) == X:
            print(a, a-diff)
            break
        

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    cout << a.at(n-1)-a.at(0) << endl;
}

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

int main() {

  vector< long long int > a;
  
  long long int n = 0;
  while( !cin.eof() ) {
    
    string s;
    getline( cin, s );
    replace(s.begin(), s.end(), ',', ' ');
    stringstream ss(s);

    long long int in = 0;
    while( ss >> in ) {
      a.push_back( in );
      //cout << in << endl;
    }
    
    
    n++;
  }
  n = (n + 1) / 2;
  //cout << n << endl;

  long long int cnt[100][100] = {0};
  long long int k = 0;
  for ( long long int i = 0; i < n; i++ ) {
    for ( long long int j = 0; j <= i; j++ ) {
      if(i == 0){
	cnt[i][j] = a[k];
      }else{
	cnt[i][j] = max(j == 0 ? 0 : cnt[i-1][j-1], cnt[i - 1][j]) + a[k];
      }
      //ut << a[k] << "(" << k <<  ")" << ",";
      k++;
    }
    //ut << endl;
  }
  for ( long long int i = n-1; i >= 1; i-- ) {
    const int h = 2 * n - i - 1;
    
    for ( long long int j = 0; j < i; j++ ) {
      cnt[h][j] = max( cnt[h-1][j], cnt[h-1][j+1] ) + a[k];
      //cout << a[k] << "(" << k <<  ")" << ",";
      k++;
    }
    // cout << endl;
  }
  cout << cnt[2*n - 2][0] << endl;

  return 0;

}

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

int main() {
  int n;
  cin >> n;
  
  bool flag = false;
  for(int i=1; i<=n; i++) {
    if((int)(i*1.08) == n) {
      cout << i << endl;
      flag = true;
      break;
    }
  }
  if(flag == false)
    cout << ":(" << endl;
}

Measured memory_bytes: 256
function main()
    H,W,M = reads(Int,Int,Int)
    hc = zeros(Int, H)
    wc = zeros(Int, W)
    hwset = Set(Tuple{Int,Int}[])
    for i in 1:M
        hi,wi = reads(Int,Int)
        push!(hwset, (hi,wi))
        hc[hi] += 1
        wc[wi] += 1
    end
    mhi = [1]
    mhv = hc[1]
    for i in 2:H
        if mhv < hc[i]
            mhi = [i]
            mhv = hc[i]
        elseif mhv == hc[i]
            push!(mhi, i)
        end
    end
    mwi = [1]
    mwv = wc[1]
    for i in 2:W
        if mwv < wc[i]
            mwi = [i]
            mwv = wc[i]
        elseif mwv == wc[i]
            push!(mwi, i)
        end
    end
    for i in mhi, j in mwi
        if !((i,j) in hwset)
            println(mhv+mwv)
            return
        end
    end
    println(mhv+mwv-1)
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


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

int main() {
  int h, n;
  int count = 0;
  cin >> h >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  while(count < n) {
    count++;
    h -= a.at(count - 1);
  }
  if (h > 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
typedef vector<double> vd;

double g(vd a, vd b, double c) {
  double res = 0;
  rep(i,6) {
    double s = a[i]*c;
    double t = b[i]*(1-c);
    res += max(s,t);
  }
  return res;
}
double f(vd a, vd b) {
  double l = 0, r = 1;
  rep(ti,100) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    double d1 = g(a,b,c1);
    double d2 = g(a,b,c2);
    if (d1 > d2) l = c1; else r = c2;
  }
  return g(a,b,l);
}

int main() {
  vd a, b;
  rep(i,6) {
    int tmp;
    scanf("%d",&tmp);
    a.pb(tmp*0.01);
  }
  rep(i,6) {
    int tmp;
    scanf("%d",&tmp);
    b.pb(tmp*0.01);
  }
  // double l = 0, r = 1;
  // rep(ti,100) {
  //   double c = (l+r)/2;
  //   if (f(a,b,c)) l = c; else r = c;
  // }
  double ans = f(a,b);
  printf("%.10f\n",ans);
  return 0;
}































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

int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll a;
        cin>>a;
        v.push_back({a,1});
    }
    rep(i,m){
        ll b,c;
        cin>>b>>c;
        v.push_back({c,b});
    }

    sort(all(v));
    reverse(all(v));
    ll ans=0,cnt=0;
    rep(i,n+m){
        if(cnt+v[i].second<n){
            ans+=v[i].second*v[i].first;
            cnt+=v[i].second;
        }
        else{
            ans+=(n-cnt)*v[i].first;
            cout<<ans<<endl;
            return 0;
        }
        //cout<<ans<<endl;
    }
}



Measured memory_bytes: 7400
import sys

N, A, B, C, D = map(int,input().split())
S = input()
# A<B<C, A<Dは保証 C<Dは保証されない
#AからDまでの間に岩が2つ並んでいたらむり
for i in range(A-1, D):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        sys.exit()
#Cのが左ならいける
if C < D:
    print("Yes")
    sys.exit()
# D<Cのときが問題
# Aが不可能な時は岩をBからCの間に1つも追加できない時
# Bが可能な限り小さいステップで進んだときに前後が.である時がCまでに現れないと死
# 見るべきはS[B-1](B番目のマス)からS[C-2](C-1番目のマス)の前後
for i in range(B-1, D):
    if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
        print("Yes")
        sys.exit()
print("No")

Measured memory_bytes: 40560
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

const ll MODULO = 1e9 + 7;

ll Pow(ll x, ll n) {
  ll result = 1;
  while (n) {
    if (n % 2) result = result * x % MODULO;
    n /= 2;
    x = x * x % MODULO;
  }
  return result;
}

ll Inv(ll n) {
  return Pow(n, MODULO - 2);
}

const int MAXN = 5 * 100 * 1000 + 2;
ll fact[MAXN];
ll inv[MAXN];

ll C(int n, int k) {
  ll result = fact[n];
  result = result * inv[k] % MODULO;
  result = result * inv[n - k] % MODULO;
  return result;
}

int main()
{
  fact[0] = 1;
  for (ll i = 1; i < MAXN; ++i) fact[i] = fact[i - 1] * i % MODULO;
  for (int i = 0; i < MAXN; ++i) inv[i] = Inv(fact[i]);

  int n, m;
  cin >> n >> m;
  ll result = 0;
  for (int t = 0; t <= n; ++t) {
    ll cur = C(n, t);
    cur = cur * fact[m] % MODULO;
    cur = cur * inv[m - t] % MODULO;

    cur = cur * fact[m - t] % MODULO;
    cur = cur * fact[m - t] % MODULO;

    cur = cur * inv[m - n] % MODULO;
    cur = cur * inv[m - n] % MODULO;

    ll sgn = 1;
    if (t % 2) sgn = -1;

    result = (result + MODULO + sgn * cur) % MODULO;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 11440
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define SIZE(a) (int)((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}

class BIT
{
  private:
    vector<int> bit;
    int len;
  public:
    BIT(int n) {
      len = n+1;
      bit = vector<int>(len);
    }
    void add(int i, int x) {
      i += 1;
      while (i <= len) {
        bit[i] += x;
        i += i & -i;
      }
    }
    int sum(int i) {
      i += 1;
      int s = 0;
      while (i > 0) {
        s += bit[i];
        i -= i & -i;
      }
      return s;
    }
};

class BIT_2D
{
  private:
    vector<BIT> bit;
    int len;
  public:
    BIT_2D(int n) {
      len = n+1;
      bit = vector<BIT>(len, BIT(n));
    }
    void add(int i, int j, int x) {
      i += 1;
      while (i <= len) {
        bit[i].add(j, x);
        i += i & -i;
      }
    }
    int sum(int i, int j) {
      i += 1;
      int s = 0;
      while (i > 0) {
        s += bit[i].sum(j);
        i -= i & -i;
      }
      return s;
    }
};


signed main()
{
  int N, K;
  cin >> N >> K;
  BIT_2D s(K);
  int x, y; char c;
  int white = 0;
  rep(i, 0, N) {
    cin >> x >> y >> c;
    int l = (x % (2*K) < K) ? 0 : 1;
    int m = (y % (2*K) < K) ? 0 : 1;
    int n = (c == 'B') ? 0 : 1;
    if ((l+m+n) % 2 == 0) {
      s.add(x % K, y % K,  1);
    } else {
      s.add(x % K, y % K, -1);
      white++;
    }
  }

  int ans = -INF;
  rep(i, 0, K) {
    rep(j, 0, K) {
      ans = max(s.sum(K-1, K-1) - s.sum(i, K-1) - s.sum(K-1, j) + 2*s.sum(i, j), ans);
      ans = max(s.sum(i, K-1) + s.sum(K-1, j) - 2*s.sum(i, j), ans);
    }
  }

  cout << ans + white << endl;

  return 0;
}


Measured memory_bytes: 8064
import sys
from collections import defaultdict


def reverse_search(n, parents):
    q = [n - 1]
    visited = set()
    while q:
        v = q.pop()
        if v in visited:
            continue
        visited.add(v)
        q.extend(u for u in parents[v] if u not in visited)
    return visited


n, m, p = list(map(int, input().split()))
INF = 10 ** 12
links = [set() for _ in range(n)]
parents = [set() for _ in range(n)]
costs = [[INF] * n for _ in range(n)]
for line in sys.stdin:
    a, b, c = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    parents[b].add(a)
    costs[a][b] = min(costs[a][b], p - c)
reachable = reverse_search(n, parents)
links = list(map(reachable.intersection, links))

dist = [INF] * n
dist[0] = 0
for _ in range(len(reachable)):
    updated = False
    for v in reachable:
        d = dist[v]
        if d == INF:
            continue
        cv = costs[v]
        for u in links[v]:
            if dist[u] > d + cv[u]:
                dist[u] = d + cv[u]
                updated = True
    if not updated:
        break
else:
    print(-1)
    exit()

print(max(0, -dist[n - 1]))


Measured memory_bytes: 100060
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long int lint;
int main() {
	int N;
	string S;
	cin >> N >> S;
	int Z = S.size();
	vector<int>vec(Z);
	int w = 0;
	int e = 0;
	for (int ia = 0; ia < Z; ia++) {
		vec.at(ia) += w;
		if (S.at(ia) == 'W') {
			w++;
		}
	}
	for (int ib = 0; ib < Z; ib++) {
		vec.at(Z - ib - 1) += e;
		if (S.at(Z - ib-1) == 'E') {
			e++;
		}
	}
	sort(vec.begin(), vec.end());
	cout << vec.at(0) << endl;
}



	


Measured memory_bytes: 1796
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  double T, X;
  cin >> T >> X;
  cout << T / X << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    size_t l=s.length();
    
    rep(i,l){
        int num=s[i]-'A';
        char c=(num+n)%26+'A';
        cout<<c;
    }
    
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9+7;
const long double PI=acos(-1);



void solve(int T){
    int n,d;
    cin>>n>>d;
    vector<vector<int> >a(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            int x;
            cin>>x;
            a[i].pb(x);
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            double x=0.0;
            for(int k=0;k<d;k++){
                x+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
            }
            x=sqrt(x);
            if(floor(x)==ceil(x))ans++;
        }
    }
    cout<<ans<<"\n";
}

int main() {
    fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 100000000000000000
#define int long long
int ans[2][100010];
typedef pair<int, int> P;
typedef pair<int, P> PP;
vector<PP> G[100010];


void dijkstra(int s, int kind) {
    priority_queue<P, vector<P>, greater<P> > que;
    rep(j, 100010) ans[kind][j] = INF2;
    ans[kind][s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (ans[kind][v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++){
            P e;
            e.first = G[v][i].first;
            if (kind == 0) e.second= G[v][i].second.first;
            else e.second = G[v][i].second.second;
            if (ans[kind][e.first] > ans[kind][v] + e.second) {
                ans[kind][e.first] = ans[kind][v] + e.second;
                que.push(P(ans[kind][e.first], e.first));
            }
        }
    }
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, s, t; cin >> n >> m >> s >> t;
    s--; t--;
    rep(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        G[u].push_back({v, {a, b}});
        G[v].push_back({u, {a, b}});
    }
    dijkstra(s, 0);
    dijkstra(t, 1);

    int k = INF2;
    vector<int> output;
    rrep(i, n - 1) {
        k = min(k, ans[0][i] + ans[1][i]);
        output.push_back(1000000000000000 - k);
    }
    rrep(i, n - 1) cout << output[i] << endl;


    return 0;
}


Measured memory_bytes: 13952
#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 < (n); ++i)

const ll mod=1000000007;

int main(){
  ll n;
  std::cin >>  n;
  std::vector<ll> a(n);

  ll sum=0;
  rep(i,n){
    std::cin >> a[i];
    sum+=a[i];
    sum%=mod;
  }

  // std::cout << sum << '\n';



  ll ans=0;
  for (int i = n-1; i >= 1; i--) {

    sum-=a[i];
    if(sum<0)sum+=mod;
    //
    // std::cout << a[i]<<"*"<<sum<< '\n';
    // std::cout << a[i]*sum << '\n';



    ll add=(a[i]*sum)%mod;
    ans+=add;
    ans%=mod;

  }


  std::cout << ans << '\n';


  return 0;
}


Measured memory_bytes: 4836