akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int c = saori.saori_hayami();
		int[] num = {a,b,c};
		Arrays.sort(num);
		if(num[0] + num[1] == num[2]){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define inf 0x3f3f3f3f
#define maxn 300005
using namespace std;
typedef long long ll;
int n,ans = inf,tmp;
char s[maxn];
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=2;i<=n;i++){
		if(s[i] == 'E') tmp++;
	}
	ans = min(ans,tmp);
	for(int i=2;i<=n;i++){
		tmp = tmp + (s[i-1] == 'W') - (s[i] == 'E');
		ans = min(ans,tmp);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define MAXN 100000
#define MAXA 1000000000
  
int main(int argc,char const* argv[])
{
  set<long long int> a;
  int n,i;
  long long int tempa;
  int ans;
  cin >> n;
  for(i=0;i<n;i++)
    {
      cin >> tempa;
      if(a.count(tempa) ==0) a.insert(tempa);
      else a.erase(tempa);
    }
  ans=a.size();
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll K,A,B; cin >> K >> A >> B;

    for (int i = A;i <= B;i++){
        if(i%K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;

}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	string L;
	cin >>L;
	reverse(L.begin(), L.end());
	long N=L.size();
	vector<long> NN(N+1, 0);
	NN.at(0)=1;
	for (long i=1; i<=N; i++) {
		NN.at(i)=NN.at(i-1)*3;
		NN.at(i) %=MOD;
	}
	vector<long> F(N+1, 0);
	int C=0;
	if ('0'==L.at(0))
		F.at(1)=1;
	else
		F.at(1)=3;
	for (long i=2; i<=N; i++) {
		if ('0'==L.at(i-1))
			F.at(i)=F.at(i-1);
		else
			F.at(i)=F.at(i-1)*2+NN.at(i-1);
		F.at(i) %=MOD;
	}
	cout <<F.at(N) <<endl;
	return 0;
}



Measured memory_bytes: 2048
n, m, k = map(int, input().split())

MOD = 998244353


def prepare(n, MOD):
    fac = [None] * (n + 2)
    finv = [None] * (n + 2)
    inv = [None] * (n + 2)
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, n + 1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
    return fac, finv


def combination(n, k, fac, finv, MOD):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    else:
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


fac, finv = prepare(n, MOD)

ans = 0
for i in range(k + 1):
    ans += combination(n - 1, i, fac, finv, MOD) * m * pow(m - 1, n - i - 1, MOD)
    ans %= MOD

print(ans)


Measured memory_bytes: 89964
import java.util.Scanner;

public class Main {

	public static int Compraison(int a, int b) {

		if (a < b)
			return a;
		else
			return b;
	}

	public static int TaskCalc(int a, int b, int c) {

		int sum = 0;

		sum += Math.abs(b - a);
		sum += Math.abs(c - b);

		return sum;
	}

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int cost;

		cost = TaskCalc(a, b, c);
		cost = Compraison(cost, TaskCalc(a, c, b));
		cost = Compraison(cost, TaskCalc(b, a, c));
		cost = Compraison(cost, TaskCalc(b, c, a));
		cost = Compraison(cost, TaskCalc(c, a, b));
		cost = Compraison(cost, TaskCalc(c, b, a));

		System.out.println(cost);

		sc.close();
	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
int main()
{
	ll n;
	cin>>n;
	vec a(n);
	floop(i,0,n)
	cin>>a[i];
	ll ans=1000;
	ll cur=1000;
	ll mi=a[0];
	floop(i,1,n)
	{
		if(a[i]>mi)
		{
			ans+=(a[i]-mi)*(cur/mi);
			cur=ans;
			mi=a[i];
		}
		else
		mi=min(a[i],mi);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3628
/**
 * @author azsy
 *
 */
import java.util.*;
public class Main {
	public static void main(String[] args) {
		int[] kth = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		Scanner sc = new Scanner(System.in);
		
		int k = sc.nextInt();
		
		System.out.println(kth[k-1]);

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main() {
	int a, b;
	cin >> a >> b;
	int tmp = a + b > a - b ? a + b : a - b;
	tmp = a * b > tmp ? a * b : tmp;
	cout << tmp;
}


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

typedef long long ll;

inline int read()
{
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            f=-f;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return f*x;
}

int a[1000005];

int main()
{
    int n;
    scanf("%d",&n);
    int z=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(i%2==1)
        {
            if(a[i]%2==1)
            {
                z++;
            }
        }
    }
    printf("%d\n",z);
    return 0;
}


Measured memory_bytes: 3812
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
vector<int>ans;
void c(int x) {
	string s = to_string(x);
	bool a = false, b = false, c = false;
	rep(i, s.size()) {
		if (s[i] == '3')a = true;
		if (s[i] == '5')b = true;
		if (s[i] == '7')c = true;
	}
	if (a&&b&&c) ans.push_back(x);
}
void d(int x) {
  c(x);
	if (x < 100000000) {
		
		d(10 * x + 3);
		d(10 * x + 5);
		d(10 * x + 7);
	}
}
int main() {
	int n;
	cin >> n;
	d(3);
	d(5);
	d(7);
	sort(ans.begin(), ans.end());
	cout << upper_bound(ans.begin(), ans.end(), n) - ans.begin() << endl;
	getchar();getchar();
	return 0;
}

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

int main()
{
  int n,w;
  cin>>n;
  cin>>w;
  if(n==0){
  cout<<"0"<<endl;
  return 0;
  }
  vector<unsigned long long> wt(n);
  vector<unsigned long long> val(n);
  int sumv=0;
  for(int i=0;i<n;i++){
    cin>>wt[i]>>val[i];
  }
  for(int x:val)
    sumv+=x;
  vector<unsigned long long> dp(sumv+1,1e18L);
  //min weight of value v
  dp[0]=0;
  //dp[1]=abs(v[1]-v[0]);
  for(int i=1;i<=n;i++)
  {
      for(int j=sumv;j>=val[i-1];j--)
      {
        //if(val[i-1]<=j)
        dp[j]=min({dp[j],dp[j-val[i-1]]+wt[i-1]});
      }
  }
  int ans=0;
  for(int i=0;i<=sumv;i++)
  {
      if(dp[i]<=w)
      ans=max(ans,i);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
    int t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) {
        cout << "infinity\n";
        return 0;
    }
    int ans = 0;
    int la = a1 * t1 + a2 * t2, lb = b1 * t1 + b2 * t2;
    if (a1 < b1) {
        if (la > lb) {
            int sum = (b1 - a1) * t1 / (la - lb);
            if ((la - lb) * sum < (b1 - a1) * t1) {
                ans += sum * 2 + 1;
            } else {
                ans += sum * 2;
            }
        } else {
            ans = 0;
        }
    } else {
        if (la < lb) {
            int sum = (a1 - b1) * t1 / (lb - la);
            if ((lb - la) * sum < (a1 - b1) * t1) {
                ans += sum * 2 + 1;
            } else {
                ans += 2 * sum;
            }
        } else {
            ans = 0;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3636
n,W = map(int,input().split())

dp = [[[0]*(3*n+1) for _ in range(n)] for _ in range(n)]

w1,v1 = map(int,input().split())
for i in range(3*n+1):
    dp[0][0][i] = v1

for i in range(1,n):
    w,v = map(int,input().split())
    w -= w1
    for j in range(min(i+1,n)):
        for k in range(3*n+1):
            if j>0 and k>=w:
                dp[i][j][k] = max(dp[i-1][j][k], dp[i-1][j-1][k-w] + v)
            elif k>=w:
                dp[i][0][k] = max(dp[i-1][0][k], v)
            else:
                dp[i][j][k] = dp[i-1][j][k]

ans = 0
for i in range(n):
    for j in range(3*n+1):
        if w1*(i+1) + j>W: continue
        ans = max(ans,dp[-1][i][j])

print(ans)

Measured memory_bytes: 53740
import numpy as np


k, q = map(int, input().split())
d = np.array(list(map(int, input().split()))).astype(np.int64)
queries = [tuple(map(int, input().split())) for _ in range(q)]

for n, x, m in queries:
    d_mod = d % m
    quotient, rem = divmod(n - 1, k)
    rem_d_mod = d_mod[:rem]
    print(n - 1 - (x % m + quotient * np.sum(d_mod) + np.sum(rem_d_mod)) // m
          - quotient * np.count_nonzero(d_mod == 0) - np.count_nonzero(rem_d_mod == 0))


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

using namespace std;

typedef long long ll;

ll comb(ll n){
  if(n>=2) return n*(n-1)/2;
  else return 0;
}

int main(){
  ll N;
  ll A[1111111];
  ll C[1111111] = {0};
  cin >> N;
  ll i;
  for(i=0;i<=N-1;i++)
    cin >> A[i];
  ll sum = 0;
  for(i=0;i<=N-1;i++)
    C[A[i]]++;
  for(i=1;i<=N;i++)
    sum += comb(C[i]);
  for(i=0;i<=N-1;i++)
    cout << sum - comb(C[A[i]]) + comb(C[A[i]]-1) << endl;
}

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

sum=0
s=[]
for i in range(N):
    temp=int(input())
    sum+=temp
    s.append(temp)

if sum%10==0:
    s.sort()
    for i in range(N):
        if s[i]%10!=0:
            sum-=s[i]
            print(sum)
            exit()
    print(0)
    exit()
else:
    print(sum)






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

int main()
{
    // 入力
    int K;
    string S;
    cin >> K >> S;

    int ans = 0;
    
    if(S.length() <= K){
        cout << S << endl;
    }else{
        cout << S.substr(0,K) + "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=105;
int n,m,b[N][N],zs[N],e[N][N],match[N];
bool vis[N];
vector<int> v[N][N];
bool dfs(int p){
	For(i,1,n)if(e[p][i]&&!vis[i]){
		vis[i]=1;
		if(!match[i]||dfs(match[i])){
			match[i]=p; return 1;
		}
	}
	return 0;
}
int main(){
	n=read(),m=read();
	For(i,1,n)For(j,1,m){int x=read(); v[i][(x+m-1)/m].pb(x);}
	For(i,1,n)For(j,1,n)e[i][j]=v[i][j].size(); 
	For(j,1,m){
		memset(match,0,sizeof(match));
		For(i,1,n){memset(vis,0,sizeof(vis)); dfs(i);}
		For(i,1,n){e[match[i]][i]--; b[match[i]][j]=v[match[i]][i].back(); v[match[i]][i].pop_back();}
	}
	For(i,1,n){For(j,1,m)wri(b[i][j]); puts("");}
	For(i,1,m){For(j,1,n)zs[(b[j][i]+m-1)/m]=b[j][i]; For(j,1,n)b[j][i]=zs[j];}
	For(i,1,n){For(j,1,m)wri(b[i][j]); puts("");}
}
/*
\sum mu(d)i/j<=mid
\sum mid*i
*/


Measured memory_bytes: 1024
A=list(map(str,input()))

if A[0]==A[1] and A[0]==A[2] and A[0]==A[3]:
    print("No")
elif A[0]==A[1] and A[2]==A[3]:
    print("Yes")
elif A[0]==A[2] and A[1]==A[3]:
    print("Yes")
elif A[0]==A[3] and A[1]==A[2]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
n, k = map(int, input().split())
s = input()
u = s + s[::-1]
t = min(u[i:i + n] for i in range(n + 1))
h = t[0]
i = min(i for i in range(n) if t[i] != h)
j = i << min(k - 1, n.bit_length())
print((h * j + t[i:i + n - j])[:n])


Measured memory_bytes: 9076
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll nCrModpDP(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C));   
    C[0] = 1;
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll nCrModp(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
  
   return (nCrModp(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p; 
} 
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,d,x;
	for(j=0;j<5;j++)
	{
		cin>>c;
		if(c==0)
			m=j+1;
	}
	cout<<m;
}



	

		

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int x, n;
	cin >> x >> n;
	VE<bool> banned(200, false);
	rep(i, n) {
		int a;
		cin >> a;
		banned[a] = true;
	}
	int ans;
	int diff = upper;
	rep(i, 102) {
		if (banned[i]) continue;
		if (diff > abs(x - i)) ans = i, diff = abs(x - i);
	}
	cout << ans << endl;
	return 0;
}

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


int main(){
int d;
cin >>d;
if (d==7||d==5||d==3) cout <<"YES" <<endl;
else cout << "NO" << endl;
}

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

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

    for(ll i = 0; i < S.size()/2; i++)
    {
        if(S[i] != S[S.size()/2-1-i])
        {
            cout << "No" << endl;
            return 0;
        }
    }

    for(ll i = S.size()/2+1; i < S.size(); i++)
    {
        if(S[i] != S[S.size()-1-i])
        {
            cout << "No" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int remain = x % 100;
		int num = x / 100;
		boolean isAble = remain <= num * 5;
		System.out.println(isAble ? 1 : 0);
	}

}

Measured memory_bytes: 23764
#include <iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;


int main()
{
   int s[4],a,b;
   while(~scanf("%d%d",&a,&b))
   {
        s[1]=a-b;
        s[2]=a+b;
        s[3]=a*b;
        sort(s+1,s+4);
       printf("%d\n",s[3]);
   }


    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
def calc(A):
    p = 0; q = N-2
    l = r = A[N-1]
    res = 0
    while p < q:
        a = A[p]; b = A[p+1]
        res += abs((l+r) - (a+b))
        p += 2
        l = a; r = b

        if not p < q:
            break

        a = A[q]; b = A[q-1]
        res += abs((l+r) - (a+b))
        l = a; r = b
        q -= 2

    if p == q:
        v = A[p]
        res += max(abs(l-v), abs(r-v))
    return res
s = calc(A)
A.reverse()
t = calc(A)

print(max(s, t))

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

using namespace std;

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

const int MOD = 1000000007;
//const int INF = 2000000000;
const int INF = (1 << 21);

int c[1000][1000];
int t[1000][1000];

int main() {
    while(true) {
        int n, m;
        cin >> n >> m;
        if(n == 0 && m == 0) break;

        rep(i, m) {
            rep(j, m) {
                c[i][j] = INF;
                t[i][j] = INF;
            }
            c[i][i] = 0;
            t[i][i] = 0;
        }
        rep(i, n) {
            int a, b, cost, time;
            cin >> a >> b >> cost >> time;
            c[a - 1][b - 1] = cost;
            c[b - 1][a - 1] = cost;
            t[a - 1][b - 1] = time;
            t[b - 1][a - 1] = time;
        }

        rep(k, m) {
            rep(i, m) {
                rep(j, m) {
                    /*if(c[i][k] != INF && c[k][j] != INF)*/ c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
                    /*if(t[i][k] != INF && t[k][j] != INF)*/ t[i][j] = min(t[i][j], t[i][k] + t[k][j]);
                }
            }
        }

        int k;
        cin >> k;
        rep(i, k) {
            int p, q, r;
            cin >> p >> q >> r;
            if(r == 0) cout << c[p - 1][q - 1] << endl;
            else cout << t[p - 1][q - 1] << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#define pb push_back
using namespace std;
int A,B,i,N,x,y,a,b,TT[100001],H[100001],cul[100001],k=0,viz[100001];
vector <int> G[100001];
void dfs(int nod)
{
    for(int i=0;i<G[nod].size();i++)
    {
        int v=G[nod][i];
        if(TT[v]==0)
        {
            TT[v]=nod;
            H[v]=H[nod]+1;
            dfs(v);
        }
    }
}
void dfs2(int nod)
{
    for(int i=0;i<G[nod].size();i++)
    {
        int v=G[nod][i];
        if(cul[v]!=2&&viz[v]==0)
        {
            viz[v]=1;
            cul[v]=1;
            dfs2(v);
        }
    }
}
int main()
{
    cin>>N;
    for(i=1;i<N;i++)
    {
        cin>>x>>y;
        G[x].pb(y);
        G[y].pb(x);
    }
    H[1]=0;
    cul[1]=1;
    cul[N]=2;
    TT[1]=-1;
    dfs(1);
    x=N;
    while(H[x]>H[N]/2)
    {
        cul[x]=2;
        x=TT[x];
    }
    cul[x]=1;
    viz[1]=1;
    dfs2(1);
    for(i=1;i<=N;i++)
        if(cul[i]==1) k++;
    if(k>N-k) cout<<"Fennec";
        else cout<<"Snuke";
    cout<<'\n';
    return 0;
}


Measured memory_bytes: 11904
import numpy as np
def comb(a, b):
    ans = 1
    for i in range(b):
        ans *= (a-i)
    for i in range(b):
        ans /= (i+1)
    return ans
N, A, B = map(int, raw_input().split())
v = sorted(map(np.int64, raw_input().split()))
value_num_mapping = {}
for _ in v:
    if not _ in value_num_mapping:
        value_num_mapping[_] = 0
    value_num_mapping[_] += 1

best = np.mean(v[-A:])
ans = 0
for T in range(A, B+1):
    if np.sum(v[-T:]) * A== np.sum(v[-A:]) * T:
        cnt = len([_ for _ in v[-T:] if _ == v[-T]])
        ans += comb(value_num_mapping[v[-T]], cnt)
print best
print ans

Measured memory_bytes: 10420
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;


//#[proconio::fastout]
fn main() {
    input! {
        r: usize,
        c: usize,
        k: usize,
        mut v0: [(usize,usize,u64);k],
    }

    let mut v = vec![vec![0u64;c+1];r+1];
    for (rr,cc,vv) in v0 {
        v[rr][cc] = vv;
    }
    //
    let mut dp = vec![0u64;c+1];
    let mut dp0 = vec![0u64;c+1];
    let mut dp1 = vec![0u64;c+1];
    let mut dp2 = vec![0u64;c+1];
    let mut dp3 = vec![0u64;c+1];
    for i in 1..=r {
        for j in 1..=c {
            if v[i][j] != 0 {
                dp0[j] = max(dp0[j-1],dp[j]);
                dp1[j] = max(dp1[j-1],max(dp0[j-1],dp[j])+v[i][j]);
                dp2[j] = max(dp2[j-1],dp1[j-1]+v[i][j]);
                dp3[j] = max(dp3[j-1],dp2[j-1]+v[i][j]);
            } else {
                dp0[j] = max(dp0[j-1],dp[j]);
                dp1[j] = dp1[j-1];
                dp2[j] = dp2[j-1];
                dp3[j] = dp3[j-1];
            }
        }

        for j in 1..=c {
            dp[j] = max(max(dp0[j],dp1[j]),max(dp2[j],dp3[j]));
        }
    }

    println!("{}", dp[c]);
}


Measured memory_bytes: 80620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char ch;
 
 
        try {
 
            String inputed = br.readLine();
 
            for(int i = 0; i < inputed.length(); i++){
                ch = inputed.charAt(i);
 
                if(ch >= 'a' && ch <= 'z'){
                    System.out.print((char)(ch-32));
                }else if(ch >= 'A' && ch <= 'Z'){
                    System.out.print((char)(ch+32));
                }else{
                    System.out.print((char)ch);
                }
            }
            System.out.printf("\n");
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 25068
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

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

	int max, x;
	max = 0;
	x = 0;
	for (int i = 0; i < N; i++) {
		char ch = S.at(i);
		if (ch == 'I') {
			x++;
		}
		else if (ch == 'D') {
			x--;
		}

		if (x > max) max = x;
	}

	cout << max << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define INFTY 10000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

typedef struct{
  int data[100];
  int head;
  int tail;
}queue;

queue Q;

int n;
int G[100][100];
int d[100] = {INFTY};
int color[100] = {WHITE};

void BFS(int);
void enqueue(int);
int dequeue();

int main(){
  int i, j;
  int u, k, v;

  scanf("%d",&n);
for(i=0;i<n;i++)
  for(i = 0 ; i < n ; i++){
    scanf("%d %d",&u,&k);
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      G[u-1][v-1] = 1;
    }
  }

  for(i = 0 ; i < n ; i++) d[i] = INFTY;

  BFS(0);

  for(i = 0 ; i < n ; i++){
    if(d[i] == INFTY) printf("%d %d\n",i+1,-1);
      else printf("%d %d\n",i+1,d[i]);
  }

  return 0;
}

void BFS(int s){
  int v, u;

  d[s] = 0;
  color[s] = GRAY;
  Q.head = Q.tail = 0;

  enqueue(s);

  while(Q.tail < n){
    u = dequeue();
    if(u == INFTY) break;
    for(v = 0 ; v < n ; v++){
      if(G[u][v] == 0) continue;
      if(color[v] == WHITE){
 d[v] = d[u] + 1;
 color[v] = GRAY;
 enqueue(v);
      }
    }color[u] = BLACK;
  }
}

void enqueue(int s){

  if(Q.tail >= n) return;

  Q.data[Q.tail] = s;
  Q.tail++;
}

int dequeue(){
  int s;

  if(Q.head == Q.tail) return INFTY;

  s = Q.data[Q.head];
  Q.head++;

  return s;
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
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;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;

int D; 
int c[30];
int s[400][30];
int t[400];


ll cal_score(int temp[]){
    int last[30] = {0};
    ll score = 0;
    for(int d=1;d<=D;++d){
        int i = temp[d];
        score += s[d][i];
        last[i] = d;
        for(int j=1;j<=26;++j){
            score -= c[j]*(d-last[j]);
        }
        //cout << score << "\n";
    }
    return score;
}

int main(){
    cin >> D;
    for(int i=1;i<=26;++i){ cin >> c[i]; }
    for(int d=1;d<=D;++d){ for(int i=1;i<=26;++i){ cin >> s[d][i]; } }
    
    int score_max = 0;
    
	random_device rand_d;
    default_random_engine e1(rand_d());
    uniform_int_distribution<int> uniform_dist(1, 26);   
    
    REP(count,20000){
        int temp[400];
        int last[30] = {0};
        for(int d=1;d<=D;++d){
            temp[d] = uniform_dist(e1);
            while(d - last[ temp[d] ] < min(7,d)){
                temp[d] = uniform_dist(e1);
            }                
            for(int i=1;i<=26;++i){
                if((double)s[d][i]>(double)s[d][temp[d]]*1.3){
                    temp[d] = i;
                }
            }
            last[ temp[d] ] = d;
        }
        if(cal_score(temp)>score_max){
            for(int d=1;d<=D;++d){
                t[d] = temp[d];
            }
        }
    }
    for(int d=1;d<=D;++d){
        cout << max(t[d]%27,1) << "\n";
    }
    if(DEBUG){
        cout << cal_score(t) << "\n";
    }
}


Measured memory_bytes: 3680
#include <stdio.h>
int main(void){
	int h,n,i,a[100000],sum=0;
	scanf("%d %d",&h,&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	
	if(sum>=h){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;

void swapp(int a[],int i,int j);
bool sorted(int a[],int s);

int main()
{
    int n;
    bool x = false;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    if(sorted(arr,n))
    {
        cout<<"YES";
    }
    else
    {
        for(int i=0; i<n-1; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if(arr[j]<arr[i])
                {
                    swapp(arr,i,j);
                    if(sorted(arr,n))
                    {
                        x = true;
                        break;
                    }
                    swapp(arr,j,i);
                }
            }
        }
        if(x)
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
    }
}

void swapp(int a[],int i,int j)
{
    int temp = a[j];
    a[j] = a[i];
    a[i] = temp;
}

bool sorted(int a[],int s)
{
    bool x = true;
    for(int i=1; i<s; i++)
    {
        if(a[i]<a[i-1])
        {
            x = false;
            break;
        }
    }
    return x;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for (int i = 0; i < N; i++) {
        cin >> l.at(i);
    }
    sort(l.begin(), l.end(), greater<int>());
    cout << accumulate(l.begin(), l.begin() + K, 0) << endl;
}


Measured memory_bytes: 256
from sys import stdin

count = int(stdin.readline())
ns = [int(n) for n in stdin.readline().split(' ')]
minimum = None
maximum = None
total = 0

for n in ns:
    if minimum == None or minimum > n:
        minimum = n
    if maximum == None or maximum < n:
        maximum = n

    total += n

print(minimum, maximum, total)

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

using namespace std;



int main(){
	vector<int> x;
	int n,p,ac=-1,sum;

	cin >>n;
	for (int i = 0; i < n; i++) {
		cin >> p;
		x.push_back(p);
	}
	sort(x.begin(),x.end());

	for (int i = x.front(); i <= x.back(); i++) {
		sum=0;
		for (auto xx : x){
			sum += (i - xx)*(i - xx);
		}
		if (ac==-1 || ac>sum) ac=sum;
	}

	cout << ac << endl;
	cin >> n;
	return 0;

	
}



Measured memory_bytes: 256
s = input()
n = len(s)
ans = 0
now = 0
mp = [0 for i in range(2019)]
mp[0] += 1
tmp = [0 for i in range(2019)]

id = [0 for i in range(2019)]
for i in range(2019):
    id[i] = i * 10 % 2019

for c in s:
    now *= 10;
    now += ord(c) - ord("0")
    now %= 2019

    ans += mp[now]
    mp[now] += 1
    for i in range(2019):
        tmp[id[i]] = mp[i]
    for i in range(2019):
        mp[i] = tmp[i]

print(ans)


Measured memory_bytes: 68720
using System;

namespace QQ
{
    class Program
    {
        static void Main(string[] args)
        {
            for (var i = 1; i < 10; i ++)
                for (var j = 1; j < 10; j++)
                    Console.WriteLine("{0}x{1}={2}", i, j, i * j);
        }
    }
}

Measured memory_bytes: 9004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//nCr mod p
ll modinv(ll n, ll p) {
  ll a = p, u = 1, v = 0;
  while (a) {
    ll t = n / a;
    n -= t * a;
    swap(n, a);
    u -= t * v;
    swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

ll ncr(ll n, ll r, ll p) {
  r = min(r, n - r);
  ll ans = 1;
  for (ll i = 0; i < r; i++) {
    ans *= (n - i) % p;
    ans %= p;
  }
  for (ll i = 0; i < r; i++) {
    ans *= modinv(i + 1, p);
    ans %= p;
  }
  return ans;
}

int main() {
  ll x, y, p = 1000000007;
  cin >> x >> y;
  if ((x + y) % 3 > 0) cout << 0 << endl;
  else if (x < (x + y) / 3 || y < (x + y) / 3) cout << 0 << endl;
  else {
    ll n = (x + y) / 3, r = x - n;
    cout << ncr(n, r, p) << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[1010];
ll b[1010];
int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,m)scanf("%lld",b+i);
	sortdown(a,n);
	sortdown(b,m);
	int i=0,j=0;
	ll ans=1;
	for(int s=n*m;s>0;s--){
		if(a[i]==s&&b[j]==s){
			i++;
			j++;			
		}else if(a[i]==s){
			ans=ans*j%MOD;
			i++;
		}else if(b[j]==s){
			ans=ans*i%MOD;
			j++;
		}else{
			if(i*j-(n*m-s)<=0){
				printf("0\n");
				return 0;	
			}
			ans=ans*(i*j-(n*m-s))%MOD;
		}
//	printf("%lld\n",ans);
	}
	printf("%lld\n",i==n&&j==m?ans:0);
	return 0;
}

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

const int N=105;
int n,a[N];

int main()
{
	n=5;int i,delt=0,ret=0;
	for(i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		int now=a[i]/10*10;
		if(now<a[i]) now+=10;
		ret+=now,delt=max(delt,now-a[i]);
	}
	printf("%d\n",ret-delt);
	return 0;
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

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

bool isPrime(int a) {
  if(a == 2) return true;
  if(a < 2 || !(a % 2)) return false;

  double sq = sqrt(a);
  for(int i = 3; i <= sq; i += 2) {
    if(a % i == 0) return false;
  }
  return true;
}

int main() {
  int w, h, m;
  cin >> w >> h >> m;
  int a = gcd(min(w, h), max(w, h));
  cout << ((w * h) / (a * a)) * m << endl;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
 
using namespace std;
 
#define LL long long 
#define ULL unsigned long long 
#define LD long double 
 
const int INF = 1e9 + 4;
 
int main() {
	//ios_base::sync_with_stdio(0);
	//cin.tie(0);
	//cout.tie(0);
	string s;
	cin>>s;
	int n = s.size();
	int w[n];
	for(int i=0; i<n; i++)
		w[i] = 0;
	int i = 0;
	while(i<n) {
		int pozr = 0;
		int pozl = INF;
		bool flaga = 0;
		int iler = 0;
		int ilel = 0;
		while(i<n) {
			if(s[i]=='R' && flaga)
				break;
			if(s[i]=='R') {
				pozr = i;
				iler++;
			}
			else if(s[i]=='L') {
				pozl = min(pozl, i);
				flaga = 1;
				ilel++;
			}
			i++;
		}
		int suma = iler+ilel;
		if(suma%2==0) {
			w[pozr]+=suma/2;
			w[pozl]+=suma/2;
		}
		else {
			w[pozr]+=suma/2;
			w[pozl]+=suma/2;
			w[pozr]+=(iler%2);
			w[pozl]+=(ilel%2);
			
		}
	}
	for(int i=0; i<n; i++)
		cout<<w[i]<<" ";
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

vector<int> tpsort(vector<vector<int>>& G) {
    int V = G.size();
    vector<int> sorted_vertices;
    queue<int> que;
    vector<int> indegree(V);
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < G[i].size(); j++) {
            indegree[G[i][j]]++;
        }
    }
    for (int i = 0; i < V; i++) {
        if (indegree[i] == 0) {
            que.push(i);
        }
    }
    while (que.empty() == false) {
        int v = que.front();
        que.pop();
        for (int i = 0; i < G[v].size(); i++) {
            int u = G[v][i];
            indegree[u] -= 1;
            if (indegree[u] == 0) que.push(u);
        }
        sorted_vertices.push_back(v);
    }
    return sorted_vertices;
}

int main() {
    ll h, w;
    cin >> h >> w;
    vector<string> z(h);
    vector<vector<ll>> dp(h,vector<ll>(w));
    for (int i = 0; i < h; i++) {
        cin >> z[i];
    }
    dp[0][0] = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (z[i][j] == '#')continue;
            if (i != 0)dp[i][j] += dp[i - 1][j];
            if (j != 0)dp[i][j] += dp[i][j - 1];
            dp[i][j] %= 1000000007;
        }
    }
    cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 13312
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
char s[200200];
ll ans[200200];
int qp(ll a,ll b,ll md){
	ll ret=1;
	a=a%md;
	while(b){
		if(b&1) ret=ret*a%md;
		a=a*a%md;
		b>>=1;
	}
	return ret;
}
ll c(ll x){
	ll ret=0;
	while(x){
		if(x&1) ret++;
		x>>=1;
	}
	return ret;
}
ll calc(ll x){
	ll ret=0;
	while(x){
		ret++;
		x%=c(x);
	}
	return ret;
}
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	int c1=0,c0=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='0') c0++;
		else c1++;
	}
	ll md=c1+1,ba=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='1') ba=(qp(2,n-i,md)+ba)%md;
	}
	for(int i=1;i<=n;i++){
		if(s[i]=='0'){
			ans[i]=(ba+qp(2,n-i,md))%md;
			ans[i]=calc(ans[i])+1;
		}
	}
	ba=0;md=c1-1;
	if(md<=0){
		for(int i=1;i<=n;i++){
			if(s[i]=='1') ans[i]=0;
		}
	}
	else{
		for(int i=1;i<=n;i++){
			if(s[i]=='1') ba=(qp(2,n-i,md)+ba)%md;
		}
		for(int i=1;i<=n;i++){
			if(s[i]=='1'){
				ans[i]=(ba-qp(2,n-i,md)+md)%md;
				ans[i]=calc(ans[i])+1;
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 5480
#include<iostream>
#include<climits>
using namespace std;
int main(){
	int s[10],d[]={4,1,4,1,2,1,2,1,4,1,4,1,2,1,2};
	int best,min,sum,pre,rea,now;
	while(cin>>s[0]>>s[1]>>s[2]>>s[3]>>s[4]>>s[5]>>s[6]>>s[7]){
		min=INT_MAX;
		for(int i=0;i<8;i++){
			sum=0;
			for(int j=0;j<8;j++){
				if(s[j]-d[i+j]<0)
					;
				else{
					sum+=(s[j]-d[i+j]);
				}

			}

			if(min>=sum){
				if(min==sum){
					now=1;
					pre=0;
					rea=0;
					for(int h=7;h>=0;h--){
						pre+=d[best+h]*now;
						rea+=d[i+h]*now;
						now*=10;
					}
					if(pre>rea)
						best=i;
				}
				else{
				min=sum;
				best=i;
				}
			}
		}
		for(int i=best;i<best+7;i++)
		cout<<d[i]<<' ';
		cout<<d[best+7]<<endl;

	}
	return 0;
}

Measured memory_bytes: 0
while True:
	a,b,c = input().split()
	num_1 = int(a)
	num_2 = int(c)

	if b == '?':
		break
	elif b == '+':
		print(num_1 + num_2)
	elif b == '-':
		print(num_1 - num_2)
	elif b == '*':
		print(num_1 * num_2)
	else:
		print(num_1 // num_2)

Measured memory_bytes: 7612
#!python3
from math import factorial

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, K = iim()
    mod = 10**9 + 7
    if N < K:
        print(0)
        return
    elif N == K:
        print(factorial(N) % mod)
        return

    ans = 0
    cm = 1
    for i in range(K):
        ans += ((-1)**i) * cm * pow(K - i, N, mod)
        ans %= mod
        cm = cm * (K - i) // (i + 1)

    print(ans)

if __name__ == "__main__":
    resolve()



Measured memory_bytes: 5664
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >>n;
    int a[110];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    bool f=1;
    for(int i=1;i<=n;i++){
        if(a[i]%2==0){
            if(a[i]%3!=0&&a[i]%5!=0){
                f=0;
                break;
            }
        }
    }
    if(f==1){
        cout<<"APPROVED";
    }
    else
    {
        cout<<"DENIED";
    }
    
}

Measured memory_bytes: 256