akhauriyash/Code-Regression huggingface dataset:
///******* In the name of Allah *******///

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

long int gcd(long int a, long int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Ok()
{
    long long int a[1013],b,c,d,e,f,g,h,t,s,i,j,k,l1,l2,m,n,r,sum = 0,ans_1,ans_2,ans_3,cnt = 0,Max,Min,flag,div,rcv,temp;
    double aa,bb,cc,dd,ee,tot;
    char aaa[1013],bbb[1013],ccc[1013];

    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];

    sort(a+1,a+n+1);
    ans_1 = a[n];
    ans_2 = 0;
    Min = 999999;
    for(i=1;i<=ans_1;i++)
    {
        for(j=1;j<=n;j++)
        {
            ans_2 += (a[j] - i) * (a[j] - i);
        }
        Min = min(Min,ans_2);
        ans_2 = 0;
    }
    cout<<Min<<endl;

    return;
}

int main()
{
    Ok();

    return 0;
}


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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    int N, K, Q, tmp;
    cin >> N >> K >> Q;
    vector<int> list(N, K - Q);
    for (int i = 0; i < Q; i++)
    {
        cin >> tmp;
        list[tmp - 1]++;
    }
    for (int i = 0; i < N; i++)
        cout << (list[i] > 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1024
import sys

def solve(n, s):
    pre = ""
    ans = n
    for s_i in s:
        if s_i == pre:
            ans -= 1
        pre = s_i

    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    s = sys.stdin.readline().strip()
    solve(n, s)

Measured memory_bytes: 39280
#include<bits/stdc++.h>
using namespace std;
char s[102];
int teck(int n){
	int ans=0,k=n-1;
	int a=n/2;
	//cout<<a<<endl;
	for(int i=0;i<a;i++){
		//cout<<s[i]<<" "<<s[k-i]<<endl;
		if(s[i]!=s[k-i]){
			ans++;
		}
	}
	return ans;
}
int main(){
	int n;
	cin>>s;
	n=strlen(s);
	//cout<<n<<endl;
	cout<<teck(n)<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict

sys.setrecursionlimit(10**7)
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0]*(n)
        self.size = [1]*(n)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

ans = []
rAB = list(reversed(AB))

uni = UnionFind(N)


inconv = N*(N-1)//2
ans = [inconv]*(M+1)
for i, rab in enumerate(rAB):
    a, b = rab[0]-1, rab[1]-1
    sizea = uni.get_size(a)
    sizeb = uni.get_size(b)
    if uni.same_check(a, b):
        ans[i+1] = ans[i]
    else:
        ans[i+1] = inconv - (sizea * sizeb)
        inconv -= (sizea * sizeb)
    uni.union(a, b)

for i in list(reversed(ans))[1:]:
    print(max(i, 0))


Measured memory_bytes: 38428
S = input()

if S =='SUN':
  print(int(7))

elif S =='MON':
  print(int(6))

elif S =='TUE':
  print(int(5))

elif S =='WED':
  print(int(4))

elif S =='THU':
  print(int(3))

elif S =='FRI':
  print(int(2))

elif S =='SAT':
  print(int(1))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cassert>
#include<map>
#include<vector>
#include<cmath>
#include<complex>
using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define N 100
#define DEAD false
#define ARRIVE true
#define eps 1e-10

typedef complex<double> P;

double dot(P a,P b){
  return a.real()*b.real()+a.imag()*b.imag();
}

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

double distance_ls_p(P a,P b,P c,double r){
  if ( dot(b-a,c-a)<0)return r*2;
  else if ( dot(a-b,c-b)<0)return r*2;
  return abs(cross(b-a,c-a))/abs(b-a);
}

bool is_intersect_cl(P a,P b,P circle,double radius){
  bool flag1 = abs(a-circle)<=radius?1:0;
  bool flag2 = abs(b-circle)<=radius?1:0;
  
  if ( flag1 == true)return true;
    else if ( flag2 == true)return true;
  if (  distance_ls_p(a,b,circle,radius)<radius+eps)return true;
  return false;
}

class UFO{
public:
  P now;
  double r,v,theta,time;
  double vx,vy;
  bool flag;
  UFO(){};
  UFO(double tx,double ty,double tr,double tv,double R){
    flag = ARRIVE;
    now.real()=tx;
    now.imag()=ty;
    v=tv;
    r=tr;
    theta = arg(now);
    time = sqrt(tx*tx+ty*ty)-R;
    if (time < 0)flag=DEAD;
    else time/=v;
    vx=-cos(theta)*v;
    vy=-sin(theta)*v;    
  }

  void move(double t){    
    if (flag == DEAD){return;}
    now.real()+=vx;
    now.imag()+=vy;
    if ( time < t+eps){flag = DEAD;return ;}
  }

  bool crash_check(P a,P b){
    if ( flag == DEAD)return false;
    if ( is_intersect_cl(a,b,now,r)==true){
      flag = DEAD;
      return true;
    }
    return false;
  }
};

int solve(int n,UFO *data,double R){
  const double INF = 20000;
  int cnt=0;
  double time=1;
  while(true){
    double dist = 1000*1000;
    int minindex = -1;
    rep(i,n){
      data[i].move(time);
      if (data[i].flag == ARRIVE&& abs(data[i].now)<dist){
	dist=abs(data[i].now);
	minindex=i;
      }
    }
    if ( minindex == -1)break;
    //cout <<"tar " <<  minindex << endl;
    P a,b,e;
    e = data[minindex].now/abs(data[minindex].now);
    a=e*R;
    b=e*INF;
    rep(i,n){
      if ( data[i].crash_check(a,b) == true){
	//cout << i << endl;
	cnt++;
      }
    }
    time+=1;
  }
  return n-cnt;
}

main(){
  double R;
  int n;
  while(cin>>R >> n && n){
    UFO data[n];
    rep(i,n){
      double x,y,r,v;
      cin>>x>>y>>r>>v;
      data[i]=UFO(x,y,r,v,R);
    }
    cout << solve(n,data,R) << endl;
  }
}

Measured memory_bytes: 0
def main():
    h, w, *ca = map(int, open(0).read().split())
    it = zip(*[iter(ca[:100])] * 10)
    *c, = map(lambda i: list(i), it)
    a = ca[100:]

    for k in range(10):
        for i in range(10):
            for j in range(10):
                c[i][j] = min(c[i][j], c[i][k] + c[k][j])

    ans = 0
    cost = {i: c[i][1] for i in [0, 2, 3, 4, 5, 6, 7, 8, 9]}

    for i in a:
        if i in [-1, 1]:
            continue
        ans += cost[i]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5896
//b.cpp

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

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= 9; i++)
        for (int j = 1; j <= 9; j++)
            if (i * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<math.h> 
#include<algorithm> 
#include<sstream>
#include<fstream>  
using namespace std; 
typedef long long ll; 
typedef long double ld; 

int ceil(int a, int m){
    // division of a and m
    if(a % m == 0){
        return a/m; 
    }
    else{
        return a/m + 1; 
    }
}

vector<int> sort(vector<int> arr){
    sort(arr.begin(), arr.end()); 
    return arr; 
}





int main(){

char nl = '\n'; 
/*
For array arr use the following preamble to sort
int diff = sizeof(arr)/sizeof(arr[0]); 
sort(arr, arr + diff); 

*/
int n; 
cin >> n; 
if(n%1000 == 0){
    cout << 0; 
}
else{
    cout << (n/1000 + 1) * 1000 - n; 
}
}

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

using namespace std;

using i64 = int64_t;
const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    for(auto& x : a){
        cin >> x;
        --x;
    }
    for(auto& x : b)
        cin >> x;
    for(auto& x : c)
        cin >> x;
    int ans = 0;
    for(int i = 0; i < n - 1; ++i){
        if(a[i + 1] - a[i] == 1)
            ans += c[a[i]];
        ans += b[a[i]];
    }
    cout << ans + b[a.back()] << endl;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N = I()
    P = LI()
    ans = 0
    min_num = P[0]
    for i in range(N):
        if min_num>=P[i]:
            ans += 1
            min_num = P[i]

    print(ans)

main()



Measured memory_bytes: 50784
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
map<ll,ll>MP;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi D(n);
  ll ans=0;
  for(auto &a:D){cin>>a;MP[a]++;}
  ll sum=0;
  bool hoge=false;
  ll po=0;
  for(auto a:MP){
    sum+=a.S;
    if(hoge){
      cout<<a.F-po<<endl;
      return 0;
    }
    if(sum==n/2){
      hoge=true;
      po=a.F;
    }
  }
  cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 4992
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main()
{

    int N;
    cin >> N;
    vector<int> a;
    for(int i=0;i<N;++i)
    {
        int t;
        cin >> t;
        a.push_back(t);
    }

    vector<long long> b;
    b.push_back(a[0]);

    for(int i=1;i<N;++i)
    {
        b.push_back(b[i-1]+a[i]);
    }

    long long x,y,m=9e18;
    for(int i=0;i<N-1;++i)
    {
        x=b[i];
        y=b[N-1]-x;
        if(abs(x-y)<m)
            m=abs(x-y);
    }
    cout << m;



	return 0;
}


Measured memory_bytes: 3188
def main():
    num = int(input())
    start = [0, 0, 0]
    flg = 1
    for i in range(num):
        data = list(map(int, input().split()))
        time_data = data[0] - start[0]
        kyori = abs(data[1] - start[1]) + abs(data[2] - start[2])
        # print(time_data, kyori)
        if time_data == kyori:
            start = data
        elif time_data < kyori:
            flg = 0
            break
        elif (time_data - kyori) % 2 == 0:
            start = data
        else:
            flg = 0
            break

    if flg:
        print('Yes')
    else:
        print('No')




if __name__ == '__main__':
    main()


Measured memory_bytes: 44648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,a[200010];
    cin>>n;
    rep(i,n)cin>>a[i];
    sort(a,a+n,greater<int>());
    int ans=0,cnt=0;
    rep(i,n){
        if(i==0){
            ans+=a[i];
            cnt++;
        }
        else if(cnt+2<n){
            ans+=a[i]*2;
            cnt+=2;
        }
        else if(cnt+1<n){
            ans+=a[i];
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5204
#include <stdio.h>
double arrsum(double data[ ], int n)
{
    int i;
    double total = 0.0;

    for(i=0; i<n; i++){
        total += data[i];
    }

    return total;
}

int main() {
    double N,M,T=0.0;
    int i,S=0,TD;
    double A[1000];
    scanf("%lf %lf",&N,&M);
    for(i=0;i<N;i++)
    {
        scanf("%lf",&A[i]);
    }
    for(i=0;i<N;i++)
    {
        T=(arrsum(A,(int)N)/(4.0*M));
        TD=(T+ 0.999999);
        if((int)A[i]>=TD)
        {
            S++;
        }
    }
    if(S>=M)
    {
        printf("Yes\n");
    } else{
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    if input() == 'ABC':
        print('ARC')
    else:
        print('ABC')
    
if __name__ == "__main__":
    main()

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

typedef long long ll;

using namespace std;

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

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;

int main(){
    int N,R;
    cin >> N >> R;
    if(N >= 10) cout << R << endl;
    else cout << R + 100*(10-N) << endl;
    return  0;
}




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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


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> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n, m, k;
		cin >> n >> m >> k;
		if (!n)break;
		vvi dp(n, vi(n*m, 0));
		REP(i, m)dp[0][i] = 1;
		REP(i, n - 1) {
			REP(j, n*m) {
				FOR(k, 1, m + 1) {
					if (j + k >= n*m)break;
					dp[i + 1][j + k] += dp[i][j];
				}
			}
		}


		long double sum = 0;
		REP(i, n*m) {
			if (i + 1 <= k)sum += dp[n - 1][i];
			else sum += (i + 1 - k)*dp[n - 1][i];
		}
		REP(i, n)sum /= m;
		cout << fixed << setprecision(12) << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3308
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,m;
  cin >> n >> m;
  if(n==1&&m==0){
    cout << 0;
    return 0;
  }
  vector<int> s(m),c(m);
  rep(i,m){
    cin >> s.at(i) >> c.at(i);
  }
  bool is=true;
  rep(i,m){
    rep(j,m){
      if(i==j){
        continue;
      }
      if(s.at(i)==s.at(j) && c.at(i)!=c.at(j)){
        is=false;
      }
    }
  }
  if(!is){
    cout << -1;
    return 0;
  }
  rep(i,m){
    if(n==1 && s.at(i)==1 && c.at(i)==0){
      cout << 0;
      return 0;
    }
    if(n!=1 && s.at(i)==1 && c.at(i)==0){
      cout << -1;
      return 0;
    }
  }
  vector<int> ans(n);
  rep(i,m){
    ans.at(s.at(i)-1)=c.at(i);
  }
  if(ans.at(0)==0){
    ans.at(0)=1;
  }
  rep(i,n){
    cout << ans.at(i);
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 100005
using namespace std;

int n,m,p[maxn],q[maxn],i,j,k;

struct per{int a[maxn];} a,b,A,B,C,D,F,G[7];
per operator*(per a,per b){
	per c;
	for(int i=1;i<=n;i++) c.a[i]=b.a[a.a[i]];
	return c;
}
per inv(per a){
	per b;
	for(int i=1;i<=n;i++) b.a[a.a[i]]=i;
	return b;
}

int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) scanf("%d",&p[i]);
	for(i=1;i<=n;i++) scanf("%d",&q[i]);
	for(i=1;i<=n;i++) a.a[i]=p[i],b.a[i]=q[i];
	A=inv(a),B=inv(b),C=B*a*b*A;
	G[1]=a,G[2]=b;
	for(i=3;i<=6;i++) G[i]=inv(G[i-2])*G[i-1];
	for(i=1;i<=n;i++) D.a[i]=i;
	for(k=(m-1)/6;k;k/=2,C=C*C) if (k&1) D=D*C;
	F=D*G[(m-1)%6+1]*inv(D);
	for(i=1;i<=n;i++) printf("%d ",F.a[i]);
}

Measured memory_bytes: 10660
#!/usr/bin/env python3
import collections
n, m = map(int, input().split())
l = []
ans = 0
for _ in range(n):
    l.extend(list(map(int, input().split()))[1:])
c = collections.Counter(l)
for k in c:
    if c[k] == n: ans += 1
print(ans)

Measured memory_bytes: 3316
def main():
    n = int(input()) 
    l = list()
    t = 0
    x , y = 0 , 0
    flag = True
    for i in range(n):
        c , a , b = map(int,input().split())
        if abs(a-x) + abs(b-y) > abs(c-t) :
            # print('%')
            flag = False 
        elif (abs(c-t)-abs(a-x)-abs(b-y)) % 2 !=0:
            # print('$')
            flag = False 
        else:
            x , y , t = a , b , c
    if flag:
        print('Yes')
    else:
        print('No')


        

main()

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

int main() {
    int n; 
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    function<bool(int, int)> Dfs = [&](int x, int p) {
        int res = 0;
        for (int u : g[x]) {
            if (u == p) continue;
            if (!Dfs(u, x) && a[x] > a[u]) res = 1;
        }
        return res;
    };

    for (int i = 0; i < n; ++i) {
        if (Dfs(i, -1)) printf("%d ", i + 1);
    }
    puts("");
}


Measured memory_bytes: 768
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void solve(){
	int n;
	cin>>n;
	int s,t;
	cin>>s;
	t=__gcd(s,n);
	s*=n;
	s/=t;
	cout<<s;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;//cin>>t;
	t=1;
	while(t--)//
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k;
ll *arr;ll *dp;
ll solve(ll k)
{
	if(k==0)
	return 0;
	if(k<0)
	return 1;
	if(dp[k]!=-1)return dp[k];
	bool fg=false;
	for(int i=0;i<n;i++)
	{
		if(solve(k-arr[i])==0)
		{fg=true;break;}
	}
	if(fg)
	dp[k]=1;
	else
	dp[k]=0;
	return dp[k];
}
int main() {
	
	cin>>n>>k;
	arr=new ll[n];dp=new ll[k+1];
	for(int i=0;i<=k;i++)dp[i]=-1;
	for(int i=0;i<n;i++)
	cin>>arr[i];
	for(int i=0;i<=k;i++)
	{
		dp[i]=solve(i);
	}
	if(dp[k]==1)cout<<"First";
	else cout<<"Second";
}	

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>

using namespace std;

int main(){
  int n;
  int h[21];
  cin >> n;
  h[0]= 0;
  int ans = 0;
  int m = 0;
  for(int i = 1; i <= n; i++){
    cin >> h[i];
    if(m <= h[i]){
      m = h[i];
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;
struct color
{
    int x,y,no;
}s[100000];
int n,k,ans,sum;
int v[2000];
int main()
{
    char ch;
    scanf("%d%d",&n,&k);
    for(int i = 0;i < n;i ++)
    {
        scanf("%d %d %c",&s[i].x,&s[i].y,&ch);
        s[i].x %= k * 2;///通过移位（移动2k）都可以在这个2k*2k的图里进行操作 不改变原来的意义
        s[i].y %= k * 2;
        s[i].no = (ch == 'W' ? 1 : 0);///颜色转数字
    }
    for(int i = 0;i < k;i ++)///x坐标衡量
    {
        sum = 0;
        memset(v,0,sizeof(v));///初始化
        for(int j = 0;j < n;j ++)
        {
            int p = s[j].x >= i && s[j].x < i + k;///x坐标在i 到 i + k为一个区域
            int q = s[j].y >= 0 && s[j].y < k;///y坐标先不做限制 起点可以是0 ~ k - 1
            if(p ^ q ^ s[j].no)sum ++,v[s[j].y] ++;///先选定一种情况 满足的话 sum ++
            else v[s[j].y] --;///不满足的话
        }
        ans = max(ans,max(sum,n - sum));
        for(int j = 0;j < k;j ++)
        {
            sum -= v[j] + v[j + k];
            ans = max(ans,max(sum,n - sum));///更新最大值，sum 和 n - sum 是黑白互换的不同结果（原来黑色的地方可以变白色，那么白色的变黑色）
        }
    }
    printf("%d",ans);
}


Measured memory_bytes: 1408
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

ll a[100010],b[100010];
const ll MOD=1e9+7;
ll inv[100010],fac[100010],finv[100010];

void fact(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(ll i=2;i<100005;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]* i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(ll a,ll b){
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}


int main(void){
	          ll i;

	          ll n;
	          cin >> n;

	          for(i=1;i<=n+1;i++){
	        	  cin >> a[i];
	        	  b[a[i]]++;
	          }

	          ll t=-1;
	          for(i=1;i<=n;i++){
	         	   if(b[i]==2){
	         		   t=i; break;
	         	   }
	         }

	          vector<ll> v;
	          for(i=1;i<=n+1;i++){
	         	   if(a[i]==t){
	         		   v.push_back(i);
	         	   }
	         }

	          fact();

	          ll x=v[0]-1;
	          ll y=n+1-v[1];
	          for(i=1;i<=n+1;i++){
	        	  ll ans=C(n+1,i);
	        	  ans-=C(x+y,i-1);
	        	  if(ans<0) ans+=MOD;

	        	  cout << ans << endl;

	          }

	          return 0;
}


Measured memory_bytes: 5120
#include<iostream>
#include<vector>

using namespace std;

constexpr long long MOD = 1000000;

void dfs(int v, vector<long long>& dp1, vector<long long>& dp2, const vector< vector<long long> >& comb, const vector< vector<int> >& g){
    dp1[v] = 1;
    dp2[v] = 0;

    for(auto to : g[v]){
        dfs(to, dp1, dp2, comb, g);
        dp1[v] = dp1[v] * comb[dp2[v] + dp2[to] + 1][dp2[to] + 1] * dp1[to] % MOD;
        dp2[v] += dp2[to] + 1;
    }

    return;
}

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

    int n;
    cin >> n;

    vector< vector<int> > g(n);
    vector<int> iri(n, 0);
    for(int i = 0 ; i < n - 1 ; ++i){
        int a, b;
        cin >> a >> b;
        g[--a].emplace_back(--b);
        ++iri[b];
    }

    vector<long long> dp1(n, -1LL);
    vector<long long> dp2(n, 0LL);

    vector< vector<long long> > comb(n + 1, vector<long long>(n + 1, 0LL));
    comb[0][0] = 1;
    for(int i = 0 ; i < n ; ++i){
        for(int j = 0 ; j <= i ; ++j){
            (comb[i + 1][j] += comb[i][j]) %= MOD;
            (comb[i + 1][j + 1] += comb[i][j]) %= MOD;
        }
    }

    int root = -1;
    for(int i = 0 ; i < n ; ++i){
        if(iri[i] == 0){
            root = i;
            break;
        }
    }

    dfs(root, dp1, dp2, comb, g);

    cout << dp1[root] << endl;

    return 0;
}


Measured memory_bytes: 10808
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 1000
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 8 && b <= 8) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    LL A, B, C;
    cin >> A >> B >> C;
    LL K;
    cin >> K;
    if (K <= A + B)
    {
        std::cout << min(K, A) << endl;
    }
    else
    {
        std::cout << A - (K - (A + B)) << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//



     signed main(){
  int d;
  clock_t st=clock();
  cin>>d;
    clock_t ed=clock();

  int c[26];
  for(int i=0;i<26;i++)cin>>c[i];
  int t[d],s[d][26],x[26]={};
    vector<int>v[26];
    for(int i=0;i<26;i++)v[i].push_back(-1);

  for(int i=0;i<d;i++)for(int j=0;j<26;j++)cin>>s[i][j];
   // cerr<<'i';
  for(int i=0;i<d;i++){
      for(int j=0;j<26;j++)x[j]+=c[j];
      int k=0;
      for(int j=1;j<26;j++)if(x[k]+s[i][k]<x[j]+s[i][j])k=j;
      t[i]=k;
      x[k]=0;
      v[k].push_back(i);
  }
  for(int i=0;i<26;i++)v[i].push_back(d);
//for(int i=0;i<d;i++)cout<<t[i]+1<<endl;
  // cerr<<double(clock()-st)/CLOCKS_PER_SEC<<endl;
//while(false){
while(double(clock()-st)/CLOCKS_PER_SEC<1.95){
  if(rand()%2){
    int p=rand()%d;
    auto q=find(v[t[p]].begin(),v[t[p]].end(),p);
    q++;
  // int m=(p+(*q))/2;
   int m=p;
   int uu=0;
//cerr<<m<<' '<<p<<endl;
  for(int m2=p+1;m2<(*q);m2++){
   auto r1=find(v[t[m2]].begin(),v[t[m2]].end(),m2);
   auto r0=r1-1,r2=r1+1;
   if((m2-p)*((*q)-m2)*c[t[p]]+s[m2][t[p]]-((m2-(*r0))*((*r2)-m2)*c[t[m2]]+s[m2][t[m2]])>uu){
     m=m2;
     uu=(m2-p)*((*q)-m2)*c[t[p]]+s[m2][t[p]]-((m2-(*r0))*((*r2)-m2)*c[t[m2]]+s[m2][t[m2]]);
   
   }
   
  }
  if(m!=p){
      v[t[p]].insert(q,m);
    v[t[m]].erase(find(v[t[m]].begin(),v[t[m]].end(),m));
    t[m]=t[p];
   }
  }else{
    int u=1;
    if(rand()%2)u++;
    u%=26;
    int p=rand()%(d-u);
    if(t[p]==t[p+u]||p+u==d){continue;}
    auto q1=find(v[t[p]].begin(),v[t[p]].end(),p);
    auto q0=q1-1,q2=q1+1;
      auto r1=find(v[t[p+u]].begin(),v[t[p+u]].end(),p+u);
    auto r0=r1-1,r2=r1+1;
    if((p-(*q0))*((*q2)-p)*c[t[p]]+s[p][t[p]]+(p+u-(*r0))*((*r2)-p-u)*c[t[p+u]]+s[p+u][t[p+u]]-((p+u-(*q0))*((*q2)-p-u)*c[t[p]]+s[p+u][t[p]]+(p-(*r0))*((*r2)-p)*c[t[p+u]]+s[p][t[p+u]])<rand()%signed(3000*exp((-double(clock()-st)/CLOCKS_PER_SEC)))){
      (*q1)=p+u;
      (*r1)=p;
      swap(t[p],t[p+u]);
    }
   
  }




}
     for(int i=0;i<d;i++)cout<<t[i]+1<<endl;


     }


 


 






    





      

        


Measured memory_bytes: 4396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace q4
{
    class Program
    {
        static void Check(long p)
        {
            var n = p;
            while (n >= 10)
            {
                var a = n / 10 % 10;
                var b = n % 10;
                if (Math.Abs(a - b) > 1)
                    throw new Exception($"error {n}");

                n /= 10;
            }
        }
        static long LunlunNext(long n)
        {
            if (n <= 11)
            {
                return n + 1;
            }
            else 
            {
                var last1 = n % 10;
                var last2 = n / 10 % 10;
                var sub = last1 - last2;
                if (sub < 1 && (n <= 100 || last1 < 9))
                {
                    return n + 1;
                }
                else
                {
                    if (n > 100)
                    {
                        var leftNext = LunlunNext(n / 10);
                        var t = leftNext % 10;
                        if (t == 0)
                            return leftNext * 10;
                        else
                            return leftNext * 10 + (t - 1);
                    }
                    else
                    {
                        if (last2 == 9)
                            return (last2 + 1) * 10;
                        else
                            return (last2 + 1) * 10 + last2;
                    }
                }
            }
        }

        static void Main(string[] args)
        {
            var K = Convert.ToInt32(Console.ReadLine());

            long r = 0;
            for (var i=0; i<K; i++)
            {
                r = LunlunNext(r);
                //Console.WriteLine(r);
                Check(r);
            }
            Console.WriteLine(r);
        }
    }
}


Measured memory_bytes: 11220
import math

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
a = 0
for i in range(n):
    for k in range(i+1, n):
        tmp = 0
        for x1, x2 in zip(x[i], x[k]):
            tmp += (x1 - x2) ** 2
        a += is_integer_num(math.sqrt(tmp))

print(a)





Measured memory_bytes: 3064
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()

	m := make(map[string]bool)

	for i := 0; i < n; i++ {
		m[sc.ReadString()] = true
	}

	fmt.Println(len(m))
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 15276
#include<stdio.h>

int main()
{
    int n,k,x,y,i=0,j=1,sum=0,count=0;
    scanf("%d%d",&n,&k);
    if(k==2||k==3||k==4||k==5||k==6||k==7||k==8||k==9 ||k==10){
    while(n>0){
    x=n/k;
    y=n%k;
    sum=sum+(j*y);
    n=x;
    j=j*10;
    count=count+1;
    }}



    printf("%d",count);
}






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

int a[1234567];
unordered_map<int, bool> mp;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int p, ans = 0, sub = 0;
  string statue;
  for (int i = 0; i < m; i++) {
    cin >> p >> statue;
    if (statue == "WA" && !mp[p]) {
      a[p]++;
    }else {
      if (!mp[p]) {
        mp[p] = true;
        ans++;
        sub += a[p];
      }
    }
  }
  cout << ans << " " << sub;
  return 0;
}

Measured memory_bytes: 4388
N = int(input())
S = input()
r_array = []
g_array = []
r, g, b = 0, 0, 0
for i, s in enumerate(S):
    if s == "R":
        r += 1
        r_array.append(i)
    elif s == "G":
        g += 1
        g_array.append(i)
    else:
        b += 1

ans = r * g * b

for r in r_array:
    for g in g_array:
        c1 = 2 * r - g
        if c1 >= 0 and c1 < N and S[c1] == "B":
            ans -= 1
        c2 = r + g
        if (r + g) % 2 == 0 and S[(r + g) // 2] == "B":
            ans -= 1
        c3 = 2 * g - r
        if c3 < N and c3 >= 0 and S[c3] == "B":
            ans -= 1

print(ans)


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

#define printl(s) cout << s << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using vvi = vector<vector<int>>;
using piv = pair<ll,vector<ll>>;

const ll modSeed = pow(10,9) + 7;
const int INF = 1'000'000'000;

template <typename T>
vector<T> getVector(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
ll N,M,X,ans;

int main(){
  ans = -1;
  cin >> N>>M>>X;
  vector<piv> books(N);
  rep(i,N){
    ll C;
    cin >>C;
    books[i] = make_pair(C, getVector<ll>(M));
  }

  for(int i=0;i<(1<<N);i++){
    vector<ll> skill(M,0LL);
    ll price =0;
    for(int j=0;j<N;j++){
      if(i&(1<<j)){
        price+=books[j].first;
        for(int h=0;h<M;h++){
          skill[h]+=books[j].second[h];
        }
      }
      bool flg = true;
      for(int j=0;j<M;j++){
        if(skill[j]<X){
          flg = false;
          break;
        }
      }
      if(flg){
        if(ans==-1){
          ans = price;
        }else{
          ans = min(ans,price);
        }
      }
    }
  }

  printl(ans);
}


Measured memory_bytes: 3652
import java.util.*;

public class Main {

	// global
	static int mod = 1_000_000_007;
	static long fact[];
	static long inverse[];

	static long pow(long a,int n) {
	    long res=1;
	    while (n>0) {
	        if ((n-n/2*2)==1) {
	            res=res*a%mod;
	        }
	        a=a*a%mod;
	        n>>=1;
	    }
	    return res;
	}

	static long modinv(long n) {
	    return pow(n, mod-2);
	}

	static long comb(int n,int k){
	    if(n<0 || k<0 || n<k)return 0;
	    return fact[n]*(inverse[k]*inverse[n-k]%mod) %mod;
	}

	static long perm(int n, int k) {
	    if(n<0 || k<0 || n<k)return 0;
	    return fact[n]*inverse[n-k]%mod;
	}

	public static void main(String[] args) {// main method
		fact=new long[600000];
		fact[0]=1;
		inverse=new long[600000];
		inverse[0]=1;
		for(int i=1;i<600000;i++){
		    fact[i]=(fact[i-1]*(long)i)%mod;
		    inverse[i]=modinv(fact[i]);
		}
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long ans = 0L;
		for (int i=0;i<=N;i++) {
			ans = (ans + comb(N, i)*pow(-1, i)%mod*perm(M, i)%mod*perm(M-i, N-i)%mod*perm(M-i, N-i)%mod)%mod;
			ans = (ans+mod)%mod;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 45344
#include <stdio.h>
#include <math.h>

typedef struct {
  double x,y;
}Point;

void koch(int n,Point p1,Point p2){
  Point s,t,u;
  double theta;
  theta=M_PI*60.0/180.0;
  if(n==0) return;
  s.x=(2.0*p1.x+1.0*p2.x)/3.0;
  s.y=(2.0*p1.y+1.0*p2.y)/3.0;
  t.x=(1.0*p1.x+2.0*p2.x)/3.0;
  t.y=(1.0*p1.y+2.0*p2.y)/3.0;
  u.x=(t.x-s.x)*cos(theta)-(t.y-s.y)*sin(theta)+s.x;
  u.y=(t.x-s.x)*sin(theta)+(t.y-s.y)*cos(theta)+s.y;
  koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,p2);
}

int main(){
  Point p1,p2;
  int n;
  scanf("%d",&n);
  p1.x=0.0;
  p1.y=0.0;
  p2.x=100.0;
  p2.y=0.0;
  printf("%.8f %.8f\n",p1.x,p1.y);
  koch(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  vector<ll> A(3), B(3);
  REP(i, 3) cin >> A[i];
  REP(i, 3) cin >> B[i];

  vector<ll> dp(N+1, N);
  REP(w, N+1) {
    REP(i, 3) {
      if (w >= A[i]) {
        dp[w] = max(dp[w], dp[w-A[i]] + B[i] - A[i]);
      }
    }
  }

  int M = *max_element(ALL(dp));
  vector<ll> dp2(M+1, M);
  REP(w, M+1) {
    REP(i, 3) {
      if (w >= B[i]) {
        dp2[w] = max(dp2[w], dp2[w-B[i]] + A[i] - B[i]);
      }
    }
  }

  cout << *max_element(ALL(dp2)) << endl;

  return 0;
}


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

A, B, K = map(int, input().split(' '))

def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
    return divisors

da = make_divisors(A)
db = make_divisors(B)
common = da & db
common_list = list(common)
common_list.sort(reverse=True)
print(common_list[K-1])

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

template<typename T, T M>
struct modint {
T n;
constexpr modint(const T n = 0) : n((n % M + M) % M) {}
constexpr modint pow(T r) const {
modint ans(1), a(n);
while(r) { if (r & 1) ans *= a; a *= a; r >>= 1; }
return ans;
}
constexpr modint& operator+= (const modint r) {
n += r.n; if (n >= M) n -= M; return *this;
}
constexpr modint& operator-= (const modint r) {
n -= r.n; if (n < 0) n += M; return *this;
}
constexpr modint& operator*= (const modint r) {
n = n * r.n % M; return *this;
}
constexpr modint operator+ (const modint r) const { return modint(n) += r; }
constexpr modint operator- (const modint r) const { return modint(n) -= r; }
constexpr modint operator* (const modint r) const { return modint(n) *= r; }
/* Divisions only work for prime modules */
constexpr modint& operator/= (const modint r) { return (*this) *= r.pow(M-2); }
constexpr modint operator/ (const modint r) const { return modint(n) /= r; }
};

template<typename T>
struct modfact {
vector<T> fact, invfact;
constexpr modfact(int n): fact(n + 1), invfact(n + 1) {
fact[0] = T(1);
for(int i = 1; i <= n; i++)
fact[i] = fact[i - 1] * T(i);
invfact[n] = T(1) / fact[n];
for(int i = n - 1; i >= 0; --i)
invfact[i] = invfact[i + 1] * T(i + 1);
}
constexpr T p(int n, int k) const {
// permutations: n! / k!
if (k < 0 || k > n) return T(0);
return fact[n] * invfact[n - k];
}
constexpr T c(int n, int k) const {
// combinations(binomial coefficient): n! / (k! * (n - k)!)
if (k < 0 || k > n) return T(0);
return p(n, k) * invfact[k];
}
};

typedef modint<long, 1000000007L> mint;

int main() {
  int n, m;
  cin >> n >> m;
  modfact<mint> mf(m);
  mint first(mf.c(m, n) * mf.p(n, n)), second(first);
  for (int i = 1; i <= n; ++i)
    second += mf.c(n, i) * mf.c(m - i, n-i) * mf.p(n-i, n-i) * mint(i % 2 ? -1 : 1);
  cout << (first * second).n << endl;
  return 0;
}

Measured memory_bytes: 11028
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
using namespace std;
#define endl '\n';

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

    int n, max_w;
    cin >> n >> max_w;

    vector<int> vector0, vector1, vector2, vector3;
    int w1,v,w;
    cin >> w1 >> v;
    vector0.push_back(v);
    for(int i=0; i<n-1; i++){
        cin >> w >> v;
        switch(w-w1){
            case 0:
                vector0.push_back(v);
                break;
            case 1:
                vector1.push_back(v);
                break;

            case 2:
                vector2.push_back(v);
                break;

            case 3:
                vector3.push_back(v);
                break;
        }
    }

    //cout << vector0.size() << vector1.size() << vector2.size() << vector3.size() << endl;

    sort(vector0.begin(), vector0.end(), greater<int>());
    sort(vector1.begin(), vector1.end(), greater<int>());
    sort(vector2.begin(), vector2.end(), greater<int>());
    sort(vector3.begin(), vector3.end(), greater<int>());

    int max = 0, tmp;
    //cout << max_w << endl;
    long long int w_sum;

    for(int i=0; i<=vector0.size(); i++){
        for(int j=0; j<=vector1.size(); j++){
            for(int k=0; k<=vector2.size(); k++){
                for(int l=0; l<=vector3.size(); l++){
                    w_sum = (long long int)w1*i + (long long int)(w1+1)*j + (long long int)(w1+2)*k + (long long int)(w1+3)*l;
                    if(w_sum > (long long int)max_w){
                        continue;
                    }
                    
                    tmp = accumulate(vector0.begin(), vector0.begin()+i, 0) 
                        + accumulate(vector1.begin(), vector1.begin()+j, 0)
                        + accumulate(vector2.begin(), vector2.begin()+k, 0)
                        + accumulate(vector3.begin(), vector3.begin()+l, 0);
                    //cout << tmp << endl;
                    if(max < tmp){
                        max = tmp;
                    }

                }
            }
        }
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

void chmin(int* a,int b){
    if(*a>b){
        *a=b;
    }
}

const int MAX = 2147483647;
int main(void){
    int N,K;
    int h[100000];
    int dp[100000];
    
    scanf("%d%d",&N,&K);
    for(int i=0;i<N;i++){
        scanf("%d",&h[i]);
        dp[i]= MAX;
    }
    
    dp[0] = 0;
    for(int i=0;i<N;i++){
        for(int j=1;j<=K;j++){
            if(i+j >= N){
                break;
            }
            chmin(&dp[i+j],dp[i]+abs(h[i+j]-h[i]));
            //printf("i,j=<%d,%d>---dp[i+j]->dp[%d]=%d\n",i,j,i+j,dp[i+j]);
        }
    }
    
    printf("%d\n",dp[N-1]);
    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

typedef pair<char,char> P;
typedef pair<int,int> Pii;

const int MAX = 30;
vector<Pii> E;

P comp(string a, string b){
  for(int i = 0; i < (int)min(a.length(), b.length()); i++)
    if(a[i] != b[i]) return P(a[i], b[i]);

  if(a.length() > b.length()) return P(a[b.length()], '?');
  if(a.length() < b.length()) return P('?', b[a.length()]);
  return P('?','?');
}

bool add_edge(const vector<string>& v){
  E.clear();

  for(int i = 0; i+1 < (int)v.size(); i++){
    P p = comp(v[i], v[i+1]);
    if(p == P('?', '?')) continue;
    if(p.second == '?') return false;
    if(p.first != '?') E.push_back(P(p.first-'a', p.second-'a'));
  }
  return true;
}

bool hasCircle(int N){
  
  vector<int> d(MAX, 0);
  for(int i = 0; i <= N; i++){
    bool update = false;
    for(int j = 0; j < (int)E.size(); j++)
      if(d[E[j].second] < d[E[j].first] + 1){
	d[E[j].second] = d[E[j].first]+1;
	update = true;
      }
    if(i == N && update) return true;
    if(!update) break;
  }
  return false;
}

bool solve(const vector<string>& v){
  if(!add_edge(v)) return false;
  return !hasCircle(v.size());
}

int main(){
  
  int N;
  while(cin >> N && N){
    vector<string> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];
    cout << (solve(v)?"yes":"no") << endl;
  }
  return 0;
}

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

int main(void)
{
    int N, K;
    cin >> N >> K;

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

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 640
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b

main = do
 getLine
 inputs <- readLnInt
 print $ solve inputs

solve s
 | any (==0) s = 0
 | otherwise = calc 1 limit s

calc tmpProd remain [] = tmpProd
calc tmpProd remain (a:as)
 | (remain`div`a) < 1 = (-1)
 | otherwise = calc (tmpProd*a) (remain`div`a) as

limit = 10^18


Measured memory_bytes: 11052
"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    const tokens = input[0].split(' ').map(function(value) { return parseInt(value, 10); });
    const n = tokens[0];
    const k = tokens[1];

    const ans = n - k + 1;
    console.log(ans);

    return 0;
}


Measured memory_bytes: 22084
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int n;
int a[100005];

struct Students {
	int curr;
	int ahead;
} stu[1000005];

bool cmp(Students A, Students B) {
	return A.ahead < B.ahead; 
}

void init() {
	scanf("%d", &n);
	for(register int i = 1; i <= n; i++) {
		scanf("%d", &stu[i].ahead);
		stu[i].curr = i;
	}
	return ;
}

void solve() {
	sort(stu+1, stu+1+n, cmp);
	for(register int i = 1; i <= n; i++) {
		printf("%d ", stu[i].curr);
	}
	return ;
}

int main() {
	init();
	solve();
	return 0;
}

Measured memory_bytes: 1536