akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int l[N], r[N];
vector<pair<int, int> > ll, rr;
long long ans, rtr, rn;
int mark[N];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> l[i] >> r[i], ll.push_back({-l[i], i}), rr.push_back({r[i], i});
	sort(ll.begin(), ll.end());
	sort(rr.begin(), rr.end());
	if (-ll[0].first > 0) {
		int plcl = 0, plcr = 0;
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				while (plcl < n && mark[ll[plcl].second])
					plcl++;
				if (plcl == n)
					break;
				pair<int, int> p = ll[plcl];
				p.first = -p.first;
				if (p.first <= rn)
					break;
				else {
					rtr += p.first - rn;
					rn = p.first;
					mark[p.second] = 1;
				}
			}
			else {
				while (plcr < n && mark[rr[plcr].second])
					plcr++;
				if (plcr == n)
					break;
				pair<int, int> p = rr[plcr];
				if (p.first >= rn)
					break;
				else {
					rtr += rn - p.first;
					rn = p.first;
					mark[p.second] = 1;
				}
			}
		}
		rtr += abs(rn);
	}
	ans = rtr;
	memset(mark, 0, sizeof(mark));
	rtr = rn = 0;
	if (rr[0].first < 0) {	
		int plcl = 0, plcr = 0;
		for (int i = 0; i < n; i++) {
			if (i % 2 == 1) {
				while (plcl < n && mark[ll[plcl].second])
					plcl++;
				if (plcl == n)
					break;
				pair<int, int> p = ll[plcl];
				p.first = -p.first;
				if (p.first <= rn)
					break;
				else {
					rtr += p.first - rn;
					rn = p.first;
					mark[p.second] = 1;
				}
			}
			else {
				while (plcr < n && mark[rr[plcr].second])
					plcr++;
				if (plcr == n)
					break;
				pair<int, int> p = rr[plcr];
				if (p.first >= rn)
					break;
				else {
					rtr += rn - p.first;
					rn = p.first;
					mark[p.second] = 1;
				}
			}
		}
		rtr += abs(rn);
	}
	cout << max(ans, rtr);
	return 0;
}


Measured memory_bytes: 3308
n=int(input())
arr=list(map(int,input().split()))
num=1
for i in range(n):
	num*=arr[i]

den=0
for i in range(n):
	temp=1
	for j in range(n):
		if(j!=i):
			temp*=arr[j]
	den+=temp
print(num/den)


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

// Shortcut

#define int long long
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
#define PrintVl(a) for (int i = 0; i < a.size(); i++) cout << a[i] << endl;
#define PrintA(a, n) for (int i = 0; i < n; i++) cout << a[i] << ' ';
#define PrintAl(a, n) for (int i = 0; i < n; i++) cout << a[i] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

#define bend(a) a.begin(), a.end()
#define mset(a) memset(a, 0, sizeof(a));
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5, mod = 1e9 + 7, inf = 1e9 + 7;


signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    cout << (c / a) * b;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

int N;
vector<vector<int>> m(11, vector<int>(11, 0));

inline int getMSD(int n) {
    int ans;
    while (n) {
        ans = n % 10;
        n /= 10;
    }
    return ans;
}

int main() {
    cin>>N;
    int ans = 0;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            for (int k = 1; k <= N; ++k) {
                int lsd = k % 10; int msd = getMSD(k);
                if (msd == j && lsd == i) m[i][j]++;
            }
        }
    }
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            ans += m[i][j] * m[j][i];
        }
    }


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>
#include <ctype.h>

#define PI 3.1415926

void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
int factorial(int n);

int main() {
	int a,b,c,d,p;
	int x = 0, y = 0;
	scanf("%d %d %d %d %d", &a, &b, &c, &d, &p);
	x = p*a;
	if (p <= c) {
		y = b;
	}
	else {
		y = b;
		y += (p - c)*d;
	}
	
	if (x <= y) {
		y = x;
	}
	printf("%d\n", y);
	return 0;
}

 int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}

Measured memory_bytes: 2704
#include <iostream> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
using namespace std; 
const int Mod = 1e9 + 7; 
int N, M, X, Y, Z, f[41][1 << 18]; 
int OK, ALL; 
void pls(int &x, int y) { x += y; if (x >= Mod) x -= Mod; } 
int main () { 
	cin >> N >> X >> Y >> Z; 
	M = X + Y + Z; 
	OK = (1 << (X + Y + Z - 1)) | (1 << (Y + Z - 1)) | (1 << (Z - 1)); 
	ALL = (1 << M) - 1; 
	f[0][0] = 1; 
	for (int i = 1; i <= N; i++) { 
		for (int s = 0; s < 1 << M; s++) { 
			for (int j = 1; j < 11; j++) { 
				int t = ((s << j) | (1 << (j - 1))) & ALL; 
				if ((t & OK) == OK) continue; 
				pls(f[i][t], f[i - 1][s]); 
			} 
		} 
	} 
	int ans = 1; 
	for (int i = 1; i <= N; i++) ans = 10ll * ans % Mod; 
	for (int i = 0; i < 1 << M; i++) ans = (ans - f[N][i] + Mod) % Mod; 
	printf("%d\n", ans); 
    return 0; 
} 

