akhauriyash/Code-Regression huggingface dataset:
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))

Measured memory_bytes: 32872
#include<iostream>
#include<string>

using namespace std;

int main() {
	int N;
	string S;
	cin >> N >> S;
	if (N % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < N / 2; i++) {
		if (S[i] != S[N / 2 + i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
n,m,k=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
t=0
for p in range(n):
    if t+a[p]>k:
        p-=1
        break
    t+=a[p]
for q in range(m):
    if t+b[q]>k:
        q-=1
        break
    t+=b[q]
ans=p+q+2
if q<m-1:
    z=ans
    q+=1
    for s in range(p,-1,-1):
        t-=a[s]
        z-=1
        while q<m and t+b[q]<=k:
            t+=b[q]
            q+=1
            z+=1
        if z>ans:
            ans=z
        if q==m:
            break
print(ans)

Measured memory_bytes: 42304
#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;
ll two[202020];
ll two2[202020];
ll two3[202020];
ll popcount(ll x) {
	int res = 0;
	for (; x > 0; x >>= 1) res += (x & 1);
	return res;
}
ll modpow(string s, int mod) {
	ll res = 0;
	ll now = 1;
	rep(i, s.size()) {
		if (s[i] == '1') res = res + now % mod;
		now = now * 2 % mod;
	}
	return res;
}
ll rem(ll x, int s) {
	if (x == 0) return s;
	ll nxt = popcount(x);
	if (nxt == 0) return s;
	return rem(x % nxt, s + 1);
}
int main() {
	two[0] = 1;
	two2[0] = 1;
	two3[0] = 1;
	int n; string s;
	cin >> n >> s;
	reverse(all(s));
	int ppcnt = 0;
	rep(i, n) {
		ppcnt += s[i] - '0';
	}
	if (ppcnt == 0) {
		rep(i, n) {
			cout << 1 << endl;
		}
		return 0;
	}
	else if (ppcnt == 1) {
		V ans(n);
		rep(i, n) {
			if (s[i] == '1') ans[i] = 0;
			else {
				if (s[0] == '1') ans[i] = 2;
				else {
					if (i == 0) ans[i] = 2;
					else ans[i] = 1;
				}
			}
		}
		reverse(all(ans));
		rep(i, n) cout << ans[i] << endl;
		return 0;
	}
	rep1(i, 200005) two[i] = (two[i - 1] * 2) % ppcnt;
	rep1(i, 200005) two2[i] = (two2[i - 1] * 2) % (ppcnt + 1);
	if (ppcnt != 1) {
		rep1(i, 200005) two3[i] = (two3[i - 1] * 2) % (ppcnt - 1);
	}
	else {
		rep1(i, 200005) two3[i] = -1;
	}
	ll x = modpow(s, ppcnt);
	ll x2 = modpow(s, ppcnt + 1);
	ll x3 = (ppcnt >= 2) ? modpow(s, ppcnt - 1) : -1;
	// 割り算はlog回で収束しそう
	V ans(n);
	rep(i, n) {
		int pc = ppcnt;
		if (s[i] == '0') {
			pc++;
			if (pc == 1) {
				ans[i] = 1;
				continue;
			}
			ll tmp = (x2 + two2[i]) % pc;
			if (tmp == 0) ans[i] = 1;
			else ans[i] = rem(tmp, 1);
		}
		else {
			pc--;
			if (pc == 1) {
				ans[i] = 1;
				continue;
			}
			else if (pc == 0) {
				ans[i] = 0;
				continue;
			}
			ll tmp = (x3 - two3[i] + pc) % pc;
			if (tmp == 0) ans[i] = 1;
			else ans[i] = rem(tmp, 1);
		}
	}
	reverse(all(ans));
	rep(i, n) cout << ans[i] << endl;
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    float yen = 0;

    for( int i=0 ; i<N ; i++ )
    {
        string s;
        float  m;

        cin >> m >> s;

        if( s == "JPY" ) yen += m;
        else             yen += 380000.0 * m;
    }

    cout << yen << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void fun(int a, int b, int h, int m) {

        double oneH = 2 * Math.PI / 12.0;
        double angleH = oneH * (h + m / 60.0);
        double oneM = 2 * Math.PI / 60.0;
        double angleM = oneM * m;

//        double angle = angleH - angleM;
        double angle = angleM - angleH;


        double ans = a * a + b * b - 2 * a * b * Math.cos(angle);
        System.out.println(Math.sqrt(ans));
    }



    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line = in.readLine();
        String[] ss=line.split(" ");
        int a = Integer.valueOf(ss[0]);
        int b = Integer.valueOf(ss[1]);
        int h = Integer.valueOf(ss[2]);
        int m = Integer.valueOf(ss[3]);
        fun(a, b, h, m);
    }



}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int a[100000];
map<int, int> c;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        c[a[i]]++;
        c[a[i] - 1]++;
        c[a[i] + 1]++;
    }

    int maxv = 0, maxc = 0;
    for (auto t : c) {
        if (maxc < t.second) {
            maxc = t.second;
            maxv = t.first;
        }
    }

    cout << maxc << endl;

    return 0;
}

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

int main() {
  int n; string s; cin >> n >> s;
  int ans = 0;
  rep(i, 1000) {
    int cnt = 0;
    int a[3];
    int num = i;
    rep(s, 3) {
      a[s] = num / (int)pow(10, 2 - s);
      num %= (int)pow(10, 2 - s);
    }
    rep(j, n) {
      if (a[cnt] == s[j] - '0')
        cnt++;
      if (cnt == 3) break;
    }
    if (cnt == 3) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;

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

int main() {
	int N;
	cin>>N;
	vector<ll> A(N),B(N),C(N);
	rep(i,N)cin>>A[i];
	rep(i,N)cin>>B[i];
	rep(i,N)cin>>C[i];
	sort(all(A));
	sort(all(C));
	ll ans = 0;
	rep(i,N){
		ll a = lower_bound(all(A),B[i]) - A.begin();
		ll c = C.end() - upper_bound(all(C), B[i]);
		ans += a*c;
	}
	cout<<ans<<endl;
}

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

#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 all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

const ll mod = 1e9+7;

vvi times(vvi &a, vvi &b) {
  vvi s(sz(a), vi(sz(a)));
  rep(i,0,sz(a)) {
    rep(j,0,sz(a)) {
      rep(k,0,sz(a)) {
        s[i][j] += (a[i][k]%mod) * (b[k][j]%mod) % mod;
        s[i][j] %= mod;
      }
    }
  }
  return s;
}
vvi square(vvi &mat) {
  return times(mat, mat);
}
vi times(vvi &mat, vi &v) {
  vi r(sz(v));
  rep(i,0,sz(v)) {
    rep(j,0,sz(v)) {
      r[i] += (mat[i][j]%mod) * v[j] % mod;
      r[i] %= mod;
    }
  }
  return r;
}

ll modpow(ll b, ll e) {
  ll ans = 1;
  for (; e; e>>=1, b = b*b%mod) {
    if (e&1) ans *= b;
    ans %= mod;
  }
  return ans;
}

vvi modpow(vvi &m, ll e) {
  vvi ans(sz(m), vi(sz(m)));
  rep(i,0,sz(ans)) ans[i][i] = 1;
  for (; e; e>>=1, m = square(m)) {
    if (e&1) ans = times(ans, m);
  }
  return ans;
}

ll inv(ll n) { return modpow(n, mod-2); }
vi fac;
ll c(ll n, ll k) { return (fac[n] * inv(fac[k]) % mod) * inv(fac[n-k]) % mod; }


int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  fac.pb(1);
  rep(i,1,2123456) fac.pb(fac[i-1]*i%mod);

  ll n, k;
  cin >> n >> k;

  vvi adj(n, vi(n));
  rep(i,0,n) rep(j,0,n) cin >> adj[i][j];

  adj = modpow(adj, k);

  ll ans = 0;
  rep(i,0,n) rep(j,0,n) {
    ans += adj[i][j];
    ans %= mod;
  }

  cout <<ans << '\n';
}

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

int n, q;
int rank[10000], par[10000];

void init() {
  for (int i=0; i<n; i++) {
    par[i] = i;
    rank[i] = 0;
  }
}

int find(int x) {
  if (x==par[x]) {
    return x;
  }
  return par[x] = find(par[x]);
}

void unite(int x,int y) {
  x = find(par[x]);
  y = find(par[y]);
  if (x==y) {
    return;
  }
  if (rank[x]<rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rank[x]==rank[y]) {
      rank[x]++;
    }
  }
}

int same(int x,int y) {
  return find(x)==find(y);
}

int main() {
  cin >> n >> q;
  init();
  for (int i=0; i<q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com==0) {
      unite(x,y);
    } else {
      cout << same(x,y) << endl;
    }
  }
  return 0;
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int counter(int x){   // returns no of set bits - honest people
  return __builtin_popcount(x);
}

int main(){
  FAST();

  int N;
  int A[20];
  int x[20][20];
  int y[20][20];

  cin >> N;
  for(int i = 1; i <= N; i++) {
    cin >> A[i];
    for(int j = 1; j <= A[i]; j++) {
      cin >> x[i][j] >> y[i][j];
    }
  }

  int bitmask, i, j, ans = 0;

  for(bitmask = 1; bitmask < (1<<N); bitmask++){
      bool ok = true;
      for(i = 1; i <= N; i++){
        if((bitmask & (1<<(i - 1))) == 0)
          continue;
        for(j = 1; j <= A[i]; j++){
          if(((bitmask >> (x[i][j] - 1)) & 1) ^ y[i][j])
            ok = false;
        }
      }
      if(ok)
        ans = max(ans, counter(bitmask));
    }
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
int n,m, d;
int main() {
scanf("%d%d%d", &n, &m, &d);
for (int i = 1; i <= n; i++,puts(""))
for (int j = 1; j <= m; j++) {
int t1 = ((i - j + m) / d) & 1, t2 = ((i + j)/d)&1;
printf("%c","RGBY"[t1*2+t2]);
}
return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int a,b,c,c5=0,c7=0;
	cin>>a>>b>>c;
	if (a==5)
		c5++;
	if (a==7)
		c7++;
	if (b==5)
		c5++;
	if (b==7)
		c7++;
	if (c==5)
		c5++;
	if (c==7)
		c7++;
	if (c5==2 && c7==1)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}


const int n_max = 100005;

signed main(){
    int n;
    cin >> n;
    int X[n];
    REP(i,n) cin >> X[i];
    int L;
    cin >> L;

    int tugi[n_max][25];
    REP(i,n_max) REP(j,25) tugi[i][j] = n;
    REP(i,n-1){
        int l = i + 1;
        int r = n;

        while(l + 1 < r){
            int mid = (l + r) / 2;
            if(X[mid] - X[i]<= L) l = mid;
            else r = mid;
        }
        tugi[i][1] = l;
    }
    REP(j,23){
        REP(i,n){
            if(tugi[i][j+1] == n) tugi[i][j+2] =n;
            tugi[i][j+2] = tugi[tugi[i][j+1]][j+1];
        }
    }



    int beki[30];
    beki[1] = 1;
    FOR(i,1,29) beki[i + 1] = beki[i] * 2;

    int q;
    cin >> q;
    REP(i,q){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        if(a == b){
            cout << 0 << endl;
            continue;
        }
        if(a > b) swap(a,b);
        int id = 24;
        int now = a;
        int ans = 0;
        while(now != b){
            if(tugi[now][id] <= b){
                now = tugi[now][id];
                ans += beki[id];
            }
            id--;
            if(id == 0) break;
        }
        if(now != b) ans ++;
        cout << ans << endl;
    }
}

Measured memory_bytes: 21120
#include<iostream>
using namespace std;
int main(){
	int n;
  int AC(0), TLE(0), WA(0), RE(0);
  cin >> n;
  string s[n];
  
  for(int i =0; i<n;++i){
  	cin >> s[i];
    if(s[i] == "AC") AC++;
    if(s[i] == "TLE") TLE++;
    if(s[i] == "WA") WA++;
    if(s[i] == "RE") RE++;
  }
  cout<<"AC x "<<AC<<endl;
  cout<<"WA x "<<WA<<endl;
  cout<<"TLE x "<<TLE<<endl;
	cout<<"RE x "<<RE;
}

Measured memory_bytes: 6700
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
string s;
int main(){
    cin>>s;
    
    if (s=="SUN") cout<<7;
    if (s=="MON") cout<<6;
    if (s=="TUE") cout<<5;
    if (s=="WED") cout<<4;
    if (s=="THU") cout<<3;
    if (s=="FRI") cout<<2;
    if (s=="SAT") cout<<1;
}

Measured memory_bytes: 256
def main():
    import sys
    input=sys.stdin.readline
    n,k=map(int,input().split())
    x=list(map(int,input().split()))
    
    min_list=[]
    max_list=[]
    m=262143+n
    segtree=[-1]*m
    
    for i in range(262143,m):
        segtree[i]=x[i-262143]
    	
    for i in range(262142,-1,-1):
        j=2*i+1
        if j>=m:
            segtree[i]=-1
        elif j+1>=m:
            segtree[i]=segtree[j]
        else:
            segtree[i]=min(segtree[j],segtree[j+1])
    
    for i in range(n-k+2):
        qq=[(i,i+k-2,0,1)]
        s=set()
        while qq:
            ii,jj,now,kubun=qq.pop()
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append((ii,jj,2*now+1,2*kubun))
                qq.append((ii,jj,2*now+2,2*kubun))
        min_list.append(min(s))
       
    for i in range(262142,-1,-1):
        j=2*i+1
        if j>=m:
            segtree[i]=n+1
        elif j+1>=m:
            segtree[i]=segtree[j]
        else:
            segtree[i]=max(segtree[j],segtree[j+1])
    
    for i in range(n-k+2):
        qq=[(i,i+k-2,0,1)]
        s=set()
        while qq:
            ii,jj,now,kubun=qq.pop()
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append((ii,jj,2*now+1,2*kubun))
                qq.append((ii,jj,2*now+2,2*kubun))
        max_list.append(max(s))
        
    cnt=0
    flag=[True]*(n-k+1)
    first=False
    for i in range(n-1):
        if x[i]<x[i+1]:
            cnt+=1
        else:
            cnt=0
        if cnt>=k-1:
            if first==False:
                first=True
            else:
                flag[i-k+2]=False
    
    for i in range(1,n-k+1):
        if x[i-1]<min_list[i] and max_list[i]<x[i+k-1]:
            flag[i]=False
            
    print(sum(flag))

if __name__ == '__main__':
	main()


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll x, ans, y;

int main() {
	cin >> x;
	ans = x/11 * 2;
	y = x/11 *11;
	int t = 0;
	while (y<x) {
		if (t%2==0) y += 6;
		else y += 5;
		t++;
	}
	cout << ans + t << ln;
}

Measured memory_bytes: 256
#include <iostream>
using lli         = long long;
constexpr lli mod = 1'000'000'007;  //'

long long comb(long long n, long long r) {
    //--------Valid Error------------------
    if (n < 0 || r < 0) return 0LL;
    if (n == 0) return 0LL;
    if (n < r) return 0LL;
    //-------------------------------------

    r = std::min(r, n - r);
    if (r == 0LL) return 1LL;
    if (r == 1LL) return n;

    int inverse[500005];
    for (lli i = 1LL; i <= r; ++i) {
        lli a = i, b = mod, u = 1LL, v = 0LL, t;
        while (b > 0) {
            t = a / b;
            std::swap(a -= t * b, b);
            std::swap(u -= t * v, v);
        }
        inverse[i] = (u >= 0 ? u % mod : (mod - (-u) % mod));
    }

    long long retVal = 1LL;
    for (long long i = 0LL; i < r; i++) {
        retVal *= (n - i);  // retVal = n! / (n-r)!
        retVal %= mod;
        retVal *= inverse[i + 1];  // retVal /= r!
        retVal %= mod;
    }
    return retVal;
}

int main(void) {
    lli x, y;
    std::cin >> x >> y;

    lli k = 2LL * x - y;
    if (k % 3LL) {
        std::cout << "0\n";
        return 0;
    }
    k /= 3LL;

    lli t = 2LL * y - x;
    if (t % 3LL) {
        std::cout << "0\n";
        return 0;
    }
    t /= 3LL;

    long long ans = comb(k + t, k);
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            double n = in.nextInt();
            int m = in.nextInt();
            int d = in.nextInt();

            if (d == 0) {
                double prob = n / (n * n);
                System.out.println((m - 1) * prob);
            } else {
                double prob = 2 * (n - d) / (n * n);
                System.out.println((m - 1) * prob);
            }
        }
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 510000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli N,K,L,sum=0;
  string S;
  cin >> S;
  cin >> K;
  N=S.size();
  Vec(P,string,0," ");
  rep(i,0,N)P.pb(S.substr(i,1));
  if(K>1)rep(i,0,N-1)P.pb(S.substr(i,2));
  if(K>2)rep(i,0,N-2)P.pb(S.substr(i,3));
  if(K>3)rep(i,0,N-3)P.pb(S.substr(i,4));
  if(K>4)rep(i,0,N-4)P.pb(S.substr(i,5));
  Sort(P);
  UE(P);
  Out(P[K-1]);
}

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

int main(){

  string n;
  cin >> n;

  int m = 0,s = 0;
  int k = 1;
  for(int i = n.size()-1; i >= 0; i--){
    int cnt = 0;
    for(char j = '0'; j <= '9'; j++){
      if(n[i] == j){
        s += cnt;
        m += cnt*k;
        k *= 10;
      }
      cnt++;
    }
  }

  //cout << m << " " << s << endl;
  cout << ((m%s == 0)?"Yes":"No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007

ll w,e;
int main(void)
{
	CIN;
	ll tc,l,k=0,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>n>>m;
	string s[100];
	tc=n;
	while(n--)cin>>s[x],x++;
	sort(s,s+tc);
	for(ll i=0;i<tc;i++)cout<<s[i];
	
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

    intmax_t x; cin >> x;

    vector<int> ok(int(1e6) + 1);
    for (int i = 1; 100 * i <= int(1e6); ++i) {
        ok[100 * i]++;
    }
    for (int i = 1; 105 * i <= int(1e6); ++i) {
        ok[105 * i + 1]--;
    }

    for (int i = 1; i <= int(1e6); ++i) {
        ok[i] += ok[i - 1];
    }

    cout << (ok[x] ? 1 : 0) << "\n";


    return 0;
}


Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {

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

        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());

        int count = 0;
        for (int i = A; i <= B; i++) {
            String temp = String.valueOf(i);
            boolean isPal = true;
            for (int j = 0; j < 2; j++) {
                if (temp.charAt(j) != temp.charAt(4 - j)) {
                    isPal = false;
                    break;
                }
            }
            if (isPal) {
                count++;
            }
        }

        System.out.println(count);

    }
}

Measured memory_bytes: 26580
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  n=n%10;
  if(n==2||n==4||n==5||n==7||n==9)
    cout<<"hon";
  else if(n==0||n==1||n==6||n==8)
    cout<<"pon";
  else
    cout<<"bon";
}

