akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;

ll n,m;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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


// combination mod prime
// mintが必要
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint c(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[n-k];
  }
  mint f(int n){
    return fact[n];
  }
};

int main(){
    combination c(1000000);
    cin >> n >> m;
    mint res = c.p(m,n);
    res *= c.p(m,n);
    for(int i=1;i<=n;i++){
        mint now = c.f(i);
        now *= c.c(n,i);
        now *= c.c(m,i);
        now *= c.p(m-i,n-i);
        now *= c.p(m-i,n-i);
        if(i%2==1){
            res -= now;
        }
        else{
            res += now;
        }
    }
    cout << res << endl;


    return 0;
}


Measured memory_bytes: 18640
n,m = map(int,input().split())
klist = []
swlist = []
ans = 0
for s in range(m):
	k,*sw = list(map(int,input().split()))#kとswを別々に入力
	klist.append(k) #<- kのリスト
	swlist.append(sw) #<- swのリスト
pwlist = list(map(int,input().split())) #pwのリスト

for i in range(2**n):#0~2**nまでの整数をカウントする(整数→ビットでの全探索)
	check = True
	for lump in range(m):#m個の電球についてカウントする
		cnt = 0
		for j in range(klist[lump]):#各スイッチ内の右シフト数をカウント	
			if (i>>swlist[lump][j]-1)&1==1:#右にjシフトする
				cnt += 1#整数iのビットに対し、klistのスイッチがいくつonかをカウントする
		if cnt%2 != pwlist[lump]:#一つのスイッチ列でのカウント終了につき、判定する
			check = False#pwと互換性が1つでもなければFalseとする
	if check == True:#最後までFalseにならなければ組み合わせがあるということになる
		ans += 1
print(ans)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

ll H, W, K;
string s[333];

int main() {
  cin >> H >> W >> K;
  ll i, j;
  
  for(i=0; i<H; i++) cin >> s[i];
  
  vector<ll> b[333];
  for(i=0; i<H; i++)
    for(j=0; j<W; j++)
      if(s[i][j]=='#') b[i].push_back(j);
  
  ll cnt=1;
  vector<ll> v[333];
  vector<P> ze;
  vector<ll> nz;
  
  for(i=0; i<H; i++) {
    ll k=0;
    
    if(b[i].empty()) {
      ze.push_back({i, -1});
      continue;
    }else {
      nz.push_back(i);
    }
    
    for(j=0; j<W; j++) {
      if(k==(ll)b[i].size()) {
        v[i].push_back(cnt-1);
      }else if(j<b[i][k]) {
        v[i].push_back(cnt);
      }else if(j==b[i][k]) {
        v[i].push_back(cnt);
        cnt++;
        k++;
      }
    }
  }
  nz.push_back(INF);
  
  for(i=0; i<ze.size(); i++) {
    ll t=ze[i].ft;
    
    ll f=0;
    ll pos=lower_bound(nz.begin(), nz.end(), t)-nz.begin()-1;
    if(pos>=0) {
      ze[i].sc=nz[pos];
      f=1;
    }
    if(f) continue;
    
    pos=lower_bound(nz.begin(), nz.end(), t)-nz.begin();
    if(pos<H) {
      ze[i].sc=nz[pos];
    }
  }
  
  for(P z: ze)
    for(i=0; i<W; i++)
      v[z.ft].push_back(v[z.sc][i]);
  
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++)
      cout << v[i][j] << " ";
    pt("");
  }
  
  
  
}



















Measured memory_bytes: 3328
#include <cstdio>
#include <cctype>

int
main(int argc, const char *argv[])
{
    char c;
    while ((c = getchar()) != EOF) {
        if (isalpha(c)) {
            if (islower(c)) putchar(toupper(c));
            else putchar(tolower(c));
        } else putchar(c);
    }

    return 0;
}

Measured memory_bytes: 2480
N, C, K = map(int, input().split())
T = sorted([int(input()) for i in range(N)])

bs = 0
st = 0
ans = 0
for t in T:
    if bs == 0:
        st = t
    if bs == C or t-st>K:
        bs = 1
        st = t
        ans += 1
    else:
        bs += 1

if bs > 0:
    ans += 1
print(ans)