Measured memory_bytes: 40192
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>
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,x); REP(i,sizeof(a)){ (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 );}
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;}

int main(){
  string s; cin>>s;
  int N; cin>>N;
  REP(count,N){
    string op,p;
    int a,b;
    cin >> op >> a >> b;
    if(op=="print"){
        cout << s.substr(a,b-a+1) <<"\n";
    }else if(op=="reverse"){
        p = s.substr(a,b-a+1);
        REP(i,p.size()){
            s[b-i] = p[i];
        }
    }else{
        cin >> p;
        REP(i,p.size()){
            s[a+i] = p[i];
        }
    }
  }
}


Measured memory_bytes: 3164
H, W, A, B = map(int, input().split())
P = 10 ** 9 + 7
N = H + W

# nCr mod P (P は素数) を 1 <= r <= n <= N の範囲で求めるための前処理の関数
# fact は n! mod P (n=0,...,N) のリストを返す
# inv_fact は n!^(-1) mod P (n=0,...,N) のリストを返す
def fact(N, P):
    ret = [1] * (N + 1)
    for n in range(2, N+1):
        ret[n] = (ret[n-1] * n) % P

    return ret


# 二分累乗法による a ** b mod P の計算
def pow_r(a, b, P):
    """
    O(log n)
    """
    if b == 0:  # exit case
        return 1
    if b % 2 == 0:  # standard case ① n is even
        return pow_r((a ** 2) % P, b // 2, P)
    else:  # standard case ② n is odd
        return (a * pow_r((a ** 2) % P, (b - 1) // 2, P)) % P


def inv_fact(N, P):
    ret = [1] * (N + 1)
    fac = fact(N, P)
    ret[N] = pow_r(fac[N], P - 2, P)
    for n in reversed(range(2, N)):
        ret[n] = (ret[n + 1] * (n + 1)) % P

    return ret


fac = fact(N, P)
inv = inv_fact(N, P)
# nCr mod P (P は素数) を 1 <= r <= n <= N の範囲で求める関数
def combination(n, r, P):
    return (fac[n] * inv[r] * inv[n - r]) % P



sub = 0
for a in range(A):
    sub = (sub + combination((H - 1 - a) + (B - 1), B - 1, P) * combination(a + (W - 1 - B), a, P)) % P

print((combination((H - 1) + (W - 1), H - 1, P) - sub) % P)

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

int main(){
  ll N,a=0,b=0;
  cin>>N;
  ll A[N];
  for(int i=0;i<N;i++) cin>>A[i];
  sort(A,A+N);
  reverse(A,A+N);
  for(int i=0;i<N;i++){
    if(A[i]==A[i+1]){
      if(a==0) a=A[i];
      else if(a!=0){
        b=A[i];
        break;
      }
      i++;
    }
  }
  cout<<a*b<<endl;
}



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

//数列v内に数nが存在するかどうか調べる
bool srt_knsk(vector<int> v,int n){
  for(int i=0; i<v.size(); i++){
    if(v.at(i) == n){
      return true;
    }
  }
  return false;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(446);
  for(int i=0; i<446; i++){
    a[i] = (i+1)*(i+2)/2;
  }
  if(srt_knsk(a,n)){
    cout << "Yes" << endl;
    int k = (1+sqrt(1+8*n))/2;
    cout << k << endl;
    int a[k][k-1];
    int cnt = 1;
    for(int i=0; i<k-1; i++){
      for(int j=i; j<k-1; j++){
        a[i][j] = cnt;
        a[j+1][i] = cnt;
        cnt++;
      }
    }
    for(int i=0; i<k; i++){
      cout << k-1 << " ";
      for(int j=0; j<k-1; j++){
        cout << a[i][j] << " ";
      }
      cout << endl;
    }
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
//https://atcoder.jp/contests/abc106/submissions/3027852

int n,m,q,l[200009],r[200009], x[509][509], c[509][509];

int main(){
    scanf("%d %d %d",&n,&m,&q);
    for (int i=1;i<=m;i++) {
        scanf("%d %d",&l[i],&r[i]);
        x[l[i]][r[i]]++;
    }
    for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) c[i][j]=c[i][j-1]+x[i][j];
    for (int i=1;i<=q;i++) {
        int a,b,sum=0;
        scanf("%d %d",&a,&b);
        for (int j=a;j<=b;j++) sum+=c[j][b]-c[j][a-1];
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int N; cin >> N;
  vector<int> A(N); vector<int> B(N); vector<int> C(N);
  int res = 0;
  for(int i = 0; i < N; i++){ cin >> A[i];}
  for(int j = 0; j < N; j++){ cin >> B[j];}
  for(int k = 0; k < N; k++){ cin >> C[k];}
  
  for(int i = 0; i < N; i++){
    if( i && A[i] == A[i-1]+1){ res += C[A[i-1]-1];}
    res += B[A[i]-1];
  }
  
  cout << res << endl; return 0;}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;cin>>n>>k;
    vector<ll> v(n);for(int i=0;i<n;i++)cin>>v[i];
    vector<ll> dp(n,1e9+5);dp[0]=0;
    for(int i=1;i<n;i++){
        int minn=1e9+5;
        for(int j=1;j<=k;j++){
            if(i-j<0)break;
            if(dp[i-j]+abs(v[i]-v[i-j])<minn)minn=dp[i-j]+abs(v[i]-v[i-j]);
        }
        if(dp[i]>minn)dp[i]=minn;
    }
    cout<<dp[n-1];
}


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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V)                                                           \
    for (auto v : (V))                                                         \
        cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) { cin >> A[i]; }
    int sNum = 1;
    int res = 0;
    for (auto a : A) {
        if (a != sNum) {
            a = 0;
            res++;
        } else {
            sNum++;
        }
    }
    if (sNum == 1) {
        cout << -1;
    } else {
        cout << res;
    }

    return 0;
}

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

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

int main() {
  
  long double A, B, C, D;
  cin >> A >> B >> C >> D;
  
  long double C_count=0, D_count=0, CD_count=0;
  long double lcm = C*D/gcd(C,D);
  long double C_mult = C, D_mult = D, CD_mult = lcm;
  
  C_count = floor(B/C)-ceil(A/C)+1;
  D_count = floor(B/D)-ceil(A/D)+1;
  CD_count = floor(B/lcm)-ceil(A/lcm)+1;
  
  if(C_count<0){C_count = 0;}
  if(D_count<0){D_count = 0;}
  if(CD_count<0){CD_count = 0;}
  
  long long res = 0;
  res = B-A+1 - C_count - D_count + CD_count;
  
  //cout << floor(B/lcm) << " " << ceil(A/lcm) << endl;
  //cout << C_count << " " << D_count << " " << CD_count << endl;
  cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    int n=in.nextInt();
    if(n%1000==0)
    {
      System.out.println("0");
    }
    else
    {
      int a=(n/1000)+1;
      System.out.println((a*1000)-n);
    }
  }
}