Measured memory_bytes: 3624
// AOJ 1189: Prime Caves
// 2017.9.21 bal4u@uu
// 2017.12.22

#include <stdio.h>
#include <string.h>

#define MAX  1020000
#define N    1010
#define SQRT 1009     // sqrt(MAX)
#define max(a,b) ((a)>=(b)?(a):(b))

char prime[MAX+2] = {1,1,0};

void mkprime()
{
	int i, j;

	for (i = 4; i <= MAX; i += 2) prime[i] = 1;
	for (i = 3; i <= SQRT; i += 2)
		if (!prime[i]) for (j = i*i; j <= MAX; j += i) prime[j] = 1;
}

typedef struct { int r, c; } PP;
PP pp[MAX+3];
int map[N+5][N+5];
int dp[N+5][N+5];
int mv[4][2] = { {-1,0},{0,-1},{1,0},{0,1} };
int m, n;

void set()
{
	int i, k, w, w2, r, c, d;

    k = 1, r = c = N >> 1, d = 3, w = 2, w2 = 1;
	while (1) {
		for (i = 0; i < w2; i++) {
			map[r][c] = k, pp[k].r = r, pp[k].c = c, k++;
			r += mv[d][0], c += mv[d][1];
			if (r < 0 || r >= N || c < 0 || c >= N) return;
		}
		if (++d == 4) d = 0;
		w++, w2 = w >> 1;
	}
}