Measured memory_bytes: 14120
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome(const string &s) {
  int n = (int)s.size();
  for(int i = 0; i < n/2; ++i) {
    if(s[i] != s[n-i-1])return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  long long n, a, b;
  cin >> n >> a >> b;
  long long n1 = n/(a+b);
  long long n2 = n%(a+b);
  long long ans = min(n2, a) + n1 * a;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <string.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 100000000
using namespace std;

int main() {
	int h, r;
	cin >> h >> r;
	if (-1 * h == r) cout << "0" << endl;
	else if (-1 * h > r) cout << "-1" << endl;
	else cout << "1" << endl;
	return 0;
}

Measured memory_bytes: 3096
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int n, k;
	static long mod = 1000000007;
	static int[][] memo;
	static String s;
	static HashSet<Integer> nodes;
	static ArrayList<Integer>[] ad, tree;
	static boolean[] vis, taken;
	static int[] a;
	static TreeSet<Long> al;
	static long[] val;
	static ArrayList<String> aa;
	static char[] b;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		System.out.println(2d*Math.PI*sc.nextDouble());
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 33304
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,K; cin>>N>>K;
  vector<ll> A(N,0);
  for(ll i=0; i<N; i++) cin>>A[i];
  sort(A.begin(), A.end());
  ll ans=0;
  for(ll i=0; i<K; i++) ans+=A[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
n,m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
ans = Array.new(n,0);
m.times do |i|
    a,b = gets.split.map(&:to_i)
    if h[a-1]<=h[b-1]
        ans[a-1] = 1
    end
    if h[a-1]>=h[b-1]
        ans[b-1] = 1
    end
end
ans.delete(1)
puts ans.length

Measured memory_bytes: 22460
from collections import Counter
import sys
n = int(input())
D = list(map(int,input().split()))
if (D[0] != 0):
  print(0)
  sys.exit(0)
c = Counter(D)
if (c[0] > 1):
  print(0)
  sys.exit(0)
ans = 1
for i in range(1,max(D)+1):
  ans *= c[i-1]**c[i]
print(ans % 998244353)

Measured memory_bytes: 19936
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  int A, B, C, X, ans=0;

  cin >> A >> B >> C >> X;

  for(int a = 0; a <= A; a++){
    for(int b = 0; b <= B; b++){
      for(int c = 0; c <= C; c++){
        if(a*500+b*100+c*50 == X) ans++;
      }
    }
  }

  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long n,M=1e9+7,i,a=0,b=1,c,d=1;
  char s[200010]={};
  scanf("%lld %s",&n,s);
  for(i=0;i<n;i++)b=(b*(i+1))%M;
  for(i=0;i<2*n;i++){
    if(s[i]=='B')c=1;
    else         c=0;
    if((c+a)%2)a++;
    else{
      if(a==0)goto END;
      d=(d*a)%M;
      a--;
    }
    //printf("%lld\n",a);
  }//printf("%lld %lld\n",d,b);
  if(a)goto END;
  printf("%lld\n",(d*b)%M);
  return 0;
 END:;
  printf("0\n");
  return 0;
}
  


Measured memory_bytes: 384
#include<stdio.h>
void pf(int,int);
void pf(int x,int y){
    int h,w;
    for(h=1;h<=x;h++){
        for(w=1;w<=y;w++){
            if(h==1 || w==1 || h==x || w==y){
                printf("#");
            }
            else{
                printf(".");
            }
        }
        printf("\n");
    }
    printf("\n");
    return;
}
int main(void){
    int H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0){
            break;
        }
        else{
            pf(H,W);
        }
    }
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

ll dp[100010][4];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  string s;
  cin >> s;
  
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  
  int n = s.size();
  rep(i,n){
    rep(j,4){
      if(s[i]=='?')dp[i+1][j]+=3*dp[i][j];
      else dp[i+1][j]+=dp[i][j];
      dp[i+1][j]%=MOD;
    }
    if(s[i]=='A' || s[i]=='?'){
      dp[i+1][1]+=dp[i][0];
      dp[i+1][1]%=MOD;
    }
    if(s[i]=='B' || s[i]=='?'){
      dp[i+1][2]+=dp[i][1];
      dp[i+1][2]%=MOD;
    }
    if(s[i]=='C' || s[i]=='?'){
      dp[i+1][3]+=dp[i][2];
      dp[i+1][3]%=MOD;
    }
  }
  
  cout << dp[n][3] << endl;
    
  return 0;
}


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

#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 INF 2e9
#define ALL(v) v.begin(), v.end()


using namespace std;

int main()
{
	double T, X;
	cin >> T >> X;

	cout << T / X << endl;

	return 0;
}


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

#define _LL long long

int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

int main()
{
    int n;
    cin >> n;
    int *a = inputint(3 * n);

    priority_queue<int, vector<int>> right;
    priority_queue<int, vector<int>, greater<int>> left;

    _LL *leftsum = new _LL[n + 1];
    _LL *rightsum = new _LL[n + 1];

    _LL sum = 0;

    for( int i = 0; i < n; i++ ) 
    {
        left.push(a[i]);
        sum += a[i];
    }

    leftsum[0] = sum;

    for( int i = 0; i < n; i++ ) 
    {
        int top = left.top();
        if( a[n + i] > top )
        {
            sum -= top;
            sum += a[n + i];
            left.pop();
            left.push(a[n + i]);
        }
        leftsum[i + 1] = sum;
    }

    sum = 0;
    for( int i = 0; i < n; i++ ) 
    {
        right.push(a[2 * n + i]);
        sum += a[2 * n + i];
    }
    rightsum[n] = sum;
    for( int i = 0; i < n; i++ ) 
    {
        int top = right.top();
        if( a[2 * n - 1 - i] < top )
        {
            sum -= top;
            sum += a[2 * n - 1 - i];
            right.pop();
            right.push(a[2 * n - 1 - i]);
        }
        rightsum[n - 1 - i] = sum;
    }

    _LL bestans = leftsum[0] - rightsum[0];
    for( int i = 0; i < n + 1; i++ ) 
    {
//        cout << leftsum[i] << " " << rightsum[i] << endl;
        bestans = max(bestans, leftsum[i] - rightsum[i]);
    }

    cout << bestans;
}

Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <cstdlib>
#include <vector>
using namespace std;