Measured memory_bytes: 35868
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


typedef  long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;


#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=2e5+5;
int mod=1e9+7;

ll mul (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll add (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a+b+mod)%mod;
}
ll fastpow(ll b, ll p)
{
    if(p==0)
        return 1;
    ll ans=fastpow(b,p/2);
    ans=mul(ans,ans);
    if(p%2)ans=mul(ans,b);
    return ans;
}
int arr[N];

int main()
{
    FIO
    set<pair<int,int>>st;
    int n;
    cin>>n;
    int co=0;
    set<pair<int,int>> ::iterator it;
for(int i=0;i<n;i++)
{
    cin>>arr[i];
}
for(int i=n-1;i>=0;i--)
{
    int x=arr[i];
    it=st.upper_bound({x,1e9});
    if(it==st.end())
    {
       /// cout<<"notfound "<<x<<endl;
        co++;
        st.insert({x,co});
    }
    else
    {
    ///    cout<<"found--> "<<it->first<<" "<<it->second<<" \n";
        int f=it->second;
        st.erase(it);
        st.insert({x,f});

    }

}
        cout<<co;

    return 0;
}



Measured memory_bytes: 5376
import java.util.*;

class Main {
 public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int A = sc.nextInt();
   int B = sc.nextInt();
   
   int sum = A + B;
   int sub = A - B;
   int mul = A * B;
   
   if(mul > sum) {
    if(mul > sub) {
     System. out.println(mul);
    }else {
     System. out.println(sub);
    }
   }else {
    if(sum > sub){
      System. out.println(sum);
    }else {
      System. out.println(sub); 
    }
   }
 }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PLL> VP;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "

int main()
{
    int N,K;
    cin >> N >> K;
    VI A(N);
    int minimum=100000;
    rep(i,N){
        cin >> A.at(i);
        minimum=min(minimum,A.at(i));
    }
    int count=0;
    for(int i=0; i<N; i++){
        if(A.at(i)==minimum){
            count++;
        }
    }
    if((N-count)%(K-1)==0){
        cout << (N-count)/(K-1) << endl;
        return 0;
    }
    else if((N-count)<=(K-1)){
        cout << 1 << endl;
        return 0;
    }
    else{
        cout << (N-count)/(K-1)+1 << endl;
    }
}

Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
b=[0 for i in range (n+2)]
c=[0 for i in range (n+2)]
i=1
def g(a,b):
	if(b==0):
		return a
	else:
		return g(b,a%b)
