akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

template <typename T>
struct edge {
  int s, t;
  T c;
  edge() {}
  edge(int t, T c) : s(-1), t(t), c(c) {}
  edge(int s, int t, T c) : s(s), t(t), c(c) {}
};

template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T>
void warshall_floyd(Matrix<T> &g, T inf) {
  for (int k = 0; k < g.size(); k++) {
    for (int i = 0; i < g.size(); i++) {
      for (int j = 0; j < g.size(); j++) {
        if (g[i][k] == inf || g[k][j] == inf) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N;
  cin >> N;
  Matrix<int> A(N,vector<int>(N,INF)), G(N,vector<int>(N,INF));
  REP(i,N) REP(j,N) cin >> A[i][j];
  int ans = 0;
  REP(i,N) G[i][i] = 0;
  REP(i,N) REP(j,N) if (i < j) {
    bool ok = true;
    REP(k,N) if (k != i && k != j) {
      if (A[i][j] == A[i][k] + A[k][j]) ok = false;
    }
    if (ok) G[i][j] = G[j][i] = A[i][j], ans += A[i][j];
  }
  warshall_floyd(G,INF);
  REP(i,N) REP(j,N) {
    if (G[i][j] != A[i][j]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
F1=[]
F2=[]
for i in range(N):
    F=list(map(int,input().split()))
    F1.append(F[::2])
    F2.append(F[1::2])
P=[list(map(int,input().split())) for _ in range(N)]

ans=-float("inf")
for i in range(1,2**10):
    F_am=[0]*5
    F_pm=[0]*5
    for j in range(5):
        F_am[j]=i%2
        i//=2
        F_pm[j]=i%2
        i//=2
    c=[0]*N
    for j in range(N):
        for k in range(5):
            if F_am[k]==1 and F1[j][k]==1:
                c[j]+=1
            if F_pm[k]==1 and F2[j][k]==1:
                c[j]+=1
    val=0
    for j in range(N):
        val+=P[j][c[j]]
    ans=max(ans,val)
print(ans)

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

using namespace std;
int v[1000010];
int memo[1000010];
int c;

int f(int i)
{

    if(memo[i]!=-1)
        return memo[i];

    if(i == 0)
        return memo[0] = 0;

    if(i == 1)
        return memo[1] = abs(v[0] - v[1]);

    return memo[i] = min(abs(v[i] - v[i-1]) + f(i-1), abs(v[i] - v[i-2]) + f(i-2));
}

int main()
{

    memset(memo, -1, sizeof(memo));
    cin>>c;

    for(int i = 0; i<c; i++)
    {
        cin>>v[i];
    }

    cout<<f(c-1)<<endl;

    return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, h;
int a[100005], b[100005];
int main() {
	scanf("%d%d", &n, &h);
	for (int i = 0; i < n; ++ i) scanf("%d%d", &a[i], &b[i]);
	int mxa = 0;
	for (int i = 0; i < n; ++ i) mxa = max(mxa, a[i]);
	sort(b, b + n);
	reverse(b, b + n);
	ll cur = 0;
	ll ans = 1e18;
	for (int i = 0; i <= n; ++ i) {
		ans = min(ans, i + (h <= cur ? 0 : (h - cur - 1) / mxa + 1));
		cur += b[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <cmath>
#include <utility>
using namespace std;

#define EPS 1e-8

typedef complex<double> P;
typedef const P &rP;

const double pi = acos(-1.0);

void intrcc(rP p1, double r1, rP p2, double r2, vector<P> &ret){
	double d = abs(p2 - p1);
	double phi = arg(p2 - p1);
	
	double ct = (d * d + r1 * r1 - r2 * r2) / (2.0 * d * r1);
	if(abs(d) < EPS || abs(ct) > 1.0 + EPS){ return; }
	if(ct > 1.0){ ct = 1.0; }
	else if(ct < -1.0){ ct = -1.0; }
	
	double theta = acos(ct);

	ret.push_back(p1 + polar(r1, phi + theta));
	ret.push_back(p1 + polar(r1, phi - theta));
}

int main(){
	vector<P> chk;
	chk.reserve(100000);

	int n;
	while(scanf("%d", &n), n){
		chk.clear();

		vector<P> ps(n);
		double x, y;
		for(int i = 0; i < n; ++i){
			scanf("%lf%lf", &x, &y);
			ps[i] = P(x, y);
			
			for(int j = 0; j < i; ++j){
				intrcc(ps[i], 1.0, ps[j], 1.0, chk);
			}
		}
		
		int ans = 1;
		for(int i = 0; i < chk.size(); ++i){
			int cnt = 0;
			for(int j = 0; j < n; ++j){
				if(abs(ps[j] - chk[i]) < 1.0 + EPS){
					++cnt;
				}
			}
			ans = max(ans, cnt);
		}

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

Measured memory_bytes: 1532
#include<bits/stdc++.h>
  
 using namespace std;
  
 void __print(int x) {cerr << x;}
 void __print(long x) {cerr << x;}
 void __print(long long x) {cerr << x;}
 void __print(unsigned x) {cerr << x;}
 void __print(unsigned long x) {cerr << x;}
 void __print(unsigned long long x) {cerr << x;}
 void __print(float x) {cerr << x;}
 void __print(double x) {cerr << x;}
 void __print(long double x) {cerr << x;}
 void __print(char x) {cerr << '\'' << x << '\'';}
 void __print(const char *x) {cerr << '\"' << x << '\"';}
 void __print(const string &x) {cerr << '\"' << x << '\"';}
 void __print(bool x) {cerr << (x ? "true" : "false");}
  
 template<typename T, typename V>
 void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
 template<typename T>
 void __print(vector<vector<T>> x){cerr<<"\n{"; int f=x.size();for(int i=0;i<f;i++){cerr<<"("; int g=x[i].size(); for(auto j:x[i]){cerr<<j; (--g!=0)?cerr<<",":cerr<<"";}cerr<<")\n";}cerr<<"}";}
 template<typename T>
 void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
 void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
 void _print() {cerr << "]\n";}
 template <typename T, typename... V>
 void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  
 #ifndef ONLINE_JUDGE
 #define trace(x...) cerr << "[" << #x << "] = [", _print(x)
 #else
 #define trace(x...)
 #endif
  
 template<typename... T>
 void read(T&... args) {
     ((cin >> args), ...);
 }
  
 template<typename... T>
 void writ(T&&... args) {
     ((cout << args << " "), ...);
 }
 #define ull unsigned long long
 #define ll long long
 #define MOD 1000000007
 #define INF (ll)1e18
 #define IINF (int)1e9
 #define EPS 1e-9
 
 int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int n,x,t; cin>>n>>x>>t;
     cout<<(int)(ceil(double(n)/x)*t);
     return 0;
 }
 
 

Measured memory_bytes: 3624
h,w = map(int,input().split())
s = [input() for _ in range(h)]

l = [[0] * w for _ in range(h)]
r = [[0] * w for _ in range(h)]
u = [[0] * w for _ in range(h)]
d = [[0] * w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i][j] = 0
        else:
            if j == 0:
                l[i][j] = 1
            else:
                l[i][j] = l[i][j-1] + 1

for i in range(h):
    for j in range(w-1, -1, -1):
        if s[i][j] == '#':
            r[i][j] = 0
        else:
            if j == w-1:
                r[i][j] = 1
            else:
                r[i][j] = r[i][j+1] + 1

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            u[i][j] = 0
        else:
            if i == 0:
                u[i][j] = 1
            else:
                u[i][j] = u[i-1][j] + 1

for i in range(h-1, -1 ,-1):
    for j in range(w):
        if s[i][j] == '#':
            d[i][j] = 0
        else:
            if i == h-1:
                d[i][j] = 1
            else:
                d[i][j] = d[i+1][j] + 1

ans = 0

for i in range(h):
    for j in range(w):
        ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3)

print(ans)


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

int main(){
  int a, b, c, d; cin>>a>>b>>c>>d;
  int x = abs(a-b);
  int y = abs(b-c);
  int z = abs(a-c);
  if((x<=d && y<=d) || z<=d) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 左右で分けてそれぞれ全探索
N = ir()
S = sr()
answer = 0
latter = S[N:][::-1]

dic_left = defaultdict(int)
for pattern in range(1<<N):
    red = ''; blue = ''
    for i in range(N):
        if pattern>>i & 1:
            red += S[i]
        else:
            blue += S[i]
    key = (red, blue)
    if key in dic_left:
        dic_left[key] += 1
    else:
        dic_left[key] = 1

dic_right = defaultdict(int)
for pattern in range(1<<N):
    red = ''; blue = ''
    for i in range(N):
        if pattern>>i & 1:
            red += latter[i]
        else:
            blue += latter[i]
    key = (red, blue)
    if key in dic_right:
        dic_right[key] += 1
    else:
        dic_right[key] = 1

answer = 0
for k, v in dic_left.items():
    if k in dic_right:
        answer += v * dic_right[k]

print(answer)
# 解説


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

int main()
{
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  int sum = a1 + a2 + a3;
  if (sum > 21)
    cout << "bust" << endl;
  else
    cout << "win" << endl;
  return 0;
}

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

int main() {
  int attend;
  cin >> attend;
  int first_score;
  cin >> first_score;
  int round_count;
  cin >> round_count;
  
  vector<int> round(round_count);
  for (int i = 0; round_count > i; i++) {
   cin >> round.at(i); 
  }
  
  map<int, int> cnt;
  for (int i = 1; i <= attend;i++) {
    cnt[i] = 0;
  }

  for (int x : round) {
    cnt.at(x)++;
  }

  for (int i = 1; i <= attend;i++) {
    int res_score = first_score - (round_count - cnt.at(i));
    if ( 0 < res_score) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 5760
S=input()
if S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]:
    print("Yes")
elif S[0]==S[2] and S[1]==S[3] and S[0]!=S[1]:
    print("Yes")
elif S[0]==S[3] and S[1]==S[2] and S[0]!=S[1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
	ios;
	string s,t;
	int i,j,k,mx=0,c;
	cin>>s>>t;
	int l=s.length(), p=t.length();
	for(i=0;i<=l-p;i++)
	{
		k=i; c=0;
		for(j=0;j<p;j++)
		{
			if(s[k]==t[j]) c++;
			k++;
		}
		mx=max(mx,c);
	}
	cout<<p-mx;
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <ctime>
using namespace std;

const unsigned long long BASE = (unsigned long long)(1e9 + 7);

#define FROM_0(i, n) for(int i = 0; i < (n); i++)
#define FROM_S(i, s, e) for(int i = (s); i < (e); i++)
#define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter != vec.end(); iter++)

int main()
{
    string s, t;
    cin >> s >> t;
    int minChange = t.length();
    FROM_0(i, s.length())
    {
        int change = 0;
        FROM_0(j, t.length())
        {
            if (i + j >= s.length())
            {
                change = t.length();
                break;
            }
            if (s[i + j] != t[j])
                change++;
        }
        minChange = min(change, minChange);
    }
    cout << minChange << endl;
}


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

int main(){
  string s;
  cin >> s;
  if(((s[0]==s[1])&&(s[1]==s[2]))||((s[1]==s[2])&&(s[2]==s[3]))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
  ll h, w, n;
  cin >> h >> w >> n;
  vector<ll> blacks(10);
  blacks[0] = (h-2) * (w - 2);

  set<pair<int, int>> board;

  for (int i=0; i<n; i++){
    int a, b;
    cin >> a >> b;

    bool mem[5][5];
    for (int x=0; x<5; x++){
      for (int y=0; y<5; y++){
        if (x==2 && y==2) mem[x][y] = true;
        else if (board.count(make_pair(a+x-2, b+y-2))) mem[x][y] = true;
        else mem[x][y] = false;
      }
    }

    for (int x=1; x<4; x++){
      for (int y=1; y<4; y++){
        int xx=a+x-2, yy=b+y-2;
        if (xx-1<1 || h<xx+1 || yy-1<1 || w<yy+1) continue;
        int num = 0;
        for (int mx=-1; mx<=1; mx++){
          for (int my=-1; my<=1; my++){
            if (mem[x+mx][y+my]) num++;
          }
        }
        blacks[num-1]--;
        blacks[num]++;
      }
    }
    board.insert(make_pair(a, b));

  }

  for (int i=0; i<10; i++){
    cout << blacks[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
    int n; cin >> n;

    cout << n * (n + 1) / 2 << endl;

    return 0;
}


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

int main(){
  int N,H,max,ans=1;
  cin >> N >> max;
  for(int i=1;i<N;i++){
    cin >> H;
    if(H>=max){
      max=H;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
function main()
  
  (A,B) = map(x -> parse(Int,x), split(readline()))
  
  ans = 0
  
  for i in 1:2
    
    if A > B
      ans += A
      A -= 1
    else
      ans += B
      B -= 1
    end
    
  end
  
  println(ans)
  
end
    
main()

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  double ans = 0.0;
  for (int dice = 1; dice < n + 1; dice++) {
    int score = dice;
    int count = 0;
    while (score < k) {
      score *= 2;
      count++;
    }
    ans += 1.0 / (pow(2, count) * (double)n);
  }
  printf("%.9lf\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
char s[120000];
int n;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i+=2) putchar(s[i]);
	putchar('\n');
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)

int main() {
	double rank[4] = {INF, 1.1, 0.6, 0.2};
	
	double in[2];
	int ans[2][4] = {};
	while (cin >> in[0] >> in[1]) {
		REP(i, 2) {
			int g = 0;
			REP(j, 4) if (in[i] < rank[j]) g++;
			ans[i][g - 1]++;
		}
	}
	
	REP(i, 4) printf("%d %d\n", ans[0][i], ans[1][i]);
	return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;
#define MOD 1000000007;

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif



int N;
int p, maxim;
lli ANS;

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

	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> p;
		ANS += p;
		maxim = max(p, maxim);
	}
	cout << ANS - maxim/2;

	return 0;
}


Measured memory_bytes: 256
size = 500001
mod = 10 ** 9 + 7
fac = [0] * size
finv = [0] * size
inv = [0] * size

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, size):
    fac[i] = fac[i-1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i-1] * inv[i] % mod

def nPr(n, r, mod):
    if n < 0 or r < 0 or n < r:
        return 0
    return fac[n] * finv[n-r] % mod

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, size + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def nCr(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N, M = map(int,input().split())

ans = 0
flag = 1

for k in range(N+1):
    ans += flag * nPr(M - k, N - k, mod) * nCr(N, k, mod) * nPr(M, N, mod)
    flag *= -1
    ans %= mod

print(ans)

Measured memory_bytes: 196848
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	ll N, A, B; cin >> N >> A >> B;

	ll cnt = N / (A + B);
	ll x = N - cnt * (A + B);

	if (x <= A)cout << cnt * A  + x<< endl;
	else cout << cnt * A + A<< endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,b,c;
  int cnta=0,cntb=0;
  while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
    if(a*a+b*b==c*c)cnta++;
    else if(a==b)cntb++;
  }
  cout<<cnta<<endl<<cntb<<endl;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  string s; std::cin >> s;
  vi r, g, b;
  rep(i, n) {
    if (s[i] == 'R') r.pb(i);
    else if (s[i] == 'G') g.pb(i);
    else b.pb(i);
  }
  int rsz = r.size(), gsz = g.size(), bsz = b.size();
  ll ans = 0;
  for (int p1 : r) for (int p2 : g) {
    int pp1 = p1;
    if (pp1 > p2) swap(pp1, p2);
    int diff = p2 - pp1;
    ans += bsz;
    if (binary_search(rng(b), pp1-diff)) ans--;
    if (diff % 2 == 0 && binary_search(rng(b), pp1+diff/2)) ans--;
    if (binary_search(rng(b), p2+diff)) ans--;
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 3672
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<=4;i++){
    cout<<s[i];
  }
  cout<<" ";
  for(int i=6;i<=12;i++){
    cout<<s[i];
  }
  cout<<" ";
  for(int i=14;i<=18;i++){
    cout<<s[i];
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#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 debug(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

const int MAX_N = 7 + 100000;
///----------------------------------------------
char str[MAX_N];
int main() {

	///read
	scanf(" %s", str);
	int len = strlen(str);

	///work
	rep(i,0,len) {
		if (i+1<len && str[i]==str[i+1]) {
			cout << i+1 << " " << i+2;
			return 0;
		}
		if (i+2<len && str[i]==str[i+2]) {
			cout << i+1 << " " << i+3;
			return 0;
		}
	}

	///print
	cout << "-1 -1";

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n, a, b, h[100020];
int main() {
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}
	long long L = 0, R = 1e9;
	while (L < R - 1) {
		long long M = (L + R) / 2, c = 0;
		for (int i = 0; i < n; i++) {
			c += max(h[i] - M * b + a - b - 1, 0LL) / (a - b);
		}
		if (M < c) {
			L = M;
		} else {
			R = M;
		}
	}
	printf("%lld\n", R);
	return 0;
}

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

using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, w, m = 0;
    cin >> n >> w;
    ll p[n], v[n];
    for(int i = 0; i < n; ++i) {
        cin >> p[i] >> v[i];
        m += v[i];
    }
    ll dp[m + 1];
    for(int i = 0; i <= m; ++i) dp[i] = INT_MAX;
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = m; j >= v[i]; --j) {
            dp[j] = min(dp[j], dp[j - v[i]] + p[i] );
        }
    }
    ll ans = 0;
    for(int i = m; i >= 0; i-- ) {
        if (dp[i] <= w) {
            ans = i; break;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

const int n_max = 1005;
int bmap[n_max][n_max] = {0}; 


/*
[check]map探索系の実装が面倒


*/

int main()
{
    int h, w;
    cin >> h >> w;

    queue<P> q;
    for (int i = 1; i <= h; i++)
    {
        string s; cin>>s;
        for (int j = 1; j <= w; j++)
        {
            if (s[j-1] == '#'){
                bmap[i][j] = 0;
                q.emplace(i, j);
            } else {
                bmap[i][j] = 10000;
            }          
        }
    }

    vector<P> ope(4);
    ope[0] = {1,0};
    ope[1] = {-1,0};
    ope[2] = {0,1};
    ope[3] = {0,-1};
    
    while(!q.empty()){
        auto now = q.front(); q.pop();
        for(auto o: ope){
            int nx = now.first + o.first;
            int ny = now.second + o.second;
            if (bmap[nx][ny] != 10000) continue;
            bmap[nx][ny] = bmap[now.first][now.second] + 1;
            q.emplace(nx,ny);
        }
    }

    int ans = 0;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {   
            //cout << bmap[i][j];
            ans = max(ans, bmap[i][j]);
        }
        //cout<<endl;
    }

    cout << ans << endl;    
}



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

using namespace std;

int main()
{
	char s1[100001], t1[100001];
	scanf("%s %s", s1, t1);
	string s(s1), t(t1);
	int q;
	cin >> q;
	vector<int> pre1(s.size() + 1), pre2(t.size() + 1);
	for (int i = 0; i < s.size(); ++i)
	{
		int val = s[i] == 'A' ? 2 : 1;
		pre1[i + 1] = pre1[i] + val;
	}
	for (int i = 0; i < t.size(); ++i)
	{
		int val = t[i] == 'A' ? 2 : 1;
		pre2[i + 1] = pre2[i] + val;
	}
	for (int i = 0; i < q; ++i)
	{
		int a, b, c, d;
		scanf("%d %d %d %d", &a, &b, &c, &d);
		--a, --c;
		int c1 = pre1[b] - pre1[a] - pre2[d] + pre2[c];
		if (c1 % 3 == 0)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

}


Measured memory_bytes: 1792
<?php
//error_reporting(0);
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($A,$B,$N) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$x=$N;
if ($N >= $B-1) $x = $B-1;

printf("%d\n",floor($A*$x/$B)-$A*floor($x/$B));


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

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> st(26);
    rep(i,n) st[s[i]-'a'].insert(i);
    rep(i,q) {
        int a;
        cin >> a;
        if (a == 1) {
            int id;
            char c;
            cin >> id >> c;
            id--;
            st[s[id]-'a'].erase(id);
            s[id] = c;
            st[s[id]-'a'].insert(id);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            int ans = 0;
            rep(j, 26) {
                auto it = st[j].lower_bound(l);
                if (it!=st[j].end() && *it<r) ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24196
#include <bits/stdc++.h>
using namespace std;
void no() {
    cout << "WA";
    exit(0);
}
int main() {
    ios_base::sync_with_stdio(false);
  //  freopen("input.txt", "r", stdin);
    string s;
    cin >> s;
    if (s[0] != 'A') no();
    // 0, 1, 2
    // s.size() - 1, s.size() - 2
    int cnt = 0;
    for (int i = 2; i <= s.size() - 2; i++) {
        if (s[i] == 'C') cnt++;
    }
    if (cnt != 1) no();
    cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] >= 'A' && s[i] <= 'Z') cnt++;
    }
    if (cnt != 2) no();
    cout << "AC";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
const int MaxN = 1e5 + 5;
char a[MaxN];
char flag[30];
bool fl[30];
int main(){
	while(~scanf("%s",&a)){
		int f = 97;
		int len = strlen(a);
		for(int i = 1;i<=26;i++){
			flag[i] = f;
			f++;
		}
		for(int i = 0;i<len;i++){
			for(int j = 1;j<=26;j++){
				if(a[i]==flag[j]){
					fl[j] = 1;
				}
			}
		}
		for(int i = 1;i<=26;i++){
			if(fl[i]==0){
				printf("%c\n",flag[i]);
				return 0;
			}
		}
		printf("None\n");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int H, W;
string S;
vi va, vb;
int field[30][30];

void input() {
  cin >> H >> W;
  rep(i, 1, H) {
    ;
    ;
    rep(j, 1, W) {
      char c;
      cin >> c;
      field[i][j] = (c == '#' ? 0 : 1);
      ;
    }
  };
  ;
}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0};
void solve() {
  // rep(i, 1, H) {
  //   rep(j, 1, W) { cout << field[i][j] << " "; }
  //   cout << endl;
  // };
  // 400 とおり？

  // wfs?
  int ans = -1;
  rep(sth, 1, H) {
    ;
    rep(stw, 1, W) {  // wfs
      // set<pii> st;
      if (!field[sth][stw]) continue;
      int table[23][23];
      rep(i, 0, 22) { rep(j, 0, 22) table[i][j] = -1; }
      queue<pii> q;
      q.push(pii(sth, stw));
      table[sth][stw] = 0;
      while (q.size()) {
        // debug(q.size());
        pii qq = q.front();
        q.pop();
        // pii qq = q1.first;
        // st.insert(qq);

        int nowh = qq.first, noww = qq.second;
        // int cnt = q1.second;
        // ans = max(ans, cnt);
        chmax(ans, (table[nowh][noww]));
        rep(i, 0, 3) {
          int nexth = nowh + dh[i];
          int nextw = noww + dw[i];
          if (table[nexth][nextw] != -1) {
            continue;
          }
          if ((nexth < 1) || (nextw < 1) || (nexth > H) || (nextw > W)) {
            continue;
          } else {
            if (field[nexth][nextw] && (table[nexth][nextw] == -1)) {
              table[nexth][nextw] = table[nowh][noww] + 1;
              q.push(pii(nexth, nextw));

            } else {
              continue;
            }
          }
        }
      }
      // rep(i, 1, H) {
      //   rep(j, 1, W) {
      //     // debug(table[i][j]);
      //   }
      // }
      // debug2(sth, stw);
      // debug(ans);
    }
  }
  cout << ans << endl;

  ;
}
signed main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n=1;
    scanf("%d",&n);
    int t[n];
    for(int i=0;i<n;i++){
        scanf("%d",&t[i]);
    }
    int m=1;
    scanf("%d",&m);
    int p[m],x[m];
    for(int i=0;i<m;i++){
        scanf("%d%d",&p[i],&x[i]);
    }
    for(int i=0;i<m;i++){
        int sum=0;
        for(int j=0;j<n;j++){
            if(j+1==p[i]){
                sum+=x[i];
            }else{
                sum+=t[j];
            }
        }
        printf("%d\n",sum);
    }
}

Measured memory_bytes: 128
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(now, ContestType):
  res = c[ContestType] * (now - LastDay[ContestType])
  return res

def nasu(now, x, y, z):
  res = 0
  res += s[now-1][x]
  res += s[now][y]
  res += s[now+1][z]
  if x == y == z:
    res += (D - now) * ((now - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * (1 * c[y])
    now += 1
    res += (D - now) * (1 * c[z])
  elif x == y:
    res += (D - now) * ((now - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * (1 * c[y])
    now += 1
    res += (D - now) * ((now - LastDay[z]) * c[z])
  elif y == z:
    res += (D - now) * ((now - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((now - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * (1 * c[z])
  elif x == z:
    res += (D - now) * ((now - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((now - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * (2 * c[z])
  else:
    res += (D - now) * ((now - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((now - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * ((now - LastDay[z]) * c[z])
  return res

D = I()
c = IL()
s = [IL() for i in range(D)]

LastDay = [0]*26
for i in range(1,D+1-2):
  tmp = ["", 0]
  for x in range(26):
    for y in range(26):
      for z in range(26):
        score = nasu(i, x, y, z)
        if tmp[1] < score:
          tmp = [(x, y, z), score]
  LastDay[tmp[0][0]] = i
  print(tmp[0][0]+1)
else:
  print(tmp[0][1]+1)
  print(tmp[0][2]+1)

Measured memory_bytes: 74972
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<long long int> d(n*2);
	for (int i = 0; i < 2*n; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	long long int sum = 0;
	for (int i = 0; i < 2*n; i+=2) {
		sum += d[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let c1: Vec<char> = parse_line::<String>().unwrap().chars().collect();
    let c2: Vec<char> = parse_line::<String>().unwrap().chars().collect();
    let c3: Vec<char> = parse_line::<String>().unwrap().chars().collect();

    println!("{}{}{}", c1[0], c2[1], c3[2]);
}


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

ll solve() {
    ll N, a;
    cin >> N;
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        while ( a % 2 == 0 ) {
            a /= 2;
            ans++;
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
l = [list(map(int,input().split())) for _ in range(3)]
m = [[0, 0, 0] for _ in range(3)]

for i in range(3):
    for j in range(3):
        m[i][j] = l[i][j] - l[0][j]

for i in range(3):
    f = True
    for j in range(3):
        if m[i][j] != m[i][0]:
            f = False
            break
    if not f:
        print('No')
        exit()

print('Yes')

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

int main() {
    for (int i=1; i<=10000; i++) {
        int d;
        cin >>d;
        if (0==d)
            break;
        cout <<"Case " <<i <<": " <<d <<endl;
    }
    return 0;
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#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 REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}

int bitCount(int x){
  int ret = 0;
  while(x){
    if(x & 1) ret++;
    x >>= 1;
  }

  return ret;
}

void solve(){
  int N;
  cin >> N;

  int A[15+5];
  int vv[16][16];
  memset(vv, -1, 16*16*sizeof(int));

  rep(i, N){
    cin >> A[i];
    rep(j, A[i]){
      int a, b;
      cin >> a >> b;
      a--;
      vv[i][a] = b;
    }
  }

  int ans = 0;
  for(int i = 0; i < (1 << N); i++){
    rep(j, N){
      if(i & (1 << j)){
        rep(k, N){
          if(vv[j][k] != -1 && vv[j][k] != ((i >> k) & 1)){
            goto doublebreak;
          }
        }
      }
    }
    ans = max(ans, bitCount(i));
  doublebreak:;
  }

  cout << ans << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int N=100020;
int v[3],p[N],q[N];
int main(){
    int n;cin >> n;
    string s;
    for(int i=0;i<3;i++)cin >> v[i];
    for(int i=1;i<=n;i++){
        cin >> s;
        p[i]=s[0]-'A';
        q[i]=s[1]-'A';
    }
    for(int i=1;i<=n;i++){
        if(v[p[i]]>v[q[i]])swap(p[i],q[i]);
        else if(v[p[i]]==v[q[i]])
            if(i<n&&(q[i]==q[i+1]||q[i]==p[i+1]))swap(p[i],q[i]);
        if(!v[q[i]])return 0*printf("No\n");
        v[p[i]]++,v[q[i]]--;
    }
    puts("Yes");
    for(int i=1;i<=n;i++) printf("%c\n",'A'+p[i]);
    return 0;
}

Measured memory_bytes: 4484
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int max = -1;
  int tempN = 0;
  int diff = 0;
  cin >> N;

  vector<int> card(N+1);     //最後に0のカードを付け加えておく　条件分岐がめんどいので

  for(int i = 0; i < N; i++)
    cin >> card.at(i);

  for(int i = 0; i < N; i++){
    for(int j = i; j < N; j++){
       if(max < card.at(j)){
          tempN = j;
          max = card.at(j);
       }
    }
    card.at(tempN) = card.at(i);
    card.at(i) = max;
    max = -1;                                        //最大値保管変数の初期化
  }


  for(int i = 0; i < (N+1)/2; i++)
    diff += card.at(2*i) - card.at(2*i+1);    //最後の0のカードが考慮されたりされなかったり

  cout << diff << endl;

}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll mini = LONG_LONG_MAX;
    ll sections;
    cin >> N;
    rep(i, 5) {
        ll temp;
        cin >> temp;
        mini = min(mini, temp);
    }
    sections = N / mini + !!(N % mini);
    cout << 6 - sections + 2 * (sections - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto a = RDR.ARR;
	a.sort();
	
	writeln(a[0] == 5 && a[1] == 5 && a[2] == 7 ? "YES" : "NO");
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=float('inf')
dp=[INF]*N
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1,1):
        if i+j>N-1:
            break
        dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
print(dp[N-1])


Measured memory_bytes: 55008
#include<cstdio>
#include<cstring>
#include<algorithm>
#define x first
#define y second
using namespace std;
typedef long long LL;
 
const int maxn = 200009;
pair<int,int> a[maxn];
int n, tmp, _mx, _mn, mx, mn, best; 
LL ans = 1e18;
 
int main(){
	scanf("%d", &n);
	if (n == 1) { puts("0"); return 0; }
	a[0].x = 1e9 + 1;
	for (int i=1; i<=n; i++){
		scanf("%d%d", &a[i].x, &a[i].y);
		if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
	}
	sort(a+1, a+n+1);
	for (int i=1; i<=n; i++)
		if (a[i].x <= a[_mn].x && a[i].y >= a[_mx].y) _mn = _mx = i;
		else if (a[i].x < a[_mn].x) _mn = i;
		else if (a[i].y > a[_mx].y) _mx = i;
	mn = 1e9 + 1;
	for (int i=1; i<=n; i++){
		mn = min(mn, a[i].y);
		mx = max(mx, a[i].x);
	}
	ans = 1LL * (mx-a[_mn].x) * (a[_mx].y-mn);
	//if (_mn != _mx){
		best = 1e9 + 1; mn = mx = a[1].y;
		for (int i=2; i<=n; i++){
			best = min(best, max(a[n].x, mx) - min(a[i].x, mn));
			mn = min(mn, a[i].y);
			mx = max(mx, a[i].y);
		}
		ans = min(ans, 1LL * best * (a[_mx].y - a[_mn].x));
	//}
	printf("%lld\n", ans);
	return 0;
}

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


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  
  for (int i=1;i<=(n);i++){
  cin >> a[i];
  }
  
  int pre = -999;
 for (int i=1;i<=(n);i++){
    if (pre <= a[i]-1){
    pre = a[i]-1;
    } else if(pre <= a[i]){
    pre =a[i];
    }else {
    puts("No");
      return 0;
    }
  }
     puts("Yes");
return 0;  
}

Measured memory_bytes: 640
import calendar
c = 0
while 1:
	f = 0
	(n,m) = map(int,raw_input().split())
	if (n == 0 and m == 0):
		break;
	if c == 1:
		print ""
	for i in range(n,m+1):
		if calendar.isleap(i):
			f = 1
			print i
	if f == 0:
		print "NA"
	c = 1

Measured memory_bytes: 4984
#include<stdio.h>
int main(void)
{
	int a,b,menseki,syu;
	scanf("%d",&a);
	scanf("%d",&b);
	menseki=a*b;
	syu=(a+b)*2;
	printf("%d ",menseki);
	printf("%d\n",syu);
	return 0;
}


Measured memory_bytes: 2148
N = int(input())
s = [int(input()) for _ in range(N)]
s.sort()
ans = sum(s)

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

         

Measured memory_bytes: 3060
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<int> a(n);
   f(i,0,n) cin >> a[i];
   sort(all(a));
   reverse(all(a));
   int ans = a.front();
   multiset<array<int,3>> s;
   s.insert({min(a[0],a[1]),a[0],a[1]});
   s.insert({min(a[0],a[1]),a[0],a[1]});
   f(i,2,n){
      auto mx = *s.rbegin();
      ans += mx[0];
      s.erase(s.find(mx));
      array<int,3> ff = {min(mx[1],a[i]),mx[1],a[i]};
      array<int,3> ss = {min(mx[2],a[i]),mx[2],a[i]};
      s.insert(ff);
      s.insert(ss);
   }
   cout << ans << '\n';
   return 0;
}

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

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;

  cout << max(0, c-(a-b));
}

Measured memory_bytes: 256
require 'prime'

$primes = Prime.first 1300
$is_prime = { }

$primes.each { |prime| $is_prime[prime] = true}

while n = gets and (not n.nil?)
  n = n.to_i
  ans = 0
  (1..n).each do |i|
    ans += 1 if $is_prime[i] and $is_prime[n - i + 1]
  end
  p ans
end

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

using namespace std;

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

    int a[3];

    for (int i=0;i<3;i++){
        cin >> a[i];
    }

    sort(a,a+3);

    cout << (int) (a[1] + a[0]) << endl;



    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>

int main(void) {
	int N;
	int sum = 0;
	scanf("%d", &N);
	char s[N];
	scanf("%s", s);
	for (int i = 0; i < N - 1; i++) {
		if (s[i] == 0) continue;
		char a = s[i];
		for (int j = i + 1; j < N; j++) {
			if (a == s[j]) {
				s[j] = 0;
			}
			else {
				break;
			}
		}
		sum++;
	}
	if (s[N - 1] != 0)sum++;

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 1;
const int inf = 1e9 + 7;
signed main () {
    int n, k;
    int ans ;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x >= k) ans++;
    }      
    cout << ans;

}


Measured memory_bytes: 256