int a , c;
string s;

int main() {
	
	cin  >> a >> s;

	for (int i = 0; i < a; i++) {
		if (s[i] == 'R') c++;
	}

	if (c > a / 2) cout << "Yes" << endl;
	else cout << "No" << endl;

	system("pause");
	return 0;
}



Measured memory_bytes: 504
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<set>
#include<string.h>
#include<map>
#include<vector>
#define pb push_back
#define ins insert 
#define mp make_pair
#define ll long long 
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 10000007
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll a[n+1],dp[n+1];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i+1];
        dp[i+1]=M;
    }
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for (int i = 3; i <n+1; ++i)
    {
        dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
        for (int j = i-2; j>0 && j>=i-k ; --j)
        {
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n];
    return 0 ;
}


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

int main()
{
	int n,maxn=0,sum=0;
	cin>>n;
	for(int i=1;i<=sqrt(n);i++)
	{
		int ni=i;
		for(int j=1;j<=9;j++)
		{
			ni*=i;
			if(ni>n) break;
			if(ni>maxn) maxn=ni;
		}
		
	}
	cout<<maxn;
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=100+10;
const int inf=0x3f3f3f3f;
int n;
int Ans=inf;
int a[maxn];

inline void file() {
	freopen("ARC059C.in","r",stdin);
	freopen("ARC059C.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read();
	For (i,1,n) a[i]=read();
	For (p,-100,100) {
		int sum=0;
		For (i,1,n) sum+=(a[i]-p)*(a[i]-p);
		chkmin(Ans,sum);
	}
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,b,k;
long long R(long long h){
    if(h==1)return 1;
    return 1+2*R(h/2);
}
int main(){
    long long h,n;
    cin>>h>>n;
    vector<int>A(n),B(n);
    for(int i=0;i<n;i++){
        cin>>A[i]>>B[i];
    }
    vector<vector<int>>dp(n+1,vector<int>(h+1,INT_MAX));
    for(int i=0;i<n;i++){
        for(int j=0;j<h+1;j++){
            int idx = j-A[i]<0?0:j-A[i];
            if(j==0){
                dp[i][j]=0;
            }
            else if(i==0){
                dp[i][j]=dp[i][idx]+B[i];
            }
            else{
                dp[i][j]=min(dp[i-1][j],B[i]+dp[i][idx]);
            }
        }
    }
    cout<<dp[n-1][h];
}

Measured memory_bytes: 39424
from collections import Counter

N = [int(_) for _ in input().split()][0]
a = [int(_) for _ in input().split()]
s = [0] * (N + 1)

cnt = Counter()
for i in range(N):
    s[i + 1] = a[i] + s[i]
    cnt[s[i + 1]] += 1

ans = 0
for k, v in cnt.items():
    # print(k,v)
    if v <= 1: continue

    ans += (v * (v - 1)) // 2
ans += cnt[0]
print(ans)


Measured memory_bytes: 40580
#include <iostream>

using namespace std;

int main()
{
	int i,j;
	int a[200], b[200];
	int digit[200] = { 0 };

	for ( i = 0; i < 200; i++){
		if(!(cin >> a[i] >> b[i])){
			break;
		}

		int sum = a[i] + b[i];
		while (1){
			digit[i]++;
			sum /= 10;
			if (sum == 0){
				break;
			}
		}
	}

	for (j = 0; j < i; j++){
		cout << digit[j] << endl;
	}

	return 0;
}

Measured memory_bytes: 3028
n, m = input().split()
n = int(n)
m = int(m)

a = list(map(int, input().split()))

x = 0
for i in range(0, len(a)):
  x = x + a[i]
  
x = int(x)
play_day = n - x

if x > n:
  print("-1")
else:
  print(play_day)

Measured memory_bytes: 10012
{-# OPTIONS_GHC -O #-}

import Data.List
import Control.Monad

main=do
    [n,m,x]<-map read.words<$>getLine::IO[Int]
    as<-map read.words<$>getLine::IO[Int]

    print $ liftM2 min (length.fst) (length.snd) $ partition (<x) as

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

class Main{

	public static void main(String[] args) throws IOException
	{
		int n,m,l;
		int i,j,k;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );

		String[] nml = br.readLine().split(" ");

		n = Integer.parseInt(nml[0]);
		m = Integer.parseInt(nml[1]);
		l = Integer.parseInt(nml[2]);
		
		int[][] a = new int[n][m];
		int[][] b = new int[m][l];
		long[][] out = new long[n][l];

		for(i=0; i<n; i++)//get a
		{
			String[] str = br.readLine().split(" ");
			for(j=0; j<m; j++) a[i][j] = Integer.parseInt(str[j]);
		}

		for(i=0; i<m; i++)//get b
		{
			String[] str = br.readLine().split(" ");
			for(j=0; j<l; j++) b[i][j] = Integer.parseInt(str[j]);
		}


		for(i=0; i<n; i++)//calc
		{
			for(j=0; j<l; j++)
			{
				for(k=0; k<m; k++)
				{
					out[i][j] = out[i][j] + a[i][k]*b[k][j];
					
				}
				
				System.out.print(out[i][j] + ( (j==l-1) ? "" : " ") );
			}

			System.out.println();
		}
		

	}
	
	/*
	static void ShowMatrix(int[][] matrix, int n, int m)
	{
		for(int i=0; i<n; i++)
		{
			for(int j=0; j<m; j++)
			{
				System.out.print(matrix[i][j]);
			}
			
			System.out.println();
		}
		
	}*/
	
}

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

int INF=0x3f3f3f3f;
typedef long long LL;

int main(){
	ios_base::sync_with_stdio(false);
	int n,l,r;
	LL ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>l>>r;
		ans+=(r-l+1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
def retminabs(x,p):
    dif=0
    while True:
        if not x-dif in p:
            return x-dif
        elif not x+dif in p:
            return x+dif
        dif+=1
X,N=map(int,input().split())
P=list(map(int,input().split()))
print(retminabs(X,P))

Measured memory_bytes: 9092
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 
ll chmin(ll &a, ll b) {return a = min(a, b);}

int main(){
	int n;
	cin >> n;
	vector<ll> row(n), col(n);// 計算に使うんでllにしときます
	for(int i=0; i<n; i++) cin >> row[i] >> col[i];
	const ll INF = 100100100100100;
	// dp[l][r]: 区間[l,r]の行列の積を計算するのに必要なスカラー乗算の最小回数 
	// ll ans = dp[0][n-1] となるよ
	vector<vector<ll>> dp(n+1, vector<ll>(n+1, INF));
	
	//初期化
	for(int l=0; l<n; l++){
		dp[l][l] = 0;//行列1つだけじゃあ計算回数は0
	}

	for(int w=1; w<n; w++){
		for(int l=0; l+w<n; l++){
			int r = l+w;
			for(int mid=l; mid<r; mid++){// 結合する位置をずらしていく
				ll num = row[l] * col[mid] * col[r];// a×b と b×c の計算回数は a * b * c
				num = row[l] * row[mid+1] * col[r];//こっちでもよい
				chmin(dp[l][r], dp[l][mid] + num + dp[mid+1][r]);// 例  a×b と b×c　と c×d　の計算回数は a*b*c + a*c*d 　と  b*c*d + a*b*d  の小さいほう 
			}
		}
	}

	cout << dp[0][n-1] << endl;
}



Measured memory_bytes: 3216
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <climits>
using namespace std; 

const int INF = 1 << 29;

int main(){
	
		int N;
		cin>>N;
		int dp[N][3];
		int cost[N][3];
		
		
		for(int i = 0; i < N; ++i){
			int x,y,z;
			cin>>x;
			cin>>y;
			cin>>z;
			
			cost[i][0] = x;
			cost[i][1] = y;
			cost[i][2] = z;
			
		}
		
		dp[0][0] = cost[0][0];
		dp[0][1] = cost[0][1];
		dp[0][2] = cost[0][2];
		
		for(int i = 1; i < N; ++i){
			dp[i][0] = max(dp[i - 1][1],dp[i - 1][2]) + cost[i][0];
			dp[i][1] = max(dp[i - 1][0],dp[i - 1][2]) + cost[i][1];
			dp[i][2] = max(dp[i - 1][0],dp[i - 1][1]) + cost[i][2];
		}
		
		
		cout << max(max(dp[N-1][0],dp[N-1][1]),dp[N-1][2]);
		
		
		return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
ll MOD = 1e9 + 7;
int A[3][3];
bool ok[3][3];
int main() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int  b;
		cin >> b;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (A[j][k] == b) ok[j][k] = 1;
			}
		}
	}
	bool bingo = 0;
	for (int i = 0; i < 3; i++) {
		bool x = 1;
		for (int j = 0; j < 3; j++) {
			if (!ok[i][j]) {
				x = 0;
				break;
			}
		}
		if (x) bingo = 1;
	}
	for (int i = 0; i < 3; i++) {
		bool x = 1;
		for (int j = 0; j < 3; j++) {
			if (!ok[j][i]) {
				x = 0;
				break;
			}
		}
		if (x) bingo = 1;
	}
	bool x = 1;
	for (int i = 0; i < 3; i++) {
		if (!ok[i][i]) {
			x = 0;
			break;
		}
	}
	if (x) bingo = 1;
	x = 1;
	for (int i = 0; i < 3; i++) {
		if (!ok[3 - i - 1][i]) {
			x = 0;
			break;
		}
	}
	if (x) bingo = 1;
	if (bingo) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

const int maxn = 110, maxw = 100010;
long long dp[maxn][maxw], w[maxn], v[maxn];
int n, W;
/**
dp[i][j]±íÊ¾Ñ¡Ç°i¸öÎïÆ·£¬·ÖÅäj¿Õ¼äÊ±»ñµÃµÄ×î´ó¼ÛÖµ 
*/
int main() {
	//freopen("demo.in", "r", stdin);
	//freopen("demo.out", "w", stdout);
	
	scanf("%d%d", &n, &W);
	for (int i = 1; i <= n; i++)
		scanf("%lld%lld", &w[i], &v[i]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= W; j++)
		{
			dp[i][j] = dp[i-1][j];
			if (j-w[i] >= 0)
				dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
		}
	printf("%lld\n", dp[n][W]);			

	return 0;
}


Measured memory_bytes: 79360
from collections import defaultdict
N = int(input())
primes = defaultdict(int)
for i in range(N):
  n = i + 1
  p = 2
  while n >= p:
    while n % p == 0:
      primes[p] += 1
      n //= p
    p += 1
  if n > 1:
    primes[n] += 1
P = [0, 0, 0, 0, 0]
for p, v in primes.items():
  if v >= 74:
    P[0] += 1
  elif v >= 24:
    P[1] += 1
  elif v >= 14:
    P[2] += 1
  elif v >= 4:
    P[3] += 1
  elif v >= 2:
    P[4] += 1
for i in range(4):
  P[i + 1] += P[i]
cnt = 0
cnt += P[0]
cnt += P[1] * (P[4] - 1)
cnt += P[2] * (P[3] - 1)
cnt += P[3] * (P[3] - 1) // 2 * (P[4] - 2)
print(cnt)

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

#undef DEBUG

#ifdef DEBUG
struct testdata{
    int N;
    char S[100000+1];
    int a;
} td[] = {
    {10, "aabbbbaaca", 5},
    {5, "aaaaa", 1},
    {20, "xxzaffeeeeddfkkkkllq", 10},
};
#endif

void
solver(int n, char *s)
{
    int a=1;
    char p=s[0];
    int i;

    for (i=1; i<strlen(s); i++) {
        if (s[i]!=p) {
            a++;
        }
        p = s[i];
    }
    printf("%d\n", a);
}

int
main(int argc, char *argv[])
{
    int i;
    int N;
    char S[100000+1];
#ifdef DEBUG
    for (i=0; i<3; i++) {
        solver(td[i].N, td[i].S);
        printf("ans: %d\n", td[i].a);
    }
#else
    scanf("%d", &N);
    scanf("%s", S);
    solver(N, S);
#endif

    return 0;
}

Measured memory_bytes: 256
# get input from user and convert in to int
current_temp = int(input())

# Check that the restriction per task instruction is met
if (current_temp <= 40) and (current_temp >= -40):
    # Check if current_temp is greater than or equal to 30
    if current_temp >= 30:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 9160
#include<iostream>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;

int main() {

	int N, M, C;
	cin >> N >>M >> C;

	vector<vector<int>> A;
	vector<int> Ai;
	vector<int> Bs;
	vector<int>anss;
	int result = 0;
	A.resize(N);
	Ai.resize(M,0);
	Bs.resize(M);
	anss.resize(N,0);
	for (auto i = 0; i < M; i++) {
		cin >> Bs[i];
	}


	for (auto i = 0; i < N; i++) {
		for (auto j = 0; j < M; j++) {
			int temp;
			cin >> temp;
			anss[i] += temp * Bs[j];
		}
		anss[i] += C;
		if (anss[i] > 0)result += 1;
	}


	cout << result << endl;


	return 0;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll; 
 
int main(void){
	
	ll N, M;
	
	cin >> N >> M;
	
	vector<pair<ll, ll>> A(N);
	
	rep(i, N)
		cin >> A[i].first >> A[i].second;
		
	sort(A.begin(), A.end());
	
	ll ans = 0;
	rep(i, N){
		if(M - A[i].second >= 0){
			M -= A[i].second;
			ans += A[i].first * A[i].second;
		}
		else{
			while(M > 0){
				M--;
				ans += A[i].first;
			}
			break;
		}
	}
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int s=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) s=s*10+ch-'0',ch=getchar();
	return s;
}
const int N=2e5+5;
typedef long long ll;
int n;
int a[N],cnt[N],fa[N],f[N],siz[N];
ll ans;
inline int findf(int x){
	return x==f[x]?x:f[x]=findf(f[x]);
}
struct node{
	int x,y,id;
	bool operator < (const node & b) const {
		return 1ll*x*b.y<1ll*y*b.x;
	}
};
priority_queue<node> q;
int main(){
	n=read();
	for(int i=2;i<=n;i++) fa[i]=read();
	for(int i=1;i<=n;i++) a[i]=read(),f[i]=i,siz[i]=1;
	for(int i=2;i<=n;i++) if(!a[i]) f[i]=findf(fa[i]),siz[f[i]]+=siz[i];
	for(int i=1;i<=n;i++) if(a[i]) {
		cnt[i]=1,siz[i]--;
		ans+=siz[i];
		q.push({siz[i],cnt[i],i});
	}
	while(!q.empty()){
		node u=q.top();q.pop();
		int x=u.id,y=findf(fa[x]);
		if(!y||u.x!=siz[x]) continue;
		ans+=1ll*cnt[y]*u.x,siz[y]+=siz[x],cnt[y]+=cnt[x],f[x]=y;
		q.push({siz[y],cnt[y],y});
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 12184
import sys
input=sys.stdin.readline
#import math
import collections
#from collections import deque
#from bisect import bisect_left
N = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
l = {}
for i in range(N):
    S = list(input())
    S.remove("\n")
    S.sort()
    S = tuple(S)
    if S in l.keys():
      l[S] += 1
    else:
      l[S] = 1
ans = 0
for j in l.values():
  ans += j*(j-1)/2
print(int(ans))

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int n, m;
  cin >> n >> m;
  vii tree(n);
  rep(i,m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  int ans = 0;
  rep(i,n){
    for(int &x : tree[i]){
      queue<int> que;
      vi seen(n);
      seen[i] = true;
      for(int &y : tree[i]){
        if(x == y) continue;
        que.push(y);
      }
      while(!que.empty()){
        int now = que.front(); que.pop();
        seen[now] = true;
        for(int &next : tree[now]){
          if(seen[next]) continue;
          que.push(next);
        }
      }
      ans += (!seen[x]);
    }
  }
  ans /= 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
	int a[]={0,1,3,1,2,1,2,1,1,2,1,2,1};
	int b,c;
	cin>>b>>c;
	if(a[b]==a[c])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import itertools
S=input()
N=len(S)-1
sum1=0

for i in itertools.product(["+",""],repeat=N):
    ans=""
    for x in range(N):
        if i[x]=="+":
            ans+=S[x]+i[x]
        else:
            ans+=S[x]
    ans+=S[-1]
    sum1+=eval(ans)
print(sum1)
    
            

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	int n, f; cin >> n >> f;
	vector<vector<string>> v(n);
	REP(i, n)
	{
		int t; cin >> t;
		REP(j, t)
		{
			string s; cin >> s;
			v[i].push_back(s);
		}
	}
	map<pair<string, string>, int> cnt;
	for(auto a : v)
	{
		REP(i, a.size())REP(j, i)
		{
			string s = a[i], t = a[j];
			if (s > t) swap(s, t);
			cnt[make_pair(s, t)]++;
		}
	}
	int ans = 0;
	for (auto p : cnt)
	{
		if (p.second >= f)
		{
			ans++;
		}
	}
	cout << ans << endl;
	for (auto p : cnt)
	{
		if (p.second >= f)
		{
			cout << p.first.first << " " << p.first.second << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int n, c = 0;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 1; i < n - 1; i++) {
        if(a[i] >= a[i - 1] && a[i] <= a[i + 1] || a[i] <= a[i - 1] && a[i] >= a[i + 1]) c++;
    }
    cout << c;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define S 100
int main()
{
    int A,B,C,m,n;
    scanf("%d %d %d",&A,&B,&C);
    if(A+B<C)
    {
        m=A+B+B+1;
        printf("%d\n",m);
    }
    else
    {
        n=B+C;
        printf("%d",n);
    }

    return 0;


}

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

template<typename T>
struct BellmanFord{
    const T inf=numeric_limits<T>::max();
    struct edge{
        int u,v; T w;
        edge(int u,int v,T w):u(u),v(v),w(w){}
    };
    int n;
    vector<vector<int>> G;
    vector<int> check,reach;
    vector<edge> es;
    BellmanFord(int n):n(n),G(n),check(n),reach(n,1){}
    void add_edge(int u,int v,T w){
        es.emplace_back(u,v,w);
        G[u].emplace_back(v);
    }
    vector<T> build(int s,int &neg_loop){
        vector<T> d(n,inf);
        d[s]=0;
        for (int i=0;i<n;++i){
            bool update=false;
            for (auto e:es){
                if (!reach[e.u]||!reach[e.v]||d[e.u]==inf) continue;
                if (d[e.u]+e.w<d[e.v]){
                    d[e.v]=d[e.u]+e.w;
                    update=true;
                }
            }
            if (!update) break;
            if (i==n-1){neg_loop=1; return d;}
        }
        neg_loop=0; return d;
    }
    void dfs(int v){
        if (check[v]) return;
        check[v]=1;
        for (int u:G[v]) dfs(u);
    }
    T shortest_path(int s,int t,int &neg_loop){
        for (int i=0;i<n;++i){
            fill(check.begin(),check.end(),0);
            dfs(i);
            reach[i]=check[t];
        }
        return build(s,neg_loop)[t];
    }
};

// https://atcoder.jp/contests/abc061/tasks/abc061_d

void ABC061_D(){
    int N,M; cin >> N >> M;

    BellmanFord<long long> BF(N);
    for (int i=0;i<M;++i){
        int a,b,c; cin >> a >> b >> c;
        BF.add_edge(--a,--b,-c);
    }

    int neg;
    long long ans=BF.shortest_path(0,N-1,neg);
    if (neg) cout << "inf" << '\n';
    else cout << -ans << '\n';
}

// https://atcoder.jp/contests/abc137/tasks/abc137_e

void ABC137_E(){
    int N,M,P; cin >> N >> M >> P;

    BellmanFord<long long> BF(N);
    for (int i=0;i<M;++i){
        int A,B,C; cin >> A >> B >> C;
        BF.add_edge(--A,--B,P-C);
    }

    int neg;
    long long ans=BF.shortest_path(0,N-1,neg);
    cout << (neg?-1:max(0LL,-ans)) << '\n';
}

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

Measured memory_bytes: 3956
import Control.Monad
import Data.IntMap.Strict ((!)) 
import qualified Data.IntMap.Strict as M 
import qualified Data.Set as S 
import qualified Data.ByteString.Char8 as B 
import qualified Data.Array.IArray as A 
import Data.Maybe 

type Vertex = Int 
type Weight = Int 
type Edge = (Vertex, (Vertex, Weight)) 
type Graph = A.Array Vertex (S.Set (Vertex, Weight))
type Memo = M.IntMap Weight

buildG :: Int -> [Edge] -> Graph 
buildG n = A.accumArray (flip S.insert) S.empty (1, n) 

from :: Graph -> Vertex -> S.Set (Vertex, Weight) 
from g = (g A.!) 

readDirectedEdge :: B.ByteString -> [Edge] 
readDirectedEdge = map ((\[s,t,w] -> (s,(t,w))) . map readVertex . B.words) . B.lines 

readVertex :: B.ByteString -> Vertex 
readVertex = fst . fromJust . B.readInt

main :: IO ()
main = do
  [n,_] <- map read . words <$> getLine
  es <- readDirectedEdge <$> B.getContents
  let g = buildG n es
  putStrLn $ maybe "inf" show (score n g)

score :: Int -> Graph -> Maybe Weight
score n g = guard (im1!n == im2!n) >> return (im1!n)
  where
    im0 = M.singleton 1 0
    im1 = bellman_ford g n im0
    im2 = bellman_ford g (n + 1) im1

bellman_ford :: Graph -> Int -> Memo -> Memo
bellman_ford g n im
  | n == 1 = im
  | otherwise = bellman_ford g (n - 1) (M.foldlWithKey' (move g) im im)

move :: Graph -> Memo -> Vertex -> Weight -> Memo
move g im s aw = S.foldl' update im (from g s)
  where 
    update acc (t,w)
      | M.notMember t acc || (acc!t) < aw + w = M.insert t (aw + w) acc
      | otherwise = acc

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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;
}


signed main() {
  int N;
  cin >> N;
  int A, B, C;
  cin >> A >> B >> C;
  vector<string> s(N);
  rep(i, N) {
    cin >> s[i];
  }

  vector<char> ans(N);
  rep(i, N) {
    if (s[i] == "AB") {
      if (A > B) {
        A--, B++, ans[i] = 'B';
      } else if (A < B) {
        B--, A++, ans[i] = 'A';
      } else {
        if (i != N - 1) {
          string ns = s[i + 1];
          if (ns == "AB" || ns == "AC") {
            B--, A++, ans[i] = 'A';
          } else {
            A--, B++, ans[i] = 'B';
          }
        } else {
          B--, A++, ans[i] = 'A';
        }
      }
    } else if (s[i] == "AC") {
      if (A > C) {
        A--, C++, ans[i] = 'C';
      } else if (A < C) {
        C--, A++, ans[i] = 'A';
      } else {
        if (i != N - 1) {
          string ns = s[i + 1];
          if (ns == "AB" || ns == "AC") {
            C--, A++, ans[i] = 'A';
          } else {
            A--, C++, ans[i] = 'C';
          }
        } else {
          C--, A++, ans[i] = 'A';
        }
      }
    } else {
      if (B > C) {
        B--, C++, ans[i] = 'C';
      } else if (B < C) {
        C--, B++, ans[i] = 'B';
      } else {
        if (i != N - 1) {
          string ns = s[i + 1];
          if (ns == "AB" || ns == "BC") {
            C--, B++, ans[i] = 'B';
          } else {
            B--, C++, ans[i] = 'C';
          }
        } else {
          C--, B++, ans[i] = 'B';
        }
      }
    }
    if (A < 0 || B < 0 || C < 0) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  rep(i, len(ans)) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, K, ans{}; cin >> N >> K;
  vector<bool> bs(N);
  while (K--) {int d; cin >> d; while (d--) {int A; cin >> A; bs[--A] = true;}}
  for (auto b : bs) ans += !b;
  cout << ans << endl;}

Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

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

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

constexpr int max_n = 200'000 + 5;
constexpr int INF = 1'000'000'000 + 5;

int n;
vector<int> as(max_n);
vector<vector<int>> adjs(max_n);
vector<int> dp(max_n, INF);
vector<int> res(max_n);

void dfs(int cur, int par = -1) {
    // dpを更新 差分を保持
    auto it = lower_bound(dp.begin(), dp.end(), as[cur]);
    int prev = *it;
    *it = as[cur];
    auto it2 = lower_bound(dp.begin(), dp.end(), INF);
    res[cur] = it2 - dp.begin();
    for (auto ch : adjs[cur])
    {
        if (ch == par) { continue; }
        dfs(ch, cur);
    }
    // dpを戻す
    *it = prev;
}

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    cin>>n;
    rep(i,n) { cin>>as[i]; }
    rep(i,n-1) {
        int u,v; cin>>u>>v; u--; v--;
        adjs[u].push_back(v);
        adjs[v].push_back(u);
    }

    dfs(0,-1);
    rep(i,n) {
        cout << res[i] << '\n';
    }

    return 0;
}


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

int main() {
	vector <char> s;
	char c;
	while (cin >>c) s.push_back(c);
	vector <char> a;
	vector <char> b;
	for (int i=0; i<s.size(); i++){
		if (i%2==0){
			a.push_back('0');
			b.push_back('1');
		}
		else{
			b.push_back('0');
			a.push_back('1');
		}
	}
	int d1=0;
	int d2=0;
	for (int i=0; i<s.size(); i++){
		if (s[i]!=a[i]) d1++;
		if (s[i]!=b[i]) d2++;
	}
	if (d1<d2) cout << d1;
	else cout << d2;
	return 0;
}

Measured memory_bytes: 640
// ------------------------------------
// Date:2018/ 4/ 3
// Problem:D - Widespread d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;
const ll MAX_L = 1e16 + 1;

int N;
ll A, B;
vector< ll > h;

bool check(ll n)
{
  ll rest = n;
  vector< ll > w(h);
  REP(i, N) {
    if (w[i] > n * B) {
      rest -= (w[i] - n * B) / (A - B) + ((w[i] - n * B) % (A - B) == 0 ? 0 : 1);
    }
    // rest -= w[i] / (A - B) + (w[i] % (A - B) == 0 ? 0ll : 1ll);
    // debug(i);
    // debug(rest);
  }
  // debug(rest);
  if (rest < 0) return false;
  return true;
}
  
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N >> A >> B;
  REP(i, N) {
    LCIN(mh);
    h.emplace_back(mh);
  }

  ll lb = 0;
  ll ub = 1e9 + 1;
  while(ub - lb > 1) {
    ll mid = (ub + lb) / 2;
    if (check(mid)) ub = mid;
    else lb = mid;
  }

  ll ans = ub;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr double eps = 1e-14; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n,q;
    cin >> n;
    set<int> s;
    rep(i,n){
        int ss;cin>>ss;
        s.insert(ss);
    }
    cin>>q;
    int ans=0;
    int t;
    rep(i,q){
        cin >> t;
        if(s.count(t)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5016
n,c,k=map(int,raw_input().split())
t=[int(raw_input()) for _ in xrange(n)]
t.sort()
i=0
ans=0
#print t
while i<n:
    li=t[i]+k
    cnt=0
    f=0
    #print t[i]
    while i<n and t[i]<=li:
        cnt+=1
        if cnt==c:
            f=1
            ans+=1
            cnt=0
        i+=1
    if f==0:
        ans+=1
    else:
        i-=cnt
print ans


Measured memory_bytes: 34716
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
const double PI  =3.141592653589793238463;
using namespace std;

int main()
{
    faster;
    ll a,b,c,d,e,f=0,ans=0,sum=0,m,n,p,q,r,t,w,x,y,z;
    string s;
    cin>>a>>b;
   int ara[1000];
   ara[0]=1;
    for(int i=1;i<=999;i++)
    {
        ara[i]=ara[i-1]+(i+1);
    }
    for(int i=0;i<=999;i++)
    {
       // cout<<ara[i]<<" ";
        if(a<=ara[i])
        {
            m=ara[i];
            n=ara[i+1];
            m=m-a;
            n=n-b;
          //  cout<<"m "<<m<<" n "<<n<<endl;
            if(m==n){
                 cout<<m<<endl;
            break;
            }

        }
    }

    return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
using namespace std;

int main(){
  int n, r;
  string cards;
  string left, right, rest;
  stringstream ss;
  int p, c;
  int ans;

  while(cin >> n >> r){
    if((n|r) == 0) break;
    cards = "";
    for(int i=n; i>0; i--){
      ss << i;
      cards = cards + ss.str() + " ";
      if(i<10) cards+= " ";
      ss.str("");
    }

    int pp, cp;
    for(int i=0; i<r; i++){

      cin >> p >> c;
      pp = (p-1)*3;
      cp = c*3;
      left = cards.substr(0, pp);
      right = cards.substr(pp, cp);
      rest = cards.substr(pp+cp);
      cards = right + left + rest;
    }
    string ans="";
    for(int i=0; i<3; i++){
      if(!isspace(cards[i]))ans += cards[i];
    }
    cout << ans << endl;
  
  }
 
 return 0;
}

Measured memory_bytes: 0