while(i<=n):
	b[i]=g(b[i-1],a[i-1])
	c[n+1-i]=g(c[n+2-i],a[n+1-i-1])
	i+=1

i=1
d=[]
while(i<=n):
	d.append(g(b[i-1],c[i+1]))
	i+=1
d.sort()
print(d[n-1])


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)


// Write From This Line
int main()
{
	int n;
	cin >> n;
	vector<int> l(n), r(n);
	rep(i,n) cin >> l[i] >> r[i];
	ll ans = 0;
	rep(i,n){
		ans += r[i] - l[i] + 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;

int main() {
   int N;
   cin>>N;
   vector<int>A(N);
   for(int i=0;i<N;i++){
     cin>>A[i];
   }
   sort(A.begin(),A.end());
   int cnt=0;
   int a= *max_element(A.begin(),A.end());
   int m= *min_element(A.begin(),A.end());
   vector<bool>ok(1000000000,true);
   for(int i=0;i<N;i++){
       if(i+1<N&&A[i+1]==A[i]){ok[A[i+1]]=false;ok[A[i]]=false;}
       int b=(a+A[i]-1)/A[i];
       for(int j=2;j<=b;j++){
        ok[A[i]*j]=false;
     }
   }
   for(int i=0;i<N;i++){
     if(ok[A[i]]){cnt++;}
   }
   cout<<cnt<<endl;
	 return 0;
}

Measured memory_bytes: 125948
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
ll mod = 998244353;
ll a, b, c, d;

ll memo[2][3005];

ll dp(ll x, ll y){
    if (x == c && y == d) return memo[x][y] = 1;
    if (memo[x][y] != -1) return memo[x][y];
    if (y == d){
        return memo[x][y] = (d*dp(x + 1, y))%mod;
    }
    if (x == c){
        return memo[x][y] = (c*dp(x, y + 1))%mod;
    }
    ll ans = (x*dp(x, y + 1))%mod + (y*dp(x + 1, y))%mod;
    ans %= mod;
    ll minus = x*y;
    minus %= mod;
    minus *= dp(x + 1, y + 1);
    minus %= mod;
    return memo[x][y] = (ans - minus + mod)%mod;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> a >> b >> c >> d;
	memset(memo, -1, sizeof(memo));
	
	for (ll i = c; i >= a; i--){
	    for (ll j = d; j >= 0; j--){
	        memo[i%2][j] = -1;
	    }
	    for (ll j = d; j >= b; j--){
	        ll x = i%2;
	        ll y = j;
            if (i == c && y == d){
                memo[x][y] = 1;
                continue;
            }
            if (y == d){
                memo[x][y] = (d*memo[1 - x][y])%mod;
                continue;
            }
            if (i == c){
                memo[x][y] = (c*memo[x][y + 1])%mod;
                continue;
            }
            ll ans = (i*memo[x][y + 1])%mod + (y*memo[1 - x][y])%mod;
            ans %= mod;
            ll minus = i*y;
            minus %= mod;
            minus *= memo[1 - x][y + 1];
            minus %= mod;
            memo[x][y] = (ans - minus + mod)%mod;
	    }
	}
	
	cout << memo[a%2][b] << endl;
}

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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()


using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;


void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}


const double EPS = 1e-8;
const long long mod = 1e9 + 7;

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

const int N = 1e5 + 5;
const long long INF = 1e18;


int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n , m;
    cin >> n >> m;
    vector<int> vec;
    int a;
    for(int i = 0; i < n; ++i){
            cin >> a;
            vec.push_back(a);
    }
    vector<pair<int,int> > b;
    int x,y;
    for(int i = 0; i < m; ++i){
            cin >> x >> y;
            b.push_back(make_pair(y,x));
    }
    sort(all(b));
    reverse(all(b));
    sort(all(vec));

    long long ans = 0, j = 0;
    for(int i = 0; i < m and j < n; ++i){
            int z = 0;
            while(j < n and vec[j] < b[i].first and z < b[i].second){
                    vec[j] = b[i].first;
                    ++z;
                    ++j;
            }
    }
    for(int i = 0; i < vec.size(); ++i)
            ans += vec[i];
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4680
// Binary Search Tree II
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root, nil;

// 木から key の値を持つノードを探す //
Node treeSearch(Node x, int k){
  if(x == nil || k == x->key) return x;
  if(k < x->key) treeSearch(x->left, k);
  else treeSearch(x->right, k);
}

// ノード x から最小の key を探す //
Node treeMinimum(Node x){
  while(x->left != nil)x = x->left;
  return x;
}

// ノード x から最大の key を探す //
Node treeMaximum(Node x){
  while(x->right != nil)x = x->right;
  return x;
}

//  二分探索木へkを挿入 //
void insert(int k){
  Node y = nil; // x の親
  Node x = root; // T の根
  Node z;
  
  //z->parent = y;
  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = nil;
  z->right = nil;

  while(x != nil){
    y = x;   // 親を設定
    if(z->key < x->key)x = x->left; // 左の子へ移動
    else x = x->right;            // 右の子へ移動
  }
  z->parent = y;

  if(y == nil)root = z; // T が空の場合
  else if(z->key < y->key)y->left = z; // z を y の左の子にする
  else y->right = z; // z を y の右の子にする
}

// 再帰を使って中間順巡回(Inorder)で表示
void printInorder(Node u){
  if(u == nil)return;
  printInorder(u->left);
  printf(" %d", u->key);
  printInorder(u->right);
}

// 再帰を使って先行順巡回(Preorder)で表示
void printPreorder(Node u){
  if(u == nil)return;
  printf(" %d", u->key);
  printPreorder(u->left);
  printPreorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];
  Node t;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != nil ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      printInorder(root);
      printf("\n");
      printPreorder(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 20476
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    
    sort(a.begin(), a.end());
    vector<int> b(N);
    rep(i, N) {
        b[i] = min(a[i], x);
        x -= b[i];
    }
    
    int cnt = 0;
    rep(i, N) {
        if (a[i] == b[i]) ++cnt;
    }
    if (x == 0) cout << cnt << endl;
    else cout << cnt - 1 << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(a) for a in input().split()]

ans = 0
C = [0] * N # [1の個数, 2の個数, 3の個数, ... , Nの個数]
for i in range(N):
  n = A[i]
  if n <= N:
    C[n-1] += 1
  else: # n > N:
    ans += 1

for i in range(N):
  cnt = C[i]
  if cnt > i+1:
    ans += (cnt - (i+1))
  elif cnt < i+1:
    ans += cnt

print(ans)

Measured memory_bytes: 14024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void){
  int a,b;
  char str[5];
  
  fgets(str,sizeof(str),stdin);
  a=atoi(str);
  fgets(str,sizeof(str),stdin);
  b=atoi(str);
  switch(a*b){
    case 2:
      printf("3\n");
      break;
    case 3:
      printf("2\n");
      break;
    case 6:
      printf("1\n");
      break;
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <tuple>

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

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

string getStr(){ static char b[256]; scanf("%s", b); return b; }

int main(){
  while(true){
    const int t = getInt();
    const int p = getInt();
    const int r = getInt();

    if(t + p + r == 0) return 0;

    vector<vector<int> > w(t, vector<int>(p));

    vector<tuple<int, int, int> > team(t);
    const int ac = 0;
    const int pn = 1;
    const int id = 2;
    REP(i,t) get<id>(team[i]) = -(i + 1);

    REP(i,r){
      const int tid = getInt() - 1;
      const int pid = getInt() - 1;
      const int tm  = getInt();
      const string mes = getStr();

      if(mes[0] == 'C'){
	if(w[tid][pid] == -1) continue;
	get<ac>(team[tid])++;
	get<pn>(team[tid]) -= 1200 * w[tid][pid] + tm;
      }else{
	w[tid][pid]++;
      }
    }

    sort(team.rbegin(), team.rend());

    for(const auto tp : team)
      printf("%d %d %d\n", -get<id>(tp), get<ac>(tp), -get<pn>(tp));

  }

  return 0;
}

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

const ll MAXN = 1e18;

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = -MAXN;
	ans = max(ans, a*c);
	ans = max(ans, b*d);
	ans = max(ans, b*c);
	ans = max(ans, a*d);
	cout << ans << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

int plot[2010][2010];
char c;

int main() {
	int n, k, sum=0 , white=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b >> c;
		a %= 2 * k; b %= 2 * k;
		if (c == 'B') { plot[b + 1][a + 1]++; sum++; }
		if (c == 'W') { plot[b + 1][a + 1]--; sum--; white++; }
	}

	for (int i = 0; i < 2 * k; i++) {
		for (int j = 0; j < 2 * k; j++) {
			plot[i + 1][j + 1] += plot[i + 1][j] + plot[i][j + 1] - plot[i][j];
		}
	}

	int mx = -(1 << 25);
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			int a = plot[i][j];
			int b = plot[i + k][j + k] - plot[i + k][j] - plot[i][j + k] + plot[i][j];
			int c = plot[2 * k][j] - plot[i + k][j];
			int d = plot[i][2 * k] - plot[i][j + k];
			int e = plot[2 * k][2 * k] - plot[2 * k][j + k] - plot[i + k][2 * k] + plot[i + k][j + k];
			int ppp = a + b + c + d + e;
			mx = max(mx, max(ppp, sum - ppp));
		}
	}

	mx += white;
	cout << mx << endl;

	return 0;
}

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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (W < (x + r)) {
        cout << "No" << endl;
        return 0;
    }

    if (H < (y + r)) {
        cout << "No" << endl;
        return 0;
    }

    if (x < r) {
        cout << "No" << endl;
        return 0;
    }

    if (y < r) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    
}