int main()
{
	int r, c, ans, x;

	mkprime(); set();
	while (scanf("%d%d", &m, &n) && m) {
		memset(dp, -1, sizeof(dp));
		r = pp[n].r, c = pp[n].c;
		dp[r][c] = !prime[n];
		for (r = 0; r < N; r++) for (c = 0; c < N; c++) {
			if (dp[r][c] >= 0 && map[r][c] <= m) {
		        if (map[r+1][c-1] <= m)
					dp[r+1][c-1] = max(dp[r+1][c-1], dp[r][c] + !prime[map[r+1][c-1]]); 
		        if (map[r+1][c] <= m)
					dp[r+1][c]   = max(dp[r+1][c],   dp[r][c] + !prime[map[r+1][c]]); 
				if (map[r+1][c+1] <= m)
					dp[r+1][c+1] = max(dp[r+1][c+1], dp[r][c] + !prime[map[r+1][c+1]]); 
			}
		}
		ans = x = 0;
		for (r = 0; r < N; r++) for (c = 0; c < N; c++)
			if (map[r][c] <= m && !prime[map[r][c]])
				if (ans < dp[r][c]) ans = dp[r][c], x = map[r][c];
				else if (ans == dp[r][c] && x < map[r][c]) x = map[r][c];

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

Measured memory_bytes: 18788
#include <bits/stdc++.h>
#define Rep(i,j,n) for(int i=j; i<n; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<int,P>
#define T tuple<int,int,int> 
using namespace std;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


int main(){
    int n; cin >> n;
    vector<P> x,y;
    rep(i,n){
        int a,b; cin >> a >> b;
        x.emplace_back(a,i);
        y.emplace_back(b,i);
    }

    sort(all(x));
    sort(all(y));
    
    vector<PP> dis;
    rep(i,n-1){
        dis.emplace_back(x[i+1].first-x[i].first,P(x[i+1].second,x[i].second));
        dis.emplace_back(y[i+1].first-y[i].first,P(y[i+1].second,y[i].second));
    }
    sort(all(dis));

    UnionFind uf(n);
    vector<int> ok(n,0);
    ll ans=0;
    rep(i,dis.size()){
        int d=dis[i].first;
        int nx=dis[i].second.first;
        int ny=dis[i].second.second;
        if(!uf.same(nx,ny)){
            ans+=d;
            uf.unite(nx,ny);
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8612
arr = list(map(int,input().split()))

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

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

vector<int> v;

bool isOK(int index, int key) {
    if (v[index] >= key) return true;
    else return false;
}

int binary_search(int key) {
    int left = -1; 
    int right = (int)v.size(); 

    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key)) right = mid;
        else left = mid;
    }

    return right;
}

int main()
{
    int n,k;
    cin >> n >> k;
    int a[n];
    double ans = 0;
    for(int i = 0; i < n; i++){
        int tmp =  i+1;
        double p = 1.0 / n;
        while(k > tmp){
            tmp *= 2;
            p *= 0.5;
        }
        ans += p;
    }
    printf("%.12lf",ans);
 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007


int main(){
    int N; cin >> N;
    int ans = 0;
    while(N!=0){
        if(N%10==2) ans++;
        N/=10;
    }
    
    cout << ans << endl;
    return 0;
}


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

int main(){
   int l,r,d;
   cin>>l>>r>>d;
   int ans=0;
   for(;l<=r;++l){
       if(l%d==0){
           ans++;
       }
   }
   cout<<ans;
    return 0;
}



Measured memory_bytes: 3632
import itertools
while 1:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    C = itertools.combinations(range(1, n+1), 3)
    ans = 0
    for a, b, c in C:
        if a+b+c == x:
            ans  += 1
    print(ans)


Measured memory_bytes: 5632
from itertools import product
s = list(input())
n = len(s)
pattern = []
answer = 0

pattern = list(product(['+', ''], repeat=n-1))

for i in range(2 ** (n-1)):
    formula = s[0]
    for j, k in zip(pattern[i], s[1:]):
        formula += (j + k)
    answer += eval(formula)

print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
int n,k,h[M],dp[M];
int main()
{
    scanf("%d %d", &n, &k);
    REP(i,1,n) scanf("%d", &h[i]);
    
    dp[1] = 0;
    REP(i,2,n) {
        dp[i] = 2000000000;
        for (int j=i-1; j>=max(1, i-k); j--) {
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    printf("%d\n", dp[n]);
    return 0;
}



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

using namespace std;
typedef long long ll;

int T, n;
const int maxl = 3000+5;
int dp[maxl][maxl];
int path[maxl][maxl];

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;

  for(int i = 0; i <= max(s.size(), t.size()); i++) dp[0][i] = dp[i][0] = 0, path[0][i]=path[i][0]=-1;
  for(int i = 1; i <= s.size(); i++)for(int j = 1; j <= t.size(); j++)
  {
    if(s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1]+1, path[i][j] = 0;
    else if(dp[i-1][j] > dp[i][j-1]) dp[i][j] = dp[i-1][j], path[i][j] = 1;
    else dp[i][j] = dp[i][j-1], path[i][j] = 2;
  }
  //cout << dp[s.size()][t.size()];
  char ans[maxl];
  int x = s.size(), y = t.size();
  int cur = dp[x][y];
  ans[cur--] = '\0';
  while(path[x][y] != -1)
  {
    if(path[x][y] == 0) x--, y--,ans[cur--] = s[x];
    else if(path[x][y] == 1) x--;
    else y--;
  }
  cout << ans;

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  int a;
  a = s.length();
  int c = 0;
  if (a%2 == 0){
    for (int i = 0; i < (a/2); i++){
      if (s[i] != s[a-1-i]) c++;
    }
  }else{
    for (int i = 0; i < (a-1)/2; i++){
      if (s[i] != s[a-1-i]) c++;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const long long MOD = (long long)1e9 + 7;
int n, h[100009], dp[100009];


int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) cin >> h[i];
	for (int i = 0; i < n; i++) {
		if (i + 2 < n)
			dp[i + 2] = dp[i] + abs(h[i + 2] - h[i]);
		if (i + 1 < n) {
			if (i)
				dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
			else
				dp[i + 1] = dp[i] + abs(h[i + 1] - h[i]);
		}
	}
	cout << dp[n - 1] << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
A,B,K=map(int,input().split())
f=1
for k in range(K):
    print(A+k)
    if A+k==B:
        f=-1
        break
if f:
    for k in range(1,K+1):
        if B-K+k<A+K:
            continue
        print(B-K+k)


Measured memory_bytes: 3060
//0:58
#include <stdio.h>
#include <string.h>
#include <algorithm>

// 2の倍数-2の倍数
// 1の倍数-4の倍数 4の倍数-1の倍数
// 1-4-1-4-1-4-1-2-2-2-2

typedef long long ll;
ll max(ll a, ll b){return(a>b)?a:b;}
ll min(ll a, ll b){return(a<b)?a:b;}
ll abs(ll a){return(a<0)?-a:a;}

ll gcd(ll a, ll b){
        if(b > a){
                ll tmp = b;
                b = a;
                a = tmp;
        }
        if(b == 0) return a;
        else return gcd(b, a%b);
}
ll lcm(ll a, ll b){
        ll gcdi = gcd(a,b);
        return a/gcdi*(b);
}

int cnt1 = 0;
int cnt2 = 0;
int cnt4 = 0;
int main(){
        int N;
        scanf("%d",&N);
        ll a;
        for(int i = 0; i < N; i ++){
                scanf("%lld",&a);
                if(a % 4 == 0){
                        cnt4++;
                }else if(a % 2 == 0){
                        cnt2++;
                }else{
                        cnt1++;
                }
        }
        if(cnt2 == 0){
                if(cnt1 <= cnt4+1) puts("Yes");
                else puts("No");
        }else{
                if(cnt1 <= cnt4) puts("Yes");
                else puts("No");
        }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B , C ,D ;
  cin >> A >> B >> C >> D ;
  A=A+B;
  C=C+D;
  if(A<C){
    cout<<"Right"<<endl;
  }else if(A>C){
    cout<<"Left"<<endl;
  }else{
    cout<<"Balanced"<<endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n,cnt=0;
	map<char, int>mp;
	cin >> n;
	string s;
	cin >> s;
	for (auto c : s) {
		mp[c]++;
	}
	if (mp['W'] == n || mp['R'] == n)cout << 0 << endl;
	else {
		rep(i, mp['R']) {
			if (s[i] == 'W')cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 3720
#include<stdio.h>
#include<algorithm>
using namespace std;
int sum[3];
int main()
{
    int p,q,r;
    int sum1,sum2,sum3;
    scanf("%d%d%d",&p,&q,&r);
    sum[0]=p+q;
    sum[1]=p+r;
    sum[2]=q+r;
    sort(sum+0,sum+3);//855555
    printf("%d",sum[0]);
    return 0;
}


Measured memory_bytes: 128
S = input()
N = len(S)
k = [0]
result = [0] * N

for i in range(N-1):
  if S[i] != S[i+1]:
    k.append(i+1)
l = [k[i+1] - k[i] for i in range(len(k) - 1)] + [N - k[-1]]

for i in range(1, len(k), 2):
  result[k[i]] += (l[i] + 1) // 2 + l[i-1] // 2
  result[k[i]-1] += l[i] // 2 + (l[i-1] + 1) // 2
print(*result)


Measured memory_bytes: 11108
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var L = sc.nextLong();
        var R = sc.nextLong();

        if (L % 2019 == 0 || R % 2019 == 0) {
            WriteLine(0);
            return;
        }

        if (L / 2019 == R / 2019) {
            var Lmod = (int)L % 2019;
            var Rmod = (int)R % 2019;
            var min = int.MaxValue;
            for (int i = Lmod; i < Rmod; i++) {
                for (int j = i+1; j <= Rmod; j++) {
                    min = Math.Min((i * j) % 2019, min);
                }
            }
            WriteLine(min);

        } else {
            WriteLine(0);
        }

    }


}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


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

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int a, b, c, k; cin >> a >> b >> c >> k;
  
  int m = 0;
  
  if(a+b >= k) {
    m = min(a, k);
  }
  else {
    k -= a+b;
    m = a-k;
  }
  
  cout << m << endl;

  
  return 0;
}




Measured memory_bytes: 3648
#include<stdio.h>

#include <string.h>

int main(void){

  int i;

  char S[1002];
char A[1005];
  char s[] = "s";

  char es[] = "es";

  scanf("%s",S);

  i = strlen(S);
if(S[i-1] == 115){
sprintf(A,"%s%s\n",S,es);
  printf(A);

    return 0;

}

  else{
sprintf(A,"%s%s\n",S,s);
  printf(A);

    return 0;

  }

}


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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<vector<string>> q(n, vector<string>(0));
    int p;
    string s;

    for (int i=0; i<m; i++) {
        cin >> p >> s;
        q.at(p-1).push_back(s);
    }
    
    int answer = 0;
    int penalty = 0;

    for (int i=0; i<n; i++) {
        int count = 0;

        for (int j=0; j<q.at(i).size(); j++) {
            if (q.at(i).at(j) == "AC") {
                answer++;
                penalty += count;
                break;
            }
            
            count++;
        }
    }

    cout << answer << " " << penalty << endl;

    return 0;

}


Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];

    sort(x.begin(), x.end());
    int ans, tmp;
    ans = INF;
    for(int i = x[0]; i <= x[n-1]; i++) {
        tmp = 0;
        for(int j = 0; j <= n-1; j++) {
            tmp += (i-x[j])*(i-x[j]);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from sys import stdin
N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

X = A[0]
index = 0
cnt = 0

while index < N:
    end_index = min(index + K, N)
    sub = [A[x] for x in range(index, end_index)]
    flag = 0
    for k in range(len(sub)):
        if sub[k] != X:
            A[k + index] = X
            flag += 1
    if flag != 0:
        cnt += 1
    index += K - 1

print(cnt)

Measured memory_bytes: 13880
# n,m=map(int,input().split())
# a=[]
# a.append(list(map(int,input().split())))

n,m, = map(int,input().split())
par = [i for i in range(n+1)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y

def size(x):
    return -par[find(x)]

# def size(self, x):
#         return -self.parents[self.find(x)]

for i in range(m):
    a,b = map(int,input().split())
    unite(a,b)

li = [0]*(n+1)
for i in range(1,n+1):
    li[(-size(par[i]))] = 1

print(li.count(1)-1)

Measured memory_bytes: 77128
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int x,y;
int main(){
    scanf("%d%d",&x,&y);
    if(x<=0&&y>=0)puts("Zero");
    else if(x>0)puts("Positive");
    else if((y-x)&1)puts("Positive");
    else puts("Negative");
    //system("pause");
    return 0;
}


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

int main() {
  string N; int k;
  cin >> N >> k;
  int dig = N.size();
  int dp0[dig+1][max(dig+1,4)], dp1[dig+1][max(dig+1,4)];
  for(int i=0;i<=dig;i++){for(int j=0;j<=max(dig,3);j++){dp0[i][j]=0;dp1[i][j]=0;}}
  int n = N[0]-'0';
  for(int d=0;d<=9;d++){
      dp0[1][d>0] += d<n;
      dp1[1][d>0] += d==n;
  }
  for(int i=1;i<dig;i++){
    int n = N[i]-'0';
    for(int j=0;j<=i;j++){
      for(int d=0;d<=9;d++){
        dp0[i+1][j+(d>0)] += dp0[i][j] + (d<n)*dp1[i][j];
        dp1[i+1][j+(d>0)] += (d==n)*dp1[i][j];
      }
    }
  }
  cout << dp0[dig][k]+dp1[dig][k] << endl;
}


Measured memory_bytes: 384
n,b,f[50001];main(a){for(;++a<50001;)for(b=a;(b+=a)<50001;)f[a]||f[b]++;for(;scanf("%d",&n),n;printf("%d\n",b))for(b=0,a=1;a++<n/2;)f[a]+f[n-a]||b++;exit(0);}

Measured memory_bytes: 596
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vpii = vector<pii>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
int main() {
	int t, p, r;
	while (cin >> t >> p >> r, t) {
		vector<tuple<int, int, int, vi>> buf(t, make_tuple(0, 0, 0, vi(p + 1)));//-ac,pena,team
		rep(i, t) {
			get<2>(buf[i]) = i + 1;
		}
		rep(j, r) {
			int t, p, time;
			string mes;
			cin >> t >> p >> time >> mes;
			t--;
			get<3>(buf[t])[p] +=(mes[0]=='W'?1200:time);
			if (mes[0] == 'C') {
				get<0>(buf[t])--;
				get<1>(buf[t]) += get<3>(buf[t])[p];
			}
		}
		sort(ALL(buf));
		for (auto &a : buf) {
			cout << get<2>(a) <<' '<< -get<0>(a) <<' '<< get<1>(a) << endl;
		}
	}
}

Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

constexpr ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    string s; 
    cin >> s;

    vector<int> cnt(26, 0);
    for (auto &&c: s) ++cnt[c-'a'];

    ll ans = 1;
    for (auto &&e: cnt) {
        ans *= (e+1);
        ans %= mod;
    }

    cout << ans-1 << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define INPUT(X) cin >> X
#define OUTPUT(X) cout << X << endl
#define REPEAT(i,n) for(int i=0;i<n;i++ )

using namespace std;

typedef long long int ll;
const ll MOD = 1e9+7;

inline ll Upstair(ll n){
	ll rt;
	if(n==1) return 1;
	return n*Upstair(n-1);
}

int main(void) {


	int a;
	string s;
	INPUT(a);
	INPUT(s);

	string ans;

	if( a >= 3200 ){
		ans = s;
	}else{
		ans = "red";
	}

	OUTPUT(ans);
		
}

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

# レベル0バーガー P
# レベル1バーガー BPPPB
# P[i] = レベルiバーガーのパティの枚数
# B[i] = レベルiバーガーの厚さ

P = [0] * 51
B = [0] * 51

P[0] = 1
B[0] = 1

for i in range(1, len(P)):
  P[i] = P[i - 1] * 2 + 1
  B[i] = B[i - 1] * 2 + 3

# レベルnバーガーを丸ごと食べたときのパティの枚数を求める
def get_whole_barger(n):
  return P[n]

# レベルnバーガーをx枚目まで食べたときのパティの枚数を求める
def get_patty(n,x):
  if n == 0 or x == 0:
    return P[0]
  if B[n] == x:
    return P[n]
  if x <= 1:
    return 0
  if x <= 1 + B[n - 1]:
    return get_patty(n - 1, x - 1)
  if x <= 2 + B[n - 1]:
    return get_whole_barger(n - 1) + 1
  if x <= 2 + B[n - 1] * 2:
    return get_whole_barger(n - 1) + 1 + get_patty(n - 1, x - 2 - B[n - 1])
  else:
    return get_whole_barger(n - 1) + 1 + get_whole_barger(n - 1)

print(get_patty(N,X))

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

int main() {

  ll A,B,C,D;
  cin >> A >> B >> C >> D;

  if(A*B >= C*D){
    cout << A*B;
  }
  else{
    cout << C*D;
  }

return 0;
}

Measured memory_bytes: 3524