Measured memory_bytes: 3120
#include <stdio.h>
int main()
{
int N,M,odd,even;
odd=even=0;
scanf ("%d %d",&N,&M);
if (N>1) 	{
			do 	{
				--N;
				even=even+N;
				} while (N>0);
			}
if (M>1) 	{
			do 	{
				--M;
				odd=odd+M;
				} while (M>0);
			}
printf ("%d\n",odd+even);
}


Measured memory_bytes: 2152
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		while(true){
			String[] ary=br.readLine().split(" ");
			int H=Integer.parseInt(ary[0]);
	        int W=Integer.parseInt(ary[1]);
			if(H==0&&W==0) break;
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					if(i!=0&&i!=H-1&&j!=0&&j!=W-1){
						sb.append('.');
					}else{
						sb.append('#');
					}
				}
				sb.append('\n');
			}
			sb.append('\n');
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 24844
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	
	vector<vector<int>> jobs(M);
	
	for (int i = 0; i < N; i++)
	{
		int A, B;
		cin >> A >> B;
		
		// M日より大きいA日の仕事は報酬をもらえないため、報酬の仕事として扱わない。
		if (A > M)
		{
			continue;
		}
		
		// 報酬BをもらうにはM - A日までに仕事を行う必要があるため
		jobs[M - A].push_back(B);
	}
	
	// 常に最大の値を取り出すためにpriority_queueを利用
	priority_queue<int> q;
	
	long answer = 0;
	// 最終日 - 1から処理を行う 貪欲法
	for (int i = M - 1; i >= 0; i--)
	{
		// キューにjobs[i]に格納された全ての報酬Bを入れる
		for (int b: jobs[i])
		{
			q.push(b);
		}
		
		if (!q.empty())
		{
			// 格納されたqの先頭の要素がjobs[i]の一番高い報酬になる
			answer += q.top();
			// 先頭のtop()を削除する
			q.pop();
		}
	}
	
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 5504
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class CompetitiveProgrammingProgram
{
    static long Gcd(long a, long b)
    {
        long[] v = new long[] { a, b };
        while (v[1] != 0) { v = new long[] { v[1], v[0] % v[1] }; }
        return v[0];
    }
    static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }
    class Node<T>
    {
        private int m_height;
        private Node<T> m_parent;
        public T Item { get; private set; }
        public Node(T item)
        {
            m_height = 0;
            m_parent = this;
            Item = item;
        }
        public Node<T> Find()
        {
            if (m_parent == this) { return this; }

            Node<T> parent = m_parent.Find();
            m_parent = parent;
            return parent;
        }
        public static void Unite(Node<T> a, Node<T> b)
        {
            Node<T> p = a.Find();
            Node<T> q = b.Find();
            if (p.m_height < q.m_height)
            {
                p.m_parent = q;
                q.m_height = Math.Max(p.m_height + 1, q.m_height);
            }
            else
            {
                q.m_parent = p;
                p.m_height = Math.Max(q.m_height + 1, p.m_height);
            }
        }
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string c = Console.ReadLine();
        int rcnt = 0;
        int wcnt = 0;
        for (int i = 0; i < N; i++)
        {
            if (c[i] == 'R')
                rcnt++;
            if (c[i] == 'W')
                wcnt++;
        }
        int ans = 0;
        for (int i = rcnt; i < N; i++)
        {
            if (c[i] == 'R')
                ans++;
        }
        Console.WriteLine(ans.ToString());
    }
}

Measured memory_bytes: 28344
using System;
using System.Collections.Generic;
using System.Linq;

namespace template
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            Console.WriteLine(cin.ReadLine.Count(x => x == '1'));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) 
                {
                    return inputStream.Dequeue();
                }

                string[] tmp = _stream.ReadLine().Split(_separator);
                
                for (int i = 0; i < tmp.Length; ++i)
                {
                    inputStream.Enqueue(tmp[i]);
                }
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 11348
a, b, c = gets.chomp.split(' ').map(&:to_i)
K = gets.to_i

K.times do
  if a <= b && c <= b
    c = c * 2
  elsif b <= a && a <= c
    b = b * 2
  elsif c <= a && a <= b
    c = c * 2
  elsif c <= b && b <= a
    c = c * 2
  elsif a <= c && c <= b
    c = c * 2
  elsif b <= c && c <= a
    b = b * 2
  end
end

if a < b && b < c
  puts 'Yes'
else
  puts 'No'
end



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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;


int main() {
    int N;
    ll H;
    cin >> N >> H;
    vector<ll> A(N), B(N);
    for(int i = 0; i < N; i++) cin >> A[i] >> B[i];
    sort(all(A));
    sort(all(B), greater<>());
    ll great = A.back();
    ll sum = 0;
    ll ans = 0;
    for(ll b : B){
        if(b >= great and sum < H){
            sum += b;
            ans++;
        }
        else break;
    }
    if(H - sum > 0){
        if((H - sum) % great) ans += (H - sum) / great + 1;
        else ans += (H - sum) / great;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, m = map(int, input().split())
  lp = list(map(int, input().split()))
  
  luf = [-1] * (n)
  def find(x):
    if luf[x] < 0:
      return x
    else:
      luf[x] = find(luf[x])
      return luf[x]
  
  def union(x, y):
    px, py = find(x), find(y)
    if px == py:
      return
    if px < py:
      px, py = py, px
    luf[px] += luf[py]
    luf[py] = px

  
  for _ in range(m):
    x, y = map(int, input().split())
    union(x-1, y-1)
  
  dic = dict()
  for i, p in enumerate(lp):
    p -= 1
    pp = find(p)
    if pp in dic:
      dic[pp]['inds'] |= set([i])
      dic[pp]['vals'] |= set([p])
    else:
      dic[pp] = dict()
      dic[pp]['inds'] = set([i])
      dic[pp]['vals'] = set([p])
  print(sum([len(v['inds'] & v['vals']) for _, v in dic.items()]))
    

if __name__=='__main__':
  main()



Measured memory_bytes: 95216
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [input().split() for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0

    s = input()
    hi = ['hi','hihi','hihihi','hihihihi','hihihihihi']
    for i in hi:
        if s == i:
            print('Yes')
            return 0
    print('No')

if __name__ == '__main__':
    main()



Measured memory_bytes: 38256
#include <algorithm>
#include <cstdio>
#include <vector>

const int N = 100000;

int n, m, a[N], parent[N], cnt[N], used[N];

bool by_a(int i, int j)
{
    return a[i] < a[j];
}

int find(int u)
{
    if (parent[u] != u) {
        parent[u] = find(parent[u]);
    }
    return parent[u];
}

int main()
{
    scanf("%d%d", &n, &m);
    std::vector<int> order(n);
    for (int i = 0; i < n; ++ i) {
        scanf("%d", a + i);
        order[i] = parent[i] = i;
    }
    std::sort(order.begin(), order.end(), by_a);
    for (int i = 0, x, y; i < m; ++ i) {
        scanf("%d%d", &x, &y);
        parent[find(x)] = find(y);
    }
    long long result = 0;
    int comp = n - m;
    int need = comp - 2;
    if (comp > 1) {
        for (int i : order) {
            int f = find(i);
            if (!cnt[f]) {
                cnt[f] = used[i] = 1;
                result += a[i];
            }
        }
        for (int i : order) {
            int f = find(i);
            if (need && !used[i]) {
                need --;
                cnt[f] ++;
                result += a[i];
            }
        }
    }
    if (need > 0) {
        puts("Impossible");
    } else {
        printf("%lld\n", result);
    }
}



Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		long min = (long)Math.pow(10,11);
		
		for(long i = 1; i * i<= N; i++) {
			if(N % i == 0) {
				if(getMax(i, N / i) < min) {
					min = getMax(i, N / i);
				}
			}
		}
		
		System.out.println(min);
		
		scan.close();

	}
	
	public static int getMax(long A, long B) {
		if(Long.toString(A).length() > Long.toString(B).length()) {
			return Long.toString(A).length();
		} else {
			return Long.toString(B).length();
		}
	}

}


Measured memory_bytes: 23764
#include<stdio.h>

int main()
{
    int a,b;
    char sign;
    scanf("%d %c %d",&a,&sign,&b);
    if(sign=='+')
    {
        printf("%d\n",a+b);
    }
    else
    {
        printf("%d\n",a-b);
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

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

void solve() {
  int n;
  cin >> n;
  vstr a(n);
  cin >> a;
  {
    bool white = true;
    rep(i, n) rep(j, n) white &= a[i][j] == '.';
    if (white) {
      cout << -1 << endl;
      return;
    }
  }
  int ans = INF;
  rep(i, n) {
    int cnt = 0;
    rep(j, n) cnt += a[i][j] == '.';
    bool blank = false;
    int j = i;
    rep(i, n) blank |= a[i][j] == '#';
    if (!blank) cnt += 1;
    amin(ans, cnt);
  }
  rep(j, n) {
    bool fill = true;
    rep(i, n) fill &= a[i][j] == '#';
    if (!fill) ans += 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3900
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

int main() {
    int a;
    int b;
    int ans;

    cin >> a >> b;
    if(b%a==0){
        ans = a + b;
    }else{
        ans = b - a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll>PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4+7;
int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
//    rep(i, k) {
//        ll tmp_a = a;
//        ll tmp_b = b;
//        ll tmp_c = c;
//        a = tmp_b + tmp_c;
//        b = tmp_a + tmp_c;
//        c = tmp_a + tmp_b;
//    }
    if ( k & 1 ) swap(a, b);
    if ( abs(a - b) >= 1e18 ) cout << "Unfair" << endl;
    else                      cout << a - b << endl;
    return 0;
}


Measured memory_bytes: 256
n = (input())
nl= [int(i) for i in n]
if nl[-1]==2 or nl[-1]==4 or nl[-1]==5 or nl[-1]==7 or nl[-1]==9:
    print('hon')
elif nl[-1]==0 or nl[-1]==1 or nl[-1]==6 or nl[-1]==8:
    print('pon')
else:
    print('bon')

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

using namespace std;

int main()
{
    int n;
    int A[128][128];
    
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            scanf("%d", &A[i][j]);
        }
    }
    
    long long ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            ans += min(A[i][j], A[j][i]);
        }
    }
    
    printf("%lld\n", ans);
    
    return (0);
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	int n;
	cin >> n;
	vector<int> divisor_cnt(n + 2, 0);
	for(int i = 1; i <= n; ++i)
	{
		for(int j = i; j <= n; j += i)
		{
			divisor_cnt[j]++;
		}
	}

	ll ans = 0;
	for(ll i = 1; i <= n; ++i)
	{
		ans += i * divisor_cnt[i];
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

int main(void)
{
	int n[3];
	int i;
	int min;
	int t;
	
	min = 100;
	for (i = 0; i < 3; i++){
		cin >> n[i];
		if (min > n[i]){
			min = n[i];
		}
	}
	
	while (1){
		if (n[0] > n[1]){
			t = n[0];
			n[0] = n[1];
			n[1] = t;
		}
		if (n[1] > n[2]){
			t = n[1];
			n[1] = n[2];
			n[2] = t;
		}
		if (n[0] == min){
			break;
		}
	}
	
	cout << n[0];
	for (i = 1; i < 3; i++){
		cout << " " << n[i];
	}
	cout << "\n";
	
	return (0);
}

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

int main(){
    int n, k;
    int cnt = 0;
    bool is_same;
    int p,q;

    long long d;
    cin >> n >> d;

    vector<long long> x;
    vector<long long> y;

    for(int i = 0; i < n; i++){
        cin >> p;
        cin >> q;
        is_same = false;
        // for(int j = 0; j < x.size(); j++){
        //     if(x[j] == p && y[j] == q){
        //         is_same = true;
        //         break;
        //     }    
        // }
        // if(!is_same){
        //     x.push_back(p);
        //     y.push_back(q);
        // }
        x.push_back(p);
        y.push_back(q);
     }

    cnt = 0;

    // for(int i = 0; i < x.size(); i++) cout << x[i] << " " << y[i] << endl;

    for(int i = 0; i < x.size(); i++){
        if((x[i] * x[i] + y[i] * y[i]) <= d * d)cnt++;
    }

    cout << cnt << endl;

    return 0;

}

Measured memory_bytes: 6564
def countchar(s) : 
  countstr = [0] * 300
  for i in s : 
    if countstr[ord(i)] != 0 : 
      return False
    countstr[ord(i)] += 1
  return True


s = input()


if countchar(s) : 
  print('yes') 
else : 
  print('no')

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

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

    bool valid = false;
    REP(i,3){
        int n = N%10;
        if(n == 7)
            valid = true;
        N /= 10;
    }

    if(valid)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int main(){
	int sx,sy,tx,ty;
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
	int i;
	for(i=0;i<tx-sx;i++){
		putchar('R');
	}
	for(i=0;i<ty-sy;i++){
		putchar('U');
	}
	for(i=0;i<tx-sx;i++){
		putchar('L');
	}
	for(i=0;i<ty-sy;i++){
		putchar('D');
	}
	putchar('D');
	for(i=0;i<tx-sx+1;i++){
		putchar('R');
	}
	for(i=0;i<ty-sy+1;i++){
		putchar('U');
	}
	putchar('L');
	putchar('U');
	for(i=0;i<tx-sx+1;i++){
		putchar('L');
	}
	for(i=0;i<ty-sy+1;i++){
		putchar('D');
	}
	putchar('R');
	putchar('\n');
	
	return 0;
}

Measured memory_bytes: 128